public void SystemAnalyzerModulesTest()
        {
            SystemAnalyzer analyzer = new SystemAnalyzer(context);

            Assert.IsNotNull(analyzer.systemInfo.Modules);

            // parse modules from windbg lm command
            IList <ModuleVersion> winDbgModules = ReadModules();

            // according to windbg, there must be 58 modules
            Assert.AreEqual(winDbgModules.Count, analyzer.systemInfo.Modules.Count);

            // replace special characters and underscores
            foreach (SDModule module in analyzer.systemInfo.Modules)
            {
                module.FileName = Regex.Replace(module.FileName, @"[^a-zA-Z0-9]", "");
            }

            foreach (ModuleVersion module in winDbgModules)
            {
                string moduleWithoutSpecialChars = Regex.Replace(module.name, @"[^a-zA-Z0-9]", "");

                Assert.IsNotNull(analyzer.systemInfo.Modules
                                 .FirstOrDefault(m => m.FileName.Contains(moduleWithoutSpecialChars)));
            }
        }
        public void SystemAnalyzerAppDomainTest()
        {
            SystemAnalyzer analyzer    = new SystemAnalyzer(context);
            IList <string> domainNames = ReadDomains();

            // Should include one AppDomain with name "dotNetWorld4.5.exe"
            Assert.IsNotNull(analyzer.systemInfo.AppDomains.First(domain => domain.Name.Equals("dotNetWorld4.5.exe")));

            // in this dump there should be exactly 15 app domains according to WinDbg
            Assert.AreEqual(domainNames.Count(n => n.ToLower() != "none"), analyzer.systemInfo.AppDomains.Count);

            // assert on system domain and shared domain
            Assert.IsNotNull(analyzer.systemInfo.SystemDomain);
            Assert.IsNotNull(analyzer.systemInfo.SharedDomain);
            // assert on right addresses
            Assert.AreEqual((ulong)1932093040, analyzer.systemInfo.SharedDomain.Address);
            Assert.AreEqual((ulong)1932093888, analyzer.systemInfo.SystemDomain.Address);

            // walk through "normal" app domains
            foreach (var domain in domainNames.Where(name => name.ToLower() != "none"))
            {
                // assert that for every domain in windbg log,
                // a corresponding app domain can be found in the analyzer.systemInfo.AppDomains collection
                Assert.IsNotNull(analyzer.systemInfo.AppDomains
                                 .FirstOrDefault(d => d.Name.ToLower()
                                                 .RemoveWhitespaces()
                                                 .Equals(domain.ToLower())));
            }
        }
Esempio n. 3
0
        public void DuplicateNodesAreFiltered()
        {
            SystemAnalyzer a = new SystemAnalyzer(XmlRpcMasterMock.DuplicateNodes, XmlRpcParameterClientMock.Empty);

            a.Update();

            Assert.IsTrue(a.Nodes.Any());
            CollectionAssert.AllItemsAreUnique(a.Nodes);
            Assert.AreEqual(1, a.Nodes.Count);
        }
Esempio n. 4
0
        public void EmptySystemStateReturnsEmptyGraph()
        {
            SystemAnalyzer a = new SystemAnalyzer(XmlRpcMasterMock.Empty, XmlRpcParameterClientMock.Empty);

            a.Update();

            Assert.AreEqual(0, a.Nodes.Count);
            // Assert.IsFalse(a.Services.Any());
            Assert.IsFalse(a.Topics.Any());
        }
