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.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/trace/telescope.zig b/src/trace/telescope.zig
index f4cf09a..efc6e43 100644
--- a/src/trace/telescope.zig
+++ b/src/trace/telescope.zig
@@ -97,6 +97,25 @@ pub fn instruction(m: Moment, addr: u64, buf: []u8) !?struct { len: u8, text: []
return .{ .len = s[0], .text = s[1..] };
}
+/// The call chain of a thread at a moment, by frame pointer, from what the
+/// recording holds of its stack: the pc, then each return address outwards.
+/// It ends where the frames were not recorded.
+pub fn backtrace(m: Moment, regs: *const event.Regs, out: []u64) ![]u64 {
+ const Memory = struct {
+ m: Moment,
+ pub fn read(mem: @This(), addr: u64, buf: []u8) usize {
+ var known: [16]bool = undefined;
+ mem.m.read(addr, buf, known[0..buf.len]) catch return 0;
+ return if (std.mem.indexOfScalar(bool, known[0..buf.len], false) == null) buf.len else 0;
+ }
+ };
+ // At a function's first instruction its frame is not made yet: the
+ // return address is on top of the stack.
+ var name: [256]u8 = undefined;
+ const at_entry = if (try m.string(regs.rip, &name)) |n| std.mem.endsWith(u8, n, "+0") else false;
+ return @import("Debugger.zig").backtrace(Memory{ .m = m }, regs, at_entry, out);
+}
+
test "a chain is followed to a string, to code, to a number, and no further than is known" {
const gpa = std.testing.allocator;
var tmp = std.testing.tmpDir(.{});