]> xenbits.xensource.com Git - people/royger/freebsd.git/commitdiff
Fix stack traces in DDB for the debugger thread.
authorjhb <jhb@FreeBSD.org>
Tue, 13 Dec 2016 22:30:48 +0000 (22:30 +0000)
committerjhb <jhb@FreeBSD.org>
Tue, 13 Dec 2016 22:30:48 +0000 (22:30 +0000)
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

sys/mips/mips/db_trace.c
sys/mips/mips/pm_machdep.c

index 74d05b92617af4fa578c15d5d3c3a8eee9443f15..8126febc144761be4fcc1313bcfb5ad31790e948 100644 (file)
@@ -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 count)
        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);
 }
index 577d1104690ae49dbe6a2a6f63bfa2b446feb23b..167706335c8dfa801e767be8e77254a94fb608a1 100644 (file)
@@ -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