This commit is contained in:
aozhiwei 2024-04-09 15:22:30 +08:00
parent 67c14c72ff
commit 01573c9947

View File

@ -236,14 +236,15 @@ func PrintCallStack() {
func GetCallStack() string {
// 获取当前函数的调用者信息
pc, file, line, ok := runtime.Caller(1)
//pc, file, line, ok := runtime.Caller(1)
_, _, _, ok := runtime.Caller(1)
if !ok {
fmt.Println("runtime.Caller error")
return ""
}
funcName := runtime.FuncForPC(pc).Name()
fmt.Printf("Function: %s\nFile: %s\nLine: %d\n", funcName, file, line)
//funcName := runtime.FuncForPC(pc).Name()
//fmt.Printf("Function: %s\nFile: %s\nLine: %d\n", funcName, file, line)
// 使用Stack打印完整的调用栈信息可以用于debug
buf := make([]byte, 1024)