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/disasm.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/cli/disasm.zig (limited to 'src/cli/disasm.zig') diff --git a/src/cli/disasm.zig b/src/cli/disasm.zig new file mode 100644 index 0000000..5c0d27b --- /dev/null +++ b/src/cli/disasm.zig @@ -0,0 +1,12 @@ +//! Disassembly for the debugger: capstone, through src/cli/disasm.c. +const std = @import("std"); +const zt = @import("ztrace"); + +extern fn zt_disasm(code: [*]const u8, len: usize, addr: u64, text: [*]u8, cap: usize) usize; + +/// What `Debugger.disasm` is set to. +pub fn one(code: []const u8, addr: u64, text: []u8) ?zt.Debugger.Insn { + const len = zt_disasm(code.ptr, code.len, addr, text.ptr, text.len); + if (len == 0) return null; + return .{ .len = @intCast(len), .text = std.mem.sliceTo(text, 0) }; +} -- cgit v1.3