Windows debugging technology-create a minidump File

Source: Internet
Author: User
We often encounter this situation, in Program During the running process, the crash suddenly fell, and it was crash at the customer. In this case, we need to use the dump file to find the location where exception occurs. The following Code Is to create a minidump file. For the reason of Mini, it is not because it is small or the content is small, but relative to fulldump, the minidump file only stores some key virtual memory information of the Process in crash. Code
# Include " Stdafx. h "
# Include < Windows. h >
# Include < Dbghelp. h >

# PragmaComment (Lib, "dbghelp. lib ")

void createminidump (lpexception_pointers lpexceptioninfo) {
// open a file
handle hfile = createfile (_ T ( " minidump. DMP " ), generic_read | generic_write,
0 , null, create_always, file_attribute_normal, null);

If (hfile ! = null & hfile ! = invalid_handle_value) {

// Create the minidump
minidump_exception_information mdei;
mdei. threadid = getcurrentthreadid ();
mdei. predictionpointers = lpexceptioninfo;
mdei. clientpointers = false;

Minidump_type MDT = Minidumpnormal;
Bool retv = Minidumpwritedump (getcurrentprocess (), getcurrentprocessid (),
Hfile, MDT, (lpexceptioninfo ! =   0 ) ?   & Mdei: 0 , 0 , 0 );

If ( ! Retv ){
_ Tprintf (_ T ( " Minidumpwritedump failed. Error: % u \ n " ), Getlasterror ());
} Else {
_ Tprintf (_ T ( " Minidump created. \ n " ));
}

//Close the file
Closehandle (hfile );

}Else{
_ Tprintf (_ T ("Createfile failed. Error: % u \ n"), Getlasterror ());
}
}

Int _ Tmain ( Int Argc, _ tchar * Argv [])
{
_ Try {
Int   * P = NULL;
* P =   20 ;
}
_ Effect (createminidump (getexceptioninformation (), exception_execute_handler ){
}

Return 0;
}

When a minidump file is created, the dump file cannot be written. That is, there is an exception processing module outside the exception block, and the minidump file is not saved for processing. At this time, there is no way to write dump.

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.