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.
This commit is contained in:
Pedro Alves
2017-09-04 16:49:29 +01:00
parent 7525b645df
commit e439fa140a
7 changed files with 203 additions and 8 deletions
+30 -7
View File
@@ -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),