[BACK]Return to db_xxx.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / ddb

Annotation of src/sys/ddb/db_xxx.c, Revision 1.64.2.1

1.64.2.1! yamt        1: /*     $NetBSD: db_xxx.c,v 1.64 2011/06/12 03:35:51 rmind Exp $        */
1.1       gwr         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.
1.26      agc        15:  * 3. Neither the name of the University nor the names of its contributors
1.1       gwr        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:  */
1.15      lukem      38:
1.46      dsl        39: #include <sys/cdefs.h>
1.64.2.1! yamt       40: __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.64 2011/06/12 03:35:51 rmind Exp $");
1.46      dsl        41:
1.57      ad         42: #ifdef _KERNEL_OPT
1.21      briggs     43: #include "opt_kgdb.h"
1.53      ad         44: #include "opt_aio.h"
1.62      rmind      45: #include "opt_mqueue.h"
1.57      ad         46: #endif
                     47:
1.59      mrg        48: #ifndef _KERNEL
                     49: #include <stdbool.h>
                     50: #endif
                     51:
1.1       gwr        52: #include <sys/param.h>
                     53: #include <sys/systm.h>
                     54: #include <sys/kernel.h>
                     55: #include <sys/proc.h>
1.12      atatat     56: #include <sys/msgbuf.h>
1.1       gwr        57: #include <sys/callout.h>
1.49      blymn      58: #include <sys/file.h>
                     59: #include <sys/filedesc.h>
                     60: #include <sys/lockdebug.h>
1.1       gwr        61: #include <sys/signalvar.h>
1.3       ross       62: #include <sys/resourcevar.h>
1.34      he         63: #include <sys/pool.h>
1.57      ad         64: #include <sys/uio.h>
1.38      elad       65: #include <sys/kauth.h>
1.47      rmind      66: #include <sys/mqueue.h>
1.49      blymn      67: #include <sys/vnode.h>
1.54      ad         68: #include <sys/module.h>
1.55      ad         69: #include <sys/cpu.h>
1.56      yamt       70: #include <sys/vmem.h>
1.1       gwr        71:
1.57      ad         72: #include <ddb/ddb.h>
1.58      mrg        73: #include <ddb/db_user.h>
1.1       gwr        74:
1.21      briggs     75: #ifdef KGDB
                     76: #include <sys/kgdb.h>
                     77: #endif
1.1       gwr        78:
                     79: void
1.42      matt       80: db_kill_proc(db_expr_t addr, bool haddr,
1.40      christos   81:     db_expr_t count, const char *modif)
1.1       gwr        82: {
1.63      christos   83: #ifdef _KERNEL /* XXX CRASH(8) */
                     84:        struct proc *p;
                     85:        ksiginfo_t      ksi;
                     86:        db_expr_t pid, sig;
                     87:        int t;
                     88:
                     89:        /* What pid? */
                     90:        if (!db_expression(&pid)) {
                     91:               db_error("pid?\n");
                     92:               /*NOTREACHED*/
                     93:        }
                     94:        /* What sig? */
                     95:        t = db_read_token();
                     96:        if (t == tCOMMA) {
                     97:               if (!db_expression(&sig)) {
                     98:                       db_error("sig?\n");
                     99:                       /*NOTREACHED*/
                    100:               }
                    101:        } else {
                    102:               db_unread_token(t);
                    103:               sig = 15;
                    104:        }
                    105:        if (db_read_token() != tEOL) {
                    106:               db_error("?\n");
                    107:               /*NOTREACHED*/
                    108:        }
1.64.2.1! yamt      109:        /* We might stop when the mutex is held or when not */
        !           110:        t = mutex_tryenter(proc_lock);
        !           111: #ifdef DIAGNOSTIC
        !           112:        if (!t) {
        !           113:               db_error("could not acquire proc_lock mutex\n");
        !           114:               /*NOTREACHED*/
        !           115:        }
        !           116: #endif
1.63      christos  117:        p = proc_find((pid_t)pid);
                    118:        if (p == NULL) {
1.64.2.1! yamt      119:                if (t)
        !           120:                        mutex_exit(proc_lock);
        !           121:                db_error("no such proc\n");
        !           122:                /*NOTREACHED*/
1.63      christos  123:        }
                    124:        KSI_INIT(&ksi);
                    125:        ksi.ksi_signo = sig;
                    126:        ksi.ksi_code = SI_USER;
                    127:        ksi.ksi_pid = 0;
                    128:        ksi.ksi_uid = 0;
1.64.2.1! yamt      129:        mutex_enter(p->p_lock);
1.63      christos  130:        kpsignal2(p, &ksi);
1.64.2.1! yamt      131:        mutex_exit(p->p_lock);
        !           132:        if (t)
        !           133:                mutex_exit(proc_lock);
1.63      christos  134: #else
1.57      ad        135:        db_printf("This command is not currently supported.\n");
1.63      christos  136: #endif
1.1       gwr       137: }
1.21      briggs    138:
                    139: #ifdef KGDB
                    140: void
1.42      matt      141: db_kgdb_cmd(db_expr_t addr, bool haddr,
1.40      christos  142:     db_expr_t count, const char *modif)
1.21      briggs    143: {
                    144:        kgdb_active++;
                    145:        kgdb_trap(db_trap_type, DDB_REGS);
                    146:        kgdb_active--;
                    147: }
                    148: #endif
1.1       gwr       149:
                    150: void
1.49      blymn     151: db_show_files_cmd(db_expr_t addr, bool haddr,
                    152:              db_expr_t count, const char *modif)
                    153: {
1.57      ad        154: #ifdef _KERNEL /* XXX CRASH(8) */
1.49      blymn     155:        struct proc *p;
                    156:        int i;
1.50      blymn     157:        filedesc_t *fdp;
                    158:        fdfile_t *ff;
                    159:        file_t *fp;
1.49      blymn     160:        struct vnode *vn;
                    161:        bool full = false;
1.61      ad        162:        fdtab_t *dt;
1.49      blymn     163:
                    164:        if (modif[0] == 'f')
                    165:                full = true;
                    166:
1.52      rmind     167:        p = (struct proc *) (uintptr_t) addr;
1.49      blymn     168:
1.50      blymn     169:        fdp = p->p_fd;
1.61      ad        170:        dt = fdp->fd_dt;
                    171:        for (i = 0; i < dt->dt_nfiles; i++) {
                    172:                if ((ff = dt->dt_ff[i]) == NULL)
1.49      blymn     173:                        continue;
                    174:
                    175:                fp = ff->ff_file;
                    176:
                    177:                /* Only look at vnodes... */
1.51      blymn     178:                if ((fp != NULL) && (fp->f_type == DTYPE_VNODE)) {
                    179:                        if (fp->f_data != NULL) {
                    180:                                vn = (struct vnode *) fp->f_data;
                    181:                                vfs_vnode_print(vn, full, db_printf);
1.49      blymn     182:
                    183: #ifdef LOCKDEBUG
1.51      blymn     184:                                db_printf("\nv_uobj.vmobjlock lock details:\n");
1.64      rmind     185:                                lockdebug_lock_print(vn->v_uobj.vmobjlock,
1.51      blymn     186:                                             db_printf);
                    187:                                db_printf("\n");
1.49      blymn     188: #endif
1.51      blymn     189:                        }
1.49      blymn     190:                }
                    191:        }
1.57      ad        192: #endif
1.49      blymn     193: }
                    194:
1.53      ad        195: #ifdef AIO
1.49      blymn     196: void
1.43      rmind     197: db_show_aio_jobs(db_expr_t addr, bool haddr,
                    198:     db_expr_t count, const char *modif)
                    199: {
1.57      ad        200:
1.43      rmind     201:        aio_print_jobs(db_printf);
                    202: }
1.53      ad        203: #endif
1.43      rmind     204:
1.62      rmind     205: #ifdef MQUEUE
1.43      rmind     206: void
1.47      rmind     207: db_show_mqueue_cmd(db_expr_t addr, bool haddr,
                    208:     db_expr_t count, const char *modif)
                    209: {
1.57      ad        210:
                    211: #ifdef _KERNEL /* XXX CRASH(8) */
1.47      rmind     212:        mqueue_print_list(db_printf);
1.57      ad        213: #endif
1.47      rmind     214: }
1.62      rmind     215: #endif
1.47      rmind     216:
                    217: void
