public static HeapDumpSegment Deserialize(this HeapDumpSegment input, BinaryReader br) { (input as HeapRawData).Deserialize(br); if (input.RawData[0] == (byte)DumpObjectTag.HEAP_INFO) { input.SegmentType = DumpSegmentType.ObjectInstance; int startIndex = 1; //原本正常的情况 input.HeapInfo = new HeapInfo().Deserialize(input.RawData, ref startIndex); //原本正常的情况 input.HeapDumpObjects = new List <HeapDumpObject>(); //int startIndex = 0; //学长的特殊情况,不导出HeapInfo while (startIndex < input.RawData.Length) { HeapDumpObject newObject = null; var flag = input.RawData[startIndex]; ++startIndex; switch (flag) { case (byte)DumpObjectTag.CLASS_OBJECT: newObject = new DumpClassObject().Deserialize(input.RawData, ref startIndex, input); break; case (byte)DumpObjectTag.OBJECT_ARRAY: newObject = new DumpObjectArray().Deserialize(input.RawData, ref startIndex); break; case (byte)DumpObjectTag.OBJECT_INSTANCE: newObject = new DumpObjectInstance().Deserialize(input.RawData, ref startIndex); break; case (byte)DumpObjectTag.PRIMITIVE_ARRAY_WITH_DATA: newObject = new DumpPrimitiveArray().Deserialize(input.RawData, ref startIndex); break; case (byte)DumpObjectTag.PRIMITIVE_ARRAY_WITHOUT_DATA: newObject = new DumpPrimitiveArrayNoData().Deserialize(input.RawData, ref startIndex); break; default: throw new Exception("尚未处理的Dump类型: " + input.RawData[startIndex]); } input.HeapDumpObjects.Add(newObject); } } else { input.SegmentType = DumpSegmentType.RootSet; } return(input); }
internal override void Process(ProfilerSession sess) { if (sess.m_currentHeapDump == null) { //Lost heap-dump start packet, and probably the roots too. throw new System.IO.IOException(); } HeapDumpObject hdo = new HeapDumpObject(); hdo.m_address = m_address; hdo.m_size = m_size; if (m_dt == _DBG.RuntimeDataType.DATATYPE_CLASS || m_dt == _DBG.RuntimeDataType.DATATYPE_VALUETYPE) { sess.ResolveTypeName(m_typedef); //Cache type name. hdo.m_type = new ObjectType(m_typedef); } else { _DBG.RuntimeDataType dt = (_DBG.RuntimeDataType)m_dt; if (dt == _DBG.RuntimeDataType.DATATYPE_SZARRAY) { sess.ResolveTypeName(m_arrayElementType); //Cache type name. hdo.m_type = new ObjectType(m_arrayElementType, m_arrayLevels); } else { hdo.m_type = new ObjectType((uint)m_dt); } } hdo.m_references = m_refs; Tracing.PacketTrace("object @ {0} ({1})", m_address, hdo.m_type); sess.m_currentHeapDump.m_objectTable.Add(hdo); }