summaryrefslogtreecommitdiff
path: root/src/cli/show.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 14:39:55 -0300
committerGabriel Schneider <[email protected]>2026-11-10 14:48:26 -0300
commited46c51fe127377eb1fde8dee83da984e0f61860 (patch)
treeaddbb6b270a22fdca2ac35c8f4094539b83cf21f /src/cli/show.zig
parent97ce7f485fc0419df693fdf16d634e9e9a6085fc (diff)
downloadcomputeranim-ed46c51fe127377eb1fde8dee83da984e0f61860.tar.gz
computeranim-ed46c51fe127377eb1fde8dee83da984e0f61860.zip
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.
Diffstat (limited to 'src/cli/show.zig')
-rw-r--r--src/cli/show.zig18
1 files changed, 14 insertions, 4 deletions
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.