xiong's profile共享空间标题PhotosBlogLists Tools Help
    November 28

    Windows错误报告

    Windows错误报告
     
    这个话题要从很久开始说,革命故事跟Windows的历史一样长
     
    Windows错误报告的前身,就是大名鼎鼎的Dr. Watson.
    Dr. Watson也有两个辈分,Win31时代的16位版本和后来大家最熟悉的32位版本.
     
    当然,如果还要再说前传的话,可以参考:
    Why is Windows Error Reporting nicknamed "Dr. Watson"?
    http://blogs.msdn.com/oldnewthing/archive/2005/08/10/449866.aspx
     
    Dr. Watson.工具的主要用途是在程序崩溃的时候抓取dump文件和其他log,并且保存在本地. 通过注册表的配置,可以指定dump文件的类型和路径.
     
    那个年代是没有CLR的,所以情况相对简单. 稍微要深入一点说的话, Dr. Watson.的启动其实是依靠AEDebug注册表控制的. 另外 Dr. Watson也不是所有的crash都能抓,具体可以参考:
     
    why drwtson32 fails to generate the dump for 2nd C++ exception
    http://blog.csdn.net/eparg/archive/2007/09/19/1791986.aspx

    到了XP时代 (准确说是Win2000 SP3), Dr. Watson的接班人, Windows错误报告现身了. 我没有记错的话, Dr. Watson这个程序直到XP上面还是健在的,并没有完全退出历史舞台. Windows错误报告当初是长这个样子的:
     
     
    如果细心的话,会发现其实有两种不同的UI:
     分别对应dw32.exe和dwwin.exe

    跟Dr. Watson相比,这个错误报告主要的优势在于能够把错误信息发送给微软官方. 这是微软改改进自己产品的一个很好渠道. 另外这个程序支持queue模式, 并且区分服务器和客户端. 比如在客户端就程序崩溃就可以看到UI,在服务器上,就要等到管理员登陆的时候才能累计起来的错误报告.
     
    这个程序的缺点在于不能像Dr. Watson那样简单直接地抓dump文件. 在MSDN中虽然提到可以通过API/Plug-in灵活配置这个程序,但我怀疑是否有用户真正看完过这个文档:
     
    How to: Configure Microsoft Error Reporting
    http://msdn.microsoft.com/en-us/library/bb219076.aspx
     
    所以说,一直到XP/2003,要自己抓dump分析还得靠Dr. Watson这个老革命.
     
    另外,悄然兴起的CLR让本身就复杂的情况更加复杂. 错误报告和Dr. Watson不支持CLR程序的:
     
    Managed Code
    Microsoft Error Reporting cannot support managed applications natively, but is designed for integration with the Common Language Runtime (CLR).
    crosoft .NET Framework 2.0 installs Microsoft Error Reporting and supports automatic reporting of unhandled managed exceptions (similar to Windows Error Reporting for unmanaged applications). Custom error reporting of handled exceptions is also supported.
    For more information about automatic reporting, see Enabling JIT-Attach Debugging.
    For more details about exception-mode reporting, see ICLRErrorReportingManager::GetBucketParametersForCurrentException Method.

    先不要说开,把Error reporting说完. 到了Windows 2008,革命形势继续发生着翻天覆地的变化. 下面这个图,就是在一个C程序和一个CLR程序同时崩溃时候抓的. 能看出差别来么?
     
    这两个UI是没有差别的,差别在于他们其实是两个不同的Error reporting, 一个叫做dw20.exe,外一个叫做WerFault.exe.玄的是, 从Windows 2008还有Vista SP1开始, Windows error reporting开始支持自动抓dump了, 同时Dr. Watson正式退出历史舞台.怎么配置怎么抓dump请看:
     
     
    更玄的是,这个dw20.exe还有双重身份。上图中的dw20.exe位置在CLR Framework下面,是CLR的error reporting shim,根OS的没什么关系。在
    C:\Windows\Microsoft.NET\Framework\v2.0.50727
     
    但是在前面的链接中可以看到,另外还有一个dw20.exe在:
    C:\Program Files\Common Files\microsoft shared\DW
     
    其实无论是dw20.exe还是werfault.exe都是ErrorReportingShim,真正抓信息的是wer.dll。CLR的shim负责控制jitdebugger: 
     
     
     
    这个历史进化图是:
    Dr. Watson16->Dr. Watson32->dwwin/dw20 ->WerFault
    中间来了个CLR,给自己弄了一个error reporting shim也叫做dw20.exe,还弄了一个JitDebugger
     
    关键的技巧:
    1. 检查WinForm的SetErrorMode
    2. 检查JitDebugger
    3. 配置WER,在Windows Help中找Windows Error Reporting
    4. 如果需要WER抓dump,选择allow send additional data. 对应的注册表是DontSendAdditionalData=0
    5. WER的配置受到GPO控制。所以修改注册表无效的话也不要奇怪
    6. LH/Vista SP1可以自动抓dump保存到指定位置。这个功能是独立的,由Error reporting实现。
    7. Dr. Watson32已经成为历史了。但是AEDebug还可以继续用。

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://eparg.spaces.live.com/blog/cns!59BFC22C0E7E1A76!3856.trak
    Weblogs that reference this entry
    • None