Skip to content

Fix interpreter context after breakpoint#127480

Merged
janvorli merged 1 commit intodotnet:mainfrom
janvorli:fix-interpreter-context-after-breakpoint
Apr 28, 2026
Merged

Fix interpreter context after breakpoint#127480
janvorli merged 1 commit intodotnet:mainfrom
janvorli:fix-interpreter-context-after-breakpoint

Conversation

@janvorli
Copy link
Copy Markdown
Member

When debugger breakpoint is hit and then debugger resumes the execution, the context at which the breakpoint was hit can be modified. For example, one of the exception interception tests does that to continue from a different location after an exception is hit. The interpreter ignored changes in the context and resumed execution at the original breakpoint location instead of the modified context.

This change fixes it by throwing the ResumeAfterCatchException if the context was modified. That ensures that we resume the exception correctly even if both the stack frame and the IP was changed. The ResumeAfterCatchException became a bit of a misnomer, but I don't want to pollute this PR by renaming the ResumeAfterCatchException to ResumeException, which would be a better name now. I'd prefer doing it in a separate PR.

Follow-up to #126576

This fixes the following interpreter debugger test failure:

  • Exceptions.InterceptTest

When debugger breakpoint is hit and then debugger resumes the execution,
the context at which the breakpoint was hit can be modified. For
example, one of the exception interception tests does that to continue
from a different location after an exception is hit.
The interpreter ignored changes in the context and resumed execution at
the original breakpoint location instead of the modified context.

This change fixes it by throwing the ResumeAfterCatchException if the
context was modified. That ensures that we resume the exception
correctly even if both the stack frame and the ip was changed.
The ResumeAfterCatchException became a bit of a misnomer, but I don't
want to pollute this PR by renaming the ResumeAfterCatchException to
ResumeException, which would be a better name. I'd prefer doing it in
a separate PR.
@janvorli janvorli added this to the 11.0.0 milestone Apr 27, 2026
@janvorli janvorli self-assigned this Apr 27, 2026
@janvorli janvorli requested a review from BrzVlad as a code owner April 27, 2026 23:32
Copilot AI review requested due to automatic review settings April 27, 2026 23:32
@janvorli janvorli requested a review from kg as a code owner April 27, 2026 23:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes CoreCLR interpreter debugging behavior when resuming from an interpreter breakpoint after the debugger has modified the thread context (e.g., changing the resume IP and/or the interpreter frame). Instead of continuing at the original breakpoint location, the interpreter now detects the modified context and forces a resume using the existing ResumeAfterCatchException unwind/resume path.

Changes:

  • Use the return value of g_pDebugInterface->FirstChanceNativeException(...) to determine whether the debugger handled the breakpoint event.
  • Detect debugger modifications to the breakpoint CONTEXT (IP and SP) after the callback returns.
  • If the context was modified, throw ResumeAfterCatchException (via ThrowResumeAfterCatchException) to correctly unwind/resume interpreter execution at the updated location.

@janvorli
Copy link
Copy Markdown
Member Author

Hmm, it breaks another diagnostic test, I need to investigate it more.

@janvorli
Copy link
Copy Markdown
Member Author

The issue I was seeing was actually unrelated, I had some extra change locally that was causing the other test break

@janvorli janvorli merged commit ef58c99 into dotnet:main Apr 28, 2026
118 checks passed
@janvorli janvorli deleted the fix-interpreter-context-after-breakpoint branch April 28, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants