예제 #1
0
            private static List<MethodMirror> GetBuiltInMethods()
            {
                Validity.Assert(staticCore != null);

                Validity.Assert(staticCore.CodeBlockList.Count > 0);

                if (builtInMethods == null)
                {
                    List<ProcedureNode> procNodes = staticCore.CodeBlockList[0].procedureTable.procList;
                    numBuiltInMethods = procNodes.Count;
                    //List<ProcedureNode> builtIns = new List<ProcedureNode>();
                    builtInMethods = new List<MethodMirror>();

                    foreach (ProcedureNode procNode in procNodes)
                    {
                        if (!procNode.name.StartsWith(ProtoCore.DSASM.Constants.kInternalNamePrefix) && !procNode.name.Equals("Break"))
                        {
                            MethodMirror builtIn = new MethodMirror(procNode);
                            builtInMethods.Add(builtIn);
                        }
                    }
                    //builtInMethods = new MethodMirror(builtIns);

                }
                Validity.Assert(builtInMethods.Count > 0);

                return builtInMethods;
            }
예제 #2
0
            /// <summary>
            /// Returns list of global methods defined in an imported DS file
            /// </summary>
            /// <returns></returns>
            public List<MethodMirror> GetGlobalMethods()
            {
                if (globalMethods == null)
                {
                    List<MethodMirror> methods = new List<MethodMirror>();

                    Validity.Assert(staticCore != null);

                    Validity.Assert(staticCore.CodeBlockList.Count > 0);

                    List<ProcedureNode> procNodes = staticCore.CodeBlockList[0].procedureTable.procList;

                    int numNewMethods = procNodes.Count - numBuiltInMethods;
                    Validity.Assert(numNewMethods >= 0);

                    for (int i = numBuiltInMethods; i < procNodes.Count; ++i)
                    {
                        MethodMirror method = new MethodMirror(procNodes[i]);
                        methods.Add(method);
                    }

                    numBuiltInMethods = procNodes.Count;

                    globalMethods = methods;
                }

                return globalMethods;
            }
 public Value RuntimeInvoke(MethodMirror method, object target, Value[] values, out Value[] outArgs)
 {
     return(RuntimeInvoke(method, target, values, true, out outArgs));
 }
        Value RuntimeInvoke(MethodMirror method, object target, Value[] values, bool enableOutArgs, out Value[] outArgs)
        {
            outArgs = null;
            if (values != null)
            {
                // Some arguments may need to be boxed
                var mparams = method.GetParameters();
                if (mparams.Length != values.Length)
                {
                    throw new EvaluatorException("Invalid number of arguments when calling: " + method.Name);
                }

                for (int n = 0; n < mparams.Length; n++)
                {
                    var tm = mparams[n].ParameterType;
                    if (tm.IsValueType || tm.IsPrimitive || tm.FullName.StartsWith("System.Nullable`1", StringComparison.Ordinal))
                    {
                        continue;
                    }

                    var type          = Adapter.GetValueType(this, values[n]);
                    var argTypeMirror = type as TypeMirror;
                    var argType       = type as Type;

                    if (IsValueTypeOrPrimitive(argTypeMirror) || IsValueTypeOrPrimitive(argType))
                    {
                        // A value type being assigned to a parameter which is not a value type. The value has to be boxed.
                        try {
                            values[n] = Thread.Domain.CreateBoxedValue(values [n]);
                        } catch (NotSupportedException) {
                            // This runtime doesn't support creating boxed values
                            throw new EvaluatorException("This runtime does not support creating boxed values.");
                        }
                    }
                }
            }

            if (!method.IsStatic && method.DeclaringType.IsClass && !IsValueTypeOrPrimitive(method.DeclaringType))
            {
                object type             = Adapter.GetValueType(this, target);
                var    targetTypeMirror = type as TypeMirror;
                var    targetType       = type as Type;

                if ((target is StructMirror && ((StructMirror)target).Type != method.DeclaringType) ||
                    (IsValueTypeOrPrimitive(targetTypeMirror) || IsValueTypeOrPrimitive(targetType)))
                {
                    // A value type being assigned to a parameter which is not a value type. The value has to be boxed.
                    try {
                        target = Thread.Domain.CreateBoxedValue((Value)target);
                    } catch (NotSupportedException) {
                        // This runtime doesn't support creating boxed values
                        throw new EvaluatorException("This runtime does not support creating boxed values.");
                    }
                }
            }

            try {
                return(method.Evaluate(target is TypeMirror ? null : (Value)target, values));
            } catch (NotSupportedException) {
                AssertTargetInvokeAllowed();
                var threadState = Thread.ThreadState;
                if ((threadState & ThreadState.WaitSleepJoin) == ThreadState.WaitSleepJoin)
                {
                    DC.DebuggerLoggingService.LogMessage("Thread state before evaluation is {0}", threadState);
                    throw new EvaluatorException("Evaluation is not allowed when the thread is in 'Wait' state");
                }
                var mc = new MethodCall(this, method, target, values, enableOutArgs);
                //Since runtime is returning NOT_SUSPENDED error if two methods invokes are executed
                //at same time we have to lock invoking to prevent this...
                lock (method.VirtualMachine) {
                    Adapter.AsyncExecute(mc, Options.EvaluationTimeout);
                }
                if (enableOutArgs)
                {
                    outArgs = mc.OutArgs;
                }
                return(mc.ReturnValue);
            }
        }
