Skip to main content

Module dap

Module dap 

Source
Expand description

Debug Adapter Protocol over stdio (node --dap).

A single-threaded source-line debugger. The program is compiled with per-statement line markers (Op::CallBuiltin(DBG_LINE, 1), emitted only in this mode — normal runs carry zero extra ops) and run on the pure interpreter (the tracing JIT would compile hot loops and skip the markers, so --dap compiles with set_debug_mode(true), which installs the marker hook instead of enable_tracing_jit). The DBG_LINE builtin fires synchronously at each marker; when it lands on a breakpoint or a step target it pauses IN PLACE and services DAP requests (stackTrace/scopes/variables/continue/next/ stepIn/stepOut) from stdin until a resume command, then returns control to the VM.

Because it is single-threaded, an async pause of a free-running program is not supported (the adapter only reads requests while stopped at a marker); breakpoints and stepping — the load-bearing features — work inside function, loop, and try/catch bodies. Program stdout is redirected to a pipe during the run and forwarded as output events, so console.log/process.stdout.write never corrupt the JSON protocol channel on the saved stdout fd.

Functions§

on_debug_line
Called by the VM at each statement marker (via the DBG_LINE builtin, which passes the marker’s source line). If it is a breakpoint or the active step target, pauses and services DAP requests until a resume command.
on_ext
Extension-handler shim kept for the Op::Extended dispatch seam registered in host::run_chunk_on. node-js emits DBG_LINE as Op::CallBuiltin, not Op::Extended, so in the current wiring the live hook is on_debug_line (invoked from the DBG_LINE builtin — see builtins::b_dbg_line). This shim routes an Extended(DBG_LINE) marker to the same logic should the emission seam ever be switched, and is a no-op for every other extension id.
run
Entry point for node --dap.