2 // usage: acid -l pool -l leak
4 include("/sys/src/libc/port/pool." + objtype + ".acid");
12 print("A: ", p.arenalist\A, "\n");
28 print("B: ", b\A, " ", atail\A, "\n");
29 while b < atail && b.magic != ARENATAIL_MAGIC do {
33 print("B2NB(", b\A, ") = b\n");
34 b = atail; // end loop
38 print("lost at block ", (b-4)\A, ", scanning forward\n");
39 while b < atail && b.magic != ALLOC_MAGIC && b.magic != FREE_MAGIC do
41 print("stopped at ", b\A, " ", *b\A, "\n");
46 print("found wrong tail to arena ", arena\A, " wanted ", atail\A, "\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");
75 if objtype == "amd64" && addr & 0x80000000 then {
76 return addr | 0xffffffff00000000;
86 if addr.magic == ALLOC_MAGIC || (!sum && addr.magic == FREE_MAGIC) then {
87 local a, x, s, allocpc, reallocpc;
92 x = fmt(addr+sizeofBhdr, 'X');
93 if addr.magic == ALLOC_MAGIC then {
95 while *x == ALIGN_MAGIC do {
100 reallocpc=sxpc(x[1]);
102 if allocpc != lastalloc then {
106 lastcount = lastcount+1;
107 lastsize = lastsize+a.size;
109 if addr.magic == ALLOC_MAGIC then {
113 print(s, " ", addr\A, " ", a.size\X, " ");
114 print(x[0]\X, " ", x[1]\X, " ", allocpc\a, " ", reallocpc\a, "\n");
120 dumprange(s, e, type)
124 print("range ", type, " ", s\X, " ", e\X, "\n");
128 if isptr(y) then print("data ", x\X, " ", y\X, " ", type, "\n");
141 if e[0] == "*data" then
154 // assume map()[1] is "data"
155 dumprange(map()[1][1], end, "bss"); // bss
156 dumprange(end, xbloc, "alloc"); // allocated
158 top = stacktop() - 8;
159 if top-0x01000000 < *SP && *SP < top then
164 dumprange(s, top, "stack");
170 dumprange(0, sizeofUreg, "reg");
177 print("==LEAK BEGIN==\n");
178 dumppool(*mainmem, 0);
186 print("==LEAK END==\n");
192 print("==BLOCK BEGIN==\n");
193 dumppool(*mainmem, 0);
194 print("==BLOCK END==\n");
200 print("==BLOCK BEGIN==\n");
201 dumppool(*mainmem, 1);
203 print("==BLOCK END==\n");
206 print("/sys/lib/acid/leak");