|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)print.c 5.3 (Berkeley) 4/9/89"; ! 3: #endif ! 4: ! 5: /* ! 6: * adb - printing routines ! 7: */ ! 8: ! 9: #include "defs.h" ! 10: #include <sys/file.h> ! 11: ! 12: extern char LONGFIL[]; ! 13: extern char NOTOPEN[]; ! 14: extern char BADMOD[]; ! 15: ! 16: int infile; /* XXX */ ! 17: int outfile; /* XXX */ ! 18: ! 19: off_t lseek(); ! 20: ! 21: /* general printing routines ($) */ ! 22: ! 23: printtrace(modif) ! 24: int modif; ! 25: { ! 26: int stack, i; ! 27: ! 28: switch (modif) { ! 29: ! 30: case '<': ! 31: if (ecount == 0) { ! 32: while (readchar() != '\n') ! 33: /* void */; ! 34: unreadc(); ! 35: break; ! 36: } ! 37: if (rdc() == '<') ! 38: stack = 1; ! 39: else { ! 40: stack = 0; ! 41: unreadc(); ! 42: } ! 43: /* FALLTHROUGH */ ! 44: ! 45: case '>': { ! 46: char file[64]; ! 47: char Ifile[128]; ! 48: extern char *Ipath; ! 49: int index; ! 50: char *strcpy(), *strcat(); ! 51: ! 52: index = 0; ! 53: if (rdc() != '\n') { ! 54: do { ! 55: file[index++] = lastc; ! 56: if (index >= 63) ! 57: error(LONGFIL); ! 58: } while (readchar() != '\n'); ! 59: file[index] = 0; ! 60: if (modif == '<') { ! 61: if (Ipath) { ! 62: (void) strcpy(Ifile, Ipath); ! 63: (void) strcat(Ifile, "/"); ! 64: (void) strcat(Ifile, file); ! 65: } ! 66: if (strcmp(file, "-") != 0) { ! 67: iclose(stack, 0); ! 68: infile = open(file, 0); ! 69: if (infile < 0) ! 70: infile = open(Ifile, 0); ! 71: } else ! 72: (void) lseek(infile, 0L, 0); ! 73: if (infile < 0) { ! 74: infile = 0; ! 75: error(NOTOPEN); ! 76: /* NOTREACHED */ ! 77: } ! 78: var[9] = ecount; ! 79: } else { ! 80: oclose(); ! 81: outfile = open(file, O_CREAT|O_WRONLY, 0644); ! 82: (void) lseek(outfile, 0L, 2); ! 83: } ! 84: } else { ! 85: if (modif == '<') ! 86: iclose(-1, 0); ! 87: else ! 88: oclose(); ! 89: } ! 90: unreadc(); ! 91: break; ! 92: } ! 93: ! 94: case 'p': ! 95: if (!kernel) ! 96: prints("not debugging kernel\n"); ! 97: else { ! 98: if (gavedot) ! 99: setpcb(dot); ! 100: getpcb(); ! 101: } ! 102: break; ! 103: ! 104: case 'd': ! 105: if (gavedot) { ! 106: i = edot; ! 107: if (!(i >= 2 && i <= 16 || i <= -2 && i >= -16)) { ! 108: adbprintf("illegal radix %d base ten", ! 109: (expr_t)i); ! 110: break; ! 111: } ! 112: radix = i; ! 113: } ! 114: adbprintf("radix=%D base ten", (expr_t)radix); ! 115: break; ! 116: ! 117: case 'q': ! 118: case 'Q': ! 119: case '%': ! 120: done(0); ! 121: ! 122: case 'w': ! 123: case 'W': ! 124: maxcol = gavedot ? edot : MAXCOL; ! 125: break; ! 126: ! 127: case 's': ! 128: case 'S': ! 129: maxoff = gavedot ? edot : MAXOFF; ! 130: break; ! 131: ! 132: case 'v': ! 133: case 'V': ! 134: prints("variables\n"); ! 135: for (i = 0; i <= 35; i++) ! 136: if (var[i]) ! 137: adbprintf("%c = %R\n", ! 138: i > 9 ? i + 'a' - 10 : i + '0', ! 139: var[i]); ! 140: break; ! 141: ! 142: case 'm': ! 143: case 'M': ! 144: printmap("? map", &txtmap); ! 145: printmap("/ map", &datmap); ! 146: break; ! 147: ! 148: case 0: ! 149: case '?': ! 150: if (pid) ! 151: adbprintf("pcs id = %D\n", (expr_t)pid); ! 152: else ! 153: prints("no process\n"); ! 154: sigprint(); ! 155: flushbuf(); ! 156: /* FALLTHROUGH */ ! 157: ! 158: case 'r': ! 159: case 'R': ! 160: printregs(); ! 161: return; ! 162: ! 163: case 'c': ! 164: case 'C': ! 165: printstack(modif == 'C', gavecount ? (int)ecount : -1); ! 166: break; ! 167: ! 168: case 'e': ! 169: case 'E': ! 170: /* print externals */ ! 171: printsyms(modif == 'E'); ! 172: break; ! 173: ! 174: ! 175: case 'b': ! 176: case 'B': ! 177: /* print breakpoints */ ! 178: printbkpts(); ! 179: break; ! 180: ! 181: default: ! 182: error(BADMOD); ! 183: } ! 184: } ! 185: ! 186: printmap(s, m) ! 187: char *s; ! 188: register struct map *m; ! 189: { ! 190: ! 191: adbprintf("%s%12t`%s'\n", s, m->ufd < 0 ? "-" : ! 192: m->ufd == corefile.fd ? corefile.name : symfile.name); ! 193: adbprintf("b1 = %-16Re1 = %-16Rf1 = %-16R\n", ! 194: m->m1.b, m->m1.e, m->m1.f); ! 195: adbprintf("b2 = %-16Re2 = %-16Rf2 = %-16R\n", ! 196: m->m2.b, m->m2.e, m->m2.f); ! 197: } ! 198: ! 199: /* ! 200: * Print global data and bss symbols, and if texttoo, text symbols too. ! 201: */ ! 202: printsyms(texttoo) ! 203: int texttoo; ! 204: { ! 205: register struct nlist *sp; ! 206: ! 207: if (symtab == NULL) ! 208: return; ! 209: for (sp = symtab; sp < esymtab; sp++) { ! 210: if ((sp->n_type & N_EXT) == 0) ! 211: continue; ! 212: switch (sp->n_type) { ! 213: ! 214: case N_TEXT|N_EXT: ! 215: if (texttoo) ! 216: adbprintf("%s:%12t@ %R\n", ! 217: sp->n_un.n_name, ! 218: (expr_t)sp->n_value); ! 219: break; ! 220: ! 221: case N_DATA|N_EXT: ! 222: case N_BSS|N_EXT: ! 223: adbprintf("%s:%12t", sp->n_un.n_name); ! 224: prfrom((addr_t)sp->n_value, '\n'); ! 225: break; ! 226: } ! 227: } ! 228: } ! 229: ! 230: /* ! 231: * Print the value stored in some location, or `?' if it cannot be read, ! 232: * then the character c (usually '\n' or ','). ! 233: */ ! 234: prfrom(a, c) ! 235: addr_t a; ! 236: int c; ! 237: { ! 238: expr_t v; ! 239: ! 240: errflag = NULL; ! 241: if (adbread(SP_DATA, a, &v, sizeof(v)) == sizeof(v) && errflag == NULL) ! 242: adbprintf("%R\%c", v, c); ! 243: else { ! 244: errflag = NULL; ! 245: adbprintf("?%c", c); ! 246: } ! 247: } ! 248: ! 249: #ifdef busted ! 250: /* ! 251: * Print a local symbol (called from printstack()). ! 252: * Local symbols end with ':', so cannot use %s format. ! 253: */ ! 254: printlsym(cp) ! 255: register char *cp; ! 256: { ! 257: ! 258: while (*cp && *cp != ':') ! 259: printc(*cp++); ! 260: } ! 261: #endif ! 262: ! 263: printregs() ! 264: { ! 265: register struct reglist *p; ! 266: expr_t v; ! 267: extern struct reglist reglist[]; ! 268: ! 269: for (p = reglist; p->r_name != NULL; p++) { ! 270: v = getreg(p); ! 271: adbprintf("%s%6t%R\%16t", p->r_name, v); ! 272: valpr(v, ispace_reg(p) ? SP_INSTR : SP_DATA); ! 273: printc('\n'); ! 274: } ! 275: printpc(); ! 276: } ! 277: ! 278: printpc() ! 279: { ! 280: ! 281: dot = getpc(); ! 282: pdot(); ! 283: printins(SP_INSTR); ! 284: printc('\n'); ! 285: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.