]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid debug prints of huge objects
authorAustin Clements <austin@google.com>
Fri, 18 Sep 2015 16:06:24 +0000 (12:06 -0400)
committerAustin Clements <austin@google.com>
Fri, 18 Sep 2015 22:23:18 +0000 (22:23 +0000)
Currently when the GC prints an object for debugging (e.g., for a
failed invalidptr or checkmark check), it dumps the entire object. To
avoid inundating the user with output for really large objects, limit
this to printing just the first 128 words (which are most likely to be
useful in identifying the type of an object) and the 32 words around
the problematic field.

Change-Id: Id94a5c9d8162f8bd9b2a63bf0b1bfb0adde83c68
Reviewed-on: https://go-review.googlesource.com/14764
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/mgcmark.go

index eb47e0918712ec9deba7e20156539595312bcea6..bdbde65d14c10705fce1e15655f720bda8242280 100644 (file)
@@ -823,13 +823,28 @@ func gcDumpObject(label string, obj, off uintptr) {
                return
        }
        print(" s.start*_PageSize=", hex(s.start*_PageSize), " s.limit=", hex(s.limit), " s.sizeclass=", s.sizeclass, " s.elemsize=", s.elemsize, "\n")
+       skipped := false
        for i := uintptr(0); i < s.elemsize; i += ptrSize {
+               // For big objects, just print the beginning (because
+               // that usually hints at the object's type) and the
+               // fields around off.
+               if !(i < 128*ptrSize || off-16*ptrSize < i && i < off+16*ptrSize) {
+                       skipped = true
+                       continue
+               }
+               if skipped {
+                       print(" ...\n")
+                       skipped = false
+               }
                print(" *(", label, "+", i, ") = ", hex(*(*uintptr)(unsafe.Pointer(obj + uintptr(i)))))
                if i == off {
                        print(" <==")
                }
                print("\n")
        }
+       if skipped {
+               print(" ...\n")
+       }
 }
 
 // If gcBlackenPromptly is true we are in the second mark phase phase so we allocate black.