diff options
author | Russ Cox <rsc@golang.org> | 2014-10-29 15:14:04 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-10-29 15:14:04 -0400 |
commit | 8db71d4ee89a505c375b550eb8fb8cc33bbabc03 (patch) | |
tree | 628fd1319bb48de9bae37c9502f4422a8250db9f | |
parent | 799da9cee79e7ee89156ddc3c8bea44fdf1ac252 (diff) | |
download | go-8db71d4ee89a505c375b550eb8fb8cc33bbabc03.tar.gz go-8db71d4ee89a505c375b550eb8fb8cc33bbabc03.zip |
runtime: update comment for Callers
Attempt to clear up confusion about how to turn
the PCs reported by Callers into the file and line
number people actually want.
Fixes #7690.
LGTM=r, chris.cs.guy
R=r, chris.cs.guy
CC=golang-codereviews
https://golang.org/cl/163550043
-rw-r--r-- | src/runtime/extern.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/runtime/extern.go b/src/runtime/extern.go index 1b8052bb56..6cc5df810c 100644 --- a/src/runtime/extern.go +++ b/src/runtime/extern.go @@ -117,11 +117,20 @@ func Caller(skip int) (pc uintptr, file string, line int, ok bool) { return } -// Callers fills the slice pc with the program counters of function invocations +// Callers fills the slice pc with the return program counters of function invocations // on the calling goroutine's stack. The argument skip is the number of stack frames // to skip before recording in pc, with 0 identifying the frame for Callers itself and // 1 identifying the caller of Callers. // It returns the number of entries written to pc. +// +// Note that since each slice entry pc[i] is a return program counter, +// looking up the file and line for pc[i] (for example, using (*Func).FileLine) +// will return the file and line number of the instruction immediately +// following the call. +// To look up the file and line number of the call itself, use pc[i]-1. +// As an exception to this rule, if pc[i-1] corresponds to the function +// runtime.sigpanic, then pc[i] is the program counter of a faulting +// instruction and should be used without any subtraction. func Callers(skip int, pc []uintptr) int { // runtime.callers uses pc.array==nil as a signal // to print a stack trace. Pick off 0-length pc here |