daveleroy / SublimeDebugger

Graphical Debugger for Sublime Text for debuggers that support the debug adapter protocol
MIT License
365 stars 41 forks source link

Swift support with `codelldb`: need to set `lldb_library` in SublimeDebugger preferences? #229

Open peterkos opened 10 months ago

peterkos commented 10 months ago

Morning!

I was struggling to attach lldb to a SwiftPM-built project (sourcekit-lsp, of course) with the following config:

"debugger_configurations":[{
    "type": "lldb",
    "request": "attach",
    "name": "Attach",
    "program": "${folder}/.build/arm64-apple-macosx/debug/sourcekit-lsp",
    "waitFor": true,
    "lldb.library": "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB",
    "lldb.verboseLogging": true
}]

(Opting for A over the /Current/ symlink, and targeting the macos SPM debug output)

After much hoopla, I found a teeny little setting in Debugger.sublime-settings that overrides the debugger configurations!

https://github.com/daveleroy/SublimeDebugger/blob/95b7098d6d432e38b847bd1d42c525186e4e64f8/Debugger.sublime-settings#L57-L58

In fact -- codelldb, contrary to its Swift documentation, doesn't need to have lldb.library set in this case, because of this setting. Nor does it need LLDB_DEBUGSERVER_PATH as a lldb.launch.env 😅

Working config:

// sourcekit-lsp.sublime-project
"debugger_configurations":[{
    "type": "lldb",
    "request": "attach",
    "name": "Attach",
    "program": "${folder}/.build/arm64-apple-macosx/debug/sourcekit-lsp",
    "waitFor": true,
    "lldb.verboseLogging": true
}]
// Debugger.sublime-settings
{
    "lldb_library": "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB",
}

Maybe a callout in the README for this setting would be helpful? I'd normally throw it in codelldb, but that's VSCode specific :eyes: Happy to add one wherever!

peterkos commented 10 months ago

The "symptom" here was hitting breakpoints, but unable to print any vars in the console, and the callstack was obfuscated, like so:

s18SKSwiftPMWorkspace05SwiftB0C3url17toolchainRegistry10buildSetupACSg10Foundation3URLV_6SKCore09ToolchainF0CAK05BuildH0VtcfC

Attempting to print a var would yield this fun error, informing us (tldr) that lldb wasn't loaded, + we're runnin' only the debug symbols from the executable:

:po buildSetup
error: Could not find type system for language swift: TypeSystem for language swift doesn't exist
daveleroy commented 8 months ago

Does lldb.library in the configuration work in vsocde? I was under the impression that was a workspace setting similar to Debugger.sublime-preferences.

There currently isn't a great place to add notes for specific adapters besides the readme