From 5eb783da53a02a5b8889fd3fa5e05525837b52fb Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 12 Sep 2024 13:45:17 -0700 Subject: [PATCH] Remove DebuggerModule::Get/SetPrimaryModule - always itself --- src/coreclr/debug/ee/debugger.h | 35 ++----------- src/coreclr/debug/ee/debugger.inl | 42 +--------------- src/coreclr/debug/ee/debuggermodule.cpp | 66 ------------------------- src/coreclr/debug/ee/functioninfo.cpp | 12 ++--- 4 files changed, 8 insertions(+), 147 deletions(-) diff --git a/src/coreclr/debug/ee/debugger.h b/src/coreclr/debug/ee/debugger.h index 48f0e23e6228c..cf08d50017bd0 100644 --- a/src/coreclr/debug/ee/debugger.h +++ b/src/coreclr/debug/ee/debugger.h @@ -469,43 +469,17 @@ class DebuggerModule Module * GetRuntimeModule(); - - // (8/12/2002) - // Currently we create a new DebuggerModules for each appdomain a shared - // module lives in. We then pretend there aren't any shared modules. - // This is bad. We need to move away from this. - // Once we stop lying, then every module will be it's own PrimaryModule. :) - // - // Currently, Module* is 1:n w/ DebuggerModule. - // We add a notion of PrimaryModule so that: - // Module* is 1:1 w/ DebuggerModule::GetPrimaryModule(); - // This should help transition towards exposing shared modules. - // If the Runtime module is shared, then this gives a common DM. - // If the runtime module is not shared, then this is an identity function. - // - // The runtime has the notion of "DomainAssembly", which is 1:1 with DebuggerModule - // and thus 1:1 with CordbModule. The CordbModule hash table on the RS now uses - // the DomainAssembly as the key instead of DebuggerModule. This is a temporary - // workaround to facilitate the removal of DebuggerModule. - // - DebuggerModule * GetPrimaryModule(); DomainAssembly * GetDomainAssembly() { LIMITED_METHOD_DAC_CONTRACT; return m_pRuntimeDomainAssembly; } - // Called by DebuggerModuleTable to set our primary module - void SetPrimaryModule(DebuggerModule * pPrimary); - void SetCanChangeJitFlags(bool fCanChangeJitFlags); private: BOOL m_enableClassLoadCallbacks; - // First step in moving away from hiding shared modules. - DebuggerModule* m_pPrimaryModule; - PTR_Module m_pRuntimeModule; PTR_DomainAssembly m_pRuntimeDomainAssembly; @@ -513,13 +487,9 @@ class DebuggerModule bool m_fHasOptimizedCode; - void PickPrimaryModule(); - // Can we change jit flags on the module? // This is true during the Module creation bool m_fCanChangeJitFlags; - - }; /* ------------------------------------------------------------------------ * @@ -1109,12 +1079,13 @@ class DebuggerMethodInfo // correct IL offset if this code happens to be instrumented ULONG32 TranslateToInstIL(const InstrumentedILOffsetMapping * pMapping, ULONG32 offOrig, bool fOrigToInst); - +private: // We don't always have a debugger module. (Ex: we're tracking debug info, // but no debugger's attached). So this may return NULL alot. // If we can, we should use the RuntimeModule when ever possible. - DebuggerModule* GetPrimaryModule(); + DebuggerModule* GetModule(); +public: // We always have a runtime module. Module * GetRuntimeModule(); diff --git a/src/coreclr/debug/ee/debugger.inl b/src/coreclr/debug/ee/debugger.inl index fa613cc625e53..d877b9a396632 100644 --- a/src/coreclr/debug/ee/debugger.inl +++ b/src/coreclr/debug/ee/debugger.inl @@ -55,7 +55,6 @@ inline DebuggerModule::DebuggerModule(Module * pRuntimeModule, DomainAssembly * pDomainAssembly, AppDomain * pAppDomain) : m_enableClassLoadCallbacks(FALSE), - m_pPrimaryModule(NULL), m_pRuntimeModule(pRuntimeModule), m_pRuntimeDomainAssembly(pDomainAssembly), m_pAppDomain(pAppDomain) @@ -63,11 +62,6 @@ inline DebuggerModule::DebuggerModule(Module * pRuntimeModule, LOG((LF_CORDB,LL_INFO10000, "DM::DM this:0x%x Module:0x%x DF:0x%x AD:0x%x\n", this, pRuntimeModule, pDomainAssembly, pAppDomain)); - // Pick a primary module. - // Arguably, this could be in DebuggerModuleTable::AddModule - PickPrimaryModule(); - - // Do we have any optimized code? DWORD dwDebugBits = pRuntimeModule->GetDebuggerInfoBits(); m_fHasOptimizedCode = CORDebuggerAllowJITOpts(dwDebugBits); @@ -90,7 +84,7 @@ inline DebuggerModule::DebuggerModule(Module * pRuntimeModule, inline bool DebuggerModule::HasAnyOptimizedCode() { LIMITED_METHOD_CONTRACT; - Module * pModule = this->GetPrimaryModule()->GetRuntimeModule(); + Module * pModule = GetRuntimeModule(); DWORD dwDebugBits = pModule->GetDebuggerInfoBits(); return CORDebuggerAllowJITOpts(dwDebugBits); } @@ -142,40 +136,6 @@ inline Module * DebuggerModule::GetRuntimeModule() return m_pRuntimeModule; } -//----------------------------------------------------------------------------- -// (8/12/2002) -// Currently we create a new DebuggerModules for each appdomain a shared -// module lives in. We then pretend there aren't any shared modules. -// This is bad. We need to move away from this. -// Once we stop lying, then every module will be it's own PrimaryModule. :) -// -// Currently, Module* is 1:n w/ DebuggerModule. -// We add a notion of PrimaryModule so that: -// Module* is 1:1 w/ DebuggerModule::GetPrimaryModule(); -// This should help transition towards exposing shared modules. -// If the Runtime module is shared, then this gives a common DM. -// If the runtime module is not shared, then this is an identity function. -// -//----------------------------------------------------------------------------- -inline DebuggerModule * DebuggerModule::GetPrimaryModule() -{ - _ASSERTE(m_pPrimaryModule != NULL); - return m_pPrimaryModule; -} - -//----------------------------------------------------------------------------- -// This is called by DebuggerModuleTable to set our primary module. -//----------------------------------------------------------------------------- -inline void DebuggerModule::SetPrimaryModule(DebuggerModule * pPrimary) -{ - _ASSERTE(pPrimary != NULL); - // Our primary module must by definition refer to the same runtime module as us - _ASSERTE(pPrimary->GetRuntimeModule() == this->GetRuntimeModule()); - - LOG((LF_CORDB, LL_EVERYTHING, "DM::SetPrimaryModule - this=%p, pPrimary=%p\n", this, pPrimary)); - m_pPrimaryModule = pPrimary; -} - inline DebuggerEval * FuncEvalFrame::GetDebuggerEval() { LIMITED_METHOD_DAC_CONTRACT; diff --git a/src/coreclr/debug/ee/debuggermodule.cpp b/src/coreclr/debug/ee/debuggermodule.cpp index 06b7c7b7f149e..8b81bfd0474eb 100644 --- a/src/coreclr/debug/ee/debuggermodule.cpp +++ b/src/coreclr/debug/ee/debuggermodule.cpp @@ -22,69 +22,6 @@ * Debugger Module routines * ------------------------------------------------------------------------ */ -// (8/12/2002) -// We need to stop lying to the debugger about not sharing Modules. -// Primary Modules allow a transition to that. Once we stop lying, -// then all modules will be their own Primary. -// -// Select the primary module. -// Primary Modules are selected DebuggerModules that map 1:1 w/ Module*. -// If the runtime module is not shared, then we're our own Primary Module. -// If the Runtime module is shared, the primary module is some specific instance. -// Note that a domain-neutral module can be loaded into multiple domains without -// being loaded into the default domain, and so there is no "primary module" as far -// as the CLR is concerned - we just pick any one and call it primary. -void DebuggerModule::PickPrimaryModule() -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - Debugger::DebuggerDataLockHolder ch(g_pDebugger); - - LOG((LF_CORDB, LL_INFO100000, "DM::PickPrimaryModule, this=0x%p\n", this)); - - // We're our own primary module, unless something else proves otherwise. - // Note that we should be able to skip all of this if this module is not domain neutral - m_pPrimaryModule = this; - - // This should be thread safe because our creation for the DebuggerModules - // are serialized. - - // Lookup our Runtime Module. If it's already in there, - // then - DebuggerModuleTable * pTable = g_pDebugger->GetModuleTable(); - - // If the table doesn't exist yet, then we must be a primary module. - if (pTable == NULL) - { - LOG((LF_CORDB, LL_INFO100000, "DM::PickPrimaryModule, this=0x%p, table not created yet\n", this)); - return; - } - - // Look through existing module list to find a common primary DebuggerModule - // for the given EE Module. We don't know what order we'll traverse in. - - HASHFIND f; - for (DebuggerModule * m = pTable->GetFirstModule(&f); - m != NULL; - m = pTable->GetNextModule(&f)) - { - - if (m->GetRuntimeModule() == this->GetRuntimeModule()) - { - // Make sure we're picking another primary module. - _ASSERTE(m->GetPrimaryModule() != m); - } - } // end for - - // If we got here, then this instance is a Primary Module. - LOG((LF_CORDB, LL_INFO100000, "DM::PickPrimaryModule, this=%p is first, primary.\n", this)); -} - void DebuggerModule::SetCanChangeJitFlags(bool fCanChangeJitFlags) { m_fCanChangeJitFlags = fCanChangeJitFlags; @@ -218,9 +155,6 @@ void DebuggerModuleTable::AddModule(DebuggerModule *pModule) } pEntry->module = pModule; - - // Don't need to update the primary module since it was set when we created the module. - _ASSERTE(pModule->GetPrimaryModule() != NULL); } //----------------------------------------------------------------------------- diff --git a/src/coreclr/debug/ee/functioninfo.cpp b/src/coreclr/debug/ee/functioninfo.cpp index d1765d176fb39..8babd5ba4431c 100644 --- a/src/coreclr/debug/ee/functioninfo.cpp +++ b/src/coreclr/debug/ee/functioninfo.cpp @@ -1432,7 +1432,7 @@ DebuggerMethodInfo::DebuggerMethodInfo(Module *module, mdMethodDef token) : _ASSERTE(g_pDebugger->HasDebuggerDataLock()); - DebuggerModule * pModule = GetPrimaryModule(); + DebuggerModule * pModule = GetModule(); m_fJMCStatus = false; @@ -1448,9 +1448,9 @@ DebuggerMethodInfo::DebuggerMethodInfo(Module *module, mdMethodDef token) : /****************************************************************************** - * Get the primary debugger module for this DMI. This is 1:1 w/ an EE Module. + * Get the debugger module for this DMI. This is 1:1 w/ an EE Module. ******************************************************************************/ -DebuggerModule* DebuggerMethodInfo::GetPrimaryModule() +DebuggerModule* DebuggerMethodInfo::GetModule() { CONTRACTL { @@ -1478,11 +1478,7 @@ DebuggerModule* DebuggerMethodInfo::GetPrimaryModule() return NULL; } - // Only give back primary modules... - DebuggerModule * p2 = pModule->GetPrimaryModule(); - _ASSERTE(p2 != NULL); - - return p2; + return pModule; } /******************************************************************************