Esempio n. 1
0
        public async Task <int> Analyze(FileInfo dump_path, string[] command)
        {
            _consoleProvider.Out.WriteLine($"Loading core dump: {dump_path} ...");

            DataTarget target = null;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                target = DataTarget.LoadCoreDump(dump_path.FullName);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                target = DataTarget.LoadCrashDump(dump_path.FullName, CrashDumpReader.ClrMD);
            }
            else
            {
                _consoleProvider.Error.WriteLine($"{RuntimeInformation.OSDescription} not supported");
                return(1);
            }

            using (target)
            {
                // Create common analyze context for commands
                var analyzeContext = new AnalyzeContext(_consoleProvider, target, _consoleProvider.Stop)
                {
                    CurrentThreadId = unchecked ((int)target.DataReader.EnumerateAllThreads().FirstOrDefault())
                };
                _commandProcessor.CommandContext = analyzeContext;

                // Automatically enable symbol server support on Linux and MacOS
                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    await _commandProcessor.Parse("setsymbolserver -ms", _consoleProvider);
                }

                // Run the commands from the dotnet-dump command line
                if (command != null)
                {
                    foreach (string cmd in command)
                    {
                        await _commandProcessor.Parse(cmd, _consoleProvider);
                    }
                }

                // Start interactive command line processing
                await _consoleProvider.Start(async (string commandLine, CancellationToken cancellation) => {
                    analyzeContext.CancellationToken = cancellation;
                    await _commandProcessor.Parse(commandLine, _consoleProvider);
                });
            }

            return(0);
        }
Esempio n. 2
0
        public async Task <int> Analyze(FileInfo dump_path, string[] command)
        {
            _consoleProvider.WriteLine($"Loading core dump: {dump_path} ...");

            try
            {
                DataTarget target = null;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    target = DataTarget.LoadCoreDump(dump_path.FullName);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    try
                    {
                        target = DataTarget.LoadCoreDump(dump_path.FullName);
                    }
                    catch (InvalidDataException)
                    {
                        // This condition occurs when we try to load a Windows dump as a Elf core dump.
                    }

                    if (target == null)
                    {
                        target = DataTarget.LoadCrashDump(dump_path.FullName, CrashDumpReader.ClrMD);
                    }
                }
                else
                {
                    throw new PlatformNotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}");
                }

                using (target)
                {
                    _consoleProvider.WriteLine("Ready to process analysis commands. Type 'help' to list available commands or 'help [command]' to get detailed help on a command.");
                    _consoleProvider.WriteLine("Type 'quit' or 'exit' to exit the session.");

                    // Add all the services needed by commands and other services
                    AddServices(target);

                    // Automatically enable symbol server support
                    SymbolReader.InitializeSymbolStore(
                        logging: false,
                        msdl: true,
                        symweb: false,
                        tempDirectory: null,
                        symbolServerPath: null,
                        timeoutInMinutes: 0,
                        symbolCachePath: null,
                        symbolDirectoryPath: null,
                        windowsSymbolPath: null);

                    // Run the commands from the dotnet-dump command line
                    if (command != null)
                    {
                        foreach (string cmd in command)
                        {
                            await _commandProcessor.Parse(cmd);

                            if (_consoleProvider.Shutdown)
                            {
                                break;
                            }
                        }
                    }

                    // Start interactive command line processing
                    var analyzeContext = _serviceProvider.GetService <AnalyzeContext>();
                    await _consoleProvider.Start(async (string commandLine, CancellationToken cancellation) => {
                        analyzeContext.CancellationToken = cancellation;
                        await _commandProcessor.Parse(commandLine);
                    });
                }
            }
            catch (Exception ex) when
                (ex is ClrDiagnosticsException ||
                ex is FileNotFoundException ||
                ex is DirectoryNotFoundException ||
                ex is UnauthorizedAccessException ||
                ex is PlatformNotSupportedException ||
                ex is InvalidDataException ||
                ex is InvalidOperationException ||
                ex is NotSupportedException)
            {
                _consoleProvider.WriteLine(OutputType.Error, $"{ex.Message}");
                return(1);
            }

            return(0);
        }
