Skip to content

Commit 3101524

Browse files
[lldb] Print "0x0" for bitfield like enums where the value is 0 (#97557)
Enums like this one are treated as bitfield like enums: enum FlagsLike {B=2, C=4}; lldb recognises them as collections of flags, so you can have "B | C". If there's any values not covered that's printed as hex "B | C | 0x1". What happened if the value was 0 was we would not match any of the enumerators, then the remainder check requires that the remainder is non-zero. So lldb would print nothing at all. Which I assume is a bug because knowing that no flags are set is useful, just as much as knowing that some unkown bit was set to make it non-zero.
1 parent 41fddc4 commit 3101524

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8693,6 +8693,13 @@ static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s,
86938693
return true;
86948694
}
86958695

8696+
if (!enum_uvalue) {
8697+
// This is a bitfield enum, but the value is 0 so we know it won't match
8698+
// with any of the enumerators.
8699+
s.Printf("0x%" PRIx64, enum_uvalue);
8700+
return true;
8701+
}
8702+
86968703
uint64_t remaining_value = enum_uvalue;
86978704
std::vector<std::pair<uint64_t, llvm::StringRef>> values;
86988705
values.reserve(num_enumerators);
@@ -8717,7 +8724,8 @@ static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s,
87178724
s.PutCString(" | ");
87188725
}
87198726

8720-
// If there is a remainder that is not covered by the value, print it as hex.
8727+
// If there is a remainder that is not covered by the value, print it as
8728+
// hex.
87218729
if (remaining_value)
87228730
s.Printf("0x%" PRIx64, remaining_value);
87238731

lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ TEST_F(ValueObjectMockProcessTest, Enum) {
165165
TEST_F(ValueObjectMockProcessTest, BitFieldLikeEnum) {
166166
// These enumerators set individual bits in the value, as if it were a flag
167167
// set. lldb treats this as a "bitfield like enum". This means we show values
168-
// as hex, a value of 0 shows nothing, and values with no exact enumerator are
169-
// shown as combinations of the other values.
168+
// as hex, and values without exact matches are shown as a combination of
169+
// enumerators and any remaining value left over.
170170
TestDumpValueObject(
171171
MakeEnumType({{"test_2", 2}, {"test_4", 4}}, false),
172172
{
173-
{0, {}, "(TestEnum) test_var =\n"},
173+
{0, {}, "(TestEnum) test_var = 0x0\n"},
174174
{1, {}, "(TestEnum) test_var = 0x1\n"},
175175
{2, {}, "(TestEnum) test_var = test_2\n"},
176176
{4, {}, "(TestEnum) test_var = test_4\n"},

0 commit comments

Comments
 (0)