diff options
| author | Rob Pike <r@golang.org> | 2008-06-21 15:36:23 -0700 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2008-06-21 15:36:23 -0700 |
| commit | aeb43984ec7c86aee220cc56146e0127de4ce2e3 (patch) | |
| tree | 7e4f626347e842638a70c0fd9a09bd26b8a586b0 /src/runtime/rt2_amd64.c | |
| parent | 54abac678ac9d92e168360e961214100712ceb4f (diff) | |
| download | go-aeb43984ec7c86aee220cc56146e0127de4ce2e3.tar.xz | |
add signal handling and traceback support therein.
factor the runtime into architecture-dependent and -independent pieces.
ditto for the OS dependence.
SVN=124020
Diffstat (limited to 'src/runtime/rt2_amd64.c')
| -rw-r--r-- | src/runtime/rt2_amd64.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/runtime/rt2_amd64.c b/src/runtime/rt2_amd64.c new file mode 100644 index 0000000000..1145ff72f8 --- /dev/null +++ b/src/runtime/rt2_amd64.c @@ -0,0 +1,68 @@ +// 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"; + +void +traceback(uint8 *pc, uint8 *sp) +{ + int32 spoff; + int8* spp; + int32 counter; + int32 i; + int8* name; + + + counter = 0; + name = "panic"; + for(;;){ + prints("0x"); + sys_printpointer(pc); + prints("?zi\n"); + /* 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; + /* print args for this frame */ + prints("\t"); + prints(name); + prints("("); + for(i = 0; i < 3; i++){ + if(i != 0) + prints(", "); + sys_printint(((uint32*)sp)[i]); + } + prints(", ...)\n"); + prints("\t"); + prints(name); + prints("("); + for(i = 0; i < 3; i++){ + if(i != 0) + prints(", "); + prints("0x"); + sys_printpointer(((void**)sp)[i]); + } + prints(", ...)\n"); + /* print pc for next frame */ + } +} |
