Ejemplo n.º 1
0
        public async Task <LinuxAnalyzerExitCode> AnalyzeAsync(string inputFile, string outputFile)
        {
            IFileInfo coredump = GetCoreDumpFile(inputFile);

            if (coredump == null)
            {
                return(LinuxAnalyzerExitCode.NoCoredumpFound);
            }
            Console.WriteLine($"Processing core dump file: {coredump}");

            init(coredump.FullName, coredump.Directory.FullName);

            SDResult analysisResult = new SDResult();

            analysisResult.SystemContext = new SDCDSystemContext();

            Console.WriteLine("Retrieving main executable ...");
            new ExecutablePathAnalyzer(filesystem, (SDCDSystemContext)analysisResult.SystemContext).Analyze();
            Console.WriteLine("Retrieving shared libraries ...");
            await new SharedLibAnalyzer(filesystem, coredump, analysisResult, true).AnalyzeAsync();
            if ((analysisResult?.SystemContext?.Modules?.Count ?? 0) == 0)
            {
                Console.WriteLine("No shared libraries detected. Maybe NT_FILE note is missing? Trying to retrieve libraries via GDB.");
                new GdbSharedLibAnalyzer(filesystem, processHandler, coredump, analysisResult).Analyze();
                if ((analysisResult?.SystemContext?.Modules?.Count ?? 0) == 0)
                {
                    Console.WriteLine("Could not extract libs from GDB either. Terminating because further analysis will not make sense.");
                    return(LinuxAnalyzerExitCode.NoSharedLibraries);
                }
            }
            else
            {
                Console.WriteLine($"Detected {analysisResult.SystemContext.Modules.Count} shared libraries.");
            }
            Console.WriteLine("Resolving debug symbols ...");
            new DebugSymbolResolver(filesystem, requestHandler, processHandler).Resolve(analysisResult.SystemContext.Modules);
            Console.WriteLine("Unwinding stacktraces ...");
            new UnwindAnalyzer(coredump, analysisResult).Analyze();
            Console.WriteLine("Retrieving agent version if available ...");
            new CoreLogAnalyzer(filesystem, coredump, analysisResult.SystemContext.Modules).Analyze();
            Console.WriteLine("Fetching debug symbols ...");
            new DebugSymbolAnalysis(filesystem, processHandler, analysisResult).Analyze();
            Console.WriteLine("Reading stack information ...");
            new GdbAnalyzer(filesystem, processHandler, coredump, analysisResult).Analyze();
            Console.WriteLine("Setting default fields ...");
            new DefaultFieldsSetter(analysisResult).SetResultFields();
            Console.WriteLine("Setting tags ...");
            new DynamicAnalysisBuilder(analysisResult,
                                       new UniversalTagAnalyzer(), new LinuxTagAnalyzer(), new DotNetTagAnalyzer(), new DynatraceTagAnalyzer())
            .Analyze();
            File.WriteAllText(outputFile, analysisResult.SerializeToJSON());
            Console.WriteLine("Finished coredump analysis.");
            destroy();
            return(LinuxAnalyzerExitCode.Success);
        }
Ejemplo n.º 2
0
        public async Task AnalyzeAsync(string inputFile, string outputFile)
        {
            IFileInfo coredump = GetCoreDumpFilePath(inputFile);

            if (coredump == null)
            {
                Console.WriteLine("No core dump found.");
                // TODO write empty json?
                return;
            }
            Console.WriteLine($"Processing core dump file: {coredump}");

            SDResult analysisResult = new SDResult();

            new UnwindAnalyzer(coredump, analysisResult).Analyze();
            Console.WriteLine("Retrieving shared libraries ...");
            await new SharedLibAnalyzer(filesystem, coredump, analysisResult).AnalyzeAsync();
            Console.WriteLine("Finding executable file ...");
            new ExecutablePathAnalyzer(filesystem, analysisResult.SystemContext as SDCDSystemContext).Analyze();
            Console.WriteLine("Retrieving agent version if available ...");
            new CoreLogAnalyzer(filesystem, coredump, analysisResult.SystemContext.Modules).Analyze();
            Console.WriteLine("Fetching debug symbols ...");
            new DebugSymbolResolver(filesystem, requestHandler).Resolve(analysisResult.SystemContext.Modules);
            Console.WriteLine("Resolving debug symbols ...");
            new DebugSymbolAnalysis(filesystem, processHandler, analysisResult).Analyze();
            Console.WriteLine("Reading stack information ...");
            new GdbAnalyzer(filesystem, processHandler, coredump, analysisResult).Analyze();
            Console.WriteLine("Setting default fields ...");
            new DefaultFieldsSetter(analysisResult).SetResultFields();
            Console.WriteLine("Setting tags ...");
            new DynamicAnalysisBuilder(analysisResult,
                                       new UniversalTagAnalyzer(), new LinuxTagAnalyzer(), new DotNetTagAnalyzer(), new DynatraceTagAnalyzer())
            .Analyze();
            File.WriteAllText(outputFile, analysisResult.SerializeToJSON());
            Console.WriteLine("Finished coredump analysis.");
        }