diff options
author | Russ Cox <rsc@golang.org> | 2014-09-01 19:42:22 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-09-01 19:42:22 -0400 |
commit | b46dc044d2eca6d46156d92dbf64fc965192ca0b (patch) | |
tree | 6a94933165afa77d446a45c52abc75fdf331bf3b /src/pkg | |
parent | 2cc5c08e8f57708722fb9afe125d7534c04ad3f1 (diff) | |
download | go-b46dc044d2eca6d46156d92dbf64fc965192ca0b.tar.gz |
runtime: fix Stack
Fixes issue 8626.
LGTM=bradfitz
R=golang-codereviews
CC=bradfitz, golang-codereviews, iant, r
https://codereview.appspot.com/137050043
Diffstat (limited to 'src/pkg')
-rw-r--r-- | src/pkg/runtime/mprof.go | 4 | ||||
-rw-r--r-- | src/pkg/runtime/stack_test.go | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/pkg/runtime/mprof.go b/src/pkg/runtime/mprof.go index 8546a341b..1734fd847 100644 --- a/src/pkg/runtime/mprof.go +++ b/src/pkg/runtime/mprof.go @@ -584,13 +584,13 @@ func Stack(buf []byte, all bool) int { n := 0 if len(buf) > 0 { - gp.writebuf = buf + gp.writebuf = buf[0:0:len(buf)] goroutineheader(gp) traceback(pc, sp, 0, gp) if all { tracebackothers(gp) } - n = len(buf) - len(gp.writebuf) + n = len(gp.writebuf) gp.writebuf = nil } diff --git a/src/pkg/runtime/stack_test.go b/src/pkg/runtime/stack_test.go index 2877074f7..b3dcbd12a 100644 --- a/src/pkg/runtime/stack_test.go +++ b/src/pkg/runtime/stack_test.go @@ -6,6 +6,7 @@ package runtime_test import ( . "runtime" + "strings" "sync" "testing" "time" @@ -331,3 +332,12 @@ func TestStackCache(t *testing.T) { } } } + +func TestStackOutput(t *testing.T) { + b := make([]byte, 1024) + stk := string(b[:Stack(b, false)]) + if !strings.HasPrefix(stk, "goroutine ") { + t.Errorf("Stack (len %d):\n%s", len(stk), stk) + t.Errorf("Stack output should begin with \"goroutine \"") + } +} |