matos/core/stack.c
2018-11-16 14:47:21 +01:00

29 lines
764 B
C

#include "stack.h"
#include "vga.h"
void printStackTrace(unsigned int maxFrames){
#ifdef DEBUG
// Now on Stack:
// ( potential second function argument )
// first function argument (maxFrames)
// return address from caller
// EBP (Extended Base Pointer) of calling function
unsigned int * ebp = &maxFrames - 2;
for (unsigned int frame = 0 ; frame < maxFrames; frame ++){
unsigned int eip = ebp [1];
if (eip == 0){
// No caller on stack
break;
}
ebp = (unsigned int *)(ebp[0]);
//unsigned int * arguments = &ebp[2];
printf(" 0x%x\n", eip);
}
#else
printf("Must be compiled with -fno-omit-frame-pointer for full stack\n");
unsigned int * ebp = &maxFrames - 2;
unsigned int eip = ebp [1];
printf("Caller: 0x%x\n", eip);
#endif
}