summaryrefslogtreecommitdiff
path: root/anim/src/descent.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/descent.zig')
-rw-r--r--anim/src/descent.zig114
1 files changed, 80 insertions, 34 deletions
diff --git a/anim/src/descent.zig b/anim/src/descent.zig
index 302de38..3394eaa 100644
--- a/anim/src/descent.zig
+++ b/anim/src/descent.zig
@@ -44,9 +44,11 @@ fn clamp01(v: f32) f32 {
}
/// One step of `by` from where the cursor is, timed as its verb
-/// (design/motion.md, "A call followed down"): into a call (`descend`, 2.7
-/// s), on through a PLT stub's `jmp` (2.0 s), out by a `ret` (`ascend`, 2.3
+/// (design/motion.md, "A call followed down"): into a call (`descend`, 2.9
+/// s), on through a PLT stub's `jmp` (2.2 s), out by a `ret` (`ascend`, 2.5
/// s), across into the kernel (`cross`: `syscalls.step`); any other walked.
+/// A window opens and closes in two moves, never at once: the rows it gives
+/// up fade, then the rows it keeps glide (and back: they glide, then fade in).
pub fn step(cur: cursors.Cursor, s: *anim.Frame, by: Recording.Stop) void {
const rec = cur.rec;
const from = cur.moment(s);
@@ -57,9 +59,9 @@ pub fn step(cur: cursors.Cursor, s: *anim.Frame, by: Recording.Stop) void {
var name_buf: [256]u8 = undefined;
const here = (rec.moment(from).string(rec.register(from, "rip"), &name_buf) catch null) orelse "";
const plan: cursors.Plan = switch (b.kind) {
- .call => .{ .at = .{ f(24), f(60), f(60) }, .advance = f(126), .travel = f(12), .total = f(162) },
- .ret => .{ .at = .{ f(36), f(18), f(36) }, .advance = f(102), .travel = f(12), .total = f(138) },
- .jump => if (std.mem.indexOf(u8, here, "@plt") != null) .{ .at = .{ f(18), f(24), f(24) }, .advance = f(84), .travel = f(12), .total = f(120) } else return cur.walk(s, by, to),
+ .call => .{ .at = .{ f(24), f(60), f(60) }, .advance = f(138), .travel = f(12), .total = f(174) },
+ .ret => .{ .at = .{ f(36), f(18), f(36) }, .advance = f(114), .travel = f(12), .total = f(150) },
+ .jump => if (std.mem.indexOf(u8, here, "@plt") != null) .{ .at = .{ f(18), f(24), f(24) }, .advance = f(96), .travel = f(12), .total = f(132) } else return cur.walk(s, by, to),
.none => return cur.walk(s, by, to),
};
cur.step(s, to, plan, plan.total);
@@ -118,11 +120,20 @@ pub const Descent = struct {
// of each that leaves or comes shows: the verb's timetable.
const move: f32 = switch (kind) {
.same => cursors.glide(going),
- .down => cursors.glide(clamp01((tm - f(72)) / f(18))),
- .through => cursors.glide(clamp01((tm - f(24)) / f(18))),
+ .down => cursors.glide(clamp01((tm - f(78)) / f(18))),
+ .through => cursors.glide(clamp01((tm - f(36)) / f(18))),
.up => cursors.glide(clamp01((tm - f(84)) / f(18))),
};
- const Placed = struct { item: Item, y: f32, shows: f32, rise: f32, old: ?Item, new: ?Item };
+ const Placed = struct { item: Item, y: f32, shows: f32, rise: f32, old: ?Item, new: ?Item, twin: bool = false };
+ // A row whose state the verb changes (the call row going to wait, a
+ // stub's jmp passing, a waiting call taking its result) crossfades from
+ // the one to the other (12 f; 6 f up), its hanging arguments with it.
+ const turn: f32 = switch (kind) {
+ .same => 0,
+ .down => clamp01((tm - f(66)) / f(12)),
+ .through => clamp01((tm - f(24)) / f(12)),
+ .up => clamp01((tm - f(114)) / f(6)),
+ };
var placed_items: std.ArrayList(Placed) = .empty;
const a = u.f.scratch;
// Leaving: bottom up when a window closes, all at once when a caller gives up rows.
@@ -146,22 +157,20 @@ pub const Descent = struct {
for (after.items) |it| {
if (find(before.items, it.key)) |old| {
const y = top + std.math.lerp(old.row, it.row, move) * m.row;
- // Going up the rows keep what they were (the ring) until the advance.
- const now_item = switch (kind) {
- .same, .up => if (going >= 0.5) it else old,
- // The call row is current until its plaque becomes the ring; a stub's jmp until it passes.
- .down => if (tm >= f(72)) it else old,
- .through => if (tm >= f(24)) it else old,
- };
- placed_items.append(a, .{ .item = now_item, .y = y, .shows = 1, .rise = 0, .old = old, .new = it }) catch {};
+ if (kind != .same and old.state != it.state) {
+ placed_items.append(a, .{ .item = old, .y = y, .shows = 1 - turn, .rise = 0, .old = old, .new = it }) catch {};
+ placed_items.append(a, .{ .item = it, .y = y, .shows = turn, .rise = 0, .old = old, .new = it, .twin = true }) catch {};
+ continue;
+ }
+ placed_items.append(a, .{ .item = if (going < 0.5) old else it, .y = y, .shows = 1, .rise = 0, .old = old, .new = it }) catch {};
continue;
}
const head = it.what == .head;
const shows: f32 = switch (kind) {
.same => clamp01(2 * going - 1),
- .down => if (head) clamp01((tm - f(96)) / f(12)) else clamp01((tm - f(102) - @as(f32, @floatFromInt(arriving)) * f(2)) / f(12)),
- .through => if (head) clamp01((tm - f(54)) / f(12)) else clamp01((tm - f(60) - @as(f32, @floatFromInt(arriving)) * f(2)) / f(12)),
- .up => clamp01((tm - f(84)) / f(18)),
+ .down => if (head) clamp01((tm - f(108)) / f(12)) else clamp01((tm - f(114) - @as(f32, @floatFromInt(arriving)) * f(2)) / f(12)),
+ .through => if (head) clamp01((tm - f(66)) / f(12)) else clamp01((tm - f(72) - @as(f32, @floatFromInt(arriving)) * f(2)) / f(12)),
+ .up => clamp01((tm - f(102)) / f(12)),
};
if (!head) arriving += 1;
placed_items.append(a, .{ .item = it, .y = top + it.row * m.row, .shows = shows, .rise = if (head and kind != .same) (1 - cursors.standard(shows)) * theme.time.caption_rise else 0, .old = null, .new = it }) catch {};
@@ -176,17 +185,33 @@ pub const Descent = struct {
// on the next; the ring on a waiting call; a passed stub's bar.
const marked = now.marks[if (going >= 0.5) 1 else 0];
const plaque = [2]f32{
- // The one it leaves: in a descend it becomes the ring (72 to 84 f),
+ // The one it leaves: in a descend it becomes the ring (84 to 96 f),
// through a stub the pass bar (24 to 36), up it closes with its window.
switch (kind) {
.same => 1,
- .down => 1 - clamp01((tm - f(72)) / f(12)),
+ .down => 1 - clamp01((tm - f(84)) / f(12)),
.through => 1 - clamp01((tm - f(24)) / f(12)),
.up => 1 - clamp01((tm - f(48)) / f(12)),
},
// The one it lands on, with the advance.
if (kind == .same) 1 else clamp01(going * 2),
};
+ // A crossing stepped over: the kernel's window opens under the call
+ // row, past the arguments hanging under it; the rows after them make
+ // room first (18 f, as the lane sets off) and close up with the
+ // window as it draws back.
+ var under: ?f32 = null;
+ if (steppedOver(now)) |made| for (placed_items.items) |p| if (p.old) |o| if (o.state == .current and o.what == .insn) {
+ const at = p.y + @as(f32, @floatFromInt(1 + disasm.hanging(u, rec, o.what.insn, now.stops[1]))) * m.row;
+ const sp = syscalls.Plan.in(now, made);
+ const opening = cursors.glide(clamp01((tm - sp.enters) / f(18)));
+ const room_ = 3 * m.row * @min(opening, 1 - clamp01((tm - now.plan.advance) / f(12)));
+ for (placed_items.items) |*q| if (q.y >= at - 1) {
+ q.y += room_;
+ };
+ under = at;
+ break;
+ };
var pc_y = [2]?f32{ null, null };
for (placed_items.items) |p| {
if (p.old) |o| if (o.state == .current) {
@@ -216,6 +241,7 @@ pub const Descent = struct {
const current_line = rec.own[marked];
const widen0 = rows.numberRoom(rec.line_count);
var covered: usize = 0;
+ var covered_before: usize = 0;
var runs: disasm.Runs = .{};
var last_line: ?u32 = null;
var last_window: ?u8 = null;
@@ -263,15 +289,17 @@ pub const Descent = struct {
.pass => v.trail(c.mark, y, 0),
.waiting => {
// The ring comes as the plaque leaves; going up it becomes a trail bar.
- const ring: f32 = if (p.old != null and p.old.?.state == .waiting) (if (kind == .up) 1 - clamp01((tm - f(102)) / f(12)) else 1) else if (kind == .down) clamp01((tm - f(72)) / f(12)) else 1;
+ const ring: f32 = if (p.old != null and p.old.?.state == .waiting) (if (kind == .up) 1 - clamp01((tm - f(114)) / f(12)) else 1) else if (kind == .down) clamp01((tm - f(84)) / f(12)) else 1;
ringAt(v.faded(ring), y);
if (ring < 1) v.faded(1 - ring).trail(c.mark, y, 0);
},
.current => {},
}
runs.add(line != null and line.? == current_line, y, y + m.row);
- const hangs = dd.insn(v, now, row, y, box.w, widen0 + wide, line, line != last_line, current_line, lead, state, base, covered > 0, .{ addrs[0], addrs[n -| 1] }, null);
- covered = @max(covered -| 1, hangs);
+ // A row drawn twice (crossfading) counts once for the arguments that hang over the rows under it.
+ const hangs = dd.insn(v, now, row, y, box.w, widen0 + wide, line, line != last_line, current_line, lead, state, base, if (p.twin) covered_before > 0 else covered > 0, .{ 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;
map.row(.disasm, row.addr, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row });
},
@@ -288,8 +316,8 @@ pub const Descent = struct {
if (q.item.window + 1 == p.item.window and (q.item.state == .waiting or q.item.state == .pass)) break q;
} else continue;
const drawn: f32 = if (p.old != null and p.new != null) 1 else if (p.new != null) switch (kind) {
- .down => clamp01((tm - f(84)) / f(18)),
- .through => clamp01((tm - f(42)) / f(18)),
+ .down => clamp01((tm - f(96)) / f(18)),
+ .through => clamp01((tm - f(54)) / f(18)),
else => clamp01(2 * going - 1),
} else switch (kind) {
.up => 1 - clamp01((tm - f(72)) / f(12)),
@@ -302,7 +330,7 @@ pub const Descent = struct {
}
map.window(.disasm, first(shown), last(shown));
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, top, room, pc_y[0] orelse pc_y[1]);
+ 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);
}
};
@@ -443,8 +471,19 @@ fn layout(u: ui.Ui, rec: *const Recording, i: u64, room: usize, root: []const u8
}
if (fold.len > 0) fixed += 1;
const remaining = room -| fixed;
- const deepest_rows = if (kept.len == 1) room else if (in_stub) @min(remaining, stubRows(rec, i, pc)) else remaining;
+ var deepest_rows = if (kept.len == 1) room else if (in_stub) @min(remaining, stubRows(rec, i, pc)) else remaining;
const extra = remaining -| deepest_rows;
+ // The nearest caller takes the rows the deepest does not use, all above
+ // its call row: it keeps one row after the call, so the callee's head is
+ // directly under its return row. Where its function starts first, what
+ // is left goes back to the deepest window.
+ var nearest_rows: usize = 3 + extra;
+ if (kept.len >= 2 and kept[kept.len - 2].kind == .caller) {
+ const above = disasm.listingAt(u, rec, i, kept[kept.len - 2].at, nearest_rows, nearest_rows - 2).pc;
+ const short = nearest_rows - 2 - above;
+ nearest_rows -= short;
+ deepest_rows += short;
+ }
var row: f32 = 0;
var tag: []const u8 = "";
for (kept, 0..) |l, li| {
@@ -459,12 +498,12 @@ fn layout(u: ui.Ui, rec: *const Recording, i: u64, room: usize, root: []const u8
}
const nearest = li + 2 == kept.len and l.kind == .caller;
const count: usize = switch (l.kind) {
- .caller => 3 + if (nearest) extra else 0,
+ .caller => if (nearest) nearest_rows else 3,
.pass => 1,
.deepest => deepest_rows,
};
const above: usize = switch (l.kind) {
- .caller => (count - 1) / 2,
+ .caller => count - 2,
.pass => 0,
// Under a `syscall` four rows hold its arguments.
.deepest => if (in_stub) 0 else if (isSyscall(rec, i, pc) and count > 5) count - 5 else (count -| 1) / 2,
@@ -502,6 +541,14 @@ fn madeAt(rec: *const Recording, i: u64, addr: u64) u64 {
return i;
}
+/// The call this step crosses with, where it was stepped over (the step
+/// began on a call to libc's wrapper, not on the `syscall` itself).
+fn steppedOver(now: cursors.Now) ?Recording.Syscall {
+ if (!now.crossings or !now.walking()) return null;
+ const made = syscalls.inStep(now) orelse return null;
+ return if (isSyscall(now.rec, now.stops[1], now.rec.register(now.stops[1], "rip"))) null else made;
+}
+
fn isSyscall(rec: *const Recording, i: u64, pc: u64) bool {
var buf: [256]u8 = undefined;
const here = rec.instruction(i, pc, &buf) orelse return false;
@@ -555,13 +602,12 @@ fn moduleOf(u: ui.Ui, rec: *const Recording, i: u64, addr: u64) []const u8 {
/// the head and the call in C's form, `returns` and what crossed back
/// with what it clobbered; the answer up the lane; and at the advance the
/// window drawing back up into the lane.
-fn kernel(u: ui.Ui, now: cursors.Now, box: Rect, top: f32, room: usize, pc_y: ?f32) void {
+fn kernel(u: ui.Ui, now: cursors.Now, box: Rect, y0: f32, pc_y: ?f32) void {
if (!now.crossings or !now.walking()) return;
const made = syscalls.inStep(now) orelse return;
const rec = now.rec;
- const p = syscalls.Plan.of(made);
+ const p = syscalls.Plan.in(now, made);
const tm = now.time;
- const y0 = top + @as(f32, @floatFromInt(room -| 3)) * m.row;
const from = (pc_y orelse y0 - m.row) + m.row;
const back_up = clamp01((tm - now.plan.advance) / f(12));
// The lane: down 24 f from the plaque, 3 units of vellum; back into it after the window.
@@ -572,7 +618,7 @@ fn kernel(u: ui.Ui, now: cursors.Now, box: Rect, top: f32, room: usize, pc_y: ?f
u.fill(.{ .x = 14 - 1.5, .y = from, .w = 3, .h = @max(end - from, 0) }, theme.color.kernel);
}
// The answer climbs the lane to the `syscall` row: a head of vellum going up it.
- const climb = cursors.standard(clamp01((tm - p.back) / syscalls.Plan.cross));
+ const climb = cursors.glide(clamp01((tm - p.back) / syscalls.Plan.cross));
if (climb > 0 and climb < 1) {
const yh = std.math.lerp(y0, from, climb);
sk.draw.polygon(u.f, &.{ .{ 14, yh - 8 }, .{ 7, yh + 2 }, .{ 21, yh + 2 } }, u.at.pen(.{ .fill = ui.rgb(theme.color.kernel) }));