diff options
Diffstat (limited to 'anim/src/context.zig')
| -rw-r--r-- | anim/src/context.zig | 90 |
1 files changed, 78 insertions, 12 deletions
diff --git a/anim/src/context.zig b/anim/src/context.zig index 9874cd7..e5a226a 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -16,6 +16,8 @@ const cursors = @import("cursor.zig"); const Recording = @import("Recording.zig"); const syscalls = @import("syscalls.zig"); const ties = @import("ties.zig"); +const hexdump = @import("hexdump.zig"); +const map = @import("map.zig"); const Stage = @import("stage.zig").Stage; const theme = ui.theme; const time = theme.time; @@ -39,9 +41,28 @@ pub const legend = blk: { }; }; -/// A panel's `Ui`, moved to where the stage has its box now. +/// While a `dive` or a `surface` plays (`map.Map`): each working panel's +/// box, and the rect it is drawn into instead, on its way between its +/// window on the map and its place; its tags, rules and lanes how much shown. +pub const Zoom = struct { box: Rect, to: Rect, chrome: f32 }; +pub var zoomed: [8]?Zoom = @splat(null); + +/// A panel's `Ui`, moved to where the stage has its box now (or, in a +/// dive, scaled into the rect it is on its way through). pub fn at(f: *sk.Frame, placed: anim.Placed, box: Rect) ui.Ui { - return (ui.Ui{ .f = f, .at = placed }).moved(box.x, box.y); + var p = placed; + ui.chrome = 1; + if (!ui.mapping) for (zoomed) |z| if (z) |zz| if (@abs(zz.box.x - box.x) < 0.5 and @abs(zz.box.y - box.y) < 0.5 and @abs(zz.box.h - box.h) < 0.5) { + const k = zz.to.w / box.w; + p.xf = p.xf.mul(.translate(zz.to.x, zz.to.y)).mul(.scale(k, k)).mul(.translate(-box.x, -box.y)); + p.scale *= k; + // On its way it is opaque, over the panels that set off before it; its tag and rules come in at the end. + const u = (ui.Ui{ .f = f, .at = p }).moved(box.x, box.y); + u.fill(.{ .x = 0, .y = m.tag, .w = box.w, .h = box.h - m.tag }, theme.color.page); + ui.chrome = zz.chrome; + return u; + }; + return (ui.Ui{ .f = f, .at = p }).moved(box.x, box.y); } pub fn veiled(u: ui.Ui, box: Rect, amount: f32) void { @@ -106,18 +127,19 @@ pub const Registers = struct { fn rip(r: *const Registers, u: ui.Ui, now: cursors.Now, y: f32, w: f32, is: Shown, was: Shown) void { const rec = r.cursor.rec; const moment = now.marks[if (now.advancing() >= 0.5) 1 else 0]; - // The flags' ticks are secondary: 6 f after the registers strike, + // 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 are ticked, for three steps. + // 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 ticks are the last one's: no effect before its cause. + // Until this step's change lands, the corners are the last one's: no effect before its cause. const age = if (landed) now.registerAge(eflags_index) else now.registerAgeFrom(eflags_index, 1); var changed: u64 = 0; if (age) |a| changed = rec.register(now.stops[a], "eflags") ^ rec.register(now.stops[a + 1], "eflags"); - const held = if (r.quiet) 0 else now.register(eflags_index, delay).level; + const heat = now.register(eflags_index, delay); + const held = if (r.quiet) 0 else heat.level * heat.corner; rows.rip(u, y, w, rec.moment(moment), rec.register(moment, "rip"), flags, changed, held, 0); } @@ -283,6 +305,8 @@ 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, pub fn draw(k: *const Stack, f: *sk.Frame, placed: anim.Placed) void { const box = k.stage.box(placed, .stack); @@ -301,7 +325,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 [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 -% 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) }; // 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, @@ -404,6 +428,16 @@ pub const Stack = struct { }.of; const size = theme.size.mono.context; const lone: ?[]const u8 = if (travel.len == 1) travel[0] else null; + // The offsets are from the rsp of the rows shown: they change with the slide, not before it. + const rsp_shown = if (landed) is.rsp else was.rsp; + // 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]; + // 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; var n: i64 = @as(i64, @intFromFloat(@floor(-slide))) - 1; while (n <= @as(i64, @intCast(slots)) - @as(i64, @intFromFloat(@floor(slide)))) : (n += 1) { const y = top + (@as(f32, @floatFromInt(n)) + slide) * m.row; @@ -416,9 +450,11 @@ pub const Stack = struct { marks.read = 0; 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 }); // `free`: above rsp, not yet reached: its address at 60%, its word faint. - if (held and addr < (if (landed) is.rsp else was.rsp)) { - rows.free(v, y, memory, addr, lead); + if (held and addr < rsp_shown) { + rows.free(v, y, memory, addr, below_rsp, lead); continue; } // A frame's name beside this row: the chain ends a character before it. @@ -435,17 +471,31 @@ 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 hops = rows.slot(v, y, room_w, memory, addr, if (gapped) &.{} else names.names, names.shows, marks); + 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); + 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. if (y >= top - 1 and y + m.row <= box.h - m.pad + 1) { - ties.anchor(u, .{ .word = addr }, .{ .x = theme.metric.slot.chain, .y = y, .w = if (hops.n > 0) hops.x[0] + hops.w[0] - theme.metric.slot.chain else 120, .h = m.row }); + ties.anchor(u, .{ .word = addr }, .{ .x = theme.metric.slot.address, .y = y, .w = if (hops.n > 0) hops.x[0] + hops.w[0] - theme.metric.slot.address else 120, .h = m.row }); 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)); + // 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; + hexdump.pointerArcs(&arcs, now, word.addr, word.y, at_rows.items, 8, .{ top - m.pad, box.h - m.pad }, false); + } + arcs.draw(v, theme.metric.arc.stack_lanes); // Where the window is, for a link to a word outside it. const lane_at = u.at.xf.apply(.{ theme.metric.slot.lane, top }); const row_px = u.at.xf.apply(.{ 0, top + m.row })[1] - lane_at[1]; - ties.stack_window = .{ .first = window[0], .slots = slots, .x = lane_at[0], .top = lane_at[1], .row = row_px }; + if (!ui.mapping) ties.stack_window = .{ .first = window[0], .slots = slots, .x = lane_at[0], .top = lane_at[1], .row = row_px }; // The travelling tags: both of them at one word share a pin. var places: [2]f32 = undefined; for (travel, places[0..travel.len]) |name, *place| { @@ -465,6 +515,22 @@ pub const Stack = struct { veiled(u, box, now.veil); } + /// A slot's role as the catalogue writes it: `saved rbx` (dim); a + /// local's name (primary, `+8` a word into it); `argc`, `argv[0]`, + /// `argv end`, `envp end`, `auxv` (dim). A return address needs none: + /// its chain is code, named. `word`: what the slot holds (0 ends argv and envp). + fn roleName(u: ui.Ui, role: zt.telescope.Role, word: u64) struct { name: []const u8, local: bool = false } { + 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 }, + .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}) }, + .auxv => |i| .{ .name = if (i == 0) "auxv" else "" }, + }; + } + /// Where `name` goes in a row pin of `others` and it, in the registers' order. fn pinPlace(u: ui.Ui, others: []const []const u8, name: []const u8) f32 { const size = theme.size.mono.context; |
