diff options
Diffstat (limited to 'anim/src/context.zig')
| -rw-r--r-- | anim/src/context.zig | 78 |
1 files changed, 59 insertions, 19 deletions
diff --git a/anim/src/context.zig b/anim/src/context.zig index 16278e3..9b466da 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -99,6 +99,10 @@ pub const Registers = struct { /// a row each, with its chain; the rest folded three to a row /// (design/README.md, `registers` `quiet`). All of them on the map. moves: u32 = every, + /// The quiet ones left out, not folded, rip under the rest: a `pair`'s four rows. + folds: bool = true, + /// Its tag's title (a `pair`'s names its run). + title: []const u8 = "registers", const Shown = struct { regs: zt.Regs, moment: Recording.Moment }; @@ -115,7 +119,7 @@ pub const Registers = struct { const was: Shown = .{ .regs = (now.before().regs(rec.tid) catch null) orelse is.regs, .moment = now.before() }; // Taller than its place on its way in: its own page under it. if (fold < 1) u.fill(.{ .x = 0, .y = m.tag, .w = shape.w, .h = shape.h - m.tag }, theme.color.page); - const body = u.panel(shape.w, shape.h, "registers", .{ .focus = r.focus, .legend = &legend }); + const body = u.panel(shape.w, shape.h, r.title, .{ .focus = r.focus, .legend = &legend }); // A link leaves from the panel's edge, not through a name. ties.anchor(u, .registers, .{ .x = 0, .y = 0, .w = shape.w, .h = shape.h }); clipBody(u, shape); @@ -124,7 +128,7 @@ pub const Registers = struct { const full = fullRows(r.moves); const top = body.y + m.pad; // The quiet ones under a rule across, in pwndbg's order; rip the last row. - if (full < 16) u.faded(fold).fill(.{ .x = theme.stroke.rule, .y = top + @as(f32, @floatFromInt(full)) * m.row - 1, .w = shape.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); + if (full < 16 and r.folds) u.faded(fold).fill(.{ .x = theme.stroke.rule, .y = top + @as(f32, @floatFromInt(full)) * m.row - 1, .w = shape.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); var rows_before: usize = 0; var quiet_before: usize = 0; for (theme.metric.all_registers[0..16], 0..) |name, i| { @@ -134,12 +138,13 @@ pub const Registers = struct { rows_before += 1; continue; } + if (!r.folds) continue; const y = std.math.lerp(unfolded, top + @as(f32, @floatFromInt(full + quiet_before / q.quiet_per_row)) * m.row, fold); const x = std.math.lerp(theme.metric.context.side, q.quiet_from + @as(f32, @floatFromInt(quiet_before % q.quiet_per_row)) * q.quiet_pitch, fold); quiet_before += 1; r.quietRow(u, now, is, was, name, x, y, shape.w, fold); } - r.rip(u, now, std.math.lerp(top + 16 * m.row, top + @as(f32, @floatFromInt(registerRows(r.moves) - 1)) * m.row, fold), shape.w, is, was); + r.rip(u, now, std.math.lerp(top + 16 * m.row, top + @as(f32, @floatFromInt(if (r.folds) registerRows(r.moves) - 1 else full)) * m.row, fold), shape.w, is, was); veiled(u, shape, now.veil); } @@ -155,7 +160,7 @@ pub const Registers = struct { _ = rows.reg(u.faded(1 - fold).moved(dx, 0), y, w - dx, name, is.moment, value, .{ .hops = 1 - std.math.clamp(fold / 0.4, 0, 1) }); } const hops = rows.quiet(u.faded(fold), x, y, name, is.moment, value, read_shows); - anchor(u, i, hops, y); + anchor(u, i, hops, y, value, w); } /// Whether `name` carries the system call the step makes, holding @@ -242,7 +247,7 @@ pub const Registers = struct { // `fd`, this call's once it is back, the last one's before. const gave = if (result) made else if (syscalls.latest(rec, now.stops[1])) |n| rec.syscalls[n] else null; if (gave) |g| if (g.exit != null and g.result == value and std.mem.eql(u8, zt.syscalls.name(g.nr) orelse "", "open")) fdNote(u, hops, y, rec.openOn(u.f.scratch, value, g.exit.? + 1)); - return anchor(u, i, hops, y); + return anchor(u, i, hops, y, value, w); } else if (r.quiet) { // Unmarked: the values change as the mark moves on. landed = now.advancing() >= 0.5; @@ -269,7 +274,7 @@ pub const Registers = struct { } const hops = rows.reg(if (ran < 1 and value_was != value_now) u.faded(ran) else u, y, w, name, memory, if (landed or ran < 1) value_now else value_was, marks); fdNote(u.faded(note_shows), hops, y, note); - anchor(u, i, hops, y); + anchor(u, i, hops, y, if (landed or ran < 1) value_now else value_was, w); } /// The `fd` class's note after a register's value: faint, what it is open on. @@ -277,8 +282,12 @@ pub const Registers = struct { if (hops.n > 0 and on.len > 0) u.text(.mono, theme.size.mono.context, hops.end + 8, rows.baseline(y), on, t.faint); } - fn anchor(u: ui.Ui, i: usize, hops: rows.Hops, y: f32) void { - if (hops.n > 0) ties.anchor(u, .{ .register = i }, .{ .x = hops.x[0], .y = y, .w = hops.w[0], .h = m.row }); + /// Its place, and its value shown there (a relation's join: `ties.show`). + fn anchor(u: ui.Ui, i: usize, hops: rows.Hops, y: f32, value: u64, w: f32) void { + if (hops.n == 0) return; + const r: Rect = .{ .x = hops.x[0], .y = y, .w = hops.w[0], .h = m.row }; + ties.anchor(u, .{ .register = i }, r); + ties.show(u, value, r, .registers, 0, @intCast(i), w); } }; @@ -605,7 +614,7 @@ 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, was: ?[]const u8 = null }; + const Span = struct { y0: f32, y1: f32, name: []const u8, newest: bool, open: bool, was: ?[]const u8 = null, shows: f32 = 1 }; // A frame whose name changes in place (on through a stub) crossfades over the 12 f before the advance. const renamed = now.renaming(); const calls_was = rec.stack(u.f.scratch, now.stops[1]); @@ -614,25 +623,53 @@ pub const Stack = struct { var n_spans: usize = 0; // Under `tied` the spans ride rsp's pin: the newest stretches or shrinks with it. const p_span = pin_sp orelse p; + // Each frame is the same frame before and after the step where it ends at the same + // word (a call puts one on top, a return takes one off): never matched by depth. + const sameAs = struct { + fn of(fr: Frame, in: []const Frame) ?usize { + for (in, 0..) |o, idx| if (std.meta.eql(o.hi, fr.hi)) return idx; + return null; + } + }.of; + const n_old = @min(old_chain.len, 16); + var kept: [16]bool = @splat(false); for (chain, 0..) |frame, i| { - const old_frame = if (i < old_chain.len) old_chain[i] else frame; + const j = sameAs(frame, old_chain); + if (j) |q| if (q < kept.len) { + kept[q] = true; + }; + // A new frame grows from its foot. + const old_frame = if (j) |q| old_chain[q] else Frame{ .pc = frame.pc, .lo = frame.hi orelse frame.lo, .hi = frame.hi }; const first = std.math.lerp(rows_of(old_frame.lo, window[0]), rows_of(frame.lo, window[0]), p_span) + slide; if (first >= @as(f32, @floatFromInt(slots))) break; const last = if (frame.hi) |hi| std.math.lerp(if (old_frame.hi) |oh| rows_of(oh, window[0]) else rows_of(hi, window[0]), rows_of(hi, window[0]), p_span) + slide else std.math.inf(f32); if (last < 0) continue; 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); + // Named as the stop the panel shows has it: before the strike by the frame as it was. + const name = if (j == null) spanName(u, rec, calls_is, i, frame.pc) else if (landed) spanName(u, rec, open_calls, i, if (i < named.len) named[i].pc else frame.pc) else spanName(u, rec, open_calls, j.?, old_chain[j.?].pc); + // A new frame comes in as rsp's pin brings it; the newest is the new one from the pin's middle. + spans[n_spans] = .{ .y0 = top + @max(first, 0) * m.row, .y1 = y1, .name = name, .newest = if (p_span < 0.5) (j != null and j.? == 0) or (j == null and i == 0 and old_chain.len == 0) else i == 0, .open = open, .shows = if (j == null and old_chain.len > 0) p_span else 1 }; + if (now.walking() and !jumped) if (j) |q| if (old_chain[q].lo == frame.lo) { + const was_name = spanName(u, rec, calls_was, q, old_chain[q].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; + if (n_spans == spans.len) break; } + // A frame the step takes off shrinks to its foot as rsp's pin falls, and goes with it. + for (old_chain[0..n_old], 0..) |o, q| if (!kept[q] and n_spans < spans.len and !jumped) { + const hi = o.hi orelse continue; + const first = std.math.lerp(rows_of(o.lo, window[0]), rows_of(hi, window[0]), p_span) + slide; + const last = rows_of(hi, window[0]) + slide; + if (last < 0 or first >= @as(f32, @floatFromInt(slots))) continue; + spans[n_spans] = .{ .y0 = top + @max(first, 0) * m.row, .y1 = top + (@min(last, @as(f32, @floatFromInt(slots)) - 1) + 1) * m.row, .name = spanName(u, rec, calls_was, q, o.pc), .newest = q == 0 and p_span < 0.5, .open = false, .shows = 1 - p_span }; + n_spans += 1; + }; // rsp or rbp travelling alone keeps its place in the pin it leaves and // the one it joins: room there, closing and opening as it goes. It // sets off 18 f after rsp's strike (`time.pin`): 24 f to the next @@ -749,6 +786,8 @@ pub const Stack = struct { // 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.address, .y = y, .w = if (hops.n > 0) hops.x[0] + hops.w[0] - theme.metric.slot.address else 120, .h = m.row }); + // Its value, where it may be an address: its first hop. + if (hops.n > 0) if (if (fades) word_is else (Recording.word(now.shownAt(addr, 8), addr, 8) catch null)) |value| ties.show(u, value, .{ .x = hops.x[0], .y = y, .w = hops.w[0], .h = m.row }, .stack, addr, 0, box.w); 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 }); } } @@ -764,7 +803,8 @@ pub const Stack = struct { hexdump.pointerArcs(&arcs, now, word.addr, word.y, at_rows.items, 8, .{ top - m.pad, box.h - m.pad }, false, false); if (arcs.n == before) continue; // Its step's alone: it goes with the advance (18 f), not in the next step's first frame. - if (saved and touched) arcs.items[before].shows *= 1 - std.math.clamp((now.time - now.plan.advance) / time.read.out, 0, 1); + // And it comes as the step begins (12 f), not in its first frame. + if ((saved or saved_was[0]) and touched) arcs.items[before].shows *= @min(1 - std.math.clamp((now.time - now.plan.advance) / time.read.out, 0, 1), if (now.resting()) 1 else std.math.clamp(now.time / time.quick, 0, 1)); // A word becoming a saved rbp, or no longer one, with the step: its arc goes or comes as its role does (12 f). if (!touched and saved != saved_was[0]) arcs.items[before].shows *= if (saved) 1 - recast else recast; } @@ -772,7 +812,7 @@ pub const Stack = struct { // 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]; - if (!ui.mapping) ties.stack_window = .{ .first = window[0], .slots = slots, .x = lane_at[0], .top = lane_at[1], .row = row_px }; + if (!ui.mapping) ties.of(u.f).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; var olds: [2]f32 = undefined; @@ -786,7 +826,7 @@ pub const Stack = struct { place.* = std.math.lerp(at_old, at_new, goes(now, was, is, name)); } // `tied`: rsp's move on its pin as it travels, counting a row at a time, held to the advance and crossfading to the bare name (12 f). - const amount_shows: f32 = if (tied and now.walking() and pin_sp != null and now.time >= now.plan.pins[0]) 1 - std.math.clamp((now.time - now.plan.advance) / time.quick, 0, 1) else 0; + const amount_shows: f32 = if (tied and now.walking() and pin_sp != null and now.time >= now.plan.pins[0]) @min(std.math.clamp((now.time - now.plan.pins[0]) / time.strike.in, 0, 1), 1 - std.math.clamp((now.time - now.plan.advance) / time.quick, 0, 1)) else 0; for (travel, places[0..travel.len], olds[0..travel.len], 0..) |name, place, old, i| { if (i == 1 and @abs(places[0] - place) < 0.05) continue; if (place < (if (tied) @as(f32, -1) else -0.5) or place > (if (tied) slots_f else slots_f - 0.5)) continue; @@ -805,10 +845,10 @@ pub const Stack = struct { if (crossed > 0.05) u.faded(amount_shows).bracket(theme.metric.arc.lanes[0], top + @min(place, old) * m.row + 2, top + @max(place, old) * m.row - 2, theme.mark(.write).solid, theme.metric.bracket.tie, 1, false); } else u.pinRow(x, top + place * m.row, names_, theme.color.region.stack); } - for (spans[0..n_spans]) |sp| if (sp.was) |was_name| { + for (spans[0..n_spans]) |sp| if (sp.shows > 0) if (sp.was) |was_name| { rows.span(v.faded(1 - renamed), map.content(box.w), sp.y0, sp.y1, was_name, sp.newest, sp.open); rows.span(v.faded(renamed), map.content(box.w), sp.y0, sp.y1, sp.name, sp.newest, sp.open); - } else rows.span(v, map.content(box.w), sp.y0, sp.y1, sp.name, sp.newest, sp.open); + } else rows.span(v.faded(sp.shows), map.content(box.w), sp.y0, sp.y1, sp.name, sp.newest, sp.open); veiled(u, box, now.veil); if (k.part == .stack) map.strip(.stack, u, box); } |
