Skip to content

Commit

Permalink
Remove managed EH code frames from stack trace (dotnet#108723)
Browse files Browse the repository at this point in the history
When StackTrace is created inside of an exception filter, it contains
stack frames of the managed exception handling code, like
System.Runtime.EH.RhThrowEx
System.Runtime.EH.DispatchEx
System.Runtime.EH.FindFirstPassHandler

These should not occur on the stack trace as they are internal
implementation detail of the new EH.

This change fixes it by adding [StackTraceHidden] attribute to these
methods.

Close dotnet#107995
  • Loading branch information
janvorli authored and mikelle-rogers committed Dec 4, 2024
1 parent 489d0b6 commit e8023ba
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ internal object ThrownException
#if NATIVEAOT
[RuntimeExport("RhThrowHwEx")]
#endif
[StackTraceHidden]
public static void RhThrowHwEx(uint exceptionCode, ref ExInfo exInfo)
{
#if NATIVEAOT
Expand Down Expand Up @@ -644,6 +645,7 @@ public static void RhThrowHwEx(uint exceptionCode, ref ExInfo exInfo)
#if NATIVEAOT
[RuntimeExport("RhThrowEx")]
#endif
[StackTraceHidden]
public static void RhThrowEx(object exceptionObj, ref ExInfo exInfo)
{
#if NATIVEAOT
Expand Down Expand Up @@ -725,6 +727,7 @@ public static void RhUnwindAndIntercept(ref ExInfo exInfo, UIntPtr interceptStac
#if NATIVEAOT
[RuntimeExport("RhRethrow")]
#endif
[StackTraceHidden]
public static void RhRethrow(ref ExInfo activeExInfo, ref ExInfo exInfo)
{
#if NATIVEAOT
Expand All @@ -742,6 +745,7 @@ public static void RhRethrow(ref ExInfo activeExInfo, ref ExInfo exInfo)
FallbackFailFast(RhFailFastReason.InternalError, null);
}

[StackTraceHidden]
private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExInfo exInfo)
{
Debug.Assert(exInfo._passNumber == 1, "expected asm throw routine to set the pass");
Expand Down Expand Up @@ -997,6 +1001,7 @@ private static void UpdateStackTrace(object exceptionObj, UIntPtr curFramePtr, I
prevFramePtr = curFramePtr;
}

[StackTraceHidden]
private static bool FindFirstPassHandler(object exception, uint idxStart,
ref StackFrameIterator frameIter, out uint tryRegionIdx, out byte* pHandler)
{
Expand Down Expand Up @@ -1154,6 +1159,7 @@ private static void InvokeSecondPass(ref ExInfo exInfo, uint idxStart)
{
InvokeSecondPass(ref exInfo, idxStart, MaxTryRegionIdx);
}

private static void InvokeSecondPass(ref ExInfo exInfo, uint idxStart, uint idxLimit)
{
EHEnum ehEnum;
Expand Down

0 comments on commit e8023ba

Please sign in to comment.