summaryrefslogtreecommitdiff
path: root/src/trace/telescope.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/trace/telescope.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/trace/telescope.zig')
-rw-r--r--src/trace/telescope.zig13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/trace/telescope.zig b/src/trace/telescope.zig
index efc6e43..ba7caa3 100644
--- a/src/trace/telescope.zig
+++ b/src/trace/telescope.zig
@@ -90,11 +90,13 @@ pub fn chase(m: Moment, value: u64, links: []Link, text: []u8) ![]Link {
}
/// The instruction at `addr` as the recording has it (`event.codeId`): its
-/// length and its text. Null where none was recorded.
-pub fn instruction(m: Moment, addr: u64, buf: []u8) !?struct { len: u8, text: []const u8 } {
+/// length, the length of the one before it (0 when the recording does not
+/// know: the one before is then not at `addr - back`), and its text. Null
+/// where none was recorded.
+pub fn instruction(m: Moment, addr: u64, buf: []u8) !?struct { len: u8, back: u8, text: []const u8 } {
const s = (try m.string(event.codeId(addr), buf)) orelse return null;
- if (s.len == 0) return null;
- return .{ .len = s[0], .text = s[1..] };
+ if (s.len < 2) return null;
+ return .{ .len = s[0], .back = s[1], .text = s[2..] };
}
/// The call chain of a thread at a moment, by frame pointer, from what the
@@ -137,7 +139,7 @@ test "a chain is followed to a string, to code, to a number, and no further than
try map(&rec, 0x900000, 0x1000, 3, "");
try rec.emit(.{ .kind = .alloc, .tid = 1, .a = .{ 0x900010, 32, 0, 0, 0, 0 } }, "");
try rec.emit(.{ .kind = .string, .a = .{ 0x400123, 0, 0, 0, 0, 0 } }, "main+4");
- try rec.emit(.{ .kind = .string, .a = .{ event.codeId(0x400123), 0, 0, 0, 0, 0 } }, "\x03mov rbp, rsp");
+ try rec.emit(.{ .kind = .string, .a = .{ event.codeId(0x400123), 0, 0, 0, 0, 0 } }, "\x03\x01mov rbp, rsp");
const word = struct {
fn at(r: *store.Recorder, addr: u64, value: u64) !void {
try r.emit(.{ .kind = .mem_write, .tid = 1, .a = .{ addr, 8, 0, 0, 0, 0 } }, std.mem.asBytes(&value));
@@ -183,6 +185,7 @@ test "a chain is followed to a string, to code, to a number, and no further than
const insn = (try instruction(m, 0x400123, &text)).?;
try std.testing.expectEqual(@as(u8, 3), insn.len);
+ try std.testing.expectEqual(@as(u8, 1), insn.back);
try std.testing.expectEqualStrings("mov rbp, rsp", insn.text);
try std.testing.expect(try instruction(m, 0x400126, &text) == null);
}