Exemplo n.º 1
0
        private static bool Write(IMarchal marchal, SafeHandle fileHandle, Option options, bool withException = false)
        {
            using (var currentProcess = Process.GetCurrentProcess())
            {
                var currentProcessHandle = currentProcess.Handle;
                var currentProcessId     = (uint)currentProcess.Id;

                MiniDumpExceptionInformation exp;

                exp.ThreadId          = GetCurrentThreadId();
                exp.ClientPointers    = false;
                exp.ExceptionPointers = IntPtr.Zero;

                if (withException)
                {
                    exp.ExceptionPointers = marchal.GetExceptionPointers();
                }

                var bRet = exp.ExceptionPointers == IntPtr.Zero
                    ? MiniDumpWriteDump(currentProcessHandle, currentProcessId, fileHandle, (uint)options, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero)
                    : MiniDumpWriteDump(currentProcessHandle, currentProcessId, fileHandle, (uint)options, ref exp, IntPtr.Zero, IntPtr.Zero);

                return(bRet);
            }
        }
 public ThreadAbortExceptionEnricher(IOptionsMonitor <CoreDebugSettings> coreDebugSettings, IHostingEnvironment hostingEnvironment, IMarchal marchal)
 {
     _coreDebugSettings  = coreDebugSettings.CurrentValue;
     _hostingEnvironment = hostingEnvironment;
     _marchal            = marchal;
     coreDebugSettings.OnChange(x => _coreDebugSettings = x);
 }
Exemplo n.º 3
0
        public static bool Dump(IMarchal marchal, IHostingEnvironment hostingEnvironment, Option options = Option.WithFullMemory, bool withException = false)
        {
            lock (LockO)
            {
                // work around "stack trace is not available while minidump debugging",
                // by making sure a local var (that we can inspect) contains the stack trace.
                // getting the call stack before it is unwound would require a special exception
                // filter everywhere in our code = not!
                var stacktrace = withException ? Environment.StackTrace : string.Empty;

                var directory = hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.Data + "/MiniDump");

                if (Directory.Exists(directory) == false)
                {
                    Directory.CreateDirectory(directory);
                }

                var filename = Path.Combine(directory, $"{DateTime.UtcNow:yyyyMMddTHHmmss}.{Guid.NewGuid().ToString("N").Substring(0, 4)}.dmp");
                using (var stream = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
                {
                    return(Write(marchal, stream.SafeFileHandle, options, withException));
                }
            }
        }
 public ThreadAbortExceptionEnricher(IOptions <CoreDebugSettings> coreDebugSettings, IHostingEnvironment hostingEnvironment, IMarchal marchal)
 {
     _coreDebugSettings  = coreDebugSettings.Value;
     _hostingEnvironment = hostingEnvironment;
     _marchal            = marchal;
 }