Ejemplo n.º 1
0
 static bool CollectCrashDump(Process process, string path)
 {
     using (var crashDump = File.OpenWrite(path))
     {
         var flags = DbgHelp.MiniDumpType.MiniDumpWithFullMemory | DbgHelp.MiniDumpType.MiniDumpIgnoreInaccessibleMemory;
         return(DbgHelp.MiniDumpWriteDump(process.Handle, process.Id, crashDump.SafeFileHandle, flags, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
     }
 }
Ejemplo n.º 2
0
        static bool CollectCrashDump(Process process, string path)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                using (var crashDump = File.OpenWrite(path))
                {
                    var flags = DbgHelp.MiniDumpType.MiniDumpWithFullMemory | DbgHelp.MiniDumpType.MiniDumpIgnoreInaccessibleMemory;
                    return(DbgHelp.MiniDumpWriteDump(process.Handle, process.Id, crashDump.SafeFileHandle, flags, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
                }
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                string           coreRoot       = Environment.GetEnvironmentVariable("CORE_ROOT");
                ProcessStartInfo createdumpInfo = new ProcessStartInfo("sudo");
                createdumpInfo.Arguments = $"{Path.Combine(coreRoot, "createdump")} --name \"{path}\" {process.Id} -h";
                Process createdump = Process.Start(createdumpInfo);
                return(createdump.WaitForExit(DEFAULT_TIMEOUT) && createdump.ExitCode == 0);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                int pid = process.Id;
                Console.WriteLine($"Aborting process {pid} to generate dump");
                int status = libSystem.kill(pid, libSystem.SIGABRT);

                string defaultCoreDumpPath = $"/cores/core.{pid}";

                if (status == 0 && File.Exists(defaultCoreDumpPath))
                {
                    Console.WriteLine($"Moving dump for {pid} to {path}.");
                    File.Move(defaultCoreDumpPath, path, true);
                }
                else
                {
                    Console.WriteLine($"Unable to find OS-generated dump for {pid} at default path: {defaultCoreDumpPath}");
                }
                return(true);
            }

            return(false);
        }