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

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