github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/src/runtime/signal_ppc64x.go (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build linux
     6  // +build ppc64 ppc64le
     7  
     8  package runtime
     9  
    10  import "unsafe"
    11  
    12  func dumpregs(c *sigctxt) {
    13  	print("r0   ", hex(c.r0()), "\t")
    14  	print("r1   ", hex(c.r1()), "\n")
    15  	print("r2   ", hex(c.r2()), "\t")
    16  	print("r3   ", hex(c.r3()), "\n")
    17  	print("r4   ", hex(c.r4()), "\t")
    18  	print("r5   ", hex(c.r5()), "\n")
    19  	print("r6   ", hex(c.r6()), "\t")
    20  	print("r7   ", hex(c.r7()), "\n")
    21  	print("r8   ", hex(c.r8()), "\t")
    22  	print("r9   ", hex(c.r9()), "\n")
    23  	print("r10  ", hex(c.r10()), "\t")
    24  	print("r11  ", hex(c.r11()), "\n")
    25  	print("r12  ", hex(c.r12()), "\t")
    26  	print("r13  ", hex(c.r13()), "\n")
    27  	print("r14  ", hex(c.r14()), "\t")
    28  	print("r15  ", hex(c.r15()), "\n")
    29  	print("r16  ", hex(c.r16()), "\t")
    30  	print("r17  ", hex(c.r17()), "\n")
    31  	print("r18  ", hex(c.r18()), "\t")
    32  	print("r19  ", hex(c.r19()), "\n")
    33  	print("r20  ", hex(c.r20()), "\t")
    34  	print("r21  ", hex(c.r21()), "\n")
    35  	print("r22  ", hex(c.r22()), "\t")
    36  	print("r23  ", hex(c.r23()), "\n")
    37  	print("r24  ", hex(c.r24()), "\t")
    38  	print("r25  ", hex(c.r25()), "\n")
    39  	print("r26  ", hex(c.r26()), "\t")
    40  	print("r27  ", hex(c.r27()), "\n")
    41  	print("r28  ", hex(c.r28()), "\t")
    42  	print("r29  ", hex(c.r29()), "\n")
    43  	print("r30  ", hex(c.r30()), "\t")
    44  	print("r31  ", hex(c.r31()), "\n")
    45  	print("pc   ", hex(c.pc()), "\t")
    46  	print("ctr  ", hex(c.ctr()), "\n")
    47  	print("link ", hex(c.link()), "\t")
    48  	print("xer  ", hex(c.xer()), "\n")
    49  	print("ccr  ", hex(c.ccr()), "\t")
    50  	print("trap ", hex(c.trap()), "\n")
    51  }
    52  
    53  func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
    54  	_g_ := getg()
    55  	c := &sigctxt{info, ctxt}
    56  
    57  	if sig == _SIGPROF {
    58  		sigprof((*byte)(unsafe.Pointer(uintptr(c.pc()))), (*byte)(unsafe.Pointer(uintptr(c.sp()))), (*byte)(unsafe.Pointer(uintptr(c.link()))), gp, _g_.m)
    59  		return
    60  	}
    61  	flags := int32(_SigThrow)
    62  	if sig < uint32(len(sigtable)) {
    63  		flags = sigtable[sig].flags
    64  	}
    65  	if c.sigcode() != _SI_USER && flags&_SigPanic != 0 {
    66  		// Make it look like a call to the signal func.
    67  		// Have to pass arguments out of band since
    68  		// augmenting the stack frame would break
    69  		// the unwinding code.
    70  		gp.sig = sig
    71  		gp.sigcode0 = uintptr(c.sigcode())
    72  		gp.sigcode1 = uintptr(c.fault())
    73  		gp.sigpc = uintptr(c.pc())
    74  
    75  		// We arrange link, and pc to pretend the panicking
    76  		// function calls sigpanic directly.
    77  		// Always save LINK to stack so that panics in leaf
    78  		// functions are correctly handled. This smashes
    79  		// the stack frame but we're not going back there
    80  		// anyway.
    81  		sp := c.sp() - ptrSize
    82  		c.set_sp(sp)
    83  		*(*uint64)(unsafe.Pointer(uintptr(sp))) = c.link()
    84  
    85  		// Don't bother saving PC if it's zero, which is
    86  		// probably a call to a nil func: the old link register
    87  		// is more useful in the stack trace.
    88  		if gp.sigpc != 0 {
    89  			c.set_link(uint64(gp.sigpc))
    90  		}
    91  
    92  		// In case we are panicking from external C code
    93  		c.set_r0(0)
    94  		c.set_r30(uint64(uintptr(unsafe.Pointer(gp))))
    95  		c.set_pc(uint64(funcPC(sigpanic)))
    96  		return
    97  	}
    98  
    99  	if c.sigcode() == _SI_USER || flags&_SigNotify != 0 {
   100  		if sigsend(sig) {
   101  			return
   102  		}
   103  	}
   104  
   105  	if flags&_SigKill != 0 {
   106  		exit(2)
   107  	}
   108  
   109  	if flags&_SigThrow == 0 {
   110  		return
   111  	}
   112  
   113  	_g_.m.throwing = 1
   114  	_g_.m.caughtsig = gp
   115  	startpanic()
   116  
   117  	if sig < uint32(len(sigtable)) {
   118  		print(sigtable[sig].name, "\n")
   119  	} else {
   120  		print("Signal ", sig, "\n")
   121  	}
   122  
   123  	print("PC=", hex(c.pc()), "\n")
   124  	if _g_.m.lockedg != nil && _g_.m.ncgo > 0 && gp == _g_.m.g0 {
   125  		print("signal arrived during cgo execution\n")
   126  		gp = _g_.m.lockedg
   127  	}
   128  	print("\n")
   129  
   130  	var docrash bool
   131  	if gotraceback(&docrash) > 0 {
   132  		goroutineheader(gp)
   133  		tracebacktrap(uintptr(c.pc()), uintptr(c.sp()), uintptr(c.link()), gp)
   134  		tracebackothers(gp)
   135  		print("\n")
   136  		dumpregs(c)
   137  	}
   138  
   139  	if docrash {
   140  		crash()
   141  	}
   142  
   143  	exit(2)
   144  }