summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--anim/src/context.zig14
-rw-r--r--anim/test/gallery/none.pngbin223411 -> 223173 bytes
-rw-r--r--src/trace/Debugger.zig22
-rw-r--r--src/trace/debugger_test.zig12
4 files changed, 45 insertions, 3 deletions
diff --git a/anim/src/context.zig b/anim/src/context.zig
index 2e86399..7740792 100644
--- a/anim/src/context.zig
+++ b/anim/src/context.zig
@@ -245,12 +245,22 @@ pub fn callArguments(u: ui.Ui, rec: *const Recording, open: []const Recording.Ca
/// Where frame `i` is in the program's source, `file:line`: the newest at
/// the moment's own line, when the moment is on one (in a library it is
-/// not); an older one where the recording knows its return address's.
+/// not); an older one on its call's line, or where the recording only
+/// knows a line near its return address, that one.
pub fn frameWhere(u: ui.Ui, rec: *const Recording, moment: u64, i: usize, pc: u64) []const u8 {
- const line = if (i == 0) rec.ownLine(moment) else rec.lineOf(pc);
+ const line = if (i == 0) rec.ownLine(moment) else callLine(rec, moment, pc) orelse rec.lineOf(pc);
return if (line) |l| u.print("{s}:{d}", .{ rec.file, l }) else "";
}
+/// The line of the call that returns to `ret`, where the recording has it:
+/// an outer frame is on its call's line, not on the one it returns to.
+fn callLine(rec: *const Recording, moment: u64, ret: u64) ?u32 {
+ var buf: [256]u8 = undefined;
+ const after = rec.instruction(moment, ret, &buf) orelse return null;
+ if (after.back == 0) return null;
+ return (rec.instruction(moment, ret - after.back, &buf) orelse return null).line;
+}
+
/// A frame's name: its function's (no offset), or its module's and offset where there is no symbol.
pub fn frameName(u: ui.Ui, rec: *const Recording, pc: u64) []const u8 {
const name = rec.strings.get(pc) orelse return u.print("{x}", .{pc});
diff --git a/anim/test/gallery/none.png b/anim/test/gallery/none.png
index 098b50a..e4e3cb4 100644
--- a/anim/test/gallery/none.png
+++ b/anim/test/gallery/none.png
Binary files differ
diff --git a/src/trace/Debugger.zig b/src/trace/Debugger.zig
index b0ebcba..a38c337 100644
--- a/src/trace/Debugger.zig
+++ b/src/trace/Debugger.zig
@@ -616,12 +616,32 @@ fn emitTelescope(d: *Debugger) !void {
const frame = try d.snap(fp, 16);
if (frame.len < 16) break;
const next = std.mem.readInt(u64, frame[0..8], .little);
- try d.chase(std.mem.readInt(u64, frame[8..16], .little));
+ const ret = std.mem.readInt(u64, frame[8..16], .little);
+ try d.chase(ret);
+ try d.emitCall(ret);
if (next <= fp) break;
fp = next;
}
}
+/// The call that returns to `ret`, and the instruction there, recorded as
+/// instructions: an outer frame is on its call's line, `back` from `ret`.
+fn emitCall(d: *Debugger, ret: u64) !void {
+ const insnAt = d.disasm orelse return;
+ if (d.code_len.contains(ret)) return;
+ const sym = d.syms.symbolAt(ret) orelse return;
+ if (sym.size == 0 or sym.size > 1 << 16 or ret == sym.addr) return;
+ const starts = try d.instructions(sym, insnAt);
+ const k = std.sort.binarySearch(u32, starts, @as(u32, @intCast(ret - sym.addr)), struct {
+ fn order(want: u32, have: u32) std.math.Order {
+ return std.math.order(want, have);
+ }
+ }.order) orelse return;
+ if (k == 0) return;
+ _ = try d.emitInstruction(insnAt, sym.addr + starts[k - 1], if (k > 1) @intCast(starts[k - 1] - starts[k - 2]) else 0);
+ _ = try d.emitInstruction(insnAt, ret, @intCast(starts[k] - starts[k - 1]));
+}
+
/// Follows `value` as a pointer: a pointer into code gets its name and
/// ends the chain, any other readable target is recorded (32 bytes: a word
/// to follow, and enough to tell a string) and followed.
diff --git a/src/trace/debugger_test.zig b/src/trace/debugger_test.zig
index 370876a..512dc6f 100644
--- a/src/trace/debugger_test.zig
+++ b/src/trace/debugger_test.zig
@@ -130,6 +130,18 @@ test "a recording by `ztrace record` has the line of each instruction round the
} else return error.NoCall;
try std.testing.expectEqual(@as(?u8, 1), call.params);
try std.testing.expectEqual(@as(u32, 5), call.line.?.line);
+ // The frame that called fib is on its call's line: the call is recorded, `back` from where it returns.
+ const tids = try m.threads(gpa);
+ defer gpa.free(tids);
+ const regs = (try m.regs(tids[0])).?;
+ var chain: [4]u64 = undefined;
+ const frames = try zt.telescope.backtrace(m, &regs, &chain);
+ try std.testing.expect(frames.len >= 2);
+ const after = (try zt.telescope.instruction(m, frames[1], &text)).?;
+ try std.testing.expect(after.back != 0);
+ const caller = (try zt.telescope.instruction(m, frames[1] - after.back, &text)).?;
+ try std.testing.expect(std.mem.startsWith(u8, caller.text, "call"));
+ try std.testing.expect(caller.line != null);
}
test "step walks the source lines, in and out of calls, as gdb does" {