1.54      ad        218: db_show_module_cmd(db_expr_t addr, bool haddr,
                    219:     db_expr_t count, const char *modif)
                    220: {
1.57      ad        221:
                    222: #ifdef _KERNEL /* XXX CRASH(8) */
1.54      ad        223:        module_print_list(db_printf);
1.57      ad        224: #endif
1.12      atatat    225: }
                    226:
                    227: void
1.42      matt      228: db_show_all_pools(db_expr_t addr, bool haddr,
1.40      christos  229:     db_expr_t count, const char *modif)
1.33      yamt      230: {
                    231:
1.57      ad        232: #ifdef _KERNEL /* XXX CRASH(8) */
1.33      yamt      233:        pool_printall(modif, db_printf);
1.57      ad        234: #endif
1.33      yamt      235: }
                    236:
                    237: void
1.56      yamt      238: db_show_all_vmems(db_expr_t addr, bool have_addr,
                    239:     db_expr_t count, const char *modif)
                    240: {
                    241:
1.57      ad        242: #ifdef _KERNEL /* XXX CRASH(8) */
1.56      yamt      243:        vmem_printall(modif, db_printf);
1.57      ad        244: #endif
1.56      yamt      245: }
                    246:
                    247: void
1.60      ad        248: db_dmesg(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
1.12      atatat    249: {
1.60      ad        250:        struct kern_msgbuf mb, *mbp;
1.25      simonb    251:        db_expr_t print;
1.60      ad        252:        int newl, skip, i;
                    253:        char *p, *bufdata, ch;
1.22      atatat    254:
1.60      ad        255:        if (!db_read_int("msgbufenabled")) {
                    256:                db_printf("message buffer not available\n");
                    257:                return;
                    258:        }
                    259:        mbp = (struct kern_msgbuf *)db_read_ptr("msgbufp");
                    260:        db_read_bytes((db_addr_t)mbp, sizeof(mb), (char *)&mb);
                    261:        if (mb.msg_magic != MSG_MAGIC) {
1.22      atatat    262:                db_printf("message buffer not available\n");
                    263:                return;
                    264:        }
1.12      atatat    265:
                    266:        bufdata = &mbp->msg_bufc[0];
                    267:
1.60      ad        268:        if (haddr && addr < mb.msg_bufs)
1.25      simonb    269:                print = addr;
                    270:        else
1.60      ad        271:                print = mb.msg_bufs;
1.25      simonb    272:
1.60      ad        273:        for (newl = skip = i = 0, p = bufdata + mb.msg_bufx;
                    274:            i < mb.msg_bufs; i++, p++) {
                    275:                if (p == bufdata + mb.msg_bufs)
1.12      atatat    276:                        p = bufdata;
1.60      ad        277:                if (i < mb.msg_bufs - print) {
1.25      simonb    278:                        continue;
1.60      ad        279:                }
                    280:                db_read_bytes((db_addr_t)p, sizeof(ch), &ch);
1.12      atatat    281:                /* Skip "\n<.*>" syslog sequences. */
                    282:                if (skip) {
                    283:                        if (ch == '>')
                    284:                                newl = skip = 0;
                    285:                        continue;
                    286:                }
                    287:                if (newl && ch == '<') {
                    288:                        skip = 1;
                    289:                        continue;
                    290:                }
                    291:                if (ch == '\0')
                    292:                        continue;
                    293:                newl = ch == '\n';
                    294:                db_printf("%c", ch);
                    295:        }
                    296:        if (!newl)
                    297:                db_printf("\n");
1.28      thorpej   298: }
                    299:
                    300: void
1.42      matt      301: db_show_sched_qs(db_expr_t addr, bool haddr,
1.40      christos  302:     db_expr_t count, const char *modif)
1.28      thorpej   303: {
1.44      yamt      304:
1.57      ad        305: #ifdef _KERNEL /* XXX CRASH(8) */
1.44      yamt      306:        sched_print_runqueue(db_printf);
1.57      ad        307: #endif
1.1       gwr       308: }

CVSweb <webmaster@jp.NetBSD.org>