D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14698 - Un-mangle symbols in disassembly?
Summary: Un-mangle symbols in disassembly?
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: visuald (show other issues)
Version: D2
Hardware: x86_64 Windows
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-14 08:35 UTC by Manu
Modified: 2015-08-05 21:18 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Manu 2015-06-14 08:35:31 UTC
Compile and disassemble is the most useful feature in forever!
That said, it would be really awesome if symbol names in the disassembly were un-mangled; D has a tendency to produce some horrible symbol names!

  0000000000000029: lea         rcx,[rbp-10h]
  000000000000002D: sub         rsp,20h
  0000000000000031: call        _D3std6format61__T11formatValueTS3std5array17__T8AppenderTAyaZ8AppenderTmTaZ11formatValueFS3std5array17__T8AppenderTAyaZ8AppendermKS3std6format18__T10FormatSpecTaZ10FormatSpecZ16__T9__lambda4TmZ9__lambda4FNaNbNiNeKmZAxa
  0000000000000036: add         rsp,20h
  000000000000003A: mov         qword ptr [rbp-60h],rax

... difficult to know what's being called in these instances ;)
Comment 1 Rainer Schuetze 2015-06-14 12:28:13 UTC
Actually, you can get that already by piping the assembly output through ddemangle. Set the disassembly command to something like:

"$(VCINSTALLDIR)\bin\dumpbin" /disasm:nobytes "$(InputPath)" | ddemangle >"$(TargetPath)"

Maybe this should even be the default, though I'm unsure ddemangle is distributed with LDC or GDC.
Comment 2 weaselcat 2015-06-14 13:21:50 UTC
@Rainer

GDC is generally bundled with binutils which includes D symbol demangling in the relevant tools(e.g, c++filt, objdump, etc)
Comment 3 Rainer Schuetze 2015-06-16 20:50:42 UTC
> GDC is generally bundled with binutils which includes D symbol demangling in the relevant tools(e.g, c++filt, objdump, etc)

I don't see any D demangling support in objdump/c++filt in the latest GDC build I could find at http://gdcproject.org/downloads. Any hidden option I should use?
Comment 4 Iain Buclaw 2015-06-16 22:02:35 UTC
(In reply to Rainer Schuetze from comment #3)
> > GDC is generally bundled with binutils which includes D symbol demangling in the relevant tools(e.g, c++filt, objdump, etc)
> 
> I don't see any D demangling support in objdump/c++filt in the latest GDC
> build I could find at http://gdcproject.org/downloads. Any hidden option I
> should use?

-s dlang or --format=dlang
Comment 5 Rainer Schuetze 2015-06-16 22:17:48 UTC
Maybe the Windows versions don't have it?

I tried

>"c:\l\GDC-2.066\bin\c++filt.exe" --version
GNU c++filt (crosstool-NG 1.20.0 - 20150413-2.066.1-f378f9ab41) 2.23.1

>"c:\l\GDC-2.066\bin\c++filt.exe" --format=dlang
c:\l\GDC-2.066\bin\c++filt.exe: unknown demangling style `dlang'
Comment 6 Iain Buclaw 2015-06-17 08:09:02 UTC
(In reply to Rainer Schuetze from comment #5)
> Maybe the Windows versions don't have it?
> 
> I tried
> 
> >"c:\l\GDC-2.066\bin\c++filt.exe" --version
> GNU c++filt (crosstool-NG 1.20.0 - 20150413-2.066.1-f378f9ab41) 2.23.1
> 
> >"c:\l\GDC-2.066\bin\c++filt.exe" --format=dlang
> c:\l\GDC-2.066\bin\c++filt.exe: unknown demangling style `dlang'

Support was added in binutils 2.25
Comment 7 Manu 2015-06-22 14:04:41 UTC
What will happen for binaries with both D and C++ symbols?
Comment 8 Rainer Schuetze 2015-06-22 17:59:20 UTC
> What will happen for binaries with both D and C++ symbols?

Good question. I was just about to adapt the demangling of linker messages to fit this use case aswell, but C++ symbols are not supported (nor by ddemangle which also doesn't support compressed symbols on Win32). Having two different C++ manglings is not so great, too.

For gdc builds you could chain two calls to c++filt if a binary is available.
Comment 9 Rainer Schuetze 2015-06-26 09:36:51 UTC
> Support was added in binutils 2.25

I've build this version, but noticed that it doesn't demangle full text files, just the arguments given on the command line. Instead, it reports "Internal error: no symbol alphabet for current style". That has an easy fix, though.

As cxxfilt will very likely never support compressed symbols aswell as MS mangled symbols, I've compiled my own version supporting all 3 manglings (D/gcc/cl) including compression.

Disassembly with demangled symbols is now enabled if the global option "Demangle symbols in linker messages/disassembly" is checked. Try it in https://github.com/D-Programming-Language/visuald/releases/tag/v0.3.42-beta2
Comment 10 Manu 2015-06-28 00:27:58 UTC
Seems to be working great now!
Comment 11 Iain Buclaw 2015-06-29 08:59:21 UTC
(In reply to Rainer Schuetze from comment #9)
> > Support was added in binutils 2.25
> 
> I've build this version, but noticed that it doesn't demangle full text
> files, just the arguments given on the command line. Instead, it reports
> "Internal error: no symbol alphabet for current style". That has an easy
> fix, though.
> 
> As cxxfilt will very likely never support compressed symbols aswell as MS
> mangled symbols, I've compiled my own version supporting all 3 manglings
> (D/gcc/cl) including compression.
> 

Nice wrapper you've got there.  The next version of binutils/gdb will have pretty much near complete 2.068 support. In my local tests, it managed to demangle all symbols in Phobos and druntime (core.demangle barely got 20% - and even then some were massively incorrect).
Comment 12 Rainer Schuetze 2015-08-05 21:14:25 UTC
released in https://github.com/D-Programming-Language/visuald/releases/tag/v0.3.42
Comment 13 Rainer Schuetze 2015-08-05 21:18:19 UTC
> The next version of binutils/gdb will have pretty much near complete 2.068
> support. In my local tests, it managed to demangle all symbols in Phobos 
> and druntime (core.demangle barely got 20% - and even then some were 
> massively incorrect).

I could use the D demangler from binutils in my tool, too. Also, the mago debug engine might need an update to its demangler.

Do you plan to submit those fixes to core.demangle, too?