2008-06-21 16:36:23 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "runtime.h"
|
|
|
|
|
|
|
|
extern int32 debug;
|
|
|
|
|
|
|
|
static int8 spmark[] = "\xa7\xf1\xd9\x2a\x82\xc8\xd8\xfe";
|
|
|
|
|
2008-07-11 20:35:14 -06:00
|
|
|
extern void morestack2();
|
2008-06-30 15:39:47 -06:00
|
|
|
|
2008-06-21 16:36:23 -06:00
|
|
|
void
|
2008-06-30 15:39:47 -06:00
|
|
|
traceback(uint8 *pc, uint8 *sp, void* r15)
|
2008-06-21 16:36:23 -06:00
|
|
|
{
|
|
|
|
int32 spoff;
|
|
|
|
int8* spp;
|
2008-06-30 15:39:47 -06:00
|
|
|
uint8* callpc;
|
2008-06-21 16:36:23 -06:00
|
|
|
int32 counter;
|
|
|
|
int32 i;
|
|
|
|
int8* name;
|
2008-07-09 12:35:26 -06:00
|
|
|
G g;
|
2008-06-30 15:39:47 -06:00
|
|
|
Stktop *stktop;
|
2008-06-21 16:36:23 -06:00
|
|
|
|
2008-06-30 15:39:47 -06:00
|
|
|
// store local copy of per-process data block that we can write as we unwind
|
2008-07-09 12:35:26 -06:00
|
|
|
mcpy((byte*)&g, (byte*)r15, sizeof(G));
|
2008-06-21 16:36:23 -06:00
|
|
|
|
|
|
|
counter = 0;
|
|
|
|
name = "panic";
|
|
|
|
for(;;){
|
2008-06-30 15:39:47 -06:00
|
|
|
callpc = pc;
|
2008-07-11 20:35:14 -06:00
|
|
|
if((uint8*)morestack2 == pc) {
|
2008-07-11 20:37:47 -06:00
|
|
|
// call site is morestack2(); pop to earlier stack block to get true caller
|
2008-07-09 12:35:26 -06:00
|
|
|
stktop = (Stktop*)g.stackbase;
|
|
|
|
g.stackbase = stktop->oldbase;
|
|
|
|
g.stackguard = stktop->oldguard;
|
2008-06-30 15:39:47 -06:00
|
|
|
sp = stktop->oldsp;
|
|
|
|
pc = ((uint8**)sp)[1];
|
|
|
|
sp += 16; // two irrelevant calls on stack - morestack, plus the call morestack made
|
|
|
|
continue;
|
|
|
|
}
|
2008-06-21 16:36:23 -06:00
|
|
|
/* find SP offset by stepping back through instructions to SP offset marker */
|
|
|
|
while(pc > (uint8*)0x1000+sizeof spmark-1) {
|
|
|
|
for(spp = spmark; *spp != '\0' && *pc++ == (uint8)*spp++; )
|
|
|
|
;
|
|
|
|
if(*spp == '\0'){
|
|
|
|
spoff = *pc++;
|
|
|
|
spoff += *pc++ << 8;
|
|
|
|
spoff += *pc++ << 16;
|
|
|
|
name = (int8*)pc;
|
|
|
|
sp += spoff + 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(counter++ > 100){
|
|
|
|
prints("stack trace terminated\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if((pc = ((uint8**)sp)[-1]) <= (uint8*)0x1000)
|
|
|
|
break;
|
2008-06-30 15:39:47 -06:00
|
|
|
|
|
|
|
/* print this frame */
|
|
|
|
prints("0x");
|
|
|
|
sys·printpointer(callpc);
|
|
|
|
prints("?zi\n");
|
2008-06-21 16:36:23 -06:00
|
|
|
prints("\t");
|
|
|
|
prints(name);
|
|
|
|
prints("(");
|
|
|
|
for(i = 0; i < 3; i++){
|
|
|
|
if(i != 0)
|
|
|
|
prints(", ");
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·printint(((uint32*)sp)[i]);
|
2008-06-21 16:36:23 -06:00
|
|
|
}
|
|
|
|
prints(", ...)\n");
|
|
|
|
prints("\t");
|
|
|
|
prints(name);
|
|
|
|
prints("(");
|
|
|
|
for(i = 0; i < 3; i++){
|
|
|
|
if(i != 0)
|
|
|
|
prints(", ");
|
|
|
|
prints("0x");
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·printpointer(((void**)sp)[i]);
|
2008-06-21 16:36:23 -06:00
|
|
|
}
|
|
|
|
prints(", ...)\n");
|
|
|
|
}
|
|
|
|
}
|