public static ObjectData[] GetAllObjectConnectingTo(CachedSnapshot snapshot, ObjectData obj) { var o = new List <ObjectData>(); int objIndex = -1; switch (obj.dataType) { case ObjectDataType.Array: case ObjectDataType.BoxedValue: case ObjectDataType.Object: { ManagedObjectInfo moi; if (snapshot.CrawledData.ManagedObjectByAddress.TryGetValue(obj.hostManagedObjectPtr, out moi)) { objIndex = snapshot.ManagedObjectIndexToUnifiedObjectIndex(moi.ManagedObjectIndex); //add crawled connections for (int i = 0; i != snapshot.CrawledData.Connections.Count; ++i) { var c = snapshot.CrawledData.Connections[i]; switch (c.connectionType) { case ManagedConnection.ConnectionType.Global_To_ManagedObject: if (c.toManagedObjectIndex == moi.ManagedObjectIndex) { o.Add(ObjectData.global); } break; case ManagedConnection.ConnectionType.ManagedObject_To_ManagedObject: if (c.toManagedObjectIndex == moi.ManagedObjectIndex) { var objParent = ObjectData.FromManagedObjectIndex(snapshot, c.fromManagedObjectIndex); if (c.fieldFrom >= 0) { o.Add(objParent.GetInstanceFieldBySnapshotFieldIndex(snapshot, c.fieldFrom, false)); } else if (c.arrayIndexFrom >= 0) { o.Add(objParent.GetArrayElement(snapshot, c.arrayIndexFrom, false)); } else { o.Add(objParent); } } break; case ManagedConnection.ConnectionType.ManagedType_To_ManagedObject: if (c.toManagedObjectIndex == moi.ManagedObjectIndex) { var objType = ObjectData.FromManagedType(snapshot, c.fromManagedType); if (c.fieldFrom >= 0) { o.Add(objType.GetInstanceFieldBySnapshotFieldIndex(snapshot, c.fieldFrom, false)); } else if (c.arrayIndexFrom >= 0) { o.Add(objType.GetArrayElement(snapshot, c.arrayIndexFrom, false)); } else { o.Add(objType); } } break; case ManagedConnection.ConnectionType.UnityEngineObject: if (c.UnityEngineManagedObjectIndex == moi.ManagedObjectIndex) { o.Add(ObjectData.FromNativeObjectIndex(snapshot, c.UnityEngineNativeObjectIndex)); } break; } } } break; } case ObjectDataType.NativeObject: objIndex = snapshot.NativeObjectIndexToUnifiedObjectIndex(obj.nativeObjectIndex); //add crawled connection for (int i = 0; i != snapshot.CrawledData.Connections.Count; ++i) { switch (snapshot.CrawledData.Connections[i].connectionType) { case ManagedConnection.ConnectionType.Global_To_ManagedObject: case ManagedConnection.ConnectionType.ManagedObject_To_ManagedObject: case ManagedConnection.ConnectionType.ManagedType_To_ManagedObject: break; case ManagedConnection.ConnectionType.UnityEngineObject: if (snapshot.CrawledData.Connections[i].UnityEngineNativeObjectIndex == obj.nativeObjectIndex) { o.Add(ObjectData.FromManagedObjectIndex(snapshot, snapshot.CrawledData.Connections[i].UnityEngineManagedObjectIndex)); } break; } } break; default: return(null); } //add connections from the raw snapshot if (objIndex >= 0) { for (int i = 0; i != snapshot.connections.Count; ++i) { if (snapshot.connections.to[i] == objIndex) { o.Add(ObjectData.FromUnifiedObjectIndex(snapshot, snapshot.connections.from[i])); } } } return(o.ToArray()); }
// Returns a new ObjectData pointing to the object's (that this ObjectData is currently pointing at) field // using a field index from snapshot.fieldDescriptions public ObjectData GetInstanceFieldBySnapshotFieldIndex(CachedSnapshot snapshot, int iField, bool expandToTarget) { ObjectData obj; ulong objectPtr; switch (m_dataType) { case ObjectDataType.ReferenceObject: objectPtr = GetReferencePointer(); obj = FromManagedPointer(snapshot, objectPtr); break; case ObjectDataType.BoxedValue: case ObjectDataType.Object: case ObjectDataType.Value: objectPtr = m_data.managed.objectPtr; obj = this; break; //case ObjectDataType.ReferenceArray: default: //TODO: add proper handling for missing types //DebugUtility.LogError("Requesting a field on an invalid data type"); return(new ObjectData()); } var fieldOffset = snapshot.fieldDescriptions.offset[iField]; var fieldType = snapshot.fieldDescriptions.typeIndex[iField]; bool isStatic = snapshot.fieldDescriptions.isStatic[iField]; switch (m_dataType) { case ObjectDataType.Value: if (!isStatic) { fieldOffset -= snapshot.virtualMachineInformation.objectHeaderSize; } break; case ObjectDataType.Object: case ObjectDataType.BoxedValue: break; case ObjectDataType.Type: if (!isStatic) { DebugUtility.LogError("Requesting a non-static field on a type"); return(invalid); } break; default: break; } ObjectData o = new ObjectData(); o.m_Parent = new ObjectDataParent(obj, iField, -1, expandToTarget); o.SetManagedType(snapshot, fieldType); o.m_dataType = TypeToSubDataType(snapshot, fieldType); if (isStatic) { //the field requested might come from a base class. make sure we are using the right staticFieldBytes. var iOwningType = obj.m_data.managed.iType; while (iOwningType >= 0) { var fieldIndex = System.Array.FindIndex(snapshot.typeDescriptions.fieldIndicesOwned_static[iOwningType], x => x == iField); if (fieldIndex >= 0) { //field iField is owned by type iCurrentBase break; } iOwningType = snapshot.typeDescriptions.baseOrElementTypeIndex[iOwningType]; } if (iOwningType < 0) { DebugUtility.LogError("Field requested is not owned by the type not any of its bases"); return(invalid); } o.m_data.managed.objectPtr = 0; var typeStaticData = new BytesAndOffset(snapshot.typeDescriptions.staticFieldBytes[iOwningType], snapshot.virtualMachineInformation.pointerSize); o.managedObjectData = typeStaticData.Add(fieldOffset); } else { o.m_data.managed.objectPtr = objectPtr;// m_data.managed.objectPtr; o.managedObjectData = obj.managedObjectData.Add(fieldOffset); } return(o); }
public ObjectReferenceTable(Database.Schema schema, SnapshotObjectDataFormatter formatter, CachedSnapshot snapshot, ManagedData crawledData, ObjectData obj, ObjectMetaType metaType) : base(schema, formatter, snapshot, crawledData, metaType) { m_Object = obj; m_References = ObjectConnection.GetAllObjectConnectingTo(snapshot, obj); #if DEBUG_VALIDATION int toUnifiedIndex = m_Object.GetUnifiedObjectIndex(snapshot); var toManagedIndex = snapshot.UnifiedObjectIndexToManagedObjectIndex(toUnifiedIndex); for (int k = 0; k != m_References.Length; ++k) { var oFrom = m_References[k]; switch (oFrom.dataType) { case ObjectDataType.ReferenceArray: case ObjectDataType.ReferenceObject: case ObjectDataType.Value: if (oFrom.m_Parent != null) { oFrom = oFrom.m_Parent.obj; } break; } bool connectionFound = false; switch (oFrom.dataType) { case ObjectDataType.Global: { if (snapshot.HasGlobalConnection(toManagedIndex)) { connectionFound = true; } } break; case ObjectDataType.Type: { if (snapshot.HasManagedTypeConnection(oFrom.managedTypeIndex, toManagedIndex)) { connectionFound = true; } } break; case ObjectDataType.Array: case ObjectDataType.BoxedValue: case ObjectDataType.Object: { if (snapshot.HasObjectConnection(oFrom.GetUnifiedObjectIndex(snapshot), toUnifiedIndex)) { connectionFound = true; break; } } break; case ObjectDataType.NativeObject: { if (snapshot.HasObjectConnection(oFrom.GetUnifiedObjectIndex(snapshot), toUnifiedIndex)) { connectionFound = true; break; } } break; } if (!connectionFound) { UnityEngine.Debug.LogError("Connection not found, index =" + k); } } #endif InitObjectList(); }
internal static ObjectData[] GetAllObjectConnectingFrom(CachedSnapshot snapshot, ObjectData obj) { //TODO var o = new List <ObjectData>(); //int objIndex = -1; //switch (obj.dataType) //{ // case ObjectDataType.Array: // case ObjectDataType.BoxedValue: // case ObjectDataType.Object: // { // ManagedObjectInfo moi; // if (snapshot.m_CrawledData.managedObjectByAddress.TryGetValue(obj.hostManagedObjectPtr, out moi)) // { // objIndex = moi.managedObjectIndex; // //add crawled connections // for (int i = 0; i != snapshot.m_CrawledData.connections.Length; ++i) // { // switch (snapshot.m_CrawledData.connections[i].connectionType) // { // case ManagedConnection.ConnectionType.ManagedObject_To_ManagedObject: // if (snapshot.m_CrawledData.connections[i].fromManagedObjectIndex == objIndex) // { // o.Add(ObjectData.FromManagedObjectIndex(snapshot, snapshot.m_CrawledData.connections[i].toManagedObjectIndex)); // } // break; // case ManagedConnection.ConnectionType.Global_To_ManagedObject: // case ManagedConnection.ConnectionType.ManagedType_To_ManagedObject: // break; // } // } // } // break; // } // case ObjectDataType.Type: // for (int i = 0; i != snapshot.m_CrawledData.connections.Length; ++i) // { // switch (snapshot.m_CrawledData.connections[i].connectionType) // { // case ManagedConnection.ConnectionType.ManagedType_To_ManagedObject: // if (snapshot.m_CrawledData.connections[i].fromManagedType == obj.managedTypeIndex) // { // o.Add(ObjectData.FromManagedObjectIndex(snapshot, snapshot.m_CrawledData.connections[i].toManagedObjectIndex)); // } // break; // case ManagedConnection.ConnectionType.Global_To_ManagedObject: // case ManagedConnection.ConnectionType.ManagedObject_To_ManagedObject: // break; // } // } // break; // case ObjectDataType.NativeObject: // objIndex = obj.nativeObjectIndex; // //for (int i = 0; i != snapshot.m_CrawledData.connections.Length; ++i) // //{ // // if (snapshot.m_CrawledData.connections[i].fromPtr == obj.hostManagedObjectPtr) // // { // // o.Add(ObjectData.FromManagedPointer(snapshot, snapshot.m_CrawledData.connections[i].toPtr)); // // } // //} // break; // default: // return null; //} //if (objIndex >= 0) //{ // for (int i = 0; i != snapshot.connections.Count; ++i) // { // if (snapshot.connections.from[i] == objIndex) // { // o.Add(ObjectData.FromUnifiedObjectIndex(snapshot, snapshot.connections.to[i])); // } // } //} return(o.ToArray()); }
public ObjectFieldTable(Schema schema, SnapshotObjectDataFormatter formatter, CachedSnapshot snapshot, ManagedData crawledData, ObjectData obj, ObjectMetaType metaType) : base(schema, formatter, snapshot, crawledData, metaType) { this.obj = obj; objBase = obj.GetBase(snapshot); SetFieldsList(BuildFieldList()); InitObjectList(); }