Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.ada / complete.exp
1 # Copyright 2005-2022 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 if { [skip_ada_tests] } { return -1 }
19
20 standard_ada_testfile foo
21
22 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
23 return -1
24 }
25
26 clean_restart ${testfile}
27
28 set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
29 runto "foo.adb:$bp_location"
30
31 set eol "\[\r\n\]*"
32
33 # A convenience function that verifies that the "complete EXPR" command
34 # returns the EXPECTED_OUTPUT.
35
36 proc test_gdb_complete { expr expected_output {msg ""} } {
37 set cmd "complete p $expr"
38 if {$msg == ""} {
39 set msg $cmd
40 }
41 gdb_test "complete p $expr" \
42 "$expected_output" $msg
43 }
44
45 # A convenience function that verifies that the "complete EXPR" command
46 # does not generate any output.
47
48 proc test_gdb_no_completion { expr } {
49 gdb_test_no_output "complete p $expr"
50 }
51
52 # Try a global variable, only one match should be found:
53
54 test_gdb_complete "my_glob" \
55 "p my_global_variable"
56
57 # A global variable, inside a nested package:
58
59 test_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
65 test_gdb_no_completion "inner.insi"
66
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"
71
72 # A fully qualified symbol name, mangled...
73 test_gdb_complete "pck__inner__ins" \
74 "p pck__inner__inside_variable"
75
76 # A fully qualified symbol name...
77 test_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"...
82 test_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.
86 test_gdb_no_completion "exported"
87
88 # check the "<...>" notation.
89 test_gdb_complete "<Exported" \
90 "p <Exported_Capitalized>"
91
92 # While at it, make sure we can print the symbol too, using the '<'
93 # notation.
94 gdb_test "p <Exported_Capitalized>" " = 2"
95
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."
101
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"
105
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>"
110
111 # A local variable
112 test_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.
117 test_gdb_no_completion "not_in_sco"
118
119 # A fully qualified variable name that doesn't exist...
120 test_gdb_no_completion "pck.ins"
121
122 # A fully qualified variable name that does exist...
123 test_gdb_complete "pck.my" \
124 "p pck.my_global_variable"
125
126 # A fully qualified package name
127 test_gdb_complete "pck.inne" \
128 "p pck.inner.inside_variable" \
129 "complete fully qualified package name"
130
131 # A fully qualified package name, with a dot at the end
132 test_gdb_complete "pck.inner." \
133 "p pck.inner.inside_variable"
134
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" ]
139
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" ]
144
145 # Two matches, from the global scope, but using mangled fully qualified
146 # names:
147 test_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:
152 test_gdb_complete "external_ident" \
153 [multi_line "p external_identical_one" \
154 "p external_identical_two" ]
155
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" \
166 "p pck.proc" ]
167
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" \
178 "p pck.proc" ]
179
180 # Complete a mangled symbol name, but using the '<...>' notation.
181 test_gdb_complete "<pck__my" \
182 "p <pck__my_global_variable>"
183
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.
188
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 $" {
194 send_gdb "\n"
195 gdb_test_multiple "" "$test" {
196 -re " = 1$eol$gdb_prompt $" {
197 pass "$test"
198 }
199 }
200 }
201 }
202 }
203
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" \
209 "p ambiguous_proc" ]
210 test_gdb_complete "ambiguous_f" \
211 "p ambiguous_func"
212 test_gdb_complete "ambiguous_func" \
213 "p ambiguous_func"
214
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.
224
225 gdb_test_no_output "set max-completions unlimited"
226
227 set test "complete break ada"
228 gdb_test_multiple "$test" $test {
229 -re "^$test$eol\(break ada\[-a-z0-9._@/\]*$eol\)+$gdb_prompt $" {
230 pass $test
231 }
232 -re "\[A-Z\].*$gdb_prompt $" {
233 fail "$test (gdb/22670)"
234 }
235 }
This page took 0.035452 seconds and 4 git commands to generate.