xref: /csrg-svn/sys/deprecated/kdb/kdb_print.c (revision 49880)
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*49880Sbostic  *	@(#)kdb_print.c	7.22 (Berkeley) 05/25/91
730296Ssam  */
830111Ssam 
937909Smarc #include "machine/mtpr.h"
1037909Smarc #undef ISP
1145789Sbostic #undef TB
1230111Ssam #include "../kdb/defs.h"
1337909Smarc #undef CTRL
1439290Skarels #include "ioctl.h"
1537909Smarc #include "tty.h"
1638274Smckusick #include "vnode.h"
1739629Smckusick #include "mount.h"
1830111Ssam 
1941340Ssklower char	*kdbBADRAD;
2030122Ssam 
2141340Ssklower char	*kdbBADMOD;
2241340Ssklower char	*kdblp;
2341340Ssklower long	kdbmaxpos;
2441340Ssklower int	kdbradix;
2541340Ssklower char	kdblastc;
2630111Ssam 
2730111Ssam /* breakpoints */
2841340Ssklower BKPTR	kdbbkpthead;
2930111Ssam 
3041340Ssklower extern	REGLIST kdbreglist[];
3130111Ssam 
3230111Ssam /* general printing routines ($) */
3330111Ssam 
kdbprinttrace(modif)3441340Ssklower kdbprinttrace(modif)
3530111Ssam {
3643427Ssklower 	register int i;
3730111Ssam 	register BKPTR bkptr;
3830111Ssam 	register char *comptr;
3930111Ssam 	register struct nlist *sp;
4039290Skarels 	register struct proc *p;
4130127Ssam 	extern struct proc *allproc;
4230111Ssam 
4341340Ssklower 	if (kdbcntflg==0)
4441340Ssklower 		kdbcntval = -1;
4530111Ssam 	switch (modif) {
4630111Ssam 
4730111Ssam 	case 'd':
4841340Ssklower 		if (kdbadrflg) {
4941340Ssklower 			if (kdbadrval < 2 || kdbadrval > 16)
5041340Ssklower 				kdberror(kdbBADRAD);
5141340Ssklower 			kdbradix = kdbadrval;
5230111Ssam 		}
5341340Ssklower 		kdbprintf("radix=%d base ten", kdbradix);
5430111Ssam 		break;
5530111Ssam 
5630111Ssam 	case 'w': case 'W':
5741340Ssklower 		kdbprintf("maxpos=%d", kdbmaxpos=(kdbadrflg?kdbadrval:MAXPOS));
5830111Ssam 		break;
5930111Ssam 
6030111Ssam 	case 's': case 'S':
6141340Ssklower 		kdbprintf("maxoff=%d", kdbmaxoff=(kdbadrflg?kdbadrval:MAXOFF));
6230111Ssam 		break;
6330111Ssam 
6439915Smckusick 	case 'V':
6541340Ssklower 		kdbprintf("variables\n");
6630111Ssam 		for (i=0;i<=35;i++)
6741340Ssklower 			if (kdbvar[i]) {
6841340Ssklower 				kdbprintc((i<=9 ? '0' : 'a'-10) + i);
6941340Ssklower 				kdbprintf(" = %R\n",kdbvar[i]);
7030111Ssam 			}
7130111Ssam 		break;
7230111Ssam 
7330111Ssam 	case 0: case '?':
7441340Ssklower 		if (p = (struct proc *)kdbvar[kdbvarchk('p')])
7541340Ssklower 			kdbprintf("pid = %d\n", p->p_pid);
7630127Ssam 		else
7741340Ssklower 			kdbprintf("in idle loop\n");
7841340Ssklower 		kdbprinttrap(kdbvar[kdbvarchk('t')], kdbvar[kdbvarchk('c')]);
7930127Ssam 		/* fall thru... */
8030111Ssam 	case 'r': case 'R':
8141340Ssklower 		kdbprintregs(modif);
8230111Ssam 		return;
8330111Ssam 
8430111Ssam 	case 'c': case 'C':
8543427Ssklower 		kdbstacktrace(modif == 'C');
8630111Ssam 		break;
8730111Ssam 
8830111Ssam 		/*print externals*/
8930111Ssam 	case 'e': case 'E':
9041340Ssklower 		for (sp = kdbsymtab; sp < kdbesymtab; sp++)
9130111Ssam 			if (sp->n_type==(N_DATA|N_EXT) ||
9230111Ssam 			    sp->n_type==(N_BSS|N_EXT))
9341340Ssklower 				kdbprintf("%s:%12t%R\n", sp->n_un.n_name,
9441340Ssklower 					kdbget((off_t)sp->n_value, DSP));
9530111Ssam 		break;
9630111Ssam 
9730111Ssam 		/*print breakpoints*/
9830111Ssam 	case 'b': case 'B':
9941340Ssklower 		kdbprintf("breakpoints\ncount%8tbkpt%24tcommand\n");
10041340Ssklower 		for (bkptr=kdbbkpthead; bkptr; bkptr=bkptr->nxtbkpt)
10130111Ssam 			if (bkptr->flag) {
10241340Ssklower 		   		kdbprintf("%-8.8d",bkptr->count);
10341340Ssklower 				kdbpsymoff((long)bkptr->loc,ISYM,"%24t");
10430111Ssam 				comptr=bkptr->comm;
10530111Ssam 				while (*comptr)
10641340Ssklower 					kdbprintc(*comptr++);
10730111Ssam 			}
10830111Ssam 		break;
10930111Ssam 
11038772Smckusick 	case 'k':
11138772Smckusick 		panic("kdb requested panic");
11238772Smckusick 		/* NOTREACHED */
11338772Smckusick 
11437909Smarc 	case 'l': {
11537909Smarc 		struct pte savemmap;
11637909Smarc 		extern char vmmap[];
11737909Smarc 
11837909Smarc 		savemmap = mmap[0];
11930111Ssam 		for (p = allproc; p; p = p->p_nxt) {
120*49880Sbostic 			kdbprintf("%lx pid %5d%c%5d %c ", p, p->p_pid,
12141340Ssklower 				p == (struct proc *)kdbvar[kdbvarchk('p')]? '*' : ' ',
12239290Skarels 				p->p_ppid,
12330111Ssam 				p->p_stat == SSLEEP ? 'S' :
12430111Ssam 				p->p_stat == SRUN ? 'R':
12530111Ssam 				p->p_stat == SIDL ? 'I':
12630111Ssam 				p->p_stat == SSTOP ? 'T' : '?');
12739290Skarels 			if (p->p_wchan)
12841340Ssklower 				kdbpsymoff((long)p->p_wchan, ISYM, "");
12937909Smarc 			if ((p->p_flag & SLOAD) && p->p_addr) {
13037909Smarc 				int i;
13137909Smarc 				*(int *)mmap = *(int *)p->p_addr;
13237909Smarc 				mtpr(TBIS, vmmap);
13337909Smarc #define U	((struct user *)vmmap)
13437909Smarc #ifdef not_until_uarea_completely_mapped
13537909Smarc 				if (U->u_ttyp)
13641340Ssklower 					kdbprintf(" ctty %x ", U->u_ttyp);
13737909Smarc #endif
13841340Ssklower 				kdbprintf(" %.8s ", p->p_comm);
13937909Smarc #undef U
14037909Smarc 			}
14137909Smarc 
14241340Ssklower 			kdbprintc(EOR);
14330111Ssam 		}
14437909Smarc 		mmap[0] = savemmap;
14537909Smarc 		mtpr(TBIS, vmmap);
14630111Ssam 		break;
14737909Smarc 	}
14830111Ssam 
14937909Smarc 	case 't':	/* XXX - debug */
15041340Ssklower 		if (kdbadrflg) {
15141340Ssklower 		      kdbprintf("dev       state  rawq   canq  outq  lwat hwat\n");
15237909Smarc 
15341340Ssklower #define T	((struct tty *)kdbadrval)
15441340Ssklower 			kdbprintf("%x  %x %d %d %d %d %d\n", T->t_dev,
15537909Smarc 				T->t_state, T->t_rawq.c_cc,
15637909Smarc 				T->t_canq.c_cc, T->t_outq.c_cc,
15737909Smarc 				T->t_lowat, T->t_hiwat);
15841340Ssklower 	       kdbprintf(" &rawq    &canq      &outq    &outq.c_cf  &rawq.c_cf\n");
15941340Ssklower 	       		kdbprintf(" %x %x  %x %x %x \n", &T->t_rawq,
16037909Smarc 				&T->t_canq, &T->t_outq, &T->t_outq.c_cf,
16137909Smarc 				&T->t_rawq.c_cf);
16237909Smarc #undef T
16337909Smarc 		}
16437909Smarc 
16549692Smckusick #ifdef DEBUG
16649692Smckusick 	case 'v':
16749692Smckusick 		printlockedvnodes();
16839915Smckusick 		break;
16949692Smckusick #endif
17039915Smckusick 
17130111Ssam 	default:
17241340Ssklower 		kdberror(kdbBADMOD);
17330111Ssam 	}
17430111Ssam }
17530111Ssam 
17630111Ssam static
kdbprintregs(c)17741340Ssklower kdbprintregs(c)
17830111Ssam {
17930111Ssam 	register REGPTR	p;
18030111Ssam 	ADDR v;
18130111Ssam 
18241340Ssklower 	for (p = kdbreglist; p->rname; p++) {
18330136Ssam 		if (c != 'R' && ishiddenreg(p))
18430111Ssam 			continue;
18530111Ssam 		v = *p->rkern;
18641340Ssklower 		kdbprintf("%s%6t%R %16t", p->rname, v);
18741340Ssklower 		kdbvalpr((long)v, p->rkern == &kdbpcb.pcb_pc ? ISYM : DSYM);
18841340Ssklower 		kdbprintc(EOR);
18930111Ssam 	}
19041340Ssklower 	kdbprintpc();
19130111Ssam }
19230111Ssam 
kdbgetreg(regnam)19341340Ssklower kdbgetreg(regnam)
19430111Ssam {
19530111Ssam 	register REGPTR	p;
19630111Ssam 	register char *regptr;
19730111Ssam 	char *olp;
19830111Ssam 
19941340Ssklower 	olp = kdblp;
20041340Ssklower 	for (p = kdbreglist; p->rname; p++) {
20130136Ssam 		regptr = p->rname;
20230111Ssam 		if (regnam == *regptr++) {
20330111Ssam 			while (*regptr)
20441340Ssklower 				if (kdbreadchar() != *regptr++) {
20530111Ssam 					--regptr;
20630111Ssam 					break;
20730111Ssam 				}
20830111Ssam 			if (*regptr)
20941340Ssklower 				kdblp = olp;
21030111Ssam 			else
21130136Ssam 				return ((int)p->rkern);
21230111Ssam 		}
21330111Ssam 	}
21441340Ssklower 	kdblp = olp;
21530111Ssam 	return (-1);
21630111Ssam }
21730111Ssam 
kdbprintpc()21841340Ssklower kdbprintpc()
21930111Ssam {
22030111Ssam 
22141340Ssklower 	kdbpsymoff((long)kdbpcb.pcb_pc, ISYM, ":%16t");
22241340Ssklower 	kdbprintins(ISP, (long)kdbchkget((off_t)kdbpcb.pcb_pc, ISP));
22341340Ssklower 	kdbprintc(EOR);
22430111Ssam }
225