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.
@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.
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
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.
@blangmuir suggestion worked. Thank you guys for helping me out
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.