1 // Copyright 2017 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.
13 func ExampleFrames() {
15 // Ask runtime.Callers for up to 10 pcs, including runtime.Callers itself.
16 pc
:= make([]uintptr, 10)
17 n
:= runtime
.Callers(0, pc
)
19 // No pcs available. Stop now.
20 // This can happen if the first argument to runtime.Callers is large.
24 pc
= pc
[:n
] // pass only valid pcs to runtime.CallersFrames
25 frames
:= runtime
.CallersFrames(pc
)
27 // Loop to get frames.
28 // A fixed number of pcs can expand to an indefinite number of Frames.
30 frame
, more
:= frames
.Next()
31 // To keep this example's output stable
32 // even if there are changes in the testing package,
33 // stop unwinding when we leave package runtime.
34 if !strings
.Contains(frame
.File
, "runtime/") {
37 fmt
.Printf("- more:%v | %s\n", more
, frame
.Function
)
49 // - more:true | runtime.Callers
50 // - more:true | runtime_test.ExampleFrames.func1
51 // - more:true | runtime_test.ExampleFrames.func2
52 // - more:true | runtime_test.ExampleFrames.func3
53 // - more:true | runtime_test.ExampleFrames