diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 12:09:27 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 12:15:20 -0300 |
| commit | a7504c6bb2ec9e906891e42bc3df28b276e67143 (patch) | |
| tree | c13e680499badf341b17960341386b8199637671 /src/trace/host.zig | |
| parent | 937b6314c4cd6fa73daeac308fbfcf69b89add56 (diff) | |
| download | computeranim-a7504c6bb2ec9e906891e42bc3df28b276e67143.tar.gz computeranim-a7504c6bb2ec9e906891e42bc3df28b276e67143.zip | |
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.
Diffstat (limited to 'src/trace/host.zig')
| -rw-r--r-- | src/trace/host.zig | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/trace/host.zig b/src/trace/host.zig index df2f845..7c43663 100644 --- a/src/trace/host.zig +++ b/src/trace/host.zig @@ -16,6 +16,22 @@ pub const Options = struct { stop_mask: u64 = 0, }; +/// `env` with the ring in it, the agent preloaded when there is one, and +/// `extra` (settings for the agent) after them. +pub fn environment(arena: std.mem.Allocator, env: [:null]const ?[*:0]const u8, ring: *const Ring, preload: ?[]const u8, extra: []const [*:0]const u8) ![:null]const ?[*:0]const u8 { + var envp: std.ArrayList(?[*:0]const u8) = .empty; + for (env) |v| { + const s = std.mem.span(v.?); + if (std.mem.startsWith(u8, s, client.env_fd ++ "=")) continue; + if (preload != null and std.mem.startsWith(u8, s, "LD_PRELOAD=")) continue; + try envp.append(arena, v); + } + try envp.append(arena, try std.fmt.allocPrintSentinel(arena, client.env_fd ++ "={d}", .{ring.fd}, 0)); + if (preload) |lib| try envp.append(arena, try std.fmt.allocPrintSentinel(arena, "LD_PRELOAD={s}", .{lib}, 0)); + for (extra) |v| try envp.append(arena, v); + return envp.toOwnedSliceSentinel(arena, null); +} + pub const Session = struct { ring: Ring, pid: linux.pid_t, @@ -27,16 +43,7 @@ pub const Session = struct { var ring = try Ring.create(options.ring_bytes); errdefer ring.close(); ring.hdr.stop_mask.store(options.stop_mask, .monotonic); - var envp: std.ArrayList(?[*:0]const u8) = .empty; - for (env) |v| { - const s = std.mem.span(v.?); - if (std.mem.startsWith(u8, s, client.env_fd ++ "=")) continue; - if (options.preload != null and std.mem.startsWith(u8, s, "LD_PRELOAD=")) continue; - try envp.append(arena, v); - } - try envp.append(arena, try std.fmt.allocPrintSentinel(arena, client.env_fd ++ "={d}", .{ring.fd}, 0)); - if (options.preload) |lib| try envp.append(arena, try std.fmt.allocPrintSentinel(arena, "LD_PRELOAD={s}", .{lib}, 0)); - const block = try envp.toOwnedSliceSentinel(arena, null); + const block = try environment(arena, env, &ring, options.preload, &.{}); const rc = linux.fork(); if (linux.errno(rc) != .SUCCESS) return error.Fork; |
