]>
git.ipfire.org Git - thirdparty/bash.git/blob - lib/malloc/trace.c
1 /* trace.c - tracing functions for malloc */
3 /* Copyright (C) 2001-2003 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with Bash; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
31 extern int malloc_trace
;
33 static int _mtrace_verbose
= 0;
37 extern FILE *_imalloc_fopen
__P((char *, char *, char *, char *, size_t));
39 FILE *_mtrace_fp
= NULL
;
40 extern char _malloc_trace_buckets
[];
43 mtrace_alloc (tag
, mem
, size
, file
, line
)
50 if (_mtrace_fp
== NULL
)
54 fprintf (_mtrace_fp
, "alloc: %s: %p (%d bytes) from '%s:%d'\n",
55 tag
, mem
, size
, file
? file
: "unknown", line
);
57 fprintf (_mtrace_fp
, "alloc:%p:%d:%s:%d\n",
58 mem
, size
, file
? file
: "unknown", line
);
62 mtrace_free (mem
, size
, file
, line
)
68 if (_mtrace_fp
== NULL
)
72 fprintf (_mtrace_fp
, "free: %p (%d bytes) from '%s:%d'\n",
73 mem
, size
, file
? file
: "unknown", line
);
75 fprintf (_mtrace_fp
, "free:%p:%d:%s:%d\n",
76 mem
, size
, file
? file
: "unknown", line
);
78 #endif /* MALLOC_TRACE */
88 _mtrace_verbose
= (n
> 1);
93 malloc_set_tracefp (fp
)
97 _mtrace_fp
= fp
? fp
: stderr
;
106 _malloc_trace_buckets
[n
] = 1;
110 #define TRACEROOT "/var/tmp/maltrace/trace."
113 malloc_set_tracefn (s
, fn
)
119 char defname
[sizeof (TRACEROOT
) + 64];
121 fp
= _imalloc_fopen (s
, fn
, TRACEROOT
, defname
, sizeof (defname
));
123 malloc_set_tracefp (fp
);