Skip to content

Host SOS in a standalone LLDB driver - #5999

Merged
steveisok merged 3 commits into
mainfrom
steveisok-sos-lldb-driver-layer
Sep 5, 2026
Merged

steveisok merged 3 commits into
mainfrom
steveisok-sos-lldb-driver-layer

Conversation

@steveisok

@steveisok steveisok commented Sep 2, 2026

Copy link
Copy Markdown
Member

Summary

  • add a temporary test-only sos-lldb executable on macOS to host SOS through Apple LLDB reliably
  • keep the driver source and build target with native test helpers while staging the executable for SOS Helix tests
  • scope LLDB command-result routing with a reentrant RAII guard that restores the previous result
  • reject invalid LLDB thread IDs at the debugger-service boundary and retain an E_UNEXPECTED CLRMA backstop
  • stop batch execution and return a non-zero exit code when an LLDB command fails

Why this layer is separate

This PR contains only the standalone LLDB test-host layer from #5981. Keeping it separate from Helix sharding, harness, documentation, and dependency work makes the temporary host independently reviewable and provides the bottom layer for subsequent stacked changes.

The executable is test infrastructure, is not included in SOS packages, and is temporary until the .NET 11 SDK contains the runtime fix that makes this Apple LLDB workaround unnecessary.

Validation

  • ./build.sh -skipmanaged (macOS arm64 Debug)
  • successful sos-lldb --no-lldbinit --batch -o version returns 0
  • failed batch command returns 1 and prevents later -o commands from running
  • an interactive command failure remains nonfatal and later commands still run
  • invalid and missing argument checks return 2
  • loaded libsosplugin.dylib through sos-lldb and ran soshelp, confirming plugin command output is routed through the scoped result

Copilot AI lite review requested due to automatic review settings September 2, 2026 22:36
@steveisok
steveisok requested a review from a team as a code owner September 2, 2026 22:36

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

🟡 Changes recommended

The new sos-lldb driver currently doesn’t reliably surface command failures to callers in --batch mode (exit code remains 0), which can break scripting/CI usage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​SOS/​lldbplugin/​driver.cpp — The standalone driver currently can't propagate LLDB command success/failure to the caller because…
What changed in this PR

This PR introduces a standalone macOS sos-lldb executable to host SOS via Apple LLDB, while also tightening LLDB command output routing and rejecting invalid CLRMA OS-thread IDs to avoid mis-resolving threads.

Changes:

  • Add a macOS-only sos-lldb LLDB driver executable and install it alongside libsosplugin.
  • Replace manual SetCurrentResult/ClearCurrentResult with a re-entrant RAII scope that restores the prior SBCommandReturnObject.
  • Reject CLRMA thread lookups that resolve to invalid OS thread IDs (0 or -1).
File Description
src/​SOS/​Strike/​clrma/​managedanalysis.cpp Rejects invalid OS thread IDs before delegating to CLRMA service or building a ClrmaThread.
src/​SOS/​lldbplugin/​soscommand.cpp Uses scoped result routing for SOS command execution so output targets the correct command result.
src/​SOS/​lldbplugin/​services.h Adds LLDBServices::CurrentResultScope RAII guard and removes the previous setter/clearer helpers.
src/​SOS/​lldbplugin/​services.cpp Applies scoped result routing in extension command execution and LLDBServices::ExecuteCommand.
src/​SOS/​lldbplugin/​driver.cpp Adds the new standalone sos-lldb driver program for LLDB command hosting.
src/​SOS/​lldbplugin/​CMakeLists.txt Builds and installs sos-lldb on macOS.
Suppressed comments (1)

