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