Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract debugging information from a crash

If my C++ app crashes on Windows I want to send useful debugging information to our server.

On Linux I would use the GNU backtrace() function - is there an equivalent for Windows?

Is there a way to extract useful debugging information after a program has crashed? Or only from within the process?

(Advice along the lines of "test you app so it doesn't crash" is not helpful! - all non-trivial programs will have bugs)

like image 469
hoju Avatar asked May 12 '09 00:05

hoju


People also ask

How do I analyze a minidump file?

To analyze a minidumpOpen Visual Studio. On the File menu, click Open Project. Set Files of type to Dump Files, navigate to the dump file, select it, and click Open. Run the debugger.

Which software can analyze a crash dump?

You can analyze crash dump files by using WinDbg and other Windows debuggers. This content is for developers. If you are a customer who has received a blue screen error code while using your computer, see Troubleshoot blue screen errors.


3 Answers

The function Stackwalk64 can be used to snap a stack trace on Windows.

If you intend to use this function, you should be sure to compile your code with FPO disabled - without symbols, StackWalk64 won't be able to properly walk FPO'd frames.

You can get some code running in process at the time of the crash via a top-level __try/__except block by calling SetUnhandledExceptionFilter. This is a bit unreliable since it requires you to have code running inside a crashed process. Alternatively, you can just the built-in Windows Error Reporting to collect crash data. This is more reliable, since it doesn't require you to add code running inside the compromised, crashed process. The only cost is to get a code-signing certificate, since you must submit a signed binary to the service. https://sysdev.microsoft.com/en-US/Hardware/signup/ has more details.

like image 114
Michael Avatar answered Nov 09 '22 09:11

Michael


You can use the Windows API call MiniDumpWriteDump if you wish to roll your own code. Both Windows XP and Vist automate this process and you can sign up at https://winqual.microsoft.com to gain access to the error reports.

Also check out http://kb.mozillazine.org/Breakpad and http://www.codeproject.com/KB/debug/crash_report.aspx for other solutions.

like image 3
Stephen Nutt Avatar answered Nov 09 '22 08:11

Stephen Nutt


This website provides quite a detailed overview of stack retrieval on Win32 after a C++ exception:

http://www.eptacom.net/pubblicazioni/pub_eng/except.html

Of course, this will only work from within the process, so if the process gets terminated or crashes to the point where it terminates before that code is run, it won't work.

like image 2
Marineio Avatar answered Nov 09 '22 08:11

Marineio