4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1998-1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/mdb_modapi.h>
33 * Initialize the proc_t walker by either using the given starting address,
34 * or reading the value of the kernel's practive pointer. We also allocate
35 * a proc_t for storage, and save this using the walk_data pointer.
38 sp_walk_init(mdb_walk_state_t
*wsp
)
40 if (wsp
->walk_addr
== NULL
&&
41 mdb_readvar(&wsp
->walk_addr
, "practive") == -1) {
42 mdb_warn("failed to read 'practive'");
46 wsp
->walk_data
= mdb_alloc(sizeof (proc_t
), UM_SLEEP
);
51 * At each step, read a proc_t into our private storage, and then invoke
52 * the callback function. We terminate when we reach a NULL p_next pointer.
55 sp_walk_step(mdb_walk_state_t
*wsp
)
59 if (wsp
->walk_addr
== NULL
)
62 if (mdb_vread(wsp
->walk_data
, sizeof (proc_t
), wsp
->walk_addr
) == -1) {
63 mdb_warn("failed to read proc at %p", wsp
->walk_addr
);
67 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
70 wsp
->walk_addr
= (uintptr_t)(((proc_t
*)wsp
->walk_data
)->p_next
);
75 * The walker's fini function is invoked at the end of each walk. Since we
76 * dynamically allocated a proc_t in sp_walk_init, we must free it now.
79 sp_walk_fini(mdb_walk_state_t
*wsp
)
81 mdb_free(wsp
->walk_data
, sizeof (proc_t
));
85 simple_ps(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
94 * If no proc_t address was specified on the command line, we can
95 * print out all processes by invoking the walker, using this
96 * dcmd itself as the callback.
98 if (!(flags
& DCMD_ADDRSPEC
)) {
99 if (mdb_walk_dcmd("simple_proc", "simple_ps",
101 mdb_warn("failed to walk 'simple_proc'");
108 * If this is the first invocation of the command, print a nice
109 * header line for the output that will follow.
111 if (DCMD_HDRSPEC(flags
))
112 mdb_printf("%5s %s\n", "PID", "COMM");
115 * For each process, we just need to read the proc_t struct, read
116 * the pid struct addressed by p_pidp, and then print out the pid
117 * and the command name.
119 if (mdb_vread(&p
, sizeof (p
), addr
) == sizeof (p
)) {
121 if (mdb_vread(&pid
, sizeof (pid
),
122 (uintptr_t)p
.p_pidp
) == sizeof (pid
))
123 mdb_printf("%5d %s\n", pid
.pid_id
, p
.p_user
.u_comm
);
125 mdb_warn("failed to read struct pid at %p", p
.p_pidp
);
127 mdb_warn("failed to read process at %p", addr
);
133 * MDB module linkage information:
135 * We declare a list of structures describing our dcmds, a list of structures
136 * describing our walkers, and a function named _mdb_init to return a pointer
137 * to our module information.
140 static const mdb_dcmd_t dcmds
[] = {
141 { "simple_ps", NULL
, "simple process list", simple_ps
},
145 static const mdb_walker_t walkers
[] = {
146 { "simple_proc", "walk list of proc_t structures",
147 sp_walk_init
, sp_walk_step
, sp_walk_fini
},
151 static const mdb_modinfo_t modinfo
= {
152 MDB_API_VERSION
, dcmds
, walkers
155 const mdb_modinfo_t
*