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
This commit is contained in:
John Baldwin 2017-01-05 00:08:04 +00:00
parent 2277edc8a6
commit da53b41194
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=311341
3 changed files with 16 additions and 36 deletions

View File

@ -92,7 +92,6 @@ db_addr_t next_instr_address(db_addr_t, boolean_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 *);

View File

@ -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 @@ stacktrace_subr(register_t pc, register_t sp, register_t ra,
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 @@ stacktrace_subr(register_t pc, register_t sp, register_t ra,
/* 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 @@ stacktrace_subr(register_t pc, register_t sp, register_t ra,
}
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 @@ stacktrace_subr(register_t pc, register_t sp, register_t ra,
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 @@ stacktrace_subr(register_t pc, register_t sp, register_t ra,
} 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 count)
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);
}

View File

@ -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 @@ trap(struct trapframe *trapframe)
err:
#if !defined(SMP) && defined(DEBUG)
stacktrace(!usermode ? trapframe : td->td_frame);
trapDump("trap");
#endif
#ifdef SMP
@ -1302,18 +1296,6 @@ MipsEmulateBranch(struct trapframe *framePtr, uintptr_t instPC, int fpcCSR,
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)
{