windows下qt生成及使用dump文件

1. 生成dump文件

LONG ApplicationCrashHandler(EXCEPTION_POINTERS *pException){//程式异常捕获
    /*
      ***转储堆栈信息***
    */
    //创建 Dump 文件
    QString dumpFilename = QString("D:\\VerSysTombs\\") + QDateTime::currentDateTime().toString("yyyyMMddhhmmss") + ".dmp";
    HANDLE hDumpFile = CreateFile((LPCWSTR)(dumpFilename.toStdWString().c_str()), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if( hDumpFile != INVALID_HANDLE_VALUE){
        //Dump信息
        MINIDUMP_EXCEPTION_INFORMATION dumpInfo;
        dumpInfo.ExceptionPointers = pException;
        dumpInfo.ThreadId = GetCurrentThreadId();
        dumpInfo.ClientPointers = TRUE;
        //写入Dump文件内容
        MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, (MINIDUMP_TYPE)(MiniDumpWithDataSegs | MiniDumpWithProcessThreadData | MiniDumpWithUnloadedModules), &dumpInfo, NULL, NULL);
    }

    /*
      ***保存数据代码***
    */
    //这里弹出一个错误对话框并退出程序
    EXCEPTION_RECORD* record = pException->ExceptionRecord;
    QString errCode(QString::number(record->ExceptionCode,16));
    QString errAdr(QString::number((uint)record->ExceptionAddress,16));

    FLOGE("Exe Crash And Restart[errcode = %s][erraddr = %s]", errCode.toStdString().c_str(), errAdr.toStdString().c_str());

    return EXCEPTION_EXECUTE_HANDLER;
}

main函数中需要调用:

SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)ApplicationCrashHandler);//注冊异常捕获函数

2. 编译连接需要的头文件

#include 

3. .pro文件配置

# 方便生成DUMP调试
LIBS += -lDbgHelp
QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO /DEBUG

4. dump文件打开方式

https://jingyan.baidu.com/article/6b1823095425c0ba58e15902.html

5. MiniDumpWriteDump详解

https://blog.csdn.net/supermapping/article/details/50470074

你可能感兴趣的:(QT)