From b039b548a979039fc343fbbbda4688f4bd703936 Mon Sep 17 00:00:00 2001 From: Max Charlamb Date: Thu, 26 Mar 2026 18:47:34 -0400 Subject: [PATCH 1/2] Convert Data classes to typed field extension methods Add TargetFieldExtensions with ReadField, ReadPointerField, ReadNUIntField, ReadCodePointerField, ReadDataField, and ReadDataFieldPointer extension methods. Each method validates the field type name from the data descriptor (when present) against the C# read type via Debug.Assert. Convert all ~110 IData classes to use the new extension methods. Fix pre-existing bugs found by the type system: - DynamicStaticsInfo.GCStatics/NonGCStatics: was uint32, is TADDR (pointer) - EEClass.FieldDescList: was Read, should be ReadPointer - ExceptionClause.ClassToken: was reading TypeHandle (nuint) as uint - SimpleComCallWrapper.RefCount: was ulong, native is LONGLONG (signed) - NativeCodeVersionNode.NativeCode: was T_POINTER, is PCODE (CodePointer) - MethodTable.EEClassOrCanonMT: was T_NUINT, managed reads as pointer Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../vm/datadescriptor/datadescriptor.inc | 8 +- .../TargetFieldExtensions.cs | 179 ++ .../Contracts/BuiltInCOM_1.cs | 4 +- .../Data/AppDomain.cs | 4 +- .../Data/ArrayListBase.cs | 6 +- .../Data/Assembly.cs | 12 +- .../Data/AssemblyBinder.cs | 2 +- .../Data/CGrowableSymbolStream.cs | 4 +- .../Data/CodeHeapListNode.cs | 12 +- .../Data/ComCallWrapper.cs | 6 +- .../Data/ComMethodTable.cs | 4 +- .../Data/CoreLibBinder.cs | 2 +- .../Data/CtxEntry.cs | 4 +- .../Data/DacEnumerableHash.cs | 2 +- .../Data/DynamicILBlobEntry.cs | 4 +- .../Data/DynamicMetadata.cs | 2 +- .../Data/DynamicStaticsInfo.cs | 4 +- .../Data/EEClass.cs | 20 +- .../Data/EEJitManager.cs | 4 +- .../Data/ExceptionClause.cs | 26 +- .../Data/ExceptionInfo.cs | 20 +- .../Data/ExceptionLookupTableEntry.cs | 4 +- .../Data/FieldDesc.cs | 6 +- .../Data/FixupPrecodeData.cs | 2 +- .../Data/GCAllocContext.cs | 8 +- .../Data/GenericsDictInfo.cs | 4 +- .../Data/HandleTable.cs | 2 +- .../Data/HandleTableBucket.cs | 2 +- .../Data/HandleTableMap.cs | 4 +- .../Data/HashMap.cs | 2 +- .../Data/ILCodeVersionNode.cs | 8 +- .../Data/ILCodeVersioningState.cs | 10 +- .../Data/IdDispenser.cs | 4 +- .../Data/ImageDataDirectory.cs | 4 +- .../Data/InflightTLSData.cs | 4 +- .../Data/InterfaceEntry.cs | 4 +- .../Data/LoaderAllocator.cs | 22 +- .../Data/ManagedObjectWrapperHolderObject.cs | 4 +- .../Data/ManagedObjectWrapperLayout.cs | 10 +- .../Data/MethodDesc.cs | 28 +- .../Data/MethodDescChunk.cs | 10 +- .../Data/MethodDescCodeData.cs | 6 +- .../Data/MethodDescVersioningState.cs | 4 +- .../Data/MethodTable.cs | 20 +- .../Data/MethodTableAuxiliaryData.cs | 6 +- .../Data/Module.cs | 28 +- .../Data/ModuleLookupMap.cs | 8 +- .../Data/NativeCodeVersionNode.cs | 12 +- .../Data/NativeObjectWrapperObject.cs | 2 +- .../Data/ObjectHeader.cs | 2 +- .../Data/PEAssembly.cs | 4 +- .../Data/PEImage.cs | 2 +- .../Data/PEImageLayout.cs | 8 +- .../Data/PatchpointInfo.cs | 2 +- .../Data/PlatformMetadata.cs | 2 +- .../Data/PortableEntryPoint.cs | 2 +- .../Data/PrecodeMachineDescriptor.cs | 16 +- .../Data/ProbeExtensionResult.cs | 2 +- .../Data/ProfControlBlock.cs | 4 +- .../Data/RCW.cs | 22 +- .../Data/RCWCleanupList.cs | 2 +- .../Data/RangeSection.cs | 14 +- .../Data/RangeSectionFragment.cs | 8 +- .../Data/ReadyToRunCoreHeader.cs | 2 +- .../Data/ReadyToRunCoreInfo.cs | 2 +- .../Data/ReadyToRunHeader.cs | 4 +- .../Data/ReadyToRunInfo.cs | 22 +- .../Data/ReadyToRunSection.cs | 2 +- .../Data/RealCodeHeader.cs | 10 +- .../Data/RuntimeFunction.cs | 6 +- .../Data/SimpleComCallWrapper.cs | 10 +- .../Data/StressLog.cs | 20 +- .../Data/StressLogChunk.cs | 8 +- .../Data/StressLogModuleDesc.cs | 4 +- .../Data/StubPrecodeData.cs | 8 +- .../Data/SyncBlock.cs | 10 +- .../Data/SyncBlockCache.cs | 4 +- .../Data/SyncTableEntry.cs | 4 +- .../Data/SystemDomain.cs | 2 +- .../Data/TLSIndex.cs | 2 +- .../Data/TableSegment.cs | 2 +- .../Data/ThisPtrRetBufPrecodeData.cs | 2 +- .../Data/Thread.cs | 39 +- .../Data/ThreadLocalData.cs | 10 +- .../Data/ThreadStore.cs | 12 +- .../Data/ThreadStressLog.cs | 14 +- .../Data/TypeDesc.cs | 20 +- .../Data/UnwindInfo.cs | 2 +- .../Data/VirtualCallStubManager.cs | 4 +- ...ostics.DataContractReader.Contracts.csproj | 1 + .../DataTypeVerificationGenerator.cs | 113 + ...stics.DataContractReader.Generators.csproj | 20 + .../DataDescriptorTypeVerification.cs | 111 + .../TypeVerificationTests.cs | 127 + .../checked-descriptor.json | 2495 +++++++++++++++++ 95 files changed, 3388 insertions(+), 351 deletions(-) create mode 100644 src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/TargetFieldExtensions.cs create mode 100644 src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/DataTypeVerificationGenerator.cs create mode 100644 src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/Microsoft.Diagnostics.DataContractReader.Generators.csproj create mode 100644 src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/DataDescriptorTypeVerification.cs create mode 100644 src/native/managed/cdac/tests/ContractDescriptor/TypeVerificationTests.cs create mode 100644 src/native/managed/cdac/tests/ContractDescriptor/checked-descriptor.json diff --git a/src/coreclr/vm/datadescriptor/datadescriptor.inc b/src/coreclr/vm/datadescriptor/datadescriptor.inc index 0effdc9ae95380..0ee65734c32da2 100644 --- a/src/coreclr/vm/datadescriptor/datadescriptor.inc +++ b/src/coreclr/vm/datadescriptor/datadescriptor.inc @@ -393,7 +393,7 @@ CDAC_TYPE_SIZE(sizeof(MethodTable)) CDAC_TYPE_FIELD(MethodTable, T_UINT32, MTFlags, cdac_data::MTFlags) CDAC_TYPE_FIELD(MethodTable, T_UINT32, BaseSize, cdac_data::BaseSize) CDAC_TYPE_FIELD(MethodTable, T_UINT32, MTFlags2, cdac_data::MTFlags2) -CDAC_TYPE_FIELD(MethodTable, T_NUINT, EEClassOrCanonMT, cdac_data::EEClassOrCanonMT) +CDAC_TYPE_FIELD(MethodTable, T_POINTER, EEClassOrCanonMT, cdac_data::EEClassOrCanonMT) CDAC_TYPE_FIELD(MethodTable, T_POINTER, Module, cdac_data::Module) CDAC_TYPE_FIELD(MethodTable, T_POINTER, ParentMethodTable, cdac_data::ParentMethodTable) CDAC_TYPE_FIELD(MethodTable, T_UINT16, NumInterfaces, cdac_data::NumInterfaces) @@ -404,8 +404,8 @@ CDAC_TYPE_END(MethodTable) CDAC_TYPE_BEGIN(DynamicStaticsInfo) CDAC_TYPE_SIZE(sizeof(DynamicStaticsInfo)) -CDAC_TYPE_FIELD(DynamicStaticsInfo, T_UINT32, GCStatics, offsetof(DynamicStaticsInfo, m_pGCStatics)) -CDAC_TYPE_FIELD(DynamicStaticsInfo, T_UINT32, NonGCStatics, offsetof(DynamicStaticsInfo, m_pNonGCStatics)) +CDAC_TYPE_FIELD(DynamicStaticsInfo, T_POINTER, GCStatics, offsetof(DynamicStaticsInfo, m_pGCStatics)) +CDAC_TYPE_FIELD(DynamicStaticsInfo, T_POINTER, NonGCStatics, offsetof(DynamicStaticsInfo, m_pNonGCStatics)) CDAC_TYPE_END(DynamicStaticsInfo) CDAC_TYPE_BEGIN(MethodTableAuxiliaryData) @@ -882,7 +882,7 @@ CDAC_TYPE_BEGIN(NativeCodeVersionNode) CDAC_TYPE_INDETERMINATE(NativeCodeVersionNode) CDAC_TYPE_FIELD(NativeCodeVersionNode, T_POINTER, Next, cdac_data::Next) CDAC_TYPE_FIELD(NativeCodeVersionNode, T_POINTER, MethodDesc, cdac_data::MethodDesc) -CDAC_TYPE_FIELD(NativeCodeVersionNode, T_POINTER, NativeCode, cdac_data::NativeCode) +CDAC_TYPE_FIELD(NativeCodeVersionNode, TYPE(CodePointer), NativeCode, cdac_data::NativeCode) CDAC_TYPE_FIELD(NativeCodeVersionNode, T_UINT32, Flags, cdac_data::Flags) CDAC_TYPE_FIELD(NativeCodeVersionNode, T_NUINT, ILVersionId, cdac_data::ILVersionId) #ifdef HAVE_GCCOVER diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/TargetFieldExtensions.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/TargetFieldExtensions.cs new file mode 100644 index 00000000000000..eb82cbdae0425d --- /dev/null +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/TargetFieldExtensions.cs @@ -0,0 +1,179 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics; +using System.Numerics; +using Microsoft.Diagnostics.DataContractReader.Data; + +namespace Microsoft.Diagnostics.DataContractReader; + +/// +/// Extension methods for that provide typed field reading with optional +/// type validation. When the data descriptor includes type information (debug/checked builds), +/// these methods assert that the declared field type is compatible with the C# read type. +/// +public static class TargetFieldExtensions +{ + /// + /// Read a primitive integer field from the target with type validation. + /// + public static T ReadField(this Target target, ulong address, Target.TypeInfo typeInfo, string fieldName) + where T : unmanaged, IBinaryInteger, IMinMaxValue + { + Target.FieldInfo field = typeInfo.Fields[fieldName]; + AssertPrimitiveType(field, fieldName); + + return target.Read(address + (ulong)field.Offset); + } + + /// + /// Read an optional primitive integer field from the target with type validation. + /// Returns if the field is not present in the descriptor. + /// + public static T ReadFieldOrDefault(this Target target, ulong address, Target.TypeInfo typeInfo, string fieldName, T defaultValue = default) + where T : unmanaged, IBinaryInteger, IMinMaxValue + { + if (!typeInfo.Fields.TryGetValue(fieldName, out Target.FieldInfo field)) + return defaultValue; + + AssertPrimitiveType(field, fieldName); + + return target.Read(address + (ulong)field.Offset); + } + + /// + /// Read a pointer field from the target with type validation. + /// + public static TargetPointer ReadPointerField(this Target target, ulong address, Target.TypeInfo typeInfo, string fieldName) + { + Target.FieldInfo field = typeInfo.Fields[fieldName]; + AssertPointerType(field, fieldName); + + return target.ReadPointer(address + (ulong)field.Offset); + } + + /// + /// Read an optional pointer field from the target with type validation. + /// Returns if the field is not present in the descriptor. + /// + public static TargetPointer ReadPointerFieldOrNull(this Target target, ulong address, Target.TypeInfo typeInfo, string fieldName) + { + if (!typeInfo.Fields.TryGetValue(fieldName, out Target.FieldInfo field)) + return TargetPointer.Null; + + AssertPointerType(field, fieldName); + + return target.ReadPointer(address + (ulong)field.Offset); + } + + /// + /// Read a native unsigned integer field from the target with type validation. + /// + public static TargetNUInt ReadNUIntField(this Target target, ulong address, Target.TypeInfo typeInfo, string fieldName) + { + Target.FieldInfo field = typeInfo.Fields[fieldName]; + Debug.Assert( + field.TypeName is null or "" or "nuint", + $"Type mismatch reading field '{fieldName}': declared as '{field.TypeName}', expected nuint"); + + return target.ReadNUInt(address + (ulong)field.Offset); + } + + /// + /// Read a code pointer field from the target with type validation. + /// + public static TargetCodePointer ReadCodePointerField(this Target target, ulong address, Target.TypeInfo typeInfo, string fieldName) + { + Target.FieldInfo field = typeInfo.Fields[fieldName]; + Debug.Assert( + field.TypeName is null or "" or "CodePointer", + $"Type mismatch reading field '{fieldName}': declared as '{field.TypeName}', expected CodePointer"); + + return target.ReadCodePointer(address + (ulong)field.Offset); + } + + /// + /// Read a field that contains an inline Data struct type, with type validation. + /// Returns the data object created by . + /// + public static T ReadDataField(this Target target, ulong address, Target.TypeInfo typeInfo, string fieldName) + where T : IData + { + Target.FieldInfo field = typeInfo.Fields[fieldName]; + Debug.Assert( + field.TypeName is null or "" || field.TypeName == typeof(T).Name, + $"Type mismatch reading field '{fieldName}': declared as '{field.TypeName}', reading as {typeof(T).Name}"); + + return target.ProcessedData.GetOrAdd(address + (ulong)field.Offset); + } + + /// + /// Read a field that contains a pointer to a Data struct type, with type validation. + /// Reads the pointer, then creates the data object via . + /// Returns null if the pointer is null. + /// + public static T? ReadDataFieldPointer(this Target target, ulong address, Target.TypeInfo typeInfo, string fieldName) + where T : IData + { + Target.FieldInfo field = typeInfo.Fields[fieldName]; + AssertPointerType(field, fieldName); + + TargetPointer pointer = target.ReadPointer(address + (ulong)field.Offset); + if (pointer == TargetPointer.Null) + return default; + + return target.ProcessedData.GetOrAdd(pointer); + } + + /// + /// Read an optional field that contains a pointer to a Data struct type, with type validation. + /// Returns null if the field is not present in the descriptor or the pointer is null. + /// + public static T? ReadDataFieldPointerOrNull(this Target target, ulong address, Target.TypeInfo typeInfo, string fieldName) + where T : IData + { + if (!typeInfo.Fields.TryGetValue(fieldName, out Target.FieldInfo field)) + return default; + + AssertPointerType(field, fieldName); + + TargetPointer pointer = target.ReadPointer(address + (ulong)field.Offset); + if (pointer == TargetPointer.Null) + return default; + + return target.ProcessedData.GetOrAdd(pointer); + } + + private static void AssertPrimitiveType(Target.FieldInfo field, string fieldName) + where T : unmanaged, IBinaryInteger, IMinMaxValue + { + Debug.Assert( + field.TypeName is null or "" || IsCompatiblePrimitiveType(field.TypeName), + $"Type mismatch reading field '{fieldName}': declared as '{field.TypeName}', reading as {typeof(T).Name}"); + } + + private static void AssertPointerType(Target.FieldInfo field, string fieldName) + { + Debug.Assert( + field.TypeName is null or "" or "pointer", + $"Type mismatch reading field '{fieldName}': declared as '{field.TypeName}', expected pointer"); + } + + private static bool IsCompatiblePrimitiveType(string typeName) + where T : unmanaged, IBinaryInteger, IMinMaxValue + { + return typeName switch + { + "uint8" => typeof(T) == typeof(byte), + "int8" => typeof(T) == typeof(sbyte), + "uint16" => typeof(T) == typeof(ushort), + "int16" => typeof(T) == typeof(short), + "uint32" => typeof(T) == typeof(uint), + "int32" => typeof(T) == typeof(int), + "uint64" => typeof(T) == typeof(ulong), + "int64" => typeof(T) == typeof(long), + "bool" => typeof(T) == typeof(byte), + _ => false, + }; + } +} diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/BuiltInCOM_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/BuiltInCOM_1.cs index a9565fe6abecdf..3de4943a1630cf 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/BuiltInCOM_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/BuiltInCOM_1.cs @@ -171,8 +171,8 @@ public SimpleComCallWrapperData GetSimpleComCallWrapperData(TargetPointer ccw) Data.SimpleComCallWrapper data = _target.ProcessedData.GetOrAdd(sccw); return new SimpleComCallWrapperData { - RefCount = data.RefCount & (ulong)ComRefCount.RefCountMask, - IsNeutered = (data.RefCount & (ulong)ComRefCount.CleanupSentinel) != 0, + RefCount = (uint)(data.RefCount & (long)ComRefCount.RefCountMask), + IsNeutered = (data.RefCount & (long)ComRefCount.CleanupSentinel) != 0, IsAggregated = (data.Flags & (uint)SimpleComCallWrapperFlags.IsAggregated) != 0, IsExtendsCOMObject = (data.Flags & (uint)SimpleComCallWrapperFlags.IsExtendsCom) != 0, IsHandleWeak = (data.Flags & (uint)SimpleComCallWrapperFlags.IsHandleWeak) != 0, diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AppDomain.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AppDomain.cs index cd21ff7172abce..e79e879d5f47e2 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AppDomain.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AppDomain.cs @@ -12,9 +12,9 @@ public AppDomain(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.AppDomain); - RootAssembly = target.ReadPointer(address + (ulong)type.Fields[nameof(RootAssembly)].Offset); + RootAssembly = target.ReadPointerField(address, type, nameof(RootAssembly)); DomainAssemblyList = address + (ulong)type.Fields[nameof(DomainAssemblyList)].Offset; - FriendlyName = target.ReadPointer(address + (ulong)type.Fields[nameof(FriendlyName)].Offset); + FriendlyName = target.ReadPointerField(address, type, nameof(FriendlyName)); } public TargetPointer RootAssembly { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ArrayListBase.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ArrayListBase.cs index e9585579371757..d8cc8767697c4b 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ArrayListBase.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ArrayListBase.cs @@ -16,7 +16,7 @@ public ArrayListBase(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ArrayListBase); - Count = target.Read(address + (ulong)type.Fields[nameof(Count)].Offset); + Count = target.ReadField(address, type, nameof(Count)); FirstBlock = address + (ulong)type.Fields[nameof(FirstBlock)].Offset; TargetPointer next = FirstBlock; @@ -56,8 +56,8 @@ public ArrayListBlock(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ArrayListBlock); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); - Size = target.Read(address + (ulong)type.Fields[nameof(Size)].Offset); + Next = target.ReadPointerField(address, type, nameof(Next)); + Size = target.ReadField(address, type, nameof(Size)); ArrayStart = address + (ulong)type.Fields[nameof(ArrayStart)].Offset; for (ulong i = 0; i < Size; i++) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Assembly.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Assembly.cs index 5c8a3b672e2a34..e84b449383dd01 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Assembly.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Assembly.cs @@ -12,12 +12,12 @@ public Assembly(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.Assembly); - Module = target.ReadPointer(address + (ulong)type.Fields[nameof(Module)].Offset); - IsCollectible = target.Read(address + (ulong)type.Fields[nameof(IsCollectible)].Offset); - IsDynamic = target.Read(address + (ulong)type.Fields[nameof(IsDynamic)].Offset) != 0; - Error = target.ReadPointer(address + (ulong)type.Fields[nameof(Error)].Offset); - NotifyFlags = target.Read(address + (ulong)type.Fields[nameof(NotifyFlags)].Offset); - IsLoaded = target.Read(address + (ulong)type.Fields[nameof(IsLoaded)].Offset) != 0; + Module = target.ReadPointerField(address, type, nameof(Module)); + IsCollectible = target.ReadField(address, type, nameof(IsCollectible)); + IsDynamic = target.ReadField(address, type, nameof(IsDynamic)) != 0; + Error = target.ReadPointerField(address, type, nameof(Error)); + NotifyFlags = target.ReadField(address, type, nameof(NotifyFlags)); + IsLoaded = target.ReadField(address, type, nameof(IsLoaded)) != 0; } public TargetPointer Module { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AssemblyBinder.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AssemblyBinder.cs index 2c13c5fe332a95..4ffb63f457472f 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AssemblyBinder.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AssemblyBinder.cs @@ -11,7 +11,7 @@ internal sealed class AssemblyBinder : IData public AssemblyBinder(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.AssemblyBinder); - AssemblyLoadContext = target.ReadPointer(address + (ulong)type.Fields[nameof(AssemblyLoadContext)].Offset); + AssemblyLoadContext = target.ReadPointerField(address, type, nameof(AssemblyLoadContext)); } public TargetPointer AssemblyLoadContext { get; init; } } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CGrowableSymbolStream.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CGrowableSymbolStream.cs index 78913d53620a8b..e0314173ef1613 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CGrowableSymbolStream.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CGrowableSymbolStream.cs @@ -10,8 +10,8 @@ public CGrowableSymbolStream(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.CGrowableSymbolStream); - Buffer = target.ReadPointer(address + (ulong)type.Fields[nameof(Buffer)].Offset); - Size = target.Read(address + (ulong)type.Fields[nameof(Size)].Offset); + Buffer = target.ReadPointerField(address, type, nameof(Buffer)); + Size = target.ReadField(address, type, nameof(Size)); } public TargetPointer Buffer { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CodeHeapListNode.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CodeHeapListNode.cs index edce53f82aa61c..bf1c618f1c2fc2 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CodeHeapListNode.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CodeHeapListNode.cs @@ -11,12 +11,12 @@ static CodeHeapListNode IData.Create(Target target, TargetPoin public CodeHeapListNode(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.CodeHeapListNode); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); - StartAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(StartAddress)].Offset); - EndAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(EndAddress)].Offset); - MapBase = target.ReadPointer(address + (ulong)type.Fields[nameof(MapBase)].Offset); - HeaderMap = target.ReadPointer(address + (ulong)type.Fields[nameof(HeaderMap)].Offset); - Heap = target.ReadPointer(address + (ulong)type.Fields[nameof(Heap)].Offset); + Next = target.ReadPointerField(address, type, nameof(Next)); + StartAddress = target.ReadPointerField(address, type, nameof(StartAddress)); + EndAddress = target.ReadPointerField(address, type, nameof(EndAddress)); + MapBase = target.ReadPointerField(address, type, nameof(MapBase)); + HeaderMap = target.ReadPointerField(address, type, nameof(HeaderMap)); + Heap = target.ReadPointerField(address, type, nameof(Heap)); } public TargetPointer Next { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ComCallWrapper.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ComCallWrapper.cs index 549830f54dc778..69bf2e74f038ae 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ComCallWrapper.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ComCallWrapper.cs @@ -11,9 +11,9 @@ public ComCallWrapper(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ComCallWrapper); - Handle = target.ReadPointer(address + (ulong)type.Fields[nameof(Handle)].Offset); - SimpleWrapper = target.ReadPointer(address + (ulong)type.Fields[nameof(SimpleWrapper)].Offset); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); + Handle = target.ReadPointerField(address, type, nameof(Handle)); + SimpleWrapper = target.ReadPointerField(address, type, nameof(SimpleWrapper)); + Next = target.ReadPointerField(address, type, nameof(Next)); IPtr = address + (ulong)type.Fields[nameof(IPtr)].Offset; int numInterfaces = (int)target.ReadGlobal(Constants.Globals.CCWNumInterfaces); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ComMethodTable.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ComMethodTable.cs index 81997c5bd0ea4b..a8c336af890150 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ComMethodTable.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ComMethodTable.cs @@ -10,8 +10,8 @@ public ComMethodTable(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ComMethodTable); - Flags = target.ReadNUInt(address + (ulong)type.Fields[nameof(Flags)].Offset); - MethodTable = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodTable)].Offset); + Flags = target.ReadNUIntField(address, type, nameof(Flags)); + MethodTable = target.ReadPointerField(address, type, nameof(MethodTable)); } public TargetNUInt Flags { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CoreLibBinder.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CoreLibBinder.cs index 49e6155d680cfa..5ce0d444b0d658 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CoreLibBinder.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CoreLibBinder.cs @@ -12,7 +12,7 @@ public CoreLibBinder(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.CoreLibBinder); - Classes = target.ReadPointer(address + (ulong)type.Fields[nameof(Classes)].Offset); + Classes = target.ReadPointerField(address, type, nameof(Classes)); } public TargetPointer Classes { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CtxEntry.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CtxEntry.cs index f67fa847424544..7f7b4f0eb862c3 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CtxEntry.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CtxEntry.cs @@ -10,8 +10,8 @@ public CtxEntry(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.CtxEntry); - STAThread = target.ReadPointer(address + (ulong)type.Fields[nameof(STAThread)].Offset); - CtxCookie = target.ReadPointer(address + (ulong)type.Fields[nameof(CtxCookie)].Offset); + STAThread = target.ReadPointerField(address, type, nameof(STAThread)); + CtxCookie = target.ReadPointerField(address, type, nameof(CtxCookie)); } public TargetPointer STAThread { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DacEnumerableHash.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DacEnumerableHash.cs index 248eb1fcc74ad5..b95af295eaecaa 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DacEnumerableHash.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DacEnumerableHash.cs @@ -61,7 +61,7 @@ public VolatileEntry(Target target, TargetPointer address, Target.TypeInfo type) { // offsets are stored on the parent type VolatileEntryValue = address + (ulong)type.Fields[nameof(VolatileEntryValue)].Offset; - VolatileEntryNextEntry = target.ReadPointer(address + (ulong)type.Fields[nameof(VolatileEntryNextEntry)].Offset); + VolatileEntryNextEntry = target.ReadPointerField(address, type, nameof(VolatileEntryNextEntry)); } public TargetPointer VolatileEntryValue { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicILBlobEntry.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicILBlobEntry.cs index b7f68e9fcee463..cdcd89bd17b440 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicILBlobEntry.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicILBlobEntry.cs @@ -11,8 +11,8 @@ static DynamicILBlobEntry IData.Create(Target target, Target public DynamicILBlobEntry(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.DynamicILBlobTable); - EntryMethodToken = target.Read(address + (ulong)type.Fields[nameof(EntryMethodToken)].Offset); - EntryIL = target.ReadPointer(address + (ulong)type.Fields[nameof(EntryIL)].Offset); + EntryMethodToken = target.ReadField(address, type, nameof(EntryMethodToken)); + EntryIL = target.ReadPointerField(address, type, nameof(EntryIL)); } public DynamicILBlobEntry(uint entryMethodToken, TargetPointer entryIL) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicMetadata.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicMetadata.cs index 2496c5324e25d4..39181dd5c46284 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicMetadata.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicMetadata.cs @@ -10,7 +10,7 @@ public DynamicMetadata(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.DynamicMetadata); - Size = target.Read(address + (ulong)type.Fields[nameof(Size)].Offset); + Size = target.ReadField(address, type, nameof(Size)); Data = address + (ulong)type.Fields[nameof(Data)].Offset; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicStaticsInfo.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicStaticsInfo.cs index 649c9ecdd881e3..b308ce5dea088b 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicStaticsInfo.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DynamicStaticsInfo.cs @@ -12,8 +12,8 @@ public DynamicStaticsInfo(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.DynamicStaticsInfo); TargetPointer mask = target.ReadGlobalPointer(Constants.Globals.StaticsPointerMask); - GCStatics = target.ReadPointer(address + (ulong)type.Fields[nameof(GCStatics)].Offset) & mask; - NonGCStatics = target.ReadPointer(address + (ulong)type.Fields[nameof(NonGCStatics)].Offset) & mask; + GCStatics = target.ReadPointerField(address, type, nameof(GCStatics)) & mask; + NonGCStatics = target.ReadPointerField(address, type, nameof(NonGCStatics)) & mask; } public TargetPointer GCStatics { get; init; } public TargetPointer NonGCStatics { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/EEClass.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/EEClass.cs index bd3efe35aaa593..0d0393f6e4e0df 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/EEClass.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/EEClass.cs @@ -10,16 +10,16 @@ public EEClass(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.EEClass); - MethodTable = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodTable)].Offset); - MethodDescChunk = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodDescChunk)].Offset); - NumMethods = target.Read(address + (ulong)type.Fields[nameof(NumMethods)].Offset); - CorTypeAttr = target.Read(address + (ulong)type.Fields[nameof(CorTypeAttr)].Offset); - InternalCorElementType = target.Read(address + (ulong)type.Fields[nameof(InternalCorElementType)].Offset); - NumInstanceFields = target.Read(address + (ulong)type.Fields[nameof(NumInstanceFields)].Offset); - NumStaticFields = target.Read(address + (ulong)type.Fields[nameof(NumStaticFields)].Offset); - NumThreadStaticFields = target.Read(address + (ulong)type.Fields[nameof(NumThreadStaticFields)].Offset); - FieldDescList = target.Read(address + (ulong)type.Fields[nameof(FieldDescList)].Offset); - NumNonVirtualSlots = target.Read(address + (ulong)type.Fields[nameof(NumNonVirtualSlots)].Offset); + MethodTable = target.ReadPointerField(address, type, nameof(MethodTable)); + MethodDescChunk = target.ReadPointerField(address, type, nameof(MethodDescChunk)); + NumMethods = target.ReadField(address, type, nameof(NumMethods)); + CorTypeAttr = target.ReadField(address, type, nameof(CorTypeAttr)); + InternalCorElementType = target.ReadField(address, type, nameof(InternalCorElementType)); + NumInstanceFields = target.ReadField(address, type, nameof(NumInstanceFields)); + NumStaticFields = target.ReadField(address, type, nameof(NumStaticFields)); + NumThreadStaticFields = target.ReadField(address, type, nameof(NumThreadStaticFields)); + FieldDescList = target.ReadPointerField(address, type, nameof(FieldDescList)); + NumNonVirtualSlots = target.ReadField(address, type, nameof(NumNonVirtualSlots)); } public TargetPointer MethodTable { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/EEJitManager.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/EEJitManager.cs index 7d2e2d074dd52c..8d52096a6d41fa 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/EEJitManager.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/EEJitManager.cs @@ -10,8 +10,8 @@ public EEJitManager(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.EEJitManager); - StoreRichDebugInfo = target.Read(address + (ulong)type.Fields[nameof(StoreRichDebugInfo)].Offset) != 0; - AllCodeHeaps = target.ReadPointer(address + (ulong)type.Fields[nameof(AllCodeHeaps)].Offset); + StoreRichDebugInfo = target.ReadField(address, type, nameof(StoreRichDebugInfo)) != 0; + AllCodeHeaps = target.ReadPointerField(address, type, nameof(AllCodeHeaps)); } public bool StoreRichDebugInfo { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionClause.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionClause.cs index d8498f67440b59..91b14c79d382f8 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionClause.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionClause.cs @@ -21,13 +21,13 @@ public EEExceptionClause(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.EEExceptionClause); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); - TryStartPC = target.Read(address + (ulong)type.Fields[nameof(TryStartPC)].Offset); - TryEndPC = target.Read(address + (ulong)type.Fields[nameof(TryEndPC)].Offset); - HandlerStartPC = target.Read(address + (ulong)type.Fields[nameof(HandlerStartPC)].Offset); - HandlerEndPC = target.Read(address + (ulong)type.Fields[nameof(HandlerEndPC)].Offset); - TypeHandle = target.ReadNUInt(address + (ulong)type.Fields[nameof(TypeHandle)].Offset); - ClassToken = target.Read(address + (ulong)type.Fields[nameof(TypeHandle)].Offset); + Flags = target.ReadField(address, type, nameof(Flags)); + TryStartPC = target.ReadField(address, type, nameof(TryStartPC)); + TryEndPC = target.ReadField(address, type, nameof(TryEndPC)); + HandlerStartPC = target.ReadField(address, type, nameof(HandlerStartPC)); + HandlerEndPC = target.ReadField(address, type, nameof(HandlerEndPC)); + TypeHandle = target.ReadNUIntField(address, type, nameof(TypeHandle)); + ClassToken = (uint)TypeHandle.Value; FilterOffset = ClassToken; } @@ -48,12 +48,12 @@ public R2RExceptionClause(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.R2RExceptionClause); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); - TryStartPC = target.Read(address + (ulong)type.Fields[nameof(TryStartPC)].Offset); - TryEndPC = target.Read(address + (ulong)type.Fields[nameof(TryEndPC)].Offset); - HandlerStartPC = target.Read(address + (ulong)type.Fields[nameof(HandlerStartPC)].Offset); - HandlerEndPC = target.Read(address + (ulong)type.Fields[nameof(HandlerEndPC)].Offset); - ClassToken = target.Read(address + (ulong)type.Fields[nameof(ClassToken)].Offset); + Flags = target.ReadField(address, type, nameof(Flags)); + TryStartPC = target.ReadField(address, type, nameof(TryStartPC)); + TryEndPC = target.ReadField(address, type, nameof(TryEndPC)); + HandlerStartPC = target.ReadField(address, type, nameof(HandlerStartPC)); + HandlerEndPC = target.ReadField(address, type, nameof(HandlerEndPC)); + ClassToken = target.ReadField(address, type, nameof(ClassToken)); FilterOffset = ClassToken; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionInfo.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionInfo.cs index 8f2470d6e71996..4e496b82c1b1be 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionInfo.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionInfo.cs @@ -12,17 +12,17 @@ public ExceptionInfo(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ExceptionInfo); - PreviousNestedInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(PreviousNestedInfo)].Offset); - ThrownObjectHandle = target.ReadPointer(address + (ulong)type.Fields[nameof(ThrownObjectHandle)].Offset); - ExceptionFlags = target.Read(address + (ulong)type.Fields[nameof(ExceptionFlags)].Offset); - StackLowBound = target.ReadPointer(address + (ulong)type.Fields[nameof(StackLowBound)].Offset); - StackHighBound = target.ReadPointer(address + (ulong)type.Fields[nameof(StackHighBound)].Offset); + PreviousNestedInfo = target.ReadPointerField(address, type, nameof(PreviousNestedInfo)); + ThrownObjectHandle = target.ReadPointerField(address, type, nameof(ThrownObjectHandle)); if (type.Fields.ContainsKey(nameof(ExceptionWatsonBucketTrackerBuckets))) - ExceptionWatsonBucketTrackerBuckets = target.ReadPointer(address + (ulong)type.Fields[nameof(ExceptionWatsonBucketTrackerBuckets)].Offset); - PassNumber = target.Read(address + (ulong)type.Fields[nameof(PassNumber)].Offset); - CSFEHClause = target.ReadPointer(address + (ulong)type.Fields[nameof(CSFEHClause)].Offset); - CSFEnclosingClause = target.ReadPointer(address + (ulong)type.Fields[nameof(CSFEnclosingClause)].Offset); - CallerOfActualHandlerFrame = target.ReadPointer(address + (ulong)type.Fields[nameof(CallerOfActualHandlerFrame)].Offset); + ExceptionWatsonBucketTrackerBuckets = target.ReadPointerField(address, type, nameof(ExceptionWatsonBucketTrackerBuckets)); + ExceptionFlags = target.ReadField(address, type, nameof(ExceptionFlags)); + StackLowBound = target.ReadPointerField(address, type, nameof(StackLowBound)); + StackHighBound = target.ReadPointerField(address, type, nameof(StackHighBound)); + PassNumber = target.ReadField(address, type, nameof(PassNumber)); + CSFEHClause = target.ReadPointerField(address, type, nameof(CSFEHClause)); + CSFEnclosingClause = target.ReadPointerField(address, type, nameof(CSFEnclosingClause)); + CallerOfActualHandlerFrame = target.ReadPointerField(address, type, nameof(CallerOfActualHandlerFrame)); } public TargetPointer PreviousNestedInfo { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionLookupTableEntry.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionLookupTableEntry.cs index 2b3d9cbe19822f..5914842e854236 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionLookupTableEntry.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionLookupTableEntry.cs @@ -9,8 +9,8 @@ internal sealed class ExceptionLookupTableEntry : IData(address + (ulong)type.Fields[nameof(MethodStartRVA)].Offset); - ExceptionInfoRVA = target.Read(address + (ulong)type.Fields[nameof(ExceptionInfoRVA)].Offset); + MethodStartRVA = target.ReadField(address, type, nameof(MethodStartRVA)); + ExceptionInfoRVA = target.ReadField(address, type, nameof(ExceptionInfoRVA)); } public uint MethodStartRVA { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/FieldDesc.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/FieldDesc.cs index 6ce2f4d2227219..4f7cbaf9fad045 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/FieldDesc.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/FieldDesc.cs @@ -9,9 +9,9 @@ internal sealed class FieldDesc : IData public FieldDesc(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.FieldDesc); - DWord1 = target.Read(address + (ulong)type.Fields[nameof(DWord1)].Offset); - DWord2 = target.Read(address + (ulong)type.Fields[nameof(DWord2)].Offset); - MTOfEnclosingClass = target.ReadPointer(address + (ulong)type.Fields[nameof(MTOfEnclosingClass)].Offset); + DWord1 = target.ReadField(address, type, nameof(DWord1)); + DWord2 = target.ReadField(address, type, nameof(DWord2)); + MTOfEnclosingClass = target.ReadPointerField(address, type, nameof(MTOfEnclosingClass)); } public uint DWord1 { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/FixupPrecodeData.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/FixupPrecodeData.cs index 811508cc4354a1..8a6bb449dc7d93 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/FixupPrecodeData.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/FixupPrecodeData.cs @@ -11,7 +11,7 @@ static FixupPrecodeData IData.Create(Target target, TargetPoin public FixupPrecodeData(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.FixupPrecodeData); - MethodDesc = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodDesc)].Offset); + MethodDesc = target.ReadPointerField(address, type, nameof(MethodDesc)); } public TargetPointer MethodDesc { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GCAllocContext.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GCAllocContext.cs index bc6b6e1a98a8a1..2a01f6407bcb75 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GCAllocContext.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GCAllocContext.cs @@ -11,10 +11,10 @@ static GCAllocContext IData.Create(Target target, TargetPointer public GCAllocContext(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.GCAllocContext); - Pointer = target.ReadPointer(address + (ulong)type.Fields[nameof(Pointer)].Offset); - Limit = target.ReadPointer(address + (ulong)type.Fields[nameof(Limit)].Offset); - AllocBytes = target.Read(address + (ulong)type.Fields[nameof(AllocBytes)].Offset); - AllocBytesLoh = target.Read(address + (ulong)type.Fields[nameof(AllocBytesLoh)].Offset); + Pointer = target.ReadPointerField(address, type, nameof(Pointer)); + Limit = target.ReadPointerField(address, type, nameof(Limit)); + AllocBytes = target.ReadField(address, type, nameof(AllocBytes)); + AllocBytesLoh = target.ReadField(address, type, nameof(AllocBytesLoh)); } public TargetPointer Pointer { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GenericsDictInfo.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GenericsDictInfo.cs index 7ece56e8bc139d..bacc4de67d535d 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GenericsDictInfo.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GenericsDictInfo.cs @@ -10,8 +10,8 @@ public GenericsDictInfo(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.GenericsDictInfo); - NumDicts = target.Read(address + (ulong)type.Fields[nameof(NumDicts)].Offset); - NumTypeArgs = target.Read(address + (ulong)type.Fields[nameof(NumTypeArgs)].Offset); + NumDicts = target.ReadField(address, type, nameof(NumDicts)); + NumTypeArgs = target.ReadField(address, type, nameof(NumTypeArgs)); } public ushort NumDicts { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTable.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTable.cs index 072c9ef00dfe5d..c3442aa6008aee 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTable.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTable.cs @@ -12,7 +12,7 @@ static HandleTable IData.Create(Target target, TargetPointer addres public HandleTable(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.HandleTable); - SegmentList = target.ReadPointer(address + (ulong)type.Fields[nameof(SegmentList)].Offset); + SegmentList = target.ReadPointerField(address, type, nameof(SegmentList)); } public TargetPointer SegmentList { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableBucket.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableBucket.cs index 648705c88b31cb..c9aa016c86f0a7 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableBucket.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableBucket.cs @@ -12,7 +12,7 @@ static HandleTableBucket IData.Create(Target target, TargetPo public HandleTableBucket(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.HandleTableBucket); - Table = target.ReadPointer(address + (ulong)type.Fields[nameof(Table)].Offset); + Table = target.ReadPointerField(address, type, nameof(Table)); } public TargetPointer Table { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableMap.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableMap.cs index b442c410be0bb0..8e1de496507136 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableMap.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HandleTableMap.cs @@ -14,14 +14,14 @@ static HandleTableMap IData.Create(Target target, TargetPointer public HandleTableMap(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.HandleTableMap); - TargetPointer bucketsPtr = target.ReadPointer(address + (ulong)type.Fields[nameof(BucketsPtr)].Offset); + TargetPointer bucketsPtr = target.ReadPointerField(address, type, nameof(BucketsPtr)); uint arrayLength = target.ReadGlobal(Constants.Globals.InitialHandleTableArraySize); for (int i = 0; i < arrayLength; i++) { TargetPointer bucketPtr = target.ReadPointer(bucketsPtr + (ulong)(i * target.PointerSize)); BucketsPtr.Add(bucketPtr); } - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); + Next = target.ReadPointerField(address, type, nameof(Next)); } public List BucketsPtr { get; init; } = new List(); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HashMap.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HashMap.cs index 3276fdefd569d9..79316a5d600080 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HashMap.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HashMap.cs @@ -12,7 +12,7 @@ public HashMap(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.HashMap); - Buckets = target.ReadPointer(address + (ulong)type.Fields[nameof(Buckets)].Offset); + Buckets = target.ReadPointerField(address, type, nameof(Buckets)); } public TargetPointer Buckets { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ILCodeVersionNode.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ILCodeVersionNode.cs index dcfac956bb2760..cf0bb305211a5f 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ILCodeVersionNode.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ILCodeVersionNode.cs @@ -12,10 +12,10 @@ public ILCodeVersionNode(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ILCodeVersionNode); - VersionId = target.ReadNUInt(address + (ulong)type.Fields[nameof(VersionId)].Offset); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); - RejitState = target.Read(address + (ulong)type.Fields[nameof(RejitState)].Offset); - ILAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(ILAddress)].Offset); + VersionId = target.ReadNUIntField(address, type, nameof(VersionId)); + Next = target.ReadPointerField(address, type, nameof(Next)); + RejitState = target.ReadField(address, type, nameof(RejitState)); + ILAddress = target.ReadPointerField(address, type, nameof(ILAddress)); } public TargetNUInt VersionId { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ILCodeVersioningState.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ILCodeVersioningState.cs index a37e93ed9637e8..8084de6debe133 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ILCodeVersioningState.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ILCodeVersioningState.cs @@ -12,11 +12,11 @@ public ILCodeVersioningState(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ILCodeVersioningState); - FirstVersionNode = target.ReadPointer(address + (ulong)type.Fields[nameof(FirstVersionNode)].Offset); - ActiveVersionKind = target.Read(address + (ulong)type.Fields[nameof(ActiveVersionKind)].Offset); - ActiveVersionNode = target.ReadPointer(address + (ulong)type.Fields[nameof(ActiveVersionNode)].Offset); - ActiveVersionModule = target.ReadPointer(address + (ulong)type.Fields[nameof(ActiveVersionModule)].Offset); - ActiveVersionMethodDef = target.Read(address + (ulong)type.Fields[nameof(ActiveVersionMethodDef)].Offset); + FirstVersionNode = target.ReadPointerField(address, type, nameof(FirstVersionNode)); + ActiveVersionKind = target.ReadField(address, type, nameof(ActiveVersionKind)); + ActiveVersionNode = target.ReadPointerField(address, type, nameof(ActiveVersionNode)); + ActiveVersionModule = target.ReadPointerField(address, type, nameof(ActiveVersionModule)); + ActiveVersionMethodDef = target.ReadField(address, type, nameof(ActiveVersionMethodDef)); } public TargetPointer FirstVersionNode { get; set; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/IdDispenser.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/IdDispenser.cs index 75806fa57e3748..cfc35cbe853878 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/IdDispenser.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/IdDispenser.cs @@ -11,8 +11,8 @@ internal sealed class IdDispenser : IData public IdDispenser(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.IdDispenser); - IdToThread = target.ReadPointer(address + (ulong)type.Fields[nameof(IdToThread)].Offset); - HighestId = target.Read(address + (ulong)type.Fields[nameof(HighestId)].Offset); + IdToThread = target.ReadPointerField(address, type, nameof(IdToThread)); + HighestId = target.ReadField(address, type, nameof(HighestId)); } public TargetPointer IdToThread { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ImageDataDirectory.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ImageDataDirectory.cs index 241cf6daabd540..a84fcc19abaa77 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ImageDataDirectory.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ImageDataDirectory.cs @@ -12,8 +12,8 @@ public ImageDataDirectory(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ImageDataDirectory); - VirtualAddress = target.Read(address + (ulong)type.Fields[nameof(VirtualAddress)].Offset); - Size = target.Read(address + (ulong)type.Fields[nameof(Size)].Offset); + VirtualAddress = target.ReadField(address, type, nameof(VirtualAddress)); + Size = target.ReadField(address, type, nameof(Size)); } public uint VirtualAddress { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/InflightTLSData.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/InflightTLSData.cs index 4a1cad9672773d..9ec716b491b15d 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/InflightTLSData.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/InflightTLSData.cs @@ -11,9 +11,9 @@ internal sealed class InflightTLSData : IData public InflightTLSData(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.InFlightTLSData); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); + Next = target.ReadPointerField(address, type, nameof(Next)); TlsIndex = target.ProcessedData.GetOrAdd(address + (ulong)type.Fields[nameof(TlsIndex)].Offset); - TLSData = target.ProcessedData.GetOrAdd(target.ReadPointer(address + (ulong)type.Fields[nameof(TLSData)].Offset)); + TLSData = target.ProcessedData.GetOrAdd(target.ReadPointerField(address, type, nameof(TLSData))); } public TargetPointer Next { get; init; } public TLSIndex TlsIndex { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/InterfaceEntry.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/InterfaceEntry.cs index 2beb7fdc8d903d..ef0232a4065bee 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/InterfaceEntry.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/InterfaceEntry.cs @@ -10,8 +10,8 @@ public InterfaceEntry(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.InterfaceEntry); - MethodTable = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodTable)].Offset); - Unknown = target.ReadPointer(address + (ulong)type.Fields[nameof(Unknown)].Offset); + MethodTable = target.ReadPointerField(address, type, nameof(MethodTable)); + Unknown = target.ReadPointerField(address, type, nameof(Unknown)); } public TargetPointer MethodTable { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/LoaderAllocator.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/LoaderAllocator.cs index 3269079ff305e3..20499fa92da6c0 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/LoaderAllocator.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/LoaderAllocator.cs @@ -12,24 +12,24 @@ public LoaderAllocator(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.LoaderAllocator); - ReferenceCount = target.Read(address + (ulong)type.Fields[nameof(ReferenceCount)].Offset); - HighFrequencyHeap = target.ReadPointer(address + (ulong)type.Fields[nameof(HighFrequencyHeap)].Offset); - LowFrequencyHeap = target.ReadPointer(address + (ulong)type.Fields[nameof(LowFrequencyHeap)].Offset); - StaticsHeap = target.ReadPointer(address + (ulong)type.Fields[nameof(StaticsHeap)].Offset); - StubHeap = target.ReadPointer(address + (ulong)type.Fields[nameof(StubHeap)].Offset); - ExecutableHeap = target.ReadPointer(address + (ulong)type.Fields[nameof(ExecutableHeap)].Offset); + ReferenceCount = target.ReadField(address, type, nameof(ReferenceCount)); + HighFrequencyHeap = target.ReadPointerField(address, type, nameof(HighFrequencyHeap)); + LowFrequencyHeap = target.ReadPointerField(address, type, nameof(LowFrequencyHeap)); + StaticsHeap = target.ReadPointerField(address, type, nameof(StaticsHeap)); + StubHeap = target.ReadPointerField(address, type, nameof(StubHeap)); + ExecutableHeap = target.ReadPointerField(address, type, nameof(ExecutableHeap)); if (type.Fields.ContainsKey(nameof(FixupPrecodeHeap))) - FixupPrecodeHeap = target.ReadPointer(address + (ulong)type.Fields[nameof(FixupPrecodeHeap)].Offset); + FixupPrecodeHeap = target.ReadPointerField(address, type, nameof(FixupPrecodeHeap)); if (type.Fields.ContainsKey(nameof(NewStubPrecodeHeap))) - NewStubPrecodeHeap = target.ReadPointer(address + (ulong)type.Fields[nameof(NewStubPrecodeHeap)].Offset); + NewStubPrecodeHeap = target.ReadPointerField(address, type, nameof(NewStubPrecodeHeap)); if (type.Fields.ContainsKey(nameof(DynamicHelpersStubHeap))) - DynamicHelpersStubHeap = target.ReadPointer(address + (ulong)type.Fields[nameof(DynamicHelpersStubHeap)].Offset); + DynamicHelpersStubHeap = target.ReadPointerField(address, type, nameof(DynamicHelpersStubHeap)); - VirtualCallStubManager = target.ReadPointer(address + (ulong)type.Fields[nameof(VirtualCallStubManager)].Offset); + VirtualCallStubManager = target.ReadPointerField(address, type, nameof(VirtualCallStubManager)); ObjectHandle = target.ProcessedData.GetOrAdd( - target.ReadPointer(address + (ulong)type.Fields[nameof(ObjectHandle)].Offset)); + target.ReadPointerField(address, type, nameof(ObjectHandle))); } public uint ReferenceCount { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ManagedObjectWrapperHolderObject.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ManagedObjectWrapperHolderObject.cs index 5a2d81429021fe..761feb21dc1bbb 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ManagedObjectWrapperHolderObject.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ManagedObjectWrapperHolderObject.cs @@ -11,8 +11,8 @@ internal sealed class ManagedObjectWrapperHolderObject : IData(address + (ulong)type.Fields[nameof(RefCount)].Offset); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); - UserDefinedCount = target.Read(address + (ulong)type.Fields[nameof(UserDefinedCount)].Offset); - UserDefined = target.ReadPointer(address + (ulong)type.Fields[nameof(UserDefined)].Offset); - Dispatches = target.ReadPointer(address + (ulong)type.Fields[nameof(Dispatches)].Offset); + RefCount = target.ReadField(address, type, nameof(RefCount)); + Flags = target.ReadField(address, type, nameof(Flags)); + UserDefinedCount = target.ReadField(address, type, nameof(UserDefinedCount)); + UserDefined = target.ReadPointerField(address, type, nameof(UserDefined)); + Dispatches = target.ReadPointerField(address, type, nameof(Dispatches)); } public long RefCount { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDesc.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDesc.cs index 0181d329a8413a..5f7e1c5b307d6a 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDesc.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDesc.cs @@ -12,15 +12,15 @@ public MethodDesc(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.MethodDesc); - ChunkIndex = target.Read(address + (ulong)type.Fields[nameof(ChunkIndex)].Offset); - Slot = target.Read(address + (ulong)type.Fields[nameof(Slot)].Offset); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); - Flags3AndTokenRemainder = target.Read(address + (ulong)type.Fields[nameof(Flags3AndTokenRemainder)].Offset); - EntryPointFlags = target.Read(address + (ulong)type.Fields[nameof(EntryPointFlags)].Offset); - CodeData = target.ReadPointer(address + (ulong)type.Fields[nameof(CodeData)].Offset); + ChunkIndex = target.ReadField(address, type, nameof(ChunkIndex)); + Slot = target.ReadField(address, type, nameof(Slot)); + Flags = target.ReadField(address, type, nameof(Flags)); + Flags3AndTokenRemainder = target.ReadField(address, type, nameof(Flags3AndTokenRemainder)); + EntryPointFlags = target.ReadField(address, type, nameof(EntryPointFlags)); + CodeData = target.ReadPointerField(address, type, nameof(CodeData)); if (type.Fields.ContainsKey(nameof(GCCoverageInfo))) { - GCCoverageInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(GCCoverageInfo)].Offset); + GCCoverageInfo = target.ReadPointerField(address, type, nameof(GCCoverageInfo)); } } @@ -42,9 +42,9 @@ public InstantiatedMethodDesc(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.InstantiatedMethodDesc); - PerInstInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(PerInstInfo)].Offset); - NumGenericArgs = target.Read(address + (ulong)type.Fields[nameof(NumGenericArgs)].Offset); - Flags2 = target.Read(address + (ulong)type.Fields[nameof(Flags2)].Offset); + PerInstInfo = target.ReadPointerField(address, type, nameof(PerInstInfo)); + NumGenericArgs = target.ReadField(address, type, nameof(NumGenericArgs)); + Flags2 = target.ReadField(address, type, nameof(Flags2)); } public TargetPointer PerInstInfo { get; init; } @@ -59,7 +59,7 @@ public DynamicMethodDesc(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.DynamicMethodDesc); - MethodName = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodName)].Offset); + MethodName = target.ReadPointerField(address, type, nameof(MethodName)); } public TargetPointer MethodName { get; init; } @@ -72,9 +72,9 @@ public StoredSigMethodDesc(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.StoredSigMethodDesc); - Sig = target.ReadPointer(address + (ulong)type.Fields[nameof(Sig)].Offset); - cSig = target.Read(address + (ulong)type.Fields[nameof(cSig)].Offset); - ExtendedFlags = target.Read(address + (ulong)type.Fields[nameof(ExtendedFlags)].Offset); + Sig = target.ReadPointerField(address, type, nameof(Sig)); + cSig = target.ReadField(address, type, nameof(cSig)); + ExtendedFlags = target.ReadField(address, type, nameof(ExtendedFlags)); } public TargetPointer Sig { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescChunk.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescChunk.cs index a157f76e2c31fc..6af32d4ccf4380 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescChunk.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescChunk.cs @@ -12,11 +12,11 @@ public MethodDescChunk(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.MethodDescChunk); - MethodTable = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodTable)].Offset); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); - Size = target.Read(address + (ulong)type.Fields[nameof(Size)].Offset); - Count = target.Read(address + (ulong)type.Fields[nameof(Count)].Offset); - FlagsAndTokenRange = target.Read(address + (ulong)type.Fields[nameof(FlagsAndTokenRange)].Offset); + MethodTable = target.ReadPointerField(address, type, nameof(MethodTable)); + Next = target.ReadPointerField(address, type, nameof(Next)); + Size = target.ReadField(address, type, nameof(Size)); + Count = target.ReadField(address, type, nameof(Count)); + FlagsAndTokenRange = target.ReadField(address, type, nameof(FlagsAndTokenRange)); // The first MethodDesc is at the end of the MethodDescChunk FirstMethodDesc = address + type.Size!.Value; diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescCodeData.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescCodeData.cs index 69240ebb7bd86b..3c187bfb649311 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescCodeData.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescCodeData.cs @@ -11,9 +11,9 @@ public MethodDescCodeData(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.MethodDescCodeData); - TemporaryEntryPoint = target.ReadCodePointer(address + (ulong)type.Fields[nameof(TemporaryEntryPoint)].Offset); - VersioningState = target.ReadPointer(address + (ulong)type.Fields[nameof(VersioningState)].Offset); - OptimizationTier = target.Read(address + (ulong)type.Fields[nameof(OptimizationTier)].Offset); + TemporaryEntryPoint = target.ReadCodePointerField(address, type, nameof(TemporaryEntryPoint)); + VersioningState = target.ReadPointerField(address, type, nameof(VersioningState)); + OptimizationTier = target.ReadField(address, type, nameof(OptimizationTier)); } public TargetCodePointer TemporaryEntryPoint { get; set; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescVersioningState.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescVersioningState.cs index 95b404afa29508..4ed45c17c8590a 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescVersioningState.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodDescVersioningState.cs @@ -12,8 +12,8 @@ public MethodDescVersioningState(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.MethodDescVersioningState); - NativeCodeVersionNode = target.ReadPointer(address + (ulong)type.Fields[nameof(NativeCodeVersionNode)].Offset); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); + NativeCodeVersionNode = target.ReadPointerField(address, type, nameof(NativeCodeVersionNode)); + Flags = target.ReadField(address, type, nameof(Flags)); } public TargetPointer NativeCodeVersionNode { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodTable.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodTable.cs index 522927b02af44b..b7d994528215a3 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodTable.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodTable.cs @@ -10,16 +10,16 @@ public MethodTable(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.MethodTable); - MTFlags = target.Read(address + (ulong)type.Fields[nameof(MTFlags)].Offset); - BaseSize = target.Read(address + (ulong)type.Fields[nameof(BaseSize)].Offset); - MTFlags2 = target.Read(address + (ulong)type.Fields[nameof(MTFlags2)].Offset); - EEClassOrCanonMT = target.ReadPointer(address + (ulong)type.Fields[nameof(EEClassOrCanonMT)].Offset); - Module = target.ReadPointer(address + (ulong)type.Fields[nameof(Module)].Offset); - ParentMethodTable = target.ReadPointer(address + (ulong)type.Fields[nameof(ParentMethodTable)].Offset); - NumInterfaces = target.Read(address + (ulong)type.Fields[nameof(NumInterfaces)].Offset); - NumVirtuals = target.Read(address + (ulong)type.Fields[nameof(NumVirtuals)].Offset); - PerInstInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(PerInstInfo)].Offset); - AuxiliaryData = target.ReadPointer(address + (ulong)type.Fields[nameof(AuxiliaryData)].Offset); + MTFlags = target.ReadField(address, type, nameof(MTFlags)); + BaseSize = target.ReadField(address, type, nameof(BaseSize)); + MTFlags2 = target.ReadField(address, type, nameof(MTFlags2)); + EEClassOrCanonMT = target.ReadPointerField(address, type, nameof(EEClassOrCanonMT)); + Module = target.ReadPointerField(address, type, nameof(Module)); + ParentMethodTable = target.ReadPointerField(address, type, nameof(ParentMethodTable)); + NumInterfaces = target.ReadField(address, type, nameof(NumInterfaces)); + NumVirtuals = target.ReadField(address, type, nameof(NumVirtuals)); + PerInstInfo = target.ReadPointerField(address, type, nameof(PerInstInfo)); + AuxiliaryData = target.ReadPointerField(address, type, nameof(AuxiliaryData)); } public uint MTFlags { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodTableAuxiliaryData.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodTableAuxiliaryData.cs index 75b3109b4331e1..79a5b650bad3b3 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodTableAuxiliaryData.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/MethodTableAuxiliaryData.cs @@ -11,9 +11,9 @@ private MethodTableAuxiliaryData(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.MethodTableAuxiliaryData); - LoaderModule = target.ReadPointer(address + (ulong)type.Fields[nameof(LoaderModule)].Offset); - OffsetToNonVirtualSlots = target.Read(address + (ulong)type.Fields[nameof(OffsetToNonVirtualSlots)].Offset); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); + LoaderModule = target.ReadPointerField(address, type, nameof(LoaderModule)); + OffsetToNonVirtualSlots = target.ReadField(address, type, nameof(OffsetToNonVirtualSlots)); + Flags = target.ReadField(address, type, nameof(Flags)); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Module.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Module.cs index 2e7b7b589eb412..3871489d556fab 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Module.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Module.cs @@ -14,19 +14,19 @@ public Module(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.Module); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); - Assembly = target.ReadPointer(address + (ulong)type.Fields[nameof(Assembly)].Offset); - PEAssembly = target.ReadPointer(address + (ulong)type.Fields[nameof(PEAssembly)].Offset); - Base = target.ReadPointer(address + (ulong)type.Fields[nameof(Base)].Offset); - LoaderAllocator = target.ReadPointer(address + (ulong)type.Fields[nameof(LoaderAllocator)].Offset); - DynamicMetadata = target.ReadPointer(address + (ulong)type.Fields[nameof(DynamicMetadata)].Offset); - SimpleName = target.ReadPointer(address + (ulong)type.Fields[nameof(SimpleName)].Offset); - Path = target.ReadPointer(address + (ulong)type.Fields[nameof(Path)].Offset); - FileName = target.ReadPointer(address + (ulong)type.Fields[nameof(FileName)].Offset); - ReadyToRunInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(ReadyToRunInfo)].Offset); - GrowableSymbolStream = target.ReadPointer(address + (ulong)type.Fields[nameof(GrowableSymbolStream)].Offset); - AvailableTypeParams = target.ReadPointer(address + (ulong)type.Fields[nameof(AvailableTypeParams)].Offset); - InstMethodHashTable = target.ReadPointer(address + (ulong)type.Fields[nameof(InstMethodHashTable)].Offset); + Flags = target.ReadField(address, type, nameof(Flags)); + Assembly = target.ReadPointerField(address, type, nameof(Assembly)); + PEAssembly = target.ReadPointerField(address, type, nameof(PEAssembly)); + Base = target.ReadPointerField(address, type, nameof(Base)); + LoaderAllocator = target.ReadPointerField(address, type, nameof(LoaderAllocator)); + DynamicMetadata = target.ReadPointerField(address, type, nameof(DynamicMetadata)); + SimpleName = target.ReadPointerField(address, type, nameof(SimpleName)); + Path = target.ReadPointerField(address, type, nameof(Path)); + FileName = target.ReadPointerField(address, type, nameof(FileName)); + ReadyToRunInfo = target.ReadPointerField(address, type, nameof(ReadyToRunInfo)); + GrowableSymbolStream = target.ReadPointerField(address, type, nameof(GrowableSymbolStream)); + AvailableTypeParams = target.ReadPointerField(address, type, nameof(AvailableTypeParams)); + InstMethodHashTable = target.ReadPointerField(address, type, nameof(InstMethodHashTable)); FieldDefToDescMap = address + (ulong)type.Fields[nameof(FieldDefToDescMap)].Offset; ManifestModuleReferencesMap = address + (ulong)type.Fields[nameof(ManifestModuleReferencesMap)].Offset; @@ -35,7 +35,7 @@ public Module(Target target, TargetPointer address) TypeDefToMethodTableMap = address + (ulong)type.Fields[nameof(TypeDefToMethodTableMap)].Offset; TypeRefToMethodTableMap = address + (ulong)type.Fields[nameof(TypeRefToMethodTableMap)].Offset; MethodDefToILCodeVersioningStateMap = address + (ulong)type.Fields[nameof(MethodDefToILCodeVersioningStateMap)].Offset; - DynamicILBlobTable = target.ReadPointer(address + (ulong)type.Fields[nameof(DynamicILBlobTable)].Offset); + DynamicILBlobTable = target.ReadPointerField(address, type, nameof(DynamicILBlobTable)); } public TargetPointer Assembly { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ModuleLookupMap.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ModuleLookupMap.cs index 449dfb0cb04523..4c5da498608afc 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ModuleLookupMap.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ModuleLookupMap.cs @@ -11,10 +11,10 @@ private ModuleLookupMap(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ModuleLookupMap); - TableData = target.ReadPointer(address + (ulong)type.Fields[nameof(TableData)].Offset); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); - Count = target.Read(address + (ulong)type.Fields[nameof(Count)].Offset); - SupportedFlagsMask = target.ReadNUInt(address + (ulong)type.Fields[nameof(SupportedFlagsMask)].Offset); + TableData = target.ReadPointerField(address, type, nameof(TableData)); + Next = target.ReadPointerField(address, type, nameof(Next)); + Count = target.ReadField(address, type, nameof(Count)); + SupportedFlagsMask = target.ReadNUIntField(address, type, nameof(SupportedFlagsMask)); } public TargetPointer TableData { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeCodeVersionNode.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeCodeVersionNode.cs index 37a9655c15534c..29d2527d11d702 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeCodeVersionNode.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeCodeVersionNode.cs @@ -12,14 +12,14 @@ public NativeCodeVersionNode(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.NativeCodeVersionNode); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); - MethodDesc = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodDesc)].Offset); - NativeCode = target.ReadCodePointer(address + (ulong)type.Fields[nameof(NativeCode)].Offset); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); - ILVersionId = target.ReadNUInt(address + (ulong)type.Fields[nameof(ILVersionId)].Offset); + Next = target.ReadPointerField(address, type, nameof(Next)); + MethodDesc = target.ReadPointerField(address, type, nameof(MethodDesc)); + NativeCode = target.ReadCodePointerField(address, type, nameof(NativeCode)); + Flags = target.ReadField(address, type, nameof(Flags)); + ILVersionId = target.ReadNUIntField(address, type, nameof(ILVersionId)); if (type.Fields.ContainsKey(nameof(GCCoverageInfo))) { - GCCoverageInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(GCCoverageInfo)].Offset); + GCCoverageInfo = target.ReadPointerField(address, type, nameof(GCCoverageInfo)); } OptimizationTier = target.Read(address + (ulong)type.Fields[nameof(OptimizationTier)].Offset); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeObjectWrapperObject.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeObjectWrapperObject.cs index f1d61ef69559ec..a344ad5ad2c10f 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeObjectWrapperObject.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeObjectWrapperObject.cs @@ -11,7 +11,7 @@ internal sealed class NativeObjectWrapperObject : IData.Create(Target target, TargetPointer addr public ObjectHeader(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ObjectHeader); - SyncBlockValue = target.Read(address + (ulong)type.Fields[nameof(SyncBlockValue)].Offset); + SyncBlockValue = target.ReadField(address, type, nameof(SyncBlockValue)); } public uint SyncBlockValue { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEAssembly.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEAssembly.cs index 09a03cb527217a..6b0ce945896cd9 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEAssembly.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEAssembly.cs @@ -12,8 +12,8 @@ public PEAssembly(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.PEAssembly); - PEImage = target.ReadPointer(address + (ulong)type.Fields[nameof(PEImage)].Offset); - AssemblyBinder = target.ReadPointer(address + (ulong)type.Fields[nameof(AssemblyBinder)].Offset); + PEImage = target.ReadPointerField(address, type, nameof(PEImage)); + AssemblyBinder = target.ReadPointerField(address, type, nameof(AssemblyBinder)); } public TargetPointer PEImage { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEImage.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEImage.cs index 5731b28e2cd4ea..54636b9b559269 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEImage.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEImage.cs @@ -10,7 +10,7 @@ public PEImage(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.PEImage); - LoadedImageLayout = target.ReadPointer(address + (ulong)type.Fields[nameof(LoadedImageLayout)].Offset); + LoadedImageLayout = target.ReadPointerField(address, type, nameof(LoadedImageLayout)); ProbeExtensionResult = target.ProcessedData.GetOrAdd(address + (ulong)type.Fields[nameof(ProbeExtensionResult)].Offset); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEImageLayout.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEImageLayout.cs index 773bc0f26ce378..fb6876885aff52 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEImageLayout.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PEImageLayout.cs @@ -10,10 +10,10 @@ public PEImageLayout(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.PEImageLayout); - Base = target.ReadPointer(address + (ulong)type.Fields[nameof(Base)].Offset); - Size = target.Read(address + (ulong)type.Fields[nameof(Size)].Offset); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); - Format = target.Read(address + (ulong)type.Fields[nameof(Format)].Offset); + Base = target.ReadPointerField(address, type, nameof(Base)); + Size = target.ReadField(address, type, nameof(Size)); + Flags = target.ReadField(address, type, nameof(Flags)); + Format = target.ReadField(address, type, nameof(Format)); } public TargetPointer Base { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PatchpointInfo.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PatchpointInfo.cs index 482174b7465406..60a283d7031e83 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PatchpointInfo.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PatchpointInfo.cs @@ -14,7 +14,7 @@ public PatchpointInfo(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.PatchpointInfo); - LocalCount = target.Read(address + (ulong)type.Fields[nameof(LocalCount)].Offset); + LocalCount = target.ReadField(address, type, nameof(LocalCount)); } public uint LocalCount { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PlatformMetadata.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PlatformMetadata.cs index b58055f4486e32..96ca1d554ad2c6 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PlatformMetadata.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PlatformMetadata.cs @@ -12,7 +12,7 @@ public PlatformMetadata(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.PlatformMetadata); PrecodeMachineDescriptor = address + (ulong)type.Fields[nameof(PrecodeMachineDescriptor)].Offset; - CodePointerFlags = target.Read(address + (ulong)type.Fields[nameof(CodePointerFlags)].Offset); + CodePointerFlags = target.ReadField(address, type, nameof(CodePointerFlags)); } /* Address of */ diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PortableEntryPoint.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PortableEntryPoint.cs index 591d6e83420f28..d5ec1f3461c17a 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PortableEntryPoint.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PortableEntryPoint.cs @@ -12,7 +12,7 @@ public PortableEntryPoint(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.PortableEntryPoint); - MethodDesc = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodDesc)].Offset); + MethodDesc = target.ReadPointerField(address, type, nameof(MethodDesc)); } public TargetPointer MethodDesc { get; } } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PrecodeMachineDescriptor.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PrecodeMachineDescriptor.cs index 3e1ec015b41048..840059e1511c95 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PrecodeMachineDescriptor.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PrecodeMachineDescriptor.cs @@ -13,9 +13,9 @@ public PrecodeMachineDescriptor(Target target, TargetPointer address) Target.TypeInfo type = target.GetTypeInfo(DataType.PrecodeMachineDescriptor); if (type.Fields.ContainsKey(nameof(OffsetOfPrecodeType))) { - OffsetOfPrecodeType = target.Read(address + (ulong)type.Fields[nameof(OffsetOfPrecodeType)].Offset); - ReadWidthOfPrecodeType = target.Read(address + (ulong)type.Fields[nameof(ReadWidthOfPrecodeType)].Offset); - ShiftOfPrecodeType = target.Read(address + (ulong)type.Fields[nameof(ShiftOfPrecodeType)].Offset); + OffsetOfPrecodeType = target.ReadField(address, type, nameof(OffsetOfPrecodeType)); + ReadWidthOfPrecodeType = target.ReadField(address, type, nameof(ReadWidthOfPrecodeType)); + ShiftOfPrecodeType = target.ReadField(address, type, nameof(ShiftOfPrecodeType)); } else { @@ -23,12 +23,12 @@ public PrecodeMachineDescriptor(Target target, TargetPointer address) ReadWidthOfPrecodeType = null; ShiftOfPrecodeType = null; } - InvalidPrecodeType = target.Read(address + (ulong)type.Fields[nameof(InvalidPrecodeType)].Offset); - StubPrecodeType = target.Read(address + (ulong)type.Fields[nameof(StubPrecodeType)].Offset); + InvalidPrecodeType = target.ReadField(address, type, nameof(InvalidPrecodeType)); + StubPrecodeType = target.ReadField(address, type, nameof(StubPrecodeType)); if (type.Fields.ContainsKey(nameof(FixupStubPrecodeSize))) { - FixupStubPrecodeSize = target.Read(address + (ulong)type.Fields[nameof(FixupStubPrecodeSize)].Offset); + FixupStubPrecodeSize = target.ReadField(address, type, nameof(FixupStubPrecodeSize)); FixupBytes = new byte[FixupStubPrecodeSize.Value]; target.ReadBuffer(address + (ulong)type.Fields[nameof(FixupBytes)].Offset, FixupBytes); FixupIgnoredBytes = new byte[FixupStubPrecodeSize.Value]; @@ -43,7 +43,7 @@ public PrecodeMachineDescriptor(Target target, TargetPointer address) if (type.Fields.ContainsKey(nameof(StubPrecodeSize))) { - StubPrecodeSize = target.Read(address + (ulong)type.Fields[nameof(FixupStubPrecodeSize)].Offset); + StubPrecodeSize = target.ReadField(address, type, nameof(FixupStubPrecodeSize)); StubBytes = new byte[StubPrecodeSize.Value]; target.ReadBuffer(address + (ulong)type.Fields[nameof(StubBytes)].Offset, StubBytes); StubIgnoredBytes = new byte[StubPrecodeSize.Value]; @@ -63,7 +63,7 @@ public PrecodeMachineDescriptor(Target target, TargetPointer address) UMEntryPrecodeType = MaybeGetPrecodeType(target, address, nameof(UMEntryPrecodeType)); DynamicHelperPrecodeType = MaybeGetPrecodeType(target, address, nameof(DynamicHelperPrecodeType)); - StubCodePageSize = target.Read(address + (ulong)type.Fields[nameof(StubCodePageSize)].Offset); + StubCodePageSize = target.ReadField(address, type, nameof(StubCodePageSize)); static byte? MaybeGetPrecodeType(Target target, TargetPointer address, string fieldName) { diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ProbeExtensionResult.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ProbeExtensionResult.cs index d356170b30a81c..49d9a690662657 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ProbeExtensionResult.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ProbeExtensionResult.cs @@ -12,7 +12,7 @@ public ProbeExtensionResult(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ProbeExtensionResult); - Type = target.Read(address + (ulong)type.Fields[nameof(Type)].Offset); + Type = target.ReadField(address, type, nameof(Type)); } public int Type { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ProfControlBlock.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ProfControlBlock.cs index 6ff54d01f8bb62..e98a6134e3afe2 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ProfControlBlock.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ProfControlBlock.cs @@ -11,8 +11,8 @@ static ProfControlBlock IData.Create(Target target, TargetPoin public ProfControlBlock(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ProfControlBlock); - GlobalEventMask = target.Read(address + (ulong)type.Fields[nameof(GlobalEventMask)].Offset); - RejitOnAttachEnabled = target.Read(address + (ulong)type.Fields[nameof(RejitOnAttachEnabled)].Offset) != 0; + GlobalEventMask = target.ReadField(address, type, nameof(GlobalEventMask)); + RejitOnAttachEnabled = target.ReadField(address, type, nameof(RejitOnAttachEnabled)) != 0; } public ulong GlobalEventMask { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RCW.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RCW.cs index 2022ef69a101ea..f900d3e82fe18c 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RCW.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RCW.cs @@ -12,17 +12,17 @@ public RCW(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.RCW); - NextCleanupBucket = target.ReadPointer(address + (ulong)type.Fields[nameof(NextCleanupBucket)].Offset); - NextRCW = target.ReadPointer(address + (ulong)type.Fields[nameof(NextRCW)].Offset); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); - CtxCookie = target.ReadPointer(address + (ulong)type.Fields[nameof(CtxCookie)].Offset); - CtxEntry = target.ReadPointer(address + (ulong)type.Fields[nameof(CtxEntry)].Offset); - IdentityPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(IdentityPointer)].Offset); - SyncBlockIndex = target.Read(address + (ulong)type.Fields[nameof(SyncBlockIndex)].Offset); - VTablePtr = target.ReadPointer(address + (ulong)type.Fields[nameof(VTablePtr)].Offset); - CreatorThread = target.ReadPointer(address + (ulong)type.Fields[nameof(CreatorThread)].Offset); - RefCount = target.Read(address + (ulong)type.Fields[nameof(RefCount)].Offset); - UnknownPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(UnknownPointer)].Offset); + NextCleanupBucket = target.ReadPointerField(address, type, nameof(NextCleanupBucket)); + NextRCW = target.ReadPointerField(address, type, nameof(NextRCW)); + Flags = target.ReadField(address, type, nameof(Flags)); + CtxCookie = target.ReadPointerField(address, type, nameof(CtxCookie)); + CtxEntry = target.ReadPointerField(address, type, nameof(CtxEntry)); + IdentityPointer = target.ReadPointerField(address, type, nameof(IdentityPointer)); + SyncBlockIndex = target.ReadField(address, type, nameof(SyncBlockIndex)); + VTablePtr = target.ReadPointerField(address, type, nameof(VTablePtr)); + CreatorThread = target.ReadPointerField(address, type, nameof(CreatorThread)); + RefCount = target.ReadField(address, type, nameof(RefCount)); + UnknownPointer = target.ReadPointerField(address, type, nameof(UnknownPointer)); TargetPointer interfaceEntriesAddr = address + (ulong)type.Fields[nameof(InterfaceEntries)].Offset; uint cacheSize = target.ReadGlobal(Constants.Globals.RCWInterfaceCacheSize); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RCWCleanupList.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RCWCleanupList.cs index ede3543a0e66bf..a12947b7a9f079 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RCWCleanupList.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RCWCleanupList.cs @@ -10,7 +10,7 @@ public RCWCleanupList(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.RCWCleanupList); - FirstBucket = target.ReadPointer(address + (ulong)type.Fields[nameof(FirstBucket)].Offset); + FirstBucket = target.ReadPointerField(address, type, nameof(FirstBucket)); } public TargetPointer FirstBucket { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RangeSection.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RangeSection.cs index 2cd68418ce85cd..cf54d9ddcef9d6 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RangeSection.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RangeSection.cs @@ -11,13 +11,13 @@ static RangeSection IData.Create(Target target, TargetPointer addr public RangeSection(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.RangeSection); - RangeBegin = target.ReadPointer(address + (ulong)type.Fields[nameof(RangeBegin)].Offset); - RangeEndOpen = target.ReadPointer(address + (ulong)type.Fields[nameof(RangeEndOpen)].Offset); - NextForDelete = target.ReadPointer(address + (ulong)type.Fields[nameof(NextForDelete)].Offset); - JitManager = target.ReadPointer(address + (ulong)type.Fields[nameof(JitManager)].Offset); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); - HeapList = target.ReadPointer(address + (ulong)type.Fields[nameof(HeapList)].Offset); - R2RModule = target.ReadPointer(address + (ulong)type.Fields[nameof(R2RModule)].Offset); + RangeBegin = target.ReadPointerField(address, type, nameof(RangeBegin)); + RangeEndOpen = target.ReadPointerField(address, type, nameof(RangeEndOpen)); + NextForDelete = target.ReadPointerField(address, type, nameof(NextForDelete)); + JitManager = target.ReadPointerField(address, type, nameof(JitManager)); + Flags = target.ReadField(address, type, nameof(Flags)); + HeapList = target.ReadPointerField(address, type, nameof(HeapList)); + R2RModule = target.ReadPointerField(address, type, nameof(R2RModule)); } public TargetPointer RangeBegin { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RangeSectionFragment.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RangeSectionFragment.cs index 8073ad3dfe9094..b0c3d95f28ff17 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RangeSectionFragment.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RangeSectionFragment.cs @@ -11,12 +11,12 @@ static RangeSectionFragment IData.Create(Target target, Ta public RangeSectionFragment(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.RangeSectionFragment); - RangeBegin = target.ReadPointer(address + (ulong)type.Fields[nameof(RangeBegin)].Offset); - RangeEndOpen = target.ReadPointer(address + (ulong)type.Fields[nameof(RangeEndOpen)].Offset); - RangeSection = target.ReadPointer(address + (ulong)type.Fields[nameof(RangeSection)].Offset); + RangeBegin = target.ReadPointerField(address, type, nameof(RangeBegin)); + RangeEndOpen = target.ReadPointerField(address, type, nameof(RangeEndOpen)); + RangeSection = target.ReadPointerField(address, type, nameof(RangeSection)); // The Next pointer uses the low bit as a collectible flag (see RangeSectionFragmentPointer in codeman.h). // Strip it to get the actual address. - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset) & ~1ul; + Next = target.ReadPointerField(address, type, nameof(Next)) & ~1ul; } public TargetPointer RangeBegin { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunCoreHeader.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunCoreHeader.cs index 3419ee49abc0d1..75d53d3a5d941a 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunCoreHeader.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunCoreHeader.cs @@ -14,7 +14,7 @@ public ReadyToRunCoreHeader(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ReadyToRunCoreHeader); - NumberOfSections = target.Read(address + (ulong)type.Fields[nameof(NumberOfSections)].Offset); + NumberOfSections = target.ReadField(address, type, nameof(NumberOfSections)); Target.TypeInfo sectionType = target.GetTypeInfo(DataType.ReadyToRunSection); for (int i = 0; i < NumberOfSections; i++) { diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunCoreInfo.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunCoreInfo.cs index 48b4b988463e08..bbd0fbb6874a95 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunCoreInfo.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunCoreInfo.cs @@ -11,7 +11,7 @@ static ReadyToRunCoreInfo IData.Create(Target target, Target public ReadyToRunCoreInfo(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ReadyToRunCoreInfo); - TargetPointer headerAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(Header)].Offset); + TargetPointer headerAddress = target.ReadPointerField(address, type, nameof(Header)); Header = target.ProcessedData.GetOrAdd(headerAddress); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunHeader.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunHeader.cs index acc35d21d80859..934ce2b0deea41 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunHeader.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunHeader.cs @@ -12,8 +12,8 @@ public ReadyToRunHeader(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ReadyToRunHeader); - MajorVersion = target.Read(address + (ulong)type.Fields[nameof(MajorVersion)].Offset); - MinorVersion = target.Read(address + (ulong)type.Fields[nameof(MinorVersion)].Offset); + MajorVersion = target.ReadField(address, type, nameof(MajorVersion)); + MinorVersion = target.ReadField(address, type, nameof(MinorVersion)); } public ushort MajorVersion { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunInfo.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunInfo.cs index 843bc82f7f1328..3241fa45b965a0 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunInfo.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunInfo.cs @@ -14,29 +14,29 @@ public ReadyToRunInfo(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ReadyToRunInfo); - CompositeInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(CompositeInfo)].Offset); + CompositeInfo = target.ReadPointerField(address, type, nameof(CompositeInfo)); - ReadyToRunHeader = target.ReadPointer(address + (ulong)type.Fields[nameof(ReadyToRunHeader)].Offset); + ReadyToRunHeader = target.ReadPointerField(address, type, nameof(ReadyToRunHeader)); - NumRuntimeFunctions = target.Read(address + (ulong)type.Fields[nameof(NumRuntimeFunctions)].Offset); + NumRuntimeFunctions = target.ReadField(address, type, nameof(NumRuntimeFunctions)); RuntimeFunctions = NumRuntimeFunctions > 0 - ? target.ReadPointer(address + (ulong)type.Fields[nameof(RuntimeFunctions)].Offset) + ? target.ReadPointerField(address, type, nameof(RuntimeFunctions)) : TargetPointer.Null; - NumHotColdMap = target.Read(address + (ulong)type.Fields[nameof(NumHotColdMap)].Offset); + NumHotColdMap = target.ReadField(address, type, nameof(NumHotColdMap)); Debug.Assert(NumHotColdMap % 2 == 0, "Hot/cold map should have an even number of entries (pairs of hot/cold runtime function indexes)"); HotColdMap = NumHotColdMap > 0 - ? target.ReadPointer(address + (ulong)type.Fields[nameof(HotColdMap)].Offset) + ? target.ReadPointerField(address, type, nameof(HotColdMap)) : TargetPointer.Null; - DelayLoadMethodCallThunks = target.ReadPointer(address + (ulong)type.Fields[nameof(DelayLoadMethodCallThunks)].Offset); - DebugInfoSection = target.ReadPointer(address + (ulong)type.Fields[nameof(DebugInfoSection)].Offset); - ExceptionInfoSection = target.ReadPointer(address + (ulong)type.Fields[nameof(ExceptionInfoSection)].Offset); + DelayLoadMethodCallThunks = target.ReadPointerField(address, type, nameof(DelayLoadMethodCallThunks)); + DebugInfoSection = target.ReadPointerField(address, type, nameof(DebugInfoSection)); + ExceptionInfoSection = target.ReadPointerField(address, type, nameof(ExceptionInfoSection)); // Map is from the composite info pointer (set to itself for non-multi-assembly composite images) EntryPointToMethodDescMap = CompositeInfo + (ulong)type.Fields[nameof(EntryPointToMethodDescMap)].Offset; - LoadedImageBase = target.ReadPointer(address + (ulong)type.Fields[nameof(LoadedImageBase)].Offset); - Composite = target.ReadPointer(address + (ulong)type.Fields[nameof(Composite)].Offset); + LoadedImageBase = target.ReadPointerField(address, type, nameof(LoadedImageBase)); + Composite = target.ReadPointerField(address, type, nameof(Composite)); } internal TargetPointer CompositeInfo { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunSection.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunSection.cs index 8fcc22401f9dca..79b07573fc3c34 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunSection.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ReadyToRunSection.cs @@ -12,7 +12,7 @@ public ReadyToRunSection(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ReadyToRunSection); - Type = target.Read(address + (ulong)type.Fields[nameof(Type)].Offset); + Type = target.ReadField(address, type, nameof(Type)); Section = target.ProcessedData.GetOrAdd(address + (ulong)type.Fields[nameof(Section)].Offset); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RealCodeHeader.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RealCodeHeader.cs index 9111838126ae78..e141a55174a991 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RealCodeHeader.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RealCodeHeader.cs @@ -11,12 +11,12 @@ static RealCodeHeader IData.Create(Target target, TargetPointer public RealCodeHeader(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.RealCodeHeader); - MethodDesc = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodDesc)].Offset); - DebugInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(DebugInfo)].Offset); - EHInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(EHInfo)].Offset); - GCInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(GCInfo)].Offset); - NumUnwindInfos = target.Read(address + (ulong)type.Fields[nameof(NumUnwindInfos)].Offset); + MethodDesc = target.ReadPointerField(address, type, nameof(MethodDesc)); + DebugInfo = target.ReadPointerField(address, type, nameof(DebugInfo)); + GCInfo = target.ReadPointerField(address, type, nameof(GCInfo)); + NumUnwindInfos = target.ReadField(address, type, nameof(NumUnwindInfos)); UnwindInfos = address + (ulong)type.Fields[nameof(UnwindInfos)].Offset; + EHInfo = target.ReadPointerField(address, type, nameof(EHInfo)); } public TargetPointer MethodDesc { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RuntimeFunction.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RuntimeFunction.cs index f614803e0efabc..54a7bbe20fd17a 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RuntimeFunction.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RuntimeFunction.cs @@ -12,13 +12,13 @@ public RuntimeFunction(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.RuntimeFunction); - BeginAddress = target.Read(address + (ulong)type.Fields[nameof(BeginAddress)].Offset); + BeginAddress = target.ReadField(address, type, nameof(BeginAddress)); // Not all platforms define EndAddress if (type.Fields.ContainsKey(nameof(EndAddress))) - EndAddress = target.Read(address + (ulong)type.Fields[nameof(EndAddress)].Offset); + EndAddress = target.ReadField(address, type, nameof(EndAddress)); - UnwindData = target.Read(address + (ulong)type.Fields[nameof(UnwindData)].Offset); + UnwindData = target.ReadField(address, type, nameof(UnwindData)); } public uint BeginAddress { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SimpleComCallWrapper.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SimpleComCallWrapper.cs index 5739b64522130b..621ffb92081877 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SimpleComCallWrapper.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SimpleComCallWrapper.cs @@ -12,15 +12,15 @@ public SimpleComCallWrapper(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.SimpleComCallWrapper); - OuterIUnknown = target.ReadPointer(address + (ulong)type.Fields[nameof(OuterIUnknown)].Offset); - RefCount = target.Read(address + (ulong)type.Fields[nameof(RefCount)].Offset); - Flags = target.Read(address + (ulong)type.Fields[nameof(Flags)].Offset); - MainWrapper = target.ReadPointer(address + (ulong)type.Fields[nameof(MainWrapper)].Offset); + OuterIUnknown = target.ReadPointerField(address, type, nameof(OuterIUnknown)); + RefCount = target.ReadField(address, type, nameof(RefCount)); + Flags = target.ReadField(address, type, nameof(Flags)); + MainWrapper = target.ReadPointerField(address, type, nameof(MainWrapper)); VTablePtr = address + (ulong)type.Fields[nameof(VTablePtr)].Offset; } public TargetPointer OuterIUnknown { get; init; } - public ulong RefCount { get; init; } + public long RefCount { get; init; } public uint Flags { get; init; } public TargetPointer MainWrapper { get; init; } public TargetPointer VTablePtr { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLog.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLog.cs index b23eff5acda316..8745dcce81c3c8 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLog.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLog.cs @@ -14,19 +14,19 @@ public StressLog(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.StressLog); - LoggedFacilities = target.Read(address + (ulong)type.Fields[nameof(LoggedFacilities)].Offset); - Level = target.Read(address + (ulong)type.Fields[nameof(Level)].Offset); - MaxSizePerThread = target.Read(address + (ulong)type.Fields[nameof(MaxSizePerThread)].Offset); - MaxSizeTotal = target.Read(address + (ulong)type.Fields[nameof(MaxSizeTotal)].Offset); - TotalChunks = target.Read(address + (ulong)type.Fields[nameof(TotalChunks)].Offset); - TickFrequency = target.Read(address + (ulong)type.Fields[nameof(TickFrequency)].Offset); - StartTimestamp = target.Read(address + (ulong)type.Fields[nameof(StartTimestamp)].Offset); - ModuleOffset = target.ReadNUInt(address + (ulong)type.Fields[nameof(ModuleOffset)].Offset); + LoggedFacilities = target.ReadField(address, type, nameof(LoggedFacilities)); + Level = target.ReadField(address, type, nameof(Level)); + MaxSizePerThread = target.ReadField(address, type, nameof(MaxSizePerThread)); + MaxSizeTotal = target.ReadField(address, type, nameof(MaxSizeTotal)); + TotalChunks = target.ReadField(address, type, nameof(TotalChunks)); + TickFrequency = target.ReadField(address, type, nameof(TickFrequency)); + StartTimestamp = target.ReadField(address, type, nameof(StartTimestamp)); + ModuleOffset = target.ReadNUIntField(address, type, nameof(ModuleOffset)); if (type.Fields.ContainsKey(nameof(Modules))) - Modules = target.ReadPointer(address + (ulong)type.Fields[nameof(Modules)].Offset); + Modules = target.ReadPointerField(address, type, nameof(Modules)); - Logs = target.ReadPointer(address + (ulong)type.Fields[nameof(Logs)].Offset); + Logs = target.ReadPointerField(address, type, nameof(Logs)); } public uint LoggedFacilities { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLogChunk.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLogChunk.cs index fed0e5ba3c0c7b..9e4003e3fb4d37 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLogChunk.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLogChunk.cs @@ -12,12 +12,12 @@ public StressLogChunk(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.StressLogChunk); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); - Prev = target.ReadPointer(address + (ulong)type.Fields[nameof(Prev)].Offset); + Next = target.ReadPointerField(address, type, nameof(Next)); + Prev = target.ReadPointerField(address, type, nameof(Prev)); Buf = new TargetPointer(address + (ulong)type.Fields[nameof(Buf)].Offset); BufSize = target.ReadGlobal(Constants.Globals.StressLogChunkSize); - Sig1 = target.Read(address + (ulong)type.Fields[nameof(Sig1)].Offset); - Sig2 = target.Read(address + (ulong)type.Fields[nameof(Sig2)].Offset); + Sig1 = target.ReadField(address, type, nameof(Sig1)); + Sig2 = target.ReadField(address, type, nameof(Sig2)); } public TargetPointer Next { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLogModuleDesc.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLogModuleDesc.cs index 06a9fdc8be2173..f6303a34b40f4f 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLogModuleDesc.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StressLogModuleDesc.cs @@ -12,8 +12,8 @@ public StressLogModuleDesc(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.StressLogModuleDesc); - BaseAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(BaseAddress)].Offset); - Size = target.ReadNUInt(address + (ulong)type.Fields[nameof(Size)].Offset); + BaseAddress = target.ReadPointerField(address, type, nameof(BaseAddress)); + Size = target.ReadNUIntField(address, type, nameof(Size)); } public TargetPointer BaseAddress { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StubPrecodeData.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StubPrecodeData.cs index 442d3067c83f24..4486a8017b14a0 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StubPrecodeData.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/StubPrecodeData.cs @@ -11,8 +11,8 @@ static StubPrecodeData_1 IData.Create(Target target, TargetPo public StubPrecodeData_1(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.StubPrecodeData); - MethodDesc = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodDesc)].Offset); - Type = target.Read(address + (ulong)type.Fields[nameof(Type)].Offset); + MethodDesc = target.ReadPointerField(address, type, nameof(MethodDesc)); + Type = target.ReadField(address, type, nameof(Type)); } public TargetPointer MethodDesc { get; init; } @@ -27,8 +27,8 @@ static StubPrecodeData_2 IData.Create(Target target, TargetPo public StubPrecodeData_2(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.StubPrecodeData); - SecretParam = target.ReadPointer(address + (ulong)type.Fields[nameof(SecretParam)].Offset); - Type = target.Read(address + (ulong)type.Fields[nameof(Type)].Offset); + SecretParam = target.ReadPointerField(address, type, nameof(SecretParam)); + Type = target.ReadField(address, type, nameof(Type)); } public TargetPointer SecretParam { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncBlock.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncBlock.cs index 4d04c48e0cbcf6..e9a7cfbbd8bc63 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncBlock.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncBlock.cs @@ -13,16 +13,16 @@ public SyncBlock(Target target, TargetPointer address) Target.TypeInfo type = target.GetTypeInfo(DataType.SyncBlock); Address = address; - TargetPointer interopInfoPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(InteropInfo)].Offset); + TargetPointer interopInfoPointer = target.ReadPointerField(address, type, nameof(InteropInfo)); if (interopInfoPointer != TargetPointer.Null) InteropInfo = target.ProcessedData.GetOrAdd(interopInfoPointer); - TargetPointer lockPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(Lock)].Offset); + TargetPointer lockPointer = target.ReadPointerField(address, type, nameof(Lock)); if (lockPointer != TargetPointer.Null) Lock = target.ProcessedData.GetOrAdd(lockPointer); - ThinLock = target.Read(address + (ulong)type.Fields[nameof(ThinLock)].Offset); - LinkNext = target.ReadPointer(address + (ulong)type.Fields[nameof(LinkNext)].Offset); - HashCode = target.Read(address + (ulong)type.Fields[nameof(HashCode)].Offset); + ThinLock = target.ReadField(address, type, nameof(ThinLock)); + LinkNext = target.ReadPointerField(address, type, nameof(LinkNext)); + HashCode = target.ReadField(address, type, nameof(HashCode)); } public TargetPointer Address { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncBlockCache.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncBlockCache.cs index 517d2778b3dd0b..1811f6e97a1a43 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncBlockCache.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncBlockCache.cs @@ -12,8 +12,8 @@ public SyncBlockCache(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.SyncBlockCache); - FreeSyncTableIndex = target.Read(address + (ulong)type.Fields[nameof(FreeSyncTableIndex)].Offset); - CleanupBlockList = target.ReadPointer(address + (ulong)type.Fields[nameof(CleanupBlockList)].Offset); + FreeSyncTableIndex = target.ReadField(address, type, nameof(FreeSyncTableIndex)); + CleanupBlockList = target.ReadPointerField(address, type, nameof(CleanupBlockList)); } public uint FreeSyncTableIndex { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncTableEntry.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncTableEntry.cs index 415d0ae6b4497b..c9fae0ba0d08d1 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncTableEntry.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SyncTableEntry.cs @@ -12,11 +12,11 @@ public SyncTableEntry(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.SyncTableEntry); - TargetPointer syncBlockPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(SyncBlock)].Offset); + TargetPointer syncBlockPointer = target.ReadPointerField(address, type, nameof(SyncBlock)); if (syncBlockPointer != TargetPointer.Null) SyncBlock = target.ProcessedData.GetOrAdd(syncBlockPointer); - TargetPointer objectPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(Object)].Offset); + TargetPointer objectPointer = target.ReadPointerField(address, type, nameof(Object)); if (objectPointer != TargetPointer.Null && (objectPointer & 1) == 0) // Defensive check: if the lowest bit is set, this is a free sync block entry and the pointer is not valid. Object = target.ProcessedData.GetOrAdd(objectPointer); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SystemDomain.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SystemDomain.cs index 526ff3cdda71d0..03ab3e05cd2623 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SystemDomain.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/SystemDomain.cs @@ -12,7 +12,7 @@ public SystemDomain(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.SystemDomain); GlobalLoaderAllocator = address + (ulong)type.Fields[nameof(GlobalLoaderAllocator)].Offset; - SystemAssembly = target.ReadPointer(address + (ulong)type.Fields[nameof(SystemAssembly)].Offset); + SystemAssembly = target.ReadPointerField(address, type, nameof(SystemAssembly)); } public TargetPointer GlobalLoaderAllocator { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TLSIndex.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TLSIndex.cs index 6f76423fe7e364..20d419fc5db62d 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TLSIndex.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TLSIndex.cs @@ -11,7 +11,7 @@ internal sealed class TLSIndex : IData public TLSIndex(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.TLSIndex); - TLSIndexRawIndex = target.Read(address + (ulong)type.Fields[nameof(TLSIndexRawIndex)].Offset); + TLSIndexRawIndex = target.ReadField(address, type, nameof(TLSIndexRawIndex)); IndexOffset = (int)(TLSIndexRawIndex & 0xFFFFFF); IndexType = (int)(TLSIndexRawIndex >> 24); IsAllocated = (TLSIndexRawIndex != 0xFFFFFFFF); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TableSegment.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TableSegment.cs index 6ff3113662bf16..1ab229c38a82c4 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TableSegment.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TableSegment.cs @@ -10,7 +10,7 @@ internal sealed class TableSegment : IData public TableSegment(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.TableSegment); - NextSegment = target.ReadPointer(address + (ulong)type.Fields[nameof(NextSegment)].Offset); + NextSegment = target.ReadPointerField(address, type, nameof(NextSegment)); uint handleBlocksPerSegment = target.ReadGlobal(Constants.Globals.HandleBlocksPerSegment); uint handleMaxInternalTypes = target.ReadGlobal(Constants.Globals.HandleMaxInternalTypes); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThisPtrRetBufPrecodeData.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThisPtrRetBufPrecodeData.cs index 1468ec622ecf78..b2b6c7dae40d5e 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThisPtrRetBufPrecodeData.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThisPtrRetBufPrecodeData.cs @@ -11,7 +11,7 @@ static ThisPtrRetBufPrecodeData IData.Create(Target ta public ThisPtrRetBufPrecodeData(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ThisPtrRetBufPrecodeData); - MethodDesc = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodDesc)].Offset); + MethodDesc = target.ReadPointerField(address, type, nameof(MethodDesc)); } public TargetPointer MethodDesc { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Thread.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Thread.cs index 6d0d675b0db0ee..8cb0fe073b957d 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Thread.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Thread.cs @@ -12,39 +12,30 @@ public Thread(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.Thread); - Id = target.Read(address + (ulong)type.Fields[nameof(Id)].Offset); - OSId = target.ReadNUInt(address + (ulong)type.Fields[nameof(OSId)].Offset); - State = target.Read(address + (ulong)type.Fields[nameof(State)].Offset); - PreemptiveGCDisabled = target.Read(address + (ulong)type.Fields[nameof(PreemptiveGCDisabled)].Offset); + Id = target.ReadField(address, type, nameof(Id)); + OSId = target.ReadNUIntField(address, type, nameof(OSId)); + State = target.ReadField(address, type, nameof(State)); + PreemptiveGCDisabled = target.ReadField(address, type, nameof(PreemptiveGCDisabled)); - TargetPointer runtimeThreadLocalsPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(RuntimeThreadLocals)].Offset); - if (runtimeThreadLocalsPointer != TargetPointer.Null) - RuntimeThreadLocals = target.ProcessedData.GetOrAdd(runtimeThreadLocalsPointer); + RuntimeThreadLocals = target.ReadDataFieldPointer(address, type, nameof(RuntimeThreadLocals)); - Frame = target.ReadPointer(address + (ulong)type.Fields[nameof(Frame)].Offset); - CachedStackBase = target.ReadPointer(address + (ulong)type.Fields[nameof(CachedStackBase)].Offset); - CachedStackLimit = target.ReadPointer(address + (ulong)type.Fields[nameof(CachedStackLimit)].Offset); + Frame = target.ReadPointerField(address, type, nameof(Frame)); + CachedStackBase = target.ReadPointerField(address, type, nameof(CachedStackBase)); + CachedStackLimit = target.ReadPointerField(address, type, nameof(CachedStackLimit)); // TEB does not exist on certain platforms - TEB = type.Fields.TryGetValue(nameof(TEB), out Target.FieldInfo fieldInfo) - ? target.ReadPointer(address + (ulong)fieldInfo.Offset) - : TargetPointer.Null; + TEB = target.ReadPointerFieldOrNull(address, type, nameof(TEB)); LastThrownObject = target.ProcessedData.GetOrAdd( - target.ReadPointer(address + (ulong)type.Fields[nameof(LastThrownObject)].Offset)); - LinkNext = target.ReadPointer(address + (ulong)type.Fields[nameof(LinkNext)].Offset); + target.ReadPointerField(address, type, nameof(LastThrownObject))); + LinkNext = target.ReadPointerField(address, type, nameof(LinkNext)); // Address of the exception tracker ExceptionTracker = address + (ulong)type.Fields[nameof(ExceptionTracker)].Offset; // UEWatsonBucketTrackerBuckets does not exist on non-Windows platforms - UEWatsonBucketTrackerBuckets = type.Fields.TryGetValue(nameof(UEWatsonBucketTrackerBuckets), out Target.FieldInfo watsonFieldInfo) - ? target.ReadPointer(address + (ulong)watsonFieldInfo.Offset) - : TargetPointer.Null; - ThreadLocalDataPtr = target.ReadPointer(address + (ulong)type.Fields[nameof(ThreadLocalDataPtr)].Offset); - - DebuggerFilterContext = target.ReadPointer(address + (ulong)type.Fields[nameof(DebuggerFilterContext)].Offset); - ProfilerFilterContext = type.Fields.TryGetValue(nameof(ProfilerFilterContext), out Target.FieldInfo profilerFilterContextInfo) - ? target.ReadPointer(address + (ulong)profilerFilterContextInfo.Offset) - : TargetPointer.Null; + UEWatsonBucketTrackerBuckets = target.ReadPointerFieldOrNull(address, type, nameof(UEWatsonBucketTrackerBuckets)); + ThreadLocalDataPtr = target.ReadPointerField(address, type, nameof(ThreadLocalDataPtr)); + DebuggerFilterContext = target.ReadPointerField(address, type, nameof(DebuggerFilterContext)); + ProfilerFilterContext = target.ReadPointerFieldOrNull(address, type, nameof(ProfilerFilterContext)); } public uint Id { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadLocalData.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadLocalData.cs index 6ea3ce3204b68b..3d3fbebdd597dc 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadLocalData.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadLocalData.cs @@ -11,11 +11,11 @@ internal sealed class ThreadLocalData : IData public ThreadLocalData(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ThreadLocalData); - CollectibleTlsArrayData = target.ReadPointer(address + (ulong)type.Fields[nameof(CollectibleTlsArrayData)].Offset); - NonCollectibleTlsArrayData = target.ReadPointer(address + (ulong)type.Fields[nameof(NonCollectibleTlsArrayData)].Offset); - CollectibleTlsDataCount = target.Read(address + (ulong)type.Fields[nameof(CollectibleTlsDataCount)].Offset); - NonCollectibleTlsDataCount = target.Read(address + (ulong)type.Fields[nameof(NonCollectibleTlsDataCount)].Offset); - InFlightData = target.ReadPointer(address + (ulong)type.Fields[nameof(InFlightData)].Offset); + CollectibleTlsArrayData = target.ReadPointerField(address, type, nameof(CollectibleTlsArrayData)); + NonCollectibleTlsArrayData = target.ReadPointerField(address, type, nameof(NonCollectibleTlsArrayData)); + CollectibleTlsDataCount = target.ReadField(address, type, nameof(CollectibleTlsDataCount)); + NonCollectibleTlsDataCount = target.ReadField(address, type, nameof(NonCollectibleTlsDataCount)); + InFlightData = target.ReadPointerField(address, type, nameof(InFlightData)); } public TargetPointer CollectibleTlsArrayData { get; init; } public TargetPointer NonCollectibleTlsArrayData { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadStore.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadStore.cs index afef1e835be324..19e1a6b821fd05 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadStore.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadStore.cs @@ -12,12 +12,12 @@ public ThreadStore(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ThreadStore); - ThreadCount = target.Read(address + (ulong)type.Fields[nameof(ThreadCount)].Offset); - FirstThreadLink = target.ReadPointer(address + (ulong)type.Fields[nameof(FirstThreadLink)].Offset); - UnstartedCount = target.Read(address + (ulong)type.Fields[nameof(UnstartedCount)].Offset); - BackgroundCount = target.Read(address + (ulong)type.Fields[nameof(BackgroundCount)].Offset); - PendingCount = target.Read(address + (ulong)type.Fields[nameof(PendingCount)].Offset); - DeadCount = target.Read(address + (ulong)type.Fields[nameof(DeadCount)].Offset); + ThreadCount = target.ReadField(address, type, nameof(ThreadCount)); + FirstThreadLink = target.ReadPointerField(address, type, nameof(FirstThreadLink)); + UnstartedCount = target.ReadField(address, type, nameof(UnstartedCount)); + BackgroundCount = target.ReadField(address, type, nameof(BackgroundCount)); + PendingCount = target.ReadField(address, type, nameof(PendingCount)); + DeadCount = target.ReadField(address, type, nameof(DeadCount)); } public int ThreadCount { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadStressLog.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadStressLog.cs index 4c01c4d527e345..ee0fc1caf13f43 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadStressLog.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ThreadStressLog.cs @@ -12,13 +12,13 @@ public ThreadStressLog(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ThreadStressLog); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); - ThreadId = target.Read(address + (ulong)type.Fields[nameof(ThreadId)].Offset); - WriteHasWrapped = target.Read(address + (ulong)type.Fields[nameof(WriteHasWrapped)].Offset) != 0; - CurrentPtr = target.ReadPointer(address + (ulong)type.Fields[nameof(CurrentPtr)].Offset); - ChunkListHead = target.ReadPointer(address + (ulong)type.Fields[nameof(ChunkListHead)].Offset); - ChunkListTail = target.ReadPointer(address + (ulong)type.Fields[nameof(ChunkListTail)].Offset); - CurrentWriteChunk = target.ReadPointer(address + (ulong)type.Fields[nameof(CurrentWriteChunk)].Offset); + Next = target.ReadPointerField(address, type, nameof(Next)); + ThreadId = target.ReadField(address, type, nameof(ThreadId)); + WriteHasWrapped = target.ReadField(address, type, nameof(WriteHasWrapped)) != 0; + CurrentPtr = target.ReadPointerField(address, type, nameof(CurrentPtr)); + ChunkListHead = target.ReadPointerField(address, type, nameof(ChunkListHead)); + ChunkListTail = target.ReadPointerField(address, type, nameof(ChunkListTail)); + CurrentWriteChunk = target.ReadPointerField(address, type, nameof(CurrentWriteChunk)); } public TargetPointer Next { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TypeDesc.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TypeDesc.cs index e46782241e6bbf..9f14c6fc49e903 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TypeDesc.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/TypeDesc.cs @@ -9,7 +9,7 @@ internal sealed class TypeDesc : IData public TypeDesc(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.TypeDesc); - TypeAndFlags = target.Read(address + (ulong)type.Fields[nameof(TypeAndFlags)].Offset); + TypeAndFlags = target.ReadField(address, type, nameof(TypeAndFlags)); } public uint TypeAndFlags { get; init; } @@ -21,10 +21,10 @@ internal sealed class ParamTypeDesc : IData public ParamTypeDesc(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.TypeDesc); - TypeAndFlags = target.Read(address + (ulong)type.Fields[nameof(TypeAndFlags)].Offset); + TypeAndFlags = target.ReadField(address, type, nameof(TypeAndFlags)); type = target.GetTypeInfo(DataType.ParamTypeDesc); - TypeArg = target.ReadPointer(address + (ulong)type.Fields[nameof(TypeArg)].Offset); + TypeArg = target.ReadPointerField(address, type, nameof(TypeArg)); } public uint TypeAndFlags { get; init; } @@ -37,12 +37,12 @@ internal sealed class TypeVarTypeDesc : IData public TypeVarTypeDesc(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.TypeDesc); - TypeAndFlags = target.Read(address + (ulong)type.Fields[nameof(TypeAndFlags)].Offset); + TypeAndFlags = target.ReadField(address, type, nameof(TypeAndFlags)); type = target.GetTypeInfo(DataType.TypeVarTypeDesc); - Module = target.ReadPointer(address + (ulong)type.Fields[nameof(Module)].Offset); - Token = target.Read(address + (ulong)type.Fields[nameof(Token)].Offset); + Module = target.ReadPointerField(address, type, nameof(Module)); + Token = target.ReadField(address, type, nameof(Token)); } public uint TypeAndFlags { get; init; } @@ -56,14 +56,14 @@ internal sealed class FnPtrTypeDesc : IData public FnPtrTypeDesc(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.TypeDesc); - TypeAndFlags = target.Read(address + (ulong)type.Fields[nameof(TypeAndFlags)].Offset); + TypeAndFlags = target.ReadField(address, type, nameof(TypeAndFlags)); type = target.GetTypeInfo(DataType.FnPtrTypeDesc); - NumArgs = target.Read(address + (ulong)type.Fields[nameof(NumArgs)].Offset); - CallConv = target.Read(address + (ulong)type.Fields[nameof(CallConv)].Offset); + NumArgs = target.ReadField(address, type, nameof(NumArgs)); + CallConv = target.ReadField(address, type, nameof(CallConv)); RetAndArgTypes = (TargetPointer)(address + (ulong)type.Fields[nameof(RetAndArgTypes)].Offset); - LoaderModule = target.ReadPointer(address + (ulong)type.Fields[nameof(LoaderModule)].Offset); + LoaderModule = target.ReadPointerField(address, type, nameof(LoaderModule)); } public uint TypeAndFlags { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/UnwindInfo.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/UnwindInfo.cs index 6af069e342b7ca..f5b09b0a423a4e 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/UnwindInfo.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/UnwindInfo.cs @@ -17,7 +17,7 @@ public UnwindInfo(Target target, TargetPointer address) if (type.Fields.ContainsKey(nameof(FunctionLength))) { // The unwind info contains the function length on some platforms (x86) - FunctionLength = target.Read(address + (ulong)type.Fields[nameof(FunctionLength)].Offset); + FunctionLength = target.ReadField(address, type, nameof(FunctionLength)); } else { diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/VirtualCallStubManager.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/VirtualCallStubManager.cs index 3db6402ad829fc..1c24e6ba26dd4c 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/VirtualCallStubManager.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/VirtualCallStubManager.cs @@ -12,10 +12,10 @@ public VirtualCallStubManager(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.VirtualCallStubManager); - IndcellHeap = target.ReadPointer(address + (ulong)type.Fields[nameof(IndcellHeap)].Offset); + IndcellHeap = target.ReadPointerField(address, type, nameof(IndcellHeap)); if (type.Fields.ContainsKey(nameof(CacheEntryHeap))) - CacheEntryHeap = target.ReadPointer(address + (ulong)type.Fields[nameof(CacheEntryHeap)].Offset); + CacheEntryHeap = target.ReadPointerField(address, type, nameof(CacheEntryHeap)); } public TargetPointer IndcellHeap { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Microsoft.Diagnostics.DataContractReader.Contracts.csproj b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Microsoft.Diagnostics.DataContractReader.Contracts.csproj index 340a1b149d2578..1ea9babdc05006 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Microsoft.Diagnostics.DataContractReader.Contracts.csproj +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Microsoft.Diagnostics.DataContractReader.Contracts.csproj @@ -13,6 +13,7 @@ + diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/DataTypeVerificationGenerator.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/DataTypeVerificationGenerator.cs new file mode 100644 index 00000000000000..2974d79d8efa41 --- /dev/null +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/DataTypeVerificationGenerator.cs @@ -0,0 +1,113 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using Microsoft.CodeAnalysis; + +namespace Microsoft.Diagnostics.DataContractReader.Generators; + +/// +/// Source generator that discovers all IData implementations across +/// referenced assemblies and generates a static verification method that instantiates +/// each one against a noop Target. This enables load-time type validation without reflection. +/// +[Generator] +public class DataTypeVerificationGenerator : IIncrementalGenerator +{ + private const string IDataFullName = "Microsoft.Diagnostics.DataContractReader.Data.IData`1"; + + public void Initialize(IncrementalGeneratorInitializationContext context) + { + // Use the compilation to scan referenced assemblies for IData implementations + context.RegisterSourceOutput(context.CompilationProvider, Execute); + } + + private static void Execute(SourceProductionContext context, Compilation compilation) + { + INamedTypeSymbol? idataInterface = compilation.GetTypeByMetadataName(IDataFullName); + if (idataInterface is null) + return; + + StringBuilder sb = new StringBuilder(); + sb.AppendLine("// "); + sb.AppendLine("using System;"); + sb.AppendLine("using System.Diagnostics;"); + sb.AppendLine(); + sb.AppendLine("namespace Microsoft.Diagnostics.DataContractReader;"); + sb.AppendLine(); + sb.AppendLine("public static partial class DataDescriptorTypeVerification"); + sb.AppendLine("{"); + sb.AppendLine(" [Conditional(\"DEBUG\")]"); + sb.AppendLine(" static partial void VerifyAllDataTypes(Target verificationTarget)"); + sb.AppendLine(" {"); + + // Scan all types in the compilation and referenced assemblies + foreach (INamedTypeSymbol type in GetAllTypes(compilation)) + { + if (type.IsAbstract || type.TypeKind != TypeKind.Class) + continue; + + // Skip types not accessible from the consuming compilation + if (!compilation.IsSymbolAccessibleWithin(type, compilation.Assembly)) + continue; + + // Check if this class implements IData + bool implementsIData = type.AllInterfaces.Any(i => + i.IsGenericType && + SymbolEqualityComparer.Default.Equals(i.OriginalDefinition, idataInterface) && + SymbolEqualityComparer.Default.Equals(i.TypeArguments[0], type)); + + if (!implementsIData) + continue; + + string fullName = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + + sb.AppendLine($" TryCreate<{fullName}>(verificationTarget);"); + } + + sb.AppendLine(" }"); + sb.AppendLine(); + sb.AppendLine(" private static void TryCreate(Target target) where T : global::Microsoft.Diagnostics.DataContractReader.Data.IData"); + sb.AppendLine(" {"); + sb.AppendLine(" try { T.Create(target, default); }"); + sb.AppendLine(" catch (global::System.InvalidOperationException) { }"); + sb.AppendLine(" catch (global::System.Collections.Generic.KeyNotFoundException) { }"); + sb.AppendLine(" }"); + sb.AppendLine("}"); + + context.AddSource("DataDescriptorTypeVerification.g.cs", sb.ToString()); + } + + private static IEnumerable GetAllTypes(Compilation compilation) + { + // Get types from the current compilation + foreach (INamedTypeSymbol type in GetTypesFromNamespace(compilation.GlobalNamespace)) + yield return type; + + // Get types from all referenced assemblies + foreach (MetadataReference reference in compilation.References) + { + ISymbol? symbol = compilation.GetAssemblyOrModuleSymbol(reference); + if (symbol is IAssemblySymbol assembly) + { + foreach (INamedTypeSymbol type in GetTypesFromNamespace(assembly.GlobalNamespace)) + yield return type; + } + } + } + + private static IEnumerable GetTypesFromNamespace(INamespaceSymbol ns) + { + foreach (INamedTypeSymbol type in ns.GetTypeMembers()) + yield return type; + + foreach (INamespaceSymbol childNs in ns.GetNamespaceMembers()) + { + foreach (INamedTypeSymbol type in GetTypesFromNamespace(childNs)) + yield return type; + } + } +} diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/Microsoft.Diagnostics.DataContractReader.Generators.csproj b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/Microsoft.Diagnostics.DataContractReader.Generators.csproj new file mode 100644 index 00000000000000..c82e92a254e29d --- /dev/null +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/Microsoft.Diagnostics.DataContractReader.Generators.csproj @@ -0,0 +1,20 @@ + + + netstandard2.0 + true + cs + latest + enable + true + false + false + + + + + + + + + diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/DataDescriptorTypeVerification.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/DataDescriptorTypeVerification.cs new file mode 100644 index 00000000000000..bcb27cba2a7b89 --- /dev/null +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/DataDescriptorTypeVerification.cs @@ -0,0 +1,111 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics; + +namespace Microsoft.Diagnostics.DataContractReader; + +/// +/// Validates that Data class field reads are type-compatible with the declared types in the +/// data descriptor. In debug/checked builds, instantiates all IData types against a noop +/// Target to trigger Debug.Assert checks in TargetFieldExtensions. +/// The VerifyAllDataTypes partial method is generated by DataTypeVerificationGenerator. +/// +public static partial class DataDescriptorTypeVerification +{ + [Conditional("DEBUG")] + public static void VerifyDataTypes(Target realTarget) + { + TypeVerificationTarget verificationTarget = new TypeVerificationTarget(realTarget); + VerifyAllDataTypes(verificationTarget); + } + + // Generated by DataTypeVerificationGenerator — instantiates all IData types. + [Conditional("DEBUG")] + static partial void VerifyAllDataTypes(Target verificationTarget); + + /// + /// A Target wrapper that delegates type info lookups to the real target + /// but returns zeroes for all reads. Used for type verification without + /// requiring actual target memory. + /// + private sealed class TypeVerificationTarget : Target + { + private readonly Target _realTarget; + + public TypeVerificationTarget(Target realTarget) + { + _realTarget = realTarget; + ProcessedData = new NoopDataCache(this); + Contracts = realTarget.Contracts; + } + + public override int PointerSize => _realTarget.PointerSize; + public override bool IsLittleEndian => _realTarget.IsLittleEndian; + + public override TypeInfo GetTypeInfo(DataType type) => _realTarget.GetTypeInfo(type); + public override IDataCache ProcessedData { get; } + public override ContractRegistry Contracts { get; } + + public override bool TryGetThreadContext(ulong threadId, uint contextFlags, System.Span buffer) => false; + public override TargetPointer ReadGlobalPointer(string global) => TargetPointer.Null; + public override bool TryReadGlobalPointer(string name, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out TargetPointer? value) { value = null; return false; } + public override TargetPointer ReadPointer(ulong address) => TargetPointer.Null; + public override bool TryReadPointer(ulong address, out TargetPointer value) { value = TargetPointer.Null; return true; } + public override TargetCodePointer ReadCodePointer(ulong address) => (TargetCodePointer)0; + public override bool TryReadCodePointer(ulong address, out TargetCodePointer value) { value = (TargetCodePointer)0; return true; } + public override void ReadBuffer(ulong address, System.Span buffer) => buffer.Clear(); + public override void WriteBuffer(ulong address, System.Span buffer) { } + public override string ReadUtf8String(ulong address, bool strict = false) => string.Empty; + public override string ReadUtf16String(ulong address) => string.Empty; + public override TargetNUInt ReadNUInt(ulong address) => new(0); + public override bool TryReadGlobalString(string name, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string? value) { value = null; return false; } + public override string ReadGlobalString(string name) => string.Empty; + public override T ReadGlobal(string name) => default; + public override bool TryReadGlobal(string name, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? value) { value = default; return false; } + public override T Read(ulong address) => default; + public override T ReadLittleEndian(ulong address) => default; + public override bool TryRead(ulong address, out T value) { value = default; return true; } + public override void Write(ulong address, T value) { } + public override TargetPointer ReadPointerFromSpan(System.ReadOnlySpan bytes) => TargetPointer.Null; + public override bool IsAlignedToPointerSize(TargetPointer pointer) => true; + + private sealed class NoopDataCache : IDataCache + { + private readonly TypeVerificationTarget _target; + private readonly System.Collections.Generic.HashSet _inProgress = []; + + public NoopDataCache(TypeVerificationTarget target) + { + _target = target; + } + + public T GetOrAdd(TargetPointer address) where T : Data.IData + { + if (!_inProgress.Add(typeof(T))) + return default!; + + try + { + return T.Create(_target, address); + } + catch + { + return default!; + } + finally + { + _inProgress.Remove(typeof(T)); + } + } + + public bool TryGet(ulong address, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? data) + { + data = default; + return false; + } + + public void Clear() { } + } + } +} diff --git a/src/native/managed/cdac/tests/ContractDescriptor/TypeVerificationTests.cs b/src/native/managed/cdac/tests/ContractDescriptor/TypeVerificationTests.cs new file mode 100644 index 00000000000000..50d98370450920 --- /dev/null +++ b/src/native/managed/cdac/tests/ContractDescriptor/TypeVerificationTests.cs @@ -0,0 +1,127 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Diagnostics; +using System.IO; +using Microsoft.Diagnostics.DataContractReader.Data; +using Xunit; + +namespace Microsoft.Diagnostics.DataContractReader.Tests.ContractDescriptor; + +/// +/// Verifies that the managed Data class field reads are type-compatible with the +/// declared types in the native data descriptor. Loads a real contract descriptor +/// JSON (generated from a checked build) and instantiates Data types against a +/// noop Target to trigger Debug.Assert type checks in TargetFieldExtensions. +/// +public class TypeVerificationTests +{ + [Fact] + public void VerifyFieldTypes_CheckedDescriptor() + { + string descriptorPath = Path.Combine( + Path.GetDirectoryName(typeof(TypeVerificationTests).Assembly.Location)!, + "checked-descriptor.json"); + + if (!File.Exists(descriptorPath)) + return; + + byte[] descriptorBytes = File.ReadAllBytes(descriptorPath); + ContractDescriptorParser.ContractDescriptor? descriptor = + ContractDescriptorParser.ParseCompact(descriptorBytes); + + Assert.NotNull(descriptor); + + ContractDescriptorTarget target = ContractDescriptorTarget.Create( + descriptor, + globalPointerValues: [], + readFromTarget: static (address, buffer) => { buffer.Clear(); return 0; }, + writeToTarget: static (address, buffer) => 0, + getThreadContext: static (threadId, contextFlags, buffer) => -1, + isLittleEndian: BitConverter.IsLittleEndian, + pointerSize: IntPtr.Size, + additionalFactories: []); + + // Verify type info is present + Target.TypeInfo threadType = target.GetTypeInfo(DataType.Thread); + Assert.True(threadType.Fields.Count > 0); + Assert.Equal("uint32", threadType.Fields["Id"].TypeName); + + // Install a trace listener that throws on Debug.Assert failures + using ThrowingTraceListener listener = new(); + + // Verify the listener catches Debug.Assert + Assert.Throws(() => System.Diagnostics.Debug.Assert(false, "test")); + + // Instantiate Data types — the ThrowingTraceListener will convert any + // Debug.Assert type mismatch failures into exceptions that fail the test. + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + TryCreate(target); + } + + private static void CreateData(Target target) where T : IData + { + T.Create(target, default); + } + + private static void TryCreate(Target target) where T : IData + { + try + { + T.Create(target, default); + } + catch (InvalidOperationException) { } + catch (System.Collections.Generic.KeyNotFoundException) { } + } + + /// + /// A trace listener that converts Debug.Assert / Debug.Fail calls to exceptions. + /// Replaces the default trace listener to prevent process termination on assert failure. + /// + private sealed class ThrowingTraceListener : TraceListener, IDisposable + { + private readonly TraceListener[] _savedListeners; + + public ThrowingTraceListener() + { + // Save and remove all existing listeners (including DefaultTraceListener + // which would terminate the process on assert failure) + _savedListeners = new TraceListener[Trace.Listeners.Count]; + Trace.Listeners.CopyTo(_savedListeners, 0); + Trace.Listeners.Clear(); + Trace.Listeners.Add(this); + } + + public override void Write(string? message) { } + public override void WriteLine(string? message) { } + + public override void Fail(string? message, string? detailMessage) + { + throw new System.Exception($"Debug.Assert failed: {message} {detailMessage}"); + } + + void IDisposable.Dispose() + { + Trace.Listeners.Remove(this); + Trace.Listeners.AddRange(_savedListeners); + } + } +} diff --git a/src/native/managed/cdac/tests/ContractDescriptor/checked-descriptor.json b/src/native/managed/cdac/tests/ContractDescriptor/checked-descriptor.json new file mode 100644 index 00000000000000..ec556bb3500299 --- /dev/null +++ b/src/native/managed/cdac/tests/ContractDescriptor/checked-descriptor.json @@ -0,0 +1,2495 @@ +{ + "version": 1, + "baseline": "empty", + "types": { + "Thread": { + "Id": [ + 16, + "uint32" + ], + "OSId": [ + 256, + "nuint" + ], + "State": [ + 0, + "uint32" + ], + "PreemptiveGCDisabled": [ + 4, + "uint32" + ], + "RuntimeThreadLocals": [ + 32, + "pointer" + ], + "Frame": [ + 8, + "pointer" + ], + "CachedStackBase": [ + 152, + "pointer" + ], + "CachedStackLimit": [ + 160, + "pointer" + ], + "ExceptionTracker": [ + 312, + "pointer" + ], + "GCHandle": [ + 264, + "GCHandle" + ], + "LastThrownObject": [ + 296, + "GCHandle" + ], + "LinkNext": [ + 144, + "pointer" + ], + "ThreadLocalDataPtr": [ + 2624, + "pointer" + ], + "TEB": [ + 48, + "pointer" + ], + "UEWatsonBucketTrackerBuckets": [ + 328, + "pointer" + ] + }, + "ThreadStore": { + "FirstThreadLink": [ + 112, + "SLink" + ], + "ThreadCount": [ + 136, + "int32" + ], + "UnstartedCount": [ + 140, + "int32" + ], + "BackgroundCount": [ + 144, + "int32" + ], + "PendingCount": [ + 148, + "int32" + ], + "DeadCount": [ + 152, + "int32" + ] + }, + "RuntimeThreadLocals": { + "AllocContext": [ + 0, + "EEAllocContext" + ] + }, + "IdDispenser": { + "IdToThread": [ + 120, + "pointer" + ], + "HighestId": [ + 0, + "uint32" + ] + }, + "ThreadStaticsInfo": { + "!": 40, + "GCTlsIndex": [ + 4, + "TLSIndex" + ], + "NonGCTlsIndex": [ + 0, + "TLSIndex" + ] + }, + "ThreadLocalData": { + "CollectibleTlsArrayData": [ + 16, + "pointer" + ], + "NonCollectibleTlsArrayData": [ + 8, + "pointer" + ], + "CollectibleTlsDataCount": [ + 4, + "int32" + ], + "NonCollectibleTlsDataCount": [ + 0, + "int32" + ], + "InFlightData": [ + 40, + "pointer" + ] + }, + "InFlightTLSData": { + "Next": [ + 0, + "pointer" + ], + "TlsIndex": [ + 8, + "TLSIndex" + ], + "TLSData": [ + 16, + "pointer" + ] + }, + "TLSIndex": { + "TLSIndexRawIndex": [ + 0, + "uint32" + ] + }, + "EEAllocContext": { + "GCAllocationContext": [ + 8, + "GCAllocContext" + ] + }, + "GCAllocContext": { + "Pointer": [ + 0, + "pointer" + ], + "Limit": [ + 8, + "pointer" + ], + "AllocBytes": [ + 16, + "int64" + ], + "AllocBytesLoh": [ + 24, + "int64" + ] + }, + "Exception": { + "_message": [ + 16, + "pointer" + ], + "_innerException": [ + 32, + "pointer" + ], + "_stackTrace": [ + 48, + "pointer" + ], + "_watsonBuckets": [ + 56, + "pointer" + ], + "_stackTraceString": [ + 64, + "pointer" + ], + "_remoteStackTraceString": [ + 72, + "pointer" + ], + "_HResult": [ + 108, + "int32" + ], + "_xcode": [ + 104, + "int32" + ] + }, + "ExceptionInfo": { + "ThrownObjectHandle": [ + 8, + "pointer" + ], + "PreviousNestedInfo": [ + 0, + "pointer" + ], + "ExceptionWatsonBucketTrackerBuckets": [ + 144, + "pointer" + ] + }, + "GCHandle": { + "!": 8 + }, + "Object": { + "!": 8, + "m_pMethTab": [ + 0, + "pointer" + ] + }, + "ObjectHeader": { + "!": 8, + "SyncBlockValue": [ + 4, + "uint32" + ] + }, + "String": { + "m_FirstChar": [ + 12, + "pointer" + ], + "m_StringLength": [ + 8, + "uint32" + ] + }, + "Array": { + "!": 16, + "m_NumComponents": [ + 8, + "pointer" + ] + }, + "InteropSyncBlockInfo": { + "CCW": [ + 8, + "pointer" + ], + "RCW": [ + 24, + "pointer" + ], + "CCF": [ + 16, + "pointer" + ] + }, + "SyncBlock": { + "InteropInfo": [ + 16, + "pointer" + ], + "Lock": [ + 0, + "pointer" + ], + "ThinLock": [ + 8, + "uint32" + ], + "LinkNext": [ + 32, + "pointer" + ], + "HashCode": [ + 40, + "uint32" + ] + }, + "SLink": { + "Next": [ + 0, + "pointer" + ] + }, + "NativeObjectWrapperObject": { + "ExternalComObject": [ + 16, + "pointer" + ] + }, + "ManagedObjectWrapperHolderObject": { + "WrappedObject": [ + 16, + "pointer" + ], + "Wrapper": [ + 24, + "pointer" + ] + }, + "ManagedObjectWrapperLayout": { + "RefCount": [ + 8, + "int64" + ], + "Flags": [ + 16, + "int32" + ], + "UserDefinedCount": [ + 20, + "int32" + ], + "UserDefined": [ + 24, + "pointer" + ], + "Dispatches": [ + 32, + "pointer" + ] + }, + "ComInterfaceEntry": { + "!": 24, + "IID": [ + 0, + "nuint" + ] + }, + "InternalComInterfaceDispatch": { + "!": 64, + "Entries": [ + 8, + "pointer" + ] + }, + "SyncTableEntry": { + "!": 16, + "SyncBlock": [ + 0, + "pointer" + ], + "Object": [ + 8, + "pointer" + ] + }, + "Module": { + "Assembly": [ + 280, + "pointer" + ], + "PEAssembly": [ + 248, + "pointer" + ], + "Base": [ + 256, + "pointer" + ], + "Flags": [ + 264, + "uint32" + ], + "LoaderAllocator": [ + 208, + "pointer" + ], + "DynamicMetadata": [ + 968, + "pointer" + ], + "SimpleName": [ + 224, + "pointer" + ], + "Path": [ + 232, + "pointer" + ], + "FileName": [ + 240, + "pointer" + ], + "ReadyToRunInfo": [ + 832, + "pointer" + ], + "GrowableSymbolStream": [ + 504, + "pointer" + ], + "AvailableTypeParams": [ + 696, + "pointer" + ], + "InstMethodHashTable": [ + 808, + "pointer" + ], + "FieldDefToDescMap": [ + 576, + "pointer" + ], + "ManifestModuleReferencesMap": [ + 40, + "pointer" + ], + "MemberRefToDescMap": [ + 72, + "pointer" + ], + "MethodDefToDescMap": [ + 544, + "pointer" + ], + "TypeDefToMethodTableMap": [ + 512, + "pointer" + ], + "TypeRefToMethodTableMap": [ + 8, + "pointer" + ], + "MethodDefToILCodeVersioningStateMap": [ + 640, + "pointer" + ], + "DynamicILBlobTable": [ + 920, + "pointer" + ] + }, + "ModuleLookupMap": { + "TableData": [ + 8, + "pointer" + ], + "Next": [ + 0, + "pointer" + ], + "Count": [ + 16, + "uint32" + ], + "SupportedFlagsMask": [ + 24, + "nuint" + ] + }, + "Assembly": { + "IsCollectible": [ + 64, + "uint8" + ], + "IsDynamic": [ + 65, + "bool" + ], + "Module": [ + 16, + "pointer" + ], + "Error": [ + 80, + "pointer" + ], + "NotifyFlags": [ + 76, + "uint32" + ], + "IsLoaded": [ + 67, + "bool" + ] + }, + "LoaderAllocator": { + "ReferenceCount": [ + 2136, + "uint32" + ], + "HighFrequencyHeap": [ + 840, + "pointer" + ], + "LowFrequencyHeap": [ + 832, + "pointer" + ], + "StaticsHeap": [ + 848, + "pointer" + ], + "StubHeap": [ + 856, + "pointer" + ], + "ExecutableHeap": [ + 864, + "pointer" + ], + "FixupPrecodeHeap": [ + 880, + "pointer" + ], + "NewStubPrecodeHeap": [ + 888, + "pointer" + ], + "VirtualCallStubManager": [ + 2104, + "pointer" + ], + "ObjectHandle": [ + 896, + "pointer" + ] + }, + "VirtualCallStubManager": { + "IndcellHeap": [ + 744, + "pointer" + ], + "CacheEntryHeap": [ + 752, + "pointer" + ] + }, + "PEAssembly": { + "PEImage": [ + 48, + "pointer" + ], + "AssemblyBinder": [ + 104, + "pointer" + ] + }, + "AssemblyBinder": { + "AssemblyLoadContext": [ + 232, + "pointer" + ] + }, + "PEImage": { + "LoadedImageLayout": [ + 144, + "pointer" + ], + "ProbeExtensionResult": [ + 48, + "ProbeExtensionResult" + ] + }, + "PEImageLayout": { + "Base": [ + 16, + "pointer" + ], + "Size": [ + 24, + "uint32" + ], + "Flags": [ + 28, + "uint32" + ], + "Format": [ + 12, + "uint32" + ] + }, + "CGrowableSymbolStream": { + "Buffer": [ + 8, + "pointer" + ], + "Size": [ + 16, + "uint32" + ] + }, + "ProbeExtensionResult": { + "Type": [ + 0, + "int32" + ] + }, + "AppDomain": { + "RootAssembly": [ + 1528, + "pointer" + ], + "DomainAssemblyList": [ + 800, + "ArrayListBase" + ], + "FriendlyName": [ + 1520, + "pointer" + ] + }, + "SystemDomain": { + "GlobalLoaderAllocator": [ + 16, + "LoaderAllocator" + ], + "SystemAssembly": [ + 8, + "pointer" + ] + }, + "ArrayListBase": { + "Count": [ + 0, + "uint32" + ], + "FirstBlock": [ + 8, + "pointer" + ] + }, + "ArrayListBlock": { + "Next": [ + 0, + "pointer" + ], + "Size": [ + 8, + "uint32" + ], + "ArrayStart": [ + 16, + "pointer" + ] + }, + "MethodTable": { + "!": 72, + "MTFlags": [ + 0, + "uint32" + ], + "BaseSize": [ + 4, + "uint32" + ], + "MTFlags2": [ + 8, + "uint32" + ], + "EEClassOrCanonMT": [ + 48, + "pointer" + ], + "Module": [ + 32, + "pointer" + ], + "ParentMethodTable": [ + 24, + "pointer" + ], + "NumInterfaces": [ + 14, + "uint16" + ], + "NumVirtuals": [ + 12, + "uint16" + ], + "PerInstInfo": [ + 56, + "pointer" + ], + "AuxiliaryData": [ + 40, + "pointer" + ] + }, + "DynamicStaticsInfo": { + "!": 24, + "GCStatics": [ + 0, + "pointer" + ], + "NonGCStatics": [ + 8, + "pointer" + ] + }, + "MethodTableAuxiliaryData": { + "LoaderModule": [ + 8, + "pointer" + ], + "OffsetToNonVirtualSlots": [ + 2, + "int16" + ], + "Flags": [ + 0, + "uint32" + ] + }, + "EEClass": { + "MethodTable": [ + 32, + "pointer" + ], + "MethodDescChunk": [ + 48, + "pointer" + ], + "NumMethods": [ + 86, + "uint16" + ], + "FieldDescList": [ + 40, + "pointer" + ], + "CorTypeAttr": [ + 72, + "uint32" + ], + "InternalCorElementType": [ + 82, + "uint8" + ], + "NumInstanceFields": [ + 84, + "uint16" + ], + "NumStaticFields": [ + 88, + "uint16" + ], + "NumThreadStaticFields": [ + 92, + "uint16" + ], + "NumNonVirtualSlots": [ + 96, + "uint16" + ] + }, + "GenericsDictInfo": { + "NumDicts": [ + 4, + "uint16" + ], + "NumTypeArgs": [ + 6, + "uint16" + ] + }, + "TypeDesc": { + "TypeAndFlags": [ + 0, + "uint32" + ] + }, + "FieldDesc": { + "!": 24, + "DWord1": [ + 8, + "uint32" + ], + "DWord2": [ + 12, + "uint32" + ], + "MTOfEnclosingClass": [ + 0, + "pointer" + ] + }, + "ParamTypeDesc": { + "TypeArg": [ + 16, + "pointer" + ] + }, + "TypeVarTypeDesc": { + "Module": [ + 16, + "pointer" + ], + "Token": [ + 40, + "uint32" + ] + }, + "FnPtrTypeDesc": { + "NumArgs": [ + 24, + "uint32" + ], + "CallConv": [ + 28, + "uint32" + ], + "RetAndArgTypes": [ + 32, + "uint32" + ], + "LoaderModule": [ + 16, + "pointer" + ] + }, + "DynamicMetadata": { + "Size": [ + 0, + "uint32" + ], + "Data": [ + 4, + "pointer" + ] + }, + "StressLog": { + "!": 184, + "LoggedFacilities": [ + 0, + "uint32" + ], + "Level": [ + 4, + "uint32" + ], + "MaxSizePerThread": [ + 8, + "uint32" + ], + "MaxSizeTotal": [ + 12, + "uint32" + ], + "TotalChunks": [ + 16, + "uint32" + ], + "Logs": [ + 24, + "pointer" + ], + "TickFrequency": [ + 48, + "uint64" + ], + "StartTimestamp": [ + 56, + "uint64" + ], + "ModuleOffset": [ + 72, + "nuint" + ], + "Modules": [ + 80, + "pointer" + ] + }, + "StressLogModuleDesc": { + "!": 16, + "BaseAddress": [ + 0, + "pointer" + ], + "Size": [ + 8, + "nuint" + ] + }, + "ThreadStressLog": { + "Next": [ + 0, + "pointer" + ], + "ThreadId": [ + 8, + "uint64" + ], + "WriteHasWrapped": [ + 18, + "uint8" + ], + "CurrentPtr": [ + 24, + "pointer" + ], + "ChunkListHead": [ + 40, + "pointer" + ], + "ChunkListTail": [ + 48, + "pointer" + ], + "CurrentWriteChunk": [ + 64, + "pointer" + ] + }, + "StressLogChunk": { + "!": 32792, + "Prev": [ + 0, + "pointer" + ], + "Next": [ + 8, + "pointer" + ], + "Buf": [ + 16, + "pointer" + ], + "Sig1": [ + 32784, + "uint32" + ], + "Sig2": [ + 32788, + "uint32" + ] + }, + "StressMsgHeader": { + "!": 16 + }, + "StressMsg": { + "Header": [ + 0, + "StressMsgHeader" + ], + "Args": [ + 16, + "pointer" + ] + }, + "MethodDesc": { + "!": 64, + "ChunkIndex": [ + 2, + "uint8" + ], + "Slot": [ + 4, + "uint16" + ], + "Flags": [ + 6, + "uint16" + ], + "Flags3AndTokenRemainder": [ + 0, + "uint16" + ], + "EntryPointFlags": [ + 3, + "uint8" + ], + "CodeData": [ + 8, + "pointer" + ], + "GCCoverageInfo": [ + 56, + "pointer" + ] + }, + "MethodDescChunk": { + "!": 24, + "MethodTable": [ + 0, + "pointer" + ], + "Next": [ + 8, + "pointer" + ], + "Size": [ + 16, + "uint8" + ], + "Count": [ + 17, + "uint8" + ], + "FlagsAndTokenRange": [ + 18, + "uint16" + ] + }, + "NonVtableSlot": { + "!": 8 + }, + "MethodImpl": { + "!": 16 + }, + "NativeCodeSlot": { + "!": 8 + }, + "AsyncMethodData": { + "!": 24 + }, + "InstantiatedMethodDesc": { + "!": 88, + "PerInstInfo": [ + 72, + "pointer" + ], + "Flags2": [ + 80, + "uint16" + ], + "NumGenericArgs": [ + 82, + "uint16" + ] + }, + "StoredSigMethodDesc": { + "Sig": [ + 64, + "pointer" + ], + "cSig": [ + 72, + "uint32" + ], + "ExtendedFlags": [ + 76, + "uint32" + ] + }, + "DynamicMethodDesc": { + "!": 104, + "MethodName": [ + 80, + "pointer" + ] + }, + "ArrayMethodDesc": { + "!": 80 + }, + "FCallMethodDesc": { + "!": 72 + }, + "PInvokeMethodDesc": { + "!": 104 + }, + "EEImplMethodDesc": { + "!": 80 + }, + "CLRToCOMCallMethodDesc": { + "!": 72 + }, + "CodePointer": { + "!": 8 + }, + "MethodDescCodeData": { + "TemporaryEntryPoint": [ + 16, + "CodePointer" + ], + "VersioningState": [ + 0, + "pointer" + ] + }, + "MethodDescVersioningState": { + "NativeCodeVersionNode": [ + 16, + "pointer" + ], + "Flags": [ + 8, + "uint8" + ] + }, + "PrecodeMachineDescriptor": { + "InvalidPrecodeType": [ + 4, + "uint8" + ], + "PInvokeImportPrecodeType": [ + 5, + "uint8" + ], + "FixupPrecodeType": [ + 6, + "uint8" + ], + "FixupCodeOffset": [ + 7, + "uint8" + ], + "FixupStubPrecodeSize": [ + 8, + "uint8" + ], + "FixupBytes": [ + 9, + "pointer" + ], + "FixupIgnoredBytes": [ + 33, + "pointer" + ], + "StubPrecodeSize": [ + 57, + "uint8" + ], + "StubPrecodeType": [ + 58, + "uint8" + ], + "StubBytes": [ + 59, + "pointer" + ], + "StubIgnoredBytes": [ + 83, + "pointer" + ], + "ThisPointerRetBufPrecodeType": [ + 107, + "uint8" + ], + "InterpreterPrecodeType": [ + 108, + "uint8" + ], + "UMEntryPrecodeType": [ + 109, + "uint8" + ], + "StubCodePageSize": [ + 0, + "uint32" + ] + }, + "PlatformMetadata": { + "PrecodeMachineDescriptor": [ + 0, + "PrecodeMachineDescriptor" + ], + "CodePointerFlags": [ + 112, + "uint8" + ] + }, + "StubPrecodeData": { + "SecretParam": [ + 0, + "pointer" + ], + "Type": [ + 16, + "uint8" + ] + }, + "ThisPtrRetBufPrecodeData": { + "MethodDesc": [ + 8, + "pointer" + ] + }, + "FixupPrecodeData": { + "MethodDesc": [ + 8, + "pointer" + ] + }, + "ReadyToRunInfo": { + "ReadyToRunHeader": [ + 16, + "pointer" + ], + "CompositeInfo": [ + 40, + "pointer" + ], + "NumRuntimeFunctions": [ + 88, + "uint32" + ], + "RuntimeFunctions": [ + 80, + "pointer" + ], + "NumHotColdMap": [ + 104, + "uint32" + ], + "HotColdMap": [ + 96, + "pointer" + ], + "DelayLoadMethodCallThunks": [ + 112, + "pointer" + ], + "DebugInfoSection": [ + 120, + "pointer" + ], + "EntryPointToMethodDescMap": [ + 400, + "HashMap" + ], + "LoadedImageBase": [ + 584, + "pointer" + ], + "Composite": [ + 72, + "pointer" + ] + }, + "ReadyToRunHeader": { + "MajorVersion": [ + 4, + "uint16" + ], + "MinorVersion": [ + 6, + "uint16" + ] + }, + "ReadyToRunCoreHeader": { + "!": 8, + "Flags": [ + 0, + "uint32" + ], + "NumberOfSections": [ + 4, + "uint32" + ] + }, + "ReadyToRunCoreInfo": { + "Header": [ + 8, + "pointer" + ] + }, + "ReadyToRunSection": { + "!": 12, + "Type": [ + 0, + "uint32" + ], + "Section": [ + 4, + "ImageDataDirectory" + ] + }, + "ExceptionLookupTableEntry": { + "!": 8, + "MethodStartRVA": [ + 0, + "uint32" + ], + "ExceptionInfoRVA": [ + 4, + "uint32" + ] + }, + "ImageDataDirectory": { + "!": 8, + "VirtualAddress": [ + 0, + "uint32" + ], + "Size": [ + 4, + "uint32" + ] + }, + "RuntimeFunction": { + "!": 12, + "BeginAddress": [ + 0, + "uint32" + ], + "EndAddress": [ + 4, + "uint32" + ], + "UnwindData": [ + 8, + "uint32" + ] + }, + "UnwindInfo": {}, + "HashMap": { + "Buckets": [ + 24, + "pointer" + ] + }, + "Bucket": { + "!": 64, + "Keys": [ + 0, + "pointer" + ], + "Values": [ + 32, + "pointer" + ] + }, + "RangeSectionMap": { + "TopLevelData": [ + 0, + "pointer" + ] + }, + "RangeSectionFragment": { + "RangeBegin": [ + 8, + "pointer" + ], + "RangeEndOpen": [ + 16, + "pointer" + ], + "RangeSection": [ + 24, + "pointer" + ], + "Next": [ + 0, + "pointer" + ] + }, + "RangeSection": { + "RangeBegin": [ + 0, + "pointer" + ], + "RangeEndOpen": [ + 8, + "pointer" + ], + "NextForDelete": [ + 64, + "pointer" + ], + "JitManager": [ + 24, + "pointer" + ], + "Flags": [ + 16, + "int32" + ], + "HeapList": [ + 40, + "pointer" + ], + "R2RModule": [ + 32, + "pointer" + ] + }, + "EEJitManager": { + "StoreRichDebugInfo": [ + 188, + "bool" + ], + "AllCodeHeaps": [ + 16, + "pointer" + ] + }, + "RealCodeHeader": { + "MethodDesc": [ + 24, + "pointer" + ], + "DebugInfo": [ + 0, + "pointer" + ], + "GCInfo": [ + 16, + "pointer" + ], + "NumUnwindInfos": [ + 32, + "uint32" + ], + "UnwindInfos": [ + 36, + "RuntimeFunction" + ], + "JitEHInfo": [ + 8, + "pointer" + ] + }, + "EEExceptionClause": { + "!": 32, + "Flags": [ + 0, + "uint32" + ], + "TryStartPC": [ + 4, + "uint32" + ], + "TryEndPC": [ + 8, + "uint32" + ], + "HandlerStartPC": [ + 12, + "uint32" + ], + "HandlerEndPC": [ + 16, + "uint32" + ], + "TypeHandle": [ + 24, + "nuint" + ] + }, + "R2RExceptionClause": { + "!": 24, + "Flags": [ + 0, + "uint32" + ], + "TryStartPC": [ + 4, + "uint32" + ], + "TryEndPC": [ + 8, + "uint32" + ], + "HandlerStartPC": [ + 12, + "uint32" + ], + "HandlerEndPC": [ + 16, + "uint32" + ], + "ClassToken": [ + 20, + "uint32" + ] + }, + "EEILException": { + "Clauses": [ + 8, + "EEExceptionClause" + ] + }, + "CodeHeapListNode": { + "Next": [ + 0, + "pointer" + ], + "StartAddress": [ + 16, + "pointer" + ], + "EndAddress": [ + 24, + "pointer" + ], + "MapBase": [ + 32, + "pointer" + ], + "HeaderMap": [ + 40, + "pointer" + ] + }, + "ILCodeVersioningState": { + "FirstVersionNode": [ + 24, + "pointer" + ], + "ActiveVersionKind": [ + 0, + "uint32" + ], + "ActiveVersionNode": [ + 8, + "pointer" + ], + "ActiveVersionModule": [ + 8, + "pointer" + ], + "ActiveVersionMethodDef": [ + 16, + "uint32" + ] + }, + "NativeCodeVersionNode": { + "Next": [ + 24, + "pointer" + ], + "MethodDesc": [ + 8, + "pointer" + ], + "NativeCode": [ + 0, + "CodePointer" + ], + "Flags": [ + 60, + "uint32" + ], + "ILVersionId": [ + 16, + "nuint" + ], + "GCCoverageInfo": [ + 40, + "pointer" + ] + }, + "ILCodeVersionNode": { + "VersionId": [ + 16, + "nuint" + ], + "Next": [ + 24, + "pointer" + ], + "RejitState": [ + 32, + "uint32" + ], + "ILAddress": [ + 40, + "pointer" + ] + }, + "ProfControlBlock": { + "GlobalEventMask": [ + 1888, + "uint64" + ], + "RejitOnAttachEnabled": [ + 1926, + "bool" + ] + }, + "GCCoverageInfo": { + "SavedCode": [ + 1340, + "pointer" + ] + }, + "Frame": { + "Next": [ + 8, + "pointer" + ] + }, + "InlinedCallFrame": { + "!": 56, + "CallSiteSP": [ + 24, + "pointer" + ], + "CallerReturnAddress": [ + 32, + "pointer" + ], + "CalleeSavedFP": [ + 40, + "pointer" + ], + "Datum": [ + 16, + "pointer" + ] + }, + "SoftwareExceptionFrame": { + "!": 1520, + "TargetContext": [ + 288, + "pointer" + ], + "ReturnAddress": [ + 16, + "pointer" + ] + }, + "FramedMethodFrame": { + "!": 32, + "TransitionBlockPtr": [ + 16, + "pointer" + ], + "MethodDescPtr": [ + 24, + "pointer" + ] + }, + "TransitionBlock": { + "!": 72, + "ReturnAddress": [ + 64, + "pointer" + ], + "CalleeSavedRegisters": [ + 0, + "CalleeSavedRegisters" + ] + }, + "FuncEvalFrame": { + "!": 40, + "DebuggerEvalPtr": [ + 24, + "pointer" + ] + }, + "DebuggerEval": { + "!": 1376, + "TargetContext": [ + 0, + "pointer" + ], + "EvalDuringException": [ + 1350, + "bool" + ] + }, + "StubDispatchFrame": { + "!": 72, + "RepresentativeMTPtr": [ + 32, + "pointer" + ], + "MethodDescPtr": [ + 24, + "pointer" + ], + "RepresentativeSlot": [ + 40, + "uint32" + ] + }, + "ResumableFrame": { + "!": 24, + "TargetContextPtr": [ + 16, + "pointer" + ] + }, + "HijackFrame": { + "!": 40, + "ReturnAddress": [ + 16, + "pointer" + ], + "HijackArgsPtr": [ + 32, + "pointer" + ] + }, + "HijackArgs": { + "!": 96, + "CalleeSavedRegisters": [ + 16, + "CalleeSavedRegisters" + ], + "Rsp": [ + 80, + "pointer" + ] + }, + "FaultingExceptionFrame": { + "!": 1280, + "TargetContext": [ + 32, + "pointer" + ] + }, + "ArgumentRegisters": { + "!": 32 + }, + "CalleeSavedRegisters": { + "!": 64, + "Rdi": [ + 0, + "nuint" + ], + "Rsi": [ + 8, + "nuint" + ], + "Rbx": [ + 16, + "nuint" + ], + "Rbp": [ + 24, + "nuint" + ], + "R12": [ + 32, + "nuint" + ], + "R13": [ + 40, + "nuint" + ], + "R14": [ + 48, + "nuint" + ], + "R15": [ + 56, + "nuint" + ] + }, + "EETypeHashTable": { + "Buckets": [ + 16, + "pointer" + ], + "Count": [ + 24, + "uint32" + ], + "VolatileEntryValue": [ + 0, + "pointer" + ], + "VolatileEntryNextEntry": [ + 8, + "pointer" + ] + }, + "InstMethodHashTable": { + "Buckets": [ + 16, + "pointer" + ], + "Count": [ + 24, + "uint32" + ], + "VolatileEntryValue": [ + 0, + "pointer" + ], + "VolatileEntryNextEntry": [ + 8, + "pointer" + ] + }, + "CoreLibBinder": { + "Classes": [ + 8, + "pointer" + ] + }, + "DynamicILBlobTable": { + "!": 16, + "Table": [ + 0, + "pointer" + ], + "TableSize": [ + 8, + "uint32" + ], + "EntryMethodToken": [ + 0, + "uint32" + ], + "EntryIL": [ + 8, + "pointer" + ] + }, + "ComCallWrapper": { + "Handle": [ + 0, + "pointer" + ], + "SimpleWrapper": [ + 8, + "pointer" + ], + "IPtr": [ + 16, + "pointer" + ], + "Next": [ + 56, + "pointer" + ] + }, + "SimpleComCallWrapper": { + "OuterIUnknown": [ + 16, + "pointer" + ], + "RefCount": [ + 144, + "int64" + ], + "Flags": [ + 136, + "uint32" + ], + "MainWrapper": [ + 96, + "pointer" + ], + "VTablePtr": [ + 24, + "pointer" + ] + }, + "ComMethodTable": { + "!": 72, + "Flags": [ + 24, + "nuint" + ], + "MethodTable": [ + 8, + "pointer" + ] + }, + "RCWCleanupList": { + "FirstBucket": [ + 0, + "pointer" + ] + }, + "RCW": { + "NextCleanupBucket": [ + 0, + "pointer" + ], + "NextRCW": [ + 176, + "pointer" + ], + "Flags": [ + 168, + "uint32" + ], + "CtxCookie": [ + 192, + "pointer" + ], + "CtxEntry": [ + 200, + "pointer" + ], + "InterfaceEntries": [ + 8, + "pointer" + ], + "IdentityPointer": [ + 136, + "pointer" + ], + "SyncBlockIndex": [ + 144, + "uint32" + ], + "VTablePtr": [ + 184, + "pointer" + ], + "CreatorThread": [ + 160, + "pointer" + ], + "RefCount": [ + 148, + "uint32" + ], + "UnknownPointer": [ + 208, + "pointer" + ] + }, + "CtxEntry": { + "STAThread": [ + 24, + "pointer" + ], + "CtxCookie": [ + 0, + "pointer" + ] + }, + "InterfaceEntry": { + "!": 16, + "MethodTable": [ + 0, + "pointer" + ], + "Unknown": [ + 8, + "pointer" + ] + }, + "ComWrappersVtablePtrs": { + "!": 16 + }, + "SyncBlockCache": { + "FreeSyncTableIndex": [ + 140, + "uint32" + ], + "CleanupBlockList": [ + 0, + "pointer" + ] + } + }, + "globals": { + "GCInfoVersion": [ + "0x4", + "uint32" + ], + "InlinedCallFrameIdentifier": [ + "0x1", + "nuint" + ], + "ResumableFrameIdentifier": [ + "0x2", + "nuint" + ], + "RedirectedThreadFrameIdentifier": [ + "0x3", + "nuint" + ], + "FaultingExceptionFrameIdentifier": [ + "0x4", + "nuint" + ], + "SoftwareExceptionFrameIdentifier": [ + "0x5", + "nuint" + ], + "FuncEvalFrameIdentifier": [ + "0x6", + "nuint" + ], + "ComMethodFrameIdentifier": [ + "0x7", + "nuint" + ], + "CLRToCOMMethodFrameIdentifier": [ + "0x8", + "nuint" + ], + "ComPrestubMethodFrameIdentifier": [ + "0x9", + "nuint" + ], + "PInvokeCalliFrameIdentifier": [ + "0xa", + "nuint" + ], + "HijackFrameIdentifier": [ + "0xb", + "nuint" + ], + "PrestubMethodFrameIdentifier": [ + "0xc", + "nuint" + ], + "CallCountingHelperFrameIdentifier": [ + "0xd", + "nuint" + ], + "StubDispatchFrameIdentifier": [ + "0xe", + "nuint" + ], + "ResolveHelperFrameIdentifier": [ + "0xf", + "nuint" + ], + "ExternalMethodFrameIdentifier": [ + "0x10", + "nuint" + ], + "DynamicHelperFrameIdentifier": [ + "0x11", + "nuint" + ], + "ProtectValueClassFrameIdentifier": [ + "0x12", + "nuint" + ], + "DebuggerClassInitMarkFrameIdentifier": [ + "0x13", + "nuint" + ], + "DebuggerExitFrameIdentifier": [ + "0x14", + "nuint" + ], + "DebuggerU2MCatchHandlerFrameIdentifier": [ + "0x15", + "nuint" + ], + "ExceptionFilterFrameIdentifier": [ + "0x16", + "nuint" + ], + "InterpreterFrameIdentifier": [ + "0x17", + "nuint" + ], + "MethodDescTokenRemainderBitCount": [ + "0xc", + "uint8" + ], + "FeatureCOMInterop": [ + "0x1", + "uint8" + ], + "FeatureComWrappers": [ + "0x1", + "uint8" + ], + "FeatureObjCMarshal": [ + "0x0", + "uint8" + ], + "FeatureJavaMarshal": [ + "0x1", + "uint8" + ], + "FeatureOnStackReplacement": [ + "0x1", + "uint8" + ], + "FeatureWebcil": [ + "0x0", + "uint8" + ], + "ObjectToMethodTableUnmask": [ + "0x7", + "uint8" + ], + "FeaturePortableEntrypoints": [ + "0x0", + "uint8" + ], + "SOSBreakingChangeVersion": [ + "0x5", + "uint8" + ], + "RecommendedReaderVersion": [ + "0x1", + "uint32" + ], + "DirectorySeparator": [ + "0x5c", + "uint8" + ], + "HashMapSlotsPerBucket": [ + "0x4", + "uint32" + ], + "HashMapValueMask": [ + "0x7fffffffffffffff", + "uint64" + ], + "MethodDescAlignment": [ + "0x8", + "uint64" + ], + "ArrayBaseSize": [ + "0x18", + "uint32" + ], + "SyncBlockValueToObjectOffset": [ + "0x4", + "uint16" + ], + "StubCodeBlockLast": [ + "0xf", + "uint8" + ], + "DefaultADID": [ + "0x1", + "uint32" + ], + "SizeOfGenericModeBlock": [ + "0x15f0", + "uint32" + ], + "StaticsPointerMask": [ + "0xfffffffffffffffe", + "nuint" + ], + "PtrArrayOffsetToDataArray": [ + "0x10", + "nuint" + ], + "NumberOfTlsOffsetsNotUsedInNoncollectibleArray": [ + "0x2", + "uint8" + ], + "MaxClrNotificationArgs": [ + "0x3", + "uint32" + ], + "FieldOffsetBigRVA": [ + "0x7fffffa", + "uint32" + ], + "FieldOffsetDynamicRVA": [ + "0x7fffff9", + "uint32" + ], + "DispatchThisPtrMask": [ + "0xffffffffffffffc0", + "nuint" + ], + "StressLogEnabled": [ + "0x1", + "uint8" + ], + "StressLogHasModuleTable": [ + "0x1", + "uint8" + ], + "StressLogMaxModules": [ + "0x5", + "uint64" + ], + "StressLogChunkSize": [ + "0x8000", + "uint32" + ], + "StressLogValidChunkSig": [ + "0xcfcfcfcf", + "uint32" + ], + "StressLogMaxMessageSize": [ + "0x208", + "uint64" + ], + "SyncBlockMaskLockThreadId": [ + "0xffff", + "uint32" + ], + "SyncBlockMaskLockRecursionLevel": [ + "0x3f0000", + "uint32" + ], + "SyncBlockRecursionLevelShift": [ + "0x10", + "uint32" + ], + "SyncBlockIsHashOrSyncBlockIndex": [ + "0x8000000", + "uint32" + ], + "SyncBlockIsHashCode": [ + "0x4000000", + "uint32" + ], + "SyncBlockIndexMask": [ + "0x3ffffff", + "uint32" + ], + "SyncBlockHashCodeMask": [ + "0x3ffffff", + "uint32" + ], + "CCWNumInterfaces": [ + "0x5", + "uint32" + ], + "CCWThisMask": [ + "0xffffffffffffffc0", + "nuint" + ], + "RCWInterfaceCacheSize": [ + "0x8", + "uint32" + ], + "AppDomain": [ + [ + 1 + ], + "pointer" + ], + "SystemDomain": [ + [ + 2 + ], + "pointer" + ], + "ThreadStore": [ + [ + 3 + ], + "pointer" + ], + "FinalizerThread": [ + [ + 4 + ], + "pointer" + ], + "GCThread": [ + [ + 5 + ], + "pointer" + ], + "ClrNotificationArguments": [ + [ + 6 + ], + "pointer" + ], + "ArrayBoundsZero": [ + [ + 7 + ], + "pointer" + ], + "ContinuationMethodTable": [ + [ + 8 + ], + "pointer" + ], + "ExceptionMethodTable": [ + [ + 9 + ], + "pointer" + ], + "FreeObjectMethodTable": [ + [ + 10 + ], + "pointer" + ], + "ObjectMethodTable": [ + [ + 11 + ], + "pointer" + ], + "ObjectArrayMethodTable": [ + [ + 12 + ], + "pointer" + ], + "StringMethodTable": [ + [ + 13 + ], + "pointer" + ], + "SyncTableEntries": [ + [ + 14 + ], + "pointer" + ], + "MiniMetaDataBuffAddress": [ + [ + 15 + ], + "pointer" + ], + "MiniMetaDataBuffMaxSize": [ + [ + 16 + ], + "pointer" + ], + "DacNotificationFlags": [ + [ + 17 + ], + "pointer" + ], + "OffsetOfCurrentThreadInfo": [ + [ + 18 + ], + "pointer" + ], + "ThinlockThreadIdDispenser": [ + [ + 19 + ], + "pointer" + ], + "ComWrappersVtablePtrs": [ + [ + 20 + ], + "pointer" + ], + "GcNotificationFlags": [ + [ + 21 + ], + "pointer" + ], + "GlobalAllocContext": [ + [ + 22 + ], + "pointer" + ], + "CoreLib": [ + [ + 23 + ], + "pointer" + ], + "TlsIndexBase": [ + [ + 24 + ], + "pointer" + ], + "StressLog": [ + [ + 25 + ], + "pointer" + ], + "ExecutionManagerCodeRangeMapAddress": [ + [ + 26 + ], + "pointer" + ], + "EEJitManagerAddress": [ + [ + 27 + ], + "pointer" + ], + "PlatformMetadata": [ + [ + 28 + ], + "pointer" + ], + "ProfilerControlBlock": [ + [ + 29 + ], + "pointer" + ], + "SyncBlockCache": [ + [ + 30 + ], + "pointer" + ], + "GCLowestAddress": [ + [ + 31 + ], + "pointer" + ], + "GCHighestAddress": [ + [ + 32 + ], + "pointer" + ], + "TearOffAddRef": [ + [ + 33 + ], + "pointer" + ], + "TearOffAddRefSimple": [ + [ + 34 + ], + "pointer" + ], + "TearOffAddRefSimpleInner": [ + [ + 35 + ], + "pointer" + ], + "RCWCleanupList": [ + [ + 36 + ], + "pointer" + ], + "OperatingSystem": [ + "Windows", + "string" + ], + "Architecture": [ + "x64", + "string" + ], + "RID": [ + "win-x64", + "string" + ] + }, + "subDescriptors": { + "GC": [ + [ + 37 + ], + "pointer" + ] + }, + "contracts": { + "BuiltInCOM": 1, + "CodeVersions": 1, + "ComWrappers": 1, + "DacStreams": 1, + "DebugInfo": 2, + "EcmaMetadata": 1, + "Exception": 1, + "ExecutionManager": 2, + "GCInfo": 1, + "Loader": 1, + "Notifications": 1, + "Object": 1, + "PlatformMetadata": 1, + "PrecodeStubs": 3, + "ReJIT": 1, + "RuntimeInfo": 1, + "RuntimeTypeSystem": 1, + "SHash": 1, + "SignatureDecoder": 1, + "ConditionalWeakTable": 1, + "SyncBlock": 1, + "StackWalk": 1, + "StressLog": 2, + "Thread": 1 + } +} \ No newline at end of file From 8ad41e446b260ef0881effa1f33beb52020014e0 Mon Sep 17 00:00:00 2001 From: Max Charlamb Date: Thu, 26 Mar 2026 18:53:49 -0400 Subject: [PATCH 2/2] Convert remaining Data classes in subdirectories to typed field extensions Convert Data classes in Frames/, GC/, and root Data/ that were missed by the initial conversion (subdirectory files, string literal field keys, underscore-prefixed variable names). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../TargetFieldExtensions.cs | 2 + .../Data/Array.cs | 2 +- .../Data/AuxiliarySymbolInfo.cs | 4 +- .../Data/CardTableInfo.cs | 6 +- .../Data/CodeHeap.cs | 2 +- .../Data/DacEnumerableHash.cs | 4 +- .../Data/Debugger.cs | 6 +- .../Data/Exception.cs | 16 +- .../Data/Frames/DebuggerEval.cs | 2 +- .../Data/Frames/Frame.cs | 2 +- .../Data/Frames/FramedMethodFrame.cs | 4 +- .../Data/Frames/FuncEvalFrame.cs | 2 +- .../Data/Frames/HijackArgsAMD64.cs | 2 +- .../Data/Frames/HijackFrame.cs | 4 +- .../Data/Frames/InlinedCallFrame.cs | 10 +- .../Data/Frames/ResumableFrame.cs | 2 +- .../Data/Frames/SoftwareExceptionFrame.cs | 2 +- .../Data/Frames/StubDispatchFrame.cs | 6 +- .../Data/Frames/TailCallFrame.cs | 2 +- .../Data/Frames/TransitionBlock.cs | 2 +- .../Data/GC/GCHeapSVR.cs | 30 +- .../Data/GC/Generation.cs | 4 +- .../Data/GC/HeapSegment.cs | 18 +- .../Data/GC/OOMHistory.cs | 18 +- .../Data/HostCodeHeap.cs | 4 +- .../Data/NativeCodeVersionNode.cs | 2 +- .../Data/Object.cs | 2 +- .../Data/RegionFreeList.cs | 2 +- .../Data/String.cs | 2 +- ...ostics.DataContractReader.Contracts.csproj | 1 - .../DataTypeVerificationGenerator.cs | 113 - ...stics.DataContractReader.Generators.csproj | 20 - .../DataDescriptorTypeVerification.cs | 111 - .../TypeVerificationTests.cs | 127 - .../checked-descriptor.json | 2495 ----------------- 35 files changed, 83 insertions(+), 2948 deletions(-) delete mode 100644 src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/DataTypeVerificationGenerator.cs delete mode 100644 src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/Microsoft.Diagnostics.DataContractReader.Generators.csproj delete mode 100644 src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/DataDescriptorTypeVerification.cs delete mode 100644 src/native/managed/cdac/tests/ContractDescriptor/TypeVerificationTests.cs delete mode 100644 src/native/managed/cdac/tests/ContractDescriptor/checked-descriptor.json diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/TargetFieldExtensions.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/TargetFieldExtensions.cs index eb82cbdae0425d..007af1845cb798 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/TargetFieldExtensions.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/TargetFieldExtensions.cs @@ -144,6 +144,7 @@ public static T ReadDataField(this Target target, ulong address, Target.TypeI return target.ProcessedData.GetOrAdd(pointer); } + [Conditional("DEBUG")] private static void AssertPrimitiveType(Target.FieldInfo field, string fieldName) where T : unmanaged, IBinaryInteger, IMinMaxValue { @@ -152,6 +153,7 @@ private static void AssertPrimitiveType(Target.FieldInfo field, string fieldN $"Type mismatch reading field '{fieldName}': declared as '{field.TypeName}', reading as {typeof(T).Name}"); } + [Conditional("DEBUG")] private static void AssertPointerType(Target.FieldInfo field, string fieldName) { Debug.Assert( diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Array.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Array.cs index ea4748d6dd4cf2..8ea007c01f75c4 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Array.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Array.cs @@ -12,7 +12,7 @@ public Array(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.Array); - NumComponents = target.Read(address + (ulong)type.Fields[Constants.FieldNames.Array.NumComponents].Offset); + NumComponents = target.ReadField(address, type, Constants.FieldNames.Array.NumComponents); DataPointer = address + type.Size!.Value; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AuxiliarySymbolInfo.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AuxiliarySymbolInfo.cs index 77f0fb9054d499..40bc6632aed430 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AuxiliarySymbolInfo.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/AuxiliarySymbolInfo.cs @@ -12,8 +12,8 @@ public AuxiliarySymbolInfo(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.AuxiliarySymbolInfo); - Address = target.ReadCodePointer(address + (ulong)type.Fields[nameof(Address)].Offset); - Name = target.ReadPointer(address + (ulong)type.Fields[nameof(Name)].Offset); + Address = target.ReadCodePointerField(address, type, nameof(Address)); + Name = target.ReadPointerField(address, type, nameof(Name)); } public TargetCodePointer Address { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CardTableInfo.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CardTableInfo.cs index 360cd94915c2cb..5a64922dbadb17 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CardTableInfo.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CardTableInfo.cs @@ -11,9 +11,9 @@ static CardTableInfo IData.Create(Target target, TargetPointer ad public CardTableInfo(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.CardTableInfo); - Recount = target.Read(address + (ulong)type.Fields[nameof(Recount)].Offset); - Size = target.ReadNUInt(address + (ulong)type.Fields[nameof(Size)].Offset); - NextCardTable = target.ReadPointer(address + (ulong)type.Fields[nameof(NextCardTable)].Offset); + Recount = target.ReadField(address, type, nameof(Recount)); + Size = target.ReadNUIntField(address, type, nameof(Size)); + NextCardTable = target.ReadPointerField(address, type, nameof(NextCardTable)); } public uint Recount { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CodeHeap.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CodeHeap.cs index d88c9b7a384bf4..e7af1deef527ad 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CodeHeap.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CodeHeap.cs @@ -11,7 +11,7 @@ static CodeHeap IData.Create(Target target, TargetPointer address) public CodeHeap(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.CodeHeap); - HeapType = target.Read(address + (ulong)type.Fields[nameof(HeapType)].Offset); + HeapType = target.ReadField(address, type, nameof(HeapType)); } public byte HeapType { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DacEnumerableHash.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DacEnumerableHash.cs index b95af295eaecaa..ad4fe352f372aa 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DacEnumerableHash.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/DacEnumerableHash.cs @@ -29,8 +29,8 @@ public DacEnumerableHash(Target target, TargetPointer address, Target.TypeInfo t _target = target; _type = type; - Buckets = _target.ReadPointer(address + (ulong)_type.Fields[nameof(Buckets)].Offset); - Count = _target.Read(address + (ulong)_type.Fields[nameof(Count)].Offset); + Buckets = _target.ReadPointerField(address, _type, nameof(Buckets)); + Count = _target.ReadField(address, _type, nameof(Count)); // read items in the hash table uint length = GetLength(); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Debugger.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Debugger.cs index 3165d480333a8e..4955f3682cf5ed 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Debugger.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Debugger.cs @@ -12,9 +12,9 @@ public Debugger(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.Debugger); - LeftSideInitialized = target.Read(address + (ulong)type.Fields[nameof(LeftSideInitialized)].Offset); - Defines = target.Read(address + (ulong)type.Fields[nameof(Defines)].Offset); - MDStructuresVersion = target.Read(address + (ulong)type.Fields[nameof(MDStructuresVersion)].Offset); + LeftSideInitialized = target.ReadField(address, type, nameof(LeftSideInitialized)); + Defines = target.ReadField(address, type, nameof(Defines)); + MDStructuresVersion = target.ReadField(address, type, nameof(MDStructuresVersion)); } public int LeftSideInitialized { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Exception.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Exception.cs index 8f08dc08810e60..d43d56cae17e3f 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Exception.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Exception.cs @@ -12,14 +12,14 @@ public Exception(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.Exception); - Message = target.ReadPointer(address + (ulong)type.Fields["_message"].Offset); - InnerException = target.ReadPointer(address + (ulong)type.Fields["_innerException"].Offset); - StackTrace = target.ReadPointer(address + (ulong)type.Fields["_stackTrace"].Offset); - WatsonBuckets = target.ReadPointer(address + (ulong)type.Fields["_watsonBuckets"].Offset); - StackTraceString = target.ReadPointer(address + (ulong)type.Fields["_stackTraceString"].Offset); - RemoteStackTraceString = target.ReadPointer(address + (ulong)type.Fields["_remoteStackTraceString"].Offset); - HResult = target.Read(address + (ulong)type.Fields["_HResult"].Offset); - XCode = target.Read(address + (ulong)type.Fields["_xcode"].Offset); + Message = target.ReadPointerField(address, type, "_message"); + InnerException = target.ReadPointerField(address, type, "_innerException"); + StackTrace = target.ReadPointerField(address, type, "_stackTrace"); + WatsonBuckets = target.ReadPointerField(address, type, "_watsonBuckets"); + StackTraceString = target.ReadPointerField(address, type, "_stackTraceString"); + RemoteStackTraceString = target.ReadPointerField(address, type, "_remoteStackTraceString"); + HResult = target.ReadField(address, type, "_HResult"); + XCode = target.ReadField(address, type, "_xcode"); } public TargetPointer Message { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/DebuggerEval.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/DebuggerEval.cs index 31352b4cc6880a..e162ce98ae3771 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/DebuggerEval.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/DebuggerEval.cs @@ -12,7 +12,7 @@ public DebuggerEval(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.DebuggerEval); TargetContext = address + (ulong)type.Fields[nameof(TargetContext)].Offset; - EvalDuringException = target.Read(address + (ulong)type.Fields[nameof(EvalDuringException)].Offset) != 0; + EvalDuringException = target.ReadField(address, type, nameof(EvalDuringException)) != 0; Address = address; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/Frame.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/Frame.cs index cee27f37f723ad..4a3ea03d63edf7 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/Frame.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/Frame.cs @@ -12,7 +12,7 @@ public Frame(Target target, TargetPointer address) { Address = address; Target.TypeInfo type = target.GetTypeInfo(DataType.Frame); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); + Next = target.ReadPointerField(address, type, nameof(Next)); Identifier = target.ReadPointer(address); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/FramedMethodFrame.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/FramedMethodFrame.cs index 0fcb030bd239eb..ffe01581f9e7f2 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/FramedMethodFrame.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/FramedMethodFrame.cs @@ -11,8 +11,8 @@ static FramedMethodFrame IData.Create(Target target, TargetPo public FramedMethodFrame(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.FramedMethodFrame); - TransitionBlockPtr = target.ReadPointer(address + (ulong)type.Fields[nameof(TransitionBlockPtr)].Offset); - MethodDescPtr = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodDescPtr)].Offset); + TransitionBlockPtr = target.ReadPointerField(address, type, nameof(TransitionBlockPtr)); + MethodDescPtr = target.ReadPointerField(address, type, nameof(MethodDescPtr)); Address = address; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/FuncEvalFrame.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/FuncEvalFrame.cs index 65379d77d35f49..4dc74145f97458 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/FuncEvalFrame.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/FuncEvalFrame.cs @@ -14,7 +14,7 @@ static FuncEvalFrame IData.Create(Target target, TargetPointer ad public FuncEvalFrame(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.FuncEvalFrame); - DebuggerEvalPtr = target.ReadPointer(address + (ulong)type.Fields[nameof(DebuggerEvalPtr)].Offset); + DebuggerEvalPtr = target.ReadPointerField(address, type, nameof(DebuggerEvalPtr)); Address = address; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/HijackArgsAMD64.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/HijackArgsAMD64.cs index e6428549a154bd..811b84abc6508a 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/HijackArgsAMD64.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/HijackArgsAMD64.cs @@ -16,7 +16,7 @@ public HijackArgsAMD64(Target target, TargetPointer address) // On Windows, Rsp is present if (type.Fields.ContainsKey(nameof(Rsp))) { - Rsp = target.ReadPointer(address + (ulong)type.Fields[nameof(Rsp)].Offset); + Rsp = target.ReadPointerField(address, type, nameof(Rsp)); } } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/HijackFrame.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/HijackFrame.cs index db5061ed271bb0..cd971512063490 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/HijackFrame.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/HijackFrame.cs @@ -11,8 +11,8 @@ static HijackFrame IData.Create(Target target, TargetPointer addres public HijackFrame(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.HijackFrame); - ReturnAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(ReturnAddress)].Offset); - HijackArgsPtr = target.ReadPointer(address + (ulong)type.Fields[nameof(HijackArgsPtr)].Offset); + ReturnAddress = target.ReadPointerField(address, type, nameof(ReturnAddress)); + HijackArgsPtr = target.ReadPointerField(address, type, nameof(HijackArgsPtr)); Address = address; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/InlinedCallFrame.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/InlinedCallFrame.cs index b544c9fc6500cc..9ea5f779969770 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/InlinedCallFrame.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/InlinedCallFrame.cs @@ -11,12 +11,12 @@ static InlinedCallFrame IData.Create(Target target, TargetPoin public InlinedCallFrame(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.InlinedCallFrame); - CallSiteSP = target.ReadPointer(address + (ulong)type.Fields[nameof(CallSiteSP)].Offset); - CallerReturnAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(CallerReturnAddress)].Offset); - CalleeSavedFP = target.ReadPointer(address + (ulong)type.Fields[nameof(CalleeSavedFP)].Offset); + CallSiteSP = target.ReadPointerField(address, type, nameof(CallSiteSP)); + CallerReturnAddress = target.ReadPointerField(address, type, nameof(CallerReturnAddress)); + CalleeSavedFP = target.ReadPointerField(address, type, nameof(CalleeSavedFP)); if (type.Fields.ContainsKey(nameof(SPAfterProlog))) - SPAfterProlog = target.ReadPointer(address + (ulong)type.Fields[nameof(SPAfterProlog)].Offset); - Datum = target.ReadPointer(address + (ulong)type.Fields[nameof(Datum)].Offset); + SPAfterProlog = target.ReadPointerField(address, type, nameof(SPAfterProlog)); + Datum = target.ReadPointerField(address, type, nameof(Datum)); Address = address; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/ResumableFrame.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/ResumableFrame.cs index 3faa26701b2102..659710f668eb0c 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/ResumableFrame.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/ResumableFrame.cs @@ -11,7 +11,7 @@ static ResumableFrame IData.Create(Target target, TargetPointer public ResumableFrame(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.ResumableFrame); - TargetContextPtr = target.ReadPointer(address + (ulong)type.Fields[nameof(TargetContextPtr)].Offset); + TargetContextPtr = target.ReadPointerField(address, type, nameof(TargetContextPtr)); Address = address; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/SoftwareExceptionFrame.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/SoftwareExceptionFrame.cs index 0cec284982faea..33246adc7ac63e 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/SoftwareExceptionFrame.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/SoftwareExceptionFrame.cs @@ -13,7 +13,7 @@ public SoftwareExceptionFrame(Target target, TargetPointer address) Target.TypeInfo type = target.GetTypeInfo(DataType.SoftwareExceptionFrame); Address = address; TargetContext = address + (ulong)type.Fields[nameof(TargetContext)].Offset; - ReturnAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(ReturnAddress)].Offset); + ReturnAddress = target.ReadPointerField(address, type, nameof(ReturnAddress)); } public TargetPointer Address { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/StubDispatchFrame.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/StubDispatchFrame.cs index f4e677dafddaa9..c49f6919353255 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/StubDispatchFrame.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/StubDispatchFrame.cs @@ -11,9 +11,9 @@ static StubDispatchFrame IData.Create(Target target, TargetPo public StubDispatchFrame(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.StubDispatchFrame); - MethodDescPtr = target.ReadPointer(address + (ulong)type.Fields[nameof(MethodDescPtr)].Offset); - RepresentativeMTPtr = target.ReadPointer(address + (ulong)type.Fields[nameof(RepresentativeMTPtr)].Offset); - RepresentativeSlot = target.Read(address + (ulong)type.Fields[nameof(RepresentativeSlot)].Offset); + MethodDescPtr = target.ReadPointerField(address, type, nameof(MethodDescPtr)); + RepresentativeMTPtr = target.ReadPointerField(address, type, nameof(RepresentativeMTPtr)); + RepresentativeSlot = target.ReadField(address, type, nameof(RepresentativeSlot)); Address = address; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/TailCallFrame.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/TailCallFrame.cs index 41381ff5fe88c9..30322766dd84df 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/TailCallFrame.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/TailCallFrame.cs @@ -13,7 +13,7 @@ public TailCallFrame(Target target, TargetPointer address) Target.TypeInfo type = target.GetTypeInfo(DataType.TailCallFrame); Address = address; CalleeSavedRegisters = address + (ulong)type.Fields[nameof(CalleeSavedRegisters)].Offset; - ReturnAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(ReturnAddress)].Offset); + ReturnAddress = target.ReadPointerField(address, type, nameof(ReturnAddress)); } public TargetPointer Address { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/TransitionBlock.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/TransitionBlock.cs index 121e7ce2561650..b2c0c71cb47ef9 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/TransitionBlock.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Frames/TransitionBlock.cs @@ -11,7 +11,7 @@ static TransitionBlock IData.Create(Target target, TargetPointe public TransitionBlock(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.TransitionBlock); - ReturnAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(ReturnAddress)].Offset); + ReturnAddress = target.ReadPointerField(address, type, nameof(ReturnAddress)); CalleeSavedRegisters = address + (ulong)type.Fields[nameof(CalleeSavedRegisters)].Offset; if (type.Fields.ContainsKey(nameof(ArgumentRegisters))) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/GCHeapSVR.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/GCHeapSVR.cs index b6f4743149844e..7acf5d75459357 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/GCHeapSVR.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/GCHeapSVR.cs @@ -14,27 +14,27 @@ public GCHeapSVR(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.GCHeap); - MarkArray = target.ReadPointer(address + (ulong)type.Fields[nameof(MarkArray)].Offset); - NextSweepObj = target.ReadPointer(address + (ulong)type.Fields[nameof(NextSweepObj)].Offset); - BackgroundMinSavedAddr = target.ReadPointer(address + (ulong)type.Fields[nameof(BackgroundMinSavedAddr)].Offset); - BackgroundMaxSavedAddr = target.ReadPointer(address + (ulong)type.Fields[nameof(BackgroundMaxSavedAddr)].Offset); - AllocAllocated = target.ReadPointer(address + (ulong)type.Fields[nameof(AllocAllocated)].Offset); - EphemeralHeapSegment = target.ReadPointer(address + (ulong)type.Fields[nameof(EphemeralHeapSegment)].Offset); - CardTable = target.ReadPointer(address + (ulong)type.Fields[nameof(CardTable)].Offset); - FinalizeQueue = target.ReadPointer(address + (ulong)type.Fields[nameof(FinalizeQueue)].Offset); + MarkArray = target.ReadPointerField(address, type, nameof(MarkArray)); + NextSweepObj = target.ReadPointerField(address, type, nameof(NextSweepObj)); + BackgroundMinSavedAddr = target.ReadPointerField(address, type, nameof(BackgroundMinSavedAddr)); + BackgroundMaxSavedAddr = target.ReadPointerField(address, type, nameof(BackgroundMaxSavedAddr)); + AllocAllocated = target.ReadPointerField(address, type, nameof(AllocAllocated)); + EphemeralHeapSegment = target.ReadPointerField(address, type, nameof(EphemeralHeapSegment)); + CardTable = target.ReadPointerField(address, type, nameof(CardTable)); + FinalizeQueue = target.ReadPointerField(address, type, nameof(FinalizeQueue)); GenerationTable = address + (ulong)type.Fields[nameof(GenerationTable)].Offset; // Fields only exist segment GC builds if (type.Fields.ContainsKey(nameof(SavedSweepEphemeralSeg))) - SavedSweepEphemeralSeg = target.ReadPointer(address + (ulong)type.Fields[nameof(SavedSweepEphemeralSeg)].Offset); + SavedSweepEphemeralSeg = target.ReadPointerField(address, type, nameof(SavedSweepEphemeralSeg)); if (type.Fields.ContainsKey(nameof(SavedSweepEphemeralStart))) - SavedSweepEphemeralStart = target.ReadPointer(address + (ulong)type.Fields[nameof(SavedSweepEphemeralStart)].Offset); + SavedSweepEphemeralStart = target.ReadPointerField(address, type, nameof(SavedSweepEphemeralStart)); OomData = target.ProcessedData.GetOrAdd(address + (ulong)type.Fields[nameof(OomData)].Offset); - InternalRootArray = target.ReadPointer(address + (ulong)type.Fields[nameof(InternalRootArray)].Offset); - InternalRootArrayIndex = target.ReadNUInt(address + (ulong)type.Fields[nameof(InternalRootArrayIndex)].Offset); - HeapAnalyzeSuccess = target.Read(address + (ulong)type.Fields[nameof(HeapAnalyzeSuccess)].Offset) != 0; + InternalRootArray = target.ReadPointerField(address, type, nameof(InternalRootArray)); + InternalRootArrayIndex = target.ReadNUIntField(address, type, nameof(InternalRootArrayIndex)); + HeapAnalyzeSuccess = target.ReadField(address, type, nameof(HeapAnalyzeSuccess)) != 0; InterestingData = address + (ulong)type.Fields[nameof(InterestingData)].Offset; CompactReasons = address + (ulong)type.Fields[nameof(CompactReasons)].Offset; @@ -42,9 +42,9 @@ public GCHeapSVR(Target target, TargetPointer address) InterestingMechanismBits = address + (ulong)type.Fields[nameof(InterestingMechanismBits)].Offset; if (type.Fields.ContainsKey(nameof(FreeableSohSegment))) - FreeableSohSegment = target.ReadPointer(address + (ulong)type.Fields[nameof(FreeableSohSegment)].Offset); + FreeableSohSegment = target.ReadPointerField(address, type, nameof(FreeableSohSegment)); if (type.Fields.ContainsKey(nameof(FreeableUohSegment))) - FreeableUohSegment = target.ReadPointer(address + (ulong)type.Fields[nameof(FreeableUohSegment)].Offset); + FreeableUohSegment = target.ReadPointerField(address, type, nameof(FreeableUohSegment)); if (type.Fields.ContainsKey(nameof(FreeRegions))) FreeRegions = address + (ulong)type.Fields[nameof(FreeRegions)].Offset; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/Generation.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/Generation.cs index 347442c12cf70e..916dd9aea6e900 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/Generation.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/Generation.cs @@ -11,11 +11,11 @@ public Generation(Target target, TargetPointer address) Target.TypeInfo type = target.GetTypeInfo(DataType.Generation); AllocationContext = target.ProcessedData.GetOrAdd(address + (ulong)type.Fields[nameof(AllocationContext)].Offset); - StartSegment = target.ReadPointer(address + (ulong)type.Fields[nameof(StartSegment)].Offset); + StartSegment = target.ReadPointerField(address, type, nameof(StartSegment)); // Fields only exist segment GC builds if (type.Fields.ContainsKey(nameof(AllocationStart))) - AllocationStart = target.ReadPointer(address + (ulong)type.Fields[nameof(AllocationStart)].Offset); + AllocationStart = target.ReadPointerField(address, type, nameof(AllocationStart)); } public GCAllocContext AllocationContext { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/HeapSegment.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/HeapSegment.cs index 1ae541d30d6df5..60ed0f31a83c63 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/HeapSegment.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/HeapSegment.cs @@ -10,18 +10,18 @@ public HeapSegment(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.HeapSegment); - Allocated = target.ReadPointer(address + (ulong)type.Fields[nameof(Allocated)].Offset); - Committed = target.ReadPointer(address + (ulong)type.Fields[nameof(Committed)].Offset); - Reserved = target.ReadPointer(address + (ulong)type.Fields[nameof(Reserved)].Offset); - Used = target.ReadPointer(address + (ulong)type.Fields[nameof(Used)].Offset); - Mem = target.ReadPointer(address + (ulong)type.Fields[nameof(Mem)].Offset); - Flags = target.ReadNUInt(address + (ulong)type.Fields[nameof(Flags)].Offset); - Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); - BackgroundAllocated = target.ReadPointer(address + (ulong)type.Fields[nameof(BackgroundAllocated)].Offset); + Allocated = target.ReadPointerField(address, type, nameof(Allocated)); + Committed = target.ReadPointerField(address, type, nameof(Committed)); + Reserved = target.ReadPointerField(address, type, nameof(Reserved)); + Used = target.ReadPointerField(address, type, nameof(Used)); + Mem = target.ReadPointerField(address, type, nameof(Mem)); + Flags = target.ReadNUIntField(address, type, nameof(Flags)); + Next = target.ReadPointerField(address, type, nameof(Next)); + BackgroundAllocated = target.ReadPointerField(address, type, nameof(BackgroundAllocated)); // Field only exists in MULTIPLE_HEAPS builds if (type.Fields.ContainsKey(nameof(Heap))) - Heap = target.ReadPointer(address + (ulong)type.Fields[nameof(Heap)].Offset); + Heap = target.ReadPointerField(address, type, nameof(Heap)); } public TargetPointer Allocated { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/OOMHistory.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/OOMHistory.cs index 42f21fc5a589c8..5d46ed395611c3 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/OOMHistory.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GC/OOMHistory.cs @@ -10,15 +10,15 @@ public OomHistory(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.OomHistory); - Reason = target.Read(address + (ulong)type.Fields[nameof(Reason)].Offset); - AllocSize = target.ReadNUInt(address + (ulong)type.Fields[nameof(AllocSize)].Offset); - Reserved = target.ReadPointer(address + (ulong)type.Fields[nameof(Reserved)].Offset); - Allocated = target.ReadPointer(address + (ulong)type.Fields[nameof(Allocated)].Offset); - GcIndex = target.ReadNUInt(address + (ulong)type.Fields[nameof(GcIndex)].Offset); - Fgm = target.Read(address + (ulong)type.Fields[nameof(Fgm)].Offset); - Size = target.ReadNUInt(address + (ulong)type.Fields[nameof(Size)].Offset); - AvailablePagefileMb = target.ReadNUInt(address + (ulong)type.Fields[nameof(AvailablePagefileMb)].Offset); - LohP = target.Read(address + (ulong)type.Fields[nameof(LohP)].Offset); + Reason = target.ReadField(address, type, nameof(Reason)); + AllocSize = target.ReadNUIntField(address, type, nameof(AllocSize)); + Reserved = target.ReadPointerField(address, type, nameof(Reserved)); + Allocated = target.ReadPointerField(address, type, nameof(Allocated)); + GcIndex = target.ReadNUIntField(address, type, nameof(GcIndex)); + Fgm = target.ReadField(address, type, nameof(Fgm)); + Size = target.ReadNUIntField(address, type, nameof(Size)); + AvailablePagefileMb = target.ReadNUIntField(address, type, nameof(AvailablePagefileMb)); + LohP = target.ReadField(address, type, nameof(LohP)); } public int Reason { get; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HostCodeHeap.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HostCodeHeap.cs index e17cf7782cc5d3..1bf9d695c80d29 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HostCodeHeap.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/HostCodeHeap.cs @@ -11,8 +11,8 @@ static HostCodeHeap IData.Create(Target target, TargetPointer addr public HostCodeHeap(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.HostCodeHeap); - BaseAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(BaseAddress)].Offset); - CurrentAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(CurrentAddress)].Offset); + BaseAddress = target.ReadPointerField(address, type, nameof(BaseAddress)); + CurrentAddress = target.ReadPointerField(address, type, nameof(CurrentAddress)); } public TargetPointer BaseAddress { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeCodeVersionNode.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeCodeVersionNode.cs index 29d2527d11d702..7420b2a46c3f04 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeCodeVersionNode.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/NativeCodeVersionNode.cs @@ -21,7 +21,7 @@ public NativeCodeVersionNode(Target target, TargetPointer address) { GCCoverageInfo = target.ReadPointerField(address, type, nameof(GCCoverageInfo)); } - OptimizationTier = target.Read(address + (ulong)type.Fields[nameof(OptimizationTier)].Offset); + OptimizationTier = target.ReadField(address, type, nameof(OptimizationTier)); } public TargetPointer Next { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Object.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Object.cs index 6b0d32238963c7..07f00e259bb3f9 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Object.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Object.cs @@ -13,7 +13,7 @@ public Object(Target target, TargetPointer address) Target.TypeInfo type = target.GetTypeInfo(DataType.Object); Address = address; - MethodTable = target.ProcessedData.GetOrAdd(target.ReadPointer(address + (ulong)type.Fields["m_pMethTab"].Offset)); + MethodTable = target.ProcessedData.GetOrAdd(target.ReadPointerField(address, type, "m_pMethTab")); Data = address + (type.Size ?? throw new InvalidOperationException("Object size must be known")); } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RegionFreeList.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RegionFreeList.cs index d31afbc0bf459d..c617a42ef994e6 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RegionFreeList.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/RegionFreeList.cs @@ -11,7 +11,7 @@ static RegionFreeList IData.Create(Target target, TargetPointer public RegionFreeList(Target target, TargetPointer address) { Target.TypeInfo type = target.GetTypeInfo(DataType.RegionFreeList); - HeadFreeRegion = target.ReadPointer(address + (ulong)type.Fields[nameof(HeadFreeRegion)].Offset); + HeadFreeRegion = target.ReadPointerField(address, type, nameof(HeadFreeRegion)); } public TargetPointer HeadFreeRegion { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/String.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/String.cs index 088d1060a7d960..a8eb77e9adc383 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/String.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/String.cs @@ -13,7 +13,7 @@ public String(Target target, TargetPointer address) Target.TypeInfo type = target.GetTypeInfo(DataType.String); FirstChar = address + (ulong)type.Fields["m_FirstChar"].Offset; - StringLength = target.Read(address + (ulong)type.Fields["m_StringLength"].Offset); + StringLength = target.ReadField(address, type, "m_StringLength"); } public TargetPointer FirstChar { get; init; } diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Microsoft.Diagnostics.DataContractReader.Contracts.csproj b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Microsoft.Diagnostics.DataContractReader.Contracts.csproj index 1ea9babdc05006..340a1b149d2578 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Microsoft.Diagnostics.DataContractReader.Contracts.csproj +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Microsoft.Diagnostics.DataContractReader.Contracts.csproj @@ -13,7 +13,6 @@ - diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/DataTypeVerificationGenerator.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/DataTypeVerificationGenerator.cs deleted file mode 100644 index 2974d79d8efa41..00000000000000 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/DataTypeVerificationGenerator.cs +++ /dev/null @@ -1,113 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using System.Text; -using Microsoft.CodeAnalysis; - -namespace Microsoft.Diagnostics.DataContractReader.Generators; - -/// -/// Source generator that discovers all IData implementations across -/// referenced assemblies and generates a static verification method that instantiates -/// each one against a noop Target. This enables load-time type validation without reflection. -/// -[Generator] -public class DataTypeVerificationGenerator : IIncrementalGenerator -{ - private const string IDataFullName = "Microsoft.Diagnostics.DataContractReader.Data.IData`1"; - - public void Initialize(IncrementalGeneratorInitializationContext context) - { - // Use the compilation to scan referenced assemblies for IData implementations - context.RegisterSourceOutput(context.CompilationProvider, Execute); - } - - private static void Execute(SourceProductionContext context, Compilation compilation) - { - INamedTypeSymbol? idataInterface = compilation.GetTypeByMetadataName(IDataFullName); - if (idataInterface is null) - return; - - StringBuilder sb = new StringBuilder(); - sb.AppendLine("// "); - sb.AppendLine("using System;"); - sb.AppendLine("using System.Diagnostics;"); - sb.AppendLine(); - sb.AppendLine("namespace Microsoft.Diagnostics.DataContractReader;"); - sb.AppendLine(); - sb.AppendLine("public static partial class DataDescriptorTypeVerification"); - sb.AppendLine("{"); - sb.AppendLine(" [Conditional(\"DEBUG\")]"); - sb.AppendLine(" static partial void VerifyAllDataTypes(Target verificationTarget)"); - sb.AppendLine(" {"); - - // Scan all types in the compilation and referenced assemblies - foreach (INamedTypeSymbol type in GetAllTypes(compilation)) - { - if (type.IsAbstract || type.TypeKind != TypeKind.Class) - continue; - - // Skip types not accessible from the consuming compilation - if (!compilation.IsSymbolAccessibleWithin(type, compilation.Assembly)) - continue; - - // Check if this class implements IData - bool implementsIData = type.AllInterfaces.Any(i => - i.IsGenericType && - SymbolEqualityComparer.Default.Equals(i.OriginalDefinition, idataInterface) && - SymbolEqualityComparer.Default.Equals(i.TypeArguments[0], type)); - - if (!implementsIData) - continue; - - string fullName = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); - - sb.AppendLine($" TryCreate<{fullName}>(verificationTarget);"); - } - - sb.AppendLine(" }"); - sb.AppendLine(); - sb.AppendLine(" private static void TryCreate(Target target) where T : global::Microsoft.Diagnostics.DataContractReader.Data.IData"); - sb.AppendLine(" {"); - sb.AppendLine(" try { T.Create(target, default); }"); - sb.AppendLine(" catch (global::System.InvalidOperationException) { }"); - sb.AppendLine(" catch (global::System.Collections.Generic.KeyNotFoundException) { }"); - sb.AppendLine(" }"); - sb.AppendLine("}"); - - context.AddSource("DataDescriptorTypeVerification.g.cs", sb.ToString()); - } - - private static IEnumerable GetAllTypes(Compilation compilation) - { - // Get types from the current compilation - foreach (INamedTypeSymbol type in GetTypesFromNamespace(compilation.GlobalNamespace)) - yield return type; - - // Get types from all referenced assemblies - foreach (MetadataReference reference in compilation.References) - { - ISymbol? symbol = compilation.GetAssemblyOrModuleSymbol(reference); - if (symbol is IAssemblySymbol assembly) - { - foreach (INamedTypeSymbol type in GetTypesFromNamespace(assembly.GlobalNamespace)) - yield return type; - } - } - } - - private static IEnumerable GetTypesFromNamespace(INamespaceSymbol ns) - { - foreach (INamedTypeSymbol type in ns.GetTypeMembers()) - yield return type; - - foreach (INamespaceSymbol childNs in ns.GetNamespaceMembers()) - { - foreach (INamedTypeSymbol type in GetTypesFromNamespace(childNs)) - yield return type; - } - } -} diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/Microsoft.Diagnostics.DataContractReader.Generators.csproj b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/Microsoft.Diagnostics.DataContractReader.Generators.csproj deleted file mode 100644 index c82e92a254e29d..00000000000000 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Generators/Microsoft.Diagnostics.DataContractReader.Generators.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - netstandard2.0 - true - cs - latest - enable - true - false - false - - - - - - - - - diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/DataDescriptorTypeVerification.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/DataDescriptorTypeVerification.cs deleted file mode 100644 index bcb27cba2a7b89..00000000000000 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/DataDescriptorTypeVerification.cs +++ /dev/null @@ -1,111 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Diagnostics; - -namespace Microsoft.Diagnostics.DataContractReader; - -/// -/// Validates that Data class field reads are type-compatible with the declared types in the -/// data descriptor. In debug/checked builds, instantiates all IData types against a noop -/// Target to trigger Debug.Assert checks in TargetFieldExtensions. -/// The VerifyAllDataTypes partial method is generated by DataTypeVerificationGenerator. -/// -public static partial class DataDescriptorTypeVerification -{ - [Conditional("DEBUG")] - public static void VerifyDataTypes(Target realTarget) - { - TypeVerificationTarget verificationTarget = new TypeVerificationTarget(realTarget); - VerifyAllDataTypes(verificationTarget); - } - - // Generated by DataTypeVerificationGenerator — instantiates all IData types. - [Conditional("DEBUG")] - static partial void VerifyAllDataTypes(Target verificationTarget); - - /// - /// A Target wrapper that delegates type info lookups to the real target - /// but returns zeroes for all reads. Used for type verification without - /// requiring actual target memory. - /// - private sealed class TypeVerificationTarget : Target - { - private readonly Target _realTarget; - - public TypeVerificationTarget(Target realTarget) - { - _realTarget = realTarget; - ProcessedData = new NoopDataCache(this); - Contracts = realTarget.Contracts; - } - - public override int PointerSize => _realTarget.PointerSize; - public override bool IsLittleEndian => _realTarget.IsLittleEndian; - - public override TypeInfo GetTypeInfo(DataType type) => _realTarget.GetTypeInfo(type); - public override IDataCache ProcessedData { get; } - public override ContractRegistry Contracts { get; } - - public override bool TryGetThreadContext(ulong threadId, uint contextFlags, System.Span buffer) => false; - public override TargetPointer ReadGlobalPointer(string global) => TargetPointer.Null; - public override bool TryReadGlobalPointer(string name, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out TargetPointer? value) { value = null; return false; } - public override TargetPointer ReadPointer(ulong address) => TargetPointer.Null; - public override bool TryReadPointer(ulong address, out TargetPointer value) { value = TargetPointer.Null; return true; } - public override TargetCodePointer ReadCodePointer(ulong address) => (TargetCodePointer)0; - public override bool TryReadCodePointer(ulong address, out TargetCodePointer value) { value = (TargetCodePointer)0; return true; } - public override void ReadBuffer(ulong address, System.Span buffer) => buffer.Clear(); - public override void WriteBuffer(ulong address, System.Span buffer) { } - public override string ReadUtf8String(ulong address, bool strict = false) => string.Empty; - public override string ReadUtf16String(ulong address) => string.Empty; - public override TargetNUInt ReadNUInt(ulong address) => new(0); - public override bool TryReadGlobalString(string name, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string? value) { value = null; return false; } - public override string ReadGlobalString(string name) => string.Empty; - public override T ReadGlobal(string name) => default; - public override bool TryReadGlobal(string name, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? value) { value = default; return false; } - public override T Read(ulong address) => default; - public override T ReadLittleEndian(ulong address) => default; - public override bool TryRead(ulong address, out T value) { value = default; return true; } - public override void Write(ulong address, T value) { } - public override TargetPointer ReadPointerFromSpan(System.ReadOnlySpan bytes) => TargetPointer.Null; - public override bool IsAlignedToPointerSize(TargetPointer pointer) => true; - - private sealed class NoopDataCache : IDataCache - { - private readonly TypeVerificationTarget _target; - private readonly System.Collections.Generic.HashSet _inProgress = []; - - public NoopDataCache(TypeVerificationTarget target) - { - _target = target; - } - - public T GetOrAdd(TargetPointer address) where T : Data.IData - { - if (!_inProgress.Add(typeof(T))) - return default!; - - try - { - return T.Create(_target, address); - } - catch - { - return default!; - } - finally - { - _inProgress.Remove(typeof(T)); - } - } - - public bool TryGet(ulong address, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? data) - { - data = default; - return false; - } - - public void Clear() { } - } - } -} diff --git a/src/native/managed/cdac/tests/ContractDescriptor/TypeVerificationTests.cs b/src/native/managed/cdac/tests/ContractDescriptor/TypeVerificationTests.cs deleted file mode 100644 index 50d98370450920..00000000000000 --- a/src/native/managed/cdac/tests/ContractDescriptor/TypeVerificationTests.cs +++ /dev/null @@ -1,127 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Diagnostics; -using System.IO; -using Microsoft.Diagnostics.DataContractReader.Data; -using Xunit; - -namespace Microsoft.Diagnostics.DataContractReader.Tests.ContractDescriptor; - -/// -/// Verifies that the managed Data class field reads are type-compatible with the -/// declared types in the native data descriptor. Loads a real contract descriptor -/// JSON (generated from a checked build) and instantiates Data types against a -/// noop Target to trigger Debug.Assert type checks in TargetFieldExtensions. -/// -public class TypeVerificationTests -{ - [Fact] - public void VerifyFieldTypes_CheckedDescriptor() - { - string descriptorPath = Path.Combine( - Path.GetDirectoryName(typeof(TypeVerificationTests).Assembly.Location)!, - "checked-descriptor.json"); - - if (!File.Exists(descriptorPath)) - return; - - byte[] descriptorBytes = File.ReadAllBytes(descriptorPath); - ContractDescriptorParser.ContractDescriptor? descriptor = - ContractDescriptorParser.ParseCompact(descriptorBytes); - - Assert.NotNull(descriptor); - - ContractDescriptorTarget target = ContractDescriptorTarget.Create( - descriptor, - globalPointerValues: [], - readFromTarget: static (address, buffer) => { buffer.Clear(); return 0; }, - writeToTarget: static (address, buffer) => 0, - getThreadContext: static (threadId, contextFlags, buffer) => -1, - isLittleEndian: BitConverter.IsLittleEndian, - pointerSize: IntPtr.Size, - additionalFactories: []); - - // Verify type info is present - Target.TypeInfo threadType = target.GetTypeInfo(DataType.Thread); - Assert.True(threadType.Fields.Count > 0); - Assert.Equal("uint32", threadType.Fields["Id"].TypeName); - - // Install a trace listener that throws on Debug.Assert failures - using ThrowingTraceListener listener = new(); - - // Verify the listener catches Debug.Assert - Assert.Throws(() => System.Diagnostics.Debug.Assert(false, "test")); - - // Instantiate Data types — the ThrowingTraceListener will convert any - // Debug.Assert type mismatch failures into exceptions that fail the test. - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - TryCreate(target); - } - - private static void CreateData(Target target) where T : IData - { - T.Create(target, default); - } - - private static void TryCreate(Target target) where T : IData - { - try - { - T.Create(target, default); - } - catch (InvalidOperationException) { } - catch (System.Collections.Generic.KeyNotFoundException) { } - } - - /// - /// A trace listener that converts Debug.Assert / Debug.Fail calls to exceptions. - /// Replaces the default trace listener to prevent process termination on assert failure. - /// - private sealed class ThrowingTraceListener : TraceListener, IDisposable - { - private readonly TraceListener[] _savedListeners; - - public ThrowingTraceListener() - { - // Save and remove all existing listeners (including DefaultTraceListener - // which would terminate the process on assert failure) - _savedListeners = new TraceListener[Trace.Listeners.Count]; - Trace.Listeners.CopyTo(_savedListeners, 0); - Trace.Listeners.Clear(); - Trace.Listeners.Add(this); - } - - public override void Write(string? message) { } - public override void WriteLine(string? message) { } - - public override void Fail(string? message, string? detailMessage) - { - throw new System.Exception($"Debug.Assert failed: {message} {detailMessage}"); - } - - void IDisposable.Dispose() - { - Trace.Listeners.Remove(this); - Trace.Listeners.AddRange(_savedListeners); - } - } -} diff --git a/src/native/managed/cdac/tests/ContractDescriptor/checked-descriptor.json b/src/native/managed/cdac/tests/ContractDescriptor/checked-descriptor.json deleted file mode 100644 index ec556bb3500299..00000000000000 --- a/src/native/managed/cdac/tests/ContractDescriptor/checked-descriptor.json +++ /dev/null @@ -1,2495 +0,0 @@ -{ - "version": 1, - "baseline": "empty", - "types": { - "Thread": { - "Id": [ - 16, - "uint32" - ], - "OSId": [ - 256, - "nuint" - ], - "State": [ - 0, - "uint32" - ], - "PreemptiveGCDisabled": [ - 4, - "uint32" - ], - "RuntimeThreadLocals": [ - 32, - "pointer" - ], - "Frame": [ - 8, - "pointer" - ], - "CachedStackBase": [ - 152, - "pointer" - ], - "CachedStackLimit": [ - 160, - "pointer" - ], - "ExceptionTracker": [ - 312, - "pointer" - ], - "GCHandle": [ - 264, - "GCHandle" - ], - "LastThrownObject": [ - 296, - "GCHandle" - ], - "LinkNext": [ - 144, - "pointer" - ], - "ThreadLocalDataPtr": [ - 2624, - "pointer" - ], - "TEB": [ - 48, - "pointer" - ], - "UEWatsonBucketTrackerBuckets": [ - 328, - "pointer" - ] - }, - "ThreadStore": { - "FirstThreadLink": [ - 112, - "SLink" - ], - "ThreadCount": [ - 136, - "int32" - ], - "UnstartedCount": [ - 140, - "int32" - ], - "BackgroundCount": [ - 144, - "int32" - ], - "PendingCount": [ - 148, - "int32" - ], - "DeadCount": [ - 152, - "int32" - ] - }, - "RuntimeThreadLocals": { - "AllocContext": [ - 0, - "EEAllocContext" - ] - }, - "IdDispenser": { - "IdToThread": [ - 120, - "pointer" - ], - "HighestId": [ - 0, - "uint32" - ] - }, - "ThreadStaticsInfo": { - "!": 40, - "GCTlsIndex": [ - 4, - "TLSIndex" - ], - "NonGCTlsIndex": [ - 0, - "TLSIndex" - ] - }, - "ThreadLocalData": { - "CollectibleTlsArrayData": [ - 16, - "pointer" - ], - "NonCollectibleTlsArrayData": [ - 8, - "pointer" - ], - "CollectibleTlsDataCount": [ - 4, - "int32" - ], - "NonCollectibleTlsDataCount": [ - 0, - "int32" - ], - "InFlightData": [ - 40, - "pointer" - ] - }, - "InFlightTLSData": { - "Next": [ - 0, - "pointer" - ], - "TlsIndex": [ - 8, - "TLSIndex" - ], - "TLSData": [ - 16, - "pointer" - ] - }, - "TLSIndex": { - "TLSIndexRawIndex": [ - 0, - "uint32" - ] - }, - "EEAllocContext": { - "GCAllocationContext": [ - 8, - "GCAllocContext" - ] - }, - "GCAllocContext": { - "Pointer": [ - 0, - "pointer" - ], - "Limit": [ - 8, - "pointer" - ], - "AllocBytes": [ - 16, - "int64" - ], - "AllocBytesLoh": [ - 24, - "int64" - ] - }, - "Exception": { - "_message": [ - 16, - "pointer" - ], - "_innerException": [ - 32, - "pointer" - ], - "_stackTrace": [ - 48, - "pointer" - ], - "_watsonBuckets": [ - 56, - "pointer" - ], - "_stackTraceString": [ - 64, - "pointer" - ], - "_remoteStackTraceString": [ - 72, - "pointer" - ], - "_HResult": [ - 108, - "int32" - ], - "_xcode": [ - 104, - "int32" - ] - }, - "ExceptionInfo": { - "ThrownObjectHandle": [ - 8, - "pointer" - ], - "PreviousNestedInfo": [ - 0, - "pointer" - ], - "ExceptionWatsonBucketTrackerBuckets": [ - 144, - "pointer" - ] - }, - "GCHandle": { - "!": 8 - }, - "Object": { - "!": 8, - "m_pMethTab": [ - 0, - "pointer" - ] - }, - "ObjectHeader": { - "!": 8, - "SyncBlockValue": [ - 4, - "uint32" - ] - }, - "String": { - "m_FirstChar": [ - 12, - "pointer" - ], - "m_StringLength": [ - 8, - "uint32" - ] - }, - "Array": { - "!": 16, - "m_NumComponents": [ - 8, - "pointer" - ] - }, - "InteropSyncBlockInfo": { - "CCW": [ - 8, - "pointer" - ], - "RCW": [ - 24, - "pointer" - ], - "CCF": [ - 16, - "pointer" - ] - }, - "SyncBlock": { - "InteropInfo": [ - 16, - "pointer" - ], - "Lock": [ - 0, - "pointer" - ], - "ThinLock": [ - 8, - "uint32" - ], - "LinkNext": [ - 32, - "pointer" - ], - "HashCode": [ - 40, - "uint32" - ] - }, - "SLink": { - "Next": [ - 0, - "pointer" - ] - }, - "NativeObjectWrapperObject": { - "ExternalComObject": [ - 16, - "pointer" - ] - }, - "ManagedObjectWrapperHolderObject": { - "WrappedObject": [ - 16, - "pointer" - ], - "Wrapper": [ - 24, - "pointer" - ] - }, - "ManagedObjectWrapperLayout": { - "RefCount": [ - 8, - "int64" - ], - "Flags": [ - 16, - "int32" - ], - "UserDefinedCount": [ - 20, - "int32" - ], - "UserDefined": [ - 24, - "pointer" - ], - "Dispatches": [ - 32, - "pointer" - ] - }, - "ComInterfaceEntry": { - "!": 24, - "IID": [ - 0, - "nuint" - ] - }, - "InternalComInterfaceDispatch": { - "!": 64, - "Entries": [ - 8, - "pointer" - ] - }, - "SyncTableEntry": { - "!": 16, - "SyncBlock": [ - 0, - "pointer" - ], - "Object": [ - 8, - "pointer" - ] - }, - "Module": { - "Assembly": [ - 280, - "pointer" - ], - "PEAssembly": [ - 248, - "pointer" - ], - "Base": [ - 256, - "pointer" - ], - "Flags": [ - 264, - "uint32" - ], - "LoaderAllocator": [ - 208, - "pointer" - ], - "DynamicMetadata": [ - 968, - "pointer" - ], - "SimpleName": [ - 224, - "pointer" - ], - "Path": [ - 232, - "pointer" - ], - "FileName": [ - 240, - "pointer" - ], - "ReadyToRunInfo": [ - 832, - "pointer" - ], - "GrowableSymbolStream": [ - 504, - "pointer" - ], - "AvailableTypeParams": [ - 696, - "pointer" - ], - "InstMethodHashTable": [ - 808, - "pointer" - ], - "FieldDefToDescMap": [ - 576, - "pointer" - ], - "ManifestModuleReferencesMap": [ - 40, - "pointer" - ], - "MemberRefToDescMap": [ - 72, - "pointer" - ], - "MethodDefToDescMap": [ - 544, - "pointer" - ], - "TypeDefToMethodTableMap": [ - 512, - "pointer" - ], - "TypeRefToMethodTableMap": [ - 8, - "pointer" - ], - "MethodDefToILCodeVersioningStateMap": [ - 640, - "pointer" - ], - "DynamicILBlobTable": [ - 920, - "pointer" - ] - }, - "ModuleLookupMap": { - "TableData": [ - 8, - "pointer" - ], - "Next": [ - 0, - "pointer" - ], - "Count": [ - 16, - "uint32" - ], - "SupportedFlagsMask": [ - 24, - "nuint" - ] - }, - "Assembly": { - "IsCollectible": [ - 64, - "uint8" - ], - "IsDynamic": [ - 65, - "bool" - ], - "Module": [ - 16, - "pointer" - ], - "Error": [ - 80, - "pointer" - ], - "NotifyFlags": [ - 76, - "uint32" - ], - "IsLoaded": [ - 67, - "bool" - ] - }, - "LoaderAllocator": { - "ReferenceCount": [ - 2136, - "uint32" - ], - "HighFrequencyHeap": [ - 840, - "pointer" - ], - "LowFrequencyHeap": [ - 832, - "pointer" - ], - "StaticsHeap": [ - 848, - "pointer" - ], - "StubHeap": [ - 856, - "pointer" - ], - "ExecutableHeap": [ - 864, - "pointer" - ], - "FixupPrecodeHeap": [ - 880, - "pointer" - ], - "NewStubPrecodeHeap": [ - 888, - "pointer" - ], - "VirtualCallStubManager": [ - 2104, - "pointer" - ], - "ObjectHandle": [ - 896, - "pointer" - ] - }, - "VirtualCallStubManager": { - "IndcellHeap": [ - 744, - "pointer" - ], - "CacheEntryHeap": [ - 752, - "pointer" - ] - }, - "PEAssembly": { - "PEImage": [ - 48, - "pointer" - ], - "AssemblyBinder": [ - 104, - "pointer" - ] - }, - "AssemblyBinder": { - "AssemblyLoadContext": [ - 232, - "pointer" - ] - }, - "PEImage": { - "LoadedImageLayout": [ - 144, - "pointer" - ], - "ProbeExtensionResult": [ - 48, - "ProbeExtensionResult" - ] - }, - "PEImageLayout": { - "Base": [ - 16, - "pointer" - ], - "Size": [ - 24, - "uint32" - ], - "Flags": [ - 28, - "uint32" - ], - "Format": [ - 12, - "uint32" - ] - }, - "CGrowableSymbolStream": { - "Buffer": [ - 8, - "pointer" - ], - "Size": [ - 16, - "uint32" - ] - }, - "ProbeExtensionResult": { - "Type": [ - 0, - "int32" - ] - }, - "AppDomain": { - "RootAssembly": [ - 1528, - "pointer" - ], - "DomainAssemblyList": [ - 800, - "ArrayListBase" - ], - "FriendlyName": [ - 1520, - "pointer" - ] - }, - "SystemDomain": { - "GlobalLoaderAllocator": [ - 16, - "LoaderAllocator" - ], - "SystemAssembly": [ - 8, - "pointer" - ] - }, - "ArrayListBase": { - "Count": [ - 0, - "uint32" - ], - "FirstBlock": [ - 8, - "pointer" - ] - }, - "ArrayListBlock": { - "Next": [ - 0, - "pointer" - ], - "Size": [ - 8, - "uint32" - ], - "ArrayStart": [ - 16, - "pointer" - ] - }, - "MethodTable": { - "!": 72, - "MTFlags": [ - 0, - "uint32" - ], - "BaseSize": [ - 4, - "uint32" - ], - "MTFlags2": [ - 8, - "uint32" - ], - "EEClassOrCanonMT": [ - 48, - "pointer" - ], - "Module": [ - 32, - "pointer" - ], - "ParentMethodTable": [ - 24, - "pointer" - ], - "NumInterfaces": [ - 14, - "uint16" - ], - "NumVirtuals": [ - 12, - "uint16" - ], - "PerInstInfo": [ - 56, - "pointer" - ], - "AuxiliaryData": [ - 40, - "pointer" - ] - }, - "DynamicStaticsInfo": { - "!": 24, - "GCStatics": [ - 0, - "pointer" - ], - "NonGCStatics": [ - 8, - "pointer" - ] - }, - "MethodTableAuxiliaryData": { - "LoaderModule": [ - 8, - "pointer" - ], - "OffsetToNonVirtualSlots": [ - 2, - "int16" - ], - "Flags": [ - 0, - "uint32" - ] - }, - "EEClass": { - "MethodTable": [ - 32, - "pointer" - ], - "MethodDescChunk": [ - 48, - "pointer" - ], - "NumMethods": [ - 86, - "uint16" - ], - "FieldDescList": [ - 40, - "pointer" - ], - "CorTypeAttr": [ - 72, - "uint32" - ], - "InternalCorElementType": [ - 82, - "uint8" - ], - "NumInstanceFields": [ - 84, - "uint16" - ], - "NumStaticFields": [ - 88, - "uint16" - ], - "NumThreadStaticFields": [ - 92, - "uint16" - ], - "NumNonVirtualSlots": [ - 96, - "uint16" - ] - }, - "GenericsDictInfo": { - "NumDicts": [ - 4, - "uint16" - ], - "NumTypeArgs": [ - 6, - "uint16" - ] - }, - "TypeDesc": { - "TypeAndFlags": [ - 0, - "uint32" - ] - }, - "FieldDesc": { - "!": 24, - "DWord1": [ - 8, - "uint32" - ], - "DWord2": [ - 12, - "uint32" - ], - "MTOfEnclosingClass": [ - 0, - "pointer" - ] - }, - "ParamTypeDesc": { - "TypeArg": [ - 16, - "pointer" - ] - }, - "TypeVarTypeDesc": { - "Module": [ - 16, - "pointer" - ], - "Token": [ - 40, - "uint32" - ] - }, - "FnPtrTypeDesc": { - "NumArgs": [ - 24, - "uint32" - ], - "CallConv": [ - 28, - "uint32" - ], - "RetAndArgTypes": [ - 32, - "uint32" - ], - "LoaderModule": [ - 16, - "pointer" - ] - }, - "DynamicMetadata": { - "Size": [ - 0, - "uint32" - ], - "Data": [ - 4, - "pointer" - ] - }, - "StressLog": { - "!": 184, - "LoggedFacilities": [ - 0, - "uint32" - ], - "Level": [ - 4, - "uint32" - ], - "MaxSizePerThread": [ - 8, - "uint32" - ], - "MaxSizeTotal": [ - 12, - "uint32" - ], - "TotalChunks": [ - 16, - "uint32" - ], - "Logs": [ - 24, - "pointer" - ], - "TickFrequency": [ - 48, - "uint64" - ], - "StartTimestamp": [ - 56, - "uint64" - ], - "ModuleOffset": [ - 72, - "nuint" - ], - "Modules": [ - 80, - "pointer" - ] - }, - "StressLogModuleDesc": { - "!": 16, - "BaseAddress": [ - 0, - "pointer" - ], - "Size": [ - 8, - "nuint" - ] - }, - "ThreadStressLog": { - "Next": [ - 0, - "pointer" - ], - "ThreadId": [ - 8, - "uint64" - ], - "WriteHasWrapped": [ - 18, - "uint8" - ], - "CurrentPtr": [ - 24, - "pointer" - ], - "ChunkListHead": [ - 40, - "pointer" - ], - "ChunkListTail": [ - 48, - "pointer" - ], - "CurrentWriteChunk": [ - 64, - "pointer" - ] - }, - "StressLogChunk": { - "!": 32792, - "Prev": [ - 0, - "pointer" - ], - "Next": [ - 8, - "pointer" - ], - "Buf": [ - 16, - "pointer" - ], - "Sig1": [ - 32784, - "uint32" - ], - "Sig2": [ - 32788, - "uint32" - ] - }, - "StressMsgHeader": { - "!": 16 - }, - "StressMsg": { - "Header": [ - 0, - "StressMsgHeader" - ], - "Args": [ - 16, - "pointer" - ] - }, - "MethodDesc": { - "!": 64, - "ChunkIndex": [ - 2, - "uint8" - ], - "Slot": [ - 4, - "uint16" - ], - "Flags": [ - 6, - "uint16" - ], - "Flags3AndTokenRemainder": [ - 0, - "uint16" - ], - "EntryPointFlags": [ - 3, - "uint8" - ], - "CodeData": [ - 8, - "pointer" - ], - "GCCoverageInfo": [ - 56, - "pointer" - ] - }, - "MethodDescChunk": { - "!": 24, - "MethodTable": [ - 0, - "pointer" - ], - "Next": [ - 8, - "pointer" - ], - "Size": [ - 16, - "uint8" - ], - "Count": [ - 17, - "uint8" - ], - "FlagsAndTokenRange": [ - 18, - "uint16" - ] - }, - "NonVtableSlot": { - "!": 8 - }, - "MethodImpl": { - "!": 16 - }, - "NativeCodeSlot": { - "!": 8 - }, - "AsyncMethodData": { - "!": 24 - }, - "InstantiatedMethodDesc": { - "!": 88, - "PerInstInfo": [ - 72, - "pointer" - ], - "Flags2": [ - 80, - "uint16" - ], - "NumGenericArgs": [ - 82, - "uint16" - ] - }, - "StoredSigMethodDesc": { - "Sig": [ - 64, - "pointer" - ], - "cSig": [ - 72, - "uint32" - ], - "ExtendedFlags": [ - 76, - "uint32" - ] - }, - "DynamicMethodDesc": { - "!": 104, - "MethodName": [ - 80, - "pointer" - ] - }, - "ArrayMethodDesc": { - "!": 80 - }, - "FCallMethodDesc": { - "!": 72 - }, - "PInvokeMethodDesc": { - "!": 104 - }, - "EEImplMethodDesc": { - "!": 80 - }, - "CLRToCOMCallMethodDesc": { - "!": 72 - }, - "CodePointer": { - "!": 8 - }, - "MethodDescCodeData": { - "TemporaryEntryPoint": [ - 16, - "CodePointer" - ], - "VersioningState": [ - 0, - "pointer" - ] - }, - "MethodDescVersioningState": { - "NativeCodeVersionNode": [ - 16, - "pointer" - ], - "Flags": [ - 8, - "uint8" - ] - }, - "PrecodeMachineDescriptor": { - "InvalidPrecodeType": [ - 4, - "uint8" - ], - "PInvokeImportPrecodeType": [ - 5, - "uint8" - ], - "FixupPrecodeType": [ - 6, - "uint8" - ], - "FixupCodeOffset": [ - 7, - "uint8" - ], - "FixupStubPrecodeSize": [ - 8, - "uint8" - ], - "FixupBytes": [ - 9, - "pointer" - ], - "FixupIgnoredBytes": [ - 33, - "pointer" - ], - "StubPrecodeSize": [ - 57, - "uint8" - ], - "StubPrecodeType": [ - 58, - "uint8" - ], - "StubBytes": [ - 59, - "pointer" - ], - "StubIgnoredBytes": [ - 83, - "pointer" - ], - "ThisPointerRetBufPrecodeType": [ - 107, - "uint8" - ], - "InterpreterPrecodeType": [ - 108, - "uint8" - ], - "UMEntryPrecodeType": [ - 109, - "uint8" - ], - "StubCodePageSize": [ - 0, - "uint32" - ] - }, - "PlatformMetadata": { - "PrecodeMachineDescriptor": [ - 0, - "PrecodeMachineDescriptor" - ], - "CodePointerFlags": [ - 112, - "uint8" - ] - }, - "StubPrecodeData": { - "SecretParam": [ - 0, - "pointer" - ], - "Type": [ - 16, - "uint8" - ] - }, - "ThisPtrRetBufPrecodeData": { - "MethodDesc": [ - 8, - "pointer" - ] - }, - "FixupPrecodeData": { - "MethodDesc": [ - 8, - "pointer" - ] - }, - "ReadyToRunInfo": { - "ReadyToRunHeader": [ - 16, - "pointer" - ], - "CompositeInfo": [ - 40, - "pointer" - ], - "NumRuntimeFunctions": [ - 88, - "uint32" - ], - "RuntimeFunctions": [ - 80, - "pointer" - ], - "NumHotColdMap": [ - 104, - "uint32" - ], - "HotColdMap": [ - 96, - "pointer" - ], - "DelayLoadMethodCallThunks": [ - 112, - "pointer" - ], - "DebugInfoSection": [ - 120, - "pointer" - ], - "EntryPointToMethodDescMap": [ - 400, - "HashMap" - ], - "LoadedImageBase": [ - 584, - "pointer" - ], - "Composite": [ - 72, - "pointer" - ] - }, - "ReadyToRunHeader": { - "MajorVersion": [ - 4, - "uint16" - ], - "MinorVersion": [ - 6, - "uint16" - ] - }, - "ReadyToRunCoreHeader": { - "!": 8, - "Flags": [ - 0, - "uint32" - ], - "NumberOfSections": [ - 4, - "uint32" - ] - }, - "ReadyToRunCoreInfo": { - "Header": [ - 8, - "pointer" - ] - }, - "ReadyToRunSection": { - "!": 12, - "Type": [ - 0, - "uint32" - ], - "Section": [ - 4, - "ImageDataDirectory" - ] - }, - "ExceptionLookupTableEntry": { - "!": 8, - "MethodStartRVA": [ - 0, - "uint32" - ], - "ExceptionInfoRVA": [ - 4, - "uint32" - ] - }, - "ImageDataDirectory": { - "!": 8, - "VirtualAddress": [ - 0, - "uint32" - ], - "Size": [ - 4, - "uint32" - ] - }, - "RuntimeFunction": { - "!": 12, - "BeginAddress": [ - 0, - "uint32" - ], - "EndAddress": [ - 4, - "uint32" - ], - "UnwindData": [ - 8, - "uint32" - ] - }, - "UnwindInfo": {}, - "HashMap": { - "Buckets": [ - 24, - "pointer" - ] - }, - "Bucket": { - "!": 64, - "Keys": [ - 0, - "pointer" - ], - "Values": [ - 32, - "pointer" - ] - }, - "RangeSectionMap": { - "TopLevelData": [ - 0, - "pointer" - ] - }, - "RangeSectionFragment": { - "RangeBegin": [ - 8, - "pointer" - ], - "RangeEndOpen": [ - 16, - "pointer" - ], - "RangeSection": [ - 24, - "pointer" - ], - "Next": [ - 0, - "pointer" - ] - }, - "RangeSection": { - "RangeBegin": [ - 0, - "pointer" - ], - "RangeEndOpen": [ - 8, - "pointer" - ], - "NextForDelete": [ - 64, - "pointer" - ], - "JitManager": [ - 24, - "pointer" - ], - "Flags": [ - 16, - "int32" - ], - "HeapList": [ - 40, - "pointer" - ], - "R2RModule": [ - 32, - "pointer" - ] - }, - "EEJitManager": { - "StoreRichDebugInfo": [ - 188, - "bool" - ], - "AllCodeHeaps": [ - 16, - "pointer" - ] - }, - "RealCodeHeader": { - "MethodDesc": [ - 24, - "pointer" - ], - "DebugInfo": [ - 0, - "pointer" - ], - "GCInfo": [ - 16, - "pointer" - ], - "NumUnwindInfos": [ - 32, - "uint32" - ], - "UnwindInfos": [ - 36, - "RuntimeFunction" - ], - "JitEHInfo": [ - 8, - "pointer" - ] - }, - "EEExceptionClause": { - "!": 32, - "Flags": [ - 0, - "uint32" - ], - "TryStartPC": [ - 4, - "uint32" - ], - "TryEndPC": [ - 8, - "uint32" - ], - "HandlerStartPC": [ - 12, - "uint32" - ], - "HandlerEndPC": [ - 16, - "uint32" - ], - "TypeHandle": [ - 24, - "nuint" - ] - }, - "R2RExceptionClause": { - "!": 24, - "Flags": [ - 0, - "uint32" - ], - "TryStartPC": [ - 4, - "uint32" - ], - "TryEndPC": [ - 8, - "uint32" - ], - "HandlerStartPC": [ - 12, - "uint32" - ], - "HandlerEndPC": [ - 16, - "uint32" - ], - "ClassToken": [ - 20, - "uint32" - ] - }, - "EEILException": { - "Clauses": [ - 8, - "EEExceptionClause" - ] - }, - "CodeHeapListNode": { - "Next": [ - 0, - "pointer" - ], - "StartAddress": [ - 16, - "pointer" - ], - "EndAddress": [ - 24, - "pointer" - ], - "MapBase": [ - 32, - "pointer" - ], - "HeaderMap": [ - 40, - "pointer" - ] - }, - "ILCodeVersioningState": { - "FirstVersionNode": [ - 24, - "pointer" - ], - "ActiveVersionKind": [ - 0, - "uint32" - ], - "ActiveVersionNode": [ - 8, - "pointer" - ], - "ActiveVersionModule": [ - 8, - "pointer" - ], - "ActiveVersionMethodDef": [ - 16, - "uint32" - ] - }, - "NativeCodeVersionNode": { - "Next": [ - 24, - "pointer" - ], - "MethodDesc": [ - 8, - "pointer" - ], - "NativeCode": [ - 0, - "CodePointer" - ], - "Flags": [ - 60, - "uint32" - ], - "ILVersionId": [ - 16, - "nuint" - ], - "GCCoverageInfo": [ - 40, - "pointer" - ] - }, - "ILCodeVersionNode": { - "VersionId": [ - 16, - "nuint" - ], - "Next": [ - 24, - "pointer" - ], - "RejitState": [ - 32, - "uint32" - ], - "ILAddress": [ - 40, - "pointer" - ] - }, - "ProfControlBlock": { - "GlobalEventMask": [ - 1888, - "uint64" - ], - "RejitOnAttachEnabled": [ - 1926, - "bool" - ] - }, - "GCCoverageInfo": { - "SavedCode": [ - 1340, - "pointer" - ] - }, - "Frame": { - "Next": [ - 8, - "pointer" - ] - }, - "InlinedCallFrame": { - "!": 56, - "CallSiteSP": [ - 24, - "pointer" - ], - "CallerReturnAddress": [ - 32, - "pointer" - ], - "CalleeSavedFP": [ - 40, - "pointer" - ], - "Datum": [ - 16, - "pointer" - ] - }, - "SoftwareExceptionFrame": { - "!": 1520, - "TargetContext": [ - 288, - "pointer" - ], - "ReturnAddress": [ - 16, - "pointer" - ] - }, - "FramedMethodFrame": { - "!": 32, - "TransitionBlockPtr": [ - 16, - "pointer" - ], - "MethodDescPtr": [ - 24, - "pointer" - ] - }, - "TransitionBlock": { - "!": 72, - "ReturnAddress": [ - 64, - "pointer" - ], - "CalleeSavedRegisters": [ - 0, - "CalleeSavedRegisters" - ] - }, - "FuncEvalFrame": { - "!": 40, - "DebuggerEvalPtr": [ - 24, - "pointer" - ] - }, - "DebuggerEval": { - "!": 1376, - "TargetContext": [ - 0, - "pointer" - ], - "EvalDuringException": [ - 1350, - "bool" - ] - }, - "StubDispatchFrame": { - "!": 72, - "RepresentativeMTPtr": [ - 32, - "pointer" - ], - "MethodDescPtr": [ - 24, - "pointer" - ], - "RepresentativeSlot": [ - 40, - "uint32" - ] - }, - "ResumableFrame": { - "!": 24, - "TargetContextPtr": [ - 16, - "pointer" - ] - }, - "HijackFrame": { - "!": 40, - "ReturnAddress": [ - 16, - "pointer" - ], - "HijackArgsPtr": [ - 32, - "pointer" - ] - }, - "HijackArgs": { - "!": 96, - "CalleeSavedRegisters": [ - 16, - "CalleeSavedRegisters" - ], - "Rsp": [ - 80, - "pointer" - ] - }, - "FaultingExceptionFrame": { - "!": 1280, - "TargetContext": [ - 32, - "pointer" - ] - }, - "ArgumentRegisters": { - "!": 32 - }, - "CalleeSavedRegisters": { - "!": 64, - "Rdi": [ - 0, - "nuint" - ], - "Rsi": [ - 8, - "nuint" - ], - "Rbx": [ - 16, - "nuint" - ], - "Rbp": [ - 24, - "nuint" - ], - "R12": [ - 32, - "nuint" - ], - "R13": [ - 40, - "nuint" - ], - "R14": [ - 48, - "nuint" - ], - "R15": [ - 56, - "nuint" - ] - }, - "EETypeHashTable": { - "Buckets": [ - 16, - "pointer" - ], - "Count": [ - 24, - "uint32" - ], - "VolatileEntryValue": [ - 0, - "pointer" - ], - "VolatileEntryNextEntry": [ - 8, - "pointer" - ] - }, - "InstMethodHashTable": { - "Buckets": [ - 16, - "pointer" - ], - "Count": [ - 24, - "uint32" - ], - "VolatileEntryValue": [ - 0, - "pointer" - ], - "VolatileEntryNextEntry": [ - 8, - "pointer" - ] - }, - "CoreLibBinder": { - "Classes": [ - 8, - "pointer" - ] - }, - "DynamicILBlobTable": { - "!": 16, - "Table": [ - 0, - "pointer" - ], - "TableSize": [ - 8, - "uint32" - ], - "EntryMethodToken": [ - 0, - "uint32" - ], - "EntryIL": [ - 8, - "pointer" - ] - }, - "ComCallWrapper": { - "Handle": [ - 0, - "pointer" - ], - "SimpleWrapper": [ - 8, - "pointer" - ], - "IPtr": [ - 16, - "pointer" - ], - "Next": [ - 56, - "pointer" - ] - }, - "SimpleComCallWrapper": { - "OuterIUnknown": [ - 16, - "pointer" - ], - "RefCount": [ - 144, - "int64" - ], - "Flags": [ - 136, - "uint32" - ], - "MainWrapper": [ - 96, - "pointer" - ], - "VTablePtr": [ - 24, - "pointer" - ] - }, - "ComMethodTable": { - "!": 72, - "Flags": [ - 24, - "nuint" - ], - "MethodTable": [ - 8, - "pointer" - ] - }, - "RCWCleanupList": { - "FirstBucket": [ - 0, - "pointer" - ] - }, - "RCW": { - "NextCleanupBucket": [ - 0, - "pointer" - ], - "NextRCW": [ - 176, - "pointer" - ], - "Flags": [ - 168, - "uint32" - ], - "CtxCookie": [ - 192, - "pointer" - ], - "CtxEntry": [ - 200, - "pointer" - ], - "InterfaceEntries": [ - 8, - "pointer" - ], - "IdentityPointer": [ - 136, - "pointer" - ], - "SyncBlockIndex": [ - 144, - "uint32" - ], - "VTablePtr": [ - 184, - "pointer" - ], - "CreatorThread": [ - 160, - "pointer" - ], - "RefCount": [ - 148, - "uint32" - ], - "UnknownPointer": [ - 208, - "pointer" - ] - }, - "CtxEntry": { - "STAThread": [ - 24, - "pointer" - ], - "CtxCookie": [ - 0, - "pointer" - ] - }, - "InterfaceEntry": { - "!": 16, - "MethodTable": [ - 0, - "pointer" - ], - "Unknown": [ - 8, - "pointer" - ] - }, - "ComWrappersVtablePtrs": { - "!": 16 - }, - "SyncBlockCache": { - "FreeSyncTableIndex": [ - 140, - "uint32" - ], - "CleanupBlockList": [ - 0, - "pointer" - ] - } - }, - "globals": { - "GCInfoVersion": [ - "0x4", - "uint32" - ], - "InlinedCallFrameIdentifier": [ - "0x1", - "nuint" - ], - "ResumableFrameIdentifier": [ - "0x2", - "nuint" - ], - "RedirectedThreadFrameIdentifier": [ - "0x3", - "nuint" - ], - "FaultingExceptionFrameIdentifier": [ - "0x4", - "nuint" - ], - "SoftwareExceptionFrameIdentifier": [ - "0x5", - "nuint" - ], - "FuncEvalFrameIdentifier": [ - "0x6", - "nuint" - ], - "ComMethodFrameIdentifier": [ - "0x7", - "nuint" - ], - "CLRToCOMMethodFrameIdentifier": [ - "0x8", - "nuint" - ], - "ComPrestubMethodFrameIdentifier": [ - "0x9", - "nuint" - ], - "PInvokeCalliFrameIdentifier": [ - "0xa", - "nuint" - ], - "HijackFrameIdentifier": [ - "0xb", - "nuint" - ], - "PrestubMethodFrameIdentifier": [ - "0xc", - "nuint" - ], - "CallCountingHelperFrameIdentifier": [ - "0xd", - "nuint" - ], - "StubDispatchFrameIdentifier": [ - "0xe", - "nuint" - ], - "ResolveHelperFrameIdentifier": [ - "0xf", - "nuint" - ], - "ExternalMethodFrameIdentifier": [ - "0x10", - "nuint" - ], - "DynamicHelperFrameIdentifier": [ - "0x11", - "nuint" - ], - "ProtectValueClassFrameIdentifier": [ - "0x12", - "nuint" - ], - "DebuggerClassInitMarkFrameIdentifier": [ - "0x13", - "nuint" - ], - "DebuggerExitFrameIdentifier": [ - "0x14", - "nuint" - ], - "DebuggerU2MCatchHandlerFrameIdentifier": [ - "0x15", - "nuint" - ], - "ExceptionFilterFrameIdentifier": [ - "0x16", - "nuint" - ], - "InterpreterFrameIdentifier": [ - "0x17", - "nuint" - ], - "MethodDescTokenRemainderBitCount": [ - "0xc", - "uint8" - ], - "FeatureCOMInterop": [ - "0x1", - "uint8" - ], - "FeatureComWrappers": [ - "0x1", - "uint8" - ], - "FeatureObjCMarshal": [ - "0x0", - "uint8" - ], - "FeatureJavaMarshal": [ - "0x1", - "uint8" - ], - "FeatureOnStackReplacement": [ - "0x1", - "uint8" - ], - "FeatureWebcil": [ - "0x0", - "uint8" - ], - "ObjectToMethodTableUnmask": [ - "0x7", - "uint8" - ], - "FeaturePortableEntrypoints": [ - "0x0", - "uint8" - ], - "SOSBreakingChangeVersion": [ - "0x5", - "uint8" - ], - "RecommendedReaderVersion": [ - "0x1", - "uint32" - ], - "DirectorySeparator": [ - "0x5c", - "uint8" - ], - "HashMapSlotsPerBucket": [ - "0x4", - "uint32" - ], - "HashMapValueMask": [ - "0x7fffffffffffffff", - "uint64" - ], - "MethodDescAlignment": [ - "0x8", - "uint64" - ], - "ArrayBaseSize": [ - "0x18", - "uint32" - ], - "SyncBlockValueToObjectOffset": [ - "0x4", - "uint16" - ], - "StubCodeBlockLast": [ - "0xf", - "uint8" - ], - "DefaultADID": [ - "0x1", - "uint32" - ], - "SizeOfGenericModeBlock": [ - "0x15f0", - "uint32" - ], - "StaticsPointerMask": [ - "0xfffffffffffffffe", - "nuint" - ], - "PtrArrayOffsetToDataArray": [ - "0x10", - "nuint" - ], - "NumberOfTlsOffsetsNotUsedInNoncollectibleArray": [ - "0x2", - "uint8" - ], - "MaxClrNotificationArgs": [ - "0x3", - "uint32" - ], - "FieldOffsetBigRVA": [ - "0x7fffffa", - "uint32" - ], - "FieldOffsetDynamicRVA": [ - "0x7fffff9", - "uint32" - ], - "DispatchThisPtrMask": [ - "0xffffffffffffffc0", - "nuint" - ], - "StressLogEnabled": [ - "0x1", - "uint8" - ], - "StressLogHasModuleTable": [ - "0x1", - "uint8" - ], - "StressLogMaxModules": [ - "0x5", - "uint64" - ], - "StressLogChunkSize": [ - "0x8000", - "uint32" - ], - "StressLogValidChunkSig": [ - "0xcfcfcfcf", - "uint32" - ], - "StressLogMaxMessageSize": [ - "0x208", - "uint64" - ], - "SyncBlockMaskLockThreadId": [ - "0xffff", - "uint32" - ], - "SyncBlockMaskLockRecursionLevel": [ - "0x3f0000", - "uint32" - ], - "SyncBlockRecursionLevelShift": [ - "0x10", - "uint32" - ], - "SyncBlockIsHashOrSyncBlockIndex": [ - "0x8000000", - "uint32" - ], - "SyncBlockIsHashCode": [ - "0x4000000", - "uint32" - ], - "SyncBlockIndexMask": [ - "0x3ffffff", - "uint32" - ], - "SyncBlockHashCodeMask": [ - "0x3ffffff", - "uint32" - ], - "CCWNumInterfaces": [ - "0x5", - "uint32" - ], - "CCWThisMask": [ - "0xffffffffffffffc0", - "nuint" - ], - "RCWInterfaceCacheSize": [ - "0x8", - "uint32" - ], - "AppDomain": [ - [ - 1 - ], - "pointer" - ], - "SystemDomain": [ - [ - 2 - ], - "pointer" - ], - "ThreadStore": [ - [ - 3 - ], - "pointer" - ], - "FinalizerThread": [ - [ - 4 - ], - "pointer" - ], - "GCThread": [ - [ - 5 - ], - "pointer" - ], - "ClrNotificationArguments": [ - [ - 6 - ], - "pointer" - ], - "ArrayBoundsZero": [ - [ - 7 - ], - "pointer" - ], - "ContinuationMethodTable": [ - [ - 8 - ], - "pointer" - ], - "ExceptionMethodTable": [ - [ - 9 - ], - "pointer" - ], - "FreeObjectMethodTable": [ - [ - 10 - ], - "pointer" - ], - "ObjectMethodTable": [ - [ - 11 - ], - "pointer" - ], - "ObjectArrayMethodTable": [ - [ - 12 - ], - "pointer" - ], - "StringMethodTable": [ - [ - 13 - ], - "pointer" - ], - "SyncTableEntries": [ - [ - 14 - ], - "pointer" - ], - "MiniMetaDataBuffAddress": [ - [ - 15 - ], - "pointer" - ], - "MiniMetaDataBuffMaxSize": [ - [ - 16 - ], - "pointer" - ], - "DacNotificationFlags": [ - [ - 17 - ], - "pointer" - ], - "OffsetOfCurrentThreadInfo": [ - [ - 18 - ], - "pointer" - ], - "ThinlockThreadIdDispenser": [ - [ - 19 - ], - "pointer" - ], - "ComWrappersVtablePtrs": [ - [ - 20 - ], - "pointer" - ], - "GcNotificationFlags": [ - [ - 21 - ], - "pointer" - ], - "GlobalAllocContext": [ - [ - 22 - ], - "pointer" - ], - "CoreLib": [ - [ - 23 - ], - "pointer" - ], - "TlsIndexBase": [ - [ - 24 - ], - "pointer" - ], - "StressLog": [ - [ - 25 - ], - "pointer" - ], - "ExecutionManagerCodeRangeMapAddress": [ - [ - 26 - ], - "pointer" - ], - "EEJitManagerAddress": [ - [ - 27 - ], - "pointer" - ], - "PlatformMetadata": [ - [ - 28 - ], - "pointer" - ], - "ProfilerControlBlock": [ - [ - 29 - ], - "pointer" - ], - "SyncBlockCache": [ - [ - 30 - ], - "pointer" - ], - "GCLowestAddress": [ - [ - 31 - ], - "pointer" - ], - "GCHighestAddress": [ - [ - 32 - ], - "pointer" - ], - "TearOffAddRef": [ - [ - 33 - ], - "pointer" - ], - "TearOffAddRefSimple": [ - [ - 34 - ], - "pointer" - ], - "TearOffAddRefSimpleInner": [ - [ - 35 - ], - "pointer" - ], - "RCWCleanupList": [ - [ - 36 - ], - "pointer" - ], - "OperatingSystem": [ - "Windows", - "string" - ], - "Architecture": [ - "x64", - "string" - ], - "RID": [ - "win-x64", - "string" - ] - }, - "subDescriptors": { - "GC": [ - [ - 37 - ], - "pointer" - ] - }, - "contracts": { - "BuiltInCOM": 1, - "CodeVersions": 1, - "ComWrappers": 1, - "DacStreams": 1, - "DebugInfo": 2, - "EcmaMetadata": 1, - "Exception": 1, - "ExecutionManager": 2, - "GCInfo": 1, - "Loader": 1, - "Notifications": 1, - "Object": 1, - "PlatformMetadata": 1, - "PrecodeStubs": 3, - "ReJIT": 1, - "RuntimeInfo": 1, - "RuntimeTypeSystem": 1, - "SHash": 1, - "SignatureDecoder": 1, - "ConditionalWeakTable": 1, - "SyncBlock": 1, - "StackWalk": 1, - "StressLog": 2, - "Thread": 1 - } -} \ No newline at end of file