aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.linespec
diff options
context:
space:
mode:
authorKeith Seitz <keiths@redhat.com>2015-08-11 17:09:36 -0700
committerKeith Seitz <keiths@redhat.com>2015-08-11 17:09:36 -0700
commit87f0e7204722a986f79f245eee716f0870832d47 (patch)
tree80936c86b139d303a7139c46ae00b55f89c91f8d /gdb/testsuite/gdb.linespec
parent00e52e5376c7ec604a739e6242e6be36221162d7 (diff)
downloadgdb-87f0e7204722a986f79f245eee716f0870832d47.zip
gdb-87f0e7204722a986f79f245eee716f0870832d47.tar.gz
gdb-87f0e7204722a986f79f245eee716f0870832d47.tar.bz2
Explicit locations: add UI features for CLI
This patch exposes explicit locations to the CLI user. This enables users to "explicitly" specify attributes of the breakpoint location to avoid any ambiguity that might otherwise exist with linespecs. The general syntax of explicit locations is: -source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME -label LABEL_NAME Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users may use the completer with either options or values. gdb/ChangeLog: * completer.c: Include location.h. (enum match_type): New enum. (location_completer): Rename to ... (linespec_completer): ... this. (collect_explicit_location_matches, backup_text_ptr) (explicit_location_completer): New functions. (location_completer): "New" function; handle linespec and explicit location completions. (complete_line_internal): Remove all location completer-specific handling. * linespec.c (linespec_lexer_lex_keyword, is_ada_operator) (find_toplevel_char): Export. (linespec_parse_line_offset): Export. Issue error if STRING is not numerical. (gdb_get_linespec_parser_quote_characters): New function. * linespec.h (linespec_parse_line_offset): Declare. (get_gdb_linespec_parser_quote_characters): Declare. (is_ada_operator): Declare. (find_toplevel_char): Declare. (linespec_lexer_lex_keyword): Declare. * location.c (explicit_to_event_location): New function. (explicit_location_lex_one): New function. (string_to_explicit_location): New function. (string_to_event_location): Handle explicit locations. * location.h (explicit_to_event_location): Declare. (string_to_explicit_location): Declare. gdb/testsuite/ChangeLog: * gdb.linespec/3explicit.c: New file. * gdb.linespec/cpexplicit.cc: New file. * gdb.linespec/cpexplicit.exp: New file. * gdb.linespec/explicit.c: New file. * gdb.linespec/explicit.exp: New file. * gdb.linespec/explicit2.c: New file. * gdb.linespec/ls-errs.exp: Add explicit location tests. * lib/gdb.exp (capture_command_output): Regexp-escape `command' before using in the matching pattern. Clarify that `prefix' is a regular expression.
Diffstat (limited to 'gdb/testsuite/gdb.linespec')
-rw-r--r--gdb/testsuite/gdb.linespec/3explicit.c28
-rw-r--r--gdb/testsuite/gdb.linespec/cpexplicit.cc63
-rw-r--r--gdb/testsuite/gdb.linespec/cpexplicit.exp112
-rw-r--r--gdb/testsuite/gdb.linespec/explicit.c56
-rw-r--r--gdb/testsuite/gdb.linespec/explicit.exp406
-rw-r--r--gdb/testsuite/gdb.linespec/explicit2.c24
-rw-r--r--gdb/testsuite/gdb.linespec/ls-errs.exp57
7 files changed, 738 insertions, 8 deletions
diff --git a/gdb/testsuite/gdb.linespec/3explicit.c b/gdb/testsuite/gdb.linespec/3explicit.c
new file mode 100644
index 0000000..12bf277
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/3explicit.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2013 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/>. */
+
+static int
+myfunction4 (int arg)
+{
+ return arg + 2;
+}
+
+int
+myfunction3 (int arg)
+{
+ return myfunction4 (arg);
+}
diff --git a/gdb/testsuite/gdb.linespec/cpexplicit.cc b/gdb/testsuite/gdb.linespec/cpexplicit.cc
new file mode 100644
index 0000000..42d50c7
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/cpexplicit.cc
@@ -0,0 +1,63 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2012-2013 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/>. */
+
+class myclass
+{
+public:
+ static int myfunction (int arg) /* entry location */
+ {
+ int i, j, r;
+
+ j = 0; /* myfunction location */
+ r = arg;
+
+ top:
+ ++j; /* top location */
+
+ if (j == 10)
+ goto done;
+
+ for (i = 0; i < 10; ++i)
+ {
+ r += i;
+ if (j % 2)
+ goto top;
+ }
+
+ done:
+ return r;
+ }
+
+ int operator, (const myclass& c) { return 0; } /* operator location */
+};
+
+int
+main (void)
+{
+ int i, j;
+
+ /* Call the test function repeatedly, enough times for all our tests
+ without running forever if something goes wrong. */
+ myclass c, d;
+ for (i = 0, j = 0; i < 1000; ++i)
+ {
+ j += myclass::myfunction (0);
+ j += (c,d);
+ }
+
+ return j;
+}
diff --git a/gdb/testsuite/gdb.linespec/cpexplicit.exp b/gdb/testsuite/gdb.linespec/cpexplicit.exp
new file mode 100644
index 0000000..90c8ce8
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/cpexplicit.exp
@@ -0,0 +1,112 @@
+# Copyright 2012-2015 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/>.
+
+# Tests for explicit linespecs
+
+if {[skip_cplus_tests]} {
+ unsupported "skipping C++ tests"
+ return
+}
+
+standard_testfile .cc
+set exefile $testfile
+
+if {[prepare_for_testing $testfile $exefile $srcfile \
+ {c++ debug nowarnings}]} {
+ return -1
+}
+
+# Wrap this whole test in a namespace to avoid contaminating other tests.
+namespace eval $testfile {
+ # Test the given (explicit) LINESPEC which should cause gdb to break
+ # at LOCATION.
+ proc test_breakpoint {linespec location} {
+
+ # Delete all breakpoints, set a new breakpoint at LINESPEC,
+ # and attempt to run to it.
+ delete_breakpoints
+ gdb_breakpoint $linespec
+ gdb_continue_to_breakpoint $linespec $location
+ }
+
+ # Add the given LINESPEC to the array named in THEARRAY. GDB is expected
+ # to stop at LOCATION.
+ proc add {thearray linespec location} {
+ upvar $thearray ar
+
+ lappend ar(linespecs) $linespec
+ lappend ar(locations) $location
+ }
+
+ # Some locations used in this test
+ variable lineno
+ variable location
+ set lineno(normal) [gdb_get_line_number "myfunction location" $srcfile]
+ set lineno(entry) [gdb_get_line_number "entry location" $srcfile]
+ set lineno(top) [gdb_get_line_number "top location" $srcfile]
+ set lineno(operator) [gdb_get_line_number "operator location" $srcfile]
+ foreach v [array names lineno] {
+ set location($v) ".*[string_to_regexp "$srcfile:$lineno($v)"].*"
+ }
+
+ # A list of explicit linespecs and the corresponding location
+ variable linespecs
+ set linespecs(linespecs) {}
+ set linespecs(location) {}
+
+ add linespecs "-source $srcfile -function myclass::myfunction" \
+ $location(normal)
+ add linespecs "-source $srcfile -function myclass::myfunction -label top" \
+ $location(top)
+
+ # This isn't implemented yet; -line is silently ignored.
+ add linespecs \
+ "-source $srcfile -function myclass::myfunction -label top -line 3" \
+ $location(top)
+ add linespecs "-source $srcfile -line $lineno(top)" $location(top)
+ add linespecs "-function myclass::myfunction" $location(normal)
+ add linespecs "-function myclass::myfunction -label top" $location(top)
+
+ # These are also not yet supported; -line is silently ignored.
+ add linespecs "-function myclass::myfunction -line 3" $location(normal)
+ add linespecs "-function myclass::myfunction -label top -line 3" \
+ $location(top)
+ add linespecs "-line 3" $location(normal)
+ add linespecs "-function myclass::operator," $location(operator)
+ add linespecs "-function 'myclass::operator,'" $location(operator)
+ add linespecs "-function \"myclass::operator,\"" $location(operator)
+
+ # Fire up gdb.
+ if {![runto_main]} {
+ namespace delete $testfile
+ return -1
+ }
+
+ # Test explicit linespecs, with and without conditions.
+ foreach linespec $linespecs(linespecs) loc_pattern $linespecs(locations) {
+ # Test the linespec
+ test_breakpoint $linespec $loc_pattern
+ }
+
+ # Special (orphaned) dprintf cases.
+ gdb_test "dprintf -function myclass::operator,,\"hello\"" \
+ "Dprintf .*$srcfile, line $lineno(operator)\\."
+ gdb_test "dprintf -function 'myclass::operator,',\"hello\"" \
+ "Dprintf .*$srcfile, line $lineno(operator)\\."
+ gdb_test "dprintf -function \"myclass::operator,\",\"hello\"" \
+ "Dprintf .*$srcfile, line $lineno(operator)\\."
+}
+
+namespace delete $testfile
diff --git a/gdb/testsuite/gdb.linespec/explicit.c b/gdb/testsuite/gdb.linespec/explicit.c
new file mode 100644
index 0000000..4e1c635
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/explicit.c
@@ -0,0 +1,56 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2012-2013 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/>. */
+
+extern int myfunction2 (int arg);
+
+static int
+myfunction (int arg)
+{
+ int i, j, r;
+
+ j = 0; /* myfunction location */
+ r = arg;
+
+ top:
+ ++j; /* top location */
+
+ if (j == 10)
+ goto done;
+
+ for (i = 0; i < 10; ++i)
+ {
+ r += i;
+ if (j % 2)
+ goto top;
+ }
+
+ done:
+ return r;
+}
+
+int
+main (void)
+{
+ int i, j;
+
+ /* Call the test function repeatedly, enough times for all our tests
+ without running forever if something goes wrong. */
+ for (i = 0, j = 0; i < 1000; ++i)
+ j += myfunction (0);
+
+ return myfunction2 (j);
+}
diff --git a/gdb/testsuite/gdb.linespec/explicit.exp b/gdb/testsuite/gdb.linespec/explicit.exp
new file mode 100644
index 0000000..344f1b0
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/explicit.exp
@@ -0,0 +1,406 @@
+# Copyright 2012-2015 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/>.
+
+# Tests for explicit locations
+
+standard_testfile explicit.c explicit2.c 3explicit.c
+set exefile $testfile
+
+if {[prepare_for_testing $testfile $exefile \
+ [list $srcfile $srcfile2 $srcfile3] {debug nowarnings}]} {
+ return -1
+}
+
+# Wrap the entire test in a namespace to avoid contaminating other tests.
+namespace eval $testfile {
+
+ # Test the given (explicit) LINESPEC which should cause gdb to break
+ # at LOCATION.
+ proc test_breakpoint {linespec location} {
+
+ set testname "set breakpoint at \"$linespec\""
+ # Delete all breakpoints, set a new breakpoint at LINESPEC,
+ # and attempt to run to it.
+ delete_breakpoints
+ if {[gdb_breakpoint $linespec]} {
+ pass $testname
+ send_log "\nexpecting locpattern \"$location\"\n"
+ gdb_continue_to_breakpoint $linespec $location
+ } else {
+ fail $testname
+ }
+ }
+
+ # Add the given LINESPEC to the array named in THEARRAY. GDB is expected
+ # to stop at LOCATION.
+ proc add {thearray linespec location} {
+ upvar $thearray ar
+
+ lappend ar(linespecs) $linespec
+ lappend ar(locations) $location
+ }
+
+ # A list of all explicit linespec arguments.
+ variable all_arguments
+ set all_arguments {"source" "function" "label" "line"}
+
+ # Some locations used in this test
+ variable lineno
+ variable location
+ set lineno(normal) [gdb_get_line_number "myfunction location" $srcfile]
+ set lineno(top) [gdb_get_line_number "top location" $srcfile]
+ foreach v [array names lineno] {
+ set location($v) ".*[string_to_regexp "$srcfile:$lineno($v)"].*"
+ }
+
+ # A list of explicit locations and the corresponding location.
+ variable linespecs
+ set linespecs(linespecs) {}
+ set linespecs(location) {}
+
+ add linespecs "-source $srcfile -function myfunction" $location(normal)
+ add linespecs "-source $srcfile -function myfunction -label top" \
+ $location(top)
+
+ # This isn't implemented yet; -line is silently ignored.
+ add linespecs "-source $srcfile -function myfunction -label top -line 3" \
+ $location(top)
+ add linespecs "-source $srcfile -line $lineno(top)" $location(top)
+ add linespecs "-function myfunction" $location(normal)
+ add linespecs "-function myfunction -label top" $location(top)
+
+ # These are also not yet supported; -line is silently ignored.
+ add linespecs "-function myfunction -line 3" $location(normal)
+ add linespecs "-function myfunction -label top -line 3" $location(top)
+ add linespecs "-line 3" $location(normal)
+
+ # Test that static tracepoints on marker ID are not interpreted
+ # as an erroneous explicit option.
+ gdb_test "strace -m gdbfoobarbaz" "You can't do that.*"
+
+ # Fire up gdb.
+ if {![runto_main]} {
+ return -1
+ }
+
+ # Turn off queries
+ gdb_test_no_output "set confirm off"
+
+ # Simple error tests (many more are tested in ls-err.exp)
+ foreach arg $all_arguments {
+ # Test missing argument
+ gdb_test "break -$arg" \
+ [string_to_regexp "missing argument for \"-$arg\""]
+
+ # Test abbreviations
+ set short [string range $arg 0 3]
+ gdb_test "break -$short" \
+ [string_to_regexp "missing argument for \"-$short\""]
+ }
+
+ # Test invalid arguments
+ foreach arg {"-foo" "-foo bar" "-function myfunction -foo" \
+ "-function -myfunction -foo bar"} {
+ gdb_test "break $arg" \
+ [string_to_regexp "invalid explicit location argument, \"-foo\""]
+ }
+
+ # Test explicit locations, with and without conditions.
+ # For these tests, it is easiest to turn of pending breakpoint.
+ gdb_test_no_output "set breakpoint pending off" \
+ "turn off pending breakpoints"
+
+ foreach linespec $linespecs(linespecs) loc_pattern $linespecs(locations) {
+
+ # Test the linespec
+ test_breakpoint $linespec $loc_pattern
+
+ # Test with a valid condition
+ delete_breakpoints
+ set tst "set breakpoint at \"$linespec\" with valid condition"
+ if {[gdb_breakpoint "$linespec if arg == 0"]} {
+ pass $tst
+
+ gdb_test "info break" ".*stop only if arg == 0.*" \
+ "info break of conditional breakpoint at \"$linespec\""
+ } else {
+ fail $tst
+ }
+
+ # Test with invalid condition
+ gdb_test "break $linespec if foofoofoo == 1" \
+ ".*No symbol \"foofoofoo\" in current context.*" \
+ "set breakpoint at \"$linespec\" with invalid condition"
+
+ # Test with thread
+ delete_breakpoints
+ gdb_test "break $linespec thread 123" "Unknown thread 123."
+ }
+
+ # Test the explicit location completer
+ foreach abbrev {"fun" "so" "lab" "li"} full {"function" "source" "label" "line"} {
+ set tst "complete 'break -$abbrev'"
+ send_gdb "break -${abbrev}\t"
+ gdb_test_multiple "" $tst {
+ "break -$full " {
+ send_gdb "\n"
+ gdb_test_multiple "" $tst {
+ -re "missing argument for \"-$full\".*$gdb_prompt " {
+ pass $tst
+ }
+ }
+ }
+ }
+ set tst "complete -$full with no value"
+ send_gdb "break -$full \t"
+ gdb_test_multiple "" $tst {
+ -re ".*break -$full " {
+ send_gdb "\n"
+ gdb_test_multiple "" $tst {
+ -re ".*Source filename requires function, label, or line offset\..*$gdb_prompt " {
+ if {[string equal $full "source"]} {
+ pass $tst
+ } else {
+ faill $tst
+ }
+ }
+ -re "missing argument for \"-$full\".*$gdb_prompt " {
+ pass $tst
+ }
+ }
+ }
+ }
+ }
+
+ set tst "complete unique function name"
+ send_gdb "break -function mai\t"
+ gdb_test_multiple "" $tst {
+ "break -function mai\\\x07n" {
+ send_gdb "\n"
+ gdb_test "" ".*Breakpoint \[0-9\]+.*" $tst
+ gdb_test_no_output "delete \$bpnum" "delete $tst breakpoint"
+ }
+ }
+
+ set tst "complete non-unique function name"
+ send_gdb "break -function myfunc\t"
+ gdb_test_multiple "" $tst {
+ "break -function myfunc\\\x07tion" {
+ send_gdb "\t\t"
+ gdb_test_multiple "" $tst {
+ -re "\\\x07\r\nmyfunction\[ \t\]+myfunction2\[ \t\]+myfunction3\[ \t\]+myfunction4\[ \t\]+\r\n$gdb_prompt " {
+ gdb_test "2" ".*Breakpoint \[0-9\]+.*" $tst
+ gdb_test_no_output "delete \$bpnum" "delete $tst breakpoint"
+ }
+ }
+ }
+ }
+
+ set tst "complete non-existant function name"
+ send_gdb "break -function foo\t"
+ gdb_test_multiple "" $tst {
+ "break -function foo\\\x07" {
+ send_gdb "\t\t"
+ gdb_test_multiple "" $tst {
+ -re "\\\x07\\\x07" {
+ send_gdb "\n"
+ gdb_test "" {Function "foo" not defined.} $tst
+ }
+ }
+ }
+ }
+
+ set tst "complete unique file name"
+ send_gdb "break -source 3ex\t"
+ gdb_test_multiple "" $tst {
+ "break -source 3explicit.c " {
+ send_gdb "\n"
+ gdb_test "" \
+ {Source filename requires function, label, or line offset.} $tst
+ }
+ }
+
+ set tst "complete non-unique file name"
+ send_gdb "break -source exp\t"
+ gdb_test_multiple "" $tst {
+ "break -source exp\\\x07licit" {
+ send_gdb "\t\t"
+ gdb_test_multiple "" $tst {
+ -re "\\\x07\r\nexplicit.c\[ \t\]+explicit2.c\[ \t\]+\r\n$gdb_prompt" {
+ send_gdb "\n"
+ gdb_test "" \
+ {Source filename requires function, label, or line offset.} \
+ $tst
+ }
+ }
+ }
+
+ "break -source exp\\\x07l" {
+ # This pattern may occur when glibc debuginfo is installed.
+ send_gdb "\t\t"
+ gdb_test_multiple "" $tst {
+ -re "\\\x07\r\nexplicit.c\[ \t\]+explicit2.c\[ \t\]+expl.*\r\n$gdb_prompt" {
+ send_gdb "\n"
+ gdb_test "" \
+ {Source filename requires function, label, or line offset.} \
+ $tst
+ }
+ }
+ }
+ }
+
+ set tst "complete non-existant file name"
+ send_gdb "break -source foo\t"
+ gdb_test_multiple "" $tst {
+ "break -source foo" {
+ send_gdb "\t\t"
+ gdb_test_multiple "" $tst {
+ "\\\x07\\\x07" {
+ send_gdb "\n"
+ gdb_test "" \
+ {Source filename requires function, label, or line offset.} \
+ $tst
+ }
+ }
+ }
+ }
+
+ set tst "complete filename and unique function name"
+ send_gdb "break -source explicit.c -function ma\t"
+ gdb_test_multiple "" $tst {
+ "break -source explicit.c -function main " {
+ send_gdb "\n"
+ gdb_test "" ".*Breakpoint .*" $tst
+ gdb_test_no_output "delete \$bpnum" "delete $tst breakpoint"
+ }
+ }
+
+ set tst "complete filename and non-unique function name"
+ send_gdb "break -so 3explicit.c -func myfunc\t"
+ gdb_test_multiple "" $tst {
+ "break -so 3explicit.c -func myfunc\\\x07tion" {
+ send_gdb "\t\t"
+ gdb_test_multiple "" $tst {
+ -re "\\\x07\r\nmyfunction3\[ \t\]+myfunction4\[ \t\]+\r\n$gdb_prompt " {
+ gdb_test "3" ".*Breakpoint \[0-9\]+.*" $tst
+ gdb_test_no_output "delete \$bpnum" "delete $tst breakpoint"
+ }
+ }
+ }
+ }
+
+ set tst "complete filename and non-existant function name"
+ send_gdb "break -sou 3explicit.c -fun foo\t"
+ gdb_test_multiple "" $tst {
+ "break -sou 3explicit.c -fun foo\\\x07" {
+ send_gdb "\t\t"
+ gdb_test_multiple "" $tst {
+ "\\\x07\\\x07" {
+ send_gdb "\n"
+ gdb_test "" \
+ {Function "foo" not defined in "3explicit.c".} $tst
+ }
+ }
+ }
+ }
+
+ set tst "complete filename and function reversed"
+ send_gdb "break -func myfunction4 -source 3ex\t"
+ gdb_test_multiple "" $tst {
+ "break -func myfunction4 -source 3explicit.c " {
+ send_gdb "\n"
+ gdb_test "" "Breakpoint \[0-9\]+.*" $tst
+ gdb_test_no_output "delete \$bpnum" "delete $tst breakpoint"
+ }
+ }
+
+ # 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.
+
+ # Test pending explicit breakpoints
+ gdb_exit
+ gdb_start
+
+ set tst "pending invalid conditional explicit breakpoint"
+ if {![gdb_breakpoint "-func myfunction if foofoofoo == 1" \
+ allow-pending]} {
+ fail "set $tst"
+ } else {
+ gdb_test "info break" ".*PENDING.*myfunction if foofoofoo == 1.*" $tst
+ }
+
+ gdb_exit
+ gdb_start
+
+ set tst "pending valid conditional explicit breakpoint"
+ if {![gdb_breakpoint "-func myfunction if arg == 0" \
+ allow-pending]} {
+ fail "set $tst"
+ } else {
+ gdb_test "info break" ".*PENDING.*myfunction if arg == 0" $tst
+
+ gdb_load [standard_output_file $exefile]
+ gdb_test "info break" \
+ ".*in myfunction at .*$srcfile:.*stop only if arg == 0.*" \
+ "$tst resolved"
+ }
+
+ # Test interaction of condition command and explicit linespec conditons.
+ gdb_exit
+ gdb_start
+ gdb_load [standard_output_file $exefile]
+
+ set tst "condition_command overrides explicit linespec condition"
+ if {![runto main]} {
+ fail $tst
+ } else {
+ if {![gdb_breakpoint "-func myfunction if arg == 1"]} {
+ fail "set breakpoint with condition 'arg == 1'"
+ } else {
+ gdb_test_no_output "cond 2 arg == 0" \
+ "set new breakpoint condition for explicit linespec"
+
+ gdb_continue_to_breakpoint $tst $location(normal)
+ }
+ }
+
+ gdb_test "cond 2" [string_to_regexp "Breakpoint 2 now unconditional."] \
+ "clear condition for explicit breakpoint"
+ set tst "info break of cleared condition of explicit breakpoint"
+ gdb_test_multiple "info break" $tst {
+ -re ".*in myfunction at .*$srcfile:.*stop only if arg == 0.*" {
+ fail $tst
+ }
+ -re ".*in myfunction at .*$srcfile:.*$gdb_prompt $" {
+ pass $tst
+ }
+ }
+
+ # Test explicit "ranges." Make sure that using explicit
+ # locations doesn't alter the expected outcome.
+ gdb_test "list main" ".*" "list main 1"
+ set list_result [capture_command_output "list -,+" ""]
+ gdb_test "list main" ".*" "list main 2"
+ gdb_test "list -line -,-line +" [string_to_regexp $list_result]
+
+ # Ditto for the reverse (except that no output is expected).
+ gdb_test "list myfunction" ".*" "list myfunction 1"
+ gdb_test_no_output "list +,-"
+ gdb_test "list myfunction" ".*" "list myfunction 2"
+ gdb_test_no_output "list -line +, -line -"
+}
+
+namespace delete $testfile
diff --git a/gdb/testsuite/gdb.linespec/explicit2.c b/gdb/testsuite/gdb.linespec/explicit2.c
new file mode 100644
index 0000000..218cccb
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/explicit2.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2013 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/>. */
+
+extern int myfunction3 (int arg);
+
+int
+myfunction2 (int arg)
+{
+ return myfunction3 (arg);
+}
diff --git a/gdb/testsuite/gdb.linespec/ls-errs.exp b/gdb/testsuite/gdb.linespec/ls-errs.exp
index 019312c..9b30720 100644
--- a/gdb/testsuite/gdb.linespec/ls-errs.exp
+++ b/gdb/testsuite/gdb.linespec/ls-errs.exp
@@ -49,11 +49,16 @@ array set error_messages {
invalid_var_or_func_f \
"Undefined convenience variable or function \"%s\" not defined in \"%s\"."
invalid_label "No label \"%s\" defined in function \"%s\"."
+ invalid_parm "invalid linespec argument, \"%s\""
invalid_offset "No line %d in the current file."
invalid_offset_f "No line %d in file \"%s\"."
+ malformed_line_offset "malformed line offset: \"%s\""
+ source_incomplete \
+ "Source filename requires function, label, or line offset."
unexpected "malformed linespec error: unexpected %s"
unexpected_opt "malformed linespec error: unexpected %s, \"%s\""
unmatched_quote "unmatched quote"
+ garbage "Garbage '%s' at end of command"
}
# Some commonly used whitespace tests around ':'.
@@ -80,6 +85,7 @@ foreach x $invalid_offsets {
incr offset 16
}
test_break $x invalid_offset $offset
+ test_break "-line $x" invalid_offset $offset
}
# Test offsets with trailing tokens w/ and w/o spaces.
@@ -91,13 +97,17 @@ foreach x $spaces {
foreach x {1 +1 +100 -10} {
test_break "3 $x" unexpected_opt "number" $x
+ test_break "-line 3 $x" garbage $x
test_break "+10 $x" unexpected_opt "number" $x
+ test_break "-line +10 $x" garbage $x
test_break "-10 $x" unexpected_opt "number" $x
+ test_break "-line -10 $x" garbage $x
}
-test_break "3 foo" unexpected_opt "string" "foo"
-test_break "+10 foo" unexpected_opt "string" "foo"
-test_break "-10 foo" unexpected_opt "string" "foo"
+foreach x {3 +10 -10} {
+ test_break "$x foo" unexpected_opt "string" "foo"
+ test_break "-line $x foo" garbage "foo"
+}
# Test invalid linespecs starting with filename.
foreach x [list "this_file_doesn't_exist.c" \
@@ -113,6 +123,25 @@ foreach x [list "this_file_doesn't_exist.c" \
# Remove any quoting from FILENAME for the error message.
test_break "$x:3" invalid_file [string trim $x \"']
}
+foreach x [list "this_file_doesn't_exist.c" \
+ "file::colons.c" \
+ "'file::colons.c'"] {
+ test_break "-source $x -line 3" \
+ invalid_file [string trim $x \"']
+}
+
+# Test that option lexing stops at whitespace boundaries
+test_break "-source this file has spaces.c -line 3" \
+ invalid_file "this"
+
+test_break "-function function whitespace" \
+ invalid_function "function"
+
+test_break "-source $srcfile -function function whitespace" \
+ invalid_function_f "function" $srcfile
+
+test_break "-function main -label label whitespace" \
+ invalid_label "label" "main"
# Test unmatched quotes.
foreach x {"\"src-file.c'" "'src-file.c"} {
@@ -123,7 +152,11 @@ test_break $srcfile invalid_function $srcfile
foreach x {"foo" " foo" " foo "} {
# Trim any leading/trailing whitespace for error messages.
test_break "$srcfile:$x" invalid_function_f [string trim $x] $srcfile
+ test_break "-source $srcfile -function $x" \
+ invalid_function_f [string trim $x] $srcfile
test_break "$srcfile:main:$x" invalid_label [string trim $x] "main"
+ test_break "-source $srcfile -function main -label $x" \
+ invalid_label [string trim $x] "main"
}
foreach x $spaces {
@@ -133,20 +166,26 @@ foreach x $spaces {
test_break "${srcfile}::" invalid_function "${srcfile}::"
test_break "$srcfile:3 1" unexpected_opt "number" "1"
+test_break "-source $srcfile -line 3 1" garbage "1"
test_break "$srcfile:3 +100" unexpected_opt "number" "+100"
+test_break "-source $srcfile -line 3 +100" garbage "+100"
test_break "$srcfile:3 -100" unexpected_opt "number" "-100"
test_break "$srcfile:3 foo" unexpected_opt "string" "foo"
+test_break "-source $srcfile -line 3 foo" garbage "foo"
foreach x $invalid_offsets {
test_break "$srcfile:$x" invalid_offset_f $x $srcfile
test_break "\"$srcfile:$x\"" invalid_offset_f $x $srcfile
test_break "'$srcfile:$x'" invalid_offset_f $x $srcfile
+ test_break "-source $srcfile -line $x" invalid_offset_f $x $srcfile
}
+test_break "-source $srcfile -line -x" malformed_line_offset "-x"
# Test invalid filespecs starting with function.
foreach x {"foobar" "foo::bar" "foo.bar" "foo ." "foo bar" "foo 1" \
"foo 0" "foo +10" "foo -10" "foo +100" "foo -100"} {
test_break $x invalid_function $x
+ test_break "-function \"$x\"" invalid_function $x
}
foreach x $spaces {
@@ -155,13 +194,12 @@ foreach x $spaces {
test_break "main:here${x}" unexpected "end of input"
}
-test_break "main 3" invalid_function "main 3"
-test_break "main +100" invalid_function "main +100"
-test_break "main -100" invalid_function "main -100"
-test_break "main foo" invalid_function "main foo"
-
foreach x {"3" "+100" "-100" "foo"} {
+ test_break "main 3" invalid_function "main 3"
+ test_break "-function \"main $x\"" invalid_function "main $x"
test_break "main:here $x" invalid_label "here $x" "main"
+ test_break "-function main -label \"here $x\"" \
+ invalid_label "here $x" "main"
}
foreach x {"if" "task" "thread"} {
@@ -178,3 +216,6 @@ test_break "'main.c'+3" unexpected_opt "number" "+3"
set x {$zippo}
test_break $x invalid_var_or_func $x
test_break "$srcfile:$x" invalid_var_or_func_f $x $srcfile
+
+# Explicit linespec-specific tests
+test_break "-source $srcfile" source_incomplete