Add debugger support (DAP)#702
Conversation
|
Hi, Sorry for not responding earlier. I've had a quick look and here are some thoughts so far:
|
|
Hi @dop251 thanks for getting back to me, unfortunately I won't have the time to address the feedback above or take this forward, so feel free to close this PR or for someone else to pick it up if they want to maintain it. I can confirm debugging works great with this PR from our experience so far, so I think its a solid base to bring support for debugging via various IDEs if you did decide this is valuable to goja, you would likely just need various pluggins for each IDE you want to target unless they support generic DAP debugging. I tried not to change the behaviour of goja when debugging is enabled to avoid hiding any issues so you can debug thing as close to ones deployed code as possible. |
This adds debugger support to goja using the Debug Adapter Protocol (DAP), so you can step-debug JavaScript/TypeScript running in goja from VS Code.
The core API lives in
debugger.goandvm_debug.go— breakpoints (line, conditional, hit count, log points), stepping, pause, variable inspection, eval while paused, exception breakpoints, and source map support. The DAP server is in a separatedebugger/submodule to keep thego-dapdependency out of the main module.When no debugger is attached there's zero overhead — everything is gated behind
vm.dbg != nil.The changes to existing files are kept minimal:
compiler.go/compiler_expr.go/compiler_stmt.goemit debug variable maps whendebugModeis set,runtime.goadds the attach/detach API andCompileForDebug, andvm.godispatches to the debug-aware execution loop and hooks into save/restore context for frame tracking.A VS Code extension is included in
debugger/vscode-goja-debugger/with a pre-built.vsix.Tests: 33 tests for the core debug API in
debugger_test.go, 17 DAP integration tests indebugger/server_test.go.Note: The
debugger/go.modcurrently has areplace github.com/dop251/goja => ../directive so it compiles against the local parent module during development. Once this PR is merged, thatreplaceshould be removed and thegithub.com/dop251/gojadependency updated to point at the merged commit (or a tagged release).