From ed46c51fe127377eb1fde8dee83da984e0f61860 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 14:39:55 -0300 Subject: context: eight instructions above the pc and eight below; where a branch goes A function is decoded once from its start, so the instructions before the pc are known: each instruction's string now says the length of the one before it, and ztrace show prints eight above and eight below, as pwndbg does. A call, a jump or a return at the pc is a branch event with its target (named) and, for a conditional jump, whether the flags take it. --- src/cli/show.zig | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/cli/show.zig') diff --git a/src/cli/show.zig b/src/cli/show.zig index 35cc928..1657644 100644 --- a/src/cli/show.zig +++ b/src/cli/show.zig @@ -93,12 +93,22 @@ pub fn state(arena: std.mem.Allocator, trace: *zt.Trace, index: u64, w: *std.Io. if (comptime std.mem.eql(u8, reg, "eflags")) try w.print("{x}", .{regs.eflags}) else try telescope(m, w, @field(regs, reg), colour); try w.writeAll("\n"); } - // The instructions from the pc on, as far as the recording has them. - var pc = regs.rip; + // The instructions round the pc, as far as the recording has them: + // eight above (inside a function they are known), the pc's, eight below. var text: [192]u8 = undefined; - for (0..8) |i| { + var from = regs.rip; + for (0..8) |_| { + const insn = (try zt.telescope.instruction(m, from, &text)) orelse break; + if (insn.back == 0) break; + from -= insn.back; + } + var pc = from; + var below: usize = 0; + try w.writeAll("\n"); + while (below <= 8) { const insn = (try zt.telescope.instruction(m, pc, &text)) orelse break; - try w.print("{s}{x:0>12} {s}\n", .{ if (i == 0) "\n ► " else " ", pc, insn.text }); + try w.print("{s}{x:0>12} {s}\n", .{ if (pc == regs.rip) " ► " else " ", pc, insn.text }); + if (pc >= regs.rip) below += 1; pc += insn.len; } // The top of the stack, a word a row. -- cgit v1.3