diff --git a/src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs b/src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs index d32fae6d4b07c..a8c8a9d0ff876 100644 --- a/src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs +++ b/src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs @@ -267,7 +267,7 @@ public TypeHandle GetTypeHandle(TargetPointer typeHandlePointer) if ((addressLowBits != TypeHandleBits.MethodTable) && (addressLowBits != TypeHandleBits.TypeDesc)) { - throw new InvalidOperationException("Invalid type handle pointer"); + throw new ArgumentException("Invalid type handle pointer", nameof(typeHandlePointer)); } // if we already validated this address, return a handle @@ -306,7 +306,7 @@ public TypeHandle GetTypeHandle(TargetPointer typeHandlePointer) // Otherwse, get ready to validate if (!_typeValidation.TryValidateMethodTablePointer(methodTablePointer)) { - throw new InvalidOperationException("Invalid method table pointer"); + throw new ArgumentException("Invalid method table pointer", nameof(typeHandlePointer)); } // ok, we validated it, cache the data and add the MethodTable_1 struct to the dictionary Data.MethodTable trustedMethodTableData = _target.ProcessedData.GetOrAdd(methodTablePointer); @@ -636,7 +636,7 @@ public MethodDescHandle GetMethodDescHandle(TargetPointer methodDescPointer) if (!_methodValidation.ValidateMethodDescPointer(methodDescPointer, out TargetPointer methodDescChunkPointer)) { - throw new InvalidOperationException("Invalid method desc pointer"); + throw new ArgumentException("Invalid method desc pointer", nameof(methodDescPointer)); } // ok, we validated it, cache the data and add the MethodDesc struct to the dictionary diff --git a/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs b/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs index b99fbdee26cac..e4367f004b0d9 100644 --- a/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs +++ b/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs @@ -195,7 +195,7 @@ int ISOSDacInterface.GetMethodDescData(ulong methodDesc, ulong ip, DacpMethodDes return HResults.E_INVALIDARG; } - int hr = HResults.E_NOTIMPL; + int hr = HResults.S_OK; try { Contracts.IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem; @@ -364,8 +364,6 @@ int ISOSDacInterface.GetMethodDescData(ulong methodDesc, ulong ip, DacpMethodDes // and would require accessing CorLib bound managed fields which the cDAC does not // currently support. However, it must remain in the return type for compatibility. data->managedDynamicMethodObject = 0; - - hr = HResults.S_OK; } catch (global::System.Exception ex) { @@ -375,25 +373,26 @@ int ISOSDacInterface.GetMethodDescData(ulong methodDesc, ulong ip, DacpMethodDes #if DEBUG if (_legacyImpl is not null) { - if (hr == HResults.S_OK) { - DacpMethodDescData dataLocal = default; - DacpReJitData[]? rgRevertedRejitDataLocal = null; - if (rgRevertedRejitData != null) - { - rgRevertedRejitDataLocal = new DacpReJitData[cRevertedRejitVersions]; - } - uint cNeededRevertedRejitDataLocal = 0; - uint* pcNeededRevertedRejitDataLocal = null; - if (pcNeededRevertedRejitData != null) - { - pcNeededRevertedRejitDataLocal = &cNeededRevertedRejitDataLocal; - } - int hrLocal; - fixed (DacpReJitData* rgRevertedRejitDataLocalPtr = rgRevertedRejitDataLocal) - { - hrLocal = _legacyImpl.GetMethodDescData(methodDesc, ip, &dataLocal, cRevertedRejitVersions, rgRevertedRejitDataLocalPtr, pcNeededRevertedRejitDataLocal); - } - Debug.Assert(hrLocal == hr); + DacpMethodDescData dataLocal = default; + DacpReJitData[]? rgRevertedRejitDataLocal = null; + if (rgRevertedRejitData != null) + { + rgRevertedRejitDataLocal = new DacpReJitData[cRevertedRejitVersions]; + } + uint cNeededRevertedRejitDataLocal = 0; + uint* pcNeededRevertedRejitDataLocal = null; + if (pcNeededRevertedRejitData != null) + { + pcNeededRevertedRejitDataLocal = &cNeededRevertedRejitDataLocal; + } + int hrLocal; + fixed (DacpReJitData* rgRevertedRejitDataLocalPtr = rgRevertedRejitDataLocal) + { + hrLocal = _legacyImpl.GetMethodDescData(methodDesc, ip, &dataLocal, cRevertedRejitVersions, rgRevertedRejitDataLocalPtr, pcNeededRevertedRejitDataLocal); + } + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { Debug.Assert(data->bHasNativeCode == dataLocal.bHasNativeCode); Debug.Assert(data->bIsDynamic == dataLocal.bIsDynamic); Debug.Assert(data->wSlotNumber == dataLocal.wSlotNumber); @@ -431,9 +430,6 @@ int ISOSDacInterface.GetMethodDescData(ulong methodDesc, ulong ip, DacpMethodDes Debug.Assert(rgRevertedRejitData[i].flags == rgRevertedRejitDataLocal[i].flags); } } - } else { - // TODO[cdac]: stop delegating to the legacy DAC - hr = _legacyImpl.GetMethodDescData(methodDesc, ip, data, cRevertedRejitVersions, rgRevertedRejitData, pcNeededRevertedRejitData); } } #endif @@ -546,7 +542,7 @@ int ISOSDacInterface.GetMethodDescName(ulong methodDesc, uint count, char* name, } catch (System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -559,9 +555,12 @@ int ISOSDacInterface.GetMethodDescName(ulong methodDesc, uint count, char* name, { hrLocal = _legacyImpl.GetMethodDescName(methodDesc, count, ptr, &neededLocal); } - Debug.Assert(hrLocal == HResults.S_OK); - Debug.Assert(pNeeded == null || *pNeeded == neededLocal); - Debug.Assert(name == null || new ReadOnlySpan(nameLocal, 0, (int)neededLocal - 1).SequenceEqual(new string(name))); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(pNeeded == null || *pNeeded == neededLocal); + Debug.Assert(name == null || new ReadOnlySpan(nameLocal, 0, (int)neededLocal - 1).SequenceEqual(new string(name))); + } } #endif return hr; @@ -578,6 +577,7 @@ int ISOSDacInterface.GetMethodTableData(ulong mt, DacpMethodTableData* data) if (mt == 0 || data == null) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.IRuntimeTypeSystem contract = _target.Contracts.RuntimeTypeSystem; @@ -616,7 +616,7 @@ int ISOSDacInterface.GetMethodTableData(ulong mt, DacpMethodTableData* data) } catch (System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -624,22 +624,25 @@ int ISOSDacInterface.GetMethodTableData(ulong mt, DacpMethodTableData* data) { DacpMethodTableData dataLocal; int hrLocal = _legacyImpl.GetMethodTableData(mt, &dataLocal); - Debug.Assert(hrLocal == HResults.S_OK); - Debug.Assert(data->module == dataLocal.module); - Debug.Assert(data->klass == dataLocal.klass); - Debug.Assert(data->parentMethodTable == dataLocal.parentMethodTable); - Debug.Assert(data->wNumInterfaces == dataLocal.wNumInterfaces); - Debug.Assert(data->wNumMethods == dataLocal.wNumMethods); - Debug.Assert(data->wNumVtableSlots == dataLocal.wNumVtableSlots); - Debug.Assert(data->wNumVirtuals == dataLocal.wNumVirtuals); - Debug.Assert(data->cl == dataLocal.cl); - Debug.Assert(data->dwAttrClass == dataLocal.dwAttrClass); - Debug.Assert(data->bContainsGCPointers == dataLocal.bContainsGCPointers); - Debug.Assert(data->bIsShared == dataLocal.bIsShared); - Debug.Assert(data->bIsDynamic == dataLocal.bIsDynamic); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(data->module == dataLocal.module); + Debug.Assert(data->klass == dataLocal.klass); + Debug.Assert(data->parentMethodTable == dataLocal.parentMethodTable); + Debug.Assert(data->wNumInterfaces == dataLocal.wNumInterfaces); + Debug.Assert(data->wNumMethods == dataLocal.wNumMethods); + Debug.Assert(data->wNumVtableSlots == dataLocal.wNumVtableSlots); + Debug.Assert(data->wNumVirtuals == dataLocal.wNumVirtuals); + Debug.Assert(data->cl == dataLocal.cl); + Debug.Assert(data->dwAttrClass == dataLocal.dwAttrClass); + Debug.Assert(data->bContainsGCPointers == dataLocal.bContainsGCPointers); + Debug.Assert(data->bIsShared == dataLocal.bIsShared); + Debug.Assert(data->bIsDynamic == dataLocal.bIsDynamic); + } } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetMethodTableFieldData(ulong mt, void* data) => _legacyImpl is not null ? _legacyImpl.GetMethodTableFieldData(mt, data) : HResults.E_NOTIMPL; @@ -648,6 +651,7 @@ int ISOSDacInterface.GetMethodTableForEEClass(ulong eeClassReallyCanonMT, ulong* if (eeClassReallyCanonMT == 0 || value == null) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.IRuntimeTypeSystem contract = _target.Contracts.RuntimeTypeSystem; @@ -656,7 +660,7 @@ int ISOSDacInterface.GetMethodTableForEEClass(ulong eeClassReallyCanonMT, ulong* } catch (global::System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -664,11 +668,12 @@ int ISOSDacInterface.GetMethodTableForEEClass(ulong eeClassReallyCanonMT, ulong* { ulong valueLocal; int hrLocal = _legacyImpl.GetMethodTableForEEClass(eeClassReallyCanonMT, &valueLocal); - Debug.Assert(hrLocal == HResults.S_OK); - Debug.Assert(*value == valueLocal); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + Debug.Assert(*value == valueLocal); } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetMethodTableName(ulong mt, uint count, char* mtName, uint* pNeeded) @@ -676,6 +681,7 @@ int ISOSDacInterface.GetMethodTableName(ulong mt, uint count, char* mtName, uint if (mt == 0) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.IRuntimeTypeSystem typeSystemContract = _target.Contracts.RuntimeTypeSystem; @@ -712,7 +718,7 @@ int ISOSDacInterface.GetMethodTableName(ulong mt, uint count, char* mtName, uint } catch (global::System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -725,12 +731,15 @@ int ISOSDacInterface.GetMethodTableName(ulong mt, uint count, char* mtName, uint { hrLocal = _legacyImpl.GetMethodTableName(mt, count, ptr, &neededLocal); } - Debug.Assert(hrLocal == HResults.S_OK); - Debug.Assert(pNeeded == null || *pNeeded == neededLocal); - Debug.Assert(mtName == null || new ReadOnlySpan(mtNameLocal, 0, (int)neededLocal - 1).SequenceEqual(new string(mtName))); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(pNeeded == null || *pNeeded == neededLocal); + Debug.Assert(mtName == null || new ReadOnlySpan(mtNameLocal, 0, (int)neededLocal - 1).SequenceEqual(new string(mtName))); + } } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetMethodTableSlot(ulong mt, uint slot, ulong* value) @@ -758,6 +767,7 @@ int ISOSDacInterface.GetModuleData(ulong moduleAddr, DacpModuleData* data) if (moduleAddr == 0 || data == null) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.ILoader contract = _target.Contracts.Loader; @@ -799,7 +809,7 @@ int ISOSDacInterface.GetModuleData(ulong moduleAddr, DacpModuleData* data) } catch (global::System.Exception e) { - return e.HResult; + hr = e.HResult; } #if DEBUG @@ -807,30 +817,33 @@ int ISOSDacInterface.GetModuleData(ulong moduleAddr, DacpModuleData* data) { DacpModuleData dataLocal; int hrLocal = _legacyImpl.GetModuleData(moduleAddr, &dataLocal); - Debug.Assert(hrLocal == HResults.S_OK); - Debug.Assert(data->Address == dataLocal.Address); - Debug.Assert(data->PEAssembly == dataLocal.PEAssembly); - Debug.Assert(data->Assembly == dataLocal.Assembly); - Debug.Assert(data->isReflection == dataLocal.isReflection); - Debug.Assert(data->isPEFile == dataLocal.isPEFile); - Debug.Assert(data->dwTransientFlags == dataLocal.dwTransientFlags); - Debug.Assert(data->ilBase == dataLocal.ilBase); - Debug.Assert(data->metadataStart == dataLocal.metadataStart); - Debug.Assert(data->metadataSize == dataLocal.metadataSize); - Debug.Assert(data->LoaderAllocator == dataLocal.LoaderAllocator); - Debug.Assert(data->ThunkHeap == dataLocal.ThunkHeap); - Debug.Assert(data->FieldDefToDescMap == dataLocal.FieldDefToDescMap); - Debug.Assert(data->ManifestModuleReferencesMap == dataLocal.ManifestModuleReferencesMap); - Debug.Assert(data->MemberRefToDescMap == dataLocal.MemberRefToDescMap); - Debug.Assert(data->MethodDefToDescMap == dataLocal.MethodDefToDescMap); - Debug.Assert(data->TypeDefToMethodTableMap == dataLocal.TypeDefToMethodTableMap); - Debug.Assert(data->TypeRefToMethodTableMap == dataLocal.TypeRefToMethodTableMap); - Debug.Assert(data->dwModuleID == dataLocal.dwModuleID); - Debug.Assert(data->dwBaseClassIndex == dataLocal.dwBaseClassIndex); - Debug.Assert(data->dwModuleIndex == dataLocal.dwModuleIndex); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(data->Address == dataLocal.Address); + Debug.Assert(data->PEAssembly == dataLocal.PEAssembly); + Debug.Assert(data->Assembly == dataLocal.Assembly); + Debug.Assert(data->isReflection == dataLocal.isReflection); + Debug.Assert(data->isPEFile == dataLocal.isPEFile); + Debug.Assert(data->dwTransientFlags == dataLocal.dwTransientFlags); + Debug.Assert(data->ilBase == dataLocal.ilBase); + Debug.Assert(data->metadataStart == dataLocal.metadataStart); + Debug.Assert(data->metadataSize == dataLocal.metadataSize); + Debug.Assert(data->LoaderAllocator == dataLocal.LoaderAllocator); + Debug.Assert(data->ThunkHeap == dataLocal.ThunkHeap); + Debug.Assert(data->FieldDefToDescMap == dataLocal.FieldDefToDescMap); + Debug.Assert(data->ManifestModuleReferencesMap == dataLocal.ManifestModuleReferencesMap); + Debug.Assert(data->MemberRefToDescMap == dataLocal.MemberRefToDescMap); + Debug.Assert(data->MethodDefToDescMap == dataLocal.MethodDefToDescMap); + Debug.Assert(data->TypeDefToMethodTableMap == dataLocal.TypeDefToMethodTableMap); + Debug.Assert(data->TypeRefToMethodTableMap == dataLocal.TypeRefToMethodTableMap); + Debug.Assert(data->dwModuleID == dataLocal.dwModuleID); + Debug.Assert(data->dwBaseClassIndex == dataLocal.dwBaseClassIndex); + Debug.Assert(data->dwModuleIndex == dataLocal.dwModuleIndex); + } } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetNestedExceptionData(ulong exception, ulong* exceptionObject, ulong* nextNestedException) @@ -838,6 +851,7 @@ int ISOSDacInterface.GetNestedExceptionData(ulong exception, ulong* exceptionObj if (exception == 0 || exceptionObject == null || nextNestedException == null) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.IException contract = _target.Contracts.Exception; @@ -847,7 +861,7 @@ int ISOSDacInterface.GetNestedExceptionData(ulong exception, ulong* exceptionObj } catch (global::System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -856,12 +870,15 @@ int ISOSDacInterface.GetNestedExceptionData(ulong exception, ulong* exceptionObj ulong exceptionObjectLocal; ulong nextNestedExceptionLocal; int hrLocal = _legacyImpl.GetNestedExceptionData(exception, &exceptionObjectLocal, &nextNestedExceptionLocal); - Debug.Assert(hrLocal == HResults.S_OK); - Debug.Assert(*exceptionObject == exceptionObjectLocal); - Debug.Assert(*nextNestedException == nextNestedExceptionLocal); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(*exceptionObject == exceptionObjectLocal); + Debug.Assert(*nextNestedException == nextNestedExceptionLocal); + } } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetObjectClassName(ulong obj, uint count, char* className, uint* pNeeded) @@ -872,6 +889,7 @@ int ISOSDacInterface.GetObjectData(ulong objAddr, DacpObjectData* data) if (objAddr == 0 || data == null) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.IObject objectContract = _target.Contracts.Object; @@ -946,7 +964,7 @@ int ISOSDacInterface.GetObjectData(ulong objAddr, DacpObjectData* data) } catch (System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -954,23 +972,26 @@ int ISOSDacInterface.GetObjectData(ulong objAddr, DacpObjectData* data) { DacpObjectData dataLocal; int hrLocal = _legacyImpl.GetObjectData(objAddr, &dataLocal); - Debug.Assert(hrLocal == HResults.S_OK); - Debug.Assert(data->MethodTable == dataLocal.MethodTable); - Debug.Assert(data->ObjectType == dataLocal.ObjectType); - Debug.Assert(data->Size == dataLocal.Size); - Debug.Assert(data->ElementTypeHandle == dataLocal.ElementTypeHandle); - Debug.Assert(data->ElementType == dataLocal.ElementType); - Debug.Assert(data->dwRank == dataLocal.dwRank); - Debug.Assert(data->dwNumComponents == dataLocal.dwNumComponents); - Debug.Assert(data->dwComponentSize == dataLocal.dwComponentSize); - Debug.Assert(data->ArrayDataPtr == dataLocal.ArrayDataPtr); - Debug.Assert(data->ArrayBoundsPtr == dataLocal.ArrayBoundsPtr); - Debug.Assert(data->ArrayLowerBoundsPtr == dataLocal.ArrayLowerBoundsPtr); - Debug.Assert(data->RCW == dataLocal.RCW); - Debug.Assert(data->CCW == dataLocal.CCW); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(data->MethodTable == dataLocal.MethodTable); + Debug.Assert(data->ObjectType == dataLocal.ObjectType); + Debug.Assert(data->Size == dataLocal.Size); + Debug.Assert(data->ElementTypeHandle == dataLocal.ElementTypeHandle); + Debug.Assert(data->ElementType == dataLocal.ElementType); + Debug.Assert(data->dwRank == dataLocal.dwRank); + Debug.Assert(data->dwNumComponents == dataLocal.dwNumComponents); + Debug.Assert(data->dwComponentSize == dataLocal.dwComponentSize); + Debug.Assert(data->ArrayDataPtr == dataLocal.ArrayDataPtr); + Debug.Assert(data->ArrayBoundsPtr == dataLocal.ArrayBoundsPtr); + Debug.Assert(data->ArrayLowerBoundsPtr == dataLocal.ArrayLowerBoundsPtr); + Debug.Assert(data->RCW == dataLocal.RCW); + Debug.Assert(data->CCW == dataLocal.CCW); + } } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetObjectStringData(ulong obj, uint count, char* stringData, uint* pNeeded) @@ -978,6 +999,7 @@ int ISOSDacInterface.GetObjectStringData(ulong obj, uint count, char* stringData if (obj == 0 || (stringData == null && pNeeded == null) || (stringData is not null && count <= 0)) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.IObject contract = _target.Contracts.Object; @@ -986,7 +1008,7 @@ int ISOSDacInterface.GetObjectStringData(ulong obj, uint count, char* stringData } catch (System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -999,13 +1021,16 @@ int ISOSDacInterface.GetObjectStringData(ulong obj, uint count, char* stringData { hrLocal = _legacyImpl.GetObjectStringData(obj, count, ptr, &neededLocal); } - Debug.Assert(hrLocal == HResults.S_OK); - Debug.Assert(pNeeded == null || *pNeeded == neededLocal); - Debug.Assert(stringData == null || new ReadOnlySpan(stringDataLocal, 0, (int)neededLocal - 1).SequenceEqual(new string(stringData))); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(pNeeded == null || *pNeeded == neededLocal); + Debug.Assert(stringData == null || new ReadOnlySpan(stringDataLocal, 0, (int)neededLocal - 1).SequenceEqual(new string(stringData))); + } } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetOOMData(ulong oomAddr, void* data) @@ -1018,6 +1043,7 @@ int ISOSDacInterface.GetPEFileBase(ulong addr, ulong* peBase) if (addr == 0 || peBase == null) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.ILoader contract = _target.Contracts.Loader; @@ -1035,7 +1061,7 @@ int ISOSDacInterface.GetPEFileBase(ulong addr, ulong* peBase) } catch (System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -1043,11 +1069,12 @@ int ISOSDacInterface.GetPEFileBase(ulong addr, ulong* peBase) { ulong peBaseLocal; int hrLocal = _legacyImpl.GetPEFileBase(addr, &peBaseLocal); - Debug.Assert(hrLocal == HResults.S_OK); - Debug.Assert(*peBase == peBaseLocal); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + Debug.Assert(*peBase == peBaseLocal); } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetPEFileName(ulong addr, uint count, char* fileName, uint* pNeeded) @@ -1055,6 +1082,7 @@ int ISOSDacInterface.GetPEFileName(ulong addr, uint count, char* fileName, uint* if (addr == 0 || (fileName == null && pNeeded == null) || (fileName is not null && count <= 0)) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.ILoader contract = _target.Contracts.Loader; @@ -1075,7 +1103,7 @@ int ISOSDacInterface.GetPEFileName(ulong addr, uint count, char* fileName, uint* } catch (System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -1088,12 +1116,15 @@ int ISOSDacInterface.GetPEFileName(ulong addr, uint count, char* fileName, uint* { hrLocal = _legacyImpl.GetPEFileName(addr, count, ptr, &neededLocal); } - Debug.Assert(hrLocal == HResults.S_OK); - Debug.Assert(pNeeded == null || *pNeeded == neededLocal); - Debug.Assert(fileName == null || new ReadOnlySpan(fileNameLocal, 0, (int)neededLocal - 1).SequenceEqual(new string(fileName))); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(pNeeded == null || *pNeeded == neededLocal); + Debug.Assert(fileName == null || new ReadOnlySpan(fileNameLocal, 0, (int)neededLocal - 1).SequenceEqual(new string(fileName))); + } } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetPrivateBinPaths(ulong appDomain, int count, char* paths, uint* pNeeded) @@ -1122,6 +1153,7 @@ int ISOSDacInterface.GetThreadData(ulong thread, DacpThreadData* data) if (thread == 0 || data == null) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.IThread contract = _target.Contracts.Thread; @@ -1148,7 +1180,7 @@ int ISOSDacInterface.GetThreadData(ulong thread, DacpThreadData* data) } catch (global::System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -1156,25 +1188,28 @@ int ISOSDacInterface.GetThreadData(ulong thread, DacpThreadData* data) { DacpThreadData dataLocal; int hrLocal = _legacyImpl.GetThreadData(thread, &dataLocal); - Debug.Assert(hrLocal >= 0); - Debug.Assert(data->corThreadId == dataLocal.corThreadId); - Debug.Assert(data->osThreadId == dataLocal.osThreadId); - Debug.Assert(data->state == dataLocal.state); - Debug.Assert(data->preemptiveGCDisabled == dataLocal.preemptiveGCDisabled); - Debug.Assert(data->allocContextPtr == dataLocal.allocContextPtr); - Debug.Assert(data->allocContextLimit == dataLocal.allocContextLimit); - Debug.Assert(data->fiberData == dataLocal.fiberData); - Debug.Assert(data->context == dataLocal.context); - Debug.Assert(data->domain == dataLocal.domain); - Debug.Assert(data->lockCount == dataLocal.lockCount); - Debug.Assert(data->pFrame == dataLocal.pFrame); - Debug.Assert(data->firstNestedException == dataLocal.firstNestedException); - Debug.Assert(data->teb == dataLocal.teb); - Debug.Assert(data->lastThrownObjectHandle == dataLocal.lastThrownObjectHandle); - Debug.Assert(data->nextThread == dataLocal.nextThread); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(data->corThreadId == dataLocal.corThreadId); + Debug.Assert(data->osThreadId == dataLocal.osThreadId); + Debug.Assert(data->state == dataLocal.state); + Debug.Assert(data->preemptiveGCDisabled == dataLocal.preemptiveGCDisabled); + Debug.Assert(data->allocContextPtr == dataLocal.allocContextPtr); + Debug.Assert(data->allocContextLimit == dataLocal.allocContextLimit); + Debug.Assert(data->fiberData == dataLocal.fiberData); + Debug.Assert(data->context == dataLocal.context); + Debug.Assert(data->domain == dataLocal.domain); + Debug.Assert(data->lockCount == dataLocal.lockCount); + Debug.Assert(data->pFrame == dataLocal.pFrame); + Debug.Assert(data->firstNestedException == dataLocal.firstNestedException); + Debug.Assert(data->teb == dataLocal.teb); + Debug.Assert(data->lastThrownObjectHandle == dataLocal.lastThrownObjectHandle); + Debug.Assert(data->nextThread == dataLocal.nextThread); + } } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetThreadFromThinlockID(uint thinLockId, ulong* pThread) => _legacyImpl is not null ? _legacyImpl.GetThreadFromThinlockID(thinLockId, pThread) : HResults.E_NOTIMPL; @@ -1188,6 +1223,7 @@ int ISOSDacInterface.GetThreadStoreData(DacpThreadStoreData* data) if (data == null) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { Contracts.IThread thread = _target.Contracts.Thread; @@ -1207,7 +1243,7 @@ int ISOSDacInterface.GetThreadStoreData(DacpThreadStoreData* data) } catch (global::System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -1215,19 +1251,22 @@ int ISOSDacInterface.GetThreadStoreData(DacpThreadStoreData* data) { DacpThreadStoreData dataLocal; int hrLocal = _legacyImpl.GetThreadStoreData(&dataLocal); - Debug.Assert(hrLocal >= 0); - Debug.Assert(data->threadCount == dataLocal.threadCount); - Debug.Assert(data->firstThread == dataLocal.firstThread); - Debug.Assert(data->finalizerThread == dataLocal.finalizerThread); - Debug.Assert(data->gcThread == dataLocal.gcThread); - Debug.Assert(data->unstartedThreadCount == dataLocal.unstartedThreadCount); - Debug.Assert(data->backgroundThreadCount == dataLocal.backgroundThreadCount); - Debug.Assert(data->pendingThreadCount == dataLocal.pendingThreadCount); - Debug.Assert(data->deadThreadCount == dataLocal.deadThreadCount); - Debug.Assert(data->fHostConfig == dataLocal.fHostConfig); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(data->threadCount == dataLocal.threadCount); + Debug.Assert(data->firstThread == dataLocal.firstThread); + Debug.Assert(data->finalizerThread == dataLocal.finalizerThread); + Debug.Assert(data->gcThread == dataLocal.gcThread); + Debug.Assert(data->unstartedThreadCount == dataLocal.unstartedThreadCount); + Debug.Assert(data->backgroundThreadCount == dataLocal.backgroundThreadCount); + Debug.Assert(data->pendingThreadCount == dataLocal.pendingThreadCount); + Debug.Assert(data->deadThreadCount == dataLocal.deadThreadCount); + Debug.Assert(data->fHostConfig == dataLocal.fHostConfig); + } } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetTLSIndex(uint* pIndex) @@ -1238,6 +1277,7 @@ int ISOSDacInterface.GetUsefulGlobals(DacpUsefulGlobalsData* data) if (data == null) return HResults.E_INVALIDARG; + int hr = HResults.S_OK; try { data->ArrayMethodTable = _target.ReadPointer( @@ -1253,7 +1293,7 @@ int ISOSDacInterface.GetUsefulGlobals(DacpUsefulGlobalsData* data) } catch (System.Exception ex) { - return ex.HResult; + hr = ex.HResult; } #if DEBUG @@ -1261,15 +1301,18 @@ int ISOSDacInterface.GetUsefulGlobals(DacpUsefulGlobalsData* data) { DacpUsefulGlobalsData dataLocal; int hrLocal = _legacyImpl.GetUsefulGlobals(&dataLocal); - Debug.Assert(hrLocal >= 0); - Debug.Assert(data->ArrayMethodTable == dataLocal.ArrayMethodTable); - Debug.Assert(data->StringMethodTable == dataLocal.StringMethodTable); - Debug.Assert(data->ObjectMethodTable == dataLocal.ObjectMethodTable); - Debug.Assert(data->ExceptionMethodTable == dataLocal.ExceptionMethodTable); - Debug.Assert(data->FreeMethodTable == dataLocal.FreeMethodTable); + Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); + if (hr == HResults.S_OK) + { + Debug.Assert(data->ArrayMethodTable == dataLocal.ArrayMethodTable); + Debug.Assert(data->StringMethodTable == dataLocal.StringMethodTable); + Debug.Assert(data->ObjectMethodTable == dataLocal.ObjectMethodTable); + Debug.Assert(data->ExceptionMethodTable == dataLocal.ExceptionMethodTable); + Debug.Assert(data->FreeMethodTable == dataLocal.FreeMethodTable); + } } #endif - return HResults.S_OK; + return hr; } int ISOSDacInterface.GetWorkRequestData(ulong addrWorkRequest, void* data) diff --git a/src/native/managed/cdacreader/tests/MethodTableTests.cs b/src/native/managed/cdacreader/tests/MethodTableTests.cs index 6b19790ae1924..fb92efe1fd530 100644 --- a/src/native/managed/cdacreader/tests/MethodTableTests.cs +++ b/src/native/managed/cdacreader/tests/MethodTableTests.cs @@ -134,7 +134,7 @@ public void MethodTableEEClassInvalidThrows(MockTarget.Architecture arch) { Contracts.IRuntimeTypeSystem metadataContract = target.Contracts.RuntimeTypeSystem; Assert.NotNull(metadataContract); - Assert.Throws(() => metadataContract.GetTypeHandle(badMethodTablePtr)); + Assert.Throws(() => metadataContract.GetTypeHandle(badMethodTablePtr)); }); }