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

[release/8.0-staging] Fix a set of minor DAC bugs I encountered recently #104919

Merged
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
17 changes: 14 additions & 3 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5650,10 +5650,13 @@ void DacDbiInterfaceImpl::LookupEnCVersions(Module* pModule,
DebuggerJitInfo * pDJI = NULL;
EX_TRY_ALLOW_DATATARGET_MISSING_MEMORY
{
pDMI = g_pDebugger->GetOrCreateMethodInfo(pModule, mdMethod);
if (pDMI != NULL)
if (g_pDebugger != NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we get to this state? This gets allocated in EEStartup. Is the DBI getting called super early on? Feels like this is something that shouldn't happen. Data target missing memory like the catch gets should be the main reason to not have it (or init error)

Copy link
Contributor

@leculver leculver Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good overall cleanup for defensive coding. To be clear for this PR, I did not encounter the dacdbiimpl.cpp change with a real world example. It would be fine with me to not backport this particular fix and just leave the fix shipping for v.next. It's only the collections.cpp issue that I'd like to backport since I ran into it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hoyosjs I hit those particular issues when debugging CLR startup scenarios. ... I spend a lot of time debugging the runtime startup path, and I regularly was hitting DAC crashes when trying to diagnose the startup path. Typically, the DAC isn't super useful at that point, but its really annoying to be unable to step through the various process creation paths.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, yes, the DBI is commonly called this early in the newer Windbg UI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I withdraw my comment. :) If this happens in CLR startup I do recommend backporting this part to .net 8 as well. We deal with that often in servicing, watson and elsewhere. Even if most CLR devs will be on .Net 9, it would be good to get ahead of this issue for our long term servicing release.

{
pDJI = pDMI->FindJitInfo(pMD, CORDB_ADDRESS_TO_TADDR(pNativeStartAddress));
pDMI = g_pDebugger->GetOrCreateMethodInfo(pModule, mdMethod);
if (pDMI != NULL)
{
pDJI = pDMI->FindJitInfo(pMD, CORDB_ADDRESS_TO_TADDR(pNativeStartAddress));
}
}
}
EX_END_CATCH_ALLOW_DATATARGET_MISSING_MEMORY;
Expand Down Expand Up @@ -7512,6 +7515,10 @@ HRESULT DacDbiInterfaceImpl::GetDefinesBitField(ULONG32 *pDefines)
DD_ENTER_MAY_THROW;
if (pDefines == NULL)
return E_INVALIDARG;

if (g_pDebugger == NULL)
return CORDBG_E_NOTREADY;

*pDefines = g_pDebugger->m_defines;
return S_OK;
}
Expand All @@ -7521,6 +7528,10 @@ HRESULT DacDbiInterfaceImpl::GetMDStructuresVersion(ULONG32* pMDStructuresVersio
DD_ENTER_MAY_THROW;
if (pMDStructuresVersion == NULL)
return E_INVALIDARG;

if (g_pDebugger == NULL)
return CORDBG_E_NOTREADY;

*pMDStructuresVersion = g_pDebugger->m_mdDataStructureVersion;
return S_OK;
}
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/debug/di/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4250,12 +4250,12 @@ HRESULT CordbNativeCode::GetILToNativeMapping(ULONG32 cMap,
LoadNativeInfo();

SequencePoints * pSeqPts = GetSequencePoints();
DebuggerILToNativeMap * rgMapInt = pSeqPts->GetMapAddr();
ULONG32 cMapIntCount = pSeqPts->GetEntryCount();

// If they gave us space to copy into...
if (map != NULL)
if (map != NULL && cMapIntCount != 0)
{
DebuggerILToNativeMap * rgMapInt = pSeqPts->GetMapAddr();
// Only copy as much as either they gave us or we have to copy.
ULONG32 cMapToCopy = min(cMap, cMapIntCount);

Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/utilcode/collections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ BYTE *CHashTable::FindNextEntry( // The next entry, or0 for end of list.
if (psSrch->iNext != UINT32_MAX)
{
psEntry = EntryPtr(psSrch->iNext);
#if DACCESS_COMPILE
// If there is a simple infinite loop in the linked list
// If more complex forms of infinite loops are present, this code may need to be adjusted to handle an arbitrary cycle.
if (psEntry->iNext == psSrch->iNext)
return NULL;
#endif
psSrch->iNext = psEntry->iNext;
return ((BYTE *) psEntry);
}
Expand Down
Loading