summaryrefslogtreecommitdiff
path: root/build/debugger.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build/debugger.zig')
-rw-r--r--build/debugger.zig18
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.