On 4/17/25 3:58 PM, Tom Tromey via Dwarf-discuss wrote: > Consider the appended Ada program. Here, the offset of "Another_Field" > is a non-constant number of bits from the start of the object. > > I think there is no way to represent this in DWARF 5. Section 5.7.6, > page 119 says: > > For a DW_AT_data_bit_offset attribute, the value is an integer > constant (see Section 2.19 on page 55) that specifies the number of > bits from the beginning of the containing entity to the beginning of > the data member. This value must be greater than or equal to zero, > but is not limited to less than the number of bits per byte. > > GNAT works around this using the deprecated-in-DWARF-4 DW_AT_bit_offset > in conjunction with DW_AT_data_member_location. (You need a patch to > GNAT to see this in action.)
Just to make sure I understand, can you clarify how DW_AT_data_member_location and DW_AT_bit_offset are used in this case? In particular, which one is constant and which one is an evaluated expression? > One way to fix this would be to lift the "integer constant" restriction > and allow an expression here. I think that this case would be naturally handled by the "DWARF locations on the stack" proposal that is currently being studied (and that will mostly likely be part of DWARF 6 in some form). You would use DW_AT_data_member_location, which pushes the location of the containing entity on the stack, prior to the evaluation. The expression would then compute the dynamic bit offset of offset the location of that amount using DW_OP_bit_offset to yield the location of the member. That being said, I don't see any reason why DW_AT_data_bit_offset couldn't be made to be an expression that yields a value. I think we should open an issue for that. Simon -- Dwarf-discuss mailing list Dwarf-discuss@lists.dwarfstd.org https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss