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
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bash is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
32 extern int malloc_trace;
34 static int _mtrace_verbose = 0;
38 extern FILE *_imalloc_fopen __P((char *, char *, char *, char *, size_t));
40 FILE *_mtrace_fp = NULL;
41 extern char _malloc_trace_buckets[];
44 mtrace_alloc (tag, mem, size, file, line)
51 if (_mtrace_fp == NULL)
55 fprintf (_mtrace_fp, "alloc: %s: %p (%d bytes) from '%s:%d'\n",
56 tag, mem, size, file ? file : "unknown", line);
58 fprintf (_mtrace_fp, "alloc:%p:%d:%s:%d\n",
59 mem, size, file ? file : "unknown", line);
63 mtrace_free (mem, size, file, line)
69 if (_mtrace_fp == NULL)
73 fprintf (_mtrace_fp, "free: %p (%d bytes) from '%s:%d'\n",
74 mem, size, file ? file : "unknown", line);
76 fprintf (_mtrace_fp, "free:%p:%d:%s:%d\n",
77 mem, size, file ? file : "unknown", line);
79 #endif /* MALLOC_TRACE */
89 _mtrace_verbose = (n > 1);
94 malloc_set_tracefp (fp)
98 _mtrace_fp = fp ? fp : stderr;
107 _malloc_trace_buckets[n] = 1;
111 #define TRACEROOT "/var/tmp/maltrace/trace."
114 malloc_set_tracefn (s, fn)
120 char defname[sizeof (TRACEROOT) + 64];
122 fp = _imalloc_fopen (s, fn, TRACEROOT, defname, sizeof (defname));
124 malloc_set_tracefp (fp);