From 8b5d0340c9f9b3168c67f04e57cfa03712ac992c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 22:02:01 -0300 Subject: canim: a continue is a wave; what arrives after a fade is plain; a pin only where its register points From the designer's review of the SQLite scene. Between far stops the changed registers strike two frames apart in pwndbg's order, and links and pins set off with memory. A stack window or a dump that fades in carries no marks of changes the viewer did not see. At rest a moved register kept a pin at its old place as well, in every scene: gone. The kernel's answer is filled before the return arrow leaves, and rax strikes as it lands. Every dump has one reading, by type (a char quoted, a bool by name); line numbers are as wide as the program's largest; pins' names keep the side they came to. Names and measures follow the catalogue (.loose, theme.metric.calls, time.pin, time.continue_wave). Co-Authored-By: Claude Fable 5.2 --- anim/src/context.zig | 76 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 18 deletions(-) (limited to 'anim/src/context.zig') diff --git a/anim/src/context.zig b/anim/src/context.zig index 7740792..9874cd7 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -106,8 +106,10 @@ pub const Registers = struct { fn rip(r: *const Registers, u: ui.Ui, now: cursors.Now, y: f32, w: f32, is: Shown, was: Shown) void { const rec = r.cursor.rec; const moment = now.marks[if (now.advancing() >= 0.5) 1 else 0]; - // The flags' ticks are secondary: 6 f after the registers strike, not with them. - const landed = now.landed(.cpu, cursors.write_apart); + // The flags' ticks are secondary: 6 f after the registers strike, + // not with them; in a continue's wave, in its place after r15. + const delay = if (now.plan.wave) ties.strikeDelay(now, index("eflags").?) else cursors.write_apart; + const landed = now.landed(.cpu, delay); const flags = (if (landed) is else was).regs.eflags; // The flags a step changed are ticked, for three steps. const eflags_index = comptime index("eflags").?; @@ -115,7 +117,7 @@ pub const Registers = struct { const age = if (landed) now.registerAge(eflags_index) else now.registerAgeFrom(eflags_index, 1); var changed: u64 = 0; if (age) |a| changed = rec.register(now.stops[a], "eflags") ^ rec.register(now.stops[a + 1], "eflags"); - const held = if (r.quiet) 0 else now.register(eflags_index, cursors.write_apart).level; + const held = if (r.quiet) 0 else now.register(eflags_index, delay).level; rows.rip(u, y, w, rec.moment(moment), rec.register(moment, "rip"), flags, changed, held, 0); } @@ -300,12 +302,12 @@ pub const Stack = struct { const held = hold >= 0; const held_at: u64 = if (held) rec.register(@intFromFloat(hold), "rsp") -% 8 * @as(u64, @intFromFloat(placed.value(k.stage.hold_free))) else 0; var window = if (held) [2]u64{ held_at, held_at } else [2]u64{ windowAt(now, is, slots, 0), windowAt(now, was, slots, 1) }; - // A window that goes further than its rows can slide (a continue - // to a stop deeper or shallower than a call is): the old rows fade - // out before memory strikes and the new ones in after, each with - // the memory of its own stop. + // A window that goes farther than its own height (a continue to a + // stop deeper or shallower than a call is) does not scroll: the old + // rows fade out before memory strikes and the new ones in after, + // each with the memory of its own stop. const landed = now.landed(.memory, 0); - const jumped = @abs(@as(f32, @floatFromInt(@as(i64, @bitCast(window[0] -% window[1])))) / 8) > 16; + const jumped = far(window[0], window[1], slots); const since_memory = now.since(.memory, 0); const jump_shows: f32 = if (!jumped or now.resting()) 1 else if (!landed) 1 - std.math.clamp((since_memory + time.quick) / time.quick, 0, 1) else std.math.clamp((since_memory - time.strike.in / 2.0) / time.quick, 0, 1); if (jumped) window = if (landed) .{ window[0], window[0] } else .{ window[1], window[1] }; @@ -328,11 +330,12 @@ pub const Stack = struct { 8 => "eight", else => u.print("{d}", .{slots}), }; - const range = if (from_rsp == 0) u.print("{s} words from rsp", .{words}) else u.print("{s} to {s}", .{ offset(u, from_rsp), offset(u, from_rsp + 8 * @as(i64, @intCast(slots))) }); + // The first word shown and the last. + const range = if (from_rsp == 0) u.print("{s} words from rsp", .{words}) else u.print("{s} to {s}", .{ offset(u, from_rsp), offset(u, from_rsp + 8 * (@as(i64, @intCast(slots)) - 1)) }); const body = u.panel(box.w, box.h, "stack", .{ .focus = k.focus, .note = u.print("{s} \u{00b7} the frames they belong to", .{range}) }); const p = cursors.glide(now.moving(.memory, 0, time.move)); const moved = @as(f32, @floatFromInt(@as(i64, @bitCast(window[0] -% window[1])))) / 8; - const slide: f32 = (if (@abs(moved) > 16) 0 else moved * (1 - p)) + hold_scroll; + const slide: f32 = (if (jumped) 0 else moved * (1 - p)) + hold_scroll; const top = body.y + m.pad; clipBody(u, box); defer u.unclip(); @@ -341,6 +344,11 @@ pub const Stack = struct { const shown_at = if (landed) window[0] else window[1]; const lead = ui.shared(&.{ shown_at, shown_at + 8 * @as(u64, slots) }); const memory = now.shown(.memory); + // Marks only for what the viewer saw change: the steps since the + // window last faded to its place (none on a window that has just + // faded in; the ticks it had on its way out). + const watched_from: usize = if (jumped and !landed) 1 else 0; + const watched_to = if (held) now.stops.len else watched(now, slots, watched_from); // rsp and rbp, moved by the step with no link to land: their tags // travel down the lane from the old word to the new, with the slide. var travel_buf: [2][]const u8 = undefined; @@ -381,8 +389,19 @@ pub const Stack = struct { n_spans += 1; } // rsp or rbp travelling alone keeps its place in the pin it leaves and - // the one it joins: room there, closing and opening as it goes. - const going = cursors.standard(if (now.resting()) 1 else std.math.clamp(now.since(.cpu, ties.strikeDelay(now, index("rsp").?)) / time.move, 0, 1)); + // the one it joins: room there, closing and opening as it goes. It + // sets off 18 f after rsp's strike (`time.pin`): 24 f to the next + // row, 2 f a further row, 36 f at most. + const goes = struct { + fn of(n: cursors.Now, a: zt.Regs, b: zt.Regs, name: []const u8) f32 { + if (n.resting()) return 1; + const pin = time.pin; + const rows_far: f32 = @floatFromInt(@abs(@as(i64, @bitCast((b.named(name) orelse 0) -% (a.named(name) orelse 0)))) / 8); + const takes = @min(pin.row + pin.step_per_row * @max(rows_far - 1, 0), pin.row_max); + // rsp's strike sets both off: rbp, struck first, goes with it. + return cursors.standard(std.math.clamp((n.since(.cpu, ties.strikeDelay(n, index("rsp").?)) - pin.after) / takes, 0, 1)); + } + }.of; const size = theme.size.mono.context; const lone: ?[]const u8 = if (travel.len == 1) travel[0] else null; var n: i64 = @as(i64, @intFromFloat(@floor(-slide))) - 1; @@ -392,8 +411,8 @@ pub const Stack = struct { const addr = window[0] +% @as(u64, @bitCast(n * 8)); // Who points here: a pin in the lane, landing with its link. const names = pins(u, now, is, was, addr, travel); - var marks: rows.Marks = .{ .lead = lead, .first = now.written(addr, 8, .memory, 0) }; - if (now.wasRead(addr, 8) and now.writeAge(addr, 8) != 0) { + var marks: rows.Marks = .{ .lead = lead, .first = now.writtenWatched(addr, 8, .memory, 0, watched_from, watched_to) }; + if (watched_from == 0 and watched_to > 0 and now.wasRead(addr, 8) and now.writeAge(addr, 8) != 0) { marks.read = 0; marks.read_shows = now.reading(.memory, 0); } @@ -410,6 +429,7 @@ pub const Stack = struct { } var gap: f32 = 0; if (lone) |name| { + const going = goes(now, was, is, name); const share: f32 = if (was.named(name) == addr) 1 - going else if (is.named(name) == addr) going else 0; gap = share * (u.width(.mono, size, name) + ui.advance(size)); } @@ -431,14 +451,14 @@ pub const Stack = struct { for (travel, places[0..travel.len]) |name, *place| { const at_old = @as(f32, @floatFromInt(@as(i64, @bitCast((was.named(name) orelse 0) -% window[0])))) / 8 + slide; const at_new = @as(f32, @floatFromInt(@as(i64, @bitCast((is.named(name) orelse 0) -% window[0])))) / 8 + slide; - place.* = std.math.lerp(at_old, at_new, going); + place.* = std.math.lerp(at_old, at_new, goes(now, was, is, name)); } for (travel, places[0..travel.len], 0..) |name, place, i| { if (i == 1 and @abs(places[0] - place) < 0.05) continue; if (place < -0.5 or place > @as(f32, @floatFromInt(slots)) - 0.5) continue; const both = i == 0 and travel.len == 2 and @abs(places[1] - place) < 0.05; // Alone, from its place among the names it leaves to its place among those it joins. - const x = if (lone != null) std.math.lerp(pinPlace(u, pins(u, now, is, was, was.named(name) orelse 0, travel).names, name), pinPlace(u, pins(u, now, is, was, is.named(name) orelse 0, travel).names, name), going) else theme.metric.slot.lane; + const x = if (lone != null) std.math.lerp(pinPlace(u, pins(u, now, is, was, was.named(name) orelse 0, travel).names, name), pinPlace(u, pins(u, now, is, was, is.named(name) orelse 0, travel).names, name), goes(now, was, is, name)) else theme.metric.slot.lane; u.pinRow(x, top + place * m.row, if (both) &.{ "rsp", "rbp" } else &.{name}, theme.color.region.stack); } for (spans[0..n_spans]) |sp| rows.span(v, box.w, sp.y0, sp.y1, sp.name, sp.newest, sp.open); @@ -475,6 +495,24 @@ pub const Stack = struct { sk.draw.polygon(u.f, &.{ .{ hx + p.row_head[0], mid }, .{ hx, mid - p.row_head[1] / 2 }, .{ hx, mid + p.row_head[1] / 2 } }, u.at.pen(.{ .fill = ui.rgb(theme.color.region.stack) })); } + /// Whether a window of `slots` going from word `a` to word `b` goes + /// farther than its own height: it fades, and does not scroll. + fn far(a: u64, b: u64, slots: usize) bool { + return @abs(@as(i64, @bitCast(a -% b))) > 8 * @as(u64, slots); + } + + /// The first step, from `age` steps ago back, in which the window faded + /// to a new place (as many as the cursor remembers when none did). + fn watched(now: cursors.Now, slots: usize, age: usize) usize { + const rec = now.rec; + for (age..now.stops.len - 1) |a| { + const to = (rec.moment(now.stops[a]).regs(rec.tid) catch null) orelse return a; + const from = (rec.moment(now.stops[a + 1]).regs(rec.tid) catch null) orelse return a; + if (far(windowAt(now, to, slots, a), windowAt(now, from, slots, a + 1), slots)) return a; + } + return now.stops.len; + } + /// The first word a window of `slots` shows, `skip` steps back: rsp, /// or within [rsp, rbp+16) (the frame, with its saved rbp and its way /// back) so that the word the newest of the last three steps wrote or @@ -531,11 +569,13 @@ pub const Backtrace = struct { cursor: cursors.Cursor, stage: *const Stage, focus: bool = false, + /// The `backtrace` lens: in the band, as its drawing. + lens: bool = false, pub fn draw(b: *const Backtrace, f: *sk.Frame, placed: anim.Placed) void { - const box = b.stage.box(placed, .backtrace); + const box = b.stage.box(placed, if (b.lens) .band else .backtrace); if (box.h < m.tag) return; - const u = at(f, placed, box); + const u = if (b.lens) at(f, placed, box).faded(placed.value(b.stage.drawing)) else at(f, placed, box); const now = b.cursor.now(placed); const rec = b.cursor.rec; // A frame is its words on the stack: the chain changes with memory. -- cgit v1.3