Skip to content

Commit 0f25102

Browse files
committed
runtime: print more information on stack overflow
Print the current SP and (old) stack bounds when the stack grows too large. This helps to identify the problem: whether a large stack is used, or something else goes wrong. For #35470. Change-Id: I34a4064d5c7280978391d835e171b90d06f87222 Reviewed-on: https://go-review.googlesource.com/c/go/+/207351 Reviewed-by: Emmanuel Odeke <[email protected]>
1 parent b2482e4 commit 0f25102

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/runtime/crash_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,23 @@ func TestGoexitDeadlock(t *testing.T) {
204204

205205
func TestStackOverflow(t *testing.T) {
206206
output := runTestProg(t, "testprog", "StackOverflow")
207-
want := "runtime: goroutine stack exceeds 1474560-byte limit\nfatal error: stack overflow"
208-
if !strings.HasPrefix(output, want) {
209-
t.Fatalf("output does not start with %q:\n%s", want, output)
207+
want := []string{
208+
"runtime: goroutine stack exceeds 1474560-byte limit\n",
209+
"fatal error: stack overflow",
210+
// information about the current SP and stack bounds
211+
"runtime: sp=",
212+
"stack=[",
213+
}
214+
if !strings.HasPrefix(output, want[0]) {
215+
t.Errorf("output does not start with %q", want[0])
216+
}
217+
for _, s := range want[1:] {
218+
if !strings.Contains(output, s) {
219+
t.Errorf("output does not contain %q", s)
220+
}
221+
}
222+
if t.Failed() {
223+
t.Logf("output:\n%s", output)
210224
}
211225
}
212226

src/runtime/stack.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ func newstack() {
10301030
newsize := oldsize * 2
10311031
if newsize > maxstacksize {
10321032
print("runtime: goroutine stack exceeds ", maxstacksize, "-byte limit\n")
1033+
print("runtime: sp=", hex(sp), " stack=[", hex(gp.stack.lo), ", ", hex(gp.stack.hi), "]\n")
10331034
throw("stack overflow")
10341035
}
10351036

0 commit comments

Comments
 (0)