• MiniDump


    一、minidump 模块集成

    // .pro
    QT -= gui
    
    CONFIG += c++11 console
    CONFIG -= app_bundle
    
    # The following define makes your compiler emit warnings if you use
    # any Qt feature that has been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
            main.cpp
    
    
    QMAKE_LFLAGS_RELEASE += /MAP
    QMAKE_CFLAGS_RELEASE += /Zi
    QMAKE_LFLAGS_RELEASE += /debug /opt:ref
    
    QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
    QMAKE_LFLAGS_RELEASE += $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO
    
    LIBS += -lDbgHelp
    
    
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    // main.cpp
    #include 
    #include 
    #include 
    #include 
    #ifdef Q_OS_WIN
    #   include 
    #   include 
    #   pragma comment( lib, "Dbghelp.lib" )
    #endif
    
    #define DumpFileDir qApp->applicationDirPath() + "/dump/"
    
    
    static LONG WINAPI AppExceptionCallback(struct _EXCEPTION_POINTERS *ExceptionInfo)
    {
        QString savePath = DumpFileDir;
        savePath.append(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
        savePath.append(".dmp");
        qDebug() << savePath;
    
        QString msg;
        HANDLE hDumpFile = CreateFileW(savePath.toStdWString().c_str(),
                                       GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ,
                                       0, CREATE_ALWAYS, 0, 0);
        if(INVALID_HANDLE_VALUE == hDumpFile)
        {
            return EXCEPTION_EXECUTE_HANDLER;
        }
    
    
        MINIDUMP_EXCEPTION_INFORMATION ExpParam;
        ExpParam.ThreadId = GetCurrentThreadId();
        ExpParam.ExceptionPointers = ExceptionInfo;
        ExpParam.ClientPointers = TRUE;
    
        // 创建Dump文件
        MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpWithDataSegs, ExceptionInfo ? &ExpParam : nullptr, nullptr, nullptr);
        CloseHandle(hDumpFile);
    
    
        // 提示
        QString strTitle ("Application Error");
        QString strContent ("I'm Sorry,Application is Crash!");
        qDebug() << strContent << "," << QStringLiteral("dump文件路径为 ") << savePath;
    
        return EXCEPTION_EXECUTE_HANDLER;
    }
    
    
    /// crashed 模块
    int testCrashedFunc(int ia,int ib)
    {
        int ret = ia/ib;
        qDebug() << ret;
        return ret;
    }
    
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc,argv);
    
    #ifdef Q_OS_WIN
        QDir dir(DumpFileDir);
        if(!dir.exists())
            if (!dir.mkpath(DumpFileDir))
                qDebug() << QStringLiteral("创建dump文件目录失败");
    
        SetUnhandledExceptionFilter(AppExceptionCallback);
    #endif
    
        testCrashedFunc(10,0);
        return 0;
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77

    二、dump文件分析

    调试可参考: https://www.cnblogs.com/kekec/archive/2012/11/14/2755924.html

    或者参考 https://learn.microsoft.com/zh-cn/windows-hardware/drivers/debugger/getting-started-with-windbg
    在这里插入图片描述

  • 相关阅读:
    Lifetime improvement through adaptive reconfiguration for nonvolatile FPGAs
    常用损失函数详解:广泛使用的优化约束方法
    数据结构与算法之矩阵: Leetcode 48. 旋转矩阵 (Typescript版)
    在Postgres中分页的五种方法,从基本到异国情调
    【MySQL函数篇】—— 字符串函数(超详细)
    云原生:构建现代化应用的新篇章
    PCA算法(python版本)
    【IPC】 共享内存
    Java中如何清空一个HashSet对象呢?
    python-立方和不等式
  • 原文地址:https://blog.csdn.net/weixin_39568531/article/details/132778700