From 3195893680368d9289d8354cfd00bf4b5b053a7d Mon Sep 17 00:00:00 2001 From: Max Charlamb Date: Mon, 16 Dec 2024 14:52:58 -0500 Subject: [PATCH 1/2] implement GetMethodDescPtrFromIp --- .../cdacreader/src/Legacy/SOSDacImpl.cs | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs b/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs index b99fbdee26cac1..6081badcc4ddac 100644 --- a/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs +++ b/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs @@ -570,7 +570,63 @@ 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) From 6fd426c0d461c25d65079eee04193298ecf87d93 Mon Sep 17 00:00:00 2001 From: Max Charlamb <44248479+max-charlamb@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:31:14 -0500 Subject: [PATCH 2/2] Update src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs Co-authored-by: Elinor Fung --- src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs b/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs index 6081badcc4ddac..a6760c425378cb 100644 --- a/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs +++ b/src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs @@ -610,7 +610,6 @@ int ISOSDacInterface.GetMethodDescPtrFromIP(ulong ip, ulong* ppMD) hr = ex.HResult; } - #if DEBUG if (_legacyImpl is not null) {