From ce7c0abf14e7ab056d5479adc3f05df9976e94e4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 11:44:48 -0300 Subject: 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 --- targets/agent_api.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 targets/agent_api.c (limited to 'targets/agent_api.c') diff --git a/targets/agent_api.c b/targets/agent_api.c new file mode 100644 index 0000000..1c954cf --- /dev/null +++ b/targets/agent_api.c @@ -0,0 +1,22 @@ +// A program that annotates itself: the agent linked in, an array on its +// stack watched, a mark after every step of an insertion sort. +#include +#include + +int main(void) { + int numbers[16] = {9, 3, 14, 0, 7, 12, 5, 1, 15, 8, 2, 11, 6, 13, 4, 10}; + int n = sizeof numbers / sizeof *numbers; + ztrace_watch(numbers, sizeof numbers, "numbers"); + for (int i = 1; i < n; i++) { + int value = numbers[i], j = i; + for (; j > 0 && numbers[j - 1] > value; j--) numbers[j] = numbers[j - 1]; + numbers[j] = value; + ztrace_mark("inserted", i); + } + unsigned long checksum = 0; + for (int i = 0; i < n; i++) checksum = checksum * 31 + numbers[i]; + ztrace_snapshot(&checksum, sizeof checksum); + ztrace_mark("done", checksum); + printf("%lu\n", checksum); + return 0; +} -- cgit v1.3