Skip to content

Instantly share code, notes, and snippets.

@ezodude
Created November 27, 2020 13:39
Show Gist options
  • Save ezodude/6948f6f89c7aee9353bfea90789f4fdc to your computer and use it in GitHub Desktop.
Save ezodude/6948f6f89c7aee9353bfea90789f4fdc to your computer and use it in GitHub Desktop.
Trace Caller - great for debugging Golang code.
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())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment