From 4b4113a0217ee27c78e7efddb66ff5a455d49083 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 12 Nov 2026 13:19:32 -0300 Subject: debugger: add a native GUI with live V8 JIT debugging --- gui/bench/RESULTS.md | 102 +++++++++++++++++++++++++++++++++++++++++ gui/bench/steps.py | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100644 gui/bench/RESULTS.md create mode 100644 gui/bench/steps.py (limited to 'gui/bench') diff --git a/gui/bench/RESULTS.md b/gui/bench/RESULTS.md new file mode 100644 index 0000000..d24659b --- /dev/null +++ b/gui/bench/RESULTS.md @@ -0,0 +1,102 @@ +# Debug V8 versus a small C target + +Measured locally on 2026-11-12, Linux 7.2.11-arch1-1, Intel i7-11700, +Zig 0.17.0, ReleaseFast controller. The targets were a `cc -g -O0` C loop +and **unoptimized debug V8**, not release d8. Both used the same controller: +512 stack bytes, 24 disassembled instructions and telescope depth 2, with a +recording flush at every stop. No syscall tracing and no continuous stepping +while the user has selected Continue. + +Final controller run: + +```sh +python3 gui/bench/steps.py \ + --d8 /tmp/computeranim-v8-debug-remote/d8 \ + --ztrace zig-out/bin/ztrace \ + --out /tmp/ztrace-step-bench-cleared +``` + +| 1,000 instruction steps | C | Debug V8 / generated JS | +| --- | ---: | ---: | +| Capture + flush, median | 35.73 µs | 38.47 µs | +| Capture + flush, p95 | 45.13 µs | 59.18 µs | +| Controller round trip, median | 46.94 µs | 49.53 µs | +| Controller round trip, p95 | 59.23 µs | 73.00 µs | +| Controller round trip, maximum | 310.72 µs | 381.48 µs | +| Launch through first requested breakpoint | 9.50 ms | 901.84 ms | + +This supports comparable steady instruction-step cost for these workloads. +It does not claim that V8 starts as quickly as a small program, or that all C++ +source/DWARF operations have this cost. The earlier 1,000-step run measured +39.09 / 44.42 µs capture medians and 53.69 / 60.57 µs round-trip medians for +C / V8. Scheduling and cache state affect these microsecond measurements; no +CPU isolation or filesystem-cache dropping was used. GUI presentation is not +included in the controller timings. + +The V8 fixture compiles `jitWork` with TurboFan, traps in the native runtime, +then installs an actual software breakpoint at `addl r8,r11` inside the +optimized loop. The harness asserts the returned RIP equals that address and +lies in an anonymous executable mapping. It then tests source-step fallback +without JIT source lines, records the instruction-step sample, and checks that +the recording no longer reports the previous native source line. The loop +address is read from V8's own output; the harness fails rather than guesses if +a different V8 compiler allocates different registers. + +The raw records, logs and JSON results are in `/tmp/ztrace-step-bench-cleared`. +The script is the durable reproducer; `/tmp` artifacts are not permanent. + +## V8 provenance + +The user's remote Arch build host (`chaincli-box`) has the existing checkout at +`/home/goblin/v8-research/v8`. Ninja verified the compatible debug build up to date +(`ninja: no work to do`). No V8 compilation was performed on the workstation. +The complete runtime artifacts were copied to `/tmp/computeranim-v8-debug-remote` +and smoke-tested locally. + +- Revision: `84703f702dca525edd469f3a98d784faa46a02f8`. +- d8 version: `15.2.0 (candidate)`. +- Output: `out/x64.debug-vuln` (historical directory name). +- Existing unrelated local `BUILD.gn` change to the `v8_fuzzer` source list was + preserved; the checkout was not reset or updated. +- `is_debug=true`, `v8_optimized_debug=false`, `symbol_level=2`, + `v8_symbol_level=2`, `use_debug_fission=true`, `target_cpu="x64"`. +- Disassembler, object printing, heap verification, slow DCHECKs and backtraces + enabled; `use_remoteexec=false`, `use_siso=false`. +- Component build: d8 plus its shared libraries (including the large debug + libv8.so), snapshots and ICU data. Split `.dwo` files were not copied, so this + run is not a validation of complete C++ local-variable/source debugging. + +## Checks + +The GUI's real-target script exercises launch, a named breakpoint, continue, +keyboard and mouse instruction stepping, source stepping, pause during execution, +and browsing history back to live. The core tests additionally check pause +signal suppression and source stepping without line information. + +The root suite had two failures before this work; they remain in the existing +loader/syscall formatting and watch/string assertions. The new debugger tests +pass (86/88 in the full root suite; 25/27 debugger tests, with those same two +failures). No assertion was +weakened to hide them. + +## Rich GUI verification + +A separate UI agent compared rendered C and V8 frames against the existing +animation design, checked strike/highlight/settled frames, and approved the +final native window. The checked-in GUI test asserts that the stack highlight +changes between strike and settled screenshots, as well as exercising controls. + +At 1920×1080, an approximate headless redraw measurement was **1.23 ms/frame +for C and 2.41 ms/frame for V8**. This subtracts the median elapsed time of +30-frame runs from 330-frame runs (three repeats each), then divides by 300. +Both opened the corresponding 1,000-step recording. V8 displayed 24 instruction +rows while C displayed 10; this is a whole-view cost, not an equal-row renderer +comparison. It excludes live trace reopening and display presentation latency. +Raw timings are in `/tmp/ztrace-gui-redraw-results.json`. + +The final native session was verified with d8 PID 2502490 in Linux tracing-stop +state and recorded RIP `0x7f09921c0196`: breakpoint 2 on `add r8d, r9d`, offset +`0x156` inside TurboFan-generated `jitWork`. It is left open in the GUI. The +recording is `/tmp/ztrace-gui-2502452-357545622054931.ztrace`; the screenshot is +`/tmp/ztrace-v8-live-final.png`. These addresses and PIDs describe this session +only. The complete animation gallery was not re-rendered. diff --git a/gui/bench/steps.py b/gui/bench/steps.py new file mode 100644 index 0000000..f97efed --- /dev/null +++ b/gui/bench/steps.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 +"""Compare the same controller's recorded instruction steps on C and debug V8.""" +import argparse +import json +import math +import os +from pathlib import Path +import re +import select +import statistics +import subprocess +import time + +ROOT = Path(__file__).resolve().parents[2] +p = argparse.ArgumentParser(description=__doc__) +p.add_argument('--d8', type=Path, required=True) +p.add_argument('--ztrace', type=Path, default=ROOT / 'gui/zig-out/bin/ztrace') +p.add_argument('--out', type=Path, default=Path('/tmp/ztrace-step-bench')) +p.add_argument('--steps', type=int, default=1000) +a = p.parse_args() +assert a.steps > 0 +a.out.mkdir(parents=True, exist_ok=True) +a.out = a.out.resolve() +a.d8 = a.d8.resolve() +small = a.out / 'loop' +subprocess.run(['cc', '-g', '-O0', str(ROOT / 'gui/targets/loop.c'), '-o', str(small)], check=True) + + +class Controller: + def __init__(self, name, argv): + self.log = (a.out / (name + '.log')).open('w+') + self.process = subprocess.Popen( + [str(a.ztrace.resolve()), 'serve', str(a.out / (name + '.ztrace')), '--', *argv], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=self.log, bufsize=0) + self.pending = b'' + + def read(self): + deadline = time.monotonic() + 30 + while b'\n' not in self.pending: + if not select.select([self.process.stdout], [], [], max(0, deadline - time.monotonic()))[0]: + raise TimeoutError('controller did not reply within 30 seconds') + data = os.read(self.process.stdout.fileno(), 4096) + if not data: + raise RuntimeError('controller exited; see ' + self.log.name) + self.pending += data + line, self.pending = self.pending.split(b'\n', 1) + return json.loads(line) + + def command(self, command): + self.process.stdin.write((command + '\n').encode()) + while True: + reply = self.read() + assert reply['status'] not in ('failed', 'exited'), reply + if reply['status'] == 'stopped': + return reply + + def close(self): + try: + if self.process.poll() is None: + self.process.stdin.write(b'quit\n') + self.process.wait(timeout=30) + finally: + if self.process.poll() is None: + self.process.kill() + self.process.wait() + self.process.stdin.close() + self.process.stdout.close() + self.log.close() + + +def summary(ns): + ordered = sorted(v / 1000 for v in ns) + return dict(median_us=statistics.median(ordered), p95_us=ordered[math.ceil(len(ns) * .95) - 1], max_us=max(ordered)) + + +results = {} +for name, argv in [('c', [str(small)]), ('v8', [str(a.d8), '--allow-natives-syntax', + '--no-concurrent-recompilation', '--no-maglev', '--print-opt-code', + '--print-opt-code-filter=jitWork', str(ROOT / 'gui/targets/jit.js')])]: + start = time.perf_counter_ns() + c = Controller(name, argv) + try: + assert c.read()['status'] == 'stopped' + entry_ns = time.perf_counter_ns() - start + if name == 'c': + c.command('break work') + else: + stopped = c.command('continue') # Native %SystemBreak, before the final JS call. + assert stopped['reason'].startswith('signal TRAP'), stopped + c.log.seek(0) + assembly = c.log.read() + assert 'kind = TURBOFAN_JS' in assembly + # shortcut: this fixture's x64 loop instruction; fail loudly if V8 changes its register allocation. + match = re.search(r'^(0x[0-9a-f]+)\s+[0-9a-f]+\s+[0-9a-f]+\s+addl r8,r11', assembly, re.M) + assert match, 'could not find jitWork loop body; inspect ' + c.log.name + address = int(match[1], 16) + c.command('signal 0') + c.command('break *' + hex(address)) + hit = c.command('continue') + assert hit['reason'].startswith('breakpoint '), hit + if name == 'v8': + assert hit['pc'] == address, hit + maps = Path(f"/proc/{hit['pid']}/maps").read_text().splitlines() + mapping = next(line for line in maps if int(line.split('-')[0], 16) <= address < int(line.split('-')[1].split()[0], 16)) + assert 'x' in mapping.split()[1] and len(mapping.split()) == 5, mapping + first_break_ns = time.perf_counter_ns() - start + if name == 'v8': + stepped = c.command('step') + assert stepped['reason'] == 'step' and stepped['pc'] != address, stepped + core, wall = [], [] + for _ in range(a.steps): + start_step = time.perf_counter_ns() + reply = c.command('stepi') + wall.append(time.perf_counter_ns() - start_step) + core.append(reply['elapsed_ns']) + assert reply['reason'] == 'step', reply + results[name] = dict(steps=a.steps, entry_ms=entry_ns / 1e6, first_break_ms=first_break_ns / 1e6, + capture=summary(core), roundtrip=summary(wall)) + print(name, json.dumps(results[name]), flush=True) + finally: + c.close() + if name == 'v8': + shown = subprocess.run([str(a.ztrace.resolve()), 'show', str(a.out / 'v8.ztrace'), '-1'], + check=True, capture_output=True, text=True) + assert f"thread {reply['tid']}" in shown.stdout.splitlines(), 'JIT stop inherited a stale native source line' +(a.out / 'results.json').write_text(json.dumps(results, indent=2) + '\n') -- cgit v1.3