diff options
Diffstat (limited to 'anim/src')
| -rw-r--r-- | anim/src/calls.zig | 6 | ||||
| -rw-r--r-- | anim/src/context.zig | 44 | ||||
| -rw-r--r-- | anim/src/cursor.zig | 195 | ||||
| -rw-r--r-- | anim/src/descent.zig | 114 | ||||
| -rw-r--r-- | anim/src/disasm.zig | 29 | ||||
| -rw-r--r-- | anim/src/hexdump.zig | 66 | ||||
| -rw-r--r-- | anim/src/loupe.zig | 39 | ||||
| -rw-r--r-- | anim/src/map.zig | 195 | ||||
| -rw-r--r-- | anim/src/nodes.zig | 1 | ||||
| -rw-r--r-- | anim/src/root.zig | 4 | ||||
| -rw-r--r-- | anim/src/rows.zig | 81 | ||||
| -rw-r--r-- | anim/src/source.zig | 14 | ||||
| -rw-r--r-- | anim/src/stage.zig | 2 | ||||
| -rw-r--r-- | anim/src/syscalls.zig | 176 | ||||
| -rw-r--r-- | anim/src/theme.zig | 7 | ||||
| -rw-r--r-- | anim/src/ui.zig | 7 | ||||
| -rw-r--r-- | anim/src/words.zig | 5 |
17 files changed, 799 insertions, 186 deletions
diff --git a/anim/src/calls.zig b/anim/src/calls.zig index d78c26c..4a669f3 100644 --- a/anim/src/calls.zig +++ b/anim/src/calls.zig @@ -45,8 +45,9 @@ pub const Tree = struct { for (nodes) |n| leaves = @max(leaves, n.x + 1); // The caller's box left of the root on its level; the leaves spread over the rest. const caller_room = m.caller[0] + 48; - const pitch = (body.w - 2 * theme.metric.panel.pad_x - 2 * m.radius - caller_room) / @max(leaves - 1, 1); const left = theme.metric.panel.pad_x + caller_room + m.radius; + // The last leaf's centre 69 in from the drawing's right edge: room for its badge on its shoulder. + const pitch = (box.w - 69 - left) / @max(leaves - 1, 1); const top = body.y + m.root; const since = now.since(.idea, 0); const returned = now.walking() and rec.depths[now.stops[0]] < rec.depths[now.stops[1]]; @@ -122,7 +123,8 @@ pub const Tree = struct { const badge: Rect = .{ .x = c[0] + m.badge_at[0], .y = c[1] - m.badge_at[1], .w = m.badge, .h = m.badge }; const heat: ui.Heat = if (n.call.exit.? > now.stops[1]) now.heat(0, null, since - time.badge_after) else .none; const ink = u.cellWritten(badge, heat, theme.color.page); - if (heat.level < 1) u.frame(badge, t.faint, theme.stroke.rule); + // Framed, as every result is, but while the strike's paper is on it. + u.faded(if (heat.level < 1) 1 else 1 - heat.solid * heat.in).frame(badge, t.faint, theme.stroke.rule); u.label(ink.face, size, badge, .center, u.print("{d}", .{@as(i64, @bitCast(n.call.result))}), if (heat.level >= 1) ink.ink else ui.rgb(t.primary)); } } diff --git a/anim/src/context.zig b/anim/src/context.zig index 6123d26..f551aa8 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -168,7 +168,7 @@ pub const Registers = struct { if (std.mem.eql(u8, carried, name) and value_was == made.args[k - 1]) break k; } else null else null; if (carrier) |k| if (crossing) |made| { - const framed = now.time - syscalls.Plan.of(made).registers - @as(f32, @floatFromInt(k - 1)) * time.flight.second; + const framed = now.time - syscalls.Plan.in(now, made).registers - @as(f32, @floatFromInt(k - 1)) * time.flight.second; marks.read = 0; marks.read_shows = @min(std.math.clamp(framed / time.read.in, 0, 1), now.reading(.cpu, 0)); // A descriptor says what it is open on: the `value` class `fd`. @@ -178,7 +178,7 @@ pub const Registers = struct { if (if (std.mem.eql(u8, name, "rax")) crossing else null) |made| { // rax: what was there, then the result, once the kernel's rows // have said it (the call's number went in at the wrapper). - const back = now.time - syscalls.Plan.of(made).struck; + const back = now.time - syscalls.Plan.in(now, made).struck; const result = back >= time.strike.in / 2.0; const value: u64 = if (result) value_now else value_was; if (back >= -time.strike.arm) { @@ -309,11 +309,15 @@ pub const Stack = struct { cursor: cursors.Cursor, stage: *const Stage, focus: bool = false, - /// On the map: the window from this many words above rsp, not scrolled. - above: u32 = 0, + /// On the map: the window from this many words above rsp, not scrolled + /// (negative: below it, the stack going on in another column's rest). + above: i32 = 0, + /// Which box of its stage it is in: the map's `more` holds the stack continued. + part: @import("stage.zig").Part = .stack, pub fn draw(k: *const Stack, f: *sk.Frame, placed: anim.Placed) void { - const box = k.stage.box(placed, .stack); + const box = k.stage.box(placed, k.part); + if (box.h < m.tag + m.row) return; const u = at(f, placed, box); const now = k.cursor.now(placed); const rec = k.cursor.rec; @@ -329,7 +333,7 @@ pub const Stack = struct { const hold = placed.value(k.stage.hold); 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 if (k.above > 0) [2]u64{ is.rsp -% 8 * @as(u64, k.above), was.rsp -% 8 * @as(u64, k.above) } else [2]u64{ windowAt(now, is, slots, 0), windowAt(now, was, slots, 1) }; + var window = if (held) [2]u64{ held_at, held_at } else if (k.above != 0) [2]u64{ is.rsp -% @as(u64, @bitCast(@as(i64, 8 * k.above))), was.rsp -% @as(u64, @bitCast(@as(i64, 8 * k.above))) } else [2]u64{ windowAt(now, is, slots, 0), windowAt(now, was, slots, 1) }; // 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, @@ -360,7 +364,7 @@ pub const Stack = struct { }; // 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 body = u.panel(box.w, box.h, if (k.part == .more) "stack, continued" else "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 (jumped) 0 else moved * (1 - p)) + hold_scroll; @@ -402,7 +406,11 @@ pub const Stack = struct { return @as(f32, @floatFromInt(@as(i64, @bitCast(addr -% base)))) / 8; } }.at; - const Span = struct { y0: f32, y1: f32, name: []const u8, newest: bool, open: bool }; + const Span = struct { y0: f32, y1: f32, name: []const u8, newest: bool, open: bool, was: ?[]const u8 = null }; + // A frame whose name changes in place (on through a stub) crossfades over the 12 f before the advance. + const renamed = std.math.clamp((now.time - now.plan.advance + 12.0 / 60.0) / (12.0 / 60.0), 0, 1); + const calls_was = rec.stack(u.f.scratch, now.stops[1]); + const calls_is = rec.stack(u.f.scratch, now.stops[0]); var spans: [16]Span = undefined; var n_spans: usize = 0; for (chain, 0..) |frame, i| { @@ -414,6 +422,14 @@ pub const Stack = struct { const open = last >= @as(f32, @floatFromInt(slots)); const y1 = top + (@min(last, @as(f32, @floatFromInt(slots)) - 1) + 1) * m.row; spans[n_spans] = .{ .y0 = top + @max(first, 0) * m.row, .y1 = y1, .name = spanName(u, rec, open_calls, i, if (i < named.len) named[i].pc else frame.pc), .newest = i == 0, .open = open }; + if (now.walking() and !jumped and i < old_chain.len and old_chain[i].lo == frame.lo) { + const was_name = spanName(u, rec, calls_was, i, old_chain[i].pc); + const is_name = spanName(u, rec, calls_is, i, frame.pc); + if (!std.mem.eql(u8, was_name, is_name)) { + spans[n_spans].name = is_name; + spans[n_spans].was = was_name; + } + } n_spans += 1; } // rsp or rbp travelling alone keeps its place in the pin it leaves and @@ -455,7 +471,7 @@ pub const Stack = struct { marks.read_shows = now.reading(.memory, 0); } const below_rsp: i64 = @bitCast(addr -% rsp_shown); - map.row(.stack, addr, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row }); + if (k.part == .stack) map.row(.stack, addr, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row }); // `free`: above rsp, not yet reached: its address at 60%, its word faint. if (held and addr < rsp_shown) { rows.free(v, y, memory, addr, below_rsp, lead); @@ -478,7 +494,7 @@ pub const Stack = struct { const k_role = (addr -% roles_from) / 8; const what: zt.telescope.Role = if (k_role < roles.len) roles[k_role].role else .none; const role = roleName(u, what, (Recording.word(memory, addr, 8) catch null) orelse 1); - const hops = rows.slot(v, y, room_w, memory, addr, below_rsp, if (gapped) &.{} else names.names, names.shows, marks, role.name, role.local); + const hops = rows.slot(v, y, room_w, now.shownAt(addr), addr, below_rsp, if (gapped) &.{} else names.names, names.shows, marks, role.name, role.local); at_rows.append(u.f.scratch, .{ .addr = addr, .y = y }) catch {}; pointers.append(u.f.scratch, .{ .{ .addr = addr, .y = y }, what == .saved and std.mem.eql(u8, what.saved, "rbp") }) catch {}; // Only a row on show is a place a tie can land. @@ -515,7 +531,10 @@ pub const Stack = struct { 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); + for (spans[0..n_spans]) |sp| if (sp.was) |was_name| { + rows.span(v.faded(1 - renamed), box.w, sp.y0, sp.y1, was_name, sp.newest, sp.open); + rows.span(v.faded(renamed), box.w, sp.y0, sp.y1, sp.name, sp.newest, sp.open); + } else rows.span(v, box.w, sp.y0, sp.y1, sp.name, sp.newest, sp.open); veiled(u, box, now.veil); } @@ -527,7 +546,7 @@ pub const Stack = struct { return switch (role) { .none, .return_address => .{ .name = "" }, .saved => |r| .{ .name = u.print("saved {s}", .{r}) }, - .local => |l| .{ .name = if (l.offset > 0) u.print("{s}+{x}", .{ l.name, @as(u32, @intCast(l.offset)) }) else l.name, .local = true }, + .local => |l| .{ .name = if (l.offset > 0) u.print("{s}+{x}", .{ l.name, @as(u32, @intCast(l.offset)) }) else if (l.offset == -4 and l.size == 4) u.print("{s}, high half", .{l.name}) else if (l.offset < 0) u.print("{s}, from byte {d}", .{ l.name, -l.offset }) else l.name, .local = true }, .argc => .{ .name = "argc" }, .argv => |i| .{ .name = if (word == 0) "argv end" else u.print("argv[{d}]", .{i}) }, .envp => |i| .{ .name = if (word == 0) "envp end" else u.print("envp[{d}]", .{i}) }, @@ -663,6 +682,7 @@ pub const Backtrace = struct { const arrive = std.math.clamp((since - time.quick / 2.0 - time.move) / time.quick, 0, 1); const room = rowsOf(box); const total = chains[if (slide >= 0.5) 1 else 0].len; + map.measure(.backtrace, @max(chains[0].len, chains[1].len)); const body = u.panel(box.w, box.h, "backtrace", .{ .focus = b.focus, .note = newestAtBottom(u, total, room) }); clipBody(u, box); defer u.unclip(); diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig index 6a02948..bbc3cf1 100644 --- a/anim/src/cursor.zig +++ b/anim/src/cursor.zig @@ -16,6 +16,7 @@ const anim = @import("anim"); const zt = @import("ztrace"); const Recording = @import("Recording.zig"); const ui = @import("ui.zig"); +const syscalls = @import("syscalls.zig"); const theme = ui.theme; const time = theme.time; @@ -80,6 +81,9 @@ pub const Plan = struct { total: f32 = time.fire + time.step + time.rest, /// A `continue`: the registers strike in a wave, no arm and no pulse. wave: bool = false, + /// The line fires (not on a step that goes on from the last one's + /// mark: a crossing stepped over, from its call row). + fires: bool = true, /// Once the pattern is known: the levels a stagger apart from the /// first frame, the mark after them, in `seconds`. @@ -93,7 +97,7 @@ pub const Plan = struct { }; /// Registers whose change is no value to read: where execution is, and the flags. -const quiet: u32 = blk: { +pub const quiet: u32 = blk: { var mask: u32 = 0; for (zt.Regs.names, 0..) |name, i| { if (std.mem.eql(u8, name, "rip") or std.mem.eql(u8, name, "eflags")) mask |= 1 << i; @@ -105,10 +109,13 @@ pub const Cursor = struct { rec: *Recording, /// Where it is (or is arriving), where it came from, and before that. stops: [history]anim.Value, + /// The pace each of those steps was taken at (`Gait`): what a run + /// changed is not marked, then or after. + gaits: [history]anim.Value, /// 0 to 1 through the step it is taking; 1 at rest. phase: anim.Value, /// The step's `Plan`, a value a field. - plan: [8]anim.Value, + plan: [9]anim.Value, /// The moment the current mark was on, and the one it is on (or going to). marks: [2]anim.Value, /// 1 while steps are hurried (the head counts them), and while what @@ -119,6 +126,10 @@ pub const Cursor = struct { sprint_veil: anim.Value, /// Steps taken. count: anim.Value, + /// The same values a little behind (`time.minimap_lag`): what the + /// minimap draws from, secondary action that never starts on a primary + /// onset's frame. + lag: Lagged, /// The levels the scene shows: set before the first step. levels: Levels = .{}, /// The scene's whole way, for the head's progress line and counter (`journey`). @@ -133,21 +144,62 @@ pub const Cursor = struct { var c: Cursor = .{ .rec = rec, .stops = undefined, + .gaits = undefined, .phase = s.value(1), - .plan = .{ s.value(0), s.value(plan.at[0]), s.value(plan.at[1]), s.value(plan.at[2]), s.value(plan.advance), s.value(plan.travel), s.value(plan.total), s.value(0) }, + .plan = .{ s.value(0), s.value(plan.at[0]), s.value(plan.at[1]), s.value(plan.at[2]), s.value(plan.advance), s.value(plan.travel), s.value(plan.total), s.value(0), s.value(1) }, .marks = .{ s.value(here), s.value(here) }, .hurried = s.value(0), .veil = s.value(0), .sprint_veil = s.value(0), .count = s.value(0), + .lag = undefined, .first = start, .last = start, }; // shortcut: an f32 holds whole moments up to 16 million; a longer recording needs two values a stop. for (&c.stops) |*stop| stop.* = s.value(here); + for (&c.gaits) |*gait| gait.* = s.value(0); + inline for (@typeInfo(Lagged).@"struct".field_names) |name| { + const from = @field(c, name); + if (@TypeOf(from) == anim.Value) { + @field(c.lag, name) = s.value(s.get(from)); + } else for (&@field(c.lag, name), from) |*to, one| { + to.* = s.value(s.get(one)); + } + } return c; } + /// The cursor's animated values, mirrored for the minimap. + pub const Lagged = struct { + stops: [history]anim.Value, + gaits: [history]anim.Value, + phase: anim.Value, + plan: [9]anim.Value, + marks: [2]anim.Value, + hurried: anim.Value, + veil: anim.Value, + sprint_veil: anim.Value, + count: anim.Value, + }; + + /// Plays `plays(values)` on the cursor's values from here, and on their + /// lagging mirror `time.minimap_lag` later; the cursor ends where the first left it. + fn both(c: Cursor, s: *anim.Frame, plays: anytype) void { + const start = s.cursor; + s.cursor = start + time.minimap_lag; + plays.run(s, lagged(c)); + s.cursor = start; + plays.run(s, c); + } + + /// `c` with its lagging values in place of its own. + fn lagged(c: Cursor) Cursor { + var out = c; + inline for (@typeInfo(Lagged).@"struct".field_names) |name| @field(out, name) = @field(c.lag, name); + return out; + } + /// Where the timeline has taken the cursor so far: for scene code that /// finds the next place from the last. pub fn moment(c: Cursor, s: *const anim.Frame) u64 { @@ -174,18 +226,36 @@ pub const Cursor = struct { /// sentence said faster). pub fn step(c: Cursor, s: *anim.Frame, to: u64, plan: Plan, seconds: f32) void { const from = c.moment(s); - var set: [history + 12]anim.Animation = undefined; - for (1..history) |i| set[i] = c.stops[i].to(settled(s, c.stops[i - 1])); - set[0] = c.stops[0].to(@floatFromInt(to)); - for (c.plan, [_]f32{ @floatFromInt(@intFromEnum(plan.gait)), plan.at[0], plan.at[1], plan.at[2], plan.advance, plan.travel, plan.total, @floatFromInt(@intFromBool(plan.wave)) }, history..) |value, is, n| set[n] = value.to(is); + // Where each value goes, from the cursor's own (the mirror goes the same way, later). + const Step = struct { + stops: [history]f32, + gaits: [history]f32, + plan: [9]f32, + marks: [2]f32, + count: f32, + seconds: f32, + fn run(st: @This(), sf: *anim.Frame, v: Cursor) void { + var set: [2 * history + 13]anim.Animation = undefined; + for (v.stops, st.stops, 0..) |value, is, i| set[i] = value.to(is); + for (v.gaits, st.gaits, 0..) |value, is, i| set[history + 13 + i] = value.to(is); + for (v.plan, st.plan, history..) |value, is, n| set[n] = value.to(is); + set[history + 9] = v.marks[0].to(st.marks[0]); + set[history + 10] = v.marks[1].to(st.marks[1]); + set[history + 11] = v.phase.to(0); + set[history + 12] = v.count.to(st.count); + sf.play(set, .{ .seconds = 0 }); + sf.play(.{v.phase.to(1)}, .{ .seconds = st.seconds, .ease = anim.ease.linear }); + } + }; + var st: Step = .{ .stops = undefined, .gaits = undefined, .plan = .{ @floatFromInt(@intFromEnum(plan.gait)), plan.at[0], plan.at[1], plan.at[2], plan.advance, plan.travel, plan.total, @floatFromInt(@intFromBool(plan.wave)), @floatFromInt(@intFromBool(plan.fires)) }, .marks = undefined, .count = settled(s, c.count) + 1, .seconds = seconds }; + st.stops[0] = @floatFromInt(to); + for (1..history) |i| st.stops[i] = settled(s, c.stops[i - 1]); + st.gaits[0] = @floatFromInt(@intFromEnum(plan.gait)); + for (1..history) |i| st.gaits[i] = settled(s, c.gaits[i - 1]); // At a sprint the mark is seen only where a phrase ends. const was = settled(s, c.marks[1]); - set[history + 8] = c.marks[0].to(was); - set[history + 9] = c.marks[1].to(if (plan.gait == .sprint and !c.phraseEnds(from, to)) was else @floatFromInt(to)); - set[history + 10] = c.phase.to(0); - set[history + 11] = c.count.to(settled(s, c.count) + 1); - s.play(set, .{ .seconds = 0 }); - s.play(.{c.phase.to(1)}, .{ .seconds = seconds, .ease = anim.ease.linear }); + st.marks = .{ was, if (plan.gait == .sprint and !c.phraseEnds(from, to)) was else @floatFromInt(to) }; + c.both(s, st); } /// Steps of `by` up to moment `until`, each shown in full and as long @@ -212,6 +282,11 @@ pub const Cursor = struct { return c.timetable(from, to, false); } + /// The timetable a step from `from` to `to` gets walked (`wave`: as a `continue`), for a scene that adds a beat to it. + pub fn planned(c: Cursor, from: u64, to: u64, wave: bool) Plan { + return c.timetable(from, to, wave); + } + /// `continue`: straight to a stop far from this one (a breakpoint, not /// a step). The line it leaves fires; the registers it changed strike /// in a wave, 2 f apart in pwndbg's order, the fill in over 6 f, no arm @@ -256,8 +331,9 @@ pub const Cursor = struct { const projected = level == 2 and is and levels[1] and (c.levels.idea == .data or deeper); if (projected) slot += time.project.bracket + @as(f32, if (c.levels.idea == .data) time.project.draw else time.project.far) + @as(f32, if (wrote > 0 and c.levels.idea == .data) time.strike.arm else 0) else if (is) slot += time.cascade; strikes.* = @max(slot, time.cascade); - // A wave's last register strikes 2 f a register after its first: the next level is 18 f after that. - if (wave and level == 0 and is) slot += (regs - 1) * time.continue_wave; + // A wave's last register strikes 2 f a register after its first, + // a cascade's 6 f (the fourth and on with the third): the next level is 18 f after that. + if (level == 0 and is) slot += if (wave) (regs - 1) * time.continue_wave else @min(regs - 1, 3) * write_apart; } // The writes of one step strike 6 f apart: the last is later. if (levels[1]) slot += @min(@max(wrote - 1, 0), 3) * write_apart; @@ -327,7 +403,7 @@ pub const Cursor = struct { // What changes faster than it can be read is veiled at a run too. const veiled = options.veil orelse true; const start = s.cursor; - s.play(.{ c.hurried.to(1), c.veil.to(if (veiled) 1 else 0), c.sprint_veil.to(if (options.pace < time.run) 1 else 0) }, .{ .seconds = time.veil, .ease = anim.ease.linear }); + c.both(s, Veils{ .to = .{ 1, if (veiled) 1 else 0, if (options.pace < time.run) 1 else 0 } }); s.cursor = start; var k: f32 = 0; while (here < until) : (k += 1) { @@ -343,22 +419,37 @@ pub const Cursor = struct { here = next; } if (!options.settle) return; - s.play(.{ c.hurried.to(0), c.veil.to(0), c.sprint_veil.to(0) }, .{ .seconds = time.veil, .ease = anim.ease.linear }); + c.both(s, Veils{ .to = .{ 0, 0, 0 } }); s.wait(time.beat); } + /// The hurry's veils going to `to` (hurried, veil, sprint_veil). + const Veils = struct { + to: [3]f32, + fn run(v: Veils, s: *anim.Frame, c: Cursor) void { + s.play(.{ c.hurried.to(v.to[0]), c.veil.to(v.to[1]), c.sprint_veil.to(v.to[2]) }, .{ .seconds = time.veil, .ease = anim.ease.linear }); + } + }; + /// There at once, with nothing struck: a cut. pub fn jump(c: Cursor, s: *anim.Frame, to: u64) void { - var all: [history + 3]anim.Animation = undefined; - for (c.stops, 0..) |stop_value, i| all[i] = stop_value.to(@floatFromInt(to)); - all[history] = c.phase.to(1); - all[history + 1] = c.marks[0].to(@floatFromInt(to)); - all[history + 2] = c.marks[1].to(@floatFromInt(to)); - s.play(all, .{ .seconds = 0 }); + const Jump = struct { + to: u64, + fn run(j: @This(), sf: *anim.Frame, v: Cursor) void { + var all: [history + 3]anim.Animation = undefined; + for (v.stops, 0..) |stop_value, i| all[i] = stop_value.to(@floatFromInt(j.to)); + all[history] = v.phase.to(1); + all[history + 1] = v.marks[0].to(@floatFromInt(j.to)); + all[history + 2] = v.marks[1].to(@floatFromInt(j.to)); + sf.play(all, .{ .seconds = 0 }); + } + }; + c.both(s, Jump{ .to = to }); } - /// For a component, while it draws. - pub fn now(c: Cursor, placed: anim.Placed) Now { + /// For a component, while it draws (on the minimap, `time.minimap_lag` behind). + pub fn now(c_: Cursor, placed: anim.Placed) Now { + const c = if (ui.strokes) lagged(c_) else c_; const rec = c.rec; var n: Now = .{ .rec = rec, @@ -371,6 +462,7 @@ pub const Cursor = struct { .travel = placed.value(c.plan[5]), .total = placed.value(c.plan[6]), .wave = placed.value(c.plan[7]) >= 0.5, + .fires = placed.value(c.plan[8]) >= 0.5, }, .marks = .{ whole(rec, placed.value(c.marks[0])), whole(rec, placed.value(c.marks[1])) }, .hurried = placed.value(c.hurried), @@ -384,6 +476,7 @@ pub const Cursor = struct { .way = .{ c.first, c.last }, }; for (&n.stops, c.stops) |*stop_at, v| stop_at.* = whole(rec, placed.value(v)); + for (&n.gaits, c.gaits) |*gait, v| gait.* = @enumFromInt(@as(u2, @intFromFloat(std.math.clamp(@round(placed.value(v)), 0, 2)))); const phase = placed.value(c.phase); if (phase < 1) n.time = phase * n.plan.total; if (c.last > c.first) { @@ -417,6 +510,8 @@ pub const Now = struct { /// `stops[0]` is the moment shown, `stops[1]` where the step came /// from: the step is every moment after it up to the one shown. stops: [history]u64, + /// The pace each step to them was taken at: `gaits[0]` this one's. + gaits: [history]Gait = @splat(.walk), /// Seconds into the step's plan; infinite at rest. time: f32, plan: Plan, @@ -494,7 +589,7 @@ pub const Now = struct { /// The fire: how far out (in units) the edges of the mark's plaque /// are, on the line about to run. The step's first beat, alone. pub fn fire(n: Now) f32 { - return if (n.walking() and n.time < time.fire) theme.pulse(n.time / time.fire) else 0; + return if (n.walking() and n.plan.fires and n.time < time.fire) theme.pulse(n.time / time.fire) else 0; } /// The same for the view the scene fires in, 0 for the other. @@ -528,6 +623,25 @@ pub const Now = struct { return n.writeAgeFrom(addr, size, 0); } + /// Of the bytes `addr .. addr + len` (16 at most), the first and the last + /// (from `addr`) whose value the step that last wrote them changed: what + /// its strike covers. Null where that is not known. + pub fn changedBytes(n: Now, addr: u64, len: u64) ?[2]u8 { + const age = n.writeAge(addr, len) orelse return null; + const l: usize = @intCast(@min(len, 16)); + var was: [16]u8 = undefined; + var is: [16]u8 = undefined; + var known_was: [16]bool = undefined; + var known_is: [16]bool = undefined; + n.rec.moment(n.stops[age + 1]).read(addr, was[0..l], known_was[0..l]) catch return null; + n.rec.moment(n.stops[age]).read(addr, is[0..l], known_is[0..l]) catch return null; + var out: ?[2]u8 = null; + for (0..l) |i| if (known_was[i] and known_is[i] and was[i] != is[i]) { + out = .{ if (out) |o| o[0] else @intCast(i), @intCast(i) }; + }; + return out; + } + /// The same, not counting the `skip` newest steps. fn writeAgeFrom(n: Now, addr: u64, size: u64, skip: usize) ?u64 { for (skip..history - 1) |age| { @@ -568,6 +682,8 @@ pub const Now = struct { const s = time.strike; const a = age orelse return .none; if (a == 0 or a > s.ember_steps) return .none; + // A run changes values unmarked: it shows them settled. + if (n.gaits[a] == .run) return .none; if (a < s.ember_steps) return .ember; // Linear: a fade, as the mark leaves: secondary action does not // start on the fire's frame, where the step's primary one does. @@ -587,7 +703,8 @@ pub const Now = struct { switch (n.plan.gait) { // Faster than a strike can be seen: embers only. .sprint => return .ember, - .run => return if (was.level >= 1 or n.resting()) .ember else .{ .level = std.math.clamp(since_strike / time.snap, 0, 1) }, + // A run strikes nothing: its values change in place. + .run => return .none, .walk => {}, } if (n.resting()) return .ember; @@ -614,9 +731,27 @@ pub const Now = struct { /// `level`, `delay` seconds after its first, and 6 f after the write of /// this step before theirs. pub fn written(n: Now, addr: u64, size: u64, level: Level, delay: f32) ui.Heat { + // What the kernel fills in a crossing lands as its work does it, unpulsed. + if (level == .memory) if (syscalls.filledAt(n, addr)) |at| { + var h = n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.time - at); + h.out = 0; + return h; + }; return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.since(level, delay + n.writeDelay(addr, size))); } + /// `written`, struck `since` seconds ago (a loupe's own times: it strikes once it has opened). + pub fn writtenAt(n: Now, addr: u64, size: u64, struck: f32) ui.Heat { + return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), struck); + } + + /// The state to draw the memory at `addr` from: `shown(.memory)`, but + /// what the kernel fills in a crossing from when its byte lands. + pub fn shownAt(n: Now, addr: u64) Recording.Moment { + if (syscalls.filledAt(n, addr)) |at| return if (n.time - at >= time.strike.in / 2.0) n.moment() else n.before(); + return n.shown(.memory); + } + /// `written`, on a thing the viewer has watched only through the steps /// `lo` to `hi` ago (a window that faded to its place, a view that came /// in after its step): what changed in any other step is plain. @@ -631,6 +766,8 @@ pub const Now = struct { var last: ?u64 = null; for (n.rec.written(n.stops[1], n.stops[0])) |span| { if (span.addr < addr + size and span.addr + span.len > addr) return @min(order, 3) * write_apart; + // The kernel's own writes have their own times (`filledAt`). + if (syscalls.filledAt(n, span.addr) != null) continue; // Bytes of one write (one store, in pieces) are one strike. if (last == null or span.addr != last.?) order += 1; last = span.addr + span.len; @@ -704,8 +841,8 @@ test "a write is armed, strikes, holds, cools with the advance, and leaves after // Struck again over its ember: armed with the ember still under it. h = instant(0.20, plan).heat(0, 1, -0.10); try expect(h.level == 1 and h.arm == 1 and h.solid == 0); - // Running: an ember and no more. Sprinting: the same, at once. - try expect(instant(0.2, Plan.running(0.3)).heat(0, null, 0.2).solid == 0); + // Running: nothing struck. Sprinting: an ember, at once. + try expectEqual(ui.Heat.none, instant(0.2, Plan.running(0.3)).heat(0, null, 0.2)); try expectEqual(ui.Heat.ember, instant(0.01, Plan.sprinting(0.05)).heat(0, null, 0.01)); } 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) })); diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index 0b6f931..e871cc6 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -81,6 +81,8 @@ pub const Disasm = struct { const going = now.advancing(); const from = listing(u, rec, now.marks[0], room, above); const to = listing(u, rec, now.marks[1], room, above); + // 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); const pc = [2]u64{ rec.register(now.marks[0], "rip"), rec.register(now.marks[1], "rip") }; const name = rec.strings.get(pc[if (going >= 0.5) 1 else 0]) orelse ""; @@ -274,7 +276,8 @@ pub const Disasm = struct { 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); - return if (need.drawn) d.annotation(u, now, row, y, x, room, state, base, window, echo).hangs else 0; + // 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; } const Note = struct { drawn: bool = false, end: f32 = 0, hangs: usize = 0 }; @@ -427,6 +430,8 @@ pub const Disasm = struct { marks.changed_heat = now.written(touch.addr, touch.len, .memory, 0); } }; + // Narrower than a word, it is read at its width. + if (touch.len < 8) return .{ .drawn = true, .end = rows.narrow(u, x, y, shown, touch.addr, touch.len, room, marks).end }; return .{ .drawn = true, .end = rows.chain(u, x, y, shown, touch.addr, room, marks).end }; } // Only a register: a small `reg` of what it left there. @@ -481,9 +486,7 @@ const Say = struct { /// its name), three when none says. How many rows they take. fn arguments(a: Say, row: Insn, to: u64, moment: u64) usize { const name = a.functionName(to, moment); - const count = @min(row.params orelse for (a.rec.functions) |fun| { - if (std.mem.eql(u8, fun.name, name)) break fun.params; - } else argumentCount(a.rec, row, name) orelse 3, 6); + const count = a.argumentRows(row, to, moment); const shown = a.rec.moment(moment); // Flags by name, where a system call of its name says which argument they are. const nr: ?u64 = if (std.meta.stringToEnum(std.os.linux.SYS, name)) |sys| @intFromEnum(sys) else null; @@ -499,6 +502,14 @@ const Say = struct { return count; } + /// How many argument rows hang under a call to `to`. + fn argumentRows(a: Say, row: Insn, to: u64, moment: u64) usize { + const name = a.functionName(to, moment); + return @min(row.params orelse for (a.rec.functions) |fun| { + if (std.mem.eql(u8, fun.name, name)) break fun.params; + } else argumentCount(a.rec, row, name) orelse 3, 6); + } + /// The call at `row` (to `to`, made at `moment`) in C's form, its /// arguments as the source wrote that many and as the system call of its /// name types them; with ` = result` when it has returned. @@ -601,6 +612,16 @@ const Say = struct { } }; +/// How many rows of arguments hang under `row` while it is current at +/// `moment`: a direct call's, a `syscall`'s; 0 for anything else. +pub fn hanging(u: ui.Ui, rec: *const Recording, row: Insn, moment: u64) usize { + const a: Say = .{ .u = u, .rec = rec, .y = 0, .x = 0, .room = 0 }; + if (std.mem.eql(u8, row.mnemonic(), "syscall")) return @min(zt.syscalls.signature(rec.register(moment, "rax")).len, 6); + const b = rec.insn_branches[moment] orelse return 0; + if (b.kind != .call or target(row) == null) return 0; + return a.argumentRows(row, b.to, moment); +} + /// A call's argument registers, in order; a system call's. const carriers = [_][]const u8{ "rdi", "rsi", "rdx", "rcx", "r8", "r9" }; const carriers_sys = [_][]const u8{ "rdi", "rsi", "rdx", "r10", "r8", "r9" }; diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig index cbd8f7f..3abd052 100644 --- a/anim/src/hexdump.zig +++ b/anim/src/hexdump.zig @@ -155,16 +155,18 @@ pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize } pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize, of: Of, loud: bool, rule: [2]f32) void { - const v = u.moved(x, 0); + const dump = u.moved(x, 0); var arcs: rows.Arcs = .{}; var at_rows: [64]RowAt = undefined; for (at_rows[0..@min(count, at_rows.len)], 0..) |*r, i| r.* = .{ .addr = first + 16 * i, .y = y + @as(f32, @floatFromInt(i)) * m.row }; const shown_rows = at_rows[0..@min(count, at_rows.len)]; - const moment = now.shown(.memory); const lead = ui.shared(&.{ first, first + 16 * @as(u64, count -| 1) }); // Room for the addresses, once for the dump: by its widest. const shift = rows.addressRoom(first + 16 * @as(u64, count -| 1)); - for (0..count) |i| { + // At a run the values crossfade (8 f), unmarked: the rows twice, the arcs once. + const passes = crossfade(now); + for (passes.moments[0..passes.n], passes.shows[0..passes.n], 0..) |moment, shows, pass| for (0..count) |i| { + const v = dump.faded(shows); const addr = first + 16 * i; const ry = y + @as(f32, @floatFromInt(i)) * m.row; var values: [16]u8 = undefined; @@ -203,6 +205,7 @@ pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: u }; } run.heat = now.written(here, run.len, .memory, 0); + run.changed = now.changedBytes(here, run.len); if (now.wasRead(here, run.len) and now.writeAge(here, run.len) != 0) run.read = now.reading(.memory, 0); if (run.kind == .number or run.kind == .pointer) ties.anchor(v, .{ .dump_run = here }, .{ .x = shift + rows.byteX(run.first) - 4, .y = ry, .w = rows.byteX(run.first + run.len - 1) + 28 - rows.byteX(run.first) + 4, .h = m.row }); readings[n] = .{ .at = run.first, .len = run.len, .reads = switch (run.kind) { @@ -216,7 +219,7 @@ pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: u } @import("map.zig").row(.view, addr, v, .{ .x = 0, .y = ry, .w = theme.layout.state.w, .h = m.row }); rows.bytesAt(v, ry, addr, &values, &known, runs[0..n], of.region, lead, holds_drawn, moment, shift); - for (runs[0..n]) |run| if (run.kind == .pointer and run.len == 8) pointerArcs(&arcs, now, addr + run.first, ry, shown_rows, 16, rule, loud, false); + if (pass + 1 == passes.n) for (runs[0..n]) |run| if (run.kind == .pointer and run.len == 8) pointerArcs(&arcs, now, addr + run.first, ry, shown_rows, 16, rule, loud, false); const end = reading(v, ry, shift, moment, &values, &known, readings[0..n]); // The size word of the chunk after: malloc's, a note after the reading. const last = runs[n - 1]; @@ -224,8 +227,19 @@ pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: u const size = std.mem.readInt(u64, values[8..16], .little) & ~@as(u64, 7); v.text(.sans, theme.size.sans.micro, end, rows.baseline(ry) - 1, v.print("malloc's: a chunk of {d}", .{size}), t.faint); } + }; + arcs.draw(dump, theme.metric.arc.lanes.len); +} + +/// The memory a dump draws now, and how much each shows: at a run, what +/// the step changed crossfades over 8 f, unmarked; otherwise memory's state. +const Passes = struct { moments: [2]Recording.Moment, shows: [2]f32, n: usize }; +fn crossfade(now: cursors.Now) Passes { + if (now.plan.gait == .run and !now.resting()) { + const q = std.math.clamp(now.since(.memory, 0) / (8.0 / 60.0), 0, 1); + if (q > 0 and q < 1) return .{ .moments = .{ now.before(), now.moment() }, .shows = .{ 1 - q, q }, .n = 2 }; } - arcs.draw(v, theme.metric.arc.lanes.len); + return .{ .moments = .{ now.shown(.memory), undefined }, .shows = .{ 1, 0 }, .n = 1 }; } /// A row of a panel: its first byte's address and its top. @@ -270,6 +284,8 @@ fn aim(arcs: *rows.Arcs, now: cursors.Now, field: u64, target: u64, from: f32, s const moment = now.moment(); var arc = state; arc.from = from; + // A run draws no arcs: they fade in, settled, as it ends. + arc.shows *= 1 - now.hurried; arc.ink = rows.ink(rows.regionOf(moment, target)); for (shown) |r| if (target >= r.addr and target < r.addr + size) { if (r.y == from) return; @@ -342,7 +358,14 @@ pub const Fields = struct { marks: []const f32 = &.{}, /// Bytes known from elsewhere than the moment's memory (what a syscall /// was given, as the kernel took them), and how much they show (0 to 1). - given: ?struct { addr: u64, bytes: []const u8, shows: f32 } = null, + given: ?struct { + addr: u64, + bytes: []const u8, + shows: f32, + /// What a read fills: seconds since the kernel's work reached the + /// first byte; they land a byte every 2 f from the low address (null: all at once). + since: ?f32 = null, + } = null, /// How much a frame round every field shows: the kernel reading them. read: f32 = 0, /// The part of the region the recording read at the stop shown (null: @@ -353,6 +376,9 @@ pub const Fields = struct { /// How many of the newest steps it has been on screen through: only /// their changes are marked. watched: usize = std.math.maxInt(usize), + /// Seconds since its strikes began, a field 6 f after the one before + /// (a loupe's, once it has opened); null: memory's slot. + struck: ?f32 = null, }; /// The region's rows in view `v`, from `y`, sixteen bytes a row from its @@ -392,7 +418,8 @@ pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void { ry += m.row; } last = r; - fieldRow(u, now, ry, of.base + 16 * r, moment, of, lead, shift); + const passes = crossfade(now); + for (passes.moments[0..passes.n], passes.shows[0..passes.n]) |mm, shows| fieldRow(u.faded(shows), now, ry, of.base + 16 * r, if (passes.n == 2) mm else moment, of, lead, shift); at_rows.append(u.f.scratch, .{ .addr = of.base + 16 * r, .y = ry }) catch {}; ry += m.row; } @@ -479,6 +506,7 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom if (of.given) |g| for (0..16) |i| { const a = addr + i; if (a < g.addr or a >= g.addr + g.bytes.len) continue; + if (g.since) |since| if (since < @as(f32, @floatFromInt(a - g.addr)) * @import("syscalls.zig").Plan.byte) continue; given_values[i] = g.bytes[a - g.addr]; given_known[i] = true; gives = true; @@ -491,8 +519,12 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom var at: u8 = 0; while (at < 16 and addr + at < of.base + of.len) { const here = addr + at; - const field = for (of.fields) |field| { - if (of.base + field.at <= here and here < of.base + field.at + field.len) break field; + var field_k: usize = 0; + const field = for (of.fields, 0..) |field, fk| { + if (of.base + field.at <= here and here < of.base + field.at + field.len) { + field_k = fk; + break field; + } } else null; var run: rows.Run = .{ .first = at, .len = 1, .kind = .loose }; if (field) |fl| { @@ -503,6 +535,10 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom .text => .text, }; run.heat = now.writtenWatched(here, run.len, .memory, 0, 0, of.watched); + run.changed = now.changedBytes(here, run.len); + if (of.struck) |since| run.heat = now.writtenAt(here, run.len, since - @as(f32, @floatFromInt(field_k)) * cursors.write_apart); + // What the kernel fills lands a byte every 2 f. + if (@import("syscalls.zig").filledAt(now, here) != null) run.apart = 2; var framed: f32 = 0; if (fl.mark) |k| if (k < of.marks.len) { framed = of.marks[k]; @@ -556,8 +592,16 @@ pub fn reading(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: * const len: usize = @intCast(if (fl.type) |ty| @min(fl.len, ty.size() orelse fl.len) else fl.len); if (len == 0 or std.mem.indexOfScalar(bool, known[first..][0..len], false) != null) continue; defer if (fl.note.len > 0) { - u.text(.sans, theme.size.sans.micro, x, base - 1, fl.note, t.faint); - x += u.width(.sans, theme.size.sans.micro, fl.note) + adv; + // Cut where the panel ends, at a word, with `…`; never mid-word without it. + var note = fl.note; + while (note.len > 0 and x + u.width(.sans, theme.size.sans.micro, if (note.len == fl.note.len) note else u.print("{s}\u{2026}", .{note})) > room) { + note = std.mem.trimEnd(u8, note[0 .. std.mem.lastIndexOfScalar(u8, note, ' ') orelse 0], " \u{00b7}"); + } + if (note.len > 0) { + const said = if (note.len == fl.note.len) note else u.print("{s}\u{2026}", .{note}); + u.text(.sans, theme.size.sans.micro, x, base - 1, said, t.faint); + x += u.width(.sans, theme.size.sans.micro, said) + adv; + } }; if (fl.reads == .bytes) continue; const bytes = values[first..][0..len]; diff --git a/anim/src/loupe.zig b/anim/src/loupe.zig index 623e966..65a9463 100644 --- a/anim/src/loupe.zig +++ b/anim/src/loupe.zig @@ -54,9 +54,15 @@ pub const Loupe = struct { /// `open`: its pointer framed as read; the stem draws and the loupe /// rises with it, its shadow growing; its target's frame lands last. + /// It may open again after a `close`. (Its clock runs on past the + /// open, for the strikes in it: `opening` counts open's lengths.) pub fn open(l: *const Loupe, s: *anim.Frame) void { - s.play(.{l.opening.to(1)}, .{ .seconds = time.open, .ease = anim.ease.linear }); + const start = s.cursor; + s.play(.{ l.opening.to(0), l.closing.to(0) }, .{ .seconds = 0 }); + s.play(.{l.opening.to(open_lengths)}, .{ .seconds = open_lengths * time.open, .ease = anim.ease.linear }); + s.cursor = start + time.open; } + const open_lengths = 8; /// `close`: the stem draws back and the loupe sinks, fading as it falls. pub fn close(l: *const Loupe, s: *anim.Frame) void { @@ -99,14 +105,24 @@ pub const Loupe = struct { const b = back.apply(.{ px[2], px[3] }); pointer = .{ .x = a[0], .y = a[1], .w = b[0] - a[0], .h = b[1] - a[1] }; target = row.fields.base; + // From the band's view it lies over the stack, never the registers (what a step changes there is what the captions are about). + const stack = l.stage.box(u.at, .stack); + const h = theme.layout.panelH(k.rows); + return .{ .box = .{ .x = stack.x, .y = stack.y + stack.h - h, .w = k.width, .h = h }, .pointer = pointer, .target = target, .first = target, .ink = rows.ink(rows.regionOf(moment, target)) }; }, } if (target == 0) return null; // shortcut: it keeps to the stage and does not yet move past the current marks or a changed row; the scene picks a pointer whose loupe covers neither. const stage = theme.canvas.stage; const h = theme.layout.panelH(k.rows); - const x = std.math.clamp(@max(pointer.x - k.hang, right), stage.x, stage.x + stage.w - k.width); - const y = @min(pointer.y + pointer.h - 1, stage.y + stage.h - h); + var x = std.math.clamp(@max(pointer.x - k.hang, right), stage.x, stage.x + stage.w - k.width); + var y = @min(pointer.y + pointer.h - 1, stage.y + stage.h - h); + // A deeper one with no room to the right hangs under the one it opens from, both whole. + if (l.from == .field and x < right) { + const parent = l.from.field.loupe.place(u, now).?.box; + x = parent.x; + y = @min(parent.y + parent.h + k.shadow[0][1], stage.y + stage.h - h); + } return .{ .box = .{ .x = x, .y = y, .w = k.width, .h = h }, .pointer = pointer, .target = target, .first = (target & ~@as(u64, 15)) - 16 * (k.rows / 2), .ink = rows.ink(rows.regionOf(moment, target)) }; } @@ -171,7 +187,10 @@ pub const Loupe = struct { const top = m.tag + m.pad; v.clip(.{ .x = 0, .y = m.tag, .w = b.w, .h = b.h - m.tag }); // By the scene's fields: the rows that hold them, the rest `more`. - if (l.from == .row) hexdump.fielded(.{ .u = v, .rows = k.rows, .box = b }, now, top, l.from.row.fields) else hexdump.drawArcs(v, now, 0, top, p.first, k.rows, .{ .things = things }, true, .{ m.tag, b.h - m.pad }); + // Its fields strike once it has opened, 6 f after it and 6 f apart. + var fields = if (l.from == .row) l.from.row.fields else undefined; + if (l.from == .row and now.walking()) fields.struck = opened - time.open - cursors.write_apart; + if (l.from == .row) hexdump.fielded(.{ .u = v, .rows = k.rows, .box = b }, now, top, fields) else hexdump.drawArcs(v, now, 0, top, p.first, k.rows, .{ .things = things }, true, .{ m.tag, b.h - m.pad }); v.unclip(); // Its target, framed bright: each field of the struct, or the word. const framed = std.math.clamp((since - time.stem - time.frame) / time.frame, 0, 1); @@ -183,8 +202,18 @@ pub const Loupe = struct { for (o.type.record.fields) |field| frameRun(w, row_y, shift, o.addr + field.offset - (p.target & ~@as(u64, 15)), field.type.size() orelse 8); } else frameRun(w, row_y, shift, p.target % 16, 8); } - // The stem: a bracket under the pointer's digits, lying on the tag, drawn head first. const drawn = cursors.standard(std.math.clamp(since / time.stem, 0, 1)) * (1 - closed); + // From a row of the band's view: the stem leaves the row's left, goes down the gutter's right lane, into the tag. + if (l.from == .row) { + const view = l.stage.box(placed, .view); + const mid = p.pointer.y + p.pointer.h / 2; + const lane = view.x - k.lane; + u.faded(@min(rise * 2, 1)).route(&.{ .{ view.x, mid }, .{ lane, mid }, .{ lane, b.y + lower + m.tag / 2 }, .{ b.x - 2, b.y + lower + m.tag / 2 } }, p.ink, .{ .width = theme.stroke.line, .head = .{ 10, 10 }, .radius = 4, .progress = drawn }); + return; + } + // Hung under the one it opens from: the stem goes down from the pointer to its tag. + if (b.y > p.pointer.y + p.pointer.h + 1) u.faded(@min(rise * 2, 1)).fill(.{ .x = p.pointer.x + 8, .y = p.pointer.y + p.pointer.h - 3, .w = k.stem, .h = (b.y + lower - (p.pointer.y + p.pointer.h - 3)) * drawn }, p.ink); + // The stem: a bracket under the pointer's digits, lying on the tag, drawn head first. u.faded(@min(rise * 2, 1)).fill(.{ .x = p.pointer.x - 2, .y = p.pointer.y + p.pointer.h - 3, .w = (p.pointer.w + 4) * drawn, .h = k.stem }, p.ink); } }; diff --git a/anim/src/map.zig b/anim/src/map.zig index e22db9f..341d75f 100644 --- a/anim/src/map.zig +++ b/anim/src/map.zig @@ -36,6 +36,14 @@ pub const diving = struct { pub const surface = 84; }; +/// The dive's frames over which the falling map crossfades into the minimap's drawing. +pub const minimap_lands = [2]f32{ 90, 96 }; + +/// How much of the minimap shows at dive frame `t`: none while the map falls, crossfading in as it lands. +pub fn minimapShows(t: f32) f32 { + return std.math.clamp((t - minimap_lands[0]) / (minimap_lands[1] - minimap_lands[0]), 0, 1); +} + /// Where each working window is on the map this frame, in canvas pixels. var window_px: [7]?[4]f32 = @splat(null); @@ -46,6 +54,16 @@ var windows: [7]?[2]u64 = @splat(null); var rows: [7][160]struct { key: u64, box: [4]f32 } = undefined; var counts: [7]usize = @splat(0); +/// The most rows each map panel has wanted so far (`measure`): its box is +/// as long as that, its content, and no longer. +/// shortcut: process-wide and a frame behind, as the drawing flags are; a scene's first frame packs by the defaults. +var held: [7]usize = @splat(0); + +/// While the map draws: `panel` wants `n` rows for what it shows now. +pub fn measure(panel: Panel, n: usize) void { + if (ui.mapping) held[@intFromEnum(panel)] = @max(held[@intFromEnum(panel)], n); +} + /// A working panel shows the rows of keys `first` to `last`. pub fn window(panel: Panel, first: u64, last: u64) void { if (!ui.mapping) windows[@intFromEnum(panel)] = .{ first, last }; @@ -62,12 +80,13 @@ pub fn row(panel: Panel, key: u64, u: ui.Ui, r: Rect) void { counts[i] += 1; } -/// The map's boxes for a recording: the drawing (with a lens) and the -/// source in the first column, the disassembly in the second, the lens's -/// view (its region whole), the registers and the backtrace in the third, -/// the stack in the fourth. Each as long as its content where that is -/// shorter than the column. -// shortcut: a panel longer than its column is a window of what fits; continuing it in the next column's free space (`continued`), and the key in a column's foot, are not built. +/// The map's boxes for a recording, packed by content: each panel as long +/// as its rows (`measure`), the next under it 12 apart (design/README.md, +/// "The map and the minimap"). The drawing and the source in the first +/// column, the backtrace at its foot; the disassembly in the second; the +/// lens's view, the registers, and in the rest the stack going on +/// (`continued`), in the third; the stack in the fourth, whole. +// shortcut: a column's rest after the disassembly is page: the 5-row dumps round what the registers point at, the open loupes and the key are not built. pub fn split(rec: *const Recording, lens: bool) Split { const st = theme.map.stage; const c = theme.map.columns; @@ -75,21 +94,32 @@ pub fn split(rec: *const Recording, lens: bool) Split { const gap = theme.canvas.row_gap; const panelH = theme.layout.panelH; const foot = st.y + st.h; + const want = struct { + fn of(panel: Panel, default: usize) f32 { + const n = held[@intFromEnum(panel)]; + return @floatFromInt(if (n > 0) n else default); + } + }.of; const band: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = if (lens) theme.layout.split.subject.band.h else 0 }; const source_y = if (lens) band.y + band.h + gap else st.y; - const source_rows: f32 = @floatFromInt(@min(rec.line_count, theme.layout.rowsIn(foot - source_y))); - const view: Rect = .{ .x = c[2], .y = st.y, .w = w, .h = if (lens) panelH(theme.map.memory_rows) else 0 }; + const bt_rows = want(.backtrace, 5); + const source_rows: f32 = @floatFromInt(@min(rec.line_count, theme.layout.rowsIn(foot - source_y - gap - panelH(bt_rows)))); + const source: Rect = .{ .x = c[0], .y = source_y, .w = w, .h = panelH(source_rows) }; + const bt_y = source.y + source.h + gap; + const view: Rect = .{ .x = c[2], .y = st.y, .w = w, .h = if (lens) panelH(@min(want(.view, theme.map.memory_rows), theme.map.memory_rows)) else 0 }; const registers: Rect = .{ .x = c[2], .y = if (lens) view.y + view.h + gap else st.y, .w = w, .h = panelH(17) }; - const bt_y = registers.y + registers.h + gap; + const more_y = registers.y + registers.h + gap; + const more_h = foot - more_y; return .{ .band = band, .view = view, - .source = .{ .x = c[0], .y = source_y, .w = w, .h = panelH(source_rows) }, - .disasm = .{ .x = c[1], .y = st.y, .w = w, .h = panelH(theme.map.disasm_rows) }, + .source = source, + .disasm = .{ .x = c[1], .y = st.y, .w = w, .h = panelH(@min(want(.disasm, theme.map.disasm_rows), theme.map.disasm_rows)) }, .registers = registers, .stack = .{ .x = c[3], .y = st.y, .w = w, .h = st.h }, - .backtrace = .{ .x = c[2], .y = bt_y, .w = w, .h = @min(panelH(12), foot - bt_y) }, + .backtrace = .{ .x = c[0], .y = bt_y, .w = w, .h = @min(panelH(bt_rows), foot - bt_y) }, .dump_rows = theme.map.memory_rows, + .more = .{ .x = c[2], .y = more_y, .w = w, .h = if (more_h >= panelH(3)) theme.layout.panelH(@floor((more_h - 32) / 24)) else 0 }, }; } @@ -108,6 +138,8 @@ pub const Map = struct { t: anim.Value, /// The map as an object of the scene, under the panels: it shows from `show`. obj: anim.Obj = undefined, + /// Where the program is: for the thread across the gutter, and the minimap's flashes. + cursor: ?@import("cursor.zig").Cursor = null, const Part = struct { ctx: *const anyopaque, draw: *const fn (*const anyopaque, *sk.Frame, anim.Placed) void }; @@ -164,33 +196,27 @@ pub const Map = struct { const t = placed.value(m.t); if (t >= diving.land) return; const fixed = @import("words.zig").fixed(f, placed, 0); - // The map: from filling the frame (half its units) to the minimap's rect (a twentieth). - const q = theme.ease(.glide, std.math.clamp((t - diving.move) / diving.fall, 0, 1)); - const mini = theme.minimap.box; - const k = std.math.pow(f32, 0.5, 1 - q) * std.math.pow(f32, theme.minimap.scale, q); - const origin = [2]f32{ q * mini.x, q * mini.y }; - var at = fixed.at; - at.xf = at.xf.mul(.translate(origin[0], origin[1])).mul(.scale(k, k)); - at.scale = fixed.at.scale * k; - fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); - m.drawAt(f, at, k < 0.12); - // The rest of the map veiled from 6 f to 24 f, lifting as it lands. - const veil = std.math.clamp((t - diving.bright) / (diving.move - diving.bright), 0, 1) * (1 - std.math.clamp((t - diving.lift) / (diving.land - diving.lift), 0, 1)); - (ui.Ui{ .f = f, .at = at }).veil(theme.map.stage, veil); - // The windows bright from 0 to 6 f, over the veil. - m.outline(f, at, k < 0.12, std.math.clamp(t / diving.bright, 0, 1)); + const at = m.falling(f, placed, t); + // Large, it is under the panels diving out of it; small (`falling`), over them, into the corner. + if (at.scale >= small * fixed.at.scale) m.copy(f, at, fixed, t) else fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); // Each working panel: from its window on the map at the start to its place, 6 f after the one before. const back = at.xf.invert(); const working = m.frame.now(placed); - inline for (.{ "band", "view", "source", "registers", "disasm", "stack", "backtrace" }, 0..) |name, order| { + // In the frame's reading order, except that a panel drawn over another + // sets off first: a panel in its place is never crossed by one still + // on its way (the disassembly over the source's foot, the stack over + // the registers' lower rows were, for a third of a second). + inline for (.{ "band", "view", "disasm", "stack", "source", "registers", "backtrace" }, 0..) |name, order| { const i = @intFromEnum(@field(Panel, name)); const box = @field(working, name); if (box.h > 0) if (window_px[i]) |w| { const a = back.apply(.{ w[0], w[1] }); const b = back.apply(.{ w[2], w[3] }); - // On the map as it fills the frame (half its units): the panel's rows on the window's rows, its tag above them. + // On the map as it fills the frame (half its units): the panel's rows on the window's rows, its tag above them; + // a window that is the panel whole (the band, the registers) has its tag in it. const s0 = (b[0] - a[0]) / 2 / box.w; - const lead = (if (i == @intFromEnum(Panel.band)) 0 else theme.metric.context.tag + theme.metric.context.pad) * s0; + const whole = i == @intFromEnum(Panel.band) or i == @intFromEnum(Panel.registers); + const lead = (if (whole) 0 else theme.metric.context.tag + theme.metric.context.pad) * s0; const from: Rect = .{ .x = a[0] / 2, .y = a[1] / 2 - lead, .w = box.w * s0, .h = box.h * s0 }; const p = theme.ease(.glide, std.math.clamp((t - diving.move - @as(f32, @floatFromInt(order)) * diving.apart) / diving.travel, 0, 1)); const scale = std.math.pow(f32, s0, 1 - p); @@ -203,6 +229,64 @@ pub const Map = struct { } } + /// Below this scale (of the frame's) the falling map is drawn over the + /// panels, on its way into the corner, and not under them. + const small = 0.12; + + /// Where the map is at dive frame `t`: from filling the frame (half + /// its units) to the minimap's rect (a twentieth), its scale on the + /// logarithm, its corner going toward the minimap's as the scale does, + /// so that it falls into the corner. + fn falling(m: *const Map, f: *sk.Frame, placed: anim.Placed, t: f32) anim.Placed { + _ = m; + const fixed = @import("words.zig").fixed(f, placed, 0); + const q = theme.ease(.glide, std.math.clamp((t - diving.move) / diving.fall, 0, 1)); + const mini = theme.minimap.box; + const k = std.math.pow(f32, 0.5, 1 - q) * std.math.pow(f32, theme.minimap.scale, q); + const toward = (0.5 - k) / (0.5 - theme.minimap.scale); + var at = fixed.at; + at.xf = at.xf.mul(.translate(toward * mini.x, toward * mini.y)).mul(.scale(k, k)); + at.scale = fixed.at.scale * k; + return at; + } + + /// The falling map, veiled, its windows outlined, and its edge as the + /// minimap's; it crossfades into the minimap's own drawing as it lands. + fn copy(m: *const Map, f: *sk.Frame, at: anim.Placed, fixed: ui.Ui, t: f32) void { + const shows = 1 - minimapShows(t); + if (shows <= 0) return; + const mini = at.scale < small * fixed.at.scale; + if (!mini) fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); + var faded = at; + faded.pose.opacity *= shows; + m.drawAt(f, faded, mini); + // The rest of the map veiled from 6 f to 24 f, lifting as it lands. + const veil = std.math.clamp((t - diving.bright) / (diving.move - diving.bright), 0, 1) * (1 - std.math.clamp((t - diving.lift) / (minimap_lands[1] - diving.lift), 0, 1)); + (ui.Ui{ .f = f, .at = faded }).veil(theme.map.stage, veil); + // The windows bright from 0 to 6 f, over the veil. + m.outline(f, faded, mini, std.math.clamp(t / diving.bright, 0, 1)); + var edge: ui.Ui = .{ .f = f, .at = faded }; + edge.at.xf = .identity; + const a = at.xf.apply(.{ 0, 0 }); + const b = at.xf.apply(.{ 2 * theme.canvas.width, 2 * theme.canvas.height }); + const q = std.math.clamp((0.5 * fixed.at.scale - at.scale) / ((0.5 - theme.minimap.scale) * fixed.at.scale), 0, 1); + edge.faded(q).frame(.{ .x = a[0] - 1, .y = a[1] - 1, .w = b[0] - a[0] + 2, .h = b[1] - a[1] + 2 }, theme.color.rule, @max(1, fixed.at.scale)); + } + + /// Small, the falling map over the working panels (the minimap's drawer calls it). + pub fn fallingOver(m: *const Map, f: *sk.Frame, placed: anim.Placed) void { + const t = placed.value(m.t); + if (t >= minimap_lands[1]) return; + const fixed = @import("words.zig").fixed(f, placed, 0); + const at = m.falling(f, placed, t); + if (at.scale >= small * fixed.at.scale) return; + // Its ground, so that it reads over what it passes. + var ground: ui.Ui = .{ .f = f, .at = at }; + ground.at.pose.opacity *= 1 - minimapShows(t); + ground.fill(.{ .x = 0, .y = 0, .w = 2 * theme.canvas.width, .h = 2 * theme.canvas.height }, theme.color.page); + m.copy(f, at, fixed, t); + } + /// The map in `at`'s transform (the map's units), and the working /// frame's windows outlined on it: a 2-unit `dim` frame 4 out; on the /// minimap (`mini`) a pixel of primary, the focused one 1.5. @@ -216,10 +300,56 @@ pub const Map = struct { ui.strokes = mini; counts = @splat(0); for (m.parts[0..m.n]) |p| p.draw(p.ctx, f, at); + if (m.cursor) |c| m.thread(f, at, c.now(at), mini); ui.mapping = false; ui.strokes = false; } + /// The thread on the map: the current line and the pc's row, joined + /// across the gutter between source and disassembly (x 1008), gold; on + /// the minimap a stroke a pixel wide. And there, a mark no working + /// window shows `flash`es: a ring 8 across drawing out to 14 and gone + /// (12 f), with the strike (the minimap's own time, 6 f behind). + fn thread(m: *const Map, f: *sk.Frame, at: anim.Placed, now: @import("cursor.zig").Now, mini: bool) void { + _ = m; + const rec = now.rec; + const k = at.scale; + var raw: ui.Ui = .{ .f = f, .at = at }; + raw.at.xf = .identity; + const marked = now.marked(); + const line = rows_of(.source, rec.own[marked]); + const pc = rows_of(.disasm, rec.register(marked, "rip")); + if (line != null and pc != null) { + const a = line.?; + const b = pc.?; + const lane = at.xf.apply(.{ 1008, 0 })[0]; + const w = if (mini) @max(1, k / theme.minimap.scale) else theme.stroke.line * k; + const gold = theme.mark(.current).solid; + raw.route(&.{ .{ a[2], (a[1] + a[3]) / 2 }, .{ lane, (a[1] + a[3]) / 2 }, .{ lane, (b[1] + b[3]) / 2 }, .{ b[0], (b[1] + b[3]) / 2 } }, gold, .{ .width = w, .head = null, .radius = 0 }); + } + if (!mini or !now.walking()) return; + // A struck word outside every window: the stack's, round its rsp. + const since = now.since(.memory, 0); + const p = since / (12.0 / 60.0); + if (p < 0 or p > 1) return; + const win = windows[@intFromEnum(Panel.stack)] orelse return; + for (rec.written(now.stops[1], now.stops[0])) |span| { + const word = span.addr & ~@as(u64, 7); + if (word >= win[0] and word <= win[1]) continue; + const box = rows_of(.stack, word) orelse continue; + const c = ui.Vec{ (box[0] + box[2]) / 2, (box[1] + box[3]) / 2 }; + const r = std.math.lerp(@as(f32, 4), 7, p) * k / theme.minimap.scale; + raw.faded(1 - p).disc(c, r, null, ui.rgb(theme.color.struck), @max(1, k / theme.minimap.scale)); + } + } + + /// Where the map's row of key `key` in `panel` is this frame, in canvas pixels. + fn rows_of(panel: Panel, key: u64) ?[4]f32 { + const i = @intFromEnum(panel); + for (rows[i][0..counts[i]]) |rw| if (rw.key == key) return rw.box; + return null; + } + /// The working windows' outlines on the map in `at`, `bright` of the way /// from `dim` to bright; where they are is kept (`window_px`). fn outline(m: *const Map, f: *sk.Frame, at: anim.Placed, mini: bool, bright: f32) void { @@ -265,7 +395,10 @@ pub const Map = struct { /// The minimap: `m` at a twentieth in the caption band's right end, still /// while the camera moves; the page under it, framed a pixel in `rule`. pub fn minimap(m: *const Map, f: *sk.Frame, at: anim.Placed) void { - const fixed = @import("words.zig").fixed(f, at, 0); + var shown = at; + shown.pose.opacity *= minimapShows(at.value(m.t)); + if (shown.pose.opacity <= 0) return; + const fixed = @import("words.zig").fixed(f, shown, 0); const box = theme.minimap.box; fixed.fill(box, theme.color.page); var placed = fixed.at; diff --git a/anim/src/nodes.zig b/anim/src/nodes.zig index b4ba951..81a9953 100644 --- a/anim/src/nodes.zig +++ b/anim/src/nodes.zig @@ -71,6 +71,7 @@ pub const Nodes = struct { hi = @max(hi, (a.ptr + a.size + 15) & ~@as(u64, 15)); }; if (lo < hi) { + @import("map.zig").measure(.view, (hi - lo) / 16); const count = theme.layout.rowsIn(g.stage.box(placed, .view).h); const first = hexdump.window(now, lo, hi, count); const shown = @min(count, (hi - first) / 16); diff --git a/anim/src/root.zig b/anim/src/root.zig index 84758f8..e289641 100644 --- a/anim/src/root.zig +++ b/anim/src/root.zig @@ -275,12 +275,14 @@ pub fn context(s: *anim.Frame, cursor_: Cursor, options: Context.Options) Contex var at = cursor_; at.levels.crossings = options.syscalls; // The map first: while it fills the frame or falls to the minimap it is under the panels diving out of it. - const whole = s.new(map.Map{ .stage = Stage.init(s, map.split(at.rec, options.split.band.h > 0)), .frame = stage, .t = s.value(map.diving.land + map.diving.still) }); + const whole = s.new(map.Map{ .stage = Stage.init(s, map.split(at.rec, options.split.band.h > 0)), .frame = stage, .t = s.value(map.diving.land + map.diving.still), .cursor = at }); whole.obj = s.custom(whole, .{ .x = -640, .y = -360, .scale = ui.scale }); whole.add(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent }); if (options.descent) whole.add(s, Descent{ .cursor = at, .stage = whole.stage }) else whole.add(s, Disasm{ .cursor = at, .stage = whole.stage }); whole.add(s, Registers{ .cursor = at, .stage = whole.stage, .syscalls = options.syscalls, .quiet = options.quiet }); whole.add(s, Stack{ .cursor = at, .stage = whole.stage, .above = theme.map.stack_above }); + // The stack goes on in the rest of the memory's column, from where its own column ends. + whole.add(s, Stack{ .cursor = at, .stage = whole.stage, .above = theme.map.stack_above - @as(i32, @intCast(theme.layout.rowsIn(whole.stage.first.stack.h))), .part = .more }); whole.add(s, Backtrace{ .cursor = at, .stage = whole.stage }); return .{ .stage = stage, diff --git a/anim/src/rows.zig b/anim/src/rows.zig index 1d097a1..69aa62b 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -58,6 +58,41 @@ pub const Marks = struct { lead: usize = 0, }; +/// `chain` of a memory access narrower than a word: its address, then what +/// the access reads there at its width (`7fffffffecc4 ◂ 15`), the marks +/// as `chain` takes them (`first`, `read` on the address; `changed` 1 on the value). +pub fn narrow(u: ui.Ui, x: f32, y: f32, moment: Recording.Moment, addr: u64, len: u64, room: f32, marks: Marks) Hops { + const base = baseline(y); + const w = ui.Value.of(addr, true).width(); + const at_addr: Rect = .{ .x = x, .y = y, .w = w, .h = row_h }; + var face_ink: ui.Ink = .{ .ink = ui.rgb(ink(regionOf(moment, addr))) }; + if (u.written(at_addr, marks.first)) |struck| face_ink = struck; + if (marks.read == 0) u.read(at_addr, marks.read_shows); + _ = u.address(x, base, addr, .{ .ink = face_ink.ink, .face = face_ink.face, .lead = marks.lead }); + var hops: Hops = .{ .n = 1, .end = x + w }; + hops.x[0] = x; + hops.w[0] = w; + var raw: [8]u8 = @splat(0); + var known: [8]bool = @splat(false); + moment.read(addr, raw[0..@min(len, 8)], known[0..@min(len, 8)]) catch return hops; + if (std.mem.indexOfScalar(bool, known[0..@min(len, 8)], false) != null) return hops; + const value = std.mem.readInt(u64, &raw, .little); + const shown = ui.Value.of(value, false); + if (hops.end + m.arrow_w + shown.width() > room) return hops; + const at = u.arrow(hops.end, y + row_h / 2, .holds); + const marked: Rect = .{ .x = at, .y = y, .w = shown.width(), .h = row_h }; + var value_ink: ui.Ink = .{ .ink = ui.rgb(t.primary) }; + if (marks.changed == 1) if (u.written(marked, marks.changed_heat)) |struck| { + value_ink = struck; + }; + _ = u.value(at, base, value, false, value_ink); + hops.x[1] = at; + hops.w[1] = shown.width(); + hops.n = 2; + hops.end = at + shown.width() + if (shown.decimal) 8 + @as(f32, @floatFromInt(std.fmt.count("{d}", .{value}))) * adv else 0; + return hops; +} + /// Where a chain's hops were drawn: x and width of each one's digits. pub const Hops = struct { x: [6]f32 = undefined, @@ -348,6 +383,11 @@ pub const Run = struct { /// Its mark: struck (heat), read (shows), held is in the heat. heat: ui.Heat = .none, read: f32 = 0, + /// The bytes of it whose value the heat's step changed, first and last + /// (from `first`): what the strike, the arm and the corner cover. Null: all of it. + changed: ?[2]u8 = null, + /// Frames between the strikes of its bytes, from the low address. + apart: f32 = 1, }; /// `bytes`: a hexdump row of sixteen bytes at `addr`: a bracket at 7 @@ -384,22 +424,28 @@ pub fn bytesAt(at: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *cons const r: Rect = .{ .x = x0, .y = y + 1, .w = x1 - x0, .h = row_h - 2 }; const field = run.kind == .number or run.kind == .pointer or run.kind == .text; if (field) u.fill(r, theme.color.raised); - // Marks per run, never per byte: struck (the softened paper, the - // digits bold and bright), read (a frame 3 out), held (a turned - // corner at the run's top left). - var face: ui.Face = .mono; - var struck_ink: ?ui.Color = null; + // Read is per run (a frame 3 out). A write's marks cover the bytes + // whose value changed, first to last (`changed`): armed, then struck + // a byte a frame from the low address (the softened paper, the + // digits bold and bright), held by a turned corner on the first. const h = run.heat; - if (h.arm > 0) u.faded(h.arm).frame(.{ .x = x0 - 3, .y = y - 1, .w = x1 - x0 + 6, .h = row_h + 2 }, theme.mark(.write).solid, 2); - const solid = if (h.level >= 1) h.solid * h.in else 0; - if (solid > 0) { - u.fill(.{ .x = r.x - h.out, .y = r.y - h.out, .w = r.w + 2 * h.out, .h = r.h + 2 * h.out }, ui.mix(theme.color.raised, theme.color.struck, solid)); - if (solid >= 0.5) { - face = .mono_bold; - struck_ink = ui.rgb(t.bright); - } - } - u.corner(x0, y + 2, m.corner, h.level * h.corner); + const lo: u8 = if (run.changed) |c| c[0] else 0; + const hi: u8 = if (run.changed) |c| c[1] else run.len - 1; + const s0 = byteX(run.first + lo) - 4; + const s1 = byteX(run.first + hi) + 28; + if (h.arm > 0) u.faded(h.arm).frame(.{ .x = s0 - 3, .y = y - 1, .w = s1 - s0 + 6, .h = row_h + 2 }, theme.mark(.write).solid, 2); + var solid_of: [16]f32 = @splat(0); + if (h.level >= 1 and h.solid > 0) for (lo..@as(usize, hi) + 1) |j| { + const i: u8 = @intCast(run.first + j); + const solid = h.solid * std.math.clamp(h.in - @as(f32, @floatFromInt(j - lo)) * run.apart / (60.0 * theme.time.strike.in), 0, 1); + solid_of[j] = solid; + if (solid <= 0) continue; + // Each byte's paper up to the next one's, the pulse on the span's outer edges. + const bx0 = byteX(i) - 4 - if (j == lo) h.out else 0; + const bx1 = (if (j < hi) byteX(i + 1) - 4 else byteX(i) + 28) + if (j == hi) h.out else 0; + u.fill(.{ .x = bx0, .y = r.y - h.out, .w = bx1 - bx0, .h = r.h + 2 * h.out }, ui.mix(theme.color.raised, theme.color.struck, solid)); + }; + u.corner(s0, y + 2, m.corner, h.level * h.corner); if (run.read > 0) u.faded(run.read).frame(.{ .x = x0 - 3, .y = y - 1, .w = x1 - x0 + 6, .h = row_h + 2 }, theme.mark(.read).solid, 2); // A little-endian word: the bytes above its highest non-zero one are its padding. var top: usize = 0; @@ -422,8 +468,9 @@ pub fn bytesAt(at: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *cons u.fill(.{ .x = x + 15, .y = y + 11, .w = 4, .h = 4 }, t.faint); continue; } - const c = struck_ink orelse if (j <= top) run_ink else ui.mix(run_ink, theme.color.page, theme.metric.context.pad_alpha); - u.text(face, size, x, base, u.print("{x:0>2}", .{values[i]}), c); + const struck = solid_of[j] >= 0.5; + const c = if (struck) ui.rgb(t.bright) else if (j <= top) run_ink else ui.mix(run_ink, theme.color.page, theme.metric.context.pad_alpha); + u.text(if (struck) .mono_bold else .mono, size, x, base, u.print("{x:0>2}", .{values[i]}), c); } } } diff --git a/anim/src/source.zig b/anim/src/source.zig index bbc985e..3843825 100644 --- a/anim/src/source.zig +++ b/anim/src/source.zig @@ -58,8 +58,18 @@ pub const Source = struct { const shown_first: u32 = @intFromFloat(windows[if (going >= 0.5) 1 else 0]); // Waiting: the pc is in code with no source, under this line's call. const waits = p.descent and !rec.sourced(now.marked()) and rec.own[now.marked()] != 0; - const note = if (waits) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(firstOwn(rec, now.marked()), "rip")), rec.own[now.marked()], whereIs(u, rec, now.marked()) }) else if (rec.line_count > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, rec.line_count), rec.line_count }) else u.print("{d} lines", .{rec.line_count}); - const body = u.panel(box.w, box.h, rec.file, .{ .focus = p.focus, .note = note }); + const lines_note = if (rec.line_count > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, rec.line_count), rec.line_count }) else u.print("{d} lines", .{rec.line_count}); + // Where the pc is, said where it waits: a change of it (on through a + // stub) crossfades over the 12 f before the advance, never in a frame. + var notes: [2][]const u8 = undefined; + for (now.marks, ¬es) |mk, *note| note.* = if (p.descent and !rec.sourced(mk) and rec.own[mk] != 0) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(firstOwn(rec, mk), "rip")), rec.own[mk], whereIs(u, rec, mk) }) else lines_note; + const swap = !std.mem.eql(u8, notes[0], notes[1]) and (notes[0].ptr != lines_note.ptr or notes[1].ptr != lines_note.ptr) and now.walking(); + const body = u.panel(box.w, box.h, rec.file, .{ .focus = p.focus, .note = if (swap) "" else if (waits) notes[if (going >= 0.5) 1 else 0] else lines_note }); + if (swap) { + const c = std.math.clamp((now.time - now.plan.advance + 12.0 / 60.0) / (12.0 / 60.0), 0, 1); + u.faded(1 - c).tagNote(box.w, notes[0]); + u.faded(c).tagNote(box.w, notes[1]); + } const top = body.y + m.pad; // Where the mark is, and how much of it. diff --git a/anim/src/stage.zig b/anim/src/stage.zig index e650906..a24ec28 100644 --- a/anim/src/stage.zig +++ b/anim/src/stage.zig @@ -10,7 +10,7 @@ const theme = ui.theme; const Split = theme.layout.Split; const Rect = theme.Rect; -pub const Part = enum { band, view, source, disasm, registers, stack, backtrace }; +pub const Part = enum { band, view, source, disasm, registers, stack, backtrace, more }; pub const Stage = struct { first: Split, diff --git a/anim/src/syscalls.zig b/anim/src/syscalls.zig index 4a46170..ca98920 100644 --- a/anim/src/syscalls.zig +++ b/anim/src/syscalls.zig @@ -63,12 +63,15 @@ pub const Plan = struct { pub fn of(call: Recording.Syscall) Plan { var p: Plan = .{}; - // Down: the bytes it was given. Up: the bytes it wrote into the program. - const down: usize = @min(call.text.len, shown_bytes); + // Down: the bytes of a buffer it was given (a path is read as the + // call comes in: no work). Up: the bytes it wrote into the program. + const down: usize = if (bufferRead(call) != null) @min(call.text.len, shown_bytes) else 0; const up: u64 = if (fills(call)) |span| span.len else 0; p.bytes = @floatFromInt(@max(down, @min(up, 32))); - if (p.bytes > 0) p.back = p.fills + p.bytes * byte + 10.0 / 60.0; - p.returns = p.back - 6.0 / 60.0; + // The kernel answers when its work is done; a call with none (open, + // close) at frame 108, straight after its call has come in. + p.returns = if (p.bytes > 0) p.fills + p.bytes * byte + 6.0 / 60.0 else 108.0 / 60.0; + p.back = p.returns + 6.0 / 60.0; p.struck = p.back + cross; p.stored = p.struck + time.cascade; p.advance = p.stored + time.read_value; @@ -76,6 +79,25 @@ pub const Plan = struct { return p; } + /// The plan of the call this step crosses with: stepped over (the step + /// went on from the call row the cascade before it advanced onto), the + /// chart with its frame 18 at the step's first: no second fire. + pub fn in(now: cursors.Now, made: Recording.Syscall) Plan { + const p = of(made); + return if (fromCall(now.rec, now.stops[1])) p.shifted(-time.cascade) else p; + } + + fn shifted(p: Plan, by: f32) Plan { + var q = p; + inline for (.{ "registers", "enters", "leaves", "name", "rows", "card", "work", "fills", "returns", "back", "struck", "stored", "advance", "total" }) |field| @field(q, field) += by; + return q; + } + + /// When byte `k` of what the call fills lands in the program's memory. + pub fn filled(p: Plan, k: u64) f32 { + return p.fills + @as(f32, @floatFromInt(@min(k, 31))) * byte; + } + /// The same as the cursor's plan: the registers are the CPU's level, /// the bytes memory's. pub fn step(p: Plan) cursors.Plan { @@ -88,17 +110,65 @@ pub const Plan = struct { const per_row = 10; const shown_bytes = 2 * per_row; -/// One line of the program and the call into the kernel it makes, as one -/// step of the cursor, timed by the crossing. A line that makes no call -/// is walked like any other. +/// One line of the program and the call into the kernel it makes, timed +/// by the crossing. Stepped over (the line calls libc's wrapper), in two +/// steps of the cursor: the instructions before the call as a cascade, the +/// mark advancing onto the call's row; then the crossing from that row, +/// with what the line stores after the call in memory's slot, after rax. +/// A line that makes no call is walked like any other. pub fn step(c: cursors.Cursor, s: *anim.Frame, by: Recording.Stop) void { + const rec = c.rec; const from = c.moment(s); - const to = c.rec.next(by, from); - const made = for (c.rec.syscalls) |made| { + const to = rec.next(by, from); + const made = for (rec.syscalls) |made| { if (made.enter > from and made.enter <= to) break made; } else return c.walk(s, by, to); - const p = Plan.of(made); - c.step(s, to, p.step(), p.total); + // The call that leads to it: the line's first. + var call = from; + while (call < made.enter and !(if (rec.insn_branches[call]) |b| b.kind == .call else false)) call += 1; + if (call >= made.enter) call = from; + // 1, the instructions before the call: a cascade, the plaque onto the + // call's row 12 f after the last strike, no rest (the line stays current). + if (call > from) { + var before = c.reading(from, call); + const regs_before: f32 = @floatFromInt(@popCount(rec.registersChanged(from, call) & ~cursors.quiet)); + var last = before.at[0] + @min(@max(regs_before - 1, 0), 3) * cursors.write_apart; + for (rec.written(from, call)) |span| if (rec.drawn(span, from, call)) { + last = @max(last, before.at[1]); + }; + before.advance = last + 12.0 / 60.0; + before.travel = time.step; + before.total = before.advance + before.travel; + c.step(s, call, before, before.total); + } + // 2, the crossing from the call row (its chart's frame 18 first); 3, the stores after. + const p = if (call > from) Plan.of(made).shifted(-time.cascade) else Plan.of(made); + var plan = p.step(); + plan.fires = call == from; + // The store after the call: 18 f after rax, and after the registers the call left (6 f apart). + const regs: f32 = @floatFromInt(@popCount(rec.registersChanged(call, to) & ~cursors.quiet)); + const last_register = p.struck + @min(@max(regs - 1, 0), 3) * cursors.write_apart; + var stores = false; + for (rec.written(call, to)) |span| if (rec.drawn(span, call, to)) { + if (fills(made)) |fill| if (span.addr >= fill.addr and span.addr < fill.addr + fill.len) continue; + stores = true; + }; + plan.at[1] = @max(p.stored, last_register + cursors.write_apart); + plan.at[2] = plan.at[1]; + plan.advance = (if (stores) plan.at[1] else last_register) + time.read_value; + plan.total = plan.advance + time.step + time.rest; + c.step(s, to, plan, plan.total); +} + +/// In a crossing, when the kernel's write of the byte at `addr` lands in +/// the program's memory (seconds into the step): what a read fills strikes +/// there as the kernel's work does it, before it returns. Null for any other byte. +pub fn filledAt(now: cursors.Now, addr: u64) ?f32 { + if (!now.crossings) return null; + const made = inStep(now) orelse return null; + const span = fills(made) orelse return null; + if (addr < span.addr or addr >= span.addr + span.len) return null; + return Plan.in(now, made).filled(addr - span.addr); } /// How long after its slot in the cascade a register this step changed @@ -107,10 +177,16 @@ pub fn step(c: cursors.Cursor, s: *anim.Frame, by: Recording.Stop) void { pub fn crossingDelay(now: cursors.Now) f32 { if (!now.crossings) return 0; const made = inStep(now) orelse return 0; - const p = Plan.of(made); + const p = Plan.in(now, made); return p.struck - p.registers; } +/// Whether the instruction at moment `i` is a call: a step from it that +/// crosses into the kernel went over libc's wrapper. +fn fromCall(rec: *const Recording, i: u64) bool { + return if (i < rec.insn_branches.len) if (rec.insn_branches[i]) |b| b.kind == .call else false else false; +} + /// The argument registers of a syscall, in order. const carriers = [_][]const u8{ "rdi", "rsi", "rdx", "r10", "r8", "r9" }; @@ -190,7 +266,7 @@ pub const Crossing = struct { // A crossing's own row comes in once it is back (rax struck), 12 f. var arrives: f32 = 1; if (newest) |n| if (inStep(now) != null and now.walking()) { - const p = Plan.of(rec.syscalls[n]); + const p = Plan.in(now, rec.syscalls[n]); arrives = std.math.clamp((now.time - p.struck - 6.0 / 60.0) / theme.time.quick, 0, 1); }; if (newest) |n| if (n < first) { @@ -208,7 +284,9 @@ pub const Crossing = struct { const v = if (i == n) u.faded(arrives) else u; const y = top + @as(f32, @floatFromInt(j)) * row_h; logRow(v, rec, rec.syscalls[i], y, box.w - theme.metric.context.side); + // The newest's turned corner; the one before keeps it until the new row is in. if (i == n) v.corner(theme.metric.context.side, y + 2, theme.metric.context.corner, 1); + if (i + 1 == n and arrives < 1) u.faded(1 - arrives).corner(theme.metric.context.side, y + 2, theme.metric.context.corner, 1); } } @@ -257,39 +335,61 @@ pub const Crossing = struct { } } - /// Its view: the bytes the newest call is given or fills (its path, a - /// buffer), as a dump over the state column; struck as the kernel - /// fills them. + /// Its view: the bytes the call crossing in this step is given or + /// fills (its path, a buffer), as a dump over the state column. They + /// come in with the argument framing (the note before them out 12 f, + /// they in 12 f); what a read fills lands a byte every 2 f with the + /// kernel's work, struck; a write's buffer is framed as read while the + /// kernel takes it; and they clear with the log's new row. Between + /// crossings the view is clear. fn bytesView(c: *const Crossing, f: *sk.Frame, placed: anim.Placed) void { - const rec = c.cursor.rec; const now = c.cursor.now(placed); - var newest = latest(rec, now.stops[0]); - // No effect before its cause: until the kernel has taken the call, the last one's bytes. - if (newest) |n| if (inStep(now) != null and now.walking() and now.time < Plan.of(rec.syscalls[n]).name) { - newest = if (n > 0) n - 1 else null; - }; - const made: ?Recording.Syscall = if (newest) |n| rec.syscalls[n] else null; + const made: ?Recording.Syscall = if (now.walking()) inStep(now) else null; + const tm = now.time; + const quick = theme.time.quick; + // The call's bytes, and the note that says there is none crossing. + var shows: f32 = 0; + var clear: f32 = 1; + if (made) |given| { + const p = Plan.in(now, given); + const out = std.math.clamp((tm - p.struck - 6.0 / 60.0) / quick, 0, 1); + shows = std.math.clamp((tm - p.registers - quick) / quick, 0, 1) * (1 - out); + clear = @max(1 - std.math.clamp((tm - p.registers) / quick, 0, 1), std.math.clamp((tm - p.struck - 6.0 / 60.0 - quick) / quick, 0, 1)); + } const path_at: ?usize = if (made) |given| std.mem.indexOfScalar(u8, zt.syscalls.signature(given.nr), 's') else null; const span: ?Recording.Span = if (made) |given| bufferRead(given) orelse fills(given) orelse if (given.text.len > 0 and path_at != null) .{ .addr = given.args[path_at.?], .len = given.text.len + 1 } else null else null; - const scratch = context.at(f, placed, c.stage.box(placed, .view)); - const about = if (span) |sp| scratch.print("the {s}, {x} to {x}", .{ if (bufferRead(made.?) != null) "buffer given" else if (fills(made.?) != null) "buffer filled" else "path given", sp.addr, sp.addr + sp.len - 1 }) else "the call names no bytes"; - const v = hexdump.panel(f, placed, c.stage, about, &.{}); + if (span) |sp| @import("map.zig").measure(.view, (sp.len + 15) / 16); + const v = hexdump.panel(f, placed, c.stage, "", &.{}); defer v.u.unclip(); + const note_x = 28 + v.u.width(.sans_medium, theme.size.sans.tag, "its bytes") + 12; + const note_y = theme.metric.context.tag - 6; + if (clear > 0) v.u.faded(clear).text(.sans, theme.size.sans.micro, note_x, note_y, "no call crossing now", theme.color.text.faint); + if (shows <= 0) return; + const given = made.?; + const about = if (span) |sp| v.u.print("the {s}, {x} to {x}", .{ if (bufferRead(given) != null) "buffer given" else if (fills(given) != null) "buffer it fills" else "path given", sp.addr, sp.addr + sp.len - 1 }) else "the call names no bytes"; + v.u.faded(shows).text(.sans, theme.size.sans.micro, note_x, note_y, about, theme.color.text.faint); const sp = span orelse return; if (v.rows == 0) return; // The bytes it names are the field the view is about: a path or a // buffer of text reads as text, anything else is left to the eye. - const given = made.?; - const text = given.text[0..@min(given.text.len, sp.len)]; + const p = Plan.in(now, given); + // What a read fills is what the program's memory holds after it. + var text = given.text[0..@min(given.text.len, sp.len)]; + if (fills(given) != null) { + const after = v.u.f.scratch.alloc(u8, sp.len) catch return; + now.moment().read(sp.addr, after, null) catch return; + text = after; + } const printable = for (text) |byte| { if (!std.ascii.isPrint(byte) and byte != '\n' and byte != '\t' and byte != 0) break false; } else true; - hexdump.fielded(v, now, theme.metric.context.tag + theme.metric.context.pad, .{ + hexdump.fielded(.{ .u = v.u.faded(shows), .rows = v.rows, .box = v.box }, now, theme.metric.context.tag + theme.metric.context.pad, .{ .base = sp.addr, .len = sp.len, .fields = &.{.{ .at = 0, .len = sp.len, .reads = if (printable) .text else .bytes }}, .region = context.ink(context.regionOf(now.moment(), sp.addr)), - .given = .{ .addr = sp.addr, .bytes = text, .shows = 1 }, + .given = .{ .addr = sp.addr, .bytes = text, .shows = 1, .since = if (fills(given) != null) tm - p.fills else null }, + .read = if (bufferRead(given) != null) now.held(p.work) else 0, }); v.veil(now); } @@ -355,14 +455,18 @@ pub const Timeline = struct { }; test "a crossing is as long as what the call does" { - // A call with no work: 3.9 s. Fifteen bytes copied up: 5.0. - try std.testing.expectApproxEqAbs(@as(f32, 3.90), Plan.of(.{ .nr = 3, .args = @splat(0), .enter = 0 }).total, 1e-3); + // A call with no bytes to move: `returns` at 108 f, then the full climb; 3.8 s. Fifteen bytes filled: 5.0. + const close = Plan.of(.{ .nr = 3, .args = @splat(0), .enter = 0 }); + try std.testing.expectApproxEqAbs(@as(f32, 108.0 / 60.0), close.returns, 1e-3); + try std.testing.expectApproxEqAbs(@as(f32, 3.80), close.total, 1e-3); const read = Plan.of(.{ .nr = 0, .args = .{ 3, 0x1000, 32, 0, 0, 0 }, .enter = 0, .exit = 0, .result = 15 }); - try std.testing.expectApproxEqAbs(@as(f32, 4.97), read.total, 1e-2); - // What came back is in the kernel's rows before the arrow back leaves, + try std.testing.expectApproxEqAbs(@as(f32, 5.0), read.total, 1e-2); + // What came back is in the kernel's rows before the answer climbs (24 f), // struck in rax as it lands (armed on its way), then stored. try std.testing.expect(read.returns < read.back and read.struck == read.back + Plan.cross and read.struck - time.strike.arm > read.back and read.stored > read.struck); - // Nothing on the kernel's side before the arrow is through the line. + // Nothing on the kernel's side before the lane is through; the last byte filled before `returns`. try std.testing.expect(read.leaves >= read.enters and read.name >= read.enters + Plan.cross); - try std.testing.expect(read.fills > read.name and read.returns > read.fills + 15 * Plan.byte); + try std.testing.expect(read.fills > read.name and read.returns > read.filled(14)); + // Stepped over: the chart from its frame 18. + try std.testing.expectApproxEqAbs(read.enters - time.cascade, read.shifted(-time.cascade).enters, 1e-4); } diff --git a/anim/src/theme.zig b/anim/src/theme.zig index 0c646d8..78c1d7d 100644 --- a/anim/src/theme.zig +++ b/anim/src/theme.zig @@ -109,6 +109,8 @@ pub const layout = struct { backtrace: Rect, /// `bytes` rows of the lens's dump. dump_rows: u32, + /// On the map: the rest of a column, where the stack goes on (`continued`). + more: Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }, }; pub const split = struct { /// The machine alone: fourteen lines over seventeen instructions; @@ -657,6 +659,8 @@ pub const metric = struct { pub const hang = 92; pub const shadow = [2][2]f32{ .{ 12, 16 }, .{ 20, 26 } }; pub const stem = 4; + /// One hung from the band's view: its stem down the gutter's right lane, this far left of the state column. + pub const lane = 14; }; /// A lens's lanes: projections 4 under its tag, links 8 above its bottom edge. @@ -964,6 +968,9 @@ pub const time = struct { pub const run_max_steps = 24; /// What moves at a run (the mark, a card, an arrow) takes this long. pub const run_ease = 8.0 / 60.0; + /// The minimap follows the frame this far behind: secondary action, it + /// never starts on a primary onset's frame. + pub const minimap_lag = 6.0 / 60.0; /// A hurried step with this long or more is still a whole sentence, /// said faster; with less, it is a run. pub const walk_least = 0.70; diff --git a/anim/src/ui.zig b/anim/src/ui.zig index cf12914..d770e05 100644 --- a/anim/src/ui.zig +++ b/anim/src/ui.zig @@ -247,6 +247,13 @@ pub const Ui = struct { return u.panelChrome(w, h, title, options.focus, options.note, options.legend); } + /// A tag's `note`, ranged right, drawn apart from its panel: for one + /// that crossfades with another. + pub fn tagNote(u: Ui, w: f32, note: []const u8) void { + const micro = theme.size.sans.micro; + u.text(.sans, micro, w - 10 - u.width(.sans, micro, note), theme.metric.context.tag - 6, note, theme.color.text.faint); + } + fn panelChrome(u: Ui, w: f32, h: f32, title: []const u8, focus: bool, note: []const u8, legend: []const Legend) Rect { const options = .{ .focus = focus, .note = note, .legend = legend }; const m = theme.metric.context; diff --git a/anim/src/words.zig b/anim/src/words.zig index 134b42f..280abbc 100644 --- a/anim/src/words.zig +++ b/anim/src/words.zig @@ -68,7 +68,10 @@ pub const Clock = struct { const steps = if (now.of > 0) u.print("step {d} of {d}", .{ now.count, now.of }) else u.print("step {d}", .{now.count}); u.faded(now.hurried).text(.mono, size, count_x - u.width(.mono, size, steps) - 3 * ui.advance(size), base, steps, t.dim); } - if (k.map) |m| if (m.settled(at)) @import("map.zig").minimap(m, f, at); + if (k.map) |m| { + m.fallingOver(f, at); + @import("map.zig").minimap(m, f, at); + } } }; |
