Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,19 @@ class AsmOffsets

#if TARGET_64BIT
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x8;
public const int SIZEOF__StackFrameIterator = 0x358;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x33A;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x350;
public const int SIZEOF__StackFrameIterator = 0x150;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x132;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x148;
#elif TARGET_X86
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
public const int SIZEOF__StackFrameIterator = 0x3c4;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x3b2;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x3c0;
#else // TARGET_64BIT
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
public const int SIZEOF__StackFrameIterator = 0x2c8;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x2b6;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x2c4;
public const int SIZEOF__StackFrameIterator = 0xc4;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0xb2;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0xc0;
#endif // TARGET_64BIT

#else // DEBUG
Expand Down Expand Up @@ -106,14 +111,19 @@ class AsmOffsets

#if TARGET_64BIT
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x8;
public const int SIZEOF__StackFrameIterator = 0x350;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x332;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x348;
public const int SIZEOF__StackFrameIterator = 0x148;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x12a;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x140;
#elif TARGET_X86
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
public const int SIZEOF__StackFrameIterator = 0x3bc;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x3aa;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x3b8;
#else // TARGET_64BIT
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
public const int SIZEOF__StackFrameIterator = 0x2c0;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x2ae;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x2bc;
public const int SIZEOF__StackFrameIterator = 0xbc;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0xaa;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0xb8;
#endif // TARGET_64BIT

#endif // DEBUG
Expand Down Expand Up @@ -164,7 +174,7 @@ class AsmOffsets

#if TARGET_64BIT
public const int SIZEOF__EHEnum = 0x20;
public const int OFFSETOF__StackFrameIterator__m_pRegDisplay = 0x228;
public const int OFFSETOF__StackFrameIterator__m_pRegDisplay = 0x20;
public const int OFFSETOF__ExInfo__m_pPrevExInfo = 0;
public const int OFFSETOF__ExInfo__m_pExContext = 0xa8;
public const int OFFSETOF__ExInfo__m_exception = 0xb0;
Expand All @@ -175,7 +185,7 @@ class AsmOffsets
public const int OFFSETOF__ExInfo__m_notifyDebuggerSP = OFFSETOF__ExInfo__m_frameIter + SIZEOF__StackFrameIterator;
#else // TARGET_64BIT
public const int SIZEOF__EHEnum = 0x10;
public const int OFFSETOF__StackFrameIterator__m_pRegDisplay = 0x218;
public const int OFFSETOF__StackFrameIterator__m_pRegDisplay = 0x14;
public const int OFFSETOF__ExInfo__m_pPrevExInfo = 0;
public const int OFFSETOF__ExInfo__m_pExContext = 0x5c;
public const int OFFSETOF__ExInfo__m_exception = 0x60;
Expand Down Expand Up @@ -224,7 +234,7 @@ class AsmOffsets
static_assert_no_msg(offsetof(ExInfo, m_idxCurClause) == OFFSETOF__ExInfo__m_idxCurClause);
static_assert_no_msg(offsetof(ExInfo, m_frameIter) == OFFSETOF__ExInfo__m_frameIter);
static_assert_no_msg(offsetof(ExInfo, m_notifyDebuggerSP) == OFFSETOF__ExInfo__m_notifyDebuggerSP);
#endif
#endif

}
#if __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/ee/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5938,7 +5938,7 @@ bool DebuggerStepper::TrapStep(ControllerStackInfo *info, bool in)
#ifdef TARGET_X86
LOG((LF_CORDB,LL_INFO1000, "GetJitInfo for pc = 0x%x (addr of "
"that value:0x%x)\n", (const BYTE*)(GetControlPC(&info->m_activeFrame.registers)),
info->m_activeFrame.registers.PCTAddr));
GetRegdisplayPCTAddr(&info->m_activeFrame.registers)));
#endif

