summaryrefslogtreecommitdiff
path: root/src/trace/telescope.zig
diff options
context:
space:
mode:
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);
}