From 0b29354e1ddf6cf75ac4c426a00dd3435ace5069 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 11:08:49 -0300 Subject: ztrace: the event, the ring, the recording, a ptrace loop One 64-byte Event for every backend; a shared-memory ring from target to tracer with stop/resume; a Recorder that folds events into xitdb moments (registers, memory in 64-byte chunks with known-byte masks, strings) and a Trace that reads any moment back; a minimal ptrace Process; ztrace record, run and dump. Per-area build files so the areas grow apart. --- src/cli/main.zig | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/cli/main.zig (limited to 'src/cli/main.zig') diff --git a/src/cli/main.zig b/src/cli/main.zig new file mode 100644 index 0000000..498f8d4 --- /dev/null +++ b/src/cli/main.zig @@ -0,0 +1,37 @@ +//! ztrace: many ways to watch a program, one recording. +const std = @import("std"); +const util = @import("util.zig"); + +/// A command is a file with `usage` and `run(init, args)`. +const commands = .{ + .record = @import("record.zig"), + .run = @import("run.zig"), + .dump = @import("dump.zig"), +}; + +const usage = + \\usage: ztrace COMMAND ... + \\ + \\ record run a program under ptrace into a recording + \\ run record a program that carries a ring producer (agent, instrumentation) + \\ dump print a recording's events + \\ + \\`ztrace COMMAND --help` for each. + \\ +; + +pub fn main(init: std.process.Init) !void { + const args = try init.minimal.args.toSlice(init.arena.allocator()); + if (args.len < 2) util.fail(usage, .{}); + inline for (@typeInfo(@TypeOf(commands)).@"struct".field_names) |name| { + if (std.mem.eql(u8, args[1], name)) { + const command = @field(commands, name); + if (args.len > 2 and std.mem.eql(u8, args[2], "--help")) { + std.debug.print("{s}", .{command.usage}); + return; + } + return command.run(init, args[2..]); + } + } + util.fail(usage, .{}); +} -- cgit v1.3