Skip to content

Commit

Permalink
[cDAC] Implement ISOSDacInterface::GetMethodDescPtrFromIp (#110755)
Browse files Browse the repository at this point in the history
Contributes to #108553

Tested using `!sos ip2md <ip>`.

---------

Co-authored-by: Max Charlamb <maxcharlamb@microsoft.com>
Co-authored-by: Elinor Fung <elfung@microsoft.com>
  • Loading branch information
3 people authored Feb 6, 2025
1 parent eadb357 commit e7e8286
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,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)
Expand Down

0 comments on commit e7e8286

Please # to comment.