请问WarcraftIII可以在它的程序crash时记录下时间、系统、程序堆栈状况等等环境信息是如何实现的?如果能在程序crash时知道比MFC断言之类错误提示更多信息的话(如:是在那个类的的哪个方法里出错的等等)对于维护和debug程序会有很大帮助。谢先。

解决方案 »

  1.   

    WarcraftIII的Crash log内容:
    ==============================================================================
    Warcraft III (build 4448)Exe:      m:\warcraft iii chinese\war3.exe
    Time:     Aug 17, 2002  7:17:36.797 PM
    User:     kim-ryo
    Computer: ADA
    ------------------------------------------------------------------------------This application has encountered a critical error:FATAL ERROR!Program: m:\warcraft iii chinese\war3.exe
    Exception: 0xC0000005 (ACCESS_VIOLATION) at 001B:6F0738C4The instruction at '0x6F0738C4' referenced memory at '0x0000007C'.
    The memory could not be 'read'.
    Played Maps\(4)Legends.w3m
    Player  0 Race Undead StartLoc  1
    Player  1 Race Undead StartLoc  2
    Player  2 Race Undead StartLoc  2
    Player  3 Race NightElf StartLoc  3
    Player  4 Race Human StartLoc -1
    Player  5 Race Undead StartLoc -1
    Player  6 Race Human StartLoc -1
    Player  7 Race Orc StartLoc -1
    Player  8 Race Undead StartLoc -1
    Player  9 Race Human StartLoc -1
    Player 10 Race Orc StartLoc -1
    Player 11 Race Orc StartLoc -1
    ----------------------------------------------------------------------------------------------------------------------
        Stack Trace (Using DBGHELP.DLL)
    ----------------------------------------6F0738C4 Game.dll     <unknown symbol>+0 (0x2B773375,0x204B03C0,0x204B03CC,0x4B58593B)
    6F0739B0 Game.dll     <unknown symbol>+0 (0x2B773375,0x204B0398,0x204B03A4,0x4B58593B)
    6F0739B0 Game.dll     <unknown symbol>+0 (0x2B773375,0x204B0370,0x204B037C,0x4B58593B)
    6F0739B0 Game.dll     <unknown symbol>+0 (0x2B773375,0x0012FA8C,0x04ED0D78,0x0012FA88)
    6F0739B0 Game.dll     <unknown symbol>+0 (0x2B773375,0x6F21D9C2,0x0012FA8C,0x0012FAC4)
    6F0739EB Game.dll     <unknown symbol>+0 (0x04ED0D78,0x0012FAC4,0x0012FAF8,0x6F5ADF99)
    6F441F70 Game.dll     <unknown symbol>+0 (0x00000000,0x17EF87F0,0x18165210,0x00000000)

    ----------------------------------------
        Stack Trace (Manual)
    ----------------------------------------Address  Frame    Logical addr  Module6F0738C4 0012F9A4 0001:000728C4 m:\warcraft iii chinese\Game.dll
    6F0739B0 0012F9D0 0001:000729B0 m:\warcraft iii chinese\Game.dll

    ----------------------------------------
        x86 Registers
    ----------------------------------------EAX=7FED7FED  EBX=0B0400A8  ECX=049B3180  EDX=F4FBE837  ESI=00000000
    EDI=2B773375  EBP=0012F9A4  ESP=0012F984  EIP=6F0738C4  FLG=00210282
    CS =001B      DS =0023      ES =0023      SS =0023      FS =0038      GS =0000
    ----------------------------------------
        Memory Dump
    ----------------------------------------Code: 16 bytes starting at (EIP = 6F0738C4)6F0738C4: 39 7E 7C 0F  84 F2 00 00  00 8D 4D FC  89 7D FC E8  9~|.......M..}..
    Stack: 1024 bytes starting at (ESP = 0012F984)* = addr               **                                         *           
    0012F980: 03 00 00 00  E8 03 4B 20  F4 03 4B 20  3B 59 58 4B  ......K ..K ;YXK
    0012F990: B0 00 03 0B  24 44 D0 04  00 00 00 00  00 00 00 00  ....$D..........
    0012F9A0: 64 39 07 6F  D0 F9 12 00  B0 39 07 6F  75 33 77 2B  d9.o.....9.ou3w+
    0012F9B0: C0 03 4B 20  CC 03 4B 20  3B 59 58 4B  B0 00 03 0B  ..K ..K ;YXK....
    0012F9C0: 28 44 D0 04  64 63 73 77  08 44 D0 04  75 33 77 2B  (D..dcsw.D..u3w+
    0012F9D0: FC F9 12 00  B0 39 07 6F  75 33 77 2B  98 03 4B 20  .....9.ou3w+..K 
    0012F9E0: A4 03 4B 20  3B 59 58 4B  B0 00 03 0B  58 77 D0 04  ..K ;YXK....Xw..
    0012F9F0: 62 64 65 70  38 77 D0 04  75 33 77 2B  28 FA 12 00  bdep8w..u3w+(...
    0012FA00: B0 39 07 6F  75 33 77 2B  70 03 4B 20  7C 03 4B 20  .9.ou3w+p.K |.K 
    0012FA10: 3B 59 58 4B  B0 00 03 0B  48 7B D0 04  64 65 75 70  ;YXK....H{..deup
    0012FA20: 28 7B D0 04  75 33 77 2B  54 FA 12 00  B0 39 07 6F  ({..u3w+T....
      

  2.   

    在SEH的过滤器中调用函数GetExceptionInformation可以获得有关异常的信息,包括当前线程throw exception时的Context结构和一个EXCEPTION_RECORD结构。其中Context结构是和CPU类型有关的,存放了出错瞬间的register data,根据register data分析应该可以获得大部分的运行信息吧。
      

  3.   

    同意楼上解释,按装SEH过滤器,在程序崩溃时调用GetExceptionInformation()可以得到相关信息,不过具体没有做过,无法提供代码。
      

  4.   

    BCB_FANS:"在程序崩溃时调用GetExceptionInformation()"
    程序都crash了,怎么还能调用其他函数???
      

  5.   

    不好意思,SEH过滤器严格来说是针对异常情况的,但程序出现异常时未必就Crash,所以我也不知道这个程序到底是如何实现的:(
      

  6.   

    我不是说异常啊,异常可以用C...Exception的.Warcraft是在程序crash(出现access voilation对话框时,记录的信息。
      

  7.   

    如果让我来实现的话,第一要知道有些错误是可以CATCH到的,包括常见的访问冲突等,用c++的try{}catch(...)可以捕捉到大部分。windows本身的结构化异常可以更加深入的捕捉到地层的一些异常错误(我没有用过,具体不是很了解.^_^。)
    理解的关键我认为是出现异常,并不代表程序已经不再能够执行代码了只是说不再能够正常的修复并继续正常运行,既然不能正常运行那就推出吧。
    另一直想法是,主进程启动的时候同时开一个独立的进程对主进程进行监控,其工作方式就向Dr.Watson(drwtsn32.exe)--没有装其他JID的情况下win2k就是通过它来捕捉应用程序的异常情况并记录下来。
      

  8.   

    refer to Debug Help Library
    http://msdn.microsoft.com/msdnmag/issues/02/06/Bugslayer/Bugslayer0206.asp
      

  9.   

    第一次看到五星人,
    都很NB。U:P