Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching]
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.linespec / cpcompletion.exp
1 # Copyright 2017 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 # This file is part of the gdb testsuite.
17
18 load_lib completion-support.exp
19
20 standard_testfile cpls.cc cpls2.cc cpls-hyphen.cc
21
22 if {[prepare_for_testing "failed to prepare" $testfile \
23 [list $srcfile $srcfile2 $srcfile3] {debug}]} {
24 return -1
25 }
26
27 # Disable the completion limit for the whole testcase.
28 gdb_test_no_output "set max-completions unlimited"
29
30 # Start of tests.
31
32 # Test completion of all parameter prefixes, crossing "(" and ")",
33 # with and without whitespace.
34
35 proc_with_prefix all-param-prefixes {} {
36
37 # Test both linespecs and explicit locations.
38 foreach cmd_prefix {"b" "b -function"} {
39 set line "$cmd_prefix param_prefixes_test_long(long)"
40 set start [index_after "test_long" $line]
41 test_complete_prefix_range $line $start
42
43 # Same, but with extra spaces. Note that the original spaces in
44 # the input line are preserved after completion.
45 test_gdb_complete_unique \
46 "$cmd_prefix param_prefixes_test_long(long " \
47 "$cmd_prefix param_prefixes_test_long(long )"
48 test_gdb_complete_unique \
49 "$cmd_prefix param_prefixes_test_long( long " \
50 "$cmd_prefix param_prefixes_test_long( long )"
51 test_gdb_complete_unique \
52 "$cmd_prefix param_prefixes_test_long ( long " \
53 "$cmd_prefix param_prefixes_test_long ( long )"
54
55 # Complete all parameter prefixes between "(i" and "(int*, int&)".
56 # Note that this exercises completing when the point is at the
57 # space in "param_prefixes_test_intp_intr(int*, ".
58 set line "$cmd_prefix param_prefixes_test_intp_intr(int*, int&)"
59 set start [index_after "intp_intr" $line]
60 test_complete_prefix_range $line $start
61
62 # Similar, but with extra spaces.
63 test_gdb_complete_unique \
64 "$cmd_prefix param_prefixes_test_intp_intr ( int* " \
65 "$cmd_prefix param_prefixes_test_intp_intr ( int* , int&)"
66
67 test_gdb_complete_unique \
68 "$cmd_prefix param_prefixes_test_intp_intr ( int *" \
69 "$cmd_prefix param_prefixes_test_intp_intr ( int *, int&)"
70
71 test_gdb_complete_unique \
72 "$cmd_prefix param_prefixes_test_intp_intr ( int *, int " \
73 "$cmd_prefix param_prefixes_test_intp_intr ( int *, int &)"
74
75 test_gdb_complete_unique \
76 "$cmd_prefix param_prefixes_test_intp_intr ( int *, int & " \
77 "$cmd_prefix param_prefixes_test_intp_intr ( int *, int & )"
78 }
79 }
80
81 # Test completion of an overloaded function.
82
83 proc_with_prefix overload {} {
84 set completion_list {
85 "overload_ambiguous_test(int, int)"
86 "overload_ambiguous_test(int, long)"
87 "overload_ambiguous_test(long)"
88 }
89
90 foreach cmd_prefix {"b" "b -function"} {
91 test_gdb_complete_multiple \
92 "$cmd_prefix " "overload_ambiguous_" "test(" \
93 $completion_list
94 check_bp_locations_match_list \
95 "$cmd_prefix overload_ambiguous_test" \
96 $completion_list
97
98 # Test disambiguating by typing enough to pick the "int" as
99 # first parameter type. This then tests handling ambiguity in
100 # the second parameter, which checks that tab completion when
101 # the point is at the whitespace behaves naturally, by showing
102 # the remaining matching overloads to the user.
103 test_gdb_complete_multiple \
104 "$cmd_prefix " "overload_ambiguous_test(i" "nt, " {
105 "overload_ambiguous_test(int, int)"
106 "overload_ambiguous_test(int, long)"
107 }
108
109 # Add a few more characters to make the completion
110 # unambiguous.
111 test_gdb_complete_unique \
112 "$cmd_prefix overload_ambiguous_test(int, i" \
113 "$cmd_prefix overload_ambiguous_test(int, int)"
114 check_bp_locations_match_list \
115 "$cmd_prefix overload_ambiguous_test(int, int)" {
116 "overload_ambiguous_test(int, int)"
117 }
118 }
119 }
120
121 # Test completion of a function that is defined in different scopes
122 # with different parameters.
123
124 proc_with_prefix overload-2 {} {
125 with_test_prefix "all" {
126 set completion_list {
127 "(anonymous namespace)::overload2_function(overload2_arg3)"
128 "(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg4)"
129 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
130 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::struct_overload2_test::overload2_function(overload2_arga)"
131 "ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
132 "ns_overload2_test::(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg8)"
133 "ns_overload2_test::overload2_function(overload2_arg5)"
134 "ns_overload2_test::struct_overload2_test::overload2_function(overload2_arg6)"
135 "overload2_function(overload2_arg1)"
136 "struct_overload2_test::overload2_function(overload2_arg2)"
137 }
138 foreach cmd_prefix {"b" "b -function"} {
139 test_gdb_complete_multiple \
140 "$cmd_prefix " "overload2_func" "tion(overload2_arg" $completion_list
141 check_bp_locations_match_list \
142 "$cmd_prefix overload2_function" $completion_list
143 }
144 }
145
146 # Same, but restrict to functions/methods in some scope.
147 with_test_prefix "restrict scope" {
148 set completion_list {
149 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
150 "ns_overload2_test::overload2_function(overload2_arg5)"
151 }
152 foreach cmd_prefix {"b" "b -function"} {
153 test_gdb_complete_multiple \
154 "$cmd_prefix " "ns_overload2_test::overload2_func" "tion(overload2_arg" $completion_list
155 check_bp_locations_match_list \
156 "$cmd_prefix ns_overload2_test::overload2_function" $completion_list
157 }
158 }
159
160 # Restrict to anonymous namespace scopes.
161 with_test_prefix "restrict scope 2" {
162 set completion_list {
163 "(anonymous namespace)::overload2_function(overload2_arg3)"
164 "ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
165 }
166 foreach cmd_prefix {"b" "b -function"} {
167 test_gdb_complete_multiple \
168 "$cmd_prefix " "(anonymous namespace)::overload2_func" "tion(overload2_arg" $completion_list
169 check_bp_locations_match_list \
170 "$cmd_prefix (anonymous namespace)::overload2_function" $completion_list
171 }
172 }
173
174 # Add enough scopes, and we get a unique completion.
175 with_test_prefix "unique completion" {
176 foreach cmd_prefix {"b" "b -function"} {
177 test_gdb_complete_unique \
178 "$cmd_prefix ns_overload2_test::(anonymous namespace)::overload2_func" \
179 "$cmd_prefix ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
180 check_setting_bp_fails "$cmd_prefix ns_overload2_test::(anonymous namespace)::overload2_func"
181 check_bp_locations_match_list \
182 "$cmd_prefix ns_overload2_test::(anonymous namespace)::overload2_function" \
183 {"ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"}
184 }
185 }
186 }
187
188 # Test linespecs / locations using fully-qualified names.
189
190 proc_with_prefix fqn {} {
191
192 # "-qualified" works with both explicit locations and linespecs.
193 # Also test that combining a source file with a function name
194 # still results in a full match, with both linespecs and explicit
195 # locations.
196 foreach cmd_prefix {
197 "b -qualified "
198 "b -qualified -function "
199 "b -qualified cpls.cc:"
200 "b -qualified -source cpls.cc -function "
201 "b -source cpls.cc -qualified -function "
202 } {
203 test_gdb_complete_unique \
204 "${cmd_prefix}overload2_func" \
205 "${cmd_prefix}overload2_function(overload2_arg1)"
206
207 # Drill down until we find a unique completion.
208 test_gdb_complete_multiple "${cmd_prefix}" "ns_overload2_test::" "" {
209 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
210 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::struct_overload2_test::overload2_function(overload2_arga)"
211 "ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
212 "ns_overload2_test::(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg8)"
213 "ns_overload2_test::overload2_function(overload2_arg5)"
214 "ns_overload2_test::struct_overload2_test::overload2_function(overload2_arg6)"
215 }
216
217 test_gdb_complete_multiple "${cmd_prefix}" "ns_overload2_test::(anonymous namespace)::" "" {
218 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
219 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::struct_overload2_test::overload2_function(overload2_arga)"
220 "ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
221 "ns_overload2_test::(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg8)"
222 }
223
224 test_gdb_complete_multiple "${cmd_prefix}" "ns_overload2_test::(anonymous namespace)::ns_overload2_test::" "" {
225 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
226 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::struct_overload2_test::overload2_function(overload2_arga)"
227 }
228
229 test_gdb_complete_unique \
230 "${cmd_prefix}ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_func" \
231 "${cmd_prefix}ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
232
233 }
234 }
235
236 # Check that a fully-qualified lookup name doesn't match symbols in
237 # nested scopes.
238
239 proc_with_prefix fqn-2 {} {
240 set linespec "struct_overload2_test::overload2_function(overload2_arg6)"
241 set cmd_prefix "b -qualified"
242 check_setting_bp_fails "$cmd_prefix $linespec"
243 test_gdb_complete_none "$cmd_prefix $linespec"
244
245 # Check that using the same name, but not fully-qualifying it,
246 # would find something, just to make sure the test above is
247 # testing what we intend to test.
248 set cmd_prefix "b -function"
249 test_gdb_complete_unique "$cmd_prefix $linespec" "$cmd_prefix $linespec"
250 check_bp_locations_match_list \
251 "$cmd_prefix $linespec" \
252 {"ns_overload2_test::struct_overload2_test::overload2_function(overload2_arg6)"}
253 }
254
255 # Test completion of functions in different scopes that have the same
256 # name and parameters. Restricting the scopes should find fewer and
257 # fewer matches.
258
259 proc_with_prefix overload-3 {} {
260 with_test_prefix "all overloads" {
261 set completion_list {
262 "(anonymous namespace)::overload3_function(int)"
263 "(anonymous namespace)::overload3_function(long)"
264 "(anonymous namespace)::struct_overload3_test::overload3_function(int)"
265 "(anonymous namespace)::struct_overload3_test::overload3_function(long)"
266 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::overload3_function(int)"
267 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::overload3_function(long)"
268 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(int)"
269 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(long)"
270 "ns_overload3_test::(anonymous namespace)::overload3_function(int)"
271 "ns_overload3_test::(anonymous namespace)::overload3_function(long)"
272 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(int)"
273 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(long)"
274 "ns_overload3_test::overload3_function(int)"
275 "ns_overload3_test::overload3_function(long)"
276 "ns_overload3_test::struct_overload3_test::overload3_function(int)"
277 "ns_overload3_test::struct_overload3_test::overload3_function(long)"
278 "overload3_function(int)"
279 "overload3_function(long)"
280 "struct_overload3_test::overload3_function(int)"
281 "struct_overload3_test::overload3_function(long)"
282 }
283 foreach cmd_prefix {"b" "b -function"} {
284 test_gdb_complete_multiple "$cmd_prefix " "overload3_func" "tion(" $completion_list
285 check_bp_locations_match_list "$cmd_prefix overload3_function" $completion_list
286 }
287 }
288
289 with_test_prefix "restrict overload" {
290 foreach cmd_prefix {"b" "b -function"} {
291 test_gdb_complete_unique \
292 "$cmd_prefix overload3_function(int)" \
293 "$cmd_prefix overload3_function(int)"
294 check_bp_locations_match_list "$cmd_prefix overload3_function(int)" {
295 "(anonymous namespace)::overload3_function(int)"
296 "(anonymous namespace)::struct_overload3_test::overload3_function(int)"
297 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::overload3_function(int)"
298 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(int)"
299 "ns_overload3_test::(anonymous namespace)::overload3_function(int)"
300 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(int)"
301 "ns_overload3_test::overload3_function(int)"
302 "ns_overload3_test::struct_overload3_test::overload3_function(int)"
303 "overload3_function(int)"
304 "struct_overload3_test::overload3_function(int)"
305 }
306 }
307 }
308
309 with_test_prefix "restrict scope" {
310 set completion_list {
311 "(anonymous namespace)::struct_overload3_test::overload3_function(int)"
312 "(anonymous namespace)::struct_overload3_test::overload3_function(long)"
313 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(int)"
314 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(long)"
315 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(int)"
316 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(long)"
317 "ns_overload3_test::struct_overload3_test::overload3_function(int)"
318 "ns_overload3_test::struct_overload3_test::overload3_function(long)"
319 "struct_overload3_test::overload3_function(int)"
320 "struct_overload3_test::overload3_function(long)"
321 }
322 foreach cmd_prefix {"b" "b -function"} {
323 test_gdb_complete_multiple \
324 "$cmd_prefix " "struct_overload3_test::overload3_func" "tion(" \
325 $completion_list
326 check_bp_locations_match_list \
327 "$cmd_prefix struct_overload3_test::overload3_function" \
328 $completion_list
329 }
330 }
331 }
332
333 # Test completing an overloaded template method.
334
335 proc_with_prefix template-overload {} {
336 set completion_list {
337 "template_struct<int>::template_overload_fn(int)"
338 "template_struct<long>::template_overload_fn(long)"
339 }
340 foreach cmd_prefix {"b" "b -function"} {
341 test_gdb_complete_multiple "$cmd_prefix " "template_overload_fn" "(" $completion_list
342 check_bp_locations_match_list "$cmd_prefix template_overload_fn" $completion_list
343 check_bp_locations_match_list \
344 "$cmd_prefix template_struct<int>::template_overload_fn" \
345 "template_struct<int>::template_overload_fn(int)"
346 }
347 }
348
349 # Test completing template methods with non-void return type.
350
351 proc_with_prefix template-ret-type {} {
352 set method_name "template2_fn<int, int>"
353 set param_list "(template2_ret_type<int>, int, int)"
354 set struct_type "template2_struct<template2_ret_type<int> >"
355 set ret_type "template2_ret_type<int>"
356
357 # Templates are listed both with and without return type, making
358 # "template2_<tab>" ambiguous.
359 foreach cmd_prefix {"b" "b -function"} {
360 set completion_list \
361 [list \
362 "${ret_type} ${struct_type}::${method_name}${param_list}" \
363 "${struct_type}::${method_name}${param_list}"]
364 test_gdb_complete_multiple "$cmd_prefix " "template2_" "" $completion_list
365
366 # Add one character more after "2_", and the linespec becomes
367 # unambiguous. Test completing the whole prefix range after that,
368 # thus testing completing either with or without return type.
369 foreach {s t} [list \
370 "template2_r" \
371 "${ret_type} ${struct_type}::${method_name}${param_list}" \
372 "template2_s" \
373 "${struct_type}::${method_name}${param_list}"] {
374 set linespec $t
375 set complete_line "$cmd_prefix $linespec"
376 set start [index_after $s $complete_line]
377 test_complete_prefix_range $complete_line $start
378 }
379
380 # Setting a breakpoint without the template params doesn't work.
381 check_setting_bp_fails "$cmd_prefix template2_fn"
382 # However, setting a breakpoint with template params and without
383 # the method params does work, just like with non-template
384 # functions. It also works with or without return type.
385 foreach linespec [list \
386 "${method_name}" \
387 "${method_name}${param_list}" \
388 "${struct_type}::${method_name}" \
389 "${struct_type}::${method_name}${param_list}" \
390 "${ret_type} ${struct_type}::${method_name}" \
391 "${ret_type} ${struct_type}::${method_name}${param_list}"] {
392 check_bp_locations_match_list \
393 "$cmd_prefix $linespec" \
394 [list "${struct_type}::${method_name}${param_list}"]
395 }
396 }
397 }
398
399 # Test completion of a const-overloaded funtion (const-overload).
400 # Note that "const" appears after the function/method parameters.
401
402 proc_with_prefix const-overload {} {
403 set completion_list {
404 "struct_with_const_overload::const_overload_fn()"
405 "struct_with_const_overload::const_overload_fn() const"
406 }
407 foreach cmd_prefix {"b" "b -function"} {
408 test_gdb_complete_multiple \
409 "$cmd_prefix " "const_overload_fn" "()" \
410 $completion_list
411 test_gdb_complete_multiple \
412 "$cmd_prefix " "const_overload_fn ( " ")" \
413 $completion_list
414 test_gdb_complete_multiple \
415 "$cmd_prefix " "const_overload_fn()" "" \
416 $completion_list
417
418 check_bp_locations_match_list \
419 "$cmd_prefix const_overload_fn" \
420 {"struct_with_const_overload::const_overload_fn()"
421 "struct_with_const_overload::const_overload_fn() const"}
422
423 check_setting_bp_fails "$cmd_prefix const_overload_fn("
424 check_bp_locations_match_list \
425 "$cmd_prefix const_overload_fn()" \
426 {"struct_with_const_overload::const_overload_fn()"}
427 check_bp_locations_match_list \
428 "$cmd_prefix const_overload_fn() const" \
429 {"struct_with_const_overload::const_overload_fn() const"}
430 }
431 }
432
433 # Same but quote-enclose the function name. This makes the overload
434 # no longer be ambiguous.
435
436 proc_with_prefix const-overload-quoted {} {
437 foreach cmd_prefix {"b" "b -function"} {
438 set linespec "'const_overload_fn()'"
439 test_gdb_complete_unique "$cmd_prefix $linespec" "$cmd_prefix $linespec"
440 check_bp_locations_match_list \
441 "$cmd_prefix $linespec" {
442 "struct_with_const_overload::const_overload_fn()"
443 }
444
445 set linespec "'const_overload_fn() const'"
446 test_gdb_complete_unique "$cmd_prefix $linespec" "$cmd_prefix $linespec"
447 check_bp_locations_match_list \
448 "$cmd_prefix $linespec" {
449 "struct_with_const_overload::const_overload_fn() const"
450 }
451 }
452 }
453
454 # Test that when the function is unambiguous, linespec completion
455 # appends the end quote char automatically, both ' and ".
456
457 proc_with_prefix append-end-quote-char-when-unambiguous {} {
458 foreach cmd_prefix {"b" "b -function"} {
459 foreach qc $completion::all_quotes_list {
460 set linespec "${qc}not_overloaded_fn()${qc}"
461 foreach cmd [list "$cmd_prefix ${qc}not_overloaded_fn()" \
462 "$cmd_prefix ${qc}not_overloaded_fn" \
463 "$cmd_prefix ${qc}not_overloaded_"] {
464 test_gdb_complete_unique $cmd "$cmd_prefix $linespec"
465 }
466 check_bp_locations_match_list \
467 "$cmd_prefix $linespec" {"not_overloaded_fn()"}
468 }
469 }
470 }
471
472 # Test completing symbols of source files.
473
474 proc_with_prefix in-source-file-unconstrained {} {
475 # First test that unconstrained matching picks up functions from
476 # multiple files.
477 test_gdb_complete_multiple "b " "file_constrained_test" "_cpls" {
478 "file_constrained_test_cpls2_function(int)"
479 "file_constrained_test_cpls_function(int)"
480 }
481 check_setting_bp_fails "b file_constrained_test_cpls"
482 }
483
484 # Test an unambiguous completion that would be ambiguous if it weren't
485 # for the source file component, due to
486 # "file_constrained_test_cpls_function" in cpls.cc. Test with
487 # different components quoted, and with whitespace before the function
488 # name.
489
490 proc_with_prefix in-source-file-unambiguous {} {
491 foreach sqc $completion::maybe_quoted_list {
492 foreach fqc $completion::maybe_quoted_list {
493 # Linespec.
494 foreach sep {":" ": "} {
495 set linespec \
496 "${sqc}cpls2.cc${sqc}${sep}${fqc}file_constrained_test_cpls2_function(int)${fqc}"
497 set complete_line "b $linespec"
498 set start [index_after "constrained_test" $complete_line]
499 set input_line [string range $complete_line 0 $start]
500 test_gdb_complete_unique $input_line ${complete_line}
501 check_bp_locations_match_list "b $linespec" {
502 "file_constrained_test_cpls2_function(int)"
503 }
504 }
505
506 # Explicit location.
507 set source_opt "-source ${sqc}cpls2.cc${sqc}"
508 set function_opt "-function ${fqc}file_constrained_test_cpls2_function(int)${fqc}"
509 set complete_line "b $source_opt $function_opt"
510 set start [index_after "cpls2_functio" $complete_line]
511 set input_line [string range $complete_line 0 $start]
512 test_gdb_complete_unique $input_line ${complete_line}
513 check_bp_locations_match_list "$complete_line" {
514 "file_constrained_test_cpls2_function(int)"
515 }
516 }
517 }
518 }
519
520 # Test an ambiguous completion constrained by a source file. Test
521 # with different components quoted, and with whitespace before the
522 # function name.
523
524 proc_with_prefix in-source-file-ambiguous {} {
525 foreach sqc $completion::maybe_quoted_list {
526 foreach fqc $completion::maybe_quoted_list {
527 # Linespec.
528 foreach sep {":" ": "} {
529 set cmd_prefix "b ${sqc}cpls2.cc${sqc}${sep}"
530 test_gdb_complete_multiple "${cmd_prefix}" ${fqc} "" {
531 "another_file_constrained_test_cpls2_function(int)"
532 "file_constrained_test_cpls2_function(int)"
533 } ${fqc} ${fqc}
534 }
535
536 # Explicit location.
537 test_gdb_complete_multiple \
538 "b -source ${sqc}cpls2.cc${sqc} -function " ${fqc} "" {
539 "another_file_constrained_test_cpls2_function(int)"
540 "file_constrained_test_cpls2_function(int)"
541 } ${fqc} ${fqc}
542 }
543 }
544 }
545
546 # Check that completing a file name in a linespec auto-appends a colon
547 # instead of a whitespace character.
548
549 proc_with_prefix source-complete-appends-colon {} {
550 # Test with quotes to make sure the end quote char is put at the
551 # right place.
552 foreach qc $completion::maybe_quoted_list {
553 test_gdb_complete_unique \
554 "b ${qc}cpls2." \
555 "b ${qc}cpls2.cc${qc}" ":"
556 test_gdb_complete_unique \
557 "b ${qc}cpls2.c" \
558 "b ${qc}cpls2.cc${qc}" ":"
559 test_gdb_complete_unique \
560 "b ${qc}cpls2.cc" \
561 "b ${qc}cpls2.cc${qc}" ":"
562
563 # Same, but with a filename with an hyphen (which is normally
564 # a language word break char).
565 test_gdb_complete_unique \
566 "b ${qc}cpls-" \
567 "b ${qc}cpls-hyphen.cc${qc}" ":"
568 test_gdb_complete_unique \
569 "b ${qc}cpls-hyphen" \
570 "b ${qc}cpls-hyphen.cc${qc}" ":"
571 }
572
573 # Test the same, but with the name of a nonexisting file.
574
575 # Cursor at the end of the string.
576 test_gdb_complete_none "b nonexistingfilename.cc"
577 # Cursor past the end of the string.
578 test_gdb_complete_multiple "b nonexistingfilename.cc " "" "" \
579 $completion::keyword_list
580 foreach qc $completion::all_quotes_list {
581 # Unterminated quote.
582 test_gdb_complete_none "b ${qc}nonexistingfilename.cc"
583 test_gdb_complete_none "b ${qc}nonexistingfilename.cc "
584 # Terminated quote, cursor at the quote.
585 test_gdb_complete_unique \
586 "b ${qc}nonexistingfilename.cc${qc}" \
587 "b ${qc}nonexistingfilename.cc${qc}"
588 # Terminated quote, cursor past the quote.
589 test_gdb_complete_multiple \
590 "b ${qc}nonexistingfilename.cc${qc} " "" "" \
591 $completion::keyword_list
592 }
593 }
594
595 ####################################################################
596
597 # Test that a colon at the end of the linespec is understood as an
598 # incomplete scope operator (incomplete-scope-colon), instead of a
599 # source/function separator.
600
601 proc_with_prefix incomplete-scope-colon {} {
602
603 # Helper for the loop below to simplify it. Tests completion of
604 # the range defined by the RANGE_SS found in the constructed line.
605 #
606 # E.g., with:
607 #
608 # source="source.cc"
609 # fqc="'"
610 # prototype="ns::function()"
611 # range_ss="s::f"
612 #
613 # we'd try completing with the cursor set in each of the
614 # underlined range's positions of:
615 #
616 # b source.cc:'ns::function()'"
617 # ^^^^
618 #
619 # Also test that setting a breakpoint at the constructed line
620 # finds the same breakpoint location as completion does.
621 #
622 proc incomplete_scope_colon_helper {prototype range_ss {skip_check_bp 0}} {
623 foreach source {"" "cpls.cc"} {
624 # Test with and without source quoting.
625 foreach sqc $completion::maybe_quoted_list {
626 if {$source == "" && $sqc != ""} {
627 # Invalid combination.
628 continue
629 }
630
631 # Test with and without function quoting.
632 foreach fqc $completion::maybe_quoted_list {
633 if {$source == ""} {
634 set linespec_source ""
635 set explicit_source ""
636 } else {
637 set linespec_source "${sqc}${source}${sqc}:"
638 set explicit_source "-source ${sqc}${source}${sqc}"
639 }
640
641 # Even though this use case is trickier with
642 # linespecs due to the ":" as separator, test both
643 # linespecs and explicit locations for
644 # completeness.
645 foreach location [list \
646 "${linespec_source}${fqc}$prototype${fqc}" \
647 "${explicit_source} -function ${fqc}$prototype${fqc}"] {
648 set complete_line "b $location"
649 set start [string first $range_ss $complete_line]
650 set end [expr ($start + [string length $range_ss])]
651 test_complete_prefix_range $complete_line $start $end
652 if {!$skip_check_bp} {
653 check_bp_locations_match_list "b $location" [list "$prototype"]
654 }
655 }
656 }
657 }
658 }
659 }
660
661 incomplete_scope_colon_helper \
662 "struct_incomplete_scope_colon_test::incomplete_scope_colon_test()" \
663 "t::i"
664
665 incomplete_scope_colon_helper \
666 "ns_incomplete_scope_colon_test::incomplete_scope_colon_test()" \
667 "t::i"
668
669 # Test completing around both "::"s.
670 foreach range_ss {"t::s" "t::i"} skip_check_bp {0 1} {
671 incomplete_scope_colon_helper \
672 "ns2_incomplete_scope_colon_test::struct_in_ns2_incomplete_scope_colon_test::incomplete_scope_colon_test()" \
673 $range_ss $skip_check_bp
674 }
675 }
676
677 # Test completing functions/methods in anonymous namespaces.
678
679 proc_with_prefix anon-ns {} {
680 foreach cmd_prefix {"b" "b -function"} {
681 foreach qc $completion::maybe_quoted_list {
682 test_gdb_complete_unique \
683 "$cmd_prefix ${qc}anon_ns_function" \
684 "$cmd_prefix ${qc}anon_ns_function()${qc}"
685 check_bp_locations_match_list "$cmd_prefix ${qc}anon_ns_function()${qc}" {
686 "(anonymous namespace)::anon_ns_function()"
687 "(anonymous namespace)::anon_ns_struct::anon_ns_function()"
688 "the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_function()"
689 "the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_struct::anon_ns_function()"
690 }
691 }
692
693 # A "(" finds all anonymous namespace functions/methods in all
694 # scopes.
695 test_gdb_complete_multiple "$cmd_prefix " "(" "anonymous namespace)::" {
696 "(anonymous namespace)::anon_ns_function()"
697 "(anonymous namespace)::anon_ns_struct::anon_ns_function()"
698 "(anonymous namespace)::overload2_function(overload2_arg3)"
699 "(anonymous namespace)::overload3_function(int)"
700 "(anonymous namespace)::overload3_function(long)"
701 "(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg4)"
702 "(anonymous namespace)::struct_overload3_test::overload3_function(int)"
703 "(anonymous namespace)::struct_overload3_test::overload3_function(long)"
704 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
705 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::struct_overload2_test::overload2_function(overload2_arga)"
706 "ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
707 "ns_overload2_test::(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg8)"
708 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::overload3_function(int)"
709 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::overload3_function(long)"
710 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(int)"
711 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(long)"
712 "ns_overload3_test::(anonymous namespace)::overload3_function(int)"
713 "ns_overload3_test::(anonymous namespace)::overload3_function(long)"
714 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(int)"
715 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(long)"
716 "the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_function()"
717 "the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_struct::anon_ns_function()"
718 }
719
720 set function "the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_function()"
721 test_gdb_complete_unique "$cmd_prefix $function" "$cmd_prefix $function"
722 check_bp_locations_match_list "$cmd_prefix $function" [list $function]
723
724 # Test completing after the "(anonymous namespace)" part.
725 test_gdb_complete_unique \
726 "$cmd_prefix the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_fu" \
727 "$cmd_prefix $function"
728
729 # Test whitespace in the "(anonymous namespace)" component.
730
731 test_gdb_complete_unique \
732 "$cmd_prefix the_anon_ns_wrapper_ns::( anonymous namespace )::anon_ns_fu" \
733 "$cmd_prefix the_anon_ns_wrapper_ns::( anonymous namespace )::anon_ns_function()"
734 check_setting_bp_fails \
735 "$cmd_prefix the_anon_ns_wrapper_ns::( anonymous namespace )::anon_ns_fu"
736
737 set function_ws \
738 "the_anon_ns_wrapper_ns::( anonymous namespace )::anon_ns_function ( )"
739 test_gdb_complete_unique "$cmd_prefix $function_ws" "$cmd_prefix $function_ws"
740 check_bp_locations_match_list "$cmd_prefix $function_ws" [list $function]
741 }
742 }
743
744 # Basic test for completing "operator<". More extensive C++ operator
745 # tests in cpls-op.exp.
746
747 proc_with_prefix operator< {} {
748 # Complete all prefixes between "oper" and the whole prototype.
749 set function "operator<(foo_enum, foo_enum)"
750 foreach cmd_prefix {"b" "b -function"} {
751 set line "$cmd_prefix $function"
752 set start [index_after "oper" $line]
753 test_complete_prefix_range $line $start
754 }
755
756 # There's a label in the function; try completing it. (Exhaustive
757 # label completion tests further below.)
758 foreach location [list \
759 "$function:label1" \
760 "-function $function -label label1"] {
761
762 set cmd "b $location"
763 set input_line [string range $cmd 0 [expr [string length $cmd] - 3]]
764
765 test_gdb_complete_unique $input_line $cmd
766 test_gdb_complete_unique $cmd $cmd
767 check_bp_locations_match_list $cmd [list "$location"]
768 }
769 }
770
771 # Test completion of scopes with an ambiguous prefix.
772
773 proc_with_prefix ambiguous-prefix {} {
774 foreach cmd_prefix {"b" "b -function"} {
775 test_gdb_complete_multiple "$cmd_prefix " "ambiguous_pre" "fix_" {
776 "ambiguous_prefix_global_func()"
777 "the_ambiguous_prefix_ns::ambiguous_prefix_ns_func()"
778 "the_ambiguous_prefix_struct::ambiguous_prefix_method()"
779 }
780 check_setting_bp_fails "$cmd_prefix ambiguous_prefix_"
781 }
782 }
783
784 # Test completion of function labels.
785
786 proc_with_prefix function-labels {} {
787 # Test with and without a source file component.
788 foreach_location_functions \
789 { "" "cpls.cc" } \
790 { "function_with_labels(int)" } \
791 {
792 # Linespec version. Test various spacing around the label
793 # colon separator.
794 foreach label_sep {":" " :" ": " " : "} {
795 set linespec "${location}${label_sep}"
796 test_gdb_complete_multiple "b $linespec" "l" "abel" {
797 "label1"
798 "label2"
799 }
800 check_setting_bp_fails "b ${linespec}label"
801
802 set tsep [string trim ${source_sep}]
803 check_bp_locations_match_list \
804 "b ${linespec}label1" [list "${source}${tsep}${function}:label1"]
805 check_bp_locations_match_list \
806 "b ${linespec}label2" [list "${source}${tsep}${function}:label2"]
807 }
808 } \
809 {
810 # Explicit locations version.
811 append location " -label"
812 test_gdb_complete_multiple "b $location " "l" "abel" {
813 "label1"
814 "label2"
815 }
816 check_setting_bp_fails "b $location label"
817
818 if {$source != ""} {
819 set bp_loc_src "-source ${source} "
820 } else {
821 set bp_loc_src ""
822 }
823 check_bp_locations_match_list \
824 "b ${location} label1" [list "${bp_loc_src}-function $function -label label1"]
825 check_bp_locations_match_list \
826 "b ${location} label2" [list "${bp_loc_src}-function $function -label label2"]
827 }
828 }
829
830 # Test that completion after a function name offers keyword
831 # (if/task/thread) matches in linespec mode, and also the explicit
832 # location options in explicit locations mode.
833
834 proc_with_prefix keywords-after-function {} {
835 set explicit_list \
836 [concat $completion::explicit_opts_list $completion::keyword_list]
837
838 # Test without a source file, with a known source file, and with
839 # and unknown source file.
840 # Test a known and an unknown function.
841 foreach_location_functions \
842 { "" "cpls.cc" "unknown_file.cc" } \
843 { "function_with_labels(int)" "unknown_function(int)" } \
844 {
845 # Linespec version.
846 test_gdb_complete_multiple "b ${location} " "" "" \
847 $completion::keyword_list
848 } \
849 {
850 # Explicit locations version.
851 test_gdb_complete_multiple "b ${location} " "" "" \
852 $explicit_list
853 }
854 }
855
856 # Same, but after a label.
857
858 proc_with_prefix keywords-after-label {} {
859 set explicit_list \
860 [concat $completion::explicit_opts_list $completion::keyword_list]
861
862 foreach_location_labels \
863 { "" "cpls.cc" } \
864 { "function_with_labels(int)" "unknown_function(int)" } \
865 { "label1" "non_existing_label" } \
866 {
867 # Linespec version.
868 test_gdb_complete_multiple "b ${location} " "" "" \
869 $completion::keyword_list
870 } \
871 {
872 # Explicit locations version.
873 test_gdb_complete_multiple "b ${location} " "" "" \
874 $explicit_list
875 }
876 }
877
878 # Similar, but after an unknown file, and in linespec mode only.
879
880 proc_with_prefix keywords-after-unknown-file {} {
881 # Test with and without quoting.
882 foreach qc $completion::maybe_quoted_list {
883 set line "b ${qc}unknown_file.cc${qc}: "
884 test_gdb_complete_multiple $line "" "" $completion::keyword_list
885 }
886 }
887
888 # Test that linespec / function completion does not match data
889 # symbols, only functions/methods.
890
891 proc_with_prefix no-data-symbols {} {
892 foreach cmd_prefix {"b" "b -function"} {
893 test_gdb_complete_unique "$cmd_prefix code_" "$cmd_prefix code_function()"
894 }
895 }
896
897
898 # After "if", we expect an expression, which has a different completer
899 # that matches data symbols as well. Check that that works.
900
901 proc_with_prefix if-expression {} {
902 foreach cmd_prefix {"b" "b -function"} {
903 test_gdb_complete_multiple "$cmd_prefix function() if " "code_" "" {
904 "code_data"
905 "code_function()"
906 }
907
908 test_gdb_complete_unique \
909 "$cmd_prefix function() if code_data + another_da" \
910 "$cmd_prefix function() if code_data + another_data"
911
912 test_gdb_complete_unique \
913 "$cmd_prefix non_existing_function() if code_data + another_da" \
914 "$cmd_prefix non_existing_function() if code_data + another_data"
915
916 # FIXME: For now, thread and task also use the expression
917 # completer.
918 test_gdb_complete_unique \
919 "$cmd_prefix function() thread code_data + another_da" \
920 "$cmd_prefix function() thread code_data + another_data"
921 test_gdb_complete_unique \
922 "$cmd_prefix function() task code_data + another_da" \
923 "$cmd_prefix function() task code_data + another_data"
924 }
925 }
926
927 # The testcase driver. Calls all test procedures.
928
929 proc test_driver {} {
930 all-param-prefixes
931 overload
932 overload-2
933 fqn
934 fqn-2
935 overload-3
936 template-overload
937 template-ret-type
938 const-overload
939 const-overload-quoted
940 append-end-quote-char-when-unambiguous
941 in-source-file-unconstrained
942 in-source-file-unambiguous
943 in-source-file-ambiguous
944 source-complete-appends-colon
945 incomplete-scope-colon
946 anon-ns
947 operator<
948 ambiguous-prefix
949 function-labels
950 keywords-after-function
951 keywords-after-label
952 keywords-after-unknown-file
953 no-data-symbols
954 if-expression
955 }
956
957 test_driver
This page took 0.050935 seconds and 4 git commands to generate.