summaryrefslogtreecommitdiff
path: root/anim/src/hexdump.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/hexdump.zig')
-rw-r--r--anim/src/hexdump.zig79
1 files changed, 67 insertions, 12 deletions
diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig
index f1087ab..cbd8f7f 100644
--- a/anim/src/hexdump.zig
+++ b/anim/src/hexdump.zig
@@ -216,7 +216,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);
+ 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];
@@ -239,10 +239,12 @@ pub const RowAt = struct { addr: u64, y: f32 };
/// framed. A target in the same region past the rows shown: a stub to the
/// panel's rule (`rule`: its top and bottom), only in the step that
/// touches it. `loud`: full ink always (a loupe's, opened to show them).
-pub fn pointerArcs(arcs: *rows.Arcs, now: cursors.Now, field: u64, from: f32, shown: []const RowAt, size: u64, rule: [2]f32, loud: bool) void {
+pub fn pointerArcs(arcs: *rows.Arcs, now: cursors.Now, field: u64, from: f32, shown: []const RowAt, size: u64, rule: [2]f32, loud: bool, protected: bool) void {
const a = time_arc;
- const new = (Recording.word(now.moment(), field, 8) catch null) orelse return;
- const old = (Recording.word(now.before(), field, 8) catch null) orelse new;
+ // Safe-linked: to the pointer it protects (a NULL so stored is the mask alone).
+ const mask: u64 = if (protected) field >> 12 else 0;
+ const new = ((Recording.word(now.moment(), field, 8) catch null) orelse return) ^ mask;
+ const old = if (Recording.word(now.before(), field, 8) catch null) |w| w ^ mask else new;
const written = now.writeAge(field, 8) == 0 and old != new;
const read = now.wasRead(field, 8) and !written;
const hot = written or read;
@@ -296,7 +298,19 @@ fn chunkAfter(moment: Recording.Moment, word: u64) bool {
/// What a field of a region reads as: a number (little-endian, or `big`),
/// a pointer, text (in quotes, C's escapes), or bytes the reading leaves
/// to the eye.
-pub const Reads = enum { number, pointer, text, bytes };
+pub const Reads = enum {
+ number,
+ pointer,
+ text,
+ bytes,
+ /// malloc's size word: the size, its three low bits cleared, in hex;
+ /// then the bits as rip's flags are drawn, `A M P` (`0x20 a m P`).
+ size,
+ /// A pointer glibc stores safe-linked (xor its own address shifted
+ /// right by 12): what it protects, `→ 405050`, or `NULL`, then the
+ /// mask, faint, `^ 405`. Its arc goes to the pointer it protects.
+ protected,
+};
/// A field of the region a view is about, from the region's first byte.
pub const Field = struct {
@@ -310,6 +324,11 @@ pub const Field = struct {
/// A number's type, where the debug info gives it: read as the lens's
/// values are (`objects.reading`: a `char` quoted, a `bool` by name).
type: ?Recording.types.Type = null,
+ /// A note from the scene, Go 18 faint, after the reading (`key`, `slots left`).
+ note: []const u8 = "",
+ /// Where the field is: a `protected` word's mask is its address shifted
+ /// right by 12 (`fieldRow` sets it).
+ addr: u64 = 0,
};
/// What a dump of fields is of, and how it is marked now.
@@ -380,9 +399,9 @@ pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void {
if (shown[shown.len - 1] < total - 1) more(u, ry, total - 1 - shown[shown.len - 1]);
// Its pointers to its own rows: arcs.
var arcs: rows.Arcs = .{};
- if (at_rows.items.len > 1) for (of.fields) |field| if (field.reads == .pointer and field.len == 8) {
+ if (at_rows.items.len > 1) for (of.fields) |field| if ((field.reads == .pointer or field.reads == .protected) and field.len == 8) {
const addr = of.base + field.at;
- for (at_rows.items) |r| if (addr >= r.addr and addr < r.addr + 16) pointerArcs(&arcs, now, addr, r.y, at_rows.items, 16, .{ y - m.pad, ry + m.pad }, false);
+ for (at_rows.items) |r| if (addr >= r.addr and addr < r.addr + 16) pointerArcs(&arcs, now, addr, r.y, at_rows.items, 16, .{ y - m.pad, ry + m.pad }, false, field.reads == .protected);
};
arcs.draw(u, theme.metric.arc.lanes.len);
}
@@ -479,7 +498,7 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom
if (field) |fl| {
run.len = @intCast(@min(of.base + fl.at + fl.len - here, 16 - @as(u64, at)));
run.kind = switch (fl.reads) {
- .number, .bytes => .number,
+ .number, .bytes, .size, .protected => .number,
.pointer => .pointer,
.text => .text,
};
@@ -490,7 +509,7 @@ 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 };
+ readings[n] = .{ .at = at, .len = run.len, .reads = fl.reads, .big = fl.big, .type = fl.type, .note = fl.note, .addr = here };
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.
@@ -535,9 +554,45 @@ pub fn reading(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: *
const first: usize = @intCast(fl.at);
// A typed number is as wide as its type (an `int` in a word: 4 bytes).
const len: usize = @intCast(if (fl.type) |ty| @min(fl.len, ty.size() orelse fl.len) else fl.len);
- if (fl.reads == .bytes or len == 0) continue;
- if (std.mem.indexOfScalar(bool, known[first..][0..len], false) != null) continue;
+ 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;
+ };
+ if (fl.reads == .bytes) continue;
const bytes = values[first..][0..len];
+ var word_: u64 = 0;
+ for (0..@min(len, 8)) |k| word_ |= @as(u64, bytes[k]) << @intCast(8 * k);
+ switch (fl.reads) {
+ .size => {
+ const shown_size = u.print("0x{x}", .{word_ & ~@as(u64, 7)});
+ u.text(.mono, size, x, base, shown_size, t.primary);
+ x += u.width(.mono, size, shown_size) + adv;
+ // A M P: set on a chip, clear in dim lower case.
+ for ([_]struct { u8, u6 }{ .{ 'A', 2 }, .{ 'M', 1 }, .{ 'P', 0 } }) |bit| {
+ const set = word_ >> bit[1] & 1 != 0;
+ if (set) u.chip(.{ .x = x - 3, .y = y + 2, .w = adv + 6, .h = theme.metric.flags.chip[1] });
+ u.text(if (set) .mono_bold else .mono, size, x, base, &.{if (set) bit[0] else std.ascii.toLower(bit[0])}, if (set) t.bright else t.dim);
+ x += 2 * adv;
+ }
+ continue;
+ },
+ .protected => {
+ const target = word_ ^ (fl.addr >> 12);
+ if (target == 0) {
+ u.text(.mono, size, x, base, "NULL", t.dim);
+ x += 5 * adv;
+ } else {
+ x = u.arrow(x, y + m.row / 2, .points);
+ x = u.address(x, base, target, .{ .ink = ui.rgb(rows.ink(rows.regionOf(moment, target))) }) + adv;
+ }
+ const masked = u.print("^ {x}", .{fl.addr >> 12});
+ u.text(.mono, size, x, base, masked, t.faint);
+ x += u.width(.mono, size, masked) + adv;
+ continue;
+ },
+ else => {},
+ }
const words: []const u8 = switch (fl.reads) {
.number => blk: {
var word: u64 = 0;
@@ -557,7 +612,7 @@ pub fn reading(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: *
continue;
},
.text => quoted(u, bytes),
- .bytes => unreachable,
+ .bytes, .size, .protected => unreachable,
};
const w = u.width(.mono, size, words);
const fits = x + w <= room;