Skip to content

Handle trigger breakpoints across process threads - #387

Draft
namtran1812 wants to merge 1 commit into
janestreet:masterfrom
namtran1812:fix/multithread-stop-indicator
Draft

Handle trigger breakpoints across process threads#387
namtran1812 wants to merge 1 commit into
janestreet:masterfrom
namtran1812:fix/multithread-stop-indicator

Conversation

@namtran1812

@namtran1812 namtran1812 commented Aug 15, 2026

Copy link
Copy Markdown

Summary

Fix trigger breakpoints so they can fire from worker threads when magic-trace is attached to a multithreaded process.

Fixes #274.

Problem

The existing trigger implementation creates a hardware breakpoint only for the head PID/TID. Since perf_event_open breakpoints are task-specific, a trigger such as magic_trace_stop_indicator() can work from the main thread but be missed when called from a worker thread.

Implementation

  • Enumerate process TIDs from /proc/<pid>/task
  • Introduce a Trigger_breakpoint abstraction for breakpoint lifecycle and Async FD monitoring
  • Maintain one trigger breakpoint per discovered TID
  • Rescan for threads created after attachment
  • Handle races where threads exit during breakpoint setup
  • Preserve single-snapshot behavior across thread breakpoints
  • Add a multithreaded regression target based on stop indicator does not work in multi-threaded application #274

Validation

  • dune build @fmt passes locally
  • git diff --check passes locally
  • multithreaded C++ regression target builds successfully

End-to-end perf breakpoint behavior requires Linux validation, so this is being opened as a draft.

Signed-off-by: namtran1812 <158846154+namtran1812@users.noreply.github.com>
@namtran1812

Copy link
Copy Markdown
Author

Draft for validation: DCO is passing, but the Linux build workflow is currently blocked before any jobs are created. I’ll keep this in draft until CI and end-to-end multithreaded perf validation are complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stop indicator does not work in multi-threaded application

1 participant