src/SOS/lldbplugin/driver.cpp:83

  • In --batch mode, failures from -o commands should typically produce a non-zero process exit code (and often stop executing further commands). As written, the driver always returns 0, which can cause scripts to miss command failures.
    lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter();
    bool keepRunning = true;
    for (const std::string& command : startupCommands)
    {
        if (!ExecuteCommand(interpreter, command))

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

Comment thread src/SOS/lldbplugin/driver.cpp Outdated
Comment thread src/SOS/lldbplugin/CMakeLists.txt Outdated
Comment thread src/SOS/Strike/clrma/managedanalysis.cpp Outdated
Comment thread src/SOS/Strike/clrma/managedanalysis.cpp
@steveisok
steveisok force-pushed the steveisok-sos-lldb-driver-layer branch from 666b424 to a14844f Compare September 4, 2026 01:57
@steveisok
steveisok changed the base branch from main to steveisok-reapply-sos-test-harness September 4, 2026 02:15
@steveisok
steveisok force-pushed the steveisok-sos-lldb-driver-layer branch 5 times, most recently from e1fe61b to b55f1b5 Compare September 4, 2026 21:12
Base automatically changed from steveisok-reapply-sos-test-harness to main September 4, 2026 23:10
steveisok added a commit that referenced this pull request Sep 4, 2026
## Summary

- Restores the complete reviewed SOS test harness from
[#5979](#5979) after its exact
revert in [#6006](#6006).
- Re-establishes this change as the new bottom layer beneath
[#5999](#5999),
[#6000](#6000),
[#6001](#6001), and
[#6002](#6002).
- Temporarily excludes only `SOS.Tests` from local CI via `SkipTests`
when `ContinuousIntegrationBuild` is true. Normal local builds and
discovery remain enabled until the upper Helix layer moves execution out
of local CI.

## Reconstruction proof

- The baseline restoration commit
`2c7616acc2be6b20cf377574fa52e40196f16ca7` has tree
`5d2ab7a6990a8cdc2ff8a3d2ec7a29e373b99d54`, exactly matching the
pre-revert commit `ec5af2a1a56c4d9348e7e92438bb2faf8684f15f`.
- The only subsequent delta is five added lines in
`src/tests/SOS.Tests/SOS.Tests.csproj` for the temporary CI-only skip.

## Validation

- `./dotnet.sh build src/tests/SOS.Tests/SOS.Tests.csproj --no-restore
--verbosity minimal` — succeeds with 0 warnings and 0 errors.
- Focused Microsoft.Testing.Platform discovery for
`SOS.Tests.PrintExceptionTests.PrintException_Data` with
DotnetDump/Core/net10 constraints — 2 expected rows discovered without
`ContinuousIntegrationBuild`.
- MSBuild property evaluation: default `SkipTests` is empty;
`-p:ContinuousIntegrationBuild=true` evaluates `SkipTests=true`.

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c34cd9f4-d3b5-4b46-b7fc-e34b34bc88c3
steveisok and others added 3 commits September 4, 2026 19:10
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move the temporary driver under native test helpers, propagate invalid
LLDB thread IDs as failures, and return nonzero for failed batch
commands.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9a6e90d9-5cd5-4ff1-a05b-11830076408d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9a6e90d9-5cd5-4ff1-a05b-11830076408d
@steveisok
steveisok force-pushed the steveisok-sos-lldb-driver-layer branch from b55f1b5 to 2f52969 Compare September 4, 2026 23:11
@steveisok
steveisok merged commit 4969077 into main Sep 5, 2026
16 of 26 checks passed
steveisok added a commit that referenced this pull request Sep 7, 2026
Stack layer 2 of the native decomposition for #5981.

Depends on #5999

This layer stabilizes the reusable SOS harness across hosts and
architectures: bounded child-process capture and stream drainage,
clearer child-host failures, bounded LLDB dump hosts, second-chance
DbgEng crash handling, macOS `sos-lldb` integration, RID-aware debuggee
builds, and focused platform/configuration validity checks.

It intentionally excludes Helix submission and pipeline wiring, payload
overlays, sharding, command-coverage migration, and legacy test
deletion.

Validation:
- `dotnet build src/tests/SOS.Tests/SOS.Tests.csproj -c Debug
-p:TargetArch=arm64 -p:TargetRid=osx-arm64 --no-restore`
- focused `BoundedProcessTests`, `HostSlotTests`, and
`TestConfigValidityTests` (20 passed)
- `dotnet publish` for the `SosHarnessScenarios` single-file `osx-arm64`
debuggee
- `./build.sh -skipmanaged -configuration Debug -architecture arm64`

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9a6e90d9-5cd5-4ff1-a05b-11830076408d
Copilot-Session: 5281acb1-f8c2-4264-9af1-d8489323b9ba
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.

5 participants