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
This commit is contained in:
John Baldwin 2016-12-13 22:30:48 +00:00
parent 2aca18c7ae
commit 2aa82aeacc
2 changed files with 22 additions and 26 deletions

View 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);
}

View 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