Skip to content

Commit

Permalink
Add GCDescs in front of MethodTable to dumps (#72658)
Browse files Browse the repository at this point in the history
* Add GCDescs in front of MethodTable to dumps

* Make DacValidateMethodTable more bullet proof by DAC'ifing the MethodTable pointer (using PTR_MethodTable). On Windows,
SEH can catch the native AV exceptions but on Linux/MacOS this can crash lldb/SOS on invalid MT addresses.

This will also help with eestack/dumpstack crashing lldb also.
  • Loading branch information
mikem8361 authored Jul 22, 2022
1 parent 4cadf9a commit 20dd6ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ BOOL DacValidateEEClass(EEClass *pEEClass)

}

BOOL DacValidateMethodTable(MethodTable *pMT, BOOL &bIsFree)
BOOL DacValidateMethodTable(PTR_MethodTable pMT, BOOL &bIsFree)
{
// Verify things are right.
BOOL retval = FALSE;
Expand Down Expand Up @@ -440,7 +440,7 @@ ClrDataAccess::GetMethodTableSlot(CLRDATA_ADDRESS mt, unsigned int slot, CLRDATA

SOSDacEnter();

MethodTable* mTable = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable mTable = PTR_MethodTable(TO_TADDR(mt));
BOOL bIsFree = FALSE;
if (!DacValidateMethodTable(mTable, bIsFree))
{
Expand Down Expand Up @@ -1465,7 +1465,7 @@ ClrDataAccess::GetObjectStringData(CLRDATA_ADDRESS obj, unsigned int count, _Ino
SOSDacEnter();

TADDR mtTADDR = DACGetMethodTableFromObjectPointer(TO_TADDR(obj), m_pTarget);
MethodTable *mt = PTR_MethodTable(mtTADDR);
PTR_MethodTable mt = PTR_MethodTable(mtTADDR);

// Object must be a string
BOOL bFree = FALSE;
Expand Down Expand Up @@ -1515,7 +1515,7 @@ ClrDataAccess::GetObjectClassName(CLRDATA_ADDRESS obj, unsigned int count, _Inou

// Don't turn the Object into a pointer, it is too costly on
// scans of the gc heap.
MethodTable *mt = NULL;
PTR_MethodTable mt = NULL;
TADDR mtTADDR = DACGetMethodTableFromObjectPointer(CLRDATA_ADDRESS_TO_TADDR(obj), m_pTarget);
if (mtTADDR != NULL)
mt = PTR_MethodTable(mtTADDR);
Expand Down Expand Up @@ -1732,7 +1732,7 @@ ClrDataAccess::GetMethodTableData(CLRDATA_ADDRESS mt, struct DacpMethodTableData

SOSDacEnter();

MethodTable* pMT = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable pMT = PTR_MethodTable(TO_TADDR(mt));
BOOL bIsFree = FALSE;
if (!DacValidateMethodTable(pMT, bIsFree))
{
Expand Down Expand Up @@ -1775,7 +1775,7 @@ ClrDataAccess::GetMethodTableName(CLRDATA_ADDRESS mt, unsigned int count, _Inout

SOSDacEnter();

MethodTable *pMT = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable pMT = PTR_MethodTable(TO_TADDR(mt));
BOOL free = FALSE;

if (mt == HOST_CDADDR(g_pFreeObjectMethodTable))
Expand Down Expand Up @@ -1936,7 +1936,7 @@ ClrDataAccess::GetMethodTableFieldData(CLRDATA_ADDRESS mt, struct DacpMethodTabl

SOSDacEnter();

MethodTable* pMT = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable pMT = PTR_MethodTable(TO_TADDR(mt));
BOOL bIsFree = FALSE;
if (!pMT || !DacValidateMethodTable(pMT, bIsFree))
{
Expand Down Expand Up @@ -1966,7 +1966,7 @@ ClrDataAccess::GetMethodTableCollectibleData(CLRDATA_ADDRESS mt, struct DacpMeth

SOSDacEnter();

MethodTable* pMT = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable pMT = PTR_MethodTable(TO_TADDR(mt));
BOOL bIsFree = FALSE;
if (!pMT || !DacValidateMethodTable(pMT, bIsFree))
{
Expand All @@ -1993,7 +1993,7 @@ ClrDataAccess::GetMethodTableTransparencyData(CLRDATA_ADDRESS mt, struct DacpMet

SOSDacEnter();

MethodTable *pMT = PTR_MethodTable(TO_TADDR(mt));
PTR_MethodTable pMT = PTR_MethodTable(TO_TADDR(mt));
BOOL bIsFree = FALSE;
if (!DacValidateMethodTable(pMT, bIsFree))
{
Expand Down Expand Up @@ -2177,7 +2177,7 @@ ClrDataAccess::GetObjectData(CLRDATA_ADDRESS addr, struct DacpObjectData *object
hr = E_INVALIDARG;

BOOL bFree = FALSE;
MethodTable *mt = NULL;
PTR_MethodTable mt = NULL;
if (SUCCEEDED(hr))
{
mt = PTR_MethodTable(mtTADDR);
Expand Down Expand Up @@ -5125,7 +5125,7 @@ HRESULT ClrDataAccess::IsTrackedType(
hr = E_INVALIDARG;

BOOL bFree = FALSE;
MethodTable *mt = NULL;
PTR_MethodTable mt = NULL;
if (SUCCEEDED(hr))
{
mt = PTR_MethodTable(mtTADDR);
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/vm/methodtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7835,6 +7835,16 @@ MethodTable::EnumMemoryRegions(CLRDataEnumMemoryFlags flags)
DWORD size = GetEndOffsetOfOptionalMembers();
DacEnumMemoryRegion(dac_cast<TADDR>(this), size);

// Make sure the GCDescs are added to the dump
if (ContainsPointers())
{
PTR_CGCDesc gcdesc = CGCDesc::GetCGCDescFromMT(this);
size_t size = gcdesc->GetSize();
// Manually calculate the start of the GCDescs because CGCDesc::GetStartOfGCData() isn't DAC'ified.
TADDR gcdescStart = dac_cast<TADDR>(this) - size;
DacEnumMemoryRegion(gcdescStart, size);
}

if (!IsCanonicalMethodTable())
{
PTR_MethodTable pMTCanonical = GetCanonicalMethodTable();
Expand Down

0 comments on commit 20dd6ea

Please sign in to comment.