github.com/newrelic/go-agent@v3.26.0+incompatible/internal/stack_frame.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  // +build go1.7
     5  
     6  package internal
     7  
     8  import "runtime"
     9  
    10  func (st StackTrace) frames() []stacktraceFrame {
    11  	if len(st) == 0 {
    12  		return nil
    13  	}
    14  	frames := runtime.CallersFrames(st) // CallersFrames is only available in Go 1.7+
    15  	fs := make([]stacktraceFrame, 0, maxStackTraceFrames)
    16  	var frame runtime.Frame
    17  	more := true
    18  	for more {
    19  		frame, more = frames.Next()
    20  		fs = append(fs, stacktraceFrame{
    21  			Name: frame.Function,
    22  			File: frame.File,
    23  			Line: int64(frame.Line),
    24  		})
    25  	}
    26  	return fs
    27  }