From 7f6a57605ca49fb28b122af7db27384177a5ba5f Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Sat, 8 Mar 2008 22:01:47 +0800 Subject: [PATCH] enhanced backtrace output Signed-off-by: Guanqun Lu --- kern/kdebug.c | 15 +++++++++++++-- kern/monitor.c | 10 ++++++++++ kern/pmap.c | 3 ++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/kern/kdebug.c b/kern/kdebug.c index 89833db..7e2c9e2 100644 --- a/kern/kdebug.c +++ b/kern/kdebug.c @@ -108,7 +108,7 @@ debuginfo_eip(uintptr_t addr, struct Eipdebuginfo *info) { const struct Stab *stabs, *stab_end; const char *stabstr, *stabstr_end; - int lfile, rfile, lfun, rfun, lline, rline; + int lfile, rfile, lfun, rfun, lline, rline, i; // Initialize *info info->eip_file = ""; @@ -181,8 +181,12 @@ debuginfo_eip(uintptr_t addr, struct Eipdebuginfo *info) // Look at the STABS documentation and to find // which one. // Your code here. + lline = lfun; + rline = rfun; + stab_binsearch(stabs, &lline, &rline, N_SLINE, addr); + if (lline <= rline) + info->eip_line = stabs[lline].n_desc; - // Search backwards from the line number for the relevant filename // stab. // We can't just use the "lfile" stab because inlined functions @@ -200,6 +204,13 @@ debuginfo_eip(uintptr_t addr, struct Eipdebuginfo *info) // or 0 if there was no containing function. // Your code here. + // but it seems that it is not used? + i = 0; + while (lline <= rline && stabs[lline].n_type == N_PSYM) { + lline++; + i++; + } + info->eip_fn_narg = i; return 0; } diff --git a/kern/monitor.c b/kern/monitor.c index 5fefbfb..36a5af6 100644 --- a/kern/monitor.c +++ b/kern/monitor.c @@ -24,6 +24,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 the backtrace information", mon_backtrace }, }; #define NCOMMANDS (sizeof(commands)/sizeof(commands[0])) @@ -60,6 +61,7 @@ int mon_backtrace(int argc, char **argv, struct Trapframe *tf) { // Your code here. + struct Eipdebuginfo eip_debug; unsigned int *ebp, *eip; int i; @@ -67,6 +69,14 @@ mon_backtrace(int argc, char **argv, struct Trapframe *tf) eip = (unsigned int *)read_eip(); cprintf("Stack backtrace:\n"); while (ebp) { + // enhanced backtrace output + debuginfo_eip((uintptr_t)eip, &eip_debug); + cprintf("%s:%d: ", eip_debug.eip_file, eip_debug.eip_line); + for (i = 0; i < eip_debug.eip_fn_namelen; i++) + cprintf("%c", eip_debug.eip_fn_name[i]); + cprintf("+%x\n", + (unsigned int)eip - (unsigned int)eip_debug.eip_fn_addr); + eip = (unsigned int *)*(ebp + 1); // basic backtrace output diff --git a/kern/pmap.c b/kern/pmap.c index 065b317..37c187a 100644 --- a/kern/pmap.c +++ b/kern/pmap.c @@ -445,6 +445,7 @@ page_init(void) // Change the code to reflect this. struct Page *ppage; unsigned int i; + extern char _start[]; LIST_INIT(&page_free_list); for (i = 0; i < npage; i++) { @@ -462,7 +463,7 @@ page_init(void) } // reserve the kernel image and data structures allocated - for (i = 0xf0100000; i < (unsigned int)boot_freemem; i += PGSIZE) { + for (i = (unsigned int)_start; i < (unsigned int)boot_freemem; i += PGSIZE) { ppage = pa2page(PADDR(i)); LIST_REMOVE(ppage, pp_link); } -- 2.11.4.GIT