summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--build/debugger.zig14
-rw-r--r--src/cli/record.zig15
3 files changed, 28 insertions, 4 deletions
diff --git a/README.md b/README.md
index 987a6d9..5e3a761 100644
--- a/README.md
+++ b/README.md
@@ -318,7 +318,8 @@ 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. In a program, it is `zt.Debugger`:
+the syscalls, `--from main` runs through the loader and the C library's
+start before the first stop. In a program, it is `zt.Debugger`:
```zig
var d = try zt.Debugger.spawn(gpa, io, path, argv, envp, recorder.sink());
diff --git a/build/debugger.zig b/build/debugger.zig
index 9779ecd..d164072 100644
--- a/build/debugger.zig
+++ b/build/debugger.zig
@@ -92,6 +92,20 @@ pub fn add(ctx: Ctx) void {
// ... which the library's tests read too.
paths.addOptionPath("fib_recording", recording);
+ // 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" });
+ const from_recording = from.addOutputFileArg("from.ztrace");
+ from.addArg("--");
+ from.addArtifactArg(fib);
+ from.addArg("10");
+ from.expectStdErrMatch(" 64 moments, ");
+ const from_show = b.addRunArtifact(ctx.exe);
+ from_show.addArg("show");
+ from_show.addFileArg(from_recording);
+ from_show.expectStdOutMatch(" 1 breakpoint\n");
+ step.dependOn(&from_show.step);
+
// A source line a moment, a watched global, to the exit code.
const lines = b.addRunArtifact(ctx.exe);
lines.addArgs(&.{ "record", "--by", "line", "-w", "dist", "-w", "queue,8", "-o" });
diff --git a/src/cli/record.zig b/src/cli/record.zig
index a82fa9e..d3fb8a9 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]]...
- \\ [--stack BYTES] [-s BYTES] [--telescope DEPTH] [--steps N]
+ \\ [--from WHERE] [--stack BYTES] [-s BYTES] [--telescope DEPTH] [--steps N]
\\ [--max-size BYTES] [--strace]
\\ [--ring] [--preload LIB] [--alloc] -- PROGRAM [ARGS]
\\
@@ -19,6 +19,8 @@ pub const usage =
\\ syscall every syscall (--syscalls is the same)
\\ break the breakpoints only
\\-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.
\\-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.
@@ -48,6 +50,7 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
var capture: ?usize = null;
var max_bytes: ?u64 = null;
var strace = false;
+ var from: ?[]const u8 = null;
var breaks: std.ArrayList([]const u8) = .empty;
var watches: std.ArrayList([]const u8) = .empty;
var producer: util.Producer = .{};
@@ -76,6 +79,9 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
} else if (std.mem.eql(u8, arg, "-b")) {
try breaks.append(arena, value.?);
i += 1;
+ } else if (std.mem.eql(u8, arg, "--from")) {
+ from = value.?;
+ i += 1;
} else if (std.mem.eql(u8, arg, "-w")) {
try watches.append(arena, value.?);
i += 1;
@@ -132,9 +138,12 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
}
// By line, the loader's hundred thousand instructions are run through
- // to a breakpoint at the entry: there are no lines in them.
+ // to a breakpoint at the entry: there are no lines in them. --from
+ // names another place to run through to.
var entry: ?u32 = null;
- if (by == .line) if (d.syms.entryPoint()) |at| if (at != d.regs.rip) {
+ if (from) |where| {
+ entry = try d.breakAt(d.resolve(where) catch fail("{s}: no such place in the program\n", .{where}), null);
+ } else if (by == .line) if (d.syms.entryPoint()) |at| if (at != d.regs.rip) {
entry = try d.breakAt(at, null);
};