123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- /*
- *
- * debugger
- *
- */
- #include "defs.h"
- #include "fns.h"
- void
- scanform(long icount, int prt, char *ifp, Map *map, int literal)
- {
- char *fp;
- char c;
- int fcount;
- ADDR savdot;
- int firstpass;
- firstpass = 1;
- while (icount) {
- fp=ifp;
- savdot=dot;
- /*now loop over format*/
- while (*fp) {
- if (!isdigit(*fp))
- fcount = 1;
- else {
- fcount = 0;
- while (isdigit(c = *fp++)) {
- fcount *= 10;
- fcount += c-'0';
- }
- fp--;
- }
- if (*fp==0)
- break;
- fp=exform(fcount,prt,fp,map,literal,firstpass);
- firstpass = 0;
- }
- dotinc=dot-savdot;
- dot=savdot;
- if (--icount)
- dot=inkdot(dotinc);
- }
- }
- char *
- exform(int fcount, int prt, char *ifp, Map *map, int literal, int firstpass)
- {
- /* execute single format item `fcount' times
- * sets `dotinc' and moves `dot'
- * returns address of next format item
- */
- uvlong v;
- ulong w;
- ADDR savdot;
- char *fp;
- char c, modifier;
- int i;
- ushort sh, *sp;
- uchar ch, *cp;
- Symbol s;
- char buf[512];
- extern int printcol;
- fp = 0;
- while (fcount > 0) {
- fp = ifp;
- c = *fp;
- modifier = *fp++;
- if (firstpass) {
- firstpass = 0;
- if (!literal && (c == 'i' || c == 'I' || c == 'M')
- && (dot & (mach->pcquant-1))) {
- dprint("warning: instruction not aligned");
- printc('\n');
- }
- if (prt && modifier != 'a' && modifier != 'A') {
- symoff(buf, 512, dot, CANY);
- dprint("%s%c%16t", buf, map==symmap? '?':'/');
- }
- }
- if (printcol==0 && modifier != 'a' && modifier != 'A')
- dprint("\t\t");
- switch(modifier) {
- case SPC:
- case TB:
- dotinc = 0;
- break;
- case 't':
- case 'T':
- dprint("%*t", fcount);
- dotinc = 0;
- return(fp);
- case 'a':
- symoff(buf, sizeof(buf), dot, CANY);
- dprint("%s%c%16t", buf, map==symmap? '?':'/');
- dotinc = 0;
- break;
- case 'A':
- dprint("%#llux%10t", dot);
- dotinc = 0;
- break;
- case 'p':
- if (get4(map, dot, &w) < 0)
- error("%r");
- symoff(buf, sizeof(buf), w, CANY);
- dprint("%s%16t", buf);
- dotinc = mach->szaddr;
- break;
- case 'u':
- case 'd':
- case 'x':
- case 'o':
- case 'q':
- if (literal)
- sh = (ushort) dot;
- else if (get2(map, dot, &sh) < 0)
- error("%r");
- w = sh;
- dotinc = 2;
- if (c == 'u')
- dprint("%-8lud", w);
- else if (c == 'x')
- dprint("%-8#lux", w);
- else if (c == 'd')
- dprint("%-8ld", w);
- else if (c == 'o')
- dprint("%-8#luo", w);
- else if (c == 'q')
- dprint("%-8#lo", w);
- break;
- case 'U':
- case 'D':
- case 'X':
- case 'O':
- case 'Q':
- if (literal)
- w = (long) dot;
- else if (get4(map, dot, &w) < 0)
- error("%r");
- dotinc = 4;
- if (c == 'U')
- dprint("%-16lud", w);
- else if (c == 'X')
- dprint("%-16#lux", w);
- else if (c == 'D')
- dprint("%-16ld", w);
- else if (c == 'O')
- dprint("%-#16luo", w);
- else if (c == 'Q')
- dprint("%-#16lo", w);
- break;
- case 'Z':
- case 'V':
- case 'Y':
- if (literal)
- v = dot;
- else if (get8(map, dot, &v) < 0)
- error("%r");
- dotinc = 8;
- if (c == 'Y')
- dprint("%-20#llux", v);
- else if (c == 'V')
- dprint("%-20lld", v);
- else if (c == 'Z')
- dprint("%-20llud", v);
- break;
- case 'B':
- case 'b':
- case 'c':
- case 'C':
- if (literal)
- ch = (uchar) dot;
- else if (get1(map, dot, &ch, 1) < 0)
- error("%r");
- if (modifier == 'C')
- printesc(ch);
- else if (modifier == 'B' || modifier == 'b')
- dprint("%-8#lux", (long) ch);
- else
- printc(ch);
- dotinc = 1;
- break;
- case 'r':
- if (literal)
- sh = (ushort) dot;
- else if (get2(map, dot, &sh) < 0)
- error("%r");
- dprint("%C", sh);
- dotinc = 2;
- break;
- case 'R':
- if (literal) {
- sp = (ushort*) ˙
- dprint("%C%C", sp[0], sp[1]);
- endline();
- dotinc = 4;
- break;
- }
- savdot=dot;
- while ((i = get2(map, dot, &sh) > 0) && sh) {
- dot=inkdot(2);
- dprint("%C", sh);
- endline();
- }
- if (i < 0)
- error("%r");
- dotinc = dot-savdot+2;
- dot=savdot;
- break;
- case 's':
- if (literal) {
- cp = (uchar*) ˙
- for (i = 0; i < 4; i++)
- buf[i] = cp[i];
- buf[i] = 0;
- dprint("%s", buf);
- endline();
- dotinc = 4;
- break;
- }
- savdot = dot;
- for(;;){
- i = 0;
- do{
- if (get1(map, dot, (uchar*)&buf[i], 1) < 0)
- error("%r");
- dot = inkdot(1);
- i++;
- }while(!fullrune(buf, i));
- if(buf[0] == 0)
- break;
- buf[i] = 0;
- dprint("%s", buf);
- endline();
- }
- dotinc = dot-savdot+1;
- dot = savdot;
- break;
- case 'S':
- if (literal) {
- cp = (uchar*) ˙
- for (i = 0; i < 4; i++)
- printesc(cp[i]);
- endline();
- dotinc = 4;
- break;
- }
- savdot=dot;
- while ((i = get1(map, dot, &ch, 1) > 0) && ch) {
- dot=inkdot(1);
- printesc(ch);
- endline();
- }
- if (i < 0)
- error("%r");
- dotinc = dot-savdot+1;
- dot=savdot;
- break;
- case 'I':
- case 'i':
- i = machdata->das(map, dot, modifier, buf, sizeof(buf));
- if (i < 0)
- error("%r");
- dotinc = i;
- dprint("%s\n", buf);
- break;
- case 'M':
- i = machdata->hexinst(map, dot, buf, sizeof(buf));
- if (i < 0)
- error("%r");
- dotinc = i;
- dprint("%s", buf);
- if (*fp) {
- dotinc = 0;
- dprint("%48t");
- } else
- dprint("\n");
- break;
- case 'f':
- /* BUG: 'f' and 'F' assume szdouble is sizeof(vlong) in the literal case */
- if (literal) {
- v = machdata->swav(dot);
- memmove(buf, &v, mach->szfloat);
- }else if (get1(map, dot, (uchar*)buf, mach->szfloat) < 0)
- error("%r");
- machdata->sftos(buf, sizeof(buf), (void*) buf);
- dprint("%s\n", buf);
- dotinc = mach->szfloat;
- break;
- case 'F':
- /* BUG: 'f' and 'F' assume szdouble is sizeof(vlong) in the literal case */
- if (literal) {
- v = machdata->swav(dot);
- memmove(buf, &v, mach->szdouble);
- }else if (get1(map, dot, (uchar*)buf, mach->szdouble) < 0)
- error("%r");
- machdata->dftos(buf, sizeof(buf), (void*) buf);
- dprint("%s\n", buf);
- dotinc = mach->szdouble;
- break;
- case 'n':
- case 'N':
- printc('\n');
- dotinc=0;
- break;
- case '"':
- dotinc=0;
- while (*fp != '"' && *fp)
- printc(*fp++);
- if (*fp)
- fp++;
- break;
- case '^':
- dot=inkdot(-dotinc*fcount);
- return(fp);
- case '+':
- dot=inkdot((WORD)fcount);
- return(fp);
- case '-':
- dot=inkdot(-(WORD)fcount);
- return(fp);
- case 'z':
- if (findsym(dot, CTEXT, &s))
- dprint("%s() ", s.name);
- printsource(dot);
- printc(EOR);
- return fp;
- default:
- error("bad modifier");
- }
- if (map->seg[0].fd >= 0)
- dot=inkdot(dotinc);
- fcount--;
- endline();
- }
- return(fp);
- }
- void
- printesc(int c)
- {
- static char hex[] = "0123456789abcdef";
- if (c < SPC || c >= 0177)
- dprint("\\x%c%c", hex[(c&0xF0)>>4], hex[c&0xF]);
- else
- printc(c);
- }
- ADDR
- inkdot(int incr)
- {
- ADDR newdot;
- newdot=dot+incr;
- if ((incr >= 0 && newdot < dot)
- || (incr < 0 && newdot > dot))
- error("address wraparound");
- return(newdot);
- }
|