db_xxx.c revision 1.6 1 /* $NetBSD: db_xxx.c,v 1.6 1999/07/22 21:11:26 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
48 #include <sys/callout.h>
49 #include <sys/signalvar.h>
50 #include <sys/resourcevar.h>
51
52 #include <machine/db_machdep.h>
53
54 #include <ddb/db_access.h>
55 #include <ddb/db_command.h>
56 #include <ddb/db_interface.h>
57 #include <ddb/db_lex.h>
58 #include <ddb/db_output.h>
59 #include <ddb/db_sym.h>
60 #include <ddb/db_extern.h>
61
62 void
63 db_kill_proc(addr, haddr, count, modif)
64 db_expr_t addr;
65 int haddr;
66 db_expr_t count;
67 char *modif;
68 {
69 struct proc *p;
70 db_expr_t pid, sig;
71 int t;
72
73 /* What pid? */
74 if (!db_expression(&pid)) {
75 db_error("pid?\n");
76 /*NOTREACHED*/
77 }
78 /* What sig? */
79 t = db_read_token();
80 if (t == tCOMMA) {
81 if (!db_expression(&sig)) {
82 db_error("sig?\n");
83 /*NOTREACHED*/
84 }
85 } else {
86 db_unread_token(t);
87 sig = 15;
88 }
89 if (db_read_token() != tEOL) {
90 db_error("?\n");
91 /*NOTREACHED*/
92 }
93
94 p = pfind((pid_t)pid);
95 if (p == NULL) {
96 db_error("no such proc\n");
97 /*NOTREACHED*/
98 }
99 psignal(p, (int)sig);
100 }
101
102 void
103 db_show_all_procs(addr, haddr, count, modif)
104 db_expr_t addr;
105 int haddr;
106 db_expr_t count;
107 char *modif;
108 {
109 int i;
110 char *mode;
111 struct proc *p, *pp;
112 struct timeval tv[3];
113 const struct proclist_desc *pd;
114
115 if (modif[0] == 0)
116 modif[0] = 'n'; /* default == normal mode */
117
118 mode = strchr("mawn", modif[0]);
119 if (mode == NULL || *mode == 'm') {
120 db_printf("usage: show all procs [/a] [/n] [/w]\n");
121 db_printf("\t/a == show process address info\n");
122 db_printf("\t/n == show normal process info [default]\n");
123 db_printf("\t/w == show process wait/emul info\n");
124 return;
125 }
126
127 switch (*mode) {
128
129 case 'a':
130 db_printf(" PID %10s %18s %18s %18s\n",
131 "COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
132 break;
133 case 'n':
134 db_printf(" PID %10s %10s %10s S %7s %16s %7s\n",
135 "PPID", "PGRP", "UID", "FLAGS", "COMMAND", "WAIT");
136 break;
137 case 'w':
138 db_printf(" PID %10s %8s %4s %5s %5s %-12s%s\n",
139 "COMMAND", "EMUL", "PRI", "UTIME", "STIME",
140 "WAIT-MSG", "WAIT-CHANNEL");
141 break;
142 }
143
144 /* XXX LOCKING XXX */
145 pd = proclists;
146 loop:
147 for (p = LIST_FIRST(pd->pd_list); p != NULL;
148 p = LIST_NEXT(p, p_list)) {
149 pp = p->p_pptr;
150 if (p->p_stat) {
151
152 db_printf("%c%-10d", " >"[curproc == p], p->p_pid);
153
154 switch (*mode) {
155
156 case 'a':
157 db_printf("%10.10s %18p %18p %18p\n",
158 p->p_comm, p, p->p_addr, p->p_vmspace);
159 break;
160
161 case 'n':
162 db_printf("%10d %10d %10d %d %#7x %16s %7.7s\n",
163 pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
164 p->p_cred->p_ruid, p->p_stat, p->p_flag,
165 p->p_comm, (p->p_wchan && p->p_wmesg) ?
166 p->p_wmesg : "");
167 break;
168
169 case 'w':
170 db_printf("%10s %8s %4d", p->p_comm,
171 p->p_emul->e_name,p->p_priority);
172 calcru(p, tv+0, tv+1, tv+2);
173 for(i = 0; i < 2; ++i) {
174 db_printf("%4ld.%1ld", tv[i].tv_sec,
175 tv[i].tv_usec/100000);
176 }
177 if(p->p_wchan && p->p_wmesg) {
178 db_printf(" %-12s", p->p_wmesg);
179 db_printsym((db_expr_t)p->p_wchan,
180 DB_STGY_XTRN);
181 }
182 db_printf("\n");
183 break;
184
185 }
186 }
187 }
188 pd++;
189 if (pd->pd_list != NULL)
190 goto loop;
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 register struct callout *p1;
201 register int cum;
202 register int s;
203 db_expr_t offset;
204 char *name;
205
206 db_printf(" cum ticks arg func\n");
207 s = splhigh();
208 for (cum = 0, p1 = calltodo.c_next; p1; p1 = p1->c_next) {
209 register int t = p1->c_time;
210
211 if (t > 0)
212 cum += t;
213
214 db_find_sym_and_offset((db_expr_t)p1->c_func, &name, &offset);
215 if (name == NULL)
216 name = "?";
217
218 db_printf("%9d %9d %p %s (%p)\n",
219 cum, t, p1->c_arg, name, p1->c_func);
220 }
221 splx(s);
222 }
223