pub fn enable(
lua: &Lua,
cfg: &DebugConfig,
source_map: Option<Arc<SourceMap>>,
) -> Result<Option<DebugHandle>, DebugError>Expand description
Enable the debug backend for lua according to cfg (task 4.1 full wiring).
- When
cfg.enabled == false: returnsOk(None). No VM hook is installed, no port is opened, no thread is spawned, andstd_debugis NOT exposed to scripts. This is the true zero-cost path (R5.2 / R5.3 / R5.5). - When
cfg.enabled == true: builds a FULLY WIRED backend and returnsOk(Some(DebugHandle)):- a shared [
BreakpointSet] (settable while the VM runs), - a [
DebugSession] over the VM-thread ends of the command/event channels, installed into the line hook viahook::install(engine-widejit.off()+ a coroutine-crossingEVERY_LINEhook) — this is the VM-thread stop core; inspect/step/continue are processed in its hook loop ON THIS THREAD (themlua::Luanever crosses a thread, R6 /!Send), - a [
Transport] bound tocfg.listen(the OS-assigned port is readable viaDebugHandle::local_addrwhenlistenuses port 0), - a shared [
DapAdapter] and two bridge threads connecting the transport to the session (see [wiring] for the thread topology).
- a shared [
§Thread topology (design “Architecture” / “System Flows”)
One VM host thread (the caller, owns mlua::Lua and the session in the hook) +
one socket-bridge thread (sole [Transport] owner: multiplexes inbound
socket reads and outbound socket writes, since Transport is !Sync and
mpsc has no select) + one event-encoder thread (session events → DAP
frames). The socket bridge and encoder share the [DapAdapter] behind an
Arc<Mutex<…>> (its seq + correlation table). See [wiring] for the full
topology and the inbound-poll / outbound-frame-channel structure.
§SHIORI independence (R6)
This function does not import or reference pasta_shiori; any pasta host (or
a test harness) drives it directly.
§Preconditions
lua must already be constructed on the VM thread.
§Source map injection (task 4.2 — pasta-source-map)
source_map is the OPTIONAL immutable shared .pasta↔.lua map (design
“Architecture”: Arc<SourceMap> 不変共有). Together with cfg.source_mode
(task 4.1) it is threaded to the three .pasta CONSUMERS — the DAP source
resolver (task 5.2), the breakpoint translator (task 5.3) and the stepper
(task 5.4) — via this injection path: enable → wiring → DebugSession
(design 548). The map+mode REACH those points only when BOTH a map is
supplied AND cfg.source_mode == SourceMode::Pasta (design 582, requirements
6.1); for None or SourceMode::Lua every consumer keeps its existing
default .lua behavior byte-for-byte (requirements 6.2 / 7.2). This task
wires the SKELETON only — the consumer LOGIC is tasks 5.x.
§Errors
DebugError::Bind if the DAP listener fails to bind; DebugError::Vm if
the hook install fails (mlua::Error is stringified at the boundary, it is
!Send). The disabled path never errors.