Пример #1
0
        /// <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;
            }
        }
Пример #2
0
        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.");
                    }
                }
            }
        }