From ebdebe04a76f0302aeb24c1ac08fa9217b1a8257 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 12 Nov 2026 03:17:32 -0300 Subject: canim: the ASan pair finished; a run's crossfade lasts its step The ASan run is recorded --until __asan_report_store1 and the scene finds its moments by what they are, not by count. The pair's tags name their run, ASan's stopped call reads never returned, and both disassemblies start level on their line. At a run a row's crossfade now lasts the whole advance and a chain crossfades when its memory changed: the pair's fast pass had thirteen one-frame changes and has none. Stale videos re-exported. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa --- anim/src/disasm.zig | 93 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 17 deletions(-) (limited to 'anim/src/disasm.zig') diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index 6c9e2dc..f61c721 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -77,6 +77,14 @@ pub const Disasm = struct { measures: bool = true, /// Its window this many rows whatever its box (a `pair`'s stopped run: the box shortens over its lower rows). rows: ?usize = null, + /// A `pair`'s: its run's name before the function's on the tag (`plain ยท fill`). + run: []const u8 = "", + /// A `pair`'s alignment: the pc's line's first row at the window's top while + /// the pc is in its upper half, so that two runs' rows of one line start level. + aligned: bool = false, + /// A `pair`'s stopped run, 0 to 1: the call at the pc never returned. Its + /// row reads so, the plaque goes, the tag says `stopped`. + stopped: ?anim.Value = null, pub fn draw(d: *const Disasm, f: *sk.Frame, placed: anim.Placed) void { const box = d.stage.box(placed, .disasm); @@ -84,13 +92,14 @@ pub const Disasm = struct { const now = d.cursor.now(placed); const rec = d.cursor.rec; const room = d.rows orelse theme.layout.rowsIn(box.h); + const stop = if (d.stopped) |v| placed.value(v) else 0; // The mark: it moves last, with the source's and rip. const going = now.advancing(); - const from = listing(u, rec, now.marks[0], room); - const to = listing(u, rec, now.marks[1], room); + const from = listing(u, rec, now.marks[0], room, d.aligned); + const to = listing(u, rec, now.marks[1], room, d.aligned); // On the map its box is as long as the instructions the recording has round the pc. // (Of the moment the pane shows: a continue's destination repacks the map as the pane goes there, not as it sets off.) - if (ui.mapping and d.measures) map.measure(.disasm, listing(u, rec, now.marks[if (going >= 0.5) 1 else 0], theme.map.disasm_rows).rows.len); + if (ui.mapping and d.measures) map.measure(.disasm, listing(u, rec, now.marks[if (going >= 0.5) 1 else 0], theme.map.disasm_rows, false).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. @@ -98,12 +107,16 @@ pub const Disasm = struct { for (pc, &names) |at_pc, *name| { const sym = rec.strings.get(at_pc) orelse ""; name.* = sym[0 .. std.mem.lastIndexOfScalar(u8, sym, '+') orelse sym.len]; + if (d.run.len > 0) name.* = u.print("{s} \u{00b7} {s}", .{ d.run, name.* }); } const renamed = !std.mem.eql(u8, names[0], names[1]); - const body = u.panel(box.w, box.h, "disassembly", .{ .focus = d.focus, .note = if (renamed) "" else names[1] }); + const body = u.panel(box.w, box.h, "disassembly", .{ .focus = d.focus, .note = if (renamed or stop > 0) "" else names[1] }); if (renamed) { u.faded(1 - going).tagNote(box.w, names[0]); u.faded(going).tagNote(box.w, names[1]); + } else if (stop > 0) { + u.faded(1 - stop).tagNote(box.w, names[1]); + u.faded(stop).tagNote(box.w, u.print("{s} \u{00b7} stopped", .{names[1]})); } const top = body.y + m.pad; // The rows' own room: a row going out of the window passes under the padding, its block's rule too. @@ -161,8 +174,8 @@ pub const Disasm = struct { // The pc's row: gold ember across, a plaque with an ink triangle. const gold = theme.mark(.current); const out = now.fires(.disasm); - if (mark_shows > 0) { - const v = u.faded(mark_shows); + if (mark_shows * (1 - stop) > 0) { + const v = u.faded(mark_shows * (1 - stop)); v.current(.{ .x = theme.stroke.rule, .y = mark_y, .w = box.w - 2 * theme.stroke.rule, .h = m.row }, theme.metric.plaque.pc, out); sk.draw.polygon(u.f, &.{ .{ 20, mark_y + m.row / 2 }, .{ 10, mark_y + 6 }, .{ 10, mark_y + m.row - 6 } }, v.at.pen(.{ .fill = ui.rgb(gold.on_solid) })); ties.anchor(u, .pc, .{ .x = 0, .y = mark_y, .w = theme.metric.plaque.pc, .h = m.row }); @@ -233,9 +246,10 @@ pub const Disasm = struct { ties.anchor(u, .{ .row = row.addr }, .{ .x = 0, .y = y, .w = box.w, .h = m.row }); const is_pc = row.addr == pc[if (going >= 0.5) 1 else 0]; // The row as before the advance and as after it (its state, its trail, its - // line number): where they differ, the one crossfades to the other over the - // advance's middle, never in a frame. - const across: f32 = if (now.resting()) 1 else std.math.clamp((going - 0.25) * 2, 0, 1); + // line number, the moment its annotation reads): where they differ, the one + // crossfades to the other over the advance's middle, at a run over the whole + // advance (the run's ease, 8 f, as a dump's values), never in a frame. + const across: f32 = if (now.resting()) 1 else if (now.plan.gait == .run) going else std.math.clamp((going - 0.25) * 2, 0, 1); var hangs: usize = 0; for ([2]usize{ 1, 0 }) |b| { const cur_s = rec.shown[now.marks[1 - b]]; @@ -248,10 +262,17 @@ pub const Disasm = struct { const cur_o = rec.shown[now.marks[1 - o]]; const line_o = if (row.outside or row.src != cur_o.src) null else row.line; const pc_o = row.addr == pc[1 - o]; - const same = pc_s == pc_o and std.meta.eql(line_s, line_o) and cur_s.line == cur_o.line and std.meta.eql(was_s, if (pc_o) null else rans[1 - o][j]); + const same = pc_s == pc_o and (!pc_s or now.marks[1 - b] == now.marks[1 - o]) and std.meta.eql(line_s, line_o) and cur_s.line == cur_o.line and std.meta.eql(was_s, if (pc_o) null else rans[1 - o][j]); const alpha: f32 = if (same) (if (main) 1 else 0) else if (b == 0) across else 1 - across; if (alpha <= 0) continue; - const v = lit.faded(alpha); + // A stopped run's call (`stopped`): the row as run, `never returned`, crossfading from the pc's. + const gone: f32 = if (pc_s) stop else 0; + if (gone > 0) { + const ran: Ran = .{ .k = 0, .at = now.marks[1 - b] }; + lit.faded(alpha * gone).trail(c.mark, y, ran.k); + _ = d.insn(lit.faded(alpha * gone), now, row, y, map.content(box.w), widen, line_s, line_s != last_line, cur_s.line, lead, .{ .ran = ran }, b, covered > 0, window, echo); + } + const v = lit.faded(alpha * (1 - gone)); if (was_s) |r| v.trail(c.mark, y, r.k); const h = d.insn(v, now, row, y, map.content(box.w), widen, line_s, line_s != last_line, cur_s.line, lead, state, b, covered > 0, window, echo); if (main) hangs = h; @@ -332,7 +353,7 @@ pub const Disasm = struct { // 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 ""; + const stub = if (target(row)) |to| (if (d.never(now, row, state, base)) bareName(u, rec, to) else pltName(u, rec, to)) else ""; var x = room + gap; 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); @@ -340,6 +361,12 @@ pub const Disasm = struct { return if (need.drawn and !covered) d.annotation(u, now, row, y, x, room, state, base, window, echo).hangs else 0; } + /// A stopped run's call that has run and not come back (`stopped`, mock 38). + fn never(d: *const Disasm, now: cursors.Now, row: Insn, state: State, base: usize) bool { + if (d.stopped == null or state != .ran or !std.mem.eql(u8, row.mnemonic(), "call")) return false; + return returned(d.cursor.rec, row, state.ran.at, now.stops[base]) == null; + } + /// 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, annotationColumn(), std.math.inf(f32), state, base, window, echo).drawn; @@ -397,6 +424,8 @@ pub const Disasm = struct { if (stub) note.hangs = a.arguments(row, b.to, moment); return note; } + // A stopped run's call (`stopped`): its callee named on its address, and it never came back. + if (d.never(now, row, state, base)) return a.said("never returned", t.dim); var note = a.callee(b.to, moment); // Its arguments hang under it, a small `reg` a row, as many as the prototype has. if (state == .current) note.hangs = a.arguments(row, b.to, moment); @@ -1225,11 +1254,16 @@ fn cells(u: ui.Ui, x: f32, base_y: f32, bytes: u8) void { /// A PLT stub's name, for a call or a jump to one: `open@plt`; "" otherwise. fn pltName(u: ui.Ui, rec: *const Recording, to: u64) []const u8 { - const name = ui.symbol(u, rec.strings.get(to) orelse return ""); - const stub = name[0 .. std.mem.lastIndexOfScalar(u8, name, '+') orelse name.len]; + const stub = bareName(u, rec, to); return if (std.mem.endsWith(u8, stub, "@plt")) stub else ""; } +/// The function at `to`, by name ("" where it has none). +fn bareName(u: ui.Ui, rec: *const Recording, to: u64) []const u8 { + const name = ui.symbol(u, rec.strings.get(to) orelse return ""); + return name[0 .. std.mem.lastIndexOfScalar(u8, name, '+') orelse name.len]; +} + /// How wide operands `ops` of `row` are, whole (a target with its stub's name `stub`). fn operandsWidth(u: ui.Ui, row: Insn, ops: Operands, stub: []const u8) f32 { if (target(row)) |to| return @as(f32, @floatFromInt(ui.digits(to) + if (stub.len > 0) stub.len + 1 else 0)) * adv; @@ -1307,14 +1341,39 @@ fn full(name: []const u8) ?[]const u8 { /// `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 { +/// the pc walks it), else round the pc. `aligned` (a `pair`'s): no more +/// rows over the pc than its line has before it, so that the line's first +/// row is the window's top while the pc is in the window's upper half. +fn listing(u: ui.Ui, rec: *const Recording, i: u64, room: usize, aligned: bool) 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); + const above = (room -| 1) / 2; + if (!aligned) return listingAt(u, rec, i, pc, room, above); + const l = listingAt(u, rec, i, pc, room, ofLine(rec, i, pc, above)); + // Where the code ends under the pc, the window is filled from above (as far as it would be unaligned). + if (l.rows.len < room and l.pc < above) return listingAt(u, rec, i, pc, room, @min(above, l.pc + room - l.rows.len)); + return l; +} + +/// How many of the `most` instructions just before `pc` are of its line (`most` where it has none). +fn ofLine(rec: *const Recording, i: u64, pc: u64, most: usize) usize { + var buf: [256]u8 = undefined; + const here = rec.instruction(i, pc, &buf) orelse return most; + const line = here.line orelse return most; + const src = here.src; + var back = here.back; + var addr = pc; + var n: usize = 0; + while (n < most and back != 0) : (n += 1) { + addr -= back; + const one = rec.instruction(i, addr, &buf) orelse break; + if (one.line == null or one.line.? != line or one.src != src) break; + back = one.back; + } + return n; } /// The same round the instruction at `pc` (in the window, `Listing.pc`). -- cgit v1.3