To debug Julia files, you can use the Julia DAP server.
Let’s debug the following test.julia file:
function main()
user = "world"
println("hello ", user)
end
main()-
install Julia. After that open a terminal and type
julia:
-
switch to Julia’s REPL by typing
]to install the DAP server with the commandadd DebugAdapter
-
here we create a Julia DAP server started with socket. Create a
server.jlin your project like this:
using Pkg
Pkg.instantiate()
using Sockets
using DebugAdapter
using Logging
function start_debugger()
try
server_port = parse(Int, ARGS[1])
server = Sockets.listen(server_port)
println("Listening on port $server_port")
conn = Sockets.accept(server)
println("Client connected")
debugsession = DebugAdapter.DebugSession(conn)
run(debugsession)
close(conn)
catch e
println("Error: ", e)
end
end
start_debugger()-
Create a DAP Run/Debug configuration:
-
In the
Servertab, click oncreate a new server: -
It opens a new dialog to create DAP server, select
Juliatemplate:
-
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:
julia $PROJECT_DIR$/server.jl ${port}
The ${port} argument will be replaced with a free port when the run configuration starts.
The julia $PROJECT_DIR$ which is an Intellij macro will be replaced with your project dir.
- the
Connect to the server by waitingoption is set toLog pattern before processingwith:
Listening on port ${port}
This means the DAP (Debug Adapter Protocol) client will connect to the DAP server when this trace appears in the console:
julia path/to/your/project/server.jl 52714
Listening on port 52714
- 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 Julia files, you need configure mappings in the Mappings tab.
As you have selected Julia server, it will automatically populate the file mappings like this:
- Fill in the
Configurationtab:
- the
working directory(usually the project's root directory) - the path to the
test.jlfile.
- Select
LaunchasDebug mode. - The DAP parameters of the launch should look like this:
{
"type": "julia",
"name": "Launch Julia file",
"request": "launch",
"program": "${file}",
"projectDir": "${workspaceFolder}",
"exitAfterTaskReturns": false,
"debugAutoInterpretAllModules": false,
"stopOnEntry": false
}When the run configuration starts:
${workspaceFolder}will be replaced with the working directory you specified.${file}will be replaced with the full path totest.jl.
After applying the run configuration, you should set a breakpoint to files which matches file mappings.
Set a breakpoint in the test.jl 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 Julia (completion, validation, etc) you can configure the Julia Language Server










