summaryrefslogtreecommitdiff
path: root/src/cli/disasm.zig
blob: 40cab9d684c48bb8a2bee69397125b7a593906a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//! 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) 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);
    if (len == 0) return null;
    return .{ .len = @intCast(len), .text = std.mem.sliceTo(text, 0), .touches = touches[0..count] };
}