DWARF5 Line Table File Numbers

From Dwarf Wiki
Revision as of 12:02, 15 October 2020 by David.anderson (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

DWARF5

Interpreting The Line Table File Numbers

Summary:

It is impossible to obey all the DWARF5 rules on file numbering in the line table at the same time. They contradict each other.

A specific example is Section 2.14 (page 50) and point 20 in the line table header (page 157).

One way to make consistency possible is to declare that things outside the file table use 1 origin numbering (DW_AT_decl_file, DW_AT_call_file,DW_MACRO_start_file) and to declare that all things *inside* the line table use zero-based file indexes. This seems messy and confusing: would a dumper like readelf or dwarfdump somehow print both meanings of a number?

A simpler way is to say that the file number value 0 meaning of 'no file' is eliminated so that part of Section 2.14 page 50 is invalidated. So then we have a zero-based file array along with all references to it. And declare that the 'file' line table register defaults to zero (DWARF5 Table 6.4 Page 153). Then the standard is self-consistent.

There was some discussion of this in the dwarf-discuss list in mid-February 2020 and a few people contributed their thoughts and observations.

Lines below are direct quotes from the standard except for [comment: wording]

DW_AT_decl_file DW_AT_call_file

  Documented in Sec 2.14 Declaration Coordinates
  (page 50).
  The value of the DW_AT_decl_file attribute corresponds 
  to a file number from the line number information table 
  for the compilation unit containing the debugging information 
  entry and represents the source file in which the
  declaration appeared (see Section 6.2 on page 148). 
  The value 0 indicates that no source file has been specified.

Sec 3.3.9.2 Concrete Instances, page 83

  [comment: also says Section 2.14 applies to
  these two attributes].

DW_MACRO_start_file

  Sec 6.3.3.1 page 169
  The source file name index is the file number
  in the line number information table for the
  compilation unit.
  [comment: Nothing is said about 0 meaning no source file.]
  [comment: Likely intended to be like Section 2.14.]

DW_LNS_set_file

  Defined in sec 6.2.5.2 page 162.
  Stores the file value into the file register of
  the state machine.
  [comment: Nothing is said about 0 meaning no source file.]

line table header, pg 157. 20. file_names (sequence of file name entries)

  The first entry in the sequence is the primary source file
  whose file name exactly matches that given in the DW_AT_name
  attribute in the compilation unit debugging information
  entry.
  The line number program references file names in this
  sequence beginning with 0, and uses those numbers instead
  of file names in the line number program that follows.
  [comment: This contradicts DW_AT_decl_file
  and DW_AT_call_file file numbers.]


Table 6.3 state machine registers page 150. file

  An unsigned integer indicating the identity of
  the source file corresponding to a machine
  instruction. While not stated it is clear this
  refers to the line table header file table.
  [comment: Nothing is said about 0 meaning no source file.]
  The first entry in the sequence is the primary source
  file whose file name exactly matches that given in the
  DW_AT_name attribute in the compilation unit debugging
  information entry.


Table 6.4 initial conditions of state machine Page 153 file 1

  [comment: Nothing is said about 0 meaning no source file.]
  [comment: There is an assumption that the file
  table has at least one entry, and that first
  entry is numbered 1.]
  [ Comment: this is consistent with the above quotes
  about the state machine registers, but
  inconsistent with the standard as a whole..
  Change the default to zero in DWARF5]

Section 6.2.4 on file numbers in the header page 158

  The line number program references file names in this
  sequence beginning with 0, and uses those numbers instead
  of file names in the line number program that follows.