OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [stdlib/] [malloc/] [malloc_debug.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/*
2
 * libc/stdlib/malloc/malloc_debug.c -- malloc debugging support
3
 *
4
 *  Copyright (C) 2002  NEC Corporation
5
 *  Copyright (C) 2002  Miles Bader <miles@gnu.org>
6
 *
7
 * This file is subject to the terms and conditions of the GNU Lesser
8
 * General Public License.  See the file COPYING.LIB in the main
9
 * directory of this archive for more details.
10
 *
11
 * Written by Miles Bader <miles@gnu.org>
12
 */
13
 
14
#include <stdlib.h>
15
#include <stdio.h>
16
#include <unistd.h>
17
#include <stdarg.h>
18
 
19
#include "malloc.h"
20
#include "heap.h"
21
 
22
int __malloc_debug = 0, __malloc_check = 0;
23
 
24
#ifdef MALLOC_MMB_DEBUGGING
25
int __malloc_mmb_debug = 0;
26
#endif
27
 
28
/* Debugging output is indented this may levels.  */
29
int __malloc_debug_cur_indent = 0;
30
 
31
 
32
/* Print FMT and args indented at the current debug print level, followed
33
   by a newline, and change the level by INDENT.  */
34
void
35
__malloc_debug_printf (int indent, const char *fmt, ...)
36
{
37
  unsigned spaces = __malloc_debug_cur_indent * MALLOC_DEBUG_INDENT_SIZE;
38
  va_list val;
39
 
40
  while (spaces > 0)
41
    {
42
      putc (' ', stderr);
43
      spaces--;
44
    }
45
 
46
  va_start (val, fmt);
47
  vfprintf (stderr, fmt, val);
48
  va_end (val);
49
 
50
  putc ('\n', stderr);
51
 
52
  __malloc_debug_indent (indent);
53
}
54
 
55
void
56
__malloc_debug_init (void)
57
{
58
  char *ev = getenv ("MALLOC_DEBUG");
59
  if (ev)
60
    {
61
      int val = atoi (ev);
62
 
63
      if (val & 1)
64
        __malloc_check = 1;
65
 
66
      if (val & 2)
67
        __malloc_debug = 1;
68
 
69
#ifdef MALLOC_MMB_DEBUGGING
70
      if (val & 4)
71
        __malloc_mmb_debug = 1;
72
#endif
73
 
74
#ifdef HEAP_DEBUGGING
75
      if (val & 8)
76
        __heap_debug = 1;
77
#endif
78
 
79
      if (val)
80
        __malloc_debug_printf
81
          (0, "malloc_debug: initialized to %d (check = %d, dump = %d, dump_mmb = %d, dump_heap = %d)",
82
           val,
83
           !!(val & 1), !!(val & 2),
84
           !!(val & 4), !!(val & 8));
85
    }
86
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.