Skip to content

Commit e7e8286

Browse files
max-charlambMax Charlambelinor-fung
authored
[cDAC] Implement ISOSDacInterface::GetMethodDescPtrFromIp (#110755)
Contributes to #108553 Tested using `!sos ip2md <ip>`. --------- Co-authored-by: Max Charlamb <[email protected]> Co-authored-by: Elinor Fung <[email protected]>
1 parent eadb357 commit e7e8286

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs

+56-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,62 @@ int ISOSDacInterface.GetMethodDescName(ulong methodDesc, uint count, char* name,
569569
int ISOSDacInterface.GetMethodDescPtrFromFrame(ulong frameAddr, ulong* ppMD)
570570
=> _legacyImpl is not null ? _legacyImpl.GetMethodDescPtrFromFrame(frameAddr, ppMD) : HResults.E_NOTIMPL;
571571
int ISOSDacInterface.GetMethodDescPtrFromIP(ulong ip, ulong* ppMD)
572-
=> _legacyImpl is not null ? _legacyImpl.GetMethodDescPtrFromIP(ip, ppMD) : HResults.E_NOTIMPL;
572+
{
573+
if (ip == 0 || ppMD == null)
574+
return HResults.E_INVALIDARG;
575+
576+
int hr = HResults.E_NOTIMPL;
577+
578+
try
579+
{
580+
IExecutionManager executionManager = _target.Contracts.ExecutionManager;
581+
IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem;
582+
583+
CodeBlockHandle? handle = executionManager.GetCodeBlockHandle(new TargetCodePointer(ip));
584+
if (handle is CodeBlockHandle codeHandle)
585+
{
586+
TargetPointer methodDescAddr = executionManager.GetMethodDesc(codeHandle);
587+
588+
try
589+
{
590+
// Runs validation of MethodDesc
591+
// if validation fails, should return E_INVALIDARG
592+
rts.GetMethodDescHandle(methodDescAddr);
593+
594+
*ppMD = methodDescAddr.Value;
595+
hr = HResults.S_OK;
596+
}
597+
catch (System.Exception)
598+
{
599+
hr = HResults.E_INVALIDARG;
600+
}
601+
}
602+
else
603+
{
604+
hr = HResults.E_FAIL;
605+
}
606+
}
607+
catch (System.Exception ex)
608+
{
609+
hr = ex.HResult;
610+
}
611+
612+
#if DEBUG
613+
if (_legacyImpl is not null)
614+
{
615+
ulong ppMDLocal;
616+
int hrLocal = _legacyImpl.GetMethodDescPtrFromIP(ip, &ppMDLocal);
617+
618+
Debug.Assert(hrLocal == hr);
619+
if (hr == HResults.S_OK)
620+
{
621+
Debug.Assert(*ppMD == ppMDLocal);
622+
}
623+
}
624+
#endif
625+
return hr;
626+
}
627+
573628
int ISOSDacInterface.GetMethodDescTransparencyData(ulong methodDesc, void* data)
574629
=> _legacyImpl is not null ? _legacyImpl.GetMethodDescTransparencyData(methodDesc, data) : HResults.E_NOTIMPL;
575630
int ISOSDacInterface.GetMethodTableData(ulong mt, DacpMethodTableData* data)

0 commit comments

Comments
 (0)