From owner-svn-src-all@freebsd.org Thu Jan 5 00:08:06 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 50845C9F82A; Thu, 5 Jan 2017 00:08:06 +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 12DE81E76; Thu, 5 Jan 2017 00:08:06 +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 v05085oX068421; Thu, 5 Jan 2017 00:08:05 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v05085bQ068419; Thu, 5 Jan 2017 00:08:05 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201701050008.v05085bQ068419@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:08:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r311341 - in head/sys/mips: include 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:08:06 -0000 Author: jhb Date: Thu Jan 5 00:08:04 2017 New Revision: 311341 URL: https://svnweb.freebsd.org/changeset/base/311341 Log: Only call stacktrace_subr() from DDB. There was a single call to stacktrace() under an #ifdef DEBUG to obtain a stack trace during a fault that resulted in a function pointer to a printf function being passed to stacktrace_subr() in db_trace.c. The kernel now has existing interfaces for obtaining a stack trace outside of DDB (kdb_backtrace(), or the stack_*() API) that should be used instead. Rather than fix the one call however, remove it since the kernel will dump a trace anyway once it panics. Make stacktrace_subr() static, remove the function pointer and change it to use db_printf() explicitly. Discussed with: kan Sponsored by: DARPA / AFRL Modified: head/sys/mips/include/db_machdep.h head/sys/mips/mips/db_trace.c head/sys/mips/mips/trap.c Modified: head/sys/mips/include/db_machdep.h ============================================================================== --- head/sys/mips/include/db_machdep.h Wed Jan 4 23:22:34 2017 (r311340) +++ head/sys/mips/include/db_machdep.h Thu Jan 5 00:08:04 2017 (r311341) @@ -92,7 +92,6 @@ db_addr_t next_instr_address(db_addr_t, int db_inst_type(int); db_addr_t branch_taken(int inst, db_addr_t pc); -void stacktrace_subr(register_t pc, register_t sp, register_t ra, int (*)(const char *, ...)); int32_t kdbpeek(int *); int64_t kdbpeekd(int *); Modified: head/sys/mips/mips/db_trace.c ============================================================================== --- head/sys/mips/mips/db_trace.c Wed Jan 4 23:22:34 2017 (r311340) +++ head/sys/mips/mips/db_trace.c Thu Jan 5 00:08:04 2017 (r311341) @@ -130,9 +130,8 @@ fn_name(uintptr_t addr) return (buf); } -void -stacktrace_subr(register_t pc, register_t sp, register_t ra, - int (*printfn) (const char *,...)) +static void +stacktrace_subr(register_t pc, register_t sp, register_t ra) { InstFmt i; /* @@ -163,14 +162,14 @@ loop: subr = 0; trapframe = false; if (frames++ > 100) { - (*printfn) ("\nstackframe count exceeded\n"); + db_printf("\nstackframe count exceeded\n"); /* return breaks stackframe-size heuristics with gcc -O2 */ goto finish; /* XXX */ } /* check for bad SP: could foul up next frame */ /*XXX MIPS64 bad: this hard-coded SP is lame */ if (!MIPS_IS_VALID_KERNELADDR(sp)) { - (*printfn) ("SP 0x%jx: not in kernel\n", sp); + db_printf("SP 0x%jx: not in kernel\n", sp); ra = 0; subr = 0; goto done; @@ -215,7 +214,7 @@ loop: /* check for bad PC */ /*XXX MIPS64 bad: These hard coded constants are lame */ if (!MIPS_IS_VALID_KERNELADDR(pc)) { - (*printfn) ("PC 0x%jx: not in kernel\n", pc); + db_printf("PC 0x%jx: not in kernel\n", pc); ra = 0; goto done; } @@ -389,17 +388,17 @@ loop: } done: - (*printfn) ("%s+%x (", fn_name(subr), pc - subr); + db_printf("%s+%jx (", fn_name(subr), (uintmax_t)(pc - subr)); for (j = 0; j < 4; j ++) { if (j > 0) - (*printfn)(","); + db_printf(","); if (valid_args[j]) - (*printfn)("%jx", (uintmax_t)(u_register_t)args[j]); + db_printf("%jx", (uintmax_t)(u_register_t)args[j]); else - (*printfn)("?"); + db_printf("?"); } - (*printfn) (") ra %jx sp %jx sz %d\n", + db_printf(") ra %jx sp %jx sz %d\n", (uintmax_t)(u_register_t) ra, (uintmax_t)(u_register_t) sp, stksize); @@ -420,12 +419,12 @@ done: badvaddr = kdbpeek((int *)TF_REG(sp, BADVADDR)); #endif #undef TF_REG - (*printfn) ("--- exception, cause %jx badvaddr %jx ---\n", + db_printf("--- exception, cause %jx badvaddr %jx ---\n", (uintmax_t)cause, (uintmax_t)badvaddr); goto loop; } else if (ra) { if (pc == ra && stksize == 0) - (*printfn) ("stacktrace: loop!\n"); + db_printf("stacktrace: loop!\n"); else { pc = ra; sp += stksize; @@ -435,9 +434,9 @@ done: } else { finish: if (curproc) - (*printfn) ("pid %d\n", curproc->p_pid); + db_printf("pid %d\n", curproc->p_pid); else - (*printfn) ("curproc NULL\n"); + db_printf("curproc NULL\n"); } } @@ -479,7 +478,7 @@ db_trace_self(void) "move $31, %1\n" /* restore ra */ : "=r" (pc) : "r" (ra)); - stacktrace_subr(pc, sp, ra, db_printf); + stacktrace_subr(pc, sp, ra); return; } @@ -493,7 +492,7 @@ db_trace_thread(struct thread *thr, int sp = (register_t)ctx->pcb_context[PCB_REG_SP]; pc = (register_t)ctx->pcb_context[PCB_REG_PC]; ra = (register_t)ctx->pcb_context[PCB_REG_RA]; - stacktrace_subr(pc, sp, ra, db_printf); + stacktrace_subr(pc, sp, ra); return (0); } Modified: head/sys/mips/mips/trap.c ============================================================================== --- head/sys/mips/mips/trap.c Wed Jan 4 23:22:34 2017 (r311340) +++ head/sys/mips/mips/trap.c Thu Jan 5 00:08:04 2017 (r311341) @@ -278,11 +278,6 @@ char *trap_type[] = { struct trapdebug trapdebug[TRAPSIZE], *trp = trapdebug; #endif -#if defined(DDB) || defined(DEBUG) -void stacktrace(struct trapframe *); -void logstacktrace(struct trapframe *); -#endif - #define KERNLAND(x) ((vm_offset_t)(x) >= VM_MIN_KERNEL_ADDRESS && (vm_offset_t)(x) < VM_MAX_KERNEL_ADDRESS) #define DELAYBRANCH(x) ((int)(x) < 0) @@ -1082,7 +1077,6 @@ dofault: err: #if !defined(SMP) && defined(DEBUG) - stacktrace(!usermode ? trapframe : td->td_frame); trapDump("trap"); #endif #ifdef SMP @@ -1302,18 +1296,6 @@ MipsEmulateBranch(struct trapframe *fram return (retAddr); } - -#if defined(DDB) || defined(DEBUG) -/* - * Print a stack backtrace. - */ -void -stacktrace(struct trapframe *regs) -{ - stacktrace_subr(regs->pc, regs->sp, regs->ra, printf); -} -#endif - static void log_frame_dump(struct trapframe *frame) {