SOS 2.0中!StopOnException和ADPlus的结合使用
.Net Framework 2.0带的Managed Debugging Extension SOS.DLL中新增了一个StopOnException的命令。使用它,我们可以比较方便得在指定类型的Exception发生时抓到进程的内存镜像。这样就避免了使用"ADPlus -Crash -FullOnFirst"而导致生成大量无用的First Chance Exception的情况,步骤如下:
1. 创建一个ADPlus的配置文件StopOnException.cfg:
<ADPlus>
<!-- Set ADPlus run options -->
<Settings>
<RunMode> CRASH </RunMode>
<OutputDir> C:\Dumps </OutputDir>
</Settings>
<!-- Load sos.dll -->
<PreCommands>
<Cmd> .loadby sos.dll mscorwks </Cmd>
</PreCommands>
<!-- Create and configure our .NET exception breakpoint -->
<Exceptions>
<Config>
<!-- Break on CLR exception type -->
<Code> CLR </Code>
<Actions1> Log;Stack </Actions1>
<!-- Action to run if our manged exception is on the stack -->
<CustomActions1> !StopOnException System.ArgumentException 1; .if (@$t1 == 1) {.dump /ma /u C:\Dumps\ArgException.dmp} </CustomActions1>
<ReturnAction1> gn </ReturnAction1>
<Actions2> Log;Stack;FullDump </Actions2>
</Config>
</Exceptions>
</ADPlus>
上面的配置将在System.ArgumentException被扔出的时候抓内存镜像,生成在C:\Dumps。
2. 以下面的命令运行ADPlus,将Debugger attach到WindowsApplication1.exe上:
cscript adplus.vbs -c c:\StopOnException.cfg -quiet -pn WindowsApplication1.exe
!StopOnException还有一个-derived参数略有用,详细可参考帮助!help StopOnException
posted on 2006-08-11 17:45:00 by TingWang 评论(2) 阅读(5426)
