Last active
September 20, 2018 20:15
-
-
Save jeanbza/d53d4283c7217982426eb5ac56dd0800 to your computer and use it in GitHub Desktop.
callers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func MyCallers() []string { | |
// we get the callers as uintptrs | |
fpcs := make([]uintptr, 1024) | |
n := runtime.Callers(-1, fpcs) | |
if n == 0 { | |
return []string{"I don't know your caller! What the heck.."} | |
} | |
var callers []string | |
for _, c := range fpcs { | |
// get the info of the actual function that's in the pointer | |
fun := runtime.FuncForPC(c-1) | |
if fun == nil { | |
// we're done | |
break | |
} | |
callers = append(callers, fun.Name()+"\n") | |
} | |
return callers | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment