public FieldReference (EvaluationContext ctx, TargetStructObject thisobj, TargetType type, TargetFieldInfo field): base (ctx) { this.type = type; this.field = field; if (!field.IsStatic) this.thisobj = thisobj; }
public ML.TargetObject RuntimeInvoke(MdbEvaluationContext ctx, ML.TargetFunctionType function, ML.TargetStructObject object_argument, params ML.TargetObject[] param_objects) { MethodCall mc = new MethodCall(ctx, function, object_argument, param_objects); ctx.Adapter.AsyncExecute(mc, ctx.Options.EvaluationTimeout); return(mc.ReturnValue); }
public static EvaluationResult GetProperty(Thread thread, TargetPropertyInfo property, TargetStructObject instance, EvaluationFlags flags, int timeout, out string error, out TargetObject result) { error = null; RuntimeInvokeResult rti; try { RuntimeInvokeFlags rti_flags = RuntimeInvokeFlags.VirtualMethod; if ((flags & EvaluationFlags.NestedBreakStates) != 0) rti_flags |= RuntimeInvokeFlags.NestedBreakStates; rti = thread.RuntimeInvoke ( property.Getter, instance, new TargetObject [0], rti_flags); if (!rti.CompletedEvent.WaitOne (timeout, false)) { rti.Abort (); result = null; return EvaluationResult.Timeout; } if ((rti.TargetException != null) && (rti.TargetException.Type == TargetError.ClassNotInitialized)) { result = null; error = rti.ExceptionMessage; return EvaluationResult.NotInitialized; } if (rti.Result is Exception) { result = null; error = ((Exception) rti.Result).Message; return EvaluationResult.UnknownError; } result = (TargetObject) rti.ReturnObject; if (rti.ExceptionMessage != null) { error = rti.ExceptionMessage; return EvaluationResult.Exception; } else if (rti.ReturnObject == null) { rti.Abort (); return EvaluationResult.UnknownError; } return EvaluationResult.Ok; } catch (TargetException ex) { result = null; error = ex.ToString (); return EvaluationResult.UnknownError; } }
public static MemberExpression FindMember(Thread target, TargetStructType stype, TargetStructObject instance, string name, bool search_static, bool search_instance) { again: TargetClass klass = stype.GetClass (target); if (klass != null) { TargetMemberInfo member = klass.FindMember ( target, name, search_static, search_instance); if (member != null) return new StructAccessExpression (stype, instance, member); ArrayList methods = new ArrayList (); bool is_instance = false; bool is_static = false; TargetMethodInfo[] klass_methods = klass.GetMethods (target); if (klass_methods != null) { foreach (TargetMethodInfo method in klass_methods) { if (method.IsStatic && !search_static) continue; if (!method.IsStatic && !search_instance) continue; if (method.Name != name) continue; methods.Add (method.Type); if (method.IsStatic) is_static = true; else is_instance = true; } } if (methods.Count > 0) { TargetFunctionType[] funcs = new TargetFunctionType [methods.Count]; methods.CopyTo (funcs, 0); return new MethodGroupExpression ( stype, instance, name, funcs, is_instance, is_static); } } TargetClassType ctype = stype as TargetClassType; if (ctype != null) { TargetMemberInfo member = ctype.FindMember ( name, search_static, search_instance); if (member != null) return new StructAccessExpression (ctype, instance, member); ArrayList methods = new ArrayList (); bool is_instance = false; bool is_static = false; if (name == ".ctor") { foreach (TargetMethodInfo method in ctype.Constructors) { if (method.IsStatic) continue; methods.Add (method.Type); is_instance = true; } } else if (name == ".cctor") { foreach (TargetMethodInfo method in ctype.Constructors) { if (!method.IsStatic) continue; methods.Add (method.Type); is_static = true; } } else { foreach (TargetMethodInfo method in ctype.Methods) { if (method.IsStatic && !search_static) continue; if (!method.IsStatic && !search_instance) continue; if (method.Name != name) continue; methods.Add (method.Type); if (method.IsStatic) is_static = true; else is_instance = true; } } if (methods.Count > 0) { TargetFunctionType[] funcs = new TargetFunctionType [methods.Count]; methods.CopyTo (funcs, 0); return new MethodGroupExpression ( ctype, instance, name, funcs, is_instance, is_static); } } if (stype.HasParent) { stype = stype.GetParentType (target); if (instance != null) { instance = instance.GetParentObject (target); if (instance == null) return null; } goto again; } return null; }
public MethodGroupExpression(TargetStructType stype, TargetStructObject instance, string name, TargetFunctionType[] methods, bool is_instance, bool is_static) { this.stype = stype; this.instance = instance; this.name = name; this.methods = methods; this.is_instance = is_instance; this.is_static = is_static; resolved = true; }
public TargetObject GetValue (MdbEvaluationContext ctx, TargetStructObject thisObj) { if (Member is TargetPropertyInfo) { TargetPropertyInfo prop = (TargetPropertyInfo) Member; return ObjectUtil.GetRealObject (ctx, Server.Instance.RuntimeInvoke (ctx, prop.Getter, thisObj)); } else if (Member is TargetFieldInfo) { TargetFieldInfo field = (TargetFieldInfo) Member; if (field.HasConstValue) return ctx.Frame.Language.CreateInstance (ctx.Thread, field.ConstValue); TargetClass cls = DeclaringType.ClassType.GetClass (ctx.Thread); return ObjectUtil.GetRealObject (ctx, cls.GetField (ctx.Thread, thisObj, field)); } else { TargetMethodInfo met = (TargetMethodInfo) Member; return ObjectUtil.GetRealObject (ctx, Server.Instance.RuntimeInvoke (ctx, met.Type, thisObj)); } }
public static EvaluationResult MonoObjectToString(Thread thread, TargetStructObject obj, EvaluationFlags flags, int timeout, out string result) { result = null; if (!obj.Type.Language.IsManaged) return EvaluationResult.MethodNotFound; again: TargetStructType ctype = obj.Type; if ((ctype.Name == "System.Object") || (ctype.Name == "System.ValueType")) return EvaluationResult.MethodNotFound; TargetClass klass = ctype.GetClass (thread); if (klass == null) return EvaluationResult.NotInitialized; TargetMethodInfo[] methods = klass.GetMethods (thread); if (methods == null) return EvaluationResult.MethodNotFound; foreach (TargetMethodInfo minfo in methods) { if (minfo.Name != "ToString") continue; TargetFunctionType ftype = minfo.Type; if (ftype.ParameterTypes.Length != 0) continue; if (ftype.ReturnType != ftype.Language.StringType) continue; RuntimeInvokeResult rti; try { RuntimeInvokeFlags rti_flags = RuntimeInvokeFlags.VirtualMethod; if ((flags & EvaluationFlags.NestedBreakStates) != 0) rti_flags |= RuntimeInvokeFlags.NestedBreakStates; rti = thread.RuntimeInvoke ( ftype, obj, new TargetObject [0], rti_flags); if (!rti.CompletedEvent.WaitOne (timeout, false)) { rti.Abort (); return EvaluationResult.Timeout; } if ((rti.TargetException != null) && (rti.TargetException.Type == TargetError.ClassNotInitialized)) { result = null; return EvaluationResult.NotInitialized; } if (rti.Result is Exception) { result = ((Exception) rti.Result).Message; return EvaluationResult.UnknownError; } if (rti.ExceptionMessage != null) { result = rti.ExceptionMessage; return EvaluationResult.Exception; } else if (rti.ReturnObject == null) { rti.Abort (); return EvaluationResult.UnknownError; } } catch (TargetException ex) { result = ex.ToString (); return EvaluationResult.UnknownError; } TargetObject retval = (TargetObject) rti.ReturnObject; result = (string) ((TargetFundamentalObject) retval).GetObject (thread); return EvaluationResult.Ok; } if (obj.Type.HasParent) { obj = obj.GetParentObject (thread) as TargetClassObject; if (obj != null) goto again; } return EvaluationResult.MethodNotFound; }
public abstract TargetObject GetField(Thread thread, TargetStructObject instance, TargetFieldInfo field);
public EE.EvaluationResult GetProperty(Thread thread, TargetPropertyInfo property, TargetStructObject instance, EE.EvaluationFlags flags, int timeout, out string error, out TargetObject value) { return EE.GetProperty (thread, property, instance, flags, timeout, out error, out value); }
TargetClassObject CheckTypeProxy(TargetStructObject obj) { if (obj.Type.DebuggerTypeProxyAttribute == null) return null; string proxy_name = obj.Type.DebuggerTypeProxyAttribute.ProxyTypeName; string original_name = proxy_name; proxy_name = proxy_name.Replace ('+', '/'); Expression expression; try { expression = new TypeProxyExpression (proxy_name, obj); expression = expression.Resolve (this); if (expression == null) return null; return (TargetClassObject) expression.EvaluateObject (this); } catch { return null; } }
public RuntimeInvokeResult RuntimeInvoke(Thread thread, TargetFunctionType function, TargetStructObject object_argument, TargetObject[] param_objects, RuntimeInvokeFlags flags) { IInterruptionHandler interruption = InterruptionHandler ?? Interpreter; if (interruption.CheckInterruption ()) throw new EvaluationTimeoutException (); RuntimeInvokeResult result = thread.RuntimeInvoke ( function, object_argument, param_objects, flags); WaitHandle[] handles = new WaitHandle [2]; handles [0] = interruption.InterruptionEvent; handles [1] = result.CompletedEvent; int ret = WaitHandle.WaitAny (handles); if (ret == 0) { result.Abort (); throw new EvaluationTimeoutException (); } return result; }
public static EE.EvaluationResult HandleDebuggerDisplay(Interpreter interpreter, Thread thread, TargetStructObject instance, DebuggerDisplayAttribute attr, int timeout, out string name, out string type) { ScriptingContext expr_context = new ScriptingContext (interpreter); expr_context.CurrentThread = thread; expr_context.CurrentLanguage = instance.Type.Language; expr_context.ImplicitInstance = instance; EE.EvaluationResult result = expr_context.HandleDebuggerDisplay ( thread, instance, attr.Value, timeout, out name); if (result != EE.EvaluationResult.Ok) { type = null; return result; } if (String.IsNullOrEmpty (attr.Type)) { type = null; return EE.EvaluationResult.Ok; } return expr_context.HandleDebuggerDisplay ( thread, instance, attr.Type, timeout, out type); }
public static TargetClassObject CheckTypeProxy(Interpreter interpreter, Thread thread, TargetStructObject obj) { if (obj.Type.DebuggerTypeProxyAttribute == null) return null; ScriptingContext expr_context = new ScriptingContext (interpreter); expr_context.CurrentThread = thread; expr_context.CurrentLanguage = obj.Type.Language; expr_context.ImplicitInstance = obj; return expr_context.CheckTypeProxy (obj); }
static TargetStructObject TryParentCast (MdbEvaluationContext ctx, TargetStructObject source, TargetStructType source_type, TargetStructType target_type) { if (source_type == target_type) return source; if (!source_type.HasParent) return null; TargetStructType parent_type = source_type.GetParentType (ctx.Thread); source = TryParentCast (ctx, source, parent_type, target_type); if (source == null) return null; return source.GetParentObject (ctx.Thread) as TargetClassObject; }
public PropertyReference (EvaluationContext ctx, TargetPropertyInfo prop, TargetStructObject thisobj): base (ctx) { this.prop = prop; if (!prop.IsStatic) this.thisobj = thisobj; }
public override void RuntimeInvoke(TargetFunctionType function, TargetStructObject object_argument, TargetObject[] param_objects, RuntimeInvokeFlags flags, RuntimeInvokeResult result) { throw new InvalidOperationException (); }
public RuntimeInvokeResult RuntimeInvoke(TargetFunctionType function, TargetStructObject object_argument, TargetObject[] param_objects, RuntimeInvokeFlags flags) { lock (this) { check_alive (); RuntimeInvokeResult result = new RuntimeInvokeResult (this); servant.RuntimeInvoke ( function, object_argument, param_objects, flags, result); return result; } }
EE.EvaluationResult HandleDebuggerDisplay(Thread thread, TargetStructObject instance, string attr_value, int timeout, out string result) { result = null; StringBuilder sb = new StringBuilder (); int pos = 0; while (pos < attr_value.Length) { if (attr_value [pos] == '\\') { if (pos == attr_value.Length) break; else { sb.Append (attr_value [++pos]); pos++; continue; } } if (attr_value [pos] == '}') { result = null; return EE.EvaluationResult.InvalidExpression; } if (attr_value [pos] != '{') { sb.Append (attr_value [pos++]); continue; } pos++; StringBuilder expr_text = new StringBuilder (); while (pos < attr_value.Length) { if (attr_value [pos] == '\\') { if (pos == attr_value.Length) break; else { expr_text.Append (attr_value [++pos]); pos++; continue; } } else if (attr_value [pos] == '{') { result = null; return EE.EvaluationResult.InvalidExpression; } else if (attr_value [pos] == '}') { pos++; break; } expr_text.Append (attr_value [pos++]); } Expression expr; try { expr = Interpreter.ExpressionParser.ParseInternal (expr_text.ToString ()); } catch (ExpressionParsingException ex) { result = ex.Message; return EE.EvaluationResult.InvalidExpression; } catch { return EE.EvaluationResult.InvalidExpression; } try { expr = expr.Resolve (this); } catch (ScriptingException ex) { result = ex.Message; return EE.EvaluationResult.InvalidExpression; } catch { return EE.EvaluationResult.InvalidExpression; } string text; try { object retval = expr.Evaluate (this); if (retval is TargetObject) text = DoFormatObject ( (TargetObject) retval, DisplayFormat.Object); else text = interpreter.Style.FormatObject ( CurrentThread, retval, DisplayFormat.Object); } catch (ScriptingException ex) { result = ex.Message; return EE.EvaluationResult.InvalidExpression; } catch { return EE.EvaluationResult.InvalidExpression; } sb.Append (text); } result = sb.ToString (); return EE.EvaluationResult.Ok; }
public EE.EvaluationResult MonoObjectToString(Thread thread, TargetStructObject obj, EE.EvaluationFlags flags, int timeout, out string text) { return EE.MonoObjectToString (thread, obj, flags, timeout, out text); }
public OperationRuntimeInvoke(SingleSteppingEngine sse, TargetFunctionType function, TargetStructObject instance, TargetObject[] param_objects, RuntimeInvokeFlags flags, RuntimeInvokeResult result) : base(sse, result) { this.Result = result; this.Function = (MonoFunctionType) function; this.Instance = instance; this.ParamObjects = param_objects; this.Flags = flags; }
public abstract void SetField(Thread thread, TargetStructObject instance, TargetFieldInfo field, TargetObject value);
public OperationRuntimeInvokeHelper(SingleSteppingEngine sse, OperationRuntimeInvoke rti) : base(sse) { this.RTI = rti; this.instance = RTI.Instance; this.method = TargetAddress.Null; this.stage = Stage.Uninitialized; language = sse.process.MonoLanguage; }
public IndexerValueReference (EvaluationContext ctx, TargetStructObject target, TargetObject[] index, TargetPropertyInfo indexerProp): base (ctx) { this.indexer = indexerProp; this.target = target; this.index = index; }
protected override EventResult CallbackCompleted(long data1, long data2, out TargetEventArgs args) { if (RTI.AbortRequested) { CompletedRTI (); RTI.Result.InvocationAborted = true; RestoreStack (); args = null; return EventResult.CompletedCallback; } switch (stage) { case Stage.Uninitialized: { TargetAddress klass = new TargetAddress (inferior.AddressDomain, data1); Report.Debug (DebugFlags.SSE, "{0} rti resolved class: {1}", sse, klass); class_info = language.ReadClassInfo (inferior, klass); ((IMonoStructType) RTI.Function.DeclaringType).ClassInfo = class_info; ((IMonoStructType) RTI.Function.DeclaringType).ResolveClass (inferior, false); stage = Stage.ResolvedClass; do_execute (); args = null; return EventResult.Running; } case Stage.BoxingInstance: { TargetAddress boxed = new TargetAddress (inferior.AddressDomain, data1); Report.Debug (DebugFlags.SSE, "{0} rti boxed object: {1}", sse, boxed); TargetLocation new_loc = new AbsoluteTargetLocation (boxed); TargetClassType parent_type = instance.Type.GetParentType (inferior); instance = (TargetClassObject) parent_type.GetObject (inferior, new_loc); stage = Stage.HasMethodAddress; do_execute (); args = null; return EventResult.Running; } case Stage.GettingVirtualMethod: { method = new TargetAddress (inferior.AddressDomain, data1); Report.Debug (DebugFlags.SSE, "{0} rti got virtual method: {1}", sse, method); TargetAddress klass = inferior.ReadAddress (method + 8); TargetType class_type = language.ReadMonoClass (inferior, klass); if (class_type == null) { RTI.Result.ExceptionMessage = String.Format ( "Unable to get virtual method `{0}'.", RTI.Function.FullName); RTI.Result.InvocationCompleted = true; RestoreStack (); args = null; return EventResult.CompletedCallback; } if (!class_type.IsByRef) { TargetLocation new_loc = instance.Location.GetLocationAtOffset ( 2 * inferior.TargetMemoryInfo.TargetAddressSize); instance = (TargetClassObject) class_type.GetObject ( inferior, new_loc); } Report.Debug (DebugFlags.SSE, "{0} rti got virtual method #1: {1} {2}", sse, class_type, instance); stage = Stage.HasVirtualMethod; do_execute (); args = null; return EventResult.Running; } case Stage.CompilingMethod: { invoke = new TargetAddress (inferior.AddressDomain, data1); Report.Debug (DebugFlags.SSE, "{0} rti compiled method: {1}", sse, invoke); stage = Stage.CompiledMethod; do_execute (); args = null; return EventResult.Running; } case Stage.InvokedMethod: { RTI.Completed (data1, data2); RestoreStack (); args = null; return EventResult.CompletedCallback; } default: throw new InternalError (); } }
public override void RuntimeInvoke(TargetFunctionType function, TargetStructObject object_argument, TargetObject[] param_objects, RuntimeInvokeFlags flags, RuntimeInvokeResult result) { enforce_managed_context (); StartOperation (new OperationRuntimeInvoke ( this, function, object_argument, param_objects, flags, result)); }
public MethodCall (MdbEvaluationContext ctx, TargetFunctionType function, TargetStructObject object_argument, TargetObject[] param_objects) { this.ctx = ctx; this.function = function; this.object_argument = object_argument; this.param_objects = param_objects; }
public StructAccessExpression(TargetStructType type, TargetStructObject instance, TargetMemberInfo member) { this.Type = type; this.Member = member; this.instance = instance; resolved = true; }
public RuntimeInvokeResult RuntimeInvoke(TargetFunctionType function, TargetStructObject object_argument, TargetObject[] param_objects, bool is_virtual, bool debug) { RuntimeInvokeFlags flags = RuntimeInvokeFlags.None; if (is_virtual) flags |= RuntimeInvokeFlags.VirtualMethod; if (debug) flags |= RuntimeInvokeFlags.BreakOnEntry; return RuntimeInvoke (function, object_argument, param_objects, flags); }
public TypeProxyExpression(string proxy_type, TargetStructObject instance) { this.proxy_type = proxy_type; this.instance = instance; }
public abstract void RuntimeInvoke(TargetFunctionType function, TargetStructObject object_argument, TargetObject[] param_objects, RuntimeInvokeFlags flags, RuntimeInvokeResult result);