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