Thread overview | |||||
---|---|---|---|---|---|
|
February 22, 2014 Modules and debugging in DWARF | ||||
---|---|---|---|---|
| ||||
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. |
February 22, 2014 Re: Modules and debugging in DWARF | ||||
---|---|---|---|---|
| ||||
Posted in reply to Iain Buclaw | On Saturday, 22 February 2014 at 00:30:18 UTC, Iain Buclaw wrote: > Hi all, > [skip] > > 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. Below is dwarf info generated by g++ for selective imports in C++ code. < 1><0x00000045> DW_TAG_typedef DW_AT_name va_list DW_AT_decl_file 0x00000002 /usr/lib/gcc/i586-suse-linux/4.7/include/stdarg.h DW_AT_decl_line 0x00000066 DW_AT_type <0x00000029> < 1><0x00000050> DW_TAG_namespace DW_AT_name std DW_AT_decl_file 0x00000004 /home/sarath/development/dbg/tests/c/<built-in> DW_AT_decl_line 0x00000000 DW_AT_sibling <0x00000079> < 2><0x0000005b> DW_TAG_imported_declaration DW_AT_decl_file 0x00000005 /usr/include/c++/4.7/cstdarg DW_AT_decl_line 0x00000038 DW_AT_import <0x00000045> - Sarath |
February 22, 2014 Re: Modules and debugging in DWARF | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sarath Kodali | On 22 February 2014 18:15, Sarath Kodali <sarath@dummy.com> wrote:
> On Saturday, 22 February 2014 at 00:30:18 UTC, Iain Buclaw wrote:
>>
>> Hi all,
>>
> [skip]
>
>>
>> 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.
>
>
> Below is dwarf info generated by g++ for selective imports in C++ code.
>
> < 1><0x00000045> DW_TAG_typedef
> DW_AT_name va_list
> DW_AT_decl_file 0x00000002
> /usr/lib/gcc/i586-suse-linux/4.7/include/stdarg.h
> DW_AT_decl_line 0x00000066
> DW_AT_type <0x00000029>
> < 1><0x00000050> DW_TAG_namespace
> DW_AT_name std
> DW_AT_decl_file 0x00000004
> /home/sarath/development/dbg/tests/c/<built-in>
> DW_AT_decl_line 0x00000000
> DW_AT_sibling <0x00000079>
> < 2><0x0000005b> DW_TAG_imported_declaration
> DW_AT_decl_file 0x00000005
> /usr/include/c++/4.7/cstdarg
> DW_AT_decl_line 0x00000038
> DW_AT_import <0x00000045>
>
> - Sarath
Yeah, I don't need to know that per say (although I will have to bear in mind how GDB represents it in its runtime environment). GCC provides a handy debug hooks called 'imported_module_or_decl'. I just need to make sure that the trees passed to it are generated correctly. :-)
I just posted this information because this is what gdc does today, and at least DMD developers have the misfortune for having to have to worry about this. :o)
Regards
Iain.
|
Copyright © 1999-2021 by the D Language Foundation