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. --- build/capstone.zig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 build/capstone.zig (limited to 'build') diff --git a/build/capstone.zig b/build/capstone.zig new file mode 100644 index 0000000..ed4f534 --- /dev/null +++ b/build/capstone.zig @@ -0,0 +1,22 @@ +//! Capstone, built from source for x86 alone, with the one function the +//! debugger asks of it (src/cli/disasm.c). After the build in 03-codenomicom. +const std = @import("std"); +const Ctx = @import("../build.zig").Ctx; + +pub fn add(ctx: Ctx) *std.Build.Step.Compile { + const b = ctx.b; + const upstream = b.dependency("capstone", .{}); + // Its tables are large and it is someone else's code: always optimized, never sanitized. + const mod = b.createModule(.{ .target = ctx.target, .optimize = .ReleaseFast, .link_libc = true, .sanitize_c = .off }); + mod.addIncludePath(upstream.path("include")); + mod.addCMacro("CAPSTONE_HAS_X86", ""); + mod.addCMacro("CAPSTONE_USE_SYS_DYN_MEM", ""); + mod.addCSourceFiles(.{ .root = upstream.path(""), .files = &.{ + "cs.c", "Mapping.c", "MCInst.c", "MCInstrDesc.c", + "MCInstPrinter.c", "MCRegisterInfo.c", "SStream.c", "utils.c", + "arch/X86/X86Disassembler.c", "arch/X86/X86DisassemblerDecoder.c", "arch/X86/X86IntelInstPrinter.c", "arch/X86/X86ATTInstPrinter.c", + "arch/X86/X86InstPrinterCommon.c", "arch/X86/X86Mapping.c", "arch/X86/X86Module.c", + } }); + mod.addCSourceFile(.{ .file = b.path("src/cli/disasm.c") }); + return b.addLibrary(.{ .name = "capstone", .linkage = .static, .root_module = mod }); +} -- cgit v1.3