Date: Thu, 5 Jan 2017 00:59:53 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r311343 - head/sys/mips/mips Message-ID: <201701050059.v050xrDZ088677@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Thu Jan 5 00:59:53 2017 New Revision: 311343 URL: https://svnweb.freebsd.org/changeset/base/311343 Log: Use db_printsym() to display function names in stack traces. Previously, the stack unwinder tried to locate the start of the function in each frame by walking backwards until it found an instruction that modified the stack pointer and then assumed that was the first instruction in a function. The unwinder would only print a function name if the starting instruction's address was an exact match for a symbol name. However, not all functions generated by modern compilers start off functions with that instruction. For those functions, the unwinder would fail to find a matching function name. As a result, most frames in a stack trace would be printed as raw hex PC's instead of a function name. Stop depending on this incorrect assumption and just use db_printsym() like other platforms to display the function name and offset for each frame. This generates a far more useful stack trace. While here, don't print out curproc's pid at the end of the trace. The pid was always from curproc even if tracing some other process. In addition, remove some rotted comments about hardcoded constants that are no longer hardcoded. Sponsored by: DARPA / AFRL Modified: head/sys/mips/mips/db_trace.c Modified: head/sys/mips/mips/db_trace.c ============================================================================== --- head/sys/mips/mips/db_trace.c Thu Jan 5 00:26:57 2017 (r311342) +++ head/sys/mips/mips/db_trace.c Thu Jan 5 00:59:53 2017 (r311343) @@ -79,57 +79,6 @@ extern char edata[]; ((vm_offset_t)(reg) >= MIPS_KSEG0_START)) #endif -/* - * Functions ``special'' enough to print by name - */ -#ifdef __STDC__ -#define Name(_fn) { (void*)_fn, # _fn } -#else -#define Name(_fn) { _fn, "_fn"} -#endif -static struct { - void *addr; - char *name; -} names[] = { - - Name(trap), - Name(MipsKernGenException), - Name(MipsUserGenException), - Name(MipsKernIntr), - Name(MipsUserIntr), - Name(cpu_switch), - { - 0, 0 - } -}; - -/* - * Map a function address to a string name, if known; or a hex string. - */ -static const char * -fn_name(uintptr_t addr) -{ - static char buf[17]; - int i = 0; - - db_expr_t diff; - c_db_sym_t sym; - const char *symname; - - diff = 0; - symname = NULL; - sym = db_search_symbol((db_addr_t)addr, DB_STGY_ANY, &diff); - db_symbol_values(sym, &symname, NULL); - if (symname && diff == 0) - return (symname); - - for (i = 0; names[i].name; i++) - if (names[i].addr == (void *)addr) - return (names[i].name); - sprintf(buf, "%jx", (uintmax_t)addr); - return (buf); -} - static void stacktrace_subr(register_t pc, register_t sp, register_t ra) { @@ -163,11 +112,10 @@ loop: trapframe = false; if (frames++ > 100) { db_printf("\nstackframe count exceeded\n"); - /* return breaks stackframe-size heuristics with gcc -O2 */ - goto finish; /* XXX */ + return; } - /* check for bad SP: could foul up next frame */ - /*XXX MIPS64 bad: this hard-coded SP is lame */ + + /* Check for bad SP: could foul up next frame. */ if (!MIPS_IS_VALID_KERNELADDR(sp)) { db_printf("SP 0x%jx: not in kernel\n", sp); ra = 0; @@ -211,8 +159,8 @@ loop: ra = 0; goto done; } - /* check for bad PC */ - /*XXX MIPS64 bad: These hard coded constants are lame */ + + /* Check for bad PC. */ if (!MIPS_IS_VALID_KERNELADDR(pc)) { db_printf("PC 0x%jx: not in kernel\n", pc); ra = 0; @@ -388,7 +336,8 @@ loop: } done: - db_printf("%s+%jx (", fn_name(subr), (uintmax_t)(pc - subr)); + db_printsym(pc, DB_STGY_PROC); + db_printf(" ("); for (j = 0; j < 4; j ++) { if (j > 0) db_printf(","); @@ -431,12 +380,6 @@ done: ra = next_ra; goto loop; } - } else { -finish: - if (curproc) - db_printf("pid %d\n", curproc->p_pid); - else - db_printf("curproc NULL\n"); } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701050059.v050xrDZ088677>