From 3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 11 Nov 2026 14:43:13 -0300 Subject: canim: a minimap in each pane; source wherever it can be had, libc's included From the user. Each pane with more than it shows carries a strip of its whole column at its right edge, the pane's window outlined and what happens off it marked there; the corner minimap is gone and the dive folds each column of the map into its pane's strip. The source panel follows the pc into any file the build has: glibc's own, from the distro's debuginfod by an optional step that caches them by build id (zig build sources; nothing else touches the network), and musl's, from Zig's lib directory. The syscalls scene shows open64.c on the way down, and a new scene follows the same call through a Zig-built musl. A graph's counts and inks are as of the moment shown. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa --- anim/src/descent.zig | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'anim/src/descent.zig') diff --git a/anim/src/descent.zig b/anim/src/descent.zig index 53d46c5..5dd156c 100644 --- a/anim/src/descent.zig +++ b/anim/src/descent.zig @@ -247,8 +247,10 @@ pub const Descent = struct { // Which rows ran in the last three steps: the trail. const ran = recentRows(a, now, if (going >= 0.5) 0 else 1); - const current_line = rec.own[marked]; - const widen0 = rows.numberRoom(rec.line_count); + // The line the source panel is on, in the file it shows: rows of that file carry their numbers. + const current = rec.shown[marked]; + const current_line = current.line; + const widen0 = rows.numberRoom(rec.most_lines); var covered: usize = 0; var covered_before: usize = 0; var runs: disasm.Runs = .{}; @@ -268,7 +270,7 @@ pub const Descent = struct { .head => |h| { v.fill(.{ .x = theme.stroke.rule, .y = y, .w = box.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); v.text(.sans_medium, theme.size.sans.micro, c.address, y + 18, h.name, t.primary); - v.text(.sans, theme.size.sans.micro, box.w - m.side - v.width(.sans, theme.size.sans.micro, h.note), y + 18, h.note, t.faint); + v.text(.sans, theme.size.sans.micro, map.content(box.w) - m.side - v.width(.sans, theme.size.sans.micro, h.note), y + 18, h.note, t.faint); covered -|= 1; }, .more => |words| { @@ -286,7 +288,7 @@ pub const Descent = struct { }; const lead = ui.shared(addrs[0..n]); const wide = @as(f32, @floatFromInt(@max(ui.digits(row.addr), 7) - 7)) * adv; - const line = if (row.outside) null else row.line; + const line = if (row.outside or row.src != current.src) null else row.line; const state: disasm.Disasm.State = switch (p.item.state) { // The row the plaque has not reached yet is ahead. .current => if (p.old == null or p.old.?.state != .current) (if (going >= 0.5) .current else .ahead) else if (p.new == null or p.new.?.state != .current) (if (going < 0.5) .current else .ahead) else .current, @@ -309,10 +311,10 @@ pub const Descent = struct { runs.add(line != null and line.? == current_line, y, y + m.row); // A row drawn twice (crossfading) counts once for the arguments that hang over the rows under it. const covers = if (p.twin) covered_before > 0 else covered > 0; - const hangs = dd.insn(v, now, row, y, box.w, widen0 + wide, line, line != last_line, current_line, lead, state, base, covers, .{ addrs[0], addrs[n -| 1] }, null); + const hangs = dd.insn(v, now, row, y, map.content(box.w), widen0 + wide, line, line != last_line, current_line, lead, state, base, covers, .{ addrs[0], addrs[n -| 1] }, null); const w = @min(p.item.window, rules.len - 1); if (rules[w] == null) rules[w] = graph.Rules.init(u.f.scratch, rec, now.marks, .{ row.addr, row.addr }, going); - rules[w].?.draw(v, row.addr, y, box.w, !covers and !row.outside and !dd.noted(v, now, row, y, state, base, .{ addrs[0], addrs[n -| 1] }, null)); + rules[w].?.draw(v, row.addr, y, map.content(box.w), !covers and !row.outside and !dd.noted(v, now, row, y, state, base, .{ addrs[0], addrs[n -| 1] }, null)); if (!p.twin) covered_before = covered; covered = if (p.twin) @max(covered, hangs) else @max(covered -| 1, hangs); last_line = line; @@ -343,10 +345,13 @@ pub const Descent = struct { const yb = p.y + m.row / 2; u.route(&.{ .{ 14, ya }, .{ 14, yb }, .{ c.address - 4, yb } }, t.primary, .{ .width = theme.stroke.rule, .head = .{ 7, 8 }, .radius = 4, .progress = cursors.standard(drawn) }); } - map.window(.disasm, .{ first(after), last(after) }, .{ first(before), last(before) }, cursors.glide(going)); + // Its strip is the deepest window's function's column, that window framed on it. + map.window(.disasm, deepest(after), deepest(before), cursors.glide(going)); if (pc_y[1] orelse pc_y[0]) |y| ties.anchor(u, .pc, .{ .x = 0, .y = y, .w = theme.metric.plaque.pc, .h = m.row }); kernel(u, now, box, under orelse top + @as(f32, @floatFromInt(room -| 3)) * m.row, pc_y[0] orelse pc_y[1]); context.veiled(u, box, now.veil); + // Going down or up, the strip is another function's column: it fades through as the mark lands (24 f). + map.strip(.disasm, if (kind == .same) u else u.faded(map.through(now, now.plan.travel + f(12))), box); } }; @@ -380,15 +385,15 @@ fn windowOf(items: anytype, window: u8) @TypeOf(items) { return if (lo < hi) items[lo..hi] else items[0..0]; } -fn first(l: Layout) u64 { - for (l.items) |it| if (it.what == .insn) return it.key; - return 0; -} - -fn last(l: Layout) u64 { - var out: u64 = 0; +/// The first and last instruction of the deepest window of code. +fn deepest(l: Layout) [2]u64 { + var window: u8 = 0; for (l.items) |it| if (it.what == .insn) { - out = it.key; + window = @max(window, it.window); + }; + var out = [2]u64{ std.math.maxInt(u64), 0 }; + for (l.items) |it| if (it.what == .insn and it.window == window) { + out = .{ @min(out[0], it.key), @max(out[1], it.key) }; }; return out; } @@ -600,7 +605,9 @@ fn headNote(u: ui.Ui, rec: *const Recording, i: u64, l: Level) []const u8 { const module = moduleOf(u, rec, i, l.at); if (std.mem.eql(u8, module, "[vdso]")) return "vdso \u{00b7} the kernel's code, run here"; var buf: [256]u8 = undefined; - if ((@import("ztrace").telescope.instruction(rec.moment(i), l.at, &buf) catch null)) |here| if (here.line != null) return rec.file; + // Its source, where the build gave it: the program's own file, or the library's (its entry's: not the header a line of it is inlined from). + const entry = if (@import("ztrace").telescope.function(rec.moment(i), l.at)) |fun| fun.start else l.at; + if (rec.instruction(i, entry, &buf)) |here| if (here.line != null) return if (here.src == 0) rec.file else u.print("{s} \u{00b7} {s}", .{ module, rec.sources[here.src].name() }); return u.print("{s} \u{00b7} no source", .{module}); } -- cgit v1.3