예제 #5
0
 public StepIntoOverData(bool isStepInto, MethodMirror method, DbgCodeRange[] statementRanges)
 {
     IsStepInto      = isStepInto;
     Method          = method;
     StatementRanges = statementRanges;
 }
 protected Value Invoke(MethodMirror method, TypeMirror type, Value instance, params Value[] parameters)
 {
     return(Adaptor.Invocator.RuntimeInvoke(Context, method, type, instance, parameters).Result);
 }
        public PropertyValueReference(EvaluationContext ctx, PropertyInfoMirror property, object obj, TypeMirror declaringType, MethodMirror getter, Value[] indexerArgs) : base(ctx)
        {
            this.safe          = Context.Adapter.IsSafeToInvokeMethod(ctx, getter, obj ?? declaringType);
            this.declaringType = declaringType;
            this.indexerArgs   = indexerArgs;
            this.property      = property;
            this.getter        = getter;
            this.obj           = obj;

            if (getter.IsStatic)
            {
                this.obj = null;
            }

            var objectMirror = obj as ObjectMirror;

            if (objectMirror != null)
            {
                EnsureContextHasDomain(objectMirror.Domain);
            }

            flags = GetFlags(property, getter);
        }
예제 #8
0
        internal DEBUG_PROPERTY_INFO GetDebugPropertyInfo(enum_DEBUGPROP_INFO_FLAGS dwFields)
        {
            var propertyInfo = new DEBUG_PROPERTY_INFO();
            var info         = GetMirrorInfo();

            if ((dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME) != 0)
            {
                propertyInfo.bstrFullName = info != null ? info.Name : variable.Name;
                propertyInfo.dwFields    |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_FULLNAME;
            }

            if ((dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME) != 0)
            {
                propertyInfo.bstrName  = info != null ? info.Name : variable.Name;
                propertyInfo.dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME;
            }

            if ((dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE) != 0)
            {
                if (info != null)
                {
                    if (info.PropertyType != null)
                    {
                        propertyInfo.bstrType = info.PropertyType.FullName;
                    }
                }
                else
                {
                    propertyInfo.bstrType = variable.Type.Namespace + "." + variable.Type.Name;
                }
                propertyInfo.dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_TYPE;
            }

            if ((dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE) != 0 && info == null)
            {
                Value value = frame.GetValue(variable);
                if (value is ObjectMirror)
                {
                    var          obj            = ((ObjectMirror)value);
                    MethodMirror toStringMethod = obj.Type.GetMethod("ToString");
                    value = obj.InvokeMethod(frame.Thread, toStringMethod, Enumerable.Empty <Value>().ToList(),
                                             InvokeOptions.DisableBreakpoints);
                    propertyInfo.bstrValue = ((StringMirror)value).Value;
                }
                else if (value is PrimitiveValue)
                {
                    var obj = ((PrimitiveValue)value);
                    if (obj.Value != null)
                    {
                        propertyInfo.bstrValue = obj.Value.ToString();
                    }
                }

                propertyInfo.dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE;
            }

            if ((dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB) != 0)
            {
                propertyInfo.dwAttrib = enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_VALUE_READONLY;

                if (IsExpandable())
                {
                    propertyInfo.dwAttrib |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_OBJ_IS_EXPANDABLE;
                }
                propertyInfo.dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ATTRIB;
            }

            if (((dwFields & enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP) != 0) || IsExpandable())
            {
                propertyInfo.pProperty = this;
                propertyInfo.dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP;
            }

            return(propertyInfo);
        }
예제 #9
0
 internal SoftScope [] GetHoistedScopes(MethodMirror method) => GetHoistedScopesPrivate(method);
예제 #10
0
 internal string [] GetTupleElementNames(MethodMirror method, int localVariableIndex) => TupleElementNamesPrivate(method, localVariableIndex);
예제 #11
0
 public abstract InvokeResult CallMethod(MethodMirror method, Value?obj, IList <Value> arguments, FuncEvalOptions options);
예제 #12
0
 public abstract InvokeResult CreateInstance(MethodMirror method, IList <Value> arguments, FuncEvalOptions options);
예제 #13
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++;

                    Debug.Assert(!isNewobj || obj is null);
                    bool isInvokeInstanceMethod = !(obj is 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();
            }
        }
예제 #14
0
 public override InvokeResult CallMethod(MethodMirror method, Value?obj, IList <Value> arguments, FuncEvalOptions options) =>
 CallCore(method, obj, arguments, options, isNewobj: false);
예제 #15
0
 public override InvokeResult CreateInstance(MethodMirror method, IList <Value> arguments, FuncEvalOptions options) =>
 CallCore(method, null, arguments, options, isNewobj: true);