From 147cc03a90af3782936787bf1da54314a2a4e385 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 20:41:07 -0300 Subject: backtrace: an outer frame is on its call's line The debugger records the call each frame returns from, as an instruction with its line; canim reads it. main is at list.c:41 while reverse() runs, not at 42, and the rows of a stop deep in SQLite have their lines. Co-Authored-By: Claude Fable 5.2 --- anim/src/context.zig | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'anim/src') 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}); -- cgit v1.3