summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-12 01:40:04 -0300
committerGabriel Schneider <[email protected]>2026-11-12 01:44:59 -0300
commitaefde257db6e7cf683b923498c0d471885ab67a9 (patch)
treec81a17d4ed07a62f2c9f1d237419e6d130dd012d
parent60e07feef401d9044db3a1c925cb9d1f6d20dac9 (diff)
downloadcomputeranim-aefde257db6e7cf683b923498c0d471885ab67a9.tar.gz
computeranim-aefde257db6e7cf683b923498c0d471885ab67a9.zip
record: --until ends the recording at a place
The ASan scene cut its run by a count of steps, which moves with the compiler; --until __asan_report_store1 ends it where the report begins. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
-rw-r--r--README.md4
-rw-r--r--build/debugger.zig16
-rw-r--r--src/cli/record.zig27
3 files changed, 45 insertions, 2 deletions
diff --git a/README.md b/README.md
index 71142c3..7b8fcfe 100644
--- a/README.md
+++ b/README.md
@@ -518,7 +518,9 @@ breakpoint 1 at 563f798b1814 fib+4 (fib.c:4)
`ztrace record` is the same debugger left to run: `--by insn|line|syscall|break`
says where it stops, `-b` adds breakpoints, `-w` watches, `--strace` prints
the syscalls, `--from main` runs through the loader and the C library's
-start before the first stop. How much of the context a stop keeps is
+start before the first stop, and `--until WHERE` ends the recording at
+the first stop there (`--until __asan_report_store1` stops an ASan run
+where its report begins, before the million instructions of writing it). How much of the context a stop keeps is
asked for: `--stack BYTES` above the stack pointer (128), every word of
it followed as a pointer; `--around BYTES` of memory each side of what a
pointer leads to (0: the 32 bytes at it); `--disasm ROWS` of instructions
diff --git a/build/debugger.zig b/build/debugger.zig
index e50c82c..f0b0e7c 100644
--- a/build/debugger.zig
+++ b/build/debugger.zig
@@ -165,6 +165,22 @@ pub fn add(ctx: Ctx) void {
// The 64 are counted from fib, whatever the loader did before.
from_show.expectStdOutMatch(" 64 step\n");
step.dependOn(&from_show.step);
+ // From main, by instruction, to fib: --until ends the recording there.
+ const until = b.addRunArtifact(ctx.exe);
+ until.addArgs(&.{ "record", "--from", "main", "--until", "fib", "-o" });
+ const until_recording = until.addOutputFileArg("until.ztrace");
+ until.addArg("--");
+ until.addArtifactArg(fib);
+ until.addArg("10");
+ until.expectStdErrMatch("ended at fib, as --until asked");
+ const until_show = b.addRunArtifact(ctx.exe);
+ until_show.addArgs(&.{ "show" });
+ until_show.addFileArg(until_recording);
+ until_show.addArg("-1");
+ // WHERE resolves as -b's does: a function's place past its prologue.
+ until_show.expectStdOutMatch("rip ");
+ until_show.expectStdOutMatch(" (fib+");
+ step.dependOn(&until_show.step);
// ... and by syscall: the loader's own are passed, not taken for the place.
const from_sys = b.addRunArtifact(ctx.exe);
from_sys.addArgs(&.{ "record", "--by", "syscall", "--from", "fib", "-o" });
diff --git a/src/cli/record.zig b/src/cli/record.zig
index 5d3726c..6b3f5c5 100644
--- a/src/cli/record.zig
+++ b/src/cli/record.zig
@@ -8,7 +8,7 @@ const fail = util.fail;
pub const usage =
\\usage: ztrace record [-o FILE] [--by insn|line|syscall|break] [-b WHERE]... [-w WHAT[,LEN]]...
- \\ [--from WHERE] [--stack BYTES] [-s BYTES] [--telescope DEPTH]
+ \\ [--from WHERE] [--until WHERE] [--stack BYTES] [-s BYTES] [--telescope DEPTH]
\\ [--around BYTES] [--disasm ROWS] [--steps N]
\\ [--max-size BYTES] [--strace] [--heap] [--asan]
\\ [--ring] [--preload LIB] [--alloc] -- PROGRAM [ARGS]
@@ -22,6 +22,9 @@ pub const usage =
\\-b adds a breakpoint, in any of them: a function, file:line or *address.
\\--from runs the program through to WHERE first, without a stop: the
\\loader and the C library's start are not what one records by instruction.
+ \\--until ends the recording at the first stop at WHERE (a place as -b
+ \\takes it), before it runs; for a library's function give --from too, so
+ \\the library is mapped by then.
\\-b usdt:PROVIDER:NAME (* for any) records the program's static probes
\\(USDT) instead, each hit a `probe` event with its arguments, without
\\stopping there.
@@ -80,6 +83,7 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
var heap = false;
var asan = false;
var from: ?[]const u8 = null;
+ var until: ?[]const u8 = null;
var breaks: std.ArrayList([]const u8) = .empty;
var watches: std.ArrayList([]const u8) = .empty;
var producer: util.Producer = .{};
@@ -117,6 +121,9 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
} else if (std.mem.eql(u8, arg, "--from")) {
from = value.?;
i += 1;
+ } else if (std.mem.eql(u8, arg, "--until")) {
+ until = value.?;
+ i += 1;
} else if (std.mem.eql(u8, arg, "-w")) {
try watches.append(arena, value.?);
i += 1;
@@ -196,6 +203,14 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
entry = try d.breakAt(at, null);
};
+ // Where to end: resolved now, or once --from's place is reached (a library is mapped by then).
+ var end: ?u64 = null;
+ if (until) |where| if (from == null) {
+ end = d.resolve(where) catch fail("{s}: no such place in the program (a library's? give --from main)\n", .{where});
+ _ = try d.breakAt(end.?, null);
+ };
+ var ended = false;
+
var timer = zt.event.now();
var exit_code: u64 = 0;
var full = false;
@@ -228,6 +243,15 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
// A signal is delivered by the next resume.
else => {},
}
+ if (until) |where| if (end == null) {
+ end = d.resolve(where) catch fail("{s}: no such place in the program\n", .{where});
+ _ = try d.breakAt(end.?, null);
+ };
+ // Stepped onto it, or stopped at its breakpoint: this moment is the last.
+ if (end) |at| if (d.regs.rip == at) {
+ ended = true;
+ break;
+ };
}
timer = zt.event.now() - timer;
@@ -245,6 +269,7 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
.no_arena => std.debug.print("heap: not recorded: more than one place in glibc looks like the main arena\n", .{}),
};
if (asan) if (d.asan_shadow) |offset| std.debug.print("asan: shadow at {x}\n", .{offset}) else std.debug.print("asan: not recorded: the runtime never set its shadow\n", .{});
+ if (ended) std.debug.print("{s}: ended at {s}, as --until asked\n", .{ out, until.? });
std.debug.print("{s}: {d} moments, {d} events, {d} bytes ({d} bytes/moment), {d:.1} ms, {d:.0} moments/s, exit {d}\n", .{
out, moments,
events, size,