Skip to content

Commit 29b6a90

Browse files
committed
Handle exceptions in AbortImpl() (Moved from MD repo)
1 parent ae0eb0f commit 29b6a90

File tree

1 file changed

+37
-18
lines changed

1 file changed

+37
-18
lines changed

Mono.Debugging.Win32/CorMethodCall.cs

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Threading.Tasks;
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using System.Threading.Tasks;
24
using Microsoft.Samples.Debugging.CorDebug;
35
using Microsoft.Samples.Debugging.CorDebug.NativeApi;
46
using Mono.Debugging.Client;
@@ -100,24 +102,41 @@ protected override Task<OperationResult<CorValue>> InvokeAsyncImpl ()
100102

101103
protected override void AbortImpl (int abortCallTimes)
102104
{
103-
if (abortCallTimes < 10) {
104-
DebuggerLoggingService.LogMessage ("Calling Abort() for {0} time", abortCallTimes);
105-
eval.Abort ();
106-
}
107-
else {
108-
if (abortCallTimes == 20) {
109-
// if Abort() and RudeAbort() didn't bring any result let's try to resume all the threads to free possible deadlocks in target process
110-
// maybe this can help to abort hanging evaluations
111-
DebuggerLoggingService.LogMessage ("RudeAbort() didn't stop eval after {0} times", abortCallTimes - 1);
112-
DebuggerLoggingService.LogMessage ("Calling Stop()");
113-
context.Session.Process.Stop (0);
114-
DebuggerLoggingService.LogMessage ("Calling SetAllThreadsDebugState(THREAD_RUN)");
115-
context.Session.Process.SetAllThreadsDebugState (CorDebugThreadState.THREAD_RUN, null);
116-
DebuggerLoggingService.LogMessage ("Calling Continue()");
117-
context.Session.Process.Continue (false);
105+
try {
106+
if (abortCallTimes < 10) {
107+
DebuggerLoggingService.LogMessage ("Calling Abort() for {0} time", abortCallTimes);
108+
eval.Abort ();
109+
}
110+
else {
111+
if (abortCallTimes == 20) {
112+
// if Abort() and RudeAbort() didn't bring any result let's try to resume all the threads to free possible deadlocks in target process
113+
// maybe this can help to abort hanging evaluations
114+
DebuggerLoggingService.LogMessage ("RudeAbort() didn't stop eval after {0} times", abortCallTimes - 1);
115+
DebuggerLoggingService.LogMessage ("Calling Stop()");
116+
context.Session.Process.Stop (0);
117+
DebuggerLoggingService.LogMessage ("Calling SetAllThreadsDebugState(THREAD_RUN)");
118+
context.Session.Process.SetAllThreadsDebugState (CorDebugThreadState.THREAD_RUN, null);
119+
DebuggerLoggingService.LogMessage ("Calling Continue()");
120+
context.Session.Process.Continue (false);
121+
}
122+
DebuggerLoggingService.LogMessage ("Calling RudeAbort() for {0} time", abortCallTimes);
123+
eval.RudeAbort();
124+
}
125+
126+
} catch (COMException e) {
127+
var hResult = e.ToHResult<HResult> ();
128+
switch (hResult) {
129+
case HResult.CORDBG_E_PROCESS_TERMINATED:
130+
DebuggerLoggingService.LogMessage ("Process was terminated. Set cancelled for eval");
131+
tcs.TrySetCanceled ();
132+
return;
133+
case HResult.CORDBG_E_OBJECT_NEUTERED:
134+
DebuggerLoggingService.LogMessage ("Eval object was neutered. Set cancelled for eval");
135+
tcs.TrySetCanceled ();
136+
return;
118137
}
119-
DebuggerLoggingService.LogMessage ("Calling RudeAbort() for {0} time", abortCallTimes);
120-
eval.RudeAbort();
138+
tcs.SetException (e);
139+
throw;
121140
}
122141
}
123142
}

0 commit comments

Comments
 (0)