Esempio n. 1
0
 public VariableReference(EvaluationContext ctx, CorValRef var, string name, DC.ObjectValueFlags flags)
     : base(ctx)
 {
     this.flags = flags;
     this.var   = var;
     this.name  = name;
 }
Esempio n. 2
0
        public static void SetValue(this CorValRef thisVal, EvaluationContext ctx, CorValRef val)
        {
            CorEvaluationContext cctx = (CorEvaluationContext)ctx;
            CorObjectAdaptor     actx = (CorObjectAdaptor)ctx.Adapter;

            if (actx.IsEnum(ctx, thisVal.Val.ExactType) && !actx.IsEnum(ctx, val.Val.ExactType))
            {
                ValueReference vr = actx.GetMember(ctx, null, thisVal, "value__");
                vr.Value = val;
                // Required to make sure that var returns an up-to-date value object
                thisVal.IsValid = false;
                return;
            }

            CorReferenceValue s = thisVal.Val.CastToReferenceValue();

            if (s != null)
            {
                CorReferenceValue v = val.Val.CastToReferenceValue();
                if (v != null)
                {
                    s.Value = v.Value;
                    return;
                }
            }
            CorGenericValue gv = CorObjectAdaptor.GetRealObject(cctx, thisVal.Val) as CorGenericValue;

            if (gv != null)
            {
                gv.SetValue(ctx.Adapter.TargetObjectToObject(ctx, val));
            }
        }
Esempio n. 3
0
		public VariableReference (EvaluationContext ctx, CorValRef var, string name, DC.ObjectValueFlags flags)
			: base (ctx)
		{
			this.flags = flags;
			this.var = var;
			this.name = name;
		}
Esempio n. 4
0
        public override object RuntimeInvoke(EvaluationContext gctx, object gtargetType, object gtarget, string methodName, object[] ggenericArgTypes, object[] gargTypes, object[] gargValues)
        {
            // FIXME: support generic methods by using the genericArgTypes parameter
            CorType   targetType = (CorType)gtargetType;
            CorValRef target     = (CorValRef)gtarget;

            CorType[]   argTypes  = CastArray <CorType> (gargTypes);
            CorValRef[] argValues = CastArray <CorValRef> (gargValues);

            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic;

            if (target != null)
            {
                flags |= BindingFlags.Instance;
            }
            else
            {
                flags |= BindingFlags.Static;
            }

            CorEvaluationContext ctx    = (CorEvaluationContext)gctx;
            MethodInfo           method = OverloadResolve(ctx, methodName, targetType, argTypes, flags, true);

            ParameterInfo[] parameters = method.GetParameters();
            for (int n = 0; n < parameters.Length; n++)
            {
                if (parameters[n].ParameterType == typeof(object) && (IsValueType(ctx, argValues[n])))
                {
                    argValues[n] = Box(ctx, argValues[n]);
                }
            }

            if (method != null)
            {
                CorValRef v = new CorValRef(delegate {
                    CorFunction func = targetType.Class.Module.GetFunctionFromToken(method.MetadataToken);
                    CorValue[] args  = new CorValue[argValues.Length];
                    for (int n = 0; n < args.Length; n++)
                    {
                        args[n] = argValues[n].Val;
                    }
                    return(ctx.RuntimeInvoke(func, new CorType[0], target != null ? target.Val : null, args));
                });
                if (v.Val == null)
                {
                    return(null);
                }
                else
                {
                    return(v);
                }
            }
            else
            {
                throw new EvaluatorException("Invalid method name or incompatible arguments.");
            }
        }
Esempio n. 5
0
        IEnumerable <ValueReference> GetLocals(CorEvaluationContext ctx, ISymbolScope scope, int offset, bool showHidden)
        {
            if (ctx.Frame.FrameType != CorFrameType.ILFrame)
            {
                yield break;
            }

            if (scope == null)
            {
                ISymbolMethod met = ctx.Frame.Function.GetSymbolMethod(ctx.Session);
                if (met != null)
                {
                    scope = met.RootScope;
                }
                else
                {
                    int count = ctx.Frame.GetLocalVariablesCount();
                    for (int n = 0; n < count; n++)
                    {
                        int       locn = n;
                        CorValRef vref = new CorValRef(delegate {
                            return(ctx.Frame.GetLocalVariable(locn));
                        });
                        yield return(new VariableReference(ctx, vref, "local_" + (n + 1), ObjectValueFlags.Variable));
                    }
                    yield break;
                }
            }

            foreach (ISymbolVariable var in scope.GetLocals())
            {
                if (var.Name == "$site")
                {
                    continue;
                }
                if (var.Name.IndexOfAny(new char[] { '$', '<', '>' }) == -1 || showHidden)
                {
                    int       addr = var.AddressField1;
                    CorValRef vref = new CorValRef(delegate {
                        return(ctx.Frame.GetLocalVariable(addr));
                    });
                    yield return(new VariableReference(ctx, vref, var.Name, ObjectValueFlags.Variable));
                }
            }

            foreach (ISymbolScope cs in scope.GetChildren())
            {
                if (cs.StartOffset <= offset && cs.EndOffset >= offset)
                {
                    foreach (VariableReference var in GetLocals(ctx, cs, offset, showHidden))
                    {
                        yield return(var);
                    }
                }
            }
        }
