diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index 4027e1dd533beb..36956768796c55 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -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)( @@ -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 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 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; @@ -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(); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs index 5fb44766193c60..58c1f420ef70b0 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs @@ -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(); + + data->AppDomainPtr = appDomain.ToClrDataAddress(_target); TargetPointer globalLoaderAllocator = loader.GetGlobalLoaderAllocator(); 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 modules = loader.GetModuleHandles( - pAppDomain, + appDomain, AssemblyIterationFlags.IncludeLoading | AssemblyIterationFlags.IncludeLoaded | AssemblyIterationFlags.IncludeExecution); @@ -143,7 +145,7 @@ int ISOSDacInterface.GetAppDomainData(ClrDataAddress addr, DacpAppDomainData* da } IEnumerable failedModules = loader.GetModuleHandles( - pAppDomain, + appDomain, AssemblyIterationFlags.IncludeFailedToLoad); data->FailedAssemblyCount = failedModules.Count(); } @@ -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; @@ -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(); List modules = loader.GetModuleHandles( appDomain,