Andrew Burgess pointed out a regression, which he described in
PR symtab/26270:
================
After commit:
commit
bcfe6157ca288efed127c5efe21ad7924e0d98cf (refs/bisect/bad)
Date: Fri Apr 24 15:35:01 2020 -0600
Use the linkage name if it exists
The disassembler no longer demangles function names in its output. So
we see things like this:
(gdb) disassemble tree_insert
Dump of assembler code for function _Z11tree_insertP4nodei:
....
Instead of this:
(gdb) disassemble tree_insert
Dump of assembler code for function tree_insert(node*, int):
....
This is because find_pc_partial_function now returns the linkage name
rather than the demangled name.
================
This patch fixes the problem by introducing a new "overload" of
find_pc_partial_function, which returns the general_symbol_info rather
than simply the name. This lets the disassemble command choose which
name to show.
Regression tested on x86-64 Fedora 32.
gdb/ChangeLog
2020-07-28 Tom Tromey <tromey@adacore.com>
PR symtab/26270:
* symtab.h (find_pc_partial_function_sym): Declare.
* cli/cli-cmds.c (disassemble_command): Use
find_pc_partial_function_sym. Check asm_demangle.
* blockframe.c (cache_pc_function_sym): New global.
(cache_pc_function_name): Remove.
(clear_pc_function_cache): Update.
(find_pc_partial_function_sym): New function, from
find_pc_partial_function.
(find_pc_partial_function): Rewrite using
find_pc_partial_function_sym.
gdb/testsuite/ChangeLog
2020-07-28 Andrew Burgess <andrew.burgess@embecosm.com>
PR symtab/26270:
* gdb.cp/disasm-func-name.cc: New file.
* gdb.cp/disasm-func-name.exp: New file.
+2020-07-28 Tom Tromey <tromey@adacore.com>
+
+ PR symtab/26270:
+ * symtab.h (find_pc_partial_function_sym): Declare.
+ * cli/cli-cmds.c (disassemble_command): Use
+ find_pc_partial_function_sym. Check asm_demangle.
+ * blockframe.c (cache_pc_function_sym): New global.
+ (cache_pc_function_name): Remove.
+ (clear_pc_function_cache): Update.
+ (find_pc_partial_function_sym): New function, from
+ find_pc_partial_function.
+ (find_pc_partial_function): Rewrite using
+ find_pc_partial_function_sym.
+
2020-07-28 Tom Tromey <tromey@adacore.com>
* cli/cli-cmds.c (_initialize_cli_cmds): Rearrange "disassemble"
static CORE_ADDR cache_pc_function_low = 0;
static CORE_ADDR cache_pc_function_high = 0;
-static const char *cache_pc_function_name = 0;
+static const general_symbol_info *cache_pc_function_sym = nullptr;
static struct obj_section *cache_pc_function_section = NULL;
static const struct block *cache_pc_function_block = nullptr;
{
cache_pc_function_low = 0;
cache_pc_function_high = 0;
- cache_pc_function_name = (char *) 0;
+ cache_pc_function_sym = nullptr;
cache_pc_function_section = NULL;
cache_pc_function_block = nullptr;
}
/* See symtab.h. */
bool
-find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address,
- CORE_ADDR *endaddr, const struct block **block)
+find_pc_partial_function_sym (CORE_ADDR pc,
+ const struct general_symbol_info **sym,
+ CORE_ADDR *address, CORE_ADDR *endaddr,
+ const struct block **block)
{
struct obj_section *section;
struct symbol *f;
{
const struct block *b = SYMBOL_BLOCK_VALUE (f);
- cache_pc_function_name = f->linkage_name ();
+ cache_pc_function_sym = f;
cache_pc_function_section = section;
cache_pc_function_block = b;
if (msymbol.minsym == NULL)
{
/* No available symbol. */
- if (name != NULL)
- *name = 0;
+ if (sym != nullptr)
+ *sym = 0;
if (address != NULL)
*address = 0;
if (endaddr != NULL)
}
cache_pc_function_low = BMSYMBOL_VALUE_ADDRESS (msymbol);
- cache_pc_function_name = msymbol.minsym->linkage_name ();
+ cache_pc_function_sym = msymbol.minsym;
cache_pc_function_section = section;
cache_pc_function_high = minimal_symbol_upper_bound (msymbol);
cache_pc_function_block = nullptr;
*address = cache_pc_function_low;
}
- if (name)
- *name = cache_pc_function_name;
+ if (sym != nullptr)
+ *sym = cache_pc_function_sym;
if (endaddr)
{
return true;
}
+/* See symtab.h. */
+
+bool
+find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address,
+ CORE_ADDR *endaddr, const struct block **block)
+{
+ const general_symbol_info *gsi;
+ bool r = find_pc_partial_function_sym (pc, &gsi, address, endaddr, block);
+ if (name != nullptr)
+ *name = r ? gsi->linkage_name () : nullptr;
+ return r;
+}
+
+
/* See symtab.h. */
bool
{
struct gdbarch *gdbarch = get_current_arch ();
CORE_ADDR low, high;
+ const general_symbol_info *symbol = nullptr;
const char *name;
CORE_ADDR pc;
gdb_disassembly_flags flags;
if (p[0] == '\0')
{
/* One argument. */
- if (find_pc_partial_function (pc, &name, &low, &high, &block) == 0)
+ if (!find_pc_partial_function_sym (pc, &symbol, &low, &high, &block))
error (_("No function contains specified address."));
+
+ if (asm_demangle)
+ name = symbol->print_name ();
+ else
+ name = symbol->linkage_name ();
+
#if defined(TUI)
/* NOTE: cagney/2003-02-13 The `tui_active' was previously
`tui_version'. */
CORE_ADDR *address, CORE_ADDR *endaddr,
const struct block **block = nullptr);
+/* Like find_pc_partial_function, above, but returns the underlying
+ general_symbol_info (rather than the name) as an out parameter. */
+
+extern bool find_pc_partial_function_sym
+ (CORE_ADDR pc, const general_symbol_info **sym,
+ CORE_ADDR *address, CORE_ADDR *endaddr,
+ const struct block **block = nullptr);
+
/* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
set to start and end addresses of the range containing the entry pc.
+2020-07-28 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ PR symtab/26270:
+ * gdb.cp/disasm-func-name.cc: New file.
+ * gdb.cp/disasm-func-name.exp: New file.
+
2020-07-28 Tom Tromey <tromey@adacore.com>
* gdb.dwarf2/varval.exp (setup_exec): Add 'or' instruction to
--- /dev/null
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2020 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/>. */
+
+class A
+{
+private:
+ int m_i;
+
+public:
+ A(int i);
+
+ int get_i () const
+ { return m_i; }
+
+ void set_i (int i)
+ { m_i = i; }
+};
+
+A::A(int i)
+ : m_i (i)
+{ /* Nothing. */ }
+
+void process (A *obj, int num)
+{
+ obj->set_i (obj->get_i () + num);
+}
+
+int
+main (void)
+{
+ A a(42);
+ process (&a, 2);
+ return a.get_i ();
+}
--- /dev/null
+# Copyright 2020 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 file is part of the gdb testsuite
+
+# Test that the disassembler correctly demangles C++ function names in
+# it's header line.
+
+if {[skip_cplus_tests]} { continue }
+
+standard_testfile .cc
+
+if [get_compiler_info "c++"] {
+ return -1
+}
+
+if {[prepare_for_testing "failed to prepare" $testfile \
+ $srcfile {debug c++}]} {
+ return -1
+}
+
+if ![runto_main] then {
+ perror "couldn't run to breakpoint"
+ continue
+}
+
+proc check_disassembly_header { request expected } {
+ gdb_test "disassemble ${request}" \
+ "Dump of assembler code for function ${expected}:\r\n.*"
+}
+
+gdb_test_no_output "set print asm-demangle on"
+
+check_disassembly_header "main" "main\\(\\)"
+check_disassembly_header "process" "process\\(A\\*, int\\)"
+check_disassembly_header "A::A" "A::A\\(int\\)"
+check_disassembly_header "A::get_i" "A::get_i\\(\\) const"
+check_disassembly_header "A::set_i" "A::set_i\\(int\\)"