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