aboutsummaryrefslogtreecommitdiff
path: root/acid/acme
blob: 1cce6eb8a503400ecc7664b2fc9874acfeb2160e (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
129
130
131
132
133
// support for acme; acid must be run with /acme/acid/$cputype/Acid


defn w(*code)
{
	local dir;

	printto("/tmp/acme.acid", eval code);
	rc("cat /tmp/acme.acid | wnew -d "+"Acid/-stk'("+itoa(pid)+")'");
}

defn procstk(pid, name)
{
	local dir;

	printto("/tmp/acme.acid", stk());
	rc("cat /tmp/acme.acid | wnew -d "+"Acid/-'"+name+"("+itoa(pid)+")'");
}

defn taskstk(tid, name)
{
	local dir;

	printto("/tmp/acme.acid", threadstk(tid));
	rc("cat /tmp/acme.acid | wnew -d "+"Acid/-"+name+"'("+itoa(pid)+")'");
}

defn _stk(pc, sp, link, dolocals)
{
	local stk;

	print("At pc:", pc, ":", fmt(pc, 'a'), " ");
	pfl(pc);

	stk = strace(pc, sp, link);

	while stk do {
		frame = head stk;
		print(fmt(frame[0], 'a'), "(");
		params(frame[2], frame[0]);
		print(") ");
		print("\n\tcalled from ", fmt(frame[1], 'a'), " ");
		pfl(frame[1]);
		stk = tail stk;
		if dolocals then
			locals(frame[3], frame[0]);
	}
}

//defn _stk(pc, sp, dolocals)
//{
//	w(__stk(pc, sp, dolocals));
//}


defn params(param, name)
{
	while param do {
		sym = head param;
		print("*", fmt(name, 'a'), ":", sym[0], "=", sym[1]);
		param = tail param;
		if param then
			print (",");
	}	
}

defn locals(l, name)
{
	local sym;

	while l do {
		sym = head l;
		print("\t*", fmt(name, 'a'), ":", sym[0], "=", sym[1], "\n");
		l = tail l;
	}	
}

defn bptab()					// print a table of breakpoints
{
	local lst, addr;

	lst = bplist;
	while lst do {
		addr = head lst;
		print("\tbpdel(", fmt(addr, 'a'), ")\n");
		lst = tail lst;
	}
}

defn procs()			// print status of processes
{
	local c, lst, cpid;

	cpid = pid;
	lst = proclist;
	while lst do {
		np = head lst;
		setproc(np);
		if np == cpid then
			print(">");
		print("\t", "setproc(", np, ")\t", status(np), " at ", fmt(*PC, 'a'), "\n");
		lst = tail lst;
	}
	pid = cpid;
	if pid != 0 then
		setproc(pid);
}

defn allstacks()			// print stacks of processes and threads
{
	complex Proc P;
	local T, Tq;
	local c, lst, cpid;

	cpid = pid;
	P = (Proc)pq.$head;
	while P != 0 do{
		Tq = (Tqueue)P.threads;
		T = (Thread)Tq.$head;
		setproc(P.pid);
		while T != 0 do{
			if(T.cmdname == 0) then taskstk(T, "unknown");
			else taskstk(T, *(T.cmdname\s));
			T = T.nextt;
		}
		P = P.next;
	}
	pid = cpid;
	if pid != 0 then
		setproc(pid);
}

print(acidfile);