Im trying to write a function in C that identifies the top of the stack and determines the first frame pointer. Then I have a different function that recursively prints the current stack frame and calls itself with the next stack frame's pointer. Any tips on how to do this and get started?
void stackTrace(int prms, int localVars){
}
void nextTrace(unsigned int *framePointer, int prms, int localVars){
}
That's how I did it, because GNU
backtracedid not work with TinyC. I think my function wotks witm gcc/clang as well. The trick here is to start from the address stored in RBP (on x86_64) and walk until__libc_stack_endwhich is a builtin variable.