summaryrefslogtreecommitdiff
path: root/src/cli/disasm.zig
blob: e096084e165f7935bf97179c16b30d238e04badd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! Disassembly for the debugger: capstone, through src/cli/disasm.c.
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, 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;
    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], .branch = branch };
}