On Sat, Aug 6, 2016 at 10:08 AM, Carl Mastrangelo
<carl.mastrang...@gmail.com> wrote:
> TL;DR:  Is the uintptr slice returned from runtime.Callers always valid?
>
> Reading the docs* for runtime.Callers says: "Callers fills the slice pc with
> the return program counters of function invocations on the calling
> goroutine's stack. "  Does this imply that once the goroutine is gone, or
> all the functions have returned, the uintptrs could be pointing to garbage?
>
> I ask because I would like a cheap-ish stacktrace for some error handling
> code I am writing, and I don't want to turn the stack frame into a full
> string.  If I can capture the functions on the stack and maybe turn them
> into an error message later that would be ideal.

The pointers are always valid.  All executable code is created at
compilation time, and the function pointers returned by
runtime.Callers always point into executable code that is always
present.

(An exception would be if you used runtime.SetCgoTraceback to collect
a C function address that happens to be in a shared library that you
happened to dlclose.  But if you don't use SetCgoTraceback or you
don't dlopen and then dlclose C shared libraries, this won't be a
problem.)

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to