summaryrefslogtreecommitdiff
path: root/targets/agent_zig.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 11:44:48 -0300
committerGabriel Schneider <[email protected]>2026-11-10 12:09:34 -0300
commitce7c0abf14e7ab056d5479adc3f05df9976e94e4 (patch)
tree8931de9a55b3d7c2ec2d52d3b3817c6f7eb5db5a /targets/agent_zig.zig
parente7aa7801c10ed34194b7fe3f5ca8722a72404e65 (diff)
downloadcomputeranim-ce7c0abf14e7ab056d5479adc3f05df9976e94e4.tar.gz
computeranim-ce7c0abf14e7ab056d5479adc3f05df9976e94e4.zip
agent: the in-process backend, and ztrace run's options for it
libztrace-agent.so (preloaded) and libztrace-agent.a (linked in), one source: map and thread_start at startup; alloc/free from the interposed allocator; syscall_enter/exit through Syscall User Dispatch; call/ret from int3 hooks; mem_write from watched regions diffed in-process; the target-side API (include/ztrace.h, and the ztrace-agent module for Zig). ztrace run turns each on (--alloc --syscalls --hook --watch), chooses the moments (--cut), and stops the target at event kinds without ptrace (--stop-at, --read, -i). test-agent records real targets and checks the recordings. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'targets/agent_zig.zig')
-rw-r--r--targets/agent_zig.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/targets/agent_zig.zig b/targets/agent_zig.zig
new file mode 100644
index 0000000..bfb2f5d
--- /dev/null
+++ b/targets/agent_zig.zig
@@ -0,0 +1,20 @@
+//! A Zig program that annotates itself: agent_api.c again, with the agent
+//! compiled in as a module instead of linked as a library.
+const std = @import("std");
+const agent = @import("ztrace-agent");
+
+pub fn main() void {
+ var numbers = [16]i32{ 9, 3, 14, 0, 7, 12, 5, 1, 15, 8, 2, 11, 6, 13, 4, 10 };
+ agent.watch(std.mem.asBytes(&numbers), "numbers");
+ for (1..numbers.len) |i| {
+ const value = numbers[i];
+ var j = i;
+ while (j > 0 and numbers[j - 1] > value) : (j -= 1) numbers[j] = numbers[j - 1];
+ numbers[j] = value;
+ agent.mark("inserted", i);
+ }
+ var checksum: u64 = 0;
+ for (numbers) |v| checksum = checksum *% 31 +% @as(u64, @intCast(v));
+ agent.snapshot(std.mem.asBytes(&checksum));
+ agent.mark("done", checksum);
+}