protected override ITarget GetTarget() { _dataTarget = DataTarget.LoadDump(DumpFile); OSPlatform targetPlatform = _dataTarget.DataReader.TargetPlatform; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { targetPlatform = OSPlatform.OSX; } _symbolService.AddDirectoryPath(Path.GetDirectoryName(DumpFile)); return new TargetFromDataReader(_dataTarget.DataReader, targetPlatform, this, _targetIdFactory++, DumpFile); }
public override void Invoke() { if (MicrosoftSymbolServer && InternalSymbolServer) { throw new DiagnosticsException("Cannot have both -ms and -mi options"); } if ((MicrosoftSymbolServer || InternalSymbolServer) && !string.IsNullOrEmpty(SymbolServerUrl)) { throw new DiagnosticsException("Cannot have -ms or -mi option and a symbol server path"); } if (Disable) { SymbolService.DisableSymbolStore(); } if (Reset) { SymbolService.Reset(); } if (MicrosoftSymbolServer || InternalSymbolServer || !string.IsNullOrEmpty(SymbolServerUrl)) { if (string.IsNullOrEmpty(Cache)) { Cache = SymbolService.DefaultSymbolCache; } SymbolService.AddSymbolServer(MicrosoftSymbolServer, InternalSymbolServer, SymbolServerUrl, AccessToken, Timeout, RetryCount); } if (!string.IsNullOrEmpty(Cache)) { SymbolService.AddCachePath(Cache); } if (!string.IsNullOrEmpty(Directory)) { SymbolService.AddDirectoryPath(Directory); } if (LoadSymbols) { foreach (IModule module in ModuleService.EnumerateModules()) { if (!module.IsManaged) { Write($"Downloading symbol file for {module.FileName}"); string downloadedModulePath = module.LoadSymbols(); WriteLine(" {0}", downloadedModulePath != null ? "SUCCEEDED" : "FAILED"); } } } else { Write(SymbolService.ToString()); } }
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) { } // Load any extra extensions LoadExtensions(); 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, default cache and search for symbols in the dump directory _symbolService.AddSymbolServer(msdl: true, symweb: false, symbolServerPath: null, authToken: null, timeoutInMinutes: 0); _symbolService.AddCachePath(_symbolService.DefaultSymbolCache); _symbolService.AddDirectoryPath(Path.GetDirectoryName(dump_path.FullName)); // Run the commands from the dotnet-dump command line if (command != null) { foreach (string cmd in command) { _commandService.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) => { _commandService.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)); }