2011-04-11 01:47:16 +08:00
|
|
|
"""Dump STLPort containers"""
|
2011-04-02 01:29:36 +08:00
|
|
|
|
|
|
|
import sys
|
|
|
|
from pykd import *
|
|
|
|
|
2011-10-07 14:48:17 +08:00
|
|
|
def ptr_t():
|
|
|
|
return is64bitSystem() and ulonglong_t or ulong_t
|
|
|
|
|
2011-06-18 01:37:11 +08:00
|
|
|
StlpNodeBase = typeInfo()
|
2011-10-07 14:48:17 +08:00
|
|
|
StlpNodeBase.append(ptr_t(), "color")
|
|
|
|
StlpNodeBase.append(ptr_t(), "parent")
|
|
|
|
StlpNodeBase.append(ptr_t(), "left")
|
|
|
|
StlpNodeBase.append(ptr_t(), "right")
|
2011-04-02 01:29:36 +08:00
|
|
|
|
2011-06-18 01:37:11 +08:00
|
|
|
StlpMap = typeInfo()
|
|
|
|
StlpMap.append(StlpNodeBase, "header")
|
2011-10-07 14:48:17 +08:00
|
|
|
StlpMap.append(ptr_t(), "node_count")
|
2011-04-02 01:29:36 +08:00
|
|
|
|
|
|
|
def stlpMapIncrement(addr):
|
2011-06-18 01:37:11 +08:00
|
|
|
node = StlpNodeBase.load(addr)
|
2011-04-02 01:29:36 +08:00
|
|
|
|
|
|
|
if (node.right != 0):
|
2011-06-18 01:37:11 +08:00
|
|
|
node = StlpNodeBase.load(node.right)
|
2011-04-02 01:29:36 +08:00
|
|
|
while (node.left != 0):
|
2011-06-18 01:37:11 +08:00
|
|
|
node = StlpNodeBase.load(node.left)
|
2011-04-02 01:29:36 +08:00
|
|
|
else:
|
2011-06-18 01:37:11 +08:00
|
|
|
ynode = StlpNodeBase.load(node.parent)
|
|
|
|
while (node.getAddress() == ynode.right):
|
|
|
|
node = ynode
|
|
|
|
ynode = StlpNodeBase.load(ynode.parent)
|
|
|
|
# check special case: This is necessary if _M_node is the
|
|
|
|
# _M_head and the tree contains only a single node __y. In
|
|
|
|
# that case parent, left and right all point to __y!
|
|
|
|
if (node.right != ynode.getAddress()):
|
|
|
|
node = ynode
|
2011-04-02 01:29:36 +08:00
|
|
|
|
2011-06-18 01:37:11 +08:00
|
|
|
return node.getAddress()
|
2011-04-02 01:29:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
def dumpStlportMap(addr):
|
|
|
|
"""Returns the list of addresses of pair<key, value>"""
|
|
|
|
addrList = list()
|
2011-06-18 01:37:11 +08:00
|
|
|
#dprintln("Map address: 0x%x" % addr)
|
|
|
|
map = StlpMap.load(addr)
|
|
|
|
#dprintln("Map node count: %u" % map.node_count)
|
2011-04-02 01:29:36 +08:00
|
|
|
|
|
|
|
count = 0
|
2011-06-18 01:37:11 +08:00
|
|
|
begin = map.header.left
|
2011-04-02 01:29:36 +08:00
|
|
|
end = addr
|
|
|
|
it = begin
|
|
|
|
while (it and it != end):
|
2011-06-18 01:37:11 +08:00
|
|
|
addrList.append(it + map.header.sizeof())
|
2011-04-02 01:29:36 +08:00
|
|
|
it = stlpMapIncrement(it)
|
|
|
|
count += 1
|
|
|
|
|
2011-06-18 01:37:11 +08:00
|
|
|
if (count != map.node_count):
|
|
|
|
dprintln("Error: map was dumped incorrectly.")
|
2011-04-02 01:29:36 +08:00
|
|
|
|
|
|
|
return addrList
|
|
|
|
|
|
|
|
|
|
|
|
def printUsage():
|
2011-06-18 01:37:11 +08:00
|
|
|
dprintln("Usage:")
|
|
|
|
dprintln("!py stlp map <map_address|variable_name> [\"accurate map pair type\"]")
|
|
|
|
dprintln("Use dt command to retrive accurate map pair type:")
|
|
|
|
dprintln("dt -r ModuleName!stlp_std::pair*")
|
|
|
|
dprintln("Find required type in the list and copy paste it as script parameter. Don't forget about quotes.")
|
2011-04-02 01:29:36 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
mapAddr = 0
|
|
|
|
|
|
|
|
argc = len(sys.argv)
|
2011-04-11 01:47:16 +08:00
|
|
|
if (argc < 3 or sys.argv[1] != "map"):
|
2011-04-02 01:29:36 +08:00
|
|
|
printUsage()
|
|
|
|
quit(0)
|
|
|
|
else:
|
2011-04-11 01:47:16 +08:00
|
|
|
mapAddr = int(expr(sys.argv[2]))
|
2011-04-02 01:29:36 +08:00
|
|
|
|
|
|
|
addrList = dumpStlportMap(mapAddr)
|
|
|
|
for addr in addrList:
|
2011-04-11 01:47:16 +08:00
|
|
|
if (argc == 3):
|
2011-06-18 01:37:11 +08:00
|
|
|
dprintln("0x%x" % addr)
|
2011-04-02 01:29:36 +08:00
|
|
|
else:
|
2011-04-11 01:47:16 +08:00
|
|
|
s = "dt -r " + sys.argv[3] + " 0x%x" % addr
|
2011-04-02 01:29:36 +08:00
|
|
|
#println(s)
|
2011-06-18 01:37:11 +08:00
|
|
|
dprintln("------------------------------------------------")
|
|
|
|
dprintln(dbgCommand(s))
|