From 112240cce5df0808897405461864d40f040f550f Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Wed, 6 Mar 2024 01:17:02 +0100 Subject: [PATCH] Fix extra stack frame on exception stack trace (#99263) A recently added diagnostic test has revealed that throwing an exception from a funclet results in an extra frame on the stack trace that should not be there. This change fixes it in a manner equivalent to how the old EH handles that. --- .../Runtime.Base/src/System/Runtime/ExceptionHandling.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs index 89855a54113d2..7ec5cd004e95d 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @@ -771,7 +771,13 @@ private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExIn DebugScanCallFrame(exInfo._passNumber, frameIter.ControlPC, frameIter.SP); - UpdateStackTrace(exceptionObj, exInfo._frameIter.FramePointer, (IntPtr)frameIter.OriginalControlPC, frameIter.SP, ref isFirstRethrowFrame, ref prevFramePtr, ref isFirstFrame, ref exInfo); +#if !NATIVEAOT + // Don't add frames at collided unwind + if (startIdx == MaxTryRegionIdx) +#endif + { + UpdateStackTrace(exceptionObj, exInfo._frameIter.FramePointer, (IntPtr)frameIter.OriginalControlPC, frameIter.SP, ref isFirstRethrowFrame, ref prevFramePtr, ref isFirstFrame, ref exInfo); + } byte* pHandler; if (FindFirstPassHandler(exceptionObj, startIdx, ref frameIter,