diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-01-07 20:12:39 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-01-07 20:12:39 +0000 |
commit | 575eb8f58b06657c9cadfe6f7ddfd9e530fe5dea (patch) | |
tree | ce0dcd8fecef8174761dfaa26962f241b47d9606 /libgo/go | |
parent | 419af57c134f3b068530ea51179c220e52623067 (diff) | |
download | gcc-575eb8f58b06657c9cadfe6f7ddfd9e530fe5dea.zip gcc-575eb8f58b06657c9cadfe6f7ddfd9e530fe5dea.tar.gz gcc-575eb8f58b06657c9cadfe6f7ddfd9e530fe5dea.tar.bz2 |
runtime: in getTraceback, set gp->m before gogo
Currently, when collecting a traceback for another goroutine,
getTraceback calls gogo(gp) switching to gp, which will resume in
mcall, which will call gtraceback, which will set up gp->m. There
is a gap between setting the current running g to gp and setting
gp->m. If a profiling signal arrives in between, sigtramp will
see a non-nil gp with a nil m, and will seg fault. Fix this by
setting up gp->m first.
Fixes golang/go#29448.
Reviewed-on: https://go-review.googlesource.com/c/156038
From-SVN: r267658
Diffstat (limited to 'libgo/go')
-rw-r--r-- | libgo/go/runtime/pprof/pprof_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libgo/go/runtime/pprof/pprof_test.go b/libgo/go/runtime/pprof/pprof_test.go index 74a7777..fd05a04 100644 --- a/libgo/go/runtime/pprof/pprof_test.go +++ b/libgo/go/runtime/pprof/pprof_test.go @@ -946,3 +946,38 @@ func TestAtomicLoadStore64(t *testing.T) { atomic.StoreUint64(&flag, 1) <-done } + +func TestTracebackAll(t *testing.T) { + // With gccgo, if a profiling signal arrives at the wrong time + // during traceback, it may crash or hang. See issue #29448. + f, err := ioutil.TempFile("", "proftraceback") + if err != nil { + t.Fatalf("TempFile: %v", err) + } + defer os.Remove(f.Name()) + defer f.Close() + + if err := StartCPUProfile(f); err != nil { + t.Fatal(err) + } + defer StopCPUProfile() + + ch := make(chan int) + defer close(ch) + + count := 10 + for i := 0; i < count; i++ { + go func() { + <-ch // block + }() + } + + N := 10000 + if testing.Short() { + N = 500 + } + buf := make([]byte, 10*1024) + for i := 0; i < N; i++ { + runtime.Stack(buf, true) + } +} |