From 4f31aaef1338b53195f8c475db5a72d75cc1fc82 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 13 Nov 2026 12:18:26 -0300 Subject: debugger: add refractive lenses and configurable memory values Use disassembly lenses for executable pointers, browse surrounding segment context, and keep the reading surface opaque with GPU refraction at the edges. Route right-clicks by stack mapping and expose byte-width and numeric-format controls. Replace matching-address arrows with staggered shared-renderer highlights. Verified GUI and renderer suites, native restart/zoom cycles, independent float-extrema and popup review, and a live wrong-map stop at Deoptimizer::New with JS origin context. Requires Sketchbook 409c1ac. --- gui/test/basic.script | 14 +++--- gui/test/lenses.py | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ gui/test/restart.py | 8 ++++ 3 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 gui/test/lenses.py (limited to 'gui/test') diff --git a/gui/test/basic.script b/gui/test/basic.script index be2034f..9aeb647 100644 --- a/gui/test/basic.script +++ b/gui/test/basic.script @@ -49,14 +49,14 @@ release left_ctrl expect nav[2].place.row 7 key f expect nav[2].place.follow true -# Rendered code addresses route to disassembly, including source-aligned rows. +# Right-click always opens bytes; only stack mappings use the stack pane. console mouse-button 3 650 204 -expect focus code -expect nav[0].place.follow false -console mouse-button 4 650 204 -expect nav[0].place.follow true -console mouse-button 5 650 204 -expect nav[0].place.follow false +expect focus memory +expect nav[2].place.follow false +console mouse-button 4 1500 1000 +expect nav[2].place.follow true +console mouse-button 5 1500 1000 +expect nav[2].place.follow false key f # Stack storage addresses route to telescope. console mouse-button 3 250 855 diff --git a/gui/test/lenses.py b/gui/test/lenses.py new file mode 100644 index 0000000..c78e250 --- /dev/null +++ b/gui/test/lenses.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +"""Executable/data lenses, scroll bounds, display formats and native glass rendering.""" +import argparse +from pathlib import Path +import re +import subprocess +import tempfile + +ROOT = Path(__file__).resolve().parents[2] +p = argparse.ArgumentParser(description=__doc__) +p.add_argument('--gui', type=Path, default=ROOT / 'gui/zig-out/bin/ztrace-gui') +p.add_argument('--native', action='store_true') +p.add_argument('--output', type=Path) +a = p.parse_args() +a.gui = a.gui.resolve() +with tempfile.TemporaryDirectory(prefix='ztrace-lenses-') as directory: + out = a.output.resolve() if a.output else Path(directory) + out.mkdir(parents=True, exist_ok=True) + target = out / 'segments' + subprocess.run(['cc', '-g', '-O0', '-no-pie', str(ROOT / 'gui/targets/segments.c'), '-o', str(target)], check=True) + symbols = {name: int(address, 16) for address, name in re.findall(r'^([0-9a-f]+) \w (\w+)$', subprocess.check_output(['nm', '-n', str(target)], text=True), re.M)} + head, code = symbols['head'], symbols['checkpoint'] + script = out / 'check.script' + commands = f'''console launch {target} +await stops 1 +console break checkpoint +console continue +await execution 1 +frames 40 +console lens {code} +expect lens_count 1 +expect lenses[0].first {code} +frames 40 +screenshot {out / 'code-glass.png'} +console set glass false +frames 20 +screenshot {out / 'code-opaque.png'} +expect-different-screenshot {out / 'code-glass.png'} {out / 'code-opaque.png'} 1120 175 1060 140 +console set glass true +wheel 1600 220 -1 +frames 40 +print lenses[0].first +expect execution 1 +# Right-clicking an executable lens address opens memory, not code. +console mouse-button 3 1230 161 +expect focus memory +expect nav[2].place.address {code} +key escape +# Data lens context is scrollable in both directions without altering its anchor. +console lens {head} +frames 40 +expect lenses[0].address {head} +expect lenses[0].first {(head & ~15) - 32} +wheel 1600 220 -2 +frames 40 +expect lenses[0].first {(head & ~15) + 64} +screenshot {out / 'memory-context.png'} +wheel 1600 220 2 +frames 40 +expect lenses[0].first {(head & ~15) - 32} +# Same-parent pointer recursion preserves ancestors and detects a cycle. +click 1230 161 +expect lens_count 2 +expect lenses[1].cycle true +frames 30 +click 2180 350 +expect lens_count 1 +key escape +console goto memory {head} +frames 40 +# Both controls are available directly on the memory pane. +click 1240 822 +expect unit 2 +click 1240 822 +expect unit 4 +click 1240 822 +expect unit 8 +click 1278 822 +expect number_format unsigned +click 1278 822 +expect number_format signed +click 1278 822 +expect number_format float +click 1278 822 +expect number_format hex +''' + for unit in (1, 2, 4, 8): + for fmt in ('hex', 'unsigned', 'signed') + (('float',) if unit >= 4 else ()): + commands += f'console memory-format {unit} {fmt}\nexpect unit {unit}\nexpect number_format {fmt}\nframes 2\n' + commands += f'''console memory-format 8 hex +frames 10 +screenshot {out / 'words.png'} +# Historical browsing never requests bytes from a live target. +key left_bracket +expect following false +print stops +console lens {head} +frames 30 +wheel 1600 220 -20 +frames 30 +print stops +expect execution 1 +key escape +expect-no-log CommandFailed +expect-no-log backdrop shader +''' + script.write_text(commands) + args = [str(a.gui), '--fresh', '--size', '2240x1260', '--state', str(out / 'session.state'), '--script', str(script)] + if not a.native: + args.append('--headless') + run = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + stdout, stderr = run.communicate(timeout=100) + (out / 'run.log').write_text(stdout + stderr) + assert run.returncode == 0, stderr + first = int(re.search(r'lenses\[0\].first = (\d+)', stderr)[1]) + assert first > code, (first, code) + stops = re.findall(r'stops = (\d+)', stderr) + assert len(stops) == 2 and stops[0] == stops[1], stops + for recording in Path('/tmp').glob(f'ztrace-gui-{run.pid}-*.ztrace'): + recording.unlink() + print(('Native' if a.native else 'Headless') + ': code/data lenses, context scrolling, pointer recursion, memory formats and historical isolation passed') diff --git a/gui/test/restart.py b/gui/test/restart.py index 166d8e3..a9447b5 100644 --- a/gui/test/restart.py +++ b/gui/test/restart.py @@ -59,6 +59,14 @@ expect stops 1 if zoom == 200: # Tiny overlays reveal the new lens's header and keep its close control reachable. commands += 'key z\nexpect lens_count 1\nframes 30\nclick 250 406\nexpect lens_count 2\nexpect lenses[1].cycle true\nframes 30\nclick 700 406\nexpect lens_count 1\nkey escape\n' + # Native glass shares the canvas: changing font size must not resize it. + commands += 'move 0 0\nkey z\nframes 10\n' + for cycle in range(3): + for zoom in (60, 200, 100): + shot = out / f'glass-{cycle}-{zoom}.png' + images.append(shot) + commands += f'console set zoom {zoom}\nframes 5\nscreenshot {shot}\n' + commands += 'key escape\n' commands += '''hold left_ctrl key minus release left_ctrl -- cgit v1.3