xref: /inferno-os/lib/acid/rdebug (revision 46439007cf417cbd9ac8049bb4122c890097a0fa)
1// Acid remote debug (using devdbg.c)
2
3defn step()
4{
5	local ur;
6	local addrs;
7	local id;
8	local l;
9	local b;
10	local bl;
11	local sl;
12
13	complex Proc proc;
14	ur = proc.dbgreg;
15	if ur == 0 then
16		error("step: process not in breakpoint trap");
17	complex Ureg ur;
18
19	 //
20	 // stop all kprocs that could potentially hit this breakpoint
21	 // make a list of all the breakpoints at this address
22	 //
23	bl = {};
24	sl = {};
25	l = bpl;
26	while l do {
27		b = head l;
28		if b[2] == ur.pc then {
29			if status(b[1]) != "Stopped" then {
30				stop(b[1]);
31				sl = append sl, b[1];
32			}
33			bl = append bl, b;
34		}
35		l = tail l;
36	}
37
38	 //
39	 // delete all the breakpoints at this address
40	 //
41	if bl then {
42		l = bl;
43		while l do {
44			b = head l;
45			_bpconddel(b[0]);
46			l = tail l;
47		}
48	}
49
50	 //
51	 // single step to the following address
52	 //
53	addrs = follow(ur.pc);
54	id = bpset(addrs[0]);
55	startstop(pid);
56	bpdel(id);
57
58	 //
59	 // restore all the breakpoints at this address
60	 //
61	if bl then {
62		l = bl;
63		while l do {
64			b = head l;
65			_bpcondset(b[0], b[1], b[2], b[3]);
66			l = tail l;
67		}
68	}
69
70	 //
71	 // restart all kprocs that could potentially hit this breakpoint
72	 //
73	if sl then {
74		l = sl;
75		while l do {
76			start(head l);
77			l = tail l;
78		}
79	}
80}
81
82defn pstop(pid)
83{
84	local l;
85	local pc;
86	local ur;
87
88	if nopstop then
89		return {};
90
91	complex Proc proc;
92	ur = proc.dbgreg;
93	complex Ureg ur;
94	pc = ur.pc;
95
96	if _breakid != -1 then {
97		print("break ", _breakid\d, ": pid ");
98		_breakid = -1;
99	}
100	print(pid,": ", status(pid), "\t");
101
102	print(fmt(pc, 'a'), "\t", fmt(pc, 'i'), "\n");
103
104	if notes then {
105		if notes[0] != "sys: breakpoint" then {
106			print("Notes pending:\n");
107			l = notes;
108			while l do {
109				print("\t", head l, "\n");
110				l = tail l;
111			}
112		}
113	}
114}
115
116print("$ROOT/lib/acid/rdebug");
117