Esempio n. 6
0
        bool IsValueType(CorEvaluationContext ctx, CorValRef val)
        {
            CorValue v = GetRealObject(ctx, val);

            if (v.Type == CorElementType.ELEMENT_TYPE_VALUETYPE)
            {
                return(true);
            }
            return(v is CorGenericValue);
        }
Esempio n. 7
0
 public CorValRef GetBoxedArg(CorEvaluationContext ctx, CorValRef val, Type argType)
 {
     // Boxes a value when required
     if (argType == typeof(object) && IsValueType(ctx, val))
     {
         return(Box(ctx, val));
     }
     else
     {
         return(val);
     }
 }
Esempio n. 8
0
		public FieldReference (EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field)
			: base (ctx)
		{
			this.thisobj = thisobj;
			this.type = type;
			this.field = field;
			if (!field.IsStatic)
				this.thisobj = thisobj;

			loader = delegate {
				return ((CorValRef)Value).Val;
			};
		}
Esempio n. 9
0
        CorValRef Box(CorEvaluationContext ctx, CorValRef val)
        {
            CorValRef arr = new CorValRef(delegate {
                return(ctx.Session.NewArray(ctx, (CorType)GetValueType(ctx, val), 1));
            });
            ArrayAdaptor realArr = new ArrayAdaptor(ctx, arr);

            realArr.SetElement(new int[] { 0 }, val);

            CorType at = (CorType)GetType(ctx, "System.Array");

            object[] argTypes = new object[] { GetType(ctx, "System.Int32") };
            return((CorValRef)RuntimeInvoke(ctx, at, arr, "GetValue", argTypes, new object[] { CreateValue(ctx, 0) }));
        }
Esempio n. 10
0
		public PropertyReference (EvaluationContext ctx, PropertyInfo prop, CorValRef thisobj, CorType declaringType, CorValRef[] index)
			: base (ctx)
		{
			this.prop = prop;
			this.declaringType = declaringType;
			this.module = declaringType.Class.Module;
			this.index = index;
			if (!prop.GetGetMethod (true).IsStatic)
				this.thisobj = thisobj;

			loader = delegate {
				return ((CorValRef)Value).Val;
			};
		}
Esempio n. 11
0
		public FieldReference (EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field, string vname, ObjectValueFlags vflags) : base (ctx)
		{
			this.thisobj = thisobj;
			this.type = type;
			this.field = field;
			this.vname = vname;
			if (field.IsStatic)
				this.thisobj = null;

			flags = vflags | GetFlags (field);

			loader = delegate {
				return ((CorValRef)Value).Val;
			};
		}
Esempio n. 12
0
        public FieldReference(EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field)
            : base(ctx)
        {
            this.thisobj = thisobj;
            this.type    = type;
            this.field   = field;
            if (field.IsStatic)
            {
                this.thisobj = null;
            }

            loader = delegate {
                return(((CorValRef)Value).Val);
            };
        }
Esempio n. 13
0
        public PropertyReference(EvaluationContext ctx, PropertyInfo prop, CorValRef thisobj, CorType declaringType, CorValRef[] index)
            : base(ctx)
        {
            this.prop          = prop;
            this.declaringType = declaringType;
            this.module        = declaringType.Class.Module;
            this.index         = index;
            if (!prop.GetGetMethod(true).IsStatic)
            {
                this.thisobj = thisobj;
            }

            loader = delegate {
                return(((CorValRef)Value).Val);
            };
        }
