Exemple #1
0
 public override void Write(IMetaWriter writer)
 {
     foreach (var result in _result)
     {
         if (result.Value.FactoryCode != null || result.Value.FactoryFactoryCode != null)
         {
             writer.WriteLine("{2}.Add<{0}>({1});", result.Key, result.Value.FactoryFactoryCode ?? result.Value.FactoryCode, typeof(TypeFactoryRegister));
         }
         else if (result.Value.Ex != null)
         {
             writer.WriteLine("#warning " + result.Value.Ex.Message);
             writer.WriteLine("/*");
             writer.WriteLine(ExceptionAnalyzer.ExceptionDetails(result.Value.Ex));
             writer.WriteLine("*/");
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// Generate code necessary to prepare registers for working with types collected
 /// </summary>
 public override void Write(IMetaWriter writer)
 {
     foreach (var kvp in _result)
     {
         if (kvp.Value.Res != null)
         {
             writer.WriteLine("{2}.Register<{0}, {1}>();", kvp.Key, kvp.Value.Res, typeof(FaceImplRegister));
         }
         else if (kvp.Value.Ex != null)
         {
             writer.WriteLine("#warning " + kvp.Value.Ex.Message);
             writer.WriteLine("/*");
             writer.WriteLine(ExceptionAnalyzer.ExceptionDetails(kvp.Value.Ex));
             writer.WriteLine("*/");
         }
     }
 }
Exemple #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);
        }
Exemple #4
0
        /// <summary>
        /// Finally write all code
        /// End your file with that line
        /// </summary>
        public static void PlasmaGenerate(this IMetaWriter writer)
        {
            #region PREPARE


            _writerTmp = writer;

            var ctx = new PlasmaContainer();

            // AssemblyAnalyzeCache.LoadAll(writer);

            AssemblyAnalyzeCache.AnalyzeImpls();

            // a set of types that is going to be asked from container
            var requests          = new HashSet <Type>(_context.Types);
            var requestsProcessed = new HashSet <Type>();

            var faceImpls = ctx.Get <FaceImplStrategy>();
            var factory   = ctx.Get <FactoryStrategy>();
            var plumbing  = ctx.Get <PlumbingStrategy>();

            var miner = ctx.Get <StaticMining>();
            miner.RequestByType += Miner_RequestByType;

            writer.WriteLine("// Analyze...");

            while (requests.Count > 0)
            {
                _requestsFromMiner.Clear();                 // not necessary - just to simplify debugging
                var fromFace  = faceImpls.GetRequests(requests).ToArray();
                var fromFact  = factory.GetRequests(requests).ToArray();
                var fromPlumb = plumbing.GetRequests(requests).ToArray();

                foreach (var request in requests)
                {
                    requestsProcessed.Add(request);
                }

                // new requests
                requests = new HashSet <Type>(fromFace.Concat(fromFact).Concat(fromPlumb).Concat(_requestsFromMiner).Except(requestsProcessed));
                writer.WriteLine("// New requests: {0}", string.Join(", ", requests.Select(x => x.CSharpTypeIdentifier())));
            }

            miner.RequestByType -= Miner_RequestByType;

            writer.WriteLine("// Analyze completed");

            #endregion

            #region Proxy

            if (_enableProxy)
            {
                foreach (var type in _context.Types.Where(x => x.IsInterface))
                {
                    _proxyGenerator.Generate(writer, type);
                    // GenerateStub(writer, type);
                }
            }

            #endregion

            #region Null

            if (_enableNullObject)
            {
                var req = _context.Types.Where(x => x.IsInterface);
                do
                {
                    foreach (var type in req.ToArray())
                    {
                        try
                        {
                            writer.Transactional(w => _nullGenerator.Generate(writer, type));
                        }
                        catch (Exception ex)
                        {
                            writer.WriteLine("#warning " + ex.Message);
                            writer.WriteLine("/*");
                            writer.WriteLine(ExceptionAnalyzer.ExceptionDetails(ex));
                            writer.WriteLine("*/");
                        }
                    }
                    req = _nullGenerator.RequestedObjects.Except(_nullGenerator.NullObjects).ToArray();
                    _nullGenerator.RequestedObjects.Clear();
                } while (req.Any());
            }

            #endregion

            writer.WriteLine(@"
public static partial class PlasmaRegistration
{{
	static volatile bool _executed;

	public static void Run({1}? reflectionPermission = null)
	{{
		if (_executed)
		{{
			return;
		}}
		_executed = true;
		{0}.DefaultReflectionPermission = reflectionPermission ?? {1}.Throw;
", typeof(PlasmaContainer), typeof(ReflectionPermission));
            writer.WriteLine();             // ignore tabs

            #region Factory

            writer.WriteLine();
            writer.WriteLine("// Factory ");

            factory.Write(writer);

            #endregion

            #region face impl

            writer.WriteLine();
            writer.WriteLine("// Iface impl");

            faceImpls.Write(writer);

            #endregion

            #region plumbers

            writer.WriteLine();
            writer.WriteLine("// Plumbers (Property injectors)");

            plumbing.Write(writer);

            #endregion

            #region null object register

            if (_enableNullObject)
            {
                foreach (var type in _nullGenerator.NullObjects.Concat(_nullGenerator.ExplicitRequests).Distinct())
                {
                    if (type.IsGenericType && type.IsGenericTypeDefinition)
                    {
                        writer.WriteLine(@"Null.RegisterGeneric(typeof({0}), t =>
	typeof ({1}).MakeGenericType(t).GetField(""Instance"").GetValue(null));"    , type.CSharpTypeIdentifier(_omitTypeDef), _nullGenerator.GetTypeName(type).FullNameGenericNoT);

                        //typeof (NullEnumerable<>).MakeGenericType(t).GetField("Instance").GetValue(null));
                    }
                    else
                    {
                        writer.WriteLine("Null.Register<{0}>({1}.Instance);", type, _nullGenerator.GetTypeName(type).FullNameGeneric);
                    }
                }
            }

            #endregion

            writer.WriteLine(@"
	}
}

");
        }