Skip to content

[clr-interp] Fix debugger MethodEnter counter and INTOP_DEBUG_METHOD_ENTER assert#127753

Open
kotlarmilos wants to merge 1 commit intodotnet:mainfrom
kotlarmilos:interp-debug-callback-correctness
Open

[clr-interp] Fix debugger MethodEnter counter and INTOP_DEBUG_METHOD_ENTER assert#127753
kotlarmilos wants to merge 1 commit intodotnet:mainfrom
kotlarmilos:interp-debug-callback-correctness

Conversation

@kotlarmilos
Copy link
Copy Markdown
Member

@kotlarmilos kotlarmilos commented May 4, 2026

Description

In DispatchMethodEnter, g_cTotalMethodEnter is supposed to count every controller with MethodEnter enabled regardless of which thread will actually fire the trigger. The increment was inside the per-thread filter, so unbound controllers were not counted, and the post-loop _ASSERTE(g_cTotalMethodEnter == count) fired. Move ++count out of the filter.

In the interpreter dispatch loop, INTOP_DEBUG_METHOD_ENTER asserts that the seq-point offset patched into the bytecode by OnMethodEnter is INTOP_DEBUG_SEQ_POINT. Once the debugger sets a user breakpoint at that sequence point the opcode is overwritten with INTOP_BREAKPOINT, which is also valid here, so the assert is updated to support such cases.

This fixes the following interpreter debugger test failures:

  • JMC.jmcChange
  • JMC.jmcDelegates
  • JMC.jmcFunceval
  • Async.AsyncStepInto

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli, @kg
See info in area-owners.md if you want to be subscribed.

…R assert

Two small interpreter-debugger callback correctness fixes. In DispatchMethodEnter, g_cTotalMethodEnter is supposed to count every controller with MethodEnter enabled regardless of which thread will actually fire the trigger. The increment was inside the per-thread filter, so unbound and other-thread controllers were not counted, and the post-loop _ASSERTE(g_cTotalMethodEnter == count) fired spuriously. Move ++count out of the filter. The trigger itself remains gated on thread affinity.

In the interpreter dispatch loop, INTOP_DEBUG_METHOD_ENTER asserts that the seq-point offset patched into the bytecode by OnMethodEnter is INTOP_DEBUG_SEQ_POINT. Once the debugger sets a user breakpoint at that sequence point the opcode is overwritten with INTOP_BREAKPOINT, which is also valid here, so the assert is relaxed to accept either.

This fixes the following interpreter debugger test failures:
- JMC.jmcChange
- JMC.jmcDelegates
- JMC.jmcFunceval
- Async.AsyncStepInto

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kotlarmilos kotlarmilos force-pushed the interp-debug-callback-correctness branch from 3a75885 to f0e5112 Compare May 4, 2026 14:23
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 two debug-time assertions in the CoreCLR interpreter + debugger integration that were causing interpreter debugger test failures when MethodEnter controllers are thread-affinitized and when the debugger installs a breakpoint on the method-entry sequence point.

Changes:

  • Fix DispatchMethodEnter’s debug-only controller counting so it matches g_cTotalMethodEnter regardless of per-thread filtering.
  • Update the interpreter INTOP_DEBUG_METHOD_ENTER assertion to allow the entry seq-point opcode to be either INTOP_DEBUG_SEQ_POINT or INTOP_BREAKPOINT (when patched by the debugger).
Show a summary per file
File Description
src/coreclr/vm/interpexec.cpp Allow INTOP_DEBUG_METHOD_ENTER’s target opcode to be a debugger-patched breakpoint as well as the original debug seq-point.
src/coreclr/debug/ee/controller.cpp Count all MethodEnter-enabled controllers (even if not firing on the current thread) so the g_cTotalMethodEnter consistency assert holds.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@kotlarmilos kotlarmilos requested review from noahfalk and tommcdon May 4, 2026 14:31
@kotlarmilos kotlarmilos added this to the 11.0.0 milestone May 4, 2026
@kotlarmilos kotlarmilos changed the title [interp] Fix debugger MethodEnter counter and INTOP_DEBUG_METHOD_ENTER assert [clr-interp] Fix debugger MethodEnter counter and INTOP_DEBUG_METHOD_ENTER assert May 4, 2026
{
if (p->m_fEnableMethodEnter)
{
++count;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this change impacting non-interpreter targets as well. Wasn't this failing before ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, the change applies to all targets. In the JIT path, the MethodEnter callback is called from JIT_DbgIsJustMyCode inside the stepped code, so the calling thread is almost always the same as the thread the stepper is bound to, and count matches g_cTotalMethodEnter by coincidence. The interpreter calls OnMethodEnter from INTOP_DEBUG_METHOD_ENTER on every method entry whenever any stepper has MethodEnter enabled.

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