Home | History | Annotate | Line # | Download | only in ddb
db_xxx.c revision 1.57
      1 /*	$NetBSD: db_xxx.c,v 1.57 2009/03/07 22:02:17 ad Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1989, 1991, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	from: kern_proc.c	8.4 (Berkeley) 1/4/94
     32  */
     33 
     34 /*
     35  * Miscellaneous DDB functions that are intimate (xxx) with various
     36  * data structures and functions used by the kernel (proc, callout).
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.57 2009/03/07 22:02:17 ad Exp $");
     41 
     42 #ifdef _KERNEL_OPT
     43 #include "opt_kgdb.h"
     44 #include "opt_aio.h"
     45 #endif
     46 
     47 #include <ddb/db_user.h>
     48 
     49 #include <sys/param.h>
     50 #include <sys/systm.h>
     51 #include <sys/kernel.h>
     52 #include <sys/proc.h>
     53 #include <sys/msgbuf.h>
     54 #include <sys/callout.h>
     55 #include <sys/file.h>
     56 #include <sys/filedesc.h>
     57 #include <sys/lockdebug.h>
     58 #include <sys/signalvar.h>
     59 #include <sys/resourcevar.h>
     60 #include <sys/pool.h>
     61 #include <sys/uio.h>
     62 #include <sys/kauth.h>
     63 #include <sys/mqueue.h>
     64 #include <sys/vnode.h>
     65 #include <sys/module.h>
     66 #include <sys/cpu.h>
     67 #include <sys/vmem.h>
     68 
     69 #include <ddb/ddb.h>
     70 
     71 #ifdef KGDB
     72 #include <sys/kgdb.h>
     73 #endif
     74 
     75 void
     76 db_kill_proc(db_expr_t addr, bool haddr,
     77     db_expr_t count, const char *modif)
     78 {
     79 
     80 	db_printf("This command is not currently supported.\n");
     81 }
     82 
     83 #ifdef KGDB
     84 void
     85 db_kgdb_cmd(db_expr_t addr, bool haddr,
     86     db_expr_t count, const char *modif)
     87 {
     88 	kgdb_active++;
     89 	kgdb_trap(db_trap_type, DDB_REGS);
     90 	kgdb_active--;
     91 }
     92 #endif
     93 
     94 void
     95 db_show_files_cmd(db_expr_t addr, bool haddr,
     96 	      db_expr_t count, const char *modif)
     97 {
     98 #ifdef _KERNEL	/* XXX CRASH(8) */
     99 	struct proc *p;
    100 	int i;
    101 	filedesc_t *fdp;
    102 	fdfile_t *ff;
    103 	file_t *fp;
    104 	struct vnode *vn;
    105 	bool full = false;
    106 
    107 	if (modif[0] == 'f')
    108 		full = true;
    109 
    110 	p = (struct proc *) (uintptr_t) addr;
    111 
    112 	fdp = p->p_fd;
    113 	for (i = 0; i < fdp->fd_nfiles; i++) {
    114 		if ((ff = fdp->fd_ofiles[i]) == NULL)
    115 			continue;
    116 
    117 		fp = ff->ff_file;
    118 
    119 		/* Only look at vnodes... */
    120 		if ((fp != NULL) && (fp->f_type == DTYPE_VNODE)) {
    121 			if (fp->f_data != NULL) {
    122 				vn = (struct vnode *) fp->f_data;
    123 				vfs_vnode_print(vn, full, db_printf);
    124 
    125 #ifdef LOCKDEBUG
    126 				db_printf("\nv_uobj.vmobjlock lock details:\n");
    127 				lockdebug_lock_print(&(vn->v_uobj.vmobjlock),
    128 					     db_printf);
    129 				db_printf("\n");
    130 #endif
    131 			}
    132 		}
    133 	}
    134 #endif
    135 }
    136 
    137 #ifdef AIO
    138 void
    139 db_show_aio_jobs(db_expr_t addr, bool haddr,
    140     db_expr_t count, const char *modif)
    141 {
    142 
    143 	aio_print_jobs(db_printf);
    144 }
    145 #endif
    146 
    147 void
    148 db_show_mqueue_cmd(db_expr_t addr, bool haddr,
    149     db_expr_t count, const char *modif)
    150 {
    151 
    152 #ifdef _KERNEL	/* XXX CRASH(8) */
    153 	mqueue_print_list(db_printf);
    154 #endif
    155 }
    156 
    157 void
    158 db_show_module_cmd(db_expr_t addr, bool haddr,
    159     db_expr_t count, const char *modif)
    160 {
    161 
    162 #ifdef _KERNEL	/* XXX CRASH(8) */
    163 	module_print_list(db_printf);
    164 #endif
    165 }
    166 
    167 void
    168 db_show_all_pools(db_expr_t addr, bool haddr,
    169     db_expr_t count, const char *modif)
    170 {
    171 
    172 #ifdef _KERNEL	/* XXX CRASH(8) */
    173 	pool_printall(modif, db_printf);
    174 #endif
    175 }
    176 
    177 void
    178 db_show_all_vmems(db_expr_t addr, bool have_addr,
    179     db_expr_t count, const char *modif)
    180 {
    181 
    182 #ifdef _KERNEL	/* XXX CRASH(8) */
    183 	vmem_printall(modif, db_printf);
    184 #endif
    185 }
    186 
    187 void
    188 db_dmesg(db_expr_t addr, bool haddr, db_expr_t count,
    189     const char *modif)
    190 {
    191 #ifdef _KERNEL	/* XXX CRASH(8) */
    192 	struct kern_msgbuf *mbp;
    193 	db_expr_t print;
    194 	int ch, newl, skip, i;
    195 	char *p, *bufdata;
    196 
    197         if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
    198 		db_printf("message buffer not available\n");
    199 		return;
    200 	}
    201 
    202 	mbp = msgbufp;
    203 	bufdata = &mbp->msg_bufc[0];
    204 
    205 	if (haddr && addr < mbp->msg_bufs)
    206 		print = addr;
    207 	else
    208 		print = mbp->msg_bufs;
    209 
    210 	for (newl = skip = i = 0, p = bufdata + mbp->msg_bufx;
    211 	    i < mbp->msg_bufs; i++, p++) {
    212 		if (p == bufdata + mbp->msg_bufs)
    213 			p = bufdata;
    214 		if (i < mbp->msg_bufs - print)
    215 			continue;
    216 		ch = *p;
    217 		/* Skip "\n<.*>" syslog sequences. */
    218 		if (skip) {
    219 			if (ch == '>')
    220 				newl = skip = 0;
    221 			continue;
    222 		}
    223 		if (newl && ch == '<') {
    224 			skip = 1;
    225 			continue;
    226 		}
    227 		if (ch == '\0')
    228 			continue;
    229 		newl = ch == '\n';
    230 		db_printf("%c", ch);
    231 	}
    232 	if (!newl)
    233 		db_printf("\n");
    234 #endif
    235 }
    236 
    237 void
    238 db_show_sched_qs(db_expr_t addr, bool haddr,
    239     db_expr_t count, const char *modif)
    240 {
    241 
    242 #ifdef _KERNEL	/* XXX CRASH(8) */
    243 	sched_print_runqueue(db_printf);
    244 #endif
    245 }
    246