[Dwarf-Discuss] EXTERNAL: Corner-cases with bitfields

Robinson, Paul paul.robinson at sony.com
Mon May 9 14:41:03 PDT 2022


> Pedro Alves wrote:
> On 2022-05-09 16:48, Ron Brender via Dwarf-Discuss wrote:
> > So my suggestion is to file a bug report with CLANG, requesting they
> correct their DWARF output to reflect all details needed
> > by your language.
> 
> An issue here is that DWARF does say this, in (DWARF 5, 5.7.6 Data Member
> Entries, page 119):
> 
>  "If the size of a data member is not the same as the size of the type
> given for the
> 
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> ^^^^^^^
>  data member, the data member has either a DW_AT_byte_size or a
>  ^^^^^^^^^^^
>  DW_AT_bit_size attribute whose integer constant value (see Section 2.19
> on
>  page 55) is the amount of storage needed to hold the value of the data
> member."
> 
> Note the part I underlined.  In Lancelot's case, the size of the data
> member
> IS the same as the size of the type given for the data member.  So Clang
> could well pedantically
> claim that they _are_ following the spec.  Shouldn't the spec be clarified
> here?

What the spec says is that a producer isn't _required_ to emit the
DW_AT_bit_size attribute.  But, given that DWARF is a permissive
standard, the producer is certainly _allowed_ to emit the attribute.  
If this is a hint that the target debugger will understand, regarding
the ABI, it seems okay to me for the producer to do that.

> This then raises the question of whether a debugger can assume that the
> presence of a DW_AT_bit_size
> attribute indicates that the field is a bit field at the C/C++ source
> level.  GDB is assuming that
> today, as there's really no other way to tell, but I don't think the spec
> explicitly says so.

GDB is choosing to make that interpretation, which it's allowed to do.
The DWARF spec just doesn't promise that interpretation is correct.

You can propose to standardize that interpretation by filing an issue
with the DWARF committee at https://dwarfstd.org/Comment.php and it might
or might not become part of DWARF v6.  It might be tricky because you'd
be generalizing something very specific to your environment.

You can also, separately, try to get Clang to emit the DW_AT_bit_size
attribute in these cases for the AMDGPU target(s).  This seems more
likely to work, especially as there's an ABI requirement involved, and
(given that GDB makes this interpretation) I assume gcc already does this.

--paulr



More information about the Dwarf-Discuss mailing list