From 8beab959b633e6641d07aba053a55e6e8e61eb00 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 11:58:00 -0300 Subject: targets, test-debugger, bench-debugger A linked list, a graph search in Zig, the same C under glibc and musl, two threads. The tests drive the debugger over them: breakpoint counts, the lines a step walks (as gdb), a list snapshotted by a hook, a watch's words, the syscalls that tell glibc from musl, threads, attach, and scripted dbg and record sessions. The bench measures steps, stops and memory access from bare ptrace up to a recording. Co-Authored-By: Claude Fable 5.2 --- targets/threads.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 targets/threads.c (limited to 'targets/threads.c') diff --git a/targets/threads.c b/targets/threads.c new file mode 100644 index 0000000..ab4d80d --- /dev/null +++ b/targets/threads.c @@ -0,0 +1,26 @@ +// Two threads and a mutex: each adds its share to `total`, main joins them +// and prints it. What clone, futex and a thread's exit look like to a tracer. +#include +#include + +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +long total; + +__attribute__((noinline)) static void *work(void *arg) { + for (long i = 0; i < 1000; i++) { + pthread_mutex_lock(&lock); + total += (long)arg; + pthread_mutex_unlock(&lock); + } + return NULL; +} + +int main(void) { + pthread_t a, b; + pthread_create(&a, NULL, work, (void *)1); + pthread_create(&b, NULL, work, (void *)2); + pthread_join(a, NULL); + pthread_join(b, NULL); + printf("total = %ld\n", total); + return 0; +} -- cgit v1.3