为了跟踪目的,我想打印出当前的函数名,比如gcc中的__FUNCTION__宏。
@H_403_1@所以当我有一个功能
func foo () { trace() }@H_403_1@它会自动打印输入foo()…或类似的东西。
套餐
runtime是你的朋友:
func trace() { pc := make([]uintptr,10) // at least 1 entry needed runtime.Callers(2,pc) f := runtime.FuncForPC(pc[0]) file,line := f.FileLine(pc[0]) fmt.Printf("%s:%d %s\n",file,line,f.Name()) }