summaryrefslogtreecommitdiff
path: root/src/cli/disasm.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/disasm.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/disasm.zig')
-rw-r--r--src/cli/disasm.zig7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/cli/disasm.zig b/src/cli/disasm.zig
index 40cab9d..e096084 100644
--- a/src/cli/disasm.zig
+++ b/src/cli/disasm.zig
@@ -3,12 +3,13 @@ const std = @import("std");
const zt = @import("ztrace");
const Touch = zt.Debugger.Touch;
-extern fn zt_disasm(code: [*]const u8, len: usize, addr: u64, text: [*]u8, cap: usize, regs: ?*const zt.Regs, touches: [*]Touch, count: ?*usize) usize;
+extern fn zt_disasm(code: [*]const u8, len: usize, addr: u64, text: [*]u8, cap: usize, regs: ?*const zt.Regs, touches: [*]Touch, count: ?*usize, branch: ?*zt.Debugger.Branch) usize;
/// What `Debugger.disasm` is set to.
pub fn one(code: []const u8, addr: u64, text: []u8, regs: ?*const zt.Regs, touches: []Touch) ?zt.Debugger.Insn {
var count = touches.len;
- const len = zt_disasm(code.ptr, code.len, addr, text.ptr, text.len, regs, touches.ptr, &count);
+ var branch: zt.Debugger.Branch = .{};
+ const len = zt_disasm(code.ptr, code.len, addr, text.ptr, text.len, regs, touches.ptr, &count, &branch);
if (len == 0) return null;
- return .{ .len = @intCast(len), .text = std.mem.sliceTo(text, 0), .touches = touches[0..count] };
+ return .{ .len = @intCast(len), .text = std.mem.sliceTo(text, 0), .touches = touches[0..count], .branch = branch };
}