コード例 #1
0
        internal Value DecodeValue(ValueImpl v, Dictionary <int, Value> parent_vtypes)
        {
            if (v.Value != null)
            {
                if (Version.AtLeast(2, 46) && v.Type == ElementType.Ptr)
                {
                    return(new PointerValue(this, GetType(v.Klass), (long)v.Value));
                }
                return(new PrimitiveValue(this, v.Value));
            }

            switch (v.Type)
            {
            case ElementType.Void:
                return(null);

            case ElementType.SzArray:
            case ElementType.Array:
                return(GetObject <ArrayMirror> (v.Objid));

            case ElementType.String:
                return(GetObject <StringMirror> (v.Objid));

            case ElementType.Class:
            case ElementType.Object:
                return(GetObject(v.Objid));

            case ElementType.ValueType:
                if (parent_vtypes == null)
                {
                    parent_vtypes = new Dictionary <int, Value> ();
                }
                StructMirror vtype;
                if (v.IsEnum)
                {
                    vtype = new EnumMirror(this, GetType(v.Klass), (Value[])null);
                }
                else
                {
                    vtype = new StructMirror(this, GetType(v.Klass), (Value[])null);
                }
                parent_vtypes [parent_vtypes.Count] = vtype;
                vtype.SetFields(DecodeValues(v.Fields, parent_vtypes));
                parent_vtypes.Remove(parent_vtypes.Count - 1);
                return(vtype);

            case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
                return(new PrimitiveValue(this, null));

            case (ElementType)ValueTypeId.VALUE_TYPE_ID_PARENT_VTYPE:
                return(parent_vtypes [v.Index]);

            default:
                throw new NotImplementedException("" + v.Type);
            }
        }
コード例 #2
0
ファイル: InstanceValue.cs プロジェクト: andyhebear/Continuum
        public InstanceValue(StructMirror 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());
        }
コード例 #3
0
 public static TypeMirror GetType(StructMirror parent, int key)
 {
     PropertyInfoMirror[] props = (from p in parent.Type.GetAllProperties() where p.ShouldDisplay() select p).ToArray();
     if (key < props.Length)
     {
         PropertyInfoMirror prop = props[key];
         return prop.PropertyType;
     }
     else
     {
         FieldInfoMirror[] fields = (from f in parent.Type.GetAllFields() where f.ShouldDisplay() select f).ToArray();
         FieldInfoMirror field = fields[key - props.Length];
         return field.FieldType;
     }
 }
コード例 #4
0
 public static VariableItem GetChild(ThreadMirror thread, VariableItem parentItem, StructMirror parent, int index)
 {
     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;
         if (field.IsStatic)
             if (field.HasCustomAttribute("System.ThreadStaticAttribute"))
                 child = parent.Type.GetValue(field, thread);
             else
                 child = parent.Type.GetValue(field);
         else
             child = parent.Fields[index - props.Length];
         return new VariableItem(thread, field.Name, parentItem, index, child, index);
     }
 }
コード例 #5
0
 public static void Set(ThreadMirror thread, VariableItem item, StructMirror parent, int key, Value newValue)
 {
     FieldInfoMirror[] fields = parent.Type.GetFields();
     if (fields[key].IsStatic)
     {
         parent.Type.SetValue(fields[key], newValue);
     }
     else
     {
         parent.Fields[key] = newValue;
         SetValue.Invoke(thread, item.Parent, item.Parent.Parent.Value, item.Parent.Key, parent);
     }
 }