Esempio n. 14
0
        public override ValueReference GetIndexerReference(EvaluationContext ctx, object target, object[] indices)
        {
            CorEvaluationContext cctx = (CorEvaluationContext)ctx;
            CorType targetType        = GetValueType(ctx, target) as CorType;

            CorValRef[] values = new CorValRef[indices.Length];
            CorType[]   types  = new CorType[indices.Length];
            for (int n = 0; n < indices.Length; n++)
            {
                types[n]  = (CorType)GetValueType(ctx, indices[n]);
                values[n] = (CorValRef)indices[n];
            }

            List <MethodInfo>   candidates = new List <MethodInfo> ();
            List <PropertyInfo> props      = new List <PropertyInfo> ();
            List <CorType>      propTypes  = new List <CorType> ();

            CorType t = targetType;

            while (t != null)
            {
                Type type = t.GetTypeInfo(cctx.Session);

                foreach (PropertyInfo prop in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    MethodInfo mi = null;
                    try {
                        mi = prop.CanRead ? prop.GetGetMethod() : null;
                    }
                    catch {
                        // Ignore
                    }
                    if (mi != null && mi.GetParameters().Length > 0)
                    {
                        candidates.Add(mi);
                        props.Add(prop);
                        propTypes.Add(t);
                    }
                }
                t = t.Base;
            }

            MethodInfo idx = OverloadResolve(cctx, GetTypeName(ctx, targetType), null, types, candidates, true);
            int        i   = candidates.IndexOf(idx);

            return(new PropertyReference(ctx, props[i], (CorValRef)target, propTypes[i], values));
        }
Esempio n. 15
0
        public FieldReference(EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field, string vname, ObjectValueFlags vflags) : base(ctx)
        {
            this.thisobj = thisobj;
            this.type    = type;
            this.field   = field;
            this.vname   = vname;
            if (field.IsStatic)
            {
                this.thisobj = null;
            }

            flags = vflags | GetFlags(field);

            loader = delegate {
                return(((CorValRef)Value).Val);
            };
        }
Esempio n. 16
0
        protected override IEnumerable <ValueReference> OnGetParameters(EvaluationContext gctx)
        {
            CorEvaluationContext ctx = (CorEvaluationContext)gctx;

            if (ctx.Frame.FrameType == CorFrameType.ILFrame && ctx.Frame.Function != null)
            {
                MethodInfo met = ctx.Frame.Function.GetMethodInfo(ctx.Session);
                if (met != null)
                {
                    foreach (ParameterInfo pi in met.GetParameters())
                    {
                        int pos = pi.Position;
                        if (met.IsStatic)
                        {
                            pos--;
                        }
                        CorValRef vref = null;
                        try {
                            vref = new CorValRef(delegate {
                                return(ctx.Frame.GetArgument(pos));
                            });
                        }
                        catch (Exception /*ex*/) {
                        }
                        if (vref != null)
                        {
                            yield return(new VariableReference(ctx, vref, pi.Name, ObjectValueFlags.Parameter));
                        }
                    }
                    yield break;
                }
            }

            int count = ctx.Frame.GetArgumentCount();

            for (int n = 0; n < count; n++)
            {
                int       locn = n;
                CorValRef vref = new CorValRef(delegate {
                    return(ctx.Frame.GetArgument(locn));
                });
                yield return(new VariableReference(ctx, vref, "arg_" + (n + 1), ObjectValueFlags.Parameter));
            }
        }
Esempio n. 17
0
        public override ValueReference GetCurrentException(EvaluationContext ctx)
        {
            CorEvaluationContext wctx      = (CorEvaluationContext)ctx;
            CorValue             exception = wctx.Thread.CurrentException;

            if (exception != null)
            {
                CorHandleValue exceptionHandle = wctx.Session.GetHandle(exception);

                CorValRef vref = new CorValRef(delegate {
                    return(exceptionHandle);
                });

                return(new VariableReference(ctx, vref, "__EXCEPTION_OBJECT__", ObjectValueFlags.Variable));
            }
            else
            {
                return(base.GetCurrentException(ctx));
            }
        }
Esempio n. 18
0
        protected override IEnumerable <ValueReference> GetMembers(EvaluationContext ctx, object tt, object gval, BindingFlags bindingFlags)
        {
            CorType   t   = (CorType)tt;
            CorValRef val = (CorValRef)gval;

            if (t.Class == null)
            {
                yield break;
            }

            CorEvaluationContext cctx = (CorEvaluationContext)ctx;

            while (t != null)
            {
                Type type = t.GetTypeInfo(cctx.Session);

                foreach (FieldInfo field in type.GetFields(bindingFlags))
                {
                    yield return(new FieldReference(ctx, val, t, field));
                }

                foreach (PropertyInfo prop in type.GetProperties(bindingFlags))
                {
                    MethodInfo mi = null;
                    try {
                        mi = prop.CanRead ? prop.GetGetMethod() : null;
                    } catch {
                        // Ignore
                    }
                    if (mi != null && mi.GetParameters().Length == 0)
                    {
                        yield return(new PropertyReference(ctx, prop, val, t));
                    }
                }
                if ((bindingFlags & BindingFlags.DeclaredOnly) != 0)
                {
                    break;
                }
                t = t.Base;
            }
        }
