diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-12 01:44:59 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-12 03:17:32 -0300 |
| commit | bf0dfa135319f8c7ca49eace4d1f81152ebfd23e (patch) | |
| tree | 9c80ade769dc9a741c9d00f63770d34dc1769ced /anim/src/segments.zig | |
| parent | aefde257db6e7cf683b923498c0d471885ab67a9 (diff) | |
| download | computeranim-bf0dfa135319f8c7ca49eace4d1f81152ebfd23e.tar.gz computeranim-bf0dfa135319f8c7ca49eace4d1f81152ebfd23e.zip | |
canim: the introduction, three chapters
From the user: a first-principles showcase that builds the views. I,
memory: the stack's bytes, words read low byte first, the address space
to true scale with each cluster enlarged and every band's addresses and
size, the bytes tied to their place, ink and chains. II, the stack: the
words become the stack panel, a real push, the return address aimed at
the row it returns to, rbp and the frame, the registers. III, code: an
instruction's bytes decoded into one listing of lines and addresses, then
two columns, then the working frame assembled and the map. Recorded from
main's call of reverse with record --until.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src/segments.zig')
| -rw-r--r-- | anim/src/segments.zig | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/anim/src/segments.zig b/anim/src/segments.zig index d28d2dd..db9d28f 100644 --- a/anim/src/segments.zig +++ b/anim/src/segments.zig @@ -69,11 +69,18 @@ pub fn read(rec: *const Recording, at: u64, arena: std.mem.Allocator) Space { const maps = mo.mappings(arena) catch &.{}; var bands: std.ArrayList(Band) = .empty; var path_buf: [512]u8 = undefined; + // The tracer's own (its ring, its preloaded agent, and an agent's bss + // after it) are not the program's: left out, as mock 34 has them. + var tracers_end: u64 = 0; for (maps) |mp| { if (mp.addr >= user_end) continue; var path: []const u8 = ""; _ = mo.mapping(mp.addr, &path, &path_buf) catch null; const name = arena.dupe(u8, nameOf(path)) catch ""; + if (std.mem.indexOf(u8, name, "ztrace") != null or (name.len == 0 and mp.addr == tracers_end)) { + tracers_end = mp.addr + mp.len; + continue; + } if (bands.items.len > 0) { const last = &bands.items[bands.items.len - 1]; if (last.hi == mp.addr and last.prot == mp.prot and (std.mem.eql(u8, last.name, name) or (name.len == 0 and last.name.len > 0 and last.name[0] != '['))) { @@ -163,6 +170,12 @@ pub fn size(buf: []u8, bytes: u64) []const u8 { return std.fmt.bufPrint(buf, "{d} {s}", .{ @as(u64, @intFromFloat(@round(v))), units[u] }) catch ""; } +/// `name` cut with `…` to fit `room` (a library's long file name in the program column). +fn cut(u: ui.Ui, name: []const u8, room: f32) []const u8 { + const most: usize = @intFromFloat(@max(room / ui.advance(m.mono), 2)); + return if (name.len > most) u.print("{s}\u{2026}", .{name[0 .. most - 1]}) else name; +} + fn perms(prot: u64) [3]u8 { return .{ if (prot & 1 != 0) 'r' else '-', if (prot & 2 != 0) 'w' else '-', if (prot & 4 != 0) 'x' else '-' }; } @@ -433,9 +446,9 @@ pub const Segments = struct { out.append(arena, .{ .kind = .unit, .addr = un.lo, .unit = k, .target = std.math.clamp((yh + yl) / 2, box.y, box.y + box.h), .ink = un.ink }) catch {}; out.append(arena, .{ .kind = .edge, .addr = un.lo, .unit = k, .target = yl, .ink = un.ink }) catch {}; } - // An edge two units share takes the ink of the one that starts there. - for (out.items, 0..) |*r, j| if (r.kind == .edge and j + 1 < out.items.len and out.items[j + 1].kind == .unit) { - r.ink = l.space.units[out.items[j + 1].unit].ink; + // An edge two units share takes the ink of the one that starts there (its lowest address). + for (out.items) |*r| if (r.kind == .edge) for (l.space.units[c.units[0]..c.units[1]]) |un| if (un.lo == r.addr) { + r.ink = un.ink; }; return out.items; } @@ -484,7 +497,7 @@ pub const Segments = struct { if (un.program) { if (first_program == null) first_program = k; last_program = k; - } else v.text(.mono, m.mono, g.x + m.name, y + 7.2, un.name, t.primary); + } else v.text(.mono, m.mono, g.x + m.name, y + 7.2, cut(v, un.name, theme.layout.program.w - 12 - m.name), t.primary); // A file whose permissions differ: each part's written inside its band, where it is 28 tall. if (un.prot == null) g.insides(v, l, i, un, scale); }, |
