diff options
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" }); |
