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.
+
+2017-09-20 Pedro Alves <palves@redhat.com>
+
* linespec.c (minsym_found): Handle non-text minsyms.
(symbol_to_sal): Record a sal.pc for non-block, non-label symbols.
/* 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);
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 (),
}
}
\f
+/* 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
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
{
*result = {};
result->symtab = symbol_symtab (sym);
+ result->symbol = sym;
result->line = SYMBOL_LINE (sym);
result->pc = SYMBOL_VALUE_ADDRESS (sym);
result->pspace = SYMTAB_PSPACE (result->symtab);
/* We know its line number. */
*result = {};
result->symtab = symbol_symtab (sym);
+ result->symbol = sym;
result->line = SYMBOL_LINE (sym);
result->pc = SYMBOL_VALUE_ADDRESS (sym);
result->pspace = SYMTAB_PSPACE (result->symtab);
obj_section *section = SYMBOL_OBJ_SECTION (symbol_objfile (sym), sym);
symtab_and_line sal
= find_pc_sect_line (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), section, 0);
+ sal.symbol = sym;
if (funfirstline && sal.symtab != NULL
&& (COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal.symtab))
sal.pspace = current_program_space;
sal.pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
sal.section = section;
+ sal.symbol = sym;
}
if (funfirstline)
struct program_space *pspace = NULL;
struct symtab *symtab = NULL;
+ struct symbol *symbol = NULL;
struct obj_section *section = NULL;
/* Line number. Line numbers start at 1 and proceed through symtab->nlines.
0 is never a valid line number; it is used to indicate that line number
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.
+
+2017-09-20 Pedro Alves <palves@redhat.com>
+
* gdb.base/list-ambiguous.exp (test_list_ambiguous_function):
Rename to ...
(test_list_ambiguous_symbol): ... this and add a symbol name
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"
+ set h0_re "file: \"${any}list-ambiguous0.c\", line number: $lineno0, symbol: \"$symbol\""
+ set h1_re "file: \"${any}list-ambiguous1.c\", line number: $lineno1, symbol: \"$symbol\""
gdb_test "list $symbol" "${h0_re}${lines0_re}\r\n${h1_re}${lines1_re}"
gdb_test "list main,$symbol" \
set lines2 [line_range_pattern [expr $line_bar_B - 5] [expr $line_bar_B + 4]]
set any "\[^\r\n\]*"
- set h1_re "file: \"${any}overload.cc\", line number: $line_bar_A"
- set h2_re "file: \"${any}overload.cc\", line number: $line_bar_B"
+ set h1_re "file: \"${any}overload.cc\", line number: $line_bar_A, symbol: \"bar\\(A\\)\""
+ set h2_re "file: \"${any}overload.cc\", line number: $line_bar_B, symbol: \"bar\\(B\\)\""
gdb_test "list bar" "${h1_re}${lines1}\r\n${h2_re}${lines2}"
}