Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 64 additions & 52 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2429,24 +2429,24 @@ ClrDataAccess::GetAppDomainStoreData(struct DacpAppDomainStoreData *adsData)
HRESULT
ClrDataAccess::GetAppDomainData(CLRDATA_ADDRESS addr, struct DacpAppDomainData *appdomainData)
{
// addr is ignored, only one AppDomain exists in CoreCLR.
SOSDacEnter();

if (addr == 0)
PTR_AppDomain pAppDomain = AppDomain::GetCurrentDomain();
if (pAppDomain == NULL)
{
hr = E_INVALIDARG;
hr = E_FAIL;
}
else
{
ZeroMemory(appdomainData, sizeof(DacpAppDomainData));
appdomainData->AppDomainPtr = addr;
appdomainData->AppDomainPtr = HOST_CDADDR(pAppDomain);
PTR_LoaderAllocator pLoaderAllocator = SystemDomain::GetGlobalLoaderAllocator();
appdomainData->pHighFrequencyHeap = HOST_CDADDR(pLoaderAllocator->GetHighFrequencyHeap());
appdomainData->pLowFrequencyHeap = HOST_CDADDR(pLoaderAllocator->GetLowFrequencyHeap());
appdomainData->pStubHeap = HOST_CDADDR(pLoaderAllocator->GetStubHeap());
appdomainData->appDomainStage = STAGE_OPEN;

PTR_AppDomain pAppDomain = PTR_AppDomain(TO_TADDR(addr));

appdomainData->dwId = DefaultADID;

AppDomain::AssemblyIterator i = pAppDomain->IterateAssembliesEx((AssemblyIterationFlags)(
Expand Down Expand Up @@ -2550,37 +2550,42 @@ ClrDataAccess::GetFailedAssemblyDisplayName(CLRDATA_ADDRESS assembly, unsigned i
HRESULT
ClrDataAccess::GetAssemblyList(CLRDATA_ADDRESS addr, int count, CLRDATA_ADDRESS values[], int *pNeeded)
{
if (addr == (CLRDATA_ADDRESS)NULL)
return E_INVALIDARG;

// addr is ignored, only one AppDomain exists in CoreCLR.
SOSDacEnter();

PTR_AppDomain pAppDomain = PTR_AppDomain(TO_TADDR(addr));
AppDomain::AssemblyIterator i = pAppDomain->IterateAssembliesEx(
(AssemblyIterationFlags)(kIncludeLoading | kIncludeLoaded | kIncludeExecution));
CollectibleAssemblyHolder<Assembly *> pAssembly;

int n = 0;
if (values)
PTR_AppDomain pAppDomain = AppDomain::GetCurrentDomain();
if (pAppDomain == NULL)
{
while (i.Next(pAssembly.This()) && (n < count))
hr = E_FAIL;
}
else
{
AppDomain::AssemblyIterator i = pAppDomain->IterateAssembliesEx(
(AssemblyIterationFlags)(kIncludeLoading | kIncludeLoaded | kIncludeExecution));
CollectibleAssemblyHolder<Assembly *> pAssembly;

int n = 0;
if (values)
{
if (pAssembly->IsLoaded())
while (i.Next(pAssembly.This()) && (n < count))
{
// Note: DAC doesn't need to keep the assembly alive - see code:CollectibleAssemblyHolder#CAH_DAC
values[n++] = HOST_CDADDR(pAssembly.Extract());
if (pAssembly->IsLoaded())
{
// Note: DAC doesn't need to keep the assembly alive - see code:CollectibleAssemblyHolder#CAH_DAC
values[n++] = HOST_CDADDR(pAssembly.Extract());
}
}
}
}
else
{
while (i.Next(pAssembly.This()))
if (pAssembly->IsLoaded())
n++;
}
else
{
while (i.Next(pAssembly.This()))
if (pAssembly->IsLoaded())
n++;
}

if (pNeeded)
*pNeeded = n;
if (pNeeded)
*pNeeded = n;
}

SOSDacLeave();
return hr;
Expand Down Expand Up @@ -2618,39 +2623,46 @@ ClrDataAccess::GetFailedAssemblyList(CLRDATA_ADDRESS appDomain, int count,
HRESULT
ClrDataAccess::GetAppDomainName(CLRDATA_ADDRESS addr, unsigned int count, _Inout_updates_z_(count) WCHAR *name, unsigned int *pNeeded)
{
// addr is ignored, only one AppDomain exists in CoreCLR.
SOSDacEnter();

PTR_AppDomain pAppDomain = PTR_AppDomain(TO_TADDR(addr));

size_t countAsSizeT = count;
if (pAppDomain->m_friendlyName.IsValid())
PTR_AppDomain pAppDomain = AppDomain::GetCurrentDomain();
if (pAppDomain == NULL)
{
LPCWSTR friendlyName = (LPCWSTR)pAppDomain->m_friendlyName;
size_t friendlyNameLen = u16_strlen(friendlyName);

if (pNeeded)
hr = E_FAIL;
}
else
{
size_t countAsSizeT = count;
if (pAppDomain->m_friendlyName.IsValid())
{
*pNeeded = (unsigned int)(friendlyNameLen + 1);
}
LPCWSTR friendlyName = (LPCWSTR)pAppDomain->m_friendlyName;
size_t friendlyNameLen = u16_strlen(friendlyName);

if (name && count > 0)
{
if (countAsSizeT > (friendlyNameLen + 1))
if (pNeeded)
{
*pNeeded = (unsigned int)(friendlyNameLen + 1);
}

if (name && count > 0)
{
countAsSizeT = friendlyNameLen + 1;
if (countAsSizeT > (friendlyNameLen + 1))
{
countAsSizeT = friendlyNameLen + 1;
}
memcpy(name, friendlyName, countAsSizeT * sizeof(WCHAR));
name[countAsSizeT - 1] = 0;
}
memcpy(name, friendlyName, countAsSizeT * sizeof(WCHAR));
name[countAsSizeT - 1] = 0;
}
}
else
{
if (pNeeded)
*pNeeded = 1;
if (name && count > 0)
name[0] = 0;
else
{
if (pNeeded)
*pNeeded = 1;
if (name && count > 0)
name[0] = 0;

hr = S_OK;
hr = S_OK;
}
}

SOSDacLeave();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,30 @@ int ISOSDacInterface.GetAppDomainConfigFile(ClrDataAddress appDomain, int count,

return hr;
}

// addr is ignored, only one AppDomain exists in CoreCLR.
int ISOSDacInterface.GetAppDomainData(ClrDataAddress addr, DacpAppDomainData* data)
{
int hr = HResults.S_OK;
try
{
if (addr == 0)
throw new ArgumentException();

*data = default;
data->AppDomainPtr = addr;
Contracts.ILoader loader = _target.Contracts.Loader;
TargetPointer appDomain = loader.GetAppDomain();
if (appDomain == TargetPointer.Null)
throw new InvalidOperationException();
Comment thread
max-charlamb marked this conversation as resolved.

data->AppDomainPtr = appDomain.ToClrDataAddress(_target);
TargetPointer globalLoaderAllocator = loader.GetGlobalLoaderAllocator();
Comment thread
max-charlamb marked this conversation as resolved.
data->pHighFrequencyHeap = loader.GetHighFrequencyHeap(globalLoaderAllocator).ToClrDataAddress(_target);
data->pLowFrequencyHeap = loader.GetLowFrequencyHeap(globalLoaderAllocator).ToClrDataAddress(_target);
data->pStubHeap = loader.GetStubHeap(globalLoaderAllocator).ToClrDataAddress(_target);
data->appDomainStage = DacpAppDomainDataStage.STAGE_OPEN;

TargetPointer pAppDomain = addr.ToTargetPointer(_target);
data->dwId = DefaultAppDomainId;

IEnumerable<Contracts.ModuleHandle> modules = loader.GetModuleHandles(
pAppDomain,
appDomain,
AssemblyIterationFlags.IncludeLoading |
AssemblyIterationFlags.IncludeLoaded |
AssemblyIterationFlags.IncludeExecution);
Expand All @@ -143,7 +145,7 @@ int ISOSDacInterface.GetAppDomainData(ClrDataAddress addr, DacpAppDomainData* da
}

IEnumerable<Contracts.ModuleHandle> failedModules = loader.GetModuleHandles(
pAppDomain,
appDomain,
AssemblyIterationFlags.IncludeFailedToLoad);
data->FailedAssemblyCount = failedModules.Count();
}
Expand Down Expand Up @@ -214,6 +216,7 @@ int ISOSDacInterface.GetAppDomainList(uint count, [In, MarshalUsing(CountElement
#endif
return hr;
}
// addr is ignored -- only one AppDomain exists in CoreCLR.
int ISOSDacInterface.GetAppDomainName(ClrDataAddress addr, uint count, char* name, uint* pNeeded)
{
int hr = HResults.S_OK;
Expand Down Expand Up @@ -386,16 +389,17 @@ int ISOSDacInterface.GetAssemblyData(ClrDataAddress domain, ClrDataAddress assem
return hr;
}

// addr is ignored, only one AppDomain exists in CoreCLR.
int ISOSDacInterface.GetAssemblyList(ClrDataAddress addr, int count, [In, MarshalUsing(CountElementName = "count"), Out] ClrDataAddress[]? values, int* pNeeded)
{
int hr = HResults.S_OK;

try
{
if (addr == 0)
throw new ArgumentException();
TargetPointer appDomain = addr.ToTargetPointer(_target);
ILoader loader = _target.Contracts.Loader;
TargetPointer appDomain = loader.GetAppDomain();
if (appDomain == TargetPointer.Null)
throw new InvalidOperationException();
Comment thread
max-charlamb marked this conversation as resolved.

List<Contracts.ModuleHandle> modules = loader.GetModuleHandles(
appDomain,
Comment thread
max-charlamb marked this conversation as resolved.
Expand Down
Loading