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*41340Ssklower * @(#)kdb_print.c 7.17 (Berkeley) 05/03/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 18*41340Ssklower char *kdbBADRAD; 1930122Ssam 20*41340Ssklower ADDR kdblastframe; 21*41340Ssklower ADDR kdbcallpc; 2230111Ssam 23*41340Ssklower char *kdbBADMOD; 24*41340Ssklower char *kdblp; 25*41340Ssklower long kdbmaxpos; 26*41340Ssklower int kdbradix; 27*41340Ssklower char kdblastc; 2830111Ssam 2930111Ssam /* breakpoints */ 30*41340Ssklower BKPTR kdbbkpthead; 3130111Ssam 32*41340Ssklower extern REGLIST kdbreglist[]; 3330111Ssam 3430111Ssam /* general printing routines ($) */ 3530111Ssam 36*41340Ssklower kdbprinttrace(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 48*41340Ssklower if (kdbcntflg==0) 49*41340Ssklower kdbcntval = -1; 5030111Ssam switch (modif) { 5130111Ssam 5230111Ssam case 'd': 53*41340Ssklower if (kdbadrflg) { 54*41340Ssklower if (kdbadrval < 2 || kdbadrval > 16) 55*41340Ssklower kdberror(kdbBADRAD); 56*41340Ssklower kdbradix = kdbadrval; 5730111Ssam } 58*41340Ssklower kdbprintf("radix=%d base ten", kdbradix); 5930111Ssam break; 6030111Ssam 6130111Ssam case 'w': case 'W': 62*41340Ssklower kdbprintf("maxpos=%d", kdbmaxpos=(kdbadrflg?kdbadrval:MAXPOS)); 6330111Ssam break; 6430111Ssam 6530111Ssam case 's': case 'S': 66*41340Ssklower kdbprintf("maxoff=%d", kdbmaxoff=(kdbadrflg?kdbadrval:MAXOFF)); 6730111Ssam break; 6830111Ssam 6939915Smckusick case 'V': 70*41340Ssklower kdbprintf("variables\n"); 7130111Ssam for (i=0;i<=35;i++) 72*41340Ssklower if (kdbvar[i]) { 73*41340Ssklower kdbprintc((i<=9 ? '0' : 'a'-10) + i); 74*41340Ssklower kdbprintf(" = %R\n",kdbvar[i]); 7530111Ssam } 7630111Ssam break; 7730111Ssam 7830111Ssam case 0: case '?': 79*41340Ssklower if (p = (struct proc *)kdbvar[kdbvarchk('p')]) 80*41340Ssklower kdbprintf("pid = %d\n", p->p_pid); 8130127Ssam else 82*41340Ssklower kdbprintf("in idle loop\n"); 83*41340Ssklower kdbprinttrap(kdbvar[kdbvarchk('t')], kdbvar[kdbvarchk('c')]); 8430127Ssam /* fall thru... */ 8530111Ssam case 'r': case 'R': 86*41340Ssklower kdbprintregs(modif); 8730111Ssam return; 8830111Ssam 8930111Ssam case 'c': case 'C': 90*41340Ssklower if (kdbadrflg) { 91*41340Ssklower frame = kdbadrval; 92*41340Ssklower kdbcallpc = getprevpc(frame); 9330111Ssam } else { 94*41340Ssklower frame = kdbpcb.pcb_fp; 95*41340Ssklower kdbcallpc = kdbpcb.pcb_pc; 9630111Ssam } 97*41340Ssklower kdblastframe = NOFRAME; 9830111Ssam ntramp = 0; 99*41340Ssklower while (kdbcntval-- && frame != NOFRAME) { 10030111Ssam char *name; 10130111Ssam 102*41340Ssklower kdbchkerr(); 10330111Ssam /* check for pc in pcb (signal trampoline code) */ 104*41340Ssklower if (issignalpc(kdbcallpc)) { 10530111Ssam name = "sigtramp"; 10630111Ssam ntramp++; 10730111Ssam } else { 10830111Ssam ntramp = 0; 109*41340Ssklower (void) kdbfindsym((long)kdbcallpc, ISYM); 110*41340Ssklower if (kdbcursym) 111*41340Ssklower name = kdbcursym->n_un.n_name; 11230111Ssam else 11330111Ssam name = "?"; 11430111Ssam } 115*41340Ssklower kdbprintf("%s(", name); 11630136Ssam narg = getnargs(frame); 11737491Smckusick if (narg > 10) 11837491Smckusick narg = 10; 11930111Ssam argp = frame; 12030111Ssam if (ntramp != 1) 12130136Ssam while (narg) { 122*41340Ssklower kdbprintf("%R", 123*41340Ssklower kdbget((off_t)(argp = nextarg(argp)), 12430296Ssam DSP)); 12530136Ssam if (--narg != 0) 126*41340Ssklower kdbprintc(','); 12730111Ssam } 128*41340Ssklower kdbprintf(") at "); 129*41340Ssklower kdbpsymoff((long)kdbcallpc, ISYM, "\n"); 13030111Ssam 13130111Ssam if (modif=='C') { 132*41340Ssklower while (kdblocalsym((long)frame)) { 133*41340Ssklower word = kdbget((off_t)kdblocalval, DSP); 134*41340Ssklower kdbprintf("%8t%s:%10t", 135*41340Ssklower kdbcursym->n_un.n_name); 136*41340Ssklower if (kdberrflg) { 137*41340Ssklower kdbprintf("?\n"); 138*41340Ssklower kdberrflg = 0; 13930111Ssam } else 140*41340Ssklower kdbprintf("%R\n", word); 14130111Ssam } 14230111Ssam } 14330111Ssam if (ntramp != 1) { 144*41340Ssklower kdbcallpc = getprevpc(frame); 145*41340Ssklower kdblastframe = frame; 14630136Ssam frame = getprevframe(frame); 14730111Ssam } else 148*41340Ssklower kdbcallpc = getsignalpc(kdblastframe); 149*41340Ssklower if (!kdbadrflg && !INSTACK(frame)) 15030111Ssam break; 15130111Ssam } 15230111Ssam break; 15330111Ssam 15430111Ssam /*print externals*/ 15530111Ssam case 'e': case 'E': 156*41340Ssklower for (sp = kdbsymtab; sp < kdbesymtab; sp++) 15730111Ssam if (sp->n_type==(N_DATA|N_EXT) || 15830111Ssam sp->n_type==(N_BSS|N_EXT)) 159*41340Ssklower kdbprintf("%s:%12t%R\n", sp->n_un.n_name, 160*41340Ssklower kdbget((off_t)sp->n_value, DSP)); 16130111Ssam break; 16230111Ssam 16330111Ssam /*print breakpoints*/ 16430111Ssam case 'b': case 'B': 165*41340Ssklower kdbprintf("breakpoints\ncount%8tbkpt%24tcommand\n"); 166*41340Ssklower for (bkptr=kdbbkpthead; bkptr; bkptr=bkptr->nxtbkpt) 16730111Ssam if (bkptr->flag) { 168*41340Ssklower kdbprintf("%-8.8d",bkptr->count); 169*41340Ssklower kdbpsymoff((long)bkptr->loc,ISYM,"%24t"); 17030111Ssam comptr=bkptr->comm; 17130111Ssam while (*comptr) 172*41340Ssklower kdbprintc(*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) { 186*41340Ssklower kdbprintf("%X pid %5d%c%5d %c ", p, p->p_pid, 187*41340Ssklower p == (struct proc *)kdbvar[kdbvarchk('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) 194*41340Ssklower kdbpsymoff((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) 202*41340Ssklower kdbprintf(" ctty %x ", U->u_ttyp); 20337909Smarc #endif 204*41340Ssklower kdbprintf(" %.8s ", p->p_comm); 20537909Smarc #undef U 20637909Smarc } 20737909Smarc 208*41340Ssklower kdbprintc(EOR); 20930111Ssam } 21037909Smarc mmap[0] = savemmap; 21137909Smarc mtpr(TBIS, vmmap); 21230111Ssam break; 21337909Smarc } 21430111Ssam 21537909Smarc case 't': /* XXX - debug */ 216*41340Ssklower if (kdbadrflg) { 217*41340Ssklower kdbprintf("dev state rawq canq outq lwat hwat\n"); 21837909Smarc 219*41340Ssklower #define T ((struct tty *)kdbadrval) 220*41340Ssklower kdbprintf("%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); 224*41340Ssklower kdbprintf(" &rawq &canq &outq &outq.c_cf &rawq.c_cf\n"); 225*41340Ssklower kdbprintf(" %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 23139915Smckusick case 'v': { 23239915Smckusick register struct mount *mp; 23339915Smckusick register struct vnode *vp; 23439915Smckusick 235*41340Ssklower kdbprintf("Locked vnodes\n"); 23639915Smckusick mp = rootfs; 23739915Smckusick do { 23839915Smckusick for (vp = mp->m_mounth; vp; vp = vp->v_mountf) 23939915Smckusick if (VOP_ISLOCKED(vp)) 24039915Smckusick vprint((char *)0, vp); 24139915Smckusick mp = mp->m_next; 24239915Smckusick } while (mp != rootfs); 24339915Smckusick break; 24439915Smckusick } 24539915Smckusick 24630111Ssam default: 247*41340Ssklower kdberror(kdbBADMOD); 24830111Ssam } 24930111Ssam } 25030111Ssam 25130111Ssam static 252*41340Ssklower kdbprintregs(c) 25330111Ssam { 25430111Ssam register REGPTR p; 25530111Ssam ADDR v; 25630111Ssam 257*41340Ssklower for (p = kdbreglist; p->rname; p++) { 25830136Ssam if (c != 'R' && ishiddenreg(p)) 25930111Ssam continue; 26030111Ssam v = *p->rkern; 261*41340Ssklower kdbprintf("%s%6t%R %16t", p->rname, v); 262*41340Ssklower kdbvalpr((long)v, p->rkern == &kdbpcb.pcb_pc ? ISYM : DSYM); 263*41340Ssklower kdbprintc(EOR); 26430111Ssam } 265*41340Ssklower kdbprintpc(); 26630111Ssam } 26730111Ssam 268*41340Ssklower kdbgetreg(regnam) 26930111Ssam { 27030111Ssam register REGPTR p; 27130111Ssam register char *regptr; 27230111Ssam char *olp; 27330111Ssam 274*41340Ssklower olp = kdblp; 275*41340Ssklower for (p = kdbreglist; p->rname; p++) { 27630136Ssam regptr = p->rname; 27730111Ssam if (regnam == *regptr++) { 27830111Ssam while (*regptr) 279*41340Ssklower if (kdbreadchar() != *regptr++) { 28030111Ssam --regptr; 28130111Ssam break; 28230111Ssam } 28330111Ssam if (*regptr) 284*41340Ssklower kdblp = olp; 28530111Ssam else 28630136Ssam return ((int)p->rkern); 28730111Ssam } 28830111Ssam } 289*41340Ssklower kdblp = olp; 29030111Ssam return (-1); 29130111Ssam } 29230111Ssam 293*41340Ssklower kdbprintpc() 29430111Ssam { 29530111Ssam 296*41340Ssklower kdbpsymoff((long)kdbpcb.pcb_pc, ISYM, ":%16t"); 297*41340Ssklower kdbprintins(ISP, (long)kdbchkget((off_t)kdbpcb.pcb_pc, ISP)); 298*41340Ssklower kdbprintc(EOR); 29930111Ssam } 300