From 590f47558d875691190b059f2696d2f9d0bf9c66 Mon Sep 17 00:00:00 2001
From: Austin Clements
+ Users of
+ runtime.Callers
+ should avoid directly inspecting the resulting PC slice and instead use
+ runtime.CallersFrames
+ to get a complete view of the call stack, or
+ runtime.Caller
+ to get information about a single caller.
+ This is because an individual element of the PC slice cannot account
+ for inlined frames or other nuances of the call stack.
+
+ Specifically, code that directly iterates over the PC slice and uses
+ functions such as
+ runtime.FuncForPC
+ to resolve each PC individually will miss inlined frames.
+ To get a complete view of the stack, such code should instead use
+ CallersFrames
.
+ Likewise, code should not assume that the length returned by
+ Callers
is any indication of the call depth.
+ It should instead count the number of frames returned by
+ CallersFrames
.
+
+ Code that queries a single caller at a specific depth should use
+ Caller
rather than passing a slice of length 1 to
+ Callers
.
+
+ runtime.CallersFrames
+ has been available since Go 1.7, so code can be updated prior to
+ upgrading to Go 1.9.
+