Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Jan 2017 00:08:05 +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: r311341 - in head/sys/mips: include mips
Message-ID:  <201701050008.v05085bQ068419@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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)
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701050008.v05085bQ068419>