From owner-svn-src-all@freebsd.org Thu Jan 5 00:59:54 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3D64AC9D40B; Thu, 5 Jan 2017 00:59:54 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1801A1356; Thu, 5 Jan 2017 00:59:54 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v050xrNl088678; Thu, 5 Jan 2017 00:59:53 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v050xrDZ088677; Thu, 5 Jan 2017 00:59:53 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201701050059.v050xrDZ088677@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Thu, 5 Jan 2017 00:59:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r311343 - head/sys/mips/mips X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Jan 2017 00:59:54 -0000 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"); } }