db_xxx.c revision 1.13 1 /* $NetBSD: db_xxx.c,v 1.13 2001/09/11 04:32:19 thorpej 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[3];
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 loop:
148 for (p = LIST_FIRST(pd->pd_list); p != NULL;
149 p = LIST_NEXT(p, p_list)) {
150 pp = p->p_pptr;
151 if (p->p_stat) {
152
153 db_printf("%c%-10d", " >"[curproc == p], p->p_pid);
154
155 switch (*mode) {
156
157 case 'a':
158 db_printf("%10.10s %18p %18p %18p\n",
159 p->p_comm, p, p->p_addr, p->p_vmspace);
160 break;
161
162 case 'n':
163 db_printf("%10d %10d %10d %d %#7x %16s %7.7s\n",
164 pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
165 p->p_cred->p_ruid, p->p_stat, p->p_flag,
166 p->p_comm, (p->p_wchan && p->p_wmesg) ?
167 p->p_wmesg : "");
168 break;
169
170 case 'w':
171 db_printf("%10s %8s %4d", p->p_comm,
172 p->p_emul->e_name,p->p_priority);
173 calcru(p, tv+0, tv+1, tv+2);
174 for(i = 0; i < 2; ++i) {
175 db_printf("%4ld.%1ld",
176 (long)tv[i].tv_sec,
177 (long)tv[i].tv_usec/100000);
178 }
179 if(p->p_wchan && p->p_wmesg) {
180 db_printf(" %-12s", p->p_wmesg);
181 db_printsym((db_expr_t)p->p_wchan,
182 DB_STGY_XTRN, db_printf);
183 }
184 db_printf("\n");
185 break;
186
187 }
188 }
189 }
190 pd++;
191 if (pd->pd_list != NULL)
192 goto loop;
193 }
194
195 void
196 db_show_callout(addr, haddr, count, modif)
197 db_expr_t addr;
198 int haddr;
199 db_expr_t count;
200 char *modif;
201 {
202 extern struct callout_queue *callwheel;
203 extern int callwheelsize;
204 uint64_t hint;
205 int i;
206
207 for (i = 0; i < callwheelsize; i++) {
208 struct callout_queue *bucket = &callwheel[i];
209 struct callout *c = TAILQ_FIRST(&bucket->cq_q);
210
211 if (c) {
212 db_printf("bucket %d (hint %llx):\n", i,
213 (long long) bucket->cq_hint);
214 hint = UQUAD_MAX;
215 while (c) {
216 if (c->c_time < hint)
217 hint = c->c_time;
218 db_printf("%p: time %llx arg %p flags %x "
219 "func %p: ", c, (long long) c->c_time,
220 c->c_arg, c->c_flags, c->c_func);
221 db_printsym((u_long)c->c_func, DB_STGY_PROC,
222 db_printf);
223 db_printf("\n");
224 c = TAILQ_NEXT(c, c_link);
225 }
226 if (bucket->cq_hint < hint)
227 printf("** HINT IS STALE\n");
228 }
229 }
230 }
231
232 void
233 db_dmesg(addr, haddr, count, modif)
234 db_expr_t addr;
235 int haddr;
236 db_expr_t count;
237 char *modif;
238 {
239 struct kern_msgbuf *mbp;
240 int ch, newl, skip, i;
241 char *p, *bufdata;
242
243 mbp = msgbufp;
244 bufdata = &mbp->msg_bufc[0];
245
246 for (newl = skip = i = 0, p = bufdata + mbp->msg_bufx;
247 i < mbp->msg_bufs; i++, p++) {
248 if (p == bufdata + mbp->msg_bufs)
249 p = bufdata;
250 ch = *p;
251 /* Skip "\n<.*>" syslog sequences. */
252 if (skip) {
253 if (ch == '>')
254 newl = skip = 0;
255 continue;
256 }
257 if (newl && ch == '<') {
258 skip = 1;
259 continue;
260 }
261 if (ch == '\0')
262 continue;
263 newl = ch == '\n';
264 db_printf("%c", ch);
265 }
266 if (!newl)
267 db_printf("\n");
268 }
269