Skip to content

Commit 5e8edc8

Browse files
Fix a set of minor DAC bugs I encountered recently (#100031)
In src/coreclr/debug/daccess/dacdbiimpl.cpp - If g_pDebugger is NULL, produce an error, or NULL result instead of an invalid memory access. - This caused problems when debugging with a debug version of the DAC In src/coreclr/debug/di/module.cpp - Avoid attempting to get the MapAddr if the number of entries in the map is 0, as it may not yet be fully initialized and attempting to call the GetMapAddr function may cause an ASSERT in debug/checked versions of the DAC In src/coreclr/utilcode/collections.cpp - If a CHashTable is not fully initialized, or is in an intermediate state, its possible for the linked list to have an infinite cycle. Tweak the iteration here under the DAC to stop - This is known to cause stack walking to loop infinitely in the debugger when debugging a runtime which has suspended at a non-safe point
1 parent de774ff commit 5e8edc8

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/coreclr/debug/daccess/dacdbiimpl.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5627,10 +5627,13 @@ void DacDbiInterfaceImpl::LookupEnCVersions(Module* pModule,
56275627
DebuggerJitInfo * pDJI = NULL;
56285628
EX_TRY_ALLOW_DATATARGET_MISSING_MEMORY
56295629
{
5630-
pDMI = g_pDebugger->GetOrCreateMethodInfo(pModule, mdMethod);
5631-
if (pDMI != NULL)
5630+
if (g_pDebugger != NULL)
56325631
{
5633-
pDJI = pDMI->FindJitInfo(pMD, CORDB_ADDRESS_TO_TADDR(pNativeStartAddress));
5632+
pDMI = g_pDebugger->GetOrCreateMethodInfo(pModule, mdMethod);
5633+
if (pDMI != NULL)
5634+
{
5635+
pDJI = pDMI->FindJitInfo(pMD, CORDB_ADDRESS_TO_TADDR(pNativeStartAddress));
5636+
}
56345637
}
56355638
}
56365639
EX_END_CATCH_ALLOW_DATATARGET_MISSING_MEMORY;
@@ -7479,6 +7482,10 @@ HRESULT DacDbiInterfaceImpl::GetDefinesBitField(ULONG32 *pDefines)
74797482
DD_ENTER_MAY_THROW;
74807483
if (pDefines == NULL)
74817484
return E_INVALIDARG;
7485+
7486+
if (g_pDebugger == NULL)
7487+
return CORDBG_E_NOTREADY;
7488+
74827489
*pDefines = g_pDebugger->m_defines;
74837490
return S_OK;
74847491
}
@@ -7488,6 +7495,10 @@ HRESULT DacDbiInterfaceImpl::GetMDStructuresVersion(ULONG32* pMDStructuresVersio
74887495
DD_ENTER_MAY_THROW;
74897496
if (pMDStructuresVersion == NULL)
74907497
return E_INVALIDARG;
7498+
7499+
if (g_pDebugger == NULL)
7500+
return CORDBG_E_NOTREADY;
7501+
74917502
*pMDStructuresVersion = g_pDebugger->m_mdDataStructureVersion;
74927503
return S_OK;
74937504
}

src/coreclr/debug/di/module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,12 +4250,12 @@ HRESULT CordbNativeCode::GetILToNativeMapping(ULONG32 cMap,
42504250
LoadNativeInfo();
42514251

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

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

src/coreclr/utilcode/collections.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ BYTE *CHashTable::FindNextEntry( // The next entry, or0 for end of list.
268268
if (psSrch->iNext != UINT32_MAX)
269269
{
270270
psEntry = EntryPtr(psSrch->iNext);
271+
#if DACCESS_COMPILE
272+
// If there is a simple infinite loop in the linked list
273+
// If more complex forms of infinite loops are present, this code may need to be adjusted to handle an arbitrary cycle.
274+
if (psEntry->iNext == psSrch->iNext)
275+
return NULL;
276+
#endif
271277
psSrch->iNext = psEntry->iNext;
272278
return ((BYTE *) psEntry);
273279
}

0 commit comments

Comments
 (0)