WinDbg:对 .if 中的条件使用命令 [英] WinDbg: using commands for the condition in .if
问题描述
WinDbg 具有用于条件执行命令的 .if 语句:
WinDbg has the .if statement for conditional execution of commands:
.if (Condition) { Commands } .else { Commands }
对于条件,不能使用 WinDbg 命令.是否有任何间接方式使用条件命令,例如通过伪寄存器?
For Condition, it's not possible to use WinDbg commands. Is there any indirect way of using commands for the condition, e.g. through pseudo registers?
要完成的示例任务:如果已打开日志文件,则不执行任何操作.如果没有打开日志文件,请使用 .logopen/t/u/d
Example task to accomplish: If a logfile is already opened, do nothing. If no logfile is open, use .logopen /t /u /d
使用 .logfile,我可以找出日志是否打开.但是如何解析该输出以及如何将结果分配给伪寄存器?
With .logfile, I can find out whether a log is open or not. But how to parse that output and how to assign the result to a pseudo register?
也欢迎任何其他没有伪寄存器的方式.
Any other way without pseudo registers is also welcome.
由于该示例似乎不是很有用,请考虑以下可以通过脚本或 .cmdtree 窗口自动执行的任务:
As the example may not seem very useful, consider the following tasks which can be automated by scripting or the .cmdtree window:
- 加载正确版本的 SOS,例如
.if (lm m clr == clr) { .loadby sos clr } .elseif (lm m mscorwks == mscorwks) {.loadby sos mscorwks}
- 我总是忘记做的事情,例如
.if (| == myprocess) {.childdbg 1;.sympath+ mydir}
推荐答案
我对此进行了测试,如果在模块列表中找到 clr
,它会加载正确的 sos.dll:.foreach (module {lm1m} ) { .if ($sicmp("${module}","clr") == 0) {.echo FOUND ${module};.loadby sos.dll clr} }
I tested this and it loads the correct sos.dll if it finds clr
in the list of modules:
.foreach (module {lm1m} ) { .if ($sicmp("${module}","clr") == 0) {.echo FOUND ${module}; .loadby sos.dll clr} }
您可以使用 .elsif
轻松扩展它,并将模块与mscorwks"进行比较.
You can easily extend it using .elsif
and comparing module with "mscorwks".
至于检查您的进程,我附加到 calc.exe 并运行 |
,它给了我:.0 id: 6bc 附加名称: C:\Windows\system32\calc.exe
As for checking for your process, I attached to calc.exe and ran |
which gives me: . 0 id: 6bc attach name: C:\Windows\system32\calc.exe
我只想要最后一个标记,所以我可以通过将/pS 6 指定为 .foreach
来跳过前六个.以下对 *calc.exe 使用通配符比较,如果找到,则告诉调试器调试子进程:
I only want the last token so I can skip the first six by specifying /pS 6 to .foreach
. The following uses a wildcard comparison for *calc.exe and if found, tells the debugger to debug child processes:
.foreach/pS 6 (token {|}) {.echo ${token};.if($spat("${token}","*calc.exe") == 1) {.echo 找到我的应用程序;.childdbg 1} .else {.echo 找不到我的应用程序} }
也经过测试和工作.
ps.我的调试器版本是 6.2.8400.0
ps. my debugger version is 6.2.8400.0
这篇关于WinDbg:对 .if 中的条件使用命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!