-
Notifications
You must be signed in to change notification settings - Fork 0
/
DMalloc.3x
169 lines (169 loc) · 3.87 KB
/
DMalloc.3x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
.\"
.\" (C) Copyright 2006 Hewlett-Packard Development Company, L.P.
.\"
.de G
.br
.B
..
.TH dmALLOC 3 local
.SH NAME
DMmalloc, DMcalloc, DMfree, DMrealloc, DMnotfreed, DMmemcheck - memory allocation debugging
.SH SYNOPSIS
.G
#include <DMalloc.h>
.PP
.G
extern int DMverbose;
.G
extern char *DMtriggeraddr;
.PP
.G
char *
.G
DMmalloc (size, fname, line)
.G
int size;
.G
char *fname;
.G
int line;
.PP
.G
char *
.G
DMcalloc (size, nitems, fname, line)
.G
int nitems;
.PP
.G
char *
.G
DMrealloc (ptr, size, fname, line)
.G
char *ptr;
.PP
.G
DMfree (ptr, fname, line)
.PP
.G
DMnotfreed ()
.PP
.G
DMmemcheck (ptr, fname, line)
.PP
.G
DMtrigger()
.PP
.SH DESCRIPTION
The
.IR DM "(debug memory)"
routines are replacements for the routines
described in
.I malloc(3)
to be used to debug memory allocation problems.
These routines check for overwriting start and/or ends of memory
areas,
passing mis-aligned pointers to
.IR free() ,
the integrity of all outstanding allocated memory,
passing already-freed pointers to
.I free()
and no-doubt some other things.
Some global variables are provided to aid the control of these
routines when using a run-time debugger.
.PP
These routines are written on top of the standard
memory allocation routines and are accessed by
.BR #includ ing
a header file which re-writes source calls
to the standard routines to be calls to the
.I DM
routines.
This header file contains:
.IP ""
.nf
#define free(p) DMfree(p,__FILE__,__LINE__)
#define malloc(s) DMmalloc(s,__FILE__,__LINE__)
#define calloc(s,i) DMcalloc(s,i,__FILE__,__LINE__)
#define memcheck(p) DMmemcheck(p,__FILE__,__LINE__)
#define realloc(p,s) DMrealloc(p,s,__FILE__,__LINE__)
.fi
.PP
.B NOTE
that the pre-processor variables __FILE__ and __LINE__
are passed in addition to the normal allocation routine
arguments to facilitate meaningful error messages.
.PP
The routines DM* are exact replacements for the standard routines
with the same name - minus the prefix, "DM",
when the header file is used.
.SH USE
To debug routines with suspect memory allocation problems,
.B #include
the header file, re-make and re-run the program.
Diagnostic output is written to stderr.
This output may be slightly customized - see section on measurements.
.SH MEASUREMENTS
Global variables
.B DMverbose
and
.B DMtriggeraddr
as well as the global function
.I DMtrigger()
are provided to interface to a run-time debugger.
.PP
The default action is for all allocation and free operations to cause
a short message to be written to stderr.
Modifying
.B DMverbose
changes this action.
If
.B DMverbose
is zero,
only errors will be printed.
.PP
.B DMtriggeraddr
may be set to a desired address and whenever this address is
found as an argument a message will be printed regardless of
the state of
.BR DMverbose .
The null function
.I DMtrigger
is called whenever a trigger is detected so that a debugger user
can set a breakpoint on this routine.
.PP
Typical use is to set
.B DMverbose
to 0,
run the program and obtain an error message containing a pointer,
set
.B DMtriggeraddr
to this address and re-run the program.
.PP
.I DMnotfreed
may be run at any time and prints a list of outstanding memory pointers
on stderr.
.PP
.I DMmemcheck
is used to check the validity of a particular memory block from user
code as well as all the outstanding blocks.
Note the macro definition in the header file.
If
.B ptr
is NULL, only the outstanding blocks are checked.
.SH FILES
.SH "SEE ALSO"
malloc(3)
.SH "BUGS"
The table of outstanding memory blocks can only hold 4K entries due to
the fact that it is static memory (for obvious reasons).
The variable TABSIZE in the source defines this limit.
An error is printed if this situation occurs.
.PP
Passing pointers to these routines obtained from other routines allocating
memory without these routines causes strange errors to occur.
.PP
Programs using these routines will be slowed considerably due to the
extensive error checking.
.SH AUTHOR
Hewlett-Packard