runtime: expand inlining iteratively in CallersFrames
runtime: expand inlining iteratively in CallersFrames

Currently CallersFrames expands each PC to a slice of Frames and then
iteratively returns those Frames. However, this makes it very
difficult to avoid heap allocation: either the Frames slice will be
heap allocated, or, if it uses internal scratch space for small slices
(as it currently does), the Frames object itself has to be heap
allocated.

Fix this, at least in the common case, by expanding each PC
iteratively. We introduce a new pcExpander type that's responsible for
expanding a single PC. This maintains state from one Frame to the next
in the same PC. Frames then becomes a wrapper around this responsible
for feeding it the next PC when the pcExpander runs out of frames for
the current PC.

This makes it possible to stack-allocate a Frames object, which will
make it possible to use this API for PC expansion from within the
runtime itself.

Change-Id: I993463945ab574557cf1d6bedbe79ce7e9cbbdcd
Reviewed-on: https://go-review.googlesource.com/40434
Run-TryBot: Austin Clements <7ea35d812706d9213868749011af1ed4fa2f6aa0@google.com>
TryBot-Result: Gobot Gobot <66cb808b70d30c07676d5e946fee83fd561249e5@golang.org>
Reviewed-by: David Lazar <859c8a6d485c34c743019c2e216e6c66f2ebb470@golang.org>

nawawi/go,polyverse-security/go,Cofyc/go,josharian/go,golang/go,codestation/go,ImJasonH/go,akutz/go,polyverse-security/go,cloudflare/go,vsekhar/elastic-go,nawawi/go,Cofyc/go,josharian/go,vsekhar/elastic-go,vsekhar/elastic-go,cloudflare/go,nawawi/go,Cofyc/go,polyverse-security/go,CAFxX/go,codestation/go,golang/go,vsekhar/elastic-go,CAFxX/go,ImJasonH/go,golang/go,akutz/go,cloudflare/go,CAFxX/go,cloudflare/go,nawawi/go,codestation/go,CAFxX/go,akutz/go,ImJasonH/go,codestation/go,akutz/go,akutz/go,josharian/go,polyverse-security/go,cloudflare/go,derekmarcotte/go,golang/go,akutz/go,ImJasonH/go,codestation/go,Cofyc/go,polyverse-security/go,CAFxX/go,akutz/go,derekmarcotte/go,ImJasonH/go,cloudflare/go,codestation/go,derekmarcotte/go,josharian/go,Cofyc/go,ImJasonH/go,derekmarcotte/go,golang/go,josharian/go,golang/go,akutz/go,CAFxX/go,Cofyc/go,derekmarcotte/go,cloudflare/go,codestation/go,vsekhar/elastic-go,nawawi/go,derekmarcotte/go,golang/go,vsekhar/elastic-go,CAFxX/go,nawawi/go,nawawi/go,Cofyc/go,josharian/go,polyverse-security/go,Cofyc/go,derekmarcotte/go,vsekhar/elastic-go,CAFxX/go,ImJasonH/go,polyverse-security/go,josharian/go,nawawi/go,codestation/go,polyverse-security/go,christopher-henderson/Go,derekmarcotte/go,golang/go,josharian/go,ImJasonH/go,cloudflare/go,vsekhar/elastic-go