-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: runtime.Caller() => "<autogenerated>" #16723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The interface call calls a wrapper which calls the direct call. The wrapper is auto-generated. Whether you consider the wrapper the "actual caller" depends on your point of view I guess. You can avoid the wrappers by defining the methods on *fooMether instead of fooMether. https://play.golang.org/p/_9UqleNykz I'm not sure what to do about this in the mean time. We'll have to look at callers again when we look at non-leaf inlining this winter. Maybe then would be a good time to revisit the behavior of runtime.Caller with respect to eliding autogenerated wrappers. /cc @aclements |
CL https://golang.org/cl/45411 mentions this issue. |
CL https://golang.org/cl/45412 mentions this issue. |
Bumping to Go 1.10 since this isn't a regression and there's some concern that this may affect code that's already compensating for this. The general consensus is that this should be fixed, however, so that the traceback APIs reflect the programmer's model of the stack rather than the implementation's model (like how the skip parameter now expands out inlined frames to match the programmer's model). Early in the 1.10 cycle we should put in something like the CLs I posted above. |
panicwrap currently uses runtime.Callers and runtime.CallersFrames to find the name of its caller. Simplify this by using getcallerpc. This will be important for #16723, since to fix that we're going to make CallersFrames skip the wrapper method, which is exactly what panicwrap needs to see. Change-Id: Icb0776d399966e31595f3ee44f980290827e32a6 Reviewed-on: https://go-review.googlesource.com/45411 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
I was playing with a method that wants to print the file:line of the caller.
runtime.Caller(1)
seems like it should do the trick, but I get ':2'. If I callruntime.Caller(2)
instead it seems to work, but I am reluctant to depend on that.It looks like this has to do with being an interface method: https://play.golang.org/p/I5XPdWR_O0
Is there a generic way to get the actual caller, safely, in all cases?
go version
)?go version go1.6.1 linux/amd64
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/thockin/src/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
The text was updated successfully, but these errors were encountered: