koush / vscode-quickjs-debug

QuickJS Debug Adapter for VS Code
MIT License
148 stars 27 forks source link

QuickJS Debug for VS Code

This is a VS Code debug adapter for QuickJS.

QuickJS Debugger supports stepping, continue, breakpoints, evaluation, and variable access.

The official QuickJS release does not have any debugger support. The QuickJS Debugger requires a forked version of QuickJS, that has minimal changes necessary to support debugging.

Using QuickJS Debug

You can now step through the test.js file, set and hit breakpoints.

QuickJS Debug

Embedding

To listen for a connection in embedded quickjs (attach + connect with vscode debugger):

// address is in format "0.0.0.0:6666" to listen on all addresses on port 6666
void js_debugger_wait_connection(JSContext *ctx, const char* address);

To initiate a connection in embedded quickjs (attach + listen with vscode debugger):

// address is in format "192.168.1.66:6666" to connect to 192.168.1.66 on port 6666
void js_debugger_connect(JSContext *ctx, const char* address);

Alternatively, provide one of the following environment variables before starting the process embedded with QuickJS:

QUICKJS_DEBUG_ADDRESS or QUICKJS_DEBUG_LISTEN_ADDRESS with the same value as above.

Using these methods will block execution until the debugger has attached.

QuickJS does not provide an event loop, so the debugger should (optionally, but recommended) be periodically called from your event loop to check for messages. Otherwise, debugger messages may go unhandled until the next time Javascript is invoked. This can be done with:

void js_debugger_cooperate(JSContext *ctx);

Protocol

Protocol documentation is here.