Blob


1 /*
2 *
3 * debugger
4 *
5 */
7 #include "defs.h"
8 #include "fns.h"
10 char NOPCS[] = "no process";
12 /* sub process control */
14 void
15 subpcs(int modif)
16 {
17 int check;
18 int runmode;
19 int keepnote;
20 int n, r;
21 ulong line, curr;
22 BKPT *bk;
23 char *comptr;
25 runmode=SINGLE;
26 r = 0;
27 keepnote=0;
28 loopcnt=cntval;
29 switch (modif) {
31 /* delete breakpoint */
32 case 'd':
33 case 'D':
34 if ((bk=scanbkpt(dot)) == 0)
35 error("no breakpoint set");
36 bk->flag=BKPTCLR;
37 return;
39 /* set breakpoint */
40 case 'b':
41 case 'B':
42 if (bk=scanbkpt(dot))
43 bk->flag=BKPTCLR;
44 for (bk=bkpthead; bk; bk=bk->nxtbkpt)
45 if (bk->flag == BKPTCLR)
46 break;
47 if (bk==0) {
48 bk = (BKPT *)malloc(sizeof(*bk));
49 if (bk == 0)
50 error("too many breakpoints");
51 bk->nxtbkpt=bkpthead;
52 bkpthead=bk;
53 }
54 bk->loc = dot;
55 bk->initcnt = bk->count = cntval;
56 bk->flag = modif == 'b' ? BKPTSET : BKPTTMP;
57 check=MAXCOM-1;
58 comptr=bk->comm;
59 rdc();
60 reread();
61 do {
62 *comptr++ = readchar();
63 } while (check-- && lastc!=EOR);
64 *comptr=0;
65 if(bk->comm[0] != EOR && cntflg == FALSE)
66 bk->initcnt = bk->count = HUGEINT;
67 reread();
68 if (check)
69 return;
70 error("bkpt command too long");
72 /* exit */
73 case 'k' :
74 case 'K':
75 if (pid == 0)
76 error(NOPCS);
77 dprint("%d: killed", pid);
78 pcsactive = 1; /* force 'kill' ctl */
79 endpcs();
80 return;
82 /* run program */
83 case 'r':
84 case 'R':
85 endpcs();
86 setup();
87 runmode = CONTIN;
88 break;
90 /* single step */
91 case 's':
92 if (pid == 0) {
93 setup();
94 loopcnt--;
95 }
96 runmode=SINGLE;
97 keepnote=defval(1);
98 break;
99 case 'S':
100 if (pid == 0) {
101 setup();
102 loopcnt--;
104 keepnote=defval(1);
105 if(pc2line(dbrget(cormap, mach->pc), &line) < 0)
106 error("%r");
107 n = loopcnt;
108 dprint("%s: running\n", symfil);
109 flush();
110 for (loopcnt = 1; n > 0; loopcnt = 1) {
111 r = runpcs(SINGLE, keepnote);
112 if(pc2line(dot, &curr) < 0)
113 error("%r");
114 if (line != curr) { /* on a new line of c */
115 line = curr;
116 n--;
119 loopcnt = 0;
120 break;
121 /* continue with optional note */
122 case 'c':
123 case 'C':
124 if (pid==0)
125 error(NOPCS);
126 runmode=CONTIN;
127 keepnote=defval(1);
128 break;
130 case 'n': /* deal with notes */
131 if (pid==0)
132 error(NOPCS);
133 n=defval(-1);
134 if(n>=0 && n<nnote){
135 nnote--;
136 memmove(note[n], note[n+1], (nnote-n)*sizeof(note[0]));
138 notes();
139 return;
141 case 'h': /* halt the current process */
142 if (adrflg && adrval == 0) {
143 if (pid == 0)
144 error(NOPCS);
145 ungrab();
147 else {
148 grab();
149 dprint("stopped at%16t");
150 goto Return;
152 return;
154 case 'x': /* continue executing the current process */
155 if (pid == 0)
156 error(NOPCS);
157 ungrab();
158 return;
160 default:
161 error("bad `:' command");
164 if (loopcnt>0) {
165 dprint("%s: running\n", symfil);
166 flush();
167 r = runpcs(runmode,keepnote);
169 if (r)
170 dprint("breakpoint%16t");
171 else
172 dprint("stopped at%16t");
173 Return:
174 delbp();
175 printpc();
176 notes();