Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing frame on inner exception stack trace in release build #105482

Conversation

janvorli
Copy link
Member

There is a problem in release builds of the runtime that was discovered by SOS tests. When an exception is thrown from reflection code, the inner exception was missing the frame(s) from the reflection called code on the stack trace and had them in the _remoteStackTraceString instead. So getting the exception stack trace as string still worked correctly. In checked or debug builds, it was working as expected.

It turned out that the issue was caused by the fact that when an exception is rethrown as native one when exception unwinding reaches native frames, it used RealCOMPlusThrow method. The catch was that while in debug / checked builds it was using this method with Object* argument, in release builds, the OBJECTREF and Object* are the same thing, so the RealCOMPlusThrow with the explicit Object* was not compiled and we were using the one with the OBJECTREF argument. Unfortunately, that one has a different semantics - to save the current stack trace into the _remoteStackTraceString and then building it from scratch.

The fix was to rename the RealCOMPlusThrow version with the Object* argument to a different name so that it can be built for release, checked and debug builds and used for the specific purpose of propagating managed exception through the native frames.

There is a problem in release builds of the runtime that was discovered
by SOS tests. When an exception is thrown from reflection code, the
inner exception was missing the frame(s) from the reflection called code
on the stack trace and had them in the `_remoteStackTraceString` instead.
So getting the exception stack trace as string still worked correctly.
In checked or debug builds, it was working as expected.

It turned out that the issue was caused by the fact that when an
exception is rethrown as native one when exception unwinding reaches
native frames, it used `RealCOMPlusThrow` method. The catch was that while
in debug / checked builds it was using this method with Object*
argument, in release builds, the `OBJECTREF` and Object* are the same
thing, so the `RealCOMPlusThrow` with the explicit Object* was not
compiled and we were using the one with the OBJECTREF argument.
Unfortunately, that one has a different semantics - to save the current
stack trace into the `_remoteStackTraceString` and then building it from
scratch.

The fix was to rename the RealCOMPlusThrow version with the Object*
argument to a different name so that it can be built for release,
checked and debug builds and used for the specific purpose of
propagating managed exception through the native frames.
@janvorli janvorli added this to the 9.0.0 milestone Jul 25, 2024
@janvorli janvorli requested a review from jkotas July 25, 2024 14:19
@janvorli janvorli self-assigned this Jul 25, 2024
@janvorli
Copy link
Member Author

cc: @mikem8361 - this fixes the issue you have shared with me yesterday.

@janvorli
Copy link
Member Author

/azp run coreclr-outerloop

Copy link

No pipelines are associated with this pull request.

@janvorli
Copy link
Member Author

/azp run coreclr-outerloop

Copy link

No pipelines are associated with this pull request.

@janvorli
Copy link
Member Author

/azp run runtime-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@janvorli
Copy link
Member Author

The outerloop failures seem to be the #105441

@janvorli janvorli merged commit 360569f into dotnet:main Jul 26, 2024
139 of 142 checks passed
@janvorli janvorli deleted the fix-missing-frame-on-eh-stacktrace-release-build branch July 26, 2024 15:24
@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants