OSDN Git Service

Update debugging hooks.
authorMiles Bader <miles@lsi.nec.co.jp>
Fri, 6 Sep 2002 04:58:53 +0000 (04:58 -0000)
committerMiles Bader <miles@lsi.nec.co.jp>
Fri, 6 Sep 2002 04:58:53 +0000 (04:58 -0000)
libc/stdlib/malloc/heap.h
libc/stdlib/malloc/malloc.c
libc/stdlib/malloc/malloc.h

index 6b370fd..d8e8335 100644 (file)
@@ -81,39 +81,21 @@ struct heap_free_area
 
 
 /* Define HEAP_DEBUGGING to cause the heap routines to emit debugging info
-   to stderr.  */
+   to stderr when the variable __heap_debug is set to true.  */
 #ifdef HEAP_DEBUGGING
-#include <stdio.h>
-static void HEAP_DEBUG (struct heap *heap, const char *str)
-{
-  static int recursed = 0;
-  if (! recursed)
-    {
-      struct heap_free_area *fa, *prev;
-      recursed = 1;
-      fprintf (stderr, "  %s: heap @0x%lx:\n", str, (long)heap);
-      for (prev = 0, fa = heap->free_areas; fa; prev = fa, fa = fa->next)
-       {
-         fprintf (stderr,
-                  "    0x%lx:  0x%lx - 0x%lx  (%d)\tP=0x%lx, N=0x%lx\n",
-                  (long)fa,
-                  (long)HEAP_FREE_AREA_START (fa),
-                  (long)HEAP_FREE_AREA_END (fa),
-                  fa->size,
-                  (long)fa->prev,
-                  (long)fa->next);
-         if (fa->prev != prev)
-           fprintf (stderr,
-                    "      PREV POINTER CORRUPTED!!!!  P=0x%lx should be 0x%lx\n",
-                    (long)fa->prev, (long)prev);
-       }
-      recursed = 0;
-    }
-}
+extern int __heap_debug;
+#define HEAP_DEBUG(heap, str) (__heap_debug ? __heap_dump (heap, str) : 0)
 #else
 #define HEAP_DEBUG(heap, str) (void)0
 #endif
 
+/* Output a text representation of HEAP to stderr, labelling it with STR.  */
+extern void __heap_dump (struct heap *heap, const char *str);
+
+/* Do some consistency checks on HEAP.  If they fail, output an error
+   message to stderr, and exit.  STR is printed with the failure message.  */
+extern void __heap_check (struct heap *heap, const char *str);
+
 
 /* Delete the free-area FA from HEAP.  */
 extern inline void
@@ -127,6 +109,7 @@ __heap_delete (struct heap *heap, struct heap_free_area *fa)
     heap->free_areas = fa->next;
 }
 
+
 /* Link the free-area FA between the existing free-area's PREV and NEXT in
    HEAP.  PREV and NEXT may be 0; if PREV is 0, FA is installed as the
    first free-area.  */
index 4b4cc7d..021ed3a 100644 (file)
@@ -31,6 +31,10 @@ malloc_mutex_t __malloc_sbrk_lock;
 # endif /* MALLOC_USE_SBRK */
 #endif /* MALLOC_USE_LOCKING */
 
+#ifdef MALLOC_DEBUGGING
+int __malloc_debug = 0;
+#endif
+
 
 void *
 malloc (size_t size)
index 30a28b7..4071a4f 100644 (file)
@@ -122,10 +122,13 @@ extern malloc_mutex_t __malloc_sbrk_lock;
 #endif /* !likely */
 
 
-/* Define MALLOC_DEBUGGING to cause malloc to emit debugging info to stderr.  */
+/* Define MALLOC_DEBUGGING to cause malloc to emit debugging info to stderr
+   when the variable __malloc_debug is set to true. */
 #ifdef MALLOC_DEBUGGING
 #include <stdio.h>
-#define MALLOC_DEBUG(fmt, args...) fprintf (stderr, fmt , ##args)
+extern int __malloc_debug;
+#define MALLOC_DEBUG(fmt, args...) \
+  (__malloc_debug ? fprintf (stderr, fmt , ##args) : 0)
 #else
 #define MALLOC_DEBUG(fmt, args...) (void)0
 #endif