3

Is there a way to create a crash dump file automatically on application crash (on Windows OS), same as if I could save with Visual Studio debugger attached? That is, I want to be able to debug my application in Visual Studio with automatically created crash dump files.

2 Answers 2

4

Update: Debug Diag 2.0 is now available. This release has native support for .NET dumps.

Yes it is possible using DebugDiag 1.2.

The Debug Diagnostic Tool (DebugDiag) is designed to assist in troubleshooting issues such as hangs, slow performance, memory leaks or fragmentation, and crashes in any user-mode process. The tool includes additional debugging scripts focused on Internet Information Services (IIS) applications, web data access components, COM+ and related Microsoft technologies.

It even allows you to run crash/hang analysis on the dump and give you a nice report about the callstack and thread that are in sleep state (for hang dumps). It also allows you to take on the fly dumps too. The dumps taken by DebugDiag can be analyzed in DebugDiag, Visual Studio and WinDbg.

EDIT: The MSDN link to how to use DebugDiag is here.

4
  • any example how to configure it so it attaches automatically to specific process whenever it is run? Sep 1, 2012 at 13:55
  • @MarcAndreson Just download it and launch it. The whole process is wizard driven. In case you need steps to use it, its here: support.microsoft.com/kb/2580960
    – Ganesh R.
    Sep 1, 2012 at 13:58
  • Thanks, just to add a little more info: once the rule is set, when the process crashes it will generate a dump file at C:\Program Files\DebugDiag\Logs\Crash rule for process id nnnn.dmp. This dump file can be downloaded from the production server and opened in Visual Studio for debugging, just need to set symbol path location (path of pdb file) so it can tell what function / which line of the source code
    – gerrytan
    Feb 9, 2014 at 22:37
  • all links are dead
    – paulm
    Oct 21, 2020 at 22:34
3

Use SetUnhandledExceptionFilter to catch exceptions. And in this global exception handler, use MiniDumpWriteDump function to create a dump file.

There is a lot around exception handling this way, like you won't be able to catch all exceptions (exception from STL, pure-virtual function, abort C runtime call etc). Also, you may be in problem if more than one thread causes some exception. You either need to suspend all other running threads when you get exception in your global exception handler, or use some logic so that other threads won't interfere with your dump-generation code.

To handle all cases, you need to tweak around linker settings (like /EHsc flag), so that ALL exceptions can be handled by try-catch, enable debugging information even for release build so that .PDB is generated and you can get call stack. Use API hooking, so that C-runtime calls won't disable your global-exception handler and lot!

See these:

My only recommendation is you start with simpler approach, and don't bother about more complex scenarios. In short, just use SetUnhandledExceptionFilter, in a single threaded application, cause an Access Violation, and in global-exception-handler, use MinidumpWriteDump to create a MINI dump (i.e. without memory-dump).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.