public static ObjectData FromManagedPointer(CachedSnapshot snapshot, ulong ptr, int asTypeIndex = -1) { if (ptr == 0) { return(ObjectData.invalid); } ManagedObjectInfo moi; if (snapshot.CrawledData.ManagedObjectByAddress.TryGetValue(ptr, out moi)) { return(FromManagedObjectInfo(snapshot, moi)); } else { ObjectData o = new ObjectData(); o.m_data.managed.objectPtr = ptr; o.managedObjectData = snapshot.managedHeapSections.Find(ptr, snapshot.virtualMachineInformation); if (o.managedObjectData.IsValid) { var info = Crawler.ParseObjectHeader(snapshot, o.managedObjectData, false); if (asTypeIndex >= 0) { o.SetManagedType(snapshot, asTypeIndex); } else { o.SetManagedType(snapshot, info.ITypeDescription); } o.m_dataType = TypeToDataType(snapshot, info.ITypeDescription); return(o); } } return(invalid); }
public static ObjectData FromManagedType(CachedSnapshot snapshot, int iType) { ObjectData o = new ObjectData(); o.SetManagedType(snapshot, iType); o.m_dataType = ObjectDataType.Type; o.managedObjectData = new BytesAndOffset { bytes = snapshot.typeDescriptions.staticFieldBytes[iType], offset = 0, pointerSize = snapshot.virtualMachineInformation.pointerSize }; return(o); }
public static ObjectData FromManagedObjectInfo(CachedSnapshot snapshot, ManagedObjectInfo moi) { if (moi.ITypeDescription < 0) { return(ObjectData.invalid); } ObjectData o = new ObjectData(); o.m_dataType = TypeToDataType(snapshot, moi.ITypeDescription);// ObjectDataType.Object; o.m_data.managed.objectPtr = moi.PtrObject; o.SetManagedType(snapshot, moi.ITypeDescription); o.managedObjectData = moi.data; return(o); }
public ObjectData GetArrayElement(CachedSnapshot snapshot, ArrayInfo ai, int index, bool expandToTarget) { switch (m_dataType) { case ObjectDataType.Array: case ObjectDataType.ReferenceArray: break; default: Debug.Log("Requesting an array element on an invalid data type"); return(invalid); } ObjectData o = new ObjectData(); o.m_Parent = new ObjectDataParent(this, -1, index, expandToTarget); o.SetManagedType(snapshot, ai.elementTypeDescription); o.m_data.managed.objectPtr = m_data.managed.objectPtr; o.m_dataType = TypeToSubDataType(snapshot, ai.elementTypeDescription); o.managedObjectData = ai.GetArrayElement(index); return(o); }
public ObjectData GetBase(CachedSnapshot snapshot) { switch (m_dataType) { case ObjectDataType.ReferenceObject: case ObjectDataType.Object: case ObjectDataType.Type: break; case ObjectDataType.Value: return(invalid); default: UnityEngine.Debug.LogError("Requesting a base on an invalid data type"); return(invalid); } var b = snapshot.typeDescriptions.baseOrElementTypeIndex[m_data.managed.iType]; if (b == snapshot.typeDescriptions.iType_ValueType) { return(invalid); } if (b == snapshot.typeDescriptions.iType_Object) { return(invalid); } if (b == snapshot.typeDescriptions.iType_Enum) { return(invalid); } ObjectData o = this; o.SetManagedType(snapshot, b); return(o); }
// 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: case ObjectDataType.Type: 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) { Debug.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) { Debug.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); }