From 47f43f0f26b08901c1ddd16aacbe50c2c843ab8a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 16:45:15 -0300 Subject: record: --from runs through to a place before the first stop By instruction, a dynamic program's loader and C library start are a million moments nobody watches: the list of anim/tools from main to its exit is 3 743. Co-Authored-By: Claude Fable 5.2 --- src/cli/record.zig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/cli') 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); }; -- cgit v1.3