Demangle names when using --line-numbers --disassemble.

Message ID 20200214201441.146590-1-rupprecht@google.com
State New
Headers show
Series
  • Demangle names when using --line-numbers --disassemble.
Related show

Commit Message

H.J. Lu via Binutils Feb. 14, 2020, 8:14 p.m.
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(-)

-- 
2.25.0.265.gbab2e86ba0-goog

Comments

Alan Modra Feb. 19, 2020, 9:03 a.m. | #1
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
Eric Christopher Feb. 19, 2020, 9:58 p.m. | #2
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

>
Alan Modra Feb. 19, 2020, 10:55 p.m. | #3
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
Eric Christopher Feb. 19, 2020, 11:35 p.m. | #4
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

>

Patch

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