Skip to content

[lldb] Print "0x0" for bitfield like enums where the value is 0 #97557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8680,6 +8680,13 @@ static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s,
return true;
}

if (!enum_uvalue) {
// This is a bitfield enum, but the value is 0 so we know it won't match
// with any of the enumerators.
s.Printf("0x%" PRIx64, enum_uvalue);
return true;
}

uint64_t remaining_value = enum_uvalue;
std::vector<std::pair<uint64_t, llvm::StringRef>> values;
values.reserve(num_enumerators);
Expand All @@ -8704,7 +8711,8 @@ static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s,
s.PutCString(" | ");
}

// If there is a remainder that is not covered by the value, print it as hex.
// If there is a remainder that is not covered by the value, print it as
// hex.
if (remaining_value)
s.Printf("0x%" PRIx64, remaining_value);

Expand Down
6 changes: 3 additions & 3 deletions lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ TEST_F(ValueObjectMockProcessTest, Enum) {
TEST_F(ValueObjectMockProcessTest, BitFieldLikeEnum) {
// These enumerators set individual bits in the value, as if it were a flag
// set. lldb treats this as a "bitfield like enum". This means we show values
// as hex, a value of 0 shows nothing, and values with no exact enumerator are
// shown as combinations of the other values.
// as hex, and values without exact matches are shown as a combination of
// enumerators and any remaining value left over.
TestDumpValueObject(
MakeEnumType({{"test_2", 2}, {"test_4", 4}}),
{
{0, {}, "(TestEnum) test_var =\n"},
{0, {}, "(TestEnum) test_var = 0x0\n"},
{1, {}, "(TestEnum) test_var = 0x1\n"},
{2, {}, "(TestEnum) test_var = test_2\n"},
{4, {}, "(TestEnum) test_var = test_4\n"},
Expand Down
Loading