aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/extern.go
diff options
context:
space:
mode:
authorDavid Lazar <lazard@golang.org>2017-04-10 14:33:07 -0400
committerDavid Lazar <lazard@golang.org>2017-04-18 19:56:30 +0000
commit0ea120a70c03c3c57778d6863188fdfee87cb0f9 (patch)
tree5128910473c16e0e068e81cc3dfd322219ba2ce4 /src/runtime/extern.go
parent5e15497b5682acfe5c761bc116c6f157efcc8042 (diff)
downloadgo-0ea120a70c03c3c57778d6863188fdfee87cb0f9.tar.gz
go-0ea120a70c03c3c57778d6863188fdfee87cb0f9.zip
runtime: skip logical frames in runtime.Caller
This rewrites runtime.Caller in terms of stackExpander, which already handles inlined frames and partially skipped frames. This also has the effect of making runtime.Caller understand cgo frames if there is a cgo symbolizer. Updates #19348. Change-Id: Icdf4df921aab5aa394d4d92e3becc4dd169c9a6e Reviewed-on: https://go-review.googlesource.com/40270 Run-TryBot: David Lazar <lazard@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/extern.go')
-rw-r--r--src/runtime/extern.go37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/runtime/extern.go b/src/runtime/extern.go
index 319d6495bd..2e67d4c3a9 100644
--- a/src/runtime/extern.go
+++ b/src/runtime/extern.go
@@ -166,33 +166,26 @@ import "runtime/internal/sys"
// program counter, file name, and line number within the file of the corresponding
// call. The boolean ok is false if it was not possible to recover the information.
func Caller(skip int) (pc uintptr, file string, line int, ok bool) {
- // Ask for two PCs: the one we were asked for
- // and what it called, so that we can see if it
- // "called" sigpanic.
- var rpc [2]uintptr
+ // Make room for three PCs: the one we were asked for,
+ // what it called, so that CallersFrames can see if it "called"
+ // sigpanic, and possibly a PC for skipPleaseUseCallersFrames.
+ var rpc [3]uintptr
if callers(1+skip-1, rpc[:]) < 2 {
return
}
- f := findfunc(rpc[1])
- if !f.valid() {
- // TODO(rsc): Probably a bug?
- // The C version said "have retpc at least"
- // but actually returned pc=0.
- ok = true
+ var stackExpander stackExpander
+ callers := stackExpander.init(rpc[:])
+ // We asked for one extra, so skip that one. If this is sigpanic,
+ // stepping over this frame will set up state in Frames so the
+ // next frame is correct.
+ callers, _, ok = stackExpander.next(callers)
+ if !ok {
return
}
- pc = rpc[1]
- xpc := pc
- g := findfunc(rpc[0])
- // All architectures turn faults into apparent calls to sigpanic.
- // If we see a call to sigpanic, we do not back up the PC to find
- // the line number of the call instruction, because there is no call.
- if xpc > f.entry && (!g.valid() || g.entry != funcPC(sigpanic)) {
- xpc--
- }
- file, line32 := funcline(f, xpc)
- line = int(line32)
- ok = true
+ _, frame, _ := stackExpander.next(callers)
+ pc = frame.PC
+ file = frame.File
+ line = frame.Line
return
}