summaryrefslogtreecommitdiff
path: root/anim/src/hexdump.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-11 09:41:45 -0300
committerGabriel Schneider <[email protected]>2026-11-11 10:14:30 -0300
commit390872b7bb9cdcf3e8095442af88af0dfcb40602 (patch)
treeab767cf46dfca036e61e0e19bb5e1c4772cb1d4d /anim/src/hexdump.zig
parent378379807fb4cd751e90808c8363caddb365bcd8 (diff)
downloadcomputeranim-390872b7bb9cdcf3e8095442af88af0dfcb40602.tar.gz
computeranim-390872b7bb9cdcf3e8095442af88af0dfcb40602.zip
canim: what the verification review found, fixed
A register's chain reads memory as its panel shows it, and follows again only after the bytes land: rsi no longer shows what read returns before the kernel writes it. Bytes keep their old value through the arm and change at their own strike, in every dump, stack word and loupe. The dive lands once. Captions lead what they name: the longest still in the syscalls scene is 2.8 s where it was 13. Pins hold through a sprint; a row of a view carries the pin of the register that points at it; a left child's badge sits on its left shoulder; a log scrolls with the row that arrives. The zoom scene's camera holds the disassembly's rows and the stack in one view. Six programs, the title says now. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src/hexdump.zig')
-rw-r--r--anim/src/hexdump.zig110
1 files changed, 103 insertions, 7 deletions
diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig
index 47283e7..21db91f 100644
--- a/anim/src/hexdump.zig
+++ b/anim/src/hexdump.zig
@@ -65,6 +65,8 @@ pub const Of = struct {
things: []const objects.Object = &.{},
array: ?struct { addr: u64, len: u64, elem: u8, type: ?Recording.types.Type = null } = null,
region: u24 = theme.color.region.heap,
+ /// A lens's view: a row a register points into carries its pin (`rowPin`).
+ pins: bool = false,
};
/// The band's view of bytes: its own panel over the state column, the
@@ -106,6 +108,7 @@ pub const Dump = struct {
if (v.rows == 0) return;
const now = d.cursor.now(placed);
var of = d.of;
+ of.pins = true;
of.watched = 0;
while (of.watched + 1 < now.stops.len and now.stops[of.watched + 1] >= d.since) of.watched += 1;
var shows: [8]f32 = @splat(0);
@@ -151,7 +154,9 @@ pub const View = struct {
/// always, with `loud`: a loupe's). `rule`: the panel's top and bottom,
/// where a stub to a row past the window ends.
pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize, of: Of) void {
- drawArcs(u, now, x, y, first, count, of, false, .{ y - m.pad, y + @as(f32, @floatFromInt(count)) * m.row + m.pad });
+ var view = of;
+ view.pins = true;
+ drawArcs(u, now, x, y, first, count, view, false, .{ y - m.pad, y + @as(f32, @floatFromInt(count)) * m.row + m.pad });
}
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 {
@@ -174,6 +179,7 @@ pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: u
moment.read(addr, &values, &known) catch return;
var runs: [16]rows.Run = undefined;
var readings: [16]Field = undefined;
+ var keeps: [16]bool = @splat(false);
var n: usize = 0;
var holds_drawn = false;
var at: u64 = 0;
@@ -206,6 +212,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.struckAgo(here, run.len)) |ago| keeps[n] = ago < theme.time.strike.in / 2.0;
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) {
@@ -218,9 +225,11 @@ pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: u
at += run.len;
}
@import("map.zig").row(.view, addr, v, .{ .x = 0, .y = ry, .w = theme.layout.state.w, .h = m.row });
+ keepOld(now, addr, &values, &known, runs[0..n], keeps[0..n]);
rows.bytesAt(v, ry, addr, &values, &known, runs[0..n], of.region, lead, holds_drawn, moment, shift);
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]);
+ const room = if (!of.pins) full_room else if (pass == 0) rowPin(dump, now, addr, ry) else rowPinRoom(dump, now, addr);
+ const end = readingIn(v, ry, shift, moment, &values, &known, readings[0..n], room);
// The size word of the chunk after: malloc's, a note after the reading.
const last = runs[n - 1];
if (last.kind == .loose and last.first == 8 and last.len == 8 and std.mem.indexOfScalar(bool, known[8..], false) == null and chunkAfter(moment, addr + 8)) {
@@ -263,6 +272,65 @@ fn rowPasses(now: cursors.Now, addr: u64) Passes {
return plain;
}
+/// The registers whose value is in the row `addr .. addr + 16`, as a step
+/// moves them (`ties.pinShows`: a name joining or leaving fades through the
+/// middle of its change), in pwndbg's order: a view's row a register points
+/// into carries its pin, at the row's end (`Ui.pinEnd`). Draws it and
+/// returns where the reading must end; publishes the row as a link's
+/// target (`dump_pin`), its left edge.
+fn rowPin(u: ui.Ui, now: cursors.Now, addr: u64, y: f32) f32 {
+ ties.anchor(u, .{ .dump_pin = addr }, .{ .x = 0, .y = y, .w = b.bracket, .h = m.row });
+ const at = pinned(u, now, addr);
+ if (at.names.len == 0 or at.shows <= 0) return full_room;
+ const x = u.faded(at.shows).pinEnd(full_room, y, at.names, rows.ink(rows.regionOf(now.moment(), addr)));
+ return x - adv;
+}
+
+/// Where the reading of a row must end for its pin (`rowPin`), not drawing it.
+fn rowPinRoom(u: ui.Ui, now: cursors.Now, addr: u64) f32 {
+ const at = pinned(u, now, addr);
+ if (at.names.len == 0 or at.shows <= 0) return full_room;
+ const p = theme.metric.pin;
+ var shown: []const u8 = "";
+ for (at.names[0..@min(at.names.len, 3)], 0..) |name, i| shown = if (i == 0) name else u.print("{s} {s}", .{ shown, name });
+ if (at.names.len > 3) shown = u.print("{s} +{d}", .{ shown, at.names.len - 3 });
+ return full_room - u.width(.mono, theme.size.mono.context, shown) - p.row_gap - p.row_head[0] - adv;
+}
+
+fn pinned(u: ui.Ui, now: cursors.Now, addr: u64) struct { names: []const []const u8, shows: f32 } {
+ const rec = now.rec;
+ const context = @import("context.zig");
+ const is = (now.moment().regs(rec.tid) catch null) orelse return .{ .names = &.{}, .shows = 0 };
+ const was = (now.before().regs(rec.tid) catch null) orelse is;
+ var names: std.ArrayList([]const u8) = .empty;
+ var shows: f32 = 1;
+ for (theme.metric.all_registers[0..16]) |name| {
+ const in_was = if (was.named(name)) |v| v >= addr and v < addr + 16 else false;
+ const in_is = if (is.named(name)) |v| v >= addr and v < addr + 16 else false;
+ if (!in_was and !in_is) continue;
+ const s = ties.pinShows(now, context.index(name).?, .node);
+ const this: f32 = if (in_was and in_is) 1 else if (in_is) s.new else s.old;
+ if (in_was != in_is) shows = @min(shows, @abs(2 * this - 1));
+ if (this < 0.5) continue;
+ names.append(u.f.scratch, name) catch break;
+ }
+ return .{ .names = names.items, .shows = shows };
+}
+
+/// The runs this step writes whose strike has not landed (`keeps`) keep
+/// the bytes they had: the digits and the reading change at s+3, as the
+/// fill comes in, never before the arm.
+fn keepOld(now: cursors.Now, addr: u64, values: *[16]u8, known: *[16]bool, runs: []const rows.Run, keeps: []const bool) void {
+ if (std.mem.indexOfScalar(bool, keeps, true) == null) return;
+ var was: [16]u8 = undefined;
+ var known_was: [16]bool = undefined;
+ now.before().read(addr, &was, &known_was) catch return;
+ for (runs, keeps) |run, old| if (old) {
+ @memcpy(values[run.first..][0..run.len], was[run.first..][0..run.len]);
+ @memcpy(known[run.first..][0..run.len], known_was[run.first..][0..run.len]);
+ };
+}
+
/// A row of a panel: its first byte's address and its top.
pub const RowAt = struct { addr: u64, y: f32 };
@@ -400,6 +468,11 @@ pub const Fields = struct {
/// 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,
+ /// A view: a row a register points into carries its pin (`rowPin`).
+ pins: bool = false,
+ /// The fields before the step, where it retypes them: a run whose strike
+ /// has not landed is read as what it was.
+ was: []const Field = &.{},
};
/// The region's rows in view `v`, from `y`, sixteen bytes a row from its
@@ -440,7 +513,8 @@ pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void {
}
last = r;
const passes = rowPasses(now, of.base + 16 * r);
- 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);
+ const room = if (of.pins) rowPin(u, now, of.base + 16 * r, ry) else full_room;
+ 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, room);
at_rows.append(u.f.scratch, .{ .addr = of.base + 16 * r, .y = ry }) catch {};
@import("map.zig").row(.view, of.base + 16 * r, u, .{ .x = 0, .y = ry, .w = 860, .h = m.row });
ry += m.row;
@@ -509,7 +583,7 @@ fn focus(now: cursors.Now, of: Fields, rs: []const u64) usize {
return 0;
}
-fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Moment, of: Fields, lead: usize, shift: f32) void {
+fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Moment, of: Fields, lead: usize, shift: f32, room: f32) void {
var values: [16]u8 = undefined;
var known: [16]bool = undefined;
moment.read(addr, &values, &known) catch return;
@@ -537,6 +611,7 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom
};
var runs: [16]rows.Run = undefined;
var readings: [16]Field = undefined;
+ var keeps: [16]bool = @splat(false);
var n: usize = 0;
var at: u8 = 0;
while (at < 16 and addr + at < of.base + of.len) {
@@ -558,6 +633,9 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom
};
run.heat = now.writtenWatched(here, run.len, .memory, 0, 0, of.watched);
run.changed = now.changedBytes(here, run.len);
+ // Until its own strike lands the old value stands: the loupe's own times, or memory's.
+ const ago = if (of.struck) |since| (if (now.walking() and now.writeAge(here, run.len) == 0) since - @as(f32, @floatFromInt(field_k)) * cursors.write_apart else null) else if (of.watched > 0) now.struckAgo(here, run.len) else null;
+ if (ago) |a| keeps[n] = a < theme.time.strike.in / 2.0;
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;
@@ -568,6 +646,16 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom
if (of.watched > 0 and now.wasRead(here, run.len) and now.writeAge(here, run.len) != 0) framed = @max(framed, now.reading(.memory, 0));
run.read = framed;
readings[n] = .{ .at = at, .len = run.len, .reads = fl.reads, .big = fl.big, .type = fl.type, .note = fl.note, .addr = here };
+ // Its old bytes read as what they were until its strike lands (the step retypes the field: malloc's).
+ if (keeps[n]) for (of.was) |old| if (of.base + old.at <= here and here < of.base + old.at + old.len) {
+ readings[n] = .{ .at = at, .len = run.len, .reads = old.reads, .big = old.big, .type = old.type, .note = old.note, .addr = here };
+ run.kind = switch (old.reads) {
+ .number, .bytes, .size, .protected => .number,
+ .pointer => .pointer,
+ .text => .text,
+ };
+ break;
+ };
ties.anchor(u, .{ .dump_run = here }, .{ .x = shift + rows.byteX(run.first) - 4, .y = y, .w = rows.byteX(run.first + run.len - 1) + 28 - rows.byteX(run.first) + 4, .h = m.row });
} else {
// Up to the next field, or the row's end.
@@ -582,16 +670,17 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom
n += 1;
at += run.len;
}
+ keepOld(now, addr, &values, &known, runs[0..n], keeps[0..n]);
// The kernel reading them: one frame round what it took of the row.
if (gives and of.read > 0) u.faded(of.read).frame(.{ .x = shift + rows.byteX(given_from) - 7, .y = y - 1, .w = rows.byteX(given_to) - rows.byteX(given_from) + 38, .h = m.row + 2 }, theme.mark(.read).solid, 2);
const shows = if (of.given) |g| g.shows else 0;
if (gives and shows > 0) {
if (shows < 1) rows.bytesAt(u.faded(1 - shows), y, addr, &values, &known, runs[0..n], of.region, lead, true, moment, shift);
rows.bytesAt(u.faded(shows), y, addr, &given_values, &given_known, runs[0..n], of.region, lead, true, moment, shift);
- _ = reading(u.faded(shows), y, shift, moment, &given_values, &given_known, readings[0..n]);
+ _ = readingIn(u.faded(shows), y, shift, moment, &given_values, &given_known, readings[0..n], room);
} else {
rows.bytesAt(u, y, addr, &values, &known, runs[0..n], of.region, lead, true, moment, shift);
- _ = reading(u, y, shift, moment, &values, &known, readings[0..n]);
+ _ = readingIn(u, y, shift, moment, &values, &known, readings[0..n], room);
}
}
@@ -604,9 +693,16 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom
/// `loose`, as nothing. Cut where the panel ends, with `…`. Returns where
/// it ends.
pub fn reading(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: *const [16]u8, known: *const [16]bool, fields: []const Field) f32 {
+ return readingIn(u, y, shift, moment, values, known, fields, full_room);
+}
+
+/// The panel's width less its side: where a reading ends with no pin at its row's end.
+const full_room = theme.layout.state.w - theme.metric.context.side;
+
+/// `reading`, ending at `room` (a pin at the row's end takes the rest).
+pub fn readingIn(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: *const [16]u8, known: *const [16]bool, fields: []const Field, room: f32) f32 {
const size = theme.size.mono.context;
const base = rows.baseline(y);
- const room = theme.layout.state.w - theme.metric.context.side;
var x: f32 = b.reading + shift;
for (fields) |fl| {
const first: usize = @intCast(fl.at);