From e8de596f04d0ea7fb6fb68b036760bf088a9c6c2 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 20 Nov 2020 17:32:46 -0500 Subject: runtime: use inlined function name for traceback elision Currently, gentraceback decides which frames to print or elide when unwinding inlined frames using only the name of the outermost function. If the outermost function should be elided, then inlined functions will also be elided, even if they shouldn't be. This happens in practice in at least one situation. As of CL 258938, exported Go functions (and functions they call) can now be inlined into the generated _cgoexp_HASH_FN function. The runtime elides _cgoexp_HASH_FN from tracebacks because it doesn't contain a ".". Because of this bug, it also elides anything that was inlined into it. This CL fixes this by synthesizing a funcInfo for the inlined functions to pass to showframe. Fixes #42754. Change-Id: Ie6c663a4a1ac7f0d4beb1aa60bc26fc8cddd0f9d Reviewed-on: https://go-review.googlesource.com/c/go/+/272131 Trust: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Go Bot Reviewed-by: Cherry Zhang --- src/runtime/testdata/testprogcgo/traceback.go | 21 +++++++++++++++++++++ src/runtime/testdata/testprogcgo/traceback_c.c | 11 +++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src/runtime/testdata') diff --git a/src/runtime/testdata/testprogcgo/traceback.go b/src/runtime/testdata/testprogcgo/traceback.go index 03de894c89..e2d7599131 100644 --- a/src/runtime/testdata/testprogcgo/traceback.go +++ b/src/runtime/testdata/testprogcgo/traceback.go @@ -12,6 +12,7 @@ package main #cgo CFLAGS: -g -O0 // Defined in traceback_c.c. +extern int crashInGo; int tracebackF1(void); void cgoTraceback(void* parg); void cgoSymbolizer(void* parg); @@ -25,9 +26,29 @@ import ( func init() { register("CrashTraceback", CrashTraceback) + register("CrashTracebackGo", CrashTracebackGo) } func CrashTraceback() { runtime.SetCgoTraceback(0, unsafe.Pointer(C.cgoTraceback), nil, unsafe.Pointer(C.cgoSymbolizer)) C.tracebackF1() } + +func CrashTracebackGo() { + C.crashInGo = 1 + CrashTraceback() +} + +//export h1 +func h1() { + h2() +} + +func h2() { + h3() +} + +func h3() { + var x *int + *x = 0 +} diff --git a/src/runtime/testdata/testprogcgo/traceback_c.c b/src/runtime/testdata/testprogcgo/traceback_c.c index 54f44e11fc..56eda8fa8c 100644 --- a/src/runtime/testdata/testprogcgo/traceback_c.c +++ b/src/runtime/testdata/testprogcgo/traceback_c.c @@ -2,14 +2,21 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// The C definitions for traceback.go. +// The C definitions for traceback.go. That file uses //export so +// it can't put function definitions in the "C" import comment. #include char *p; +int crashInGo; +extern void h1(void); + int tracebackF3(void) { - *p = 0; + if (crashInGo) + h1(); + else + *p = 0; return 0; } -- cgit v1.3