Skip to content

Commit 39bae18

Browse files
committed
Fixup support for newer (> 2022) versions.
1 parent e88ab71 commit 39bae18

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

UMS.Analysis/Structures/Objects/StringFieldValue.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public StringFieldValue(SnapshotFile file, Span<byte> data)
3838
data = managedObjectInfo.Data;
3939

4040
var offset = file.VirtualMachineInformation.ObjectHeaderSize + 4;
41+
42+
if(offset > data.Length)
43+
{
44+
FailedToParse = true;
45+
FailedParseFromPtr = ptr;
46+
return;
47+
}
48+
4149
var stringPtr = data[offset..];
4250

4351
var end = stringPtr.LastIndexOf(new byte[] { 0, 0 });

UMS.LowLevel/LowLevelSnapshotFile.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ public unsafe LowLevelSnapshotFile(string path)
8686
ReadMetadataForAllChapters(entryTypeToChapterOffset);
8787

8888
VirtualMachineInformation = ReadChapterAsStruct<VirtualMachineInformation>(EntryType.Metadata_VirtualMachineInformation);
89+
90+
var areHeapAddressesEncoded = SnapshotFormatVersion >= FormatVersion.MemLabelSizeAndHeapIdVersion;
91+
8992
ManagedHeapSectionStartAddresses = ReadValueTypeChapter<ulong>(EntryType.ManagedHeapSections_StartAddress, 0, -1).ToArray()
90-
.Select((a, i) => new ManagedHeapSection(a, ReadChapterBody(EntryType.ManagedHeapSections_Bytes, i, 1)))
93+
.Select((a, i) => new ManagedHeapSection(a, areHeapAddressesEncoded, ReadChapterBody(EntryType.ManagedHeapSections_Bytes, i, 1)))
9194
.ToArray();
9295

9396
Array.Sort(ManagedHeapSectionStartAddresses);

UMS.LowLevel/Structures/EntryType.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,23 @@ public enum EntryType : ushort
8686
NativeAllocatorInfo_PeakUsedSize,
8787
NativeAllocatorInfo_AllocationCount,
8888
NativeAllocatorInfo_Flags, //80
89+
// NativeObjectMetaDataVersion = 15
90+
// Adds meta data
91+
ObjectMetaData_MetaDataBufferIndicies,
92+
ObjectMetaData_MetaDataBuffer,
93+
// SystemMemoryRegionsVersion = 16
94+
// Adds system memory regions
95+
SystemMemoryRegions_Address,
96+
SystemMemoryRegions_Size,
97+
SystemMemoryRegions_Resident,
98+
SystemMemoryRegions_Type,
99+
SystemMemoryRegions_Name,
100+
// SystemMemoryResidentPagesVersion = 17
101+
// Adds system memory resident pages
102+
SystemMemoryResidentPages_Address,
103+
SystemMemoryResidentPages_FirstPageIndex,
104+
SystemMemoryResidentPages_LastPageIndex,
105+
SystemMemoryResidentPages_PagesState,
106+
SystemMemoryResidentPages_PageSize,
89107
Count, //used to keep track of entry count, only add c++ matching entries above this one
90108
}

UMS.LowLevel/Structures/FormatVersion.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ public enum FormatVersion : uint
66
NativeConnectionsAsInstanceIdsVersion = 10, //native object collection reworked, added new gchandleIndex array to native objects for fast managed object access (2019.3 or newer?)
77
ProfileTargetInfoAndMemStatsVersion = 11, //added profile target info and memory summary struct (shortly before 2021.2.0a12 on 2021.2, backported together with v.12)
88
MemLabelSizeAndHeapIdVersion = 12, //added gc heap / vm heap identification encoded within each heap address and memory label size reporting (2021.2.0a12, 2021.1.9, 2020.3.12f1, 2019.4.29f1 or newer)
9+
// below are present from 2022.2+
910
SceneRootsAndAssetBundlesVersion = 13, //added scene roots and asset bundle relations (not yet landed)
10-
GfxResourceReferencesAndAllocatorsVersion = 14 //added gfx resource to root mapping and allocators information (including extra allocator information to memory labels)
11+
GfxResourceReferencesAndAllocatorsVersion = 14, //added gfx resource to root mapping and allocators information (including extra allocator information to memory labels)
12+
NativeObjectMetaDataVersion = 15, // adds the ability to get meta data for native objects
13+
SystemMemoryRegionsVersion = 16, // adds system memory regions information
14+
// below are present from 2023.1+
15+
SystemMemoryResidentPagesVersion = 17, // adds system memory resident pages information
1116
}

UMS.LowLevel/Structures/ManagedHeapSection.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22

33
public class ManagedHeapSection : IComparable
44
{
5+
private const ulong referenceBit = 1UL << 63;
6+
57
public ulong VirtualAddress;
68
public ulong VirtualAddressEnd;
79
public byte[] Heap;
810

9-
public ManagedHeapSection(ulong virtualAddress, byte[] heap)
11+
public bool IsVmSection;
12+
13+
public ManagedHeapSection(ulong virtualAddress, bool areAddressesEncoded, byte[] heap)
1014
{
11-
VirtualAddress = virtualAddress;
15+
if (areAddressesEncoded)
16+
{
17+
VirtualAddress = virtualAddress & ~referenceBit;
18+
IsVmSection = (virtualAddress & referenceBit) != 0;
19+
}
20+
else
21+
{
22+
VirtualAddress = virtualAddress;
23+
IsVmSection = false;
24+
}
25+
1226
Heap = heap;
1327
VirtualAddressEnd = VirtualAddress + (ulong) Heap.Length;
1428
}

0 commit comments

Comments
 (0)