1
// Copyright 2009 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.
5
// +build darwin freebsd linux netbsd openbsd
8
#include "defs_GOOS_GOARCH.h"
10
#include "signal_GOOS_GOARCH.h"
11
#include "signals_GOOS.h"
14
runtime·dumpregs(Siginfo *info, void *ctxt)
19
runtime·printf("trap %x\n", SIG_TRAP(info, ctxt));
20
runtime·printf("error %x\n", SIG_ERROR(info, ctxt));
21
runtime·printf("oldmask %x\n", SIG_OLDMASK(info, ctxt));
22
runtime·printf("r0 %x\n", SIG_R0(info, ctxt));
23
runtime·printf("r1 %x\n", SIG_R1(info, ctxt));
24
runtime·printf("r2 %x\n", SIG_R2(info, ctxt));
25
runtime·printf("r3 %x\n", SIG_R3(info, ctxt));
26
runtime·printf("r4 %x\n", SIG_R4(info, ctxt));
27
runtime·printf("r5 %x\n", SIG_R5(info, ctxt));
28
runtime·printf("r6 %x\n", SIG_R6(info, ctxt));
29
runtime·printf("r7 %x\n", SIG_R7(info, ctxt));
30
runtime·printf("r8 %x\n", SIG_R8(info, ctxt));
31
runtime·printf("r9 %x\n", SIG_R9(info, ctxt));
32
runtime·printf("r10 %x\n", SIG_R10(info, ctxt));
33
runtime·printf("fp %x\n", SIG_FP(info, ctxt));
34
runtime·printf("ip %x\n", SIG_IP(info, ctxt));
35
runtime·printf("sp %x\n", SIG_SP(info, ctxt));
36
runtime·printf("lr %x\n", SIG_LR(info, ctxt));
37
runtime·printf("pc %x\n", SIG_PC(info, ctxt));
38
runtime·printf("cpsr %x\n", SIG_CPSR(info, ctxt));
39
runtime·printf("fault %x\n", SIG_FAULT(info, ctxt));
43
runtime·sighandler(int32 sig, Siginfo *info, void *ctxt, G *gp)
49
if(gp != m->g0 && gp != m->gsignal)
50
runtime·sigprof((uint8*)SIG_PC(info, ctxt), (uint8*)SIG_SP(info, ctxt), (uint8*)SIG_LR(info, ctxt), gp);
54
t = &runtime·sigtab[sig];
55
if(SIG_CODE0(info, ctxt) != SI_USER && (t->flags & SigPanic)) {
56
if(gp == nil || gp == m->g0)
59
// Make it look like a call to the signal func.
60
// Have to pass arguments out of band since
61
// augmenting the stack frame would break
62
// the unwinding code.
64
gp->sigcode0 = SIG_CODE0(info, ctxt);
65
gp->sigcode1 = SIG_FAULT(info, ctxt);
66
gp->sigpc = SIG_PC(info, ctxt);
68
// We arrange lr, and pc to pretend the panicking
69
// function calls sigpanic directly.
70
// Always save LR to stack so that panics in leaf
71
// functions are correctly handled. This smashes
72
// the stack frame but we're not going back there
74
SIG_SP(info, ctxt) -= 4;
75
*(uint32*)SIG_SP(info, ctxt) = SIG_LR(info, ctxt);
76
// Don't bother saving PC if it's zero, which is
77
// probably a call to a nil func: the old link register
78
// is more useful in the stack trace.
80
SIG_LR(info, ctxt) = gp->sigpc;
81
// In case we are panicking from external C code
82
SIG_R10(info, ctxt) = (uintptr)gp;
83
SIG_R9(info, ctxt) = (uintptr)m;
84
SIG_PC(info, ctxt) = (uintptr)runtime·sigpanic;
88
if(SIG_CODE0(info, ctxt) == SI_USER || (t->flags & SigNotify))
89
if(runtime·sigsend(sig))
91
if(t->flags & SigKill)
93
if(!(t->flags & SigThrow))
97
if(runtime·panicking) // traceback already printed
99
runtime·panicking = 1;
101
if(sig < 0 || sig >= NSIG)
102
runtime·printf("Signal %d\n", sig);
104
runtime·printf("%s\n", runtime·sigtab[sig].name);
106
runtime·printf("PC=%x\n", SIG_PC(info, ctxt));
107
if(m->lockedg != nil && m->ncgo > 0 && gp == m->g0) {
108
runtime·printf("signal arrived during cgo execution\n");
111
runtime·printf("\n");
113
if(runtime·gotraceback(&crash)){
114
runtime·traceback((void*)SIG_PC(info, ctxt), (void*)SIG_SP(info, ctxt), (void*)SIG_LR(info, ctxt), gp);
115
runtime·tracebackothers(gp);
116
runtime·printf("\n");
117
runtime·dumpregs(info, ctxt);