1
0

leak 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 && a < 0x60000000 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 < atail && b.magic != ARENATAIL_MAGIC 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. if nb > atail then {
  31. b = (Bhdr)(b+4);
  32. print("lost at block ", (b-4)\X, ", scanning forward\n");
  33. while b < atail && b.magic != KEMPT_MAGIC && b.magic != FREE_MAGIC do
  34. b = (Bhdr)(b+4);
  35. print("stopped at ", b\X, " ", *b\X, "\n");
  36. }else
  37. b = nb;
  38. }
  39. if b != atail then
  40. print("found wrong tail to arena ", arena\X, " wanted ", atail\X, "\n");
  41. }
  42. defn
  43. isptr(a)
  44. {
  45. if end <= a && a < xbloc then
  46. return 1;
  47. if 0x7efff000 <= a && a < 0x7ffff000 then
  48. return 1;
  49. return 0;
  50. }
  51. defn
  52. dumpblock(addr)
  53. {
  54. complex Bhdr addr;
  55. if addr.magic == KEMPT_MAGIC || addr.magic == FREE_MAGIC then {
  56. local a, x, s;
  57. a = addr;
  58. complex Alloc a;
  59. x = addr+8;
  60. if addr.magic == KEMPT_MAGIC then
  61. s = "block";
  62. else
  63. s = "free";
  64. print(s, " ", addr\X, " ", a.size\X, " ");
  65. print(*(addr+8)\X, " ", *(addr+12)\X, "\n");
  66. }
  67. }
  68. defn
  69. dumprange(s, e, type)
  70. {
  71. local x, y;
  72. print("range ", type, " ", s\X, " ", e\X, "\n");
  73. x = s;
  74. while x < e do {
  75. y = *x;
  76. if isptr(y) then print("data ", x\X, " ", y\X, " ", type, "\n");
  77. x = x + 4;
  78. }
  79. }
  80. defn
  81. dumpmem()
  82. {
  83. local s;
  84. xbloc = *bloc;
  85. // assume map()[1] is "data"
  86. dumprange(map()[1][1], end, "bss"); // bss
  87. dumprange(end, xbloc, "alloc"); // allocated
  88. if 0x7efff000 < *SP && *SP < 0x7ffff000 then
  89. s = *SP;
  90. else
  91. s = 0x7fff7000; // 32 k
  92. dumprange(s, 0x7ffff000, "stack");
  93. }
  94. defn
  95. dumpregs()
  96. {
  97. dumprange(0, sizeofUreg, "reg");
  98. }
  99. defn
  100. leakdump(l)
  101. {
  102. print("==LEAK BEGIN==\n");
  103. dumppool(sbrkmem);
  104. dumpmem();
  105. dumpregs();
  106. while l != {} do {
  107. setproc(head l);
  108. dumpregs();
  109. l = tail l;
  110. }
  111. print("==LEAK END==\n");
  112. }
  113. defn
  114. blockdump()
  115. {
  116. print("==BLOCK BEGIN==\n");
  117. dumppool(sbrkmem);
  118. print("==BLOCK END==\n");
  119. }