db_xxx.c revision 1.11.2.2 1 /* $NetBSD: db_xxx.c,v 1.11.2.2 2001/08/24 00:09:02 nathanw Exp $ */
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 */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/lwp.h>
47 #include <sys/proc.h>
48 #include <sys/msgbuf.h>
49
50 #include <sys/callout.h>
51 #include <sys/signalvar.h>
52 #include <sys/resourcevar.h>
53
54 #include <machine/db_machdep.h>
55
56 #include <ddb/db_access.h>
57 #include <ddb/db_command.h>
58 #include <ddb/db_interface.h>
59 #include <ddb/db_lex.h>
60 #include <ddb/db_output.h>
61 #include <ddb/db_sym.h>
62 #include <ddb/db_extern.h>
63
64 void
65 db_kill_proc(addr, haddr, count, modif)
66 db_expr_t addr;
67 int haddr;
68 db_expr_t count;
69 char *modif;
70 {
71 struct proc *p;
72 db_expr_t pid, sig;
73 int t;
74
75 /* What pid? */
76 if (!db_expression(&pid)) {
77 db_error("pid?\n");
78 /*NOTREACHED*/
79 }
80 /* What sig? */
81 t = db_read_token();
82 if (t == tCOMMA) {
83 if (!db_expression(&sig)) {
84 db_error("sig?\n");
85 /*NOTREACHED*/
86 }
87 } else {
88 db_unread_token(t);
89 sig = 15;
90 }
91 if (db_read_token() != tEOL) {
92 db_error("?\n");
93 /*NOTREACHED*/
94 }
95
96 p = pfind((pid_t)pid);
97 if (p == NULL) {
98 db_error("no such proc\n");
99 /*NOTREACHED*/
100 }
101 psignal(p, (int)sig);
102 }
103
104 void
105 db_show_all_procs(addr, haddr, count, modif)
106 db_expr_t addr;
107 int haddr;
108 db_expr_t count;
109 char *modif;
110 {
111 int i;
112
113 char *mode;
114 struct proc *p, *pp, *cp;
115 struct lwp *l, *cl;
116 struct timeval tv[3];
117 const struct proclist_desc *pd;
118
119 if (modif[0] == 0)
120 modif[0] = 'n'; /* default == normal mode */
121
122 mode = strchr("mawln", modif[0]);
123 if (mode == NULL || *mode == 'm') {
124 db_printf("usage: show all procs [/a] [/n] [/w]\n");
125 db_printf("\t/a == show process address info\n");
126 db_printf("\t/l == show LWP info\n");
127 db_printf("\t/n == show normal process info [default]\n");
128 db_printf("\t/w == show process wait/emul info\n");
129 return;
130 }
131
132 switch (*mode) {
133
134 case 'a':
135 db_printf(" PID %10s %18s %18s %18s\n",
136 "COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
137 break;
138 case 'l':
139 db_printf(" PID %4s S %7s %18s %18s %-12s\n",
140 "LID", "FLAGS", "STRUCT LWP *", "UAREA *", "WAIT");
141 break;
142 case 'n':
143 db_printf(" PID %8s %8s %10s S %7s %4s %16s %7s\n",
144 "PPID", "PGRP", "UID", "FLAGS", "LWPS", "COMMAND", "WAIT");
145 break;
146 case 'w':
147 db_printf(" PID %10s %8s %4s %5s %5s %-12s%s\n",
148 "COMMAND", "EMUL", "PRI", "UTIME", "STIME",
149 "WAIT-MSG", "WAIT-CHANNEL");
150 break;
151 }
152
153 /* XXX LOCKING XXX */
154 pd = proclists;
155 cp = curproc ? curproc->l_proc : 0;
156 cl = curproc;
157 loop:
158 for (p = LIST_FIRST(pd->pd_list); p != NULL;
159 p = LIST_NEXT(p, p_list)) {
160 pp = p->p_pptr;
161 if (p->p_stat) {
162 l = LIST_FIRST(&p->p_lwps);
163 db_printf("%c%-10d", " >"[cp == p], p->p_pid);
164
165 switch (*mode) {
166
167 case 'a':
168 db_printf("%10.10s %18p %18p %18p\n",
169 p->p_comm, p, l->l_addr, p->p_vmspace);
170 break;
171 case 'l':
172 do {
173 db_printf("%c%4d %d %#7x %18p %18p %s\n",
174 " >"[cl == l], l->l_lid,
175 l->l_stat, l->l_flag, l,
176 l->l_addr,
177 (l->l_wchan && l->l_wmesg) ?
178 l->l_wmesg : "");
179
180 l = LIST_NEXT(l, l_sibling);
181 if (l)
182 db_printf("%11s","");
183 } while (l != NULL);
184 break;
185 case 'n':
186 db_printf("%8d %8d %10d %d %#7x %4d %16s %7.7s\n",
187 pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
188 p->p_cred->p_ruid, p->p_stat, p->p_flag,
189 p->p_nlwps, p->p_comm,
190 (p->p_nlwps > 1) ? "*" : (
191 (l->l_wchan && l->l_wmesg) ?
192 l->l_wmesg : ""));
193 break;
194
195 case 'w':
196 db_printf("%10s %8s %4d", p->p_comm,
197 p->p_emul->e_name,l->l_priority);
198 calcru(p, tv+0, tv+1, tv+2);
199 for(i = 0; i < 2; ++i) {
200 db_printf("%4ld.%1ld",
201 (long)tv[i].tv_sec,
202 (long)tv[i].tv_usec/100000);
203 }
204 if(p->p_nlwps <= 1) {
205 if(l->l_wchan && l->l_wmesg) {
206 db_printf(" %-12s", l->l_wmesg);
207 db_printsym((db_expr_t)l->l_wchan,
208 DB_STGY_XTRN, db_printf);
209 } } else {
210 db_printf(" * ");
211 }
212 db_printf("\n");
213 break;
214
215 }
216 }
217 }
218 pd++;
219 if (pd->pd_list != NULL)
220 goto loop;
221 }
222
223 void
224 db_show_callout(addr, haddr, count, modif)
225 db_expr_t addr;
226 int haddr;
227 db_expr_t count;
228 char *modif;
229 {
230 extern struct callout_queue *callwheel;
231 extern int callwheelsize;
232 int i;
233
234 for (i = 0; i < callwheelsize; i++) {
235 struct callout_queue *bucket = &callwheel[i];
236 struct callout *c = TAILQ_FIRST(bucket);
237
238 if (c) db_printf("bucket %d:\n", i);
239 while (c) {
240 db_printf("%p: time %llx arg %p flags %x func %p: ",
241 c, (long long) c->c_time, c->c_arg,
242 c->c_flags, c->c_func);
243 db_printsym((u_long)c->c_func, DB_STGY_PROC, db_printf);
244 db_printf("\n");
245 c = TAILQ_NEXT(c, c_link);
246 }
247 }
248 }
249
250 void
251 db_dmesg(addr, haddr, count, modif)
252 db_expr_t addr;
253 int haddr;
254 db_expr_t count;
255 char *modif;
256 {
257 struct kern_msgbuf *mbp;
258 int ch, newl, skip, i;
259 char *p, *bufdata;
260
261 mbp = msgbufp;
262 bufdata = &mbp->msg_bufc[0];
263
264 for (newl = skip = i = 0, p = bufdata + mbp->msg_bufx;
265 i < mbp->msg_bufs; i++, p++) {
266 if (p == bufdata + mbp->msg_bufs)
267 p = bufdata;
268 ch = *p;
269 /* Skip "\n<.*>" syslog sequences. */
270 if (skip) {
271 if (ch == '>')
272 newl = skip = 0;
273 continue;
274 }
275 if (newl && ch == '<') {
276 skip = 1;
277 continue;
278 }
279 if (ch == '\0')
280 continue;
281 newl = ch == '\n';
282 db_printf("%c", ch);
283 }
284 if (!newl)
285 db_printf("\n");
286 }
287