mirror of
https://github.com/golang/go
synced 2024-11-23 10:00:03 -07:00
69c2c56453
Work involved in getting a stack trace is divided between runtime.Callers and runtime.CallersFrames. Before this CL, runtime.Callers returns a pc per runtime frame. runtime.CallersFrames is responsible for expanding a runtime frame into potentially multiple user frames. After this CL, runtime.Callers returns a pc per user frame. runtime.CallersFrames just maps those to user frame info. Entries in the result of runtime.Callers are now pcs of the calls (or of the inline marks), not of the instruction just after the call. Fixes #29007 Fixes #28640 Update #26320 Change-Id: I1c9567596ff73dc73271311005097a9188c3406f Reviewed-on: https://go-review.googlesource.com/c/152537 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
39 lines
586 B
Go
39 lines
586 B
Go
// run
|
|
|
|
// Copyright 2013 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.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
f()
|
|
panic("deferred function not run")
|
|
}
|
|
|
|
var x = 1
|
|
|
|
func f() {
|
|
if x == 0 {
|
|
return
|
|
}
|
|
defer g()
|
|
panic("panic")
|
|
}
|
|
|
|
func g() {
|
|
_, file, line, _ := runtime.Caller(2)
|
|
if !strings.HasSuffix(file, "issue5856.go") || line != 28 {
|
|
fmt.Printf("BUG: defer called from %s:%d, want issue5856.go:28\n", file, line)
|
|
os.Exit(1)
|
|
}
|
|
os.Exit(0)
|
|
}
|