From aeb43984ec7c86aee220cc56146e0127de4ce2e3 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Sat, 21 Jun 2008 15:36:23 -0700 Subject: add signal handling and traceback support therein. factor the runtime into architecture-dependent and -independent pieces. ditto for the OS dependence. SVN=124020 --- src/runtime/rt2_amd64.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/runtime/rt2_amd64.c (limited to 'src/runtime/rt2_amd64.c') 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 */ + } +} -- cgit v1.3-5-g9baa