Commit c959fc5f authored by hjk's avatar hjk
Browse files

Debugger: Use Dumper.putPair in Q{Multi,}Map dumper



Change-Id: I4c9abdc1d14823b35a8cbf3b375acc4a45274193
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 90911fc9
......@@ -182,24 +182,29 @@ class Children:
return True
class PairedChildrenData:
def __init__(self, d, pairType):
def __init__(self, d, pairType, keyType, valueType):
self.pairType = pairType
self.keyType = d.templateArgument(pairType, 0).unqualified()
self.valueType = d.templateArgument(pairType, 1)
self.keyType = keyType
self.valueType = valueType
self.isCompact = d.isMapCompact(self.keyType, self.valueType)
self.childNumChild = None if self.isCompact else 2
self.childType = self.valueType if self.isCompact else self.pairType
self.childType = valueType if self.isCompact else pairType
ns = d.qtNamespace()
self.keyIsQString = str(self.keyType) == ns + "QString"
self.keyIsQByteArray = str(self.keyType) == ns + "QByteArray"
class PairedChildren(Children):
def __init__(self, d, numChild, pairType, maxNumChild = None):
def __init__(self, d, numChild, pairType = None, keyType = None, valueType = None, maxNumChild = None):
self.d = d
d.pairData = PairedChildrenData(d, pairType)
if keyType is None:
keyType = d.templateArgument(pairType, 0).unqualified()
if valueType is None:
valueType = d.templateArgument(pairType, 1)
d.pairData = PairedChildrenData(d, pairType, keyType, valueType)
Children.__init__(self, d, numChild,
d.pairData.childType, d.pairData.childNumChild,
maxNumChild, addrBase = None, addrStep = None)
d.pairData.childType,
maxNumChild = maxNumChild,
addrBase = None, addrStep = None)
def __enter__(self):
self.savedPairData = self.d.pairData if hasattr(self.d, "pairData") else None
......@@ -453,8 +458,16 @@ class DumperBase:
self.put('key="[%d] %s",' % (index, val))
def putPair(self, pair, index = -1):
key = pair["first"]
value = pair["second"]
try:
key = pair["first"]
value = pair["second"]
keyName = "first"
valueName = "second"
except:
key = pair["key"]
value = pair["value"]
keyName = "key"
valueName = "value"
if self.pairData.isCompact:
if self.pairData.keyIsQString:
self.put('key="%s",' % self.encodeString(key))
......@@ -471,10 +484,12 @@ class DumperBase:
self.putItem(value)
else:
self.putEmptyValue()
self.putNumChild(2)
self.putField("iname", self.currentIName)
if self.isExpanded():
with Children(self, 2):
self.putSubItem("first", key)
self.putSubItem("second", value)
with Children(self):
self.putSubItem(keyName, key)
self.putSubItem(valueName, value)
def isMapCompact(self, keyType, valueType):
format = self.currentItemFormat()
......
......@@ -907,7 +907,7 @@ def qdump__QMapNode(d, value):
d.putSubItem("value", value["value"])
def qdumpHelper__Qt4_QMap(d, value, forceLong):
def qdumpHelper__Qt4_QMap(d, value):
d_ptr = value["d"].dereference()
e_ptr = value["e"].dereference()
n = int(d_ptr["size"])
......@@ -922,7 +922,6 @@ def qdumpHelper__Qt4_QMap(d, value, forceLong):
keyType = d.templateArgument(value.type, 0)
valueType = d.templateArgument(value.type, 1)
isCompact = d.isMapCompact(keyType, valueType)
it = e_ptr["forward"].dereference()
......@@ -941,30 +940,17 @@ def qdumpHelper__Qt4_QMap(d, value, forceLong):
else:
payloadSize = nodeType.sizeof - 2 * nodePointerType.sizeof
if isCompact:
innerType = valueType
else:
innerType = nodeType
with Children(d, n, childType=innerType):
with PairedChildren(d, n, keyType=keyType, valueType=valueType, pairType = nodeType):
for i in xrange(n):
base = it.cast(d.charPtrType()) - payloadSize
node = base.cast(nodePointerType).dereference()
with SubItem(d, i):
d.putField("iname", d.currentIName)
if isCompact:
#d.putType(valueType)
if forceLong:
d.putName("[%s] %s" % (i, node["key"]))
else:
d.putMapName(node["key"])
d.putItem(node["value"])
else:
d.putItem(node)
#d.putField("iname", d.currentIName)
d.putPair(node, i)
it = it.dereference()["forward"].dereference()
def qdumpHelper__Qt5_QMap(d, value, forceLong):
def qdumpHelper__Qt5_QMap(d, value):
d_ptr = value["d"].dereference()
n = int(d_ptr["size"])
d.check(0 <= n and n <= 100*1000*1000)
......@@ -978,36 +964,21 @@ def qdumpHelper__Qt5_QMap(d, value, forceLong):
keyType = d.templateArgument(value.type, 0)
valueType = d.templateArgument(value.type, 1)
isCompact = d.isMapCompact(keyType, valueType)
# Note: Keeping the spacing in the type lookup
# below is important for LLDB.
needle = str(d_ptr.type).replace("QMapData", "QMapNode", 1)
nodeType = d.lookupType(needle)
if isCompact:
innerType = valueType
else:
innerType = nodeType
def helper(d, node, nodeType, isCompact, forceLong, i, n):
def helper(d, node, nodeType, i):
left = node["left"]
if not d.isNull(left):
i = helper(d, left.dereference(), nodeType, isCompact, forceLong, i, n)
i = helper(d, left.dereference(), nodeType, i)
if i >= n:
return i
nodex = node.cast(nodeType)
with SubItem(d, i):
d.putField("iname", d.currentIName)
if isCompact:
if forceLong:
d.putName("[%s] %s" % (i, nodex["key"]))
else:
d.putMapName(nodex["key"])
d.putItem(nodex["value"])
else:
qdump__QMapNode(d, nodex)
d.putPair(nodex, i)
i += 1
if i >= n:
......@@ -1015,33 +986,29 @@ def qdumpHelper__Qt5_QMap(d, value, forceLong):
right = node["right"]
if not d.isNull(right):
i = helper(d, right.dereference(), nodeType, isCompact, forceLong, i, n)
i = helper(d, right.dereference(), nodeType, i)
return i
with Children(d, n, childType=innerType):
with PairedChildren(d, n, keyType=keyType, valueType=valueType, pairType = nodeType):
node = d_ptr["header"]
helper(d, node, nodeType, isCompact, forceLong, 0, n)
helper(d, node, nodeType, 0)
def qdumpHelper__QMap(d, value, forceLong):
if d.fieldAt(value["d"].dereference().type, 0).name == "backward":
qdumpHelper__Qt4_QMap(d, value, forceLong)
else:
qdumpHelper__Qt5_QMap(d, value, forceLong)
def qform__QMap():
return mapForms()
def qdump__QMap(d, value):
qdumpHelper__QMap(d, value, False)
if d.fieldAt(value["d"].dereference().type, 0).name == "backward":
qdumpHelper__Qt4_QMap(d, value)
else:
qdumpHelper__Qt5_QMap(d, value)
def qform__QMultiMap():
return mapForms()
def qdump__QMultiMap(d, value):
qdumpHelper__QMap(d, value, True)
qdump__QMap(d, value)
def extractCString(table, offset):
......
......@@ -194,7 +194,7 @@ def qdump__std__map(d, value):
if d.isExpanded():
pairType = d.templateArgument(d.templateArgument(value.type, 3), 0)
pairPointer = pairType.pointer()
with PairedChildren(d, size, pairType, maxNumChild=1000):
with PairedChildren(d, size, pairType=pairType, maxNumChild=1000):
node = impl["_M_header"]["_M_left"]
for i in d.childRange():
with SubItem(d, i):
......@@ -644,8 +644,7 @@ def qdump__std____1__unordered_map(d, value):
d.putItemCount(size)
if d.isExpanded():
node = value["__table_"]["__p1_"]["__first_"]["__next_"]
pairType = node["__value_"].type
with PairedChildren(d, size, pairType, maxNumChild=1000):
with PairedChildren(d, size, pairType=node["__value_"].type, maxNumChild=1000):
for i in d.childRange():
with SubItem(d, i):
d.putPair(node["__value_"], i)
......
......@@ -2080,12 +2080,12 @@ void tst_Dumpers::dumper_data()
QTest::newRow("QMapUIntFloat")
<< Data("#include <QMap>\n",
"QMap<uint, float> map;\n"
"map[11] = 11.0;\n"
"map[22] = 22.0;\n")
"map[11] = 31.0;\n"
"map[22] = 32.0;\n")
% CoreProfile()
% Check("map", "<2 items>", "@QMap<unsigned int, float>")
% Check("map.0", "[11]", "11", "float")
% Check("map.1", "[22]", "22", "float");
% Check("map.0", "[0] 11", FloatValue("31.0"), "float")
% Check("map.1", "[1] 22", FloatValue("32.0"), "float");
QTest::newRow("QMapStringFloat")
<< Data("#include <QMap>\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