1: #
   2: /*
   3:  *
   4:  *	UNIX debugger
   5:  *
   6:  */
   7: 
   8: #include "defs.h"
   9: 
  10: 
  11: MSG     NOFORK;
  12: MSG     ENDPCS;
  13: MSG     BADWAIT;
  14: 
  15: CHAR        *lp;
  16: INT     sigint;
  17: INT     sigqit;
  18: 
  19: /* breakpoints */
  20: BKPTR       bkpthead;
  21: 
  22: REGLIST     reglist[];
  23: 
  24: CHAR        lastc;
  25: POS     corhdr[];
  26: POS     *uar0;
  27: int     overlay;
  28: OVTAG       curov;
  29: 
  30: INT     fcor;
  31: INT     fsym;
  32: STRING      errflg;
  33: INT     errno;
  34: INT     signo;
  35: 
  36: L_INT       dot;
  37: STRING      symfil;
  38: INT     wtflag;
  39: INT     pid;
  40: L_INT       expv;
  41: INT     adrflg;
  42: L_INT       loopcnt;
  43: L_INT       var[];
  44: 
  45: 
  46: 
  47: 
  48: 
  49: /* service routines for sub process control */
  50: 
  51: getsig(sig)
  52: {   return(expr(0) ? shorten(expv) : sig);
  53: }
  54: 
  55: INT     userpc=1;
  56: 
  57: runpcs(runmode, execsig)
  58: {
  59:     INT     rc;
  60:     REG BKPTR   bkpt;
  61:     IF adrflg
  62:     THEN userpc=shorten(dot);
  63:     FI
  64:     if (overlay)
  65:         choverlay((U *)corhdr->u_ovdata.uo_curov);
  66:     printf("%s: running\n", symfil);
  67: 
  68:     WHILE (loopcnt--)>0
  69:     DO
  70: #ifdef DEBUG
  71:         printf("\ncontinue %d %d\n",userpc,execsig);
  72: #endif
  73:         stty(0,&usrtty);
  74:         ptrace(runmode,pid,userpc,execsig);
  75:         bpwait(); chkerr(); readregs();
  76: 
  77:         /*look for bkpt*/
  78:         IF signo==0 ANDF (bkpt=scanbkpt(uar0[PC]-2))
  79:         THEN /*stopped at bkpt*/
  80:              userpc=uar0[PC]=bkpt->loc;
  81:              IF bkpt->flag==BKPTEXEC
  82:             ORF ((bkpt->flag=BKPTEXEC, command(bkpt->comm,':')) ANDF --bkpt->count)
  83:              THEN execbkpt(bkpt); execsig=0; loopcnt++;
  84:               userpc=1;
  85:              ELSE bkpt->count=bkpt->initcnt;
  86:               rc=1;
  87:              FI
  88:         ELSE rc=0; execsig=signo; userpc=1;
  89:         FI
  90:     OD
  91:     return(rc);
  92: }
  93: 
  94: endpcs()
  95: {
  96:     REG BKPTR   bkptr;
  97:     IF pid
  98:     THEN ptrace(EXIT,pid,0,0); pid=0; userpc=1;
  99:          FOR bkptr=bkpthead; bkptr; bkptr=bkptr->nxtbkpt
 100:          DO IF bkptr->flag
 101:         THEN bkptr->flag=BKPTSET;
 102:         FI
 103:          OD
 104:     FI
 105: }
 106: 
 107: setup()
 108: {
 109:     close(fsym); fsym = -1;
 110:     IF (pid = fork()) == 0
 111:     THEN ptrace(SETTRC,0,0,0);
 112:          signal(SIGINT,sigint); signal(SIGQUIT,sigqit);
 113:          doexec(); exit(0);
 114:     ELIF pid == -1
 115:     THEN error(NOFORK);
 116:     ELSE bpwait(); readregs(); lp[0]=EOR; lp[1]=0;
 117:          fsym=open(symfil,wtflag);
 118:          IF errflg
 119:          THEN printf("%s: cannot execute\n",symfil);
 120:           endpcs(); error(0);
 121:          FI
 122:     FI
 123: }
 124: 
 125: execbkpt(bkptr)
 126: BKPTR   bkptr;
 127: {   INT     bkptloc;
 128: #ifdef DEBUG
 129:     printf("exbkpt: %d\n",bkptr->count);
 130: #endif
 131:     bkptloc = bkptr->loc;
 132:     ptrace(WIUSER,pid,bkptloc,bkptr->ins);
 133:     stty(0,&usrtty);
 134:     ptrace(SINGLE,pid,bkptloc,0);
 135:     bpwait(); chkerr();
 136:     ptrace(WIUSER,pid,bkptloc,BPT);
 137:     bkptr->flag=BKPTSET;
 138: }
 139: 
 140: 
 141: doexec()
 142: {
 143:     STRING      argl[MAXARG];
 144:     CHAR        args[LINSIZ];
 145:     STRING      p, *ap, filnam;
 146:     ap=argl; p=args;
 147:     *ap++=symfil;
 148:     REP IF rdc()==EOR THEN break; FI
 149:         *ap = p;
 150:         WHILE lastc!=EOR ANDF lastc!=SP ANDF lastc!=TB DO *p++=lastc; readchar(); OD
 151:         *p++=0; filnam = *ap+1;
 152:         IF **ap=='<'
 153:         THEN    close(0);
 154:             IF open(filnam,0)<0
 155:             THEN    printf("%s: cannot open\n",filnam); exit(0);
 156:             FI
 157:         ELIF **ap=='>'
 158:         THEN    close(1);
 159:             IF creat(filnam,0666)<0
 160:             THEN    printf("%s: cannot create\n",filnam); exit(0);
 161:             FI
 162:         ELSE    ap++;
 163:         FI
 164:     PER lastc!=EOR DONE
 165:     *ap++=0;
 166:     execv(symfil, argl);
 167: }
 168: 
 169: BKPTR   scanbkpt(adr)
 170: {
 171:     REG BKPTR   bkptr;
 172:     FOR bkptr=bkpthead; bkptr; bkptr=bkptr->nxtbkpt
 173:     DO IF bkptr->flag ANDF bkptr->loc==adr ANDF
 174:       (bkptr->ovly == 0 || bkptr->ovly==curov)
 175:        THEN break;
 176:        FI
 177:     OD
 178:     return(bkptr);
 179: }
 180: 
 181: delbp()
 182: {
 183:     REG BKPTR   bkptr;
 184:     FOR bkptr=bkpthead; bkptr; bkptr=bkptr->nxtbkpt
 185:     DO IF bkptr->flag
 186:        THEN del1bp(bkptr);
 187:        FI
 188:     OD
 189: }
 190: 
 191: del1bp(bkptr)
 192: BKPTR bkptr;
 193: {
 194:     if (bkptr->ovly)
 195:         choverlay(bkptr->ovly);
 196:     ptrace(WIUSER,pid,bkptr->loc,bkptr->ins);
 197: }
 198: 
 199: /* change overlay in subprocess */
 200: choverlay(ovno)
 201: OVTAG ovno;
 202: {
 203:     errno = 0;
 204:     if (overlay && pid && ovno>0 && ovno<=7)
 205:         ptrace(WUREGS,pid,&((U *)0->u_ovdata.uo_curov),ovno);
 206:     IF errno
 207:     THEN printf("cannot change to overlay %d\n", ovno);
 208:     FI
 209: }
 210: 
 211: setbp()
 212: {
 213:     REG BKPTR   bkptr;
 214: 
 215:     FOR bkptr=bkpthead; bkptr; bkptr=bkptr->nxtbkpt
 216:     DO IF bkptr->flag
 217:        THEN set1bp(bkptr);
 218:        FI
 219:     OD
 220: }
 221: set1bp(bkptr)
 222: BKPTR bkptr;
 223: {
 224:     REG INT     a;
 225:     a = bkptr->loc;
 226:     if (bkptr->ovly)
 227:         choverlay(bkptr->ovly);
 228:     bkptr->ins = ptrace(RIUSER, pid, a, 0);
 229:     ptrace(WIUSER, pid, a, BPT);
 230:     IF errno
 231:     THEN prints("cannot set breakpoint: ");
 232:          psymoff(leng(bkptr->loc),ISYM,"\n");
 233:     FI
 234: }
 235: 
 236: bpwait()
 237: {
 238:     REG INT w;
 239:     INT stat;
 240: 
 241:     signal(SIGINT, 1);
 242:     WHILE (w = wait(&stat))!=pid ANDF w != -1 DONE
 243:     signal(SIGINT,sigint);
 244:     gtty(0,&usrtty);
 245:     stty(0,&adbtty);
 246:     IF w == -1
 247:     THEN pid=0;
 248:          errflg=BADWAIT;
 249:     ELIF (stat & 0177) != 0177
 250:     THEN IF signo = stat&0177
 251:          THEN sigprint();
 252:          FI
 253:          IF stat&0200
 254:          THEN prints(" - core dumped");
 255:           close(fcor);
 256:           setcor();
 257:          FI
 258:          pid=0;
 259:          errflg=ENDPCS;
 260:     ELSE signo = stat>>8;
 261:          IF signo!=SIGTRAP
 262:          THEN sigprint();
 263:          ELSE signo=0;
 264:          FI
 265:          flushbuf();
 266:     FI
 267: }
 268: 
 269: readregs()
 270: {
 271:     /*get REG values from pcs*/
 272:     REG i;
 273:     FOR i=0; i<NREG; i++
 274:     DO uar0[reglist[i].roffs] =
 275:             ptrace(RUREGS, pid, (int)&uar0[reglist[i].roffs]-
 276:             (int)&corhdr, 0);
 277:     OD
 278:     /* if overlaid, get ov */
 279:     IF overlay
 280:     THEN    OVTAG ovno;
 281:         ovno = ptrace(RUREGS, pid,
 282:             &(((struct user *)0)->u_ovdata.uo_curov),0);
 283:         var[VARC] = ovno;
 284:         ((U *)corhdr)->u_ovdata.uo_curov = ovno;
 285:         setovmap(ovno);
 286:     FI
 287: 
 288: #ifndef NONFP
 289:     /* REALing poINT		*/
 290:     FOR i=FROFF; i<FRLEN+FROFF; i++
 291:     DO corhdr[i] = ptrace(RUREGS,pid,i,0); OD
 292: #endif
 293: }

Defined functions

bpwait defined in line 236; used 3 times
choverlay defined in line 200; used 4 times
del1bp defined in line 191; used 3 times
delbp defined in line 181; never used
doexec defined in line 141; used 1 times
endpcs defined in line 94; used 1 times
execbkpt defined in line 125; used 1 times
  • in line 83
getsig defined in line 51; used 2 times
readregs defined in line 269; used 2 times
runpcs defined in line 57; used 1 times
scanbkpt defined in line 169; used 6 times
set1bp defined in line 221; used 2 times
setbp defined in line 211; used 1 times
setup defined in line 107; used 2 times

Defined variables

overlay defined in line 27; used 3 times
Last modified: 1982-08-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1167
Valid CSS Valid XHTML 1.0 Strict