xref: /csrg-svn/sys/deprecated/kdb/kdb_print.c (revision 39915)
130296Ssam /*
230296Ssam  * Copyright (c) 1986 Regents of the University of California.
330296Ssam  * All rights reserved.  The Berkeley software License Agreement
430296Ssam  * specifies the terms and conditions for redistribution.
530296Ssam  *
6*39915Smckusick  *	@(#)kdb_print.c	7.15 (Berkeley) 01/15/90
730296Ssam  */
830111Ssam 
937909Smarc #include "machine/mtpr.h"
1037909Smarc #undef ISP
1130111Ssam #include "../kdb/defs.h"
1237909Smarc #undef CTRL
1339290Skarels #include "ioctl.h"
1437909Smarc #include "tty.h"
1538274Smckusick #include "vnode.h"
1639629Smckusick #include "mount.h"
1730111Ssam 
1830122Ssam char	*BADRAD;
1930122Ssam 
2030111Ssam ADDR	lastframe;
2130111Ssam ADDR	callpc;
2230111Ssam 
2330111Ssam char	*BADMOD;
2430111Ssam char	*lp;
2530111Ssam long	maxpos;
2630111Ssam int	radix;
2730111Ssam char	lastc;
2830111Ssam 
2930111Ssam /* breakpoints */
3030111Ssam BKPTR	bkpthead;
3130111Ssam 
3230136Ssam extern	REGLIST reglist[];
3330111Ssam 
3430111Ssam /* general printing routines ($) */
3530111Ssam 
3630111Ssam printtrace(modif)
3730111Ssam {
3830111Ssam 	register narg, i;
3930111Ssam 	register BKPTR bkptr;
4030111Ssam 	register ADDR word;
4130111Ssam 	register char *comptr;
4230111Ssam 	register ADDR argp, frame;
4330111Ssam 	register struct nlist *sp;
4430296Ssam 	int ntramp;
4539290Skarels 	register struct proc *p;
4630127Ssam 	extern struct proc *allproc;
4730111Ssam 
4830111Ssam 	if (cntflg==0)
4930111Ssam 		cntval = -1;
5030111Ssam 	switch (modif) {
5130111Ssam 
5230111Ssam 	case 'd':
5330111Ssam 		if (adrflg) {
5430122Ssam 			if (adrval < 2 || adrval > 16)
5530122Ssam 				error(BADRAD);
5630122Ssam 			radix = adrval;
5730111Ssam 		}
5830122Ssam 		printf("radix=%d base ten", radix);
5930111Ssam 		break;
6030111Ssam 
6130111Ssam 	case 'w': case 'W':
6230122Ssam 		printf("maxpos=%d", maxpos=(adrflg?adrval:MAXPOS));
6330111Ssam 		break;
6430111Ssam 
6530111Ssam 	case 's': case 'S':
6630122Ssam 		printf("maxoff=%d", maxoff=(adrflg?adrval:MAXOFF));
6730111Ssam 		break;
6830111Ssam 
69*39915Smckusick 	case 'V':
7030111Ssam 		printf("variables\n");
7130111Ssam 		for (i=0;i<=35;i++)
7230111Ssam 			if (var[i]) {
7330111Ssam 				printc((i<=9 ? '0' : 'a'-10) + i);
7430111Ssam 				printf(" = %R\n",var[i]);
7530111Ssam 			}
7630111Ssam 		break;
7730111Ssam 
7830111Ssam 	case 0: case '?':
7930127Ssam 		if (p = (struct proc *)var[varchk('p')])
8030127Ssam 			printf("pid = %d\n", p->p_pid);
8130127Ssam 		else
8230127Ssam 			printf("in idle loop\n");
8330127Ssam 		printtrap(var[varchk('t')], var[varchk('c')]);
8430127Ssam 		/* fall thru... */
8530111Ssam 	case 'r': case 'R':
8630111Ssam 		printregs(modif);
8730111Ssam 		return;
8830111Ssam 
8930111Ssam 	case 'c': case 'C':
9030111Ssam 		if (adrflg) {
9130136Ssam 			frame = adrval;
9230136Ssam 			callpc = getprevpc(frame);
9330111Ssam 		} else {
9430111Ssam 			frame = pcb.pcb_fp;
9530111Ssam 			callpc = pcb.pcb_pc;
9630111Ssam 		}
9730136Ssam 		lastframe = NOFRAME;
9830111Ssam 		ntramp = 0;
9930136Ssam 		while (cntval-- && frame != NOFRAME) {
10030111Ssam 			char *name;
10130111Ssam 
10230111Ssam 			chkerr();
10330111Ssam 			/* check for pc in pcb (signal trampoline code) */
10430136Ssam 			if (issignalpc(callpc)) {
10530111Ssam 				name = "sigtramp";
10630111Ssam 				ntramp++;
10730111Ssam 			} else {
10830111Ssam 				ntramp = 0;
10930296Ssam 				(void) findsym((long)callpc, ISYM);
11030111Ssam 				if (cursym)
11130111Ssam 					name = cursym->n_un.n_name;
11230111Ssam 				else
11330111Ssam 					name = "?";
11430111Ssam 			}
11530111Ssam 			printf("%s(", name);
11630136Ssam 			narg = getnargs(frame);
11737491Smckusick 			if (narg > 10)
11837491Smckusick 				narg = 10;
11930111Ssam 			argp = frame;
12030111Ssam 			if (ntramp != 1)
12130136Ssam 				while (narg) {
12230136Ssam 					printf("%R",
12330296Ssam 					    get((off_t)(argp = nextarg(argp)),
12430296Ssam 					        DSP));
12530136Ssam 					if (--narg != 0)
12630111Ssam 						printc(',');
12730111Ssam 				}
12830111Ssam 			printf(") at ");
12930296Ssam 			psymoff((long)callpc, ISYM, "\n");
13030111Ssam 
13130111Ssam 			if (modif=='C') {
13230296Ssam 				while (localsym((long)frame)) {
13330296Ssam 					word = get((off_t)localval, DSP);
13430111Ssam 					printf("%8t%s:%10t",
13530111Ssam 					    cursym->n_un.n_name);
13630111Ssam 					if (errflg) {
13730111Ssam 						printf("?\n");
13830136Ssam 						errflg = 0;
13930111Ssam 					} else
14030136Ssam 						printf("%R\n", word);
14130111Ssam 				}
14230111Ssam 			}
14330111Ssam 			if (ntramp != 1) {
14430136Ssam 				callpc = getprevpc(frame);
14530111Ssam 				lastframe = frame;
14630136Ssam 				frame = getprevframe(frame);
14730111Ssam 			} else
14830136Ssam 				callpc = getsignalpc(lastframe);
14930136Ssam 			if (!adrflg && !INSTACK(frame))
15030111Ssam 				break;
15130111Ssam 		}
15230111Ssam 		break;
15330111Ssam 
15430111Ssam 		/*print externals*/
15530111Ssam 	case 'e': case 'E':
15630111Ssam 		for (sp = symtab; sp < esymtab; sp++)
15730111Ssam 			if (sp->n_type==(N_DATA|N_EXT) ||
15830111Ssam 			    sp->n_type==(N_BSS|N_EXT))
15930111Ssam 				printf("%s:%12t%R\n", sp->n_un.n_name,
16030296Ssam 					get((off_t)sp->n_value, DSP));
16130111Ssam 		break;
16230111Ssam 
16330111Ssam 		/*print breakpoints*/
16430111Ssam 	case 'b': case 'B':
16530111Ssam 		printf("breakpoints\ncount%8tbkpt%24tcommand\n");
16630111Ssam 		for (bkptr=bkpthead; bkptr; bkptr=bkptr->nxtbkpt)
16730111Ssam 			if (bkptr->flag) {
16830111Ssam 		   		printf("%-8.8d",bkptr->count);
16930296Ssam 				psymoff((long)bkptr->loc,ISYM,"%24t");
17030111Ssam 				comptr=bkptr->comm;
17130111Ssam 				while (*comptr)
17230111Ssam 					printc(*comptr++);
17330111Ssam 			}
17430111Ssam 		break;
17530111Ssam 
17638772Smckusick 	case 'k':
17738772Smckusick 		panic("kdb requested panic");
17838772Smckusick 		/* NOTREACHED */
17938772Smckusick 
18037909Smarc 	case 'l': {
18137909Smarc 		struct pte savemmap;
18237909Smarc 		extern char vmmap[];
18337909Smarc 
18437909Smarc 		savemmap = mmap[0];
18530111Ssam 		for (p = allproc; p; p = p->p_nxt) {
18639290Skarels 			printf("%X pid %5d%c%5d %c ", p, p->p_pid,
18739290Skarels 				p == (struct proc *)var[varchk('p')]? '*' : ' ',
18839290Skarels 				p->p_ppid,
18930111Ssam 				p->p_stat == SSLEEP ? 'S' :
19030111Ssam 				p->p_stat == SRUN ? 'R':
19130111Ssam 				p->p_stat == SIDL ? 'I':
19230111Ssam 				p->p_stat == SSTOP ? 'T' : '?');
19339290Skarels 			if (p->p_wchan)
19430296Ssam 				psymoff((long)p->p_wchan, ISYM, "");
19537909Smarc 			if ((p->p_flag & SLOAD) && p->p_addr) {
19637909Smarc 				int i;
19737909Smarc 				*(int *)mmap = *(int *)p->p_addr;
19837909Smarc 				mtpr(TBIS, vmmap);
19937909Smarc #define U	((struct user *)vmmap)
20037909Smarc #ifdef not_until_uarea_completely_mapped
20137909Smarc 				if (U->u_ttyp)
20237909Smarc 					printf(" ctty %x ", U->u_ttyp);
20337909Smarc #endif
20437909Smarc 				printf(" %.8s ", U->u_comm);
20537909Smarc #undef U
20637909Smarc 			}
20737909Smarc 
20830111Ssam 			printc(EOR);
20930111Ssam 		}
21037909Smarc 		mmap[0] = savemmap;
21137909Smarc 		mtpr(TBIS, vmmap);
21230111Ssam 		break;
21337909Smarc 	}
21430111Ssam 
21537909Smarc 	case 't':	/* XXX - debug */
21637909Smarc 		if (adrflg) {
21737909Smarc 		      printf("dev       state  rawq   canq  outq  lwat hwat\n");
21837909Smarc 
21937909Smarc #define T	((struct tty *)adrval)
22037909Smarc 			printf("%x  %x %d %d %d %d %d\n", T->t_dev,
22137909Smarc 				T->t_state, T->t_rawq.c_cc,
22237909Smarc 				T->t_canq.c_cc, T->t_outq.c_cc,
22337909Smarc 				T->t_lowat, T->t_hiwat);
22437909Smarc 	       printf(" &rawq    &canq      &outq    &outq.c_cf  &rawq.c_cf\n");
22537909Smarc 	       		printf(" %x %x  %x %x %x \n", &T->t_rawq,
22637909Smarc 				&T->t_canq, &T->t_outq, &T->t_outq.c_cf,
22737909Smarc 				&T->t_rawq.c_cf);
22837909Smarc #undef T
22937909Smarc 		}
23037909Smarc 
231*39915Smckusick 	case 'v': {
232*39915Smckusick 		register struct mount *mp;
233*39915Smckusick 		register struct vnode *vp;
234*39915Smckusick 
235*39915Smckusick 		printf("Locked vnodes\n");
236*39915Smckusick 		mp = rootfs;
237*39915Smckusick 		do {
238*39915Smckusick 			for (vp = mp->m_mounth; vp; vp = vp->v_mountf)
239*39915Smckusick 				if (VOP_ISLOCKED(vp))
240*39915Smckusick 					vprint((char *)0, vp);
241*39915Smckusick 			mp = mp->m_next;
242*39915Smckusick 		} while (mp != rootfs);
243*39915Smckusick 		break;
244*39915Smckusick 	}
245*39915Smckusick 
24630111Ssam 	default:
24730111Ssam 		error(BADMOD);
24830111Ssam 	}
24930111Ssam }
25030111Ssam 
25130111Ssam static
25230111Ssam printregs(c)
25330111Ssam {
25430111Ssam 	register REGPTR	p;
25530111Ssam 	ADDR v;
25630111Ssam 
25730136Ssam 	for (p = reglist; p->rname; p++) {
25830136Ssam 		if (c != 'R' && ishiddenreg(p))
25930111Ssam 			continue;
26030111Ssam 		v = *p->rkern;
26130111Ssam 		printf("%s%6t%R %16t", p->rname, v);
26230296Ssam 		valpr((long)v, p->rkern == &pcb.pcb_pc ? ISYM : DSYM);
26330111Ssam 		printc(EOR);
26430111Ssam 	}
26530111Ssam 	printpc();
26630111Ssam }
26730111Ssam 
26830111Ssam getreg(regnam)
26930111Ssam {
27030111Ssam 	register REGPTR	p;
27130111Ssam 	register char *regptr;
27230111Ssam 	char *olp;
27330111Ssam 
27430136Ssam 	olp = lp;
27530136Ssam 	for (p = reglist; p->rname; p++) {
27630136Ssam 		regptr = p->rname;
27730111Ssam 		if (regnam == *regptr++) {
27830111Ssam 			while (*regptr)
27930111Ssam 				if (readchar() != *regptr++) {
28030111Ssam 					--regptr;
28130111Ssam 					break;
28230111Ssam 				}
28330111Ssam 			if (*regptr)
28430136Ssam 				lp = olp;
28530111Ssam 			else
28630136Ssam 				return ((int)p->rkern);
28730111Ssam 		}
28830111Ssam 	}
28930136Ssam 	lp = olp;
29030111Ssam 	return (-1);
29130111Ssam }
29230111Ssam 
29330111Ssam printpc()
29430111Ssam {
29530111Ssam 
29630296Ssam 	psymoff((long)pcb.pcb_pc, ISYM, ":%16t");
29730296Ssam 	printins(ISP, (long)chkget((off_t)pcb.pcb_pc, ISP));
29830111Ssam 	printc(EOR);
29930111Ssam }
300