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