]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make gcDumpObject useful on stack frames
authorAustin Clements <austin@google.com>
Fri, 9 Sep 2016 14:22:10 +0000 (10:22 -0400)
committerAustin Clements <austin@google.com>
Mon, 3 Oct 2016 21:59:54 +0000 (21:59 +0000)
gcDumpObject is often used on a stack pointer (for example, when
checkmark finds an unmarked object on the stack), but since stack
spans don't have an elemsize, it doesn't print any of the memory from
the frame. Make it at least slightly more useful by printing
everything between obj and obj+off (inclusive). While we're here, also
print out the span state.

Change-Id: I51be064ea8791b4a365865bfdc7afa7b5aaecfbd
Reviewed-on: https://go-review.googlesource.com/30142
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/mgcmark.go
src/runtime/mheap.go

index 003073f42fd3f3f6227e01a5b82919ad6e3b3f2c..aa107ee65cdd01b9b4039c53874fa847814dc199 100644 (file)
@@ -1320,9 +1320,22 @@ func gcDumpObject(label string, obj, off uintptr) {
                print(" s=nil\n")
                return
        }
-       print(" s.base()=", hex(s.base()), " s.limit=", hex(s.limit), " s.sizeclass=", s.sizeclass, " s.elemsize=", s.elemsize, "\n")
+       print(" s.base()=", hex(s.base()), " s.limit=", hex(s.limit), " s.sizeclass=", s.sizeclass, " s.elemsize=", s.elemsize, " s.state=")
+       if 0 <= s.state && int(s.state) < len(mSpanStateNames) {
+               print(mSpanStateNames[s.state], "\n")
+       } else {
+               print("unknown(", s.state, ")\n")
+       }
+
        skipped := false
-       for i := uintptr(0); i < s.elemsize; i += sys.PtrSize {
+       size := s.elemsize
+       if s.state == _MSpanStack && size == 0 {
+               // We're printing something from a stack frame. We
+               // don't know how big it is, so just show up to an
+               // including off.
+               size = off + sys.PtrSize
+       }
+       for i := uintptr(0); i < size; i += sys.PtrSize {
                // For big objects, just print the beginning (because
                // that usually hints at the object's type) and the
                // fields around off.
index 808f1419465eebb7b123a162ce860873304b96c5..cc2de012fffb259d3f9913298673bd8474e79e61 100644 (file)
@@ -111,6 +111,15 @@ const (
        _MSpanDead
 )
 
+// mSpanStateNames are the names of the span states, indexed by
+// mSpanState.
+var mSpanStateNames = []string{
+       "_MSpanInUse",
+       "_MSpanStack",
+       "_MSpanFree",
+       "_MSpanDead",
+}
+
 // mSpanList heads a linked list of spans.
 //
 // Linked list structure is based on BSD's "tail queue" data structure.