Skip to content

Conversation

@janvorli
Copy link
Member

The VS team has recently reported two issues with the new exception handling in Visual Studio debugger.
The first issue was that an unhandled exception on a secondary managed thread wasn't showing any stack trace when the exception occured and the debugger has broken in.
The other issue was that when an exception occured during a funceval invoked from the immediate window, the debugger would not highlight the source line where the exception occured and it would not display a dialog with the exception details.
Both problems were caused by the same underlying problem. In both cases, the "catch handler found" notification was to be sent at a point when the managed stack frames were already gone - in native code in catch / filter. In the funceval case, there was even a check that prevented sending the notification at all when there was no exception info present.

The fix is to move the notification to the point where the managed stack frames are still present - when we detect in the EH code that there is no managed frame left and either the DebuggerU2MCatchHandler frame or FuncEvalFrame is the explicit frame we've encountered as the next one to process. The FuncEvalFrame case is a bit more involved, as we always push ProtectValueClassFrame after the FuncEvalFrame, so we need to skip that one in the check. The debugger actually needs to get a pointer to the FuncEvalFrame in the notification to do the right thing.

Close #102178 and #101729

The VS team has recently reported two issues with the new exception
handling in Visual Studio debugger.
The first issue was that an unhandled exception on a secondary managed
thread wasn't showing any stack trace when the exception occured and the
debugger has broken in.
The other issue was that when an exception occured during a funceval
invoked from the immediate window, the debugger would not highlight the
source line where the exception occured and it would not display a
dialog with the exception details.
Both problems were caused by the same underlying problem. In both cases,
the "catch handler found" notification was to be sent at a point when
the managed stack frames were already gone - in native code in catch / filter.
In the funceval case, there was even a check that prevented sending the
notification at all when there was no exception info present.

The fix is to move the notification to the point where the managed stack
frames are still present - when we detect in the EH code that there is
no managed frame left and either the DebuggerU2MCatchHandler frame or
FuncEvalFrame is the explicit frame we've encountered as the next one to
process. The FuncEvalFrame case is a bit more involved, as we always
push ProtectValueClassFrame after the FuncEvalFrame, so we need to skip
that one in the check. The debugger actually needs to get a pointer to
the FuncEvalFrame in the notification to do the right thing.

Close dotnet#102178 and dotnet#101729
@janvorli janvorli added this to the 9.0.0 milestone May 20, 2024
@janvorli janvorli requested review from jkotas and tommcdon May 20, 2024 22:01
@janvorli janvorli self-assigned this May 20, 2024
Copy link
Member

@tommcdon tommcdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

The ProtectValueClassFrame can also occur without FuncEvalFrame in the
reflection invocation.
@janvorli
Copy link
Member Author

/azp run runtime-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@janvorli
Copy link
Member Author

The test failures are known and unrelated to this change.

@janvorli janvorli merged commit a142e77 into dotnet:main May 21, 2024
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
…2470)

* Fix VS debugger issues with funceval and secondary threads

The VS team has recently reported two issues with the new exception
handling in Visual Studio debugger.
The first issue was that an unhandled exception on a secondary managed
thread wasn't showing any stack trace when the exception occured and the
debugger has broken in.
The other issue was that when an exception occured during a funceval
invoked from the immediate window, the debugger would not highlight the
source line where the exception occured and it would not display a
dialog with the exception details.
Both problems were caused by the same underlying problem. In both cases,
the "catch handler found" notification was to be sent at a point when
the managed stack frames were already gone - in native code in catch / filter.
In the funceval case, there was even a check that prevented sending the
notification at all when there was no exception info present.

The fix is to move the notification to the point where the managed stack
frames are still present - when we detect in the EH code that there is
no managed frame left and either the DebuggerU2MCatchHandler frame or
FuncEvalFrame is the explicit frame we've encountered as the next one to
process. The FuncEvalFrame case is a bit more involved, as we always
push ProtectValueClassFrame after the FuncEvalFrame, so we need to skip
that one in the check. The debugger actually needs to get a pointer to
the FuncEvalFrame in the notification to do the right thing.

Close dotnet#102178 and dotnet#101729

* Fix too strong assert

The ProtectValueClassFrame can also occur without FuncEvalFrame in the
reflection invocation.
@github-actions github-actions bot locked and limited conversation to collaborators Jun 21, 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.

DEBUG_EXCEPTION_CATCH_HANDLER_FOUND events missing for exceptions caught by func-eval

3 participants