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

Michael Eager eager at eagercon.com
Mon May 9 16:04:05 PDT 2022

On 5/9/22 13:18, Pedro Alves via Dwarf-Discuss wrote:
> 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?
> 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.

DWARF tries to avoid having one piece of information with a clear 
description imply or suggest something else, with perhaps different 
implications for different people.

It seems to me that other languages (Ada?) have variables which do not 
fill the data type, so it would be reasonable for them to have a 
DW_AT_bit_size which is different from the data type size, yet not be a 
bit field.

As currently described, DW_AT_bit_size only describes the size of the 
data, nothing more, and only when that cannot be determined from the 
size of the base type.  If you want to change the definition to say that 
it has an additional meaning (describing a bit field with a certain 
size), submit an issue.  Alternately, Todd suggested a new flag to 
identify a bit field.

Michael Eager

More information about the Dwarf-Discuss mailing list