]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: print more information on stack overflow
authorCherry Zhang <cherryyz@google.com>
Fri, 15 Nov 2019 02:34:35 +0000 (21:34 -0500)
committerCherry Zhang <cherryyz@google.com>
Wed, 27 Nov 2019 01:30:32 +0000 (01:30 +0000)
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 <emm.odeke@gmail.com>
src/runtime/crash_test.go
src/runtime/stack.go

index 6c3127fa7558a8c69f8895a0c8e3f13d835cd309..5333b6064635cdc982c778657afcd98825ae9b36 100644 (file)
@@ -204,9 +204,23 @@ func TestGoexitDeadlock(t *testing.T) {
 
 func TestStackOverflow(t *testing.T) {
        output := runTestProg(t, "testprog", "StackOverflow")
-       want := "runtime: goroutine stack exceeds 1474560-byte limit\nfatal error: stack overflow"
-       if !strings.HasPrefix(output, want) {
-               t.Fatalf("output does not start with %q:\n%s", want, output)
+       want := []string{
+               "runtime: goroutine stack exceeds 1474560-byte limit\n",
+               "fatal error: stack overflow",
+               // information about the current SP and stack bounds
+               "runtime: sp=",
+               "stack=[",
+       }
+       if !strings.HasPrefix(output, want[0]) {
+               t.Errorf("output does not start with %q", want[0])
+       }
+       for _, s := range want[1:] {
+               if !strings.Contains(output, s) {
+                       t.Errorf("output does not contain %q", s)
+               }
+       }
+       if t.Failed() {
+               t.Logf("output:\n%s", output)
        }
 }
 
index 84fbd33329613f88a7f0b05200c8d4668352afc9..ebbe3e013de5eb524307a44813b538b7ce0bfddb 100644 (file)
@@ -1030,6 +1030,7 @@ func newstack() {
        newsize := oldsize * 2
        if newsize > maxstacksize {
                print("runtime: goroutine stack exceeds ", maxstacksize, "-byte limit\n")
+               print("runtime: sp=", hex(sp), " stack=[", hex(gp.stack.lo), ", ", hex(gp.stack.hi), "]\n")
                throw("stack overflow")
        }