[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.49

1.49    ! blymn       1: /*     $NetBSD: db_xxx.c,v 1.48 2007/12/02 19:35:33 ad 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.49    ! blymn      40: __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.48 2007/12/02 19:35:33 ad Exp $");
1.46      dsl        41:
1.21      briggs     42: #include "opt_kgdb.h"
                     43:
1.1       gwr        44: #include <sys/param.h>
                     45: #include <sys/systm.h>
                     46: #include <sys/kernel.h>
                     47: #include <sys/proc.h>
1.12      atatat     48: #include <sys/msgbuf.h>
1.1       gwr        49:
                     50: #include <sys/callout.h>
1.49    ! blymn      51: #include <sys/file.h>
        !            52: #include <sys/filedesc.h>
        !            53: #include <sys/lockdebug.h>
1.1       gwr        54: #include <sys/signalvar.h>
1.3       ross       55: #include <sys/resourcevar.h>
1.34      he         56: #include <sys/pool.h>
1.38      elad       57: #include <sys/kauth.h>
1.47      rmind      58: #include <sys/mqueue.h>
1.49    ! blymn      59: #include <sys/vnode.h>
1.1       gwr        60:
                     61: #include <machine/db_machdep.h>
                     62:
                     63: #include <ddb/db_access.h>
                     64: #include <ddb/db_command.h>
                     65: #include <ddb/db_interface.h>
                     66: #include <ddb/db_lex.h>
                     67: #include <ddb/db_output.h>
                     68: #include <ddb/db_sym.h>
                     69: #include <ddb/db_extern.h>
1.21      briggs     70: #ifdef KGDB
                     71: #include <sys/kgdb.h>
                     72: #endif
1.1       gwr        73:
                     74: void
1.42      matt       75: db_kill_proc(db_expr_t addr, bool haddr,
1.40      christos   76:     db_expr_t count, const char *modif)
1.1       gwr        77: {
                     78:        struct proc *p;
                     79:        db_expr_t pid, sig;
                     80:        int t;
                     81:
                     82:        /* What pid? */
                     83:        if (!db_expression(&pid)) {
                     84:                db_error("pid?\n");
1.16      simonb     85:                /*NOTREACHED*/
1.1       gwr        86:        }
                     87:        /* What sig? */
                     88:        t = db_read_token();
                     89:        if (t == tCOMMA) {
                     90:                if (!db_expression(&sig)) {
                     91:                        db_error("sig?\n");
                     92:                        /*NOTREACHED*/
                     93:                }
                     94:        } else {
                     95:                db_unread_token(t);
                     96:                sig = 15;
                     97:        }
                     98:        if (db_read_token() != tEOL) {
1.16      simonb     99:                db_error("?\n");
                    100:                /*NOTREACHED*/
1.1       gwr       101:        }
                    102:
                    103:        p = pfind((pid_t)pid);
                    104:        if (p == NULL) {
                    105:                db_error("no such proc\n");
1.16      simonb    106:                /*NOTREACHED*/
1.1       gwr       107:        }
                    108:        psignal(p, (int)sig);
                    109: }
1.21      briggs    110:
                    111: #ifdef KGDB
                    112: void
1.42      matt      113: db_kgdb_cmd(db_expr_t addr, bool haddr,
1.40      christos  114:     db_expr_t count, const char *modif)
1.21      briggs    115: {
                    116:        kgdb_active++;
                    117:        kgdb_trap(db_trap_type, DDB_REGS);
                    118:        kgdb_active--;
                    119: }
                    120: #endif
1.1       gwr       121:
                    122: void
1.49    ! blymn     123: db_show_files_cmd(db_expr_t addr, bool haddr,
        !           124:              db_expr_t count, const char *modif)
        !           125: {
        !           126:        struct proc *p;
        !           127:        int i;
        !           128:         filedesc_t *fdp;
        !           129:         fdfile_t *ff;
        !           130:         file_t *fp;
        !           131:        struct vnode *vn;
        !           132:        bool full = false;
        !           133:
        !           134:        if (modif[0] == 'f')
        !           135:                full = true;
        !           136:
        !           137:        p = (struct proc *) (intptr_t) addr;
        !           138:
        !           139:         fdp = p->p_fd;
        !           140:        for (i = 0; i < fdp->fd_nfiles; i++) {
        !           141:                if ((ff = fdp->fd_ofiles[i]) == NULL)
        !           142:                        continue;
        !           143:
        !           144:                fp = ff->ff_file;
        !           145:
        !           146:                /* Only look at vnodes... */
        !           147:                if (fp->f_type == DTYPE_VNODE) {
        !           148:                        vn = (struct vnode *) fp->f_data;
        !           149:                        vfs_vnode_print(vn, full, db_printf);
        !           150:
        !           151: #ifdef LOCKDEBUG
        !           152:                        lockdebug_lock_print(&(vn->v_uobj.vmobjlock),
        !           153:                             db_printf);
        !           154: #endif
        !           155:                }
        !           156:        }
        !           157:
        !           158: }
        !           159:
        !           160: void
1.43      rmind     161: db_show_aio_jobs(db_expr_t addr, bool haddr,
                    162:     db_expr_t count, const char *modif)
                    163: {
                    164:        aio_print_jobs(db_printf);
                    165: }
                    166:
                    167: void
1.47      rmind     168: db_show_mqueue_cmd(db_expr_t addr, bool haddr,
                    169:     db_expr_t count, const char *modif)
                    170: {
                    171:        mqueue_print_list(db_printf);
                    172: }
                    173:
                    174: void
1.42      matt      175: db_show_all_procs(db_expr_t addr, bool haddr,
1.40      christos  176:     db_expr_t count, const char *modif)
1.1       gwr       177: {
1.31      drochner  178:        const char *mode;
1.18      thorpej   179:        struct proc *p, *pp, *cp;
                    180:        struct lwp *l, *cl;
1.5       thorpej   181:        const struct proclist_desc *pd;
1.49    ! blymn     182:        char db_nbuf[MAXCOMLEN + 1];
1.16      simonb    183:
1.2       chuck     184:        if (modif[0] == 0)
1.31      drochner  185:                mode = "n";                     /* default == normal mode */
                    186:        else
                    187:                mode = strchr("mawln", modif[0]);
1.2       chuck     188:
                    189:        if (mode == NULL || *mode == 'm') {
1.36      uwe       190:                db_printf("usage: show all procs [/a] [/l] [/n] [/w]\n");
1.2       chuck     191:                db_printf("\t/a == show process address info\n");
1.18      thorpej   192:                db_printf("\t/l == show LWP info\n");
1.2       chuck     193:                db_printf("\t/n == show normal process info [default]\n");
                    194:                db_printf("\t/w == show process wait/emul info\n");
                    195:                return;
                    196:        }
1.16      simonb    197:
1.2       chuck     198:        switch (*mode) {
                    199:        case 'a':
1.3       ross      200:                db_printf(" PID       %10s %18s %18s %18s\n",
1.2       chuck     201:                    "COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
                    202:                break;
1.18      thorpej   203:        case 'l':
1.45      ad        204:                db_printf(" PID        %4s S %9s %18s %18s %-8s\n",
                    205:                    "LID", "FLAGS", "STRUCT LWP *", "NAME", "WAIT");
1.18      thorpej   206:                break;
1.2       chuck     207:        case 'n':
1.18      thorpej   208:                db_printf(" PID       %8s %8s %10s S %7s %4s %16s %7s\n",
                    209:                    "PPID", "PGRP", "UID", "FLAGS", "LWPS", "COMMAND", "WAIT");
1.2       chuck     210:                break;
                    211:        case 'w':
1.48      ad        212:                db_printf(" PID       %4s %16s %8s %4s %-12s%s\n",
                    213:                    "LID", "COMMAND", "EMUL", "PRI", "WAIT-MSG",
                    214:                    "WAIT-CHANNEL");
1.2       chuck     215:                break;
                    216:        }
                    217:
1.6       thorpej   218:        /* XXX LOCKING XXX */
1.5       thorpej   219:        pd = proclists;
1.18      thorpej   220:        cp = curproc;
                    221:        cl = curlwp;
1.14      chs       222:        for (pd = proclists; pd->pd_list != NULL; pd++) {
                    223:                LIST_FOREACH(p, pd->pd_list, p_list) {
                    224:                        pp = p->p_pptr;
                    225:                        if (p->p_stat == 0) {
                    226:                                continue;
                    227:                        }
1.24      fvdl      228:                        l = LIST_FIRST(&p->p_lwps);
1.35      uwe       229:                        db_printf("%c%-10d", (cp == p ? '>' : ' '), p->p_pid);
1.2       chuck     230:
                    231:                        switch (*mode) {
                    232:
                    233:                        case 'a':
1.45      ad        234:                                db_printf("%10.10s %18lx %18lx %18lx\n",
                    235:                                    p->p_comm, (long)p,
                    236:                                    (long)(l != NULL ? l->l_addr : 0),
                    237:                                    (long)p->p_vmspace);
1.18      thorpej   238:                                break;
                    239:                        case 'l':
1.19      pk        240:                                 while (l != NULL) {
1.45      ad        241:                                        if (l->l_name != NULL) {
1.49    ! blymn     242:                                                snprintf(db_nbuf,
        !           243:                                                         sizeof(db_nbuf),
1.45      ad        244:                                                    "%s", l->l_name);
                    245:                                        } else
1.49    ! blymn     246:                                                snprintf(db_nbuf,
        !           247:                                                    sizeof(db_nbuf),
1.45      ad        248:                                                    "%s", p->p_comm);
                    249:                                        db_printf("%c%4d %d %9x %18lx %18s %-8s\n",
1.35      uwe       250:                                            (cl == l ? '>' : ' '), l->l_lid,
1.49    ! blymn     251:                                            l->l_stat, l->l_flag, (long)l,
        !           252:                                                  db_nbuf,
1.18      thorpej   253:                                            (l->l_wchan && l->l_wmesg) ?
                    254:                                            l->l_wmesg : "");
                    255:
                    256:                                        l = LIST_NEXT(l, l_sibling);
                    257:                                        if (l)
                    258:                                                db_printf("%11s","");
1.19      pk        259:                                }
1.2       chuck     260:                                break;
                    261:                        case 'n':
1.18      thorpej   262:                                db_printf("%8d %8d %10d %d %#7x %4d %16s %7.7s\n",
1.2       chuck     263:                                    pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
1.38      elad      264:                                    kauth_cred_getuid(p->p_cred), p->p_stat, p->p_flag,
1.18      thorpej   265:                                    p->p_nlwps, p->p_comm,
1.19      pk        266:                                    (p->p_nlwps != 1) ? "*" : (
1.30      perry     267:                                    (l->l_wchan && l->l_wmesg) ?
1.18      thorpej   268:                                    l->l_wmesg : ""));
1.2       chuck     269:                                break;
                    270:
                    271:                        case 'w':
1.48      ad        272:                                 while (l != NULL) {
                    273:                                        db_printf(
                    274:                                            "%4d %16s %8s %4d %-12s %-18lx\n",
                    275:                                            l->l_lid, p->p_comm,
                    276:                                            p->p_emul->e_name, l->l_priority,
                    277:                                            (l->l_wchan && l->l_wmesg) ?
                    278:                                            l->l_wmesg : "", (long)l->l_wchan);
                    279:                                        l = LIST_NEXT(l, l_sibling);
                    280:                                        if (l != NULL) {
                    281:                                                db_printf("%c%-10d", (cp == p ?
                    282:                                                    '>' : ' '), p->p_pid);
                    283:                                        }
1.3       ross      284:                                }
1.2       chuck     285:                                break;
1.1       gwr       286:                        }
1.10      eeh       287:                }
                    288:        }
1.12      atatat    289: }
                    290:
                    291: void
1.42      matt      292: db_show_all_pools(db_expr_t addr, bool haddr,
1.40      christos  293:     db_expr_t count, const char *modif)
1.33      yamt      294: {
                    295:
                    296:        pool_printall(modif, db_printf);
                    297: }
                    298:
                    299: void
1.42      matt      300: db_dmesg(db_expr_t addr, bool haddr, db_expr_t count,
1.40      christos  301:     const char *modif)
1.12      atatat    302: {
                    303:        struct kern_msgbuf *mbp;
1.25      simonb    304:        db_expr_t print;
1.12      atatat    305:        int ch, newl, skip, i;
                    306:        char *p, *bufdata;
1.22      atatat    307:
                    308:         if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
                    309:                db_printf("message buffer not available\n");
                    310:                return;
                    311:        }
1.12      atatat    312:
                    313:        mbp = msgbufp;
                    314:        bufdata = &mbp->msg_bufc[0];
                    315:
1.25      simonb    316:        if (haddr && addr < mbp->msg_bufs)
                    317:                print = addr;
                    318:        else
                    319:                print = mbp->msg_bufs;
                    320:
1.12      atatat    321:        for (newl = skip = i = 0, p = bufdata + mbp->msg_bufx;
                    322:            i < mbp->msg_bufs; i++, p++) {
                    323:                if (p == bufdata + mbp->msg_bufs)
                    324:                        p = bufdata;
1.25      simonb    325:                if (i < mbp->msg_bufs - print)
                    326:                        continue;
1.12      atatat    327:                ch = *p;
                    328:                /* Skip "\n<.*>" syslog sequences. */
                    329:                if (skip) {
                    330:                        if (ch == '>')
                    331:                                newl = skip = 0;
                    332:                        continue;
                    333:                }
                    334:                if (newl && ch == '<') {
                    335:                        skip = 1;
                    336:                        continue;
                    337:                }
                    338:                if (ch == '\0')
                    339:                        continue;
                    340:                newl = ch == '\n';
                    341:                db_printf("%c", ch);
                    342:        }
                    343:        if (!newl)
                    344:                db_printf("\n");
1.28      thorpej   345: }
                    346:
                    347: void
1.42      matt      348: db_show_sched_qs(db_expr_t addr, bool haddr,
1.40      christos  349:     db_expr_t count, const char *modif)
1.28      thorpej   350: {
1.44      yamt      351:
                    352:        sched_print_runqueue(db_printf);
1.1       gwr       353: }

CVSweb <webmaster@jp.NetBSD.org>