I've been trying to get this stack tracer to work, but I always get a page fault.
Code:
void kstrace(int depth) {
unsigned int *ebp = &depth - 2;
printf("Stack trace:\n");
for (unsigned int frame = 0; frame < depth; ++frame) {
unsigned int eip = ebp[1];
if (eip == 0)
break;
ebp = (unsigned int *)(ebp[0]);
unsigned int *arguments = &ebp[2];
printf(" %02X\n", eip);
}
}
As you can see, it's copied pretty much straight from the wiki.
If I use GDB, I can see what's going on:
Code:
Remote debugging using :1234
k_main (mboot=0x10000) at src/kernel/kernel.c:104
104 kstrace(10);
(gdb) continue
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0x0010472e in kstrace (depth=10) at src/libk/stdlib.c:126
126 unsigned int eip = ebp[1];
(gdb) stop
(gdb) backtrace
#0 0x0010373e in kstrace (depth=10) at src/libk/stdlib.c:126
#1 0x0010310d in k_main (mboot=0x10000) at src/kernel/kernel.c:104
#2 0x00104d14 in start ()
(gdb)
And on the kernel's ouput, I see this:
Code:
Stack trace:
0x0010310D
0x00104D14
0xF000FF53
(Page Fault)
It's like it's shifted. I'm new to using GDB, stack tracing, and debugging in general. It's never something I've done or used before.
If you need a register dump, let me know.
I don't know what I need to do here, so that's why I'm asking for help. Thanks in advance!