DCSIMG
Programmatically Generating a Dump File - All Your Base Are Belong To Us

All Your Base Are Belong To Us

Mostly .NET internals and other kinds of gory details

Programmatically Generating a Dump File

I've discussed dump analysis on several occasions, including detailed walkthroughs of native and managed issues - crashes, hangs, deadlocks and the rest of the bug zoo.

(Alon has just recently been to this bug zoo and promised me pictures.)

Oftentimes it's useful to generate a dump programmatically.  For example, if your application fails and you want to record the data and send it over the network or persist it to some durable storage, you can do so without relying on Windows Error Reporting or other mechanisms.

[DllImportAttribute("dbghelp.dll")]

[return: MarshalAsAttribute(UnmanagedType.Bool)]

private static extern bool MiniDumpWriteDump(

    [In] IntPtr hProcess,

    uint ProcessId,

    SafeFileHandle hFile,

    DumpType DumpType,

    [In] IntPtr ExceptionParam,

    [In] IntPtr UserStreamParam,

    [In] IntPtr CallbackParam);

The way to go is the MiniDumpWriteDump function, exposed from dbghelp.dll.  I've written a simple helper class for using this API from C#, which can be downloaded from here.  Sample usage would be:

DumpHelper.WriteTinyDumpForThisProcess(

    @"D:\temp\mini.dmp");

 

Process process = Process.Start("notepad.exe");

process.WaitForInputIdle();

DumpHelper.WriteFullDumpForProcess(

    process, @"D:\temp\full.dmp");

 

process.Kill();

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: