diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-11 10:38:30 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-11 10:38:37 -0300 |
| commit | 6a7a87b8ecb7902de5640cad00028997825024d2 (patch) | |
| tree | 9e76e47c769d62f0a1affa563b9fba9849e2ab5d /build | |
| parent | 390872b7bb9cdcf3e8095442af88af0dfcb40602 (diff) | |
| download | computeranim-6a7a87b8ecb7902de5640cad00028997825024d2.tar.gz computeranim-6a7a87b8ecb7902de5640cad00028997825024d2.zip | |
trace: a function's basic blocks; ASan's shadow memory
For a graph of a function's blocks: at the first stop inside it a
function's blocks are recorded once (bounds, how each ends, where its
edges go), with every instruction's text up to 2048 of them;
telescope.blocks reads them, and a branch event ties a run to the edge
it took. Stripped libraries get blocks from their unwind bounds.
For a plain build seen against an ASan one: record --asan keeps the
shadow of every region it records, the offset found from the process;
telescope.shadow gives an address's shadow byte. The report functions
are named and the chain holds from inside the report to main. Tested on
an overflowing target built plain, with gcc's ASan and with clang's.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'build')
| -rw-r--r-- | build/debugger.zig | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/build/debugger.zig b/build/debugger.zig index 6e0ddf9..bd6a18d 100644 --- a/build/debugger.zig +++ b/build/debugger.zig @@ -25,6 +25,10 @@ pub fn add(ctx: Ctx) void { const hello = ctx.cTarget("hello", &.{"hello.c"}); hello.link_z_lazy = true; const clock = ctx.cTarget("clock", &.{"clock.c"}); + // A stack overflow, plain: -O0 and no canary, so it overflows as written. + const overflow_mod = b.createModule(.{ .target = ctx.target, .optimize = .Debug, .link_libc = true, .omit_frame_pointer = false, .stack_protector = false }); + overflow_mod.addCSourceFiles(.{ .root = b.path("targets"), .files = &.{"overflow.c"}, .flags = &.{ "-O0", "-g" } }); + const overflow = b.addExecutable(.{ .name = "overflow", .root_module = overflow_mod }); // 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"), @@ -32,7 +36,7 @@ pub fn add(ctx: Ctx) void { .optimize = .Debug, }) }); - const targets = [_]*std.Build.Step.Compile{ fib, list, list_o0, hello, clock, threads, libc_glibc, libc_musl, graph }; + const targets = [_]*std.Build.Step.Compile{ fib, list, list_o0, hello, clock, overflow, 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 @@ -99,6 +103,9 @@ pub fn add(ctx: Ctx) void { step.dependOn(&show.step); // ... which the library's tests read too. paths.addOptionPath("fib_recording", recording); + // The overflow built with ASan by the system's compilers and recorded by the command, in the tests. + paths.addOptionPath("overflow_source", b.path("targets/overflow.c")); + paths.addOptionPath("ztrace", ctx.exe.getEmittedBin()); // 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. @@ -109,6 +116,15 @@ pub fn add(ctx: Ctx) void { descent.addArtifactArg(hello); descent.expectStdErrMatch("exit 0"); + // Two loops by instruction, `reverse` and `list_done`: their blocks. + const loops = b.addRunArtifact(ctx.exe); + loops.addArgs(&.{ "record", "--by", "insn", "--from", "reverse", "--steps", "100", "-o" }); + paths.addOptionPath("list_recording", loops.addOutputFileArg("list.ztrace")); + loops.addArg("--"); + loops.addArtifactArg(list); + loops.addArg("3"); + loops.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. |
