diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 11:44:48 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 12:09:34 -0300 |
| commit | ce7c0abf14e7ab056d5479adc3f05df9976e94e4 (patch) | |
| tree | 8931de9a55b3d7c2ec2d52d3b3817c6f7eb5db5a /targets/agent_fib.c | |
| parent | e7aa7801c10ed34194b7fe3f5ca8722a72404e65 (diff) | |
| download | computeranim-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_fib.c')
| -rw-r--r-- | targets/agent_fib.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/targets/agent_fib.c b/targets/agent_fib.c new file mode 100644 index 0000000..33ae856 --- /dev/null +++ b/targets/agent_fib.c @@ -0,0 +1,15 @@ +// A function to hook: fib(n) the slow way, kept from being turned into a +// loop so that it makes the 2 fib(n+1) - 1 calls the definition says. +#include <stdio.h> +#include <stdlib.h> + +__attribute__((noinline, optnone)) static unsigned long fib(unsigned long n) { + if (n < 2) return n; + return fib(n - 1) + fib(n - 2); +} + +int main(int argc, char **argv) { + unsigned long n = argc > 1 ? strtoul(argv[1], NULL, 10) : 10; + printf("fib(%lu) = %lu\n", n, fib(n)); + return 0; +} |
