diff --git a/.dockerignore b/.dockerignore
index ad846d8bd8..4d0d10c087 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -3,6 +3,7 @@
**/build
**/.gradle
**/.idea
+!**/.idea/runConfigurations/
/.vscode
!.vscode/tasks.json
**/*.sw*
diff --git a/.gitignore b/.gitignore
index c7e9411b51..e54ce37176 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,9 @@
.hermit/
-.vscode/
+.vscode/*
!/.vscode/settings.json
-.idea/
+!/.vscode/launch.json
+.idea/*
+!.idea/runConfigurations/
*.iml
target/
build/
@@ -20,6 +22,7 @@ testdata/**/go.work
testdata/**/go.work.sum
**/testdata/**/_ftl
**/examples/**/_ftl
+**/examples/**/types.ftl.go
buildengine/.gitignore
go.work*
junit*.xml
diff --git a/.idea/runConfigurations/Debug_FTL.xml b/.idea/runConfigurations/Debug_FTL.xml
new file mode 100644
index 0000000000..425c6ffc8c
--- /dev/null
+++ b/.idea/runConfigurations/Debug_FTL.xml
@@ -0,0 +1,10 @@
+
+
+ 127.0.0.1
+ 2345
+ 2
+
+
+
+
+
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000000..6b143d6bb4
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,14 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Debug FTL",
+ "type": "go",
+ "request": "attach",
+ "mode": "remote",
+ "apiVersion": 2,
+ "host": "127.0.0.1",
+ "port": 2345
+ }
+ ]
+}
\ No newline at end of file
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 72149ea050..0b42927dfa 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -150,6 +150,35 @@ just publish-extension
This will publish the extension to the FTL marketplace. This command will require you to have a Personal Access Token (PAT) with the `Marketplace` scope. You can create a PAT [here](https://dev.azure.com/ftl-org/_usersSettings/tokens).
+## Debugging with Delve
+
+### Building with Full Debug Information
+
+To build a binary with full debug information for Delve, use the following command:
+
+```sh
+FTL_DEBUG=true just build ftl
+```
+
+### Debugging a Running Process
+
+For an in-line replacement of `ftl dev `, use the command:
+
+```sh
+just debug
+```
+
+This command compiles a binary with debug information, runs `ftl dev ` using this binary, and provides an endpoint to attach a remote debugger at __127.0.0.1:2345__.
+You do not need to run `FTL_DEBUG=true just build ftl` separately when using this command.
+### Attaching a Debugger
+
+By running `just debug ` and then attaching a remote debugger, you can debug the FTL infrastructure while running your project.
+
+#### IntelliJ
+Run `Debug FTL` from the `Run/Debug Configurations` dropdown while in the FTL project.
+#### VSCode
+Run `Debug FTL` from the `Run and Debug` dropdown while in the FTL project.
+
## Useful links
- [VSCode extension samples](https://github.com/microsoft/vscode-extension-samples)
diff --git a/Justfile b/Justfile
index f1c7be41cd..2a128e369f 100644
--- a/Justfile
+++ b/Justfile
@@ -50,7 +50,12 @@ build-generate:
build +tools: build-protos build-zips build-frontend
#!/bin/bash
shopt -s extglob
- for tool in $@; do mk "{{RELEASE}}/$tool" : !(build|integration) -- go build -o "{{RELEASE}}/$tool" -tags release -ldflags "-X github.com/TBD54566975/ftl.Version={{VERSION}} -X github.com/TBD54566975/ftl.Timestamp={{TIMESTAMP}}" "./cmd/$tool"; done
+
+ if [ "${FTL_DEBUG:-}" = "true" ]; then
+ for tool in $@; do go build -o "{{RELEASE}}/$tool" -tags release -gcflags=all="-N -l" -ldflags "-X github.com/TBD54566975/ftl.Version={{VERSION}} -X github.com/TBD54566975/ftl.Timestamp={{TIMESTAMP}}" "./cmd/$tool"; done
+ else
+ for tool in $@; do mk "{{RELEASE}}/$tool" : !(build|integration) -- go build -o "{{RELEASE}}/$tool" -tags release -ldflags "-X github.com/TBD54566975/ftl.Version={{VERSION}} -X github.com/TBD54566975/ftl.Timestamp={{TIMESTAMP}}" "./cmd/$tool"; done
+ fi
# Build all backend binaries
build-backend:
@@ -148,3 +153,20 @@ docs:
# Generate LSP hover help text
lsp-generate:
@mk lsp/hoveritems.go : lsp docs/content -- "scripts/ftl-gen-lsp"
+
+# Run `ftl dev` providing a Delve endpoint for attaching a debugger.
+debug *args:
+ #!/bin/bash
+ set -euo pipefail
+
+ cleanup() {
+ if [ -n "${dlv_pid:-}" ] && kill -0 "$dlv_pid" 2>/dev/null; then
+ kill "$dlv_pid"
+ fi
+ }
+ trap cleanup EXIT
+
+ FTL_DEBUG=true just build ftl
+ dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec "{{RELEASE}}/ftl" -- dev {{args}} &
+ dlv_pid=$!
+ wait "$dlv_pid"
\ No newline at end of file
diff --git a/bin/.dlv-1.22.1.pkg b/bin/.dlv-1.22.1.pkg
new file mode 120000
index 0000000000..383f4511d4
--- /dev/null
+++ b/bin/.dlv-1.22.1.pkg
@@ -0,0 +1 @@
+hermit
\ No newline at end of file
diff --git a/bin/delve-1.22.1 b/bin/delve-1.22.1
new file mode 120000
index 0000000000..8076e960be
--- /dev/null
+++ b/bin/delve-1.22.1
@@ -0,0 +1 @@
+.dlv-1.22.1.pkg
\ No newline at end of file