internal static extern Boolean MiniDumpWriteDump( IntPtr hProcess, UInt32 ProcessId, SafeFileHandle hFile, MinidumpType DumpType, ref MinidumpExceptionInformation ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);
public static void WriteDump(bool ownProcess = true, MinidumpType minidumpType = MinidumpType.MiniDumpWithFullMemory) { if (!Directory.Exists(DumpDirectory)) { Directory.CreateDirectory(DumpDirectory); } var currentProcess = Process.GetCurrentProcess(); var fileName = string.Format("{0}_{1}_{2}.dmp", currentProcess.ProcessName, DateTime.Now.ToString("yyyy-dd-mm_HH-mm-ss"), Path.GetRandomFileName().Replace(".", "")); var currentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var filePath = Path.Combine(currentDir, DumpDirectory, fileName); var handler = currentProcess.Handle; var processId = currentProcess.Id; Console.WriteLine($"Handle = {handler} ProcessId = {processId}"); if (ownProcess) { using (var fileStream = new FileStream(filePath, FileMode.CreateNew)) { MiniDumpWriteDump( handler, processId, fileStream.SafeFileHandle.DangerousGetHandle(), (int)minidumpType, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } } else { var arguments = string.Join(" ", new object[] { processId, (int)minidumpType, filePath }.Select(arg => string.Format("\"{0}\"", arg.ToString()))); var minidumperPath = "Minidumper.exe"; //var minidumperPath = CreateMinidumper(); var process = Process.Start(minidumperPath, string.Join(" ", arguments)); if (process != null) { process.WaitForExit(10000); //File.Delete(minidumperPath); } } }
public static bool WriteDump( MinidumpType minidumpType = MinidumpType.MiniDumpWithFullMemory | MinidumpType.MiniDumpWithHandleData | MinidumpType.MiniDumpWithUnloadedModules | MinidumpType.MiniDumpWithFullMemoryInfo | MinidumpType.MiniDumpWithThreadInfo) { try { if (!Directory.Exists(DumpDirectory)) { Directory.CreateDirectory(DumpDirectory); } var currentProcess = Process.GetCurrentProcess(); var fileName = GetNewDumpFileName(currentProcess.ProcessName); var currentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var filePath = Path.Combine(currentDir, DumpDirectory, fileName); var handler = currentProcess.Handle; var processId = currentProcess.Id; using (var fileStream = new FileStream(filePath, FileMode.CreateNew)) { return(MiniDumpWriteDump( handler, processId, fileStream.SafeFileHandle.DangerousGetHandle(), (int)minidumpType, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero)); } } catch (Exception) { return(false); } }
static extern bool MiniDumpWriteDump(IntPtr hProcess, Int32 ProcessId, IntPtr hFile, MinidumpType DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallackParam);
internal static extern Int32 RegisterFilter(string FileName, MinidumpType DumpType);
internal static extern Int32 CreateDump(Int32 ProcessId, string FileName, MinidumpType DumpType, Int32 ExcThreadId, IntPtr ExtPtrs);
public static extern bool MiniDumpWriteDump(IntPtr process, int processId, IntPtr file, MinidumpType type, IntPtr a, IntPtr b, IntPtr c);
internal static extern bool MiniDumpWriteDump(IntPtr hProcess, uint processId, SafeFileHandle hFile, MinidumpType dumpType, ref MinidumpExceptionInformation exceptionParam, IntPtr userStreamParam, IntPtr callbackParam);
public static extern bool MiniDumpWriteDump(IntPtr hProcess, uint processId, SafeHandle hFile, MinidumpType dumpType, IntPtr expParam, IntPtr userStreamParam, IntPtr callbackParam);