2 // usage: acid -l pool -l leak
4 include("/sys/src/libc/port/pool.acid");
12 print("A: ", p.arenalist\X, "\n");
13 while a != 0 && a < 0xff000000 do {
28 print("B: ", b\X, " ", atail\X, "\n");
29 while b < atail && b.magic != ARENATAIL_MAGIC do {
33 print("B2NB(", b\X, ") = b\n");
34 b = atail; // end loop
38 print("lost at block ", (b-4)\X, ", scanning forward\n");
39 while b < atail && b.magic != ALLOC_MAGIC && b.magic != FREE_MAGIC do
41 print("stopped at ", b\X, " ", *b\X, "\n");
46 print("found wrong tail to arena ", arena\X, " wanted ", atail\X, "\n");
52 if end <= a && a < xbloc then
54 if 0xdefff000 <= a && a < 0xdffff000 then
66 print("summary ", lastalloc\a, " ", lastcount\D, " ", lastsize\D, "\n");
77 if addr.magic == ALLOC_MAGIC || (!sum && addr.magic == FREE_MAGIC) then {
85 if *(addr+8) != lastalloc then {
87 lastalloc = *(addr+8);
89 lastcount = lastcount+1;
90 lastsize = lastsize+a.size;
92 if addr.magic == ALLOC_MAGIC then
96 print(s, " ", addr\X, " ", a.size\X, " ");
97 print(*(addr+8)\X, " ", *(addr+12)\X, " ",
98 *(addr+8)\a, " ", *(addr+12)\a, "\n");
104 dumprange(s, e, type)
108 print("range ", type, " ", s\X, " ", e\X, "\n");
112 if isptr(y) then print("data ", x\X, " ", y\X, " ", type, "\n");
125 if e[0] == "*data" then
138 // assume map()[1] is "data"
139 dumprange(map()[1][1], end, "bss"); // bss
140 dumprange(end, xbloc, "alloc"); // allocated
142 top = stacktop() - 8;
143 if top-0x01000000 < *SP && *SP < top then
148 dumprange(s, top, "stack");
154 dumprange(0, sizeofUreg, "reg");
161 print("==LEAK BEGIN==\n");
162 dumppool(*mainmem, 0);
170 print("==LEAK END==\n");
176 print("==BLOCK BEGIN==\n");
177 dumppool(*mainmem, 0);
178 print("==BLOCK END==\n");
184 print("==BLOCK BEGIN==\n");
185 dumppool(*mainmem, 1);
187 print("==BLOCK END==\n");