Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove DebuggerModule::Get/SetPrimaryModule - always itself #107767

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 3 additions & 32 deletions src/coreclr/debug/ee/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,57 +469,27 @@ class DebuggerModule

Module * GetRuntimeModule();


// <TODO> (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.
// </TODO>
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;

AppDomain* m_pAppDomain;

bool m_fHasOptimizedCode;

void PickPrimaryModule();

// Can we change jit flags on the module?
// This is true during the Module creation
bool m_fCanChangeJitFlags;


};

/* ------------------------------------------------------------------------ *
Expand Down Expand Up @@ -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();

Expand Down
42 changes: 1 addition & 41 deletions src/coreclr/debug/ee/debugger.inl
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,13 @@ inline DebuggerModule::DebuggerModule(Module * pRuntimeModule,
DomainAssembly * pDomainAssembly,
AppDomain * pAppDomain) :
m_enableClassLoadCallbacks(FALSE),
m_pPrimaryModule(NULL),
m_pRuntimeModule(pRuntimeModule),
m_pRuntimeDomainAssembly(pDomainAssembly),
m_pAppDomain(pAppDomain)
{
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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -142,40 +136,6 @@ inline Module * DebuggerModule::GetRuntimeModule()
return m_pRuntimeModule;
}

//-----------------------------------------------------------------------------
// <TODO> (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.
// </TODO>
//-----------------------------------------------------------------------------
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;
Expand Down
66 changes: 0 additions & 66 deletions src/coreclr/debug/ee/debuggermodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,6 @@
* Debugger Module routines
* ------------------------------------------------------------------------ */

// <TODO> (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.
// </TODO>
// 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;
Expand Down Expand Up @@ -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);
}

//-----------------------------------------------------------------------------
Expand Down
12 changes: 4 additions & 8 deletions src/coreclr/debug/ee/functioninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ DebuggerMethodInfo::DebuggerMethodInfo(Module *module, mdMethodDef token) :

_ASSERTE(g_pDebugger->HasDebuggerDataLock());

DebuggerModule * pModule = GetPrimaryModule();
DebuggerModule * pModule = GetModule();

m_fJMCStatus = false;

Expand All @@ -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
{
Expand Down Expand Up @@ -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;
}

/******************************************************************************
Expand Down
Loading