[Lldb-commits] [lldb] [lldb] Fix printing of unsigned enum bitfields when they contain the max value (PR #96202)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 10 05:03:11 PDT 2024


DavidSpickett wrote:

Clang's decision to emit DW_AT_type or not goes back to https://reviews.llvm.org/D42734 and in particular this code:
```
void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
  const DIType *DTy = resolve(CTy->getBaseType());
  bool IsUnsigned = DTy && isUnsignedDIType(DD, DTy);
  if (DTy && DD->getDwarfVersion() >= 3)
    addType(Buffer, DTy);
```

DWARF v2 (https://dwarfstd.org/doc/dwarf-2.0.0.pdf) does have the concept of DW_AT_type but it does not mention that it may be found in enumeration types.

"5.6 Enumeration Type Entries
<...>
Each enumerator entry has a DW_AT_name attribute, whose value is a null-terminated string
containing the name of the enumeration literal as it appears in the source program. Each
enumerator entry also has a DW_AT_const_value attribute, whose value is the actual numeric
value of the enumerator as represented on the target system."

So perhaps you could infer the type from the enumerators, but this is ambiguous if you only have positive enumerators within signed int's range. If the debugger is in C/C++ mode, it's reasonable for it to assume signed int most of the time.

In DWARF v3 (https://dwarfstd.org/doc/Dwarf3.pdf) "5.8 Enumeration Type Entries" we have an explicit mention of DW_AT_type.

"The enumeration type entry may also have a DW_AT_type attribute which refers to the
underlying data type used to implement the enumeration.

In C or C++, the underlying type will be the appropriate integral type determined by the
compiler from the properties of the enumeration literal values."

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16063 for details on what g++ did for this.
```
	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if DWARF
	version >= 3 or not strict DWARF.
```
If you pass `-gstrict-dwarf` to g++ then DW_AT_type is not emitted.

Clang does have that option so we could do the same, let me see what `-gstrict-dwarf` things we have currently.

https://github.com/llvm/llvm-project/pull/96202


More information about the lldb-commits mailing list