forked from kmvi/minidump
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
namespace minidump | ||
{ | ||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms680519(v=vs.85).aspx | ||
[Flags] | ||
public enum MINIDUMP_TYPE | ||
{ | ||
MiniDumpNormal = 0x00000000, | ||
MiniDumpWithDataSegs = 0x00000001, | ||
MiniDumpWithFullMemory = 0x00000002, | ||
MiniDumpWithHandleData = 0x00000004, | ||
MiniDumpFilterMemory = 0x00000008, | ||
MiniDumpScanMemory = 0x00000010, | ||
MiniDumpWithUnloadedModules = 0x00000020, | ||
MiniDumpWithIndirectlyReferencedMemory = 0x00000040, | ||
MiniDumpFilterModulePaths = 0x00000080, | ||
MiniDumpWithProcessThreadData = 0x00000100, | ||
MiniDumpWithPrivateReadWriteMemory = 0x00000200, | ||
MiniDumpWithoutOptionalData = 0x00000400, | ||
MiniDumpWithFullMemoryInfo = 0x00000800, | ||
MiniDumpWithThreadInfo = 0x00001000, | ||
MiniDumpWithCodeSegs = 0x00002000, | ||
MiniDumpWithoutAuxiliaryState = 0x00004000, | ||
MiniDumpWithFullAuxiliaryState = 0x00008000, | ||
MiniDumpWithPrivateWriteCopyMemory = 0x00010000, | ||
MiniDumpIgnoreInaccessibleMemory = 0x00020000, | ||
MiniDumpWithTokenInformation = 0x00040000, | ||
MiniDumpWithModuleHeaders = 0x00080000, | ||
MiniDumpFilterTriage = 0x00100000, | ||
MiniDumpValidTypeFlags = 0x001fffff | ||
} | ||
|
||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms680366(v=vs.85).aspx | ||
[StructLayout(LayoutKind.Sequential, Pack = 4)] | ||
public struct MINIDUMP_EXCEPTION_INFORMATION | ||
{ | ||
public uint ThreadId; | ||
public IntPtr ExceptionPointers; | ||
public int ClientPointers; | ||
} | ||
|
||
public class MiniDump | ||
{ | ||
[DllImport("kernel32.dll")] | ||
private static extern uint GetCurrentThreadId(); | ||
|
||
[DllImport("DbgHelp.dll")] | ||
private static extern bool MiniDumpWriteDump(IntPtr hProcess, uint ProcessId, | ||
IntPtr hFile, int DumpType, ref MINIDUMP_EXCEPTION_INFORMATION ExceptionParam, | ||
IntPtr UserStreamParam, IntPtr CallbackParam); | ||
|
||
public static void CreateMiniDump() | ||
{ | ||
var proc = Process.GetCurrentProcess(); | ||
var fileName = String.Format("minidump_{0}_{1}.dmp", proc.ProcessName, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")); | ||
|
||
var info = new MINIDUMP_EXCEPTION_INFORMATION() | ||
{ | ||
ThreadId = GetCurrentThreadId(), | ||
ExceptionPointers = Marshal.GetExceptionPointers(), | ||
ClientPointers = 1 | ||
}; | ||
|
||
using (var fs = new FileStream(fileName, FileMode.Create)) { | ||
MiniDumpWriteDump(proc.Handle, (uint)proc.Id, fs.SafeFileHandle.DangerousGetHandle(), | ||
(int)MINIDUMP_TYPE.MiniDumpNormal, ref info, IntPtr.Zero, IntPtr.Zero); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters