summaryrefslogtreecommitdiff
path: root/src/cli/dbg.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/dbg.zig')
-rw-r--r--src/cli/dbg.zig12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/cli/dbg.zig b/src/cli/dbg.zig
index 007b790..6876f84 100644
--- a/src/cli/dbg.zig
+++ b/src/cli/dbg.zig
@@ -7,7 +7,8 @@ const fail = util.fail;
const Moment = zt.store.Moment;
pub const usage =
- \\usage: ztrace dbg [-o FILE] [--stack BYTES] [-s BYTES] [--max-size BYTES] -- PROGRAM [ARGS]
+ \\usage: ztrace dbg [-o FILE] [--stack BYTES] [-s BYTES] [--max-size BYTES]
+ \\ [--ring] [--preload LIB] [--alloc] -- PROGRAM [ARGS]
\\ ztrace dbg [-o FILE] [--stack BYTES] [-s BYTES] [--max-size BYTES] -p PID
\\
\\Starts PROGRAM stopped at its first instruction (or attaches to PID)
@@ -34,7 +35,7 @@ pub const usage =
\\bytes (default 256) of what a syscall points at. The session ends when
\\the file reaches --max-size (default 1G).
\\
-;
+++ util.Producer.usage;
pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
const arena = init.arena.allocator();
@@ -44,12 +45,15 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
var stack_bytes: usize = 4096;
var capture: ?usize = null;
var max_bytes: ?u64 = null;
+ var producer: util.Producer = .{};
var i: usize = 0;
while (i < args.len) : (i += 1) {
const arg = args[i];
if (std.mem.eql(u8, arg, "--")) {
i += 1;
break;
+ } else if (producer.take(args, &i)) {
+ // Its own argument, when it has one, is taken.
} else if (std.mem.eql(u8, arg, "-o") and i + 1 < args.len) {
i += 1;
out = args[i];
@@ -71,11 +75,13 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void {
s.rec.cut = (s.rec.cut | zt.Kind.syscall_enter.bit()) & ~zt.Kind.line.bit();
if (max_bytes) |n| s.rec.max_bytes = n;
const sink: zt.Sink = .{ .ctx = &s, .emitFn = Session.emit };
+ const produced = if (pid == null) try producer.start(arena, init.minimal.environ.block.slice) else null;
s.d = if (pid) |p|
zt.Debugger.attach(init.gpa, init.io, p, sink) catch |err| fail("cannot attach to {d}: {t}\n", .{ p, err })
else
- try zt.Debugger.spawn(init.gpa, init.io, try util.resolve(init, args[i]), try util.targetArgv(arena, args[i..]), init.minimal.environ.block.slice.ptr, sink);
+ try zt.Debugger.spawn(init.gpa, init.io, try util.resolve(init, args[i]), try util.targetArgv(arena, args[i..]), if (produced) |p| p.envp.ptr else init.minimal.environ.block.slice.ptr, sink);
defer s.d.deinit();
+ if (produced) |p| s.d.ring = p.ring;
defer s.stop_payload.deinit(init.gpa);
s.d.stack_watch = stack_bytes;
if (capture) |n| s.d.capture = n;