[Dwarf-Discuss] DW_AT_decl_file etc understood now. Question answered.

Todd Allen todd.allen@concurrent-rt.com
Wed Feb 19 12:42:06 GMT 2020


David,

DIRECTORIES:

The situation for directories seems pretty clear to me, and much the same as how
Philip saw it (I think).  From 6.2.4, item 16 (page 157, lines 4-11):

   The line number program assigns a number (index) to each of the directory
   entries in order, beginning with 0.

   Prior to DWARF Version 5, the current directory was not represented in the
   directories field and a directory index of 0 implicitly referred to that directory as found
   in the DW_AT_comp_dir attribute of the compilation unit debugging information
   entry. In DWARF Version 5, the current directory is explicitly present in the
   directories field. This is needed to support the common practice of stripping all but
   the line number sections ( .debug_line and .debug_line_str ) from an executable.

That seems pretty clearly to be a base of 0.

My understanding:

   For DWARF 2,3,4, the directory table starts with 1; 0 meant
   "go use DW_AT_comp_dir".

   For DWARF 5, the directory table starts with 0.  And presumably the 0th index
   is essentially the same as DW_AT_comp_dir.

FILES:

The case for the file table being base 1 seems strong.

-- 
Todd Allen
Concurrent Real-Time

On Tue, Feb 18, 2020 at 10:25:21AM -0800, Dwarf Discussion wrote:
> February 18, 2020.
> 
> Lets see if we can get a complete picture of the
> indexing into the line table header directory/file
> names tables.
> 
> The conjecture at the end of this suggests that
> all places with an actual file/directory number
> or index should be 1-origin, reserving 0 to
> mean no file named.
> 
> The parts of DWARF5 that seem to be a complete picture
> of the line table file/directory numbers are;
> 
> A) DW_AT_decl_file
> A) DW_AT_call_file? /* DWARF5 */
> C) DW_LNS_set_file
> D) The current compilation file name
> E) The current compilation directory name
> F) The line table 'file' register.
> 
> G) The array of file names in the line table header
> ?? (called the line table prologue in DWARF2).
> 
> H) The array of directory names in the line table header.
> 
> J) DW_MACRO_start_file (DW5)
> 
> ============
> DWARF5: the first entry in the directory table file names array
> ?? is the name of the current compilation unit directory
> ?? (the same as DW_AT_comp_dir in the CU die)
> 
> DWARF2,3,4: the first entry in the directory table file names array
> ?? is the name of some directory, not necessarily
> ?? the same as DW_AT_comp_dir in the CU die
> 
> DWARF5: the first entry in the line table file names array
> ?? is the name of the current compilation unit (the same as
> ?? DW_AT_name in the CU die).
> 
> DWARF2,3,4
> ?? the first entry in the line table file names array
> ?? does not have the current compilation unit file name,
> ?? that name is only in DW_AT_name in the CU die.
> 
> Where DW_AT_decl_file is defined the standard(s)
> indicate 0 is reserved to mean no file is specified
> (Section 2.14, Declaration Coordinates)
> That's the only place where zero is explictly
> mentioned .
> 
> DW_LNS_set_file is defined to set the 'file' register
> in the line state machine.
> In all versions of DWARF the default value of the 'file'
> register is 1 (not zero).
> 
> DW_MACRO_start_file (DW5):
> The source file name index is the file number in the line number information
> table for the compilation unit.
> 
> While the standard sometimes says file number and sometimes says 'index'
> this note regards them as the same thing with regard to the line table
> header arrays..
> 
> In DWARF 2,3,4 1 refers to a directory or file entry but not the
> compilation unit
> directory/file.
> 
> In DWARF 2,3,4 1 refers to a directory or file entry applicable to the
> compilation unit.
> 
> CONJECTURE:
> In all cases the index or array references are intended to be 1-origin.
> 
> In DWARF 2,3,4 1 refers to a directory or file entry but not the
> compilation unit
> directory/file.
> 
> In DWARF 2,3,4 1 refers to a directory or file entry applicable to the
> compilation unit.
> 
> Taking this approach seems to resolve all issues pretty well.
> ===============
> 
> _______________________________________________
> Dwarf-Discuss mailing list
> Dwarf-Discuss at lists.dwarfstd.org
> http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org



More information about the Dwarf-discuss mailing list