public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Demangle names when using --line-numbers --disassemble.
@ 2020-02-14 20:15 Jordan Rupprecht via binutils
  2020-02-19  9:03 ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Jordan Rupprecht via binutils @ 2020-02-14 20:15 UTC (permalink / raw)
  Cc: binutils, Jordan Rupprecht

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-19 23:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14 20:15 [PATCH] Demangle names when using --line-numbers --disassemble Jordan Rupprecht via binutils
2020-02-19  9:03 ` Alan Modra
2020-02-19 21:58   ` Eric Christopher
2020-02-19 22:55     ` Committing patches for other people Alan Modra
2020-02-19 23:35       ` Eric Christopher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).