To debug Swift files, you can use the lldb-dap DAP server.
Let’s debug the following Sources/main.swift file:
// The Swift Programming Language
// https://docs.swift.org/swift-book
var user = "word";
print("Hello, " + user + "!")-
Install Swift. Please see the Getting Started Guide on Swift.org for details on how to install Swift on your system. This installation will install the lldb-dap DAP server.
-
After the installation, you should have the
lldb-dapcommand available (make sure to close and reopen your IDE to ensure thelldb-dapcommand is properly recognized).
If you open a terminal and run the following command:
lldb-dap -help
You should see some instructions how to start lldb-dap server.
-
Create a DAP Run/Debug configuration:
-
In the
Servertab, click oncreate a new server: -
It opens a new dialog to create DAP server, select
Swift lldbtemplate:
-
After clicking on
OKbutton, it will select the new server and pre-fill configurations:
This will automatically populate:
- the server
name - the
commandwhich starts the DAP server which should look like this:
lldb-dap
This command will start the DAP server with stdio mode. You could start the server in socket mode
with the following command:
lldb-dap -p ${port}
- Enable DAP server traces
If you wish to show DAP request/response traces when you will debug:
you need to select Trace with verbose.
To allows settings breakpoints to Swift files, you need configure mappings in the Mappings tab.
As you have selected Swift lldb server, it will automatically populate the file mappings like this:
To debug swift files, you will need to build an executable. You can do that with
swift build
This command should generate an executable according your swift project settings:
- Fill in the
Configurationtab:
- the
working directory(usually the project's root directory) - the path to the executable file.
- Select
LaunchasDebug mode. - The DAP parameters of the launch should look like this:
{
"type": "swift-lldb",
"name": "Launch Swift executable",
"request": "launch",
"program": "${file}",
"cwd": "${workspaceFolder}"
}When the run configuration starts:
${workspaceFolder}will be replaced with the working directory you specified.${file}will be replaced with the full path to your executable.
After applying the run configuration, you should set a breakpoint to files which matches file mappings.
Set a breakpoint in the Sources/main.swift file:
You can start the run configuration in either Run or Debug mode. Once started, you should see DAP traces in the console:
You will also see Threads and Variables:
If you need language support for Swift (completion, validation, etc) you can configure the SourceKit-LSP Language Server









