From 02aa51a6f54235cf18e627dbbfe21f21e502eb0b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 13:36:32 -0300 Subject: context: disassembly, telescopes and names in every stop; strings as one table For a viewer to show what pwndbg's context shows, the debugger records it while the memory is there: each register and the top of the stack followed as pointers three deep (--telescope), every code address met named, eight instructions from the pc disassembled by capstone (built from source for x86, into the command only; pinned as in 03-codenomicom). zt.telescope reads a chain back with the kind of memory each link points into, and ztrace show prints the context, coloured on a terminal as pwndbg colours. The thirty thousand strings of a small run showed that a string map in each keyframe costs 700 bytes of tree a string: strings are now one table for the recording, appended a batch and read whole at open. fib(12) by instruction with everything on: 9 MB, 71 000 moments/s. --- src/cli/record.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/cli/record.zig') diff --git a/src/cli/record.zig b/src/cli/record.zig index f508ddc..f5281ca 100644 --- a/src/cli/record.zig +++ b/src/cli/record.zig @@ -3,11 +3,13 @@ const std = @import("std"); const zt = @import("ztrace"); const util = @import("util.zig"); +const disasm = @import("disasm.zig"); const fail = util.fail; pub const usage = \\usage: ztrace record [-o FILE] [--by insn|line|syscall|break] [-b WHERE]... [-w WHAT[,LEN]]... - \\ [--stack BYTES] [-s BYTES] [--steps N] [--max-size BYTES] [--strace] + \\ [--stack BYTES] [-s BYTES] [--telescope DEPTH] [--steps N] + \\ [--max-size BYTES] [--strace] \\ [--ring] [--preload LIB] [--alloc] -- PROGRAM [ARGS] \\ \\Runs PROGRAM under ptrace into a recording (default out.ztrace). --by @@ -27,6 +29,11 @@ pub const usage = \\that changed since the stop before: the --stack bytes above the stack \\pointer (default 128) and each -w region, an address or a symbol, as \\long as the symbol unless LEN says. + \\At every stop the registers and the top of the stack are also followed + \\as pointers, --telescope deep (default 3, 0 for not at all): what they + \\lead to is recorded, code they lead to is named, and the instructions + \\at the pc are disassembled, so that a viewer can show what pwndbg's + \\context shows. \\--steps ends the recording after N moments, and --max-size when the \\file is that large (default 1G). Sizes take a suffix: 64K, 4G. \\ @@ -44,6 +51,7 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void { var breaks: std.ArrayList([]const u8) = .empty; var watches: std.ArrayList([]const u8) = .empty; var producer: util.Producer = .{}; + var telescope: u8 = 3; var i: usize = 0; while (i < args.len) : (i += 1) { const arg = args[i]; @@ -71,6 +79,9 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void { } else if (std.mem.eql(u8, arg, "-w")) { try watches.append(arena, value.?); i += 1; + } else if (std.mem.eql(u8, arg, "--telescope")) { + telescope = std.fmt.parseInt(u8, value.?, 10) catch fail("--telescope needs a depth\n", .{}); + i += 1; } else if (std.mem.eql(u8, arg, "--steps")) { max_moments = std.fmt.parseInt(u64, value.?, 0) catch fail("--steps needs a number\n", .{}); i += 1; @@ -96,6 +107,8 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void { var d = try zt.Debugger.spawn(init.gpa, init.io, path, argv, if (produced) |p| p.envp.ptr else init.minimal.environ.block.slice.ptr, if (strace) printer.sink() else rec.sink()); defer d.deinit(); if (produced) |p| d.ring = p.ring; + d.disasm = disasm.one; + d.telescope = telescope; d.syscalls = if (by == .syscall) .stop else .record; d.stack_watch = stack_bytes; if (capture) |n| d.capture = n; -- cgit v1.3