1: # 2: /* 3: * 4: * UNIX debugger 5: * 6: */ 7: 8: #include "defs.h" 9: 10: 11: MSG ODDADR; 12: MSG BADDAT; 13: MSG BADTXT; 14: MAP txtmap; 15: MAP datmap; 16: INT wtflag; 17: STRING errflg; 18: INT errno; 19: 20: INT pid; 21: 22: struct ovhead ovlseg; 23: L_INT ovloff[]; 24: OVTAG curov; 25: int overlay; 26: 27: L_INT var[]; 28: 29: 30: 31: /* file handling and access routines */ 32: 33: put(adr,space,value) 34: L_INT adr; 35: { 36: access(WT,adr,space,value); 37: } 38: 39: POS get(adr, space) 40: L_INT adr; 41: { 42: return(access(RD,adr,space,0)); 43: } 44: 45: POS chkget(n, space) 46: L_INT n; 47: { 48: REG INT w; 49: 50: w = get(n, space); 51: chkerr(); 52: return(w); 53: } 54: 55: access(mode,adr,space,value) 56: L_INT adr; 57: { 58: INT w, w1, pmode, rd, file; 59: BKPTR bkptr, scanbkpt(); 60: rd = mode==RD; 61: 62: IF space == NSP THEN return(0); FI 63: 64: IF pid /* tracing on? */ 65: THEN IF (adr&01) ANDF !rd THEN error(ODDADR); FI 66: pmode = (space&DSP?(rd?RDUSER:WDUSER):(rd?RIUSER:WIUSER)); 67: if (bkptr=scanbkpt((POS)adr)) { 68: if (rd) { 69: return(bkptr->ins); 70: } else { 71: bkptr->ins = value; 72: return(0); 73: } 74: } 75: w = ptrace(pmode, pid, shorten(adr&~01), value); 76: IF adr&01 77: THEN w1 = ptrace(pmode, pid, shorten(adr+1), value); 78: w = (w>>8)&LOBYTE | (w1<<8); 79: FI 80: IF errno 81: THEN errflg = (space&DSP ? BADDAT : BADTXT); 82: FI 83: return(w); 84: FI 85: w = 0; 86: IF mode==WT ANDF wtflag==0 87: THEN error("not in write mode"); 88: FI 89: IF !chkmap(&adr,space) 90: THEN return(0); 91: FI 92: file=(space&DSP?datmap.ufd:txtmap.ufd); 93: IF longseek(file,adr)==0 ORF 94: (rd ? read(file,&w,2) : write(file,&value,2)) < 1 95: THEN errflg=(space&DSP?BADDAT:BADTXT); 96: FI 97: return(w); 98: 99: } 100: 101: chkmap(adr,space) 102: REG L_INT *adr; 103: REG INT space; 104: { 105: REG MAPPTR amap; 106: amap=((space&DSP?&datmap:&txtmap)); 107: switch(space&(ISP|DSP|STAR)) { 108: 109: case ISP: 110: IF within(*adr, amap->b1, amap->e1) 111: THEN *adr += (amap->f1) - (amap->b1); 112: break; 113: ELIF within(*adr, amap->bo, amap->eo) 114: THEN *adr += (amap->fo) - (amap->bo); 115: break; 116: FI 117: /* falls through */ 118: 119: case ISP+STAR: 120: IF within(*adr, amap->b2, amap->e2) 121: THEN *adr += (amap->f2) - (amap->b2); 122: break; 123: ELSE goto error; 124: FI 125: 126: case DSP: 127: IF within(*adr, amap->b1, amap->e1) 128: THEN *adr += (amap->f1) - (amap->b1); 129: break; 130: FI 131: /* falls through */ 132: 133: case DSP+STAR: 134: IF within(*adr, amap->b2, amap->e2) 135: THEN *adr += (amap->f2) - (amap->b2); 136: break; 137: FI 138: /* falls through */ 139: 140: default: 141: error: 142: errflg = (space&DSP ? BADDAT: BADTXT); 143: return(0); 144: } 145: return(1); 146: } 147: 148: setovmap(ovno) 149: OVTAG ovno; 150: { 151: REG MAPPTR amap; 152: 153: if ((!overlay) || (ovno < 0) || (ovno > 7)) 154: return; 155: amap = &txtmap; 156: IF ovno == 0 157: THEN amap->eo = amap->bo; 158: amap->fo = 0; 159: ELSE amap->eo = amap->bo + ovlseg.ov[ovno-1]; 160: amap->fo = ovloff[ovno-1]; 161: FI 162: var[VARC] = curov = ovno; 163: if (pid) 164: choverlay(ovno); 165: } 166: 167: within(adr,lbd,ubd) 168: L_INT adr, lbd, ubd; 169: { 170: return(adr>=lbd && adr<ubd); 171: }