Commit 26fa769b authored by hjk's avatar hjk Committed by hjk

Debugger: Add dumper for QMeta{Enum,Method,Property}

Task-number: QTCREATORBUG-16593
Change-Id: Iaa710660d8ef69459596f93831cf8467913f0468
Reviewed-by: Alexandru Croitor's avatarAlexandru Croitor <alexandru.croitor@qt.io>
parent ac1c04b6
......@@ -737,12 +737,16 @@ class DumperBase:
with Children(self):
self.putFields(value, dumpBase)
def putMembersItem(self, value, sortorder = 10):
with SubItem(self, "[members]"):
self.put('sortgroup="%s"' % sortorder)
self.putPlainChildren(value)
def isMapCompact(self, keyType, valueType):
if self.currentItemFormat() == CompactMapFormat:
return True
return self.isSimpleType(keyType) and self.isSimpleType(valueType)
def check(self, exp):
if not exp:
raise RuntimeError("Check failed")
......@@ -923,13 +927,6 @@ class DumperBase:
# self.expandedINames, self.currentIName in self.expandedINames))
return self.currentIName in self.expandedINames
def putPlainChildren(self, value):
self.putEmptyValue(-99)
self.putNumChild(1)
if self.currentIName in self.expandedINames:
with Children(self):
self.putFields(value)
def putCStyleArray(self, value):
arrayType = value.type.unqualified()
innerType = value[0].type
......@@ -1325,50 +1322,6 @@ class DumperBase:
self.knownStaticMetaObjects[typeName] = result
return result
def staticQObjectMetaData(self, metaobject, offset1, offset2, step):
items = []
dd = metaobject["d"]
data = self.extractPointer(dd["data"])
sd = self.extractPointer(dd["stringdata"])
metaObjectVersion = self.extractInt(data)
itemCount = self.extractInt(data + offset1)
itemData = -offset2 if offset2 < 0 else self.extractInt(data + offset2)
if metaObjectVersion >= 7: # Qt 5.
byteArrayDataType = self.lookupType(self.qtNamespace() + "QByteArrayData")
byteArrayDataSize = byteArrayDataType.sizeof
for i in range(itemCount):
x = data + (itemData + step * i) * 4
literal = sd + self.extractInt(x) * byteArrayDataSize
ldata, lsize, lalloc = self.byteArrayDataHelper(literal)
items.append(self.extractBlob(ldata, lsize).toString())
else: # Qt 4.
for i in range(itemCount):
x = data + (itemData + step * i) * 4
ldata = sd + self.extractInt(x)
items.append(self.extractCString(ldata).decode("utf8"))
return items
def staticQObjectPropertyCount(self, metaobject):
return self.extractInt(self.extractPointer(metaobject["d"]["data"]) + 24)
def staticQObjectPropertyNames(self, metaobject):
return self.staticQObjectMetaData(metaobject, 24, 28, 3)
def staticQObjectMethodCount(self, metaobject):
return self.extractInt(self.extractPointer(metaobject["d"]["data"]) + 16)
def staticQObjectMethodNames(self, metaobject):
return self.staticQObjectMetaData(metaobject, 16, 20, 5)
def staticQObjectSignalCount(self, metaobject):
return self.extractInt(self.extractPointer(metaobject["d"]["data"]) + 52)
def staticQObjectSignalNames(self, metaobject):
return self.staticQObjectMetaData(metaobject, 52, -14, 5)
def extractCString(self, addr):
result = bytearray()
while True:
......@@ -1406,6 +1359,21 @@ class DumperBase:
for i in range(size):
yield self.createValue(data + i * innerSize, innerType)
def putStructGuts(self, value):
self.putEmptyValue()
if self.showQObjectNames:
staticMetaObject = self.extractStaticMetaObject(value.type)
if staticMetaObject:
self.context = value
self.putQObjectNameValue(value)
if self.isExpanded():
self.put('sortable="1"')
with Children(self, 1, childType=None):
self.putFields(value)
if not self.showQObjectNames:
staticMetaObject = self.extractStaticMetaObject(value.type)
if staticMetaObject:
self.putQObjectGuts(value, staticMetaObject)
# This is called is when a QObject derived class is expanded
def putQObjectGuts(self, qobject, smo):
......@@ -1414,9 +1382,14 @@ class DumperBase:
# Parent and children.
try:
d_ptr = qobject["d_ptr"]["d"]
self.putSubItem("[parent]", d_ptr["parent"])
self.putSubItem("[children]", d_ptr["children"])
if qobject:
d_ptr = qobject["d_ptr"]["d"]
with SubItem(self, "[parent]"):
self.putItem(d_ptr["parent"])
self.put('sortgroup="9"')
with SubItem(self, "[children]"):
self.putItem(d_ptr["children"])
self.put('sortgroup="1"')
except:
pass
......@@ -1424,29 +1397,46 @@ class DumperBase:
isQt5 = self.qtVersion() >= 0x50000
extraDataOffset = 5 * ptrSize + 8 if isQt5 else 6 * ptrSize + 8
extraData = self.extractPointer(dd + extraDataOffset)
self.putQObjectGutsHelper(extraData, dd, smo)
self.putQObjectGutsHelper(qobject, extraData, -1, smo, "QObject")
def metaString(self, metaObject, index, revision = 7):
sd = self.extractPointer(metaObject["d"]["stringdata"])
if revision >= 7: # Qt 5.
byteArrayDataType = self.lookupQtType("QByteArrayData")
byteArrayDataSize = byteArrayDataType.sizeof
literal = toInteger(sd) + toInteger(index) * byteArrayDataSize
ldata, lsize, lalloc = self.byteArrayDataHelper(literal)
try:
return self.extractBlob(ldata, lsize).toString()
except:
return "<unavailable>"
else: # Qt 4.
ldata = sd + index
return self.extractCString(ldata).decode("utf8")
def putQMetaStuff(self, value, origType):
metaObject = value["mobj"]
if not metaObject:
self.putEmptyValue()
if self.isExpanded():
with Children(self):
self.putFields(value)
else:
handle = toInteger(value["handle"])
index = toInteger(metaObject["d"]["data"][handle])
name = self.metaString(metaObject.dereference(), index)
self.putValue(name)
self.putNumChild(1)
if self.isExpanded():
with Children(self):
self.putFields(value)
self.putQObjectGutsHelper(0, 0, handle, metaObject, origType)
def putQObjectGutsHelper(self, extraData, dd, smo):
def putQObjectGutsHelper(self, qobject, extraData, handle, metaObject, origType):
intSize = self.intSize()
ptrSize = self.ptrSize()
data = smo["d"]["data"]
#warn("DATA: %s" % data)
def metaString(offset):
ddata = self.extractPointer(data)
sd = self.extractPointer(smo["d"]["stringdata"])
metaObjectVersion = self.extractInt(ddata)
if metaObjectVersion >= 7: # Qt 5.
byteArrayDataType = self.lookupType(self.qtNamespace() + "QByteArrayData")
byteArrayDataSize = byteArrayDataType.sizeof
literal = sd + offset * byteArrayDataSize
ldata, lsize, lalloc = self.byteArrayDataHelper(literal)
return self.extractBlob(ldata, lsize).toString()
else: # Qt 4.
ldata = sd + offset
return self.extractCString(ldata).decode("utf8")
data = metaObject["d"]["data"]
def walker(base):
ptr = toInteger(base)
......@@ -1454,63 +1444,105 @@ class DumperBase:
yield self.extractInt(ptr)
ptr += intSize
def put1(name, p):
x = p.next()
with SubItem(self, name):
self.putValue(x)
self.putType("uint")
self.putNumChild(0)
return x
def put2(name, p):
xy = (p.next(), p.next())
with SubItem(self, name):
self.putValue("%s %s" % xy)
self.putType("uint")
self.putNumChild(0)
return xy[0]
def putt(name, value):
def putt(name, value, typeName = ' '):
with SubItem(self, name):
self.putValue(value)
self.putType(" ")
self.putType(typeName)
self.putNumChild(0)
with SubItem(self, "[raw]"):
self.putEmptyValue()
self.putNumChild(1)
if self.isExpanded():
self.put('sortable="0"')
def superData(mo):
return mo['d']['superdata']
isQMetaObject = origType == "QMetaObject"
isQObject = origType == "QObject"
p = walker(data)
revision = p.next()
classname = p.next()
classinfo = p.next()
classinfo2 = p.next()
methodCount = p.next()
methods = p.next()
propertyCount = p.next()
properties = p.next()
enumCount = p.next()
enums = p.next()
constructorCount = p.next()
constructors = p.next()
flags = p.next()
signalCount = p.next()
globalOffset = 0
superdata = superData(metaObject)
while toInteger(superdata):
sdata = superdata["d"]["data"]
p = walker(sdata)
revision = p.next()
classname = p.next()
classinfo = p.next()
classinfo2 = p.next()
methodCount = p.next()
globalOffset += methodCount
superdata = superData(superdata)
largestStringIndex = -1
for i in range(methodCount):
t = (p.next(), p.next(), p.next(), p.next(), p.next())
if largestStringIndex < t[0]:
largestStringIndex = t[0]
if isQMetaObject:
with SubItem(self, "[strings]"):
self.put('sortgroup="2"')
self.putSpecialValue("minimumitemcount", largestStringIndex + 1)
self.putNumChild(1)
if self.isExpanded():
with Children(self, largestStringIndex + 1):
for i in self.childRange():
with SubItem(self, i):
self.putValue(self.hexencode(self.metaString(metaObject, i)), "latin1")
self.putNumChild(0)
if isQMetaObject:
with SubItem(self, "[raw]"):
self.put('sortgroup="1"')
p = walker(data)
with Children(self):
put1("revision", p)
put1("classname", p)
put2("classinfo", p)
methodCount = put2("methods", p)
put2("properties", p)
put2("enums/sets", p)
put2("constructors", p)
put1("flags", p)
signalCount = put1("signalCount", p)
if extraData:
with SubItem(self, "[extraData]"):
self.putValue("0x%x" % toInteger(extraData))
self.putType("void *")
self.putNumChild(0)
self.putEmptyValue()
self.putNumChild(1)
if self.isExpanded():
with Children(self):
putt("revision", revision)
putt("classname", classname)
putt("classinfo", classinfo)
putt("methods", "%d %d" % (methodCount, methods))
putt("properties", "%d %d" % (propertyCount, properties))
putt("enums/sets", "%d %d" % (enumCount, enums))
putt("constructors", "%d %d" % (constructorCount, constructors))
putt("flags", flags)
putt("signalCount", signalCount)
p = walker(toInteger(data) + 14 * 4)
for i in range(methodCount):
t = (p.next(), p.next(), p.next(), p.next(), p.next())
putt("method %d" % i, "%s %s %s %s %s" % t)
putt("[extraData]", "0x%x" % toInteger(extraData), "void *")
if isQMetaObject or isQObject:
with SubItem(self, "[properties]"):
propertyCount = 0
usesVector = self.qtVersion() >= 0x50700
self.put('sortgroup="5"')
self.putItemCount(propertyCount)
if self.isExpanded():
propertyNames = self.staticQObjectPropertyNames(smo)
propertyCount = len(propertyNames) # Doesn't include dynamic properties.
usesVector = self.qtVersion() >= 0x50700
with Children(self):
# Static properties.
p = walker(toInteger(data) + properties * 4)
for i in range(propertyCount):
name = propertyNames[i]
self.putCallItem(str(name), qobject, "property", '"' + name + '"')
t = (p.next(), p.next(), p.next())
name = self.metaString(metaObject, t[0])
if qobject:
self.putCallItem(name, qobject, "property", '"' + name + '"')
else:
putt(name, ' ')
# Dynamic properties.
if extraData:
......@@ -1527,68 +1559,93 @@ class DumperBase:
self.put('keyencoded="latin1",')
self.putItem(v)
propertyCount += 1
self.putItemCount(propertyCount)
else:
# We need a handle to [x] for the user to expand the item
# before we know whether there are actual children. Counting
# them is too expensive.
self.putNumChild(1)
self.putSpecialValue("minimumitemcount", 0)
self.putSpecialValue("minimumitemcount", propertyCount)
#with SubItem(self, "[methods]"):
# methodCount = self.staticQObjectMethodCount(smo)
# self.putItemCount(methodCount)
# if self.isExpanded():
# methodNames = self.staticQObjectMethodNames(smo)
# with Children(self):
# for i in range(methodCount):
# k = methodNames[i]
# with SubItem(self, k):
# self.putEmptyValue()
#
with SubItem(self, "[methods]"):
methodCount = self.staticQObjectMethodCount(smo)
self.putItemCount(methodCount)
if self.isExpanded():
with Children(self):
p = walker(toInteger(data) + 14 * 4)
for i in range(methodCount):
t = (p.next(), p.next(), p.next(), p.next(), p.next())
name = metaString(t[0])
with SubItem(self, "[%s]" % i):
self.putValue(name)
self.putType(" ")
self.putNumChild(1)
with Children(self):
putt("name", name)
putt("nameindex", t[0])
if isQMetaObject or isQObject:
with SubItem(self, "[methods]"):
self.put('sortgroup="3"')
self.putItemCount(methodCount)
if self.isExpanded():
with Children(self):
p = walker(toInteger(data) + 14 * 4)
for i in range(methodCount):
t = (p.next(), p.next(), p.next(), p.next(), p.next())
name = self.metaString(metaObject, t[0])
with SubItem(self, i):
self.putValue(name)
self.putType(" ")
self.putNumChild(1)
isSignal = False
flags = t[4]
if flags == 0x06:
putt("type", "signal")
typ = "signal"
isSignal = True
elif flags == 0x0a:
putt("type", "slot")
typ = "slot"
elif flags == 0x0a:
putt("type", "invokable")
putt("argc", t[1])
putt("parameter", t[2])
putt("tag", t[3])
putt("flags", t[4])
with SubItem(self, "[signals]"):
signalCount = self.staticQObjectSignalCount(smo)
self.putItemCount(signalCount)
if self.isExpanded():
signalNames = self.staticQObjectSignalNames(smo)
signalCount = len(signalNames)
with Children(self):
for i in range(signalCount):
k = signalNames[i]
with SubItem(self, k):
self.putEmptyValue()
if dd:
self.putQObjectConnections(dd)
typ = "invokable"
else:
typ = "<unknown>"
with Children(self):
putt("[nameindex]", t[0])
putt("[type]", typ)
putt("[argc]", t[1])
putt("[parameter]", t[2])
putt("[tag]", t[3])
putt("[flags]", t[4])
putt("[localindex]", str(i))
putt("[globalindex]", str(globalOffset + i))
if isQObject:
self.putSubItem("[metaObject]", metaObject)
if isQObject:
with SubItem(self, "d"):
self.put('sortgroup="15"')
self.putItem(qobject["d_ptr"]["d"])
if isQMetaObject:
with SubItem(self, "[superdata]"):
self.put('sortgroup="12"')
superdata = superData(metaObject)
self.putValue("0x%x" % superdata)
if toInteger(superdata):
self.putNumChild(1)
if self.isExpanded():
with Children(self):
self.putSubItem('*', superdata)
else:
self.putNumChild(0)
self.putType(superdata.type)
if handle >= 0:
localIndex = (handle - methods) / 5
with SubItem(self, "[localindex]"):
self.put('sortgroup="12"')
self.putValue(localIndex)
with SubItem(self, "[globalindex]"):
self.put('sortgroup="11"')
self.putValue(globalOffset + localIndex)
#with SubItem(self, "[signals]"):
# self.putItemCount(signalCount)
# signalNames = metaData(52, -14, 5)
# warn("NAMES: %s" % signalNames)
# if self.isExpanded():
# with Children(self):
# putt("A", "b")
# for i in range(signalCount):
# k = signalNames[i]
# with SubItem(self, k):
# self.putEmptyValue()
# if dd:
# self.putQObjectConnections(dd)
def putQObjectConnections(self, dd):
with SubItem(self, "[connections]"):
......
......@@ -1136,23 +1136,10 @@ class Dumper(DumperBase):
#warn("INAME: %s " % self.currentIName)
#warn("INAMES: %s " % self.expandedINames)
#warn("EXPANDED: %s " % (self.currentIName in self.expandedINames))
if self.showQObjectNames:
staticMetaObject = self.extractStaticMetaObject(value.type)
if staticMetaObject:
self.putQObjectNameValue(value)
self.putType(typeName)
self.putEmptyValue()
self.putNumChild(len(typeobj.fields()))
self.putStructGuts(value)
if self.currentIName in self.expandedINames:
innerType = None
self.put('sortable="1"')
with Children(self, 1, childType=innerType):
self.putFields(value)
if not self.showQObjectNames:
staticMetaObject = self.extractStaticMetaObject(value.type)
if staticMetaObject:
self.putQObjectGuts(value, staticMetaObject)
def toBlob(self, value):
size = toInteger(value.type.sizeof)
......@@ -1251,7 +1238,7 @@ class Dumper(DumperBase):
# int (**)(void)
n = 100
self.putType(" ")
self.put('sortgroup="1"')
self.put('sortgroup="20"')
self.putValue(value[field.name])
self.putNumChild(n)
if self.isExpanded():
......@@ -1275,7 +1262,7 @@ class Dumper(DumperBase):
baseNumber += 1
with UnnamedSubItem(self, "@%d" % baseNumber):
baseValue = value.cast(field.type)
self.put('sortgroup="2"')
self.put('sortgroup="30"')
self.putBaseClassName(field.name)
self.putAddress(baseValue.address)
self.putItem(baseValue, False)
......
......@@ -1084,27 +1084,14 @@ class Dumper(DumperBase):
self.putValue(v)
self.putType(typeName)
self.putEmptyValue()
self.putNumChild(numchild)
if self.showQObjectNames:
staticMetaObject = self.extractStaticMetaObject(value.GetType())
if staticMetaObject:
self.context = value
self.putQObjectNameValue(value)
self.putStructGuts(value)
if self.currentIName in self.expandedINames:
self.put('sortable="1"')
with Children(self):
self.putFields(value)
if not self.showQObjectNames:
staticMetaObject = self.extractStaticMetaObject(value.GetType())
if staticMetaObject:
self.putQObjectGuts(value, staticMetaObject)
def warn(self, msg):
self.put('{name="%s",value="",type="",numchild="0"},' % msg)
def putFields(self, value):
def putFields(self, value, dumpBase = True):
# Suppress printing of 'name' field for arrays.
if value.GetType().GetTypeClass() == lldb.eTypeClassArray:
for i in xrange(value.GetNumChildren()):
......@@ -1139,9 +1126,10 @@ class Dumper(DumperBase):
for i in xrange(len(baseObjects)):
baseObject = baseObjects[i]
with UnnamedSubItem(self, "@%d" % (i + 1)):
self.put('iname="%s",' % self.currentIName)
self.put('name="[%s]",' % baseObject.name)
self.putItem(baseObject.value)
self.put('iname="%s",' % self.currentIName)
self.put('name="[%s]",' % baseObject.name)
self.put('sortgroup="30"')
self.putItem(baseObject.value)
memberCount = value.GetNumChildren()
if memberCount > 10000:
......
......@@ -268,28 +268,7 @@ def qdump__QDateTime(d, value):
# {sharedref(4), ...
base = d.extractPointer(value)
is32bit = d.is32bit()
if qtVersion >= 0x050800:
# FIXME: Don't give up.
d.putPlainChildren(value)
return
msecsOffset = 0
statusOffset = 8
offsetFromUtcOffset = 12
timeZoneOffset = 24
status = d.extractInt(base + statusOffset)
if int(status & 0x0c == 0x0c): # ValidDate and ValidTime
isValid = True
msecs = d.extractInt64(base + msecsOffset)
offset = d.extractInt(base + offsetFromUtcOffset)
tzp = d.extractPointer(base + timeZoneOffset)
if tzp == 0:
tz = ""
else:
idBase = tzp + 2 * d.ptrSize() # [QSharedData] + [vptr]
elided, tz = d.encodeByteArrayHelper(d.extractPointer(idBase), limit=100)
d.putValue("%s/%s/%s/%s/%s" % (msecs, -1, offset, tz, status),
"datetimeinternal")
elif qtVersion >= 0x050200:
if qtVersion >= 0x050200:
if d.isWindowsTarget():
msecsOffset = 8
specOffset = 16
......@@ -1110,371 +1089,26 @@ def qdump__QVariantMap(d, value):
qdump__QMap(d, value)
def qdump__QMetaObjectPrivate(d, value):
d.putEmptyValue()
d.putNumChild(1)
if d.isExpanded():
with Children(d):