Skip to content

Add opt-in hardware breakpoints for SOS JIT breakpoints - #6081

Merged
max-charlamb merged 1 commit into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/lldb-hardware-jit-breakpoints
Oct 2, 2026
Merged

max-charlamb merged 1 commit into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/lldb-hardware-jit-breakpoints

Conversation

@max-charlamb

Copy link
Copy Markdown
Member

Summary

Adds an opt-in environment variable, SOS_LLDB_HARDWARE_JIT_BREAKPOINTS=1. When set, SOS appends --hardware to the LLDB breakpoints it plants in JIT code: bpmd (IssueDebuggerBPCommand) and the one-shot exception-catcher breakpoint. The SOS test harness sets it for live LLDB hosts on macOS arm64.

Why

On macOS arm64, a live LLDB bpmd test intermittently crashes the debuggee with EXC_BAD_ACCESS / KERN_PROTECTION_FAILURE. The ESR is 0x8200000f, an instruction-abort permission fault with FAR == PC in JIT code, and the fault clears on retry.

Debugserver writes a software breakpoint like this:

  1. mach_vm_protect(RW | VM_PROT_COPY), which copy-on-writes the MAP_JIT page.
  2. mach_vm_write of the BRK instruction.
  3. MATTR_CACHE flush.
  4. Restore the page to RX.

Other threads that execute from the freshly copied page can briefly take a spurious permission fault. A standalone C repro that performs the same sequence, with no debugger involved, reproduces it on macOS 27 / M3 Pro. It does not reproduce when the page is patched in-process with pthread_jit_write_protect_np, or in a macOS VM. This is being reported to Apple.

Hardware breakpoints are programmed through the ARM debug registers and never modify the page, so they avoid the problem.

Local GcWhere replay on stock CLT LLDB (lldb-2103), with SOS hosted on .NET 11:

Breakpoint type Healthy Faulted
Software 129/130 1
Hardware 30/30 0

Earlier runs with the sos-lldb driver:

Breakpoint type Healthy Faulted
Software 27/30 3
Hardware 330/330 0

Limitations

  • Only a few hardware breakpoint slots exist per process (6 on Apple M-series). Setting more fails; LLDB does not fall back to software breakpoints.
  • Breakpoints that SOS doesn't plant (e.g. named native breakpoints) are unaffected.
  • The variable is opt-in and off by default for users.

Testing

  • GcWhereTests and LiveBpmdTests (live LLDB, Core net8/net10/net11, legacy DAC and cDAC) pass locally on osx-arm64.
  • The trace shows every SOS breakpoint command planted with --hardware (16/16).

Setting SOS_LLDB_HARDWARE_JIT_BREAKPOINTS=1 makes SOS append --hardware to
the LLDB breakpoints it plants in JIT code (bpmd and exception catchers).

On macOS arm64, debugserver writes a software breakpoint by copy-on-writing
the MAP_JIT page (mach_vm_protect with VM_PROT_COPY) and patching in a BRK.
Threads that then run code on the new page can intermittently take a spurious
EXC_BAD_ACCESS/KERN_PROTECTION_FAILURE instruction abort. Hardware breakpoints
use debug registers and never modify the page.

The SOS test harness opts in for live LLDB hosts on macOS arm64. Only a few
hardware breakpoint slots exist (6 on Apple M-series), and setting more fails
rather than falling back to software breakpoints.

Co-authored-by: Copilot <[email protected]>
@max-charlamb
max-charlamb requested a review from a team as a code owner September 30, 2026 23:18
@max-charlamb

Copy link
Copy Markdown
Member Author

/ba-g unrelated test failure (legacy SOS tests)

@max-charlamb
max-charlamb merged commit 4e5180c into dotnet:main Oct 2, 2026
20 of 22 checks passed
@max-charlamb
max-charlamb deleted the dev/max-charlamb/lldb-hardware-jit-breakpoints branch October 2, 2026 20:06
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants