Beispiel #1
0
        protected override void AbortImpl(int abortCallTimes)
        {
            try {
                if (abortCallTimes < 10)
                {
                    DebuggerLoggingService.LogMessage("Calling Abort() for {0} time", abortCallTimes);
                    eval.Abort();
                }
                else
                {
                    if (abortCallTimes == 20)
                    {
                        // if Abort() and RudeAbort() didn't bring any result let's try to resume all the threads to free possible deadlocks in target process
                        // maybe this can help to abort hanging evaluations
                        DebuggerLoggingService.LogMessage("RudeAbort() didn't stop eval after {0} times", abortCallTimes - 1);
                        DebuggerLoggingService.LogMessage("Calling Stop()");
                        context.Session.Process.Stop(0);
                        DebuggerLoggingService.LogMessage("Calling SetAllThreadsDebugState(THREAD_RUN)");
                        context.Session.Process.SetAllThreadsDebugState(CorDebugThreadState.THREAD_RUN, null);
                        DebuggerLoggingService.LogMessage("Calling Continue()");
                        context.Session.Process.Continue(false);
                    }
                    DebuggerLoggingService.LogMessage("Calling RudeAbort() for {0} time", abortCallTimes);
                    eval.RudeAbort();
                }
            } catch (COMException e) {
                var hResult = e.ToHResult <HResult> ();
                switch (hResult)
                {
                case HResult.CORDBG_E_PROCESS_TERMINATED:
                    DebuggerLoggingService.LogMessage("Process was terminated. Set cancelled for eval");
                    tcs.TrySetCanceled();
                    return;

                case HResult.CORDBG_E_OBJECT_NEUTERED:
                    DebuggerLoggingService.LogMessage("Eval object was neutered. Set cancelled for eval");
                    tcs.TrySetCanceled();
                    return;
                }
                tcs.SetException(e);
                throw;
            }
        }
Beispiel #2
0
        public CorValue RuntimeInvoke(CorEvaluationContext ctx, CorFunction function, CorType[] typeArgs, CorValue thisObj, CorValue[] arguments)
        {
            if (!ctx.Thread.ActiveChain.IsManaged)
            {
                throw new EvaluatorException("Cannot evaluate expression because the thread is stopped in native code.");
            }

            CorValue[] args;
            if (thisObj == null)
            {
                args = arguments;
            }
            else
            {
                args    = new CorValue[arguments.Length + 1];
                args[0] = thisObj;
                arguments.CopyTo(args, 1);
            }

            CorMethodCall mc        = new CorMethodCall();
            CorValue      exception = null;
            CorEval       eval      = ctx.Eval;

            EvalEventHandler completeHandler = delegate(object o, CorEvalEventArgs eargs) {
                OnEndEvaluating();
                mc.DoneEvent.Set();
                eargs.Continue = false;
            };

            EvalEventHandler exceptionHandler = delegate(object o, CorEvalEventArgs eargs) {
                OnEndEvaluating();
                exception = eargs.Eval.Result;
                mc.DoneEvent.Set();
                eargs.Continue = false;
            };

            process.OnEvalComplete  += completeHandler;
            process.OnEvalException += exceptionHandler;

            mc.OnInvoke = delegate {
                if (function.GetMethodInfo(this).Name == ".ctor")
                {
                    eval.NewParameterizedObject(function, typeArgs, args);
                }
                else
                {
                    eval.CallParameterizedFunction(function, typeArgs, args);
                }
                process.SetAllThreadsDebugState(CorDebugThreadState.THREAD_SUSPEND, ctx.Thread);
                ClearEvalStatus();
                OnStartEvaluating();
                process.Continue(false);
            };
            mc.OnAbort = delegate {
                eval.Abort();
            };
            mc.OnGetDescription = delegate {
                System.Reflection.MethodInfo met = function.GetMethodInfo(ctx.Session);
                if (met != null)
                {
                    return(met.Name);
                }
                else
                {
                    return("<Unknown>");
                }
            };

            try {
                ObjectAdapter.AsyncExecute(mc, ctx.Options.EvaluationTimeout);
            }
            finally {
                process.OnEvalComplete  -= completeHandler;
                process.OnEvalException -= exceptionHandler;
            }

            if (exception != null)
            {
/*				ValueReference<CorValue, CorType> msg = ctx.Adapter.GetMember (ctx, val, "Message");
 *                              if (msg != null) {
 *                                      string s = msg.ObjectValue as string;
 *                                      mc.ExceptionMessage = s;
 *                              }
 *                              else
 *                                      mc.ExceptionMessage = "Evaluation failed.";*/
                CorValRef vref = new CorValRef(exception);
                throw new EvaluatorException("Evaluation failed: " + ObjectAdapter.GetValueTypeName(ctx, vref));
            }

            return(eval.Result);
        }