1 /* $NetBSD: db_proc.c,v 1.2 2009/03/08 11:40:00 mrg Exp $ */
4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1982, 1986, 1989, 1991, 1993
34 * The Regents of the University of California. All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * from: kern_proc.c 8.4 (Berkeley) 1/4/94
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: db_proc.c,v 1.2 2009/03/08 11:40:00 mrg Exp $");
70 #include <sys/param.h>
73 #ifdef _KERNEL /* XXX */
74 #include <sys/kauth.h>
83 return db_read_ptr("allproc");
87 db_proc_next(proc_t
*p
)
90 db_read_bytes((db_addr_t
)&p
->p_list
.le_next
, sizeof(p
), (char *)&p
);
95 db_proc_find(pid_t pid
)
100 for (p
= db_proc_first(); p
!= NULL
; p
= db_proc_next(p
)) {
101 db_read_bytes((db_addr_t
)&p
->p_pid
, sizeof(tp
),
111 db_show_all_procs(db_expr_t addr
, bool haddr
, db_expr_t count
,
114 static struct pgrp pgrp
;
117 const char *mode
, *ename
;
120 char db_nbuf
[MAXCOMLEN
+ 1], wbuf
[MAXCOMLEN
+ 1];
125 mode
= "l"; /* default == lwp mode */
127 mode
= strchr("mawln", modif
[0]);
129 if (mode
== NULL
|| *mode
== 'm') {
130 db_printf("usage: show all procs [/a] [/l] [/n] [/w]\n");
131 db_printf("\t/a == show process address info\n");
132 db_printf("\t/l == show LWP info\n");
133 db_printf("\t/n == show normal process info [default]\n");
134 db_printf("\t/w == show process wait/emul info\n");
140 db_printf("PID %10s %18s %18s %18s\n",
141 "COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
144 db_printf("PID %4s S %3s %9s %18s %18s %-8s\n",
145 "LID", "CPU", "FLAGS", "STRUCT LWP *", "NAME", "WAIT");
148 db_printf("PID %8s %8s %10s S %7s %4s %16s %7s\n",
149 "PPID", "PGRP", "UID", "FLAGS", "LWPS", "COMMAND", "WAIT");
152 db_printf("PID %4s %16s %8s %4s %-12s%s\n",
153 "LID", "COMMAND", "EMUL", "PRI", "WAIT-MSG",
158 for (pp
= db_proc_first(); pp
!= NULL
; pp
= db_proc_next(pp
)) {
159 db_read_bytes((db_addr_t
)pp
, sizeof(p
), (char *)&p
);
163 lp
= p
.p_lwps
.lh_first
;
165 db_read_bytes((db_addr_t
)lp
, sizeof(l
), (char *)&l
);
167 db_printf("%-5d", p
.p_pid
);
171 db_printf("%10.10s %18lx %18lx %18lx\n",
173 (long)(lp
!= NULL
? l
.l_addr
: 0),
178 if (l
.l_name
!= NULL
) {
179 db_read_bytes((db_addr_t
)l
.l_name
,
182 strlcpy(db_nbuf
, p
.p_comm
,
185 run
= (l
.l_stat
== LSONPROC
||
186 (l
.l_pflag
& LP_RUNNING
) != 0);
187 if (l
.l_cpu
!= NULL
) {
188 db_read_bytes((db_addr_t
)
189 &l
.l_cpu
->ci_data
.cpu_index
,
190 sizeof(cpuno
), (char *)&cpuno
);
193 if (l
.l_wchan
&& l
.l_wmesg
) {
194 db_read_bytes((db_addr_t
)l
.l_wmesg
,
195 sizeof(wbuf
), (char *)wbuf
);
199 db_printf("%c%4d %d %3d %9x %18lx %18s %-8s\n",
200 (run
? '>' : ' '), l
.l_lid
,
201 l
.l_stat
, cpuno
, l
.l_flag
, (long)lp
,
203 lp
= LIST_NEXT((&l
), l_sibling
);
205 db_printf("%-5d", p
.p_pid
);
206 db_read_bytes((db_addr_t
)lp
, sizeof(l
),
212 db_read_bytes((db_addr_t
)p
.p_pgrp
, sizeof(pgrp
),
214 if (lp
!= NULL
&& l
.l_wchan
&& l
.l_wmesg
) {
215 db_read_bytes((db_addr_t
)l
.l_wmesg
,
216 sizeof(wbuf
), (char *)wbuf
);
220 db_printf("%8d %8d %10d %d %#7x %4d %16s %7.7s\n",
221 p
.p_pptr
!= NULL
? p
.p_pid
: -1, pgrp
.pg_id
,
223 kauth_cred_getuid(p
.p_cred
),
225 /* XXX CRASH(8) */ 666,
229 (p
.p_nlwps
!= 1) ? "*" : wbuf
);
234 if (l
.l_wchan
&& l
.l_wmesg
) {
235 db_read_bytes((db_addr_t
)l
.l_wmesg
,
236 sizeof(wbuf
), (char *)wbuf
);
240 db_read_bytes((db_addr_t
)&p
.p_emul
->e_name
,
241 sizeof(ename
), (char *)&ename
);
242 db_read_bytes((db_addr_t
)ename
,
243 sizeof(db_nbuf
), db_nbuf
);
245 "%4d %16s %8s %4d %-12s %-18lx\n",
246 l
.l_lid
, p
.p_comm
, db_nbuf
,
247 l
.l_priority
, wbuf
, (long)l
.l_wchan
);
248 lp
= LIST_NEXT((&l
), l_sibling
);
250 db_printf("%-5d", p
.p_pid
);
251 db_read_bytes((db_addr_t
)lp
, sizeof(l
),