#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
void *stack_start;
// Fix: also needs to scan registers
void __attribute__((noinline)) foo(int *a) {
void *stack_curr = &(size_t){0x87654321};
while(stack_curr < stack_start) {
int *v = *(int **)stack_curr;
printf("0x%.16zX", v);
if(v == a) {
printf(" <-- %i", *v);
}
printf("\n");
stack_curr += sizeof(size_t);
}
}
void bar() {
int *a = malloc(4);
*a = 56;
printf("0x%.16zX <--\n", a);
foo(a);
}
int main(void) {
stack_start = &(size_t){0x12345678};
bar();
return 0;
}