[Dwarf-Discuss] Producing .debug_names and questions about this lookup format

Greg Clayton clayborg@gmail.com
Tue Feb 1 23:45:10 GMT 2022

I am in the process if writing a tool that can add .debug_names to a file that contains DWARF but doesn?t have an accelerator table that is adequate for debuggers to use. I was trying to see some example implementations of the .debug_names section to see exactly what I should emit from this tool.

I have a question on the following section from the DWARF 5 specification: Abbreviations Table. It contains "Table 6.1: Index attribute encodings? which shows the available attributes for the abbreviations that can be used for each index entry:

DW_IDX_compile_unit. // Index of CU
DW_IDX_type_unit  // Index of TU
DW_IDX_die_offset // Offset of DIE within CU or TU
DW_IDX_parent // Index of name table entry for parent
DW_IDX_type_hash // Hash of type declaration

My main question is what are the best practices for how producers should emit an entry for a specific DIE in this lookup table. One option is to specify both a CU index and a relative DIE offset:

DW_IDX_compile_unit + DW_FORM_dataX form
DW_IDX_die_offset + DW_FORM_ref4

?DW_FORM_ref4? is known to be a CU relative offset.

Or we can simply emit a single attribute for the die_offset using an absolute DIE offset reference?

DW_IDX_die_offset + DW_FORM_ref_addr

There isn?t much written up in the DWARF spec about these attributes except that it seems to imply that DW_IDX_die_offset must also have a CU or TU since the comment says "Offset of DIE within CU or TU?

I was looking at the output of dsymutil, a smart DWARF linker maintained by Apple, and it can emit .debug_names with an option, but it emits the following abbreviation, as seen by using ?llvm-dwarfdump --debug-names?:

    Abbreviation 0x16 {
      Tag: DW_TAG_typedef
      DW_IDX_die_offset: DW_FORM_ref4

And the in the Entry for each type, dsymutil only emits a DIE offset as a DW_FORM_ref4, which seems to imply it is an absolute offset:

  Bucket 0 [
    Name 1 {
      Hash: 0x4D51C8E0
      String: 0x000010c4 "pthread_t"
      Entry @ 0x5a7 {
        Abbrev: 0x16
        Tag: DW_TAG_typedef
        DW_IDX_die_offset: 0x00002162
    Name 2 {
      Hash: 0x8FEC1B20
      String: 0x00000323 "long int"
      Entry @ 0x5ad {
        Abbrev: 0x24
        Tag: DW_TAG_base_type
        DW_IDX_die_offset: 0x00000920

Should dsymutil be emitting both a CU index and a CU relative offset, or should it just switch over to using a DW_FORM_ref_addr as the encoding for the DIE?

Do any current compilers support emitting .debug_names when ?-gdwarf-5? is produced?

Any clarification or pointers to other producers would be appreciated!

Greg Clayton

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dwarfstd.org/pipermail/dwarf-discuss-dwarfstd.org/attachments/20220201/49cbe9b4/attachment.html>

More information about the Dwarf-discuss mailing list