Skip to content

Host SOS in a standalone LLDB driver - #5998

Closed
steveisok wants to merge 1 commit into
dotnet:mainfrom
steveisok:steveisok-sos-lldb-driver
Closed

Host SOS in a standalone LLDB driver#5998
steveisok wants to merge 1 commit into
dotnet:mainfrom
steveisok:steveisok-sos-lldb-driver

Conversation

@steveisok

Copy link
Copy Markdown
Member

Summary

  • add a temporary sos-lldb executable on macOS to host SOS through Apple LLDB reliably
  • scope LLDB command-result routing with a reentrant RAII guard that restores the previous result
  • reject CLRMA thread lookups that resolve to invalid OS thread IDs (0 or -1)

Why this layer is separate

This PR contains only the standalone product-facing LLDB hosting layer from #5981. Keeping it separate from Helix sharding, harness, test, documentation, and dependency work makes the temporary host independently reviewable and provides a clean bottom layer for subsequent changes. The executable is intentionally temporary while SOS needs a reliable Apple LLDB command host.

Validation

  • ./build.sh -skipmanaged (macOS arm64 Debug)
  • sos-lldb --no-lldbinit --batch -o version
  • invalid and missing argument exit-code checks
  • loaded libsosplugin.dylib through sos-lldb and ran soshelp, confirming plugin command output is routed through the scoped result

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 2, 2026 22:10
@steveisok
steveisok requested a review from a team as a code owner September 2, 2026 22:10

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 does not currently propagate failed -o startup command execution into a non-zero exit code, which breaks reliable scripting/batch 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 — In batch/non-interactive usage, command failures from SBCommandInterpreter::HandleCommand() are not…
What changed in this PR

This PR introduces a temporary macOS-only sos-lldb standalone LLDB driver executable to host SOS via Apple LLDB, while also tightening LLDB command output routing and validating CLRMA thread lookups to avoid invalid OS thread IDs.

Changes:

  • Add a macOS sos-lldb driver executable (CMake + new driver.cpp) for reliable LLDB hosting in batch/CLI scenarios.
  • Scope LLDB SBCommandReturnObject routing via a reentrant RAII guard (LLDBServices::CurrentResultScope) and apply it to command entry points.
  • Reject CLRMA GetThread resolutions that produce invalid OS thread IDs (0 or -1).
File Description
src/​SOS/​Strike/​clrma/​managedanalysis.cpp Adds validation to reject invalid resolved OS thread IDs before querying CLRMA thread services.
src/​SOS/​lldbplugin/​soscommand.cpp Uses a scoped guard to ensure SOS command output is routed to the correct LLDB result object.
src/​SOS/​lldbplugin/​services.h Introduces LLDBServices::CurrentResultScope RAII guard and removes direct set/clear helpers.
src/​SOS/​lldbplugin/​services.cpp Applies the result scope to extension command execution and to LLDBServices::ExecuteCommand.
src/​SOS/​lldbplugin/​driver.cpp Adds the new sos-lldb standalone LLDB driver executable implementation.
src/​SOS/​lldbplugin/​CMakeLists.txt Builds/installs sos-lldb on macOS and links it against LLDB.
Suppressed comments (1)

src/SOS/lldbplugin/driver.cpp:83

  • main() always returns 0 on normal shutdown, even if one of the -o startup commands failed. After capturing per-command success, propagate it via a non-zero exit code (and in --batch mode, stop on the first failure).
    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 on lines +18 to +28
bool ExecuteCommand(lldb::SBCommandInterpreter& interpreter, const std::string& command)
{
lldb::SBCommandReturnObject result;
result.SetImmediateOutputFile(stdout, false);
result.SetImmediateErrorFile(stderr, false);
interpreter.HandleCommand(command.c_str(), result, false);
std::fflush(stdout);
std::fflush(stderr);

return result.GetStatus() != lldb::eReturnStatusQuit;
}
@steveisok

Copy link
Copy Markdown
Member Author

Superseded by upstream-owned bottom stack layer #5999, which contains the same tested commit and participates in native stack #6003.

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.

2 participants