[windows]_[Primary]_[release Program crash report minidump solution]

Source: Internet
Author: User


Scene:

1. When the release program crashes, the crash report allows the developer to pinpoint where the code has gone wrong and is useful.

2. Only the compiler with VS is supported, so the MINGW is not available.

3. The unhandled exception filtering handler is used.

4. The generated. dmp file is compressed with the Zlib library, using the following Ziphelper class, which requires zlib libraries and dbghelp.lib at compile time

http://blog.csdn.net/infoworld/article/details/41290969


5. The use of Dbgreport as a member variable of the app class, or a file-scoped global variable is initialized, before the program runs before the start of the call

Registercrashfilter

6. Helpful help to top down or leave a message.


Dbg_report.h

#ifndef __dbg_report#define __dbg_report#include <string>//1. You can modify the parameters yourself to add additional information. typedef void (* Reportcallbackfunc) (const wchar_t* Dump_zip_path); class Dbgreport{public:dbgreport () {}~dbgreport () {}void Registercrashfilter (const wchar_t* dump_path,reportcallbackfunc func);}; #endif

Dbg_report.cpp

#include "dbg_report.h" #include <Windows.h> #include <DbgHelp.h> #include "zip_helper.h" Static std:: Wstring gdumppath;static std::wstring gdumpzippath;static reportcallbackfunc greportcallbackfunc = NULL;static char*      Qxunicode2utf8 (const wchar_t* Unicode) {int len;      Len = WideCharToMultiByte (Cp_utf8, 0, Unicode,-1, NULL, 0, NULL, NULL);      Char *szutf8 = (char*) malloc (len + 1);      memset (SzUtf8, 0, Len + 1);      WideCharToMultiByte (Cp_utf8, 0, Unicode,-1, SzUtf8, Len, null,null);  return SzUtf8;  }static wchar_t* qxutf82unicode (const char* UTF) {if (!utf | |!strlen (UTF)) {return NULL;  } int dwunicodelen = MultiByteToWideChar (cp_utf8,0,utf,-1,null,0);  size_t num = dwunicodelen*sizeof (wchar_t);  wchar_t *pwtext = (wchar_t*) malloc (num);  memset (Pwtext,0,num);  MultiByteToWideChar (Cp_utf8,0,utf,-1,pwtext,dwunicodelen);  return pwtext; } static LONG WINAPI toplevelunhandledexceptionfilter (pexception_pointers pexinfo) {HANDLE hfile =:: CreateFile (GdumPpath.c_str (), Generic_write, 0, Null,create_always, File_attribute_normal, NULL); if (hfile! = Invalid_handle_value) { Minidump_exception_information Einfo;einfo. ThreadId =:: GetCurrentThreadID (); Einfo. Exceptionpointers = Pexinfo;einfo. Clientpointers = False;::minidumpwritedump (:: GetCurrentProcess (),:: GetCurrentProcessId (), HFile,MiniDumpNormal, &einfo, NULL, NULL);:: CloseHandle (hfile);} 1. Compress DMP files and other char* UTF8 = Qxunicode2utf8 (Gdumppath.c_str ()); Ziphelper z;z.addfile (UTF8); std::string output (UTF8); Output.append (". zip"); wchar_t* Unicode = Qxutf82unicode ( Output.c_str ()), Gdumpzippath.append (Unicode), Z.tozip (Output.c_str ()), free (UTF8), free (Unicode), if ( Greportcallbackfunc) {Greportcallbackfunc (Gdumpzippath.c_str ());} return exception_execute_handler;} void Dbgreport::registercrashfilter (const wchar_t* dump_path,reportcallbackfunc func) {#ifndef _ Debuggdumppath.append (dump_path); greportcallbackfunc = func; SetUnhandledExceptionFilter (Toplevelunhandledexceptionfilter); #endif}




[windows]_[Primary]_[release Program crash report minidump solution]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.