mirror of
https://github.com/golang/go
synced 2024-11-23 01:40:03 -07:00
19916e453e
For #11656. Change-Id: I8365d33a15419bd0e54f71182ad0994e41650264 Reviewed-on: https://go-review.googlesource.com/12248 Reviewed-by: Russ Cox <rsc@golang.org>
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
// run
|
|
|
|
// Copyright 2015 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.
|
|
|
|
// darwin/386 seems to mangle the PC and SP before
|
|
// it manages to invoke the signal handler, so this test fails there.
|
|
// +build !darwin !386
|
|
//
|
|
// openbsd/386 and plan9/386 don't work, not sure why.
|
|
// +build !openbsd !386
|
|
// +build !plan9 !386
|
|
//
|
|
// windows doesn't work, because Windows exception handling
|
|
// delivers signals based on the current PC, and that current PC
|
|
// doesn't go into the Go runtime.
|
|
// +build !windows
|
|
//
|
|
// arm64 gets "illegal instruction" (why is the data executable?)
|
|
// and is unable to do the traceback correctly (why?).
|
|
// +build !arm64
|
|
|
|
package main
|
|
|
|
import (
|
|
"runtime"
|
|
"runtime/debug"
|
|
"unsafe"
|
|
)
|
|
|
|
func main() {
|
|
debug.SetPanicOnFault(true)
|
|
defer func() {
|
|
if err := recover(); err == nil {
|
|
panic("not panicking")
|
|
}
|
|
pc, _, _, _ := runtime.Caller(10)
|
|
f := runtime.FuncForPC(pc)
|
|
if f == nil || f.Name() != "main.f" {
|
|
if f == nil {
|
|
println("no func for ", unsafe.Pointer(pc))
|
|
} else {
|
|
println("found func:", f.Name())
|
|
}
|
|
panic("cannot find main.f on stack")
|
|
}
|
|
}()
|
|
f(20)
|
|
}
|
|
|
|
func f(n int) {
|
|
if n > 0 {
|
|
f(n - 1)
|
|
}
|
|
var f struct {
|
|
x uintptr
|
|
}
|
|
f.x = uintptr(unsafe.Pointer(&f))
|
|
fn := *(*func())(unsafe.Pointer(&f))
|
|
fn()
|
|
}
|