3 84114f06 2004-04-19 devnull * debugger
7 84114f06 2004-04-19 devnull #include "defs.h"
8 84114f06 2004-04-19 devnull #include "fns.h"
10 84114f06 2004-04-19 devnull BKPT *bkpthead;
12 84114f06 2004-04-19 devnull BOOL bpin;
15 84114f06 2004-04-19 devnull int nnote;
16 84114f06 2004-04-19 devnull int ending;
17 84114f06 2004-04-19 devnull char note[NNOTE][ERRMAX];
19 84114f06 2004-04-19 devnull /* service routines for sub process control */
22 84114f06 2004-04-19 devnull runpcs(int runmode, int keepnote)
25 84114f06 2004-04-19 devnull BKPT *bkpt;
29 84114f06 2004-04-19 devnull if (adrflg)
30 84114f06 2004-04-19 devnull rput(correg, mach->pc, dot);
31 84114f06 2004-04-19 devnull if(rget(correg, mach->pc, &dot) < 0)
32 84114f06 2004-04-19 devnull error("%r");
34 84114f06 2004-04-19 devnull while (--loopcnt >= 0) {
35 84114f06 2004-04-19 devnull if(loopcnt != 0)
36 84114f06 2004-04-19 devnull printpc();
37 84114f06 2004-04-19 devnull if (runmode == SINGLE) {
38 84114f06 2004-04-19 devnull bkpt = scanbkpt(dot);
39 84114f06 2004-04-19 devnull if (bkpt) {
40 84114f06 2004-04-19 devnull switch(bkpt->flag){
41 84114f06 2004-04-19 devnull case BKPTTMP:
42 84114f06 2004-04-19 devnull bkpt->flag = BKPTCLR;
44 84114f06 2004-04-19 devnull case BKPTSKIP:
45 84114f06 2004-04-19 devnull bkpt->flag = BKPTSET;
49 84114f06 2004-04-19 devnull runstep(dot, keepnote);
51 84114f06 2004-04-19 devnull if(rget(correg, mach->pc, &x) < 0)
52 84114f06 2004-04-19 devnull error("%r");
53 84114f06 2004-04-19 devnull if ((bkpt = scanbkpt(x)) != 0) {
54 84114f06 2004-04-19 devnull execbkpt(bkpt, keepnote);
55 84114f06 2004-04-19 devnull keepnote = 0;
58 84114f06 2004-04-19 devnull runrun(keepnote);
60 84114f06 2004-04-19 devnull keepnote = 0;
62 84114f06 2004-04-19 devnull if(rget(correg, mach->pc, &dot) < 0)
63 84114f06 2004-04-19 devnull error("%r");
64 84114f06 2004-04-19 devnull /* real note? */
65 84114f06 2004-04-19 devnull if (nnote > 0) {
66 84114f06 2004-04-19 devnull keepnote = 1;
68 84114f06 2004-04-19 devnull continue;
70 84114f06 2004-04-19 devnull bkpt = scanbkpt(dot);
71 84114f06 2004-04-19 devnull if(bkpt == 0){
72 84114f06 2004-04-19 devnull keepnote = 0;
74 84114f06 2004-04-19 devnull continue;
76 84114f06 2004-04-19 devnull /* breakpoint */
77 84114f06 2004-04-19 devnull if (bkpt->flag == BKPTTMP)
78 84114f06 2004-04-19 devnull bkpt->flag = BKPTCLR;
79 84114f06 2004-04-19 devnull else if (bkpt->flag == BKPTSKIP) {
80 84114f06 2004-04-19 devnull execbkpt(bkpt, keepnote);
81 84114f06 2004-04-19 devnull keepnote = 0;
82 84114f06 2004-04-19 devnull loopcnt++; /* we didn't really stop */
83 84114f06 2004-04-19 devnull continue;
86 84114f06 2004-04-19 devnull bkpt->flag = BKPTSKIP;
87 84114f06 2004-04-19 devnull --bkpt->count;
88 84114f06 2004-04-19 devnull if ((bkpt->comm[0] == EOR || command(bkpt->comm, ':') != 0)
89 84114f06 2004-04-19 devnull && bkpt->count != 0) {
90 84114f06 2004-04-19 devnull execbkpt(bkpt, keepnote);
91 84114f06 2004-04-19 devnull keepnote = 0;
92 84114f06 2004-04-19 devnull loopcnt++;
93 84114f06 2004-04-19 devnull continue;
95 84114f06 2004-04-19 devnull bkpt->count = bkpt->initcnt;
99 84114f06 2004-04-19 devnull return(rc);
103 84114f06 2004-04-19 devnull * finish the process off;
104 84114f06 2004-04-19 devnull * kill if still running
108 84114f06 2004-04-19 devnull endpcs(void)
110 84114f06 2004-04-19 devnull BKPT *bk;
112 84114f06 2004-04-19 devnull if(ending)
114 84114f06 2004-04-19 devnull ending = 1;
115 84114f06 2004-04-19 devnull if (pid) {
116 84114f06 2004-04-19 devnull if(pcsactive){
117 84114f06 2004-04-19 devnull killpcs();
118 84114f06 2004-04-19 devnull pcsactive = 0;
121 84114f06 2004-04-19 devnull nnote=0;
122 84114f06 2004-04-19 devnull for (bk=bkpthead; bk; bk = bk->nxtbkpt)
123 84114f06 2004-04-19 devnull if (bk->flag == BKPTTMP)
124 84114f06 2004-04-19 devnull bk->flag = BKPTCLR;
125 84114f06 2004-04-19 devnull else if (bk->flag != BKPTCLR)
126 84114f06 2004-04-19 devnull bk->flag = BKPTSET;
128 84114f06 2004-04-19 devnull bpin = FALSE;
129 84114f06 2004-04-19 devnull ending = 0;
133 84114f06 2004-04-19 devnull * start up the program to be debugged in a child
137 84114f06 2004-04-19 devnull setup(void)
140 84114f06 2004-04-19 devnull nnote = 0;
141 84114f06 2004-04-19 devnull startpcs();
142 84114f06 2004-04-19 devnull bpin = FALSE;
143 84114f06 2004-04-19 devnull pcsactive = 1;
147 84114f06 2004-04-19 devnull * skip over a breakpoint:
148 84114f06 2004-04-19 devnull * remove breakpoints, then single step
149 84114f06 2004-04-19 devnull * so we can put it back
152 84114f06 2004-04-19 devnull execbkpt(BKPT *bk, int keepnote)
154 84114f06 2004-04-19 devnull runstep(bk->loc, keepnote);
155 84114f06 2004-04-19 devnull bk->flag = BKPTSET;
159 84114f06 2004-04-19 devnull * find the breakpoint at adr, if any
163 84114f06 2004-04-19 devnull scanbkpt(ADDR adr)
165 84114f06 2004-04-19 devnull BKPT *bk;
167 84114f06 2004-04-19 devnull for (bk = bkpthead; bk; bk = bk->nxtbkpt)
168 84114f06 2004-04-19 devnull if (bk->flag != BKPTCLR && bk->loc == adr)
170 84114f06 2004-04-19 devnull return(bk);
174 84114f06 2004-04-19 devnull * remove all breakpoints from the process' address space
178 84114f06 2004-04-19 devnull delbp(void)
180 84114f06 2004-04-19 devnull BKPT *bk;
182 84114f06 2004-04-19 devnull if (bpin == FALSE || pid == 0)
184 84114f06 2004-04-19 devnull for (bk = bkpthead; bk; bk = bk->nxtbkpt)
185 84114f06 2004-04-19 devnull if (bk->flag != BKPTCLR)
186 84114f06 2004-04-19 devnull bkput(bk, 0);
187 84114f06 2004-04-19 devnull bpin = FALSE;
191 84114f06 2004-04-19 devnull * install all the breakpoints
195 84114f06 2004-04-19 devnull setbp(void)
197 84114f06 2004-04-19 devnull BKPT *bk;
199 84114f06 2004-04-19 devnull if (bpin == TRUE || pid == 0)
201 84114f06 2004-04-19 devnull for (bk = bkpthead; bk; bk = bk->nxtbkpt)
202 84114f06 2004-04-19 devnull if (bk->flag != BKPTCLR)
203 84114f06 2004-04-19 devnull bkput(bk, 1);
204 84114f06 2004-04-19 devnull bpin = TRUE;