Don't use __builtin_return_address for stack traces

上级 553de92d
...@@ -191,6 +191,14 @@ rrsp(void) ...@@ -191,6 +191,14 @@ rrsp(void)
return val; return val;
} }
static inline u64
rrbp(void)
{
u64 val;
__asm volatile("movq %%rbp,%0" : "=r" (val));
return val;
}
static inline void static inline void
lcr4(u64 val) lcr4(u64 val)
{ {
......
...@@ -135,26 +135,13 @@ puts(const char *s) ...@@ -135,26 +135,13 @@ puts(const char *s)
} }
static inline void static inline void
stacktrace(void) printtrace(u64 rbp)
{ {
#define PRINT_RET(i) \ uptr pc[10];
do { \
uptr addr = (uptr) __builtin_return_address(i); \ getcallerpcs((void*)rbp, pc, NELEM(pc));
if ((addr & KBASE) == KBASE) \ for (int i = 0; i < NELEM(pc) && pc[i] != 0; i++)
__cprintf(" %lx\n", addr); \ __cprintf(" %p\n", pc[i]);
else \
return; \
} while (0)
PRINT_RET(0);
PRINT_RET(1);
PRINT_RET(2);
PRINT_RET(3);
PRINT_RET(4);
PRINT_RET(5);
PRINT_RET(6);
#undef PRINT_RET
} }
void __noret__ void __noret__
...@@ -164,8 +151,6 @@ kerneltrap(struct trapframe *tf) ...@@ -164,8 +151,6 @@ kerneltrap(struct trapframe *tf)
const char *name = "(no name)"; const char *name = "(no name)";
void *kstack = NULL; void *kstack = NULL;
int pid = 0; int pid = 0;
uptr pc[10];
int i;
cli(); cli();
acquire(&cons.lock); acquire(&cons.lock);
...@@ -182,9 +167,7 @@ kerneltrap(struct trapframe *tf) ...@@ -182,9 +167,7 @@ kerneltrap(struct trapframe *tf)
tf->trapno, mycpu()->id, tf->trapno, mycpu()->id,
tf->rip, tf->rsp, rcr2(), tf->rip, tf->rsp, rcr2(),
name, pid, kstack); name, pid, kstack);
getcallerpcs((void*)tf->rbp, pc, NELEM(pc)); printtrace(tf->rbp);
for (i = 0; i < NELEM(pc) && pc[i] != 0; i++)
__cprintf(" %p\n", pc[i]);
panicked = 1; panicked = 1;
sys_halt(); sys_halt();
...@@ -206,7 +189,7 @@ panic(const char *fmt, ...) ...@@ -206,7 +189,7 @@ panic(const char *fmt, ...)
vprintfmt(writecons, 0, fmt, ap); vprintfmt(writecons, 0, fmt, ap);
va_end(ap); va_end(ap);
__cprintf("\n"); __cprintf("\n");
stacktrace(); printtrace(rrbp());
panicked = 1; panicked = 1;
sys_halt(); sys_halt();
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论