Would you trade 0.1% in performance for a better debugging experience?

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 18 11:06:29 PST 2014


Am Tue, 18 Nov 2014 17:15:12 +0000
schrieb "Vladimir Panteleev" <vladimir at thecybershadow.net>:

> On Tuesday, 18 November 2014 at 16:49:55 UTC, Marco Leise wrote:
> > Without fully understanding the issue, omitting the frame
> > pointer on GNU amd64 systems is the default and is supposed to
> > work using DWARF debug information. So there should be no need
> > for a stack frame pointer, right?
> 
> Firstly, does DMD generate DWARF debug information in practice 
> that's correct enough to substitute stack frames? As far as I can 
> tell, it doesn't.

Is it fair if I argue that fixing DWARF info generation is a
better solution then?

> Second, there's still the argument that not every debugger and 
> profiler can take advantage of the DWARF debug information. It's 
> certainly nowhere as easy: from the technical point of view, but 
> also from a legal one, considering that (IIRC) most libraries 
> dealing with DWARF debug information are GPL or LGPL, meaning we 
> can't use them in the D runtime. And indeed, for printing the 
> stack trace for an unhandled exception, Druntime currently walks 
> the stack frames:
> 
> https://github.com/D-Programming-Language/druntime/blob/master/src/core/runtime.d#L452-L478

I don't need to open the link to know the code you linked to.
Ever since I had weird seg faults when an exception was thrown
from my D callback in Gtk code I wondered when this code will
be updated. Consider that "no frame pointers" is the default
for GCC on amd64 and thus practically all libraries on Linux
can't be stack traced by druntime. It needs to use libunwind
in the long run when C++ interfacing becomes more viable and D
programmers start to expect exception handling and stack
traces to work as per system ABI. At least that's what I
believe.

> There is also the libc backtrace function, which the D runtime 
> apparently used at some point:
> 
> http://www.gnu.org/software/libc/manual/html_node/Backtraces.html
> 
> It was removed in this commit:
> 
> https://github.com/D-Programming-Language/druntime/commit/9dca50fe65402fb3cdfbb689f1aca58dc835dce4
> 
> The commit message doesn't seem to mention why the use of the 
> backtrace function was removed. But from reading the function's 
> documentation, it looks like it works in the same way (walking 
> the stack frame pointers, i.e. also reliant on stack frames).

It probably fell short when amd64 was introduced. Although
libunwind is not part of the GNU project, it is the de facto
standard on Linux/GNU for stack unwinding with projects like
Mono or perf using it. The license is MIT and it is easy to
make it a runtime dependency of dmd/Phobos packages on Linux.

-- 
Marco



More information about the Digitalmars-d mailing list