aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-09-20 16:12:54 +0100
committerPedro Alves <palves@redhat.com>2017-09-20 16:21:26 +0100
commit06871ae84096ed1672eb76f44cea4d5dbe79ae24 (patch)
treee08ebe280efb9b5ebf2bd9055a3d8b1423762d6a /gdb/cli
parente5f25bc5d6dba5a5c4dd36e08afd57e918c63dea (diff)
downloadgdb-06871ae84096ed1672eb76f44cea4d5dbe79ae24.zip
gdb-06871ae84096ed1672eb76f44cea4d5dbe79ae24.tar.gz
gdb-06871ae84096ed1672eb76f44cea4d5dbe79ae24.tar.bz2
Make "list ambiguous" show symbol names too
Currently, with an ambiguous "list first,last", we get: (gdb) list bar,main Specified first line 'bar' is ambiguous: file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97 file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98 This commit makes gdb's output above a bit clearer by printing the symbol name as well: (gdb) list bar,main Specified first line 'bar' is ambiguous: file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97, symbol: "bar(A)" file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98, symbol: "bar(B)" And while at it, makes gdb print the symbol name when actually listing multiple locations too. I.e., before (with "set listsize 2"): (gdb) list bar file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97 96 97 int bar (A) { return 11; } file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98 97 int bar (A) { return 11; } 98 int bar (B) { return 22; } After: (gdb) list bar file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97, symbol: "bar(A)" 96 97 int bar (A) { return 11; } file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98, symbol: "bar(B)" 97 int bar (A) { return 11; } 98 int bar (B) { return 22; } Currently, the result of decoding a linespec loses information about the original symbol that was found. All we end up with is an address. This makes it difficult to find the original symbol again to get at its print name. Fix that by storing a pointer to the symbol in the sal. We already store the symtab and obj_section, so it feels like a natural progression to me. This avoids having to do any extra symbol lookup too. gdb/ChangeLog: 2017-09-20 Pedro Alves <palves@redhat.com> * cli/cli-cmds.c (list_command): Use print_sal_location. (print_sal_location): New function. (ambiguous_line_spec): Use print_sal_location. * linespec.c (symbol_to_sal): Record the symbol in the sal. * symtab.c (find_function_start_sal): Likewise. * symtab.h (symtab_and_line::symbol): New field. gdb/testsuite/ChangeLog: 2017-09-20 Pedro Alves <palves@redhat.com> * gdb.base/list-ambiguous.exp (test_list_ambiguous_symbol): Expect symbol names in gdb's output. * gdb.cp/overload.exp ("list all overloads"): Likewise.
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-cmds.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 883844e..260fd3f 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -90,6 +90,8 @@ static void list_command (char *, int);
/* Prototypes for local utility functions */
+static void print_sal_location (const symtab_and_line &sal);
+
static void ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals,
const char *format, ...)
ATTRIBUTE_PRINTF (2, 3);
@@ -1094,11 +1096,7 @@ list_command (char *arg, int from_tty)
if (first_line < 1)
first_line = 1;
if (sals.size () > 1)
- {
- printf_filtered (_("file: \"%s\", line number: %d\n"),
- symtab_to_filename_for_display (sal.symtab),
- sal.line);
- }
+ print_sal_location (sal);
print_source_lines (sal.symtab,
first_line,
first_line + get_lines_to_list (),
@@ -1516,6 +1514,23 @@ alias_command (char *args, int from_tty)
}
}
+/* Print the file / line number / symbol name of the location
+ specified by SAL. */
+
+static void
+print_sal_location (const symtab_and_line &sal)
+{
+ scoped_restore_current_program_space restore_pspace;
+ set_current_program_space (sal.pspace);
+
+ const char *sym_name = NULL;
+ if (sal.symbol != NULL)
+ sym_name = SYMBOL_PRINT_NAME (sal.symbol);
+ printf_filtered (_("file: \"%s\", line number: %d, symbol: \"%s\"\n"),
+ symtab_to_filename_for_display (sal.symtab),
+ sal.line, sym_name != NULL ? sym_name : "???");
+}
+
/* 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 SALS
@@ -1533,9 +1548,7 @@ ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals,
va_end (ap);
for (const auto &sal : sals)
- printf_filtered (_("file: \"%s\", line number: %d\n"),
- symtab_to_filename_for_display (sal.symtab),
- sal.line);
+ print_sal_location (sal);
}
/* Comparison function for filter_sals. Returns a qsort-style