/// <summary> /// Add all the services needed by commands /// </summary> private void AddServices(DataTarget target) { _serviceProvider.AddService(target); _serviceProvider.AddService <IConsoleService>(_consoleProvider); _serviceProvider.AddService(_commandProcessor); _serviceProvider.AddServiceFactory(typeof(IHelpBuilder), _commandProcessor.CreateHelpBuilder); // Create common analyze context for commands var analyzeContext = new AnalyzeContext() { CurrentThreadId = unchecked ((int)target.DataReader.EnumerateAllThreads().FirstOrDefault()) }; _serviceProvider.AddService(analyzeContext); // Add the register, memory, SOSHost and ClrRuntime services var registerService = new RegisterService(target); _serviceProvider.AddService(registerService); var memoryService = new MemoryService(target.DataReader); _serviceProvider.AddService(memoryService); _serviceProvider.AddServiceFactory(typeof(ClrRuntime), () => CreateRuntime(target)); _serviceProvider.AddServiceFactory(typeof(SOSHost), () => { var sosHost = new SOSHost(_serviceProvider); sosHost.InitializeSOSHost(SymbolReader.TempDirectory, _isDesktop, _dacFilePath, dbiFilePath: null); return(sosHost); }); }
/// <summary> /// Add all the services needed by commands /// </summary> private void AddServices(DataTarget target) { _serviceProvider.AddService(target); _serviceProvider.AddService(target.DataReader); _serviceProvider.AddService <IConsoleService>(_consoleProvider); _serviceProvider.AddService(_commandProcessor); _serviceProvider.AddServiceFactory(typeof(IHelpBuilder), _commandProcessor.CreateHelpBuilder); if (!(target.DataReader is IThreadReader threadReader)) { throw new InvalidOperationException("IThreadReader not implemented"); } // Create common analyze context for commands var analyzeContext = new AnalyzeContext() { CurrentThreadId = threadReader.EnumerateOSThreadIds().FirstOrDefault() }; _serviceProvider.AddService(analyzeContext); // Add the thread, memory, SOSHost and ClrRuntime services var threadService = new ThreadService(target.DataReader); _serviceProvider.AddService <IThreadService>(threadService); var memoryService = new MemoryService(target.DataReader); _serviceProvider.AddService(memoryService); _serviceProvider.AddServiceFactory(typeof(ClrRuntime), () => CreateRuntime(target)); _serviceProvider.AddServiceFactory(typeof(SOSHost), () => { var sosHost = new SOSHost(_serviceProvider); sosHost.InitializeSOSHost(SymbolReader.TempDirectory, _isDesktop, _dacFilePath, dbiFilePath: null); return(sosHost); }); // ClrMD helper for extended commands _serviceProvider.AddServiceFactory(typeof(ClrMDHelper), () => new ClrMDHelper(_serviceProvider) ); }
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 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); }