1 # Copyright 2005-2019 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 standard_ada_testfile foo
20 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
24 clean_restart ${testfile}
26 set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
27 runto "foo.adb:$bp_location"
31 # A convenience function that verifies that the "complete EXPR" command
32 # returns the EXPECTED_OUTPUT.
34 proc test_gdb_complete { expr expected_output } {
35 gdb_test "complete p $expr" \
40 # A convenience function that verifies that the "complete EXPR" command
41 # does not generate any output.
43 proc test_gdb_no_completion { expr } {
44 gdb_test_no_output "complete p $expr"
47 # Try a global variable, only one match should be found:
49 test_gdb_complete "my_glob" \
50 "p my_global_variable"
52 # A global variable, inside a nested package:
54 test_gdb_complete "insi" \
57 # A global variable inside a nested package, but only giving part of
58 # the fully qualified name (top level package name missing):
60 test_gdb_no_completion "inner.insi"
62 # An incomplete nested package name, were lies a single symbol:
63 test_gdb_complete "pck.inne" \
64 "p pck.inner.inside_variable"
66 # A fully qualified symbol name, mangled...
67 test_gdb_complete "pck__inner__ins" \
68 "p pck__inner__inside_variable"
70 # A fully qualified symbol name...
71 test_gdb_complete "pck.inner.ins" \
72 "p pck.inner.inside_variable"
74 # Make sure that "inside" is not returned as a possible completion
76 test_gdb_no_completion "side"
78 # Verify that "Exported_Capitalized" is not returned as a match for
79 # "exported", since its symbol name contains capital letters.
80 test_gdb_no_completion "exported"
82 # check the "<...>" notation.
83 test_gdb_complete "<Exported" \
84 "p <Exported_Capitalized>"
86 # While at it, make sure we can print the symbol too, using the '<'
88 gdb_test "p <Exported_Capitalized>" " = 2"
90 # Confirm that we can't print the symbol without the '<' notation.
91 gdb_test "p Exported_Capitalized" \
92 "No definition of \"exported_capitalized\" in current context."
93 gdb_test "p exported_capitalized" \
94 "No definition of \"exported_capitalized\" in current context."
96 # A global symbol, created by the binder, that starts with __gnat...
97 test_gdb_complete "__gnat_ada_main_progra" \
98 "p __gnat_ada_main_program_name"
100 # A global symbol, created by the binder, that starts with __gnat,
101 # and using the '<' notation.
102 test_gdb_complete "<__gnat_ada_main_prog" \
103 "p <__gnat_ada_main_program_name>"
106 test_gdb_complete "some" \
107 "p some_local_variable"
109 # A local variable variable, but in a different procedure. No match
110 # should be returned.
111 test_gdb_no_completion "not_in_sco"
113 # A fully qualified variable name that doesn't exist...
114 test_gdb_no_completion "pck.ins"
116 # A fully qualified variable name that does exist...
117 test_gdb_complete "pck.my" \
118 "p pck.my_global_variable"
120 # A fully qualified package name
121 test_gdb_complete "pck.inne" \
122 "p pck.inner.inside_variable"
124 # A fully qualified package name, with a dot at the end
125 test_gdb_complete "pck.inner." \
126 "p pck.inner.inside_variable"
128 # Two matches, from the global scope:
129 test_gdb_complete "local_ident" \
130 [multi_line "p local_identical_one" \
131 "p local_identical_two" ]
133 # Two matches, from the global scope, but using fully qualified names:
134 test_gdb_complete "pck.local_ident" \
135 [multi_line "p pck.local_identical_one" \
136 "p pck.local_identical_two" ]
138 # Two matches, from the global scope, but using mangled fully qualified
140 test_gdb_complete "pck__local_ident" \
141 [multi_line "p pck__local_identical_one" \
142 "p pck__local_identical_two" ]
144 # Two matches, one from the global scope, the other from the local scope:
145 test_gdb_complete "external_ident" \
146 [multi_line "p external_identical_one" \
147 "p external_identical_two" ]
149 # Complete on the name of package.
150 test_gdb_complete "pck" \
151 [multi_line "(p pck\\.ad\[sb\])?" \
152 "(p pck\\.ad\[sb\])?" \
153 "p pck.ambiguous_func" \
154 "p pck.external_identical_one" \
155 "p pck.inner.inside_variable" \
156 "p pck.local_identical_one" \
157 "p pck.local_identical_two" \
158 "p pck.my_global_variable" \
161 # Complete on the name of a package followed by a dot:
162 test_gdb_complete "pck." \
163 [multi_line "(p pck\\.ad\[sb\])?" \
164 "(p pck\\.ad\[sb\])?" \
165 "p pck.ambiguous_func" \
166 "p pck.external_identical_one" \
167 "p pck.inner.inside_variable" \
168 "p pck.local_identical_one" \
169 "p pck.local_identical_two" \
170 "p pck.my_global_variable" \
173 # Complete a mangled symbol name, but using the '<...>' notation.
174 test_gdb_complete "<pck__my" \
175 "p <pck__my_global_variable>"
177 # Very simple completion, but using the interactive form, this time.
178 # The verification we are trying to make involves the event loop,
179 # and using the "complete" command is not sufficient to reproduce
180 # the original problem.
182 if { [readline_is_used] } {
183 set test "interactive complete 'print some'"
184 send_gdb "print some\t"
185 gdb_test_multiple "" "$test" {
186 -re "^print some_local_variable $" {
188 gdb_test_multiple "" "$test" {
189 -re " = 1$eol$gdb_prompt $" {
197 # Usually, parsing a function name that is ambiguous yields a menu through
198 # which users can select a specific function. This should not happen during
199 # completion, though.
200 test_gdb_complete "ambig" \
201 [multi_line "p ambiguous_func" \
203 test_gdb_complete "ambiguous_f" \
205 test_gdb_complete "ambiguous_func" \
208 # Perform a test intented to verify the behavior where the number
209 # of possible completions is very large. The goal is not to verify
210 # precisely the list returned by the complete command (this depends
211 # on too many parameters -- targets, compiler version, runtime, etc).
212 # However, we want to sanity-check each one of them, knowing that
213 # each result should start with "break ada" and that the proposed
214 # completion should look like a valid symbol name (in particular,
215 # no uppercase letters...). See gdb/22670.
217 gdb_test_no_output "set max-completions unlimited"
219 set test "complete break ada"
220 gdb_test_multiple "$test" $test {
221 -re "^$test$eol\(break ada(\[a-z0-9._@\])*$eol\)+$gdb_prompt $" {
224 -re "\[A-Z\].*$gdb_prompt $" {
225 fail "$test (gdb/22670)"