]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/lib/acid/leak
merge
[plan9front.git] / sys / lib / acid / leak
old mode 100755 (executable)
new mode 100644 (file)
index 7469287..a4449f1
@@ -1,7 +1,7 @@
 //
 // usage: acid -l pool -l leak
 //
-include("/sys/src/libc/port/pool.acid");
+include("/sys/src/libc/port/pool." + objtype + ".acid");
 
 defn
 dumppool(p, sum)
@@ -9,12 +9,21 @@ dumppool(p, sum)
        complex Pool p;
        a = p.arenalist;
 
-       print("A: ", p.arenalist\X, "\n");
-       while a != 0 && a < 0xff000000 do {
+       allocsize = 0;
+
+       print("A: ", p.arenalist\A, "\n");
+       while a != 0 do {
                complex Arena a;
                dumparena(a, sum);
                a = a.down;
        }
+       if sum then {
+               emitsum();
+       }
+
+       if allocsize != p.curalloc then {
+               print("found alloc size mismatch ", allocsize, " != ", p.curalloc, "\n");
+       }
 }
 
 defn
@@ -25,25 +34,24 @@ dumparena(arena, sum)
        atail = A2TB(arena);
        complex Bhdr arena;
        b = a;
-       print("B: ", b\X, " ", atail\X, "\n");
+       print("B: ", b\A, " ", atail\A, "\n");
        while b < atail && b.magic != ARENATAIL_MAGIC do {
                dumpblock(b, sum);
                nb = B2NB(b);
                if nb == b then {
-                       print("B2NB(", b\X, ") = b\n");
+                       print("B2NB(", b\A, ") = b\n");
                        b = atail;      // end loop
-               }
-               if nb > atail then {
+               } else if nb > atail then {
                        b = (Bhdr)(b+4);
-                       print("lost at block ", (b-4)\X, ", scanning forward\n");
+                       print("lost at block ", (b-4)\A, ", scanning forward\n");
                        while b < atail && b.magic != ALLOC_MAGIC && b.magic != FREE_MAGIC do
                                b = (Bhdr)(b+4);
-                       print("stopped at ", b\X, " ", *b\X, "\n");
+                       print("stopped at ", b\A, " ", *b\A, "\n");
                }else
                        b = nb;
        }
        if b != atail then
-               print("found wrong tail to arena ", arena\X, " wanted ", atail\X, "\n");
+               print("found wrong tail to arena ", arena\A, " wanted ", atail\A, "\n");
 }
 
 defn
@@ -69,33 +77,50 @@ emitsum()
        lastsize = 0;
 }
 
+defn
+sxpc(addr)
+{
+       if objtype == "amd64" && addr & 0x80000000 then {
+               return addr | 0xffffffff00000000;
+       }
+       return addr;
+}
+
 defn
 dumpblock(addr, sum)
 {
        complex Bhdr addr;
 
        if addr.magic == ALLOC_MAGIC || (!sum && addr.magic == FREE_MAGIC) then {
-               local a, x, s;
+               local a, x, s, allocpc, reallocpc;
 
                a = addr;
                complex Alloc a;
 
-               x = addr+8;
+               x = fmt(addr+sizeofBhdr, 'X');
+               if addr.magic == ALLOC_MAGIC then {
+                       allocsize = allocsize+a.size;
+                       // for mallocalign()
+                       while *x == ALIGN_MAGIC do {
+                               x = x + 4;
+                       }
+               }
+               allocpc=sxpc(x[0]);
+               reallocpc=sxpc(x[1]);
                if sum then {
-                       if *(addr+8) != lastalloc then {
+                       if allocpc != lastalloc then {
                                emitsum();
-                               lastalloc = *(addr+8);
+                               lastalloc = allocpc;
                        }
                        lastcount = lastcount+1;
                        lastsize = lastsize+a.size;
                }else{
-                       if addr.magic == ALLOC_MAGIC then
+                       if addr.magic == ALLOC_MAGIC then {
                                s = "block";
-                       else
+                       else
                                s = "free";
-                       print(s, " ", addr\X, " ", a.size\X, " ");
-                       print(*(addr+8)\X, " ", *(addr+12)\X, " ",
-                               *(addr+8)\a, " ", *(addr+12)\a, "\n");
+                       print(s, " ", addr\A, " ", a.size\X, " ");
+                       print(x[0]\X, " ", x[1]\X, " ", allocpc\a, " ", reallocpc\a, "\n");
                }
        }
 }
@@ -183,6 +208,7 @@ blocksummary()
 {
        print("==BLOCK BEGIN==\n");
        dumppool(*mainmem, 1);
-       emitsum();
        print("==BLOCK END==\n");
 }
+
+print("/sys/lib/acid/leak");