Esempio n. 5
0
        public void EveryTopicGetItsType()
        {
            SystemAnalyzer a = new SystemAnalyzer(XmlRpcMasterMock.EveryTopicHasAType, XmlRpcParameterClientMock.Empty);

            a.Update();

            foreach (Topic t in a.Topics)
            {
                Assert.AreNotEqual("unknown", t.Type);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// When things are shutting down send the
        /// log report off to be saved to file.
        /// </summary>
        public override void OnEnd()
        {
            LogReport logReport   = new LogReport(SystemAnalyzer.GetSystemInfo(), Logger.History);
            string    logFileName = string.Format("{0}.log", DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss"));

            //Create and save the file.
            LogFile logFile = LogFileHandler.Create(logFileName, logReport);

            Task.Run(async() => { await LogFileHandler.SaveAsync(logFile); });
            Engine.Context.OnUnhandledException -= OnUnhandledException;
        }
        public void SystemAnalyzerOSVersionTest()
        {
            SystemAnalyzer analyzer = new SystemAnalyzer(context);

            Assert.IsNotNull(analyzer.systemInfo.OSVersion);

            string osVersion = ReadOSString();

            Assert.IsNotNull(osVersion);

            StringAssert.Contains(analyzer.systemInfo.OSVersion, osVersion);
        }
        public void SystemAnalyzerClrVersionsTest()
        {
            SystemAnalyzer analyzer = new SystemAnalyzer(context);

            Assert.IsNotNull(analyzer.systemInfo.Modules);

            // get mscorwks or clr out of modules, these are the interesting dlls
            IList <ModuleVersion> winDbgClrModules = ReadModules()
                                                     .Where(m => m.name.ToLower().Equals("clr.dll") ||
                                                            m.name.ToLower().Equals("mscorwks.dll"))
                                                     .ToList();

            Assert.AreEqual(winDbgClrModules.Count, analyzer.systemInfo.ClrVersions.Count);

            foreach (var module in winDbgClrModules)
            {
                Assert.IsNotNull(analyzer.systemInfo.ClrVersions.FirstOrDefault(clr => clr.Version.Contains(module.version)));
            }
        }
        public void SystemContextSerializationTest()
        {
            var analyzer = new SystemAnalyzer(this.context);

            Assert.IsNotNull(analyzer);

            string json = analyzer.SerializeSystemInfoToJSON();
            // deserialize
            SDSystemContext systemInfo = JsonConvert.DeserializeObject <SDSystemContext>(json);

            // serialize again, and then check strings
            string json2 = systemInfo.SerializeToJSON();

            // check if objects are equal, relies on correct equals implementation!
            Assert.AreEqual(analyzer.systemInfo, systemInfo);

            // check json before serializing and after deserializing
            StringAssert.Equals(json, json2);
        }
        public void ClrVersionsSerializationTest()
        {
            SystemAnalyzer      analyzer = new SystemAnalyzer(this.context);
            List <SDClrVersion> versions = new List <SDClrVersion>();

            foreach (SDClrVersion versionBefore in analyzer.systemInfo.ClrVersions)
            {
                string json = versionBefore.SerializeToJSON();

                SDClrVersion versionAfter = JsonConvert.DeserializeObject <SDClrVersion>(json);
                versions.Add(versionAfter);
                Assert.AreEqual(versionBefore, versionAfter);

                // serialize again and check version
                string jsonAfter = versionAfter.SerializeToJSON();
                StringAssert.Equals(json, jsonAfter);
            }

            Assert.IsTrue(Enumerable.SequenceEqual(analyzer.systemInfo.ClrVersions, versions));
        }
        public void AppDomainSerializationTest()
        {
            SystemAnalyzer     analyzer = new SystemAnalyzer(this.context);
            List <SDAppDomain> domains  = new List <SDAppDomain>();

            foreach (SDAppDomain domainBefore in analyzer.systemInfo.AppDomains)
            {
                string json = domainBefore.SerializeToJSON();
                // deserialize domain
                SDAppDomain domainAfter = JsonConvert.DeserializeObject <SDAppDomain>(json);
                domains.Add(domainAfter);
                // assert
                Assert.AreEqual(domainBefore, domainAfter);

                // serialize again and check
                string jsonAfter = domainAfter.SerializeToJSON();
                StringAssert.Equals(json, jsonAfter);
            }

            // extra assert on collection, assume order stays the same after deserialization
            Assert.IsTrue(Enumerable.SequenceEqual(domains, analyzer.systemInfo.AppDomains));
        }
        public void ModuleSerializationTest()
        {
            SystemAnalyzer  analyzer = new SystemAnalyzer(this.context);
            List <SDModule> modules  = new List <SDModule>();

            foreach (SDModule moduleBefore in analyzer.systemInfo.Modules)
            {
                string json = moduleBefore.SerializeToJSON();

                // deserialize module
                SDModule moduleAfter = JsonConvert.DeserializeObject <SDModule>(json);
                modules.Add(moduleAfter);

                // assert
                Assert.AreEqual(moduleBefore, moduleAfter);

                // serialize again and check
                string jsonAfter = moduleAfter.SerializeToJSON();
                StringAssert.Equals(json, jsonAfter);
            }

            Assert.IsTrue(Enumerable.SequenceEqual(analyzer.systemInfo.Modules, modules));
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
 /// <summary>
 /// Initialize a new log module for use.
 /// <paramref name="engine">The engine that owns the module.</paramref>
 /// </summary>
 /// <param name="engine">The parent game engine.</param>
 public LogModule(GameEngine engine) : base(engine)
 {
     Logger         = engine.GetService <ILogger>();
     SystemAnalyzer = new SystemAnalyzer();
     LogFileHandler = new LogFileHandler();
 }