From 63722ae375ecf2151401ba7c9663cd418efb443d Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Thu, 22 May 2025 21:18:53 -0300 Subject: [PATCH 1/2] Do not send DB_IPCE_LOAD_ASSEMBLY event --- src/coreclr/debug/di/process.cpp | 40 +++++++++------------- src/coreclr/debug/ee/debugger.cpp | 57 ------------------------------- src/coreclr/debug/ee/debugger.h | 3 -- src/coreclr/vm/appdomain.hpp | 1 - src/coreclr/vm/assembly.cpp | 13 ++----- src/coreclr/vm/dbginterface.h | 8 ----- 6 files changed, 19 insertions(+), 103 deletions(-) diff --git a/src/coreclr/debug/di/process.cpp b/src/coreclr/debug/di/process.cpp index 94f5d8d25864cb..4103ecbbb16b83 100644 --- a/src/coreclr/debug/di/process.cpp +++ b/src/coreclr/debug/di/process.cpp @@ -5078,6 +5078,23 @@ void CordbProcess::RawDispatchEvent( case DB_IPCE_LOAD_MODULE: { + LOG((LF_CORDB, LL_INFO100, + "RCET::HRCE: load assembly on thread %#x Asm:0x%08x AD:0x%08x \n", + dwVolatileThreadId, + VmPtrToCookie(pEvent->LoadModuleData.vmDomainAssembly), + VmPtrToCookie(pEvent->vmAppDomain))); + + _ASSERTE (pAppDomain != NULL); + + // Determine if this Assembly is cached. + CordbAssembly * pAssembly = pAppDomain->LookupOrCreateAssembly(pEvent->LoadModuleData.vmDomainAssembly); + _ASSERTE(pAssembly != NULL); // throws on error + + // If created, or have, an Assembly, notify callback. + { + PUBLIC_CALLBACK_IN_THIS_SCOPE(this, pLockHolder, pEvent); + hr = pCallback1->LoadAssembly(pAppDomain, pAssembly); + } _ASSERTE (pAppDomain != NULL); CordbModule * pModule = pAppDomain->LookupOrCreateModule(pEvent->LoadModuleData.vmDomainAssembly); @@ -5405,29 +5422,6 @@ void CordbProcess::RawDispatchEvent( break; - case DB_IPCE_LOAD_ASSEMBLY: - { - LOG((LF_CORDB, LL_INFO100, - "RCET::HRCE: load assembly on thread %#x Asm:0x%08x AD:0x%08x \n", - dwVolatileThreadId, - VmPtrToCookie(pEvent->AssemblyData.vmDomainAssembly), - VmPtrToCookie(pEvent->vmAppDomain))); - - _ASSERTE (pAppDomain != NULL); - - // Determine if this Assembly is cached. - CordbAssembly * pAssembly = pAppDomain->LookupOrCreateAssembly(pEvent->AssemblyData.vmDomainAssembly); - _ASSERTE(pAssembly != NULL); // throws on error - - // If created, or have, an Assembly, notify callback. - { - PUBLIC_CALLBACK_IN_THIS_SCOPE(this, pLockHolder, pEvent); - hr = pCallback1->LoadAssembly(pAppDomain, pAssembly); - } - } - - break; - case DB_IPCE_UNLOAD_ASSEMBLY: { LOG((LF_CORDB, LL_INFO100, "RCET::DRCE: unload assembly on thread %#x Asm:0x%x AD:0x%x\n", diff --git a/src/coreclr/debug/ee/debugger.cpp b/src/coreclr/debug/ee/debugger.cpp index 1da42283144c4f..b57e9b171358e6 100644 --- a/src/coreclr/debug/ee/debugger.cpp +++ b/src/coreclr/debug/ee/debugger.cpp @@ -9261,63 +9261,6 @@ void Debugger::SendCreateAppDomainEvent(AppDomain * pRuntimeAppDomain) } - -// -// LoadAssembly is called when a new Assembly gets loaded. -// -void Debugger::LoadAssembly(DomainAssembly * pDomainAssembly) -{ - CONTRACTL - { - MAY_DO_HELPER_THREAD_DUTY_THROWS_CONTRACT; - MAY_DO_HELPER_THREAD_DUTY_GC_TRIGGERS_CONTRACT; - } - CONTRACTL_END; - - if (CORDBUnrecoverableError(this)) - return; - - LOG((LF_CORDB, LL_INFO100, "D::LA: Load Assembly Asy:0x%p AD:0x%p which:%s\n", - pDomainAssembly, AppDomain::GetCurrentDomain(), pDomainAssembly->GetAssembly()->GetDebugName() )); - - if (!CORDebuggerAttached()) - { - return; - } - - Thread *pThread = g_pEEInterface->GetThread(); - SENDIPCEVENT_BEGIN(this, pThread) - - - if (CORDebuggerAttached()) - { - // Send a load assembly event to the Right Side. - DebuggerIPCEvent* ipce = m_pRCThread->GetIPCEventSendBuffer(); - InitIPCEvent(ipce, - DB_IPCE_LOAD_ASSEMBLY, - pThread, - AppDomain::GetCurrentDomain()); - - ipce->AssemblyData.vmDomainAssembly.SetRawPtr(pDomainAssembly); - - m_pRCThread->SendIPCEvent(); - } - else - { - LOG((LF_CORDB,LL_INFO1000, "D::LA: Skipping SendIPCEvent because RS detached.")); - } - - // Stop all Runtime threads - if (CORDebuggerAttached()) - { - TrapAllRuntimeThreads(); - } - - SENDIPCEVENT_END; -} - - - // // UnloadAssembly is called when a Runtime thread unloads an assembly. // diff --git a/src/coreclr/debug/ee/debugger.h b/src/coreclr/debug/ee/debugger.h index d13b6790e94b7d..10668a59a5dc00 100644 --- a/src/coreclr/debug/ee/debugger.h +++ b/src/coreclr/debug/ee/debugger.h @@ -2628,9 +2628,6 @@ class Debugger : public DebugInterface void SendCreateAppDomainEvent(AppDomain * pAppDomain); - // Notify the debugger that an assembly has been loaded - void LoadAssembly(DomainAssembly * pDomainAssembly); - // Notify the debugger that an assembly has been unloaded void UnloadAssembly(DomainAssembly * pDomainAssembly); diff --git a/src/coreclr/vm/appdomain.hpp b/src/coreclr/vm/appdomain.hpp index c6624b5fef470b..7c1ac90a1ab3c9 100644 --- a/src/coreclr/vm/appdomain.hpp +++ b/src/coreclr/vm/appdomain.hpp @@ -425,7 +425,6 @@ class LoadLevelLimiter final enum { - ATTACH_ASSEMBLY_LOAD = 0x1, ATTACH_MODULE_LOAD = 0x2, ATTACH_CLASS_LOAD = 0x4, diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 091a061ba5a863..0c76c01e4cfaeb 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -2369,7 +2369,7 @@ void Assembly::DeliverSyncEvents() SetShouldNotifyDebugger(); // Still work to do even if no debugger is attached. - NotifyDebuggerLoad(ATTACH_ASSEMBLY_LOAD, FALSE); + NotifyDebuggerLoad(ATTACH_MODULE_LOAD, FALSE); } #endif // DEBUGGING_SUPPORTED @@ -2492,16 +2492,7 @@ BOOL Assembly::NotifyDebuggerLoad(int flags, BOOL attaching) } // There is still work we need to do even when no debugger is attached. - if (flags & ATTACH_ASSEMBLY_LOAD) - { - if (ShouldNotifyDebugger()) - { - g_pDebugInterface->LoadAssembly(GetDomainAssembly()); - } - result = TRUE; - } - - if(this->ShouldNotifyDebugger()) + if(this->ShouldNotifyDebugger() && !(flags & ATTACH_MODULE_LOAD)) { result = result || this->GetModule()->NotifyDebuggerLoad(GetDomainAssembly(), flags, attaching); diff --git a/src/coreclr/vm/dbginterface.h b/src/coreclr/vm/dbginterface.h index ff8d8580f22c5d..79c7c93b5fec51 100644 --- a/src/coreclr/vm/dbginterface.h +++ b/src/coreclr/vm/dbginterface.h @@ -297,14 +297,6 @@ class DebugInterface virtual HRESULT UpdateAppDomainEntryInIPC (AppDomain *pAppDomain) = 0; - // Called when an assembly is being loaded into an AppDomain. - // This includes when a domain neutral assembly is loaded into a new AppDomain. - // This is called only when a debugger is attached, and will occur after the - // related AddAppDomainToIPCBlock call and before any LoadModule or - // LoadClass calls for this assembly. - virtual void LoadAssembly(DomainAssembly * pDomainAssembly) = 0; // the assembly being loaded - - // Called for all assemblies in an AppDomain when the AppDomain is unloaded. // This includes domain neutral assemblies that are also loaded into other domains. // This is called only when a debugger is attached, and will occur after all UnloadClass From fb9e13c93caec86a82c55d86dbe09da90c2a8225 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Tue, 15 Jul 2025 17:01:10 -0300 Subject: [PATCH 2/2] Update src/coreclr/debug/di/process.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/coreclr/debug/di/process.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/debug/di/process.cpp b/src/coreclr/debug/di/process.cpp index 0945fb7bdbc9a1..b9218b4845d721 100644 --- a/src/coreclr/debug/di/process.cpp +++ b/src/coreclr/debug/di/process.cpp @@ -5062,7 +5062,7 @@ void CordbProcess::RawDispatchEvent( case DB_IPCE_LOAD_MODULE: { LOG((LF_CORDB, LL_INFO100, - "RCET::HRCE: load assembly on thread %#x Asm:0x%08x AD:0x%08x \n", + "RCET::HRCE: load module (includes assembly loading) on thread %#x Asm:0x%08x AD:0x%08x \n", dwVolatileThreadId, VmPtrToCookie(pEvent->LoadModuleData.vmDomainAssembly), VmPtrToCookie(pEvent->vmAppDomain)));