Ejemplo n.º 1
0
        private void WriteCrashDumps(GCMode gc)
        {
            if (_fullDumpPath[(int)gc] != null)
            {
                return;
            }

            string            executable = Executable;
            DebuggerStartInfo info       = new DebuggerStartInfo();

            if (gc == GCMode.Server)
            {
                info.SetEnvironmentVariable("COMPlus_BuildFlavor", "svr");
            }

            using (Debugger dbg = info.LaunchProcess(executable, Helpers.TestWorkingDirectory))
            {
                dbg.SecondChanceExceptionEvent += delegate(Debugger d, EXCEPTION_RECORD64 ex)
                {
                    if (ex.ExceptionCode == (uint)ExceptionTypes.Clr)
                    {
                        WriteDumps(dbg, executable, gc);
                    }
                };

                DEBUG_STATUS status;
                do
                {
                    status = dbg.ProcessEvents(0xffffffff);
                } while (status != DEBUG_STATUS.NO_DEBUGGEE);

                Assert.IsNotNull(_miniDumpPath[(int)gc]);
                Assert.IsNotNull(_fullDumpPath[(int)gc]);
            }
        }
Ejemplo n.º 2
0
        public DataTarget LoadFullDumpWithDbgEng(GCMode gc = GCMode.Workstation)
        {
            Guid guid = new Guid("27fe5639-8407-4f47-8364-ee118fb08ac8");
            int  hr   = DebugCreate(guid, out IntPtr pDebugClient);

            if (hr != 0)
            {
                throw new Exception($"Failed to create DebugClient, hr={hr:x}.");
            }

            IDebugClient  client  = (IDebugClient)Marshal.GetTypedObjectForIUnknown(pDebugClient, typeof(IDebugClient));
            IDebugControl control = (IDebugControl)client;

            string dumpPath = BuildDumpName(gc, true);

            hr = client.OpenDumpFile(dumpPath);
            if (hr != 0)
            {
                throw new Exception($"Failed to OpenDumpFile, hr={hr:x}.");
            }

            hr = control.WaitForEvent(DEBUG_WAIT.DEFAULT, 10000);

            if (hr != 0)
            {
                throw new Exception($"Failed to attach to dump file, hr={hr:x}.");
            }

            Marshal.Release(pDebugClient);
            return(DataTarget.CreateFromDbgEng(pDebugClient));
        }
Ejemplo n.º 3
0
        private static string GetFullDumpName(string executable, GCMode gc)
        {
            string basePath = Path.Combine(Path.GetDirectoryName(executable), Path.GetFileNameWithoutExtension(executable));

            basePath += gc == GCMode.Workstation ? "_wks" : "_svr";
            basePath += "_full.dmp";
            return(basePath);
        }
Ejemplo n.º 4
0
        private string BuildDumpName(GCMode gcmode, bool full)
        {
            string filename = Path.Combine(Path.GetDirectoryName(Executable), Path.GetFileNameWithoutExtension(Executable));

            string gc       = gcmode == GCMode.Server ? "svr" : "wks";
            string dumpType = full ? "" : "_mini";

            filename = $"{filename}_{gc}{dumpType}.dmp";
            return(filename);
        }
Ejemplo n.º 5
0
        public DataTarget LoadMiniDump(GCMode gc = GCMode.Workstation)
        {
            string path = GetMiniDumpName(Executable, gc);
            if (File.Exists(path))
                return DataTarget.LoadCrashDump(path);

            WriteCrashDumps(gc);

            return DataTarget.LoadCrashDump(_miniDumpPath[(int)gc]);
        }
Ejemplo n.º 6
0
        public DataTarget LoadMiniDump(GCMode gc = GCMode.Workstation)
        {
            string path = GetMiniDumpName(Executable, gc);

            if (File.Exists(path))
            {
                return(DataTarget.LoadCrashDump(path));
            }

            WriteCrashDumps(gc);

            return(DataTarget.LoadCrashDump(_miniDumpPath[(int)gc]));
        }
Ejemplo n.º 7
0
        private void WriteDumps(Debugger dbg, string exe, GCMode gc)
        {
            string dump = GetMiniDumpName(exe, gc);

            dbg.WriteDumpFile(dump, DEBUG_DUMP.SMALL);
            _miniDumpPath[(int)gc] = dump;

            dump = GetFullDumpName(exe, gc);
            dbg.WriteDumpFile(dump, DEBUG_DUMP.DEFAULT);
            _fullDumpPath[(int)gc] = dump;

            dbg.TerminateProcess();
        }
