svn commit: r310037 - head/sys/mips/mips

John Baldwin jhb at FreeBSD.org
Tue Dec 13 22:30:49 UTC 2016


Author: jhb
Date: Tue Dec 13 22:30:48 2016
New Revision: 310037
URL: https://svnweb.freebsd.org/changeset/base/310037

Log:
  Fix stack traces in DDB for the debugger thread.
  
  When the kernel debugger is entered, makectx() is called to store
  appropriate state from the trapframe for the debugger into a global
  kdb_pcb used as the thread context of the thread entering the
  debugger.  Stack unwinders for DDB called via db_trace_thread() are
  supposed to then use this saved context so that the stack trace for
  the current thread starts at the location of the event that triggered
  debugger entry.
  
  MIPS was instead starting the stack trace of the current thread from
  the context of db_trace_thread itself and unwinding back out through
  the debugger to the original frame.  Fix a couple of things to bring
  MIPS inline with other platforms:
  - Fix makectx() to store the PC, SP, and RA in the right portion of
    the PCB used by db_trace_thread().
  - Fix db_trace_thread() to always use kdb_thr_ctx() (and thus kdb_pcb
    for the debugger thread).
  - Move the logic for tracing curthread from within the current
    function into db_trace_self() to match other architectures.
  
  Sponsored by:	DARPA / AFRL

Modified:
  head/sys/mips/mips/db_trace.c
  head/sys/mips/mips/pm_machdep.c

Modified: head/sys/mips/mips/db_trace.c
==============================================================================
--- head/sys/mips/mips/db_trace.c	Tue Dec 13 22:16:02 2016	(r310036)
+++ head/sys/mips/mips/db_trace.c	Tue Dec 13 22:30:48 2016	(r310037)
@@ -432,7 +432,20 @@ db_md_list_watchpoints()
 void
 db_trace_self(void)
 {
-	db_trace_thread (curthread, -1);
+	register_t pc, ra, sp;
+
+	sp = (register_t)(intptr_t)__builtin_frame_address(0);
+	ra = (register_t)(intptr_t)__builtin_return_address(0);
+
+	__asm __volatile(
+		"jal 99f\n"
+		"nop\n"
+		"99:\n"
+		 "move %0, $31\n" /* get ra */
+		 "move $31, %1\n" /* restore ra */
+		 : "=r" (pc)
+		 : "r" (ra));
+	stacktrace_subr(pc, sp, ra, db_printf);
 	return;
 }
 
@@ -442,28 +455,11 @@ db_trace_thread(struct thread *thr, int 
 	register_t pc, ra, sp;
 	struct pcb *ctx;
 
-	if (thr == curthread) {
-		sp = (register_t)(intptr_t)__builtin_frame_address(0);
-		ra = (register_t)(intptr_t)__builtin_return_address(0);
-
-        	__asm __volatile(
-			"jal 99f\n"
-			"nop\n"
-			"99:\n"
-                         "move %0, $31\n" /* get ra */
-                         "move $31, %1\n" /* restore ra */
-                         : "=r" (pc)
-			 : "r" (ra));
-
-	} else {
-		ctx = kdb_thr_ctx(thr);
-		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,
-	    (int (*) (const char *, ...))db_printf);
+	ctx = kdb_thr_ctx(thr);
+	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);
 
 	return (0);
 }

Modified: head/sys/mips/mips/pm_machdep.c
==============================================================================
--- head/sys/mips/mips/pm_machdep.c	Tue Dec 13 22:16:02 2016	(r310036)
+++ head/sys/mips/mips/pm_machdep.c	Tue Dec 13 22:30:48 2016	(r310037)
@@ -292,9 +292,9 @@ void
 makectx(struct trapframe *tf, struct pcb *pcb)
 {
 
-	pcb->pcb_regs.ra = tf->ra;
-	pcb->pcb_regs.pc = tf->pc;
-	pcb->pcb_regs.sp = tf->sp;
+	pcb->pcb_context[PCB_REG_RA] = tf->ra;
+	pcb->pcb_context[PCB_REG_PC] = tf->pc;
+	pcb->pcb_context[PCB_REG_SP] = tf->sp;
 }
 
 int


More information about the svn-src-head mailing list