Commit 0c9f23db authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

GDB: Fix printing of flag enums

It worked with plain GDB (parse_and_eval), and was broken by
696b2d42.

Change-Id: Ibc143efdbd90681a2f9f4d84b75063eb98078f2b
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent eb4b4d7b
......@@ -379,9 +379,27 @@ class Dumper(DumperBase):
def nativeTypeEnumDisplay(self, nativeType, intval):
try:
enumerators = []
for field in nativeType.fields():
# If we found an exact match, return it immediately
if field.enumval == intval:
return '%s (%d)' % (field.name, intval)
enumerators.append((field.name, field.enumval))
# No match was found, try to return as flags
enumerators.sort(key = lambda x: x[1])
flags = []
v = intval
found = False
for (name, value) in enumerators:
if v & value != 0:
flags.append(name)
v = v & ~value
found = True
if not found or v != 0:
# Leftover value
flags.append('unknown:%d' % v)
return "(%s) (%d)" % (" | ".join(flags), intval)
except:
pass
return '%d' % intval
......
......@@ -5094,6 +5094,20 @@ void tst_Dumpers::dumper_data()
+ Check("fd", "d (2)", "Foo");
QTest::newRow("EnumFlags")
<< Data("\n"
"enum Flags { one = 1, two = 2, four = 4 };\n",
"Flags fone = one; unused(&fone);\n"
"Flags fthree = (Flags)(one|two); unused(&fthree);\n"
"Flags fmixed = (Flags)(two|8); unused(&fmixed);\n"
"Flags fbad = (Flags)(24); unused(&fbad);\n")
+ GdbEngine
+ Check("fone", "one (1)", "Flags")
+ Check("fthree", "(one | two) (3)", "Flags")
+ Check("fmixed", "(two | unknown:8) (10)", "Flags")
+ Check("fbad", "(unknown:24) (24)", "Flags");
QTest::newRow("Array")
<< Data("double a1[3][3];\n"
"for (int i = 0; i != 3; ++i)\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment