程序崩溃信息

zyc_0204 2014-08-05 05:22:14
如果 windows 上程序崩溃。
会有对话框弹出,有以下信息,并记录到系统事件,可通过事件查看器找到。

错误应用程序名称: test.exe,版本: 0.0.0.0,时间戳: 0x53e09403
错误模块名称: test.exe,版本: 0.0.0.0,时间戳: 0x53e09403
异常代码: 0xc0000005
错误偏移量: 0x00000000000036e7
错误进程 ID: 0xda0
错误应用程序启动时间: 0x01cfb088983f4e3b
错误应用程序路径: ~
错误模块路径:~

其中的错误偏移量很有用,可以通过生成的map文件大致定位到崩溃发生在哪一个函数。

如果 使用 SetUnhandledExceptionFilter 捕获崩溃异常时的,是否可以获取这个 错误偏移量 。还是说这个错误偏移量 是操作系统 在检测程序崩溃时生成的,程序没法获取这个值,求解答。
...全文
203 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-08-06
  • 打赏
  • 举报
回复
WinXP: drwtsn32 -i drwtsn32 Win7及以上: http://www.nirsoft.net/utils/app_crash_view.html
赵4老师 2014-08-06
  • 打赏
  • 举报
回复
引用 5 楼 zyc_0204 的回复:
64位程序没有是Eip,只有Rip。还有Rip每次运行都会变化,肯定不是 那个偏移位置的值。 或者通过变换,能计算出来?@zhao4zhong1
我只能劝你放弃研究exception,转而 研究WinDbg是怎么加载dump文件后用k命令查看call stack 和 有时不将“调用函数名字+各参数值,进入函数后各参数值,中间变量值,退出函数前准备返回的值,返回函数到调用处后函数名字+各参数值+返回值”这些信息写日志到文件中是无论如何也发现不了问题在哪里的,包括捕获各种异常、写日志到屏幕、单步或设断点或生成core文件、……这些方法都不行! 写日志到文件参考下面:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
    #include <windows.h>
    #include <io.h>
#else
    #include <unistd.h>
    #include <sys/time.h>
    #include <pthread.h>
    #define  CRITICAL_SECTION   pthread_mutex_t
    #define  _vsnprintf         vsnprintf
#endif
//Log{
#define MAXLOGSIZE 20000000
#define MAXLINSIZE 16000
#include <time.h>
#include <sys/timeb.h>
#include <stdarg.h>
char logfilename1[]="MyLog1.log";
char logfilename2[]="MyLog2.log";
static char logstr[MAXLINSIZE+1];
char datestr[16];
char timestr[16];
char mss[4];
CRITICAL_SECTION cs_log;
FILE *flog;
#ifdef WIN32
void Lock(CRITICAL_SECTION *l) {
    EnterCriticalSection(l);
}
void Unlock(CRITICAL_SECTION *l) {
    LeaveCriticalSection(l);
}
#else
void Lock(CRITICAL_SECTION *l) {
    pthread_mutex_lock(l);
}
void Unlock(CRITICAL_SECTION *l) {
    pthread_mutex_unlock(l);
}
#endif
void LogV(const char *pszFmt,va_list argp) {
    struct tm *now;
    struct timeb tb;

    if (NULL==pszFmt||0==pszFmt[0]) return;
    _vsnprintf(logstr,MAXLINSIZE,pszFmt,argp);
    ftime(&tb);
    now=localtime(&tb.time);
    sprintf(datestr,"%04d-%02d-%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday);
    sprintf(timestr,"%02d:%02d:%02d",now->tm_hour     ,now->tm_min  ,now->tm_sec );
    sprintf(mss,"%03d",tb.millitm);
    printf("%s %s.%s %s",datestr,timestr,mss,logstr);
    flog=fopen(logfilename1,"a");
    if (NULL!=flog) {
        fprintf(flog,"%s %s.%s %s",datestr,timestr,mss,logstr);
        if (ftell(flog)>MAXLOGSIZE) {
            fclose(flog);
            if (rename(logfilename1,logfilename2)) {
                remove(logfilename2);
                rename(logfilename1,logfilename2);
            }
        } else {
            fclose(flog);
        }
    }
}
void Log(const char *pszFmt,...) {
    va_list argp;

    Lock(&cs_log);
    va_start(argp,pszFmt);
    LogV(pszFmt,argp);
    va_end(argp);
    Unlock(&cs_log);
}
//Log}
int main(int argc,char * argv[]) {
    int i;
#ifdef WIN32
    InitializeCriticalSection(&cs_log);
#else
    pthread_mutex_init(&cs_log,NULL);
#endif
    for (i=0;i<10000;i++) {
        Log("This is a Log %04d from FILE:%s LINE:%d\n",i, __FILE__, __LINE__);
    }
#ifdef WIN32
    DeleteCriticalSection(&cs_log);
#else
    pthread_mutex_destroy(&cs_log);
#endif
    return 0;
}
//1-78行添加到你带main的.c或.cpp的那个文件的最前面
//81-85行添加到你的main函数开头
//89-93行添加到你的main函数结束前
//在要写LOG的地方仿照第87行的写法写LOG到文件MyLog1.log中
zyc_0204 2014-08-05
  • 打赏
  • 举报
回复
64位程序没有是Eip,只有Rip。还有Rip每次运行都会变化,肯定不是 那个偏移位置的值。 或者通过变换,能计算出来?@zhao4zhong1
shiguojie19892 2014-08-05
  • 打赏
  • 举报
回复
setunhandledexceptionfilter 该setunhandledexceptionfilter功能可以让应用程序取代Win32的地方在每个进程和线程上顶级异常处理程序。 调用这个函数后,如果发生异常的过程,是不是正在调试,和异常使得Win32异常过滤器,过滤器,会叫的lptoplevelexceptionfilter参数指定的异常过滤器功能。 lptop_level_exception_filter setunhandledexceptionfilter( lptop_level_exception_filter lptoplevelexceptionfilter / /异常过滤器功能 ); 参数 lptoplevelexceptionfilter 一个顶级异常过滤器函数将被调用时,unhandledexceptionfilter功能得到控制指针,而不是被调试的进程。一个空值对于此参数指定默认处理在unhandledexceptionfilter。 过滤功能语法一致,unhandledexceptionfilter:以lpexception_pointers型单参数,并返回一个值类型的长。过滤函数应该返回下列值之一:价值意义 exception_execute_handler返回unhandledexceptionfilter和执行相关的异常处理程序。这通常会导致进程终止。 从unhandledexceptionfilter exception_continue_execution回来继续从异常点执行。注意过滤功能是自由的通过修改通过其lpexception_pointers参数提供异常信息修改连续状态。 exception_continue_search着手unhandledexceptionfilter正常执行。这意味着遵守seterrormode旗帜,或调用应用程序错误消息框弹出。 unhandledexceptionfilter 该unhandledexceptionfilter函数通过调试器未处理的异常,如果正在调试的进程。否则,它可以显示应用程序错误消息框并导致异常处理程序执行。这个功能可以被称为只有从一试的筛选器表达式在除了异常处理程序。 长unhandledexceptionfilter( 结构_exception_pointers * exceptioninfo /地址 / /异常信息 ); 参数 exceptioninfo 一个exception_pointers结构包含一个描述例外和异常发生时的处理器上下文的指针。这指针的呼吁getexceptioninformation函数的返回值。 返回值 getexceptioninformation 该getexceptioninformation函数检索异常独立于机器的描述,和信息的机器状态,存在异常发生时线程。这个功能可以被称为只有从一试的筛选器表达式在除了异常处理程序。 注意,微软的C / C + +编译器将此函数作为优化关键词,和它的使用在适当的异常处理语法生成编译错误。 lpexception_pointers getexceptioninformation(无效) 参数 这个函数没有参数。 返回值 返回值是一个指针指向一个exception_pointers结构包含两个其他结构指针:包含一个描述的一个例外exception_record结构,和含有机状态信息的上下文结构。 语境 一个上下文结构包含特定于处理器的寄存器中的数据。Windows NT使用的上下文结构进行各种内部操作。目前,有上下文的结构为英特尔,MIPS,α,和PowerPC处理器的定义。指的是头文件WinNT。H对这些结构的定义。 quickinfo
shiguojie19892 2014-08-05
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
SetUnhandledExceptionFilter The SetUnhandledExceptionFilter function lets an application supersede the top-level exception handler that Win32 places at the top of each thread and process. After calling this function, if an exception occurs in a process that is not being debugged, and the exception makes it to the Win32 unhandled exception filter, that filter will call the exception filter function specified by the lpTopLevelExceptionFilter parameter. LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter // exception filter function ); Parameters lpTopLevelExceptionFilter Pointer to a top-level exception filter function that will be called whenever the UnhandledExceptionFilter function gets control, and the process is not being debugged. A value of NULL for this parameter specifies default handling within UnhandledExceptionFilter. The filter function has syntax congruent to that of UnhandledExceptionFilter: It takes a single parameter of type LPEXCEPTION_POINTERS, and returns a value of type LONG. The filter function should return one of the following values: Value Meaning EXCEPTION_EXECUTE_HANDLER Return from UnhandledExceptionFilter and execute the associated exception handler. This usually results in process termination. EXCEPTION_CONTINUE_EXECUTION Return from UnhandledExceptionFilter and continue execution from the point of the exception. Note that the filter function is free to modify the continuation state by modifying the exception information supplied through its LPEXCEPTION_POINTERS parameter. EXCEPTION_CONTINUE_SEARCH Proceed with normal execution of UnhandledExceptionFilter. That means obeying the SetErrorMode flags, or invoking the Application Error pop-up message box. UnhandledExceptionFilter The UnhandledExceptionFilter function passes unhandled exceptions to the debugger, if the process is being debugged. Otherwise, it optionally displays an Application Error message box and causes the exception handler to be executed. This function can be called only from within the filter expression of a try-except exception handler. LONG UnhandledExceptionFilter( STRUCT _EXCEPTION_POINTERS *ExceptionInfo // address of // exception info ); Parameters ExceptionInfo Pointer to an EXCEPTION_POINTERS structure containing a description of the exception and the processor context at the time of the exception. This pointer is the return value of a call to the GetExceptionInformation function. Return Values GetExceptionInformation The GetExceptionInformation function retrieves a machine-independent description of an exception, and information about the machine state that existed for the thread when the exception occurred. This function can be called only from within the filter expression of a try-except exception handler. Note The Microsoft C/C++ Optimizing Compiler interprets this function as a keyword, and its use outside the appropriate exception-handling syntax generates a compiler error. LPEXCEPTION_POINTERS GetExceptionInformation(VOID) Parameters This function has no parameters. Return Values The return value is a pointer to an EXCEPTION_POINTERS structure that contains pointers to two other structures: an EXCEPTION_RECORD structure containing a description of the exception, and a CONTEXT structure containing the machine-state information. CONTEXT A CONTEXT structure contains processor-specific register data. Windows NT uses CONTEXT structures to perform various internal operations. Currently, there are CONTEXT structures defined for Intel, MIPS, Alpha, and PowerPC, processors. Refer to the header file WinNT.h for definitions of these structures. QuickInfo
这个还要google翻译啊
赵4老师 2014-08-05
  • 打赏
  • 举报
回复
typedef struct _CONTEXT { // // The flags values within this flag control the contents of // a CONTEXT record. // // If the context record is used as an input parameter, then // for each portion of the context record controlled by a flag // whose value is set, it is assumed that that portion of the // context record contains valid context. If the context record // is being used to modify a threads context, then only that // portion of the threads context will be modified. // // If the context record is used as an IN OUT parameter to capture // the context of a thread, then only those portions of the thread's // context corresponding to set flags will be returned. // // The context record is never used as an OUT only parameter. // DWORD ContextFlags; // // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT // included in CONTEXT_FULL. // DWORD Dr0; DWORD Dr1; DWORD Dr2; DWORD Dr3; DWORD Dr6; DWORD Dr7; // // This section is specified/returned if the // ContextFlags word contians the flag CONTEXT_FLOATING_POINT. // FLOATING_SAVE_AREA FloatSave; // // This section is specified/returned if the // ContextFlags word contians the flag CONTEXT_SEGMENTS. // DWORD SegGs; DWORD SegFs; DWORD SegEs; DWORD SegDs; // // This section is specified/returned if the // ContextFlags word contians the flag CONTEXT_INTEGER. // DWORD Edi; DWORD Esi; DWORD Ebx; DWORD Edx; DWORD Ecx; DWORD Eax; // // This section is specified/returned if the // ContextFlags word contians the flag CONTEXT_CONTROL. // DWORD Ebp; DWORD Eip; DWORD SegCs; // MUST BE SANITIZED DWORD EFlags; // MUST BE SANITIZED DWORD Esp; DWORD SegSs; // // This section is specified/returned if the ContextFlags word // contains the flag CONTEXT_EXTENDED_REGISTERS. // The format and contexts are processor specific // BYTE ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION]; } CONTEXT;
赵4老师 2014-08-05
  • 打赏
  • 举报
回复
SetUnhandledExceptionFilter The SetUnhandledExceptionFilter function lets an application supersede the top-level exception handler that Win32 places at the top of each thread and process. After calling this function, if an exception occurs in a process that is not being debugged, and the exception makes it to the Win32 unhandled exception filter, that filter will call the exception filter function specified by the lpTopLevelExceptionFilter parameter. LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter // exception filter function ); Parameters lpTopLevelExceptionFilter Pointer to a top-level exception filter function that will be called whenever the UnhandledExceptionFilter function gets control, and the process is not being debugged. A value of NULL for this parameter specifies default handling within UnhandledExceptionFilter. The filter function has syntax congruent to that of UnhandledExceptionFilter: It takes a single parameter of type LPEXCEPTION_POINTERS, and returns a value of type LONG. The filter function should return one of the following values: Value Meaning EXCEPTION_EXECUTE_HANDLER Return from UnhandledExceptionFilter and execute the associated exception handler. This usually results in process termination. EXCEPTION_CONTINUE_EXECUTION Return from UnhandledExceptionFilter and continue execution from the point of the exception. Note that the filter function is free to modify the continuation state by modifying the exception information supplied through its LPEXCEPTION_POINTERS parameter. EXCEPTION_CONTINUE_SEARCH Proceed with normal execution of UnhandledExceptionFilter. That means obeying the SetErrorMode flags, or invoking the Application Error pop-up message box. UnhandledExceptionFilter The UnhandledExceptionFilter function passes unhandled exceptions to the debugger, if the process is being debugged. Otherwise, it optionally displays an Application Error message box and causes the exception handler to be executed. This function can be called only from within the filter expression of a try-except exception handler. LONG UnhandledExceptionFilter( STRUCT _EXCEPTION_POINTERS *ExceptionInfo // address of // exception info ); Parameters ExceptionInfo Pointer to an EXCEPTION_POINTERS structure containing a description of the exception and the processor context at the time of the exception. This pointer is the return value of a call to the GetExceptionInformation function. Return Values GetExceptionInformation The GetExceptionInformation function retrieves a machine-independent description of an exception, and information about the machine state that existed for the thread when the exception occurred. This function can be called only from within the filter expression of a try-except exception handler. Note The Microsoft C/C++ Optimizing Compiler interprets this function as a keyword, and its use outside the appropriate exception-handling syntax generates a compiler error. LPEXCEPTION_POINTERS GetExceptionInformation(VOID) Parameters This function has no parameters. Return Values The return value is a pointer to an EXCEPTION_POINTERS structure that contains pointers to two other structures: an EXCEPTION_RECORD structure containing a description of the exception, and a CONTEXT structure containing the machine-state information. CONTEXT A CONTEXT structure contains processor-specific register data. Windows NT uses CONTEXT structures to perform various internal operations. Currently, there are CONTEXT structures defined for Intel, MIPS, Alpha, and PowerPC, processors. Refer to the header file WinNT.h for definitions of these structures. QuickInfo

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