Comment #0 by thelastmammoth — 2012-05-31T00:54:11Z
I'm trying to have proper debug info for D on OSX (D2, 2.059 but it shouldn't matter). Currently I can only do that on ubuntu. I see several posts about this topic but they seem out of date and the information is scattered.
I tried several options:
****
A) OSX
1) gdb (default provided by apple: gdb 6.3.50)
2) ggdb (from macports: version 7.3) => doesn't seem to work at all even for simple C hello world
3) gdb-7.4.1 (manual build from gdb website, somehow requires to run as sudo otherwise complains : please check gdb is codesigned - see taskgated, but despite instructions online running as sudo was the only way to make it work)
4) cgdb
5) lldb
B) Ubuntu
1) gdb 7.2 (according to http://www.dsource.org/projects/gdb-patches, a patch for D is part of GDB " as of 7.2)
****
I'm compiling a simple hello world with a forced seg fault: compiled with dmd -g main.d.
cat main.d:
module main; void fun(){int *x = null; *x = 1;} void main(){fun;}
Here are the results on $debugger_name main:
A.1: mangled names, line numbers: 0x00000001000014e3 in _D4main3funFZv () at main.d:2
A.2: just addresses: 0x000000010bb5a4e3 in ?? ()
A.3: mangled names, no line numbers: 0x00000001000014e3 in D4main3funFZv ()
A.4: mangled names, line numbers: 0x00000001000014e3 in _D4main3funFZv () at main.d:2
A.5: mangled names, line numbers: frame #0: 0x00000001000014e3 main`D4main3funFZv + 15 at main.d:2
B.1: demangled names, line numbers 0x00000000004016c7 in main.fun () at main.d:2
Note, even on OSX the D demangling would be easy via dfilt or ddemangle [cf git repo: dmd/tools/ddemangle.d for a tool or dmd/druntime/src/core/demangle.d for the function]):
dfilt D4fun25fun2bFPiZv => void main.fun()
Would you have any ideas how to make it work on OSX?
****
Another related issue is wrt stacktraces: the situation is reversed, ie it displays the demangled names, but no line numbers:
6 main2 0x000000010b6b94db void main.__assert(int) + 23
There were some previous threads about requiring to add to dmd.conf "-L--export-dynamic" but that will not let dmd run.
I'm not sure whether it's relevant, but I am able to get proper stack traces in C++ programs on OSX using code similar to http://www.tekkotsu.org/dox/StackTrace_8h.html
****
btw is there a way to print stack trace without having an assertion failed in D?
Comment #1 by code — 2012-06-07T15:43:29Z
Issue 8208 might be related, depending on how the GDB patches expect the mangled names.
Comment #2 by thelastmammoth — 2012-06-07T16:09:16Z
(In reply to comment #1)
> Issue 8208 might be related, depending on how the GDB patches expect the
> mangled names.
Did you mean Issue 8207?
I would LOVE to see this resolved ASAP, this issue has been there for a while!
Comment #3 by code — 2012-06-07T16:10:21Z
Oh, yes, the perils of _not_ using copy and paste… ;)
Comment #4 by thelastmammoth — 2012-06-07T16:13:16Z
(In reply to comment #3)
> Oh, yes, the perils of _not_ using copy and paste… ;)
does your intended pull request solve this issue on OSX ?
Comment #5 by code — 2012-06-07T16:20:49Z
Didn't try yet; I didn't have too much luck with getting newer (non-Apple) GDB versions to reliably work so far.
For LLDB to display demangled names, somebody would need to write a LLDB patch/plugin for D, which, to my knowledge, has not happened yet.
Comment #6 by thelastmammoth — 2012-06-07T16:25:22Z
(In reply to comment #5)
> Didn't try yet; I didn't have too much luck with getting newer (non-Apple) GDB
> versions to reliably work so far.
>
> For LLDB to display demangled names, somebody would need to write a LLDB
> patch/plugin for D, which, to my knowledge, has not happened yet.
newer, non-apple gdb versions work on osx, but have to be run under sudo in my experience; I could try myself if I had your pull request to see if it resolves this issue.
Comment #7 by code — 2012-06-07T16:35:46Z
With my preliminary patches and GDB 7.4.1, name demangling in GDB indeed seems to work. Added a dependency on Issue 8207.
Comment #8 by thelastmammoth — 2012-06-07T16:43:57Z
(In reply to comment #7)
> With my preliminary patches and GDB 7.4.1, name demangling in GDB indeed seems
> to work. Added a dependency on Issue 8207.
wonderful, at last!
btw did you figure out a way to run the new gdb without sudo on osx?
looking forward for your patch
Comment #9 by andrei — 2014-01-10T17:48:30Z
placed $50 bounty
Comment #10 by camille — 2014-02-13T13:13:18Z
To anyone working on this, some notes from David Nadlinger via email --
While the patch I was testing would fix the reported issue (missing
mangled names in debuggers on OS X) in conjunction with GDB 7.1+, it
would not be enough to resolve the issue to general satisfaction, as
recent GDB versions are not available from Apple, and using upstream
(vanilla GNU) gdb comes with its own share of shortcomings.
I'd expect a fix eligible for collecting the bounty to offer some way
of pretty-printing symbols in LLDB, which is pushed by Apple as a GDB
replacement, and is in the process of becoming the de-facto standard
debugger on OS X. This could either be done by directly adding the
support to the upstream LLDB project, or by providing some kind of
hooking or wrapper script adding that functionality. Last time I
checked, LLDB, though extensively scriptable, didn't offer direct
support for adding external name demangling routines, which is why I
didn't continue work on the issue so far, although this restriction
could certainly be removed or worked around.
I'm in a hurry right now, but please feel free to relay the above to
the bug tracker.
Best,
David
(In reply to comment #11)
> As for demangling support in GDB, I have committed it into upstream
> development. If anyone wants to test this on OSX, be my guest.
Not even the rudimentary demangling support in GDB 7.1+ works on OS X right now due to the missing underscore issue mentioned above, and somehow I'm sceptical that your patch changes that, unless you explicitly made the leading underscore optional.
Comment #13 by dlang.x.ox336699 — 2014-03-01T18:23:34Z
The bounty has been bumped up by another $50
Comment #14 by timothee.cour2 — 2018-02-27T21:03:17Z