Esempio n. 19
0
		public PropertyReference (EvaluationContext ctx, PropertyInfo prop, CorValRef thisobj, CorType declaringType, CorValRef[] index)
			: base (ctx)
		{
			this.prop = prop;
			this.declaringType = declaringType;
			if (declaringType.Type == CorElementType.ELEMENT_TYPE_ARRAY ||
			    declaringType.Type == CorElementType.ELEMENT_TYPE_SZARRAY) {
				this.module = ((CorType)((CorEvaluationContext)ctx).Adapter.GetType (ctx, "System.Object")).Class.Module;
			} else {
				this.module = declaringType.Class.Module;
			}
			this.index = index;
			if (!prop.GetGetMethod (true).IsStatic)
				this.thisobj = thisobj;

			flags = GetFlags (prop);

			loader = delegate {
				return ((CorValRef)Value).Val;
			};
		}
Esempio n. 20
0
        protected override ValueReference OnGetThisReference(EvaluationContext gctx)
        {
            CorEvaluationContext ctx = (CorEvaluationContext)gctx;

            if (ctx.Frame.FrameType != CorFrameType.ILFrame || ctx.Frame.Function == null)
            {
                return(null);
            }

            MethodInfo mi = ctx.Frame.Function.GetMethodInfo(ctx.Session);

            if (mi == null || mi.IsStatic)
            {
                return(null);
            }

            CorValRef vref = new CorValRef(delegate {
                return(ctx.Frame.GetArgument(0));
            });

            return(new VariableReference(ctx, vref, "this", ObjectValueFlags.Variable | ObjectValueFlags.ReadOnly));
        }
 public StringAdaptor(EvaluationContext ctx, CorValRef obj, CorStringValue str)
 {
     this.ctx = (CorEvaluationContext)ctx;
     this.str = str;
     this.obj = obj;
 }
Esempio n. 22
0
		public PropertyReference (EvaluationContext ctx, PropertyInfo prop, CorValRef thisobj, CorType declaringType)
			: this (ctx, prop, thisobj, declaringType, null)
		{
		}
Esempio n. 23
0
		public StringAdaptor (EvaluationContext ctx, CorValRef obj, CorStringValue str)
		{
			this.ctx = (CorEvaluationContext) ctx;
			this.str = str;
			this.obj = obj;
		}
		public static void SetValue (this CorValRef thisVal, EvaluationContext ctx, CorValRef val)
		{
			CorEvaluationContext cctx = (CorEvaluationContext) ctx;
			CorObjectAdaptor actx = (CorObjectAdaptor) ctx.Adapter;
			if (actx.IsEnum (ctx, thisVal.Val.ExactType) && !actx.IsEnum (ctx, val.Val.ExactType)) {
				ValueReference vr = actx.GetMember (ctx, null, thisVal, "value__");
				vr.Value = val;
				// Required to make sure that var returns an up-to-date value object
				thisVal.IsValid = false;
				return;
			}
				
			CorReferenceValue s = thisVal.Val.CastToReferenceValue ();
			if (s != null) {
				CorReferenceValue v = val.Val.CastToReferenceValue ();
				if (v != null) {
					s.Value = v.Value;
					return;
				}
			}
			CorGenericValue gv = CorObjectAdaptor.GetRealObject (cctx, thisVal.Val) as CorGenericValue;
			if (gv != null)
				gv.SetValue (ctx.Adapter.TargetObjectToObject (ctx, val));
		}
Esempio n. 25
0
		public ArrayAdaptor (EvaluationContext ctx, CorValRef obj, CorArrayValue array)
		{
			this.ctx = (CorEvaluationContext) ctx;
			this.array = array;
			this.obj = obj;
		}
Esempio n. 26
0
 public FieldReference(EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field)
     : this(ctx, thisobj, type, field, null, ObjectValueFlags.Field)
 {
 }
Esempio n. 27
0
 public ArrayAdaptor(EvaluationContext ctx, CorValRef obj)
 {
     this.obj = obj;
     this.ctx = (CorEvaluationContext)ctx;
 }
Esempio n. 28
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);
        }
Esempio n. 29
0
        public override bool IsNull(EvaluationContext ctx, object gval)
        {
            CorValRef val = (CorValRef)gval;

            return(val == null || ((val.Val is CorReferenceValue) && ((CorReferenceValue)val.Val).IsNull));
        }
Esempio n. 30
0
		public FieldReference (EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field)
			: this (ctx, thisobj, type, field, null, ObjectValueFlags.Field)
		{
		}
		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;
		}
		public ArrayAdaptor (EvaluationContext ctx, CorValRef obj)
		{
			this.obj = obj;
			this.ctx = (CorEvaluationContext) ctx;
		}