Commit d6f25597 authored by Rob Pike's avatar Rob Pike

print rudimentary stack traceback after panic

SVN=123524
parent ddba96ae
...@@ -102,11 +102,61 @@ sys_printpc(void *p) ...@@ -102,11 +102,61 @@ sys_printpc(void *p)
void void
sys_panicl(int32 lno) sys_panicl(int32 lno)
{ {
uint8 *pc;
uint8 *sp;
uint8 *retpc;
int32 spoff;
static int8 spmark[] = "\xa7\xf1\xd9\x2a\x82\xc8\xd8\xfe";
int8* spp;
int32 counter;
int32 i;
prints("\npanic on line "); prints("\npanic on line ");
sys_printint(lno); sys_printint(lno);
prints(" "); prints(" ");
sys_printpc(&lno); sys_printpc(&lno);
prints("\n"); prints("\n");
sp = (uint8*)&lno;
pc = (uint8*)sys_panicl;
counter = 0;
while((pc = ((uint8**)sp)[-1]) > (uint8*)0x1000) {
for(i = 0; i < 3; i++){
prints("\tint32[");
sys_printint(i);
prints("]=");
sys_printint(((uint32*)sp)[i]);
prints("\tint64*[");
sys_printint(i);
prints("]=");
sys_printpointer(((void**)sp)[i]);
prints("\n");
}
prints("0x");
sys_printpointer(pc);
prints(" ");
/* next word down on stack is PC */
retpc = pc;
/* find SP offset by stepping back through instructions to SP offset marker */
while(pc > (uint8*)0x1000+11) {
for(spp = spmark; *spp != '\0' && *pc++ == (uint8)*spp++; )
;
if(*spp == '\0'){
spoff = *pc++;
spoff += *pc++ << 8;
spoff += *pc++ << 16;
prints((int8*)pc);
prints("+");
sys_printint(pc-retpc);
prints("?zi\n");
sp += spoff + 8;
break;
}
}
if(counter++ > 100){
prints("stack trace terminated\n");
break;
}
}
*(int32*)0 = 0; *(int32*)0 = 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment