Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 1 && args[0].EndsWith(".dmp", StringComparison.InvariantCultureIgnoreCase))
                {
                    args = new[] { "launch", args[0] };
                }

                if (args.Length != 2 || (args[0] != "download" && args[0] != "launch"))
                {
                    Console.WriteLine("Usage: sosloader <download | launch> <dump file path>");
                    return;
                }

                Console.WriteLine("\nPlease make sure that you have dbghelp.dll and symsrv.dll accessible\nto the application. Otherwise, we will not be able to retrieve files\nfrom the Microsoft symbol server.\n");

                string     dumpFilePath = args[1];
                DataTarget target       = DataTarget.LoadCrashDump(dumpFilePath);
                if (target.ClrVersions.Count == 0)
                {
                    Console.WriteLine("This dump file does not have a CLR loaded in it.");
                    return;
                }
                if (target.ClrVersions.Count > 1)
                {
                    Console.WriteLine("This dump file has multiple CLR versions loaded in it.");
                    return;
                }

                if (target.Architecture == Architecture.X86 && IntPtr.Size != 4)
                {
                    Console.WriteLine("Please use the 32 bit version of sosloader to analyze this dump.");
                    return;
                }
                if (target.Architecture == Architecture.Amd64 && IntPtr.Size != 8)
                {
                    Console.WriteLine("Please use the 64 bit version of sosloader to analyze this dump.");
                    return;
                }

                string dacLocation = target.ClrVersions[0].LocalMatchingDac;
                if (!String.IsNullOrEmpty(dacLocation))
                {
                    Console.WriteLine();
                    Console.WriteLine($"dacLocation: {dacLocation}");
                    Console.WriteLine("The debug support files are available on the local machine.");
                    if (args[0] == "launch")
                    {
                        Console.WriteLine("Launching windbg.exe with the provided dump file...");
                        var loadByCommand = ".loadby sos " + (target.ClrVersions[0].Version.Major == 4 ? "clr" : "mscorwks");

                        StartWinDbg($"-z {dumpFilePath} -c \"{loadByCommand}\"");
                    }
                    return;
                }

                string debugSupportFilesLocation = DacLocator.GetDebugSupportFiles(target.ClrVersions[0], target);
                if (args[0] == "launch")
                {
                    Console.WriteLine("Launching windbg.exe with the provided dump file (must be in path)...");
                    var loadCommand = String.Format(".load {0}; .cordll -se -lp {1}",
                                                    Path.Combine(debugSupportFilesLocation, "sos"), debugSupportFilesLocation);

                    StartWinDbg($"-z {dumpFilePath} -c \"{loadCommand}\"");
                }
                else
                {
                    Console.WriteLine("Debug support files are now available in " + debugSupportFilesLocation);
                    Console.WriteLine("Use .load <location>\\sos to load SOS and .cordll -se -lp <location> to set up DAC");
                }
            }
            finally
            {
                Console.WriteLine("press any key to pause");
                Thread.Sleep(5000);
                if (Console.KeyAvailable)
                {
                    Console.WriteLine("|| paused ||");
                    Thread.Sleep(1000000);
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length != 2 || (args[0] != "download" && args[0] != "launch"))
            {
                Console.WriteLine("Usage: sosloader <download | launch> <dump file path>");
                return;
            }

            Console.WriteLine("\nPlease make sure that you have dbghelp.dll and symsrv.dll accessible\nto the application. Otherwise, we will not be able to retrieve files\nfrom the Microsoft symbol server.\n");

            string     dumpFilePath = args[1];
            DataTarget target       = DataTarget.LoadCrashDump(dumpFilePath);

            if (target.ClrVersions.Count == 0)
            {
                Console.WriteLine("This dump file does not have a CLR loaded in it.");
                return;
            }
            if (target.ClrVersions.Count > 1)
            {
                Console.WriteLine("This dump file has multiple CLR versions loaded in it.");
                return;
            }

            if (target.Architecture == Architecture.X86 && IntPtr.Size != 4)
            {
                Console.WriteLine("Please use the 32 bit version of sosloader to analyze this dump.");
                return;
            }
            if (target.Architecture == Architecture.Amd64 && IntPtr.Size != 8)
            {
                Console.WriteLine("Please use the 64 bit version of sosloader to analyze this dump.");
                return;
            }

            string dacLocation = target.ClrVersions[0].TryGetDacLocation();

            if (!String.IsNullOrEmpty(dacLocation))
            {
                //No symbol load needed, the files are available on the local machine
                Console.WriteLine("The debug support files are available on the local machine.");
                if (args[0] == "launch")
                {
                    Console.WriteLine("Launching windbg.exe with the provided dump file...");
                    string loadByCommand = ".loadby sos " + (target.ClrVersions[0].Version.Major == 4 ? "clr" : "mscorwks");
                    Process.Start("windbg.exe", String.Format("-z {0} -c \"{1}\"", dumpFilePath, loadByCommand));
                }
                return;
            }

            string debugSupportFilesLocation = DacLocator.GetDebugSupportFiles(target.ClrVersions[0], target);

            if (args[0] == "launch")
            {
                Console.WriteLine("Launching windbg.exe with the provided dump file...");
                string loadCommand = String.Format(".load {0}; .cordll -se -lp {1}",
                                                   Path.Combine(debugSupportFilesLocation, "sos"), debugSupportFilesLocation);
                Process.Start("windbg.exe", String.Format("-z {0} -c \"{1}\"", dumpFilePath, loadCommand));
            }
            else
            {
                Console.WriteLine("Debug support files are now available in " + debugSupportFilesLocation);
                Console.WriteLine("Use .load <location>\\sos to load SOS and .cordll -se -lp <location> to set up DAC");
            }
        }