1 # Copyright 2005-2022 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 if { [skip_ada_tests] } { return -1 }
20 standard_ada_testfile foo
22 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
26 clean_restart ${testfile}
28 set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
29 runto "foo.adb:$bp_location"
33 # A convenience function that verifies that the "complete EXPR" command
34 # returns the EXPECTED_OUTPUT.
36 proc test_gdb_complete { expr expected_output {msg ""} } {
37 set cmd "complete p $expr"
41 gdb_test "complete p $expr" \
42 "$expected_output" $msg
45 # A convenience function that verifies that the "complete EXPR" command
46 # does not generate any output.
48 proc test_gdb_no_completion { expr } {
49 gdb_test_no_output "complete p $expr"
52 # Try a global variable, only one match should be found:
54 test_gdb_complete "my_glob" \
55 "p my_global_variable"
57 # A global variable, inside a nested package:
59 test_gdb_complete "insi" \
62 # A global variable inside a nested package, but only giving part of
63 # the fully qualified name (top level package name missing):
65 test_gdb_no_completion "inner.insi"
67 # An incomplete nested package name, were lies a single symbol:
68 test_gdb_complete "pck.inne" \
69 "p pck.inner.inside_variable" \
70 "complete nested package name"
72 # A fully qualified symbol name, mangled...
73 test_gdb_complete "pck__inner__ins" \
74 "p pck__inner__inside_variable"
76 # A fully qualified symbol name...
77 test_gdb_complete "pck.inner.ins" \
78 "p pck.inner.inside_variable"
80 # Make sure that "inside" is not returned as a possible completion
82 test_gdb_no_completion "side"
84 # Verify that "Exported_Capitalized" is not returned as a match for
85 # "exported", since its symbol name contains capital letters.
86 test_gdb_no_completion "exported"
88 # check the "<...>" notation.
89 test_gdb_complete "<Exported" \
90 "p <Exported_Capitalized>"
92 # While at it, make sure we can print the symbol too, using the '<'
94 gdb_test "p <Exported_Capitalized>" " = 2"
96 # Confirm that we can't print the symbol without the '<' notation.
97 gdb_test "p Exported_Capitalized" \
98 "No definition of \"exported_capitalized\" in current context."
99 gdb_test "p exported_capitalized" \
100 "No definition of \"exported_capitalized\" in current context."
102 # A global symbol, created by the binder, that starts with __gnat...
103 test_gdb_complete "__gnat_ada_main_progra" \
104 "p __gnat_ada_main_program_name"
106 # A global symbol, created by the binder, that starts with __gnat,
107 # and using the '<' notation.
108 test_gdb_complete "<__gnat_ada_main_prog" \
109 "p <__gnat_ada_main_program_name>"
112 test_gdb_complete "some" \
113 "p some_local_variable"
115 # A local variable variable, but in a different procedure. No match
116 # should be returned.
117 test_gdb_no_completion "not_in_sco"
119 # A fully qualified variable name that doesn't exist...
120 test_gdb_no_completion "pck.ins"
122 # A fully qualified variable name that does exist...
123 test_gdb_complete "pck.my" \
124 "p pck.my_global_variable"
126 # A fully qualified package name
127 test_gdb_complete "pck.inne" \
128 "p pck.inner.inside_variable" \
129 "complete fully qualified package name"
131 # A fully qualified package name, with a dot at the end
132 test_gdb_complete "pck.inner." \
133 "p pck.inner.inside_variable"
135 # Two matches, from the global scope:
136 test_gdb_complete "local_ident" \
137 [multi_line "p local_identical_one" \
138 "p local_identical_two" ]
140 # Two matches, from the global scope, but using fully qualified names:
141 test_gdb_complete "pck.local_ident" \
142 [multi_line "p pck.local_identical_one" \
143 "p pck.local_identical_two" ]
145 # Two matches, from the global scope, but using mangled fully qualified
147 test_gdb_complete "pck__local_ident" \
148 [multi_line "p pck__local_identical_one" \
149 "p pck__local_identical_two" ]
151 # Two matches, one from the global scope, the other from the local scope:
152 test_gdb_complete "external_ident" \
153 [multi_line "p external_identical_one" \
154 "p external_identical_two" ]
156 # Complete on the name of package.
157 test_gdb_complete "pck" \
158 [multi_line "(p pck\\.ad\[sb\])?" \
159 "(p pck\\.ad\[sb\])?" \
160 "p pck.ambiguous_func" \
161 "p pck.external_identical_one" \
162 "p pck.inner.inside_variable" \
163 "p pck.local_identical_one" \
164 "p pck.local_identical_two" \
165 "p pck.my_global_variable" \
168 # Complete on the name of a package followed by a dot:
169 test_gdb_complete "pck." \
170 [multi_line "(p pck\\.ad\[sb\])?" \
171 "(p pck\\.ad\[sb\])?" \
172 "p pck.ambiguous_func" \
173 "p pck.external_identical_one" \
174 "p pck.inner.inside_variable" \
175 "p pck.local_identical_one" \
176 "p pck.local_identical_two" \
177 "p pck.my_global_variable" \
180 # Complete a mangled symbol name, but using the '<...>' notation.
181 test_gdb_complete "<pck__my" \
182 "p <pck__my_global_variable>"
184 # Very simple completion, but using the interactive form, this time.
185 # The verification we are trying to make involves the event loop,
186 # and using the "complete" command is not sufficient to reproduce
187 # the original problem.
189 if { [readline_is_used] } {
190 set test "interactive complete 'print some'"
191 send_gdb "print some\t"
192 gdb_test_multiple "" "$test" {
193 -re "^print some_local_variable $" {
195 gdb_test_multiple "" "$test" {
196 -re " = 1$eol$gdb_prompt $" {
204 # Usually, parsing a function name that is ambiguous yields a menu through
205 # which users can select a specific function. This should not happen during
206 # completion, though.
207 test_gdb_complete "ambig" \
208 [multi_line "p ambiguous_func" \
210 test_gdb_complete "ambiguous_f" \
212 test_gdb_complete "ambiguous_func" \
215 # Perform a test intented to verify the behavior where the number
216 # of possible completions is very large. The goal is not to verify
217 # precisely the list returned by the complete command (this depends
218 # on too many parameters -- targets, compiler version, runtime, etc).
219 # However, we want to sanity-check each one of them, knowing that
220 # each result should start with "break ada" and that the proposed
221 # completion should look like a valid symbol name (in particular,
222 # no uppercase letters...). See gdb/22670. File names are OK as
223 # well, which is why "/" and "-" appear in the regexp.
225 gdb_test_no_output "set max-completions unlimited"
227 set test "complete break ada"
228 gdb_test_multiple "$test" $test {
229 -re "^$test$eol\(break ada\[\]\[a-z0-9._@/-\]*$eol\)+$gdb_prompt $" {
232 -re "\[A-Z\].*$gdb_prompt $" {
233 fail "$test (gdb/22670)"