summaryrefslogtreecommitdiff
path: root/anim/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-12 01:44:59 -0300
committerGabriel Schneider <[email protected]>2026-11-12 03:17:32 -0300
commitbf0dfa135319f8c7ca49eace4d1f81152ebfd23e (patch)
tree9c80ade769dc9a741c9d00f63770d34dc1769ced /anim/build.zig
parentaefde257db6e7cf683b923498c0d471885ab67a9 (diff)
downloadcomputeranim-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/build.zig')
-rw-r--r--anim/build.zig13
1 files changed, 11 insertions, 2 deletions
diff --git a/anim/build.zig b/anim/build.zig
index 9c7d63e..63d962e 100644
--- a/anim/build.zig
+++ b/anim/build.zig
@@ -107,6 +107,10 @@ pub fn build(b: *std.Build) void {
glibc: bool = false,
/// Stops after `from` before the recording ends: main's return, not the exit's.
steps: ?[]const u8 = null,
+ /// Ends the recording at the first stop here (`--until`).
+ until: ?[]const u8 = null,
+ /// The name it runs by (argv[0], its mapping), where not the recording's.
+ program: ?[]const u8 = null,
/// Also glibc's heap at every stop (`--heap`), and memory watched (`-w`).
heap: bool = false,
watch: []const []const u8 = &.{},
@@ -130,6 +134,9 @@ pub fn build(b: *std.Build) void {
// (the agent's and the runtime's first calls) run through.
.{ .name = "sort", .source = "sort.c", .by = "insn", .instr = "vars", .only = "sort,a", .from = "main" },
.{ .name = "list", .source = "list.c", .by = "insn", .instr = "vars", .only = "push,reverse,head", .from = "reverse", .alloc = true },
+ // The introduction's: the same program from main's call of reverse
+ // (its push of the way back, reverse's prologue) to line 22, past the load.
+ .{ .name = "intro", .source = "list.c", .by = "insn", .instr = "vars", .only = "push,reverse,head", .from = "list.c:41", .until = "list.c:22", .alloc = true, .program = "list" },
// `hello` again, built by Zig against musl, static: no PLT; musl's
// own source (`open.c`, `syscall_cp`) on the way down to the kernel.
.{ .name = "musl", .source = "hello.c", .by = "insn", .from = "main", .steps = "166", .reads = "note" },
@@ -164,7 +171,8 @@ pub fn build(b: *std.Build) void {
// environment: the strings on its stack (its name, its variables)
// end up on screen, and should say nothing of the machine it was made on.
const where = b.addWriteFiles();
- _ = where.addCopyFile(program, r.name);
+ const runs_as = r.program orelse r.name;
+ _ = where.addCopyFile(program, runs_as);
if (r.reads) |name| _ = where.addCopyFile(b.path(b.fmt("tools/{s}", .{name})), name);
// A dynamic program's libraries are named by their debug info in
// the debuginfod cache: the recorder finds it by DEBUGINFOD_CACHE_PATH,
@@ -196,6 +204,7 @@ pub fn build(b: *std.Build) void {
run.addArgs(&.{ "--by", r.by, "--stack", r.stack, "--around", "256", "--disasm", "69", "-s", "64" });
if (r.from) |place| run.addArgs(&.{ "--from", place });
if (r.steps) |n| run.addArgs(&.{ "--steps", n });
+ if (r.until) |place| run.addArgs(&.{ "--until", place });
if (r.heap) run.addArg("--heap");
for (r.watch) |what| run.addArgs(&.{ "-w", what });
// What an instrumented program tells of itself comes through a ring.
@@ -206,7 +215,7 @@ pub fn build(b: *std.Build) void {
}
run.addArg("-o");
const trace = run.addOutputFileArg(b.fmt("{s}.ztrace", .{r.name}));
- run.addArgs(&.{ "--", b.fmt("./{s}", .{r.name}) });
+ run.addArgs(&.{ "--", b.fmt("./{s}", .{runs_as}) });
run.setCwd(where.getDirectory());
run.expectExitCode(0);
run.expectStdErrMatch("exit 0");