From e0c9d04aec958b4b4f9315037a49c4459424a728 Mon Sep 17 00:00:00 2001 From: Jan Ziak <0xe2.0x9a.0x9b@gmail.com> Date: Thu, 1 Nov 2012 12:56:25 -0400 Subject: [PATCH] runtime: add memorydump() debugging function R=golang-dev CC=golang-dev, remyoudompheng, rsc https://golang.org/cl/6780059 --- src/pkg/runtime/malloc.h | 2 ++ src/pkg/runtime/mgc0.c | 75 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/src/pkg/runtime/malloc.h b/src/pkg/runtime/malloc.h index e221faae37..765cd02eb2 100644 --- a/src/pkg/runtime/malloc.h +++ b/src/pkg/runtime/malloc.h @@ -489,3 +489,5 @@ enum // defined in mgc0.go void runtime·gc_m_ptr(Eface*); + +void runtime·memorydump(void); diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c index 4d857bf0b7..ab68619d00 100644 --- a/src/pkg/runtime/mgc0.c +++ b/src/pkg/runtime/mgc0.c @@ -806,6 +806,81 @@ sweepspan(ParFor *desc, uint32 idx) } } +static void +dumpspan(uint32 idx) +{ + int32 sizeclass, n, npages, i, column; + uintptr size; + byte *p; + byte *arena_start; + MSpan *s; + bool allocated, special; + + s = runtime·mheap.allspans[idx]; + if(s->state != MSpanInUse) + return; + arena_start = runtime·mheap.arena_start; + p = (byte*)(s->start << PageShift); + sizeclass = s->sizeclass; + size = s->elemsize; + if(sizeclass == 0) { + n = 1; + } else { + npages = runtime·class_to_allocnpages[sizeclass]; + n = (npages << PageShift) / size; + } + + runtime·printf("%p .. %p:\n", p, p+n*size); + column = 0; + for(; n>0; n--, p+=size) { + uintptr off, *bitp, shift, bits; + + off = (uintptr*)p - (uintptr*)arena_start; + bitp = (uintptr*)arena_start - off/wordsPerBitmapWord - 1; + shift = off % wordsPerBitmapWord; + bits = *bitp>>shift; + + allocated = ((bits & bitAllocated) != 0); + special = ((bits & bitSpecial) != 0); + + for(i=0; i= size) { + runtime·printf(allocated ? ") " : "] "); + } + + column++; + if(column == 8) { + runtime·printf("\n"); + column = 0; + } + } + } + runtime·printf("\n"); +} + +// A debugging function to dump the contents of memory +void +runtime·memorydump(void) +{ + uint32 spanidx; + + for(spanidx=0; spanidx