示例#1
0
        private static void SetupCLRRuntime()
        {
            // for .NET specific
            try {
                string dac = null;
                context.DacLocation = dac;
                context.Runtime     = target.CreateRuntime(ref dac);
                context.WriteInfo("created runtime with version " + context.Runtime.ClrInfo.Version);
                context.Heap = context.Runtime.GetHeap();
            } catch (FileNotFoundException ex) {
                context.WriteError("The right dac file could not be found.");
                context.WriteLine(ex.Message);
                context.WriteLine(ex.StackTrace);

                context.Runtime = null;
                //context.Dispose();
                //throw ex;
            } catch (Exception ex) {
                context.WriteError("Exception creating CLR Runtime");
                context.WriteError(ex.Message);
                context.WriteLine(ex.StackTrace);
            }
        }
示例#2
0
        public int Output(DEBUG_OUTPUT mask, string text)
        {
            switch (mask)
            {
            case DEBUG_OUTPUT.ERROR:
                context.WriteError(text.TrimEnd('\n', '\r'));
                break;

            case DEBUG_OUTPUT.EXTENSION_WARNING:
            case DEBUG_OUTPUT.WARNING:
                context.WriteWarning(text.TrimEnd('\n', '\r'));
                break;

            case DEBUG_OUTPUT.SYMBOLS:
                context.WriteInfo(text.TrimEnd('\n', '\r'));
                break;

            default:
                context.WriteLine(text);
                break;
            }

            return(0);
        }
示例#3
0
        private static int Main(string[] args)
        {
            if (Environment.Is64BitProcess)
            {
                Environment.SetEnvironmentVariable("_NT_DEBUGGER_EXTENSION_PATH", @"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\WINXP;C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\winext;C:\Program Files (x86)\Windows Kits\10\Debuggers\x64;");
            }
            else
            {
                Environment.SetEnvironmentVariable("_NT_DEBUGGER_EXTENSION_PATH", @"C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\WINXP;C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\winext;C:\Program Files (x86)\Windows Kits\10\Debuggers\x86;");
            }
            using (context = new DumpContext()) {
                Console.WriteLine("SuperDump - Windows dump analysis tool");
                Console.WriteLine("--------------------------");
                //check if symbol path is set
                if (string.IsNullOrEmpty(SYMBOL_PATH))
                {
                    Console.WriteLine("WARNING: Environment variable _NT_SYMBOL_PATH is not set!");
                }

                if (args.Length < 1)
                {
                    Console.WriteLine("no dump file was specified! Please enter dump path: ");
                    DUMP_LOC = Console.ReadLine();
                }
                else
                {
                    DUMP_LOC = args[0];
                }

                if (args.Length < 2)
                {
                    Console.WriteLine("no output file was specified! Please enter output file: ");
                    OUTPUT_LOC = Console.ReadLine();
                }
                else
                {
                    OUTPUT_LOC = args[1];
                }

                string absoluteDumpFile = Path.GetFullPath(DUMP_LOC);
                Console.WriteLine(absoluteDumpFile);

                var logfile = new FileInfo(Path.Combine(Path.GetDirectoryName(OUTPUT_LOC), "superdump.log"));
                context.Printer = new FilePrinter(logfile.FullName);

                try {
                    if (File.Exists(absoluteDumpFile))
                    {
                        LoadDump(absoluteDumpFile);

                        // do this as early as possible, as some WinDbg commands help us get the right DAC files
                        var windbgAnalyzer = new WinDbgAnalyzer(context, Path.Combine(context.DumpDirectory, "windbg.log"));
                        windbgAnalyzer.Analyze();

                        // start analysis
                        var analysisResult = new SDResult();
                        analysisResult.IsManagedProcess = context.Target.ClrVersions.Count > 0;

                        if (analysisResult.IsManagedProcess)
                        {
                            SetupCLRRuntime();
                        }

                        var sysInfo = new SystemAnalyzer(context);
                        analysisResult.SystemContext = sysInfo.systemInfo;

                        var exceptionAnalyzer = new ExceptionAnalyzer(context, analysisResult);

                        context.WriteInfo("--- Thread analysis ---");
                        ThreadAnalyzer threadAnalyzer = new ThreadAnalyzer(context);
                        analysisResult.ExceptionRecord     = threadAnalyzer.exceptions;
                        analysisResult.ThreadInformation   = threadAnalyzer.threads;
                        analysisResult.DeadlockInformation = threadAnalyzer.deadlocks;
                        analysisResult.LastExecutedThread  = threadAnalyzer.GetLastExecutedThreadOSId();
                        context.WriteInfo("Last executed thread (engine id): " + threadAnalyzer.GetLastExecutedThreadEngineId().ToString());

                        var analyzer = new MemoryAnalyzer(context);
                        analysisResult.MemoryInformation = analyzer.memDict;
                        analysisResult.BlockingObjects   = analyzer.blockingObjects;

                        // this analyzer runs after all others to put tags onto taggableitems
                        var tagAnalyzer = new TagAnalyzer(analysisResult);
                        tagAnalyzer.Analyze();

                        //get non loaded symbols
                        List <string> notLoadedSymbols = new List <string>();
                        foreach (var item in sysInfo.systemInfo.Modules)
                        {
                            if (item.PdbInfo == null || string.IsNullOrEmpty(item.PdbInfo.FileName) || string.IsNullOrEmpty(item.PdbInfo.Guid))
                            {
                                notLoadedSymbols.Add(item.FileName);
                            }
                        }
                        analysisResult.NotLoadedSymbols = notLoadedSymbols;

                        // print to log
                        sysInfo.PrintArchitecture();
                        sysInfo.PrintCLRVersions();
                        sysInfo.PrintAppDomains();
                        sysInfo.PrintModuleList();
                        threadAnalyzer.PrintManagedExceptions();
                        threadAnalyzer.PrintCompleteStackTrace();
                        analyzer.PrintExceptionsObjects();

                        // write to json
                        analysisResult.WriteResultToJSONFile(OUTPUT_LOC);

                        context.WriteInfo("--- End of output ---");
                        Console.WriteLine("done.");
                    }
                    else
                    {
                        throw new FileNotFoundException("File can not be found!");
                    }
                } catch (Exception e) {
                    context.WriteError($"Exception happened: {e}");
                    return(1);
                }
            }
            return(0);
        }