10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #if defined(DEBUG)
27
28 #include "debug_util.h"
29
30 #define DMEM_MIN(a,b) (a) < (b) ? (a) : (b)
31 #define DMEM_MAX(a,b) (a) > (b) ? (a) : (b)
32
33 typedef char byte_t;
34
35 static const byte_t ByteInited = '\xCD';
36 static const byte_t ByteFreed = '\xDD';
37 static const byte_t ByteGuard = '\xFD';
38
39 enum {
40 MAX_LINENUM = 50000, /* I certainly hope we don't have source files bigger than this */
41 MAX_CHECK_BYTES = 27, /* max bytes to check at start of block */
42 MAX_GUARD_BYTES = 8, /* size of guard areas on either side of a block */
43 MAX_DECIMAL_DIGITS = 15
44 };
45
46 /* Debug Info Header to precede allocated block */
47 typedef struct MemoryBlockHeader {
48 char filename[FILENAME_MAX+1]; /* filename where alloc occurred */
49 int linenumber; /* line where alloc occurred */
274 static const char * reportFormat =
275 "file: %s, line %d\n"
276 "size: %d bytes\n"
277 "order: %d\n"
278 "-------";
279
280 DMem_VerifyHeader(header);
281 sprintf(report, reportFormat, header->filename, header->linenumber, header->size, header->order);
282 DTRACE_PRINTLN(report);
283 }
284
285 /*
286 * Call this function at shutdown time to report any leaked blocks
287 */
288 void DMem_ReportLeaks() {
289 MemoryListLink * link;
290
291 DMutex_Enter(DMemMutex);
292
293 /* Force memory leaks to be output regardless of trace settings */
294 DTrace_EnableFile(__FILE__, TRUE);
295 DTRACE_PRINTLN("--------------------------");
296 DTRACE_PRINTLN("Debug Memory Manager Leaks");
297 DTRACE_PRINTLN("--------------------------");
298
299 /* walk through allocated list and dump any blocks not marked as freed */
300 link = MemoryList.next;
301 while (link != NULL) {
302 if ( !link->freed ) {
303 DMem_DumpHeader(link->header);
304 }
305 link = link->next;
306 }
307
308 DMutex_Exit(DMemMutex);
309 }
310
311 void DMem_SetAllocCallback( DMEM_ALLOCFN pfn ) {
312 DMutex_Enter(DMemMutex);
313 DMemGlobalState.pfnAlloc = pfn;
314 DMutex_Exit(DMemMutex);
|
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #if defined(DEBUG)
27
28 #include "debug_util.h"
29
30 /* Use THIS_FILE when it is available. */
31 #ifndef THIS_FILE
32 #define THIS_FILE __FILE__
33 #endif
34
35 #define DMEM_MIN(a,b) (a) < (b) ? (a) : (b)
36 #define DMEM_MAX(a,b) (a) > (b) ? (a) : (b)
37
38 typedef char byte_t;
39
40 static const byte_t ByteInited = '\xCD';
41 static const byte_t ByteFreed = '\xDD';
42 static const byte_t ByteGuard = '\xFD';
43
44 enum {
45 MAX_LINENUM = 50000, /* I certainly hope we don't have source files bigger than this */
46 MAX_CHECK_BYTES = 27, /* max bytes to check at start of block */
47 MAX_GUARD_BYTES = 8, /* size of guard areas on either side of a block */
48 MAX_DECIMAL_DIGITS = 15
49 };
50
51 /* Debug Info Header to precede allocated block */
52 typedef struct MemoryBlockHeader {
53 char filename[FILENAME_MAX+1]; /* filename where alloc occurred */
54 int linenumber; /* line where alloc occurred */
279 static const char * reportFormat =
280 "file: %s, line %d\n"
281 "size: %d bytes\n"
282 "order: %d\n"
283 "-------";
284
285 DMem_VerifyHeader(header);
286 sprintf(report, reportFormat, header->filename, header->linenumber, header->size, header->order);
287 DTRACE_PRINTLN(report);
288 }
289
290 /*
291 * Call this function at shutdown time to report any leaked blocks
292 */
293 void DMem_ReportLeaks() {
294 MemoryListLink * link;
295
296 DMutex_Enter(DMemMutex);
297
298 /* Force memory leaks to be output regardless of trace settings */
299 DTrace_EnableFile(THIS_FILE, TRUE);
300 DTRACE_PRINTLN("--------------------------");
301 DTRACE_PRINTLN("Debug Memory Manager Leaks");
302 DTRACE_PRINTLN("--------------------------");
303
304 /* walk through allocated list and dump any blocks not marked as freed */
305 link = MemoryList.next;
306 while (link != NULL) {
307 if ( !link->freed ) {
308 DMem_DumpHeader(link->header);
309 }
310 link = link->next;
311 }
312
313 DMutex_Exit(DMemMutex);
314 }
315
316 void DMem_SetAllocCallback( DMEM_ALLOCFN pfn ) {
317 DMutex_Enter(DMemMutex);
318 DMemGlobalState.pfnAlloc = pfn;
319 DMutex_Exit(DMemMutex);
|