コード例 #6
0
ファイル: TraceRoots.cs プロジェクト: andyhebear/Continuum
        // TODO: Should special case the target of GCHandle, but only if it is not a weak reference
        // (and it is far from clear how to determine the GCHandleType).
        private void DoWalkStruct(StructMirror value, Trace parent)
        {
            if (DoShouldWalkType(value.Type))
            {
                foreach (FieldInfoMirror field in value.Type.GetFields())
                {
                    if (!field.IsStatic && DoShouldWalkType(field.FieldType))
                    {
                        Log.WriteLine(TraceLevel.Verbose, "TraceRoots", "struct {0}.{1} [{2}]", field.DeclaringType.FullName, field.Name, field.FieldType.FullName);
                        Log.Indent();

                        Value v = value[field.Name];
                        var child = new Trace(field.Name, field.FieldType.FullName, v);
                        DoWalkValue(v, child, field.Name);
                        parent.Children.Add(child);

                        Log.Unindent();
                    }
                }
            }
        }
コード例 #7
0
ファイル: InvokeMethod.cs プロジェクト: andyhebear/Continuum
        private Value DoInvoke(ThreadMirror thread, StructMirror obj, string name)
        {
            Value result = null;

            MethodMirror method = obj.Type.ResolveProperty(name);
            if (method == null)
                method = obj.Type.FindMethod(name, 0);

            if (method != null)
            {
                if (!Debugger.IsTypeLoaded(method.DeclaringType.FullName))
                {
                    // TODO: The soft debugger was timing out when calling BeginInvokeMethod and
                    // then locking up when CreateString was called. This works around that problem,
                    // but not in a good way because it's possible that the ToString will use fields which
                    // have types which are not loaded.
                    result = thread.Domain.CreateString("type not loaded");
                }
                else if (obj.Type.IsPrimitive)
                {
                    // Boxed primitive (we need this special case or BeginInvokeMethod will hang).
                    if (obj.Fields.Length > 0 && (obj.Fields[0] is PrimitiveValue))
                    {
                        if (name == "ToString")
                        {
                            PrimitiveValue value = (PrimitiveValue) (obj.Fields[0]);
                            result = thread.Domain.CreateString(value.Value.ToString());
                        }
                    }

                    if (result == null)
                        throw new Exception(string.Format("{0} is a primitive type and only ToString can be used on those.", obj.Type.FullName));
                }
                else
                {
                    IAsyncResult ar;
                    Func<Value> getter;
                    if (method.IsStatic)
                    {
                        ar = method.DeclaringType.BeginInvokeMethod(thread, method, new Value[0], InvokeOptions.DisableBreakpoints | InvokeOptions.SingleThreaded, null, null);
                        getter = () => method.DeclaringType.EndInvokeMethod(ar);
                    }
                    else
                    {
                        ar = obj.BeginInvokeMethod(thread, method, new Value[0], InvokeOptions.DisableBreakpoints | InvokeOptions.SingleThreaded, null, null);
                        getter = () =>
                        {
                            Value vvv = null;
                            vvv = obj.EndInvokeMethod(ar);
                            return vvv;
                        };
                    }

                    if (!ar.IsCompleted)
                        ar.AsyncWaitHandle.WaitOne(Timeout);

                    if (ar.IsCompleted)
                    {
                        result = getter();
                    }
                    else
                    {
                        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;
        }
コード例 #8
0
ファイル: EvalMember.cs プロジェクト: andyhebear/Continuum
        private static Value DoGetField(StructMirror 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 = mirror.Type.GetValue(field, thread);
                    else
                        result = mirror.Type.GetValue(field);
                else
                    result = mirror[name];
            }

            return result;
        }
コード例 #9
0
ファイル: EvalMember.cs プロジェクト: andyhebear/Continuum
        private static Value DoEvaluateProperty(ThreadMirror thread, StructMirror obj, string name)
        {
            Value result = null;

            MethodMirror method = obj.Type.ResolveProperty(name);
            if (method != null)
            {
                if (method.IsStatic)
                    result = method.DeclaringType.InvokeMethod(thread, method, new Value[0], InvokeOptions.DisableBreakpoints | InvokeOptions.SingleThreaded);
                else
                    result = obj.InvokeMethod(thread, method, new Value[0], InvokeOptions.DisableBreakpoints | InvokeOptions.SingleThreaded);
            }

            return result;
        }