diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-11 14:43:13 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-11 16:17:33 -0300 |
| commit | 3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6 (patch) | |
| tree | f1bc91879a447f178dfaba39d0df107d01e557bd /anim/src/disasm.zig | |
| parent | a72831d5c322078260314c305ddd940e4967947d (diff) | |
| download | computeranim-3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6.tar.gz computeranim-3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src/disasm.zig')
| -rw-r--r-- | anim/src/disasm.zig | 73 |
1 files changed, 48 insertions, 25 deletions
diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index 282c66e..be3452f 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -37,8 +37,9 @@ pub const Insn = struct { text: []const u8, /// Past the function's end. outside: bool = false, - /// The line of the program's source it was compiled from. + /// The line it was compiled from, of `src` (`Recording.sources`). line: ?u32 = null, + src: u16 = 0, /// A direct call's callee's parameter count. params: ?u8 = null, /// A graph's row: its block's head carries the address, the row its offset. @@ -72,6 +73,8 @@ pub const Disasm = struct { cursor: cursors.Cursor, stage: *const Stage, focus: bool = false, + /// On the map its box is as long as what it shows (not where it is a strip's column alone). + measures: bool = true, pub fn draw(d: *const Disasm, f: *sk.Frame, placed: anim.Placed) void { const box = d.stage.box(placed, .disasm); @@ -79,13 +82,12 @@ pub const Disasm = struct { const now = d.cursor.now(placed); const rec = d.cursor.rec; const room = theme.layout.rowsIn(box.h); - const above = (room -| 1) / 2; // The mark: it moves last, with the source's and rip. const going = now.advancing(); - const from = listing(u, rec, now.marks[0], room, above); - const to = listing(u, rec, now.marks[1], room, above); + const from = listing(u, rec, now.marks[0], room); + const to = listing(u, rec, now.marks[1], room); // On the map its box is as long as the instructions the recording has round the pc. - if (ui.mapping) map.measure(.disasm, listing(u, rec, now.marks[1], theme.map.disasm_rows, (theme.map.disasm_rows - 1) / 2).rows.len); + if (ui.mapping and d.measures) map.measure(.disasm, listing(u, rec, now.marks[1], theme.map.disasm_rows).rows.len); const pc = [2]u64{ rec.register(now.marks[0], "rip"), rec.register(now.marks[1], "rip") }; // The function's name: one that changes with the advance crossfades over it. @@ -111,6 +113,7 @@ pub const Disasm = struct { var merged: []const Insn = to.rows; var offsets = [2]f32{ 0, 0 }; var fade: f32 = 1; + var faded_through = false; var shown = to; if (pc[0] != pc[1] and going < 1) { if (merge(u, from.rows, to.rows)) |both| { @@ -120,6 +123,7 @@ pub const Disasm = struct { merged = if (going < 0.5) from.rows else to.rows; shown = if (going < 0.5) from else to; fade = @abs(2 * going - 1); + faded_through = true; } } const scroll = std.math.lerp(offsets[0], offsets[1], cursors.glide(going)); @@ -137,7 +141,9 @@ pub const Disasm = struct { // Which moment the current mark stands for, and the three steps before it. const base: usize = if (going >= 0.5) 0 else 1; - const current_line = rec.own[now.marks[if (going >= 0.5) 1 else 0]]; + // The line the source panel is on, in the file it shows: rows of that file carry their numbers. + const current = rec.shown[now.marks[if (going >= 0.5) 1 else 0]]; + const current_line = current.line; // The addresses' shared digits, of the window the mark is in: they // change with the advance, not before it. const lead = blk: { @@ -190,12 +196,12 @@ pub const Disasm = struct { var last_line: ?u32 = null; // A source of many lines (SQLite's) has wider numbers, as wide as // its largest: what is right of them moves right by as much. - const widen = rows.numberRoom(rec.line_count); + const widen = rows.numberRoom(rec.most_lines); // The thread's runs: of the line the mark leaves and of the one it // goes to, each a span of rows; published sliding from the one to // the other with the advance (`threadRuns`). var runs: [2]Runs = .{ .{}, .{} }; - const lines_of = [2]u32{ rec.own[now.marks[0]], rec.own[now.marks[1]] }; + const lines_of = [2]Recording.Shown{ rec.shown[now.marks[0]], rec.shown[now.marks[1]] }; var lanes: [2]?f32 = .{ null, null }; // A call's arguments hang in the annotation column of the rows under it. var covered: usize = 0; @@ -206,9 +212,9 @@ pub const Disasm = struct { const rules = graph.Rules.init(u.f.scratch, rec, now.marks, pc, going); for (merged, 0..) |row, j| { const y = top + (@as(f32, @floatFromInt(j)) - scroll) * m.row; - const line = if (row.outside) null else row.line; + const line = if (row.outside or row.src != current.src) null else row.line; // The thread: the current line's runs of instructions. - for (&runs, lines_of) |*r, of| r.add(line != null and line.? == of and mark_shows >= 1, @max(y, top), @min(y, box.h - m.pad)); + for (&runs, lines_of) |*r, of| r.add(!row.outside and row.line != null and row.line.? == of.line and row.src == of.src and mark_shows >= 1, @max(y, top), @min(y, box.h - m.pad)); // A row wholly above the body (the window it scrolls from or to) // does not take the line number from the first row shown. const above_body = y + m.row <= top + 0.5; @@ -222,8 +228,8 @@ pub const Disasm = struct { const was = if (is_pc) null else ran[j]; if (was) |r| lit.trail(c.mark, y, r.k); const state: State = if (is_pc) .current else if (was) |r| .{ .ran = r } else .ahead; - const hangs = d.insn(lit, now, row, y, box.w, widen, line, line != last_line, current_line, lead, state, base, covered > 0, window, echo); - rules.draw(lit, row.addr, y, box.w, covered == 0 and !row.outside and !d.noted(lit, now, row, y, state, base, window, echo)); + const hangs = d.insn(lit, now, row, y, map.content(box.w), widen, line, line != last_line, current_line, lead, state, base, covered > 0, window, echo); + rules.draw(lit, row.addr, y, map.content(box.w), covered == 0 and !row.outside and !d.noted(lit, now, row, y, state, base, window, echo)); covered = @max(covered -| 1, hangs); last_line = if (above_body) null else line; if (jumped == row.addr and !is_pc) lanes[0] = y; @@ -231,13 +237,16 @@ pub const Disasm = struct { } const end_y = @min(top + (@as(f32, @floatFromInt(merged.len)) - scroll) * m.row, box.h - m.pad); for (&runs) |*r| r.add(false, end_y, end_y); - threadRuns(u, box.w, runs, if (lines_of[0] == lines_of[1]) 1 else cursors.standard(going)); + threadRuns(u, box.w, runs, if (std.meta.eql(lines_of[0], lines_of[1])) 1 else cursors.standard(going)); if (lanes[0] != null and lanes[1] != null and lanes[0].? != lanes[1].?) { const ya = lanes[0].? + m.row / 2; const yb = lanes[1].? + m.row / 2; lit.route(&.{ .{ 38, ya }, .{ c.jump_lane, ya }, .{ c.jump_lane, yb }, .{ 39, yb } }, theme.color.trail[0], .{ .width = theme.stroke.rule, .head = .{ 7, 8 }, .radius = 4 }); } context.veiled(u, box, now.veil); + // A window going to another column (another function) fades through, and its strip with it. + const column_changes = faded_through and (from.rows.len == 0 or to.rows.len == 0 or !(map.inColumn(.disasm, .{ from.rows[0].addr, from.rows[from.rows.len - 1].addr }) and map.inColumn(.disasm, .{ to.rows[0].addr, to.rows[to.rows.len - 1].addr }))); + map.strip(.disasm, if (column_changes) u.faded(map.through(now, now.plan.travel)) else u, box); } pub const State = union(enum) { @@ -272,7 +281,7 @@ pub const Disasm = struct { const name = if (rec.strings.get(row.addr)) |n| n[0 .. std.mem.lastIndexOfScalar(u8, n, '+') orelse n.len] else ""; const ops = shorn(u, row); const x = if (name.len > 0) annotationX(operandsWidth(u, row, ops, ""), room, @as(f32, @floatFromInt(name.len)) * adv) else room + gap; - operands(u, row, ops, "", base_y, (if (covered) c.annotation else x) - gap - c.operands, t.faint); + operands(u, row, ops, "", base_y, (if (covered) annotationColumn() else x) - gap - c.operands, t.faint); u.text(.mono, size, x, base_y, name, t.faint); return 0; } @@ -286,21 +295,21 @@ pub const Disasm = struct { const pad = row.padding(); u.text(.mono_bold, size, c.mnemonic, base_y, row.mnemonic(), if (pad) t.faint else theme.color.code.keyword); // How wide the annotation is, drawn where nothing shows; then where it goes. - const need = d.annotation(u.faded(0), now, row, y, c.annotation, std.math.inf(f32), state, base, window, echo); + const need = d.annotation(u.faded(0), now, row, y, annotationColumn(), std.math.inf(f32), state, base, window, echo); // When the operands and the annotation do not both fit: the // annotation moves left (never past its column), then the operands give way. const ops = shorn(u, row); const stub = if (target(row)) |to| pltName(u, rec, to) else ""; var x = room + gap; - if (need.drawn) x = annotationX(operandsWidth(u, row, ops, stub), room, need.end - c.annotation); - operands(u, row, ops, stub, base_y, (if (covered) @min(x, c.annotation) else x) - gap - c.operands, if (pad) t.faint else theme.color.code.plain); + if (need.drawn) x = annotationX(operandsWidth(u, row, ops, stub), room, need.end - annotationColumn()); + operands(u, row, ops, stub, base_y, (if (covered) @min(x, annotationColumn()) else x) - gap - c.operands, if (pad) t.faint else theme.color.code.plain); // Its annotation column holds the arguments of a call above: its own gives way. return if (need.drawn and !covered) d.annotation(u, now, row, y, x, room, state, base, window, echo).hangs else 0; } /// Whether `row` has an annotation: where it has none, its block's visits may be ranged right. pub fn noted(d: *const Disasm, u: ui.Ui, now: cursors.Now, row: Insn, y: f32, state: State, base: usize, window: [2]u64, echo: ?Echo) bool { - return d.annotation(u.faded(0), now, row, y, c.annotation, std.math.inf(f32), state, base, window, echo).drawn; + return d.annotation(u.faded(0), now, row, y, annotationColumn(), std.math.inf(f32), state, base, window, echo).drawn; } const Note = struct { drawn: bool = false, end: f32 = 0, hangs: usize = 0 }; @@ -809,6 +818,11 @@ pub fn readsFlags(rec: *const Recording, i: u64) u16 { return flagsRead((Insn{ .addr = pc, .len = here.len, .text = here.text }).mnemonic()); } +/// Where an annotation starts: 564 on the map, 540 in a pane with a strip. +fn annotationColumn() f32 { + return if (ui.mapping) c.annotation else c.annotation - theme.strip.cost / 2; +} + /// The gap between the operands and the annotation: a character. const gap = adv; @@ -853,7 +867,7 @@ pub fn threadRuns(u: ui.Ui, w: f32, runs: [2]Runs, p: f32) void { /// after operands `width` wide: at its column, or a character after the /// operands, or (when both do not fit) where it just fits. fn annotationX(width: f32, room: f32, need: f32) f32 { - return @max(c.annotation, @min(c.operands + width + gap, room - need)); + return @max(annotationColumn(), @min(c.operands + width + gap, room - need)); } /// The row in `rows` (in address order) of the instruction at `addr`. @@ -899,7 +913,7 @@ pub fn bareRow(u: ui.Ui, row: Insn, y: f32) void { const base_y = rows.baseline(y); const pad = row.padding(); u.text(.mono_bold, size, c.mnemonic, base_y, row.mnemonic(), if (pad) t.faint else theme.color.code.keyword); - operands(u, row, shorn(u, row), "", base_y, c.annotation - gap - c.operands, if (pad) t.faint else theme.color.code.plain); + operands(u, row, shorn(u, row), "", base_y, annotationColumn() - gap - c.operands, if (pad) t.faint else theme.color.code.plain); } /// Operands as canim draws them (design/README.md, `insn` and `width`): @@ -1056,15 +1070,24 @@ fn full(name: []const u8) ?[]const u8 { /// The window at moment `i`: up to `above` of the function's own /// instructions over the pc (fewer near its start), the pc's, and as many /// after it as fill `room`; past the function's end, `outside`. -fn listing(u: ui.Ui, rec: *const Recording, i: u64, room: usize, above: usize) Listing { - return listingAt(u, rec, i, rec.register(i, "rip"), room, above); +/// `room` rows round the pc at moment `i`: in a pane, as many above as +/// below; on the map, the function from its start where the pc is in its +/// first three quarters of the rows (a strip's column stays still while +/// the pc walks it), else round the pc. +fn listing(u: ui.Ui, rec: *const Recording, i: u64, room: usize) Listing { + const pc = rec.register(i, "rip"); + if (ui.mapping) { + const whole = listingAt(u, rec, i, pc, room, room * 3 / 4); + if (whole.pc < room * 3 / 4) return whole; + } + return listingAt(u, rec, i, pc, room, (room -| 1) / 2); } /// The same round the instruction at `pc` (in the window, `Listing.pc`). pub fn listingAt(u: ui.Ui, rec: *const Recording, i: u64, pc: u64, room: usize, above: usize) Listing { const out = u.f.scratch.alloc(Insn, room) catch return .{ .rows = &.{}, .pc = 0 }; var buf: [256]u8 = undefined; - var up: [16]Insn = undefined; + var up: [theme.map.disasm_rows]Insn = undefined; var n_up: usize = 0; var addr = pc; while (n_up < @min(above, up.len)) { @@ -1072,7 +1095,7 @@ pub fn listingAt(u: ui.Ui, rec: *const Recording, i: u64, pc: u64, room: usize, if (here.back == 0) break; addr -= here.back; const one = rec.instruction(i, addr, &buf) orelse break; - up[n_up] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .line = one.line, .params = one.params }; + up[n_up] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .line = one.line, .src = one.src, .params = one.params }; n_up += 1; } var n: usize = 0; @@ -1083,7 +1106,7 @@ pub fn listingAt(u: ui.Ui, rec: *const Recording, i: u64, pc: u64, room: usize, while (n < room) : (n += 1) { const one = rec.instruction(i, addr, &buf) orelse break; if (n > pc_row and one.back == 0) outside = true; - out[n] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .outside = outside, .line = one.line, .params = one.params }; + out[n] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .outside = outside, .line = one.line, .src = one.src, .params = one.params }; addr += one.len; } return .{ .rows = out[0..n], .pc = pc_row }; |
