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