20 lines
402 B
Go
20 lines
402 B
Go
// call-stack.go
|
|
package golang
|
|
|
|
import (
|
|
"runtime"
|
|
)
|
|
|
|
func Trace(upStack int) (source string, line int, function string) {
|
|
pc := make([]uintptr, 15)
|
|
n := runtime.Callers(upStack, pc)
|
|
frames := runtime.CallersFrames(pc[:n])
|
|
frame, _ := frames.Next()
|
|
source = frame.File
|
|
line = frame.Line
|
|
function = frame.Function
|
|
// fmt.Printf("%s:%d %s\n", frame.File, frame.Line, frame.Function)
|
|
return
|
|
}
|
|
|