// Note: we used to pass in the IP from the active frame to GetJitInfo, but there seems to be no value in that, and
Expand Down
4 changes: 1 addition & 3 deletions src/coreclr/debug/ee/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16858,21 +16858,19 @@ void FuncEvalFrame::UpdateRegDisplay_Impl(const PREGDISPLAY pRD, bool updateFloa
pRD->SetEcxLocation(&(pDE->m_context.Ecx));
pRD->SetEaxLocation(&(pDE->m_context.Eax));
pRD->SetEbpLocation(&(pDE->m_context.Ebp));
pRD->PCTAddr = GetReturnAddressPtr();
SetRegdisplayPCTAddr(pRD, GetReturnAddressPtr());

#ifdef FEATURE_EH_FUNCLETS

pRD->IsCallerContextValid = FALSE;
pRD->IsCallerSPValid = FALSE; // Don't add usage of this field. This is only temporary.

pRD->pCurrentContext->Eip = *PTR_PCODE(pRD->PCTAddr);
pRD->pCurrentContext->Esp = (DWORD)GetSP(&pDE->m_context);

SyncRegDisplayToCurrentContext(pRD);

#else // FEATURE_EH_FUNCLETS

pRD->ControlPC = *PTR_PCODE(pRD->PCTAddr);
pRD->SP = (DWORD)GetSP(&pDE->m_context);

#endif // FEATURE_EH_FUNCLETS
Expand Down
57 changes: 9 additions & 48 deletions src/coreclr/inc/eetwain.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ typedef void (*GCEnumCallback)(
DAC_ARG(DacSlotLocation loc) // where the reference came from
);

/******************************************************************************
The stackwalker maintains some state on behalf of ICodeManager.
*/

const int CODEMAN_STATE_SIZE = 512;

struct CodeManState
{
DWORD dwIsSet; // Is set to 0 by the stackwalk as appropriate
BYTE stateBuf[CODEMAN_STATE_SIZE];
};

/******************************************************************************
These flags are used by some functions, although not all combinations might
make sense for all functions.
Expand Down Expand Up @@ -169,7 +157,6 @@ virtual void FixContext(ContextType ctxType,
DWORD dwRelOffset,
DWORD nestingLevel,
OBJECTREF thrownObject,
CodeManState *pState,
size_t ** ppShadowSP, // OUT
size_t ** ppEndRegion) = 0; // OUT
#endif // !FEATURE_EH_FUNCLETS
Expand All @@ -183,8 +170,7 @@ virtual void FixContext(ContextType ctxType,
virtual TADDR GetAmbientSP(PREGDISPLAY pContext,
EECodeInfo *pCodeInfo,
DWORD dwRelOffset,
DWORD nestingLevel,
CodeManState *pState) = 0;
DWORD nestingLevel) = 0;
#endif // TARGET_X86

/*
Expand All @@ -203,8 +189,7 @@ virtual ULONG32 GetStackParameterSize(EECodeInfo* pCodeInfo) = 0;
*/
virtual bool UnwindStackFrame(PREGDISPLAY pRD,
EECodeInfo *pCodeInfo,
unsigned flags,
CodeManState *pState) = 0;
unsigned flags) = 0;

#ifdef FEATURE_EH_FUNCLETS
virtual void EnsureCallerContextIsValid(PREGDISPLAY pRD, EECodeInfo * pCodeInfo = NULL, unsigned flags = 0) = 0;
Expand Down Expand Up @@ -265,8 +250,7 @@ virtual GenericParamContextType GetParamContextType(PREGDISPLAY pContext,
*/
virtual void * GetGSCookieAddr(PREGDISPLAY pContext,
EECodeInfo * pCodeInfo,
unsigned flags,
CodeManState * pState) = 0;
unsigned flags) = 0;

