Skip to content

Commit

Permalink
Fix SOS !dumpmt -md command (#105575)
Browse files Browse the repository at this point in the history
* Fix SOS !dumpmt -md command

The new virtual method slot enumerator failed if any of the Precode slot values were not in
the dump. There are usually 2 or so that are invalid/not in dump but that should not stop/fail
the new enumeration DAC API.

Part of this is to make MethodTable::GetMethodDescForSlot_NoThrow not throw a read exception and
return a null MD.

* Code review feedback - move CATCH to request.cpp
  • Loading branch information
mikem8361 committed Jul 26, 2024
1 parent 24367aa commit b2b0db0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
33 changes: 22 additions & 11 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,20 +490,31 @@ ClrDataAccess::GetMethodTableSlotEnumerator(CLRDATA_ADDRESS mt, ISOSMethodEnum *

HRESULT DacMethodTableSlotEnumerator::Init(PTR_MethodTable mTable)
{
unsigned int slot = 0;

WORD numVtableSlots = mTable->GetNumVtableSlots();
while (slot < numVtableSlots)
for (WORD slot = 0; slot < numVtableSlots; slot++)
{
MethodDesc* pMD = mTable->GetMethodDescForSlot_NoThrow(slot);
SOSMethodData methodData = {0};
methodData.MethodDesc = HOST_CDADDR(pMD);
methodData.Entrypoint = mTable->GetSlot(slot);
methodData.DefininingMethodTable = PTR_CDADDR(pMD->GetMethodTable());
methodData.DefiningModule = HOST_CDADDR(pMD->GetModule());
methodData.Token = pMD->GetMemberDef();
SOSMethodData methodData = {0, 0, 0, 0, 0, 0};
MethodDesc* pMD = nullptr;

EX_TRY
{
pMD = mTable->GetMethodDescForSlot_NoThrow(slot);
}
EX_CATCH
{
}
EX_END_CATCH(SwallowAllExceptions)

methodData.Slot = slot++;
if (pMD != nullptr)
{
methodData.MethodDesc = HOST_CDADDR(pMD);
methodData.DefininingMethodTable = PTR_CDADDR(pMD->GetMethodTable());
methodData.DefiningModule = HOST_CDADDR(pMD->GetModule());
methodData.Token = pMD->GetMemberDef();
}

methodData.Entrypoint = mTable->GetSlot(slot);
methodData.Slot = slot;

if (!mMethods.Add(methodData))
return E_OUTOFMEMORY;
Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/vm/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2624,7 +2624,7 @@ MethodDesc* MethodDesc::GetMethodDescFromStubAddr(PCODE addr, BOOL fSpeculative
}
CONTRACT_END;

MethodDesc * pMD = NULL;
MethodDesc* pMD = NULL;

// Otherwise this must be some kind of precode
//
Expand All @@ -2633,10 +2633,9 @@ MethodDesc* MethodDesc::GetMethodDescFromStubAddr(PCODE addr, BOOL fSpeculative
if (pPrecode != NULL)
{
pMD = pPrecode->GetMethodDesc(fSpeculative);
RETURN(pMD);
}

RETURN(NULL); // Not found
RETURN(pMD);
}

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

0 comments on commit b2b0db0

Please sign in to comment.