From 3c0fee10dbe82771dcaa956a95bdfabdced5fff7 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 14 Jan 2015 11:09:50 -0500 Subject: cmd/6g, liblink, runtime: support saving base pointers This adds a "framepointer" GOEXPERIMENT that that makes the amd64 toolchain maintain base pointer chains in the same way that gcc -fno-omit-frame-pointer does. Go doesn't use these saved base pointers, but this does enable external tools like Linux perf and VTune to unwind Go stacks when collecting system-wide profiles. This requires support in the compilers to not clobber BP, support in liblink for generating the BP-saving function prologue and unwinding epilogue, and support in the runtime to save BPs across preemption, to skip saved BPs during stack unwinding and, and to adjust saved BPs during stack moving. As with other GOEXPERIMENTs, everything from the toolchain to the runtime must be compiled with this experiment enabled. To do this, run make.bash (or all.bash) with GOEXPERIMENT=framepointer. Change-Id: I4024853beefb9539949e5ca381adfdd9cfada544 Reviewed-on: https://go-review.googlesource.com/2992 Reviewed-by: Russ Cox --- src/runtime/traceback.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/runtime/traceback.go') diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index 499256f42d..c813453399 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -232,6 +232,12 @@ func gentraceback(pc0 uintptr, sp0 uintptr, lr0 uintptr, gp *g, skip int, pcbuf frame.varp -= regSize } + // If framepointer_enabled and there's a frame, then + // there's a saved bp here. + if GOARCH == "amd64" && frame.varp > frame.sp && framepointer_enabled { + frame.varp -= ptrSize + } + // Derive size of arguments. // Most functions have a fixed-size argument block, // so we can use metadata about the function f. -- cgit v1.3-5-g9baa