public InstanceValue(ObjectMirror instance, FieldInfoMirror[] fields) { Contract.Requires(instance != null); Contract.Requires(fields != null); Instance = instance; Type = instance.Type; Length += instance.Type.GetAllProperties().Count(p => p.ShouldDisplay()); Length += instance.Type.GetAllFields().Count(f => f.ShouldDisplay()); }
public static void Set(ThreadMirror thread, VariableItem item, ObjectMirror parent, FieldInfoMirror key, Value newValue) { if (key.IsStatic) key.DeclaringType.SetValue(key, newValue); else parent.SetValue(key, newValue); }
private void DoWalkObject(ObjectMirror value, Trace parent) { if (!value.IsCollected && !m_objects.Contains(value.Address)) { m_objects.Add(value.Address); foreach (FieldInfoMirror field in value.Type.GetAllFields()) { if (!field.IsStatic && DoShouldWalkType(field.FieldType)) { Log.WriteLine(TraceLevel.Verbose, "TraceRoots", "object {0}.{1} [{2}]", field.DeclaringType.FullName, field.Name, field.FieldType.FullName); Log.Indent(); Value v = value.GetValue(field); var child = new Trace(field.Name, field.FieldType.FullName, v); DoWalkValue(v, child, field.Name); parent.Children.Add(child); Log.Unindent(); } } } }
public static void Set(ThreadMirror thread, VariableItem item, ObjectMirror parent, PropertyInfoMirror key, Value newValue) { Contract.Assert(key.HasSimpleGetter()); // indexors aren't shown... MethodMirror method = key.GetSetMethod(true); if (method != null) { Unused.Value = parent.InvokeMethod(thread, method, new Value[]{newValue}, InvokeOptions.DisableBreakpoints | InvokeOptions.SingleThreaded); } else { throw new Exception("Property does not have a setter."); } }
public InvocationException (ObjectMirror exception) { this.exception = exception; }
private Value DoInvoke(ThreadMirror thread, ObjectMirror obj, string name) { Value result; MethodMirror method = obj.Type.ResolveProperty(name); if (method == null) method = obj.Type.FindMethod(name, 0); if (method != null) { if (!Debugger.IsTypeLoaded(method.DeclaringType.FullName)) { result = thread.Domain.CreateString("type not loaded"); } else { IAsyncResult ar = obj.BeginInvokeMethod(thread, method, new Value[0], InvokeOptions.DisableBreakpoints | InvokeOptions.SingleThreaded, null, null); if (!ar.IsCompleted) ar.AsyncWaitHandle.WaitOne(Timeout); if (ar.IsCompleted) { result = obj.EndInvokeMethod(ar); } else { Func<Value> getter = () => obj.EndInvokeMethod(ar); ThreadPool.QueueUserWorkItem(o => DoIgnoreResult(getter, ar)); // the pool uses background threads so the app will exit even if this thread is still running result = thread.Domain.CreateString("timed out"); } } } else { throw new Exception(string.Format("Couldn't find a property for {0}.{1}", obj.Type.FullName, name)); } return result; }
private static Value DoGetField(ObjectMirror mirror, string name, ThreadMirror thread) { Value result = null; FieldInfoMirror field = mirror.Type.ResolveField(name); if (field != null && field.ShouldEvaluate()) { if (field.IsStatic) if (field.HasCustomAttribute("System.ThreadStaticAttribute")) result = field.DeclaringType.GetValue(field, thread); else result = field.DeclaringType.GetValue(field); else result = mirror.GetValue(field); } return result; }
public Value NewInstance(ThreadMirror thread, MethodMirror method, IList <Value> arguments, InvokeOptions options) { return(ObjectMirror.InvokeMethod(vm, thread, method, null, arguments, options)); }
public Value InvokeMethod(ThreadMirror thread, MethodMirror method, IList <Value> arguments, InvokeOptions options) { return(ObjectMirror.InvokeMethod(vm, thread, method, this, arguments, options)); }
public IAsyncResult BeginInvokeMethod(ThreadMirror thread, MethodMirror method, IList <Value> arguments, InvokeOptions options, AsyncCallback callback, object state) { return(ObjectMirror.BeginInvokeMethod(vm, thread, method, this, arguments, options, callback, state)); }
public Value EndInvokeMethod(IAsyncResult asyncResult) { return(ObjectMirror.EndInvokeMethodInternal(asyncResult)); }
internal T GetObject <T> (long id, long domain_id, long type_id) where T : ObjectMirror { ObjectMirror obj = null; lock (objects_lock) { if (objects == null) { objects = new Dictionary <long, ObjectMirror> (); } objects.TryGetValue(id, out obj); } if (obj == null) { /* * Obtain the domain/type of the object to determine the type of * object we need to create. Do this outside the lock. */ if (domain_id == 0 || type_id == 0) { if (conn.Version.AtLeast(2, 5)) { var info = conn.Object_GetInfo(id); domain_id = info.domain_id; type_id = info.type_id; } else { if (domain_id == 0) { domain_id = conn.Object_GetDomain(id); } if (type_id == 0) { type_id = conn.Object_GetType(id); } } } AppDomainMirror d = GetDomain(domain_id); TypeMirror t = GetType(type_id); if (t.Assembly == d.Corlib && t.Namespace == "System.Threading" && t.Name == "Thread") { obj = new ThreadMirror(this, id, t, d); } else if (t.Assembly == d.Corlib && t.Namespace == "System" && t.Name == "String") { obj = new StringMirror(this, id, t, d); } else if (typeof(T) == typeof(ArrayMirror)) { obj = new ArrayMirror(this, id, t, d); } else { obj = new ObjectMirror(this, id, t, d); } // Publish lock (objects_lock) { ObjectMirror prev_obj; if (objects.TryGetValue(id, out prev_obj)) { obj = prev_obj; } else { objects [id] = obj; } } } return((T)obj); }
public InvokeResult EndInvokeMethodWithResult(IAsyncResult asyncResult) { return(ObjectMirror.EndInvokeMethodInternalWithResult(asyncResult)); }
public static VariableItem GetChild(ThreadMirror thread, VariableItem parentItem, ObjectMirror parent, int index) { if (parent.Type.IsType("System.MulticastDelegate")) { return DoGetMulticastDelegateChild(thread, parentItem, parent, index); } // else if (parent.Type.FullName.StartsWith("System.Collections") && parent.Type.FindMethod("GetEnumerator", 0) != null) // TODO: better to use Is(ICollection) but TypeMirror does not expose interfaces // { // var child = new EnumerableValue(parentItem, parent); // return new VariableItem(thread, "Enumerable", parentItem, index, child, index); // } else { PropertyInfoMirror[] props = (from p in parent.Type.GetAllProperties() where p.ShouldDisplay() select p).ToArray(); if (index < props.Length) { PropertyInfoMirror prop = props[index]; Value child = EvalMember.Evaluate(thread, parent, prop.Name); return new VariableItem(thread, prop.Name, parentItem, prop, child, index); } else { FieldInfoMirror[] fields = (from f in parent.Type.GetAllFields() where f.ShouldDisplay() select f).ToArray(); FieldInfoMirror field = fields[index - props.Length]; Value child = EvalMember.Evaluate(thread, parent, field.Name); return new VariableItem(thread, field.Name, parentItem, field, child, index); } } }
private static Value DoEvaluateMethod(ThreadMirror thread, ObjectMirror obj, string name) { Value result = null; try { MethodMirror method = obj.Type.FindMethod(name, 0); if (method != null) { result = obj.InvokeMethod(thread, method, new Value[0], InvokeOptions.DisableBreakpoints | InvokeOptions.SingleThreaded); } } catch (Exception e) { string mesg = string.Format("{0} calling {1}.{2}", e.Message, obj.TypeName(), name); result = obj.Domain.CreateString(mesg); } return result; }
private static VariableItem DoGetMulticastDelegateChild(ThreadMirror thread, VariableItem parentItem, ObjectMirror target, int index) { Value result; FieldInfoMirror field; switch (index) { case 0: result = EvalMember.Evaluate(thread, target, "Target"); field = target.Type.GetAllFields().Single(f => f.Name == "m_target"); return new VariableItem(thread, "Target", parentItem, field, result, index); case 1: result = EvalMember.Evaluate(thread, target, "Method"); field = target.Type.GetAllFields().Single(f => f.Name == "method"); return new VariableItem(thread, "Method", parentItem, field, result, index); case 2: result = EvalMember.Evaluate(thread, target, "kpm_next"); field = target.Type.GetAllFields().Single(f => f.Name == "kpm_next"); return new VariableItem(thread, "Next", parentItem, field, result, index); case 3: result = EvalMember.Evaluate(thread, target, "prev"); field = target.Type.GetAllFields().Single(f => f.Name == "prev"); return new VariableItem(thread, "Previous", parentItem, field, result, index); default: Contract.Assert(false); return null; } }
public Value InvokeMethod(ThreadMirror thread, MethodMirror method, IList <Value> arguments) { return(ObjectMirror.InvokeMethod(vm, thread, method, null, arguments, InvokeOptions.None)); }