zoukankan      html  css  js  c++  java
  • windows设置程序崩溃转储

    设置崩溃处理函数

    #if (defined _WIN32)||(defined _WIN64)
    #include <windows.h>
    #include <Dbghelp.h>
    #include <tchar.h>
    //#pragma execution_character_set( "utf-8" )
    typedef BOOL(WINAPI* MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
    
    void CreateMinDump(struct _EXCEPTION_POINTERS* apExceptionInfo)
    {
        HMODULE mhLib = ::LoadLibrary(_T("dbghelp.dll"));
        MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress(mhLib, "MiniDumpWriteDump");
    
        HANDLE  hFile = ::CreateFile(_T("core.dmp"), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
            FILE_ATTRIBUTE_NORMAL, NULL);
    
        _MINIDUMP_EXCEPTION_INFORMATION ExInfo;
        ExInfo.ThreadId = ::GetCurrentThreadId();
        ExInfo.ExceptionPointers = apExceptionInfo;
        ExInfo.ClientPointers = FALSE;
    
        pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL);
        ::CloseHandle(hFile);
    }
    
    long   __stdcall   HandlerCrash(struct _EXCEPTION_POINTERS* apExceptionInfo)
    {
        DLOG(INFO) << "crashed!!!!!!!!!!!!!!!!!!!!!!!!!";
        CreateMinDump(apExceptionInfo);
        return EXCEPTION_CONTINUE_SEARCH;
    }
    #endif

    注册崩溃事件

    #if (defined _WIN32)||(defined _WIN64)
        SetUnhandledExceptionFilter(HandlerCrash);
    #endif
    MINIDUMPWRITEDUMP 不是线程安全的 有时可能无法生成转储文件


    通过配置注册表windows错误报告时限捕捉转储文件 wer

    reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsWindows Error ReportingLocalDumps" /f
    reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsWindows Error ReportingLocalDumpshttpd.exe" /f
    reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsWindows Error ReportingLocalDumpshttpd.exe" /v DumpFolder /t REG_EXPAND_SZ /d "C:crashdumps" /f
    reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsWindows Error ReportingLocalDumpshttpd.exe" /v DumpType /t REG_DWORD /d "1" /f

    其中

    DumpType 设置1 未mindump   转储文件几m
          设置为2 为fulldump 转储文件几十m


  • 相关阅读:
    在VMware 虚拟机中彻底删除linux系统
    Linux中安装MySQL5.7和查看启动状态
    VMware启动时提示我已移动或我已复制该虚拟机
    Linux中查看MySQL版本启动默认安装位置
    linux 下查看redis是否启动和启动命令
    Linux中查看redis版本
    maven下载依赖失败解决方案
    《痞子衡嵌入式半月刊》 第 27 期
    痞子衡嵌入式:盘点国内车规级MCU厂商
    痞子衡嵌入式:盘点国内Cortex-M内核MCU厂商高性能产品
  • 原文地址:https://www.cnblogs.com/wolbo/p/14868051.html
Copyright © 2011-2022 走看看