summaryrefslogtreecommitdiff
path: root/anim/src/source.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-11 00:06:30 -0300
committerGabriel Schneider <[email protected]>2026-11-11 01:16:48 -0300
commitc3d9f7ba5effd615374b1359ad98ecf801559f83 (patch)
tree07f85932abc1df23c722bcd1bd1b3b65bca28f2e /anim/src/source.zig
parentc94ade9e77a811d3ff75ffc2889a65375262ab1f (diff)
downloadcomputeranim-c3d9f7ba5effd615374b1359ad98ecf801559f83.tar.gz
computeranim-c3d9f7ba5effd615374b1359ad98ecf801559f83.zip
canim: a call followed down to the kernel; rows that say what they do; the heap from the inside
From the user. The disassembly can descend: the syscalls scene is glibc's hello by instruction, and open is followed from main through its PLT stub, whose jmp reads the GOT, into libc's wrapper to the syscall row, which crosses to the kernel's window under it, and back up. The band keeps the calls so far as strace writes them. Operands lose their size words and show a width as byte cells only where nothing else says it. A compare shows its values and the flags it leaves, a jump the flags it reads, lea its result, an indirect jump its target and the slot it read, a call that has run its C form. The backtrace has its newest frame at the bottom. A new scene shows glibc 2.44's heap from blocks that exist: chunks read by fields (a size with its bits, a protected pointer), the free list as arcs, the tcache in a loupe, the program's list over malloc's own. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src/source.zig')
-rw-r--r--anim/src/source.zig37
1 files changed, 34 insertions, 3 deletions
diff --git a/anim/src/source.zig b/anim/src/source.zig
index 58b9df0..bbc985e 100644
--- a/anim/src/source.zig
+++ b/anim/src/source.zig
@@ -17,6 +17,7 @@ const ties = @import("ties.zig");
const map = @import("map.zig");
const cursors = @import("cursor.zig");
const Stage = @import("stage.zig").Stage;
+const Recording = @import("Recording.zig");
const Cursor = cursors.Cursor;
const theme = ui.theme;
const Rect = ui.Rect;
@@ -28,6 +29,9 @@ pub const Source = struct {
cursor: Cursor,
stage: *const Stage,
focus: bool = false,
+ /// In a `descent`: while the pc is in code without source, the line it
+ /// called from waits, ringed, and the tag says where the pc is.
+ descent: bool = false,
pub fn draw(p: *const Source, f: *sk.Frame, placed: anim.Placed) void {
const box = p.stage.box(placed, .source);
@@ -52,7 +56,10 @@ pub const Source = struct {
const from: u32 = @intFromFloat(@floor(first));
const last: u32 = @min(from + @as(u32, @intCast(context.rowsOf(box))), rec.line_count);
const shown_first: u32 = @intFromFloat(windows[if (going >= 0.5) 1 else 0]);
- const body = u.panel(box.w, box.h, rec.file, .{ .focus = p.focus, .note = if (rec.line_count > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, rec.line_count), rec.line_count }) else u.print("{d} lines", .{rec.line_count}) });
+ // Waiting: the pc is in code with no source, under this line's call.
+ const waits = p.descent and !rec.sourced(now.marked()) and rec.own[now.marked()] != 0;
+ const note = if (waits) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(firstOwn(rec, now.marked()), "rip")), rec.own[now.marked()], whereIs(u, rec, now.marked()) }) else if (rec.line_count > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, rec.line_count), rec.line_count }) else u.print("{d} lines", .{rec.line_count});
+ const body = u.panel(box.w, box.h, rec.file, .{ .focus = p.focus, .note = note });
const top = body.y + m.pad;
// Where the mark is, and how much of it.
@@ -85,7 +92,11 @@ pub const Source = struct {
defer u.unclip();
// The plaque over the number. Fire: on the line about to run its
// edges go out and come back, once, and nothing else moves.
- if (shows > 0) u.faded(shows).current(.{ .x = theme.stroke.rule, .y = mark_y, .w = box.w - 2 * theme.stroke.rule, .h = m.row }, theme.metric.plaque.line + widen, now.fires(.source));
+ if (waits) {
+ // The number ringed: a 2-unit primary frame where the plaque would be, no wash.
+ u.faded(shows).frame(.{ .x = theme.stroke.rule + 1, .y = mark_y + 1, .w = theme.metric.plaque.line + widen - 2, .h = m.row - 2 }, theme.color.text.primary, theme.stroke.rule);
+ if (!ui.mapping) ties.thread_waits = true;
+ } else if (shows > 0) u.faded(shows).current(.{ .x = theme.stroke.rule, .y = mark_y, .w = box.w - 2 * theme.stroke.rule, .h = m.row }, theme.metric.plaque.line + widen, now.fires(.source));
if (shows >= 1 and mark_y >= body.y and mark_y + m.row <= box.h) ties.anchor(u, .source, .{ .x = 0, .y = mark_y, .w = box.w, .h = m.row });
// The trail: the last three other lines it was on. It shifts without animation.
@@ -109,13 +120,33 @@ pub const Source = struct {
const span = text.lines[line - 1];
const k = std.mem.indexOfScalar(u32, trail[0..found], line);
const on = shows >= 0.5 and line == mark_line;
- rows.line(lit, y, box.w, line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on) .marked else if (k) |n| .{ .trail = n } else .plain);
+ rows.line(lit, y, box.w, line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on and !waits) .marked else if (k) |n| .{ .trail = n } else .plain);
}
// The source is read at a run; at a sprint it is veiled too.
context.veiled(u, box, now.sprint_veil);
}
};
+/// The last moment at or before `i` whose pc was on a line of the program's source.
+fn firstOwn(rec: *const Recording, i: u64) u64 {
+ var at = i;
+ while (at > 0 and !rec.sourced(at)) at -= 1;
+ return at;
+}
+
+/// Where the pc is at moment `i`, for the waiting line's tag: `the PLT`,
+/// `libc's open`, `the vdso`.
+fn whereIs(u: ui.Ui, rec: *const Recording, i: u64) []const u8 {
+ const name = context.frameName(u, rec, rec.register(i, "rip"));
+ if (std.mem.endsWith(u8, name, "@plt")) return "the PLT";
+ var module: []const u8 = "";
+ var buf: [256]u8 = undefined;
+ _ = (rec.moment(i).mapping(rec.register(i, "rip"), &module, &buf) catch null);
+ const base = std.fs.path.basename(module);
+ const short = base[0 .. std.mem.indexOfScalar(u8, base, '.') orelse base.len];
+ return u.print("{s}'s {s}", .{ short, name });
+}
+
/// A source ready to draw: a class for each byte, and where each line is.
const Text = struct {
bytes: []const u8,