diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a70fb7b5b3..2d12899746 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2017-09-04 Pedro Alves + + * 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. + 2017-09-04 Pedro Alves * btrace.c (ftrace_add_pt): Pass btrace_insn to diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 8221747ae4..01ae88e4e4 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -90,7 +90,9 @@ static void list_command (char *, int); /* Prototypes for local utility functions */ -static void ambiguous_line_spec (struct symtabs_and_lines *); +static void ambiguous_line_spec (struct symtabs_and_lines *, + const char *format, ...) + ATTRIBUTE_PRINTF (2, 3); static void filter_sals (struct symtabs_and_lines *); @@ -825,7 +827,8 @@ edit_command (char *arg, int from_tty) } if (sals.nelts > 1) { - ambiguous_line_spec (&sals); + ambiguous_line_spec (&sals, + _("Specified line is ambiguous:\n")); xfree (sals.sals); return; } @@ -980,6 +983,11 @@ list_command (char *arg, int from_tty) for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; p++); linenum_beg = (p == arg1); + /* Save the range of the first argument, in case we need to let the + user know it was ambiguous. */ + const char *beg = arg; + size_t beg_len = arg1 - beg; + while (*arg1 == ' ' || *arg1 == '\t') arg1++; if (*arg1 == ',') @@ -987,7 +995,9 @@ list_command (char *arg, int from_tty) no_end = 0; if (sals.nelts > 1) { - ambiguous_line_spec (&sals); + ambiguous_line_spec (&sals, + _("Specified first line '%.*s' is ambiguous:\n"), + (int) beg_len, beg); xfree (sals.sals); return; } @@ -998,6 +1008,10 @@ list_command (char *arg, int from_tty) dummy_end = 1; else { + /* Save the last argument, in case we need to let the user + know it was ambiguous. */ + const char *end_arg = arg1; + event_location_up location = string_to_event_location (&arg1, current_language); if (dummy_beg) @@ -1015,7 +1029,9 @@ list_command (char *arg, int from_tty) } if (sals_end.nelts > 1) { - ambiguous_line_spec (&sals_end); + ambiguous_line_spec (&sals_end, + _("Specified last line '%s' is ambiguous:\n"), + end_arg); xfree (sals_end.sals); xfree (sals.sals); return; @@ -1030,7 +1046,7 @@ list_command (char *arg, int from_tty) if (!no_end && !dummy_beg && !dummy_end && sal.symtab != sal_end.symtab) - error (_("Specified start and end are in different files.")); + error (_("Specified first and last lines are in different files.")); if (dummy_beg && dummy_end) error (_("Two empty args do not say what lines to list.")); @@ -1515,13 +1531,20 @@ alias_command (char *args, int from_tty) /* Print a list of files and line numbers which a user may choose from in order to list a function which was specified ambiguously (as with `list classname::overloadedfuncname', for example). The - vector in SALS provides the filenames and line numbers. */ + vector in SALS provides the filenames and line numbers. FORMAT is + a printf-style format string used to tell the user what was + ambiguous. */ static void -ambiguous_line_spec (struct symtabs_and_lines *sals) +ambiguous_line_spec (struct symtabs_and_lines *sals, const char *format, ...) { int i; + va_list ap; + va_start (ap, format); + vprintf_filtered (format, ap); + va_end (ap); + for (i = 0; i < sals->nelts; ++i) printf_filtered (_("file: \"%s\", line number: %d\n"), symtab_to_filename_for_display (sals->sals[i].symtab), diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index c15743b309..5943b63691 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2017-09-04 Pedro Alves + + * 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 * 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 0000000000..db9d028453 --- /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 . + +# 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 0000000000..91f7fe968c --- /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 . */ + + + + + +/* 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 0000000000..024299aa94 --- /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 . */ + + + + + + + + + +/* 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 53775719d0..d554c9e607 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" } #