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