diff options
Diffstat (limited to 'src/cli/record.zig')
| -rw-r--r-- | src/cli/record.zig | 27 |
1 files changed, 26 insertions, 1 deletions
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, |
