2 // usage: acid -l pool -l leak
4 include("/sys/src/libc/port/pool." + objtype + ".acid");
14 print("A: ", p.arenalist\A, "\n");
24 if allocsize != p.curalloc then {
25 print("found alloc size mismatch ", allocsize, " != ", p.curalloc, "\n");
37 print("B: ", b\A, " ", atail\A, "\n");
38 while b < atail && b.magic != ARENATAIL_MAGIC do {
42 print("B2NB(", b\A, ") = b\n");
43 b = atail; // end loop
44 } else if nb > atail then {
46 print("lost at block ", (b-4)\A, ", scanning forward\n");
47 while b < atail && b.magic != ALLOC_MAGIC && b.magic != FREE_MAGIC do
49 print("stopped at ", b\A, " ", *b\A, "\n");
54 print("found wrong tail to arena ", arena\A, " wanted ", atail\A, "\n");
60 if end <= a && a < xbloc then
62 if 0xdefff000 <= a && a < 0xdffff000 then
74 print("summary ", lastalloc\a, " ", lastcount\D, " ", lastsize\D, "\n");
83 if objtype == "amd64" && addr & 0x80000000 then {
84 return addr | 0xffffffff00000000;
94 if addr.magic == ALLOC_MAGIC || (!sum && addr.magic == FREE_MAGIC) then {
95 local a, x, s, allocpc, reallocpc;
100 x = fmt(addr+sizeofBhdr, 'X');
101 if addr.magic == ALLOC_MAGIC then {
102 allocsize = allocsize+a.size;
104 while *x == ALIGN_MAGIC do {
109 reallocpc=sxpc(x[1]);
111 if allocpc != lastalloc then {
115 lastcount = lastcount+1;
116 lastsize = lastsize+a.size;
118 if addr.magic == ALLOC_MAGIC then {
122 print(s, " ", addr\A, " ", a.size\X, " ");
123 print(x[0]\X, " ", x[1]\X, " ", allocpc\a, " ", reallocpc\a, "\n");
129 dumprange(s, e, type)
133 print("range ", type, " ", s\X, " ", e\X, "\n");
137 if isptr(y) then print("data ", x\X, " ", y\X, " ", type, "\n");
150 if e[0] == "*data" then
163 // assume map()[1] is "data"
164 dumprange(map()[1][1], end, "bss"); // bss
165 dumprange(end, xbloc, "alloc"); // allocated
167 top = stacktop() - 8;
168 if top-0x01000000 < *SP && *SP < top then
173 dumprange(s, top, "stack");
179 dumprange(0, sizeofUreg, "reg");
186 print("==LEAK BEGIN==\n");
187 dumppool(*mainmem, 0);
195 print("==LEAK END==\n");
201 print("==BLOCK BEGIN==\n");
202 dumppool(*mainmem, 0);
203 print("==BLOCK END==\n");
209 print("==BLOCK BEGIN==\n");
210 dumppool(*mainmem, 1);
211 print("==BLOCK END==\n");
214 print("/sys/lib/acid/leak");