Windows Dump Debugging

Source: Internet
Author: User

Sometimes when the release version of the program is released, sending an exception on the client's machine, most of the time we can find the problem through the log we write, but sometimes send a crash exception (such as using the wild pointer), we want to be able to locate the code line to send the crash. At this point we can use the dump file. Similar to the core file under Linux. You can call him a "Death note."


1. Generate a dump file.

Windows provides MiniDumpWriteDump () in Dbghelp.dll. Function prototypes refer to MSDN.

"Dbghelp.h" "Dbghelp.lib" is included in the program first

The code is as follows:


#include "windows.h" #include "dbghelp.h"//long Callbackcrashhandler (exception_pointers *pexception)  {   // Here you can make a nice interface or other//  MessageBox (null,l "Oops mom, Crash", L "error", MB_OK);//write dmp file Handle hfile = CreateFile (_t ("Dump.dmp"), Generic_read | Generic_write, 0, NULL, create_always, file_attribute_normal, NULL); Please refer to msdnminidump_exception_information Einfo;einfo.threadid = GetCurrentThreadID () for a moment. Einfo.exceptionpointers = Pexception;einfo.clientpointers = FALSE; MiniDumpWriteDump (GetCurrentProcess (), GetCurrentProcessId (), hfile,minidumpnormal,pexception? &einfo:null, Null,null); CloseHandle (hfile); return exception_execute_handler;  }  void Crash ()   {    int i =;  int j = 0;  int m = i/j;  printf ("%d", m);}  int _tmain (int argc, _tchar* argv[])  {  //Set callback function for handling unhandled exception  // Program sends exception call SetUnhandledExceptionFilter ((lptop_level_exception_filter) callbackcrashhandler);  Crash (); return 0;  }


2. Analyze the dump file.

I use VS2010 to analyze the steps below.

1. Get the DUMP.DMP on the client machine.

2, put it in the same directory as your native exe,pdb. (The release version by default does not generate PDB files, can be changed through "linker", "Debug", "Generate Debugging Information", "yes" changes, so you use SVN to manage the version of the time to manage) (main EXE PDB DMP if consistent)

3, open the Dump.dmp file with vs.


The information is as follows:




Can know the cause of the exception.


4, click "Use Native only for debugging" in the upper right corner


You can trace the current number of lines in the code.







Windows Dump Debugging

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.