Memory Dump during abnormal downtime in Windows

Source: Internet
Author: User

 

If you write more code, you will inevitably encounter unexpected or unknown errors. Unlike the Java pure oo advanced language, exception capture in C ++ is rarely used (it seems that foreigners like it very much, such as ogre and cegui are used ). Besides, this is not efficient. Therefore, when a program goes down, the log (for example, better debugging) or the memory dumping file (for example, core dump in Linux and mini dump in Windows) should be taken into account ). Here, we only provide a simple usage of minidump in Windows (it has never been used before, and this is what we learned from the main program ^_^ .. The generated DMP file can be analyzed by windbg. In this way, you can quickly locate errors.

 

# Ifdef Win32 <br/> // dump minidump in Windows environment <br/> # include <dbghelp. h> <br/> # pragma comment (Lib, "dbghelp. lib ") <br/> int write_dump (pexception_pointers extends tptr) <br/>{< br/> If (! Extends tptr) {return 0 ;}< br/> const int tempstrlen = 256; <br/> char filename [tempstrlen]; <br/>:: zeromemory (filename, tempstrlen ); <br/> systemtime effecime; <br/>: zeromemory (& systime, sizeof (systime); <br/>: getlocaltime (& systime ); <br/> sprintf_s (filename, tempstrlen ,". /guistudio_memdump _ % d. % d. % d _ % d. % d. % d. DMP ", <br/> policime. wyear, too ime. wmonth, too ime. wday, <br/> policime. whour, mongoime. wminute, policime. Wsecond); <br/> minidump_exception_information effectinfo; <br/>: zeromemory (& effectinfo, sizeof (effectinfo); <br/> effectinfo. predictionpointers = effectptr; <br/> effectinfo. clientpointers = false; <br/> using tinfo. threadid =: getcurrentthreadid (); <br/> handle hfile =: createfilea (filename, generic_write, 0, create_new, file_attribute_compressed, 0); <br/> :: minidumpwritedump (<br/>: getcurrentprocess (), <Br/>: getcurrentprocessid (), <br/> hfile, <br/> minidumpnormal, <br/> & cmdtinfo, null, null); <br/> :: closehandle (hfile); <br/> return 0; <br/>}< br/> # endif <br/> // proxy main <br/> int proxy_main (INT argc, char ** argv) <br/> {<br/> // your code... <br/>}< br/> // real main entry <br/> int main (INT argc, char ** argv) <br/> {<br/> int ret = 0; <br/> # ifdef Win32 <br/>__ try <br/> {<br/> # endif <br/> ret = proxy_m Ain (argc, argv); <br/> # ifdef Win32 <br/>__ compile T (write_dump (getexceptioninformation ())) <br/>{< br/> // we got an exception! <Br/> return-1; <br/>}< br/> # endif <br/> return ret; <br/>}< br/> 

 

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.