leak 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // usage: acid -l pool -l leak
  3. //
  4. include("/sys/src/libc/port/pool.acid");
  5. defn
  6. dumppool(p)
  7. {
  8. complex Pool p;
  9. a = p.arenalist;
  10. while a != 0 do {
  11. complex Arena a;
  12. dumparena(a);
  13. a = a.down;
  14. }
  15. }
  16. defn
  17. dumparena(arena)
  18. {
  19. local atail, b, nb;
  20. atail = A2TB(arena);
  21. complex Bhdr arena;
  22. b = a;
  23. while b.magic != ARENATAIL_MAGIC && b < atail do {
  24. dumpblock(b);
  25. nb = B2NB(b);
  26. if nb == b then {
  27. print("B2NB(", b\X, ") = b\n");
  28. b = atail; // end loop
  29. }
  30. b = nb;
  31. }
  32. dumpblock(b);
  33. if b != atail then
  34. print("found wrong tail to arena ", arena\X, "\n");
  35. }
  36. defn
  37. isptr(a)
  38. {
  39. if end <= a && a < xbloc then
  40. return 1;
  41. if 0x7efff000 <= a && a < 0x7ffff000 then
  42. return 1;
  43. return 0;
  44. }
  45. defn
  46. dumpblock(addr)
  47. {
  48. complex Bhdr addr;
  49. if addr.magic == KEMPT_MAGIC then {
  50. local a, x;
  51. a = addr;
  52. complex Alloc a;
  53. x = addr+8;
  54. print("block ", addr\X, " ", a.size\X, " ", *(addr+8)\X, " ", *(addr+12)\X, "\n");
  55. }
  56. }
  57. defn
  58. dumprange(s, e, type)
  59. {
  60. local x, y;
  61. print("range ", type, " ", s\X, " ", e\X, "\n");
  62. x = s;
  63. while x < e do {
  64. y = *x;
  65. if isptr(y) then print("data ", x\X, " ", y\X, " ", type, "\n");
  66. x = x + 4;
  67. }
  68. }
  69. defn
  70. dumpmem()
  71. {
  72. local s;
  73. xbloc = *bloc;
  74. // assume map()[1] is "data"
  75. dumprange(map()[1][1], end, "bss"); // bss
  76. dumprange(end, xbloc, "alloc"); // allocated
  77. if 0x7efff000 < *SP && *SP < 0x7ffff000 then
  78. s = *SP;
  79. else
  80. s = 0x7fff7000; // 32 k
  81. dumprange(s, 0x7ffff000, "stack");
  82. }
  83. defn
  84. dumpregs()
  85. {
  86. dumprange(0, sizeofUreg, "reg");
  87. }
  88. defn
  89. leakdump(l)
  90. {
  91. print("==LEAK BEGIN==\n");
  92. dumppool(sbrkmem);
  93. dumpmem();
  94. dumpregs();
  95. while l != {} do {
  96. setproc(head l);
  97. dumpregs();
  98. l = tail l;
  99. }
  100. print("==LEAK END==\n");
  101. }
  102. defn
  103. blockdump()
  104. {
  105. print("==BLOCK BEGIN==\n");
  106. dumppool(sbrkmem);
  107. print("==BLOCK END==\n");
  108. }