summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.linespec
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite/gdb.linespec')
-rw-r--r--gdb/testsuite/gdb.linespec/cpcompletion.exp534
-rw-r--r--gdb/testsuite/gdb.linespec/cpls-hyphen.cc33
-rw-r--r--gdb/testsuite/gdb.linespec/cpls.cc386
-rw-r--r--gdb/testsuite/gdb.linespec/cpls2.cc46
-rw-r--r--gdb/testsuite/gdb.linespec/explicit.exp208
5 files changed, 1200 insertions, 7 deletions
diff --git a/gdb/testsuite/gdb.linespec/cpcompletion.exp b/gdb/testsuite/gdb.linespec/cpcompletion.exp
new file mode 100644
index 00000000000..873dc785cda
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/cpcompletion.exp
@@ -0,0 +1,534 @@
+# Copyright 2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the gdb testsuite.
+
+load_lib completion-support.exp
+
+standard_testfile cpls.cc cpls2.cc cpls-hyphen.cc
+
+if {[prepare_for_testing "failed to prepare" $testfile \
+ [list $srcfile $srcfile2 $srcfile3] {debug}]} {
+ return -1
+}
+
+# Disable the completion limit for the whole testcase.
+gdb_test_no_output "set max-completions unlimited"
+
+# Start of tests.
+
+# Test completion of all parameter prefixes, crossing "(" and ")",
+# with and without whitespace.
+
+proc_with_prefix all-param-prefixes {} {
+
+ # Test both linespecs and explicit locations.
+ foreach cmd_prefix {"b" "b -function"} {
+ set line "$cmd_prefix param_prefixes_test_long(long)"
+ set start [index_after "test_long" $line]
+ test_complete_prefix_range $line $start
+
+ # Same, but with extra spaces. Note that the original spaces in
+ # the input line are preserved after completion.
+ test_gdb_complete_unique \
+ "$cmd_prefix param_prefixes_test_long(long " \
+ "$cmd_prefix param_prefixes_test_long(long )"
+ test_gdb_complete_unique \
+ "$cmd_prefix param_prefixes_test_long( long " \
+ "$cmd_prefix param_prefixes_test_long( long )"
+ test_gdb_complete_unique \
+ "$cmd_prefix param_prefixes_test_long ( long " \
+ "$cmd_prefix param_prefixes_test_long ( long )"
+
+ # Complete all parameter prefixes between "(i" and "(int*, int&)".
+ # Note that this exercises completing when the point is at the
+ # space in "param_prefixes_test_intp_intr(int*, ".
+ set line "$cmd_prefix param_prefixes_test_intp_intr(int*, int&)"
+ set start [index_after "intp_intr" $line]
+ test_complete_prefix_range $line $start
+
+ # Similar, but with extra spaces.
+ test_gdb_complete_unique \
+ "$cmd_prefix param_prefixes_test_intp_intr ( int* " \
+ "$cmd_prefix param_prefixes_test_intp_intr ( int* , int&)"
+
+ test_gdb_complete_unique \
+ "$cmd_prefix param_prefixes_test_intp_intr ( int *" \
+ "$cmd_prefix param_prefixes_test_intp_intr ( int *, int&)"
+
+ test_gdb_complete_unique \
+ "$cmd_prefix param_prefixes_test_intp_intr ( int *, int " \
+ "$cmd_prefix param_prefixes_test_intp_intr ( int *, int &)"
+
+ test_gdb_complete_unique \
+ "$cmd_prefix param_prefixes_test_intp_intr ( int *, int & " \
+ "$cmd_prefix param_prefixes_test_intp_intr ( int *, int & )"
+ }
+}
+
+# Test completion of an overloaded function.
+
+proc_with_prefix overload {} {
+ set completion_list {
+ "overload_ambiguous_test(int, int)"
+ "overload_ambiguous_test(int, long)"
+ "overload_ambiguous_test(long)"
+ }
+
+ foreach cmd_prefix {"b" "b -function"} {
+ test_gdb_complete_multiple \
+ "$cmd_prefix " "overload_ambiguous_" "test(" \
+ $completion_list
+ check_bp_locations_match_list \
+ "$cmd_prefix overload_ambiguous_test" \
+ $completion_list
+
+ # Test disambiguating by typing enough to pick the "int" as
+ # first parameter type. This then tests handling ambiguity in
+ # the second parameter, which checks that tab completion when
+ # the point is at the whitespace behaves naturally, by showing
+ # the remaining matching overloads to the user.
+ test_gdb_complete_multiple \
+ "$cmd_prefix " "overload_ambiguous_test(i" "nt, " {
+ "overload_ambiguous_test(int, int)"
+ "overload_ambiguous_test(int, long)"
+ }
+
+ # Add a few more characters to make the completion
+ # unambiguous.
+ test_gdb_complete_unique \
+ "$cmd_prefix overload_ambiguous_test(int, i" \
+ "$cmd_prefix overload_ambiguous_test(int, int)"
+ check_bp_locations_match_list \
+ "$cmd_prefix overload_ambiguous_test(int, int)" {
+ "overload_ambiguous_test(int, int)"
+ }
+ }
+}
+
+# Test that when the function is unambiguous, linespec completion
+# appends the end quote char automatically, both ' and ".
+
+proc_with_prefix append-end-quote-char-when-unambiguous {} {
+ foreach cmd_prefix {"b" "b -function"} {
+ foreach qc $completion::all_quotes_list {
+ set linespec "${qc}not_overloaded_fn()${qc}"
+ foreach cmd [list "$cmd_prefix ${qc}not_overloaded_fn()" \
+ "$cmd_prefix ${qc}not_overloaded_fn" \
+ "$cmd_prefix ${qc}not_overloaded_"] {
+ test_gdb_complete_unique $cmd "$cmd_prefix $linespec"
+ }
+ check_bp_locations_match_list \
+ "$cmd_prefix $linespec" {"not_overloaded_fn()"}
+ }
+ }
+}
+
+# Test completing symbols of source files.
+
+proc_with_prefix in-source-file-unconstrained {} {
+ # First test that unconstrained matching picks up functions from
+ # multiple files.
+ test_gdb_complete_multiple "b " "file_constrained_test" "_cpls" {
+ "file_constrained_test_cpls2_function(int)"
+ "file_constrained_test_cpls_function(int)"
+ }
+ check_setting_bp_fails "b file_constrained_test_cpls"
+}
+
+# Test an unambiguous completion that would be ambiguous if it weren't
+# for the source file component, due to
+# "file_constrained_test_cpls_function" in cpls.cc. Test with
+# different components quoted, and with whitespace before the function
+# name.
+
+proc_with_prefix in-source-file-unambiguous {} {
+ foreach sqc $completion::maybe_quoted_list {
+ foreach fqc $completion::maybe_quoted_list {
+ # Linespec.
+ foreach sep {":" ": "} {
+ set linespec \
+ "${sqc}cpls2.cc${sqc}${sep}${fqc}file_constrained_test_cpls2_function(int)${fqc}"
+ set complete_line "b $linespec"
+ set start [index_after "constrained_test" $complete_line]
+ set input_line [string range $complete_line 0 $start]
+ test_gdb_complete_unique $input_line ${complete_line}
+ check_bp_locations_match_list "b $linespec" {
+ "file_constrained_test_cpls2_function(int)"
+ }
+ }
+
+ # Explicit location.
+ set source_opt "-source ${sqc}cpls2.cc${sqc}"
+ set function_opt "-function ${fqc}file_constrained_test_cpls2_function(int)${fqc}"
+ set complete_line "b $source_opt $function_opt"
+ set start [index_after "cpls2_functio" $complete_line]
+ set input_line [string range $complete_line 0 $start]
+ test_gdb_complete_unique $input_line ${complete_line}
+ check_bp_locations_match_list "$complete_line" {
+ "file_constrained_test_cpls2_function(int)"
+ }
+ }
+ }
+}
+
+# Test an ambiguous completion constrained by a source file. Test
+# with different components quoted, and with whitespace before the
+# function name.
+
+proc_with_prefix in-source-file-ambiguous {} {
+ foreach sqc $completion::maybe_quoted_list {
+ foreach fqc $completion::maybe_quoted_list {
+ # Linespec.
+ foreach sep {":" ": "} {
+ set cmd_prefix "b ${sqc}cpls2.cc${sqc}${sep}"
+ test_gdb_complete_multiple "${cmd_prefix}" ${fqc} "" {
+ "another_file_constrained_test_cpls2_function(int)"
+ "file_constrained_test_cpls2_function(int)"
+ } ${fqc} ${fqc}
+ }
+
+ # Explicit location.
+ test_gdb_complete_multiple \
+ "b -source ${sqc}cpls2.cc${sqc} -function " ${fqc} "" {
+ "another_file_constrained_test_cpls2_function(int)"
+ "file_constrained_test_cpls2_function(int)"
+ } ${fqc} ${fqc}
+ }
+ }
+}
+
+# Check that completing a file name in a linespec auto-appends a colon
+# instead of a whitespace character.
+
+proc_with_prefix source-complete-appends-colon {} {
+ # Test with quotes to make sure the end quote char is put at the
+ # right place.
+ foreach qc $completion::maybe_quoted_list {
+ test_gdb_complete_unique \
+ "b ${qc}cpls2." \
+ "b ${qc}cpls2.cc${qc}" ":"
+ test_gdb_complete_unique \
+ "b ${qc}cpls2.c" \
+ "b ${qc}cpls2.cc${qc}" ":"
+ test_gdb_complete_unique \
+ "b ${qc}cpls2.cc" \
+ "b ${qc}cpls2.cc${qc}" ":"
+
+ # Same, but with a filename with an hyphen (which is normally
+ # a language word break char).
+ test_gdb_complete_unique \
+ "b ${qc}cpls-" \
+ "b ${qc}cpls-hyphen.cc${qc}" ":"
+ test_gdb_complete_unique \
+ "b ${qc}cpls-hyphen" \
+ "b ${qc}cpls-hyphen.cc${qc}" ":"
+ }
+
+ # Test the same, but with the name of a nonexisting file.
+
+ # Cursor at the end of the string.
+ test_gdb_complete_none "b nonexistingfilename.cc"
+ # Cursor past the end of the string.
+ test_gdb_complete_multiple "b nonexistingfilename.cc " "" "" \
+ $completion::keyword_list
+ foreach qc $completion::all_quotes_list {
+ # Unterminated quote.
+ test_gdb_complete_none "b ${qc}nonexistingfilename.cc"
+ test_gdb_complete_none "b ${qc}nonexistingfilename.cc "
+ # Terminated quote, cursor at the quote.
+ test_gdb_complete_unique \
+ "b ${qc}nonexistingfilename.cc${qc}" \
+ "b ${qc}nonexistingfilename.cc${qc}"
+ # Terminated quote, cursor past the quote.
+ test_gdb_complete_multiple \
+ "b ${qc}nonexistingfilename.cc${qc} " "" "" \
+ $completion::keyword_list
+ }
+}
+
+####################################################################
+
+# Test that a colon at the end of the linespec is understood as an
+# incomplete scope operator (incomplete-scope-colon), instead of a
+# source/function separator.
+
+proc_with_prefix incomplete-scope-colon {} {
+
+ # Helper for the loop below to simplify it. Tests completion of
+ # the range defined by the RANGE_SS found in the constructed line.
+ #
+ # E.g., with:
+ #
+ # source="source.cc"
+ # fqc="'"
+ # prototype="ns::function()"
+ # range_ss="s::f"
+ #
+ # we'd try completing with the cursor set in each of the
+ # underlined range's positions of:
+ #
+ # b source.cc:'ns::function()'"
+ # ^^^^
+ #
+ # Also test that setting a breakpoint at the constructed line
+ # finds the same breakpoint location as completion does.
+ #
+ proc incomplete_scope_colon_helper {prototype range_ss {skip_check_bp 0}} {
+ foreach source {"" "cpls.cc"} {
+ # Test with and without source quoting.
+ foreach sqc $completion::maybe_quoted_list {
+ if {$source == "" && $sqc != ""} {
+ # Invalid combination.
+ continue
+ }
+
+ # Test with and without function quoting.
+ foreach fqc $completion::maybe_quoted_list {
+ if {$source == ""} {
+ set linespec_source ""
+ set explicit_source ""
+ } else {
+ set linespec_source "${sqc}${source}${sqc}:"
+ set explicit_source "-source ${sqc}${source}${sqc}"
+ }
+
+ # Even though this use case is trickier with
+ # linespecs due to the ":" as separator, test both
+ # linespecs and explicit locations for
+ # completeness.
+ foreach location [list \
+ "${linespec_source}${fqc}$prototype${fqc}" \
+ "${explicit_source} -function ${fqc}$prototype${fqc}"] {
+ set complete_line "b $location"
+ set start [string first $range_ss $complete_line]
+ set end [expr ($start + [string length $range_ss])]
+ test_complete_prefix_range $complete_line $start $end
+ if {!$skip_check_bp} {
+ check_bp_locations_match_list "b $location" [list "$prototype"]
+ }
+ }
+ }
+ }
+ }
+ }
+
+ incomplete_scope_colon_helper \
+ "struct_incomplete_scope_colon_test::incomplete_scope_colon_test()" \
+ "t::i"
+
+ incomplete_scope_colon_helper \
+ "ns_incomplete_scope_colon_test::incomplete_scope_colon_test()" \
+ "t::i"
+
+ # Test completing around both "::"s.
+ foreach range_ss {"t::s" "t::i"} skip_check_bp {0 1} {
+ incomplete_scope_colon_helper \
+ "ns2_incomplete_scope_colon_test::struct_in_ns2_incomplete_scope_colon_test::incomplete_scope_colon_test()" \
+ $range_ss $skip_check_bp
+ }
+}
+
+# Basic test for completing "operator<". More extensive C++ operator
+# tests in cpls-op.exp.
+
+proc_with_prefix operator< {} {
+ # Complete all prefixes between "oper" and the whole prototype.
+ set function "operator<(foo_enum, foo_enum)"
+ foreach cmd_prefix {"b" "b -function"} {
+ set line "$cmd_prefix $function"
+ set start [index_after "oper" $line]
+ test_complete_prefix_range $line $start
+ }
+
+ # There's a label in the function; try completing it. (Exhaustive
+ # label completion tests further below.)
+ foreach location [list \
+ "$function:label1" \
+ "-function $function -label label1"] {
+
+ set cmd "b $location"
+ set input_line [string range $cmd 0 [expr [string length $cmd] - 3]]
+
+ test_gdb_complete_unique $input_line $cmd
+ test_gdb_complete_unique $cmd $cmd
+ check_bp_locations_match_list $cmd [list "$location"]
+ }
+}
+
+# Test completion of function labels.
+
+proc_with_prefix function-labels {} {
+ # Test with and without a source file component.
+ foreach_location_functions \
+ { "" "cpls.cc" } \
+ { "function_with_labels(int)" } \
+ {
+ # Linespec version. Test various spacing around the label
+ # colon separator.
+ foreach label_sep {":" " :" ": " " : "} {
+ set linespec "${location}${label_sep}"
+ test_gdb_complete_multiple "b $linespec" "l" "abel" {
+ "label1"
+ "label2"
+ }
+ check_setting_bp_fails "b ${linespec}label"
+
+ set tsep [string trim ${source_sep}]
+ check_bp_locations_match_list \
+ "b ${linespec}label1" [list "${source}${tsep}${function}:label1"]
+ check_bp_locations_match_list \
+ "b ${linespec}label2" [list "${source}${tsep}${function}:label2"]
+ }
+ } \
+ {
+ # Explicit locations version.
+ append location " -label"
+ test_gdb_complete_multiple "b $location " "l" "abel" {
+ "label1"
+ "label2"
+ }
+ check_setting_bp_fails "b $location label"
+
+ if {$source != ""} {
+ set bp_loc_src "-source ${source} "
+ } else {
+ set bp_loc_src ""
+ }
+ check_bp_locations_match_list \
+ "b ${location} label1" [list "${bp_loc_src}-function $function -label label1"]
+ check_bp_locations_match_list \
+ "b ${location} label2" [list "${bp_loc_src}-function $function -label label2"]
+ }
+}
+
+# Test that completion after a function name offers keyword
+# (if/task/thread) matches in linespec mode, and also the explicit
+# location options in explicit locations mode.
+
+proc_with_prefix keywords-after-function {} {
+ set explicit_list \
+ [concat $completion::explicit_opts_list $completion::keyword_list]
+
+ # Test without a source file, with a known source file, and with
+ # and unknown source file.
+ # Test a known and an unknown function.
+ foreach_location_functions \
+ { "" "cpls.cc" "unknown_file.cc" } \
+ { "function_with_labels(int)" "unknown_function(int)" } \
+ {
+ # Linespec version.
+ test_gdb_complete_multiple "b ${location} " "" "" \
+ $completion::keyword_list
+ } \
+ {
+ # Explicit locations version.
+ test_gdb_complete_multiple "b ${location} " "" "" \
+ $explicit_list
+ }
+}
+
+# Same, but after a label.
+
+proc_with_prefix keywords-after-label {} {
+ set explicit_list \
+ [concat $completion::explicit_opts_list $completion::keyword_list]
+
+ foreach_location_labels \
+ { "" "cpls.cc" } \
+ { "function_with_labels(int)" "unknown_function(int)" } \
+ { "label1" "non_existing_label" } \
+ {
+ # Linespec version.
+ test_gdb_complete_multiple "b ${location} " "" "" \
+ $completion::keyword_list
+ } \
+ {
+ # Explicit locations version.
+ test_gdb_complete_multiple "b ${location} " "" "" \
+ $explicit_list
+ }
+}
+
+# Similar, but after an unknown file, and in linespec mode only.
+
+proc_with_prefix keywords-after-unknown-file {} {
+ # Test with and without quoting.
+ foreach qc $completion::maybe_quoted_list {
+ set line "b ${qc}unknown_file.cc${qc}: "
+ test_gdb_complete_multiple $line "" "" $completion::keyword_list
+ }
+}
+
+# Test that linespec / function completion does not match data
+# symbols, only functions/methods.
+
+proc_with_prefix no-data-symbols {} {
+ foreach cmd_prefix {"b" "b -function"} {
+ test_gdb_complete_unique "$cmd_prefix code_" "$cmd_prefix code_function()"
+ }
+}
+
+
+# After "if", we expect an expression, which has a different completer
+# that matches data symbols as well. Check that that works.
+
+proc_with_prefix if-expression {} {
+ foreach cmd_prefix {"b" "b -function"} {
+ test_gdb_complete_multiple "$cmd_prefix function() if " "code_" "" {
+ "code_data"
+ "code_function()"
+ }
+
+ test_gdb_complete_unique \
+ "$cmd_prefix function() if code_data + another_da" \
+ "$cmd_prefix function() if code_data + another_data"
+
+ test_gdb_complete_unique \
+ "$cmd_prefix non_existing_function() if code_data + another_da" \
+ "$cmd_prefix non_existing_function() if code_data + another_data"
+
+ # FIXME: For now, thread and task also use the expression
+ # completer.
+ test_gdb_complete_unique \
+ "$cmd_prefix function() thread code_data + another_da" \
+ "$cmd_prefix function() thread code_data + another_data"
+ test_gdb_complete_unique \
+ "$cmd_prefix function() task code_data + another_da" \
+ "$cmd_prefix function() task code_data + another_data"
+ }
+}
+
+# The testcase driver. Calls all test procedures.
+
+proc test_driver {} {
+ all-param-prefixes
+ overload
+ append-end-quote-char-when-unambiguous
+ in-source-file-unconstrained
+ in-source-file-unambiguous
+ in-source-file-ambiguous
+ source-complete-appends-colon
+ incomplete-scope-colon
+ operator<
+ function-labels
+ keywords-after-function
+ keywords-after-label
+ keywords-after-unknown-file
+ no-data-symbols
+ if-expression
+}
+
+test_driver
diff --git a/gdb/testsuite/gdb.linespec/cpls-hyphen.cc b/gdb/testsuite/gdb.linespec/cpls-hyphen.cc
new file mode 100644
index 00000000000..4bd2d9fa332
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/cpls-hyphen.cc
@@ -0,0 +1,33 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2017 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* A function in a file whose name has an hyphen. */
+
+int
+ns_hyphen_function (int i)
+{
+ if (i > 0)
+ {
+ label1:
+ return i + 20;
+ }
+ else
+ {
+ label2:
+ return i + 10;
+ }
+}
diff --git a/gdb/testsuite/gdb.linespec/cpls.cc b/gdb/testsuite/gdb.linespec/cpls.cc
new file mode 100644
index 00000000000..776dd4cfaa1
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/cpls.cc
@@ -0,0 +1,386 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2017 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Code for the all-param-prefixes test. */
+
+void
+param_prefixes_test_long (long)
+{}
+
+void
+param_prefixes_test_intp_intr (int *, int&)
+{}
+
+/* Code for the overload test. */
+
+void
+overload_ambiguous_test (long)
+{}
+
+void
+overload_ambiguous_test (int, int)
+{}
+
+void
+overload_ambiguous_test (int, long)
+{}
+
+/* Code for the overload-2 test. */
+
+/* Generate functions/methods all with the same name, in different
+ scopes, but all with different parameters. */
+
+struct overload2_arg1 {};
+struct overload2_arg2 {};
+struct overload2_arg3 {};
+struct overload2_arg4 {};
+struct overload2_arg5 {};
+struct overload2_arg6 {};
+struct overload2_arg7 {};
+struct overload2_arg8 {};
+struct overload2_arg9 {};
+struct overload2_arga {};
+
+#define GEN_OVERLOAD2_FUNCTIONS(ARG1, ARG2) \
+ void \
+ overload2_function (ARG1) \
+ {} \
+ \
+ struct struct_overload2_test \
+ { \
+ void overload2_function (ARG2); \
+ }; \
+ \
+ void \
+ struct_overload2_test::overload2_function (ARG2) \
+ {}
+
+/* In the global namespace. */
+GEN_OVERLOAD2_FUNCTIONS( overload2_arg1, overload2_arg2)
+
+namespace
+{
+ /* In an anonymous namespace. */
+ GEN_OVERLOAD2_FUNCTIONS (overload2_arg3, overload2_arg4)
+}
+
+namespace ns_overload2_test
+{
+ /* In a namespace. */
+ GEN_OVERLOAD2_FUNCTIONS (overload2_arg5, overload2_arg6)
+
+ namespace
+ {
+ /* In a nested anonymous namespace. */
+ GEN_OVERLOAD2_FUNCTIONS (overload2_arg7, overload2_arg8)
+
+ namespace ns_overload2_test
+ {
+ /* In a nested namespace. */
+ GEN_OVERLOAD2_FUNCTIONS (overload2_arg9, overload2_arga)
+ }
+ }
+}
+
+/* Code for the overload-3 test. */
+
+#define GEN_OVERLOAD3_FUNCTIONS(ARG1, ARG2) \
+ void \
+ overload3_function (ARG1) \
+ {} \
+ void \
+ overload3_function (ARG2) \
+ {} \
+ \
+ struct struct_overload3_test \
+ { \
+ void overload3_function (ARG1); \
+ void overload3_function (ARG2); \
+ }; \
+ \
+ void \
+ struct_overload3_test::overload3_function (ARG1) \
+ {} \
+ void \
+ struct_overload3_test::overload3_function (ARG2) \
+ {}
+
+/* In the global namespace. */
+GEN_OVERLOAD3_FUNCTIONS (int, long)
+
+namespace
+{
+ /* In an anonymous namespace. */
+ GEN_OVERLOAD3_FUNCTIONS (int, long)
+}
+
+namespace ns_overload3_test
+{
+ /* In a namespace. */
+ GEN_OVERLOAD3_FUNCTIONS (int, long)
+
+ namespace
+ {
+ /* In a nested anonymous namespace. */
+ GEN_OVERLOAD3_FUNCTIONS (int, long)
+
+ namespace ns_overload3_test
+ {
+ /* In a nested namespace. */
+ GEN_OVERLOAD3_FUNCTIONS (int, long)
+ }
+ }
+}
+
+/* Code for the template-overload tests. */
+
+template <typename T>
+struct template_struct
+{
+ T template_overload_fn (T);
+};
+
+template <typename T>
+T template_struct<T>::template_overload_fn (T t)
+{
+ return t;
+}
+
+template_struct<int> template_struct_int;
+template_struct<long> template_struct_long;
+
+/* Code for the template2-ret-type tests. */
+
+template <typename T>
+struct template2_ret_type {};
+
+template <typename T>
+struct template2_struct
+{
+ template <typename T2, typename T3>
+ T template2_fn (T = T (), T2 t2 = T2 (), T3 t3 = T3 ());
+};
+
+template <typename T>
+template <typename T2, typename T3>
+T template2_struct<T>::template2_fn (T t, T2 t2, T3 t3)
+{
+ return T ();
+}
+
+template2_struct<template2_ret_type<int> > template2_struct_inst;
+
+/* Code for the const-overload tests. */
+
+struct struct_with_const_overload
+{
+ void const_overload_fn ();
+ void const_overload_fn () const;
+};
+
+void
+struct_with_const_overload::const_overload_fn ()
+{}
+
+void
+struct_with_const_overload::const_overload_fn () const
+{}
+
+void
+not_overloaded_fn ()
+{}
+
+/* Code for the incomplete-scope-colon tests. */
+
+struct struct_incomplete_scope_colon_test
+{
+ void incomplete_scope_colon_test ();
+};
+
+void
+struct_incomplete_scope_colon_test::incomplete_scope_colon_test ()
+{}
+
+namespace ns_incomplete_scope_colon_test
+{
+ void incomplete_scope_colon_test () {}
+}
+
+namespace ns2_incomplete_scope_colon_test
+{
+ struct struct_in_ns2_incomplete_scope_colon_test
+ {
+ void incomplete_scope_colon_test ();
+ };
+
+ void
+ struct_in_ns2_incomplete_scope_colon_test::incomplete_scope_colon_test ()
+ {}
+}
+
+/* Code for the anon-ns tests. */
+
+namespace
+{
+ void anon_ns_function ()
+ {}
+
+ struct anon_ns_struct
+ {
+ void anon_ns_function ();
+ };
+
+ void
+ anon_ns_struct::anon_ns_function ()
+ {}
+}
+
+namespace the_anon_ns_wrapper_ns
+{
+
+namespace
+{
+ void anon_ns_function ()
+ {}
+
+ struct anon_ns_struct
+ {
+ void anon_ns_function ();
+ };
+
+ void
+ anon_ns_struct::anon_ns_function ()
+ {}
+}
+
+} /* the_anon_ns_wrapper_ns */
+
+/* Code for the global-ns-scope-op tests. */
+
+void global_ns_scope_op_function ()
+{
+}
+
+/* Add a function with the same name to a namespace. We want to test
+ that "b ::global_ns_function" does NOT select it. */
+namespace the_global_ns_scope_op_ns
+{
+ void global_ns_scope_op_function ()
+ {
+ }
+}
+
+/* Code for the ambiguous-prefix tests. */
+
+/* Create a few functions/methods with the same "ambiguous_prefix_"
+ prefix. They in different scopes, but "b ambiguous_prefix_<tab>"
+ should list them all, and figure out the LCD is
+ ambiguous_prefix_. */
+
+void ambiguous_prefix_global_func ()
+{
+}
+
+namespace the_ambiguous_prefix_ns
+{
+ void ambiguous_prefix_ns_func ()
+ {
+ }
+}
+
+struct the_ambiguous_prefix_struct
+{
+ void ambiguous_prefix_method ();
+};
+
+void
+the_ambiguous_prefix_struct::ambiguous_prefix_method ()
+{
+}
+
+/* Code for the function-labels test. */
+
+int
+function_with_labels (int i)
+{
+ if (i > 0)
+ {
+ label1:
+ return i + 20;
+ }
+ else
+ {
+ label2:
+ return i + 10;
+ }
+}
+
+/* Code for the no-data-symbols and if-expression tests. */
+
+int code_data = 0;
+
+int another_data = 0;
+
+/* A function that has a same "code" prefix as the global above. We
+ want to ensure that completing on "b code" doesn't offer the data
+ symbol. */
+void
+code_function ()
+{
+}
+
+/* Code for the operator< tests. */
+
+enum foo_enum
+ {
+ foo_value
+ };
+
+bool operator<(foo_enum lhs, foo_enum rhs)
+{
+ label1:
+ return false;
+}
+
+/* Code for the in-source-file-unconstrained /
+ in-source-file-ambiguous tests. */
+
+int
+file_constrained_test_cpls_function (int i)
+{
+ if (i > 0)
+ {
+ label1:
+ return i + 20;
+ }
+ else
+ {
+ label2:
+ return i + 10;
+ }
+}
+
+
+int
+main ()
+{
+ template2_struct_inst.template2_fn<int, int> ();
+ template_struct_int.template_overload_fn(0);
+ template_struct_long.template_overload_fn(0);
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.linespec/cpls2.cc b/gdb/testsuite/gdb.linespec/cpls2.cc
new file mode 100644
index 00000000000..a8f1319840a
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/cpls2.cc
@@ -0,0 +1,46 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2017 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+int
+file_constrained_test_cpls2_function (int i)
+{
+ if (i > 0)
+ {
+ label1:
+ return i + 20;
+ }
+ else
+ {
+ label2:
+ return i + 10;
+ }
+}
+
+int
+another_file_constrained_test_cpls2_function (int i)
+{
+ if (i > 0)
+ {
+ label1:
+ return i + 20;
+ }
+ else
+ {
+ label2:
+ return i + 10;
+ }
+}
diff --git a/gdb/testsuite/gdb.linespec/explicit.exp b/gdb/testsuite/gdb.linespec/explicit.exp
index 65d78caddb6..9cf0162f16b 100644
--- a/gdb/testsuite/gdb.linespec/explicit.exp
+++ b/gdb/testsuite/gdb.linespec/explicit.exp
@@ -15,6 +15,8 @@
# Tests for explicit locations
+load_lib completion-support.exp
+
standard_testfile explicit.c explicit2.c 3explicit.c
set exefile $testfile
@@ -222,13 +224,14 @@ namespace eval $testfile {
}
}
- set tst "complete unique file name"
- send_gdb "break -source 3ex\t"
- gdb_test_multiple "" $tst {
- -re "break -source 3explicit.c " {
- send_gdb "\n"
- gdb_test "" \
- {Source filename requires function, label, or line offset.} $tst
+ with_test_prefix "complete unique file name" {
+ foreach qc $completion::maybe_quoted_list {
+ set cmd "break -source ${qc}3explicit.c${qc}"
+ test_gdb_complete_unique \
+ "break -source ${qc}3ex" \
+ $cmd
+ gdb_test $cmd \
+ {Source filename requires function, label, or line offset.}
}
}
@@ -326,10 +329,201 @@ namespace eval $testfile {
}
}
+ with_test_prefix "complete unique label name" {
+ foreach qc $completion::maybe_quoted_list {
+ test_gdb_complete_unique \
+ "break -function myfunction -label ${qc}to" \
+ "break -function myfunction -label ${qc}top${qc}"
+ }
+ }
+
+ with_test_prefix "complete unique label name with source file" {
+ test_gdb_complete_unique \
+ "break -source explicit.c -function myfunction -label to" \
+ "break -source explicit.c -function myfunction -label top"
+ }
+
+ with_test_prefix "complete unique label name reversed" {
+ test_gdb_complete_multiple "b -label top -function " "myfunction" "" {
+ "myfunction"
+ "myfunction2"
+ "myfunction3"
+ "myfunction4"
+ }
+ }
+
+ with_test_prefix "complete non-unique label name" {
+ test_gdb_complete_multiple "b -function myfunction -label " "" "" {
+ "done"
+ "top"
+ }
+ }
+
+ # The program is stopped at myfunction, so gdb is able to
+ # infer the label's function.
+ with_test_prefix "complete label name with no function" {
+ test_gdb_complete_unique \
+ "break -label to" \
+ "break -label top"
+ check_bp_locations_match_list \
+ "break -label top" {
+ "-function myfunction -label top"
+ }
+ }
+
+ # See above.
+ with_test_prefix "complete label name with source file but no function" {
+ test_gdb_complete_unique \
+ "break -source explicit.c -label to" \
+ "break -source explicit.c -label top"
+ check_bp_locations_match_list \
+ "break -source explicit.c -label top" {
+ "-source explicit.c -function myfunction -label top"
+ }
+ }
+
+ with_test_prefix "complete label name with wrong source file" {
+ test_gdb_complete_none \
+ "break -source explicit2.c -function myfunction -label to"
+ check_setting_bp_fails \
+ "break -source explicit2.c -function myfunction -label top"
+ }
+
+ # Get rid of symbols from shared libraries, otherwise
+ # "b -source thr<tab>" could find some system library's
+ # source.
+ gdb_test_no_output "nosharedlibrary"
+
+ # Test that after a seemingly finished option argument,
+ # completion matches both the explicit location options and
+ # the linespec keywords.
+ set completions_list {
+ "-function"
+ "-label"
+ "-line"
+ "-source"
+ "if"
+ "task"
+ "thread"
+ }
+ foreach what { "-function" "-label" "-line" "-source" } {
+ with_test_prefix "complete after $what" {
+ if {$what != "-line"} {
+ set w "$what argument "
+ test_gdb_complete_multiple \
+ "b $w" "" "" $completions_list
+ test_gdb_complete_unique \
+ "b $w thr" \
+ "b $w thread"
+ test_gdb_complete_unique \
+ "b $w -fun" \
+ "b $w -function"
+ } else {
+ # After -line, we expect a number / offset.
+ foreach line {"10" "+10" "-10"} {
+ set w "-line $line"
+ test_gdb_complete_multiple \
+ "b $w " "" "" $completions_list
+ test_gdb_complete_unique \
+ "b $w thr" \
+ "b $w thread"
+ test_gdb_complete_unique \
+ "b $w -fun" \
+ "b $w -function"
+ }
+
+ # With an invalid -line argument, we don't get any
+ # completions.
+ test_gdb_complete_none "b -line argument "
+ }
+
+ # Don't complete a linespec keyword ("thread") or
+ # another option name when expecting an option
+ # argument.
+ test_gdb_complete_none "b $what thr"
+ test_gdb_complete_none "b $what -fun"
+ }
+ }
+
+
+ # Tests that ensure that after "if" we complete on expressions
+ # are in cpcompletion.exp.
+
+ # Disable the completion limit for the rest of the testcase.
+ gdb_test_no_output "set max-completions unlimited"
+
+ # Get rid of symbols from shared libraries, otherwise the
+ # completions match list for "break <tab>" is huge and makes
+ # the test below quite long while the gdb_test_multiple loop
+ # below consumes the matches. Not doing this added ~20
+ # seconds at the time of writing. (Actually, already done above.)
+ # gdb_test_no_output "nosharedlibrary"
+
+ # Test completion with no input argument. We should see all
+ # the options, plus all the functions. To keep it simple, as
+ # proxy, we check for presence of one explicit location
+ # option, one probe location, and one function.
+ set saw_opt_function 0
+ set saw_opt_probe_stap 0
+ set saw_function 0
+
+ set tst "complete with no arguments"
+ send_gdb "break \t"
+ gdb_test_multiple "" $tst {
+ "break \\\x07" {
+ send_gdb "\t\t"
+ gdb_test_multiple "" $tst {
+ "Display all" {
+ send_gdb "y"
+ exp_continue
+ }
+ -re "-function" {
+ set saw_opt_function 1
+ exp_continue
+ }
+ -re "-probe-stap" {
+ set saw_opt_probe_stap 1
+ exp_continue
+ }
+ -re "myfunction4" {
+ set saw_function 1
+ exp_continue
+ }
+ -re "\r\n$gdb_prompt " {
+ gdb_assert {$saw_opt_function && $saw_opt_probe_stap && $saw_function} $tst
+ }
+ -re " " {
+ exp_continue
+ }
+ }
+ }
+ }
+ clear_input_line $tst
+
# NOTE: We don't bother testing more elaborate combinations of options,
# such as "-func main -sour 3ex\t" (main is defined in explicit.c).
# The completer cannot handle these yet.
+ # The following completion tests require having no symbols
+ # loaded.
+ gdb_exit
+ gdb_start
+
+ # The match list you get when you complete with no options
+ # specified at all.
+ set completion_list {
+ "-function"
+ "-label"
+ "-line"
+ "-probe"
+ "-probe-dtrace"
+ "-probe-stap"
+ "-source"
+ }
+ with_test_prefix "complete with no arguments and no symbols" {
+ test_gdb_complete_multiple "b " "" "-" $completion_list
+ test_gdb_complete_multiple "b " "-" "" $completion_list
+ }
}
# End of completion tests.