summaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-09-04 16:49:29 +0100
committerPedro Alves <palves@redhat.com>2017-09-04 16:49:29 +0100
commite439fa140afdaedb28a97acaa2b0432b884d8a91 (patch)
tree93a1682af136319ce89647a5186295ccc0feb1f9 /gdb/testsuite
parent7525b645dfaa302091591d0f87d9682ce988ed13 (diff)
downloadbinutils-gdb-e439fa140afdaedb28a97acaa2b0432b884d8a91.tar.gz
Clarify "list" output when specified lines are ambiguous
Currently, with "list LINESPEC1,LINESPEC2", if one of the linespecs is ambiguous, i.e., if it expands to multiple locations, you get this seemingly odd output: (gdb) list foo,bar file: "file0.c", line number: 26 file: "file1.c", line number: 29 Since "foo" above expands to multiple locations, the specified range is indeterminate, and GDB is trying to be helpful by showing you what was ambiguous. It looks confusing to me, though. I think it'd be much more user friendly if GDB actually told you that, like this: (gdb) list foo,bar Specified first line 'foo' is ambiguous: file: "file0.c", line number: 26 file: "file1.c", line number: 29 (gdb) list bar,foo Specified last line 'foo' is ambiguous: file: "file0.c", line number: 26 file: "file1.c", line number: 29 Note, I'm using "first" and "last" in the output because that's what the manual uses: ~~~ list first,last Print lines from first to last. [...] ~~~ Tested on x86-64 GNU/Linux. gdb/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * cli/cli-cmds.c (edit_command): Pass message to ambiguous_line_spec. (list_command): Pass message to ambiguous_line_spec. Say "first"/"last" instead of "start" and "end" to be consistent with the manual. (ambiguous_line_spec): Add 'format' and vararg parameters. Use them to print formatted message. gdb/testsuite/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * gdb.base/list-ambiguous.exp: New file. * gdb.base/list-ambiguous0.c: New file. * gdb.base/list-ambiguous1.c: New file. * gdb.base/list.exp (test_list_range): Adjust expected output.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog7
-rw-r--r--gdb/testsuite/gdb.base/list-ambiguous.exp74
-rw-r--r--gdb/testsuite/gdb.base/list-ambiguous0.c41
-rw-r--r--gdb/testsuite/gdb.base/list-ambiguous1.c40
-rw-r--r--gdb/testsuite/gdb.base/list.exp2
5 files changed, 163 insertions, 1 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c15743b3091..5943b636911 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2017-09-04 Pedro Alves <palves@redhat.com>
+
+ * gdb.base/list-ambiguous.exp: New file.
+ * gdb.base/list-ambiguous0.c: New file.
+ * gdb.base/list-ambiguous1.c: New file.
+ * gdb.base/list.exp (test_list_range): Adjust expected output.
+
2017-08-31 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/share-env-with-gdbserver.c: New file.
diff --git a/gdb/testsuite/gdb.base/list-ambiguous.exp b/gdb/testsuite/gdb.base/list-ambiguous.exp
new file mode 100644
index 00000000000..db9d0284534
--- /dev/null
+++ b/gdb/testsuite/gdb.base/list-ambiguous.exp
@@ -0,0 +1,74 @@
+# 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/>.
+
+# Test the "list" command with linespecs that expand to multiple
+# locations.
+
+standard_testfile list-ambiguous0.c list-ambiguous1.c
+
+if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $srcfile2] \
+ {debug}]} {
+ return -1
+}
+
+# Build source listing pattern based on an inclusive line range.
+
+proc line_range_pattern { range_start range_end } {
+ global line_re
+
+ for {set i $range_start} {$i <= $range_end} {incr i} {
+ append pattern "\r\n$i\[ \t\]\[^\r\n\]*"
+ }
+
+ verbose -log "pattern $pattern"
+ return $pattern
+}
+
+# Test the "list" command with linespecs that expand to multiple
+# locations.
+
+proc test_list_ambiguous_function {} {
+ global srcfile srcfile2
+
+ set lineno0 [gdb_get_line_number "ambiguous (void)" $srcfile]
+ set lineno1 [gdb_get_line_number "ambiguous (void)" $srcfile2]
+ set lines0_re [line_range_pattern [expr $lineno0 - 5] [expr $lineno0 + 4]]
+ set lines1_re [line_range_pattern [expr $lineno1 - 5] [expr $lineno1 + 4]]
+
+ set any "\[^\r\n\]*"
+ set h0_re "file: \"${any}list-ambiguous0.c\", line number: $lineno0"
+ set h1_re "file: \"${any}list-ambiguous1.c\", line number: $lineno1"
+ gdb_test "list ambiguous" "${h0_re}${lines0_re}\r\n${h1_re}${lines1_re}"
+
+ gdb_test "list main,ambiguous" \
+ "Specified last line 'ambiguous' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+ gdb_test "list ,ambiguous" \
+ "Specified last line 'ambiguous' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+ gdb_test "list ambiguous,main" \
+ "Specified first line 'ambiguous' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+ gdb_test "list ambiguous,ambiguous" \
+ "Specified first line 'ambiguous' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+ gdb_test "list ambiguous," \
+ "Specified first line 'ambiguous' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+
+ # While at it, test the "edit" command as well, since it shares
+ # code with "list".
+ gdb_test "edit ambiguous" \
+ "Specified line is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+}
+
+gdb_test_no_output "set listsize 10"
+
+test_list_ambiguous_function
diff --git a/gdb/testsuite/gdb.base/list-ambiguous0.c b/gdb/testsuite/gdb.base/list-ambiguous0.c
new file mode 100644
index 00000000000..91f7fe968cd
--- /dev/null
+++ b/gdb/testsuite/gdb.base/list-ambiguous0.c
@@ -0,0 +1,41 @@
+/* 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/>. */
+
+
+
+
+
+/* This function is defined in both
+ list-ambiguous0.c/list-ambiguous1.c files, in order to test
+ "list"'s behavior with ambiguous linespecs. */
+
+static void __attribute__ ((used)) ambiguous (void) {}
+
+
+
+
+
+
+
+
+
+
+int
+main (void)
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/list-ambiguous1.c b/gdb/testsuite/gdb.base/list-ambiguous1.c
new file mode 100644
index 00000000000..024299aa943
--- /dev/null
+++ b/gdb/testsuite/gdb.base/list-ambiguous1.c
@@ -0,0 +1,40 @@
+/* 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/>. */
+
+
+
+
+
+
+
+
+
+/* This function is defined in both
+ list-ambiguous0.c/list-ambiguous1.c files, in order to test
+ "list"'s behavior with ambiguous linespecs. */
+static void __attribute__ ((used)) ambiguous (void) {}
+
+
+
+
+
+
+
+
+
+
+/* last line */
diff --git a/gdb/testsuite/gdb.base/list.exp b/gdb/testsuite/gdb.base/list.exp
index 53775719d0f..d554c9e607f 100644
--- a/gdb/testsuite/gdb.base/list.exp
+++ b/gdb/testsuite/gdb.base/list.exp
@@ -361,7 +361,7 @@ proc test_list_range {} {
gdb_test "list ${past_end},${much_past_end}" "Line number ${past_end} out of range; .*list0.c has ${last_line} lines." "list range; both bounds past EOF"
- gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
+ gdb_test "list list0.c:2,list1.c:17" "Specified first and last lines are in different files." "list range, must be same files"
}
#