Skip to content

Commit e1f7852

Browse files
committed
More proper evaluation aborting
1 parent 0aec667 commit e1f7852

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

Mono.Debugging.Win32/CorMethodCall.cs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Threading;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32
using Microsoft.Samples.Debugging.CorDebug;
43
using Microsoft.Samples.Debugging.CorDebug.NativeApi;
4+
using Mono.Debugging.Client;
55
using Mono.Debugging.Evaluation;
66

77
namespace Mono.Debugging.Win32
@@ -40,10 +40,12 @@ void DoProcessEvalFinished (CorEvalEventArgs evalArgs, bool isException)
4040
return;
4141
context.Session.OnEndEvaluating ();
4242
evalArgs.Continue = false;
43-
if (aborted) {
43+
if (Token.IsCancellationRequested) {
44+
DebuggerLoggingService.LogMessage ("EvalFinished() but evaluation was cancelled");
4445
tcs.TrySetCanceled ();
4546
}
4647
else {
48+
DebuggerLoggingService.LogMessage ("EvalFinished(). Setting the result");
4749
tcs.TrySetResult(new OperationResult<CorValue> (evalArgs.Eval.Result, isException));
4850
}
4951
}
@@ -66,30 +68,16 @@ public override string Description
6668
{
6769
var met = function.GetMethodInfo (context.Session);
6870
if (met == null)
69-
return "<Unknown>";
71+
return "[Unknown method]";
7072
if (met.DeclaringType == null)
7173
return met.Name;
7274
return met.DeclaringType.FullName + "." + met.Name;
7375
}
7476
}
7577

7678
readonly TaskCompletionSource<OperationResult<CorValue>> tcs = new TaskCompletionSource<OperationResult<CorValue>> ();
77-
bool aborted = false;
78-
const int DelayAfterAbort = 500;
7979

80-
protected override void AfterCancelledImpl (int elapsedAfterCancelMs)
81-
{
82-
if (tcs.TrySetCanceled ()) {
83-
// really cancelled for the first time not before. so we should check that we awaited necessary amout of time after Abort() call
84-
// else if we return too earle after Abort() the process may be PROCESS_NOT_SYNCHRONIZED
85-
if (elapsedAfterCancelMs < DelayAfterAbort) {
86-
Thread.Sleep (DelayAfterAbort - elapsedAfterCancelMs);
87-
}
88-
}
89-
context.Session.OnEndEvaluating ();
90-
}
91-
92-
protected override Task<OperationResult<CorValue>> InvokeAsyncImpl (CancellationToken token)
80+
protected override Task<OperationResult<CorValue>> InvokeAsyncImpl ()
9381
{
9482
SubscribeOnEvals ();
9583

@@ -102,19 +90,24 @@ protected override Task<OperationResult<CorValue>> InvokeAsyncImpl (Cancellation
10290
context.Session.OnStartEvaluating ();
10391
context.Session.Process.Continue (false);
10492
Task = tcs.Task;
105-
// Don't pass token here, because it causes immediately task cancellation which must be performed by debugger event or real timeout
106-
// ReSharper disable once MethodSupportsCancellation
93+
// Don't pass token here, because it causes immediately task cancellation which must be performed by debugger event or real timeout
10794
return Task.ContinueWith (task => {
10895
UnSubcribeOnEvals ();
10996
return task.Result;
11097
});
11198
}
11299

113100

114-
protected override void CancelImpl ( )
101+
protected override void AbortImpl (int abortCallTimes)
115102
{
116-
eval.Abort ();
117-
aborted = true;
103+
if (abortCallTimes < 10) {
104+
DebuggerLoggingService.LogMessage ("Calling Abort()");
105+
eval.Abort ();
106+
}
107+
else {
108+
DebuggerLoggingService.LogMessage ("Calling RudeAbort()");
109+
eval.RudeAbort();
110+
}
118111
}
119112
}
120113
}

0 commit comments

Comments
 (0)