diff options
Diffstat (limited to 'anim/src/context.zig')
| -rw-r--r-- | anim/src/context.zig | 198 |
1 files changed, 133 insertions, 65 deletions
diff --git a/anim/src/context.zig b/anim/src/context.zig index f551aa8..37a95a6 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -62,6 +62,8 @@ pub fn at(f: *sk.Frame, placed: anim.Placed, box: Rect) ui.Ui { ui.chrome = zz.chrome; return u; }; + // Looking at the map alone (`map.looking`): the working panels stand aside. + if (!ui.mapping and map.looking(f)) p.pose.opacity = 0; return (ui.Ui{ .f = f, .at = p }).moved(box.x, box.y); } @@ -126,12 +128,10 @@ pub const Registers = struct { /// disassembly's; it moves with them, at the advance. fn rip(r: *const Registers, u: ui.Ui, now: cursors.Now, y: f32, w: f32, is: Shown, was: Shown) void { const rec = r.cursor.rec; - const moment = now.marks[if (now.advancing() >= 0.5) 1 else 0]; // The flags' corners are secondary: 6 f after the registers strike, // not with them; in a continue's wave, in its place after r15. const delay = if (now.plan.wave) ties.strikeDelay(now, index("eflags").?) else cursors.write_apart; const landed = now.landed(.cpu, delay); - const flags = (if (landed) is else was).regs.eflags; // The flags a step changed have a turned corner, for three steps. const eflags_index = comptime index("eflags").?; // Until this step's change lands, the corners are the last one's: no effect before its cause. @@ -142,7 +142,9 @@ pub const Registers = struct { const held = if (r.quiet) 0 else heat.level * heat.corner; // While a conditional jump runs, the flags it reads are framed (an echo of the row that set them). const reads: u64 = if (now.resting() or now.advancing() >= 0.5) 0 else @import("disasm.zig").readsFlags(rec, now.stops[1]); - rows.rip(u, y, w, rec.moment(moment), rec.register(moment, "rip"), flags, changed, held, 0, reads, now.reading(.cpu, 0)); + // rip crossfades with the advance; a flag set or cleared, over the 6 f it lands in. + const flip = std.math.clamp(now.since(.cpu, delay) / time.strike.in, 0, 1); + rows.rip(u, y, w, rec.moment(now.marks[1]), rec.register(now.marks[1], "rip"), is.regs.eflags, changed, held, 0, reads, now.reading(.cpu, 0), .{ .moment = rec.moment(now.marks[0]), .pc = rec.register(now.marks[0], "rip"), .eflags = was.regs.eflags, .going = now.advancing(), .flip = if (now.resting()) 1 else flip }); } fn row(r: *const Registers, u: ui.Ui, now: cursors.Now, line_is: Shown, line_was: Shown, name: []const u8, y: f32, w: f32) void { @@ -205,7 +207,10 @@ pub const Registers = struct { const since = now.since(.cpu, delay); if (age == 0 and now.walking() and since >= 0) marks.extend = since; } - const hops = rows.reg(u, y, w, name, if (landed) is.moment else was.moment, if (landed) value_now else value_was, marks); + // At a run a value changes in place under an 8 f crossfade, unmarked, never in a frame. + const ran = runFade(now, .cpu); + if (ran < 1 and value_was != value_now) _ = rows.reg(u.faded(1 - ran), y, w, name, was.moment, value_was, marks); + const hops = rows.reg(if (ran < 1 and value_was != value_now) u.faded(ran) else u, y, w, name, if (landed or ran < 1) is.moment else was.moment, if (landed or ran < 1) value_now else value_was, marks); fdNote(u, hops, y, note); anchor(u, i, hops, y); } @@ -220,6 +225,12 @@ pub const Registers = struct { } }; +/// How far (0 to 1) a run's step has crossfaded its values at `level` (8 f from it); 1 at any other pace. +fn runFade(now: cursors.Now, level: cursors.Level) f32 { + if (now.plan.gait != .run or now.resting()) return 1; + return std.math.clamp(now.since(level, 0) / time.run_ease, 0, 1); +} + /// A register's place in `Regs.names`. pub fn index(name: []const u8) ?usize { for (zt.Regs.names, 0..) |known, i| if (std.mem.eql(u8, known, name)) return i; @@ -340,6 +351,8 @@ pub const Stack = struct { // each with the memory of its own stop. const landed = now.landed(.memory, 0); const jumped = far(window[0], window[1], slots); + // On the minimap the window glides there, whether it scrolls or fades here. + const ways = window; const since_memory = now.since(.memory, 0); const jump_shows: f32 = if (!jumped or now.resting()) 1 else if (!landed) 1 - std.math.clamp((since_memory + time.quick) / time.quick, 0, 1) else std.math.clamp((since_memory - time.strike.in / 2.0) / time.quick, 0, 1); if (jumped) window = if (landed) .{ window[0], window[0] } else .{ window[1], window[1] }; @@ -350,7 +363,6 @@ pub const Stack = struct { const hold_scroll: f32 = if (held) @as(f32, @floatFromInt(@as(i64, @bitCast(held_at -% natural)))) / 8 * (1 - cursors.glide(placed.value(k.stage.hold_in))) else 0; // From rsp, or the range shown when the window is elsewhere: in // bytes from rsp, as the catalogue writes it (`rsp+20 to rsp+48`). - const from_rsp: i64 = if (landed) @bitCast(window[0] -% is.rsp) else @bitCast(window[1] -% was.rsp); const offset = struct { fn of(u_: ui.Ui, d: i64) []const u8 { return if (d == 0) "rsp" else if (d > 0) u_.print("rsp+{x}", .{@as(u64, @intCast(d))}) else u_.print("rsp-{x}", .{@as(u64, @intCast(-d))}); @@ -363,8 +375,20 @@ pub const Stack = struct { else => u.print("{d}", .{slots}), }; // The first word shown and the last. - const range = if (from_rsp == 0) u.print("{s} words from rsp", .{words}) else u.print("{s} to {s}", .{ offset(u, from_rsp), offset(u, from_rsp + 8 * (@as(i64, @intCast(slots)) - 1)) }); - const body = u.panel(box.w, box.h, if (k.part == .more) "stack, continued" else "stack", .{ .focus = k.focus, .note = u.print("{s} \u{00b7} the frames they belong to", .{range}) }); + // The range before memory lands and after: one that changes crossfades (12 f), as a role does. + const recast = if (now.resting()) 1 else std.math.clamp(since_memory / time.quick, 0, 1); + const ranges = [2]i64{ @bitCast(ways[1] -% was.rsp), @bitCast(ways[0] -% is.rsp) }; + var notes: [2][]const u8 = undefined; + for (ranges, ¬es) |r_, *note| { + const range = if (r_ == 0) u.print("{s} words from rsp", .{words}) else u.print("{s} to {s}", .{ offset(u, r_), offset(u, r_ + 8 * (@as(i64, @intCast(slots)) - 1)) }); + note.* = u.print("{s} \u{00b7} the frames they belong to", .{range}); + } + const renote = !std.mem.eql(u8, notes[0], notes[1]) and recast < 1; + const body = u.panel(box.w, box.h, if (k.part == .more) "stack, continued" else "stack", .{ .focus = k.focus, .note = if (renote) "" else notes[1] }); + if (renote) { + u.faded(1 - recast).tagNote(box.w, notes[0]); + u.faded(recast).tagNote(box.w, notes[1]); + } 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; @@ -408,7 +432,7 @@ pub const Stack = struct { }.at; 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 renamed = now.renaming(); 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; @@ -453,8 +477,12 @@ pub const Stack = struct { // What each word is, where the recording says (`zt.telescope.slots`): // a register saved for the caller, a local, the process's first stack. const roles_from = window[0] -% 16; - var roles_buf: [80]zt.telescope.Slot = undefined; - const roles = zt.telescope.slots(memory, if (landed) &is else &was, roles_from, roles_buf[0..@min(slots + 4, roles_buf.len)]) catch roles_buf[0..0]; + // Before the step and after it: a role that changes crossfades as memory strikes (12 f). + var roles_buf: [2][80]zt.telescope.Slot = undefined; + const roles = [2][]zt.telescope.Slot{ + zt.telescope.slots(now.before(), &was, roles_from, roles_buf[0][0..@min(slots + 4, roles_buf[0].len)]) catch roles_buf[0][0..0], + zt.telescope.slots(now.moment(), &is, roles_from, roles_buf[1][0..@min(slots + 4, roles_buf[1].len)]) catch roles_buf[1][0..0], + }; // The words that point at other words of the window: `arc`s. var at_rows: std.ArrayList(hexdump.RowAt) = .empty; var pointers: std.ArrayList(struct { hexdump.RowAt, bool }) = .empty; @@ -470,8 +498,8 @@ pub const Stack = struct { marks.read = 0; marks.read_shows = now.reading(.memory, 0); } - const below_rsp: i64 = @bitCast(addr -% rsp_shown); - if (k.part == .stack) map.row(.stack, addr, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row }); + const below_rsp: i64 = @bitCast(addr -% if (held) rsp_shown else is.rsp); + 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); @@ -492,9 +520,21 @@ pub const Stack = struct { const gapped = gap > 0 and names.names.len > 0 and names.shows > 0; if (gapped) pinGap(v.faded(names.shows), y, names.names, lone.?, gap); 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, now.shownAt(addr), addr, below_rsp, if (gapped) &.{} else names.names, names.shows, marks, role.name, role.local); + var role_at: [2]@TypeOf(roleName(u, .none, 0)) = undefined; + for (&role_at, roles, [2]Recording.Moment{ now.before(), now.moment() }) |*r, of, mem| { + const what: zt.telescope.Role = if (k_role < of.len) of[k_role].role else .none; + r.* = roleName(u, what, (Recording.word(mem, addr, 8) catch null) orelse 1); + } + const what: zt.telescope.Role = if (k_role < roles[1].len) roles[1][k_role].role else .none; + const role = role_at[1]; + const role_was: rows.Role = .{ .name = role_at[0].name, .local = role_at[0].local, .going = recast, .from_rsp = @bitCast(addr -% was.rsp) }; + // At a run a word changes in place under an 8 f crossfade, as a register does. + const ran = runFade(now, .memory); + const word_was = Recording.word(now.before(), addr, 8) catch null; + const word_is = Recording.word(now.moment(), addr, 8) catch null; + const fades = ran < 1 and !std.meta.eql(word_was, word_is); + if (fades) _ = rows.slot(v.faded(1 - ran), y, room_w, now.before(), addr, below_rsp, &.{}, 0, marks, role.name, role.local, role_was); + const hops = rows.slot(if (fades) v.faded(ran) else v, y, room_w, if (fades) now.moment() else now.shownAt(addr), addr, below_rsp, if (gapped) &.{} else names.names, names.shows, marks, role.name, role.local, role_was); 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. @@ -503,13 +543,16 @@ pub const Stack = struct { ties.anchor(u, .{ .slot_pin = addr }, .{ .x = theme.metric.slot.lane, .y = y, .w = theme.metric.slot.lane_end - theme.metric.slot.lane, .h = m.row }); } } - map.window(.stack, shown_at, shown_at + 8 * (@as(u64, slots) -| 1)); + if (k.part == .stack) map.window(.stack, .{ ways[0], ways[0] + 8 * (@as(u64, slots) -| 1) }, .{ ways[1], ways[1] + 8 * (@as(u64, slots) -| 1) }, p); // A frame's saved rbp is drawn by its span: its arc only in a step that touches it. var arcs: rows.Arcs = .{}; for (pointers.items) |p_| { const word, const saved = p_; if (saved and !(now.writeAge(word.addr, 8) == 0 or now.wasRead(word.addr, 8))) continue; + const before = arcs.n; hexdump.pointerArcs(&arcs, now, word.addr, word.y, at_rows.items, 8, .{ top - m.pad, box.h - m.pad }, false, false); + // Its step's alone: it goes with the advance (18 f), not in the next step's first frame. + if (saved and arcs.n > before) arcs.items[before].shows *= 1 - std.math.clamp((now.time - now.plan.advance) / time.read.out, 0, 1); } arcs.draw(v, theme.metric.arc.stack_lanes); // Where the window is, for a link to a word outside it. @@ -666,59 +709,84 @@ pub const Backtrace = struct { if (box.h < m.tag) return; const u = if (b.lens) at(f, placed, box).faded(placed.value(b.stage.drawing)) else at(f, placed, box); const now = b.cursor.now(placed); - const rec = b.cursor.rec; - // A frame is its words on the stack: the chain changes with memory. - // The frames both chains have (the same way back, counted from the - // oldest) slide to their new depth, as rows making room; those that - // end fade out first, those that begin fade in after. - var new_buf: [24]Frame = undefined; - var old_buf: [24]Frame = undefined; - const chains = [2][]Frame{ frames(rec, now.stops[1], &old_buf), frames(rec, now.stops[0], &new_buf) }; - var shared: usize = 0; - while (shared < @min(chains[0].len, chains[1].len) and chains[0][chains[0].len - 1 - shared].pc == chains[1][chains[1].len - 1 - shared].pc) shared += 1; - const since = if (now.walking()) now.since(.memory, 0) else if (now.landed(.memory, 0)) std.math.inf(f32) else -std.math.inf(f32); - const leave = std.math.clamp(since / time.quick, 0, 1); - const slide = cursors.glide(std.math.clamp((since - time.quick / 2.0) / time.move, 0, 1)); - 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(); - const opens = [2][]const Recording.Call{ rec.stack(u.f.scratch, now.stops[1]), rec.stack(u.f.scratch, now.stops[0]) }; - const top = body.y + m.pad; - // Newest at the bottom, `#0` last: a frame's row is its place from - // the oldest, less the oldest that do not fit (dropped from the top). - const dropped = [2]usize{ chains[0].len -| room, chains[1].len -| room }; - for (chains, 0..) |chain, side| { - const shows = if (side == 0) 1 - leave else arrive; - for (chain, 0..) |frame, i| { - const from_end = chain.len - 1 - i; - const kept = from_end < shared; - // A frame both have is drawn once, from the old chain to its place in the new. - if (kept and side == 1) continue; - var at_row = @as(f32, @floatFromInt(from_end)) - @as(f32, @floatFromInt(dropped[side])); - var depth = i; - var which = side; - if (kept) { - const to = chains[1].len - 1 - from_end; - at_row = std.math.lerp(at_row, @as(f32, @floatFromInt(from_end)) - @as(f32, @floatFromInt(dropped[1])), slide); - if (slide >= 0.5) { - depth = to; - which = 1; - } - } else if (shows <= 0) continue; - if (at_row <= -1 or at_row >= @as(f32, @floatFromInt(room))) continue; - const v = if (kept) u else u.faded(shows); - const name = ui.symbol(u, rec.strings.get(frame.pc) orelse u.print("{x}", .{frame.pc})); - rows.callRow(v, top + at_row * m.row, box.w, depth, name, callArguments(u, rec, opens[which], depth, frame.pc), frameWhere(u, rec, if (which == 1) now.marks[1] else now.marks[0], depth, frame.pc), depth == 0); - } - } + backtraceRows(u, now, b.cursor.rec, box, b.focus, ""); veiled(u, box, now.veil); } }; +/// A backtrace's panel and rows in `u`'s `box` (the panel, a lens's +/// drawing, the calls lens's view: its tag's note after `prefix`). +/// A frame is its words on the stack: the chain changes with memory. The +/// frames both chains have (the same way back, counted from the oldest) +/// slide to their new depth, as rows making room; those that end fade out +/// first, those that begin fade in after. What a kept row says that +/// changes (its depth, its pc's offset, its line) crossfades over the 12 f +/// before the advance, as a stack span's name does; the newest's wash goes +/// from one row to the other the same way. Nothing changes in a frame. +pub fn backtraceRows(u: ui.Ui, now: cursors.Now, rec: *const Recording, box: Rect, focus: bool, prefix: []const u8) void { + var new_buf: [24]Frame = undefined; + var old_buf: [24]Frame = undefined; + const chains = [2][]Frame{ frames(rec, now.stops[1], &old_buf), frames(rec, now.stops[0], &new_buf) }; + var shared: usize = 0; + while (shared < @min(chains[0].len, chains[1].len) and chains[0][chains[0].len - 1 - shared].pc == chains[1][chains[1].len - 1 - shared].pc) shared += 1; + // The newest frame's pc is the step's: it is the same frame whatever its offset. + if (shared < @min(chains[0].len, chains[1].len) and chains[0].len == chains[1].len and shared + 1 == chains[0].len) shared += 1; + const since = if (now.walking()) now.since(.memory, 0) else if (now.landed(.memory, 0)) std.math.inf(f32) else -std.math.inf(f32); + const leave = std.math.clamp(since / time.quick, 0, 1); + const slide = cursors.glide(std.math.clamp((since - time.quick / 2.0) / time.move, 0, 1)); + const arrive = std.math.clamp((since - time.quick / 2.0 - time.move) / time.quick, 0, 1); + const renamed = now.renaming(); + const room = rowsOf(box); + map.measure(.backtrace, @max(chains[0].len, chains[1].len)); + const notes = [2][]const u8{ u.print("{s}{s}", .{ prefix, newestAtBottom(u, chains[0].len, room) }), u.print("{s}{s}", .{ prefix, newestAtBottom(u, chains[1].len, room) }) }; + const renote = !std.mem.eql(u8, notes[0], notes[1]); + const body = u.panel(box.w, box.h, "backtrace", .{ .focus = focus, .note = if (renote) "" else notes[1] }); + if (renote) { + u.faded(1 - slide).tagNote(box.w, notes[0]); + u.faded(slide).tagNote(box.w, notes[1]); + } + clipBody(u, box); + defer u.unclip(); + const opens = [2][]const Recording.Call{ rec.stack(u.f.scratch, now.stops[1]), rec.stack(u.f.scratch, now.stops[0]) }; + const top = body.y + m.pad; + // Newest at the bottom, `#0` last: a frame's row is its place from + // the oldest, less the oldest that do not fit (dropped from the top). + const dropped = [2]usize{ chains[0].len -| room, chains[1].len -| room }; + const Row = struct { depth: usize, name: []const u8, args: []const u8, where: []const u8 }; + for (chains, 0..) |chain, side| { + const shows = if (side == 0) 1 - leave else arrive; + for (chain, 0..) |frame, i| { + const from_end = chain.len - 1 - i; + const kept = from_end < shared; + // A frame both have is drawn once, from the old chain to its place in the new. + if (kept and side == 1) continue; + var at_row = @as(f32, @floatFromInt(from_end)) - @as(f32, @floatFromInt(dropped[side])); + const here: Row = .{ .depth = i, .name = ui.symbol(u, rec.strings.get(frame.pc) orelse u.print("{x}", .{frame.pc})), .args = callArguments(u, rec, opens[side], i, frame.pc), .where = frameWhere(u, rec, now.marks[side], i, frame.pc) }; + if (!kept) { + if (shows <= 0 or at_row <= -1 or at_row >= @as(f32, @floatFromInt(room))) continue; + rows.callRow(u.faded(shows), top + at_row * m.row, box.w, here.depth, here.name, here.args, here.where, here.depth == 0); + continue; + } + const to = chains[1].len - 1 - from_end; + const next = chains[1][to]; + const there: Row = .{ .depth = to, .name = ui.symbol(u, rec.strings.get(next.pc) orelse u.print("{x}", .{next.pc})), .args = callArguments(u, rec, opens[1], to, next.pc), .where = frameWhere(u, rec, now.marks[1], to, next.pc) }; + at_row = std.math.lerp(at_row, @as(f32, @floatFromInt(from_end)) - @as(f32, @floatFromInt(dropped[1])), slide); + if (at_row <= -1 or at_row >= @as(f32, @floatFromInt(room))) continue; + const y = top + at_row * m.row; + // The wash where the row is the newest, going and coming with the words. + const washed = @as(f32, if (here.depth == 0) 1 - renamed else 0) + @as(f32, if (there.depth == 0) renamed else 0); + if (washed > 0) rows.callCurrent(u.faded(washed), y, box.w); + const same = here.depth == there.depth and std.mem.eql(u8, here.name, there.name) and std.mem.eql(u8, here.args, there.args) and std.mem.eql(u8, here.where, there.where); + if (same) { + rows.callLabels(u, y, box.w, there.depth, there.name, there.args, there.where, there.depth == 0); + } else { + rows.callLabels(u.faded(1 - renamed), y, box.w, here.depth, here.name, here.args, here.where, here.depth == 0); + rows.callLabels(u.faded(renamed), y, box.w, there.depth, there.name, there.args, there.where, there.depth == 0); + } + } + } +} + /// A backtrace's tag note: `newest at the bottom`, and how many of the /// oldest a panel of `room` rows leaves out above. pub fn newestAtBottom(u: ui.Ui, total: usize, room: usize) []const u8 { |
