1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // Frames may be used to get function/file/line information for a
8 // slice of PC values returned by Callers.
12 // The last PC we saw.
15 // The number of times we've seen last.
19 // Frame is the information returned by Frames for each call frame.
21 // Program counter for this frame; multiple frames may have
25 // Func for this frame; may be nil for non-Go code or fully
29 // Function name, file name, and line number for this call frame.
30 // May be the empty string or zero if not known.
31 // If Func is not nil then Function == Func.Name().
36 // Entry point for the function; may be zero if not known.
37 // If Func is not nil then Entry == Func.Entry().
41 // CallersFrames takes a slice of PC values returned by Callers and
42 // prepares to return function/file/line information.
43 // Do not change the slice until you are done with the Frames.
44 func CallersFrames(callers
[]uintptr) *Frames
{
45 return &Frames
{callers
: callers
}
48 // Next returns frame information for the next caller.
49 // If more is false, there are no more callers (the Frame value is valid).
50 func (ci
*Frames
) Next() (frame Frame
, more
bool) {
51 if len(ci
.callers
) == 0 {
56 ci
.callers
= ci
.callers
[1:]
66 more
= len(ci
.callers
) > 0
68 f
, file
, line
:= funcframe(pc
, i
)
93 // NOTE: Func does not expose the actual unexported fields, because we return *Func
94 // values to users, and we want to keep them from being able to overwrite the data
95 // with (say) *f = Func{}.
96 // All code operating on a *Func must call raw to get the *_func instead.
98 // A Func represents a Go function in the running binary.
100 opaque
struct{} // unexported field to disallow conversions
103 // FuncForPC returns a *Func describing the function that contains the
104 // given program counter address, or else nil.
105 func FuncForPC(pc
uintptr) *Func
107 // Name returns the name of the function.
108 func (f
*Func
) Name() string {
109 return funcname_go(f
)
112 // Entry returns the entry address of the function.
113 func (f
*Func
) Entry() uintptr {
114 return funcentry_go(f
)
117 // FileLine returns the file name and line number of the
118 // source code corresponding to the program counter pc.
119 // The result will not be accurate if pc is not a program
121 func (f
*Func
) FileLine(pc
uintptr) (file
string, line
int) {
122 return funcline_go(f
, pc
)
125 // implemented in symtab.c
126 func funcline_go(*Func
, uintptr) (string, int)
127 func funcname_go(*Func
) string
128 func funcentry_go(*Func
) uintptr
129 func funcframe(uintptr, int) (*Func
, string, int)