示例#1
0
            public void Initialize(ConnectionsControl owner, PackedMemorySnapshot snapshot, int arrayIndex)
            {
                m_Owner       = owner;
                m_Snapshot    = snapshot;
                m_StaticField = m_Snapshot.managedStaticFields[arrayIndex];

                displayName = m_Snapshot.managedTypes[m_StaticField.managedTypesArrayIndex].name;
                address     = 0;
                m_Value     = "static " + m_Snapshot.managedTypes[m_StaticField.managedTypesArrayIndex].name + "." + m_Snapshot.managedTypes[m_StaticField.managedTypesArrayIndex].fields[m_StaticField.fieldIndex].name;
            }
示例#2
0
        void AddStaticField(TreeViewItem parent, PackedManagedStaticField staticField)
        {
            var item = new ManagedStaticFieldItem
            {
                id    = m_UniqueId++,
                depth = parent.depth + 1,
            };

            item.Initialize(this, m_Snapshot, staticField.staticFieldsArrayIndex);
            parent.AddChild(item);
        }
        public void GetConnections(PackedManagedStaticField staticField, List <PackedConnection> references, List <PackedConnection> referencedBy)
        {
            var index = staticField.staticFieldsArrayIndex;

            if (index == -1)
            {
                return;
            }

            GetConnectionsInternal(PackedConnection.Kind.StaticField, index, references, referencedBy);
        }
示例#4
0
            public void Initialize(RootPathControl owner, PackedMemorySnapshot snapshot, int arrayIndex)
            {
                m_Owner       = owner;
                m_Snapshot    = snapshot;
                m_StaticField = m_Snapshot.managedStaticFields[arrayIndex];

                var staticClassType = m_Snapshot.managedTypes[m_StaticField.managedTypesArrayIndex];
                var staticField     = staticClassType.fields[m_StaticField.fieldIndex];

                m_Address   = 0;
                displayName = staticClassType.name;
                m_Value     = "static " + staticField.name;
            }
