Using DBGHELP to generate dump files and post-mortem debug analysis

Source: Internet
Author: User

Objective

In the actual application of the product environment, if our program in the customer there is a problem, such as the program is abnormal, and this time the phenomenon can not be restored or difficult to restore reproduce, then only use dump file to save the program's current running information, such as Call stack, and use symbol files to locate the problem; The main explanation here is to use the DBGHELP library to generate the output dump file, using symbol files and WinDbg to analyze the problem.

Sample code


 1 #include "stdafx.h" 2 #include <Windows.h> 3 #include <iostream> 4 #include "dbghelp.h" 5 using namespace S td 6 LONG WINAPI toplevelexceptionfilter (struct _exception_pointers *pexceptioninfo) 7 {8 cout << "Enter topleve   Lexceptionfilter Function "<< Endl;  9 HANDLE hfile = CreateFile (_t ("Project.dmp"), generic_write,0,null,create_always,file_attribute_normal,null);  Ten minidump_exception_information Stexceptionparam;  One stexceptionparam.threadid = GetCurrentThreadID ();  Stexceptionparam.exceptionpointers = Pexceptioninfo;  Stexceptionparam.clientpointers = FALSE; MiniDumpWriteDump (GetCurrentProcess (), GetCurrentProcessId (),hfile,minidumpwithfullmemory,&  Stexceptionparam,null,null);  CloseHandle (hfile); GetChar (); exception_execute_handler;18}19 int _tmain (int argc, _tchar* argv[]) {cout< < "Enter Main Function" <<endl;23 setunhandledexceptionfilter (ToplevElexceptionfilter); *pvalue int = null;25 cout<< "Invalid Access" <<endl;26 *pvalue = 0;27 cout<< "Finish Ma In Function "<<endl;28 GetChar (); 0;31}

The code is simple, there are several API functions you can look up MSDN, I will not explain.

Project Setup

Because of the use of the DBGHELP library, we need to configure the library dependencies as well as the header file containing information, as shown in the Settings header file:



Set the library file dependencies as shown in:





Once set, the project code is compiled successfully, and the Dbghelp.dll file is placed in the executable directory; The final result is as follows:



Since I set the build symbol file by default, that is, the dumpproject.pdb file, about the symbol file generation, as shown in the setup:





Run the program

Double-click the DumpProject.exe file, according to the code logic, because the program has an exception, so the dump file will be generated, running the result as shown:



The Project.dmp file is also generated, as shown in:



Analyze problems

Get the DMP file, symbol file, while there is the corresponding source code, then use the WinDbg tool to solve the problem, find out where the anomaly.

Open the WinDbg tool, set the good symbol file location directory, the source file location directory, and then open the Project.dmp file, which is shown below:



Enter the following!ANALYZE-V command on the WinDbg command line to parse the exact location where the exception appears, as shown in:



End

Convenient and quick positioning analysis problem, improve efficiency;

Http://www.cnblogs.com/appsucc/p/3458906.html

Using DBGHELP to generate dump files and post-mortem debug analysis

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.