3 /* $KAME: debugrm.c,v 1.6 2001/12/13 16:07:46 sakane Exp $ */
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/types.h>
39 #include <sys/param.h>
49 #include "vmbuf.h" /* need to mask vmbuf.c functions. */
51 #define DRMLISTSIZE 1024
57 static struct drm_list_t drmlist
[DRMLISTSIZE
];
59 static int drm_unknown
;
61 static void DRM_add
__P((void *, char *));
62 static void DRM_del
__P((void *));
63 static void DRM_setmsg
__P((char *, int, void *, int, char *, int, char *));
70 for (i
= 0; i
< sizeof(drmlist
)/sizeof(drmlist
[0]); i
++)
80 fp
= fopen(DRMDUMPFILE
, "w");
82 err(1, "fopen"); /*XXX*/
83 fprintf(fp
, "drm_unknown=%d\n", drm_unknown
);
84 for (i
= 0; i
< sizeof(drmlist
)/sizeof(drmlist
[0]); i
++) {
86 fprintf(fp
, "%s\n", drmlist
[i
].msg
);
97 for (i
= 0; i
< sizeof(drmlist
)/sizeof(drmlist
[0]); i
++) {
98 if (!drmlist
[i
].ptr
) {
100 strlcpy(drmlist
[i
].msg
, msg
, sizeof(drmlist
[i
].msg
));
115 for (i
= 0; i
< sizeof(drmlist
)/sizeof(drmlist
[0]); i
++) {
116 if (drmlist
[i
].ptr
== p
) {
125 DRM_setmsg(buf
, buflen
, ptr
, size
, file
, line
, func
)
126 char *buf
, *file
, *func
;
127 int buflen
, size
, line
;
136 len
= strftime(buf
, buflen
, "%Y/%m/%d:%T ", tm
);
138 snprintf(buf
+ len
, buflen
- len
, "%p %6d %s:%d:%s",
139 ptr
, size
, file
, line
, func
);
143 DRM_malloc(file
, line
, func
, size
)
153 DRM_setmsg(buf
, sizeof(buf
), p
, size
, file
, line
, func
);
161 DRM_calloc(file
, line
, func
, number
, size
)
168 p
= calloc(number
, size
);
171 DRM_setmsg(buf
, sizeof(buf
), p
, number
* size
, file
, line
, func
);
178 DRM_realloc(file
, line
, func
, ptr
, size
)
186 p
= realloc(ptr
, size
);
189 if (ptr
&& p
!= ptr
) {
191 DRM_setmsg(buf
, sizeof(buf
), p
, size
, file
, line
, func
);
200 DRM_free(file
, line
, func
, ptr
)
210 DRM_strdup(file
, line
, func
, str
)
221 DRM_setmsg(buf
, sizeof(buf
), p
, size
, file
, line
, func
);
229 * mask vmbuf.c functions.
232 DRM_vmalloc(file
, line
, func
, size
)
242 DRM_setmsg(buf
, sizeof(buf
), p
, size
, file
, line
, func
);
250 DRM_vrealloc(file
, line
, func
, ptr
, size
)
258 p
= vrealloc(ptr
, size
);
261 if (ptr
&& p
!= ptr
) {
263 DRM_setmsg(buf
, sizeof(buf
), p
, size
, file
, line
, func
);
272 DRM_vfree(file
, line
, func
, ptr
)
282 DRM_vdup(file
, line
, func
, ptr
)
292 DRM_setmsg(buf
, sizeof(buf
), p
, 0, file
, line
, func
);