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