12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include "malloc.h"
- #include "heap.h"
- #ifdef MALLOC_DEBUGGING
- int __malloc_debug = 0, __malloc_check = 0;
- #endif
- #ifdef MALLOC_MMB_DEBUGGING
- int __malloc_mmb_debug = 0;
- #endif
- int __malloc_debug_cur_indent = 0;
- void
- __malloc_debug_printf (int indent, const char *fmt, ...)
- {
- int i;
- va_list val;
- for (i = 0; i < __malloc_debug_cur_indent; i++)
- fputs (" ", stderr);
- va_start (val, fmt);
- vfprintf (stderr, fmt, val);
- va_end (val);
- putc ('\n', stderr);
- __malloc_debug_indent (indent);
- }
- void
- __malloc_debug_init (void)
- {
- char *ev = getenv ("MALLOC_DEBUG");
- if (ev)
- {
- int val = atoi (ev);
- if (val & 1)
- __malloc_check = 1;
- #ifdef MALLOC_DEBUGGING
- if (val & 2)
- __malloc_debug = 1;
- #endif
- #ifdef MALLOC_MMB_DEBUGGING
- if (val & 4)
- __malloc_mmb_debug = 1;
- #endif
- #ifdef HEAP_DEBUGGING
- if (val & 8)
- __heap_debug = 1;
- #endif
- if (val)
- __malloc_debug_printf
- (0, "malloc_debug: initialized to %d (check = %d, dump = %d, dump_mmb = %d, dump_heap = %d)",
- val,
- !!(val & 1), !!(val & 2),
- !!(val & 4), !!(val & 8));
- }
- }
|