Annotation of src/sys/ddb/db_xxx.c, Revision 1.22
1.22 ! atatat 1: /* $NetBSD: db_xxx.c,v 1.21 2003/04/28 02:49:55 briggs 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.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: *
35: * from: kern_proc.c 8.4 (Berkeley) 1/4/94
36: */
37:
38: /*
39: * Miscellaneous DDB functions that are intimate (xxx) with various
40: * data structures and functions used by the kernel (proc, callout).
41: */
1.15 lukem 42:
1.21 briggs 43: #include "opt_kgdb.h"
44:
1.15 lukem 45: #include <sys/cdefs.h>
1.22 ! atatat 46: __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.21 2003/04/28 02:49:55 briggs Exp $");
1.1 gwr 47:
48: #include <sys/param.h>
49: #include <sys/systm.h>
50: #include <sys/kernel.h>
51: #include <sys/proc.h>
1.12 atatat 52: #include <sys/msgbuf.h>
1.1 gwr 53:
54: #include <sys/callout.h>
55: #include <sys/signalvar.h>
1.3 ross 56: #include <sys/resourcevar.h>
1.1 gwr 57:
58: #include <machine/db_machdep.h>
59:
60: #include <ddb/db_access.h>
61: #include <ddb/db_command.h>
62: #include <ddb/db_interface.h>
63: #include <ddb/db_lex.h>
64: #include <ddb/db_output.h>
65: #include <ddb/db_sym.h>
66: #include <ddb/db_extern.h>
1.21 briggs 67: #ifdef KGDB
68: #include <sys/kgdb.h>
69: #endif
1.1 gwr 70:
71: void
1.16 simonb 72: db_kill_proc(db_expr_t addr, int haddr, db_expr_t count, 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
109: db_kgdb_cmd(db_expr_t addr, int haddr, db_expr_t count, char *modif)
110: {
111: kgdb_active++;
112: kgdb_trap(db_trap_type, DDB_REGS);
113: kgdb_active--;
114: }
115: #endif
1.1 gwr 116:
117: void
1.16 simonb 118: db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
1.1 gwr 119: {
1.3 ross 120: int i;
1.18 thorpej 121:
1.2 chuck 122: char *mode;
1.18 thorpej 123: struct proc *p, *pp, *cp;
124: struct lwp *l, *cl;
1.14 chs 125: struct timeval tv[2];
1.5 thorpej 126: const struct proclist_desc *pd;
1.16 simonb 127:
1.2 chuck 128: if (modif[0] == 0)
129: modif[0] = 'n'; /* default == normal mode */
130:
1.18 thorpej 131: mode = strchr("mawln", modif[0]);
1.2 chuck 132: if (mode == NULL || *mode == 'm') {
133: db_printf("usage: show all procs [/a] [/n] [/w]\n");
134: db_printf("\t/a == show process address info\n");
1.18 thorpej 135: db_printf("\t/l == show LWP info\n");
1.2 chuck 136: db_printf("\t/n == show normal process info [default]\n");
137: db_printf("\t/w == show process wait/emul info\n");
138: return;
139: }
1.16 simonb 140:
1.2 chuck 141: switch (*mode) {
142: case 'a':
1.3 ross 143: db_printf(" PID %10s %18s %18s %18s\n",
1.2 chuck 144: "COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
145: break;
1.18 thorpej 146: case 'l':
147: db_printf(" PID %4s S %7s %18s %18s %-12s\n",
148: "LID", "FLAGS", "STRUCT LWP *", "UAREA *", "WAIT");
149: break;
1.2 chuck 150: case 'n':
1.18 thorpej 151: db_printf(" PID %8s %8s %10s S %7s %4s %16s %7s\n",
152: "PPID", "PGRP", "UID", "FLAGS", "LWPS", "COMMAND", "WAIT");
1.2 chuck 153: break;
154: case 'w':
1.3 ross 155: db_printf(" PID %10s %8s %4s %5s %5s %-12s%s\n",
156: "COMMAND", "EMUL", "PRI", "UTIME", "STIME",
157: "WAIT-MSG", "WAIT-CHANNEL");
1.2 chuck 158: break;
159: }
160:
1.6 thorpej 161: /* XXX LOCKING XXX */
1.5 thorpej 162: pd = proclists;
1.18 thorpej 163: cp = curproc;
164: cl = curlwp;
1.14 chs 165: for (pd = proclists; pd->pd_list != NULL; pd++) {
166: LIST_FOREACH(p, pd->pd_list, p_list) {
167: pp = p->p_pptr;
168: if (p->p_stat == 0) {
169: continue;
170: }
1.18 thorpej 171: l = LIST_FIRST(&p->p_lwps);
172: db_printf("%c%-10d", " >"[cp == p], p->p_pid);
1.2 chuck 173:
174: switch (*mode) {
175:
176: case 'a':
177: db_printf("%10.10s %18p %18p %18p\n",
1.19 pk 178: p->p_comm, p,
179: l != NULL ? l->l_addr : 0,
180: p->p_vmspace);
1.18 thorpej 181: break;
182: case 'l':
1.19 pk 183: while (l != NULL) {
1.18 thorpej 184: db_printf("%c%4d %d %#7x %18p %18p %s\n",
185: " >"[cl == l], l->l_lid,
186: l->l_stat, l->l_flag, l,
187: l->l_addr,
188: (l->l_wchan && l->l_wmesg) ?
189: l->l_wmesg : "");
190:
191: l = LIST_NEXT(l, l_sibling);
192: if (l)
193: db_printf("%11s","");
1.19 pk 194: }
1.2 chuck 195: break;
196: case 'n':
1.18 thorpej 197: db_printf("%8d %8d %10d %d %#7x %4d %16s %7.7s\n",
1.2 chuck 198: pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
199: p->p_cred->p_ruid, p->p_stat, p->p_flag,
1.18 thorpej 200: p->p_nlwps, p->p_comm,
1.19 pk 201: (p->p_nlwps != 1) ? "*" : (
1.18 thorpej 202: (l->l_wchan && l->l_wmesg) ?
203: l->l_wmesg : ""));
1.2 chuck 204: break;
205:
206: case 'w':
1.3 ross 207: db_printf("%10s %8s %4d", p->p_comm,
1.19 pk 208: p->p_emul->e_name,
209: (l != NULL) ? l->l_priority : -1);
1.14 chs 210: calcru(p, &tv[0], &tv[1], NULL);
211: for (i = 0; i < 2; ++i) {
1.8 kleink 212: db_printf("%4ld.%1ld",
213: (long)tv[i].tv_sec,
214: (long)tv[i].tv_usec/100000);
1.3 ross 215: }
1.19 pk 216: if (p->p_nlwps == 1) {
1.18 thorpej 217: if (l->l_wchan && l->l_wmesg) {
218: db_printf(" %-12s", l->l_wmesg);
1.17 scw 219: db_printsym(
1.18 thorpej 220: (db_expr_t)(intptr_t)l->l_wchan,
1.9 jhawk 221: DB_STGY_XTRN, db_printf);
1.18 thorpej 222: } } else {
223: db_printf(" * ");
1.3 ross 224: }
225: db_printf("\n");
1.2 chuck 226: break;
227:
1.1 gwr 228: }
1.10 eeh 229: }
230: }
1.12 atatat 231: }
232:
233: void
1.16 simonb 234: db_dmesg(db_expr_t addr, int haddr, db_expr_t count, char *modif)
1.12 atatat 235: {
236: struct kern_msgbuf *mbp;
237: int ch, newl, skip, i;
238: char *p, *bufdata;
1.22 ! atatat 239:
! 240: if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
! 241: db_printf("message buffer not available\n");
! 242: return;
! 243: }
1.12 atatat 244:
245: mbp = msgbufp;
246: bufdata = &mbp->msg_bufc[0];
247:
248: for (newl = skip = i = 0, p = bufdata + mbp->msg_bufx;
249: i < mbp->msg_bufs; i++, p++) {
250: if (p == bufdata + mbp->msg_bufs)
251: p = bufdata;
252: ch = *p;
253: /* Skip "\n<.*>" syslog sequences. */
254: if (skip) {
255: if (ch == '>')
256: newl = skip = 0;
257: continue;
258: }
259: if (newl && ch == '<') {
260: skip = 1;
261: continue;
262: }
263: if (ch == '\0')
264: continue;
265: newl = ch == '\n';
266: db_printf("%c", ch);
267: }
268: if (!newl)
269: db_printf("\n");
1.1 gwr 270: }
CVSweb <webmaster@jp.NetBSD.org>