Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1.67 KB

DEVELOPMENT.adoc

File metadata and controls

50 lines (35 loc) · 1.67 KB

Pkl Go Development Guide

Debugging the Pkl Server

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

  1. Create a file named debugpkl

  2. Mark the file executable with chmod +x debugpkl

  3. 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:

  1. Open the pkl project

  2. Build jpkl by running ./gradlew javaExecutable so it is available to the script defined above

  3. Run > Edit Configurations…​

  4. Add a new "Remote JVM Debug" configuration

  5. Provide a name, eg. debugpkl

  6. Under "Configuration", select the "Listen to remote JVM" debugger mode

  7. Enable "Auto restart"

  8. Ensure Host is "localhost" and Port is "5005"

Usage

  1. Configure pkl-go to use debugpkl as the server executable: export PKL_EXEC=./debugpkl

  2. Optionally, turn on extra debug output: export PKL_DEBUG=1

  3. Define breakpoints as desired in the Pkl codebase using IntelliJ

  4. In IntelliJ, start debugging the "Remote JVM Debug" configuration defined above

  5. Execute the process using pkl-go

When the Pkl server execution reaches a defined breakpoint, it will pause and activate the debugger in IntelliJ.