Skip to content

Commit ef0c712

Browse files
authored
Fix storage of stack trace of exception from reflection (#106901)
There was one more case where we have saved the stack trace into the _remoteStackTraceString field in the exception when the exception was passing from reflection invoked code to the caller of that code. While there is no visible difference in the Exception.ToString, a SOS test was failing due to that. And it is not necessary to save the stack trace there. I have thought about the cases when we really need the stack trace saved into the _remoteStackTraceString and I believe that actually the only case is when an existing exception is thrown again in managed code. So I have removed the option to save the stack trace from all the variants of the DispatchManagedException.
1 parent 5d21506 commit ef0c712

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

src/coreclr/vm/excep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7504,7 +7504,7 @@ VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFra
75047504
}
75057505
else
75067506
{
7507-
DispatchManagedException(orThrowable, /* preserveStackTrace */ false);
7507+
DispatchManagedException(orThrowable);
75087508
}
75097509
}
75107510
else

src/coreclr/vm/exceptionhandling.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ ProcessCLRExceptionNew(IN PEXCEPTION_RECORD pExceptionRecord,
970970
else
971971
{
972972
OBJECTREF oref = ExceptionTracker::CreateThrowable(pExceptionRecord, FALSE);
973-
DispatchManagedException(oref, pContextRecord, /* preserveStackTrace */ false);
973+
DispatchManagedException(oref, pContextRecord);
974974
}
975975
}
976976
#endif // !HOST_UNIX
@@ -5649,7 +5649,7 @@ void FirstChanceExceptionNotification()
56495649
#endif // TARGET_UNIX
56505650
}
56515651

5652-
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT* pExceptionContext, bool preserveStackTrace)
5652+
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT* pExceptionContext)
56535653
{
56545654
STATIC_CONTRACT_THROWS;
56555655
STATIC_CONTRACT_GC_TRIGGERS;
@@ -5661,19 +5661,12 @@ VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT* pE
56615661

56625662
Thread *pThread = GetThread();
56635663

5664-
if (preserveStackTrace)
5665-
{
5666-
pThread->IncPreventAbort();
5667-
ExceptionPreserveStackTrace(throwable);
5668-
pThread->DecPreventAbort();
5669-
}
5670-
56715664
ULONG_PTR hr = GetHRFromThrowable(throwable);
56725665

56735666
EXCEPTION_RECORD exceptionRecord;
56745667
exceptionRecord.ExceptionCode = EXCEPTION_COMPLUS;
56755668
exceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE | EXCEPTION_SOFTWARE_ORIGINATE;
5676-
exceptionRecord.ExceptionAddress = (void *)(void (*)(OBJECTREF, bool))&DispatchManagedException;
5669+
exceptionRecord.ExceptionAddress = (void *)(void (*)(OBJECTREF))&DispatchManagedException;
56775670
exceptionRecord.NumberParameters = MarkAsThrownByUs(exceptionRecord.ExceptionInformation, hr);
56785671
exceptionRecord.ExceptionRecord = NULL;
56795672

@@ -5709,7 +5702,7 @@ VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT* pE
57095702
UNREACHABLE();
57105703
}
57115704

5712-
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, bool preserveStackTrace)
5705+
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable)
57135706
{
57145707
STATIC_CONTRACT_THROWS;
57155708
STATIC_CONTRACT_GC_TRIGGERS;
@@ -5718,7 +5711,7 @@ VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, bool preser
57185711
CONTEXT exceptionContext;
57195712
RtlCaptureContext(&exceptionContext);
57205713

5721-
DispatchManagedException(throwable, &exceptionContext, preserveStackTrace);
5714+
DispatchManagedException(throwable, &exceptionContext);
57225715
UNREACHABLE();
57235716
}
57245717

src/coreclr/vm/exceptionhandling.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord,
2222
IN OUT PT_CONTEXT pContextRecord,
2323
IN OUT PT_DISPATCHER_CONTEXT pDispatcherContext);
2424

25-
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT *pExceptionContext, bool preserveStackTrace = true);
26-
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, bool preserveStackTrace = true);
25+
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT *pExceptionContext);
26+
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable);
2727
VOID DECLSPEC_NORETURN DispatchManagedException(RuntimeExceptionKind reKind);
2828

2929
enum CLRUnwindStatus { UnwindPending, FirstPassComplete, SecondPassComplete };

src/coreclr/vm/jithelpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2991,7 +2991,7 @@ void ThrowNew(OBJECTREF oref)
29912991
}
29922992
}
29932993

2994-
DispatchManagedException(oref, /* preserveStackTrace */ false);
2994+
DispatchManagedException(oref);
29952995
}
29962996
#endif // FEATURE_EH_FUNCLETS
29972997

0 commit comments

Comments
 (0)