Skip to content

Fix edit and continue in VS with hardware exceptions #76401

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

Merged

Conversation

janvorli
Copy link
Member

There is a subtle bug in hardware exception handling in the runtime that causes the debugged process to crash when a user tries to use the "unwind to this frame" on the frame where the exception happened. This issue was introduced by the recent changes that modified hardware exception handling.

The problem turned out to be in how we update the exception and context records in the HandleManagedFaultFilter when we re-raise the exception using RaiseException from the VEH. Updating the context is both not necessary and wrong. All we need to update is the ExceptionAddress in the EXCEPTION_RECORD, since the RaiseException puts the address of itself there and we need the address of the original access violation to be there.
The context should stay untouched as we are unwinding from the RaiseException.

The context copying was originally made to mimick the code in the NakedThrowHelper used before the exception handling change. That one needed the context update, as it was used to fix unwinding over the NakedThrowHelper that was a hijack helper. In the current state, nothing like that is needed.

With this fix, the VS debugger works as expected.

Close #75762

There is a subtle bug in hardware exception handling in the runtime
that causes the debugged process to crash when a user tries to use the
"unwind to this frame" on the frame where the exception happened.
This issue was introduced by the recent changes that modified hardware
exception handling.

The problem turned out to be in how we update the exception and context
records in the HandleManagedFaultFilter when we re-raise the exception
using RaiseException from the VEH. Updating the context is both not
necessary and wrong. All we need to update is the `ExceptionAddress` in
the `EXCEPTION_RECORD`, since the RaiseException puts the address of
itself there and we need the address of the original access violation to
be there.
The context should stay untouched as we are unwinding from the
RaiseException.

The context copying was originally made to mimick the code in the
`NakedThrowHelper` used before the exception handling change. That one
needed the context update, as it was used to fix unwinding over the
NakedThrowHelper that was a hijack helper. In the current state, nothing
like that is needed.

With this fix, the VS debugger works as expected.
@janvorli janvorli added this to the 7.0.0 milestone Sep 29, 2022
@janvorli janvorli requested a review from jkotas September 29, 2022 19:56
@janvorli janvorli self-assigned this Sep 29, 2022
@janvorli
Copy link
Member Author

cc: @tommcdon, @hoyosjs

@janvorli janvorli merged commit 062fb45 into dotnet:main Sep 30, 2022
@janvorli
Copy link
Member Author

/backport to release/7.0

@github-actions
Copy link
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3157197640

@ghost ghost locked as resolved and limited conversation to collaborators Oct 30, 2022
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.

ICorDebugThread2.InterceptCurrentException corrupts process in x64 Windows
2 participants