Esempio n. 3
0
        public async Task<int> Analyze(FileInfo dump_path, string[] command)
        {
            _consoleProvider.WriteLine($"Loading core dump: {dump_path} ...");

            try
            { 
                using (DataTarget target = DataTarget.LoadDump(dump_path.FullName))
                {
                    _consoleProvider.WriteLine("Ready to process analysis commands. Type 'help' to list available commands or 'help [command]' to get detailed help on a command.");
                    _consoleProvider.WriteLine("Type 'quit' or 'exit' to exit the session.");

                    // Add all the services needed by commands and other services
                    AddServices(target);

                    // Set the default symbol cache to match Visual Studio's when running on Windows
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
                        SymbolReader.DefaultSymbolCache = Path.Combine(Path.GetTempPath(), "SymbolCache");
                    }

                    // Automatically enable symbol server support
                    SymbolReader.InitializeSymbolStore(
                        logging: false, 
                        msdl: true,
                        symweb: false,
                        tempDirectory: null,
                        symbolServerPath: null,
                        authToken: null,
                        timeoutInMinutes: 0,
                        symbolCachePath: null,
                        symbolDirectoryPath: null,
                        windowsSymbolPath: null);

                    target.BinaryLocator = new BinaryLocator();

                    // Run the commands from the dotnet-dump command line
                    if (command != null)
                    {
                        foreach (string cmd in command)
                        {
                            await _commandProcessor.Parse(cmd);

                            if (_consoleProvider.Shutdown)
                                break;
                        }
                    }

                    // Start interactive command line processing
                    var analyzeContext = _serviceProvider.GetService<AnalyzeContext>();
                    await _consoleProvider.Start(async (string commandLine, CancellationToken cancellation) => {
                        analyzeContext.CancellationToken = cancellation;
                        await _commandProcessor.Parse(commandLine);
                    });
                }
            }
            catch (Exception ex) when 
                (ex is ClrDiagnosticsException ||
                 ex is FileNotFoundException || 
                 ex is DirectoryNotFoundException || 
                 ex is UnauthorizedAccessException || 
                 ex is PlatformNotSupportedException || 
                 ex is UnsupportedCommandException ||
                 ex is InvalidDataException ||
                 ex is InvalidOperationException ||
                 ex is NotSupportedException)
            {
                _consoleProvider.WriteLine(OutputType.Error, $"{ex.Message}");
                return 1;
            }

            return 0;
        }
Esempio n. 4
0
        public Task <int> Analyze(FileInfo dump_path, string[] command)
        {
            _consoleProvider.WriteLine($"Loading core dump: {dump_path} ...");

            // Attempt to load the persisted command history
            string dotnetHome;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                dotnetHome = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), ".dotnet");
            }
            else
            {
                dotnetHome = Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".dotnet");
            }
            string historyFileName = Path.Combine(dotnetHome, "dotnet-dump.history");

            try
            {
                string[] history = File.ReadAllLines(historyFileName);
                _consoleProvider.AddCommandHistory(history);
            }
            catch (Exception ex) when
                (ex is IOException ||
                ex is UnauthorizedAccessException ||
                ex is NotSupportedException ||
                ex is SecurityException)
            {
            }

            try
            {
                using DataTarget dataTarget = DataTarget.LoadDump(dump_path.FullName);

                OSPlatform targetPlatform = dataTarget.DataReader.TargetPlatform;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || dataTarget.DataReader.EnumerateModules().Any((module) => Path.GetExtension(module.FileName) == ".dylib"))
                {
                    targetPlatform = OSPlatform.OSX;
                }
                _target = new TargetFromDataReader(dataTarget.DataReader, targetPlatform, this, _targetIdFactory++, dump_path.FullName);
                _contextService.SetCurrentTarget(_target);

                _target.ServiceProvider.AddServiceFactory <SOSHost>(() => new SOSHost(_contextService.Services));

                // Automatically enable symbol server support
                _symbolService.AddSymbolServer(msdl: true, symweb: false, symbolServerPath: null, authToken: null, timeoutInMinutes: 0);
                _symbolService.AddCachePath(_symbolService.DefaultSymbolCache);

                // Run the commands from the dotnet-dump command line
                if (command != null)
                {
                    foreach (string cmd in command)
                    {
                        _commandProcessor.Execute(cmd, _contextService.Services);
                        if (_consoleProvider.Shutdown)
                        {
                            break;
                        }
                    }
                }
                if (!_consoleProvider.Shutdown && (!Console.IsOutputRedirected || Console.IsInputRedirected))
                {
                    // Start interactive command line processing
                    _consoleProvider.WriteLine("Ready to process analysis commands. Type 'help' to list available commands or 'help [command]' to get detailed help on a command.");
                    _consoleProvider.WriteLine("Type 'quit' or 'exit' to exit the session.");

                    _consoleProvider.Start((string commandLine, CancellationToken cancellation) => {
                        _commandProcessor.Execute(commandLine, _contextService.Services);
                    });
                }
            }
            catch (Exception ex) when
                (ex is ClrDiagnosticsException ||
                ex is FileNotFoundException ||
                ex is DirectoryNotFoundException ||
                ex is UnauthorizedAccessException ||
                ex is PlatformNotSupportedException ||
                ex is InvalidDataException ||
                ex is InvalidOperationException ||
                ex is NotSupportedException)
            {
                _consoleProvider.WriteLine(OutputType.Error, $"{ex.Message}");
                return(Task.FromResult(1));
            }
            finally
            {
                if (_target != null)
                {
                    DestroyTarget(_target);
                }
                // Persist the current command history
                try
                {
                    File.WriteAllLines(historyFileName, _consoleProvider.GetCommandHistory());
                }
                catch (Exception ex) when
                    (ex is IOException ||
                    ex is UnauthorizedAccessException ||
                    ex is NotSupportedException ||
                    ex is SecurityException)
                {
                }
                // Send shutdown event on exit
                OnShutdownEvent.Fire();
            }
            return(Task.FromResult(0));
        }
Esempio n. 5
0
        public async Task <int> Analyze(FileInfo dump_path, string[] command)
        {
            _consoleProvider.Out.WriteLine($"Loading core dump: {dump_path} ...");

            try
            {
                DataTarget target = null;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    target = DataTarget.LoadCoreDump(dump_path.FullName);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    target = DataTarget.LoadCrashDump(dump_path.FullName, CrashDumpReader.ClrMD);
                }
                else
                {
                    throw new PlatformNotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}");
                }

                using (target)
                {
                    _consoleProvider.Out.WriteLine("Ready to process analysis commands. Type 'help' to list available commands or 'help [command]' to get detailed help on a command.");
                    _consoleProvider.Out.WriteLine("Type 'quit' or 'exit' to exit the session.");

                    // Create common analyze context for commands
                    var analyzeContext = new AnalyzeContext(_consoleProvider, target)
                    {
                        CurrentThreadId = unchecked ((int)target.DataReader.EnumerateAllThreads().FirstOrDefault())
                    };
                    _commandProcessor.AddService(analyzeContext);

                    // Automatically enable symbol server support on Linux and MacOS
                    //if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        SymbolReader.InitializeSymbolStore(logging: false, msdl: true, symweb: false, symbolServerPath: null, symbolCachePath: null, windowsSymbolPath: null);
                    }

                    // Run the commands from the dotnet-dump command line
                    if (command != null)
                    {
                        foreach (string cmd in command)
                        {
                            await _commandProcessor.Parse(cmd);
                        }
                    }

                    // Start interactive command line processing
                    await _consoleProvider.Start(async (string commandLine, CancellationToken cancellation) => {
                        analyzeContext.CancellationToken = cancellation;
                        await _commandProcessor.Parse(commandLine);
                    });
                }
            }
            catch (Exception ex) when
                (ex is ClrDiagnosticsException ||
                ex is FileNotFoundException ||
                ex is DirectoryNotFoundException ||
                ex is UnauthorizedAccessException ||
                ex is PlatformNotSupportedException ||
                ex is InvalidDataException ||
                ex is InvalidOperationException ||
                ex is NotSupportedException)
            {
                _consoleProvider.Error.WriteLine($"{ex.Message}");
                return(1);
            }

            return(0);
        }
Esempio n. 6
0
        public Task <int> Analyze(FileInfo dump_path, string[] command)
        {
            _consoleProvider.WriteLine($"Loading core dump: {dump_path} ...");

            try
            {
                using DataTarget dataTarget = DataTarget.LoadDump(dump_path.FullName);

                OSPlatform targetPlatform = dataTarget.DataReader.TargetPlatform;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    targetPlatform = OSPlatform.OSX;
                }
                _target = new TargetFromDataReader(dataTarget.DataReader, targetPlatform, this, dump_path.FullName);

                _target.ServiceProvider.AddServiceFactory <SOSHost>(() => {
                    var sosHost = new SOSHost(_target);
                    sosHost.InitializeSOSHost();
                    return(sosHost);
                });

                // Set the default symbol cache to match Visual Studio's when running on Windows
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    _symbolService.DefaultSymbolCache = Path.Combine(Path.GetTempPath(), "SymbolCache");
                }
                // Automatically enable symbol server support
                _symbolService.AddSymbolServer(msdl: true, symweb: false, symbolServerPath: null, authToken: null, timeoutInMinutes: 0);
                _symbolService.AddCachePath(_symbolService.DefaultSymbolCache);

                // Run the commands from the dotnet-dump command line
                if (command != null)
                {
                    foreach (string cmd in command)
                    {
                        Parse(cmd);

                        if (_consoleProvider.Shutdown)
                        {
                            break;
                        }
                    }
                }
                if (!_consoleProvider.Shutdown)
                {
                    // Start interactive command line processing
                    _consoleProvider.WriteLine("Ready to process analysis commands. Type 'help' to list available commands or 'help [command]' to get detailed help on a command.");
                    _consoleProvider.WriteLine("Type 'quit' or 'exit' to exit the session.");

                    _consoleProvider.Start((string commandLine, CancellationToken cancellation) => {
                        Parse(commandLine);
                    });
                }
            }
            catch (Exception ex) when
                (ex is ClrDiagnosticsException ||
                ex is FileNotFoundException ||
                ex is DirectoryNotFoundException ||
                ex is UnauthorizedAccessException ||
                ex is PlatformNotSupportedException ||
                ex is InvalidDataException ||
                ex is InvalidOperationException ||
                ex is NotSupportedException)
            {
                _consoleProvider.WriteLine(OutputType.Error, $"{ex.Message}");
                return(Task.FromResult(1));
            }
            finally
            {
                if (_target != null)
                {
                    _target.Close();
                    _target = null;
                }
                // Send shutdown event on exit
                OnShutdownEvent?.Invoke(this, new EventArgs());
            }
            return(Task.FromResult(0));
        }