如何允许 WinXP 和 Win7 自动创建 dump 文件

Part 1 Windows 7 默认情况下 dump 文件的自动生成是关闭的。要开启这个功能需要新建这样一个 key --

HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/Windows Error Reporting/LocalDumps,并在该 key 下按照下表进行如下配置。

 

对于表中这些项,没必要全部定义。一般情况下,定义一个 DumpFolder 并将 DumpType设置为 2 就可以了,这样就可以在指定目录下生成 full dump 文件。

这个 key 的作用域是全局的。你也可以为指定的进程配置单独的设置来覆盖全局设置。要为指定进程创建调试设置,你需要以进程名字 MyApplication.exe创建一个形如 HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/Windows Error Reporting/LocalDumps/MyApplication.exekey,并在该 key 下如法炮制上表中的选项。这样,当MyApplication.exe crash 的时候,操作系统会首先读取全局设置,然后再读取该进程自己的设置,并用这个局部设置去覆盖全局设置。

 

Part 2 Windows XP配置方法略有不同。Windows XP 自带了一个调试工具 Dr.Watson 可以用来自动生成 dump 文件。通过在<Start>菜单中<Run>输入drwtsn32 可以启动它。具体配置方法是在注册表下面的 key 下配置 <Debugger> 的值即可。当然,64-bitWindows XP 需要 branch 到Wow6432Node\ 下对应的路径。注意,参数 –p 可以用来指定特定进程ID。

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]

"Auto"="1"

"Debugger"="\"DRWTSN32\" -p %ld -e %ld"

"UserDebuggerHotKey"=dword:00000000

如下图所示,Dr.Watson 会根据相应的 options 和路径,生成相应的 dump 文件和 log 文件。在下面的 Application Errors 一栏中,可以看到进程 crash 的历史记录。log 文件也很有用,它是把一些内存信息 dump 到文本文件中了。

当然,在同样的 key 下配置 <Debugger> 的值为 WinDebug 。这样可以将其设置为 Just-In-Time Debugger,异常发生的时候 WinDebug 会自动被运行起来,crash 的进程会被中断到调试器中。别忘记将 WinDebug 的安装目录添加到 PATH 中。Note: Just in time (JIT) debugger is used at time of exception and gives you the possibility to check the state of the application at run time. Post mortem debugging is used when trying to figure out what has happened to an already crashed application, i.e. investigating the state of the application through a dump file. 这里,在cmd-line 里输入 "windbg -I"或者“windbg –IS” (静默模式) 则可以将 WinDebug 设置为 default debugger。另外,输入”windbg -IA” or “windbg -IAS”(静默模式)会让 WinDebug 自动关联 *.dmp 文件。

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]

"Debugger"="C:\\Program Files\\Debugging Tools for Windows (x86)\\windbg.exe -p %ld -e %ld"

 

最后,你也可以在同样的 key 下配置 <Debugger> 的值为 Visual Studio 的 Debugger。

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]

"Debugger"="C:\\Program Files\\Debugging Tools for Windows (x86)\\VSJITDebugger -p %ld -e %ld"

 

Reference

[1] http://trifoliummedium.blogspot.de/2011/03/installing-windbg-as-default-jit-and.html

[2] http://xmuxsp.blog.51cto.com/144876/133192

[3] http://www.networkworld.com/news/2005/041105-windows-crash.html

[4] http://msdn.microsoft.com/en-us/library/windows/desktop/ee416349%28v=vs.85%29.aspx

 

<EOF>

posted on 2012-05-03 20:05  Cary_Fan  阅读(3060)  评论(0编辑  收藏  举报

导航