package main
import (
"fmt"
"runtime"
)
func main() {
for skip := 0; ; skip++ {
pc, file, line, ok := runtime.Caller(skip)
if !ok {
break
}
fmt.Printf("skip = %v, pc = %v, file = %v, line = %v\n", skip, pc, file, line)
}
}
输出:
skip = 0, pc = 4761622, file = C:/Go/mycode/20170508/1/h.go, line = 11
skip = 1, pc = 4366150, file = C:/Go/src/runtime/proc.go, line = 185
skip = 2, pc = 4513537, file = C:/Go/src/runtime/asm_amd64.s, line = 2197
有疑问加站长微信联系(非本文作者)