Fixes #8626.
LGTM=bradfitz
R=golang-codereviews
CC=bradfitz, golang-codereviews, iant, r
https://golang.org/cl/
137050043
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
}
import (
. "runtime"
+ "strings"
"sync"
"testing"
"time"
}
}
}
+
+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 \"")
+ }
+}