@@ -226,11 +226,10 @@ void DebuggerModuleTable::AddModule(DebuggerModule *pModule)
226
226
}
227
227
228
228
// -----------------------------------------------------------------------------
229
- // Remove a DebuggerModule from the module table.
230
- // This occurs in response to AppDomain unload.
231
- // Note that this doesn't necessarily mean the EE Module is being unloaded (it may be shared)
229
+ // Remove a DebuggerModule from the module table when it gets notified.
230
+ // This occurs in response to the finalization of an unloaded AssemblyLoadContext.
232
231
// -----------------------------------------------------------------------------
233
- void DebuggerModuleTable::RemoveModule (Module* module , AppDomain *pAppDomain)
232
+ void DebuggerModuleTable::RemoveModule (Module* pModule , AppDomain *pAppDomain)
234
233
{
235
234
CONTRACTL
236
235
{
@@ -239,12 +238,33 @@ void DebuggerModuleTable::RemoveModule(Module* module, AppDomain *pAppDomain)
239
238
}
240
239
CONTRACTL_END;
241
240
242
- // If this is a domain neutral module, then scan the complete list of DebuggerModules looking
243
- // for the one with a matching appdomain id.
244
- // Note: we have to make sure to lookup the module with the app domain parameter if the module lives in a shared
245
- // assembly or the system assembly. <BUGNUM>Bugs 65943 & 81728.</BUGNUM>
246
- _ASSERTE ( FALSE );
247
-
241
+ LOG ((LF_CORDB, LL_INFO1000, " DMT::RM Attempting to remove Module:0x%x AD:0x%x\n " , pModule, pAppDomain));
242
+
243
+ _ASSERTE (ThreadHoldsLock ());
244
+ _ASSERTE (pModule != NULL );
245
+
246
+ HASHFIND hf;
247
+
248
+ for (DebuggerModuleEntry *pDME = (DebuggerModuleEntry *) FindFirstEntry (&hf);
249
+ pDME != NULL ;
250
+ pDME = (DebuggerModuleEntry*) FindNextEntry (&hf))
251
+ {
252
+ DebuggerModule *pDM = pDME->module ;
253
+ Module* pRuntimeModule = pDM->GetRuntimeModule ();
254
+
255
+ if ((pRuntimeModule == pModule) && (pDM->GetAppDomain () == pAppDomain))
256
+ {
257
+ LOG ((LF_CORDB, LL_INFO1000, " DMT::RM Removing DebuggerMod:0x%x - Module:0x%x DF:0x%x AD:0x%x\n " ,
258
+ pDM, pModule, pDM->GetDomainFile (), pAppDomain));
259
+ TRACE_FREE (pDM);
260
+ DeleteInteropSafe (pDM);
261
+ Delete (HASH (pRuntimeModule), (HASHENTRY *) pDME);
262
+ _ASSERTE (GetModule (pModule, pAppDomain) == NULL );
263
+ return ;
264
+ }
265
+ }
266
+
267
+ LOG ((LF_CORDB, LL_INFO1000, " DMT::RM No debugger module found for Module:0x%x AD:0x%x\n " , pModule, pAppDomain));
248
268
}
249
269
250
270
@@ -337,5 +357,3 @@ DebuggerModule *DebuggerModuleTable::GetNextModule(HASHFIND *info)
337
357
else
338
358
return entry->module ;
339
359
}
340
-
341
-
0 commit comments