forked from qt-creator/qt-creator
Debugger: print QFlags and bitfields as hex
It's a lot more useful to see in Qt Creator: QAbstractFileEngine::FlagsMask (0xff00000) Than QAbstractFileEngine::FlagsMask (267386880) Change-Id: I8d96dea9955d4c749b99fffd14cd690574b433e5 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -2734,7 +2734,7 @@ class DumperBase:
|
||||
#warn('BITFIELD VALUE: %s %d %s' % (value.name, value.lvalue, typeName))
|
||||
self.putNumChild(0)
|
||||
if typeobj.ltarget and typeobj.ltarget.code == TypeCodeEnum:
|
||||
self.putValue(typeobj.ltarget.typeData().enumDisplay(value.lvalue, value.laddress))
|
||||
self.putValue(typeobj.ltarget.typeData().enumHexDisplay(value.lvalue, value.laddress))
|
||||
else:
|
||||
self.putValue(value.lvalue)
|
||||
self.putType(typeName)
|
||||
@@ -2891,9 +2891,11 @@ class DumperBase:
|
||||
% (self.name, self.type.name, self.lbitsize, self.lbitpos,
|
||||
self.dumper.hexencode(self.ldata), addr)
|
||||
|
||||
def display(self):
|
||||
def display(self, useHex = 1):
|
||||
if self.type.code == TypeCodeEnum:
|
||||
intval = self.integer()
|
||||
if useHex:
|
||||
return self.type.typeData().enumHexDisplay(intval, self.laddress)
|
||||
return self.type.typeData().enumDisplay(intval, self.laddress)
|
||||
simple = self.value()
|
||||
if simple is not None:
|
||||
|
||||
@@ -354,7 +354,9 @@ class Dumper(DumperBase):
|
||||
}[code]
|
||||
if tdata.code == TypeCodeEnum:
|
||||
tdata.enumDisplay = lambda intval, addr : \
|
||||
self.nativeTypeEnumDisplay(nativeType, intval)
|
||||
self.nativeTypeEnumDisplay(nativeType, intval, 0)
|
||||
tdata.enumHexDisplay = lambda intval, addr : \
|
||||
self.nativeTypeEnumDisplay(nativeType, intval, 1)
|
||||
if tdata.code == TypeCodeStruct:
|
||||
tdata.lalignment = lambda : \
|
||||
self.nativeStructAlignment(nativeType)
|
||||
@@ -385,13 +387,17 @@ class Dumper(DumperBase):
|
||||
targs2 = self.listTemplateParametersManually(str(nativeType))
|
||||
return targs if len(targs) >= len(targs2) else targs2
|
||||
|
||||
def nativeTypeEnumDisplay(self, nativeType, intval):
|
||||
def nativeTypeEnumDisplay(self, nativeType, intval, useHex):
|
||||
if useHex:
|
||||
format = lambda text, intval: '%s (0x%04x)' % (text, intval)
|
||||
else:
|
||||
format = lambda text, intval: '%s (%d)' % (text, 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)
|
||||
return format(field.name, intval)
|
||||
enumerators.append((field.name, field.enumval))
|
||||
|
||||
# No match was found, try to return as flags
|
||||
@@ -407,9 +413,11 @@ class Dumper(DumperBase):
|
||||
if not found or v != 0:
|
||||
# Leftover value
|
||||
flags.append('unknown:%d' % v)
|
||||
return "(%s) (%d)" % (" | ".join(flags), intval)
|
||||
return format(" | ".join(flags), intval)
|
||||
except:
|
||||
pass
|
||||
if useHex:
|
||||
return '0x%04x' % intval;
|
||||
return '%d' % intval
|
||||
|
||||
def nativeTypeId(self, nativeType):
|
||||
|
||||
@@ -643,7 +643,7 @@ def qdump__QFlags(d, value):
|
||||
i = value.split('{int}')[0]
|
||||
enumType = value.type[0]
|
||||
if d.isGdb:
|
||||
d.putValue(i.cast('enum ' + enumType.name).display())
|
||||
d.putValue(i.cast('enum ' + enumType.name).display(useHex = 1))
|
||||
else:
|
||||
d.putValue(i.cast(enumType.name).display())
|
||||
d.putNumChild(0)
|
||||
|
||||
Reference in New Issue
Block a user