Debugging DMD executables with GDB in Linux; dynamic arrays and other oddities.
Bernard Helyer
b.helyer at gmail.com
Sun Nov 22 03:24:31 PST 2009
Given a simple module:
// dmd -g file.d
void main()
{
int i = 3;
i++;
}
We can debug it using gdb (patched or no) like so:
$ gdb file
GNU gdb 6.8... <snip>
(gdb) list _Dmain
1 void main()
2 {
3 int i = 3;
4 i++;
5 }
6
(gdb)
And then set break points and variables to watch as we please. Even over
multiple modules. But as soon as a dynamic array shows anywhere, in any
fashion, in any module...
// dmd -g file.d
void main()
{
int i = 3;
i++;
bool[] a = null; // <--
}
$ gdb file
<snip>
(gdb) list _Dmain
(gdb) list _Dmain
Die: DW_TAG_<unknown> (abbrev = 5, offset = 471)
has children: FALSE
attributes:
DW_AT_byte_size (DW_FORM_data1) constant: 8
DW_AT_type (DW_FORM_ref4) constant ref: 462
(adjusted)
Dwarf Error: Cannot find type of die [in module /path/to/module]
This is with a patched gdb. Now, sometimes compiling with `-gc` allows
this to work (as it does with this simple example), but in my larger
programs, this error message is given instead:
Dwarf Error: Cannot find DIE at 0xe36 referenced from DIE at
0x165 [in module /path/to/module]
I'm not sure whose fault this is, so instead of posting a bug, I thought
I would post it to the newsgroup (my first to a newsgroup, so if I've
made a galling error in etiquette, please, be gentle. :]
Also, shouldn't the GDB command 'list' list out the D module, without
having to specify _Dmain? If you don't, it just gives this report:
(gdb) list
1 ../sysdeps/i386/elf/start.S: No such file or directory.
in ../sysdeps/i386/elf/start.S
I think having GDB and DMD working together nicely is important. If push
comes to shove, I'm willing to learn about DWARF and ELF and GDB
internals as a project, but to be completely honest, I'd rather not have to.
Thanks,
-Bernard.
More information about the Digitalmars-d-debugger
mailing list