Home | History | Annotate | Line # | Download | only in ddb
db_xxx.c revision 1.62.4.1
      1 /*	$NetBSD: db_xxx.c,v 1.62.4.1 2010/03/16 15:38:05 rmind 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.62.4.1 2010/03/16 15:38:05 rmind Exp $");
     41 
     42 #ifdef _KERNEL_OPT
     43 #include "opt_kgdb.h"
     44 #include "opt_aio.h"
     45 #include "opt_mqueue.h"
     46 #endif
     47 
     48 #ifndef _KERNEL
     49 #include <stdbool.h>
     50 #endif
     51 
     52 #include <sys/param.h>
     53 #include <sys/systm.h>
     54 #include <sys/kernel.h>
     55 #include <sys/proc.h>
     56 #include <sys/msgbuf.h>
     57 #include <sys/callout.h>
     58 #include <sys/file.h>
     59 #include <sys/filedesc.h>
     60 #include <sys/lockdebug.h>
     61 #include <sys/signalvar.h>
     62 #include <sys/resourcevar.h>
     63 #include <sys/pool.h>
     64 #include <sys/uio.h>
     65 #include <sys/kauth.h>
     66 #include <sys/mqueue.h>
     67 #include <sys/vnode.h>
     68 #include <sys/module.h>
     69 #include <sys/cpu.h>
     70 #include <sys/vmem.h>
     71 
     72 #include <ddb/ddb.h>
     73 #include <ddb/db_user.h>
     74 
     75 #ifdef KGDB
     76 #include <sys/kgdb.h>
     77 #endif
     78 
     79 void
     80 db_kill_proc(db_expr_t addr, bool haddr,
     81     db_expr_t count, const char *modif)
     82 {
     83 
     84 	db_printf("This command is not currently supported.\n");
     85 }
     86 
     87 #ifdef KGDB
     88 void
     89 db_kgdb_cmd(db_expr_t addr, bool haddr,
     90     db_expr_t count, const char *modif)
     91 {
     92 	kgdb_active++;
     93 	kgdb_trap(db_trap_type, DDB_REGS);
     94 	kgdb_active--;
     95 }
     96 #endif
     97 
     98 void
     99 db_show_files_cmd(db_expr_t addr, bool haddr,
    100 	      db_expr_t count, const char *modif)
    101 {
    102 #ifdef _KERNEL	/* XXX CRASH(8) */
    103 	struct proc *p;
    104 	int i;
    105 	filedesc_t *fdp;
    106 	fdfile_t *ff;
    107 	file_t *fp;
    108 	struct vnode *vn;
    109 	bool full = false;
    110 	fdtab_t *dt;
    111 
    112 	if (modif[0] == 'f')
    113 		full = true;
    114 
    115 	p = (struct proc *) (uintptr_t) addr;
    116 
    117 	fdp = p->p_fd;
    118 	dt = fdp->fd_dt;
    119 	for (i = 0; i < dt->dt_nfiles; i++) {
    120 		if ((ff = dt->dt_ff[i]) == NULL)
    121 			continue;
    122 
    123 		fp = ff->ff_file;
    124 
    125 		/* Only look at vnodes... */
    126 		if ((fp != NULL) && (fp->f_type == DTYPE_VNODE)) {
    127 			if (fp->f_data != NULL) {
    128 				vn = (struct vnode *) fp->f_data;
    129 				vfs_vnode_print(vn, full, db_printf);
    130 
    131 #ifdef LOCKDEBUG
    132 				db_printf("\nv_uobj.vmobjlock lock details:\n");
    133 				lockdebug_lock_print(vn->v_uobj.vmobjlock,
    134 					     db_printf);
    135 				db_printf("\n");
    136 #endif
    137 			}
    138 		}
    139 	}
    140 #endif
    141 }
    142 
    143 #ifdef AIO
    144 void
    145 db_show_aio_jobs(db_expr_t addr, bool haddr,
    146     db_expr_t count, const char *modif)
    147 {
    148 
    149 	aio_print_jobs(db_printf);
    150 }
    151 #endif
    152 
    153 #ifdef MQUEUE
    154 void
    155 db_show_mqueue_cmd(db_expr_t addr, bool haddr,
    156     db_expr_t count, const char *modif)
    157 {
    158 
    159 #ifdef _KERNEL	/* XXX CRASH(8) */
    160 	mqueue_print_list(db_printf);
    161 #endif
    162 }
    163 #endif
    164 
    165 void
    166 db_show_module_cmd(db_expr_t addr, bool haddr,
    167     db_expr_t count, const char *modif)
    168 {
    169 
    170 #ifdef _KERNEL	/* XXX CRASH(8) */
    171 	module_print_list(db_printf);
    172 #endif
    173 }
    174 
    175 void
    176 db_show_all_pools(db_expr_t addr, bool haddr,
    177     db_expr_t count, const char *modif)
    178 {
    179 
    180 #ifdef _KERNEL	/* XXX CRASH(8) */
    181 	pool_printall(modif, db_printf);
    182 #endif
    183 }
    184 
    185 void
    186 db_show_all_vmems(db_expr_t addr, bool have_addr,
    187     db_expr_t count, const char *modif)
    188 {
    189 
    190 #ifdef _KERNEL	/* XXX CRASH(8) */
    191 	vmem_printall(modif, db_printf);
    192 #endif
    193 }
    194 
    195 void
    196 db_dmesg(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
    197 {
    198 	struct kern_msgbuf mb, *mbp;
    199 	db_expr_t print;
    200 	int newl, skip, i;
    201 	char *p, *bufdata, ch;
    202 
    203 	if (!db_read_int("msgbufenabled")) {
    204 		db_printf("message buffer not available\n");
    205 		return;
    206 	}
    207 	mbp = (struct kern_msgbuf *)db_read_ptr("msgbufp");
    208 	db_read_bytes((db_addr_t)mbp, sizeof(mb), (char *)&mb);
    209 	if (mb.msg_magic != MSG_MAGIC) {
    210 		db_printf("message buffer not available\n");
    211 		return;
    212 	}
    213 
    214 	bufdata = &mbp->msg_bufc[0];
    215 
    216 	if (haddr && addr < mb.msg_bufs)
    217 		print = addr;
    218 	else
    219 		print = mb.msg_bufs;
    220 
    221 	for (newl = skip = i = 0, p = bufdata + mb.msg_bufx;
    222 	    i < mb.msg_bufs; i++, p++) {
    223 		if (p == bufdata + mb.msg_bufs)
    224 			p = bufdata;
    225 		if (i < mb.msg_bufs - print) {
    226 			continue;
    227 		}
    228 		db_read_bytes((db_addr_t)p, sizeof(ch), &ch);
    229 		/* Skip "\n<.*>" syslog sequences. */
    230 		if (skip) {
    231 			if (ch == '>')
    232 				newl = skip = 0;
    233 			continue;
    234 		}
    235 		if (newl && ch == '<') {
    236 			skip = 1;
    237 			continue;
    238 		}
    239 		if (ch == '\0')
    240 			continue;
    241 		newl = ch == '\n';
    242 		db_printf("%c", ch);
    243 	}
    244 	if (!newl)
    245 		db_printf("\n");
    246 }
    247 
    248 void
    249 db_show_sched_qs(db_expr_t addr, bool haddr,
    250     db_expr_t count, const char *modif)
    251 {
    252 
    253 #ifdef _KERNEL	/* XXX CRASH(8) */
    254 	sched_print_runqueue(db_printf);
    255 #endif
    256 }
    257