[snippets] improved stlp.py: typeInfo() used to create stlp tree and stlp node representation.

git-svn-id: https://pykd.svn.codeplex.com/svn@67068 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\air_max_cp 2011-06-17 17:37:11 +00:00
parent b5f25cc5c8
commit 5d1bd33f62

View File

@ -3,91 +3,67 @@
import sys
from pykd import *
StlpNodeBase = typeInfo()
StlpNodeBase.append(ptr_t, "color")
StlpNodeBase.append(ptr_t, "parent")
StlpNodeBase.append(ptr_t, "left")
StlpNodeBase.append(ptr_t, "right")
def println(msg):
if runningAsWinDbgExtension:
dprintln(msg)
else:
print msg
class StlpNodeWrapper:
def __init__(self, addr):
# Wrapper specific field
self.addr = addr
# Wrapper specific field
self.sizeOf = 4 * ptrSize()
self.color = ptrByte(addr)
# By default, fields in structure aligned by 4 Bytes on x86 and by 8 Bytes on x64
addr += ptrSize()
self.parent = ptrPtr(addr)
addr += ptrSize()
self.left = ptrPtr(addr)
addr += ptrSize()
self.right = ptrPtr(addr)
class StlpMapWrapper:
def __init__(self, addr):
# Wrapper specific field
self.addr = addr
self.rootNode = StlpNodeWrapper(addr)
self.size = ptrPtr(addr + self.rootNode.sizeOf)
StlpMap = typeInfo()
StlpMap.append(StlpNodeBase, "header")
StlpMap.append(ptr_t, "node_count")
def stlpMapIncrement(addr):
node = StlpNodeWrapper(addr)
node = StlpNodeBase.load(addr)
if (node.right != 0):
node = StlpNodeWrapper(node.right)
node = StlpNodeBase.load(node.right)
while (node.left != 0):
node = StlpNodeWrapper(node.left)
node = StlpNodeBase.load(node.left)
else:
ynode = StlpNodeWrapper(node.parent)
while (node.addr == ynode.right):
ynode = StlpNodeBase.load(node.parent)
while (node.getAddress() == ynode.right):
node = ynode
ynode = StlpNodeWrapper(ynode.parent)
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.addr):
if (node.right != ynode.getAddress()):
node = ynode
return node.addr
return node.getAddress()
def dumpStlportMap(addr):
"""Returns the list of addresses of pair<key, value>"""
addrList = list()
#println("Map address: 0x%x" % addr)
map = StlpMapWrapper(addr)
#println("Map node count: %u" % map.size)
#dprintln("Map address: 0x%x" % addr)
map = StlpMap.load(addr)
#dprintln("Map node count: %u" % map.node_count)
count = 0
begin = map.rootNode.left
begin = map.header.left
end = addr
it = begin
while (it and it != end):
addrList.append(it + map.rootNode.sizeOf)
addrList.append(it + map.header.sizeof())
it = stlpMapIncrement(it)
count += 1
if (count != map.size):
println("Error: map was dumped incorrectly.")
if (count != map.node_count):
dprintln("Error: map was dumped incorrectly.")
return addrList
def printUsage():
println("Usage:")
println("!py stlp map <map_address|variable_name> [\"accurate map pair type\"]")
println("Use dt command to retrive accurate map pair type:")
println("dt -r ModuleName!stlp_std::pair*")
println("Find required type in the list and copy paste it as script parameter. Don't forget about quotes.")
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.")
if __name__ == "__main__":
global runningAsWinDbgExtension
runningAsWinDbgExtension = isWindbgExt()
mapAddr = 0
argc = len(sys.argv)
@ -100,9 +76,9 @@ if __name__ == "__main__":
addrList = dumpStlportMap(mapAddr)
for addr in addrList:
if (argc == 3):
println("0x%x" % addr)
dprintln("0x%x" % addr)
else:
s = "dt -r " + sys.argv[3] + " 0x%x" % addr
#println(s)
println("------------------------------------------------")
println(dbgCommand(s))
dprintln("------------------------------------------------")
dprintln(dbgCommand(s))