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

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

CVSweb <webmaster@jp.NetBSD.org>