From 3d68d7121ea176d1c7d10ab4156a491f61973ec2 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Wed, 7 May 2025 18:46:55 -0700 Subject: [PATCH 1/2] Fix issue where SoftwareExceptionFrame on non EH Funclet model X86 was mishandled by the DAC --- src/coreclr/vm/excep.cpp | 9 ++++++++- src/coreclr/vm/frames.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index 726384d64950db..4d0470610d84e7 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -11341,7 +11341,7 @@ void SoftwareExceptionFrame::UpdateRegDisplay_Impl(const PREGDISPLAY pRD, bool u pRD->IsCallerContextValid = FALSE; pRD->IsCallerSPValid = FALSE; // Don't add usage of this field. This is only temporary. #elif defined(TARGET_X86) -#define CALLEE_SAVED_REGISTER(regname) pRD->Set##regname##Location(m_ContextPointers.regname); +#define CALLEE_SAVED_REGISTER(regname) pRD->Set##regname##Location(&m_Context.regname); ENUM_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER @@ -11366,6 +11366,7 @@ void SoftwareExceptionFrame::UpdateContextFromTransitionBlock(TransitionBlock *p m_Context.Eax = 0; m_Context.Ecx = pTransitionBlock->m_argumentRegisters.ECX; m_Context.Edx = pTransitionBlock->m_argumentRegisters.EDX; +#ifdef FEATURE_EH_FUNCLETS m_ContextPointers.Ecx = &m_Context.Ecx; m_ContextPointers.Edx = &m_Context.Edx; @@ -11374,6 +11375,12 @@ void SoftwareExceptionFrame::UpdateContextFromTransitionBlock(TransitionBlock *p m_ContextPointers.reg = &m_Context.reg; ENUM_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER +#else // FEATURE_EH_FUNCLETS +#define CALLEE_SAVED_REGISTER(reg) \ + m_Context.reg = pTransitionBlock->m_calleeSavedRegisters.reg; + ENUM_CALLEE_SAVED_REGISTERS(); +#undef CALLEE_SAVED_REGISTER +#endif // FEATURE_EH_FUNCLETS m_Context.Esp = (UINT_PTR)(pTransitionBlock + 1); m_Context.Eip = pTransitionBlock->m_ReturnAddress; diff --git a/src/coreclr/vm/frames.h b/src/coreclr/vm/frames.h index 9636dd9ee73c24..e94b1a88c2bea7 100644 --- a/src/coreclr/vm/frames.h +++ b/src/coreclr/vm/frames.h @@ -1040,7 +1040,9 @@ typedef DPTR(class SoftwareExceptionFrame) PTR_SoftwareExceptionFrame; class SoftwareExceptionFrame : public Frame { TADDR m_ReturnAddress; +#if !defined(TARGET_X86) || defined(FEATURE_EH_FUNCLETS) T_KNONVOLATILE_CONTEXT_POINTERS m_ContextPointers; +#endif // This T_CONTEXT field needs to be the last field in the class because it is a // different size between Linux (pal.h) and the Windows cross-DAC (winnt.h). T_CONTEXT m_Context; From c85475a3ecb8b730a541f112b461b6b18da32db4 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Thu, 8 May 2025 10:07:02 -0700 Subject: [PATCH 2/2] Fix issue where EH stack traces aren't properly visible in the debugger --- src/coreclr/vm/object.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreclr/vm/object.h b/src/coreclr/vm/object.h index ca924879b7939c..a72ab1ab3b90e5 100644 --- a/src/coreclr/vm/object.h +++ b/src/coreclr/vm/object.h @@ -2268,7 +2268,11 @@ class ExceptionObject : public Object void GetStackTrace(StackTraceArray & stackTrace, PTRARRAYREF * outKeepaliveArray = NULL) const { +#ifdef DACCESS_COMPILE + return GetStackTrace(stackTrace, outKeepaliveArray, NULL); +#else return GetStackTrace(stackTrace, outKeepaliveArray, GetThread()); +#endif // DACCESS_COMPILE } private: