/// <inheritdoc /> public DetachDebuggerResult DetachFromProcess(Process process) { if (process == null) { throw new ArgumentNullException("process"); } DetachDebuggerResult result = DetachDebuggerResult.AlreadyDetached; try { IVisualStudio visualStudio = GetVisualStudio(false, logger); if (visualStudio != null) { visualStudio.Call(dte => { EnvDTE.Process dteProcess = FindProcess(dte.Debugger.DebuggedProcesses, process); if (dteProcess != null) { dteProcess.Detach(false); result = DetachDebuggerResult.Detached; } }); } } catch (VisualStudioException ex) { result = DetachDebuggerResult.CouldNotDetach; logger.Log(LogSeverity.Debug, "Failed to detach Visual Studio debugger from process.", ex); } return(result); }
/// <summary> /// Detaches the debugger from a process if the host settings require it. /// </summary> protected void DetachDebuggerIfNeeded() { if (debugger != null && debuggedProcess != null) { Logger.Log(LogSeverity.Important, "Detaching debugger from the host."); DetachDebuggerResult result = debugger.DetachFromProcess(debuggedProcess); if (result == DetachDebuggerResult.CouldNotDetach) { Logger.Log(LogSeverity.Warning, "Could not detach debugger from the host."); } debuggedProcess = null; debugger = null; } }
private void RunEndpointWithDebugger(ILogger logger) { Process currentProcess = Process.GetCurrentProcess(); IDebuggerManager debuggerManager = new DefaultDebuggerManager(); // FIXME: Get from IoC var debuggerSetup = new DebuggerSetup(); IDebugger debugger = debuggerManager.GetDebugger(debuggerSetup, logger); AttachDebuggerResult attachResult = AttachDebuggerResult.CouldNotAttach; try { if (!Debugger.IsAttached) { logger.Log(LogSeverity.Important, "Attaching the debugger to the host."); attachResult = debugger.AttachToProcess(currentProcess); if (attachResult == AttachDebuggerResult.CouldNotAttach) { logger.Log(LogSeverity.Warning, "Could not attach debugger to the host."); } } RunEndpoint(logger); } finally { if (attachResult == AttachDebuggerResult.Attached) { logger.Log(LogSeverity.Important, "Detaching the debugger from the host."); DetachDebuggerResult detachResult = debugger.DetachFromProcess(currentProcess); if (detachResult == DetachDebuggerResult.CouldNotDetach) { logger.Log(LogSeverity.Warning, "Could not detach debugger from the host."); } } } }