mirror of
https://github.com/golang/go
synced 2024-11-20 06:14:53 -07:00
1b49a86ece
The Go builders (and standard development cycle) for programs on iOS require running the programs under lldb. Unfortunately lldb intercepts SIGSEGV and will not give it back. https://llvm.org/bugs/show_bug.cgi?id=22868 We get around this by never letting lldb see the SIGSEGV. On darwin, Unix signals are emulated on top of mach exceptions. The debugger registers a task-level mach exception handler. We register a thread-level exception handler which acts as a faux signal handler. The thread-level handler gets precedence over the task-level handler, so we can turn the exception EXC_BAD_ACCESS into a panic before lldb can see it. Fixes #10043 Change-Id: I64d7c310dfa7ecf60eb1e59f094966520d473335 Reviewed-on: https://go-review.googlesource.com/7072 Reviewed-by: Minux Ma <minux@golang.org> Run-TryBot: David Crawshaw <crawshaw@golang.org>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
// Copyright 2014 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.
|
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
|
|
|
package runtime
|
|
|
|
func sigpanic() {
|
|
g := getg()
|
|
if !canpanic(g) {
|
|
throw("unexpected signal during runtime execution")
|
|
}
|
|
|
|
switch g.sig {
|
|
case _SIGBUS:
|
|
if g.sigcode0 == _BUS_ADRERR && g.sigcode1 < 0x1000 || g.paniconfault {
|
|
panicmem()
|
|
}
|
|
print("unexpected fault address ", hex(g.sigcode1), "\n")
|
|
throw("fault")
|
|
case _SIGSEGV:
|
|
if (g.sigcode0 == 0 || g.sigcode0 == _SEGV_MAPERR || g.sigcode0 == _SEGV_ACCERR) && g.sigcode1 < 0x1000 || g.paniconfault {
|
|
panicmem()
|
|
}
|
|
print("unexpected fault address ", hex(g.sigcode1), "\n")
|
|
throw("fault")
|
|
case _SIGFPE:
|
|
switch g.sigcode0 {
|
|
case _FPE_INTDIV:
|
|
panicdivide()
|
|
case _FPE_INTOVF:
|
|
panicoverflow()
|
|
}
|
|
panicfloat()
|
|
}
|
|
|
|
if g.sig >= uint32(len(sigtable)) {
|
|
// can't happen: we looked up g.sig in sigtable to decide to call sigpanic
|
|
throw("unexpected signal value")
|
|
}
|
|
panic(errorString(sigtable[g.sig].name))
|
|
}
|
|
|
|
// setsigsegv is used on darwin/arm{,64} to fake a segmentation fault.
|
|
//go:nosplit
|
|
func setsigsegv(pc uintptr) {
|
|
g := getg()
|
|
g.sig = _SIGSEGV
|
|
g.sigpc = pc
|
|
g.sigcode0 = _SEGV_MAPERR
|
|
g.sigcode1 = 0 // TODO: emulate si_addr
|
|
}
|