f2149daefec7c2b229efd9409721033947f612ec
[binutils-gdb.git] / gdb / testsuite / gdb.ada / complete.exp
1 # Copyright 2005-2020 Free Software Foundation, Inc.
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
16 load_lib "ada.exp"
17
18 standard_ada_testfile foo
19
20 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
21 return -1
22 }
23
24 clean_restart ${testfile}
25
26 set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
27 runto "foo.adb:$bp_location"
28
29 set eol "\[\r\n\]*"
30
31 # A convenience function that verifies that the "complete EXPR" command
32 # returns the EXPECTED_OUTPUT.
33
34 proc test_gdb_complete { expr expected_output {msg ""} } {
35 set cmd "complete p $expr"
36 if {$msg == ""} {
37 set msg $cmd
38 }
39 gdb_test "complete p $expr" \
40 "$expected_output" $msg
41 }
42
43 # A convenience function that verifies that the "complete EXPR" command
44 # does not generate any output.
45
46 proc test_gdb_no_completion { expr } {
47 gdb_test_no_output "complete p $expr"
48 }
49
50 # Try a global variable, only one match should be found:
51
52 test_gdb_complete "my_glob" \
53 "p my_global_variable"
54
55 # A global variable, inside a nested package:
56
57 test_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
63 test_gdb_no_completion "inner.insi"
64
65 # An incomplete nested package name, were lies a single symbol:
66 test_gdb_complete "pck.inne" \
67 "p pck.inner.inside_variable" \
68 "complete nested package name"
69
70 # A fully qualified symbol name, mangled...
71 test_gdb_complete "pck__inner__ins" \
72 "p pck__inner__inside_variable"
73
74 # A fully qualified symbol name...
75 test_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"...
80 test_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.
84 test_gdb_no_completion "exported"
85
86 # check the "<...>" notation.
87 test_gdb_complete "<Exported" \
88 "p <Exported_Capitalized>"
89
90 # While at it, make sure we can print the symbol too, using the '<'
91 # notation.
92 gdb_test "p <Exported_Capitalized>" " = 2"
93
94 # Confirm that we can't print the symbol without the '<' notation.
95 gdb_test "p Exported_Capitalized" \
96 "No definition of \"exported_capitalized\" in current context."
97 gdb_test "p exported_capitalized" \
98 "No definition of \"exported_capitalized\" in current context."
99
100 # A global symbol, created by the binder, that starts with __gnat...
101 test_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.
106 test_gdb_complete "<__gnat_ada_main_prog" \
107 "p <__gnat_ada_main_program_name>"
108
109 # A local variable
110 test_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.
115 test_gdb_no_completion "not_in_sco"
116
117 # A fully qualified variable name that doesn't exist...
118 test_gdb_no_completion "pck.ins"
119
120 # A fully qualified variable name that does exist...
121 test_gdb_complete "pck.my" \
122 "p pck.my_global_variable"
123
124 # A fully qualified package name
125 test_gdb_complete "pck.inne" \
126 "p pck.inner.inside_variable" \
127 "complete fully qualified package name"
128
129 # A fully qualified package name, with a dot at the end
130 test_gdb_complete "pck.inner." \
131 "p pck.inner.inside_variable"
132
133 # Two matches, from the global scope:
134 test_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:
139 test_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:
145 test_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:
150 test_gdb_complete "external_ident" \
151 [multi_line "p external_identical_one" \
152 "p external_identical_two" ]
153
154 # Complete on the name of package.
155 test_gdb_complete "pck" \
156 [multi_line "(p pck\\.ad\[sb\])?" \
157 "(p pck\\.ad\[sb\])?" \
158 "p pck.ambiguous_func" \
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:
167 test_gdb_complete "pck." \
168 [multi_line "(p pck\\.ad\[sb\])?" \
169 "(p pck\\.ad\[sb\])?" \
170 "p pck.ambiguous_func" \
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.
179 test_gdb_complete "<pck__my" \
180 "p <pck__my_global_variable>"
181
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.
186
187 if { [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 }
199 }
200 }
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.
205 test_gdb_complete "ambig" \
206 [multi_line "p ambiguous_func" \
207 "p ambiguous_proc" ]
208 test_gdb_complete "ambiguous_f" \
209 "p ambiguous_func"
210 test_gdb_complete "ambiguous_func" \
211 "p ambiguous_func"
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,
220 # no uppercase letters...). See gdb/22670. File names are OK as
221 # well, which is why "/" and "-" appear in the regexp.
222
223 gdb_test_no_output "set max-completions unlimited"
224
225 set test "complete break ada"
226 gdb_test_multiple "$test" $test {
227 -re "^$test$eol\(break ada\[-a-z0-9._@/\]*$eol\)+$gdb_prompt $" {
228 pass $test
229 }
230 -re "\[A-Z\].*$gdb_prompt $" {
231 fail "$test (gdb/22670)"
232 }
233 }