diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 23:55:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-11 00:06:30 -0300 |
| commit | c94ade9e77a811d3ff75ffc2889a65375262ab1f (patch) | |
| tree | cd6e1da77cae54dc1ff4c35ee9d9262549819770 /build/debugger.zig | |
| parent | 81d97a9e38c740a96af13a8a981878947a508bc0 (diff) | |
| download | computeranim-c94ade9e77a811d3ff75ffc2889a65375262ab1f.tar.gz computeranim-c94ade9e77a811d3ff75ffc2889a65375262ab1f.zip | |
trace: names for PLT stubs and GOT slots; a call followed down; the vDSO is run through
For a disassembly that follows a call into libc. A stub is open@plt and a
slot open@got, from the relocations (libc's own, IFUNC and nameless, by
the function they resolve to); telescope.got says what a slot holds and
whether it is still lazy. A library function's entry is named even when
its mapping was not known yet, by the alias the program imports. The
chain holds through the stub's jump, the callee's first instruction, the
syscall and the loader's resolver: ld.so's unwind section lacks the entry
that ends it, which lost every frame there. A syscall is tied to its
instruction's moment, and each frame's call is recorded with the row
before it. Stepped by instruction, a call into the vDSO is one moment and
its return the next: its clock loop, single-stepped, made three million
moments of three reads.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'build/debugger.zig')
| -rw-r--r-- | build/debugger.zig | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/build/debugger.zig b/build/debugger.zig index 7b90454..6e0ddf9 100644 --- a/build/debugger.zig +++ b/build/debugger.zig @@ -21,6 +21,10 @@ pub fn add(ctx: Ctx) void { const o0_mod = b.createModule(.{ .target = ctx.target, .optimize = .Debug, .link_libc = true, .omit_frame_pointer = false }); o0_mod.addCSourceFiles(.{ .root = b.path("targets"), .files = &.{"list.c"}, .flags = &.{ "-O0", "-g" } }); const list_o0 = b.addExecutable(.{ .name = "list-O0", .root_module = o0_mod }); + // Calls through the PLT, bound at their first call (Zig links for binding at load). + const hello = ctx.cTarget("hello", &.{"hello.c"}); + hello.link_z_lazy = true; + const clock = ctx.cTarget("clock", &.{"clock.c"}); // Zig, no libc: always a debug build, so its lines are the source's. const graph = b.addExecutable(.{ .name = "graph", .root_module = b.createModule(.{ .root_source_file = b.path("targets/graph.zig"), @@ -28,7 +32,7 @@ pub fn add(ctx: Ctx) void { .optimize = .Debug, }) }); - const targets = [_]*std.Build.Step.Compile{ fib, list, list_o0, threads, libc_glibc, libc_musl, graph }; + const targets = [_]*std.Build.Step.Compile{ fib, list, list_o0, hello, clock, threads, libc_glibc, libc_musl, graph }; for (targets) |t| b.getInstallStep().dependOn(&b.addInstallArtifact(t, .{ .dest_dir = .{ .override = .{ .custom = "targets" } } }).step); // The compiler's own checks (UBSan, on by default in a debug build) are @@ -96,6 +100,27 @@ pub fn add(ctx: Ctx) void { // ... which the library's tests read too. paths.addOptionPath("fib_recording", recording); + // A call followed down by instruction: through the PLT, the loader's + // resolver and libc to the kernel, and back; read by the library's tests. + const descent = b.addRunArtifact(ctx.exe); + descent.addArgs(&.{ "record", "--by", "insn", "--from", "main", "-o" }); + paths.addOptionPath("hello_recording", descent.addOutputFileArg("hello.ztrace")); + descent.addArg("--"); + descent.addArtifactArg(hello); + descent.expectStdErrMatch("exit 0"); + + // Into libc by its PLT stub, syscalls not followed: the libraries' + // mappings are read when a name is wanted in them, and the callee's + // first instruction is named in the recording, its caller under it. + const entry = b.addRunArtifact(ctx.exe); + entry.addArgs(&.{ "dbg", "-o" }); + _ = entry.addOutputFileArg("entry.ztrace"); + entry.addArg("--"); + entry.addArtifactArg(libc_glibc); + entry.setStdIn(.{ .bytes = "b main\nr\nsi\nsi\nsi\ncontext\nquit\n" }); + for ([_][]const u8{ " malloc@plt+0\n", " rip ", " (libc.so.6!malloc+0)\n", " libc.so.6!malloc+0\n #1 ", " main+14\n" }) |expected| entry.expectStdOutMatch(expected); + step.dependOn(&entry.step); + // From a place on, by instruction: what ran before fib is no moment but its syscalls. const from = b.addRunArtifact(ctx.exe); from.addArgs(&.{ "record", "--from", "fib", "--steps", "64", "-o" }); |
