126418Ssam #ifndef lint 2*30720Sbostic static char sccsid[] = "@(#)format.c 1.3 (Berkeley) 04/01/87"; 326418Ssam #endif 426418Ssam /* 526418Ssam * 626418Ssam * UNIX debugger 726418Ssam * 826418Ssam */ 926418Ssam 1026418Ssam #include "defs.h" 1126418Ssam 1226418Ssam MSG BADMOD; 1326418Ssam MSG NOFORK; 1426418Ssam MSG ADWRAP; 1526418Ssam 1626418Ssam INT mkfault; 1726418Ssam CHAR *lp; 1826418Ssam ADDR maxoff; 1926418Ssam SIG sigint; 2026418Ssam SIG sigqit; 2126418Ssam STRING errflg; 2226418Ssam CHAR lastc,peekc; 2326418Ssam L_INT dot; 2426418Ssam INT dotinc; 2526418Ssam L_INT expv; 2626418Ssam L_INT var[]; 2726418Ssam 2826418Ssam scanform(icount,ifp,itype,ptype) 2926418Ssam L_INT icount; 3026418Ssam STRING ifp; 3126418Ssam { 3226418Ssam REG STRING fp; 3326418Ssam CHAR modifier; 3426418Ssam REG fcount, init=1; 3526418Ssam L_INT savdot; 3626418Ssam BOOL exact; 3726418Ssam 3826418Ssam WHILE icount 3926418Ssam DO fp=ifp; 4026418Ssam savdot=dot; init=0; 4126418Ssam 4226418Ssam IF init==0 ANDF (exact=(findsym(dot,ptype)==0)) ANDF maxoff 4326418Ssam THEN printf("\n%s:%16t",cursym->n_un.n_name); 4426418Ssam FI 4526418Ssam 4626418Ssam /*now loop over format*/ 4726418Ssam WHILE *fp ANDF errflg==0 4826418Ssam DO IF isdigit(modifier = *fp) 4926418Ssam THEN fcount = 0; 5026418Ssam WHILE isdigit(modifier = *fp++) 5126418Ssam DO fcount *= 10; 5226418Ssam fcount += modifier-'0'; 5326418Ssam OD 5426418Ssam fp--; 5526418Ssam ELSE fcount = 1; 5626418Ssam FI 5726418Ssam 5826418Ssam IF *fp==0 THEN break; FI 5926418Ssam /* check for entry mask */ 6026418Ssam IF exact ANDF dot==savdot ANDF 6126418Ssam (cursym->n_type&N_TYPE)==N_TEXT ANDF 6226418Ssam cursym->n_un.n_name[0]=='_' ANDF *fp=='i' 6326418Ssam THEN exform(1,"x",itype,ptype); fp++; printc(EOR); 6426418Ssam ELSE fp=exform(fcount,fp,itype,ptype); 6526418Ssam FI 6626418Ssam OD 6726418Ssam dotinc=dot-savdot; 6826418Ssam dot=savdot; 6926418Ssam 7026418Ssam IF errflg 7126418Ssam THEN IF icount<0 7226418Ssam THEN errflg=0; break; 7326418Ssam ELSE error(errflg); 7426418Ssam FI 7526418Ssam FI 7626418Ssam IF --icount 7726418Ssam THEN dot=inkdot(dotinc); 7826418Ssam FI 7926418Ssam IF mkfault THEN error(0); FI 8026418Ssam OD 8126418Ssam } 8226418Ssam 8326418Ssam STRING 8426418Ssam exform(fcount,ifp,itype,ptype) 8526418Ssam INT fcount; 8626418Ssam STRING ifp; 8726418Ssam { 8826418Ssam /* execute single format item `fcount' times 8926418Ssam * sets `dotinc' and moves `dot' 9026418Ssam * returns address of next format item 9126418Ssam */ 9226418Ssam REG POS w; 9326418Ssam REG L_INT savdot, wx; 9426418Ssam REG STRING fp; 9526418Ssam CHAR c, modifier, longpr; 9626418Ssam union{ /* compatible with both VAX and TAHOE */ 9726418Ssam L_REAL d; 9826418Ssam INT s[4]; 9926418Ssam }fw; 10026418Ssam 10126418Ssam WHILE fcount>0 10226418Ssam DO fp = ifp; c = *fp; 10326418Ssam longpr=(c>='A')&&(c<='Z')||(c=='f')||(c=='4')||(c=='p'); 10426418Ssam IF itype==NSP ORF *fp=='a' 10526418Ssam THEN wx=dot; w=dot; 10630131Ssam IF c=='b' ORF c=='B' ORF c=='c' ORF c=='C' ORF c=='1' 10730131Ssam THEN w=btol(wx); FI 10826418Ssam ELSE wx=get(dot,itype); 10926418Ssam w=shorten(wx); 11026418Ssam FI 11126418Ssam IF errflg THEN return(fp); FI 11226418Ssam IF mkfault THEN error(0); FI 11326418Ssam var[0]=wx; 11426418Ssam modifier = *fp++; 11526418Ssam dotinc=(longpr?4:2); 11626418Ssam 11726418Ssam IF charpos()==0 ANDF modifier!='a' THEN printf("%16m"); FI 11826418Ssam 11926418Ssam switch(modifier) { 12026418Ssam 12126418Ssam case SP: case TB: 12226418Ssam break; 12326418Ssam 12426418Ssam case 't': case 'T': 12526418Ssam printf("%T",fcount); return(fp); 12626418Ssam 12726418Ssam case 'r': case 'R': 12826418Ssam printf("%M",fcount); return(fp); 12926418Ssam 13026418Ssam case 'a': 13126418Ssam psymoff(dot,ptype,":%16t"); dotinc=0; break; 13226418Ssam 13326418Ssam case 'p': 13426418Ssam psymoff(var[0],ptype,"%16t"); break; 13526418Ssam 13626418Ssam case 'u': 13726418Ssam printf("%-8u",w); break; 13826418Ssam 13926418Ssam case 'U': 14026418Ssam printf("%-16U",wx); break; 14126418Ssam 14226418Ssam case 'c': case 'C': 14326418Ssam IF modifier=='C' 14430131Ssam THEN printesc(byte(w)); 14530131Ssam ELSE printc(byte(w)); 14626418Ssam FI 14726418Ssam dotinc=1; break; 14826418Ssam 14926418Ssam case 'b': case 'B': 15030131Ssam printf("%-8o", byte(w)); dotinc=1; break; 15126418Ssam 15226418Ssam case '1': 15326418Ssam printf("%-8R", byte(wx)); dotinc=1; break; 15426418Ssam 15526418Ssam case '2': 15626418Ssam case 'w': 15726418Ssam printf("%-8R", w); break; 15826418Ssam 15926418Ssam case '4': 16026418Ssam case 'W': 16126418Ssam printf("%-16R", wx); break; 16226418Ssam 16326418Ssam case 's': case 'S': 16426418Ssam savdot=dot; dotinc=1; 16526418Ssam WHILE (c=byte(get(dot,itype))) ANDF errflg==0 16626418Ssam DO dot=inkdot(1); 16726418Ssam IF modifier == 'S' 16826418Ssam THEN printesc(c); 16926418Ssam ELSE printc(c); 17026418Ssam FI 17126418Ssam endline(); 17226418Ssam OD 17326418Ssam dotinc=dot-savdot+1; dot=savdot; break; 17426418Ssam 17526418Ssam case 'x': 17626418Ssam printf("%-8x",w); break; 17726418Ssam 17826418Ssam case 'X': 17926418Ssam printf("%-16X", wx); break; 18026418Ssam 18126418Ssam case 'z': 18226418Ssam printf("%-8z",w); break; 18326418Ssam 18426418Ssam case 'Z': 18526418Ssam printf("%-16Z", wx); break; 18626418Ssam 18726418Ssam case 'Y': 18826418Ssam printf("%-24Y", wx); break; 18926418Ssam 19026418Ssam case 'q': 19126418Ssam printf("%-8q", w); break; 19226418Ssam 19326418Ssam case 'Q': 19426418Ssam printf("%-16Q", wx); break; 19526418Ssam 19626418Ssam case 'o': 19726418Ssam printf("%-8o", w); break; 19826418Ssam 19926418Ssam case 'O': 20026418Ssam printf("%-16O", wx); break; 20126418Ssam 20226418Ssam case 'i': 20326418Ssam case 'I': 20426418Ssam printins(itype,wx); printc(EOR); break; 20526418Ssam 20626418Ssam case 'd': 20726418Ssam printf("%-8d", w); break; 20826418Ssam 20926418Ssam case 'D': 21026418Ssam printf("%-16D", wx); break; 21126418Ssam 21226418Ssam case 'f': 213*30720Sbostic if ((w & ~0xFFFF00FF) == 0x8000) 214*30720Sbostic printf("(reserved oprnd)"); 215*30720Sbostic else { 216*30720Sbostic fw.d = 0; 217*30720Sbostic fw.s[0] = w; 218*30720Sbostic fw.s[1] = wx&0xffff; 219*30720Sbostic printf("%-16.9f", fw.d); 220*30720Sbostic } 221*30720Sbostic dotinc = 4; 222*30720Sbostic break; 22326418Ssam 22426418Ssam case 'F': /* may be done with one get call on TAHOE */ 225*30720Sbostic if ((w & ~0xFFFF00FF) == 0x8000) 226*30720Sbostic printf("(reserved oprnd)"); 227*30720Sbostic else { 228*30720Sbostic fw.s[2] = shorten(get(inkdot(4),itype)); 229*30720Sbostic fw.s[3] = shorten(get(inkdot(6),itype)); 230*30720Sbostic if (errflg) 231*30720Sbostic return(fp); 232*30720Sbostic fw.s[0] = w; 233*30720Sbostic fw.s[1] = wx&0xffff; 234*30720Sbostic printf("%-32.18F", fw.d); 235*30720Sbostic } 236*30720Sbostic dotinc = 8; 237*30720Sbostic break; 23826418Ssam 23926418Ssam case 'n': case 'N': 24026418Ssam printc('\n'); dotinc=0; break; 24126418Ssam 24226418Ssam case '"': 24326418Ssam dotinc=0; 24426418Ssam WHILE *fp != '"' ANDF *fp 24526418Ssam DO printc(*fp++); OD 24626418Ssam IF *fp THEN fp++; FI 24726418Ssam break; 24826418Ssam 24926418Ssam case '^': 25026418Ssam dot=inkdot(-dotinc*fcount); return(fp); 25126418Ssam 25226418Ssam case '+': 25326418Ssam dot=inkdot(fcount); return(fp); 25426418Ssam 25526418Ssam case '-': 25626418Ssam dot=inkdot(-fcount); return(fp); 25726418Ssam 25826418Ssam default: error(BADMOD); 25926418Ssam } 26026418Ssam IF itype!=NSP 26126418Ssam THEN dot=inkdot(dotinc); 26226418Ssam FI 26326418Ssam fcount--; endline(); 26426418Ssam OD 26526418Ssam 26626418Ssam return(fp); 26726418Ssam } 26826418Ssam 26926418Ssam shell() 27026418Ssam { 27126418Ssam #ifndef EDDT 27226418Ssam REG rc, unixpid; 27326418Ssam int status; 27426418Ssam REG STRING argp = lp; 27526418Ssam STRING getenv(), shell = getenv("SHELL"); 27626418Ssam #ifdef VFORK 27726418Ssam char oldstlp; 27826418Ssam #endif 27926418Ssam 28026418Ssam if (shell == 0) 28126418Ssam shell = "/bin/sh"; 28226418Ssam WHILE lastc!=EOR DO rdc(); OD 28326418Ssam #ifndef VFORK 28426418Ssam IF (unixpid=fork())==0 28526418Ssam #else 28626418Ssam oldstlp = *lp; 28726418Ssam IF (unixpid=vfork())==0 28826418Ssam #endif 28926418Ssam THEN signal(SIGINT,sigint); signal(SIGQUIT,sigqit); 29026418Ssam *lp=0; execl(shell, "sh", "-c", argp, 0); 29126418Ssam _exit(16); 29226418Ssam #ifndef VFORK 29326418Ssam ELIF unixpid == -1 29426418Ssam #else 29526418Ssam ELIF *lp = oldstlp, unixpid == -1 29626418Ssam #endif 29726418Ssam THEN error(NOFORK); 29826418Ssam ELSE signal(SIGINT,1); 29926418Ssam WHILE (rc = wait(&status)) != unixpid ANDF rc != -1 DONE 30026418Ssam signal(SIGINT,sigint); 30126418Ssam printc('!'); lp--; 30226418Ssam FI 30326418Ssam #endif 30426418Ssam } 30526418Ssam 30626418Ssam 30726418Ssam printesc(c) 30826418Ssam REG c; 30926418Ssam { 31026418Ssam c &= STRIP; 31126418Ssam IF c==0177 ORF c<SP 31226418Ssam THEN printf("^%c", c ^ 0100); 31326418Ssam ELSE printc(c); 31426418Ssam FI 31526418Ssam } 31626418Ssam 31726418Ssam L_INT inkdot(incr) 31826418Ssam { 31926418Ssam REG L_INT newdot; 32026418Ssam 32126418Ssam newdot=dot+incr; 32226418Ssam IF (dot ^ newdot) >> 24 THEN error(ADWRAP); FI 32326418Ssam return(newdot); 32426418Ssam } 325