pykd/samples/stacks.py
SND\kernelnet_cp de82f9d737 [samples] updated: refactored samples
git-svn-id: https://pykd.svn.codeplex.com/svn@63978 9b283d60-5439-405e-af05-b73fd8c4d996
2011-04-14 16:01:29 +00:00

70 lines
1.5 KiB
Python

import sys
from pykd import *
def printStack():
def printThreadStack( threadPtr ):
setImplicitThread( threadPtr )
stackFrames = getCurrentStack()
for frame in stackFrames: dprintln( findSymbol( frame.instructionOffset ) + " (%x)" % frame.instructionOffset )
dprintln("")
def printUserStack():
threadList = getThreadList()
oldMode = getProcessorMode()
if oldMode == "X64" and loadModule( "wow64" ) != None:
setProcessorMode("X86")
for threadPtr in threadList:
printThreadStack( threadPtr )
setProcessorMode(oldMode)
def printKernelStack():
process = typedVar( "nt", "_EPROCESS", getCurrentProcess() )
threadList = typedVarList( process.ThreadListHead.getAddress(), "nt", "_ETHREAD", "ThreadListEntry" )
oldMode = getProcessorMode()
if is64bitSystem() and process.Wow64Process != 0:
setProcessorMode("X86")
for thread in threadList:
printThreadStack( thread.getAddress() )
setProcessorMode(oldMode)
if isKernelDebugging():
printKernelStack()
else:
printUserStack()
if __name__ == "__main__":
while True:
if not isWindbgExt():
if not loadDump( sys.argv[1] ):
dprintln( sys.argv[1] + " - load failed" )
break
printStack()
break