Annotation of researchv9/cmd/adb/comm/runpcs.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *
                      3:  *     UNIX debugger
                      4:  *
                      5:  */
                      6: 
                      7: #include "defs.h"
                      8: #include "regs.h"
                      9: #include "bkpt.h"
                     10: 
                     11: BKPT *bkpthead;
                     12: 
                     13: BOOL bpin;
                     14: 
                     15: int pid;
                     16: int sigcode, signo;
                     17: 
                     18: /* service routines for sub process control */
                     19: 
                     20: runpcs(runmode, keepsig)
                     21: {
                     22:        register int rc;
                     23:        register BKPT *bkpt;
                     24: 
                     25:        if (adrflg)
                     26:                rput(PC, (TREG)dot);
                     27:        printf("%s: running\n", symfil);
                     28:        while (--loopcnt >= 0) {
                     29:                rrest();
                     30:                if (runmode == SINGLE)
                     31:                        runstep(keepsig);
                     32:                else {
                     33:                        if ((bkpt = scanbkpt((ADDR)rtow(rget(PC)))) != NULL) {
                     34:                                execbkpt(bkpt, keepsig);
                     35:                                keepsig = 0;
                     36:                        }
                     37:                        setbp();
                     38:                        runrun(keepsig);
                     39:                }
                     40:                keepsig = 0;
                     41:                bpwait();
                     42:                chkerr();
                     43:                delbp();
                     44:                /* real signal? */
                     45:                if (signo != 0) {
                     46:                        keepsig = 1;
                     47:                        rc = 0;
                     48:                        continue;
                     49:                }
                     50:                /* single step? */
                     51:                if ((bkpt = scanbkpt((ADDR)rtow(rget(PC)))) == NULL) {
                     52:                        keepsig = 0;
                     53:                        rc = 0;
                     54:                        continue;
                     55:                }
                     56:                /* breakpoint */
                     57:                dot = bkpt->loc;
                     58:                if (bkpt->flag == BKPTTMP)
                     59:                        bkpt->flag = BKPTCLR;
                     60:                else if (bkpt->flag == BKPTSKIP) {
                     61:                        execbkpt(bkpt, keepsig);
                     62:                        keepsig = 0;
                     63:                        loopcnt++;      /* we didn't really stop */
                     64:                        continue;
                     65:                }
                     66:                else {
                     67:                        bkpt->flag = BKPTSKIP;
                     68:                        --bkpt->count;
                     69:                        if ((bkpt->comm[0] != EOR && command(bkpt->comm, ':') == 0)
                     70:                        ||  bkpt->count != 0) {
                     71:                                execbkpt(bkpt, keepsig);
                     72:                                keepsig = 0;
                     73:                                loopcnt++;
                     74:                                continue;
                     75:                        }
                     76:                        bkpt->count = bkpt->initcnt;
                     77:                }
                     78:                rc = 1;
                     79:        }
                     80:        return(rc);
                     81: }
                     82: 
                     83: /*
                     84:  * finish the process off;
                     85:  * kill if still running
                     86:  */
                     87: 
                     88: endpcs()
                     89: {
                     90:        register BKPT *bk;
                     91: 
                     92:        if (pid) {
                     93:                killpcs();
                     94:                pid=0;
                     95:                for (bk=bkpthead; bk; bk = bk->nxtbkpt)
                     96:                        if (bk->flag == BKPTTMP)
                     97:                                bk->flag = BKPTCLR;
                     98:                        else if (bk->flag != BKPTCLR)
                     99:                                bk->flag = BKPTSET;
                    100:        }
                    101:        bpin = FALSE;
                    102: }
                    103: 
                    104: /*
                    105:  * start up the program to be debugged in a child
                    106:  */
                    107: 
                    108: setup()
                    109: {
                    110: 
                    111:        startpcs();
                    112:        if (errflg) {
                    113:                printf("%s\n", errflg);
                    114:                printf("%s: cannot execute\n", symfil);
                    115:                endpcs();
                    116:                error(0);
                    117:        }
                    118:        bpin = FALSE;
                    119: }
                    120: 
                    121: /*
                    122:  * skip over a breakpoint:
                    123:  * remove breakpoints, then single step
                    124:  * so we can put it back
                    125:  */
                    126: execbkpt(bk, keepsig)
                    127: BKPT *bk;
                    128: {
                    129:        runstep(keepsig);
                    130:        bk->flag = BKPTSET;
                    131:        bpwait();
                    132:        chkerr();
                    133: }
                    134: 
                    135: /*
                    136:  * find the breakpoint at adr, if any
                    137:  */
                    138: 
                    139: BKPT *
                    140: scanbkpt(adr)
                    141: ADDR adr;
                    142: {
                    143:        register BKPT *bk;
                    144: 
                    145:        for (bk = bkpthead; bk; bk = bk->nxtbkpt)
                    146:                if (bk->flag != BKPTCLR && bk->loc == adr)
                    147:                        break;
                    148:        return(bk);
                    149: }
                    150: 
                    151: /*
                    152:  * remove all breakpoints from the process' address space
                    153:  */
                    154: 
                    155: delbp()
                    156: {
                    157:        register BKPT *bk;
                    158: 
                    159:        if (bpin == FALSE || pid == 0)
                    160:                return;
                    161:        for (bk = bkpthead; bk; bk = bk->nxtbkpt)
                    162:                if (bk->flag != BKPTCLR)
                    163:                        bkput(bk, 0);
                    164:        bpin = FALSE;
                    165: }
                    166: 
                    167: /*
                    168:  * install all the breakpoints
                    169:  */
                    170: 
                    171: setbp()
                    172: {
                    173:        register BKPT *bk;
                    174: 
                    175:        if (bpin == TRUE || pid == 0)
                    176:                return;
                    177:        for (bk = bkpthead; bk; bk = bk->nxtbkpt)
                    178:                if (bk->flag != BKPTCLR)
                    179:                        bkput(bk, 1);
                    180:        bpin = TRUE;
                    181: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.