/// <summary> /// Attaches the debugger to a process if the host settings require it. /// </summary> protected void AttachDebuggerIfNeeded(IDebuggerManager debuggerManager, Process debuggedProcess) { if (HostSetup.DebuggerSetup != null) { IDebugger debugger = debuggerManager.GetDebugger(HostSetup.DebuggerSetup, Logger); if (!Debugger.IsAttached) { Logger.Log(LogSeverity.Important, "Attaching debugger to the host."); AttachDebuggerResult result = debugger.AttachToProcess(debuggedProcess); if (result == AttachDebuggerResult.Attached) { this.debugger = debugger; this.debuggedProcess = debuggedProcess; } else if (result == AttachDebuggerResult.CouldNotAttach) { Logger.Log(LogSeverity.Warning, "Could not attach debugger to the host."); } } } }
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."); } } } }