[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 import sys
from pykd import * 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): StlpMap = typeInfo()
if runningAsWinDbgExtension: StlpMap.append(StlpNodeBase, "header")
dprintln(msg) StlpMap.append(ptr_t, "node_count")
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)
def stlpMapIncrement(addr): def stlpMapIncrement(addr):
node = StlpNodeWrapper(addr) node = StlpNodeBase.load(addr)
if (node.right != 0): if (node.right != 0):
node = StlpNodeWrapper(node.right) node = StlpNodeBase.load(node.right)
while (node.left != 0): while (node.left != 0):
node = StlpNodeWrapper(node.left) node = StlpNodeBase.load(node.left)
else: else:
ynode = StlpNodeWrapper(node.parent) ynode = StlpNodeBase.load(node.parent)
while (node.addr == ynode.right): while (node.getAddress() == ynode.right):
node = ynode node = ynode
ynode = StlpNodeWrapper(ynode.parent) ynode = StlpNodeBase.load(ynode.parent)
# check special case: This is necessary if _M_node is the # check special case: This is necessary if _M_node is the
# _M_head and the tree contains only a single node __y. In # _M_head and the tree contains only a single node __y. In
# that case parent, left and right all point to __y! # that case parent, left and right all point to __y!
if (node.right != ynode.addr): if (node.right != ynode.getAddress()):
node = ynode node = ynode
return node.addr return node.getAddress()
def dumpStlportMap(addr): def dumpStlportMap(addr):
"""Returns the list of addresses of pair<key, value>""" """Returns the list of addresses of pair<key, value>"""
addrList = list() addrList = list()
#println("Map address: 0x%x" % addr) #dprintln("Map address: 0x%x" % addr)
map = StlpMapWrapper(addr) map = StlpMap.load(addr)
#println("Map node count: %u" % map.size) #dprintln("Map node count: %u" % map.node_count)
count = 0 count = 0
begin = map.rootNode.left begin = map.header.left
end = addr end = addr
it = begin it = begin
while (it and it != end): while (it and it != end):
addrList.append(it + map.rootNode.sizeOf) addrList.append(it + map.header.sizeof())
it = stlpMapIncrement(it) it = stlpMapIncrement(it)
count += 1 count += 1
if (count != map.size): if (count != map.node_count):
println("Error: map was dumped incorrectly.") dprintln("Error: map was dumped incorrectly.")
return addrList return addrList
def printUsage(): def printUsage():
println("Usage:") dprintln("Usage:")
println("!py stlp map <map_address|variable_name> [\"accurate map pair type\"]") dprintln("!py stlp map <map_address|variable_name> [\"accurate map pair type\"]")
println("Use dt command to retrive accurate map pair type:") dprintln("Use dt command to retrive accurate map pair type:")
println("dt -r ModuleName!stlp_std::pair*") dprintln("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("Find required type in the list and copy paste it as script parameter. Don't forget about quotes.")
if __name__ == "__main__": if __name__ == "__main__":
global runningAsWinDbgExtension
runningAsWinDbgExtension = isWindbgExt()
mapAddr = 0 mapAddr = 0
argc = len(sys.argv) argc = len(sys.argv)
@ -100,9 +76,9 @@ if __name__ == "__main__":
addrList = dumpStlportMap(mapAddr) addrList = dumpStlportMap(mapAddr)
for addr in addrList: for addr in addrList:
if (argc == 3): if (argc == 3):
println("0x%x" % addr) dprintln("0x%x" % addr)
else: else:
s = "dt -r " + sys.argv[3] + " 0x%x" % addr s = "dt -r " + sys.argv[3] + " 0x%x" % addr
#println(s) #println(s)
println("------------------------------------------------") dprintln("------------------------------------------------")
println(dbgCommand(s)) dprintln(dbgCommand(s))