2 * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).
3 * You may copy, distribute, and use this software as long as this
4 * copyright statement is not removed.
11 * Function: malloc_dump()
13 * Purpose: to dump a printed copy of the malloc chain and
14 * associated data elements
16 * Arguments: fd - file descriptor to write data to
18 * Returns: nothing of any use
20 * Narrative: Just print out all the junk
22 * Notes: This function is implemented using low level calls because
23 * of the likelyhood that the malloc tree is damaged when it
24 * is called. (Lots of things in the c library use malloc and
25 * we don't want to get into a catch-22).
31 char rcs_hdr
[] = "$Id: dump.c,v 1.2 2006-07-25 10:07:38 rt Exp $";
35 #define ERRSTR "I/O Error on malloc dump file descriptor\n"
37 #define WRITEOUT(fd,str,len) if( write(fd,str,(unsigned)len) != len ) \
39 (void) write(2,ERRSTR,\
40 (unsigned)strlen(ERRSTR));\
51 extern char * malloc_data_end
;
52 extern char * malloc_data_start
;
53 extern struct mlist
* malloc_end
;
54 extern struct mlist malloc_start
;
57 WRITEOUT(fd
,"MALLOC CHAIN:\n",14);
58 WRITEOUT(fd
,"-------------------- START ----------------\n",44);
65 for(ptr
= &malloc_start
; ptr
; ptr
= ptr
->next
)
67 (void) tostring(buffer
, (int)ptr
, 8, B_HEX
, '0');
68 (void) tostring(buffer
+9, (int)ptr
->next
, 8, B_HEX
, '0');
69 (void) tostring(buffer
+18, (int)ptr
->prev
, 8, B_HEX
, '0');
70 (void) tostring(buffer
+27, (int)ptr
->flag
, 10, B_HEX
, '0');
71 (void) tostring(buffer
+38, (int)ptr
->s
.size
, 8, B_DEC
, ' ');
72 (void) tostring(buffer
+47, (int)ptr
->s
.size
, 8, B_HEX
, '0');
73 (void) tostring(buffer
+57, (int)ptr
->data
, 8, B_HEX
, '0');
77 WRITEOUT(fd
,buffer
,66);
79 WRITEOUT(fd
,"-------------------- DONE -----------------\n",44);
81 WRITEOUT(fd
,"Malloc start: ",19);
82 (void) tostring(buffer
, (int) &malloc_start
, 8, B_HEX
, '0');
84 WRITEOUT(fd
,buffer
,9);
86 WRITEOUT(fd
,"Malloc end: ", 19);
87 (void) tostring(buffer
, (int) malloc_end
, 8, B_HEX
, '0');
89 WRITEOUT(fd
,buffer
,9);
91 WRITEOUT(fd
,"Malloc data start: ", 19);
92 (void) tostring(buffer
, (int) malloc_data_start
, 8, B_HEX
, '0');
94 WRITEOUT(fd
,buffer
,9);
96 WRITEOUT(fd
,"Malloc data end: ", 19);
97 (void) tostring(buffer
, (int) malloc_data_end
, 8, B_HEX
, '0');
99 WRITEOUT(fd
,buffer
,9);
101 } /* malloc_dump(... */