diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-13 01:24:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-13 01:34:46 -0300 |
| commit | 5a40dca5adb6e9e650f55f3ec6f254a13bf50493 (patch) | |
| tree | 5fdffebd75ed3fbac1eae5dec0a3f2d491450342 /gui/test/inspection.py | |
| parent | 4b4113a0217ee27c78e7efddb66ff5a455d49083 (diff) | |
| download | computeranim-5a40dca5adb6e9e650f55f3ec6f254a13bf50493.tar.gz computeranim-5a40dca5adb6e9e650f55f3ec6f254a13bf50493.zip | |
debugger: align source and add rich Vim-style navigation
Diffstat (limited to 'gui/test/inspection.py')
| -rw-r--r-- | gui/test/inspection.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/gui/test/inspection.py b/gui/test/inspection.py new file mode 100644 index 0000000..368b6aa --- /dev/null +++ b/gui/test/inspection.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +"""Real-target checks for read-only inspection and explicit GDB JIT ELF import.""" +import argparse +import json +import os +from pathlib import Path +import re +import select +import subprocess +import tempfile + +ROOT = Path(__file__).resolve().parents[2] +p = argparse.ArgumentParser(description=__doc__) +p.add_argument('--ztrace', type=Path, default=ROOT / 'gui/zig-out/bin/ztrace') +p.add_argument('--d8', type=Path) +a = p.parse_args() +a.ztrace = a.ztrace.resolve() + +with tempfile.TemporaryDirectory(prefix='ztrace-inspect-') as directory: + work = Path(directory) + small = work / 'loop' + subprocess.run(['cc', '-g', '-O0', str(ROOT / 'gui/targets/loop.c'), '-o', str(small)], check=True) + programs = [('c', [str(small)])] + js = work / f'gui-inspect-{os.getpid()}.js' + if a.d8: + js.write_bytes((ROOT / 'gui/targets/jit.js').read_bytes()) + programs.append(('v8', [str(a.d8.resolve()), '--allow-natives-syntax', '--no-concurrent-recompilation', + '--no-maglev', '--gdbjit', '--gdbjit-dump', '--gdbjit-dump-filter=jitWork', + '--print-opt-code', '--print-opt-code-filter=jitWork', js.name])) + for name, argv in programs: + recording = work / (name + '.ztrace') + with (work / (name + '.log')).open('w+') as log: + target = subprocess.Popen([str(a.ztrace), 'serve', str(recording), '--', *argv], + cwd=work, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=log, bufsize=0) + pending = b'' + def read(): + global pending + while b'\n' not in pending: + assert select.select([target.stdout], [], [], 30)[0], 'controller timeout' + data = os.read(target.stdout.fileno(), 4096) + assert data, 'controller exited' + pending += data + line, pending = pending.split(b'\n', 1) + return json.loads(line) + def command(text, status='stopped'): + target.stdin.write((text + '\n').encode()) + while True: + answer = read() + if answer['status'] != 'running': + assert answer['status'] == status, answer + return answer + elf = None + try: + assert read()['status'] == 'stopped' + if name == 'c': + command('break work') + stopped = command('continue') + else: + command('continue') + log.seek(0) + assembly = log.read() + address = int(re.search(r'^(0x[0-9a-f]+)\s+[0-9a-f]+\s+[0-9a-f]+\s+addl r8,r11', assembly, re.M)[1], 16) + command('signal 0') + command('break *' + hex(address)) + stopped = command('continue') + assert stopped['pc'] == address + elf, = Path('/tmp').glob('elfdumpjitWork ' + js.name + ':*.o') + loaded = command('symbols ' + str(elf)) + assert loaded['pc'] == stopped['pc'], loaded + show = subprocess.check_output([str(a.ztrace), 'show', str(recording), '-1'], text=True) + assert str(js) + ':6:' in show, show[:2000] + assert '(gui-inspect-' in show, 'instruction source metadata missing' + for kind, count in [('code', 128), ('memory', 256)]: + seen = command(f'inspect {kind} {stopped["pc"]} {count}') + assert seen['pc'] == stopped['pc'], seen + for request in ['inspect code 0 0', 'inspect code 0 257', 'inspect memory 0 4097', 'inspect cheese 0 8']: + failed = command(request, 'failed') + assert failed['pc'] == stopped['pc'] + seen = command('inspect memory 0 16') + assert seen['pc'] == stopped['pc'] + assert 'State:\tt' in Path(f'/proc/{stopped["pid"]}/status').read_text() + moved = command('stepi') + assert moved['pc'] != stopped['pc'] + print(name + ': inspection preserved PC; bounds rejected; stepping still works' + ('; real JIT source line recorded' if name == 'v8' else '')) + finally: + if target.poll() is None: + target.stdin.write(b'quit\n') + target.wait(timeout=30) + target.stdin.close() + target.stdout.close() + if elf is not None: + elf.unlink(missing_ok=True) |
