Skip to content

Commit

Permalink
[cdac] Implement ISOSDacInterface::GetPEFileBase in cDAC (dotnet#108602)
Browse files Browse the repository at this point in the history
Implements ISOSDacInterface::GetPEFileBase in cDAC

Module already contains the Base so no change is needed.
Loader_1.cs already implements GetILBase to get the Base off of the module.

Contributes to dotnet#108450
  • Loading branch information
max-charlamb authored Oct 8, 2024
1 parent 667c007 commit 219126c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/coreclr/debug/daccess/dacimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,7 @@ class ClrDataAccess
HRESULT GetObjectDataImpl(CLRDATA_ADDRESS addr, struct DacpObjectData *objectData);
HRESULT GetObjectExceptionDataImpl(CLRDATA_ADDRESS objAddr, struct DacpExceptionObjectData *data);
HRESULT GetObjectStringDataImpl(CLRDATA_ADDRESS obj, unsigned int count, _Inout_updates_z_(count) WCHAR *stringData, unsigned int *pNeeded);
HRESULT GetPEFileBaseImpl(CLRDATA_ADDRESS moduleAddr, CLRDATA_ADDRESS *base);
HRESULT GetPEFileNameImpl(CLRDATA_ADDRESS moduleAddr, unsigned int count, _Inout_updates_z_(count) WCHAR *fileName, unsigned int *pNeeded);
HRESULT GetUsefulGlobalsImpl(struct DacpUsefulGlobalsData *globalsData);
HRESULT GetMethodDescDataImpl(CLRDATA_ADDRESS methodDesc, CLRDATA_ADDRESS ip, struct DacpMethodDescData *data, ULONG cRevertedRejitVersions, DacpReJitData * rgRevertedRejitData, ULONG * pcNeededRevertedRejitData);
Expand Down
34 changes: 32 additions & 2 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,37 @@ ClrDataAccess::GetPEFileBase(CLRDATA_ADDRESS moduleAddr, CLRDATA_ADDRESS *base)

SOSDacEnter();

if (m_cdacSos != NULL)
{
hr = m_cdacSos->GetPEFileBase(moduleAddr, base);
if (FAILED(hr))
{
hr = GetPEFileBaseImpl(moduleAddr, base);
}
#ifdef _DEBUG
else
{
CLRDATA_ADDRESS baseLocal = 0;
HRESULT hrLocal = GetPEFileBaseImpl(moduleAddr, &baseLocal);

DacAssertsEnabledHolder assertsEnabled;
_ASSERTE(hr == hrLocal);
_ASSERTE(*base == baseLocal);
}
#endif
}
else
{
hr = GetPEFileBaseImpl(moduleAddr, base);
}

SOSDacLeave();
return hr;
}

HRESULT
ClrDataAccess::GetPEFileBaseImpl(CLRDATA_ADDRESS moduleAddr, CLRDATA_ADDRESS *base)
{
PTR_Module pModule = PTR_Module(TO_TADDR(moduleAddr));

// More fields later?
Expand All @@ -2622,8 +2653,7 @@ ClrDataAccess::GetPEFileBase(CLRDATA_ADDRESS moduleAddr, CLRDATA_ADDRESS *base)
*base = (CLRDATA_ADDRESS)NULL;
}

SOSDacLeave();
return hr;
return S_OK;
}

DWORD DACGetNumComponents(TADDR addr, ICorDebugDataTarget* target)
Expand Down
26 changes: 25 additions & 1 deletion src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,31 @@ public unsafe int GetObjectStringData(ulong obj, uint count, char* stringData, u
}
public unsafe int GetOOMData(ulong oomAddr, void* data) => HResults.E_NOTIMPL;
public unsafe int GetOOMStaticData(void* data) => HResults.E_NOTIMPL;
public unsafe int GetPEFileBase(ulong addr, ulong* peBase) => HResults.E_NOTIMPL;

public unsafe int GetPEFileBase(ulong addr, ulong* peBase)
{
try
{
Contracts.ILoader contract = _target.Contracts.Loader;
Contracts.ModuleHandle handle = contract.GetModuleHandle(addr);
Contracts.ModuleFlags flags = contract.GetFlags(handle);

if (!flags.HasFlag(Contracts.ModuleFlags.ReflectionEmit))
{
*peBase = contract.GetILBase(handle);
}
else
{
*peBase = 0;
}
}
catch (System.Exception ex)
{
return ex.HResult;
}

return HResults.S_OK;
}

public unsafe int GetPEFileName(ulong addr, uint count, char* fileName, uint* pNeeded)
{
Expand Down

0 comments on commit 219126c

Please sign in to comment.