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