示例#5
0
 public ObjectProxy(PackedMemorySnapshot snp, PackedManagedStaticField packed)
 {
     snapshot    = snp;
     staticField = new RichStaticField(snp, packed.staticFieldsArrayIndex);
 }
        void CrawlStatic()
        {
            var crawlStatic        = new List <int>();
            var managedTypes       = m_Snapshot.managedTypes;
            var staticManagedTypes = new List <int>(1024);

            // Unity BUG: (Case 984330) PackedMemorySnapshot: Type contains staticFieldBytes, but has no static field
            for (int n = 0, nend = managedTypes.Length; n < nend; ++n)
            {
                var type = managedTypes[n];

                // Some static classes have no staticFieldBytes. As I understand this, the staticFieldBytes
                // are only filled if that static class has been initialized (its cctor called), otherwise it's zero.
                if (type.staticFieldBytes == null || type.staticFieldBytes.Length == 0)
                {
                    continue;
                }

                //var hasStaticField = false;
                for (int j = 0, jend = type.fields.Length; j < jend; ++j)
                {
                    if (!type.fields[j].isStatic)
                    {
                        continue;
                    }

                    //var field = type.fields[j];
                    //var fieldType = managedTypes[field.managedTypesArrayIndex];
                    //hasStaticField = true;

                    var item = new PackedManagedStaticField
                    {
                        managedTypesArrayIndex = type.managedTypesArrayIndex,
                        fieldIndex             = j,
                        staticFieldsArrayIndex = m_StaticFields.Count,
                    };
                    m_StaticFields.Add(item);

                    crawlStatic.Add(item.staticFieldsArrayIndex);
                }

                //if (hasStaticField)
                staticManagedTypes.Add(type.managedTypesArrayIndex);
            }

            m_Snapshot.managedStaticTypes = staticManagedTypes.ToArray();

            //var loopGuard = 0;
            while (crawlStatic.Count > 0)
            {
                //if (++loopGuard > 100000)
                //{
                //    m_snapshot.Error("Loop-guard kicked in while analyzing static fields.");
                //    break;
                //}

                m_TotalCrawled++;
                if ((m_TotalCrawled % 1000) == 0)
                {
                    UpdateProgress();
                    if (m_Snapshot.abortActiveStepRequested)
                    {
                        break;
                    }
                }

                var staticField = m_StaticFields[crawlStatic[crawlStatic.Count - 1]];
                crawlStatic.RemoveAt(crawlStatic.Count - 1);

                var staticClass  = m_Snapshot.managedTypes[staticField.managedTypesArrayIndex];
                var field        = staticClass.fields[staticField.fieldIndex];
                var fieldType    = m_Snapshot.managedTypes[field.managedTypesArrayIndex];
                var staticReader = new StaticMemoryReader(m_Snapshot, staticClass.staticFieldBytes);

                if (fieldType.isValueType)
                {
                    if (staticClass.staticFieldBytes == null || staticClass.staticFieldBytes.Length == 0)
                    {
                        continue;
                    }

                    var newObj = PackedManagedObject.New();
                    newObj.address = (ulong)field.offset;
                    // BUG: TODO: If staticFieldsArrayIndex=0, then it's detected as managedObject rather than staticField?
                    newObj.managedObjectsArrayIndex = -staticField.staticFieldsArrayIndex;
                    newObj.managedTypesArrayIndex   = fieldType.managedTypesArrayIndex;
                    newObj.staticBytes = staticClass.staticFieldBytes;
                    SetObjectSize(ref newObj, fieldType);

                    m_Crawl.Add(newObj);
                    m_TotalCrawled++;
                    continue;
                }

                // If it's a reference type, it simply points to a ManagedObject on the heap and all
                // we need to do it to create a new ManagedObject and add it to the list to crawl.
                if (!fieldType.isValueType)
                {
                    var addr = staticReader.ReadPointer((uint)field.offset);
                    if (addr == 0)
                    {
                        continue;
                    }

#if DEBUG_BREAK_ON_ADDRESS
                    if (addr == DebugBreakOnAddress)
                    {
                        int a = 0;
                    }
#endif

                    int newObjIndex;
                    if (!m_Seen.TryGetValue(addr, out newObjIndex))
                    {
                        var newObj = PackedManagedObject.New();
                        newObj.address = addr;
                        newObj.managedObjectsArrayIndex = m_ManagedObjects.Count;

                        // The static field could be a basetype, such as UnityEngine.Object, but actually point to a Texture2D.
                        // Therefore it's important to find the type of the specified address, rather than using the field type.
                        newObj.managedTypesArrayIndex = m_Snapshot.FindManagedObjectTypeOfAddress(addr);
                        if (newObj.managedTypesArrayIndex == -1)
                        {
                            newObj.managedTypesArrayIndex = fieldType.managedTypesArrayIndex;
                        }

                        // Check if the object has a GCHandle
                        var gcHandleIndex = m_Snapshot.FindGCHandleOfTargetAddress(addr);
                        if (gcHandleIndex != -1)
                        {
                            newObj.gcHandlesArrayIndex = gcHandleIndex;
                            m_Snapshot.gcHandles[gcHandleIndex].managedObjectsArrayIndex = newObj.managedObjectsArrayIndex;

                            m_Snapshot.AddConnection(PackedConnection.Kind.GCHandle, gcHandleIndex, PackedConnection.Kind.Managed, newObj.managedObjectsArrayIndex);
                        }
                        SetObjectSize(ref newObj, managedTypes[newObj.managedTypesArrayIndex]);
                        TryConnectNativeObject(ref newObj);

                        m_ManagedObjects.Add(newObj);
                        m_Seen[newObj.address] = newObj.managedObjectsArrayIndex;
                        m_Crawl.Add(newObj);
                        m_TotalCrawled++;
                        newObjIndex = newObj.managedObjectsArrayIndex;
                    }

                    m_Snapshot.AddConnection(PackedConnection.Kind.StaticField, staticField.staticFieldsArrayIndex, PackedConnection.Kind.Managed, newObjIndex);

                    continue;
                }
            }
        }
 public void Inspect(PackedManagedStaticField item)
 {
     ScheduleJob(new ObjectProxy(snapshot, item));
 }