/**//* * 自己包装的一个函数 */ public static Boolean TryDump(String dmpPath, MiniDumpType dmpType) { //使用文件流来创健 .dmp文件 using (FileStream stream = new FileStream(dmpPath, FileMode.Create, FileAccess.ReadWrite)) { //取得进程信息 Process process = Process.GetCurrentProcess(); // MINIDUMP_EXCEPTION_INFORMATION 信息的初始化 MinidumpExceptionInfo mei = new MinidumpExceptionInfo(); mei.ThreadId = Thread.CurrentThread.ManagedThreadId; mei.ExceptionPointers = Marshal.GetExceptionPointers(); mei.ClientPointers = true; Boolean res = MiniDumpWriteDump( process.Handle, process.Id, stream.Handle, //stream.SafeFileHandle.DangerousGetHandle(), dmpType, ref mei, IntPtr.Zero, IntPtr.Zero); //清空 stream stream.Flush(); stream.Close(); return(res); } }
public static extern bool MiniDumpWriteDump( IntPtr hProcess, uint ProcessId, IntPtr hFile, MiniDumpType DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);
public static bool TryWriteMiniDump(string dmpFileName, MiniDumpType dmpType) { try { using (FileStream stream = new FileStream(dmpFileName, FileMode.OpenOrCreate)) { Process process = Process.GetCurrentProcess(); MiniDumpExceptionInfo exceptionInfo = new MiniDumpExceptionInfo(); exceptionInfo.ThreadId = GetCurrentThreadId(); exceptionInfo.ExceptionPointers = Marshal.GetExceptionPointers(); exceptionInfo.ClientPointers = true; if (exceptionInfo.ExceptionPointers == IntPtr.Zero) { return(MiniDumpWriteDump(process.Handle, process.Id, stream.SafeFileHandle.DangerousGetHandle(), dmpType, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero)); } else { return(MiniDumpWriteDump(process.Handle, process.Id, stream.SafeFileHandle.DangerousGetHandle(), dmpType, ref exceptionInfo, IntPtr.Zero, IntPtr.Zero)); } } } catch (Exception e) { Console.WriteLine(e.Message); } return(true); }
/* * 自己包装的一个函数 */ public static Boolean TryDump(String dmpPath, MiniDumpType dmpType) { var path = Path.Combine(Environment.CurrentDirectory, dmpPath); var dir = Path.GetDirectoryName(path); if (dir != null && !Directory.Exists(dir)) { Directory.CreateDirectory(dir); } //使用文件流来创健 .dmp文件 using (FileStream stream = new FileStream(path, FileMode.Create)) { //取得进程信息 Process process = Process.GetCurrentProcess(); // MINIDUMP_EXCEPTION_INFORMATION 信息的初始化 MinidumpExceptionInfo mei = new MinidumpExceptionInfo(); mei.ThreadId = System.AppDomain.GetCurrentThreadId();//only this can generate full imformation,f**k ms//System.Threading.Thread.CurrentThread.ManagedThreadId;//System.AppDomain.GetCurrentThreadId();//Thread.CurrentThread.ManagedThreadId; mei.ExceptionPointers = Marshal.GetExceptionPointers(); mei.ClientPointers = true; //这里调用的Win32 API Boolean res = MiniDumpWriteDump( process.Handle, process.Id, stream.SafeFileHandle.DangerousGetHandle(), dmpType, ref mei, IntPtr.Zero, IntPtr.Zero); //清空 stream stream.Flush(); stream.Close(); return(res); } }
public static Boolean TryDump(String dmpPath, MiniDumpType dmpType) { //Dumpファイルを作成 using (FileStream stream = new FileStream(dmpPath, FileMode.Create)) { //プロセス情報を取得 Process process = Process.GetCurrentProcess(); // MINIDUMP_EXCEPTION_INFORMATION 情報の初期化 MinidumpExceptionInfo mei = new MinidumpExceptionInfo(); mei.ThreadId = Thread.CurrentThread.ManagedThreadId; mei.ExceptionPointers = Marshal.GetExceptionPointers(); mei.ClientPointers = true; //Win32 APIを呼び出し Boolean res = MiniDumpWriteDump( process.Handle, process.Id, stream.SafeFileHandle.DangerousGetHandle(), dmpType, ref mei, IntPtr.Zero, IntPtr.Zero); //ストリームをクリア stream.Flush(); stream.Close(); return(res); } }
private static bool Write(SafeHandle fileHandle, MiniDumpType options, Exception e) { Process currentProcess = Process.GetCurrentProcess(); IntPtr currentProcessHandle = currentProcess.Handle; uint currentProcessId = (uint)currentProcess.Id; MiniDumpExceptionInformation exp; exp.ThreadId = GetCurrentThreadId(); exp.ClientPointers = false; exp.ExceptionPointers = IntPtr.Zero; if (e != null) { // TODO 어떻게 넘겨줘야되지? 이렇게 하면되나 exp.ExceptionPointers = System.Runtime.InteropServices.Marshal.GetExceptionPointers(); //exp.ExceptionPointers = System.Runtime.InteropServices.Marshal.get } bool bRet = false; if (exp.ExceptionPointers == IntPtr.Zero) { bRet = MiniDumpWriteDump(currentProcessHandle, currentProcessId, fileHandle, (uint)options, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } else { bRet = MiniDumpWriteDump(currentProcessHandle, currentProcessId, fileHandle, (uint)options, ref exp, IntPtr.Zero, IntPtr.Zero); } return(bRet); }
public static bool Write(string fileNamePrefix, string directoryName, MiniDumpType options = MiniDumpType.MiniDumpWithFullMemory | MiniDumpType.MiniDumpWithFullMemoryInfo | MiniDumpType.MiniDumpWithDataSegs | MiniDumpType.MiniDumpWithUnloadedModules | MiniDumpType.MiniDumpWithThreadInfo | MiniDumpType.MiniDumpWithHandleData) { bool result = false; if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } string fileName = Path.Combine(directoryName, string.Format("{0}-{1}.dmp", fileNamePrefix, DateTime.Now.ToString(DateTimeFormat))); try { using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Write)) { Process currentProcess = Process.GetCurrentProcess(); IntPtr currentProcessHandle = currentProcess.Handle; uint currentProcessId = (uint)currentProcess.Id; result = MiniDumpWriter.MiniDumpWriteDump(currentProcessHandle, currentProcessId, fs.SafeFileHandle.DangerousGetHandle(), (uint)options, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } } catch (Exception) { // WriteLog } return(result); }
internal static FileInfo CreateMiniDump(MiniDumpType dumpType = MiniDumpType.MiniDumpNormal) { const string dateFormat = "yyyy-MM-dd-HH-mm-ss-fffZ"; // Example: 2010-09-02-09-50-43-341Z var thisAssembly = Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly() ?? typeof(LogManager) .GetTypeInfo().Assembly; var dumpFileName = $@"{thisAssembly.GetName().Name}-MiniDump-{DateTime.UtcNow.ToString(dateFormat, CultureInfo.InvariantCulture)}.dmp"; using (var stream = File.Create(dumpFileName)) { var process = Process.GetCurrentProcess(); // It is safe to call DangerousGetHandle() here because the process is already crashing. var handle = GetProcessHandle(process); NativeMethods.MiniDumpWriteDump( handle, process.Id, stream.SafeFileHandle.DangerousGetHandle(), dumpType, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } return(new FileInfo(dumpFileName)); }
public static Boolean TryDump(String dmpPath, MiniDumpType dmpType) { //使用文件流来创健 .dmp文件 using (var stream = new FileStream(dmpPath, FileMode.Create)) { //取得进程信息 var process = Process.GetCurrentProcess(); // MINIDUMP_EXCEPTION_INFORMATION 信息的初始化 var mei = new MinidumpExceptionInfo(); mei.ThreadId = (UInt32)GetCurrentThreadId(); mei.ExceptionPointers = Marshal.GetExceptionPointers(); mei.ClientPointers = 1; //这里调用的Win32 API var fileHandle = stream.SafeFileHandle.DangerousGetHandle(); var res = MiniDumpWriteDump(process.Handle, process.Id, fileHandle, dmpType, ref mei, IntPtr.Zero, IntPtr.Zero); //清空 stream stream.Flush(); stream.Close(); return(res); } }
private static bool Write(SafeHandle fileHandle, MiniDumpType dumpType) { switch (dumpType) { case MiniDumpType.None: // just ignore break; case MiniDumpType.Tiny: return(Write(fileHandle, DumpTypeFlag.WithIndirectlyReferencedMemory | DumpTypeFlag.ScanMemory)); case MiniDumpType.Normal: // If the debugger is attached, it is not possible to access private read-write memory if (Debugger.IsAttached) { return(Write(fileHandle, DumpTypeFlag.WithDataSegs | DumpTypeFlag.WithHandleData | DumpTypeFlag.WithUnloadedModules)); } // Bug: Combination of WithPrivateReadWriteMemory + WithDataSegs hangs Visual Studio 2010 SP1 on some cases while loading the minidump for debugging in mixed mode which was created in by a release build application return(Write(fileHandle, DumpTypeFlag.WithPrivateReadWriteMemory | DumpTypeFlag.WithDataSegs | DumpTypeFlag.WithHandleData | DumpTypeFlag.WithUnloadedModules)); case MiniDumpType.Full: return(Write(fileHandle, DumpTypeFlag.WithFullMemory)); default: throw new ArgumentOutOfRangeException("dumpType"); } return(false); }
private static extern Boolean MiniDumpWriteDump( IntPtr hProcess, Int32 processId, IntPtr fileHandle, MiniDumpType dumpType, ref MinidumpExceptionInfo excepInfo, IntPtr userInfo, IntPtr extInfo);
public static extern bool MiniDumpWriteDump( IntPtr hProcess, uint processId, SafeHandle hFile, MiniDumpType dumpType, IntPtr expParam, IntPtr userStreamParam, IntPtr callbackParam);
public static extern bool MiniDumpWriteDump( IntPtr hProcess, int processId, IntPtr hFile, MiniDumpType dumpType, IntPtr exceptionParam, IntPtr userStreamParam, IntPtr callbackParam);
private static extern Boolean MiniDumpWriteDump( IntPtr hProcess, Int32 processid, IntPtr fileHandle, MiniDumpType dumpType, IntPtr exinfo, IntPtr userInfo, IntPtr extInfo);
internal static extern bool MiniDumpWriteDump( IntPtr hProcess, Int32 processId, Microsoft.Win32.SafeHandles.SafeFileHandle hFile, MiniDumpType dumpType, IntPtr exceptionParam, IntPtr userStreamParam, IntPtr callbackParam);
public extern static bool MiniDumpWriteDump( IntPtr hProcess, UInt32 ProcessId, // DWORD is a 32 bit unsigned integer SafeHandle hFile, MiniDumpType DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);
public static extern bool MiniDumpWriteDump( IntPtr hProcess, UInt32 ProcessId, // DWORD is a 32 bit unsigned integer SafeHandle hFile, MiniDumpType DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);
public static extern bool MiniDumpWriteDump( IntPtr hProcess, uint ProcessId, IntPtr hFile, MiniDumpType DumpType, ref MINIDUMP_EXCEPTION_INFORMATION ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);
internal static void WriteMiniDump(string file, MiniDumpType dumpType) { Process currentProcess = Process.GetCurrentProcess(); using (FileStream stream = new FileStream(file, FileMode.Create)) { NativeMethods.MiniDumpWriteDump(currentProcess.Handle, currentProcess.Id, stream.SafeFileHandle, dumpType, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } }
public static bool TryDump(String dmpPath, MiniDumpType dmpType) { mArgs.path = dmpPath; mArgs.type = dmpType; mMei.ThreadId = GetCurrentThreadId(); mMei.ExceptionPointers = Marshal.GetExceptionPointers(); mMei.ClientPointers = false; Thread t = new Thread(new ThreadStart(MakeDump)); t.Start(); t.Join(); return(mDumpError == 0); }
public static long WriteDump(Process proc, string dump, MiniDumpType type) { Directory.CreateDirectory(Path.GetDirectoryName(dump)); FileStream stream = null; for (int retries = 10; retries > 0 && stream == null; --retries) { try { stream = new FileStream(dump, FileMode.Create, FileAccess.Write, FileShare.None); } catch (IOException ex) { Console.WriteLine("Dump failed: {0}", ex.Message); Console.WriteLine("Retrying in 10 seconds ({0} retries remaining before choosing another name)", retries); // Ensure this is Ctrl+C abortable var evt = new AutoResetEvent(false); ConsoleCancelEventHandler handler = (o, e) => { evt.Set(); }; Console.CancelKeyPress += handler; try { if (evt.WaitOne(10000)) { Environment.Exit(1); } } finally { Console.CancelKeyPress -= handler; evt.Dispose(); } } } if (stream == null) { var baseName = Path.GetFileNameWithoutExtension(dump); var ext = Path.GetExtension(dump); dump = string.Format("{0}{1}{2}", baseName, 1, ext); for (int i = 0; File.Exists(dump); ++i) { dump = string.Format("{0}{1}{2}", baseName, 1, ext); } stream = new FileStream(dump, FileMode.Create, FileAccess.Write, FileShare.None); } using (stream) { if (!MiniDumpWriteDump(proc.Handle, (uint)proc.Id, stream.SafeFileHandle.DangerousGetHandle(), type, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero)) { throw new Win32Exception(); } return(stream.Length); } }
/// <summary> /// Create new minidump file in database directory path. Minidump file name is a random Guid /// </summary> /// <param name="backtraceReport">Current report</param> /// <param name="miniDumpType">Generated minidump type</param> /// <returns>Path to minidump file</returns> private string GenerateMiniDump(BacktraceReport backtraceReport, MiniDumpType miniDumpType) { //note that every minidump file generated by app ends with .dmp extension //its important information if you want to clear minidump file string minidumpDestinationPath = Path.Combine(DatabaseSettings.DatabasePath, $"{backtraceReport.Uuid}-dump.dmp"); MinidumpException minidumpExceptionType = backtraceReport.ExceptionTypeReport ? MinidumpException.Present : MinidumpException.None; bool minidumpSaved = MinidumpHelper.Write( filePath: minidumpDestinationPath, options: miniDumpType, exceptionType: minidumpExceptionType); return(minidumpSaved ? minidumpDestinationPath : string.Empty); }
/// <summary> /// dump,C# Invoke /// </summary> /// <param name="dmpPath"></param> /// <param name="dmpType"></param> /// <returns></returns> public static Boolean TryDump(string dmpPath, MiniDumpType dmpType) { using (FileStream stream = new FileStream(dmpPath, FileMode.Create)) { Process process = Process.GetCurrentProcess(); Boolean res = MiniDumpWriteDump(process.Handle, process.Id, stream.SafeFileHandle.DangerousGetHandle(), dmpType, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); stream.Flush(); stream.Close(); return(res); } }
public static void CreateDump(string path, MiniDumpType miniDumpType) { var exceptionInfo = new MiniDumpExceptionInfo { ThreadId = GetCurrentThreadId(), ExceptionPointers = Marshal.GetExceptionPointers(), ClientPointers = false // false because own process }; Process process = Process.GetCurrentProcess(); using (var stream = new FileStream(path, FileMode.Create)) { Debug.Assert(stream.SafeFileHandle != null); // The problem Marshal.GetExceptionPointers can return null on x86 machines due to differences // in low-level exception handling. // Then passing a MiniDumpExceptionInfo structure with a NULL ExceptionPointers members causes an // access violation. So we only pass this structure if we got a valid ExceptionPointers member. // It will probably result that x86 machines will see the instruction pointer to the MiniDumpWriteDump // line and not the exception itself. IntPtr exceptionInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(exceptionInfo)); Marshal.StructureToPtr(exceptionInfo, exceptionInfoPtr, false); try { MiniDumpWriteDump( process.Handle, process.Id, stream.SafeFileHandle.DangerousGetHandle(), miniDumpType, exceptionInfo.ExceptionPointers == IntPtr.Zero ? IntPtr.Zero : exceptionInfoPtr, IntPtr.Zero, IntPtr.Zero); } catch (Exception /*exception*/) { } Marshal.FreeHGlobal(exceptionInfoPtr); } }
public void Refresh() { if (Configuration == null || !Configuration.IsValid()) { return; } Enabled = true; #if UNITY_STANDALONE_WIN MiniDumpType = Configuration.MinidumpType; #else MiniDumpType = MiniDumpType.None; #endif Annotations.GameObjectDepth = Configuration.GameObjectDepth; HandleUnhandledExceptions(); _reportLimitWatcher = new ReportLimitWatcher(Convert.ToUInt32(Configuration.ReportPerMin)); #if UNITY_2018_4_OR_NEWER BacktraceApi = new BacktraceApi( credentials: new BacktraceCredentials(Configuration.GetValidServerUrl()), ignoreSslValidation: Configuration.IgnoreSslValidation); #else BacktraceApi = new BacktraceApi(new BacktraceCredentials(Configuration.GetValidServerUrl())); #endif if (Configuration.DestroyOnLoad == false) { DontDestroyOnLoad(gameObject); _instance = this; } Database = GetComponent <BacktraceDatabase>(); if (Database == null) { return; } Database.Reload(); Database.SetApi(BacktraceApi); Database.SetReportWatcher(_reportLimitWatcher); }
/// <summary> /// Save memory dump on disk /// </summary> /// <param name="filePath">The path where the minidump file will be saved</param> /// <param name="options">Minidump save options</param> /// <param name="exceptionType">Type to check if exception exists</param> internal static bool Write(string filePath, MiniDumpType options = MiniDumpType.WithFullMemory, MinidumpException exceptionType = MinidumpException.None) { bool miniDumpAvailable = IsMemoryDumpAvailable(); if (!miniDumpAvailable) { return(false); } Process currentProcess = Process.GetCurrentProcess(); IntPtr currentProcessHandle = currentProcess.Handle; uint currentProcessId = (uint)currentProcess.Id; var exceptionInformation = MiniDumpExceptionInformation.GetInstance(exceptionType); using (FileStream fileHandle = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Write)) { return(exceptionInformation.ExceptionPointers == IntPtr.Zero ? MiniDumpWriteDump(currentProcessHandle, currentProcessId, fileHandle.SafeFileHandle, (uint)options, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) : MiniDumpWriteDump(currentProcessHandle, currentProcessId, fileHandle.SafeFileHandle, (uint)options, ref exceptionInformation, IntPtr.Zero, IntPtr.Zero)); } }
public static int Write(string filepath, MiniDumpType dumpType) { MiniDumpProvider.MinidumpExceptionInfo structure = new MiniDumpProvider.MinidumpExceptionInfo() { ThreadId = MiniDumpProvider.GetCurrentThreadId(), ExceptionPointers = Marshal.GetExceptionPointers(), ClientPointers = false }; IntPtr num = Marshal.AllocHGlobal(Marshal.SizeOf <MiniDumpProvider.MinidumpExceptionInfo>(structure)); try { using (FileStream fileStream = new FileStream(filepath, FileMode.Create)) { Process currentProcess = Process.GetCurrentProcess(); Marshal.StructureToPtr <MiniDumpProvider.MinidumpExceptionInfo>(structure, num, false); return(MiniDumpProvider.MiniDumpWriteDump(currentProcess.Handle, currentProcess.Id, fileStream.SafeFileHandle.DangerousGetHandle(), dumpType, structure.ClientPointers ? num : IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) ? 0 : Marshal.GetLastWin32Error()); } } finally { Marshal.FreeHGlobal(num); } }
public static bool Write(string fileName, MiniDumpType dumpType) { try { using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { MiniDumpExceptionInformation exp; exp.ThreadId = GetCurrentThreadId(); exp.ClientPointers = 0; exp.ExceptionPointers = System.Runtime.InteropServices.Marshal.GetExceptionPointers(); return(MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), fs.SafeFileHandle.DangerousGetHandle(), (uint)dumpType, ref exp, IntPtr.Zero, IntPtr.Zero)); } } catch { return(false); } }
/// <summary> /// Create new minidump file in database directory path. Minidump file name is a random Guid /// </summary> /// <param name="backtraceReport">Current report</param> /// <param name="miniDumpType">Generated minidump type</param> /// <returns>Path to minidump file</returns> internal virtual string GenerateMiniDump(BacktraceReport backtraceReport, MiniDumpType miniDumpType) { if (miniDumpType == MiniDumpType.None) { return(string.Empty); } //note that every minidump file generated by app ends with .dmp extension //its important information if you want to clear minidump file string minidumpDestinationPath = Path.Combine(_path, string.Format("{0}-dump.dmp", backtraceReport.Uuid)); MinidumpException minidumpExceptionType = backtraceReport.ExceptionTypeReport ? MinidumpException.Present : MinidumpException.None; bool minidumpSaved = MinidumpHelper.Write( filePath: minidumpDestinationPath, options: miniDumpType, exceptionType: minidumpExceptionType); return(minidumpSaved ? minidumpDestinationPath : string.Empty); }
/// <summary> /// Creates a new memory dump of specified type and writes it to the specified file. /// </summary> /// <param name="minidumpFilePath">The minidump file path. Overwritten if exists.</param> /// <param name="type">Mini dump type</param> /// <returns>True if Settings.MiniDumpType settings is set to anything else then MiniDumpType.None.</returns> internal static bool Write(string minidumpFilePath, MiniDumpType type) { if (type == MiniDumpType.None) { return false; } bool created; using (var fileStream = new FileStream(minidumpFilePath, FileMode.Create, FileAccess.Write)) { // ToDo: Create the minidump at a seperate process! Use this to deal with access errors: http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/c314e6ca-4892-41e7-ae19-b3a36ad640e9 // Bug: In process minidumps causes all sorts of access problems (i.e. one of them is explained below, debugger prevents accessing private memory) created = Write(fileStream.SafeFileHandle, type); } if (created) { return true; } File.Delete(minidumpFilePath); return false; }
/// <summary> /// Creates a new memory dump of specified type and writes it to the specified file. /// </summary> /// <param name="minidumpFilePath">The minidump file path. Overwritten if exists.</param> /// <param name="type">Mini dump type</param> /// <returns>True if Settings.MiniDumpType settings is set to anything else then MiniDumpType.None.</returns> internal static bool Write(string minidumpFilePath, MiniDumpType type) { if (type == MiniDumpType.None) { return(false); } bool created; using (var fileStream = new FileStream(minidumpFilePath, FileMode.Create, FileAccess.Write)) { // ToDo: Create the minidump at a seperate process! Use this to deal with access errors: http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/c314e6ca-4892-41e7-ae19-b3a36ad640e9 // Bug: In process minidumps causes all sorts of access problems (i.e. one of them is explained below, debugger prevents accessing private memory) created = Write(fileStream.SafeFileHandle, type); } if (created) { return(true); } File.Delete(minidumpFilePath); return(false); }
/// <summary> /// Add new record to database /// </summary> /// <param name="backtraceData">Diagnostic data that should be stored in database</param> /// <returns>New instance of DatabaseRecordy</returns> public virtual BacktraceDatabaseRecord Add(BacktraceData backtraceData, MiniDumpType miniDumpType = MiniDumpType.None) { if (backtraceData == null) { throw new NullReferenceException(nameof(backtraceData)); } string hash = GetHash(backtraceData); if (!string.IsNullOrEmpty(hash)) { var existRecord = BatchRetry.SelectMany(n => n.Value) .FirstOrDefault(n => n.Hash == hash); if (existRecord != null) { existRecord.Locked = true; existRecord.Increment(); TotalRecords++; return(existRecord); } } string minidumpPath = GenerateMiniDump(backtraceData.Report, miniDumpType); backtraceData.Report.SetMinidumpPath(minidumpPath); backtraceData.Attachments.Add(minidumpPath); //create new record and save it on hard drive var record = new BacktraceDatabaseRecord(backtraceData, _path) { Hash = hash }; record.Save(); //add record to database context return(Add(record)); }
private static bool Write(SafeHandle fileHandle, MiniDumpType dumpType) { switch (dumpType) { case MiniDumpType.None: // just ignore break; case MiniDumpType.Tiny: return Write(fileHandle, DumpTypeFlag.WithIndirectlyReferencedMemory | DumpTypeFlag.ScanMemory); case MiniDumpType.Normal: // If the debugger is attached, it is not possible to access private read-write memory if (Debugger.IsAttached) { return Write(fileHandle, DumpTypeFlag.WithDataSegs | DumpTypeFlag.WithHandleData | DumpTypeFlag.WithUnloadedModules); } // Bug: Combination of WithPrivateReadWriteMemory + WithDataSegs hangs Visual Studio 2010 SP1 on some cases while loading the minidump for debugging in mixed mode which was created in by a release build application return Write(fileHandle, DumpTypeFlag.WithPrivateReadWriteMemory | DumpTypeFlag.WithDataSegs | DumpTypeFlag.WithHandleData | DumpTypeFlag.WithUnloadedModules); case MiniDumpType.Full: return Write(fileHandle, DumpTypeFlag.WithFullMemory); default: throw new ArgumentOutOfRangeException("dumpType"); } return false; }
internal DumpParams(string fileName, MiniDumpType dumpType) { this.fileName = fileName; this.dumpType = dumpType; }
internal static extern bool MiniDumpWriteDump( IntPtr hProcess, Int32 processId, Microsoft.Win32.SafeHandles.SafeFileHandle hFile, MiniDumpType dumpType, IntPtr exceptionParam, IntPtr userStreamParam, IntPtr callbackParam);
private static bool Write(SafeHandle fileHandle, MiniDumpType options, Exception e) { Process currentProcess = Process.GetCurrentProcess(); IntPtr currentProcessHandle = currentProcess.Handle; uint currentProcessId = (uint)currentProcess.Id; MiniDumpExceptionInformation exp; exp.ThreadId = GetCurrentThreadId(); exp.ClientPointers = false; exp.ExceptionPointers = IntPtr.Zero; if (e != null) { // TODO 어떻게 넘겨줘야되지? 이렇게 하면되나 exp.ExceptionPointers = System.Runtime.InteropServices.Marshal.GetExceptionPointers(); //exp.ExceptionPointers = System.Runtime.InteropServices.Marshal.get } bool bRet = false; if (exp.ExceptionPointers == IntPtr.Zero) { bRet = MiniDumpWriteDump(currentProcessHandle, currentProcessId, fileHandle, (uint)options, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } else { bRet = MiniDumpWriteDump(currentProcessHandle, currentProcessId, fileHandle, (uint)options, ref exp, IntPtr.Zero, IntPtr.Zero); } return bRet; }
public static Boolean TryDump(String dmpPath, MiniDumpType dmpType) { //使用文件流来创健 .dmp文件 using (FileStream stream = new FileStream(dmpPath, FileMode.Create)) { //取得进程信息 Process process = Process.GetCurrentProcess(); // MINIDUMP_EXCEPTION_INFORMATION 信息的初始化 MinidumpExceptionInfo mei = new MinidumpExceptionInfo(); mei.ThreadId = (UInt32)GetCurrentThreadId(); mei.ExceptionPointers = Marshal.GetExceptionPointers(); mei.ClientPointers = 1; //这里调用的Win32 API Boolean res = MiniDumpWriteDump( process.Handle, process.Id, stream.SafeFileHandle.DangerousGetHandle(), dmpType, ref mei, IntPtr.Zero, IntPtr.Zero); //清空 stream stream.Flush(); stream.Close(); return res; } }
public static extern bool MiniDumpWriteDump(IntPtr hProcess, uint ProcessId, IntPtr hFile, MiniDumpType DumpType, ref MINIDUMP_EXCEPTION_INFORMATION ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);
public static extern bool MiniDumpWriteDump( IntPtr hProcess, int processId, SafeFileHandle hFile, MiniDumpType dumpType, IntPtr exceptionParam, IntPtr userStreamParam, IntPtr callbackParam);
private static extern Boolean MiniDumpWriteDump( IntPtr hProcess, Int32 processId, IntPtr fileHandle, MiniDumpType dumpType, ref MinidumpExceptionInfo excepInfo, IntPtr userInfo, IntPtr extInfo);
public static extern bool MiniDumpWriteDump(IntPtr hProcess, uint ProcessId, SafeFileHandle hFile, MiniDumpType DumpType, ref MiniDumpExceptionInfo ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);
internal static void WriteMiniDump(string file, MiniDumpType dumpType) { Process currentProcess = Process.GetCurrentProcess(); using (FileStream stream = new FileStream(file, FileMode.Create)) { NativeMethods.MiniDumpWriteDump(currentProcess.Handle, currentProcess.Id, stream.SafeFileHandle, dumpType, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } }
public static void CreateDump(string dumpFileName, MiniDumpType dumpType) { if (!isMiniDumpExecuting) ThreadPool.QueueUserWorkItem(new WaitCallback(CreateDump), new DumpParams(dumpFileName, dumpType)); }