The pkl-go evaluator API runs pkl server
as a subprocess, which presents obstacles for directly debugging the server process.
It is possible to
Debug Stub Setup
-
Create a file named
debugpkl
-
Mark the file executable with
chmod +x debugpkl
-
Populate the file with this content (note: the value for
JPKL_EXEC
will need to be updated depending on where the Pkl repo is cloned):
#!/bin/sh
JPKL_EXEC=/path/to/pkl/pkl-cli/build/executable/jpkl
if [ "$1" = "--version" ]; then
# if this is the version discovery command, don't connect to the debugger
exec "$JPKL_EXEC" "$@"
fi
exec java -agentlib:jdwp=transport=dt_socket,server=n,address=127.0.0.1:5005,suspend=y -jar "$JPKL_EXEC" "$@"
IntelliJ IDEA Setup:
-
Open the pkl project
-
Build
jpkl
by running./gradlew javaExecutable
so it is available to the script defined above -
Run > Edit Configurations…
-
Add a new "Remote JVM Debug" configuration
-
Provide a name, eg.
debugpkl
-
Under "Configuration", select the "Listen to remote JVM" debugger mode
-
Enable "Auto restart"
-
Ensure Host is "localhost" and Port is "5005"
Usage
-
Configure pkl-go to use
debugpkl
as the server executable:export PKL_EXEC=./debugpkl
-
Optionally, turn on extra debug output:
export PKL_DEBUG=1
-
Define breakpoints as desired in the Pkl codebase using IntelliJ
-
In IntelliJ, start debugging the "Remote JVM Debug" configuration defined above
-
Execute the process using pkl-go
When the Pkl server execution reaches a defined breakpoint, it will pause and activate the debugger in IntelliJ.