1
0

coverage 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Coverage library
  2. defn coverage()
  3. {
  4. local lmap, lp, e, pc, n, l;
  5. new();
  6. bblock = {};
  7. // find the first location in the text
  8. e = (map()[0][1])\i;
  9. while e < etext-4 do {
  10. l = follow(e);
  11. if tail l != {} then {
  12. if match(l[0], bblock) < 0 then
  13. bblock = append bblock, l[0];
  14. if match(l[1], bblock) < 0 then
  15. bblock = append bblock, l[1];
  16. }
  17. e++;
  18. }
  19. l = bblock;
  20. while l != {} do {
  21. *fmt(head l, bpfmt) = bpinst;
  22. l = tail l;
  23. }
  24. while 1 do {
  25. cont();
  26. pc = *PC;
  27. n = match(pc, bblock);
  28. if n >= 0 then {
  29. pc = fmt(pc, bpfmt);
  30. *pc = @pc;
  31. bblock = delete bblock, n;
  32. }
  33. else {
  34. pstop(pid);
  35. return {};
  36. }
  37. }
  38. }
  39. defn eblock(addr)
  40. {
  41. addr = addr\i;
  42. while addr < etext do {
  43. if (tail follow(addr)) != {} then
  44. return pcline(addr);
  45. addr++;
  46. }
  47. return 0;
  48. }
  49. defn basic(stsrc, ensrc, file)
  50. {
  51. local src, text;
  52. if stsrc >= ensrc then
  53. return {};
  54. print(file, ":", stsrc, ",", ensrc, "\n");
  55. src = match(file, srcfiles);
  56. if src >= 0 then
  57. src = srctext[src];
  58. else
  59. src = findsrc(file);
  60. if src == {} then
  61. print("no source for ", file, "\n");
  62. else {
  63. while stsrc <= ensrc do {
  64. text = src[stsrc];
  65. if text != {} then
  66. print("\t", stsrc, ":", text, "\n");
  67. stsrc = stsrc+1;
  68. }
  69. }
  70. }
  71. defn analyse(fnaddr)
  72. {
  73. local addr, l, tfn;
  74. new();
  75. tfn = fnbound(fnaddr);
  76. l = bblock;
  77. while l do {
  78. addr = head l;
  79. if addr >= tfn[0] && addr < tfn[1] then
  80. basic(pcline(addr), eblock(addr), pcfile(addr));
  81. l = tail l;
  82. }
  83. kill(pid);
  84. }
  85. defn report()
  86. {
  87. local addr, l;
  88. new();
  89. l = bblock;
  90. while l do {
  91. addr = head l;
  92. basic(pcline(addr), eblock(addr), pcfile(addr));
  93. l = tail l;
  94. }
  95. kill(pid);
  96. }
  97. defn stopped(pid)
  98. {
  99. return {};
  100. }
  101. print("/sys/lib/acid/coverage");