Debugging sourcekit-lsp using LLDB

I have been trying to debug sourcekit-lsp using lldb, I have set breakpoints on Xcode and attached Xcode debugger with sourcekit-lsp process, code pauses on breakpoints and shows all the variables on the scope but when I try to print the content using p command on lldb it says
Shared Swift state for sourcekit-lsp could not be initialized. The REPL and expressions are unavailable.

What wrong am I doing here?

  • @Adrian_Prantl
    can you attach the types log?
    add log enable lldb types -f ~/lldb-sourcekit.log to your ~/.lldbinit, close xcode, rerun and paste the log here.

Also, what Xcode version, what swift version? Are you using a nightly?

My Xcode Version is 11.0 beta 6 (11M392q)

My Apple Swift version is 5.1 (swiftlang-1100.0.270.6 clang-1100.0.32.1)

And the log I got is lldb-sourcekit.log

The log shows 0 AST blobs imported for every dylib. Is it possible you built sourcekit-lsp with swiftpm? You may be running into a well-known issue in swiftpm where it doesn't pass -add_ast_path to the linker.
@Aciid

Yes @Adrian_Prantl I did build sourcekit-lsp with swiftpm

The workaround is to manually re-run the linker invocation and add -add_ast_path /path/to/my.swiftmodule for every .swiftmodule built in the project.

Oh !!! Ok, I will try it out and let you guys know, Thank you :slight_smile:

Would it also work to build sourcekit-lsp in Xcode using the swift package support?

That's a good point, I think that should work, too!

Basic.swiftmodule
Build.swiftmodule
ISDBTestSupport.swiftmodule
ISDBTibs.swiftmodule
IndexStoreDB.swiftmodule
LanguageServerProtocol.swiftmodule
LanguageServerProtocolJSONRPC.swiftmodule
PackageGraph.swiftmodule
PackageLoading.swiftmodule
PackageModel.swiftmodule
SKCore.swiftmodule
SKSupport.swiftmodule
SKSwiftPMWorkspace.swiftmodule
SKTestSupport.swiftmodule
SPMLLBuild.swiftmodule
SPMLibc.swiftmodule
SPMUtility.swiftmodule
SourceControl.swiftmodule
SourceKit.swiftmodule
Workspace.swiftmodule
Xcodeproj.swiftmodule
llbuildSwift.swiftmodule
sourcekit_lsp.swiftmodule
tibs.swiftmodule

These are all the .swiftmodule present on my .build/debug/ folder
I manually re-ran the linker invocation and added -add_ast_path
My command was something like this for each of the .swiftmodule
swift build -Xlinker -add_ast_path -Xlinker Basic.swiftmodule

When I run debugger now I get this as error

Error while loading Swift module:
sourcekit-lsp: :1:9: note: in file included from :1:
#import "llbuild/llbuild.h"
^
error: /Users/rabingaire/Desktop/opensource/sourcekit-lsp/.build/checkouts/swift-llbuild/products/libllbuild/include/llbuild/llbuild.h:112:10: error: 'llbuild/core.h' file not found
#include "llbuild/core.h"
^
error: could not build Objective-C module 'llbuild'
Debug info from this module will be unavailable in the debugger.
warning: Swift error in scratch context: error: missing required module 'CIndexStoreDB'
:1:9: note: in file included from :1:
#import "llbuild/llbuild.h"
^
.
Shared Swift state for sourcekit-lsp has developed fatal errors and is being discarded.
REPL definitions and persistent names/types will be lost.
warning: Swift error in scratch context: error: missing required module 'CIndexStoreDB'
:1:9: note: in file included from :1:
#import "llbuild/llbuild.h"
^
.
Shared Swift state for sourcekit-lsp has developed fatal errors and is being discarded.
REPL definitions and persistent names/types will be lost.
warning: Swift error in scratch context: error: missing required module 'CIndexStoreDB'
:1:9: note: in file included from :1:
#import "llbuild/llbuild.h"
^
.
Shared Swift state for sourcekit-lsp has developed fatal errors and is being discarded.
REPL definitions and persistent names/types will be lost.
warning: Swift error in fallback scratch context: error: missing required module 'CIndexStoreDB'
:1:9: note: in file included from :1:
#import "llbuild/llbuild.h"
^
note: This error message is displayed only once. If the error displayed above is due to conflicting search paths to Clang modules in different images of the debugged executable, this can slow down debugging of Swift code significantly, since a fresh Swift context has to be created every time a conflict is encountered.
error: warning: failed to get module "SourceKit" from AST context:
error: missing required module 'CIndexStoreDB'
:1:9: note: in file included from :1:
#import "llbuild/llbuild.h"
^
error: error: missing required module 'CIndexStoreDB'
:1:9: note: in file included from :1:
#import "llbuild/llbuild.h"
^
Couldn't initialize Swift expression evaluator due to previous errors.

Can you try @blangmuir suggestion?

@blangmuir suggestion worked. Thank you guys for helping me out :smile:
Swift Package Support does not shows Products folder where we can find the executable I had to generate .xcodeproj file so that I could see Products folder and find the path to executable so that I could point that executable on vscode extension.

Terms of Service

Privacy Policy

Cookie Policy