是否有任何等效命令!findstack来过滤托管代码?

时间:2016-08-11 03:10:16

标签: windbg

我发现!findstack只能用于过滤非托管代码,但是无法过滤托管代码,那么是否有!findstack过滤托管代码的等效命令?

1 个答案:

答案 0 :(得分:2)

我不知道这样的即用型功能,所以我在这里看到两个选项:

  • 使用一些WinDbg内部命令(半年后你几乎无法理解),
  • 使用PyKd并在Python中编写一个漂亮的脚本

接近a)

这可能与此类似:

~*e .foreach(word {!clrstack}) {.if ($spat("${word}", "?*RunMessageLoop?*") == 1) {.printf "Found!\n"}}

方法b)

将以下内容放入名为clrfindstack.py

的文件中
from pykd import *
import sys

if len(sys.argv) == 1: # script name only
    print "Please provide a search string as argument"
    exit()
threads = getNumberThreads()
for thread in range(0, threads):
    dbgCommand("~"+str(thread)+"s")  # select the thread
    stack = dbgCommand("!clrstack")  # run !clrstack
    if sys.argv[1] in stack: # [0] is the script name
        print "Found", sys.argv[1], "in thread", thread, "(Use ~"+str(thread)+"s to select it)"

然后运行它

0:000> !py c:\tmp\clrfindstack.py
Please provide a search string as argument
0:000> !py c:\tmp\clrfindstack.py RunMessageLoop
Found RunMessageLoop in thread 0 (Use ~0s to select it)

实施可能不是非常pythonic,但它的工作。

相关问题