Use db_printsym() to display function names in stack traces.

Previously, the stack unwinder tried to locate the start of the function
in each frame by walking backwards until it found an instruction that
modified the stack pointer and then assumed that was the first instruction
in a function.  The unwinder would only print a function name if the
starting instruction's address was an exact match for a symbol name.
However, not all functions generated by modern compilers start off functions
with that instruction.  For those functions, the unwinder would fail to
find a matching function name.  As a result, most frames in a stack
trace would be printed as raw hex PC's instead of a function name.

Stop depending on this incorrect assumption and just use db_printsym()
like other platforms to display the function name and offset for each
frame.  This generates a far more useful stack trace.

While here, don't print out curproc's pid at the end of the trace.  The
pid was always from curproc even if tracing some other process.

In addition, remove some rotted comments about hardcoded constants that
are no longer hardcoded.

Sponsored by:	DARPA / AFRL
This commit is contained in:
John Baldwin 2017-01-05 00:59:53 +00:00
parent da53b41194
commit 58ffa42f64
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=311343

View File

@ -79,57 +79,6 @@ extern char edata[];
((vm_offset_t)(reg) >= MIPS_KSEG0_START))
#endif
/*
* Functions ``special'' enough to print by name
*/
#ifdef __STDC__
#define Name(_fn) { (void*)_fn, # _fn }
#else
#define Name(_fn) { _fn, "_fn"}
#endif
static struct {
void *addr;
char *name;
} names[] = {
Name(trap),
Name(MipsKernGenException),
Name(MipsUserGenException),
Name(MipsKernIntr),
Name(MipsUserIntr),
Name(cpu_switch),
{
0, 0
}
};
/*
* Map a function address to a string name, if known; or a hex string.
*/
static const char *
fn_name(uintptr_t addr)
{
static char buf[17];
int i = 0;
db_expr_t diff;
c_db_sym_t sym;
const char *symname;
diff = 0;
symname = NULL;
sym = db_search_symbol((db_addr_t)addr, DB_STGY_ANY, &diff);
db_symbol_values(sym, &symname, NULL);
if (symname && diff == 0)
return (symname);
for (i = 0; names[i].name; i++)
if (names[i].addr == (void *)addr)
return (names[i].name);
sprintf(buf, "%jx", (uintmax_t)addr);
return (buf);
}
static void
stacktrace_subr(register_t pc, register_t sp, register_t ra)
{
@ -163,11 +112,10 @@ stacktrace_subr(register_t pc, register_t sp, register_t ra)
trapframe = false;
if (frames++ > 100) {
db_printf("\nstackframe count exceeded\n");
/* return breaks stackframe-size heuristics with gcc -O2 */
goto finish; /* XXX */
return;
}
/* check for bad SP: could foul up next frame */
/*XXX MIPS64 bad: this hard-coded SP is lame */
/* Check for bad SP: could foul up next frame. */
if (!MIPS_IS_VALID_KERNELADDR(sp)) {
db_printf("SP 0x%jx: not in kernel\n", sp);
ra = 0;
@ -211,8 +159,8 @@ stacktrace_subr(register_t pc, register_t sp, register_t ra)
ra = 0;
goto done;
}
/* check for bad PC */
/*XXX MIPS64 bad: These hard coded constants are lame */
/* Check for bad PC. */
if (!MIPS_IS_VALID_KERNELADDR(pc)) {
db_printf("PC 0x%jx: not in kernel\n", pc);
ra = 0;
@ -388,7 +336,8 @@ stacktrace_subr(register_t pc, register_t sp, register_t ra)
}
done:
db_printf("%s+%jx (", fn_name(subr), (uintmax_t)(pc - subr));
db_printsym(pc, DB_STGY_PROC);
db_printf(" (");
for (j = 0; j < 4; j ++) {
if (j > 0)
db_printf(",");
@ -431,12 +380,6 @@ stacktrace_subr(register_t pc, register_t sp, register_t ra)
ra = next_ra;
goto loop;
}
} else {
finish:
if (curproc)
db_printf("pid %d\n", curproc->p_pid);
else
db_printf("curproc NULL\n");
}
}