#ifndef USE_GC_INFO_DECODER
/*
Expand Down Expand Up @@ -378,7 +362,6 @@ void FixContext(ContextType ctxType,
DWORD dwRelOffset,
DWORD nestingLevel,
OBJECTREF thrownObject,
CodeManState *pState,
size_t ** ppShadowSP, // OUT
size_t ** ppEndRegion); // OUT
#endif // !FEATURE_EH_FUNCLETS
Expand All @@ -393,8 +376,7 @@ virtual
TADDR GetAmbientSP(PREGDISPLAY pContext,
EECodeInfo *pCodeInfo,
DWORD dwRelOffset,
DWORD nestingLevel,
CodeManState *pState);
DWORD nestingLevel);
#endif // TARGET_X86

/*
Expand All @@ -416,8 +398,7 @@ virtual
bool UnwindStackFrame(
PREGDISPLAY pRD,
EECodeInfo *pCodeInfo,
unsigned flags,
CodeManState *pState);
unsigned flags);

#ifdef HAS_LIGHTUNWIND
enum LightUnwindFlag
Expand Down Expand Up @@ -515,8 +496,7 @@ PTR_VOID GetExactGenericsToken(SIZE_T baseStackSlot,
virtual
void * GetGSCookieAddr(PREGDISPLAY pContext,
EECodeInfo * pCodeInfo,
unsigned flags,
CodeManState * pState);
unsigned flags);


#ifndef USE_GC_INFO_DECODER
Expand Down Expand Up @@ -606,21 +586,6 @@ HRESULT FixContextForEnC(PCONTEXT pCtx,

};

#ifdef TARGET_X86
#include "gc_unwind_x86.h"

/*****************************************************************************
How the stackwalkers buffer will be interpreted
*/

struct CodeManStateBuf
{
DWORD hdrInfoSize;
hdrInfo hdrInfoBody;
};

#endif

#ifdef FEATURE_INTERPRETER

