Commit a8c5e87b authored by Russ Cox's avatar Russ Cox

runtime: fix Stack

Fixes #8626.

LGTM=bradfitz
R=golang-codereviews
CC=bradfitz, golang-codereviews, iant, r
https://golang.org/cl/137050043
parent 548d0805
...@@ -584,13 +584,13 @@ func Stack(buf []byte, all bool) int { ...@@ -584,13 +584,13 @@ func Stack(buf []byte, all bool) int {
n := 0 n := 0
if len(buf) > 0 { if len(buf) > 0 {
gp.writebuf = buf gp.writebuf = buf[0:0:len(buf)]
goroutineheader(gp) goroutineheader(gp)
traceback(pc, sp, 0, gp) traceback(pc, sp, 0, gp)
if all { if all {
tracebackothers(gp) tracebackothers(gp)
} }
n = len(buf) - len(gp.writebuf) n = len(gp.writebuf)
gp.writebuf = nil gp.writebuf = nil
} }
......
...@@ -6,6 +6,7 @@ package runtime_test ...@@ -6,6 +6,7 @@ package runtime_test
import ( import (
. "runtime" . "runtime"
"strings"
"sync" "sync"
"testing" "testing"
"time" "time"
...@@ -331,3 +332,12 @@ func TestStackCache(t *testing.T) { ...@@ -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 \"")
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment