While testing register fields I found that if you put the max value into a bitfield with an underlying type that is an unsigned enum, lldb would not print the enum name. This is because the code to match values to names wasn't checking whether the enum's type was signed, it just assumed it was. So for example a 2 bit field with value 3 got signed extended to -1, which didn't match the enumerator value of 3. So lldb just printed the number instead of the name. For a value of 1, the top bit was 0 so the sign extend became a zero extend, and lldb did print the name of the enumerator. I added a new test because I needed to use C++ to get typed enums. It checks min, max and an in between value for signed and unsigned enums applied to a bitfield.
25 lines
647 B
C++
25 lines
647 B
C++
enum class SignedEnum : int { min = -2, max = 1 };
|
|
enum class UnsignedEnum : unsigned { min = 0, max = 3 };
|
|
|
|
struct BitfieldStruct {
|
|
SignedEnum signed_min : 2;
|
|
SignedEnum signed_other : 2;
|
|
SignedEnum signed_max : 2;
|
|
UnsignedEnum unsigned_min : 2;
|
|
UnsignedEnum unsigned_other : 2;
|
|
UnsignedEnum unsigned_max : 2;
|
|
};
|
|
|
|
int main() {
|
|
BitfieldStruct bfs;
|
|
bfs.signed_min = SignedEnum::min;
|
|
bfs.signed_other = static_cast<SignedEnum>(-1);
|
|
bfs.signed_max = SignedEnum::max;
|
|
|
|
bfs.unsigned_min = UnsignedEnum::min;
|
|
bfs.unsigned_other = static_cast<UnsignedEnum>(1);
|
|
bfs.unsigned_max = UnsignedEnum::max;
|
|
|
|
return 0; // break here
|
|
}
|