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