Hi all,

I've been making some changes in GDC that will eventually be made updated to be specially handled in GDB when it comes to non-local symbol lookup, completion, etc.

Here's the current implementation in a brief nutshell. It's a bit rough, but hopefully someone with knowledge of DMD's internals may understand it well enough to update the DMD backend to produce the correct debug code.


The the debug generation of 'module foo' emits a DW_TAG_module at the file name and location of the module foo. If there is no module declaration in the file, then the location defaults to line 1 in the source file.

/* module foo; */
 <1><2d>: Abbrev Number: 2 (DW_TAG_module)
    <2e>   DW_AT_name        : foo
    <32>   DW_AT_decl_file   : 1
    <33>   DW_AT_decl_line   : 2


Packages are handled by emitting the parent tags first, then the sub-modules in order. Children of parent modules are referenced using DW_AT_sibling.

/* module std.foo; */
 <1><2d>: Abbrev Number: 2 (DW_TAG_module)
    <2e>   DW_AT_name        : std
    <32>   DW_AT_decl_file   : 1
    <33>   DW_AT_decl_line   : 2
 <2><38>: Abbrev Number: 3 (DW_TAG_module)
<39> DW_AT_name : (indirect string, offset: 0xe0): foo
    <3d>   DW_AT_decl_file   : 1
    <3e>   DW_AT_decl_line   : 2
...
/* module std.bar; */
 <1><4d>: Abbrev Number: 2 (DW_TAG_module)
    <4e>   DW_AT_name        : std
    <52>   DW_AT_decl_file   : 2
    <53>   DW_AT_decl_line   : 3
 <2><58>: Abbrev Number: 3 (DW_TAG_module)
<59> DW_AT_name : (indirect string, offset: 0x4b): bar
    <5d>   DW_AT_decl_file   : 2
    <5e>   DW_AT_decl_line   : 3

The DW_TAG_module being emitted twice isn't intentional here. And more a side effect of the front-end sending two different instantiations of the same 'std' package to the backend. If it is genuinely needed, then expect this to change when I come round to it.


Imported modules are tagged with DW_TAG_imported_module, and the DW_AT_import points to the external module declaration.

/* import object.d.  */
 <3><3f>: Abbrev Number: 4 (DW_TAG_imported_module)
    <40>   DW_AT_decl_file   : 1
    <41>   DW_AT_decl_line   : 1
<42> DW_AT_import : <0x53> [Abbrev Number: 6 (DW_TAG_module)]
...
 <1><53>: Abbrev Number: 6 (DW_TAG_module)
<54> DW_AT_name : (indirect string, offset: 0x0): object
    <58>   DW_AT_declaration : 1


Renamed imports are identical, but with the addition of DW_AT_name to reference the alias.

/* import simd = core.simd;  */
 <3><46>: Abbrev Number: 5 (DW_TAG_imported_module)
    <47>   DW_AT_decl_file   : 1
    <48>   DW_AT_decl_line   : 4
<49> DW_AT_name : (indirect string, offset: 0x81): simd <4d> DW_AT_import : <0x63> [Abbrev Number: 6 (DW_TAG_module)]
...
 <1><58>: Abbrev Number: 7 (DW_TAG_module)
<59> DW_AT_name : (indirect string, offset: 0x8d): core
    <5d>   DW_AT_decl_file   : 2
    <5e>   DW_AT_decl_line   : 13
    <5f>   DW_AT_sibling     : <0x69>
 <2><63>: Abbrev Number: 6 (DW_TAG_module)
<64> DW_AT_name : (indirect string, offset: 0x81): simd
    <68>   DW_AT_declaration : 1


And currently I'm testing selective imports to be represented as DW_TAG_imported_declaration. Don't have any examples for yet, but it looks like it would be the imported declaration tag pointing to the real declaration.


Regards
Iain.

Reply via email to