@@ -921,7 +921,6 @@ CordbProcess::CordbProcess(ULONG64 clrInstanceId,
921921 m_unmanagedThreads(11),
922922#endif
923923 m_appDomains(11),
924- m_sharedAppDomain(0),
925924 m_steppers(11),
926925 m_continueCounter(1),
927926 m_flushCounter(0),
@@ -956,7 +955,6 @@ CordbProcess::CordbProcess(ULONG64 clrInstanceId,
956955 m_iFirstPatch(0),
957956 m_hHelperThread(NULL),
958957 m_dispatchedEvent(DB_IPCE_DEBUGGER_INVALID),
959- m_pDefaultAppDomain(NULL),
960958 m_hDacModule(hDacModule),
961959 m_pDacPrimitives(NULL),
962960 m_pEventChannel(NULL),
@@ -1059,8 +1057,6 @@ CordbProcess::~CordbProcess()
10591057 // We shouldn't still be in Cordb's list of processes. Unfortunately, our root Cordb object
10601058 // may have already been deleted b/c we're at the mercy of ref-counting, so we can't check.
10611059
1062- _ASSERTE(m_sharedAppDomain == NULL);
1063-
10641060 m_processMutex.Destroy();
10651061 m_StopGoLock.Destroy();
10661062
@@ -1288,16 +1284,8 @@ void CordbProcess::NeuterChildren()
12881284
12891285 m_userThreads.NeuterAndClear(GetProcessLock());
12901286
1291- m_pDefaultAppDomain = NULL;
1292-
12931287 // Frees per-appdomain left-side resources. See assumptions above.
12941288 m_appDomains.NeuterAndClear(GetProcessLock());
1295- if (m_sharedAppDomain != NULL)
1296- {
1297- m_sharedAppDomain->Neuter();
1298- m_sharedAppDomain->InternalRelease();
1299- m_sharedAppDomain = NULL;
1300- }
13011289
13021290 m_steppers.NeuterAndClear(GetProcessLock());
13031291
@@ -2306,10 +2294,10 @@ HRESULT CordbProcess::EnumerateHeapRegions(ICorDebugHeapSegmentEnum **ppRegions)
23062294
23072295HRESULT CordbProcess::GetObject(CORDB_ADDRESS addr, ICorDebugObjectValue **ppObject)
23082296{
2309- return this->GetObjectInternal(addr, nullptr, ppObject);
2297+ return this->GetObjectInternal(addr, ppObject);
23102298}
23112299
2312- HRESULT CordbProcess::GetObjectInternal(CORDB_ADDRESS addr, CordbAppDomain* pAppDomainOverride, ICorDebugObjectValue **pObject)
2300+ HRESULT CordbProcess::GetObjectInternal(CORDB_ADDRESS addr, ICorDebugObjectValue **pObject)
23132301{
23142302 HRESULT hr = S_OK;
23152303
@@ -2333,7 +2321,7 @@ HRESULT CordbProcess::GetObjectInternal(CORDB_ADDRESS addr, CordbAppDomain* pApp
23332321
23342322 CordbAppDomain *cdbAppDomain = NULL;
23352323 CordbType *pType = NULL;
2336- hr = GetTypeForObject(addr, pAppDomainOverride, &pType, &cdbAppDomain);
2324+ hr = GetTypeForObject(addr, &pType, &cdbAppDomain);
23372325
23382326 if (SUCCEEDED(hr))
23392327 {
@@ -2441,7 +2429,7 @@ HRESULT CordbProcess::GetTypeForTypeID(COR_TYPEID id, ICorDebugType **ppType)
24412429 GetDAC()->GetObjectExpandedTypeInfoFromID(AllBoxed, VMPTR_AppDomain::NullPtr(), id, &data);
24422430
24432431 CordbType *type = 0;
2444- hr = CordbType::TypeDataToType(GetSharedAppDomain (), &data, &type);
2432+ hr = CordbType::TypeDataToType(GetAppDomain (), &data, &type);
24452433
24462434 if (SUCCEEDED(hr))
24472435 hr = type->QueryInterface(IID_ICorDebugType, (void**)ppType);
@@ -2569,7 +2557,7 @@ COM_METHOD CordbProcess::EnumerateLoaderHeapMemoryRegions(ICorDebugMemoryRangeEn
25692557 return hr;
25702558}
25712559
2572- HRESULT CordbProcess::GetTypeForObject(CORDB_ADDRESS addr, CordbAppDomain* pAppDomainOverride, CordbType **ppType, CordbAppDomain **pAppDomain)
2560+ HRESULT CordbProcess::GetTypeForObject(CORDB_ADDRESS addr, CordbType **ppType, CordbAppDomain **pAppDomain)
25732561{
25742562 VMPTR_AppDomain appDomain;
25752563 VMPTR_Module mod;
@@ -2578,11 +2566,7 @@ HRESULT CordbProcess::GetTypeForObject(CORDB_ADDRESS addr, CordbAppDomain* pAppD
25782566 HRESULT hr = E_FAIL;
25792567 if (GetDAC()->GetAppDomainForObject(addr, &appDomain, &mod, &domainAssembly))
25802568 {
2581- if (pAppDomainOverride)
2582- {
2583- appDomain = pAppDomainOverride->GetADToken();
2584- }
2585- CordbAppDomain *cdbAppDomain = appDomain.IsNull() ? GetSharedAppDomain() : LookupOrCreateAppDomain(appDomain);
2569+ CordbAppDomain *cdbAppDomain = appDomain.IsNull() ? GetAppDomain() : LookupOrCreateAppDomain(appDomain);
25862570
25872571 _ASSERTE(cdbAppDomain);
25882572
@@ -5369,19 +5353,6 @@ void CordbProcess::RawDispatchEvent(
53695353 }
53705354 _ASSERTE (pAppDomain != NULL);
53715355
5372- // See if this is the default AppDomain exiting. This should only happen very late in
5373- // the shutdown cycle, and so we shouldn't do anything significant with m_pDefaultDomain==NULL.
5374- // We should try and remove m_pDefaultDomain entirely since we can't count on it always existing.
5375- if (pAppDomain == m_pDefaultAppDomain)
5376- {
5377- m_pDefaultAppDomain = NULL;
5378- }
5379-
5380- // Update any threads which were last seen in this AppDomain. We don't
5381- // get any notification when a thread leaves an AppDomain, so our idea
5382- // of what AppDomain the thread is in may be out of date.
5383- UpdateThreadsForAdUnload( pAppDomain );
5384-
53855356 // This will still maintain weak references so we could call Continue.
53865357 AddToNeuterOnContinueList(pAppDomain);
53875358
@@ -8717,19 +8688,23 @@ CordbAppDomain * CordbProcess::LookupOrCreateAppDomain(VMPTR_AppDomain vmAppDoma
87178688 return CacheAppDomain(vmAppDomain);
87188689}
87198690
8720- CordbAppDomain * CordbProcess::GetSharedAppDomain ()
8691+ CordbAppDomain * CordbProcess::GetAppDomain ()
87218692{
8722- if (m_sharedAppDomain == NULL)
8693+ // Return the one and only app domain
8694+ HASHFIND find;
8695+ CordbAppDomain* appDomain = m_appDomains.FindFirst(&find);
8696+ if (appDomain != NULL)
87238697 {
8724- CordbAppDomain *pAD = new CordbAppDomain(this, VMPTR_AppDomain::NullPtr());
8725- if (InterlockedCompareExchangeT<CordbAppDomain*>(&m_sharedAppDomain, pAD, NULL) != NULL)
8726- {
8727- delete pAD;
8728- }
8729- m_sharedAppDomain->InternalAddRef();
8698+ const ULONG appDomainId = 1; // DefaultADID in appdomain.hpp
8699+ ULONG32 id;
8700+ HRESULT hr = appDomain->GetID(&id);
8701+ TargetConsistencyCheck(SUCCEEDED(hr) && id == appDomainId);
8702+ return appDomain;
87308703 }
87318704
8732- return m_sharedAppDomain;
8705+ VMPTR_AppDomain vmAppDomain = GetDAC()->GetCurrentAppDomain();
8706+ appDomain = LookupOrCreateAppDomain(vmAppDomain);
8707+ return appDomain;
87338708}
87348709
87358710//---------------------------------------------------------------------------------------
@@ -8765,10 +8740,6 @@ CordbAppDomain * CordbProcess::CacheAppDomain(VMPTR_AppDomain vmAppDomain)
87658740 // The cache will take ownership.
87668741 m_appDomains.AddBaseOrThrow(pAppDomain);
87678742
8768- // If this assert fires, then it likely means the target is corrupted.
8769- TargetConsistencyCheck(m_pDefaultAppDomain == NULL);
8770- m_pDefaultAppDomain = pAppDomain;
8771-
87728743 CordbAppDomain * pReturn = pAppDomain;
87738744 pAppDomain.ClearAndMarkDontNeuter();
87748745
@@ -15263,46 +15234,6 @@ HRESULT CordbProcess::IsReadyForDetach()
1526315234 return S_OK;
1526415235}
1526515236
15266-
15267- /*
15268- * Look for any thread which was last seen in the specified AppDomain.
15269- * The CordbAppDomain object is about to be neutered due to an AD Unload
15270- * So the thread must no longer be considered to be in that domain.
15271- * Note that this is a workaround due to the existence of the (possibly incorrect)
15272- * cached AppDomain value. Ideally we would remove the cached value entirely
15273- * and there would be no need for this.
15274- *
15275- * @dbgtodo: , appdomain: We should remove CordbThread::m_pAppDomain in the V3 architecture.
15276- * If we need the thread's current domain, we should get it accurately with DAC.
15277- */
15278- void CordbProcess::UpdateThreadsForAdUnload(CordbAppDomain * pAppDomain)
15279- {
15280- INTERNAL_API_ENTRY(this);
15281-
15282- // If we're doing an AD unload then we should have already seen the ATTACH
15283- // notification for the default domain.
15284- //_ASSERTE( m_pDefaultAppDomain != NULL );
15285- // @dbgtodo appdomain: fix Default domain invariants with DAC-izing Appdomain work.
15286-
15287- RSLockHolder lockHolder(GetProcessLock());
15288-
15289- CordbThread* t;
15290- HASHFIND find;
15291-
15292- // We don't need to prepopulate here (to collect LS state) because we're just updating RS state.
15293- for (t = m_userThreads.FindFirst(&find);
15294- t != NULL;
15295- t = m_userThreads.FindNext(&find))
15296- {
15297- if( t->GetAppDomain() == pAppDomain )
15298- {
15299- // This thread cannot actually be in this AppDomain anymore (since it's being
15300- // unloaded). Reset it to point to the default AppDomain
15301- t->m_pAppDomain = m_pDefaultAppDomain;
15302- }
15303- }
15304- }
15305-
1530615237// CordbProcess::LookupClass
1530715238// Looks up a previously constructed CordbClass instance without creating. May return NULL if the
1530815239// CordbClass instance doesn't exist.
0 commit comments