runtime: print exported methods from the runtime in tracebacks

We currently suppress runtime frames in tracebacks, except for
exported functions.
This CL also prints exported methods of exported types
in tracebacks, for consistency.

Change-Id: Ic65e7611621f0b210de5ae0c02b9d0a044f39fd6
Reviewed-on: https://go-review.googlesource.com/c/go/+/507736
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
This commit is contained in:
Keith Randall 2023-07-03 13:49:26 -07:00
parent 65f056d07a
commit a0d477cb6d
2 changed files with 61 additions and 3 deletions

View file

@ -773,6 +773,16 @@ func init() {
// We expect to crash, so exit 0 to indicate failure.
os.Exit(0)
}
if os.Getenv("GO_TEST_RUNTIME_NPE_READMEMSTATS") == "1" {
runtime.ReadMemStats(nil)
os.Exit(0)
}
if os.Getenv("GO_TEST_RUNTIME_NPE_FUNCMETHOD") == "1" {
var f *runtime.Func
_ = f.Entry()
os.Exit(0)
}
}
func TestRuntimePanic(t *testing.T) {
@ -788,6 +798,32 @@ func TestRuntimePanic(t *testing.T) {
}
}
func TestTracebackRuntimeFunction(t *testing.T) {
testenv.MustHaveExec(t)
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestTracebackRuntimeFunction"))
cmd.Env = append(cmd.Env, "GO_TEST_RUNTIME_NPE_READMEMSTATS=1")
out, err := cmd.CombinedOutput()
t.Logf("%s", out)
if err == nil {
t.Error("child process did not fail")
} else if want := "runtime.ReadMemStats"; !bytes.Contains(out, []byte(want)) {
t.Errorf("output did not contain expected string %q", want)
}
}
func TestTracebackRuntimeMethod(t *testing.T) {
testenv.MustHaveExec(t)
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestTracebackRuntimeMethod"))
cmd.Env = append(cmd.Env, "GO_TEST_RUNTIME_NPE_FUNCMETHOD=1")
out, err := cmd.CombinedOutput()
t.Logf("%s", out)
if err == nil {
t.Error("child process did not fail")
} else if want := "runtime.(*Func).Entry"; !bytes.Contains(out, []byte(want)) {
t.Errorf("output did not contain expected string %q", want)
}
}
// Test that g0 stack overflows are handled gracefully.
func TestG0StackOverflow(t *testing.T) {
testenv.MustHaveExec(t)