]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.linespec/cpcompletion.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.linespec / cpcompletion.exp
1 # Copyright 2017-2024 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 load_lib data-structures.exp
20
21 standard_testfile cpls.cc cpls2.cc cpls-hyphen.cc
22
23 set opts {}
24 lappend opts debug
25 lappend opts additional_flags=-std=c++11
26
27 if {[prepare_for_testing "failed to prepare" $testfile \
28 [list $srcfile $srcfile2 $srcfile3] $opts]} {
29 return -1
30 }
31
32 # Tests below are about tab-completion, which doesn't work if readline
33 # library isn't used. Check it first.
34
35 if { ![readline_is_used] } {
36 untested "no tab completion support without readline"
37 return -1
38 }
39
40 #
41 # Some convenience procedures for testing template parameter list
42 # completion.
43 #
44
45 # For the variable named ARGLISTVAR, which should be the name of an
46 # argument list in the calling frame, "consume" the top-most token.
47 # [See comments for makefoo for description of arglist format.]
48
49 proc consume {arglistvar} {
50 upvar $arglistvar arglist
51
52 # ARGLIST is a string -- simply strip off the first character.
53 set arglist [string range $arglist 1 end]
54 }
55
56 # Create a function template named NAME, using the given stack ID to grab
57 # NUM template parameters. The result is pushed back onto the
58 # stack. NUM may be "all," in which case we use the entire stack
59 # to create the function template, including function arguments.
60 # The resulting template function's arguments are taken from the test
61 # source code for the function "foo" and is not generalized.
62
63 proc maket {sid name {num 1}} {
64
65 # Set up a temporary stack of parameters. This will reverse
66 # the order in SID so that when they are popped again below,
67 # we get them in the correct order. This also takes into account
68 # how many levels of the result stack we want to consider.
69
70 set paramstack [::Stack::new]
71 if {[string equal $num "all"]} {
72 while {![stack empty $sid]} {
73 stack push $paramstack [stack pop $sid]
74 }
75 } else {
76 for {set i 0} {$i < $num} {incr i} {
77 stack push $paramstack [stack pop $sid]
78 }
79 }
80
81 # Construct the function template and push it back to the
82 # top of the stack given by SID.
83 set result ""
84 set first true
85 while {![stack empty $paramstack]} {
86 set top [stack pop $paramstack]
87 if {$first} {
88 set first false
89 } else {
90 append result ", "
91 }
92 append result $top
93 }
94
95 # Save argument list.
96 set args $result
97
98 # GDB outputs "> >" instead of ">>".
99 if {[string index $top end] == ">"} {
100 append result " "
101 }
102 set result "$name<$result>"
103 if {[string equal $num "all"]} {
104 append result "($args)"
105 }
106 stack push $sid $result
107 stack delete $paramstack
108 }
109
110 # Given the stack SID and the name of a variable of the desired template
111 # parameters, construct the actual template parameter and push it to the
112 # top of the stack.
113
114 proc makearg {sid arglistvar} {
115 upvar $arglistvar arglist
116
117 set c [string index $arglist 0]
118 consume arglist
119 switch $c {
120 A -
121 B {
122 makearg $sid arglist
123 makearg $sid arglist
124 maket $sid $c 2
125 }
126
127 a -
128 b -
129 c -
130 d {
131 makearg $sid arglist
132 maket $sid $c
133 }
134
135 i {
136 stack push $sid "int"
137 }
138
139 n {
140 # These are not templates.
141 set c [string index $arglist 0]
142 stack push $sid "n::n$c"
143 consume arglist
144 }
145
146 N {
147 set c [string index $arglist 0]
148 makearg $sid arglist
149 set top [stack pop $sid]
150 stack push $sid "n::N$top"
151 }
152
153 default { error "unhandled arglist identifier: '$c'" }
154 }
155 }
156
157 # Given ARGLIST, construct a class template for the type and return
158 # it as a string.
159
160 proc maketype {arglist} {
161 set s [Stack::new]
162 makearg $s arglist
163 set result [stack pop $s]
164 stack delete $s
165 return $result
166 }
167
168 # Returns a function template declaration for the function "foo" in the
169 # corresponding test source code. ARGLIST specifies the exact instantiation
170 # that is desired.
171 #
172 # Generically, this procedure returns a string of the form,
173 # "foo<parameter-list> (arg-list)", where ARGLIST describes the parameter(s).
174 #
175 # Valid specifiers for ARGLIST (must be kept in sync with source code):
176 #
177 # i: Creates an "int" type.
178 # a, b, c, d: Creates the struct template of the same name, taking a single
179 # template parameter.
180 # A, B: Creates the struct template of the same name, taking two template
181 # parameters.
182 # na, nb: Creates the non-template structs n::na and n::nb, respectively.
183 # NA, NB: Creates the struct templates n::NA and n::NB, respectively, which
184 # take two template parameters.
185 #
186 # Examples:
187 # makefoo i
188 # --> foo<int> (int)
189 # makefoo ii
190 # --> foo<int, int> (int, int)
191 # makefoo Aiabi
192 # --> foo<A<int, a<b<int> > > > (A<int, a<b<int> > >)
193 # makefoo NANAiaiNBbiabi
194 # --> foo<n::NA<n::NA<int, a<int> >, n::NB<b<int>, a<b<int> > > > >
195 # (n::NA<n::NA<int, a<int> >, n::NB<b<int>, a<b<int> > > >)
196
197 proc makefoo {arglist} {
198 set s [::Stack::new]
199 while {[string length $arglist] > 0} {
200 makearg $s arglist
201 }
202
203 maket $s "foo" all
204 set result [stack pop $s]
205 stack delete $s
206 return $result
207 }
208
209 # Test wrapper for a single "makefoo" unit test.
210
211 proc test_makefoo_1 {arglist expected} {
212 set exp "foo<$expected"
213 if {[string index $exp end] == ">"} {
214 append exp " "
215 }
216 append exp ">"
217 append exp "($expected)"
218
219 set calc [makefoo $arglist]
220 send_log "makefoo $arglist = $calc\n"
221 send_log "expecting: $exp\n"
222 if {[string equal $exp $calc]} {
223 pass "makefoo unit test: $arglist"
224 } else {
225 fail "makefoo unit test: $arglist"
226 }
227 }
228
229 # Test whether the procedure "makefoo" is functioning as expected.
230
231 proc test_makefoo {} {
232 test_makefoo_1 "i" "int"
233 test_makefoo_1 "ai" "a<int>"
234 test_makefoo_1 "aai" "a<a<int> >"
235 test_makefoo_1 "ii" "int, int"
236 test_makefoo_1 "aaibi" "a<a<int> >, b<int>"
237 test_makefoo_1 \
238 "ababiibababai" "a<b<a<b<int> > > >, int, b<a<b<a<b<a<int> > > > > >"
239 test_makefoo_1 "Aii" "A<int, int>"
240 test_makefoo_1 "ABaibibi" "A<B<a<int>, b<int> >, b<int> >"
241 test_makefoo_1 "na" "n::na"
242 test_makefoo_1 "nana" "n::na, n::na"
243 test_makefoo_1 "NAii" "n::NA<int, int>"
244 test_makefoo_1 "NANAiiNAii" "n::NA<n::NA<int, int>, n::NA<int, int> >"
245 }
246
247 #
248 # Tests start here.
249 #
250
251 # Disable the completion limit for the whole testcase.
252 gdb_test_no_output "set max-completions unlimited"
253
254 # Start of tests.
255
256 # Test completion of all parameter prefixes, crossing "(" and ")",
257 # with and without whitespace.
258
259 proc_with_prefix all-param-prefixes {} {
260
261 # Test both linespecs and explicit locations.
262 foreach cmd_prefix {"b" "b -function"} {
263 set line "$cmd_prefix param_prefixes_test_long(long)"
264 set start [index_after "test_long" $line]
265 test_complete_prefix_range $line $start
266
267 # Same, but with extra spaces. Note that the original spaces in
268 # the input line are preserved after completion.
269 test_gdb_complete_unique \
270 "$cmd_prefix param_prefixes_test_long(long " \
271 "$cmd_prefix param_prefixes_test_long(long )"
272 test_gdb_complete_unique \
273 "$cmd_prefix param_prefixes_test_long( long " \
274 "$cmd_prefix param_prefixes_test_long( long )"
275 test_gdb_complete_unique \
276 "$cmd_prefix param_prefixes_test_long ( long " \
277 "$cmd_prefix param_prefixes_test_long ( long )"
278
279 # Complete all parameter prefixes between "(i" and "(int*, int&)".
280 # Note that this exercises completing when the point is at the
281 # space in "param_prefixes_test_intp_intr(int*, ".
282 set line "$cmd_prefix param_prefixes_test_intp_intr(int*, int&)"
283 set start [index_after "intp_intr" $line]
284 test_complete_prefix_range $line $start
285
286 # Similar, but with extra spaces.
287 test_gdb_complete_unique \
288 "$cmd_prefix param_prefixes_test_intp_intr ( int* " \
289 "$cmd_prefix param_prefixes_test_intp_intr ( int* , int&)"
290
291 test_gdb_complete_unique \
292 "$cmd_prefix param_prefixes_test_intp_intr ( int *" \
293 "$cmd_prefix param_prefixes_test_intp_intr ( int *, int&)"
294
295 test_gdb_complete_unique \
296 "$cmd_prefix param_prefixes_test_intp_intr ( int *, int " \
297 "$cmd_prefix param_prefixes_test_intp_intr ( int *, int &)"
298
299 test_gdb_complete_unique \
300 "$cmd_prefix param_prefixes_test_intp_intr ( int *, int & " \
301 "$cmd_prefix param_prefixes_test_intp_intr ( int *, int & )"
302 }
303 }
304
305 # Test completion of an overloaded function.
306
307 proc_with_prefix overload {} {
308 set completion_list {
309 "overload_ambiguous_test(int, int)"
310 "overload_ambiguous_test(int, long)"
311 "overload_ambiguous_test(long)"
312 }
313
314 foreach cmd_prefix {"b" "b -function"} {
315 test_gdb_complete_multiple \
316 "$cmd_prefix " "overload_ambiguous_" "test(" \
317 $completion_list
318 check_bp_locations_match_list \
319 "$cmd_prefix overload_ambiguous_test" \
320 $completion_list
321
322 # Test disambiguating by typing enough to pick the "int" as
323 # first parameter type. This then tests handling ambiguity in
324 # the second parameter, which checks that tab completion when
325 # the point is at the whitespace behaves naturally, by showing
326 # the remaining matching overloads to the user.
327 test_gdb_complete_multiple \
328 "$cmd_prefix " "overload_ambiguous_test(i" "nt, " {
329 "overload_ambiguous_test(int, int)"
330 "overload_ambiguous_test(int, long)"
331 }
332
333 # Add a few more characters to make the completion
334 # unambiguous.
335 test_gdb_complete_unique \
336 "$cmd_prefix overload_ambiguous_test(int, i" \
337 "$cmd_prefix overload_ambiguous_test(int, int)"
338 check_bp_locations_match_list \
339 "$cmd_prefix overload_ambiguous_test(int, int)" {
340 "overload_ambiguous_test(int, int)"
341 }
342 }
343 }
344
345 # Test completion of a function that is defined in different scopes
346 # with different parameters.
347
348 proc_with_prefix overload-2 {} {
349 with_test_prefix "all" {
350 set completion_list {
351 "(anonymous namespace)::overload2_function(overload2_arg3)"
352 "(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg4)"
353 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
354 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::struct_overload2_test::overload2_function(overload2_arga)"
355 "ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
356 "ns_overload2_test::(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg8)"
357 "ns_overload2_test::overload2_function(overload2_arg5)"
358 "ns_overload2_test::struct_overload2_test::overload2_function(overload2_arg6)"
359 "overload2_function(overload2_arg1)"
360 "struct_overload2_test::overload2_function(overload2_arg2)"
361 }
362 foreach cmd_prefix {"b" "b -function"} {
363 test_gdb_complete_multiple \
364 "$cmd_prefix " "overload2_func" "tion(overload2_arg" $completion_list
365 check_bp_locations_match_list \
366 "$cmd_prefix overload2_function" $completion_list
367 }
368 }
369
370 # Same, but restrict to functions/methods in some scope.
371 with_test_prefix "restrict scope" {
372 set completion_list {
373 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
374 "ns_overload2_test::overload2_function(overload2_arg5)"
375 }
376 foreach cmd_prefix {"b" "b -function"} {
377 test_gdb_complete_multiple \
378 "$cmd_prefix " "ns_overload2_test::overload2_func" "tion(overload2_arg" $completion_list
379 check_bp_locations_match_list \
380 "$cmd_prefix ns_overload2_test::overload2_function" $completion_list
381 }
382 }
383
384 # Restrict to anonymous namespace scopes.
385 with_test_prefix "restrict scope 2" {
386 set completion_list {
387 "(anonymous namespace)::overload2_function(overload2_arg3)"
388 "ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
389 }
390 foreach cmd_prefix {"b" "b -function"} {
391 test_gdb_complete_multiple \
392 "$cmd_prefix " "(anonymous namespace)::overload2_func" "tion(overload2_arg" $completion_list
393 check_bp_locations_match_list \
394 "$cmd_prefix (anonymous namespace)::overload2_function" $completion_list
395 }
396 }
397
398 # Add enough scopes, and we get a unique completion.
399 with_test_prefix "unique completion" {
400 foreach cmd_prefix {"b" "b -function"} {
401 test_gdb_complete_unique \
402 "$cmd_prefix ns_overload2_test::(anonymous namespace)::overload2_func" \
403 "$cmd_prefix ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
404 check_setting_bp_fails "$cmd_prefix ns_overload2_test::(anonymous namespace)::overload2_func"
405 check_bp_locations_match_list \
406 "$cmd_prefix ns_overload2_test::(anonymous namespace)::overload2_function" \
407 {"ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"}
408 }
409 }
410 }
411
412 # Test linespecs / locations using fully-qualified names.
413
414 proc_with_prefix fqn {} {
415
416 # "-qualified" works with both explicit locations and linespecs.
417 # Also test that combining a source file with a function name
418 # still results in a full match, with both linespecs and explicit
419 # locations.
420 foreach cmd_prefix {
421 "b -qualified "
422 "b -qualified -function "
423 "b -qualified cpls.cc:"
424 "b -qualified -source cpls.cc -function "
425 "b -source cpls.cc -qualified -function "
426 } {
427 test_gdb_complete_unique \
428 "${cmd_prefix}overload2_func" \
429 "${cmd_prefix}overload2_function(overload2_arg1)"
430
431 # Drill down until we find a unique completion.
432 test_gdb_complete_multiple "${cmd_prefix}" "ns_overload2_test::" "" {
433 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
434 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::struct_overload2_test::overload2_function(overload2_arga)"
435 "ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
436 "ns_overload2_test::(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg8)"
437 "ns_overload2_test::overload2_function(overload2_arg5)"
438 "ns_overload2_test::struct_overload2_test::overload2_function(overload2_arg6)"
439 }
440
441 test_gdb_complete_multiple "${cmd_prefix}" "ns_overload2_test::(anonymous namespace)::" "" {
442 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
443 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::struct_overload2_test::overload2_function(overload2_arga)"
444 "ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
445 "ns_overload2_test::(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg8)"
446 }
447
448 test_gdb_complete_multiple "${cmd_prefix}" "ns_overload2_test::(anonymous namespace)::ns_overload2_test::" "" {
449 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
450 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::struct_overload2_test::overload2_function(overload2_arga)"
451 }
452
453 test_gdb_complete_unique \
454 "${cmd_prefix}ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_func" \
455 "${cmd_prefix}ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
456
457 }
458 }
459
460 # Check that a fully-qualified lookup name doesn't match symbols in
461 # nested scopes.
462
463 proc_with_prefix fqn-2 {} {
464 set linespec "struct_overload2_test::overload2_function(overload2_arg6)"
465 set cmd_prefix "b -qualified"
466 check_setting_bp_fails "$cmd_prefix $linespec"
467 test_gdb_complete_none "$cmd_prefix $linespec"
468
469 # Check that using the same name, but not fully-qualifying it,
470 # would find something, just to make sure the test above is
471 # testing what we intend to test.
472 set cmd_prefix "b -function"
473 test_gdb_complete_unique "$cmd_prefix $linespec" "$cmd_prefix $linespec"
474 check_bp_locations_match_list \
475 "$cmd_prefix $linespec" \
476 {"ns_overload2_test::struct_overload2_test::overload2_function(overload2_arg6)"}
477 }
478
479 # Test completion of functions in different scopes that have the same
480 # name and parameters. Restricting the scopes should find fewer and
481 # fewer matches.
482
483 proc_with_prefix overload-3 {} {
484 with_test_prefix "all overloads" {
485 set completion_list {
486 "(anonymous namespace)::overload3_function(int)"
487 "(anonymous namespace)::overload3_function(long)"
488 "(anonymous namespace)::struct_overload3_test::overload3_function(int)"
489 "(anonymous namespace)::struct_overload3_test::overload3_function(long)"
490 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::overload3_function(int)"
491 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::overload3_function(long)"
492 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(int)"
493 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(long)"
494 "ns_overload3_test::(anonymous namespace)::overload3_function(int)"
495 "ns_overload3_test::(anonymous namespace)::overload3_function(long)"
496 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(int)"
497 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(long)"
498 "ns_overload3_test::overload3_function(int)"
499 "ns_overload3_test::overload3_function(long)"
500 "ns_overload3_test::struct_overload3_test::overload3_function(int)"
501 "ns_overload3_test::struct_overload3_test::overload3_function(long)"
502 "overload3_function(int)"
503 "overload3_function(long)"
504 "struct_overload3_test::overload3_function(int)"
505 "struct_overload3_test::overload3_function(long)"
506 }
507 foreach cmd_prefix {"b" "b -function"} {
508 test_gdb_complete_multiple "$cmd_prefix " "overload3_func" "tion(" $completion_list
509 check_bp_locations_match_list "$cmd_prefix overload3_function" $completion_list
510 }
511 }
512
513 with_test_prefix "restrict overload" {
514 foreach cmd_prefix {"b" "b -function"} {
515 test_gdb_complete_unique \
516 "$cmd_prefix overload3_function(int)" \
517 "$cmd_prefix overload3_function(int)"
518 check_bp_locations_match_list "$cmd_prefix overload3_function(int)" {
519 "(anonymous namespace)::overload3_function(int)"
520 "(anonymous namespace)::struct_overload3_test::overload3_function(int)"
521 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::overload3_function(int)"
522 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(int)"
523 "ns_overload3_test::(anonymous namespace)::overload3_function(int)"
524 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(int)"
525 "ns_overload3_test::overload3_function(int)"
526 "ns_overload3_test::struct_overload3_test::overload3_function(int)"
527 "overload3_function(int)"
528 "struct_overload3_test::overload3_function(int)"
529 }
530 }
531 }
532
533 with_test_prefix "restrict scope" {
534 set completion_list {
535 "(anonymous namespace)::struct_overload3_test::overload3_function(int)"
536 "(anonymous namespace)::struct_overload3_test::overload3_function(long)"
537 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(int)"
538 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(long)"
539 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(int)"
540 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(long)"
541 "ns_overload3_test::struct_overload3_test::overload3_function(int)"
542 "ns_overload3_test::struct_overload3_test::overload3_function(long)"
543 "struct_overload3_test::overload3_function(int)"
544 "struct_overload3_test::overload3_function(long)"
545 }
546 foreach cmd_prefix {"b" "b -function"} {
547 test_gdb_complete_multiple \
548 "$cmd_prefix " "struct_overload3_test::overload3_func" "tion(" \
549 $completion_list
550 check_bp_locations_match_list \
551 "$cmd_prefix struct_overload3_test::overload3_function" \
552 $completion_list
553 }
554 }
555 }
556
557 # Test completing an overloaded template method.
558
559 proc_with_prefix template-overload {} {
560 set completion_list {
561 "template_struct<int>::template_overload_fn(int)"
562 "template_struct<long>::template_overload_fn(long)"
563 }
564 foreach cmd_prefix {"b" "b -function"} {
565 test_gdb_complete_multiple "$cmd_prefix " "template_overload_fn" "(" $completion_list
566 check_bp_locations_match_list "$cmd_prefix template_overload_fn" $completion_list
567 check_bp_locations_match_list \
568 "$cmd_prefix template_struct<int>::template_overload_fn" \
569 "template_struct<int>::template_overload_fn(int)"
570 }
571 }
572
573 # Test completing template methods with non-void return type.
574
575 proc_with_prefix template-ret-type {} {
576 set method_name "template2_fn<int, int>"
577 set param_list "(template2_ret_type<int>, int, int)"
578 set struct_type "template2_struct<template2_ret_type<int> >"
579 set ret_type "template2_ret_type<int>"
580
581 # Templates are listed both with and without return type, making
582 # "template2_<tab>" ambiguous.
583 foreach cmd_prefix {"b" "b -function"} {
584 set completion_list \
585 [list \
586 "${ret_type} ${struct_type}::${method_name}${param_list}" \
587 "${struct_type}::${method_name}${param_list}"]
588 test_gdb_complete_multiple "$cmd_prefix " "template2_" "" $completion_list
589
590 # Add one character more after "2_", and the linespec becomes
591 # unambiguous. Test completing the whole prefix range after that,
592 # thus testing completing either with or without return type.
593 foreach {s t} [list \
594 "template2_r" \
595 "${ret_type} ${struct_type}::${method_name}${param_list}" \
596 "template2_s" \
597 "${struct_type}::${method_name}${param_list}"] {
598 set linespec $t
599 set complete_line "$cmd_prefix $linespec"
600 set start [index_after $s $complete_line]
601 test_complete_prefix_range $complete_line $start
602 }
603
604 # Setting a breakpoint with or without template params and without
605 # the method params works, just like with non-template functions.
606 # It also works with or without return type.
607 foreach linespec [list \
608 "template2_fn" \
609 "${method_name}" \
610 "${method_name}${param_list}" \
611 "${struct_type}::${method_name}" \
612 "${struct_type}::${method_name}${param_list}" \
613 "${ret_type} ${struct_type}::${method_name}" \
614 "${ret_type} ${struct_type}::${method_name}${param_list}"] {
615 check_bp_locations_match_list \
616 "$cmd_prefix $linespec" \
617 [list "${struct_type}::${method_name}${param_list}"]
618 }
619 }
620 }
621
622 # Test completion of function template foo.
623
624 proc_with_prefix template-function-foo {} {
625
626 foreach cmd_prefix {"b" "b -function"} {
627 # "foo" is ambiguous, this will set many different breakpoints.
628 set completion_list \
629 [list \
630 [makefoo Aabiaai] \
631 [makefoo Aabiabi] \
632 [makefoo Aabicdi] \
633 [makefoo AabicdiAabiaai] \
634 [makefoo AabicdiAabiabi] \
635 [makefoo AabicdiBabicdi] \
636 [makefoo Babicdi] \
637 [makefoo aai] \
638 [makefoo aaiabi] \
639 [makefoo aaicci] \
640 [makefoo aaicdi] \
641 [makefoo abi] \
642 [makefoo anabnb] \
643 [makefoo cci] \
644 [makefoo cdi] \
645 [makefoo NAnanbNBnanb] \
646 [makefoo nanb]]
647 test_gdb_complete_multiple "$cmd_prefix " "foo" "<" $completion_list
648 check_bp_locations_match_list "$cmd_prefix foo" $completion_list
649
650 # "foo<" should give the same result, but it should not set any
651 # breakpoints.
652 test_gdb_complete_multiple "$cmd_prefix " "foo<" "" $completion_list
653 check_setting_bp_fails "$cmd_prefix foo<"
654
655 # "foo<A" should only give completions in COMPLETION_LIST that
656 # start with "A" but should set no breakpoints.
657 set completion_list \
658 [list \
659 [makefoo Aabiaai] \
660 [makefoo Aabiabi] \
661 [makefoo Aabicdi] \
662 [makefoo AabicdiAabiaai] \
663 [makefoo AabicdiAabiabi] \
664 [makefoo AabicdiBabicdi]]
665 test_gdb_complete_multiple "$cmd_prefix " "foo<A" "<a<b<int> >, " \
666 $completion_list
667 check_setting_bp_fails "$cmd_prefix foo<A"
668
669 # "foo<A>" should give any function with one parameter of any type
670 # of A. While the parameter list in the template should be ignored,
671 # the function's argument list should not be ignored.
672 set completion_list \
673 [list \
674 [makefoo Aabiaai] \
675 [makefoo Aabiabi] \
676 [makefoo Aabicdi]]
677 test_gdb_complete_multiple "$cmd_prefix " "foo<A>" \
678 "(A<a<b<int> >, " $completion_list
679 check_bp_locations_match_list "$cmd_prefix foo<A>" $completion_list
680
681 # "foo<A," should complete to any function with more than one
682 # parameter where the first parameter is any type of A. Insufficient
683 # location to set breakpoints.
684 set completion_list \
685 [list \
686 [makefoo AabicdiAabiaai] \
687 [makefoo AabicdiAabiabi] \
688 [makefoo AabicdiBabicdi]]
689 test_gdb_complete_multiple "$cmd_prefix " "foo<A," " " \
690 $completion_list
691 check_setting_bp_fails "$cmd_prefix foo<A,"
692
693 # "foo<A<a<b<int>, a" should give all completions starting with
694 # "Aabia" but it is insufficient to set breakpoints.
695 set completion_list \
696 [list \
697 [makefoo Aabiaai] \
698 [makefoo Aabiabi]]
699 test_gdb_complete_multiple "$cmd_prefix " "foo<A<a<b<int> >, a" \
700 "<" $completion_list
701 check_setting_bp_fails "$cmd_prefix foo<A<a<b<int> >, a"
702
703 # "foo<A<a<b<int>, a<" should yield the same results as above.
704 test_gdb_complete_multiple "$cmd_prefix " "foo<A<a<b<int> >, a<" \
705 "" $completion_list
706 check_setting_bp_fails "$cmd_prefix foo<A<a<b<int> >, a<"
707
708 # "foo<A<a<b<int>, a<a" is unique but insufficient to set a
709 # breakpoint. This has an ignored template parameter list, so
710 # the completion will contain an ignored list ("a<a>")
711 test_gdb_complete_unique "$cmd_prefix foo<A<a<b<int> >, a<a" \
712 "$cmd_prefix [makefoo Aabiaai]"
713 check_setting_bp_fails "$cmd_prefix foo<A<b<int> >, a<a"
714
715 # "foo<A<a<b<int>, a<b" is also unique. Same parameter ignoring
716 # happens here, too (except "a<b>").
717 test_gdb_complete_unique "$cmd_prefix foo<A<a<b<int> >, a<b" \
718 "$cmd_prefix [makefoo Aabiabi]"
719 check_setting_bp_fails "$cmd_prefix foo<A<a<b<int> >, a<b"
720
721 # "foo<B" is unique but insufficient to set a breakpoint.
722 test_gdb_complete_unique "$cmd_prefix foo<B" \
723 "$cmd_prefix [makefoo Babicdi]"
724 check_setting_bp_fails "$cmd_prefix foo<B"
725
726 # "foo<B>" yields the same unique result and sets a breakpoint.
727 # Since the input skips the parameter list, so does the completion.
728 test_gdb_complete_unique "$cmd_prefix foo<B>" \
729 "$cmd_prefix foo<B>(B<a<b<int> >, c<d<int> > >)"
730 check_bp_locations_match_list "$cmd_prefix foo<B>" \
731 [list [makefoo Babicdi]]
732
733 # "foo<B," should return no completions and no breakpoints.
734 test_gdb_complete_none "$cmd_prefix foo<B,"
735 check_setting_bp_fails "$cmd_prefix foo<B,"
736
737 # "foo<n::" should yield only the functions starting with
738 # "n" and "N" and no breakpoints.
739 set completion_list \
740 [list \
741 [makefoo NAnanbNBnanb] \
742 [makefoo nanb]]
743 test_gdb_complete_multiple "$cmd_prefix " "foo<n::" "" \
744 $completion_list
745 check_setting_bp_fails "$cmd_prefix foo<n::"
746
747 # "foo<A<a, c> >" is unique and sets a breakpoint.
748 # Multiple template parameter lists are skipped, so GDB will ignore
749 # them in the completion.
750 test_gdb_complete_unique "$cmd_prefix foo<A<a, c> >" \
751 "$cmd_prefix foo<A<a, c> >(A<a<b<int> >, c<d<int> > >)"
752 check_bp_locations_match_list "$cmd_prefix foo<A<a, c> >" \
753 [list [makefoo Aabicdi]]
754 }
755 }
756
757 # Helper for template-class-with-method to build completion lists.
758
759 proc makem {arglist_list} {
760 set completion_list {}
761 foreach arglist $arglist_list {
762 lappend completion_list "[maketype $arglist]::method()"
763 }
764 return $completion_list
765 }
766
767 # Returns a list of elements that look like
768 # void TYPE::method()
769 # where TYPE is derived from each arglist in ARGLIST_LIST.
770
771 proc test_makem_1 {arglist_list expected_list} {
772 set result [makem $arglist_list]
773 send_log "makem $arglist = $result\n"
774 send_log "expecting $expected_list\n"
775
776 # Do list equality via canonical strings.
777 if {[expr {[list {*}$expected_list] eq [list {*}$result]}]} {
778 pass "makem unit test: $arglist"
779 } else {
780 fail "makem unit test: $arglist"
781 }
782 }
783
784 # Unit tests for makem.
785
786 proc test_makem {} {
787 test_makem_1 ai {"a<int>::method()"}
788 test_makem_1 bi {"b<int>::method()"}
789 test_makem_1 {ai bi} {"a<int>::method()" "b<int>::method()"}
790 test_makem_1 {Aaiaai Bbibbi abi cdi} {
791 "A<a<int>, a<a<int> > >::method()"
792 "B<b<int>, b<b<int> > >::method()"
793 "a<b<int> >::method()"
794 "c<d<int> >::method()"
795 }
796 }
797
798 # Test class template containing a (non-templated) method called "method."
799
800 proc_with_prefix template-class-with-method {} {
801
802 foreach {type type_list} \
803 [list \
804 "" {aai abi cci cdi Aabicdi Aabiaai Aabiabi Babicdi} \
805 "a" {aai abi} \
806 "b" {} \
807 "c" {cci cdi} \
808 "A" {Aabicdi Aabiaai Aabiabi} \
809 "B" {Babicdi} \
810 "A<a, a>" {Aabiaai Aabiabi} \
811 "A<a<b>, c>" {Aabicdi}\
812 "A<a, d>" {} \
813 "B<a, a>" {} \
814 "B<a, b>" {} \
815 "B<a, c>" {Babicdi}] \
816 {
817 foreach cmd_prefix {"b" "b -function"} {
818 set c "$cmd_prefix "
819 if {$type != ""} {
820 append c "${type}::"
821 }
822 append c "method"
823
824 if {[llength $type_list] > 0} {
825 test_gdb_complete_unique $c "${c}()"
826 check_bp_locations_match_list $c [makem $type_list]
827 } else {
828 test_gdb_complete_none $c
829 }
830 }
831 }
832 }
833
834 # Test completion of a const-overloaded funtion (const-overload).
835 # Note that "const" appears after the function/method parameters.
836
837 proc_with_prefix const-overload {} {
838 set completion_list {
839 "struct_with_const_overload::const_overload_fn()"
840 "struct_with_const_overload::const_overload_fn() const"
841 }
842 foreach cmd_prefix {"b" "b -function"} {
843 test_gdb_complete_multiple \
844 "$cmd_prefix " "const_overload_fn" "()" \
845 $completion_list
846 test_gdb_complete_multiple \
847 "$cmd_prefix " "const_overload_fn ( " ")" \
848 $completion_list
849 test_gdb_complete_multiple \
850 "$cmd_prefix " "const_overload_fn()" "" \
851 $completion_list
852
853 check_bp_locations_match_list \
854 "$cmd_prefix const_overload_fn" \
855 {"struct_with_const_overload::const_overload_fn()"
856 "struct_with_const_overload::const_overload_fn() const"}
857
858 check_setting_bp_fails "$cmd_prefix const_overload_fn("
859 check_bp_locations_match_list \
860 "$cmd_prefix const_overload_fn()" \
861 {"struct_with_const_overload::const_overload_fn()"}
862 check_bp_locations_match_list \
863 "$cmd_prefix const_overload_fn() const" \
864 {"struct_with_const_overload::const_overload_fn() const"}
865 }
866 }
867
868 # Same but quote-enclose the function name. This makes the overload
869 # no longer be ambiguous.
870
871 proc_with_prefix const-overload-quoted {} {
872 foreach cmd_prefix {"b" "b -function"} {
873 set linespec "'const_overload_fn()'"
874 test_gdb_complete_unique "$cmd_prefix $linespec" "$cmd_prefix $linespec"
875 check_bp_locations_match_list \
876 "$cmd_prefix $linespec" {
877 "struct_with_const_overload::const_overload_fn()"
878 }
879
880 set linespec "'const_overload_fn() const'"
881 test_gdb_complete_unique "$cmd_prefix $linespec" "$cmd_prefix $linespec"
882 check_bp_locations_match_list \
883 "$cmd_prefix $linespec" {
884 "struct_with_const_overload::const_overload_fn() const"
885 }
886 }
887 }
888
889 # Test that when the function is unambiguous, linespec completion
890 # appends the end quote char automatically, both ' and ".
891
892 proc_with_prefix append-end-quote-char-when-unambiguous {} {
893 foreach cmd_prefix {"b" "b -function"} {
894 foreach qc $completion::all_quotes_list {
895 set linespec "${qc}not_overloaded_fn()${qc}"
896 foreach cmd [list "$cmd_prefix ${qc}not_overloaded_fn()" \
897 "$cmd_prefix ${qc}not_overloaded_fn" \
898 "$cmd_prefix ${qc}not_overloaded_"] {
899 test_gdb_complete_unique $cmd "$cmd_prefix $linespec"
900 }
901 check_bp_locations_match_list \
902 "$cmd_prefix $linespec" {"not_overloaded_fn()"}
903 }
904 }
905 }
906
907 # Test completing symbols of source files.
908
909 proc_with_prefix in-source-file-unconstrained {} {
910 # First test that unconstrained matching picks up functions from
911 # multiple files.
912 test_gdb_complete_multiple "b " "file_constrained_test" "_cpls" {
913 "file_constrained_test_cpls2_function(int)"
914 "file_constrained_test_cpls_function(int)"
915 }
916 check_setting_bp_fails "b file_constrained_test_cpls"
917 }
918
919 # Test an unambiguous completion that would be ambiguous if it weren't
920 # for the source file component, due to
921 # "file_constrained_test_cpls_function" in cpls.cc. Test with
922 # different components quoted, and with whitespace before the function
923 # name.
924
925 proc_with_prefix in-source-file-unambiguous {} {
926 foreach sqc $completion::maybe_quoted_list {
927 foreach fqc $completion::maybe_quoted_list {
928 # Linespec.
929 foreach sep {":" ": "} {
930 set linespec \
931 "${sqc}cpls2.cc${sqc}${sep}${fqc}file_constrained_test_cpls2_function(int)${fqc}"
932 set complete_line "b $linespec"
933 set start [index_after "constrained_test" $complete_line]
934 set input_line [string range $complete_line 0 $start]
935 test_gdb_complete_unique $input_line ${complete_line}
936 check_bp_locations_match_list "b $linespec" {
937 "file_constrained_test_cpls2_function(int)"
938 }
939 }
940
941 # Explicit location.
942 set source_opt "-source ${sqc}cpls2.cc${sqc}"
943 set function_opt "-function ${fqc}file_constrained_test_cpls2_function(int)${fqc}"
944 set complete_line "b $source_opt $function_opt"
945 set start [index_after "cpls2_functio" $complete_line]
946 set input_line [string range $complete_line 0 $start]
947 test_gdb_complete_unique $input_line ${complete_line}
948 check_bp_locations_match_list "$complete_line" {
949 "file_constrained_test_cpls2_function(int)"
950 }
951 }
952 }
953 }
954
955 # Test an ambiguous completion constrained by a source file. Test
956 # with different components quoted, and with whitespace before the
957 # function name.
958
959 proc_with_prefix in-source-file-ambiguous {} {
960 foreach sqc $completion::maybe_quoted_list {
961 foreach fqc $completion::maybe_quoted_list {
962 # Linespec.
963 foreach sep {":" ": "} {
964 set cmd_prefix "b ${sqc}cpls2.cc${sqc}${sep}"
965 test_gdb_complete_multiple "${cmd_prefix}" ${fqc} "" {
966 "another_file_constrained_test_cpls2_function(int)"
967 "file_constrained_test_cpls2_function(int)"
968 } ${fqc} ${fqc}
969 }
970
971 # Explicit location.
972 test_gdb_complete_multiple \
973 "b -source ${sqc}cpls2.cc${sqc} -function " ${fqc} "" {
974 "another_file_constrained_test_cpls2_function(int)"
975 "file_constrained_test_cpls2_function(int)"
976 } ${fqc} ${fqc}
977 }
978 }
979 }
980
981 # Check that completing a file name in a linespec auto-appends a colon
982 # instead of a whitespace character.
983
984 proc_with_prefix source-complete-appends-colon {} {
985 # Test with quotes to make sure the end quote char is put at the
986 # right place.
987 foreach qc $completion::maybe_quoted_list {
988 test_gdb_complete_unique \
989 "b ${qc}cpls2." \
990 "b ${qc}cpls2.cc${qc}" ":"
991 test_gdb_complete_unique \
992 "b ${qc}cpls2.c" \
993 "b ${qc}cpls2.cc${qc}" ":"
994 test_gdb_complete_unique \
995 "b ${qc}cpls2.cc" \
996 "b ${qc}cpls2.cc${qc}" ":"
997
998 # Same, but with a filename with an hyphen (which is normally
999 # a language word break char).
1000 test_gdb_complete_unique \
1001 "b ${qc}cpls-" \
1002 "b ${qc}cpls-hyphen.cc${qc}" ":"
1003 test_gdb_complete_unique \
1004 "b ${qc}cpls-hyphen" \
1005 "b ${qc}cpls-hyphen.cc${qc}" ":"
1006 }
1007
1008 # Test the same, but with the name of a nonexisting file.
1009
1010 # Cursor at the end of the string.
1011 test_gdb_complete_none "b nonexistingfilename.cc"
1012 # Cursor past the end of the string.
1013 test_gdb_complete_multiple "b nonexistingfilename.cc " "" "" \
1014 $completion::keyword_list
1015 foreach qc $completion::all_quotes_list {
1016 # Unterminated quote.
1017 test_gdb_complete_none "b ${qc}nonexistingfilename.cc"
1018 test_gdb_complete_none "b ${qc}nonexistingfilename.cc "
1019 # Terminated quote, cursor at the quote.
1020 test_gdb_complete_unique \
1021 "b ${qc}nonexistingfilename.cc${qc}" \
1022 "b ${qc}nonexistingfilename.cc${qc}"
1023 # Terminated quote, cursor past the quote.
1024 test_gdb_complete_multiple \
1025 "b ${qc}nonexistingfilename.cc${qc} " "" "" \
1026 $completion::keyword_list
1027 }
1028 }
1029
1030 ####################################################################
1031
1032 # Test that a colon at the end of the linespec is understood as an
1033 # incomplete scope operator (incomplete-scope-colon), instead of a
1034 # source/function separator.
1035
1036 proc_with_prefix incomplete-scope-colon {} {
1037
1038 # Helper for the loop below to simplify it. Tests completion of
1039 # the range defined by the RANGE_SS found in the constructed line.
1040 #
1041 # E.g., with:
1042 #
1043 # source="source.cc"
1044 # fqc="'"
1045 # prototype="ns::function()"
1046 # range_ss="s::f"
1047 #
1048 # we'd try completing with the cursor set in each of the
1049 # underlined range's positions of:
1050 #
1051 # b source.cc:'ns::function()'"
1052 # ^^^^
1053 #
1054 # Also test that setting a breakpoint at the constructed line
1055 # finds the same breakpoint location as completion does.
1056 #
1057 proc incomplete_scope_colon_helper {prototype range_ss {skip_check_bp 0}} {
1058 foreach source {"" "cpls.cc"} {
1059 # Test with and without source quoting.
1060 foreach sqc $completion::maybe_quoted_list {
1061 if {$source == "" && $sqc != ""} {
1062 # Invalid combination.
1063 continue
1064 }
1065
1066 # Test with and without function quoting.
1067 foreach fqc $completion::maybe_quoted_list {
1068 if {$source == ""} {
1069 set linespec_source ""
1070 set explicit_source ""
1071 } else {
1072 set linespec_source "${sqc}${source}${sqc}:"
1073 set explicit_source "-source ${sqc}${source}${sqc}"
1074 }
1075
1076 # Even though this use case is trickier with
1077 # linespecs due to the ":" as separator, test both
1078 # linespecs and explicit locations for
1079 # completeness.
1080 foreach location [list \
1081 "${linespec_source}${fqc}$prototype${fqc}" \
1082 "${explicit_source} -function ${fqc}$prototype${fqc}"] {
1083 set complete_line "b $location"
1084 set start [string first $range_ss $complete_line]
1085 set end [expr ($start + [string length $range_ss])]
1086 test_complete_prefix_range $complete_line $start $end
1087 if {!$skip_check_bp} {
1088 check_bp_locations_match_list "b $location" [list "$prototype"]
1089 }
1090 }
1091 }
1092 }
1093 }
1094 }
1095
1096 incomplete_scope_colon_helper \
1097 "struct_incomplete_scope_colon_test::incomplete_scope_colon_test()" \
1098 "t::i"
1099
1100 incomplete_scope_colon_helper \
1101 "ns_incomplete_scope_colon_test::incomplete_scope_colon_test()" \
1102 "t::i"
1103
1104 # Test completing around both "::"s.
1105 foreach range_ss {"t::s" "t::i"} skip_check_bp {0 1} {
1106 incomplete_scope_colon_helper \
1107 "ns2_incomplete_scope_colon_test::struct_in_ns2_incomplete_scope_colon_test::incomplete_scope_colon_test()" \
1108 $range_ss $skip_check_bp
1109 }
1110 }
1111
1112 # Test completing functions/methods in anonymous namespaces.
1113
1114 proc_with_prefix anon-ns {} {
1115 foreach cmd_prefix {"b" "b -function"} {
1116 foreach qc $completion::maybe_quoted_list {
1117 test_gdb_complete_unique \
1118 "$cmd_prefix ${qc}anon_ns_function" \
1119 "$cmd_prefix ${qc}anon_ns_function()${qc}"
1120 check_bp_locations_match_list "$cmd_prefix ${qc}anon_ns_function()${qc}" {
1121 "(anonymous namespace)::anon_ns_function()"
1122 "(anonymous namespace)::anon_ns_struct::anon_ns_function()"
1123 "the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_function()"
1124 "the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_struct::anon_ns_function()"
1125 }
1126 }
1127
1128 # A "(" finds all anonymous namespace functions/methods in all
1129 # scopes.
1130 test_gdb_complete_multiple "$cmd_prefix " "(" "anonymous namespace)::" {
1131 "(anonymous namespace)::anon_ns_function()"
1132 "(anonymous namespace)::anon_ns_struct::anon_ns_function()"
1133 "(anonymous namespace)::overload2_function(overload2_arg3)"
1134 "(anonymous namespace)::overload3_function(int)"
1135 "(anonymous namespace)::overload3_function(long)"
1136 "(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg4)"
1137 "(anonymous namespace)::struct_overload3_test::overload3_function(int)"
1138 "(anonymous namespace)::struct_overload3_test::overload3_function(long)"
1139 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::overload2_function(overload2_arg9)"
1140 "ns_overload2_test::(anonymous namespace)::ns_overload2_test::struct_overload2_test::overload2_function(overload2_arga)"
1141 "ns_overload2_test::(anonymous namespace)::overload2_function(overload2_arg7)"
1142 "ns_overload2_test::(anonymous namespace)::struct_overload2_test::overload2_function(overload2_arg8)"
1143 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::overload3_function(int)"
1144 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::overload3_function(long)"
1145 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(int)"
1146 "ns_overload3_test::(anonymous namespace)::ns_overload3_test::struct_overload3_test::overload3_function(long)"
1147 "ns_overload3_test::(anonymous namespace)::overload3_function(int)"
1148 "ns_overload3_test::(anonymous namespace)::overload3_function(long)"
1149 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(int)"
1150 "ns_overload3_test::(anonymous namespace)::struct_overload3_test::overload3_function(long)"
1151 "the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_function()"
1152 "the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_struct::anon_ns_function()"
1153 }
1154
1155 set function "the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_function()"
1156 test_gdb_complete_unique "$cmd_prefix $function" "$cmd_prefix $function"
1157 check_bp_locations_match_list "$cmd_prefix $function" [list $function]
1158
1159 # Test completing after the "(anonymous namespace)" part.
1160 test_gdb_complete_unique \
1161 "$cmd_prefix the_anon_ns_wrapper_ns::(anonymous namespace)::anon_ns_fu" \
1162 "$cmd_prefix $function"
1163
1164 # Test whitespace in the "(anonymous namespace)" component.
1165
1166 test_gdb_complete_unique \
1167 "$cmd_prefix the_anon_ns_wrapper_ns::( anonymous namespace )::anon_ns_fu" \
1168 "$cmd_prefix the_anon_ns_wrapper_ns::( anonymous namespace )::anon_ns_function()"
1169 check_setting_bp_fails \
1170 "$cmd_prefix the_anon_ns_wrapper_ns::( anonymous namespace )::anon_ns_fu"
1171
1172 set function_ws \
1173 "the_anon_ns_wrapper_ns::( anonymous namespace )::anon_ns_function ( )"
1174 test_gdb_complete_unique "$cmd_prefix $function_ws" "$cmd_prefix $function_ws"
1175 check_bp_locations_match_list "$cmd_prefix $function_ws" [list $function]
1176 }
1177 }
1178
1179 # Basic test for completing "operator<". More extensive C++ operator
1180 # tests in cpls-op.exp.
1181
1182 proc_with_prefix operator< {} {
1183 # Complete all prefixes between "oper" and the whole prototype.
1184 set function "operator<(foo_enum, foo_enum)"
1185 foreach cmd_prefix {"b" "b -function"} {
1186 set line "$cmd_prefix $function"
1187 set start [index_after "oper" $line]
1188 test_complete_prefix_range $line $start
1189 }
1190
1191 # There's a label in the function; try completing it. (Exhaustive
1192 # label completion tests further below.)
1193 foreach location [list \
1194 "$function:label1" \
1195 "-function $function -label label1"] {
1196
1197 set cmd "b $location"
1198 set input_line [string range $cmd 0 [expr [string length $cmd] - 3]]
1199
1200 test_gdb_complete_unique $input_line $cmd
1201 test_gdb_complete_unique $cmd $cmd
1202 check_bp_locations_match_list $cmd [list "$location"]
1203 }
1204 }
1205
1206 # Test completion of scopes with an ambiguous prefix.
1207
1208 proc_with_prefix ambiguous-prefix {} {
1209 foreach cmd_prefix {"b" "b -function"} {
1210 test_gdb_complete_multiple "$cmd_prefix " "ambiguous_pre" "fix_" {
1211 "ambiguous_prefix_global_func()"
1212 "the_ambiguous_prefix_ns::ambiguous_prefix_ns_func()"
1213 "the_ambiguous_prefix_struct::ambiguous_prefix_method()"
1214 }
1215 check_setting_bp_fails "$cmd_prefix ambiguous_prefix_"
1216 }
1217 }
1218
1219 # Test completion of function labels.
1220
1221 proc_with_prefix function-labels {} {
1222 # Test with and without a source file component.
1223 foreach_location_functions \
1224 { "" "cpls.cc" } \
1225 { "function_with_labels(int)" } \
1226 {
1227 # Linespec version. Test various spacing around the label
1228 # colon separator.
1229 foreach label_sep {":" " :" ": " " : "} {
1230 set linespec "${location}${label_sep}"
1231 test_gdb_complete_multiple "b $linespec" "l" "abel" {
1232 "label1"
1233 "label2"
1234 }
1235 check_setting_bp_fails "b ${linespec}label"
1236
1237 set tsep [string trim ${source_sep}]
1238 check_bp_locations_match_list \
1239 "b ${linespec}label1" [list "${source}${tsep}${function}:label1"]
1240 check_bp_locations_match_list \
1241 "b ${linespec}label2" [list "${source}${tsep}${function}:label2"]
1242 }
1243 } \
1244 {
1245 # Explicit locations version.
1246 append location " -label"
1247 test_gdb_complete_multiple "b $location " "l" "abel" {
1248 "label1"
1249 "label2"
1250 }
1251 check_setting_bp_fails "b $location label"
1252
1253 if {$source != ""} {
1254 set bp_loc_src "-source ${source} "
1255 } else {
1256 set bp_loc_src ""
1257 }
1258 check_bp_locations_match_list \
1259 "b ${location} label1" [list "${bp_loc_src}-function $function -label label1"]
1260 check_bp_locations_match_list \
1261 "b ${location} label2" [list "${bp_loc_src}-function $function -label label2"]
1262 }
1263 }
1264
1265 # Test that completion after a function name offers keyword
1266 # (if/inferior/task/thread/-force-condition) matches in linespec mode,
1267 # and also the explicit location options in explicit locations mode.
1268
1269 proc_with_prefix keywords-after-function {} {
1270 set explicit_list \
1271 [lsort [concat \
1272 $completion::explicit_opts_list \
1273 $completion::keyword_list]]
1274
1275 # Test without a source file, with a known source file, and with
1276 # and unknown source file.
1277 # Test a known and an unknown function.
1278 foreach_location_functions \
1279 { "" "cpls.cc" "unknown_file.cc" } \
1280 { "function_with_labels(int)" "unknown_function(int)" } \
1281 {
1282 # Linespec version.
1283 test_gdb_complete_multiple "b ${location} " "" "" \
1284 $completion::keyword_list
1285 } \
1286 {
1287 # Explicit locations version.
1288 test_gdb_complete_multiple "b ${location} " "" "" \
1289 $explicit_list
1290 }
1291 }
1292
1293 # Same, but after a label.
1294
1295 proc_with_prefix keywords-after-label {} {
1296 set explicit_list \
1297 [lsort [concat \
1298 $completion::explicit_opts_list \
1299 $completion::keyword_list]]
1300
1301 foreach_location_labels \
1302 { "" "cpls.cc" } \
1303 { "function_with_labels(int)" "unknown_function(int)" } \
1304 { "label1" "non_existing_label" } \
1305 {
1306 # Linespec version.
1307 test_gdb_complete_multiple "b ${location} " "" "" \
1308 $completion::keyword_list
1309 } \
1310 {
1311 # Explicit locations version.
1312 test_gdb_complete_multiple "b ${location} " "" "" \
1313 $explicit_list
1314 }
1315 }
1316
1317 # Similar, but after an unknown file, and in linespec mode only.
1318
1319 proc_with_prefix keywords-after-unknown-file {} {
1320 # Test with and without quoting.
1321 foreach qc $completion::maybe_quoted_list {
1322 set line "b ${qc}unknown_file.cc${qc}: "
1323 test_gdb_complete_multiple $line "" "" $completion::keyword_list
1324 }
1325 }
1326
1327 # Test that linespec / function completion does not match data
1328 # symbols, only functions/methods.
1329
1330 proc_with_prefix no-data-symbols {} {
1331 foreach cmd_prefix {"b" "b -function"} {
1332 test_gdb_complete_unique "$cmd_prefix code_" "$cmd_prefix code_function()"
1333 }
1334 }
1335
1336
1337 # After "if", we expect an expression, which has a different completer
1338 # that matches data symbols as well. Check that that works.
1339
1340 proc_with_prefix if-expression {} {
1341 foreach cmd_prefix {"b" "b -function"} {
1342 test_gdb_complete_multiple "$cmd_prefix function() if " "code_" "" {
1343 "code_data"
1344 "code_function()"
1345 }
1346
1347 test_gdb_complete_unique \
1348 "$cmd_prefix function() if code_data + another_da" \
1349 "$cmd_prefix function() if code_data + another_data"
1350
1351 test_gdb_complete_unique \
1352 "$cmd_prefix non_existing_function() if code_data + another_da" \
1353 "$cmd_prefix non_existing_function() if code_data + another_data"
1354
1355 # FIXME: For now, thread and task also use the expression
1356 # completer.
1357 test_gdb_complete_unique \
1358 "$cmd_prefix function() thread code_data + another_da" \
1359 "$cmd_prefix function() thread code_data + another_data"
1360 test_gdb_complete_unique \
1361 "$cmd_prefix function() task code_data + another_da" \
1362 "$cmd_prefix function() task code_data + another_data"
1363 }
1364 }
1365
1366 # The testcase driver. Calls all test procedures.
1367
1368 proc test_driver {} {
1369 all-param-prefixes
1370 overload
1371 overload-2
1372 fqn
1373 fqn-2
1374 overload-3
1375 template-overload
1376 template-ret-type
1377 #test_makefoo
1378 template-function-foo
1379 #test_makem
1380 template-class-with-method
1381 const-overload
1382 const-overload-quoted
1383 append-end-quote-char-when-unambiguous
1384 in-source-file-unconstrained
1385 in-source-file-unambiguous
1386 in-source-file-ambiguous
1387 source-complete-appends-colon
1388 incomplete-scope-colon
1389 anon-ns
1390 operator<
1391 ambiguous-prefix
1392 function-labels
1393 keywords-after-function
1394 keywords-after-label
1395 keywords-after-unknown-file
1396 no-data-symbols
1397 if-expression
1398 }
1399
1400 test_driver