コード例 #1
0
        /**//*
         * 自己包装的一个函数
         */
        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);
            }
        }
コード例 #2
0
 public static extern bool MiniDumpWriteDump(
     IntPtr hProcess,
     uint ProcessId,
     IntPtr hFile,
     MiniDumpType DumpType,
     IntPtr ExceptionParam,
     IntPtr UserStreamParam, IntPtr CallbackParam);
コード例 #3
0
ファイル: MiniDumpUtil.cs プロジェクト: rox00/WPF
 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);
 }
コード例 #4
0
        /*
         * 自己包装的一个函数
         */
        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);
            }
        }
コード例 #5
0
ファイル: ToolMiniDump.cs プロジェクト: LiYouR/MyCommonTool
        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);
            }
        }
コード例 #6
0
ファイル: MiniDump.cs プロジェクト: jungrok5/BitBox
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: LogManager.cs プロジェクト: vansha/orleans
        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));
        }
コード例 #9
0
            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);
                }
            }
コード例 #10
0
        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);
        }
コード例 #11
0
 private static extern Boolean MiniDumpWriteDump(
     IntPtr hProcess,
     Int32 processId,
     IntPtr fileHandle,
     MiniDumpType dumpType,
     ref MinidumpExceptionInfo excepInfo,
     IntPtr userInfo,
     IntPtr extInfo);
コード例 #12
0
 public static extern bool MiniDumpWriteDump(
     IntPtr hProcess,
     uint processId,
     SafeHandle hFile,
     MiniDumpType dumpType,
     IntPtr expParam,
     IntPtr userStreamParam,
     IntPtr callbackParam);
コード例 #13
0
ファイル: LogManager.cs プロジェクト: vansha/orleans
 public static extern bool MiniDumpWriteDump(
     IntPtr hProcess,
     int processId,
     IntPtr hFile,
     MiniDumpType dumpType,
     IntPtr exceptionParam,
     IntPtr userStreamParam,
     IntPtr callbackParam);
コード例 #14
0
 private static extern Boolean MiniDumpWriteDump(
     IntPtr hProcess,
     Int32 processid,
     IntPtr fileHandle,
     MiniDumpType dumpType,
     IntPtr exinfo,
     IntPtr userInfo,
     IntPtr extInfo);
コード例 #15
0
 internal static extern bool MiniDumpWriteDump(
     IntPtr hProcess,
     Int32 processId,
     Microsoft.Win32.SafeHandles.SafeFileHandle hFile,
     MiniDumpType dumpType,
     IntPtr exceptionParam,
     IntPtr userStreamParam,
     IntPtr callbackParam);
コード例 #16
0
 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);
コード例 #17
0
 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);
コード例 #18
0
 public static extern bool MiniDumpWriteDump(
     IntPtr hProcess,
     uint ProcessId,
     IntPtr hFile,
     MiniDumpType DumpType,
     ref MINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
     IntPtr UserStreamParam,
     IntPtr CallbackParam);
コード例 #19
0
        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);
            }
        }
コード例 #20
0
        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);
        }
コード例 #21
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);
            }
        }
コード例 #22
0
        /// <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);
        }
コード例 #23
0
        /// <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);
            }
        }
コード例 #24
0
            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);
                }
            }
コード例 #25
0
        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);
        }
コード例 #26
0
        /// <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));
            }
        }
コード例 #27
0
        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);
            }
        }
コード例 #28
0
 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);
     }
 }
コード例 #29
0
        /// <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);
        }
コード例 #30
0
ファイル: DumpWriter.cs プロジェクト: mgnslndh/NCrash
        /// <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;
        }
コード例 #31
0
        /// <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);
        }
コード例 #32
0
        /// <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));
        }
コード例 #33
0
ファイル: DumpWriter.cs プロジェクト: mgnslndh/NCrash
 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;
 }
コード例 #34
0
ファイル: DumpUtil.cs プロジェクト: zhangz/Toolbox
			internal DumpParams(string fileName, MiniDumpType dumpType)
			{
				this.fileName = fileName;
				this.dumpType = dumpType;
			}
コード例 #35
0
 internal static extern bool MiniDumpWriteDump(
     IntPtr hProcess,
     Int32 processId,
     Microsoft.Win32.SafeHandles.SafeFileHandle hFile,
     MiniDumpType dumpType,
     IntPtr exceptionParam,
     IntPtr userStreamParam,
     IntPtr callbackParam);
コード例 #36
0
ファイル: MiniDump.cs プロジェクト: jungrok5/BitBox
        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;
        }
コード例 #37
0
ファイル: XTrace.cs プロジェクト: windygu/asxinyunet
            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;
                }
            }
コード例 #38
0
ファイル: DbgHelp.cs プロジェクト: John-Leitch/GenomeDotNet
 public static extern bool MiniDumpWriteDump(IntPtr hProcess, uint ProcessId,
     IntPtr hFile, MiniDumpType DumpType, ref MINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
     IntPtr UserStreamParam, IntPtr CallbackParam);
コード例 #39
0
ファイル: NativeMethods.cs プロジェクト: bashwork/common
 public static extern bool MiniDumpWriteDump( IntPtr hProcess,
     int processId,
     SafeFileHandle hFile,
     MiniDumpType dumpType,
     IntPtr exceptionParam,
     IntPtr userStreamParam,
     IntPtr callbackParam);
コード例 #40
0
ファイル: XTrace.cs プロジェクト: windygu/asxinyunet
  private static extern Boolean MiniDumpWriteDump(
  IntPtr hProcess,
  Int32 processId,
  IntPtr fileHandle,
  MiniDumpType dumpType,
 ref MinidumpExceptionInfo excepInfo,
  IntPtr userInfo,
  IntPtr extInfo);
コード例 #41
0
ファイル: BlackBox.cs プロジェクト: RoDaniel/featurehouse
         public static extern bool MiniDumpWriteDump(IntPtr hProcess, uint ProcessId,
 SafeFileHandle hFile, MiniDumpType DumpType,
 ref MiniDumpExceptionInfo ExceptionParam, IntPtr UserStreamParam,
 IntPtr CallbackParam);
コード例 #42
0
 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);
     }
 }
コード例 #43
0
ファイル: DumpUtil.cs プロジェクト: zhangz/Toolbox
		public static void CreateDump(string dumpFileName, MiniDumpType dumpType)
		{
			if (!isMiniDumpExecuting)
				ThreadPool.QueueUserWorkItem(new WaitCallback(CreateDump), new DumpParams(dumpFileName, dumpType));
		}