diff: runtime/memory.c debugging stuff

Fergus Henderson fjh at hydra.cs.mu.oz.au
Fri May 23 04:09:29 AEST 1997


runtime/memory.c:
	Add back the old code (resurrected from the CVS archive) to
	print out debugging information about memory allocation for
	MERCURY_OPTIONS="-dm".  (Tom, I presume there was no good
	reason for deleting it?)

Index: memory.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/memory.c,v
retrieving revision 1.69
diff -u -r1.69 memory.c
--- memory.c	1997/04/02 07:50:55	1.69
+++ memory.c	1997/05/22 08:22:53
@@ -190,6 +190,8 @@
 static	size_t		unit;
 static	size_t		page_size;
 
+static void		debug_memory(void);
+
 static MemoryZone	*get_zone(void);
 static void		unget_zone(MemoryZone *zone);
 
@@ -266,7 +268,49 @@
 	init_memory_arena();
 	init_zones();
 	setup_signal();
+	if (memdebug) debug_memory();
 } /* end init_memory() */
+
+static void
+debug_memory(void)
+{
+	MemoryZone	*zone;
+
+	fprintf(stderr, "\n");
+	fprintf(stderr, "pcache_size  = %d (0x%x)\n",
+		pcache_size, pcache_size);
+	fprintf(stderr, "page_size    = %d (0x%x)\n",
+		page_size, page_size);
+	fprintf(stderr, "unit         = %d (0x%x)\n",
+		unit, unit);
+
+	fprintf(stderr, "\n");
+	fprintf(stderr, "fake_reg       = %p (offset %ld)\n",
+		(void *) fake_reg, (long) fake_reg & (unit-1));
+	fprintf(stderr, "\n");
+
+	for (zone = used_memory_zones; zone; zone = zone->next)
+	{
+		fprintf(stderr, "%-16s#%d-base	= %p\n",
+			zone->name, zone->id, (void *) zone->bottom);
+		fprintf(stderr, "%-16s#%d-min		= %p\n",
+			zone->name, zone->id, (void *) zone->min);
+		fprintf(stderr, "%-16s#%d-top		= %p\n",
+			zone->name, zone->id, (void *) zone->top);
+#ifdef HAVE_MPROTECT
+  #ifdef HAVE_SIGINFO
+		fprintf(stderr, "%-16s#%d-redzone	= %p\n",
+			zone->name, zone->id, (void *) zone->redzone);
+  #endif /* HAVE_SIGINFO */
+		fprintf(stderr, "%-16s#%d-hardmax		= %p\n",
+			zone->name, zone->id, (void *) zone->hardmax);
+#endif /* HAVE_MPROTECT */
+		fprintf(stderr, "%-16s#%d-size		= %lu\n",
+			zone->name, zone->id, (unsigned long)
+			((char *)zone->hardmax - (char *)zone->min));
+		fprintf(stderr, "\n");
+	}
+}
 
 /*
 ** init_memory_arena() allocates (if necessary) the top-level memory pool

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list