diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 11:58:00 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 11:58:53 -0300 |
| commit | 8beab959b633e6641d07aba053a55e6e8e61eb00 (patch) | |
| tree | 0e5a91c0a00e121fe4094a333438ee90ccc5fdda /targets/list.c | |
| parent | 3fdb67c479dcc1ad0f1e51832bc086622692249c (diff) | |
| download | computeranim-8beab959b633e6641d07aba053a55e6e8e61eb00.tar.gz computeranim-8beab959b633e6641d07aba053a55e6e8e61eb00.zip | |
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 <[email protected]>
Diffstat (limited to 'targets/list.c')
| -rw-r--r-- | targets/list.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/targets/list.c b/targets/list.c new file mode 100644 index 0000000..e09d301 --- /dev/null +++ b/targets/list.c @@ -0,0 +1,42 @@ +// A linked list on the heap: built, reversed, summed. `list_done` gets the +// finished list, the place for a tracer to look at it. +#include <stdio.h> +#include <stdlib.h> + +struct node { + long value; + struct node *next; +}; + +__attribute__((noinline)) static struct node *push(struct node *head, long value) { + struct node *n = malloc(sizeof *n); + n->value = value; + n->next = head; + return n; +} + +__attribute__((noinline)) static struct node *reverse(struct node *head) { + struct node *prev = NULL; + while (head) { + struct node *next = head->next; + head->next = prev; + prev = head; + head = next; + } + return prev; +} + +__attribute__((noinline)) long list_done(struct node *head) { + long sum = 0; + for (; head; head = head->next) sum += head->value; + return sum; +} + +int main(int argc, char **argv) { + int n = argc > 1 ? atoi(argv[1]) : 6; + struct node *head = NULL; + for (int i = n; i >= 1; i--) head = push(head, i * i); + head = reverse(head); + printf("sum = %ld\n", list_done(head)); + return 0; +} |
