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

* Re: [PATCH] Demangle names when using --line-numbers --disassemble.
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2020-02-19  9:03 UTC (permalink / raw)
  To: Jordan Rupprecht; +Cc: binutils

On Fri, Feb 14, 2020 at 12:14:41PM -0800, Jordan Rupprecht via binutils wrote:
> +2020-02-14  Jordan Rupprecht  <rupprecht@google.com>
> +
> +  * objdump.c (show_line): call bfd_demangle when using do_demangle.

OK.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [PATCH] Demangle names when using --line-numbers --disassemble.
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Christopher @ 2020-02-19 21:58 UTC (permalink / raw)
  To: Alan Modra; +Cc: Jordan Rupprecht, binutils

I've gone ahead and committed this for Jordan.

On Wed, Feb 19, 2020 at 1:03 AM Alan Modra <amodra@gmail.com> wrote:

> On Fri, Feb 14, 2020 at 12:14:41PM -0800, Jordan Rupprecht via binutils
> wrote:
> > +2020-02-14  Jordan Rupprecht  <rupprecht@google.com>
> > +
> > +  * objdump.c (show_line): call bfd_demangle when using do_demangle.
>
> OK.
>
> --
> Alan Modra
> Australia Development Lab, IBM
>

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

* Committing patches for other people
  2020-02-19 21:58   ` Eric Christopher
@ 2020-02-19 22:55     ` Alan Modra
  2020-02-19 23:35       ` Eric Christopher
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2020-02-19 22:55 UTC (permalink / raw)
  To: binutils; +Cc: Eric Christopher

On Wed, Feb 19, 2020 at 01:58:20PM -0800, Eric Christopher wrote:
> I've gone ahead and committed this for Jordan.

OK, but I'll note that when not using "git am" to commit other
people's patches you should take steps to properly attribute
authorship.
  git commit --amend --author="Joe Bloe <joe@somewhere.net>"

As it is, "git blame" shows
741cb83912f (Eric Christopher  2020-02-19 13:55:25 -0800
for objdump.c lines changed by Jordan's patch.

None of this matters very much at the moment, but if we are to move
away from ChangeLogs then we will need to learn better habits.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: Committing patches for other people
  2020-02-19 22:55     ` Committing patches for other people Alan Modra
@ 2020-02-19 23:35       ` Eric Christopher
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Christopher @ 2020-02-19 23:35 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

Ah yes that's a very good point.

On Wed, Feb 19, 2020, 2:55 PM Alan Modra <amodra@gmail.com> wrote:

> On Wed, Feb 19, 2020 at 01:58:20PM -0800, Eric Christopher wrote:
> > I've gone ahead and committed this for Jordan.
>
> OK, but I'll note that when not using "git am" to commit other
> people's patches you should take steps to properly attribute
> authorship.
>   git commit --amend --author="Joe Bloe <joe@somewhere.net>"
>
> As it is, "git blame" shows
> 741cb83912f (Eric Christopher  2020-02-19 13:55:25 -0800
> for objdump.c lines changed by Jordan's patch.
>
> None of this matters very much at the moment, but if we are to move
> away from ChangeLogs then we will need to learn better habits.
>
> --
> Alan Modra
> Australia Development Lab, IBM
>

^ 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).