From 9b67631e5599fe0a03fb2b26ee7969a67023c53b Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 10 May 2014 20:12:12 +0200 Subject: [PATCH] Debugger: During callback processing, handle the COMException "Process was terminated. (Exception from HRESULT: 0x80131301)". The exception occurs if a process is killed (e.g. console window of console application closed) while the application is doing something involving debugger callbacks (Debug.WriteLine calls, or throwing+handling exceptions). --- src/AddIns/Debugger/Debugger.Core/Process.cs | 30 +++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.Core/Process.cs b/src/AddIns/Debugger/Debugger.Core/Process.cs index 542bb4a480..6ebdeee737 100644 --- a/src/AddIns/Debugger/Debugger.Core/Process.cs +++ b/src/AddIns/Debugger/Debugger.Core/Process.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using ICSharpCode.NRefactory.TypeSystem; using Debugger.Interop.CorDebug; using Debugger.Interop.CorSym; @@ -480,17 +481,26 @@ namespace Debugger { AssertPaused(); - if (threadToRun != null) { - corProcess.SetAllThreadsDebugState(CorDebugThreadState.THREAD_SUSPEND, null); - threadToRun.CorThread.SetDebugState(CorDebugThreadState.THREAD_RUN); - } else { - corProcess.SetAllThreadsDebugState(CorDebugThreadState.THREAD_RUN, null); - } - - NotifyResumed(action); - corProcess.Continue(0); - // this.TraceMessage("Continue"); + try { + if (threadToRun != null) { + corProcess.SetAllThreadsDebugState(CorDebugThreadState.THREAD_SUSPEND, null); + threadToRun.CorThread.SetDebugState(CorDebugThreadState.THREAD_RUN); + } else { + corProcess.SetAllThreadsDebugState(CorDebugThreadState.THREAD_RUN, null); + } + NotifyResumed(action); + corProcess.Continue(0); + // this.TraceMessage("Continue"); + } catch (COMException ex) { + if (ex.HResult == unchecked((int)0x80131301)) { + // Process was terminated. (Exception from HRESULT: 0x80131301) + // This occurs if a process is killed (e.g. console window of console application closed) + // while the application is doing something involving debugger callbacks (Debug.WriteLine calls, or throwing+handling exceptions). + + // I think we can safely ignore this error. + } + } if (action == DebuggeeStateAction.Clear) { OnResumed(); }