1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
22 #if defined(_UWIN) && defined(_BLD_ast)
24 void _STUB_vmtrace(){}
30 /* Turn on tracing for regions
32 ** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
35 static int Trfile
= -1;
36 static char Trbuf
[128];
39 static char* trstrcpy(char* to
, const char* from
, int endc
)
41 static char* trstrcpy(to
, from
, endc
)
56 /* convert a long value to an ascii representation */
58 static char* tritoa(Vmulong_t v
, int type
)
60 static char* tritoa(v
, type
)
61 Vmulong_t v
; /* value to convert */
62 int type
; /* =0 base-16, >0: unsigned base-10, <0: signed base-10 */
67 s
= &Trbuf
[sizeof(Trbuf
) - 1];
70 if(type
== 0) /* base-16 */
71 { reg
char* digit
= "0123456789abcdef";
73 { *s
-- = digit
[v
&0xf];
77 else if(type
> 0) /* unsigned base-10 */
79 { *s
-- = (char)('0' + (v
%10));
83 else /* signed base-10 */
84 { int sign
= ((long)v
< 0);
86 v
= (Vmulong_t
)(-((long)v
));
88 { *s
-- = (char)('0' + (v
%10));
98 /* generate a trace of some call */
100 static void trtrace(Vmalloc_t
* vm
,
101 Vmuchar_t
* oldaddr
, Vmuchar_t
* newaddr
, size_t size
, size_t align
)
103 static void trtrace(vm
, oldaddr
, newaddr
, size
, align
)
104 Vmalloc_t
* vm
; /* region call was made from */
105 Vmuchar_t
* oldaddr
; /* old data address */
106 Vmuchar_t
* newaddr
; /* new data address */
107 size_t size
; /* size of piece */
108 size_t align
; /* alignment */
111 char buf
[1024], *bufp
, *endbuf
;
112 Vmdata_t
* vd
= vm
->data
;
113 const char* file
= 0;
115 const Void_t
* func
= 0;
123 if(oldaddr
== (Vmuchar_t
*)(-1)) /* printing busy blocks */
125 oldaddr
= NIL(Vmuchar_t
*);
128 { type
= vd
->mode
&VM_METHODS
;
129 VMFLF(vm
,file
,line
,func
);
135 bufp
= buf
; endbuf
= buf
+sizeof(buf
);
136 bufp
= trstrcpy(bufp
, tritoa(oldaddr
? VLONG(oldaddr
) : 0L, 0), ':');
137 bufp
= trstrcpy(bufp
, tritoa(newaddr
? VLONG(newaddr
) : 0L, 0), ':');
138 bufp
= trstrcpy(bufp
, tritoa((Vmulong_t
)size
, 1), ':');
139 bufp
= trstrcpy(bufp
, tritoa((Vmulong_t
)align
, 1), ':');
140 bufp
= trstrcpy(bufp
, tritoa(VLONG(vm
), 0), ':');
142 bufp
= trstrcpy(bufp
, "b", ':');
143 else if(type
&VM_MTLAST
)
144 bufp
= trstrcpy(bufp
, "l", ':');
145 else if(type
&VM_MTPOOL
)
146 bufp
= trstrcpy(bufp
, "p", ':');
147 else if(type
&VM_MTPROFILE
)
148 bufp
= trstrcpy(bufp
, "s", ':');
149 else if(type
&VM_MTDEBUG
)
150 bufp
= trstrcpy(bufp
, "d", ':');
151 else bufp
= trstrcpy(bufp
, "u", ':');
154 if(file
&& file
[0] && line
> 0)
155 { if((bufp
+ strlen(file
) + SLOP
) >= endbuf
)
157 for(f
= bufp
+ strlen(file
); f
> file
; --f
)
158 if(f
[-1] == '/' || f
[-1] == '\\')
163 bufp
= trstrcpy(bufp
, "file", '=');
164 n
= endbuf
- bufp
- SLOP
- 3;
168 bufp
= trstrcpy(bufp
, "..", '.');
170 bufp
= trstrcpy(bufp
, file
, ',');
171 bufp
= trstrcpy(bufp
, "line", '=');
172 bufp
= trstrcpy(bufp
, tritoa((Vmulong_t
)line
,1), 0);
178 bufp
= trstrcpy(bufp
, "func", '=');
180 bufp
= trstrcpy(bufp
, (const char*)func
, 0);
182 bufp
= trstrcpy(bufp
, tritoa((Vmulong_t
)func
,0), 0);
192 write(Trfile
,buf
,(bufp
-buf
));
197 void _vmmessage(const char* s1
, long n1
, const char* s2
, long n2
)
199 void _vmmessage(s1
, n1
, s2
, n2
)
206 char buf
[1024], *bufp
;
209 bufp
= trstrcpy(bufp
, "vmalloc", ':');
212 bufp
= trstrcpy(bufp
, s1
, ':');
214 bufp
= trstrcpy(bufp
, tritoa(n1
, 1), ':');
218 bufp
= trstrcpy(bufp
, s2
, ':');
220 bufp
= trstrcpy(bufp
, tritoa(n2
, 0), ':');
222 bufp
= trstrcpy(bufp
, tritoa((long)getpid(), 1), ':');
224 write(2,buf
,(bufp
-buf
));
229 int vmtrace(int file
)
237 _Vmstrcpy
= trstrcpy
;
247 int vmtrbusy(Vmalloc_t
* vm
)
254 Vmdata_t
* vd
= vm
->data
;
256 if(Trfile
< 0 || !(vd
->mode
&(VM_MTBEST
|VM_MTDEBUG
|VM_MTPROFILE
)))
259 for(seg
= vd
->seg
; seg
; seg
= seg
->next
)
264 for(b
= SEGBLOCK(seg
), endb
= BLOCK(seg
->baddr
); b
< endb
; )
265 { if(ISJUNK(SIZE(b
)) || !ISBUSY(SIZE(b
)))
269 if(vd
->mode
&VM_MTDEBUG
)
270 { data
= DB2DEBUG(data
);
273 else if(vd
->mode
&VM_MTPROFILE
)
275 else s
= SIZE(b
)&~BITS
;
277 trtrace(vm
, (Vmuchar_t
*)(-1), data
, s
, 0);
279 b
= (Block_t
*)((Vmuchar_t
*)DATA(b
) + (SIZE(b
)&~BITS
) );