Esempio n. 1
0
        public void Inspect(PackedMemorySnapshot snapshot, PackedManagedObject managedObject)
        {
            m_Snapshot = snapshot;
            var m_type    = snapshot.managedTypes[managedObject.managedTypesArrayIndex];
            var m_address = managedObject.address;

            if (m_type.isValueType)
            {
                m_address -= (ulong)m_Snapshot.virtualMachineInformation.objectHeaderSize;
            }

            var root = new TreeViewItem {
                id = 0, depth = -1, displayName = "Root"
            };

            if (m_Snapshot == null)
            {
                root.AddChild(new TreeViewItem {
                    id = 1, depth = -1, displayName = ""
                });
                return;
            }

            var args = new PropertyGridItem.BuildChildrenArgs();

            args.parent       = root;
            args.type         = m_type;
            args.address      = m_address;
            args.memoryReader = new MemoryReader(snapshot);

            AddType(args);

            // add at least one item to the tree, otherwise it outputs an error
            if (!root.hasChildren)
            {
                root.AddChild(new TreeViewItem(1, 0, ""));
            }

            SetTree(root);
            TryCreateDataVisualizer(args.memoryReader, args.type, args.address, false);
        }
Esempio n. 2
0
        public void InspectStaticType(PackedMemorySnapshot snapshot, PackedManagedType managedType)
        {
            m_Snapshot = snapshot;
            var m_type    = managedType;
            var m_address = 0ul;

            var root = new TreeViewItem {
                id = 0, depth = -1, displayName = "Root"
            };

            if (m_Snapshot == null)
            {
                root.AddChild(new TreeViewItem {
                    id = 1, depth = -1, displayName = ""
                });
                return;
            }

            var args = new PropertyGridItem.BuildChildrenArgs();

            args.parent       = root;
            args.type         = m_type;
            args.address      = m_address;
            args.memoryReader = new StaticMemoryReader(snapshot, managedType.staticFieldBytes);

            AddType(args);

            // add at least one item to the tree, otherwise it outputs an error
            if (!root.hasChildren)
            {
                root.AddChild(new TreeViewItem(1, 0, ""));
            }

            SetTree(root);
            TryCreateDataVisualizer(args.memoryReader, args.type, args.address, false);
        }
Esempio n. 3
0
        void AddType(PropertyGridItem.BuildChildrenArgs args)
        {
            var target      = args.parent;
            var type        = args.type;
            var address     = args.address;
            var reader      = args.memoryReader;
            var addStatic   = reader is StaticMemoryReader;
            var addInstance = !addStatic;

            if (target.depth > 64)
            {
                Debug.LogFormat("recursive reference found? type: {0}", type.name);
                return;
            }

            // Add the base class, if any, to the tree.
            if (type.isDerivedReferenceType && !type.isArray)
            {
                var baseType       = m_Snapshot.managedTypes[type.baseOrElementTypeIndex];
                var isSystemObject = baseType.managedTypesArrayIndex == m_Snapshot.coreTypes.systemObject;
                if (!isSystemObject && PackedManagedTypeUtility.HasTypeOrBaseAnyField(m_Snapshot, baseType, !addStatic, addStatic))
                {
                    var item = new BaseClassPropertyGridItem(this, m_Snapshot, address, reader)
                    {
                        depth = target.depth + 1,
                        type  = baseType
                    };
                    item.Initialize();

                    target.AddChild(item);
                }
            }

            // Array
            if (type.isArray)
            {
                // Normally the baseOrElementTypeIndex of an array represents the element type.
                // If inspecting static generic fields though, there is no element type available for '_EmptyArray'.
                // class ArrayList<T>
                // {
                //   static readonly T[] _EmptyArray = new T[0];
                // }
                if (type.baseOrElementTypeIndex == -1)
                {
                    return;
                }

                var pointer = address;
                var item    = new ArrayPropertyGridItem(this, m_Snapshot, pointer, reader)
                {
                    depth       = target.depth + 1,
                    type        = type,
                    displayName = type.name,
                };
                item.Initialize();

                target.AddChild(item);
                return;
            }



            for (var n = 0; n < type.fields.Length; ++n)
            {
                if (type.fields[n].isStatic && !addStatic)
                {
                    continue;
                }

                if (!type.fields[n].isStatic && !addInstance)
                {
                    continue;
                }

                var fieldType = m_Snapshot.managedTypes[type.fields[n].managedTypesArrayIndex];

                // Array
                if (fieldType.isArray)
                {
                    if (fieldType.baseOrElementTypeIndex == -1)
                    {
                        continue;
                    }

                    var pointer = reader.ReadPointer(address + (ulong)type.fields[n].offset);
                    var item    = new ArrayPropertyGridItem(this, m_Snapshot, pointer, new MemoryReader(m_Snapshot))
                    {
                        depth       = target.depth + 1,
                        type        = fieldType,
                        displayName = type.fields[n].name
                    };
                    item.Initialize();

                    target.AddChild(item);
                    continue;
                }

                // Primitive types and types derived from System.Enum
                if (fieldType.isValueType && (fieldType.isPrimitive || m_Snapshot.IsEnum(fieldType)))
                {
                    var item = new PrimitiveTypePropertyGridItem(this, m_Snapshot, address + (ulong)type.fields[n].offset, reader)
                    {
                        depth = target.depth + 1,
                        field = type.fields[n]
                    };
                    item.Initialize();

                    target.AddChild(item);
                    continue;
                }

                // Value types
                if (fieldType.isValueType)
                {
                    var item = new ValueTypePropertyGridItem(this, m_Snapshot, address + (ulong)type.fields[n].offset, reader)
                    {
                        depth = target.depth + 1,
                        field = type.fields[n]
                    };
                    item.Initialize();

                    target.AddChild(item);
                    continue;
                }

                // Reference types
                //if (fieldType.isPointer)
                {
                    var item = new ReferenceTypePropertyGridItem(this, m_Snapshot, address + (ulong)type.fields[n].offset, reader)
                    {
                        depth = target.depth + 1,
                        field = type.fields[n]
                    };
                    item.Initialize();

                    target.AddChild(item);
                    continue;
                }
            }
        }