Ejemplo n.º 8
0
        public DataTarget LoadFullDumpWithDbgEng(GCMode gc = GCMode.Workstation)
        {
            Guid guid = DebugClient.IID_IDebugClient;
            int  hr   = DebugCreate(guid, out IntPtr pDebugClient);

            if (hr != 0)
            {
                throw new Exception($"Failed to create DebugClient, hr={hr:x}.");
            }

            RefCountedFreeLibrary library = new RefCountedFreeLibrary(IntPtr.Zero);

            Marshal.AddRef(pDebugClient);
            Marshal.AddRef(pDebugClient);
            DebugSystemObjects sys     = new DebugSystemObjects(library, pDebugClient);
            DebugClient        client  = new DebugClient(library, pDebugClient, sys);
            DebugControl       control = new DebugControl(library, pDebugClient, sys);

            string dumpPath = BuildDumpName(gc, true);

            hr = client.OpenDumpFile(dumpPath);
            if (hr != 0)
            {
                throw new Exception($"Failed to OpenDumpFile, hr={hr:x}.");
            }

            hr = control.WaitForEvent(10000);

            if (hr != 0)
            {
                throw new Exception($"Failed to attach to dump file, hr={hr:x}.");
            }

            Marshal.Release(pDebugClient);
            return(DataTarget.CreateFromDbgEng(pDebugClient));
        }
Ejemplo n.º 9
0
        public DataTarget LoadFullDump(GCMode gc = GCMode.Workstation)
        {
            string path = BuildDumpName(gc, full: true);

            return(DataTarget.LoadCrashDump(path));
        }
Ejemplo n.º 10
0
 private static string GetFullDumpName(string executable, GCMode gc)
 {
     string basePath = Path.Combine(Path.GetDirectoryName(executable), Path.GetFileNameWithoutExtension(executable));
     basePath += gc == GCMode.Workstation ? "_wks" : "_svr";
     basePath += "_full.dmp";
     return basePath;
 }
Ejemplo n.º 11
0
        private void WriteDumps(Debugger dbg, string exe, GCMode gc)
        {
            string dump = GetMiniDumpName(exe, gc);
            dbg.WriteDumpFile(dump, DEBUG_DUMP.SMALL);
            _miniDumpPath[(int)gc] = dump;

            dump = GetFullDumpName(exe, gc);
            dbg.WriteDumpFile(dump, DEBUG_DUMP.DEFAULT);
            _fullDumpPath[(int)gc] = dump;

            dbg.TerminateProcess();
        }
Ejemplo n.º 12
0
        private void WriteCrashDumps(GCMode gc)
        {
            if (_fullDumpPath[(int)gc] != null)
                return;

            string executable = Executable;
            DebuggerStartInfo info = new DebuggerStartInfo();
            if (gc == GCMode.Server)
                info.SetEnvironmentVariable("COMPlus_BuildFlavor", "svr");

            using (Debugger dbg = info.LaunchProcess(executable, Helpers.TestWorkingDirectory))
            {
                dbg.SecondChanceExceptionEvent += delegate (Debugger d, EXCEPTION_RECORD64 ex)
                {
                    if (ex.ExceptionCode == (uint)ExceptionTypes.Clr)
                        WriteDumps(dbg, executable, gc);
                };

                DEBUG_STATUS status;
                do
                {
                    status = dbg.ProcessEvents(0xffffffff);
                } while (status != DEBUG_STATUS.NO_DEBUGGEE);

                Assert.IsNotNull(_miniDumpPath[(int)gc]);
                Assert.IsNotNull(_fullDumpPath[(int)gc]);
            }
        }
Ejemplo n.º 13
0
 public DataTarget LoadFullDump(GCMode gc = GCMode.Workstation) => LoadDump(BuildDumpName(gc, true));
Ejemplo n.º 14
0
 public DataTarget LoadMinidump(GCMode gc = GCMode.Workstation) => LoadDump(BuildDumpName(gc, false));
Ejemplo n.º 15
0
        public DataTarget LoadMiniDump(GCMode gc = GCMode.Workstation)
        {
            string path = BuildDumpName(gc, false);

            return(DataTarget.LoadCrashDump(path));
        }