diff --git a/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs b/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs index b99fbdee26cac1..a6760c425378cb 100644 --- a/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs +++ b/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs @@ -570,7 +570,62 @@ int ISOSDacInterface.GetMethodDescName(ulong methodDesc, uint count, char* name, int ISOSDacInterface.GetMethodDescPtrFromFrame(ulong frameAddr, ulong* ppMD) => _legacyImpl is not null ? _legacyImpl.GetMethodDescPtrFromFrame(frameAddr, ppMD) : HResults.E_NOTIMPL; int ISOSDacInterface.GetMethodDescPtrFromIP(ulong ip, ulong* ppMD) - => _legacyImpl is not null ? _legacyImpl.GetMethodDescPtrFromIP(ip, ppMD) : HResults.E_NOTIMPL; + { + if (ip == 0 || ppMD == null) + return HResults.E_INVALIDARG; + + int hr = HResults.E_NOTIMPL; + + try + { + IExecutionManager executionManager = _target.Contracts.ExecutionManager; + IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; + + CodeBlockHandle? handle = executionManager.GetCodeBlockHandle(new TargetCodePointer(ip)); + if (handle is CodeBlockHandle codeHandle) + { + TargetPointer methodDescAddr = executionManager.GetMethodDesc(codeHandle); + + try + { + // Runs validation of MethodDesc + // if validation fails, should return E_INVALIDARG + rts.GetMethodDescHandle(methodDescAddr); + + *ppMD = methodDescAddr.Value; + hr = HResults.S_OK; + } + catch (System.Exception) + { + hr = HResults.E_INVALIDARG; + } + } + else + { + hr = HResults.E_FAIL; + } + } + catch (System.Exception ex) + { + hr = ex.HResult; + } + +#if DEBUG + if (_legacyImpl is not null) + { + ulong ppMDLocal; + int hrLocal = _legacyImpl.GetMethodDescPtrFromIP(ip, &ppMDLocal); + + Debug.Assert(hrLocal == hr); + if (hr == HResults.S_OK) + { + Debug.Assert(*ppMD == ppMDLocal); + } + } +#endif + return hr; + } + int ISOSDacInterface.GetMethodDescTransparencyData(ulong methodDesc, void* data) => _legacyImpl is not null ? _legacyImpl.GetMethodDescTransparencyData(methodDesc, data) : HResults.E_NOTIMPL; int ISOSDacInterface.GetMethodTableData(ulong mt, DacpMethodTableData* data)