136559Sbostic #ifndef lint 2*37337Storek static char sccsid[] = "@(#)print.c 5.3 (Berkeley) 04/09/89"; 336559Sbostic #endif 436559Sbostic 536559Sbostic /* 636559Sbostic * adb - printing routines 736559Sbostic */ 836559Sbostic 936559Sbostic #include "defs.h" 1036559Sbostic #include <sys/file.h> 1136559Sbostic 1236559Sbostic extern char LONGFIL[]; 1336559Sbostic extern char NOTOPEN[]; 1436559Sbostic extern char BADMOD[]; 1536559Sbostic 1636559Sbostic int infile; /* XXX */ 1736559Sbostic int outfile; /* XXX */ 1836559Sbostic 1936559Sbostic off_t lseek(); 2036559Sbostic 2136559Sbostic /* general printing routines ($) */ 2236559Sbostic 2336559Sbostic printtrace(modif) 2436559Sbostic int modif; 2536559Sbostic { 2636559Sbostic int stack, i; 2736559Sbostic 2836559Sbostic switch (modif) { 2936559Sbostic 3036559Sbostic case '<': 3136559Sbostic if (ecount == 0) { 3236559Sbostic while (readchar() != '\n') 3336559Sbostic /* void */; 3436559Sbostic unreadc(); 3536559Sbostic break; 3636559Sbostic } 3736559Sbostic if (rdc() == '<') 3836559Sbostic stack = 1; 3936559Sbostic else { 4036559Sbostic stack = 0; 4136559Sbostic unreadc(); 4236559Sbostic } 4336559Sbostic /* FALLTHROUGH */ 4436559Sbostic 4536559Sbostic case '>': { 4636559Sbostic char file[64]; 4736559Sbostic char Ifile[128]; 4836559Sbostic extern char *Ipath; 4936559Sbostic int index; 5036559Sbostic char *strcpy(), *strcat(); 5136559Sbostic 5236559Sbostic index = 0; 5336559Sbostic if (rdc() != '\n') { 5436559Sbostic do { 5536559Sbostic file[index++] = lastc; 5636559Sbostic if (index >= 63) 5736559Sbostic error(LONGFIL); 5836559Sbostic } while (readchar() != '\n'); 5936559Sbostic file[index] = 0; 6036559Sbostic if (modif == '<') { 6136559Sbostic if (Ipath) { 6236559Sbostic (void) strcpy(Ifile, Ipath); 6336559Sbostic (void) strcat(Ifile, "/"); 6436559Sbostic (void) strcat(Ifile, file); 6536559Sbostic } 6636559Sbostic if (strcmp(file, "-") != 0) { 6736559Sbostic iclose(stack, 0); 6836559Sbostic infile = open(file, 0); 6936559Sbostic if (infile < 0) 7036559Sbostic infile = open(Ifile, 0); 7136559Sbostic } else 7236559Sbostic (void) lseek(infile, 0L, 0); 7336559Sbostic if (infile < 0) { 7436559Sbostic infile = 0; 7536559Sbostic error(NOTOPEN); 7636559Sbostic /* NOTREACHED */ 7736559Sbostic } 78*37337Storek var[9] = ecount; 7936559Sbostic } else { 8036559Sbostic oclose(); 8136559Sbostic outfile = open(file, O_CREAT|O_WRONLY, 0644); 8236559Sbostic (void) lseek(outfile, 0L, 2); 8336559Sbostic } 8436559Sbostic } else { 8536559Sbostic if (modif == '<') 8636559Sbostic iclose(-1, 0); 8736559Sbostic else 8836559Sbostic oclose(); 8936559Sbostic } 9036559Sbostic unreadc(); 9136559Sbostic break; 9236559Sbostic } 9336559Sbostic 9436559Sbostic case 'p': 9536559Sbostic if (!kernel) 9636559Sbostic prints("not debugging kernel\n"); 9736559Sbostic else { 9836559Sbostic if (gavedot) 9936559Sbostic setpcb(dot); 10036559Sbostic getpcb(); 10136559Sbostic } 10236559Sbostic break; 10336559Sbostic 10436559Sbostic case 'd': 10536559Sbostic if (gavedot) { 10636559Sbostic i = edot; 10736559Sbostic if (!(i >= 2 && i <= 16 || i <= -2 && i >= -16)) { 10836559Sbostic adbprintf("illegal radix %d base ten", 10936559Sbostic (expr_t)i); 11036559Sbostic break; 11136559Sbostic } 11236559Sbostic radix = i; 11336559Sbostic } 11436559Sbostic adbprintf("radix=%D base ten", (expr_t)radix); 11536559Sbostic break; 11636559Sbostic 11736559Sbostic case 'q': 11836559Sbostic case 'Q': 11936559Sbostic case '%': 12036559Sbostic done(0); 12136559Sbostic 12236559Sbostic case 'w': 12336559Sbostic case 'W': 12436559Sbostic maxcol = gavedot ? edot : MAXCOL; 12536559Sbostic break; 12636559Sbostic 12736559Sbostic case 's': 12836559Sbostic case 'S': 12936559Sbostic maxoff = gavedot ? edot : MAXOFF; 13036559Sbostic break; 13136559Sbostic 13236559Sbostic case 'v': 13336559Sbostic case 'V': 13436559Sbostic prints("variables\n"); 13536559Sbostic for (i = 0; i <= 35; i++) 13636559Sbostic if (var[i]) 13736559Sbostic adbprintf("%c = %R\n", 13836559Sbostic i > 9 ? i + 'a' - 10 : i + '0', 13936559Sbostic var[i]); 14036559Sbostic break; 14136559Sbostic 14236559Sbostic case 'm': 14336559Sbostic case 'M': 14436559Sbostic printmap("? map", &txtmap); 14536559Sbostic printmap("/ map", &datmap); 14636559Sbostic break; 14736559Sbostic 14836559Sbostic case 0: 14936559Sbostic case '?': 15036559Sbostic if (pid) 15136559Sbostic adbprintf("pcs id = %D\n", (expr_t)pid); 15236559Sbostic else 15336559Sbostic prints("no process\n"); 15436559Sbostic sigprint(); 15536559Sbostic flushbuf(); 15636559Sbostic /* FALLTHROUGH */ 15736559Sbostic 15836559Sbostic case 'r': 15936559Sbostic case 'R': 16036559Sbostic printregs(); 16136559Sbostic return; 16236559Sbostic 16336559Sbostic case 'c': 16436559Sbostic case 'C': 16536559Sbostic printstack(modif == 'C', gavecount ? (int)ecount : -1); 16636559Sbostic break; 16736559Sbostic 16836559Sbostic case 'e': 16936559Sbostic case 'E': 17036559Sbostic /* print externals */ 17136559Sbostic printsyms(modif == 'E'); 17236559Sbostic break; 17336559Sbostic 17436559Sbostic 17536559Sbostic case 'b': 17636559Sbostic case 'B': 17736559Sbostic /* print breakpoints */ 17836559Sbostic printbkpts(); 17936559Sbostic break; 18036559Sbostic 18136559Sbostic default: 18236559Sbostic error(BADMOD); 18336559Sbostic } 18436559Sbostic } 18536559Sbostic 18636559Sbostic printmap(s, m) 18736559Sbostic char *s; 18836559Sbostic register struct map *m; 18936559Sbostic { 19036559Sbostic 19136559Sbostic adbprintf("%s%12t`%s'\n", s, m->ufd < 0 ? "-" : 19236559Sbostic m->ufd == corefile.fd ? corefile.name : symfile.name); 19336559Sbostic adbprintf("b1 = %-16Re1 = %-16Rf1 = %-16R\n", 19436559Sbostic m->m1.b, m->m1.e, m->m1.f); 19536559Sbostic adbprintf("b2 = %-16Re2 = %-16Rf2 = %-16R\n", 19636559Sbostic m->m2.b, m->m2.e, m->m2.f); 19736559Sbostic } 19836559Sbostic 19936559Sbostic /* 20036559Sbostic * Print global data and bss symbols, and if texttoo, text symbols too. 20136559Sbostic */ 20236559Sbostic printsyms(texttoo) 20336559Sbostic int texttoo; 20436559Sbostic { 20536559Sbostic register struct nlist *sp; 20636559Sbostic 20736559Sbostic if (symtab == NULL) 20836559Sbostic return; 20936559Sbostic for (sp = symtab; sp < esymtab; sp++) { 21036559Sbostic if ((sp->n_type & N_EXT) == 0) 21136559Sbostic continue; 21236559Sbostic switch (sp->n_type) { 21336559Sbostic 21436559Sbostic case N_TEXT|N_EXT: 21536559Sbostic if (texttoo) 21636559Sbostic adbprintf("%s:%12t@ %R\n", 21736559Sbostic sp->n_un.n_name, 21836559Sbostic (expr_t)sp->n_value); 21936559Sbostic break; 22036559Sbostic 22136559Sbostic case N_DATA|N_EXT: 22236559Sbostic case N_BSS|N_EXT: 22336559Sbostic adbprintf("%s:%12t", sp->n_un.n_name); 22436559Sbostic prfrom((addr_t)sp->n_value, '\n'); 22536559Sbostic break; 22636559Sbostic } 22736559Sbostic } 22836559Sbostic } 22936559Sbostic 23036559Sbostic /* 23136559Sbostic * Print the value stored in some location, or `?' if it cannot be read, 23236559Sbostic * then the character c (usually '\n' or ','). 23336559Sbostic */ 23436559Sbostic prfrom(a, c) 23536559Sbostic addr_t a; 23636559Sbostic int c; 23736559Sbostic { 23836559Sbostic expr_t v; 23936559Sbostic 24036559Sbostic errflag = NULL; 24136559Sbostic if (adbread(SP_DATA, a, &v, sizeof(v)) == sizeof(v) && errflag == NULL) 24236573Storek adbprintf("%R\%c", v, c); 24336559Sbostic else { 24436559Sbostic errflag = NULL; 24536559Sbostic adbprintf("?%c", c); 24636559Sbostic } 24736559Sbostic } 24836559Sbostic 24936559Sbostic #ifdef busted 25036559Sbostic /* 25136559Sbostic * Print a local symbol (called from printstack()). 25236559Sbostic * Local symbols end with ':', so cannot use %s format. 25336559Sbostic */ 25436559Sbostic printlsym(cp) 25536559Sbostic register char *cp; 25636559Sbostic { 25736559Sbostic 25836559Sbostic while (*cp && *cp != ':') 25936559Sbostic printc(*cp++); 26036559Sbostic } 26136559Sbostic #endif 26236559Sbostic 26336559Sbostic printregs() 26436559Sbostic { 26536559Sbostic register struct reglist *p; 26636559Sbostic expr_t v; 26736559Sbostic extern struct reglist reglist[]; 26836559Sbostic 26936559Sbostic for (p = reglist; p->r_name != NULL; p++) { 27036559Sbostic v = getreg(p); 27136573Storek adbprintf("%s%6t%R\%16t", p->r_name, v); 27236559Sbostic valpr(v, ispace_reg(p) ? SP_INSTR : SP_DATA); 27336559Sbostic printc('\n'); 27436559Sbostic } 27536559Sbostic printpc(); 27636559Sbostic } 27736559Sbostic 27836559Sbostic printpc() 27936559Sbostic { 28036559Sbostic 28136559Sbostic dot = getpc(); 28236559Sbostic pdot(); 28336559Sbostic printins(SP_INSTR); 28436559Sbostic printc('\n'); 28536559Sbostic } 286