class InterpreterCodeManager : public ICodeManager {
Expand All @@ -639,7 +604,6 @@ void FixContext(ContextType ctxType,
DWORD dwRelOffset,
DWORD nestingLevel,
OBJECTREF thrownObject,
CodeManState *pState,
size_t ** ppShadowSP, // OUT
size_t ** ppEndRegion) // OUT
{
Expand All @@ -658,8 +622,7 @@ virtual
TADDR GetAmbientSP(PREGDISPLAY pContext,
EECodeInfo *pCodeInfo,
DWORD dwRelOffset,
DWORD nestingLevel,
CodeManState *pState)
DWORD nestingLevel)
{
// Interpreter-TODO: Implement this if needed
_ASSERTE(FALSE);
Expand All @@ -677,8 +640,7 @@ virtual
bool UnwindStackFrame(
PREGDISPLAY pRD,
EECodeInfo *pCodeInfo,
unsigned flags,
CodeManState *pState);
unsigned flags);

#ifdef FEATURE_EH_FUNCLETS
virtual
Expand Down Expand Up @@ -721,8 +683,7 @@ virtual GenericParamContextType GetParamContextType(PREGDISPLAY pContext,
virtual
void * GetGSCookieAddr(PREGDISPLAY pContext,
EECodeInfo * pCodeInfo,
unsigned flags,
CodeManState * pState)
unsigned flags)
{
return NULL;
}
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/inc/gc_unwind_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ struct hdrInfo
bool isSpeculativeStackWalk; // is the stackwalk seeded by an untrusted source (e.g., sampling profiler)?

// These always includes EBP for EBP-frames and double-aligned-frames
RegMask savedRegMask:8; // which callee-saved regs are saved on stack
RegMask savedRegMask; // which callee-saved regs are saved on stack

// Count of the callee-saved registers, excluding the frame pointer.
// This does not include EBP for EBP-frames and double-aligned-frames.
Expand Down Expand Up @@ -397,6 +397,8 @@ bool UnwindStackFrameX86(PREGDISPLAY pContext,
IN_EH_FUNCLETS_COMMA(bool isFunclet)
bool updateAllRegs);

unsigned int DecodeGCHdrInfoMethodSize(GCInfoToken gcInfoToken);

size_t DecodeGCHdrInfo(GCInfoToken gcInfoToken,
unsigned curOffset,
hdrInfo * infoPtr);
Expand Down
13 changes: 10 additions & 3 deletions src/coreclr/inc/regdisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,30 @@ inline LPVOID GetRegdisplayFPAddress(REGDISPLAY *display) {
return (LPVOID)display->GetEbpLocation();
}

inline TADDR GetRegdisplayPCTAddr(REGDISPLAY *display)
{
return display->PCTAddr;
}

inline void SetRegdisplayPCTAddr(REGDISPLAY *display, TADDR addr)
Comment on lines +138 to 143
Copy link
Member Author

Choose a reason for hiding this comment

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

I initially tried to optimize how the PCTAddr is stored for callee context to avoid recomputation. Unfortunately it results in some bugs (eg. CopyRegDisplay doesn't transfer the information correctly, IsInCalleesFrames depends on quirks in the initial state, etc.) and I opted not to pursue this optimization at this time. I left the helper methods in place to make it easier to address this in future and to create a central place where we can _ASSERTE on invalid values.

{
display->PCTAddr = addr;
#ifdef FEATURE_EH_FUNCLETS
display->pCurrentContext->Eip = *PTR_PCODE(addr);
#endif
display->ControlPC = *PTR_PCODE(addr);
}


// This function tells us if the given stack pointer is in one of the frames of the functions called by the given frame
inline BOOL IsInCalleesFrames(REGDISPLAY *display, LPVOID stackPointer) {
LIMITED_METHOD_CONTRACT;

return (TADDR)stackPointer < display->PCTAddr;
return (TADDR)stackPointer < GetRegdisplayPCTAddr(display);
}
inline TADDR GetRegdisplayStackMark(REGDISPLAY *display) {
LIMITED_METHOD_DAC_CONTRACT;

return display->PCTAddr;
return GetRegdisplayPCTAddr(display);
}

#elif defined(TARGET_64BIT)
Expand Down
9 changes: 3 additions & 6 deletions src/coreclr/unwinder/i386/unwinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ BOOL OOPStackUnwinderX86::Unwind(T_CONTEXT* pContextRecord, T_KNONVOLATILE_CONTE

FillRegDisplay(&rd, pContextRecord);

rd.SP = pContextRecord->Esp;
rd.PCTAddr = (UINT_PTR)&(pContextRecord->Eip);

if (pContextPointers)
{
rd.pCurrentContextPointers = pContextPointers;
Expand All @@ -27,13 +24,13 @@ BOOL OOPStackUnwinderX86::Unwind(T_CONTEXT* pContextRecord, T_KNONVOLATILE_CONTE
codeInfo.Init((PCODE) ControlPc);

GCInfoToken gcInfoToken = codeInfo.GetGCInfoToken();
hdrInfo hdrInfoBody;
DWORD hdrInfoSize = (DWORD)DecodeGCHdrInfo(gcInfoToken, codeInfo.GetRelOffset(), &hdrInfoBody);
hdrInfo *hdrInfoBody;
DWORD hdrInfoSize = codeInfo.DecodeGCHdrInfo(&hdrInfoBody);

if (!UnwindStackFrameX86(&rd,
PTR_CBYTE(codeInfo.GetSavedMethodCode()),
codeInfo.GetRelOffset(),
&hdrInfoBody,
hdrInfoBody,
dac_cast<PTR_CBYTE>(gcInfoToken.Info) + hdrInfoSize,
PTR_CBYTE(codeInfo.GetJitManager()->GetFuncletStartAddress(&codeInfo)),
codeInfo.IsFunclet(),
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/vm/codeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Module Name:
#include "pedecoder.h"
#include "gcinfo.h"
#include "eexcp.h"
#ifdef TARGET_X86
#include "gc_unwind_x86.h"
#endif

class MethodDesc;
class ICorJitCompiler;
Expand Down Expand Up @@ -2902,6 +2905,8 @@ class EECodeInfo
WRAPPER_NO_CONTRACT;
return GetCodeManager()->GetFrameSize(GetGCInfoToken());
}

DWORD DecodeGCHdrInfo(hdrInfo ** infoPtr);
#endif // TARGET_X86

#if defined(TARGET_WASM)
Expand All @@ -2926,6 +2931,11 @@ ULONG GetFixedStackSize();
PTR_RUNTIME_FUNCTION m_pFunctionEntry;
#endif // FEATURE_EH_FUNCLETS

#ifdef TARGET_X86
DWORD m_hdrInfoSize;
hdrInfo m_hdrInfoBody;
#endif

#ifdef TARGET_AMD64
// Simple helper to return a pointer to the UNWIND_INFO given the offset to the unwind info.
UNWIND_INFO * GetUnwindInfoHelper(ULONG unwindInfoOffset);
Expand Down
Loading