Skip to content

Fix LLDB notification callback continuation - #6054

Merged
max-charlamb merged 2 commits into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/fix-lldb-notification-callback
Sep 22, 2026
Merged

max-charlamb merged 2 commits into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/fix-lldb-notification-callback

Conversation

@max-charlamb

Copy link
Copy Markdown
Member

Summary

Fix intermittent macOS ARM64 failures when SOS resolves a pending managed bpmd breakpoint from an LLDB exception callback.

The LLDB callback now uses its return value as the stop/continue disposition:

  • S_OK stops the process.
  • S_FALSE continues after the callback unwinds.
  • A failed HRESULT stops so the processing error remains inspectable.

The CDB path is unchanged and continues to use its debugger event command (sxe -c "!SOSHandleCLRN" clrn) followed by g.

Failure evidence

The same SOS.Tests.GcWhereTests.GcWhere_Moves live test failed independently on different machines, configurations, and runtime versions:

  • Build 1599994 - macOS ARM64 Release, .NET 9, failed navigating to AtGen1 on dci-mac-build-441.
  • Build 1600264 - macOS ARM64 Debug, .NET 9, failed navigating to AtGen2 on DNCHELIXMAC099.
  • Build 1603177 - macOS ARM64 Debug, .NET 11, failed navigating to AtGen2 on dci-mac-build-425.

In each failure, SOS reported that the method was JIT-compiled and installed an LLDB breakpoint at the resulting native address. Continuing did not report that breakpoint. Instead, the process stopped with SIGABRT, and clrstack showed an AccessViolationException in the requested marker method at the breakpoint address.

Event chain

  1. bpmd creates a pending managed breakpoint and registers HandleExceptionNotification through ILLDBServices::SetExceptionCallback.
  2. SetExceptionCallback stores that handler as the LLDB breakpoint callback baton.
  3. The CLR JIT notification hits the LLDB exception breakpoint and invokes ExceptionBreakpointCallback.
  4. HandleCLRNotificationEvent translates the notification. CNotification::OnCodeGenerated2 resolves the pending breakpoint, installs the concrete native breakpoint, and sets DEBUG_STATUS_GO_HANDLED.
  5. The previous PAL path executed process continue immediately, while LLDB was still inside ExceptionBreakpointCallback.
  6. After that nested continuation returned, HandleCLRNotificationEvent returned S_OK, which ExceptionBreakpointCallback interpreted as true (stop). The resulting control flow was therefore "continue recursively, then return stop".

This change returns S_FALSE for PAL notifications whose disposition is DEBUG_STATUS_GO*. LLDB receives false from its callback and performs the continuation only after the callback has unwound. Non-CLR exceptions observed by the broad LLDB exception breakpoint also return S_FALSE, preserving the previous continue behavior without re-entering LLDB.

Stress reproduction

On a macOS ARM64 checkout built with the SOS test harness, repeatedly launch a fresh live target with the matrix narrowed to the affected path:

for i in $(seq 1 100); do
  SOSHARNESS_ONLY_HOSTS=Lldb \
  SOSHARNESS_ONLY_FLAVORS=Core \
  SOSHARNESS_ONLY_LIVENESS=Live \
  SOSHARNESS_ONLY_GCTYPE=Workstation \
  SOSHARNESS_ONLY_COREVERSIONS=Net9,Net11 \
  SOSHARNESS_ONLY_DAC=Legacy \
  ./artifacts/bin/SOS.Tests/Debug/net10.0/SOS.Tests \
    --filter-method SOS.Tests.GcWhereTests.GcWhere_Moves \
    --parallel none --output Normal || break
done

The historical CI rate was 3 failures in 37 completed macOS ARM64 SOS legs, so a repeated fresh-process run is substantially stronger than a single green CI leg. The same loop can be run before and after this change for an A/B comparison.

Validation

  • Build.cmd -skipmanaged -configuration Debug
  • Native Debug build completed with zero warnings and zero errors after regenerating stale local CMake intermediates.
  • macOS ARM64 stress validation is expected from PR CI or an ARM64 Mac using the command above.

Return the notification disposition through the LLDB breakpoint callback instead of recursively continuing the process from inside the callback.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 2d5c60f7-9c89-42e6-b9fc-04ef78c8f8d8
Copilot AI lite review requested due to automatic review settings September 21, 2026 17:05
@max-charlamb
max-charlamb requested a review from a team as a code owner September 21, 2026 17:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The behavioral change matches the described LLDB callback contract and appears correct; only a small, non-blocking maintainability nit remains.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

This PR fixes an intermittent macOS ARM64 SOS failure caused by continuing the debuggee from inside LLDB’s exception breakpoint callback while resolving pending managed bpmd breakpoints. The change aligns LLDB callback behavior with an explicit stop/continue contract based on HRESULT, avoiding re-entrancy into LLDB and keeping errors inspectable.

Changes:

  • Update SOS’s PAL/LLDB CLR-notification handling to return S_FALSE (continue) for DEBUG_STATUS_GO* dispositions instead of issuing an immediate nested process continue.
  • Update the LLDB exception breakpoint callback to interpret HRESULT return values as stop/continue disposition (S_FALSE => continue; anything else => stop).
  • Document the exception-callback return contract in lldbservices.h.
File Description
src/​SOS/​Strike/​strike.cpp Returns S_FALSE on LLDB/PAL when the notification disposition is “go/continue”, preventing nested process continue during the callback.
src/​SOS/​lldbplugin/​services.cpp Changes callback disposition logic to continue only on S_FALSE, and stop on S_OK or errors.
src/​SOS/​inc/​lldbservices.h Documents the stop/continue/error contract for exception callbacks.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/SOS/Strike/strike.cpp Resolved
Keep the CDB break in its platform branch so the LLDB return path has no dead statement.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 2d5c60f7-9c89-42e6-b9fc-04ef78c8f8d8
@max-charlamb
max-charlamb enabled auto-merge (squash) September 21, 2026 18:06
@max-charlamb

Copy link
Copy Markdown
Member Author

/ba-g flaky test run

@max-charlamb
max-charlamb merged commit 43c8fd9 into dotnet:main Sep 22, 2026
19 of 22 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 23, 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.

4 participants