Implement the backtrace code.

This commit is contained in:
Danila Fedorin 2019-04-04 20:37:53 -07:00
parent 8ef5e2f810
commit dd3281aba0
1 changed files with 20 additions and 0 deletions

View File

@ -25,6 +25,7 @@ struct Command {
static struct Command commands[] = {
{ "help", "Display this list of commands", mon_help },
{ "kerninfo", "Display information about the kernel", mon_kerninfo },
{ "backtrace", "Display current backtrace", mon_backtrace }
};
/***** Implementations of basic kernel monitor commands *****/
@ -61,6 +62,25 @@ mon_backtrace(int argc, char **argv, struct Trapframe *tf)
// LAB 1: Your code here.
// HINT 1: use read_ebp().
// HINT 2: print the current ebp on the first line (not current_ebp[0])
uint32_t* ebp;
uint32_t eip;
struct Eipdebuginfo info;
ebp = (uint32_t*) read_ebp();
cprintf("Stack backtrace:\n");
while(ebp) {
eip = ebp[1];
cprintf(" ebp %08x eip %08x args %08x %08x %08x %08x %08x\n",
ebp, eip, ebp[2], ebp[3], ebp[4], ebp[5], ebp[6]);
ebp = (uint32_t*) ebp[0];
debuginfo_eip(eip, &info);
cprintf(" %s:%d: %.*s+%d\n",
info.eip_file, info.eip_line,
info.eip_fn_namelen, info.eip_fn_name,
eip - info.eip_fn_addr);
};
return 0;
}