On a kernel trap, print a stacktrace from the RSP when the trap was raised

上级 fc7e1de6
......@@ -147,23 +147,44 @@ stacktrace(void)
#undef PRINT_RET
}
void __attribute__((noreturn))
panic(const char *s)
void __noret__
kerneltrap(struct trapframe *tf)
{
extern void sys_halt();
uptr pc[10];
int i;
cli();
cons.locking = 0;
cprintf("unexpected trap %d from cpu %d rip %lx (cr2=0x%lx)\n",
tf->trapno, mycpu()->id, tf->rip, rcr2());
getcallerpcs((void*)tf->rbp, pc);
for (i = 0; i < NELEM(pc) && pc[i] != 0; i++)
cprintf(" %p\n", pc[i]);
panicked = 1;
acquire(&cons.lock);
sys_halt();
for(;;)
;
}
void __noret__
panic(const char *s)
{
extern void sys_halt();
cli();
cons.locking = 0;
cprintf("cpu%d: panic: ", mycpu()->id);
cprintf(s);
cprintf("\n");
stacktrace();
panicked = 1;
acquire(&cons.lock);
// Never release cons.lock
sys_halt();
for(;;)
;
......
......@@ -45,7 +45,8 @@ void cv_tick(void);
// console.c
void cprintf(const char*, ...);
void panic(const char*) __attribute__((noreturn));
void panic(const char*) __noret__;
void kerneltrap(struct trapframe *tf) __noret__;
void snprintf(char *buf, u32 n, char *fmt, ...);
void consoleintr(int(*)(void));
......@@ -237,7 +238,7 @@ int growproc(int);
int kill(int);
void pinit(void);
void procdumpall(void);
void scheduler(void) __attribute__((noreturn));
void scheduler(void) __noret__;
void sched(void);
void userinit(void);
int wait(void);
......
......@@ -115,12 +115,8 @@ trap(struct trapframe *tf)
break;
}
if(myproc() == 0 || (tf->cs&3) == 0){
// In kernel, it must be our mistake.
cprintf("unexpected trap %d from cpu %d rip %lx (cr2=0x%lx)\n",
tf->trapno, mycpu()->id, tf->rip, rcr2());
panic("trap");
}
if (myproc() == 0 || (tf->cs&3) == 0)
kerneltrap(tf);
if(tf->trapno == T_PGFLT){
uptr addr = rcr2();
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论