Issue 080112.2: FORM Reform Proposal 2: Block Class Forms and Expressions

Author: Cary Coutant
Champion: Cary Coutant
Date submitted: 2008-01-12
Date revised:
Date closed:
Type: Extension
Status: Accepted with changes
DWARF Version: 4
Background

Since expressions can contain reference to DIEs, it's important for any 
generic DWARF consumer to be able to identify and parse expressions without 
a complete understanding of what attributes may have blocks that should be 
treated as expressions. This proposal adds a new form, DW_FORM_expr, which 
takes a ULEB128 length parameter, followed by "length" bytes interpreted as 
an expression.

I don't believe that fixed 1-, 2-, 4-, and 8-byte lengths are necessary 
here -- any producer should be able to determine how long the expression 
is before it needs to emit the length field.

This proposal also deprecates DW_FORM_block1, block2, and block4 in favor 
of DW_FORM_block. For blocks that aren't expressions (e.g., constant values 
expressed as a block of bytes), the length of the block can just as easily 
be expressed as a ULEB128. Any producer can reasonably be expected to know 
how long the block is before it needs to emit the length.


Proposal

The proposed changes to the DWARF specification are detailed below, keyed 
to the section numbering for the December 20, 2005, version of the DWARF-3 
document.

In Section 2.2, "Attribute Types," add the following row to the table of 
Figure 3:

 expr     An arbitrary number of bytes of data, interpreted
          as a DWARF expression (see Section 2.5).

[Note: The terminology for DWARF expressions has been under discussion. 
This proposal may need to be updated to be consistent with the final 
terminology.]

In Section 6.4.2.2, "CFA Definition Instructions," Item 6, 
"DW_CFA_def_cfa_expression", change "DW_FORM_block" to "DW_FORM_expr".

In Section 7.5.4, "Attribute Encodings," add the following paragraph to 
the description of class block:

 The use of forms DW_FORM_block1, DW_FORM_block2,
 and DW_FORM_block4 is deprecated. Producers should
 use DW_FORM_block instead.

Add the following paragraphs immediately preceding the description for 
class flag:

 expr

   Represented as an unsigned LEB128 length followed by the
   number of bytes specified by the length (DW_FORM_expr).
   The information bytes contain a DWARF expression (see
   Section 2.5).

In FIgure 20, "Attribute encodings," change "block" to "expr" in the 
"Classes" column for the following attributes:

 DW_AT_location
 DW_AT_byte_size
 DW_AT_bit_offset
 DW_AT_bit_size
 DW_AT_string_length
 DW_AT_lower_bound
 DW_AT_return_addr
 DW_AT_upper_bound
 DW_AT_count
 DW_AT_data_member_location
 DW_AT_discr_list
 DW_AT_frame_base
 DW_AT_namelist_item
 DW_AT_segment
 DW_AT_static_link
 DW_AT_use_location
 DW_AT_vtable_elem_location
 DW_AT_allocated
 DW_AT_associated
 DW_AT_data_location
 DW_AT_byte_stride

In Figure 21, add the following row:

 Form name       Value    Class

 DW_FORM_expr    0x18     expr

--

Accepted with changes:
  1.  Remove DW_AT_namelist_item from list of changes
  2.  Fix typo on pg. 136 -- DW_AT_namelist_item is reference, not block
  3.  No deprecation of block1-4
  4.  Clarify block form description (pg. 126) with reference to expr.