]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.ada/complete.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.ada / complete.exp
CommitLineData
1d506c26 1# Copyright 2005-2024 Free Software Foundation, Inc.
439048e8
JB
2#
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.
7#
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.
12#
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/>.
15
439048e8
JB
16load_lib "ada.exp"
17
74dcf082 18require allow_ada_tests
7a82e903 19
8223e12c 20standard_ada_testfile foo
439048e8 21
439048e8
JB
22if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
23 return -1
24}
25
09050809 26clean_restart ${testfile}
439048e8
JB
27
28set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
29runto "foo.adb:$bp_location"
30
e59d0ad9 31set eol "\r\n"
439048e8
JB
32
33# A convenience function that verifies that the "complete EXPR" command
34# returns the EXPECTED_OUTPUT.
35
ba3e70b0
KS
36proc test_gdb_complete { expr expected_output {msg ""} } {
37 set cmd "complete p $expr"
38 if {$msg == ""} {
39 set msg $cmd
40 }
439048e8 41 gdb_test "complete p $expr" \
ba3e70b0 42 "$expected_output" $msg
439048e8
JB
43}
44
45# A convenience function that verifies that the "complete EXPR" command
177aadc4 46# does not generate any output.
439048e8
JB
47
48proc test_gdb_no_completion { expr } {
177aadc4 49 gdb_test_no_output "complete p $expr"
439048e8
JB
50}
51
439048e8
JB
52# Try a global variable, only one match should be found:
53
54test_gdb_complete "my_glob" \
55 "p my_global_variable"
56
57# A global variable, inside a nested package:
58
59test_gdb_complete "insi" \
60 "p inside_variable"
61
62# A global variable inside a nested package, but only giving part of
63# the fully qualified name (top level package name missing):
64
65test_gdb_no_completion "inner.insi"
66
67# An incomplete nested package name, were lies a single symbol:
68test_gdb_complete "pck.inne" \
ba3e70b0
KS
69 "p pck.inner.inside_variable" \
70 "complete nested package name"
439048e8
JB
71
72# A fully qualified symbol name, mangled...
73test_gdb_complete "pck__inner__ins" \
74 "p pck__inner__inside_variable"
75
76# A fully qualified symbol name...
77test_gdb_complete "pck.inner.ins" \
78 "p pck.inner.inside_variable"
79
80# Make sure that "inside" is not returned as a possible completion
81# for "side"...
82test_gdb_no_completion "side"
83
84# Verify that "Exported_Capitalized" is not returned as a match for
85# "exported", since its symbol name contains capital letters.
86test_gdb_no_completion "exported"
87
88# check the "<...>" notation.
89test_gdb_complete "<Exported" \
90 "p <Exported_Capitalized>"
91
b5ec771e
PA
92# While at it, make sure we can print the symbol too, using the '<'
93# notation.
94gdb_test "p <Exported_Capitalized>" " = 2"
95
96# Confirm that we can't print the symbol without the '<' notation.
97gdb_test "p Exported_Capitalized" \
98 "No definition of \"exported_capitalized\" in current context."
99gdb_test "p exported_capitalized" \
100 "No definition of \"exported_capitalized\" in current context."
101
439048e8
JB
102# A global symbol, created by the binder, that starts with __gnat...
103test_gdb_complete "__gnat_ada_main_progra" \
104 "p __gnat_ada_main_program_name"
105
106# A global symbol, created by the binder, that starts with __gnat,
107# and using the '<' notation.
108test_gdb_complete "<__gnat_ada_main_prog" \
109 "p <__gnat_ada_main_program_name>"
110
111# A local variable
112test_gdb_complete "some" \
113 "p some_local_variable"
114
115# A local variable variable, but in a different procedure. No match
116# should be returned.
117test_gdb_no_completion "not_in_sco"
118
119# A fully qualified variable name that doesn't exist...
120test_gdb_no_completion "pck.ins"
121
122# A fully qualified variable name that does exist...
123test_gdb_complete "pck.my" \
124 "p pck.my_global_variable"
125
126# A fully qualified package name
127test_gdb_complete "pck.inne" \
ba3e70b0
KS
128 "p pck.inner.inside_variable" \
129 "complete fully qualified package name"
439048e8
JB
130
131# A fully qualified package name, with a dot at the end
132test_gdb_complete "pck.inner." \
133 "p pck.inner.inside_variable"
134
135# Two matches, from the global scope:
136test_gdb_complete "local_ident" \
137 [multi_line "p local_identical_one" \
138 "p local_identical_two" ]
139
140# Two matches, from the global scope, but using fully qualified names:
141test_gdb_complete "pck.local_ident" \
142 [multi_line "p pck.local_identical_one" \
143 "p pck.local_identical_two" ]
144
145# Two matches, from the global scope, but using mangled fully qualified
146# names:
147test_gdb_complete "pck__local_ident" \
148 [multi_line "p pck__local_identical_one" \
149 "p pck__local_identical_two" ]
150
151# Two matches, one from the global scope, the other from the local scope:
152test_gdb_complete "external_ident" \
153 [multi_line "p external_identical_one" \
154 "p external_identical_two" ]
155
156# Complete on the name of package.
157test_gdb_complete "pck" \
158 [multi_line "(p pck\\.ad\[sb\])?" \
159 "(p pck\\.ad\[sb\])?" \
dc5c8746 160 "p pck.ambiguous_func" \
439048e8
JB
161 "p pck.external_identical_one" \
162 "p pck.inner.inside_variable" \
d5acae9e 163 "p pck.internal_capitalized" \
439048e8
JB
164 "p pck.local_identical_one" \
165 "p pck.local_identical_two" \
166 "p pck.my_global_variable" \
167 "p pck.proc" ]
168
169# Complete on the name of a package followed by a dot:
170test_gdb_complete "pck." \
171 [multi_line "(p pck\\.ad\[sb\])?" \
172 "(p pck\\.ad\[sb\])?" \
dc5c8746 173 "p pck.ambiguous_func" \
439048e8
JB
174 "p pck.external_identical_one" \
175 "p pck.inner.inside_variable" \
d5acae9e 176 "p pck.internal_capitalized" \
439048e8
JB
177 "p pck.local_identical_one" \
178 "p pck.local_identical_two" \
179 "p pck.my_global_variable" \
180 "p pck.proc" ]
181
182# Complete a mangled symbol name, but using the '<...>' notation.
183test_gdb_complete "<pck__my" \
184 "p <pck__my_global_variable>"
185
b8fea896
JB
186# Very simple completion, but using the interactive form, this time.
187# The verification we are trying to make involves the event loop,
188# and using the "complete" command is not sufficient to reproduce
189# the original problem.
0d4d0e77
YQ
190
191if { [readline_is_used] } {
192 set test "interactive complete 'print some'"
193 send_gdb "print some\t"
194 gdb_test_multiple "" "$test" {
195 -re "^print some_local_variable $" {
196 send_gdb "\n"
197 gdb_test_multiple "" "$test" {
198 -re " = 1$eol$gdb_prompt $" {
199 pass "$test"
200 }
201 }
202 }
b8fea896
JB
203 }
204}
dc5c8746
PMR
205
206# Usually, parsing a function name that is ambiguous yields a menu through
207# which users can select a specific function. This should not happen during
208# completion, though.
209test_gdb_complete "ambig" \
210 [multi_line "p ambiguous_func" \
211 "p ambiguous_proc" ]
212test_gdb_complete "ambiguous_f" \
213 "p ambiguous_func"
214test_gdb_complete "ambiguous_func" \
215 "p ambiguous_func"
344420da
JB
216
217# Perform a test intented to verify the behavior where the number
218# of possible completions is very large. The goal is not to verify
219# precisely the list returned by the complete command (this depends
220# on too many parameters -- targets, compiler version, runtime, etc).
221# However, we want to sanity-check each one of them, knowing that
222# each result should start with "break ada" and that the proposed
223# completion should look like a valid symbol name (in particular,
f49055a5
TT
224# no uppercase letters...). See gdb/22670. File names are OK as
225# well, which is why "/" and "-" appear in the regexp.
344420da
JB
226
227gdb_test_no_output "set max-completions unlimited"
228
229set test "complete break ada"
e59d0ad9
AB
230gdb_test_multiple $test "" {
231 -re "^($test$eol)" {
232 exp_continue
344420da 233 }
e59d0ad9
AB
234
235 -re "^(break ada\[\]\[a-z0-9._@/-\]*$eol)" {
236 exp_continue
237 }
238
239 -re "^$gdb_prompt $" {
240 pass $gdb_test_name
241 }
242
344420da 243 -re "\[A-Z\].*$gdb_prompt $" {
e59d0ad9 244 fail "$gdb_test_name (gdb/22670)"
344420da
JB
245 }
246}