Marc Andreson
Marc Andreson

Reputation: 3495

Automatically create Visual C++ crash dump

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.

Upvotes: 5

Views: 17188

Answers (3)

Ganesh R.
Ganesh R.

Reputation: 4385

Update: Debug Diag 2.x 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.

Upvotes: 4

zerocukor287
zerocukor287

Reputation: 1046

You might want to check WER (Windows Error Reporting).

It is possible to configure it with a registry key to generate crash dump of a C++ application (not working for .NET).

The registry key*:

(as an expandable string)
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Windows Error Reporting\LocalDumps\DumpFolder

I set the value to %LOCALAPPDATA%\CrashDumps.

Also, you can filter only to your application or maximize the number of dumps even set the type of the dump.

* if it is a 32-bit application running on a 64bit system, you need to insert WOW6432Node between Software and Microsoft.

Upvotes: 0

Ajay
Ajay

Reputation: 18411

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).

Upvotes: 3

Related Questions