Debugger: Change/improve LLDB display of enums in some cases

This fixes the Internal2, EnumFlags and EnumInClass tests on Linux.

The values lose now the previously hand-crafted Class:: prefixes,
but the context is clear from the type column, and it's what LLDB
developers (and potentially users) consider normal.

Change-Id: I09e41f7b4fb4f078ef3f535fe650d06e7c2a0331
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2020-12-11 08:42:58 +01:00
parent 0a20b8e7de
commit d4ed07eb87
2 changed files with 17 additions and 16 deletions

View File

@@ -219,16 +219,14 @@ class Dumper(DumperBase):
if code == lldb.eTypeClassEnumeration: if code == lldb.eTypeClassEnumeration:
intval = nativeValue.GetValueAsSigned() intval = nativeValue.GetValueAsSigned()
if hasattr(nativeType, 'get_enum_members_array'): display = str(nativeValue).split(' = ')
for enumMember in nativeType.get_enum_members_array(): if len(display) == 2:
# Even when asking for signed we get unsigned with LLDB 3.8. verbose = display[1]
diff = enumMember.GetValueAsSigned() - intval if '|' in verbose and not verbose.startswith('('):
mask = (1 << nativeType.GetByteSize() * 8) - 1 verbose = '(' + verbose + ')'
if diff & mask == 0: else:
path = nativeType.GetName().split('::') verbose = intval
path[-1] = enumMember.GetName() val.ldisplay = '%s (%d)' % (verbose, intval)
val.ldisplay = '%s (%d)' % ('::'.join(path), intval)
val.ldisplay = '%d' % intval
elif code in (lldb.eTypeClassComplexInteger, lldb.eTypeClassComplexFloat): elif code in (lldb.eTypeClassComplexInteger, lldb.eTypeClassComplexFloat):
val.ldisplay = str(nativeValue.GetValue()) val.ldisplay = str(nativeValue.GetValue())
#elif code == lldb.eTypeClassArray: #elif code == lldb.eTypeClassArray:

View File

@@ -5905,7 +5905,7 @@ void tst_Dumpers::dumper_data()
"Flags fone = one;\n" "Flags fone = one;\n"
"Flags fthree = (Flags)(one|two);\n" "Flags fthree = (Flags)(one|two);\n"
"Flags fmixed = (Flags)(two|8);\n" "Flags fmixed = (Flags)(two|8);\n"
"Flags fbad = (Flags)(24);", "Flags fbad = (Flags)(8);",
"&fone, &fthree, &fmixed, &fbad") "&fone, &fthree, &fmixed, &fbad")
@@ -5913,8 +5913,10 @@ void tst_Dumpers::dumper_data()
+ Check("fone", "one (1)", "Flags") + Check("fone", "one (1)", "Flags")
+ Check("fthree", "(one | two) (3)", "Flags") + Check("fthree", "(one | two) (3)", "Flags")
+ Check("fmixed", "(two | unknown: 8) (10)", "Flags") // There are optional 'unknown:' prefixes and possibly hex
+ Check("fbad", "(unknown: 24) (24)", "Flags"); // displays for the unknown flags.
+ Check("fmixed", ValuePattern("(two \\| .*8) (10)"), "Flags")
+ Check("fbad", ValuePattern(".*8.* (.*8)"), "Flags");
QTest::newRow("EnumInClass") QTest::newRow("EnumInClass")
@@ -5933,9 +5935,10 @@ void tst_Dumpers::dumper_data()
+ NoCdbEngine + NoCdbEngine
+ Check("e.e1", "(E::b1 | E::c1) (3)", "E::Enum1") // GDB prefixes with E::, LLDB not.
+ Check("e.e2", "(E::b2 | E::c2) (3)", "E::Enum2") + Check("e.e1", ValuePattern("(.*b1 \\| .*c1) (3)"), "E::Enum1")
+ Check("e.e3", "(E::b3 | E::c3) (3)", "E::Enum3"); + Check("e.e2", ValuePattern("(.*b2 \\| .*c2) (3)"), "E::Enum2")
+ Check("e.e3", ValuePattern("(.*b3 \\| .*c3) (3)"), "E::Enum3");
QTest::newRow("QSizePolicy") QTest::newRow("QSizePolicy")