From a7504c6bb2ec9e906891e42bc3df28b276e67143 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 12:09:27 -0300 Subject: the backends together: a ring under the debugger, strings that do not collide ztrace record and dbg take --ring, --preload and --alloc: the target gets the ring ztrace run gives it, and the debugger drains it while the target runs (polling for the stop, so a full ring cannot hold both) and before it reports a stop. A program compiled by ztrace cc, with the agent preloaded, stopped at breakpoints, is one recording in order; test-together checks it. Recording such a program showed the debugger's file names and the pass's strings both counted from 1: event.stringId (a hash, top bit set) is now what every producer without a table of its own uses. --- src/trace/ptrace.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/trace/ptrace.zig') diff --git a/src/trace/ptrace.zig b/src/trace/ptrace.zig index fd7ebd1..ca3dc39 100644 --- a/src/trace/ptrace.zig +++ b/src/trace/ptrace.zig @@ -119,8 +119,19 @@ pub const Process = struct { /// The next stop of one thread (-1: of any child), which becomes the current one. pub fn wait(p: *Process, tid: linux.pid_t) !Stop { + return (try p.next(tid, WALL)).?; + } + + /// The same without waiting: null while nothing has stopped. + pub fn poll(p: *Process, tid: linux.pid_t) !?Stop { + return p.next(tid, WALL | linux.W.NOHANG); + } + + fn next(p: *Process, tid: linux.pid_t, flags: u32) !?Stop { var status: u32 = 0; - p.tid = @intCast(try check(linux.waitpid(tid, @ptrCast(&status), WALL))); + const stopped = try check(linux.waitpid(tid, @ptrCast(&status), flags)); + if (stopped == 0) return null; + p.tid = @intCast(stopped); if (linux.W.IFEXITED(status) or linux.W.IFSIGNALED(status)) { if (p.tid == p.pid) p.gone = true else p.threads -= 1; return if (linux.W.IFEXITED(status)) .{ .exited = linux.W.EXITSTATUS(status) } else .{ .killed = linux.W.TERMSIG(status) }; -- cgit v1.3