Esempio n. 1
0
        EvalResult SyncWait()
        {
            Debug.Assert(startTime != null);

            var now = DateTime.UtcNow;

            if (now >= endTime)
            {
                now = endTime;
            }
            var timeLeft = endTime - now;

            if (!useTotalTimeout)
            {
                timeLeft = TimeSpan.FromMilliseconds(TIMEOUT_MS);
            }

            var    infos = new ThreadInfos(thread, SuspendOtherThreads);
            object dispResult;

            debugger.DebugCallbackEvent += Debugger_DebugCallbackEvent;
            bool timedOut;

            try {
                infos.EnableThread();

                debugger.EvalStarted();
                dispResult = debugMessageDispatcher.DispatchQueue(timeLeft, out timedOut);
                if (timedOut)
                {
                    bool timedOutTmp;
                    int  hr = eval.Abort();
                    if (hr >= 0)
                    {
                        debugMessageDispatcher.DispatchQueue(TimeSpan.FromMilliseconds(ABORT_TIMEOUT_MS), out timedOutTmp);
                        if (timedOutTmp)
                        {
                            hr = eval.RudeAbort();
                            if (hr >= 0)
                            {
                                debugMessageDispatcher.DispatchQueue(TimeSpan.FromMilliseconds(RUDE_ABORT_TIMEOUT_MS), out timedOutTmp);
                            }
                        }
                    }
                    hr = debugger.TryBreakProcesses();
                    Debug.WriteLineIf(hr != 0, string.Format("Eval timed out and TryBreakProcesses() failed: hr=0x{0:X8}", hr));
                    EvalTimedOut = true;
                    throw new TimeoutException();
                }
            }
            finally {
                debugger.DebugCallbackEvent -= Debugger_DebugCallbackEvent;
                infos.RestoreThreads();
                debugger.EvalStopped();
            }
            Debug.Assert(dispResult is bool);
            bool wasException = (bool)dispResult;

            return(new EvalResult(wasException, eval.Result));
        }
Esempio n. 2
0
        InvokeResult CallCore(MethodMirror method, Value?obj, IList <Value> arguments, FuncEvalOptions options, bool isNewobj)
        {
            if (evalTimedOut)
            {
                throw new TimeoutException();
            }

            IInvokeAsyncResult?asyncRes = null;
            bool done = false;

            try {
                funcEvalState.isEvaluatingCounter++;

                var currTime = DateTime.UtcNow;
                var timeLeft = endTime - currTime;
                if (timeLeft >= TimeSpan.Zero)
                {
                    funcEvalState.methodInvokeCounter++;

                    Debug2.Assert(!isNewobj || obj is null);
                    bool isInvokeInstanceMethod = obj is not null && !isNewobj;

                    AsyncCallback asyncCallback = asyncRes2 => {
                        if (done)
                        {
                            return;
                        }
                        InvokeResult resTmp;
                        try {
                            if (isInvokeInstanceMethod)
                            {
                                resTmp = obj !.EndInvokeMethodWithResult(asyncRes2);
                            }
                            else
                            {
                                resTmp = method.DeclaringType.EndInvokeMethodWithResult(asyncRes2);
                            }
                            debugMessageDispatcher.CancelDispatchQueue(resTmp);
                        }
                        catch (Exception ex) {
                            debugMessageDispatcher.CancelDispatchQueue(ExceptionDispatchInfo.Capture(ex));
                        }
                    };

                    if (isInvokeInstanceMethod)
                    {
                        asyncRes = obj !.BeginInvokeMethod(thread, method, arguments, GetInvokeOptions(options), asyncCallback, null);
                    }
                    else
                    {
                        asyncRes = method.DeclaringType.BeginInvokeMethod(thread, method, arguments, GetInvokeOptions(options), asyncCallback, null);
                    }

                    var res = debugMessageDispatcher.DispatchQueue(timeLeft, out bool timedOut);
                    if (timedOut)
                    {
                        evalTimedOut = true;
                        try {
                            asyncRes.Abort();
                        }
                        catch (CommandException ce) when(ce.ErrorCode == ErrorCode.ERR_NO_INVOCATION)
                        {
                        }
                        throw new TimeoutException();
                    }
                    if (res is ExceptionDispatchInfo exInfo)
                    {
                        exInfo.Throw();
                    }
                    Debug.Assert(res is InvokeResult);
                    return(res as InvokeResult ?? throw new InvalidOperationException());
                }
                else
                {
                    evalTimedOut = true;
                    throw new TimeoutException();
                }
            }
            finally {
                done = true;
                funcEvalState.isEvaluatingCounter--;
                asyncRes?.Dispose();
            }
        }