diff options
Diffstat (limited to 'anim/build.zig')
| -rw-r--r-- | anim/build.zig | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/anim/build.zig b/anim/build.zig index d12912d..5601e39 100644 --- a/anim/build.zig +++ b/anim/build.zig @@ -87,6 +87,10 @@ pub fn build(b: *std.Build) void { /// Also glibc's heap at every stop (`--heap`), and memory watched (`-w`). heap: bool = false, watch: []const []const u8 = &.{}, + /// Also a stop at the call, in function [0], of function [1] through + /// its PLT stub (found by objdump: there is no name for it): the row + /// a line's cascade lands on before the call is stepped over. + break_call: ?[2][]const u8 = null, }; for ([_]Recording{ .{ .name = "steps", .source = "fib.c", .by = "insn" }, @@ -94,7 +98,7 @@ pub fn build(b: *std.Build) void { // the kernel and back: the descent; to main's return. .{ .name = "hello", .source = "hello.c", .by = "insn", .from = "main", .steps = "132", .glibc = true, .reads = "note" }, // A line a stop, malloc and free run through; glibc's heap at each. - .{ .name = "heap", .source = "heap.c", .by = "line", .from = "main", .glibc = true, .heap = true, .watch = &.{ "0x405000,1024", "head" } }, + .{ .name = "heap", .source = "heap.c", .by = "line", .from = "main", .glibc = true, .heap = true, .watch = &.{ "0x405000,1024", "head" }, .break_call = .{ "pop", "free" } }, // By instruction, as `steps` is: the registers are the program's // own, so they strike and link. Only the variables the scenes name // are told by the instrumentation (each a call into its runtime, @@ -135,13 +139,24 @@ pub fn build(b: *std.Build) void { const where = b.addWriteFiles(); _ = where.addCopyFile(program, r.name); if (r.reads) |name| _ = where.addCopyFile(b.path(b.fmt("tools/{s}", .{name})), name); - const run = b.addSystemCommand(&.{ "env", "-i", "setarch", "-R" }); + const run = if (r.break_call) |call| blk: { + // The call's address, from the program as built, then the recorder with a breakpoint there. + const sh = b.addSystemCommand(&.{ "sh", "-c", b.fmt( + \\p=$0 z=$1; shift + \\at=$(objdump -d --no-show-raw-insn "$p" | awk '/<{s}>:/ {{ f = 1 }} f && /call.*<{s}@plt>/ {{ sub(":", "", $1); print "0x" $1; exit }}') + \\[ -n "$at" ] || {{ echo "no call of {s} in {s}" >&2; exit 1; }} + \\exec env -i setarch -R "$z" record -b "*$at" "$@" + , .{ call[0], call[1], call[1], call[0] }) }); + sh.addFileArg(program); + break :blk sh; + } else b.addSystemCommand(&.{ "env", "-i", "setarch", "-R" }); run.addArtifactArg(ztrace); // More round each stop than the working frame shows: the map of // the whole context wants the words of the stack, 256 bytes round // what a pointer leads to and what a step touches, and 69 // instructions round the pc. - run.addArgs(&.{ "record", "--by", r.by, "--stack", r.stack, "--around", "256", "--disasm", "69", "-s", "64" }); + if (r.break_call == null) run.addArg("record"); + 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.heap) run.addArg("--heap"); |
