aboutsummaryrefslogtreecommitdiff
path: root/acid/coverage
blob: 3436bd1c84849e56d4bce6d91ce608d45b6312d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Coverage library

defn coverage()
{
	local lmap, lp, e, pc, n, l;

	new();

	bblock = {};

	// find the first location in the text
	e = (map()[0][1])\i;

	while e < etext-4 do {
		l = follow(e);
		if tail l != {} then {
			if match(l[0], bblock) < 0 then
				bblock = append bblock, l[0];
			if match(l[1], bblock) < 0 then
				bblock = append bblock, l[1];
		}
		e++;
	}

	l = bblock;
	while l != {} do {
		*fmt(head l, bpfmt) = bpinst;
		l = tail l;
	}

	while 1 do {
		cont();
		pc = *PC;
		n = match(pc, bblock);
		if n >= 0 then {
			pc = fmt(pc, bpfmt);
			*pc = @pc;
			bblock = delete bblock, n;
		}
		else {
			pstop(pid);
			return {};
		}
	}
}

defn eblock(addr)
{
	addr = addr\i;

	while addr < etext do {
		if (tail follow(addr)) != {} then
			return pcline(addr);
		addr++;
	}
	return 0;
}

defn basic(stsrc, ensrc, file)
{
	local src, text;

	if stsrc >= ensrc then
		return {};

	print(file, ":", stsrc, ",", ensrc, "\n");
	src = match(file, srcfiles);

	if src >= 0 then
		src = srctext[src];
	else
		src = findsrc(file);

	if src == {} then
		print("no source for ", file, "\n");
	else {
		while stsrc <= ensrc do {
			text = src[stsrc];
			if text != {} then
				print("\t", stsrc, ":", text, "\n");
			stsrc = stsrc+1;
		}
	}
}

defn analyse(fnaddr)
{
	local addr, l, tfn;

	new();

	tfn = fnbound(fnaddr);

	l = bblock;
	while l do {
		addr = head l;

		if addr >= tfn[0] && addr < tfn[1] then
			basic(pcline(addr), eblock(addr), pcfile(addr));
		
		l = tail l;
	}
	kill(pid);
}

defn report()
{
	local addr, l;

	new();

	l = bblock;
	while l do {
		addr = head l;

		basic(pcline(addr), eblock(addr), pcfile(addr));
		
		l = tail l;
	}
	kill(pid);
}

defn stopped(pid)
{
	return {};
}

print(acidfile);