[PATCH] Demangle names when using --line-numbers --disassemble.
Jordan Rupprecht via binutils
binutils@sourceware.org
Fri Feb 14 20:15:00 GMT 2020
This fixes the lack of demangling of names within interleaved disassembly, such as:
```
$ echo "namespace xyz { void foo(){} }" | g++ -x c++ -c - -o foo.o && objdump -ldC foo.o
...
Disassembly of section .text:
0000000000000000 <xyz::foo()>:
_ZN3xyz3fooEv():
0: 55 push %rbp
```
With this patch:
```
Disassembly of section .text:
0000000000000000 <xyz::foo()>:
xyz::foo():
0: 55 push %rbp
```
---
binutils/ChangeLog | 4 ++++
binutils/objdump.c | 16 +++++++++++++++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 06bbf5d6b7..8153160223 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,7 @@
+2020-02-14 Jordan Rupprecht <rupprecht@google.com>
+
+ * objdump.c (show_line): call bfd_demangle when using do_demangle.
+
2020-02-10 Fangrui Song <maskray@google.com>
* objcopy.c (parse_flags): Handle "exclude".
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 8182dcc362..6eef38f0e2 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -1734,8 +1734,22 @@ show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
&& (prev_functionname == NULL
|| strcmp (functionname, prev_functionname) != 0))
{
- printf ("%s():\n", sanitize_string (functionname));
+ char *demangle_alloc = NULL;
+ if (do_demangle && functionname[0] != '\0')
+ {
+ /* Demangle the name. */
+ demangle_alloc = bfd_demangle (abfd, functionname,
+ demangle_flags);
+ }
+
+ /* Demangling adds trailing parens, so don't print those. */
+ if (demangle_alloc != NULL)
+ printf ("%s:\n", sanitize_string (demangle_alloc));
+ else
+ printf ("%s():\n", sanitize_string (functionname));
+
prev_line = -1;
+ free (demangle_alloc);
}
if (linenumber > 0
&& (linenumber != prev_line
--
2.25.0.265.gbab2e86ba0-goog
More information about the Binutils
mailing list