frames_go17.go 627 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2021 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.
  4. //go:build go1.7
  5. // +build go1.7
  6. package pkgbits
  7. import "runtime"
  8. // walkFrames calls visit for each call frame represented by pcs.
  9. //
  10. // pcs should be a slice of PCs, as returned by runtime.Callers.
  11. func walkFrames(pcs []uintptr, visit frameVisitor) {
  12. if len(pcs) == 0 {
  13. return
  14. }
  15. frames := runtime.CallersFrames(pcs)
  16. for {
  17. frame, more := frames.Next()
  18. visit(frame.File, frame.Line, frame.Function, frame.PC-frame.Entry)
  19. if !more {
  20. return
  21. }
  22. }
  23. }