What's the proper way to debug D programs with GDB?

Robert Clipsham robert at octarineparrot.com
Wed Mar 17 17:04:44 PDT 2010


On 17/03/10 22:50, Walter Bright wrote:
> grauzone wrote:
>> dmd producing buggy debugging information seems to be an old problem:
>> http://d.puremagic.com/issues/show_bug.cgi?id=1079
>
> The problem is that dmd produces dwarf debug info according to the dwarf
> spec. When gdb fails, I have no clue why, and nobody has ever been able
> to figure out just *what* in the dwarf info is causing gdb to fail.
>
> Some problems were identified a few months back, and those were fixed
> (evidently gdb cannot handle module records, and gdb also relied on some
> undocumented stuff).
>
> If anyone wants to peruse the gdb source and figure out exactly *what*
> it is choking on, that would be most appreciated.

I've spent about half an hour trying to track this down, and I can't 
seem to reproduce the problem. The only time I can get the errors 
mentioned here and in the listed bug is when using -g. When switching to 
-gc the problems disappear. Does anyone have a test case that fails with 
-gc too that I can play with?

The reason this happens when using -g is the D extensions to dwarf which 
GDB doesn't support (even with the gdb-patches applied) are used here, 
which causes the error, as gdb is unable to parse the debug info. When 
using -gc, dmd doesn't use the D extensions, so the error doesn't occur. 
To fix this, gdb would need patching to add support for the D 
extensions, or alternatively we'll have to keep using -gc.

----
void main()
{
         char[] foo;
         foo ~= 'a';
}
----
When compiled using -gc, gdb works as expected. When compiled with -g, 
gdb gives the following error:

(gdb) b test.d:3
Die: DW_TAG_<unknown> (abbrev = 4, offset = 77)
         has children: FALSE
         attributes:
                 DW_AT_byte_size (DW_FORM_data1) constant: 8
                 DW_AT_type (DW_FORM_ref4) constant ref: 69 (adjusted)
Dwarf Error: Cannot find type of die [in module /tmp/test]

Taking a look at the dwarf info for test:
% objdump --dwarf=abbrev test
-- SNIP --
    4      Unknown TAG value: 41    [no children]
     DW_AT_byte_size    DW_FORM_data1
     DW_AT_type         DW_FORM_ref4
-- SNIP --

Unknown TAG value at 41... This isn't part of the dwarf spec, looking at 
src/dmd/backend/dwarf2.h:
----
        // D programming language extensions
         DW_TAG_darray_type              = 0x41,
         DW_TAG_aarray_type              = 0x42,
         DW_TAG_delegate_type            = 0x43,

         DW_TAG_lo_user                  = 0x4080,
         DW_TAG_hi_user                  = 0xFFFF,
----

Oh look, 0x41 is a D extension, no wonder GDB chokes :)

I'll look more into this if someone can provide me a test case which 
doesn't require the D extensions to cause the error, currently this 
looks like a non-bug to me as gdb doesn't support D extensions yet (yes, 
this is even with a patched gdb).

Robert


More information about the Digitalmars-d-debugger mailing list