Blob


1 // Coverage library
3 defn coverage()
4 {
5 local lmap, lp, e, pc, n, l;
7 new();
9 bblock = {};
11 // find the first location in the text
12 e = (map()[0][1])\i;
14 while e < etext-4 do {
15 l = follow(e);
16 if tail l != {} then {
17 if match(l[0], bblock) < 0 then
18 bblock = append bblock, l[0];
19 if match(l[1], bblock) < 0 then
20 bblock = append bblock, l[1];
21 }
22 e++;
23 }
25 l = bblock;
26 while l != {} do {
27 *fmt(head l, bpfmt) = bpinst;
28 l = tail l;
29 }
31 while 1 do {
32 cont();
33 pc = *PC;
34 n = match(pc, bblock);
35 if n >= 0 then {
36 pc = fmt(pc, bpfmt);
37 *pc = @pc;
38 bblock = delete bblock, n;
39 }
40 else {
41 pstop(pid);
42 return {};
43 }
44 }
45 }
47 defn eblock(addr)
48 {
49 addr = addr\i;
51 while addr < etext do {
52 if (tail follow(addr)) != {} then
53 return pcline(addr);
54 addr++;
55 }
56 return 0;
57 }
59 defn basic(stsrc, ensrc, file)
60 {
61 local src, text;
63 if stsrc >= ensrc then
64 return {};
66 print(file, ":", stsrc, ",", ensrc, "\n");
67 src = match(file, srcfiles);
69 if src >= 0 then
70 src = srctext[src];
71 else
72 src = findsrc(file);
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 }
86 defn analyse(fnaddr)
87 {
88 local addr, l, tfn;
90 new();
92 tfn = fnbound(fnaddr);
94 l = bblock;
95 while l do {
96 addr = head l;
98 if addr >= tfn[0] && addr < tfn[1] then
99 basic(pcline(addr), eblock(addr), pcfile(addr));
101 l = tail l;
103 kill(pid);
106 defn report()
108 local addr, l;
110 new();
112 l = bblock;
113 while l do {
114 addr = head l;
116 basic(pcline(addr), eblock(addr), pcfile(addr));
118 l = tail l;
120 kill(pid);
123 defn stopped(pid)
125 return {};
128 print(acidfile);