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

本文转自:http://www.cnblogs.com/rmcary/archive/2012/05/03/2481242.html

 

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>

 

补充:

根据作者的方法,我写了两个批处理,用于win7打开Dump与关闭Dump,此处将生成目录设置成C:\CrashDump。(注:运行时应右键以管理员方式运行,否则可能无效)

这里提供打包下载:http://download.csdn.net/detail/lx198986611235/6949979

OpenDump.bat

@echo off
echo 正在启用Dump...
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps"
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" /v DumpFolder /t REG_EXPAND_SZ /d "C:\CrashDump" /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" /v DumpType /t REG_DWORD /d 2 /f

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" /v DumpCount /t REG_DWORD /d 10 /f
echo Dump已经启用
pause
@echo on

//

CloseDump.bat

@echo off
echo 正在关闭Dump...
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" /f
echo Dump已经关闭
pause
@echo on

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值