1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <mdb/mdb_param.h>
30*0Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
31*0Sstevel@tonic-gate #include <mdb/mdb_ks.h>
32*0Sstevel@tonic-gate #include <mdb/mdb_ctf.h>
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include <sys/types.h>
35*0Sstevel@tonic-gate #include <sys/thread.h>
36*0Sstevel@tonic-gate #include <sys/session.h>
37*0Sstevel@tonic-gate #include <sys/user.h>
38*0Sstevel@tonic-gate #include <sys/proc.h>
39*0Sstevel@tonic-gate #include <sys/var.h>
40*0Sstevel@tonic-gate #include <sys/t_lock.h>
41*0Sstevel@tonic-gate #include <sys/callo.h>
42*0Sstevel@tonic-gate #include <sys/priocntl.h>
43*0Sstevel@tonic-gate #include <sys/class.h>
44*0Sstevel@tonic-gate #include <sys/regset.h>
45*0Sstevel@tonic-gate #include <sys/stack.h>
46*0Sstevel@tonic-gate #include <sys/cpuvar.h>
47*0Sstevel@tonic-gate #include <sys/vnode.h>
48*0Sstevel@tonic-gate #include <sys/vfs.h>
49*0Sstevel@tonic-gate #include <sys/flock_impl.h>
50*0Sstevel@tonic-gate #include <sys/kmem_impl.h>
51*0Sstevel@tonic-gate #include <sys/vmem_impl.h>
52*0Sstevel@tonic-gate #include <sys/kstat.h>
53*0Sstevel@tonic-gate #include <vm/seg_vn.h>
54*0Sstevel@tonic-gate #include <vm/anon.h>
55*0Sstevel@tonic-gate #include <vm/as.h>
56*0Sstevel@tonic-gate #include <vm/seg_map.h>
57*0Sstevel@tonic-gate #include <sys/dditypes.h>
58*0Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
59*0Sstevel@tonic-gate #include <sys/sysmacros.h>
60*0Sstevel@tonic-gate #include <sys/sysconf.h>
61*0Sstevel@tonic-gate #include <sys/task.h>
62*0Sstevel@tonic-gate #include <sys/project.h>
63*0Sstevel@tonic-gate #include <sys/taskq.h>
64*0Sstevel@tonic-gate #include <sys/taskq_impl.h>
65*0Sstevel@tonic-gate #include <sys/errorq_impl.h>
66*0Sstevel@tonic-gate #include <sys/cred_impl.h>
67*0Sstevel@tonic-gate #include <sys/zone.h>
68*0Sstevel@tonic-gate #include <sys/panic.h>
69*0Sstevel@tonic-gate #include <regex.h>
70*0Sstevel@tonic-gate #include <sys/port_impl.h>
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate #include "contract.h"
73*0Sstevel@tonic-gate #include "cpupart_mdb.h"
74*0Sstevel@tonic-gate #include "devinfo.h"
75*0Sstevel@tonic-gate #include "leaky.h"
76*0Sstevel@tonic-gate #include "lgrp.h"
77*0Sstevel@tonic-gate #include "list.h"
78*0Sstevel@tonic-gate #include "log.h"
79*0Sstevel@tonic-gate #include "kgrep.h"
80*0Sstevel@tonic-gate #include "kmem.h"
81*0Sstevel@tonic-gate #include "bio.h"
82*0Sstevel@tonic-gate #include "streams.h"
83*0Sstevel@tonic-gate #include "cyclic.h"
84*0Sstevel@tonic-gate #include "findstack.h"
85*0Sstevel@tonic-gate #include "ndievents.h"
86*0Sstevel@tonic-gate #include "mmd.h"
87*0Sstevel@tonic-gate #include "net.h"
88*0Sstevel@tonic-gate #include "nvpair.h"
89*0Sstevel@tonic-gate #include "ctxop.h"
90*0Sstevel@tonic-gate #include "tsd.h"
91*0Sstevel@tonic-gate #include "thread.h"
92*0Sstevel@tonic-gate #include "memory.h"
93*0Sstevel@tonic-gate #include "sobj.h"
94*0Sstevel@tonic-gate #include "sysevent.h"
95*0Sstevel@tonic-gate #include "rctl.h"
96*0Sstevel@tonic-gate #include "typegraph.h"
97*0Sstevel@tonic-gate #include "ldi.h"
98*0Sstevel@tonic-gate #include "vfs.h"
99*0Sstevel@tonic-gate #include "zone.h"
100*0Sstevel@tonic-gate #include "modhash.h"
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate /*
103*0Sstevel@tonic-gate  * Surely this is defined somewhere...
104*0Sstevel@tonic-gate  */
105*0Sstevel@tonic-gate #define	NINTR		16
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate #ifndef STACK_BIAS
108*0Sstevel@tonic-gate #define	STACK_BIAS	0
109*0Sstevel@tonic-gate #endif
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate static char
112*0Sstevel@tonic-gate pstat2ch(uchar_t state)
113*0Sstevel@tonic-gate {
114*0Sstevel@tonic-gate 	switch (state) {
115*0Sstevel@tonic-gate 		case SSLEEP: return ('S');
116*0Sstevel@tonic-gate 		case SRUN: return ('R');
117*0Sstevel@tonic-gate 		case SZOMB: return ('Z');
118*0Sstevel@tonic-gate 		case SIDL: return ('I');
119*0Sstevel@tonic-gate 		case SONPROC: return ('O');
120*0Sstevel@tonic-gate 		case SSTOP: return ('T');
121*0Sstevel@tonic-gate 		default: return ('?');
122*0Sstevel@tonic-gate 	}
123*0Sstevel@tonic-gate }
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate #define	PS_PRTTHREADS	0x1
126*0Sstevel@tonic-gate #define	PS_PRTLWPS	0x2
127*0Sstevel@tonic-gate #define	PS_PSARGS	0x4
128*0Sstevel@tonic-gate #define	PS_TASKS	0x8
129*0Sstevel@tonic-gate #define	PS_PROJECTS	0x10
130*0Sstevel@tonic-gate #define	PS_ZONES	0x20
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate static int
133*0Sstevel@tonic-gate ps_threadprint(uintptr_t addr, const void *data, void *private)
134*0Sstevel@tonic-gate {
135*0Sstevel@tonic-gate 	const kthread_t *t = (const kthread_t *)data;
136*0Sstevel@tonic-gate 	uint_t prt_flags = *((uint_t *)private);
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate 	static const mdb_bitmask_t t_state_bits[] = {
139*0Sstevel@tonic-gate 		{ "TS_FREE",	UINT_MAX,	TS_FREE		},
140*0Sstevel@tonic-gate 		{ "TS_SLEEP",	TS_SLEEP,	TS_SLEEP	},
141*0Sstevel@tonic-gate 		{ "TS_RUN",	TS_RUN,		TS_RUN		},
142*0Sstevel@tonic-gate 		{ "TS_ONPROC",	TS_ONPROC,	TS_ONPROC	},
143*0Sstevel@tonic-gate 		{ "TS_ZOMB",	TS_ZOMB,	TS_ZOMB		},
144*0Sstevel@tonic-gate 		{ "TS_STOPPED",	TS_STOPPED,	TS_STOPPED	},
145*0Sstevel@tonic-gate 		{ NULL,		0,		0		}
146*0Sstevel@tonic-gate 	};
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate 	if (prt_flags & PS_PRTTHREADS)
149*0Sstevel@tonic-gate 		mdb_printf("\tT  %?a <%b>\n", addr, t->t_state, t_state_bits);
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate 	if (prt_flags & PS_PRTLWPS)
152*0Sstevel@tonic-gate 		mdb_printf("\tL  %?a ID: %u\n", t->t_lwp, t->t_tid);
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate 	return (WALK_NEXT);
155*0Sstevel@tonic-gate }
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate int
158*0Sstevel@tonic-gate ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
159*0Sstevel@tonic-gate {
160*0Sstevel@tonic-gate 	uint_t prt_flags = 0;
161*0Sstevel@tonic-gate 	proc_t pr;
162*0Sstevel@tonic-gate 	struct pid pid, pgid, sid;
163*0Sstevel@tonic-gate 	sess_t session;
164*0Sstevel@tonic-gate 	cred_t cred;
165*0Sstevel@tonic-gate 	task_t tk;
166*0Sstevel@tonic-gate 	kproject_t pj;
167*0Sstevel@tonic-gate 	zone_t zn;
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
170*0Sstevel@tonic-gate 		if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) {
171*0Sstevel@tonic-gate 			mdb_warn("can't walk 'proc'");
172*0Sstevel@tonic-gate 			return (DCMD_ERR);
173*0Sstevel@tonic-gate 		}
174*0Sstevel@tonic-gate 		return (DCMD_OK);
175*0Sstevel@tonic-gate 	}
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
178*0Sstevel@tonic-gate 	    'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags,
179*0Sstevel@tonic-gate 	    'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags,
180*0Sstevel@tonic-gate 	    'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags,
181*0Sstevel@tonic-gate 	    'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags,
182*0Sstevel@tonic-gate 	    'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags,
183*0Sstevel@tonic-gate 	    't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc)
184*0Sstevel@tonic-gate 		return (DCMD_USAGE);
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
187*0Sstevel@tonic-gate 		mdb_printf("%<u>%1s %6s %6s %6s %6s ",
188*0Sstevel@tonic-gate 		    "S", "PID", "PPID", "PGID", "SID");
189*0Sstevel@tonic-gate 		if (prt_flags & PS_TASKS)
190*0Sstevel@tonic-gate 			mdb_printf("%5s ", "TASK");
191*0Sstevel@tonic-gate 		if (prt_flags & PS_PROJECTS)
192*0Sstevel@tonic-gate 			mdb_printf("%5s ", "PROJ");
193*0Sstevel@tonic-gate 		if (prt_flags & PS_ZONES)
194*0Sstevel@tonic-gate 			mdb_printf("%5s ", "ZONE");
195*0Sstevel@tonic-gate 		mdb_printf("%6s %10s %?s %s%</u>\n",
196*0Sstevel@tonic-gate 		    "UID", "FLAGS", "ADDR", "NAME");
197*0Sstevel@tonic-gate 	}
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate 	mdb_vread(&pr, sizeof (pr), addr);
200*0Sstevel@tonic-gate 	mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp);
201*0Sstevel@tonic-gate 	mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp);
202*0Sstevel@tonic-gate 	mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred);
203*0Sstevel@tonic-gate 	mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp);
204*0Sstevel@tonic-gate 	mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp);
205*0Sstevel@tonic-gate 	if (prt_flags & (PS_TASKS | PS_PROJECTS))
206*0Sstevel@tonic-gate 		mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task);
207*0Sstevel@tonic-gate 	if (prt_flags & PS_PROJECTS)
208*0Sstevel@tonic-gate 		mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj);
209*0Sstevel@tonic-gate 	if (prt_flags & PS_ZONES)
210*0Sstevel@tonic-gate 		mdb_vread(&zn, sizeof (zone_t), (uintptr_t)pr.p_zone);
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate 	mdb_printf("%c %6d %6d %6d %6d ",
213*0Sstevel@tonic-gate 	    pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id,
214*0Sstevel@tonic-gate 	    sid.pid_id);
215*0Sstevel@tonic-gate 	if (prt_flags & PS_TASKS)
216*0Sstevel@tonic-gate 		mdb_printf("%5d ", tk.tk_tkid);
217*0Sstevel@tonic-gate 	if (prt_flags & PS_PROJECTS)
218*0Sstevel@tonic-gate 		mdb_printf("%5d ", pj.kpj_id);
219*0Sstevel@tonic-gate 	if (prt_flags & PS_ZONES)
220*0Sstevel@tonic-gate 		mdb_printf("%5d ", zn.zone_id);
221*0Sstevel@tonic-gate 	mdb_printf("%6d 0x%08x %0?p %s\n",
222*0Sstevel@tonic-gate 	    cred.cr_uid, pr.p_flag, addr,
223*0Sstevel@tonic-gate 	    (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm);
224*0Sstevel@tonic-gate 
225*0Sstevel@tonic-gate 	if (prt_flags & ~PS_PSARGS)
226*0Sstevel@tonic-gate 		(void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr);
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate 	return (DCMD_OK);
229*0Sstevel@tonic-gate }
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate #define	PG_NEWEST	0x0001
232*0Sstevel@tonic-gate #define	PG_OLDEST	0x0002
233*0Sstevel@tonic-gate #define	PG_PIPE_OUT	0x0004
234*0Sstevel@tonic-gate 
235*0Sstevel@tonic-gate typedef struct pgrep_data {
236*0Sstevel@tonic-gate 	uint_t pg_flags;
237*0Sstevel@tonic-gate 	uint_t pg_psflags;
238*0Sstevel@tonic-gate 	uintptr_t pg_xaddr;
239*0Sstevel@tonic-gate 	hrtime_t pg_xstart;
240*0Sstevel@tonic-gate 	const char *pg_pat;
241*0Sstevel@tonic-gate #ifndef _KMDB
242*0Sstevel@tonic-gate 	regex_t pg_reg;
243*0Sstevel@tonic-gate #endif
244*0Sstevel@tonic-gate } pgrep_data_t;
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate /*ARGSUSED*/
247*0Sstevel@tonic-gate static int
248*0Sstevel@tonic-gate pgrep_cb(uintptr_t addr, const void *pdata, void *data)
249*0Sstevel@tonic-gate {
250*0Sstevel@tonic-gate 	const proc_t *prp = pdata;
251*0Sstevel@tonic-gate 	pgrep_data_t *pgp = data;
252*0Sstevel@tonic-gate #ifndef _KMDB
253*0Sstevel@tonic-gate 	regmatch_t pmatch;
254*0Sstevel@tonic-gate #endif
255*0Sstevel@tonic-gate 
256*0Sstevel@tonic-gate 	/*
257*0Sstevel@tonic-gate 	 * kmdb doesn't have access to the reg* functions, so we fall back
258*0Sstevel@tonic-gate 	 * to strstr.
259*0Sstevel@tonic-gate 	 */
260*0Sstevel@tonic-gate #ifdef _KMDB
261*0Sstevel@tonic-gate 	if (strstr(prp->p_user.u_comm, pgp->pg_pat) == NULL)
262*0Sstevel@tonic-gate 		return (WALK_NEXT);
263*0Sstevel@tonic-gate #else
264*0Sstevel@tonic-gate 	if (regexec(&pgp->pg_reg, prp->p_user.u_comm, 1, &pmatch, 0) != 0)
265*0Sstevel@tonic-gate 		return (WALK_NEXT);
266*0Sstevel@tonic-gate #endif
267*0Sstevel@tonic-gate 
268*0Sstevel@tonic-gate 	if (pgp->pg_flags & (PG_NEWEST | PG_OLDEST)) {
269*0Sstevel@tonic-gate 		hrtime_t start;
270*0Sstevel@tonic-gate 
271*0Sstevel@tonic-gate 		start = (hrtime_t)prp->p_user.u_start.tv_sec * NANOSEC +
272*0Sstevel@tonic-gate 		    prp->p_user.u_start.tv_nsec;
273*0Sstevel@tonic-gate 
274*0Sstevel@tonic-gate 		if (pgp->pg_flags & PG_NEWEST) {
275*0Sstevel@tonic-gate 			if (pgp->pg_xaddr == NULL || start > pgp->pg_xstart) {
276*0Sstevel@tonic-gate 				pgp->pg_xaddr = addr;
277*0Sstevel@tonic-gate 				pgp->pg_xstart = start;
278*0Sstevel@tonic-gate 			}
279*0Sstevel@tonic-gate 		} else {
280*0Sstevel@tonic-gate 			if (pgp->pg_xaddr == NULL || start < pgp->pg_xstart) {
281*0Sstevel@tonic-gate 				pgp->pg_xaddr = addr;
282*0Sstevel@tonic-gate 				pgp->pg_xstart = start;
283*0Sstevel@tonic-gate 			}
284*0Sstevel@tonic-gate 		}
285*0Sstevel@tonic-gate 
286*0Sstevel@tonic-gate 	} else if (pgp->pg_flags & PG_PIPE_OUT) {
287*0Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate 	} else {
290*0Sstevel@tonic-gate 		if (mdb_call_dcmd("ps", addr, pgp->pg_psflags, 0, NULL) != 0) {
291*0Sstevel@tonic-gate 			mdb_warn("can't invoke 'ps'");
292*0Sstevel@tonic-gate 			return (WALK_DONE);
293*0Sstevel@tonic-gate 		}
294*0Sstevel@tonic-gate 		pgp->pg_psflags &= ~DCMD_LOOPFIRST;
295*0Sstevel@tonic-gate 	}
296*0Sstevel@tonic-gate 
297*0Sstevel@tonic-gate 	return (WALK_NEXT);
298*0Sstevel@tonic-gate }
299*0Sstevel@tonic-gate 
300*0Sstevel@tonic-gate /*ARGSUSED*/
301*0Sstevel@tonic-gate int
302*0Sstevel@tonic-gate pgrep(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
303*0Sstevel@tonic-gate {
304*0Sstevel@tonic-gate 	pgrep_data_t pg;
305*0Sstevel@tonic-gate 	int i;
306*0Sstevel@tonic-gate #ifndef _KMDB
307*0Sstevel@tonic-gate 	int err;
308*0Sstevel@tonic-gate #endif
309*0Sstevel@tonic-gate 
310*0Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
311*0Sstevel@tonic-gate 		return (DCMD_USAGE);
312*0Sstevel@tonic-gate 
313*0Sstevel@tonic-gate 	pg.pg_flags = 0;
314*0Sstevel@tonic-gate 	pg.pg_xaddr = 0;
315*0Sstevel@tonic-gate 
316*0Sstevel@tonic-gate 	i = mdb_getopts(argc, argv,
317*0Sstevel@tonic-gate 	    'n', MDB_OPT_SETBITS, PG_NEWEST, &pg.pg_flags,
318*0Sstevel@tonic-gate 	    'o', MDB_OPT_SETBITS, PG_OLDEST, &pg.pg_flags,
319*0Sstevel@tonic-gate 	    NULL);
320*0Sstevel@tonic-gate 
321*0Sstevel@tonic-gate 	argc -= i;
322*0Sstevel@tonic-gate 	argv += i;
323*0Sstevel@tonic-gate 
324*0Sstevel@tonic-gate 	if (argc != 1)
325*0Sstevel@tonic-gate 		return (DCMD_USAGE);
326*0Sstevel@tonic-gate 
327*0Sstevel@tonic-gate 	/*
328*0Sstevel@tonic-gate 	 * -n and -o are mutually exclusive.
329*0Sstevel@tonic-gate 	 */
330*0Sstevel@tonic-gate 	if ((pg.pg_flags & PG_NEWEST) && (pg.pg_flags & PG_OLDEST))
331*0Sstevel@tonic-gate 		return (DCMD_USAGE);
332*0Sstevel@tonic-gate 
333*0Sstevel@tonic-gate 	if (argv->a_type != MDB_TYPE_STRING)
334*0Sstevel@tonic-gate 		return (DCMD_USAGE);
335*0Sstevel@tonic-gate 
336*0Sstevel@tonic-gate 	if (flags & DCMD_PIPE_OUT)
337*0Sstevel@tonic-gate 		pg.pg_flags |= PG_PIPE_OUT;
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate 	pg.pg_pat = argv->a_un.a_str;
340*0Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
341*0Sstevel@tonic-gate 		pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP | DCMD_LOOPFIRST;
342*0Sstevel@tonic-gate 	else
343*0Sstevel@tonic-gate 		pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP;
344*0Sstevel@tonic-gate 
345*0Sstevel@tonic-gate #ifndef _KMDB
346*0Sstevel@tonic-gate 	if ((err = regcomp(&pg.pg_reg, pg.pg_pat, REG_EXTENDED)) != 0) {
347*0Sstevel@tonic-gate 		size_t nbytes;
348*0Sstevel@tonic-gate 		char *buf;
349*0Sstevel@tonic-gate 
350*0Sstevel@tonic-gate 		nbytes = regerror(err, &pg.pg_reg, NULL, 0);
351*0Sstevel@tonic-gate 		buf = mdb_alloc(nbytes + 1, UM_SLEEP | UM_GC);
352*0Sstevel@tonic-gate 		(void) regerror(err, &pg.pg_reg, buf, nbytes);
353*0Sstevel@tonic-gate 		mdb_warn("%s\n", buf);
354*0Sstevel@tonic-gate 
355*0Sstevel@tonic-gate 		return (DCMD_ERR);
356*0Sstevel@tonic-gate 	}
357*0Sstevel@tonic-gate #endif
358*0Sstevel@tonic-gate 
359*0Sstevel@tonic-gate 	if (mdb_walk("proc", pgrep_cb, &pg) != 0) {
360*0Sstevel@tonic-gate 		mdb_warn("can't walk 'proc'");
361*0Sstevel@tonic-gate 		return (DCMD_ERR);
362*0Sstevel@tonic-gate 	}
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate 	if (pg.pg_xaddr != 0 && (pg.pg_flags & (PG_NEWEST | PG_OLDEST))) {
365*0Sstevel@tonic-gate 		if (pg.pg_flags & PG_PIPE_OUT) {
366*0Sstevel@tonic-gate 			mdb_printf("%p\n", pg.pg_xaddr);
367*0Sstevel@tonic-gate 		} else {
368*0Sstevel@tonic-gate 			if (mdb_call_dcmd("ps", pg.pg_xaddr, pg.pg_psflags,
369*0Sstevel@tonic-gate 			    0, NULL) != 0) {
370*0Sstevel@tonic-gate 				mdb_warn("can't invoke 'ps'");
371*0Sstevel@tonic-gate 				return (DCMD_ERR);
372*0Sstevel@tonic-gate 			}
373*0Sstevel@tonic-gate 		}
374*0Sstevel@tonic-gate 	}
375*0Sstevel@tonic-gate 
376*0Sstevel@tonic-gate 	return (DCMD_OK);
377*0Sstevel@tonic-gate }
378*0Sstevel@tonic-gate 
379*0Sstevel@tonic-gate int
380*0Sstevel@tonic-gate task(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
381*0Sstevel@tonic-gate {
382*0Sstevel@tonic-gate 	task_t tk;
383*0Sstevel@tonic-gate 	kproject_t pj;
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
386*0Sstevel@tonic-gate 		if (mdb_walk_dcmd("task_cache", "task", argc, argv) == -1) {
387*0Sstevel@tonic-gate 			mdb_warn("can't walk task_cache");
388*0Sstevel@tonic-gate 			return (DCMD_ERR);
389*0Sstevel@tonic-gate 		}
390*0Sstevel@tonic-gate 		return (DCMD_OK);
391*0Sstevel@tonic-gate 	}
392*0Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
393*0Sstevel@tonic-gate 		mdb_printf("%<u>%?s %6s %6s %6s %6s %10s%</u>\n",
394*0Sstevel@tonic-gate 		    "ADDR", "TASKID", "PROJID", "ZONEID", "REFCNT", "FLAGS");
395*0Sstevel@tonic-gate 	}
396*0Sstevel@tonic-gate 	if (mdb_vread(&tk, sizeof (task_t), addr) == -1) {
397*0Sstevel@tonic-gate 		mdb_warn("can't read task_t structure at %p", addr);
398*0Sstevel@tonic-gate 		return (DCMD_ERR);
399*0Sstevel@tonic-gate 	}
400*0Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), (uintptr_t)tk.tk_proj) == -1) {
401*0Sstevel@tonic-gate 		mdb_warn("can't read project_t structure at %p", addr);
402*0Sstevel@tonic-gate 		return (DCMD_ERR);
403*0Sstevel@tonic-gate 	}
404*0Sstevel@tonic-gate 	mdb_printf("%0?p %6d %6d %6d %6u 0x%08x\n",
405*0Sstevel@tonic-gate 	    addr, tk.tk_tkid, pj.kpj_id, pj.kpj_zoneid, tk.tk_hold_count,
406*0Sstevel@tonic-gate 	    tk.tk_flags);
407*0Sstevel@tonic-gate 	return (DCMD_OK);
408*0Sstevel@tonic-gate }
409*0Sstevel@tonic-gate 
410*0Sstevel@tonic-gate int
411*0Sstevel@tonic-gate project(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
412*0Sstevel@tonic-gate {
413*0Sstevel@tonic-gate 	kproject_t pj;
414*0Sstevel@tonic-gate 
415*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
416*0Sstevel@tonic-gate 		if (mdb_walk_dcmd("projects", "project", argc, argv) == -1) {
417*0Sstevel@tonic-gate 			mdb_warn("can't walk projects");
418*0Sstevel@tonic-gate 			return (DCMD_ERR);
419*0Sstevel@tonic-gate 		}
420*0Sstevel@tonic-gate 		return (DCMD_OK);
421*0Sstevel@tonic-gate 	}
422*0Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
423*0Sstevel@tonic-gate 		mdb_printf("%<u>%?s %6s %6s %6s%</u>\n",
424*0Sstevel@tonic-gate 		    "ADDR", "PROJID", "ZONEID", "REFCNT");
425*0Sstevel@tonic-gate 	}
426*0Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
427*0Sstevel@tonic-gate 		mdb_warn("can't read kproject_t structure at %p", addr);
428*0Sstevel@tonic-gate 		return (DCMD_ERR);
429*0Sstevel@tonic-gate 	}
430*0Sstevel@tonic-gate 	mdb_printf("%0?p %6d %6d %6u\n", addr, pj.kpj_id, pj.kpj_zoneid,
431*0Sstevel@tonic-gate 	    pj.kpj_count);
432*0Sstevel@tonic-gate 	return (DCMD_OK);
433*0Sstevel@tonic-gate }
434*0Sstevel@tonic-gate 
435*0Sstevel@tonic-gate /*ARGSUSED*/
436*0Sstevel@tonic-gate int
437*0Sstevel@tonic-gate callout(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
438*0Sstevel@tonic-gate {
439*0Sstevel@tonic-gate 	callout_table_t	*co_ktable[CALLOUT_TABLES];
440*0Sstevel@tonic-gate 	int co_kfanout;
441*0Sstevel@tonic-gate 	callout_table_t co_table;
442*0Sstevel@tonic-gate 	callout_t co_callout;
443*0Sstevel@tonic-gate 	callout_t *co_ptr;
444*0Sstevel@tonic-gate 	int co_id;
445*0Sstevel@tonic-gate 	clock_t lbolt;
446*0Sstevel@tonic-gate 	int i, j, k;
447*0Sstevel@tonic-gate 	const char *lbolt_sym;
448*0Sstevel@tonic-gate 
449*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) || argc != 0)
450*0Sstevel@tonic-gate 		return (DCMD_USAGE);
451*0Sstevel@tonic-gate 
452*0Sstevel@tonic-gate 	if (mdb_prop_postmortem)
453*0Sstevel@tonic-gate 		lbolt_sym = "panic_lbolt";
454*0Sstevel@tonic-gate 	else
455*0Sstevel@tonic-gate 		lbolt_sym = "lbolt";
456*0Sstevel@tonic-gate 
457*0Sstevel@tonic-gate 	if (mdb_readvar(&lbolt, lbolt_sym) == -1) {
458*0Sstevel@tonic-gate 		mdb_warn("failed to read '%s'", lbolt_sym);
459*0Sstevel@tonic-gate 		return (DCMD_ERR);
460*0Sstevel@tonic-gate 	}
461*0Sstevel@tonic-gate 
462*0Sstevel@tonic-gate 	if (mdb_readvar(&co_kfanout, "callout_fanout") == -1) {
463*0Sstevel@tonic-gate 		mdb_warn("failed to read callout_fanout");
464*0Sstevel@tonic-gate 		return (DCMD_ERR);
465*0Sstevel@tonic-gate 	}
466*0Sstevel@tonic-gate 
467*0Sstevel@tonic-gate 	if (mdb_readvar(&co_ktable, "callout_table") == -1) {
468*0Sstevel@tonic-gate 		mdb_warn("failed to read callout_table");
469*0Sstevel@tonic-gate 		return (DCMD_ERR);
470*0Sstevel@tonic-gate 	}
471*0Sstevel@tonic-gate 
472*0Sstevel@tonic-gate 	mdb_printf("%<u>%-24s %-?s %-?s %-?s%</u>\n",
473*0Sstevel@tonic-gate 	    "FUNCTION", "ARGUMENT", "ID", "TIME");
474*0Sstevel@tonic-gate 
475*0Sstevel@tonic-gate 	for (i = 0; i < CALLOUT_NTYPES; i++) {
476*0Sstevel@tonic-gate 		for (j = 0; j < co_kfanout; j++) {
477*0Sstevel@tonic-gate 
478*0Sstevel@tonic-gate 			co_id = CALLOUT_TABLE(i, j);
479*0Sstevel@tonic-gate 
480*0Sstevel@tonic-gate 			if (mdb_vread(&co_table, sizeof (co_table),
481*0Sstevel@tonic-gate 			    (uintptr_t)co_ktable[co_id]) == -1) {
482*0Sstevel@tonic-gate 				mdb_warn("failed to read table at %p",
483*0Sstevel@tonic-gate 				    (uintptr_t)co_ktable[co_id]);
484*0Sstevel@tonic-gate 				continue;
485*0Sstevel@tonic-gate 			}
486*0Sstevel@tonic-gate 
487*0Sstevel@tonic-gate 			for (k = 0; k < CALLOUT_BUCKETS; k++) {
488*0Sstevel@tonic-gate 				co_ptr = co_table.ct_idhash[k];
489*0Sstevel@tonic-gate 
490*0Sstevel@tonic-gate 				while (co_ptr != NULL) {
491*0Sstevel@tonic-gate 					mdb_vread(&co_callout,
492*0Sstevel@tonic-gate 					    sizeof (co_callout),
493*0Sstevel@tonic-gate 					    (uintptr_t)co_ptr);
494*0Sstevel@tonic-gate 
495*0Sstevel@tonic-gate 					mdb_printf("%-24a %0?p %0?lx %?lx "
496*0Sstevel@tonic-gate 					    "(T%+ld)\n", co_callout.c_func,
497*0Sstevel@tonic-gate 					    co_callout.c_arg, co_callout.c_xid,
498*0Sstevel@tonic-gate 					    co_callout.c_runtime,
499*0Sstevel@tonic-gate 					    co_callout.c_runtime - lbolt);
500*0Sstevel@tonic-gate 
501*0Sstevel@tonic-gate 					co_ptr = co_callout.c_idnext;
502*0Sstevel@tonic-gate 				}
503*0Sstevel@tonic-gate 			}
504*0Sstevel@tonic-gate 		}
505*0Sstevel@tonic-gate 	}
506*0Sstevel@tonic-gate 
507*0Sstevel@tonic-gate 	return (DCMD_OK);
508*0Sstevel@tonic-gate }
509*0Sstevel@tonic-gate 
510*0Sstevel@tonic-gate /*ARGSUSED*/
511*0Sstevel@tonic-gate int
512*0Sstevel@tonic-gate class(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
513*0Sstevel@tonic-gate {
514*0Sstevel@tonic-gate 	long num_classes, i;
515*0Sstevel@tonic-gate 	sclass_t *class_tbl;
516*0Sstevel@tonic-gate 	GElf_Sym g_sclass;
517*0Sstevel@tonic-gate 	char class_name[PC_CLNMSZ];
518*0Sstevel@tonic-gate 	size_t tbl_size;
519*0Sstevel@tonic-gate 
520*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("sclass", &g_sclass) == -1) {
521*0Sstevel@tonic-gate 		mdb_warn("failed to find symbol sclass\n");
522*0Sstevel@tonic-gate 		return (DCMD_ERR);
523*0Sstevel@tonic-gate 	}
524*0Sstevel@tonic-gate 
525*0Sstevel@tonic-gate 	tbl_size = (size_t)g_sclass.st_size;
526*0Sstevel@tonic-gate 	num_classes = tbl_size / (sizeof (sclass_t));
527*0Sstevel@tonic-gate 	class_tbl = mdb_alloc(tbl_size, UM_SLEEP | UM_GC);
528*0Sstevel@tonic-gate 
529*0Sstevel@tonic-gate 	if (mdb_readsym(class_tbl, tbl_size, "sclass") == -1) {
530*0Sstevel@tonic-gate 		mdb_warn("failed to read sclass");
531*0Sstevel@tonic-gate 		return (DCMD_ERR);
532*0Sstevel@tonic-gate 	}
533*0Sstevel@tonic-gate 
534*0Sstevel@tonic-gate 	mdb_printf("%<u>%4s %-10s %-24s %-24s%</u>\n", "SLOT", "NAME",
535*0Sstevel@tonic-gate 	    "INIT FCN", "CLASS FCN");
536*0Sstevel@tonic-gate 
537*0Sstevel@tonic-gate 	for (i = 0; i < num_classes; i++) {
538*0Sstevel@tonic-gate 		if (mdb_vread(class_name, sizeof (class_name),
539*0Sstevel@tonic-gate 		    (uintptr_t)class_tbl[i].cl_name) == -1)
540*0Sstevel@tonic-gate 			(void) strcpy(class_name, "???");
541*0Sstevel@tonic-gate 
542*0Sstevel@tonic-gate 		mdb_printf("%4ld %-10s %-24a %-24a\n", i, class_name,
543*0Sstevel@tonic-gate 		    class_tbl[i].cl_init, class_tbl[i].cl_funcs);
544*0Sstevel@tonic-gate 	}
545*0Sstevel@tonic-gate 
546*0Sstevel@tonic-gate 	return (DCMD_OK);
547*0Sstevel@tonic-gate }
548*0Sstevel@tonic-gate 
549*0Sstevel@tonic-gate #define	FSNAMELEN	32	/* Max len of FS name we read from vnodeops */
550*0Sstevel@tonic-gate 
551*0Sstevel@tonic-gate int
552*0Sstevel@tonic-gate vnode2path(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
553*0Sstevel@tonic-gate {
554*0Sstevel@tonic-gate 	uintptr_t rootdir;
555*0Sstevel@tonic-gate 	vnode_t vn;
556*0Sstevel@tonic-gate 	char buf[MAXPATHLEN];
557*0Sstevel@tonic-gate 
558*0Sstevel@tonic-gate 	uint_t opt_F = FALSE;
559*0Sstevel@tonic-gate 
560*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
561*0Sstevel@tonic-gate 	    'F', MDB_OPT_SETBITS, TRUE, &opt_F, NULL) != argc)
562*0Sstevel@tonic-gate 		return (DCMD_USAGE);
563*0Sstevel@tonic-gate 
564*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
565*0Sstevel@tonic-gate 		mdb_warn("expected explicit vnode_t address before ::\n");
566*0Sstevel@tonic-gate 		return (DCMD_USAGE);
567*0Sstevel@tonic-gate 	}
568*0Sstevel@tonic-gate 
569*0Sstevel@tonic-gate 	if (mdb_readvar(&rootdir, "rootdir") == -1) {
570*0Sstevel@tonic-gate 		mdb_warn("failed to read rootdir");
571*0Sstevel@tonic-gate 		return (DCMD_ERR);
572*0Sstevel@tonic-gate 	}
573*0Sstevel@tonic-gate 
574*0Sstevel@tonic-gate 	if (mdb_vnode2path(addr, buf, sizeof (buf)) == -1)
575*0Sstevel@tonic-gate 		return (DCMD_ERR);
576*0Sstevel@tonic-gate 
577*0Sstevel@tonic-gate 	if (*buf == '\0') {
578*0Sstevel@tonic-gate 		mdb_printf("??\n");
579*0Sstevel@tonic-gate 		return (DCMD_OK);
580*0Sstevel@tonic-gate 	}
581*0Sstevel@tonic-gate 
582*0Sstevel@tonic-gate 	mdb_printf("%s", buf);
583*0Sstevel@tonic-gate 	if (opt_F && buf[strlen(buf)-1] != '/' &&
584*0Sstevel@tonic-gate 	    mdb_vread(&vn, sizeof (vn), addr) == sizeof (vn))
585*0Sstevel@tonic-gate 		mdb_printf("%c", mdb_vtype2chr(vn.v_type, 0));
586*0Sstevel@tonic-gate 	mdb_printf("\n");
587*0Sstevel@tonic-gate 
588*0Sstevel@tonic-gate 	return (DCMD_OK);
589*0Sstevel@tonic-gate }
590*0Sstevel@tonic-gate 
591*0Sstevel@tonic-gate int
592*0Sstevel@tonic-gate ld_walk_init(mdb_walk_state_t *wsp)
593*0Sstevel@tonic-gate {
594*0Sstevel@tonic-gate 	wsp->walk_data = (void *)wsp->walk_addr;
595*0Sstevel@tonic-gate 	return (WALK_NEXT);
596*0Sstevel@tonic-gate }
597*0Sstevel@tonic-gate 
598*0Sstevel@tonic-gate int
599*0Sstevel@tonic-gate ld_walk_step(mdb_walk_state_t *wsp)
600*0Sstevel@tonic-gate {
601*0Sstevel@tonic-gate 	int status;
602*0Sstevel@tonic-gate 	lock_descriptor_t ld;
603*0Sstevel@tonic-gate 
604*0Sstevel@tonic-gate 	if (mdb_vread(&ld, sizeof (lock_descriptor_t), wsp->walk_addr) == -1) {
605*0Sstevel@tonic-gate 		mdb_warn("couldn't read lock_descriptor_t at %p\n",
606*0Sstevel@tonic-gate 		    wsp->walk_addr);
607*0Sstevel@tonic-gate 		return (WALK_ERR);
608*0Sstevel@tonic-gate 	}
609*0Sstevel@tonic-gate 
610*0Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, &ld, wsp->walk_cbdata);
611*0Sstevel@tonic-gate 	if (status == WALK_ERR)
612*0Sstevel@tonic-gate 		return (WALK_ERR);
613*0Sstevel@tonic-gate 
614*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)ld.l_next;
615*0Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data)
616*0Sstevel@tonic-gate 		return (WALK_DONE);
617*0Sstevel@tonic-gate 
618*0Sstevel@tonic-gate 	return (status);
619*0Sstevel@tonic-gate }
620*0Sstevel@tonic-gate 
621*0Sstevel@tonic-gate int
622*0Sstevel@tonic-gate lg_walk_init(mdb_walk_state_t *wsp)
623*0Sstevel@tonic-gate {
624*0Sstevel@tonic-gate 	GElf_Sym sym;
625*0Sstevel@tonic-gate 
626*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("lock_graph", &sym) == -1) {
627*0Sstevel@tonic-gate 		mdb_warn("failed to find symbol 'lock_graph'\n");
628*0Sstevel@tonic-gate 		return (WALK_ERR);
629*0Sstevel@tonic-gate 	}
630*0Sstevel@tonic-gate 
631*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)sym.st_value;
632*0Sstevel@tonic-gate 	wsp->walk_data = (void *)(sym.st_value + sym.st_size);
633*0Sstevel@tonic-gate 
634*0Sstevel@tonic-gate 	return (WALK_NEXT);
635*0Sstevel@tonic-gate }
636*0Sstevel@tonic-gate 
637*0Sstevel@tonic-gate typedef struct lg_walk_data {
638*0Sstevel@tonic-gate 	uintptr_t startaddr;
639*0Sstevel@tonic-gate 	mdb_walk_cb_t callback;
640*0Sstevel@tonic-gate 	void *data;
641*0Sstevel@tonic-gate } lg_walk_data_t;
642*0Sstevel@tonic-gate 
643*0Sstevel@tonic-gate /*
644*0Sstevel@tonic-gate  * We can't use ::walk lock_descriptor directly, because the head of each graph
645*0Sstevel@tonic-gate  * is really a dummy lock.  Rather than trying to dynamically determine if this
646*0Sstevel@tonic-gate  * is a dummy node or not, we just filter out the initial element of the
647*0Sstevel@tonic-gate  * list.
648*0Sstevel@tonic-gate  */
649*0Sstevel@tonic-gate static int
650*0Sstevel@tonic-gate lg_walk_cb(uintptr_t addr, const void *data, void *priv)
651*0Sstevel@tonic-gate {
652*0Sstevel@tonic-gate 	lg_walk_data_t *lw = priv;
653*0Sstevel@tonic-gate 
654*0Sstevel@tonic-gate 	if (addr != lw->startaddr)
655*0Sstevel@tonic-gate 		return (lw->callback(addr, data, lw->data));
656*0Sstevel@tonic-gate 
657*0Sstevel@tonic-gate 	return (WALK_NEXT);
658*0Sstevel@tonic-gate }
659*0Sstevel@tonic-gate 
660*0Sstevel@tonic-gate int
661*0Sstevel@tonic-gate lg_walk_step(mdb_walk_state_t *wsp)
662*0Sstevel@tonic-gate {
663*0Sstevel@tonic-gate 	graph_t *graph;
664*0Sstevel@tonic-gate 	lg_walk_data_t lw;
665*0Sstevel@tonic-gate 
666*0Sstevel@tonic-gate 	if (wsp->walk_addr >= (uintptr_t)wsp->walk_data)
667*0Sstevel@tonic-gate 		return (WALK_DONE);
668*0Sstevel@tonic-gate 
669*0Sstevel@tonic-gate 	if (mdb_vread(&graph, sizeof (graph), wsp->walk_addr) == -1) {
670*0Sstevel@tonic-gate 		mdb_warn("failed to read graph_t at %p", wsp->walk_addr);
671*0Sstevel@tonic-gate 		return (WALK_ERR);
672*0Sstevel@tonic-gate 	}
673*0Sstevel@tonic-gate 
674*0Sstevel@tonic-gate 	wsp->walk_addr += sizeof (graph);
675*0Sstevel@tonic-gate 
676*0Sstevel@tonic-gate 	if (graph == NULL)
677*0Sstevel@tonic-gate 		return (WALK_NEXT);
678*0Sstevel@tonic-gate 
679*0Sstevel@tonic-gate 	lw.callback = wsp->walk_callback;
680*0Sstevel@tonic-gate 	lw.data = wsp->walk_cbdata;
681*0Sstevel@tonic-gate 
682*0Sstevel@tonic-gate 	lw.startaddr = (uintptr_t)&(graph->active_locks);
683*0Sstevel@tonic-gate 	if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
684*0Sstevel@tonic-gate 		mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
685*0Sstevel@tonic-gate 		return (WALK_ERR);
686*0Sstevel@tonic-gate 	}
687*0Sstevel@tonic-gate 
688*0Sstevel@tonic-gate 	lw.startaddr = (uintptr_t)&(graph->sleeping_locks);
689*0Sstevel@tonic-gate 	if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
690*0Sstevel@tonic-gate 		mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
691*0Sstevel@tonic-gate 		return (WALK_ERR);
692*0Sstevel@tonic-gate 	}
693*0Sstevel@tonic-gate 
694*0Sstevel@tonic-gate 	return (WALK_NEXT);
695*0Sstevel@tonic-gate }
696*0Sstevel@tonic-gate 
697*0Sstevel@tonic-gate /*
698*0Sstevel@tonic-gate  * The space available for the path corresponding to the locked vnode depends
699*0Sstevel@tonic-gate  * on whether we are printing 32- or 64-bit addresses.
700*0Sstevel@tonic-gate  */
701*0Sstevel@tonic-gate #ifdef _LP64
702*0Sstevel@tonic-gate #define	LM_VNPATHLEN	20
703*0Sstevel@tonic-gate #else
704*0Sstevel@tonic-gate #define	LM_VNPATHLEN	30
705*0Sstevel@tonic-gate #endif
706*0Sstevel@tonic-gate 
707*0Sstevel@tonic-gate /*ARGSUSED*/
708*0Sstevel@tonic-gate static int
709*0Sstevel@tonic-gate lminfo_cb(uintptr_t addr, const void *data, void *priv)
710*0Sstevel@tonic-gate {
711*0Sstevel@tonic-gate 	const lock_descriptor_t *ld = data;
712*0Sstevel@tonic-gate 	char buf[LM_VNPATHLEN];
713*0Sstevel@tonic-gate 	proc_t p;
714*0Sstevel@tonic-gate 
715*0Sstevel@tonic-gate 	mdb_printf("%-?p %2s %04x %6d %-16s %-?p ",
716*0Sstevel@tonic-gate 	    addr, ld->l_type == F_RDLCK ? "RD" :
717*0Sstevel@tonic-gate 	    ld->l_type == F_WRLCK ? "WR" : "??",
718*0Sstevel@tonic-gate 	    ld->l_state, ld->l_flock.l_pid,
719*0Sstevel@tonic-gate 	    ld->l_flock.l_pid == 0 ? "<kernel>" :
720*0Sstevel@tonic-gate 	    mdb_pid2proc(ld->l_flock.l_pid, &p) == NULL ?
721*0Sstevel@tonic-gate 	    "<defunct>" : p.p_user.u_comm,
722*0Sstevel@tonic-gate 	    ld->l_vnode);
723*0Sstevel@tonic-gate 
724*0Sstevel@tonic-gate 	mdb_vnode2path((uintptr_t)ld->l_vnode, buf,
725*0Sstevel@tonic-gate 	    sizeof (buf));
726*0Sstevel@tonic-gate 	mdb_printf("%s\n", buf);
727*0Sstevel@tonic-gate 
728*0Sstevel@tonic-gate 	return (WALK_NEXT);
729*0Sstevel@tonic-gate }
730*0Sstevel@tonic-gate 
731*0Sstevel@tonic-gate /*ARGSUSED*/
732*0Sstevel@tonic-gate int
733*0Sstevel@tonic-gate lminfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
734*0Sstevel@tonic-gate {
735*0Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
736*0Sstevel@tonic-gate 		mdb_printf("%<u>%-?s %2s %4s %6s %-16s %-?s %s%</u>\n",
737*0Sstevel@tonic-gate 		    "ADDR", "TP", "FLAG", "PID", "COMM", "VNODE", "PATH");
738*0Sstevel@tonic-gate 
739*0Sstevel@tonic-gate 	return (mdb_pwalk("lock_graph", lminfo_cb, NULL, NULL));
740*0Sstevel@tonic-gate }
741*0Sstevel@tonic-gate 
742*0Sstevel@tonic-gate /*ARGSUSED*/
743*0Sstevel@tonic-gate int
744*0Sstevel@tonic-gate seg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
745*0Sstevel@tonic-gate {
746*0Sstevel@tonic-gate 	struct seg s;
747*0Sstevel@tonic-gate 
748*0Sstevel@tonic-gate 	if (argc != 0)
749*0Sstevel@tonic-gate 		return (DCMD_USAGE);
750*0Sstevel@tonic-gate 
751*0Sstevel@tonic-gate 	if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
752*0Sstevel@tonic-gate 		mdb_printf("%<u>%?s %?s %?s %?s %s%</u>\n",
753*0Sstevel@tonic-gate 		    "SEG", "BASE", "SIZE", "DATA", "OPS");
754*0Sstevel@tonic-gate 	}
755*0Sstevel@tonic-gate 
756*0Sstevel@tonic-gate 	if (mdb_vread(&s, sizeof (s), addr) == -1) {
757*0Sstevel@tonic-gate 		mdb_warn("failed to read seg at %p", addr);
758*0Sstevel@tonic-gate 		return (DCMD_ERR);
759*0Sstevel@tonic-gate 	}
760*0Sstevel@tonic-gate 
761*0Sstevel@tonic-gate 	mdb_printf("%?p %?p %?lx %?p %a\n",
762*0Sstevel@tonic-gate 	    addr, s.s_base, s.s_size, s.s_data, s.s_ops);
763*0Sstevel@tonic-gate 
764*0Sstevel@tonic-gate 	return (DCMD_OK);
765*0Sstevel@tonic-gate }
766*0Sstevel@tonic-gate 
767*0Sstevel@tonic-gate /*ARGSUSED*/
768*0Sstevel@tonic-gate static int
769*0Sstevel@tonic-gate pmap_walk_anon(uintptr_t addr, const struct anon *anon, int *nres)
770*0Sstevel@tonic-gate {
771*0Sstevel@tonic-gate 	uintptr_t pp =
772*0Sstevel@tonic-gate 	    mdb_vnode2page((uintptr_t)anon->an_vp, (uintptr_t)anon->an_off);
773*0Sstevel@tonic-gate 
774*0Sstevel@tonic-gate 	if (pp != NULL)
775*0Sstevel@tonic-gate 		(*nres)++;
776*0Sstevel@tonic-gate 
777*0Sstevel@tonic-gate 	return (WALK_NEXT);
778*0Sstevel@tonic-gate }
779*0Sstevel@tonic-gate 
780*0Sstevel@tonic-gate static int
781*0Sstevel@tonic-gate pmap_walk_seg(uintptr_t addr, const struct seg *seg, uintptr_t segvn)
782*0Sstevel@tonic-gate {
783*0Sstevel@tonic-gate 
784*0Sstevel@tonic-gate 	mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024);
785*0Sstevel@tonic-gate 
786*0Sstevel@tonic-gate 	if (segvn == (uintptr_t)seg->s_ops) {
787*0Sstevel@tonic-gate 		struct segvn_data svn;
788*0Sstevel@tonic-gate 		int nres = 0;
789*0Sstevel@tonic-gate 
790*0Sstevel@tonic-gate 		(void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data);
791*0Sstevel@tonic-gate 
792*0Sstevel@tonic-gate 		if (svn.amp == NULL) {
793*0Sstevel@tonic-gate 			mdb_printf(" %8s", "");
794*0Sstevel@tonic-gate 			goto drive_on;
795*0Sstevel@tonic-gate 		}
796*0Sstevel@tonic-gate 
797*0Sstevel@tonic-gate 		/*
798*0Sstevel@tonic-gate 		 * We've got an amp for this segment; walk through
799*0Sstevel@tonic-gate 		 * the amp, and determine mappings.
800*0Sstevel@tonic-gate 		 */
801*0Sstevel@tonic-gate 		if (mdb_pwalk("anon", (mdb_walk_cb_t)pmap_walk_anon,
802*0Sstevel@tonic-gate 		    &nres, (uintptr_t)svn.amp) == -1)
803*0Sstevel@tonic-gate 			mdb_warn("failed to walk anon (amp=%p)", svn.amp);
804*0Sstevel@tonic-gate 
805*0Sstevel@tonic-gate 		mdb_printf(" %7dk", (nres * PAGESIZE) / 1024);
806*0Sstevel@tonic-gate drive_on:
807*0Sstevel@tonic-gate 
808*0Sstevel@tonic-gate 		if (svn.vp != NULL) {
809*0Sstevel@tonic-gate 			char buf[29];
810*0Sstevel@tonic-gate 
811*0Sstevel@tonic-gate 			mdb_vnode2path((uintptr_t)svn.vp, buf, sizeof (buf));
812*0Sstevel@tonic-gate 			mdb_printf(" %s", buf);
813*0Sstevel@tonic-gate 		} else
814*0Sstevel@tonic-gate 			mdb_printf(" [ anon ]");
815*0Sstevel@tonic-gate 	}
816*0Sstevel@tonic-gate 
817*0Sstevel@tonic-gate 	mdb_printf("\n");
818*0Sstevel@tonic-gate 	return (WALK_NEXT);
819*0Sstevel@tonic-gate }
820*0Sstevel@tonic-gate 
821*0Sstevel@tonic-gate static int
822*0Sstevel@tonic-gate pmap_walk_seg_quick(uintptr_t addr, const struct seg *seg, uintptr_t segvn)
823*0Sstevel@tonic-gate {
824*0Sstevel@tonic-gate 	mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024);
825*0Sstevel@tonic-gate 
826*0Sstevel@tonic-gate 	if (segvn == (uintptr_t)seg->s_ops) {
827*0Sstevel@tonic-gate 		struct segvn_data svn;
828*0Sstevel@tonic-gate 
829*0Sstevel@tonic-gate 		(void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data);
830*0Sstevel@tonic-gate 
831*0Sstevel@tonic-gate 		if (svn.vp != NULL) {
832*0Sstevel@tonic-gate 			mdb_printf(" %0?p", svn.vp);
833*0Sstevel@tonic-gate 		} else {
834*0Sstevel@tonic-gate 			mdb_printf(" [ anon ]");
835*0Sstevel@tonic-gate 		}
836*0Sstevel@tonic-gate 	}
837*0Sstevel@tonic-gate 
838*0Sstevel@tonic-gate 	mdb_printf("\n");
839*0Sstevel@tonic-gate 	return (WALK_NEXT);
840*0Sstevel@tonic-gate }
841*0Sstevel@tonic-gate 
842*0Sstevel@tonic-gate /*ARGSUSED*/
843*0Sstevel@tonic-gate int
844*0Sstevel@tonic-gate pmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
845*0Sstevel@tonic-gate {
846*0Sstevel@tonic-gate 	uintptr_t segvn;
847*0Sstevel@tonic-gate 	proc_t proc;
848*0Sstevel@tonic-gate 	uint_t quick = FALSE;
849*0Sstevel@tonic-gate 	mdb_walk_cb_t cb = (mdb_walk_cb_t)pmap_walk_seg;
850*0Sstevel@tonic-gate 
851*0Sstevel@tonic-gate 	GElf_Sym sym;
852*0Sstevel@tonic-gate 
853*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
854*0Sstevel@tonic-gate 		return (DCMD_USAGE);
855*0Sstevel@tonic-gate 
856*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
857*0Sstevel@tonic-gate 	    'q', MDB_OPT_SETBITS, TRUE, &quick, NULL) != argc)
858*0Sstevel@tonic-gate 		return (DCMD_USAGE);
859*0Sstevel@tonic-gate 
860*0Sstevel@tonic-gate 	if (mdb_vread(&proc, sizeof (proc), addr) == -1) {
861*0Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", addr);
862*0Sstevel@tonic-gate 		return (DCMD_ERR);
863*0Sstevel@tonic-gate 	}
864*0Sstevel@tonic-gate 
865*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("segvn_ops", &sym) == 0)
866*0Sstevel@tonic-gate 		segvn = (uintptr_t)sym.st_value;
867*0Sstevel@tonic-gate 	else
868*0Sstevel@tonic-gate 		segvn = NULL;
869*0Sstevel@tonic-gate 
870*0Sstevel@tonic-gate 	mdb_printf("%?s %?s %8s ", "SEG", "BASE", "SIZE");
871*0Sstevel@tonic-gate 
872*0Sstevel@tonic-gate 	if (quick) {
873*0Sstevel@tonic-gate 		mdb_printf("VNODE\n");
874*0Sstevel@tonic-gate 		cb = (mdb_walk_cb_t)pmap_walk_seg_quick;
875*0Sstevel@tonic-gate 	} else {
876*0Sstevel@tonic-gate 		mdb_printf("%8s %s\n", "RES", "PATH");
877*0Sstevel@tonic-gate 	}
878*0Sstevel@tonic-gate 
879*0Sstevel@tonic-gate 	if (mdb_pwalk("seg", cb, (void *)segvn, (uintptr_t)proc.p_as) == -1) {
880*0Sstevel@tonic-gate 		mdb_warn("failed to walk segments of as %p", proc.p_as);
881*0Sstevel@tonic-gate 		return (DCMD_ERR);
882*0Sstevel@tonic-gate 	}
883*0Sstevel@tonic-gate 
884*0Sstevel@tonic-gate 	return (DCMD_OK);
885*0Sstevel@tonic-gate }
886*0Sstevel@tonic-gate 
887*0Sstevel@tonic-gate typedef struct anon_walk_data {
888*0Sstevel@tonic-gate 	uintptr_t *aw_levone;
889*0Sstevel@tonic-gate 	uintptr_t *aw_levtwo;
890*0Sstevel@tonic-gate 	int aw_nlevone;
891*0Sstevel@tonic-gate 	int aw_levone_ndx;
892*0Sstevel@tonic-gate 	int aw_levtwo_ndx;
893*0Sstevel@tonic-gate 	struct anon_map aw_amp;
894*0Sstevel@tonic-gate 	struct anon_hdr aw_ahp;
895*0Sstevel@tonic-gate } anon_walk_data_t;
896*0Sstevel@tonic-gate 
897*0Sstevel@tonic-gate int
898*0Sstevel@tonic-gate anon_walk_init(mdb_walk_state_t *wsp)
899*0Sstevel@tonic-gate {
900*0Sstevel@tonic-gate 	anon_walk_data_t *aw;
901*0Sstevel@tonic-gate 
902*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
903*0Sstevel@tonic-gate 		mdb_warn("anon walk doesn't support global walks\n");
904*0Sstevel@tonic-gate 		return (WALK_ERR);
905*0Sstevel@tonic-gate 	}
906*0Sstevel@tonic-gate 
907*0Sstevel@tonic-gate 	aw = mdb_alloc(sizeof (anon_walk_data_t), UM_SLEEP);
908*0Sstevel@tonic-gate 
909*0Sstevel@tonic-gate 	if (mdb_vread(&aw->aw_amp, sizeof (aw->aw_amp), wsp->walk_addr) == -1) {
910*0Sstevel@tonic-gate 		mdb_warn("failed to read anon map at %p", wsp->walk_addr);
911*0Sstevel@tonic-gate 		mdb_free(aw, sizeof (anon_walk_data_t));
912*0Sstevel@tonic-gate 		return (WALK_ERR);
913*0Sstevel@tonic-gate 	}
914*0Sstevel@tonic-gate 
915*0Sstevel@tonic-gate 	if (mdb_vread(&aw->aw_ahp, sizeof (aw->aw_ahp),
916*0Sstevel@tonic-gate 	    (uintptr_t)(aw->aw_amp.ahp)) == -1) {
917*0Sstevel@tonic-gate 		mdb_warn("failed to read anon hdr ptr at %p", aw->aw_amp.ahp);
918*0Sstevel@tonic-gate 		mdb_free(aw, sizeof (anon_walk_data_t));
919*0Sstevel@tonic-gate 		return (WALK_ERR);
920*0Sstevel@tonic-gate 	}
921*0Sstevel@tonic-gate 
922*0Sstevel@tonic-gate 	if (aw->aw_ahp.size <= ANON_CHUNK_SIZE ||
923*0Sstevel@tonic-gate 	    (aw->aw_ahp.flags & ANON_ALLOC_FORCE)) {
924*0Sstevel@tonic-gate 		aw->aw_nlevone = aw->aw_ahp.size;
925*0Sstevel@tonic-gate 		aw->aw_levtwo = NULL;
926*0Sstevel@tonic-gate 	} else {
927*0Sstevel@tonic-gate 		aw->aw_nlevone =
928*0Sstevel@tonic-gate 		    (aw->aw_ahp.size + ANON_CHUNK_OFF) >> ANON_CHUNK_SHIFT;
929*0Sstevel@tonic-gate 		aw->aw_levtwo =
930*0Sstevel@tonic-gate 		    mdb_zalloc(ANON_CHUNK_SIZE * sizeof (uintptr_t), UM_SLEEP);
931*0Sstevel@tonic-gate 	}
932*0Sstevel@tonic-gate 
933*0Sstevel@tonic-gate 	aw->aw_levone =
934*0Sstevel@tonic-gate 	    mdb_alloc(aw->aw_nlevone * sizeof (uintptr_t), UM_SLEEP);
935*0Sstevel@tonic-gate 
936*0Sstevel@tonic-gate 	aw->aw_levone_ndx = 0;
937*0Sstevel@tonic-gate 	aw->aw_levtwo_ndx = 0;
938*0Sstevel@tonic-gate 
939*0Sstevel@tonic-gate 	mdb_vread(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t),
940*0Sstevel@tonic-gate 	    (uintptr_t)aw->aw_ahp.array_chunk);
941*0Sstevel@tonic-gate 
942*0Sstevel@tonic-gate 	if (aw->aw_levtwo != NULL) {
943*0Sstevel@tonic-gate 		while (aw->aw_levone[aw->aw_levone_ndx] == NULL) {
944*0Sstevel@tonic-gate 			aw->aw_levone_ndx++;
945*0Sstevel@tonic-gate 			if (aw->aw_levone_ndx == aw->aw_nlevone) {
946*0Sstevel@tonic-gate 				mdb_warn("corrupt anon; couldn't"
947*0Sstevel@tonic-gate 				    "find ptr to lev two map");
948*0Sstevel@tonic-gate 				goto out;
949*0Sstevel@tonic-gate 			}
950*0Sstevel@tonic-gate 		}
951*0Sstevel@tonic-gate 
952*0Sstevel@tonic-gate 		mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t),
953*0Sstevel@tonic-gate 		    aw->aw_levone[aw->aw_levone_ndx]);
954*0Sstevel@tonic-gate 	}
955*0Sstevel@tonic-gate 
956*0Sstevel@tonic-gate out:
957*0Sstevel@tonic-gate 	wsp->walk_data = aw;
958*0Sstevel@tonic-gate 	return (0);
959*0Sstevel@tonic-gate }
960*0Sstevel@tonic-gate 
961*0Sstevel@tonic-gate int
962*0Sstevel@tonic-gate anon_walk_step(mdb_walk_state_t *wsp)
963*0Sstevel@tonic-gate {
964*0Sstevel@tonic-gate 	int status;
965*0Sstevel@tonic-gate 	anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data;
966*0Sstevel@tonic-gate 	struct anon anon;
967*0Sstevel@tonic-gate 	uintptr_t anonptr;
968*0Sstevel@tonic-gate 
969*0Sstevel@tonic-gate again:
970*0Sstevel@tonic-gate 	/*
971*0Sstevel@tonic-gate 	 * Once we've walked through level one, we're done.
972*0Sstevel@tonic-gate 	 */
973*0Sstevel@tonic-gate 	if (aw->aw_levone_ndx == aw->aw_nlevone)
974*0Sstevel@tonic-gate 		return (WALK_DONE);
975*0Sstevel@tonic-gate 
976*0Sstevel@tonic-gate 	if (aw->aw_levtwo == NULL) {
977*0Sstevel@tonic-gate 		anonptr = aw->aw_levone[aw->aw_levone_ndx];
978*0Sstevel@tonic-gate 		aw->aw_levone_ndx++;
979*0Sstevel@tonic-gate 	} else {
980*0Sstevel@tonic-gate 		anonptr = aw->aw_levtwo[aw->aw_levtwo_ndx];
981*0Sstevel@tonic-gate 		aw->aw_levtwo_ndx++;
982*0Sstevel@tonic-gate 
983*0Sstevel@tonic-gate 		if (aw->aw_levtwo_ndx == ANON_CHUNK_SIZE) {
984*0Sstevel@tonic-gate 			aw->aw_levtwo_ndx = 0;
985*0Sstevel@tonic-gate 
986*0Sstevel@tonic-gate 			do {
987*0Sstevel@tonic-gate 				aw->aw_levone_ndx++;
988*0Sstevel@tonic-gate 
989*0Sstevel@tonic-gate 				if (aw->aw_levone_ndx == aw->aw_nlevone)
990*0Sstevel@tonic-gate 					return (WALK_DONE);
991*0Sstevel@tonic-gate 			} while (aw->aw_levone[aw->aw_levone_ndx] == NULL);
992*0Sstevel@tonic-gate 
993*0Sstevel@tonic-gate 			mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE *
994*0Sstevel@tonic-gate 			    sizeof (uintptr_t),
995*0Sstevel@tonic-gate 			    aw->aw_levone[aw->aw_levone_ndx]);
996*0Sstevel@tonic-gate 		}
997*0Sstevel@tonic-gate 	}
998*0Sstevel@tonic-gate 
999*0Sstevel@tonic-gate 	if (anonptr != NULL) {
1000*0Sstevel@tonic-gate 		mdb_vread(&anon, sizeof (anon), anonptr);
1001*0Sstevel@tonic-gate 		status = wsp->walk_callback(anonptr, &anon, wsp->walk_cbdata);
1002*0Sstevel@tonic-gate 	} else
1003*0Sstevel@tonic-gate 		goto again;
1004*0Sstevel@tonic-gate 
1005*0Sstevel@tonic-gate 	return (status);
1006*0Sstevel@tonic-gate }
1007*0Sstevel@tonic-gate 
1008*0Sstevel@tonic-gate void
1009*0Sstevel@tonic-gate anon_walk_fini(mdb_walk_state_t *wsp)
1010*0Sstevel@tonic-gate {
1011*0Sstevel@tonic-gate 	anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data;
1012*0Sstevel@tonic-gate 
1013*0Sstevel@tonic-gate 	if (aw->aw_levtwo != NULL)
1014*0Sstevel@tonic-gate 		mdb_free(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t));
1015*0Sstevel@tonic-gate 
1016*0Sstevel@tonic-gate 	mdb_free(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t));
1017*0Sstevel@tonic-gate 	mdb_free(aw, sizeof (anon_walk_data_t));
1018*0Sstevel@tonic-gate }
1019*0Sstevel@tonic-gate 
1020*0Sstevel@tonic-gate /*ARGSUSED*/
1021*0Sstevel@tonic-gate int
1022*0Sstevel@tonic-gate whereopen_fwalk(uintptr_t addr, struct file *f, uintptr_t *target)
1023*0Sstevel@tonic-gate {
1024*0Sstevel@tonic-gate 	if ((uintptr_t)f->f_vnode == *target) {
1025*0Sstevel@tonic-gate 		mdb_printf("file %p\n", addr);
1026*0Sstevel@tonic-gate 		*target = NULL;
1027*0Sstevel@tonic-gate 	}
1028*0Sstevel@tonic-gate 
1029*0Sstevel@tonic-gate 	return (WALK_NEXT);
1030*0Sstevel@tonic-gate }
1031*0Sstevel@tonic-gate 
1032*0Sstevel@tonic-gate /*ARGSUSED*/
1033*0Sstevel@tonic-gate int
1034*0Sstevel@tonic-gate whereopen_pwalk(uintptr_t addr, void *ignored, uintptr_t *target)
1035*0Sstevel@tonic-gate {
1036*0Sstevel@tonic-gate 	uintptr_t t = *target;
1037*0Sstevel@tonic-gate 
1038*0Sstevel@tonic-gate 	if (mdb_pwalk("file", (mdb_walk_cb_t)whereopen_fwalk, &t, addr) == -1) {
1039*0Sstevel@tonic-gate 		mdb_warn("couldn't file walk proc %p", addr);
1040*0Sstevel@tonic-gate 		return (WALK_ERR);
1041*0Sstevel@tonic-gate 	}
1042*0Sstevel@tonic-gate 
1043*0Sstevel@tonic-gate 	if (t == NULL)
1044*0Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
1045*0Sstevel@tonic-gate 
1046*0Sstevel@tonic-gate 	return (WALK_NEXT);
1047*0Sstevel@tonic-gate }
1048*0Sstevel@tonic-gate 
1049*0Sstevel@tonic-gate /*ARGSUSED*/
1050*0Sstevel@tonic-gate int
1051*0Sstevel@tonic-gate whereopen(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1052*0Sstevel@tonic-gate {
1053*0Sstevel@tonic-gate 	uintptr_t target = addr;
1054*0Sstevel@tonic-gate 
1055*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC) || addr == NULL)
1056*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1057*0Sstevel@tonic-gate 
1058*0Sstevel@tonic-gate 	if (mdb_walk("proc", (mdb_walk_cb_t)whereopen_pwalk, &target) == -1) {
1059*0Sstevel@tonic-gate 		mdb_warn("can't proc walk");
1060*0Sstevel@tonic-gate 		return (DCMD_ERR);
1061*0Sstevel@tonic-gate 	}
1062*0Sstevel@tonic-gate 
1063*0Sstevel@tonic-gate 	return (DCMD_OK);
1064*0Sstevel@tonic-gate }
1065*0Sstevel@tonic-gate 
1066*0Sstevel@tonic-gate typedef struct datafmt {
1067*0Sstevel@tonic-gate 	char	*hdr1;
1068*0Sstevel@tonic-gate 	char	*hdr2;
1069*0Sstevel@tonic-gate 	char	*dashes;
1070*0Sstevel@tonic-gate 	char	*fmt;
1071*0Sstevel@tonic-gate } datafmt_t;
1072*0Sstevel@tonic-gate 
1073*0Sstevel@tonic-gate static datafmt_t kmemfmt[] = {
1074*0Sstevel@tonic-gate 	{ "cache                    ", "name                     ",
1075*0Sstevel@tonic-gate 	"-------------------------", "%-25s "				},
1076*0Sstevel@tonic-gate 	{ "   buf",	"  size",	"------",	"%6u "		},
1077*0Sstevel@tonic-gate 	{ "   buf",	"in use",	"------",	"%6u "		},
1078*0Sstevel@tonic-gate 	{ "   buf",	" total",	"------",	"%6u "		},
1079*0Sstevel@tonic-gate 	{ "   memory",	"   in use",	"---------",	"%9u "		},
1080*0Sstevel@tonic-gate 	{ "    alloc",	"  succeed",	"---------",	"%9u "		},
1081*0Sstevel@tonic-gate 	{ "alloc",	" fail",	"-----",	"%5u "		},
1082*0Sstevel@tonic-gate 	{ NULL,		NULL,		NULL,		NULL		}
1083*0Sstevel@tonic-gate };
1084*0Sstevel@tonic-gate 
1085*0Sstevel@tonic-gate static datafmt_t vmemfmt[] = {
1086*0Sstevel@tonic-gate 	{ "vmem                     ", "name                     ",
1087*0Sstevel@tonic-gate 	"-------------------------", "%-*s "				},
1088*0Sstevel@tonic-gate 	{ "   memory",	"   in use",	"---------",	"%9llu "	},
1089*0Sstevel@tonic-gate 	{ "    memory",	"     total",	"----------",	"%10llu "	},
1090*0Sstevel@tonic-gate 	{ "   memory",	"   import",	"---------",	"%9llu "	},
1091*0Sstevel@tonic-gate 	{ "    alloc",	"  succeed",	"---------",	"%9llu "	},
1092*0Sstevel@tonic-gate 	{ "alloc",	" fail",	"-----",	"%5llu "	},
1093*0Sstevel@tonic-gate 	{ NULL,		NULL,		NULL,		NULL		}
1094*0Sstevel@tonic-gate };
1095*0Sstevel@tonic-gate 
1096*0Sstevel@tonic-gate /*ARGSUSED*/
1097*0Sstevel@tonic-gate static int
1098*0Sstevel@tonic-gate kmastat_cpu_avail(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *avail)
1099*0Sstevel@tonic-gate {
1100*0Sstevel@tonic-gate 	if (ccp->cc_rounds > 0)
1101*0Sstevel@tonic-gate 		*avail += ccp->cc_rounds;
1102*0Sstevel@tonic-gate 	if (ccp->cc_prounds > 0)
1103*0Sstevel@tonic-gate 		*avail += ccp->cc_prounds;
1104*0Sstevel@tonic-gate 
1105*0Sstevel@tonic-gate 	return (WALK_NEXT);
1106*0Sstevel@tonic-gate }
1107*0Sstevel@tonic-gate 
1108*0Sstevel@tonic-gate /*ARGSUSED*/
1109*0Sstevel@tonic-gate static int
1110*0Sstevel@tonic-gate kmastat_cpu_alloc(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *alloc)
1111*0Sstevel@tonic-gate {
1112*0Sstevel@tonic-gate 	*alloc += ccp->cc_alloc;
1113*0Sstevel@tonic-gate 
1114*0Sstevel@tonic-gate 	return (WALK_NEXT);
1115*0Sstevel@tonic-gate }
1116*0Sstevel@tonic-gate 
1117*0Sstevel@tonic-gate /*ARGSUSED*/
1118*0Sstevel@tonic-gate static int
1119*0Sstevel@tonic-gate kmastat_slab_avail(uintptr_t addr, const kmem_slab_t *sp, int *avail)
1120*0Sstevel@tonic-gate {
1121*0Sstevel@tonic-gate 	*avail += sp->slab_chunks - sp->slab_refcnt;
1122*0Sstevel@tonic-gate 
1123*0Sstevel@tonic-gate 	return (WALK_NEXT);
1124*0Sstevel@tonic-gate }
1125*0Sstevel@tonic-gate 
1126*0Sstevel@tonic-gate typedef struct kmastat_vmem {
1127*0Sstevel@tonic-gate 	uintptr_t kv_addr;
1128*0Sstevel@tonic-gate 	struct kmastat_vmem *kv_next;
1129*0Sstevel@tonic-gate 	int kv_meminuse;
1130*0Sstevel@tonic-gate 	int kv_alloc;
1131*0Sstevel@tonic-gate 	int kv_fail;
1132*0Sstevel@tonic-gate } kmastat_vmem_t;
1133*0Sstevel@tonic-gate 
1134*0Sstevel@tonic-gate static int
1135*0Sstevel@tonic-gate kmastat_cache(uintptr_t addr, const kmem_cache_t *cp, kmastat_vmem_t **kvp)
1136*0Sstevel@tonic-gate {
1137*0Sstevel@tonic-gate 	kmastat_vmem_t *kv;
1138*0Sstevel@tonic-gate 	datafmt_t *dfp = kmemfmt;
1139*0Sstevel@tonic-gate 	int magsize;
1140*0Sstevel@tonic-gate 
1141*0Sstevel@tonic-gate 	int avail, alloc, total;
1142*0Sstevel@tonic-gate 	size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) *
1143*0Sstevel@tonic-gate 	    cp->cache_slabsize;
1144*0Sstevel@tonic-gate 
1145*0Sstevel@tonic-gate 	mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)kmastat_cpu_avail;
1146*0Sstevel@tonic-gate 	mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)kmastat_cpu_alloc;
1147*0Sstevel@tonic-gate 	mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)kmastat_slab_avail;
1148*0Sstevel@tonic-gate 
1149*0Sstevel@tonic-gate 	magsize = kmem_get_magsize(cp);
1150*0Sstevel@tonic-gate 
1151*0Sstevel@tonic-gate 	alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc;
1152*0Sstevel@tonic-gate 	avail = cp->cache_full.ml_total * magsize;
1153*0Sstevel@tonic-gate 	total = cp->cache_buftotal;
1154*0Sstevel@tonic-gate 
1155*0Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_cpu_cache", cpu_alloc, &alloc, addr);
1156*0Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_cpu_cache", cpu_avail, &avail, addr);
1157*0Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_slab_partial", slab_avail, &avail, addr);
1158*0Sstevel@tonic-gate 
1159*0Sstevel@tonic-gate 	for (kv = *kvp; kv != NULL; kv = kv->kv_next) {
1160*0Sstevel@tonic-gate 		if (kv->kv_addr == (uintptr_t)cp->cache_arena)
1161*0Sstevel@tonic-gate 			goto out;
1162*0Sstevel@tonic-gate 	}
1163*0Sstevel@tonic-gate 
1164*0Sstevel@tonic-gate 	kv = mdb_zalloc(sizeof (kmastat_vmem_t), UM_SLEEP | UM_GC);
1165*0Sstevel@tonic-gate 	kv->kv_next = *kvp;
1166*0Sstevel@tonic-gate 	kv->kv_addr = (uintptr_t)cp->cache_arena;
1167*0Sstevel@tonic-gate 	*kvp = kv;
1168*0Sstevel@tonic-gate out:
1169*0Sstevel@tonic-gate 	kv->kv_meminuse += meminuse;
1170*0Sstevel@tonic-gate 	kv->kv_alloc += alloc;
1171*0Sstevel@tonic-gate 	kv->kv_fail += cp->cache_alloc_fail;
1172*0Sstevel@tonic-gate 
1173*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_name);
1174*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_bufsize);
1175*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, total - avail);
1176*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, total);
1177*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, meminuse);
1178*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, alloc);
1179*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_alloc_fail);
1180*0Sstevel@tonic-gate 	mdb_printf("\n");
1181*0Sstevel@tonic-gate 
1182*0Sstevel@tonic-gate 	return (WALK_NEXT);
1183*0Sstevel@tonic-gate }
1184*0Sstevel@tonic-gate 
1185*0Sstevel@tonic-gate static int
1186*0Sstevel@tonic-gate kmastat_vmem_totals(uintptr_t addr, const vmem_t *v, kmastat_vmem_t *kv)
1187*0Sstevel@tonic-gate {
1188*0Sstevel@tonic-gate 	size_t len;
1189*0Sstevel@tonic-gate 
1190*0Sstevel@tonic-gate 	while (kv != NULL && kv->kv_addr != addr)
1191*0Sstevel@tonic-gate 		kv = kv->kv_next;
1192*0Sstevel@tonic-gate 
1193*0Sstevel@tonic-gate 	if (kv == NULL || kv->kv_alloc == 0)
1194*0Sstevel@tonic-gate 		return (WALK_NEXT);
1195*0Sstevel@tonic-gate 
1196*0Sstevel@tonic-gate 	len = MIN(17, strlen(v->vm_name));
1197*0Sstevel@tonic-gate 
1198*0Sstevel@tonic-gate 	mdb_printf("Total [%s]%*s %6s %6s %6s %9u %9u %5u\n", v->vm_name,
1199*0Sstevel@tonic-gate 	    17 - len, "", "", "", "",
1200*0Sstevel@tonic-gate 	    kv->kv_meminuse, kv->kv_alloc, kv->kv_fail);
1201*0Sstevel@tonic-gate 
1202*0Sstevel@tonic-gate 	return (WALK_NEXT);
1203*0Sstevel@tonic-gate }
1204*0Sstevel@tonic-gate 
1205*0Sstevel@tonic-gate /*ARGSUSED*/
1206*0Sstevel@tonic-gate static int
1207*0Sstevel@tonic-gate kmastat_vmem(uintptr_t addr, const vmem_t *v, void *ignored)
1208*0Sstevel@tonic-gate {
1209*0Sstevel@tonic-gate 	datafmt_t *dfp = vmemfmt;
1210*0Sstevel@tonic-gate 	const vmem_kstat_t *vkp = &v->vm_kstat;
1211*0Sstevel@tonic-gate 	uintptr_t paddr;
1212*0Sstevel@tonic-gate 	vmem_t parent;
1213*0Sstevel@tonic-gate 	int ident = 0;
1214*0Sstevel@tonic-gate 
1215*0Sstevel@tonic-gate 	for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) {
1216*0Sstevel@tonic-gate 		if (mdb_vread(&parent, sizeof (parent), paddr) == -1) {
1217*0Sstevel@tonic-gate 			mdb_warn("couldn't trace %p's ancestry", addr);
1218*0Sstevel@tonic-gate 			ident = 0;
1219*0Sstevel@tonic-gate 			break;
1220*0Sstevel@tonic-gate 		}
1221*0Sstevel@tonic-gate 		paddr = (uintptr_t)parent.vm_source;
1222*0Sstevel@tonic-gate 	}
1223*0Sstevel@tonic-gate 
1224*0Sstevel@tonic-gate 	mdb_printf("%*s", ident, "");
1225*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name);
1226*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_mem_inuse.value.ui64);
1227*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_mem_total.value.ui64);
1228*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_mem_import.value.ui64);
1229*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_alloc.value.ui64);
1230*0Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_fail.value.ui64);
1231*0Sstevel@tonic-gate 
1232*0Sstevel@tonic-gate 	mdb_printf("\n");
1233*0Sstevel@tonic-gate 
1234*0Sstevel@tonic-gate 	return (WALK_NEXT);
1235*0Sstevel@tonic-gate }
1236*0Sstevel@tonic-gate 
1237*0Sstevel@tonic-gate /*ARGSUSED*/
1238*0Sstevel@tonic-gate int
1239*0Sstevel@tonic-gate kmastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1240*0Sstevel@tonic-gate {
1241*0Sstevel@tonic-gate 	kmastat_vmem_t *kv = NULL;
1242*0Sstevel@tonic-gate 	datafmt_t *dfp;
1243*0Sstevel@tonic-gate 
1244*0Sstevel@tonic-gate 	if (argc != 0)
1245*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1246*0Sstevel@tonic-gate 
1247*0Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
1248*0Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr1);
1249*0Sstevel@tonic-gate 	mdb_printf("\n");
1250*0Sstevel@tonic-gate 
1251*0Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
1252*0Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr2);
1253*0Sstevel@tonic-gate 	mdb_printf("\n");
1254*0Sstevel@tonic-gate 
1255*0Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
1256*0Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
1257*0Sstevel@tonic-gate 	mdb_printf("\n");
1258*0Sstevel@tonic-gate 
1259*0Sstevel@tonic-gate 	if (mdb_walk("kmem_cache", (mdb_walk_cb_t)kmastat_cache, &kv) == -1) {
1260*0Sstevel@tonic-gate 		mdb_warn("can't walk 'kmem_cache'");
1261*0Sstevel@tonic-gate 		return (DCMD_ERR);
1262*0Sstevel@tonic-gate 	}
1263*0Sstevel@tonic-gate 
1264*0Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
1265*0Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
1266*0Sstevel@tonic-gate 	mdb_printf("\n");
1267*0Sstevel@tonic-gate 
1268*0Sstevel@tonic-gate 	if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem_totals, kv) == -1) {
1269*0Sstevel@tonic-gate 		mdb_warn("can't walk 'vmem'");
1270*0Sstevel@tonic-gate 		return (DCMD_ERR);
1271*0Sstevel@tonic-gate 	}
1272*0Sstevel@tonic-gate 
1273*0Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
1274*0Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
1275*0Sstevel@tonic-gate 	mdb_printf("\n");
1276*0Sstevel@tonic-gate 
1277*0Sstevel@tonic-gate 	mdb_printf("\n");
1278*0Sstevel@tonic-gate 
1279*0Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
1280*0Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr1);
1281*0Sstevel@tonic-gate 	mdb_printf("\n");
1282*0Sstevel@tonic-gate 
1283*0Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
1284*0Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr2);
1285*0Sstevel@tonic-gate 	mdb_printf("\n");
1286*0Sstevel@tonic-gate 
1287*0Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
1288*0Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
1289*0Sstevel@tonic-gate 	mdb_printf("\n");
1290*0Sstevel@tonic-gate 
1291*0Sstevel@tonic-gate 	if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem, NULL) == -1) {
1292*0Sstevel@tonic-gate 		mdb_warn("can't walk 'vmem'");
1293*0Sstevel@tonic-gate 		return (DCMD_ERR);
1294*0Sstevel@tonic-gate 	}
1295*0Sstevel@tonic-gate 
1296*0Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
1297*0Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
1298*0Sstevel@tonic-gate 	mdb_printf("\n");
1299*0Sstevel@tonic-gate 	return (DCMD_OK);
1300*0Sstevel@tonic-gate }
1301*0Sstevel@tonic-gate 
1302*0Sstevel@tonic-gate /*
1303*0Sstevel@tonic-gate  * Our ::kgrep callback scans the entire kernel VA space (kas).  kas is made
1304*0Sstevel@tonic-gate  * up of a set of 'struct seg's.  We could just scan each seg en masse, but
1305*0Sstevel@tonic-gate  * unfortunately, a few of the segs are both large and sparse, so we could
1306*0Sstevel@tonic-gate  * spend quite a bit of time scanning VAs which have no backing pages.
1307*0Sstevel@tonic-gate  *
1308*0Sstevel@tonic-gate  * So for the few very sparse segs, we skip the segment itself, and scan
1309*0Sstevel@tonic-gate  * the allocated vmem_segs in the vmem arena which manages that part of kas.
1310*0Sstevel@tonic-gate  * Currently, we do this for:
1311*0Sstevel@tonic-gate  *
1312*0Sstevel@tonic-gate  *	SEG		VMEM ARENA
1313*0Sstevel@tonic-gate  *	kvseg		heap_arena
1314*0Sstevel@tonic-gate  *	kvseg32		heap32_arena
1315*0Sstevel@tonic-gate  *	kvseg_core	heap_core_arena
1316*0Sstevel@tonic-gate  *
1317*0Sstevel@tonic-gate  * In addition, we skip the segkpm segment in its entirety, since it is very
1318*0Sstevel@tonic-gate  * sparse, and contains no new kernel data.
1319*0Sstevel@tonic-gate  */
1320*0Sstevel@tonic-gate typedef struct kgrep_walk_data {
1321*0Sstevel@tonic-gate 	kgrep_cb_func *kg_cb;
1322*0Sstevel@tonic-gate 	void *kg_cbdata;
1323*0Sstevel@tonic-gate 	uintptr_t kg_kvseg;
1324*0Sstevel@tonic-gate 	uintptr_t kg_kvseg32;
1325*0Sstevel@tonic-gate 	uintptr_t kg_kvseg_core;
1326*0Sstevel@tonic-gate 	uintptr_t kg_segkpm;
1327*0Sstevel@tonic-gate } kgrep_walk_data_t;
1328*0Sstevel@tonic-gate 
1329*0Sstevel@tonic-gate static int
1330*0Sstevel@tonic-gate kgrep_walk_seg(uintptr_t addr, const struct seg *seg, kgrep_walk_data_t *kg)
1331*0Sstevel@tonic-gate {
1332*0Sstevel@tonic-gate 	uintptr_t base = (uintptr_t)seg->s_base;
1333*0Sstevel@tonic-gate 
1334*0Sstevel@tonic-gate 	if (addr == kg->kg_kvseg || addr == kg->kg_kvseg32 ||
1335*0Sstevel@tonic-gate 	    addr == kg->kg_kvseg_core)
1336*0Sstevel@tonic-gate 		return (WALK_NEXT);
1337*0Sstevel@tonic-gate 
1338*0Sstevel@tonic-gate 	if ((uintptr_t)seg->s_ops == kg->kg_segkpm)
1339*0Sstevel@tonic-gate 		return (WALK_NEXT);
1340*0Sstevel@tonic-gate 
1341*0Sstevel@tonic-gate 	return (kg->kg_cb(base, base + seg->s_size, kg->kg_cbdata));
1342*0Sstevel@tonic-gate }
1343*0Sstevel@tonic-gate 
1344*0Sstevel@tonic-gate /*ARGSUSED*/
1345*0Sstevel@tonic-gate static int
1346*0Sstevel@tonic-gate kgrep_walk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
1347*0Sstevel@tonic-gate {
1348*0Sstevel@tonic-gate 	return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
1349*0Sstevel@tonic-gate }
1350*0Sstevel@tonic-gate 
1351*0Sstevel@tonic-gate static int
1352*0Sstevel@tonic-gate kgrep_walk_vmem(uintptr_t addr, const vmem_t *vmem, kgrep_walk_data_t *kg)
1353*0Sstevel@tonic-gate {
1354*0Sstevel@tonic-gate 	if (strcmp(vmem->vm_name, "heap") != 0 &&
1355*0Sstevel@tonic-gate 	    strcmp(vmem->vm_name, "heap32") != 0 &&
1356*0Sstevel@tonic-gate 	    strcmp(vmem->vm_name, "heap_core") != 0)
1357*0Sstevel@tonic-gate 		return (WALK_NEXT);
1358*0Sstevel@tonic-gate 
1359*0Sstevel@tonic-gate 	if (mdb_pwalk("vmem_alloc",
1360*0Sstevel@tonic-gate 	    (mdb_walk_cb_t)kgrep_walk_vseg, kg, addr) == -1) {
1361*0Sstevel@tonic-gate 		mdb_warn("couldn't walk vmem_alloc for vmem %p", addr);
1362*0Sstevel@tonic-gate 		return (WALK_ERR);
1363*0Sstevel@tonic-gate 	}
1364*0Sstevel@tonic-gate 
1365*0Sstevel@tonic-gate 	return (WALK_NEXT);
1366*0Sstevel@tonic-gate }
1367*0Sstevel@tonic-gate 
1368*0Sstevel@tonic-gate int
1369*0Sstevel@tonic-gate kgrep_subr(kgrep_cb_func *cb, void *cbdata)
1370*0Sstevel@tonic-gate {
1371*0Sstevel@tonic-gate 	GElf_Sym kas, kvseg, kvseg32, kvseg_core, segkpm;
1372*0Sstevel@tonic-gate 	kgrep_walk_data_t kg;
1373*0Sstevel@tonic-gate 
1374*0Sstevel@tonic-gate 	if (mdb_get_state() == MDB_STATE_RUNNING) {
1375*0Sstevel@tonic-gate 		mdb_warn("kgrep can only be run on a system "
1376*0Sstevel@tonic-gate 		    "dump or under kmdb; see dumpadm(1M)\n");
1377*0Sstevel@tonic-gate 		return (DCMD_ERR);
1378*0Sstevel@tonic-gate 	}
1379*0Sstevel@tonic-gate 
1380*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("kas", &kas) == -1) {
1381*0Sstevel@tonic-gate 		mdb_warn("failed to locate 'kas' symbol\n");
1382*0Sstevel@tonic-gate 		return (DCMD_ERR);
1383*0Sstevel@tonic-gate 	}
1384*0Sstevel@tonic-gate 
1385*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg", &kvseg) == -1) {
1386*0Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg' symbol\n");
1387*0Sstevel@tonic-gate 		return (DCMD_ERR);
1388*0Sstevel@tonic-gate 	}
1389*0Sstevel@tonic-gate 
1390*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg32", &kvseg32) == -1) {
1391*0Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg32' symbol\n");
1392*0Sstevel@tonic-gate 		return (DCMD_ERR);
1393*0Sstevel@tonic-gate 	}
1394*0Sstevel@tonic-gate 
1395*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg_core", &kvseg_core) == -1) {
1396*0Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg_core' symbol\n");
1397*0Sstevel@tonic-gate 		return (DCMD_ERR);
1398*0Sstevel@tonic-gate 	}
1399*0Sstevel@tonic-gate 
1400*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("segkpm_ops", &segkpm) == -1) {
1401*0Sstevel@tonic-gate 		mdb_warn("failed to locate 'segkpm_ops' symbol\n");
1402*0Sstevel@tonic-gate 		return (DCMD_ERR);
1403*0Sstevel@tonic-gate 	}
1404*0Sstevel@tonic-gate 
1405*0Sstevel@tonic-gate 	kg.kg_cb = cb;
1406*0Sstevel@tonic-gate 	kg.kg_cbdata = cbdata;
1407*0Sstevel@tonic-gate 	kg.kg_kvseg = (uintptr_t)kvseg.st_value;
1408*0Sstevel@tonic-gate 	kg.kg_kvseg32 = (uintptr_t)kvseg32.st_value;
1409*0Sstevel@tonic-gate 	kg.kg_kvseg_core = (uintptr_t)kvseg_core.st_value;
1410*0Sstevel@tonic-gate 	kg.kg_segkpm = (uintptr_t)segkpm.st_value;
1411*0Sstevel@tonic-gate 
1412*0Sstevel@tonic-gate 	if (mdb_pwalk("seg", (mdb_walk_cb_t)kgrep_walk_seg,
1413*0Sstevel@tonic-gate 	    &kg, kas.st_value) == -1) {
1414*0Sstevel@tonic-gate 		mdb_warn("failed to walk kas segments");
1415*0Sstevel@tonic-gate 		return (DCMD_ERR);
1416*0Sstevel@tonic-gate 	}
1417*0Sstevel@tonic-gate 
1418*0Sstevel@tonic-gate 	if (mdb_walk("vmem", (mdb_walk_cb_t)kgrep_walk_vmem, &kg) == -1) {
1419*0Sstevel@tonic-gate 		mdb_warn("failed to walk heap/heap32 vmem arenas");
1420*0Sstevel@tonic-gate 		return (DCMD_ERR);
1421*0Sstevel@tonic-gate 	}
1422*0Sstevel@tonic-gate 
1423*0Sstevel@tonic-gate 	return (DCMD_OK);
1424*0Sstevel@tonic-gate }
1425*0Sstevel@tonic-gate 
1426*0Sstevel@tonic-gate size_t
1427*0Sstevel@tonic-gate kgrep_subr_pagesize(void)
1428*0Sstevel@tonic-gate {
1429*0Sstevel@tonic-gate 	return (PAGESIZE);
1430*0Sstevel@tonic-gate }
1431*0Sstevel@tonic-gate 
1432*0Sstevel@tonic-gate typedef struct file_walk_data {
1433*0Sstevel@tonic-gate 	struct uf_entry *fw_flist;
1434*0Sstevel@tonic-gate 	int fw_flistsz;
1435*0Sstevel@tonic-gate 	int fw_ndx;
1436*0Sstevel@tonic-gate 	int fw_nofiles;
1437*0Sstevel@tonic-gate } file_walk_data_t;
1438*0Sstevel@tonic-gate 
1439*0Sstevel@tonic-gate int
1440*0Sstevel@tonic-gate file_walk_init(mdb_walk_state_t *wsp)
1441*0Sstevel@tonic-gate {
1442*0Sstevel@tonic-gate 	file_walk_data_t *fw;
1443*0Sstevel@tonic-gate 	proc_t p;
1444*0Sstevel@tonic-gate 
1445*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
1446*0Sstevel@tonic-gate 		mdb_warn("file walk doesn't support global walks\n");
1447*0Sstevel@tonic-gate 		return (WALK_ERR);
1448*0Sstevel@tonic-gate 	}
1449*0Sstevel@tonic-gate 
1450*0Sstevel@tonic-gate 	fw = mdb_alloc(sizeof (file_walk_data_t), UM_SLEEP);
1451*0Sstevel@tonic-gate 
1452*0Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (p), wsp->walk_addr) == -1) {
1453*0Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
1454*0Sstevel@tonic-gate 		mdb_warn("failed to read proc structure at %p", wsp->walk_addr);
1455*0Sstevel@tonic-gate 		return (WALK_ERR);
1456*0Sstevel@tonic-gate 	}
1457*0Sstevel@tonic-gate 
1458*0Sstevel@tonic-gate 	if (p.p_user.u_finfo.fi_nfiles == 0) {
1459*0Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
1460*0Sstevel@tonic-gate 		return (WALK_DONE);
1461*0Sstevel@tonic-gate 	}
1462*0Sstevel@tonic-gate 
1463*0Sstevel@tonic-gate 	fw->fw_nofiles = p.p_user.u_finfo.fi_nfiles;
1464*0Sstevel@tonic-gate 	fw->fw_flistsz = sizeof (struct uf_entry) * fw->fw_nofiles;
1465*0Sstevel@tonic-gate 	fw->fw_flist = mdb_alloc(fw->fw_flistsz, UM_SLEEP);
1466*0Sstevel@tonic-gate 
1467*0Sstevel@tonic-gate 	if (mdb_vread(fw->fw_flist, fw->fw_flistsz,
1468*0Sstevel@tonic-gate 	    (uintptr_t)p.p_user.u_finfo.fi_list) == -1) {
1469*0Sstevel@tonic-gate 		mdb_warn("failed to read file array at %p",
1470*0Sstevel@tonic-gate 		    p.p_user.u_finfo.fi_list);
1471*0Sstevel@tonic-gate 		mdb_free(fw->fw_flist, fw->fw_flistsz);
1472*0Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
1473*0Sstevel@tonic-gate 		return (WALK_ERR);
1474*0Sstevel@tonic-gate 	}
1475*0Sstevel@tonic-gate 
1476*0Sstevel@tonic-gate 	fw->fw_ndx = 0;
1477*0Sstevel@tonic-gate 	wsp->walk_data = fw;
1478*0Sstevel@tonic-gate 
1479*0Sstevel@tonic-gate 	return (WALK_NEXT);
1480*0Sstevel@tonic-gate }
1481*0Sstevel@tonic-gate 
1482*0Sstevel@tonic-gate int
1483*0Sstevel@tonic-gate file_walk_step(mdb_walk_state_t *wsp)
1484*0Sstevel@tonic-gate {
1485*0Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
1486*0Sstevel@tonic-gate 	struct file file;
1487*0Sstevel@tonic-gate 	uintptr_t fp;
1488*0Sstevel@tonic-gate 
1489*0Sstevel@tonic-gate again:
1490*0Sstevel@tonic-gate 	if (fw->fw_ndx == fw->fw_nofiles)
1491*0Sstevel@tonic-gate 		return (WALK_DONE);
1492*0Sstevel@tonic-gate 
1493*0Sstevel@tonic-gate 	if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) == NULL)
1494*0Sstevel@tonic-gate 		goto again;
1495*0Sstevel@tonic-gate 
1496*0Sstevel@tonic-gate 	(void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
1497*0Sstevel@tonic-gate 	return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
1498*0Sstevel@tonic-gate }
1499*0Sstevel@tonic-gate 
1500*0Sstevel@tonic-gate int
1501*0Sstevel@tonic-gate allfile_walk_step(mdb_walk_state_t *wsp)
1502*0Sstevel@tonic-gate {
1503*0Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
1504*0Sstevel@tonic-gate 	struct file file;
1505*0Sstevel@tonic-gate 	uintptr_t fp;
1506*0Sstevel@tonic-gate 
1507*0Sstevel@tonic-gate 	if (fw->fw_ndx == fw->fw_nofiles)
1508*0Sstevel@tonic-gate 		return (WALK_DONE);
1509*0Sstevel@tonic-gate 
1510*0Sstevel@tonic-gate 	if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) != NULL)
1511*0Sstevel@tonic-gate 		(void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
1512*0Sstevel@tonic-gate 	else
1513*0Sstevel@tonic-gate 		bzero(&file, sizeof (file));
1514*0Sstevel@tonic-gate 
1515*0Sstevel@tonic-gate 	return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
1516*0Sstevel@tonic-gate }
1517*0Sstevel@tonic-gate 
1518*0Sstevel@tonic-gate void
1519*0Sstevel@tonic-gate file_walk_fini(mdb_walk_state_t *wsp)
1520*0Sstevel@tonic-gate {
1521*0Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
1522*0Sstevel@tonic-gate 
1523*0Sstevel@tonic-gate 	mdb_free(fw->fw_flist, fw->fw_flistsz);
1524*0Sstevel@tonic-gate 	mdb_free(fw, sizeof (file_walk_data_t));
1525*0Sstevel@tonic-gate }
1526*0Sstevel@tonic-gate 
1527*0Sstevel@tonic-gate int
1528*0Sstevel@tonic-gate port_walk_init(mdb_walk_state_t *wsp)
1529*0Sstevel@tonic-gate {
1530*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
1531*0Sstevel@tonic-gate 		mdb_warn("port walk doesn't support global walks\n");
1532*0Sstevel@tonic-gate 		return (WALK_ERR);
1533*0Sstevel@tonic-gate 	}
1534*0Sstevel@tonic-gate 
1535*0Sstevel@tonic-gate 	if (mdb_layered_walk("file", wsp) == -1) {
1536*0Sstevel@tonic-gate 		mdb_warn("couldn't walk 'file'");
1537*0Sstevel@tonic-gate 		return (WALK_ERR);
1538*0Sstevel@tonic-gate 	}
1539*0Sstevel@tonic-gate 	return (WALK_NEXT);
1540*0Sstevel@tonic-gate }
1541*0Sstevel@tonic-gate 
1542*0Sstevel@tonic-gate int
1543*0Sstevel@tonic-gate port_walk_step(mdb_walk_state_t *wsp)
1544*0Sstevel@tonic-gate {
1545*0Sstevel@tonic-gate 	struct vnode	vn;
1546*0Sstevel@tonic-gate 	uintptr_t	vp;
1547*0Sstevel@tonic-gate 	uintptr_t	pp;
1548*0Sstevel@tonic-gate 	struct port	port;
1549*0Sstevel@tonic-gate 
1550*0Sstevel@tonic-gate 	vp = (uintptr_t)((struct file *)wsp->walk_layer)->f_vnode;
1551*0Sstevel@tonic-gate 	if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
1552*0Sstevel@tonic-gate 		mdb_warn("failed to read vnode_t at %p", vp);
1553*0Sstevel@tonic-gate 		return (WALK_ERR);
1554*0Sstevel@tonic-gate 	}
1555*0Sstevel@tonic-gate 	if (vn.v_type != VPORT)
1556*0Sstevel@tonic-gate 		return (WALK_NEXT);
1557*0Sstevel@tonic-gate 
1558*0Sstevel@tonic-gate 	pp = (uintptr_t)vn.v_data;
1559*0Sstevel@tonic-gate 	if (mdb_vread(&port, sizeof (port), pp) == -1) {
1560*0Sstevel@tonic-gate 		mdb_warn("failed to read port_t at %p", pp);
1561*0Sstevel@tonic-gate 		return (WALK_ERR);
1562*0Sstevel@tonic-gate 	}
1563*0Sstevel@tonic-gate 	return (wsp->walk_callback(pp, &port, wsp->walk_cbdata));
1564*0Sstevel@tonic-gate }
1565*0Sstevel@tonic-gate 
1566*0Sstevel@tonic-gate typedef struct portev_walk_data {
1567*0Sstevel@tonic-gate 	list_node_t	*pev_node;
1568*0Sstevel@tonic-gate 	list_node_t	*pev_last;
1569*0Sstevel@tonic-gate 	size_t		pev_offset;
1570*0Sstevel@tonic-gate } portev_walk_data_t;
1571*0Sstevel@tonic-gate 
1572*0Sstevel@tonic-gate int
1573*0Sstevel@tonic-gate portev_walk_init(mdb_walk_state_t *wsp)
1574*0Sstevel@tonic-gate {
1575*0Sstevel@tonic-gate 	portev_walk_data_t *pevd;
1576*0Sstevel@tonic-gate 	struct port	port;
1577*0Sstevel@tonic-gate 	struct vnode	vn;
1578*0Sstevel@tonic-gate 	struct list	*list;
1579*0Sstevel@tonic-gate 	uintptr_t	vp;
1580*0Sstevel@tonic-gate 
1581*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
1582*0Sstevel@tonic-gate 		mdb_warn("portev walk doesn't support global walks\n");
1583*0Sstevel@tonic-gate 		return (WALK_ERR);
1584*0Sstevel@tonic-gate 	}
1585*0Sstevel@tonic-gate 
1586*0Sstevel@tonic-gate 	pevd = mdb_alloc(sizeof (portev_walk_data_t), UM_SLEEP);
1587*0Sstevel@tonic-gate 
1588*0Sstevel@tonic-gate 	if (mdb_vread(&port, sizeof (port), wsp->walk_addr) == -1) {
1589*0Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
1590*0Sstevel@tonic-gate 		mdb_warn("failed to read port structure at %p", wsp->walk_addr);
1591*0Sstevel@tonic-gate 		return (WALK_ERR);
1592*0Sstevel@tonic-gate 	}
1593*0Sstevel@tonic-gate 
1594*0Sstevel@tonic-gate 	vp = (uintptr_t)port.port_vnode;
1595*0Sstevel@tonic-gate 	if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
1596*0Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
1597*0Sstevel@tonic-gate 		mdb_warn("failed to read vnode_t at %p", vp);
1598*0Sstevel@tonic-gate 		return (WALK_ERR);
1599*0Sstevel@tonic-gate 	}
1600*0Sstevel@tonic-gate 
1601*0Sstevel@tonic-gate 	if (vn.v_type != VPORT) {
1602*0Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
1603*0Sstevel@tonic-gate 		mdb_warn("input address (%p) does not point to an event port",
1604*0Sstevel@tonic-gate 		    wsp->walk_addr);
1605*0Sstevel@tonic-gate 		return (WALK_ERR);
1606*0Sstevel@tonic-gate 	}
1607*0Sstevel@tonic-gate 
1608*0Sstevel@tonic-gate 	if (port.port_queue.portq_nent == 0) {
1609*0Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
1610*0Sstevel@tonic-gate 		return (WALK_DONE);
1611*0Sstevel@tonic-gate 	}
1612*0Sstevel@tonic-gate 	list = &port.port_queue.portq_list;
1613*0Sstevel@tonic-gate 	pevd->pev_offset = list->list_offset;
1614*0Sstevel@tonic-gate 	pevd->pev_last = list->list_head.list_prev;
1615*0Sstevel@tonic-gate 	pevd->pev_node = list->list_head.list_next;
1616*0Sstevel@tonic-gate 	wsp->walk_data = pevd;
1617*0Sstevel@tonic-gate 	return (WALK_NEXT);
1618*0Sstevel@tonic-gate }
1619*0Sstevel@tonic-gate 
1620*0Sstevel@tonic-gate int
1621*0Sstevel@tonic-gate portev_walk_step(mdb_walk_state_t *wsp)
1622*0Sstevel@tonic-gate {
1623*0Sstevel@tonic-gate 	portev_walk_data_t	*pevd;
1624*0Sstevel@tonic-gate 	struct port_kevent	ev;
1625*0Sstevel@tonic-gate 	uintptr_t		evp;
1626*0Sstevel@tonic-gate 
1627*0Sstevel@tonic-gate 	pevd = (portev_walk_data_t *)wsp->walk_data;
1628*0Sstevel@tonic-gate 
1629*0Sstevel@tonic-gate 	if (pevd->pev_last == NULL)
1630*0Sstevel@tonic-gate 		return (WALK_DONE);
1631*0Sstevel@tonic-gate 	if (pevd->pev_node == pevd->pev_last)
1632*0Sstevel@tonic-gate 		pevd->pev_last = NULL;		/* last round */
1633*0Sstevel@tonic-gate 
1634*0Sstevel@tonic-gate 	evp = ((uintptr_t)(((char *)pevd->pev_node) - pevd->pev_offset));
1635*0Sstevel@tonic-gate 	if (mdb_vread(&ev, sizeof (ev), evp) == -1) {
1636*0Sstevel@tonic-gate 		mdb_warn("failed to read port_kevent at %p", evp);
1637*0Sstevel@tonic-gate 		return (WALK_DONE);
1638*0Sstevel@tonic-gate 	}
1639*0Sstevel@tonic-gate 	pevd->pev_node = ev.portkev_node.list_next;
1640*0Sstevel@tonic-gate 	return (wsp->walk_callback(evp, &ev, wsp->walk_cbdata));
1641*0Sstevel@tonic-gate }
1642*0Sstevel@tonic-gate 
1643*0Sstevel@tonic-gate void
1644*0Sstevel@tonic-gate portev_walk_fini(mdb_walk_state_t *wsp)
1645*0Sstevel@tonic-gate {
1646*0Sstevel@tonic-gate 	portev_walk_data_t *pevd = (portev_walk_data_t *)wsp->walk_data;
1647*0Sstevel@tonic-gate 
1648*0Sstevel@tonic-gate 	if (pevd != NULL)
1649*0Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
1650*0Sstevel@tonic-gate }
1651*0Sstevel@tonic-gate 
1652*0Sstevel@tonic-gate typedef struct proc_walk_data {
1653*0Sstevel@tonic-gate 	uintptr_t *pw_stack;
1654*0Sstevel@tonic-gate 	int pw_depth;
1655*0Sstevel@tonic-gate 	int pw_max;
1656*0Sstevel@tonic-gate } proc_walk_data_t;
1657*0Sstevel@tonic-gate 
1658*0Sstevel@tonic-gate int
1659*0Sstevel@tonic-gate proc_walk_init(mdb_walk_state_t *wsp)
1660*0Sstevel@tonic-gate {
1661*0Sstevel@tonic-gate 	GElf_Sym sym;
1662*0Sstevel@tonic-gate 	proc_walk_data_t *pw;
1663*0Sstevel@tonic-gate 
1664*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
1665*0Sstevel@tonic-gate 		if (mdb_lookup_by_name("p0", &sym) == -1) {
1666*0Sstevel@tonic-gate 			mdb_warn("failed to read 'practive'");
1667*0Sstevel@tonic-gate 			return (WALK_ERR);
1668*0Sstevel@tonic-gate 		}
1669*0Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)sym.st_value;
1670*0Sstevel@tonic-gate 	}
1671*0Sstevel@tonic-gate 
1672*0Sstevel@tonic-gate 	pw = mdb_zalloc(sizeof (proc_walk_data_t), UM_SLEEP);
1673*0Sstevel@tonic-gate 
1674*0Sstevel@tonic-gate 	if (mdb_readvar(&pw->pw_max, "nproc") == -1) {
1675*0Sstevel@tonic-gate 		mdb_warn("failed to read 'nproc'");
1676*0Sstevel@tonic-gate 		mdb_free(pw, sizeof (pw));
1677*0Sstevel@tonic-gate 		return (WALK_ERR);
1678*0Sstevel@tonic-gate 	}
1679*0Sstevel@tonic-gate 
1680*0Sstevel@tonic-gate 	pw->pw_stack = mdb_alloc(pw->pw_max * sizeof (uintptr_t), UM_SLEEP);
1681*0Sstevel@tonic-gate 	wsp->walk_data = pw;
1682*0Sstevel@tonic-gate 
1683*0Sstevel@tonic-gate 	return (WALK_NEXT);
1684*0Sstevel@tonic-gate }
1685*0Sstevel@tonic-gate 
1686*0Sstevel@tonic-gate int
1687*0Sstevel@tonic-gate proc_walk_step(mdb_walk_state_t *wsp)
1688*0Sstevel@tonic-gate {
1689*0Sstevel@tonic-gate 	proc_walk_data_t *pw = wsp->walk_data;
1690*0Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
1691*0Sstevel@tonic-gate 	uintptr_t cld, sib;
1692*0Sstevel@tonic-gate 
1693*0Sstevel@tonic-gate 	int status;
1694*0Sstevel@tonic-gate 	proc_t pr;
1695*0Sstevel@tonic-gate 
1696*0Sstevel@tonic-gate 	if (mdb_vread(&pr, sizeof (proc_t), addr) == -1) {
1697*0Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", addr);
1698*0Sstevel@tonic-gate 		return (WALK_DONE);
1699*0Sstevel@tonic-gate 	}
1700*0Sstevel@tonic-gate 
1701*0Sstevel@tonic-gate 	cld = (uintptr_t)pr.p_child;
1702*0Sstevel@tonic-gate 	sib = (uintptr_t)pr.p_sibling;
1703*0Sstevel@tonic-gate 
1704*0Sstevel@tonic-gate 	if (pw->pw_depth > 0 && addr == pw->pw_stack[pw->pw_depth - 1]) {
1705*0Sstevel@tonic-gate 		pw->pw_depth--;
1706*0Sstevel@tonic-gate 		goto sib;
1707*0Sstevel@tonic-gate 	}
1708*0Sstevel@tonic-gate 
1709*0Sstevel@tonic-gate 	status = wsp->walk_callback(addr, &pr, wsp->walk_cbdata);
1710*0Sstevel@tonic-gate 
1711*0Sstevel@tonic-gate 	if (status != WALK_NEXT)
1712*0Sstevel@tonic-gate 		return (status);
1713*0Sstevel@tonic-gate 
1714*0Sstevel@tonic-gate 	if ((wsp->walk_addr = cld) != NULL) {
1715*0Sstevel@tonic-gate 		if (mdb_vread(&pr, sizeof (proc_t), cld) == -1) {
1716*0Sstevel@tonic-gate 			mdb_warn("proc %p has invalid p_child %p; skipping\n",
1717*0Sstevel@tonic-gate 			    addr, cld);
1718*0Sstevel@tonic-gate 			goto sib;
1719*0Sstevel@tonic-gate 		}
1720*0Sstevel@tonic-gate 
1721*0Sstevel@tonic-gate 		pw->pw_stack[pw->pw_depth++] = addr;
1722*0Sstevel@tonic-gate 
1723*0Sstevel@tonic-gate 		if (pw->pw_depth == pw->pw_max) {
1724*0Sstevel@tonic-gate 			mdb_warn("depth %d exceeds max depth; try again\n",
1725*0Sstevel@tonic-gate 			    pw->pw_depth);
1726*0Sstevel@tonic-gate 			return (WALK_DONE);
1727*0Sstevel@tonic-gate 		}
1728*0Sstevel@tonic-gate 		return (WALK_NEXT);
1729*0Sstevel@tonic-gate 	}
1730*0Sstevel@tonic-gate 
1731*0Sstevel@tonic-gate sib:
1732*0Sstevel@tonic-gate 	/*
1733*0Sstevel@tonic-gate 	 * We know that p0 has no siblings, and if another starting proc
1734*0Sstevel@tonic-gate 	 * was given, we don't want to walk its siblings anyway.
1735*0Sstevel@tonic-gate 	 */
1736*0Sstevel@tonic-gate 	if (pw->pw_depth == 0)
1737*0Sstevel@tonic-gate 		return (WALK_DONE);
1738*0Sstevel@tonic-gate 
1739*0Sstevel@tonic-gate 	if (sib != NULL && mdb_vread(&pr, sizeof (proc_t), sib) == -1) {
1740*0Sstevel@tonic-gate 		mdb_warn("proc %p has invalid p_sibling %p; skipping\n",
1741*0Sstevel@tonic-gate 		    addr, sib);
1742*0Sstevel@tonic-gate 		sib = NULL;
1743*0Sstevel@tonic-gate 	}
1744*0Sstevel@tonic-gate 
1745*0Sstevel@tonic-gate 	if ((wsp->walk_addr = sib) == NULL) {
1746*0Sstevel@tonic-gate 		if (pw->pw_depth > 0) {
1747*0Sstevel@tonic-gate 			wsp->walk_addr = pw->pw_stack[pw->pw_depth - 1];
1748*0Sstevel@tonic-gate 			return (WALK_NEXT);
1749*0Sstevel@tonic-gate 		}
1750*0Sstevel@tonic-gate 		return (WALK_DONE);
1751*0Sstevel@tonic-gate 	}
1752*0Sstevel@tonic-gate 
1753*0Sstevel@tonic-gate 	return (WALK_NEXT);
1754*0Sstevel@tonic-gate }
1755*0Sstevel@tonic-gate 
1756*0Sstevel@tonic-gate void
1757*0Sstevel@tonic-gate proc_walk_fini(mdb_walk_state_t *wsp)
1758*0Sstevel@tonic-gate {
1759*0Sstevel@tonic-gate 	proc_walk_data_t *pw = wsp->walk_data;
1760*0Sstevel@tonic-gate 
1761*0Sstevel@tonic-gate 	mdb_free(pw->pw_stack, pw->pw_max * sizeof (uintptr_t));
1762*0Sstevel@tonic-gate 	mdb_free(pw, sizeof (proc_walk_data_t));
1763*0Sstevel@tonic-gate }
1764*0Sstevel@tonic-gate 
1765*0Sstevel@tonic-gate int
1766*0Sstevel@tonic-gate task_walk_init(mdb_walk_state_t *wsp)
1767*0Sstevel@tonic-gate {
1768*0Sstevel@tonic-gate 	task_t task;
1769*0Sstevel@tonic-gate 
1770*0Sstevel@tonic-gate 	if (mdb_vread(&task, sizeof (task_t), wsp->walk_addr) == -1) {
1771*0Sstevel@tonic-gate 		mdb_warn("failed to read task at %p", wsp->walk_addr);
1772*0Sstevel@tonic-gate 		return (WALK_ERR);
1773*0Sstevel@tonic-gate 	}
1774*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)task.tk_memb_list;
1775*0Sstevel@tonic-gate 	wsp->walk_data = task.tk_memb_list;
1776*0Sstevel@tonic-gate 	return (WALK_NEXT);
1777*0Sstevel@tonic-gate }
1778*0Sstevel@tonic-gate 
1779*0Sstevel@tonic-gate int
1780*0Sstevel@tonic-gate task_walk_step(mdb_walk_state_t *wsp)
1781*0Sstevel@tonic-gate {
1782*0Sstevel@tonic-gate 	proc_t proc;
1783*0Sstevel@tonic-gate 	int status;
1784*0Sstevel@tonic-gate 
1785*0Sstevel@tonic-gate 	if (mdb_vread(&proc, sizeof (proc_t), wsp->walk_addr) == -1) {
1786*0Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", wsp->walk_addr);
1787*0Sstevel@tonic-gate 		return (WALK_DONE);
1788*0Sstevel@tonic-gate 	}
1789*0Sstevel@tonic-gate 
1790*0Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata);
1791*0Sstevel@tonic-gate 
1792*0Sstevel@tonic-gate 	if (proc.p_tasknext == wsp->walk_data)
1793*0Sstevel@tonic-gate 		return (WALK_DONE);
1794*0Sstevel@tonic-gate 
1795*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)proc.p_tasknext;
1796*0Sstevel@tonic-gate 	return (status);
1797*0Sstevel@tonic-gate }
1798*0Sstevel@tonic-gate 
1799*0Sstevel@tonic-gate int
1800*0Sstevel@tonic-gate project_walk_init(mdb_walk_state_t *wsp)
1801*0Sstevel@tonic-gate {
1802*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
1803*0Sstevel@tonic-gate 		if (mdb_readvar(&wsp->walk_addr, "proj0p") == -1) {
1804*0Sstevel@tonic-gate 			mdb_warn("failed to read 'proj0p'");
1805*0Sstevel@tonic-gate 			return (WALK_ERR);
1806*0Sstevel@tonic-gate 		}
1807*0Sstevel@tonic-gate 	}
1808*0Sstevel@tonic-gate 	wsp->walk_data = (void *)wsp->walk_addr;
1809*0Sstevel@tonic-gate 	return (WALK_NEXT);
1810*0Sstevel@tonic-gate }
1811*0Sstevel@tonic-gate 
1812*0Sstevel@tonic-gate int
1813*0Sstevel@tonic-gate project_walk_step(mdb_walk_state_t *wsp)
1814*0Sstevel@tonic-gate {
1815*0Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
1816*0Sstevel@tonic-gate 	kproject_t pj;
1817*0Sstevel@tonic-gate 	int status;
1818*0Sstevel@tonic-gate 
1819*0Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
1820*0Sstevel@tonic-gate 		mdb_warn("failed to read project at %p", addr);
1821*0Sstevel@tonic-gate 		return (WALK_DONE);
1822*0Sstevel@tonic-gate 	}
1823*0Sstevel@tonic-gate 	status = wsp->walk_callback(addr, &pj, wsp->walk_cbdata);
1824*0Sstevel@tonic-gate 	if (status != WALK_NEXT)
1825*0Sstevel@tonic-gate 		return (status);
1826*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)pj.kpj_next;
1827*0Sstevel@tonic-gate 	if ((void *)wsp->walk_addr == wsp->walk_data)
1828*0Sstevel@tonic-gate 		return (WALK_DONE);
1829*0Sstevel@tonic-gate 	return (WALK_NEXT);
1830*0Sstevel@tonic-gate }
1831*0Sstevel@tonic-gate 
1832*0Sstevel@tonic-gate static int
1833*0Sstevel@tonic-gate generic_walk_step(mdb_walk_state_t *wsp)
1834*0Sstevel@tonic-gate {
1835*0Sstevel@tonic-gate 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
1836*0Sstevel@tonic-gate 	    wsp->walk_cbdata));
1837*0Sstevel@tonic-gate }
1838*0Sstevel@tonic-gate 
1839*0Sstevel@tonic-gate struct aw_info {
1840*0Sstevel@tonic-gate 	void *aw_buff;		/* buffer to hold the tree's data structure */
1841*0Sstevel@tonic-gate 	avl_tree_t aw_tree;	/* copy of avl_tree_t being walked */
1842*0Sstevel@tonic-gate };
1843*0Sstevel@tonic-gate 
1844*0Sstevel@tonic-gate /*
1845*0Sstevel@tonic-gate  * common code used to find the addr of the the leftmost child below
1846*0Sstevel@tonic-gate  * an AVL node
1847*0Sstevel@tonic-gate  */
1848*0Sstevel@tonic-gate static uintptr_t
1849*0Sstevel@tonic-gate avl_leftmostchild(uintptr_t addr, void * buff, size_t offset, size_t size)
1850*0Sstevel@tonic-gate {
1851*0Sstevel@tonic-gate 	avl_node_t *node = (avl_node_t *)((uintptr_t)buff + offset);
1852*0Sstevel@tonic-gate 
1853*0Sstevel@tonic-gate 	for (;;) {
1854*0Sstevel@tonic-gate 		addr -= offset;
1855*0Sstevel@tonic-gate 		if (mdb_vread(buff, size, addr) == -1) {
1856*0Sstevel@tonic-gate 			mdb_warn("read of avl_node_t failed: %p", addr);
1857*0Sstevel@tonic-gate 			return ((uintptr_t)-1L);
1858*0Sstevel@tonic-gate 		}
1859*0Sstevel@tonic-gate 		if (node->avl_child[0] == NULL)
1860*0Sstevel@tonic-gate 			break;
1861*0Sstevel@tonic-gate 		addr = (uintptr_t)node->avl_child[0];
1862*0Sstevel@tonic-gate 	}
1863*0Sstevel@tonic-gate 	return (addr);
1864*0Sstevel@tonic-gate }
1865*0Sstevel@tonic-gate 
1866*0Sstevel@tonic-gate /*
1867*0Sstevel@tonic-gate  * initialize a forward walk thru an avl tree.
1868*0Sstevel@tonic-gate  */
1869*0Sstevel@tonic-gate int
1870*0Sstevel@tonic-gate avl_walk_init(mdb_walk_state_t *wsp)
1871*0Sstevel@tonic-gate {
1872*0Sstevel@tonic-gate 	struct aw_info *aw;
1873*0Sstevel@tonic-gate 	avl_tree_t *tree;
1874*0Sstevel@tonic-gate 	uintptr_t addr;
1875*0Sstevel@tonic-gate 
1876*0Sstevel@tonic-gate 	/*
1877*0Sstevel@tonic-gate 	 * allocate the AVL walk data
1878*0Sstevel@tonic-gate 	 */
1879*0Sstevel@tonic-gate 	wsp->walk_data = aw = mdb_zalloc(sizeof (struct aw_info), UM_SLEEP);
1880*0Sstevel@tonic-gate 
1881*0Sstevel@tonic-gate 	/*
1882*0Sstevel@tonic-gate 	 * get an mdb copy of the avl_tree_t being walked
1883*0Sstevel@tonic-gate 	 */
1884*0Sstevel@tonic-gate 	tree = &aw->aw_tree;
1885*0Sstevel@tonic-gate 	if (mdb_vread(tree, sizeof (avl_tree_t), wsp->walk_addr) == -1) {
1886*0Sstevel@tonic-gate 		mdb_warn("read of avl_tree_t failed: %p", wsp->walk_addr);
1887*0Sstevel@tonic-gate 		goto error;
1888*0Sstevel@tonic-gate 	}
1889*0Sstevel@tonic-gate 	if (tree->avl_size < tree->avl_offset + sizeof (avl_node_t)) {
1890*0Sstevel@tonic-gate 		mdb_warn("invalid avl_tree_t at %p, avl_size:%d, avl_offset:%d",
1891*0Sstevel@tonic-gate 		    wsp->walk_addr, tree->avl_size, tree->avl_offset);
1892*0Sstevel@tonic-gate 		goto error;
1893*0Sstevel@tonic-gate 	}
1894*0Sstevel@tonic-gate 
1895*0Sstevel@tonic-gate 	/*
1896*0Sstevel@tonic-gate 	 * allocate a buffer to hold the mdb copy of tree's structs
1897*0Sstevel@tonic-gate 	 * "node" always points at the avl_node_t field inside the struct
1898*0Sstevel@tonic-gate 	 */
1899*0Sstevel@tonic-gate 	aw->aw_buff = mdb_zalloc(tree->avl_size, UM_SLEEP);
1900*0Sstevel@tonic-gate 
1901*0Sstevel@tonic-gate 	/*
1902*0Sstevel@tonic-gate 	 * get the first avl_node_t address, use same algorithm
1903*0Sstevel@tonic-gate 	 * as avl_start() -- leftmost child in tree from root
1904*0Sstevel@tonic-gate 	 */
1905*0Sstevel@tonic-gate 	addr = (uintptr_t)tree->avl_root;
1906*0Sstevel@tonic-gate 	if (addr == NULL) {
1907*0Sstevel@tonic-gate 		wsp->walk_addr = NULL;
1908*0Sstevel@tonic-gate 		return (WALK_NEXT);
1909*0Sstevel@tonic-gate 	}
1910*0Sstevel@tonic-gate 	addr = avl_leftmostchild(addr, aw->aw_buff, tree->avl_offset,
1911*0Sstevel@tonic-gate 	    tree->avl_size);
1912*0Sstevel@tonic-gate 	if (addr == (uintptr_t)-1L)
1913*0Sstevel@tonic-gate 		goto error;
1914*0Sstevel@tonic-gate 
1915*0Sstevel@tonic-gate 	wsp->walk_addr = addr;
1916*0Sstevel@tonic-gate 	return (WALK_NEXT);
1917*0Sstevel@tonic-gate 
1918*0Sstevel@tonic-gate error:
1919*0Sstevel@tonic-gate 	if (aw->aw_buff != NULL)
1920*0Sstevel@tonic-gate 		mdb_free(aw->aw_buff, sizeof (tree->avl_size));
1921*0Sstevel@tonic-gate 	mdb_free(aw, sizeof (struct aw_info));
1922*0Sstevel@tonic-gate 	return (WALK_ERR);
1923*0Sstevel@tonic-gate }
1924*0Sstevel@tonic-gate 
1925*0Sstevel@tonic-gate /*
1926*0Sstevel@tonic-gate  * At each step, visit (callback) the current node, then move to the next
1927*0Sstevel@tonic-gate  * in the AVL tree.  Uses the same algorithm as avl_walk().
1928*0Sstevel@tonic-gate  */
1929*0Sstevel@tonic-gate int
1930*0Sstevel@tonic-gate avl_walk_step(mdb_walk_state_t *wsp)
1931*0Sstevel@tonic-gate {
1932*0Sstevel@tonic-gate 	struct aw_info *aw;
1933*0Sstevel@tonic-gate 	size_t offset;
1934*0Sstevel@tonic-gate 	size_t size;
1935*0Sstevel@tonic-gate 	uintptr_t addr;
1936*0Sstevel@tonic-gate 	avl_node_t *node;
1937*0Sstevel@tonic-gate 	int status;
1938*0Sstevel@tonic-gate 	int was_child;
1939*0Sstevel@tonic-gate 
1940*0Sstevel@tonic-gate 	/*
1941*0Sstevel@tonic-gate 	 * don't walk past the end of the tree!
1942*0Sstevel@tonic-gate 	 */
1943*0Sstevel@tonic-gate 	addr = wsp->walk_addr;
1944*0Sstevel@tonic-gate 	if (addr == NULL)
1945*0Sstevel@tonic-gate 		return (WALK_DONE);
1946*0Sstevel@tonic-gate 
1947*0Sstevel@tonic-gate 	aw = (struct aw_info *)wsp->walk_data;
1948*0Sstevel@tonic-gate 	size = aw->aw_tree.avl_size;
1949*0Sstevel@tonic-gate 	offset = aw->aw_tree.avl_offset;
1950*0Sstevel@tonic-gate 	node = (avl_node_t *)((uintptr_t)aw->aw_buff + offset);
1951*0Sstevel@tonic-gate 
1952*0Sstevel@tonic-gate 	/*
1953*0Sstevel@tonic-gate 	 * must read the current node for the call back to use
1954*0Sstevel@tonic-gate 	 */
1955*0Sstevel@tonic-gate 	if (mdb_vread(aw->aw_buff, size, addr) == -1) {
1956*0Sstevel@tonic-gate 		mdb_warn("read of avl_node_t failed: %p", addr);
1957*0Sstevel@tonic-gate 		return (WALK_ERR);
1958*0Sstevel@tonic-gate 	}
1959*0Sstevel@tonic-gate 
1960*0Sstevel@tonic-gate 	/*
1961*0Sstevel@tonic-gate 	 * do the call back
1962*0Sstevel@tonic-gate 	 */
1963*0Sstevel@tonic-gate 	status = wsp->walk_callback(addr, aw->aw_buff, wsp->walk_cbdata);
1964*0Sstevel@tonic-gate 	if (status != WALK_NEXT)
1965*0Sstevel@tonic-gate 		return (status);
1966*0Sstevel@tonic-gate 
1967*0Sstevel@tonic-gate 	/*
1968*0Sstevel@tonic-gate 	 * move to the next node....
1969*0Sstevel@tonic-gate 	 * note we read in new nodes, so the pointer to the buffer is fixed
1970*0Sstevel@tonic-gate 	 */
1971*0Sstevel@tonic-gate 
1972*0Sstevel@tonic-gate 	/*
1973*0Sstevel@tonic-gate 	 * if the node has a right child then go to it and then all the way
1974*0Sstevel@tonic-gate 	 * thru as many left children as possible
1975*0Sstevel@tonic-gate 	 */
1976*0Sstevel@tonic-gate 	addr = (uintptr_t)node->avl_child[1];
1977*0Sstevel@tonic-gate 	if (addr != NULL) {
1978*0Sstevel@tonic-gate 		addr = avl_leftmostchild(addr, aw->aw_buff, offset, size);
1979*0Sstevel@tonic-gate 		if (addr == (uintptr_t)-1L)
1980*0Sstevel@tonic-gate 			return (WALK_ERR);
1981*0Sstevel@tonic-gate 
1982*0Sstevel@tonic-gate 	/*
1983*0Sstevel@tonic-gate 	 * othewise return to parent nodes, stopping if we ever return from
1984*0Sstevel@tonic-gate 	 * a left child
1985*0Sstevel@tonic-gate 	 */
1986*0Sstevel@tonic-gate 	} else {
1987*0Sstevel@tonic-gate 		for (;;) {
1988*0Sstevel@tonic-gate 			was_child = AVL_XCHILD(node);
1989*0Sstevel@tonic-gate 			addr = (uintptr_t)AVL_XPARENT(node);
1990*0Sstevel@tonic-gate 			if (addr == NULL)
1991*0Sstevel@tonic-gate 				break;
1992*0Sstevel@tonic-gate 			addr -= offset;
1993*0Sstevel@tonic-gate 			if (was_child == 0) /* stop on return from left child */
1994*0Sstevel@tonic-gate 				break;
1995*0Sstevel@tonic-gate 			if (mdb_vread(aw->aw_buff, size, addr) == -1) {
1996*0Sstevel@tonic-gate 				mdb_warn("read of avl_node_t failed: %p", addr);
1997*0Sstevel@tonic-gate 				return (WALK_ERR);
1998*0Sstevel@tonic-gate 			}
1999*0Sstevel@tonic-gate 		}
2000*0Sstevel@tonic-gate 	}
2001*0Sstevel@tonic-gate 
2002*0Sstevel@tonic-gate 	wsp->walk_addr = addr;
2003*0Sstevel@tonic-gate 	return (WALK_NEXT);
2004*0Sstevel@tonic-gate }
2005*0Sstevel@tonic-gate 
2006*0Sstevel@tonic-gate /*
2007*0Sstevel@tonic-gate  * Release the memory allocated for the walk
2008*0Sstevel@tonic-gate  */
2009*0Sstevel@tonic-gate void
2010*0Sstevel@tonic-gate avl_walk_fini(mdb_walk_state_t *wsp)
2011*0Sstevel@tonic-gate {
2012*0Sstevel@tonic-gate 	struct aw_info *aw;
2013*0Sstevel@tonic-gate 
2014*0Sstevel@tonic-gate 	aw = (struct aw_info *)wsp->walk_data;
2015*0Sstevel@tonic-gate 
2016*0Sstevel@tonic-gate 	if (aw == NULL)
2017*0Sstevel@tonic-gate 		return;
2018*0Sstevel@tonic-gate 
2019*0Sstevel@tonic-gate 	if (aw->aw_buff != NULL)
2020*0Sstevel@tonic-gate 		mdb_free(aw->aw_buff, aw->aw_tree.avl_size);
2021*0Sstevel@tonic-gate 
2022*0Sstevel@tonic-gate 	mdb_free(aw, sizeof (struct aw_info));
2023*0Sstevel@tonic-gate }
2024*0Sstevel@tonic-gate 
2025*0Sstevel@tonic-gate 
2026*0Sstevel@tonic-gate int
2027*0Sstevel@tonic-gate seg_walk_init(mdb_walk_state_t *wsp)
2028*0Sstevel@tonic-gate {
2029*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
2030*0Sstevel@tonic-gate 		mdb_warn("seg walk must begin at struct as *\n");
2031*0Sstevel@tonic-gate 		return (WALK_ERR);
2032*0Sstevel@tonic-gate 	}
2033*0Sstevel@tonic-gate 
2034*0Sstevel@tonic-gate 	/*
2035*0Sstevel@tonic-gate 	 * this is really just a wrapper to AVL tree walk
2036*0Sstevel@tonic-gate 	 */
2037*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)&((struct as *)wsp->walk_addr)->a_segtree;
2038*0Sstevel@tonic-gate 	return (avl_walk_init(wsp));
2039*0Sstevel@tonic-gate }
2040*0Sstevel@tonic-gate 
2041*0Sstevel@tonic-gate static int
2042*0Sstevel@tonic-gate cpu_walk_cmp(const void *l, const void *r)
2043*0Sstevel@tonic-gate {
2044*0Sstevel@tonic-gate 	uintptr_t lhs = *((uintptr_t *)l);
2045*0Sstevel@tonic-gate 	uintptr_t rhs = *((uintptr_t *)r);
2046*0Sstevel@tonic-gate 	cpu_t lcpu, rcpu;
2047*0Sstevel@tonic-gate 
2048*0Sstevel@tonic-gate 	(void) mdb_vread(&lcpu, sizeof (lcpu), lhs);
2049*0Sstevel@tonic-gate 	(void) mdb_vread(&rcpu, sizeof (rcpu), rhs);
2050*0Sstevel@tonic-gate 
2051*0Sstevel@tonic-gate 	if (lcpu.cpu_id < rcpu.cpu_id)
2052*0Sstevel@tonic-gate 		return (-1);
2053*0Sstevel@tonic-gate 
2054*0Sstevel@tonic-gate 	if (lcpu.cpu_id > rcpu.cpu_id)
2055*0Sstevel@tonic-gate 		return (1);
2056*0Sstevel@tonic-gate 
2057*0Sstevel@tonic-gate 	return (0);
2058*0Sstevel@tonic-gate }
2059*0Sstevel@tonic-gate 
2060*0Sstevel@tonic-gate typedef struct cpu_walk {
2061*0Sstevel@tonic-gate 	uintptr_t *cw_array;
2062*0Sstevel@tonic-gate 	int cw_ndx;
2063*0Sstevel@tonic-gate } cpu_walk_t;
2064*0Sstevel@tonic-gate 
2065*0Sstevel@tonic-gate int
2066*0Sstevel@tonic-gate cpu_walk_init(mdb_walk_state_t *wsp)
2067*0Sstevel@tonic-gate {
2068*0Sstevel@tonic-gate 	cpu_walk_t *cw;
2069*0Sstevel@tonic-gate 	int max_ncpus, i = 0;
2070*0Sstevel@tonic-gate 	uintptr_t current, first;
2071*0Sstevel@tonic-gate 	cpu_t cpu, panic_cpu;
2072*0Sstevel@tonic-gate 	uintptr_t panicstr, addr;
2073*0Sstevel@tonic-gate 	GElf_Sym sym;
2074*0Sstevel@tonic-gate 
2075*0Sstevel@tonic-gate 	cw = mdb_zalloc(sizeof (cpu_walk_t), UM_SLEEP | UM_GC);
2076*0Sstevel@tonic-gate 
2077*0Sstevel@tonic-gate 	if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
2078*0Sstevel@tonic-gate 		mdb_warn("failed to read 'max_ncpus'");
2079*0Sstevel@tonic-gate 		return (WALK_ERR);
2080*0Sstevel@tonic-gate 	}
2081*0Sstevel@tonic-gate 
2082*0Sstevel@tonic-gate 	if (mdb_readvar(&panicstr, "panicstr") == -1) {
2083*0Sstevel@tonic-gate 		mdb_warn("failed to read 'panicstr'");
2084*0Sstevel@tonic-gate 		return (WALK_ERR);
2085*0Sstevel@tonic-gate 	}
2086*0Sstevel@tonic-gate 
2087*0Sstevel@tonic-gate 	if (panicstr != NULL) {
2088*0Sstevel@tonic-gate 		if (mdb_lookup_by_name("panic_cpu", &sym) == -1) {
2089*0Sstevel@tonic-gate 			mdb_warn("failed to find 'panic_cpu'");
2090*0Sstevel@tonic-gate 			return (WALK_ERR);
2091*0Sstevel@tonic-gate 		}
2092*0Sstevel@tonic-gate 
2093*0Sstevel@tonic-gate 		addr = (uintptr_t)sym.st_value;
2094*0Sstevel@tonic-gate 
2095*0Sstevel@tonic-gate 		if (mdb_vread(&panic_cpu, sizeof (cpu_t), addr) == -1) {
2096*0Sstevel@tonic-gate 			mdb_warn("failed to read 'panic_cpu'");
2097*0Sstevel@tonic-gate 			return (WALK_ERR);
2098*0Sstevel@tonic-gate 		}
2099*0Sstevel@tonic-gate 	}
2100*0Sstevel@tonic-gate 
2101*0Sstevel@tonic-gate 	/*
2102*0Sstevel@tonic-gate 	 * Unfortunately, there is no platform-independent way to walk
2103*0Sstevel@tonic-gate 	 * CPUs in ID order.  We therefore loop through in cpu_next order,
2104*0Sstevel@tonic-gate 	 * building an array of CPU pointers which will subsequently be
2105*0Sstevel@tonic-gate 	 * sorted.
2106*0Sstevel@tonic-gate 	 */
2107*0Sstevel@tonic-gate 	cw->cw_array =
2108*0Sstevel@tonic-gate 	    mdb_zalloc((max_ncpus + 1) * sizeof (uintptr_t), UM_SLEEP | UM_GC);
2109*0Sstevel@tonic-gate 
2110*0Sstevel@tonic-gate 	if (mdb_readvar(&first, "cpu_list") == -1) {
2111*0Sstevel@tonic-gate 		mdb_warn("failed to read 'cpu_list'");
2112*0Sstevel@tonic-gate 		return (WALK_ERR);
2113*0Sstevel@tonic-gate 	}
2114*0Sstevel@tonic-gate 
2115*0Sstevel@tonic-gate 	current = first;
2116*0Sstevel@tonic-gate 	do {
2117*0Sstevel@tonic-gate 		if (mdb_vread(&cpu, sizeof (cpu), current) == -1) {
2118*0Sstevel@tonic-gate 			mdb_warn("failed to read cpu at %p", current);
2119*0Sstevel@tonic-gate 			return (WALK_ERR);
2120*0Sstevel@tonic-gate 		}
2121*0Sstevel@tonic-gate 
2122*0Sstevel@tonic-gate 		if (panicstr != NULL && panic_cpu.cpu_id == cpu.cpu_id) {
2123*0Sstevel@tonic-gate 			cw->cw_array[i++] = addr;
2124*0Sstevel@tonic-gate 		} else {
2125*0Sstevel@tonic-gate 			cw->cw_array[i++] = current;
2126*0Sstevel@tonic-gate 		}
2127*0Sstevel@tonic-gate 	} while ((current = (uintptr_t)cpu.cpu_next) != first);
2128*0Sstevel@tonic-gate 
2129*0Sstevel@tonic-gate 	qsort(cw->cw_array, i, sizeof (uintptr_t), cpu_walk_cmp);
2130*0Sstevel@tonic-gate 	wsp->walk_data = cw;
2131*0Sstevel@tonic-gate 
2132*0Sstevel@tonic-gate 	return (WALK_NEXT);
2133*0Sstevel@tonic-gate }
2134*0Sstevel@tonic-gate 
2135*0Sstevel@tonic-gate int
2136*0Sstevel@tonic-gate cpu_walk_step(mdb_walk_state_t *wsp)
2137*0Sstevel@tonic-gate {
2138*0Sstevel@tonic-gate 	cpu_walk_t *cw = wsp->walk_data;
2139*0Sstevel@tonic-gate 	cpu_t cpu;
2140*0Sstevel@tonic-gate 	uintptr_t addr = cw->cw_array[cw->cw_ndx++];
2141*0Sstevel@tonic-gate 
2142*0Sstevel@tonic-gate 	if (addr == NULL)
2143*0Sstevel@tonic-gate 		return (WALK_DONE);
2144*0Sstevel@tonic-gate 
2145*0Sstevel@tonic-gate 	if (mdb_vread(&cpu, sizeof (cpu), addr) == -1) {
2146*0Sstevel@tonic-gate 		mdb_warn("failed to read cpu at %p", addr);
2147*0Sstevel@tonic-gate 		return (WALK_DONE);
2148*0Sstevel@tonic-gate 	}
2149*0Sstevel@tonic-gate 
2150*0Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &cpu, wsp->walk_cbdata));
2151*0Sstevel@tonic-gate }
2152*0Sstevel@tonic-gate 
2153*0Sstevel@tonic-gate typedef struct cpuinfo_data {
2154*0Sstevel@tonic-gate 	intptr_t cid_cpu;
2155*0Sstevel@tonic-gate 	uintptr_t cid_lbolt;
2156*0Sstevel@tonic-gate 	uintptr_t **cid_ithr;
2157*0Sstevel@tonic-gate 	char	cid_print_head;
2158*0Sstevel@tonic-gate 	char	cid_print_thr;
2159*0Sstevel@tonic-gate 	char	cid_print_ithr;
2160*0Sstevel@tonic-gate 	char	cid_print_flags;
2161*0Sstevel@tonic-gate } cpuinfo_data_t;
2162*0Sstevel@tonic-gate 
2163*0Sstevel@tonic-gate int
2164*0Sstevel@tonic-gate cpuinfo_walk_ithread(uintptr_t addr, const kthread_t *thr, cpuinfo_data_t *cid)
2165*0Sstevel@tonic-gate {
2166*0Sstevel@tonic-gate 	cpu_t c;
2167*0Sstevel@tonic-gate 	int id;
2168*0Sstevel@tonic-gate 	uint8_t pil;
2169*0Sstevel@tonic-gate 
2170*0Sstevel@tonic-gate 	if (!(thr->t_flag & T_INTR_THREAD) || thr->t_state == TS_FREE)
2171*0Sstevel@tonic-gate 		return (WALK_NEXT);
2172*0Sstevel@tonic-gate 
2173*0Sstevel@tonic-gate 	if (thr->t_bound_cpu == NULL) {
2174*0Sstevel@tonic-gate 		mdb_warn("thr %p is intr thread w/out a CPU\n", addr);
2175*0Sstevel@tonic-gate 		return (WALK_NEXT);
2176*0Sstevel@tonic-gate 	}
2177*0Sstevel@tonic-gate 
2178*0Sstevel@tonic-gate 	(void) mdb_vread(&c, sizeof (c), (uintptr_t)thr->t_bound_cpu);
2179*0Sstevel@tonic-gate 
2180*0Sstevel@tonic-gate 	if ((id = c.cpu_id) >= NCPU) {
2181*0Sstevel@tonic-gate 		mdb_warn("CPU %p has id (%d) greater than NCPU (%d)\n",
2182*0Sstevel@tonic-gate 		    thr->t_bound_cpu, id, NCPU);
2183*0Sstevel@tonic-gate 		return (WALK_NEXT);
2184*0Sstevel@tonic-gate 	}
2185*0Sstevel@tonic-gate 
2186*0Sstevel@tonic-gate 	if ((pil = thr->t_pil) >= NINTR) {
2187*0Sstevel@tonic-gate 		mdb_warn("thread %p has pil (%d) greater than %d\n",
2188*0Sstevel@tonic-gate 		    addr, pil, NINTR);
2189*0Sstevel@tonic-gate 		return (WALK_NEXT);
2190*0Sstevel@tonic-gate 	}
2191*0Sstevel@tonic-gate 
2192*0Sstevel@tonic-gate 	if (cid->cid_ithr[id][pil] != NULL) {
2193*0Sstevel@tonic-gate 		mdb_warn("CPU %d has multiple threads at pil %d (at least "
2194*0Sstevel@tonic-gate 		    "%p and %p)\n", id, pil, addr, cid->cid_ithr[id][pil]);
2195*0Sstevel@tonic-gate 		return (WALK_NEXT);
2196*0Sstevel@tonic-gate 	}
2197*0Sstevel@tonic-gate 
2198*0Sstevel@tonic-gate 	cid->cid_ithr[id][pil] = addr;
2199*0Sstevel@tonic-gate 
2200*0Sstevel@tonic-gate 	return (WALK_NEXT);
2201*0Sstevel@tonic-gate }
2202*0Sstevel@tonic-gate 
2203*0Sstevel@tonic-gate #define	CPUINFO_IDWIDTH		3
2204*0Sstevel@tonic-gate #define	CPUINFO_FLAGWIDTH	9
2205*0Sstevel@tonic-gate 
2206*0Sstevel@tonic-gate #ifdef _LP64
2207*0Sstevel@tonic-gate #define	CPUINFO_CPUWIDTH	11
2208*0Sstevel@tonic-gate #define	CPUINFO_TWIDTH		11
2209*0Sstevel@tonic-gate #else
2210*0Sstevel@tonic-gate #define	CPUINFO_CPUWIDTH	8
2211*0Sstevel@tonic-gate #define	CPUINFO_TWIDTH		8
2212*0Sstevel@tonic-gate #endif
2213*0Sstevel@tonic-gate 
2214*0Sstevel@tonic-gate #define	CPUINFO_THRDELT		(CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 9)
2215*0Sstevel@tonic-gate #define	CPUINFO_FLAGDELT	(CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 4)
2216*0Sstevel@tonic-gate #define	CPUINFO_ITHRDELT	4
2217*0Sstevel@tonic-gate 
2218*0Sstevel@tonic-gate #define	CPUINFO_INDENT	mdb_printf("%*s", CPUINFO_THRDELT, \
2219*0Sstevel@tonic-gate     flagline < nflaglines ? flagbuf[flagline++] : "")
2220*0Sstevel@tonic-gate 
2221*0Sstevel@tonic-gate int
2222*0Sstevel@tonic-gate cpuinfo_walk_cpu(uintptr_t addr, const cpu_t *cpu, cpuinfo_data_t *cid)
2223*0Sstevel@tonic-gate {
2224*0Sstevel@tonic-gate 	kthread_t t;
2225*0Sstevel@tonic-gate 	disp_t disp;
2226*0Sstevel@tonic-gate 	proc_t p;
2227*0Sstevel@tonic-gate 	uintptr_t pinned;
2228*0Sstevel@tonic-gate 	char **flagbuf;
2229*0Sstevel@tonic-gate 	int nflaglines = 0, flagline = 0, bspl, rval = WALK_NEXT;
2230*0Sstevel@tonic-gate 
2231*0Sstevel@tonic-gate 	const char *flags[] = {
2232*0Sstevel@tonic-gate 	    "RUNNING", "READY", "QUIESCED", "EXISTS",
2233*0Sstevel@tonic-gate 	    "ENABLE", "OFFLINE", "POWEROFF", "FROZEN",
2234*0Sstevel@tonic-gate 	    "SPARE", "FAULTED", NULL
2235*0Sstevel@tonic-gate 	};
2236*0Sstevel@tonic-gate 
2237*0Sstevel@tonic-gate 	if (cid->cid_cpu != -1) {
2238*0Sstevel@tonic-gate 		if (addr != cid->cid_cpu && cpu->cpu_id != cid->cid_cpu)
2239*0Sstevel@tonic-gate 			return (WALK_NEXT);
2240*0Sstevel@tonic-gate 
2241*0Sstevel@tonic-gate 		/*
2242*0Sstevel@tonic-gate 		 * Set cid_cpu to -1 to indicate that we found a matching CPU.
2243*0Sstevel@tonic-gate 		 */
2244*0Sstevel@tonic-gate 		cid->cid_cpu = -1;
2245*0Sstevel@tonic-gate 		rval = WALK_DONE;
2246*0Sstevel@tonic-gate 	}
2247*0Sstevel@tonic-gate 
2248*0Sstevel@tonic-gate 	if (cid->cid_print_head) {
2249*0Sstevel@tonic-gate 		mdb_printf("%3s %-*s %3s %4s %4s %3s %4s %5s %-6s %-*s %s\n",
2250*0Sstevel@tonic-gate 		    "ID", CPUINFO_CPUWIDTH, "ADDR", "FLG", "NRUN", "BSPL",
2251*0Sstevel@tonic-gate 		    "PRI", "RNRN", "KRNRN", "SWITCH", CPUINFO_TWIDTH, "THREAD",
2252*0Sstevel@tonic-gate 		    "PROC");
2253*0Sstevel@tonic-gate 		cid->cid_print_head = FALSE;
2254*0Sstevel@tonic-gate 	}
2255*0Sstevel@tonic-gate 
2256*0Sstevel@tonic-gate 	bspl = cpu->cpu_base_spl;
2257*0Sstevel@tonic-gate 
2258*0Sstevel@tonic-gate 	if (mdb_vread(&disp, sizeof (disp_t), (uintptr_t)cpu->cpu_disp) == -1) {
2259*0Sstevel@tonic-gate 		mdb_warn("failed to read disp_t at %p", cpu->cpu_disp);
2260*0Sstevel@tonic-gate 		return (WALK_ERR);
2261*0Sstevel@tonic-gate 	}
2262*0Sstevel@tonic-gate 
2263*0Sstevel@tonic-gate 	mdb_printf("%3d %0*p %3x %4d %4d ",
2264*0Sstevel@tonic-gate 	    cpu->cpu_id, CPUINFO_CPUWIDTH, addr, cpu->cpu_flags,
2265*0Sstevel@tonic-gate 	    disp.disp_nrunnable, bspl);
2266*0Sstevel@tonic-gate 
2267*0Sstevel@tonic-gate 	if (mdb_vread(&t, sizeof (t), (uintptr_t)cpu->cpu_thread) != -1) {
2268*0Sstevel@tonic-gate 		mdb_printf("%3d ", t.t_pri);
2269*0Sstevel@tonic-gate 	} else {
2270*0Sstevel@tonic-gate 		mdb_printf("%3s ", "-");
2271*0Sstevel@tonic-gate 	}
2272*0Sstevel@tonic-gate 
2273*0Sstevel@tonic-gate 	mdb_printf("%4s %5s ", cpu->cpu_runrun ? "yes" : "no",
2274*0Sstevel@tonic-gate 	    cpu->cpu_kprunrun ? "yes" : "no");
2275*0Sstevel@tonic-gate 
2276*0Sstevel@tonic-gate 	if (cpu->cpu_last_swtch) {
2277*0Sstevel@tonic-gate 		clock_t lbolt;
2278*0Sstevel@tonic-gate 
2279*0Sstevel@tonic-gate 		if (mdb_vread(&lbolt, sizeof (lbolt), cid->cid_lbolt) == -1) {
2280*0Sstevel@tonic-gate 			mdb_warn("failed to read lbolt at %p", cid->cid_lbolt);
2281*0Sstevel@tonic-gate 			return (WALK_ERR);
2282*0Sstevel@tonic-gate 		}
2283*0Sstevel@tonic-gate 		mdb_printf("t-%-4d ", lbolt - cpu->cpu_last_swtch);
2284*0Sstevel@tonic-gate 	} else {
2285*0Sstevel@tonic-gate 		mdb_printf("%-6s ", "-");
2286*0Sstevel@tonic-gate 	}
2287*0Sstevel@tonic-gate 
2288*0Sstevel@tonic-gate 	mdb_printf("%0*p", CPUINFO_TWIDTH, cpu->cpu_thread);
2289*0Sstevel@tonic-gate 
2290*0Sstevel@tonic-gate 	if (cpu->cpu_thread == cpu->cpu_idle_thread)
2291*0Sstevel@tonic-gate 		mdb_printf(" (idle)\n");
2292*0Sstevel@tonic-gate 	else if (cpu->cpu_thread == NULL)
2293*0Sstevel@tonic-gate 		mdb_printf(" -\n");
2294*0Sstevel@tonic-gate 	else {
2295*0Sstevel@tonic-gate 		if (mdb_vread(&p, sizeof (p), (uintptr_t)t.t_procp) != -1) {
2296*0Sstevel@tonic-gate 			mdb_printf(" %s\n", p.p_user.u_comm);
2297*0Sstevel@tonic-gate 		} else {
2298*0Sstevel@tonic-gate 			mdb_printf(" ?\n");
2299*0Sstevel@tonic-gate 		}
2300*0Sstevel@tonic-gate 	}
2301*0Sstevel@tonic-gate 
2302*0Sstevel@tonic-gate 	flagbuf = mdb_zalloc(sizeof (flags), UM_SLEEP | UM_GC);
2303*0Sstevel@tonic-gate 
2304*0Sstevel@tonic-gate 	if (cid->cid_print_flags) {
2305*0Sstevel@tonic-gate 		int first = 1, i, j, k;
2306*0Sstevel@tonic-gate 		char *s;
2307*0Sstevel@tonic-gate 
2308*0Sstevel@tonic-gate 		cid->cid_print_head = TRUE;
2309*0Sstevel@tonic-gate 
2310*0Sstevel@tonic-gate 		for (i = 1, j = 0; flags[j] != NULL; i <<= 1, j++) {
2311*0Sstevel@tonic-gate 			if (!(cpu->cpu_flags & i))
2312*0Sstevel@tonic-gate 				continue;
2313*0Sstevel@tonic-gate 
2314*0Sstevel@tonic-gate 			if (first) {
2315*0Sstevel@tonic-gate 				s = mdb_alloc(CPUINFO_THRDELT + 1,
2316*0Sstevel@tonic-gate 				    UM_GC | UM_SLEEP);
2317*0Sstevel@tonic-gate 
2318*0Sstevel@tonic-gate 				(void) mdb_snprintf(s, CPUINFO_THRDELT + 1,
2319*0Sstevel@tonic-gate 				    "%*s|%*s", CPUINFO_FLAGDELT, "",
2320*0Sstevel@tonic-gate 				    CPUINFO_THRDELT - 1 - CPUINFO_FLAGDELT, "");
2321*0Sstevel@tonic-gate 				flagbuf[nflaglines++] = s;
2322*0Sstevel@tonic-gate 			}
2323*0Sstevel@tonic-gate 
2324*0Sstevel@tonic-gate 			s = mdb_alloc(CPUINFO_THRDELT + 1, UM_GC | UM_SLEEP);
2325*0Sstevel@tonic-gate 			(void) mdb_snprintf(s, CPUINFO_THRDELT + 1, "%*s%*s %s",
2326*0Sstevel@tonic-gate 			    CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH -
2327*0Sstevel@tonic-gate 			    CPUINFO_FLAGWIDTH, "", CPUINFO_FLAGWIDTH, flags[j],
2328*0Sstevel@tonic-gate 			    first ? "<--+" : "");
2329*0Sstevel@tonic-gate 
2330*0Sstevel@tonic-gate 			for (k = strlen(s); k < CPUINFO_THRDELT; k++)
2331*0Sstevel@tonic-gate 				s[k] = ' ';
2332*0Sstevel@tonic-gate 			s[k] = '\0';
2333*0Sstevel@tonic-gate 
2334*0Sstevel@tonic-gate 			flagbuf[nflaglines++] = s;
2335*0Sstevel@tonic-gate 			first = 0;
2336*0Sstevel@tonic-gate 		}
2337*0Sstevel@tonic-gate 	}
2338*0Sstevel@tonic-gate 
2339*0Sstevel@tonic-gate 	if (cid->cid_print_ithr) {
2340*0Sstevel@tonic-gate 		int i, found_one = FALSE;
2341*0Sstevel@tonic-gate 		int print_thr = disp.disp_nrunnable && cid->cid_print_thr;
2342*0Sstevel@tonic-gate 
2343*0Sstevel@tonic-gate 		for (i = NINTR - 1; i >= 0; i--) {
2344*0Sstevel@tonic-gate 			uintptr_t iaddr = cid->cid_ithr[cpu->cpu_id][i];
2345*0Sstevel@tonic-gate 
2346*0Sstevel@tonic-gate 			if (iaddr == NULL)
2347*0Sstevel@tonic-gate 				continue;
2348*0Sstevel@tonic-gate 
2349*0Sstevel@tonic-gate 			if (!found_one) {
2350*0Sstevel@tonic-gate 				found_one = TRUE;
2351*0Sstevel@tonic-gate 
2352*0Sstevel@tonic-gate 				CPUINFO_INDENT;
2353*0Sstevel@tonic-gate 				mdb_printf("%c%*s|\n", print_thr ? '|' : ' ',
2354*0Sstevel@tonic-gate 				    CPUINFO_ITHRDELT, "");
2355*0Sstevel@tonic-gate 
2356*0Sstevel@tonic-gate 				CPUINFO_INDENT;
2357*0Sstevel@tonic-gate 				mdb_printf("%c%*s+--> %3s %s\n",
2358*0Sstevel@tonic-gate 				    print_thr ? '|' : ' ', CPUINFO_ITHRDELT,
2359*0Sstevel@tonic-gate 				    "", "PIL", "THREAD");
2360*0Sstevel@tonic-gate 			}
2361*0Sstevel@tonic-gate 
2362*0Sstevel@tonic-gate 			if (mdb_vread(&t, sizeof (t), iaddr) == -1) {
2363*0Sstevel@tonic-gate 				mdb_warn("failed to read kthread_t at %p",
2364*0Sstevel@tonic-gate 				    iaddr);
2365*0Sstevel@tonic-gate 				return (WALK_ERR);
2366*0Sstevel@tonic-gate 			}
2367*0Sstevel@tonic-gate 
2368*0Sstevel@tonic-gate 			CPUINFO_INDENT;
2369*0Sstevel@tonic-gate 			mdb_printf("%c%*s     %3d %0*p\n",
2370*0Sstevel@tonic-gate 			    print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "",
2371*0Sstevel@tonic-gate 			    t.t_pil, CPUINFO_TWIDTH, iaddr);
2372*0Sstevel@tonic-gate 
2373*0Sstevel@tonic-gate 			pinned = (uintptr_t)t.t_intr;
2374*0Sstevel@tonic-gate 		}
2375*0Sstevel@tonic-gate 
2376*0Sstevel@tonic-gate 		if (found_one && pinned != NULL) {
2377*0Sstevel@tonic-gate 			cid->cid_print_head = TRUE;
2378*0Sstevel@tonic-gate 			(void) strcpy(p.p_user.u_comm, "?");
2379*0Sstevel@tonic-gate 
2380*0Sstevel@tonic-gate 			if (mdb_vread(&t, sizeof (t),
2381*0Sstevel@tonic-gate 			    (uintptr_t)pinned) == -1) {
2382*0Sstevel@tonic-gate 				mdb_warn("failed to read kthread_t at %p",
2383*0Sstevel@tonic-gate 				    pinned);
2384*0Sstevel@tonic-gate 				return (WALK_ERR);
2385*0Sstevel@tonic-gate 			}
2386*0Sstevel@tonic-gate 			if (mdb_vread(&p, sizeof (p),
2387*0Sstevel@tonic-gate 			    (uintptr_t)t.t_procp) == -1) {
2388*0Sstevel@tonic-gate 				mdb_warn("failed to read proc_t at %p",
2389*0Sstevel@tonic-gate 				    t.t_procp);
2390*0Sstevel@tonic-gate 				return (WALK_ERR);
2391*0Sstevel@tonic-gate 			}
2392*0Sstevel@tonic-gate 
2393*0Sstevel@tonic-gate 			CPUINFO_INDENT;
2394*0Sstevel@tonic-gate 			mdb_printf("%c%*s     %3s %0*p %s\n",
2395*0Sstevel@tonic-gate 			    print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", "-",
2396*0Sstevel@tonic-gate 			    CPUINFO_TWIDTH, pinned,
2397*0Sstevel@tonic-gate 			    pinned == (uintptr_t)cpu->cpu_idle_thread ?
2398*0Sstevel@tonic-gate 			    "(idle)" : p.p_user.u_comm);
2399*0Sstevel@tonic-gate 		}
2400*0Sstevel@tonic-gate 	}
2401*0Sstevel@tonic-gate 
2402*0Sstevel@tonic-gate 	if (disp.disp_nrunnable && cid->cid_print_thr) {
2403*0Sstevel@tonic-gate 		dispq_t *dq;
2404*0Sstevel@tonic-gate 
2405*0Sstevel@tonic-gate 		int i, npri = disp.disp_npri;
2406*0Sstevel@tonic-gate 
2407*0Sstevel@tonic-gate 		dq = mdb_alloc(sizeof (dispq_t) * npri, UM_SLEEP | UM_GC);
2408*0Sstevel@tonic-gate 
2409*0Sstevel@tonic-gate 		if (mdb_vread(dq, sizeof (dispq_t) * npri,
2410*0Sstevel@tonic-gate 		    (uintptr_t)disp.disp_q) == -1) {
2411*0Sstevel@tonic-gate 			mdb_warn("failed to read dispq_t at %p", disp.disp_q);
2412*0Sstevel@tonic-gate 			return (WALK_ERR);
2413*0Sstevel@tonic-gate 		}
2414*0Sstevel@tonic-gate 
2415*0Sstevel@tonic-gate 		CPUINFO_INDENT;
2416*0Sstevel@tonic-gate 		mdb_printf("|\n");
2417*0Sstevel@tonic-gate 
2418*0Sstevel@tonic-gate 		CPUINFO_INDENT;
2419*0Sstevel@tonic-gate 		mdb_printf("+-->  %3s %-*s %s\n", "PRI",
2420*0Sstevel@tonic-gate 		    CPUINFO_TWIDTH, "THREAD", "PROC");
2421*0Sstevel@tonic-gate 
2422*0Sstevel@tonic-gate 		for (i = npri - 1; i >= 0; i--) {
2423*0Sstevel@tonic-gate 			uintptr_t taddr = (uintptr_t)dq[i].dq_first;
2424*0Sstevel@tonic-gate 
2425*0Sstevel@tonic-gate 			while (taddr != NULL) {
2426*0Sstevel@tonic-gate 				if (mdb_vread(&t, sizeof (t), taddr) == -1) {
2427*0Sstevel@tonic-gate 					mdb_warn("failed to read kthread_t "
2428*0Sstevel@tonic-gate 					    "at %p", taddr);
2429*0Sstevel@tonic-gate 					return (WALK_ERR);
2430*0Sstevel@tonic-gate 				}
2431*0Sstevel@tonic-gate 				if (mdb_vread(&p, sizeof (p),
2432*0Sstevel@tonic-gate 				    (uintptr_t)t.t_procp) == -1) {
2433*0Sstevel@tonic-gate 					mdb_warn("failed to read proc_t at %p",
2434*0Sstevel@tonic-gate 					    t.t_procp);
2435*0Sstevel@tonic-gate 					return (WALK_ERR);
2436*0Sstevel@tonic-gate 				}
2437*0Sstevel@tonic-gate 
2438*0Sstevel@tonic-gate 				CPUINFO_INDENT;
2439*0Sstevel@tonic-gate 				mdb_printf("      %3d %0*p %s\n", t.t_pri,
2440*0Sstevel@tonic-gate 				    CPUINFO_TWIDTH, taddr, p.p_user.u_comm);
2441*0Sstevel@tonic-gate 
2442*0Sstevel@tonic-gate 				taddr = (uintptr_t)t.t_link;
2443*0Sstevel@tonic-gate 			}
2444*0Sstevel@tonic-gate 		}
2445*0Sstevel@tonic-gate 		cid->cid_print_head = TRUE;
2446*0Sstevel@tonic-gate 	}
2447*0Sstevel@tonic-gate 
2448*0Sstevel@tonic-gate 	while (flagline < nflaglines)
2449*0Sstevel@tonic-gate 		mdb_printf("%s\n", flagbuf[flagline++]);
2450*0Sstevel@tonic-gate 
2451*0Sstevel@tonic-gate 	if (cid->cid_print_head)
2452*0Sstevel@tonic-gate 		mdb_printf("\n");
2453*0Sstevel@tonic-gate 
2454*0Sstevel@tonic-gate 	return (rval);
2455*0Sstevel@tonic-gate }
2456*0Sstevel@tonic-gate 
2457*0Sstevel@tonic-gate int
2458*0Sstevel@tonic-gate cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2459*0Sstevel@tonic-gate {
2460*0Sstevel@tonic-gate 	uint_t verbose = FALSE;
2461*0Sstevel@tonic-gate 	cpuinfo_data_t cid;
2462*0Sstevel@tonic-gate 	GElf_Sym sym;
2463*0Sstevel@tonic-gate 	clock_t lbolt;
2464*0Sstevel@tonic-gate 
2465*0Sstevel@tonic-gate 	cid.cid_print_ithr = FALSE;
2466*0Sstevel@tonic-gate 	cid.cid_print_thr = FALSE;
2467*0Sstevel@tonic-gate 	cid.cid_print_flags = FALSE;
2468*0Sstevel@tonic-gate 	cid.cid_print_head = DCMD_HDRSPEC(flags) ? TRUE : FALSE;
2469*0Sstevel@tonic-gate 	cid.cid_cpu = -1;
2470*0Sstevel@tonic-gate 
2471*0Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
2472*0Sstevel@tonic-gate 		cid.cid_cpu = addr;
2473*0Sstevel@tonic-gate 
2474*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
2475*0Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc)
2476*0Sstevel@tonic-gate 		return (DCMD_USAGE);
2477*0Sstevel@tonic-gate 
2478*0Sstevel@tonic-gate 	if (verbose) {
2479*0Sstevel@tonic-gate 		cid.cid_print_ithr = TRUE;
2480*0Sstevel@tonic-gate 		cid.cid_print_thr = TRUE;
2481*0Sstevel@tonic-gate 		cid.cid_print_flags = TRUE;
2482*0Sstevel@tonic-gate 		cid.cid_print_head = TRUE;
2483*0Sstevel@tonic-gate 	}
2484*0Sstevel@tonic-gate 
2485*0Sstevel@tonic-gate 	if (cid.cid_print_ithr) {
2486*0Sstevel@tonic-gate 		int i;
2487*0Sstevel@tonic-gate 
2488*0Sstevel@tonic-gate 		cid.cid_ithr = mdb_alloc(sizeof (uintptr_t **)
2489*0Sstevel@tonic-gate 		    * NCPU, UM_SLEEP | UM_GC);
2490*0Sstevel@tonic-gate 
2491*0Sstevel@tonic-gate 		for (i = 0; i < NCPU; i++)
2492*0Sstevel@tonic-gate 			cid.cid_ithr[i] = mdb_zalloc(sizeof (uintptr_t *) *
2493*0Sstevel@tonic-gate 			    NINTR, UM_SLEEP | UM_GC);
2494*0Sstevel@tonic-gate 
2495*0Sstevel@tonic-gate 		if (mdb_walk("thread", (mdb_walk_cb_t)cpuinfo_walk_ithread,
2496*0Sstevel@tonic-gate 		    &cid) == -1) {
2497*0Sstevel@tonic-gate 			mdb_warn("couldn't walk thread");
2498*0Sstevel@tonic-gate 			return (DCMD_ERR);
2499*0Sstevel@tonic-gate 		}
2500*0Sstevel@tonic-gate 	}
2501*0Sstevel@tonic-gate 
2502*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("panic_lbolt", &sym) == -1) {
2503*0Sstevel@tonic-gate 		mdb_warn("failed to find panic_lbolt");
2504*0Sstevel@tonic-gate 		return (DCMD_ERR);
2505*0Sstevel@tonic-gate 	}
2506*0Sstevel@tonic-gate 
2507*0Sstevel@tonic-gate 	cid.cid_lbolt = (uintptr_t)sym.st_value;
2508*0Sstevel@tonic-gate 
2509*0Sstevel@tonic-gate 	if (mdb_vread(&lbolt, sizeof (lbolt), cid.cid_lbolt) == -1) {
2510*0Sstevel@tonic-gate 		mdb_warn("failed to read panic_lbolt");
2511*0Sstevel@tonic-gate 		return (DCMD_ERR);
2512*0Sstevel@tonic-gate 	}
2513*0Sstevel@tonic-gate 
2514*0Sstevel@tonic-gate 	if (lbolt == 0) {
2515*0Sstevel@tonic-gate 		if (mdb_lookup_by_name("lbolt", &sym) == -1) {
2516*0Sstevel@tonic-gate 			mdb_warn("failed to find lbolt");
2517*0Sstevel@tonic-gate 			return (DCMD_ERR);
2518*0Sstevel@tonic-gate 		}
2519*0Sstevel@tonic-gate 		cid.cid_lbolt = (uintptr_t)sym.st_value;
2520*0Sstevel@tonic-gate 	}
2521*0Sstevel@tonic-gate 
2522*0Sstevel@tonic-gate 	if (mdb_walk("cpu", (mdb_walk_cb_t)cpuinfo_walk_cpu, &cid) == -1) {
2523*0Sstevel@tonic-gate 		mdb_warn("can't walk cpus");
2524*0Sstevel@tonic-gate 		return (DCMD_ERR);
2525*0Sstevel@tonic-gate 	}
2526*0Sstevel@tonic-gate 
2527*0Sstevel@tonic-gate 	if (cid.cid_cpu != -1) {
2528*0Sstevel@tonic-gate 		/*
2529*0Sstevel@tonic-gate 		 * We didn't find this CPU when we walked through the CPUs
2530*0Sstevel@tonic-gate 		 * (i.e. the address specified doesn't show up in the "cpu"
2531*0Sstevel@tonic-gate 		 * walk).  However, the specified address may still correspond
2532*0Sstevel@tonic-gate 		 * to a valid cpu_t (for example, if the specified address is
2533*0Sstevel@tonic-gate 		 * the actual panicking cpu_t and not the cached panic_cpu).
2534*0Sstevel@tonic-gate 		 * Point is:  even if we didn't find it, we still want to try
2535*0Sstevel@tonic-gate 		 * to print the specified address as a cpu_t.
2536*0Sstevel@tonic-gate 		 */
2537*0Sstevel@tonic-gate 		cpu_t cpu;
2538*0Sstevel@tonic-gate 
2539*0Sstevel@tonic-gate 		if (mdb_vread(&cpu, sizeof (cpu), cid.cid_cpu) == -1) {
2540*0Sstevel@tonic-gate 			mdb_warn("%p is neither a valid CPU ID nor a "
2541*0Sstevel@tonic-gate 			    "valid cpu_t address\n", cid.cid_cpu);
2542*0Sstevel@tonic-gate 			return (DCMD_ERR);
2543*0Sstevel@tonic-gate 		}
2544*0Sstevel@tonic-gate 
2545*0Sstevel@tonic-gate 		(void) cpuinfo_walk_cpu(cid.cid_cpu, &cpu, &cid);
2546*0Sstevel@tonic-gate 	}
2547*0Sstevel@tonic-gate 
2548*0Sstevel@tonic-gate 	return (DCMD_OK);
2549*0Sstevel@tonic-gate }
2550*0Sstevel@tonic-gate 
2551*0Sstevel@tonic-gate /*ARGSUSED*/
2552*0Sstevel@tonic-gate int
2553*0Sstevel@tonic-gate flipone(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2554*0Sstevel@tonic-gate {
2555*0Sstevel@tonic-gate 	int i;
2556*0Sstevel@tonic-gate 
2557*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
2558*0Sstevel@tonic-gate 		return (DCMD_USAGE);
2559*0Sstevel@tonic-gate 
2560*0Sstevel@tonic-gate 	for (i = 0; i < sizeof (addr) * NBBY; i++)
2561*0Sstevel@tonic-gate 		mdb_printf("%p\n", addr ^ (1UL << i));
2562*0Sstevel@tonic-gate 
2563*0Sstevel@tonic-gate 	return (DCMD_OK);
2564*0Sstevel@tonic-gate }
2565*0Sstevel@tonic-gate 
2566*0Sstevel@tonic-gate /*
2567*0Sstevel@tonic-gate  * Grumble, grumble.
2568*0Sstevel@tonic-gate  */
2569*0Sstevel@tonic-gate #define	SMAP_HASHFUNC(vp, off)	\
2570*0Sstevel@tonic-gate 	((((uintptr_t)(vp) >> 6) + ((uintptr_t)(vp) >> 3) + \
2571*0Sstevel@tonic-gate 	((off) >> MAXBSHIFT)) & smd_hashmsk)
2572*0Sstevel@tonic-gate 
2573*0Sstevel@tonic-gate int
2574*0Sstevel@tonic-gate vnode2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2575*0Sstevel@tonic-gate {
2576*0Sstevel@tonic-gate 	long smd_hashmsk;
2577*0Sstevel@tonic-gate 	int hash;
2578*0Sstevel@tonic-gate 	uintptr_t offset = 0;
2579*0Sstevel@tonic-gate 	struct smap smp;
2580*0Sstevel@tonic-gate 	uintptr_t saddr, kaddr;
2581*0Sstevel@tonic-gate 	uintptr_t smd_hash, smd_smap;
2582*0Sstevel@tonic-gate 	struct seg seg;
2583*0Sstevel@tonic-gate 
2584*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
2585*0Sstevel@tonic-gate 		return (DCMD_USAGE);
2586*0Sstevel@tonic-gate 
2587*0Sstevel@tonic-gate 	if (mdb_readvar(&smd_hashmsk, "smd_hashmsk") == -1) {
2588*0Sstevel@tonic-gate 		mdb_warn("failed to read smd_hashmsk");
2589*0Sstevel@tonic-gate 		return (DCMD_ERR);
2590*0Sstevel@tonic-gate 	}
2591*0Sstevel@tonic-gate 
2592*0Sstevel@tonic-gate 	if (mdb_readvar(&smd_hash, "smd_hash") == -1) {
2593*0Sstevel@tonic-gate 		mdb_warn("failed to read smd_hash");
2594*0Sstevel@tonic-gate 		return (DCMD_ERR);
2595*0Sstevel@tonic-gate 	}
2596*0Sstevel@tonic-gate 
2597*0Sstevel@tonic-gate 	if (mdb_readvar(&smd_smap, "smd_smap") == -1) {
2598*0Sstevel@tonic-gate 		mdb_warn("failed to read smd_hash");
2599*0Sstevel@tonic-gate 		return (DCMD_ERR);
2600*0Sstevel@tonic-gate 	}
2601*0Sstevel@tonic-gate 
2602*0Sstevel@tonic-gate 	if (mdb_readvar(&kaddr, "segkmap") == -1) {
2603*0Sstevel@tonic-gate 		mdb_warn("failed to read segkmap");
2604*0Sstevel@tonic-gate 		return (DCMD_ERR);
2605*0Sstevel@tonic-gate 	}
2606*0Sstevel@tonic-gate 
2607*0Sstevel@tonic-gate 	if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) {
2608*0Sstevel@tonic-gate 		mdb_warn("failed to read segkmap at %p", kaddr);
2609*0Sstevel@tonic-gate 		return (DCMD_ERR);
2610*0Sstevel@tonic-gate 	}
2611*0Sstevel@tonic-gate 
2612*0Sstevel@tonic-gate 	if (argc != 0) {
2613*0Sstevel@tonic-gate 		const mdb_arg_t *arg = &argv[0];
2614*0Sstevel@tonic-gate 
2615*0Sstevel@tonic-gate 		if (arg->a_type == MDB_TYPE_IMMEDIATE)
2616*0Sstevel@tonic-gate 			offset = arg->a_un.a_val;
2617*0Sstevel@tonic-gate 		else
2618*0Sstevel@tonic-gate 			offset = (uintptr_t)mdb_strtoull(arg->a_un.a_str);
2619*0Sstevel@tonic-gate 	}
2620*0Sstevel@tonic-gate 
2621*0Sstevel@tonic-gate 	hash = SMAP_HASHFUNC(addr, offset);
2622*0Sstevel@tonic-gate 
2623*0Sstevel@tonic-gate 	if (mdb_vread(&saddr, sizeof (saddr),
2624*0Sstevel@tonic-gate 	    smd_hash + hash * sizeof (uintptr_t)) == -1) {
2625*0Sstevel@tonic-gate 		mdb_warn("couldn't read smap at %p",
2626*0Sstevel@tonic-gate 		    smd_hash + hash * sizeof (uintptr_t));
2627*0Sstevel@tonic-gate 		return (DCMD_ERR);
2628*0Sstevel@tonic-gate 	}
2629*0Sstevel@tonic-gate 
2630*0Sstevel@tonic-gate 	do {
2631*0Sstevel@tonic-gate 		if (mdb_vread(&smp, sizeof (smp), saddr) == -1) {
2632*0Sstevel@tonic-gate 			mdb_warn("couldn't read smap at %p", saddr);
2633*0Sstevel@tonic-gate 			return (DCMD_ERR);
2634*0Sstevel@tonic-gate 		}
2635*0Sstevel@tonic-gate 
2636*0Sstevel@tonic-gate 		if ((uintptr_t)smp.sm_vp == addr && smp.sm_off == offset) {
2637*0Sstevel@tonic-gate 			mdb_printf("vnode %p, offs %p is smap %p, vaddr %p\n",
2638*0Sstevel@tonic-gate 			    addr, offset, saddr, ((saddr - smd_smap) /
2639*0Sstevel@tonic-gate 			    sizeof (smp)) * MAXBSIZE + seg.s_base);
2640*0Sstevel@tonic-gate 			return (DCMD_OK);
2641*0Sstevel@tonic-gate 		}
2642*0Sstevel@tonic-gate 
2643*0Sstevel@tonic-gate 		saddr = (uintptr_t)smp.sm_hash;
2644*0Sstevel@tonic-gate 	} while (saddr != NULL);
2645*0Sstevel@tonic-gate 
2646*0Sstevel@tonic-gate 	mdb_printf("no smap for vnode %p, offs %p\n", addr, offset);
2647*0Sstevel@tonic-gate 	return (DCMD_OK);
2648*0Sstevel@tonic-gate }
2649*0Sstevel@tonic-gate 
2650*0Sstevel@tonic-gate /*ARGSUSED*/
2651*0Sstevel@tonic-gate int
2652*0Sstevel@tonic-gate addr2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2653*0Sstevel@tonic-gate {
2654*0Sstevel@tonic-gate 	uintptr_t kaddr;
2655*0Sstevel@tonic-gate 	struct seg seg;
2656*0Sstevel@tonic-gate 	struct segmap_data sd;
2657*0Sstevel@tonic-gate 
2658*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
2659*0Sstevel@tonic-gate 		return (DCMD_USAGE);
2660*0Sstevel@tonic-gate 
2661*0Sstevel@tonic-gate 	if (mdb_readvar(&kaddr, "segkmap") == -1) {
2662*0Sstevel@tonic-gate 		mdb_warn("failed to read segkmap");
2663*0Sstevel@tonic-gate 		return (DCMD_ERR);
2664*0Sstevel@tonic-gate 	}
2665*0Sstevel@tonic-gate 
2666*0Sstevel@tonic-gate 	if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) {
2667*0Sstevel@tonic-gate 		mdb_warn("failed to read segkmap at %p", kaddr);
2668*0Sstevel@tonic-gate 		return (DCMD_ERR);
2669*0Sstevel@tonic-gate 	}
2670*0Sstevel@tonic-gate 
2671*0Sstevel@tonic-gate 	if (mdb_vread(&sd, sizeof (sd), (uintptr_t)seg.s_data) == -1) {
2672*0Sstevel@tonic-gate 		mdb_warn("failed to read segmap_data at %p", seg.s_data);
2673*0Sstevel@tonic-gate 		return (DCMD_ERR);
2674*0Sstevel@tonic-gate 	}
2675*0Sstevel@tonic-gate 
2676*0Sstevel@tonic-gate 	mdb_printf("%p is smap %p\n", addr,
2677*0Sstevel@tonic-gate 	    ((addr - (uintptr_t)seg.s_base) >> MAXBSHIFT) *
2678*0Sstevel@tonic-gate 	    sizeof (struct smap) + (uintptr_t)sd.smd_sm);
2679*0Sstevel@tonic-gate 
2680*0Sstevel@tonic-gate 	return (DCMD_OK);
2681*0Sstevel@tonic-gate }
2682*0Sstevel@tonic-gate 
2683*0Sstevel@tonic-gate int
2684*0Sstevel@tonic-gate as2proc_walk(uintptr_t addr, const proc_t *p, struct as **asp)
2685*0Sstevel@tonic-gate {
2686*0Sstevel@tonic-gate 	if (p->p_as == *asp)
2687*0Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
2688*0Sstevel@tonic-gate 	return (WALK_NEXT);
2689*0Sstevel@tonic-gate }
2690*0Sstevel@tonic-gate 
2691*0Sstevel@tonic-gate /*ARGSUSED*/
2692*0Sstevel@tonic-gate int
2693*0Sstevel@tonic-gate as2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2694*0Sstevel@tonic-gate {
2695*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC) || argc != 0)
2696*0Sstevel@tonic-gate 		return (DCMD_USAGE);
2697*0Sstevel@tonic-gate 
2698*0Sstevel@tonic-gate 	if (mdb_walk("proc", (mdb_walk_cb_t)as2proc_walk, &addr) == -1) {
2699*0Sstevel@tonic-gate 		mdb_warn("failed to walk proc");
2700*0Sstevel@tonic-gate 		return (DCMD_ERR);
2701*0Sstevel@tonic-gate 	}
2702*0Sstevel@tonic-gate 
2703*0Sstevel@tonic-gate 	return (DCMD_OK);
2704*0Sstevel@tonic-gate }
2705*0Sstevel@tonic-gate 
2706*0Sstevel@tonic-gate /*ARGSUSED*/
2707*0Sstevel@tonic-gate int
2708*0Sstevel@tonic-gate ptree_walk(uintptr_t addr, const proc_t *p, void *ignored)
2709*0Sstevel@tonic-gate {
2710*0Sstevel@tonic-gate 	proc_t parent;
2711*0Sstevel@tonic-gate 	int ident = 0;
2712*0Sstevel@tonic-gate 	uintptr_t paddr;
2713*0Sstevel@tonic-gate 
2714*0Sstevel@tonic-gate 	for (paddr = (uintptr_t)p->p_parent; paddr != NULL; ident += 5) {
2715*0Sstevel@tonic-gate 		mdb_vread(&parent, sizeof (parent), paddr);
2716*0Sstevel@tonic-gate 		paddr = (uintptr_t)parent.p_parent;
2717*0Sstevel@tonic-gate 	}
2718*0Sstevel@tonic-gate 
2719*0Sstevel@tonic-gate 	mdb_inc_indent(ident);
2720*0Sstevel@tonic-gate 	mdb_printf("%0?p  %s\n", addr, p->p_user.u_comm);
2721*0Sstevel@tonic-gate 	mdb_dec_indent(ident);
2722*0Sstevel@tonic-gate 
2723*0Sstevel@tonic-gate 	return (WALK_NEXT);
2724*0Sstevel@tonic-gate }
2725*0Sstevel@tonic-gate 
2726*0Sstevel@tonic-gate void
2727*0Sstevel@tonic-gate ptree_ancestors(uintptr_t addr, uintptr_t start)
2728*0Sstevel@tonic-gate {
2729*0Sstevel@tonic-gate 	proc_t p;
2730*0Sstevel@tonic-gate 
2731*0Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (p), addr) == -1) {
2732*0Sstevel@tonic-gate 		mdb_warn("couldn't read ancestor at %p", addr);
2733*0Sstevel@tonic-gate 		return;
2734*0Sstevel@tonic-gate 	}
2735*0Sstevel@tonic-gate 
2736*0Sstevel@tonic-gate 	if (p.p_parent != NULL)
2737*0Sstevel@tonic-gate 		ptree_ancestors((uintptr_t)p.p_parent, start);
2738*0Sstevel@tonic-gate 
2739*0Sstevel@tonic-gate 	if (addr != start)
2740*0Sstevel@tonic-gate 		(void) ptree_walk(addr, &p, NULL);
2741*0Sstevel@tonic-gate }
2742*0Sstevel@tonic-gate 
2743*0Sstevel@tonic-gate /*ARGSUSED*/
2744*0Sstevel@tonic-gate int
2745*0Sstevel@tonic-gate ptree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2746*0Sstevel@tonic-gate {
2747*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
2748*0Sstevel@tonic-gate 		addr = NULL;
2749*0Sstevel@tonic-gate 	else
2750*0Sstevel@tonic-gate 		ptree_ancestors(addr, addr);
2751*0Sstevel@tonic-gate 
2752*0Sstevel@tonic-gate 	if (mdb_pwalk("proc", (mdb_walk_cb_t)ptree_walk, NULL, addr) == -1) {
2753*0Sstevel@tonic-gate 		mdb_warn("couldn't walk 'proc'");
2754*0Sstevel@tonic-gate 		return (DCMD_ERR);
2755*0Sstevel@tonic-gate 	}
2756*0Sstevel@tonic-gate 
2757*0Sstevel@tonic-gate 	return (DCMD_OK);
2758*0Sstevel@tonic-gate }
2759*0Sstevel@tonic-gate 
2760*0Sstevel@tonic-gate /*ARGSUSED*/
2761*0Sstevel@tonic-gate static int
2762*0Sstevel@tonic-gate fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2763*0Sstevel@tonic-gate {
2764*0Sstevel@tonic-gate 	int fdnum;
2765*0Sstevel@tonic-gate 	const mdb_arg_t *argp = &argv[0];
2766*0Sstevel@tonic-gate 	proc_t p;
2767*0Sstevel@tonic-gate 	uf_entry_t uf;
2768*0Sstevel@tonic-gate 
2769*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
2770*0Sstevel@tonic-gate 		mdb_warn("fd doesn't give global information\n");
2771*0Sstevel@tonic-gate 		return (DCMD_ERR);
2772*0Sstevel@tonic-gate 	}
2773*0Sstevel@tonic-gate 	if (argc != 1)
2774*0Sstevel@tonic-gate 		return (DCMD_USAGE);
2775*0Sstevel@tonic-gate 
2776*0Sstevel@tonic-gate 	if (argp->a_type == MDB_TYPE_IMMEDIATE)
2777*0Sstevel@tonic-gate 		fdnum = argp->a_un.a_val;
2778*0Sstevel@tonic-gate 	else
2779*0Sstevel@tonic-gate 		fdnum = mdb_strtoull(argp->a_un.a_str);
2780*0Sstevel@tonic-gate 
2781*0Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (struct proc), addr) == -1) {
2782*0Sstevel@tonic-gate 		mdb_warn("couldn't read proc_t at %p", addr);
2783*0Sstevel@tonic-gate 		return (DCMD_ERR);
2784*0Sstevel@tonic-gate 	}
2785*0Sstevel@tonic-gate 	if (fdnum > p.p_user.u_finfo.fi_nfiles) {
2786*0Sstevel@tonic-gate 		mdb_warn("process %p only has %d files open.\n",
2787*0Sstevel@tonic-gate 		    addr, p.p_user.u_finfo.fi_nfiles);
2788*0Sstevel@tonic-gate 		return (DCMD_ERR);
2789*0Sstevel@tonic-gate 	}
2790*0Sstevel@tonic-gate 	if (mdb_vread(&uf, sizeof (uf_entry_t),
2791*0Sstevel@tonic-gate 	    (uintptr_t)&p.p_user.u_finfo.fi_list[fdnum]) == -1) {
2792*0Sstevel@tonic-gate 		mdb_warn("couldn't read uf_entry_t at %p",
2793*0Sstevel@tonic-gate 		    &p.p_user.u_finfo.fi_list[fdnum]);
2794*0Sstevel@tonic-gate 		return (DCMD_ERR);
2795*0Sstevel@tonic-gate 	}
2796*0Sstevel@tonic-gate 
2797*0Sstevel@tonic-gate 	mdb_printf("%p\n", uf.uf_file);
2798*0Sstevel@tonic-gate 	return (DCMD_OK);
2799*0Sstevel@tonic-gate }
2800*0Sstevel@tonic-gate 
2801*0Sstevel@tonic-gate /*ARGSUSED*/
2802*0Sstevel@tonic-gate static int
2803*0Sstevel@tonic-gate pid2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2804*0Sstevel@tonic-gate {
2805*0Sstevel@tonic-gate 	pid_t pid = (pid_t)addr;
2806*0Sstevel@tonic-gate 
2807*0Sstevel@tonic-gate 	if (argc != 0)
2808*0Sstevel@tonic-gate 		return (DCMD_USAGE);
2809*0Sstevel@tonic-gate 
2810*0Sstevel@tonic-gate 	if ((addr = mdb_pid2proc(pid, NULL)) == NULL) {
2811*0Sstevel@tonic-gate 		mdb_warn("PID 0t%d not found\n", pid);
2812*0Sstevel@tonic-gate 		return (DCMD_ERR);
2813*0Sstevel@tonic-gate 	}
2814*0Sstevel@tonic-gate 
2815*0Sstevel@tonic-gate 	mdb_printf("%p\n", addr);
2816*0Sstevel@tonic-gate 	return (DCMD_OK);
2817*0Sstevel@tonic-gate }
2818*0Sstevel@tonic-gate 
2819*0Sstevel@tonic-gate static char *sysfile_cmd[] = {
2820*0Sstevel@tonic-gate 	"exclude:",
2821*0Sstevel@tonic-gate 	"include:",
2822*0Sstevel@tonic-gate 	"forceload:",
2823*0Sstevel@tonic-gate 	"rootdev:",
2824*0Sstevel@tonic-gate 	"rootfs:",
2825*0Sstevel@tonic-gate 	"swapdev:",
2826*0Sstevel@tonic-gate 	"swapfs:",
2827*0Sstevel@tonic-gate 	"moddir:",
2828*0Sstevel@tonic-gate 	"set",
2829*0Sstevel@tonic-gate 	"unknown",
2830*0Sstevel@tonic-gate };
2831*0Sstevel@tonic-gate 
2832*0Sstevel@tonic-gate static char *sysfile_ops[] = { "", "=", "&", "|" };
2833*0Sstevel@tonic-gate 
2834*0Sstevel@tonic-gate /*ARGSUSED*/
2835*0Sstevel@tonic-gate static int
2836*0Sstevel@tonic-gate sysfile_vmem_seg(uintptr_t addr, const vmem_seg_t *vsp, void **target)
2837*0Sstevel@tonic-gate {
2838*0Sstevel@tonic-gate 	if (vsp->vs_type == VMEM_ALLOC && (void *)vsp->vs_start == *target) {
2839*0Sstevel@tonic-gate 		*target = NULL;
2840*0Sstevel@tonic-gate 		return (WALK_DONE);
2841*0Sstevel@tonic-gate 	}
2842*0Sstevel@tonic-gate 	return (WALK_NEXT);
2843*0Sstevel@tonic-gate }
2844*0Sstevel@tonic-gate 
2845*0Sstevel@tonic-gate /*ARGSUSED*/
2846*0Sstevel@tonic-gate static int
2847*0Sstevel@tonic-gate sysfile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2848*0Sstevel@tonic-gate {
2849*0Sstevel@tonic-gate 	struct sysparam *sysp, sys;
2850*0Sstevel@tonic-gate 	char var[256];
2851*0Sstevel@tonic-gate 	char modname[256];
2852*0Sstevel@tonic-gate 	char val[256];
2853*0Sstevel@tonic-gate 	char strval[256];
2854*0Sstevel@tonic-gate 	vmem_t *mod_sysfile_arena;
2855*0Sstevel@tonic-gate 	void *straddr;
2856*0Sstevel@tonic-gate 
2857*0Sstevel@tonic-gate 	if (mdb_readvar(&sysp, "sysparam_hd") == -1) {
2858*0Sstevel@tonic-gate 		mdb_warn("failed to read sysparam_hd");
2859*0Sstevel@tonic-gate 		return (DCMD_ERR);
2860*0Sstevel@tonic-gate 	}
2861*0Sstevel@tonic-gate 
2862*0Sstevel@tonic-gate 	if (mdb_readvar(&mod_sysfile_arena, "mod_sysfile_arena") == -1) {
2863*0Sstevel@tonic-gate 		mdb_warn("failed to read mod_sysfile_arena");
2864*0Sstevel@tonic-gate 		return (DCMD_ERR);
2865*0Sstevel@tonic-gate 	}
2866*0Sstevel@tonic-gate 
2867*0Sstevel@tonic-gate 	while (sysp != NULL) {
2868*0Sstevel@tonic-gate 		var[0] = '\0';
2869*0Sstevel@tonic-gate 		val[0] = '\0';
2870*0Sstevel@tonic-gate 		modname[0] = '\0';
2871*0Sstevel@tonic-gate 		if (mdb_vread(&sys, sizeof (sys), (uintptr_t)sysp) == -1) {
2872*0Sstevel@tonic-gate 			mdb_warn("couldn't read sysparam %p", sysp);
2873*0Sstevel@tonic-gate 			return (DCMD_ERR);
2874*0Sstevel@tonic-gate 		}
2875*0Sstevel@tonic-gate 		if (sys.sys_modnam != NULL &&
2876*0Sstevel@tonic-gate 		    mdb_readstr(modname, 256,
2877*0Sstevel@tonic-gate 		    (uintptr_t)sys.sys_modnam) == -1) {
2878*0Sstevel@tonic-gate 			mdb_warn("couldn't read modname in %p", sysp);
2879*0Sstevel@tonic-gate 			return (DCMD_ERR);
2880*0Sstevel@tonic-gate 		}
2881*0Sstevel@tonic-gate 		if (sys.sys_ptr != NULL &&
2882*0Sstevel@tonic-gate 		    mdb_readstr(var, 256, (uintptr_t)sys.sys_ptr) == -1) {
2883*0Sstevel@tonic-gate 			mdb_warn("couldn't read ptr in %p", sysp);
2884*0Sstevel@tonic-gate 			return (DCMD_ERR);
2885*0Sstevel@tonic-gate 		}
2886*0Sstevel@tonic-gate 		if (sys.sys_op != SETOP_NONE) {
2887*0Sstevel@tonic-gate 			/*
2888*0Sstevel@tonic-gate 			 * Is this an int or a string?  We determine this
2889*0Sstevel@tonic-gate 			 * by checking whether straddr is contained in
2890*0Sstevel@tonic-gate 			 * mod_sysfile_arena.  If so, the walker will set
2891*0Sstevel@tonic-gate 			 * straddr to NULL.
2892*0Sstevel@tonic-gate 			 */
2893*0Sstevel@tonic-gate 			straddr = (void *)(uintptr_t)sys.sys_info;
2894*0Sstevel@tonic-gate 			if (sys.sys_op == SETOP_ASSIGN &&
2895*0Sstevel@tonic-gate 			    sys.sys_info != 0 &&
2896*0Sstevel@tonic-gate 			    mdb_pwalk("vmem_seg",
2897*0Sstevel@tonic-gate 			    (mdb_walk_cb_t)sysfile_vmem_seg, &straddr,
2898*0Sstevel@tonic-gate 			    (uintptr_t)mod_sysfile_arena) == 0 &&
2899*0Sstevel@tonic-gate 			    straddr == NULL &&
2900*0Sstevel@tonic-gate 			    mdb_readstr(strval, 256,
2901*0Sstevel@tonic-gate 			    (uintptr_t)sys.sys_info) != -1) {
2902*0Sstevel@tonic-gate 				(void) mdb_snprintf(val, sizeof (val), "\"%s\"",
2903*0Sstevel@tonic-gate 				    strval);
2904*0Sstevel@tonic-gate 			} else {
2905*0Sstevel@tonic-gate 				(void) mdb_snprintf(val, sizeof (val),
2906*0Sstevel@tonic-gate 				    "0x%llx [0t%llu]", sys.sys_info,
2907*0Sstevel@tonic-gate 				    sys.sys_info);
2908*0Sstevel@tonic-gate 			}
2909*0Sstevel@tonic-gate 		}
2910*0Sstevel@tonic-gate 		mdb_printf("%s %s%s%s%s%s\n", sysfile_cmd[sys.sys_type],
2911*0Sstevel@tonic-gate 		    modname, modname[0] == '\0' ? "" : ":",
2912*0Sstevel@tonic-gate 		    var, sysfile_ops[sys.sys_op], val);
2913*0Sstevel@tonic-gate 
2914*0Sstevel@tonic-gate 		sysp = sys.sys_next;
2915*0Sstevel@tonic-gate 	}
2916*0Sstevel@tonic-gate 
2917*0Sstevel@tonic-gate 	return (DCMD_OK);
2918*0Sstevel@tonic-gate }
2919*0Sstevel@tonic-gate 
2920*0Sstevel@tonic-gate /*
2921*0Sstevel@tonic-gate  * Dump a taskq_ent_t given its address.
2922*0Sstevel@tonic-gate  */
2923*0Sstevel@tonic-gate /*ARGSUSED*/
2924*0Sstevel@tonic-gate int
2925*0Sstevel@tonic-gate taskq_ent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2926*0Sstevel@tonic-gate {
2927*0Sstevel@tonic-gate 	taskq_ent_t	taskq_ent;
2928*0Sstevel@tonic-gate 	GElf_Sym	sym;
2929*0Sstevel@tonic-gate 	char		buf[MDB_SYM_NAMLEN+1];
2930*0Sstevel@tonic-gate 
2931*0Sstevel@tonic-gate 
2932*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
2933*0Sstevel@tonic-gate 		mdb_warn("expected explicit taskq_ent_t address before ::\n");
2934*0Sstevel@tonic-gate 		return (DCMD_USAGE);
2935*0Sstevel@tonic-gate 	}
2936*0Sstevel@tonic-gate 
2937*0Sstevel@tonic-gate 	if (mdb_vread(&taskq_ent, sizeof (taskq_ent_t), addr) == -1) {
2938*0Sstevel@tonic-gate 		mdb_warn("failed to read taskq_ent_t at %p", addr);
2939*0Sstevel@tonic-gate 		return (DCMD_ERR);
2940*0Sstevel@tonic-gate 	}
2941*0Sstevel@tonic-gate 
2942*0Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
2943*0Sstevel@tonic-gate 		mdb_printf("%<u>%-?s    %-?s    %-s%</u>\n",
2944*0Sstevel@tonic-gate 		"ENTRY", "ARG", "FUNCTION");
2945*0Sstevel@tonic-gate 	}
2946*0Sstevel@tonic-gate 
2947*0Sstevel@tonic-gate 	if (mdb_lookup_by_addr((uintptr_t)taskq_ent.tqent_func, MDB_SYM_EXACT,
2948*0Sstevel@tonic-gate 	    buf, sizeof (buf), &sym) == -1) {
2949*0Sstevel@tonic-gate 		(void) strcpy(buf, "????");
2950*0Sstevel@tonic-gate 	}
2951*0Sstevel@tonic-gate 
2952*0Sstevel@tonic-gate 	mdb_printf("%-?p    %-?p    %s\n", addr, taskq_ent.tqent_arg, buf);
2953*0Sstevel@tonic-gate 
2954*0Sstevel@tonic-gate 	return (DCMD_OK);
2955*0Sstevel@tonic-gate }
2956*0Sstevel@tonic-gate 
2957*0Sstevel@tonic-gate /*
2958*0Sstevel@tonic-gate  * Given the address of the (taskq_t) task queue head, walk the queue listing
2959*0Sstevel@tonic-gate  * the address of every taskq_ent_t.
2960*0Sstevel@tonic-gate  */
2961*0Sstevel@tonic-gate int
2962*0Sstevel@tonic-gate taskq_walk_init(mdb_walk_state_t *wsp)
2963*0Sstevel@tonic-gate {
2964*0Sstevel@tonic-gate 	taskq_t	tq_head;
2965*0Sstevel@tonic-gate 
2966*0Sstevel@tonic-gate 
2967*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
2968*0Sstevel@tonic-gate 		mdb_warn("start address required\n");
2969*0Sstevel@tonic-gate 		return (WALK_ERR);
2970*0Sstevel@tonic-gate 	}
2971*0Sstevel@tonic-gate 
2972*0Sstevel@tonic-gate 
2973*0Sstevel@tonic-gate 	/*
2974*0Sstevel@tonic-gate 	 * Save the address of the list head entry.  This terminates the list.
2975*0Sstevel@tonic-gate 	 */
2976*0Sstevel@tonic-gate 	wsp->walk_data = (void *)
2977*0Sstevel@tonic-gate 	    ((size_t)wsp->walk_addr + offsetof(taskq_t, tq_task));
2978*0Sstevel@tonic-gate 
2979*0Sstevel@tonic-gate 
2980*0Sstevel@tonic-gate 	/*
2981*0Sstevel@tonic-gate 	 * Read in taskq head, set walk_addr to point to first taskq_ent_t.
2982*0Sstevel@tonic-gate 	 */
2983*0Sstevel@tonic-gate 	if (mdb_vread((void *)&tq_head, sizeof (taskq_t), wsp->walk_addr) ==
2984*0Sstevel@tonic-gate 	    -1) {
2985*0Sstevel@tonic-gate 		mdb_warn("failed to read taskq list head at %p",
2986*0Sstevel@tonic-gate 		    wsp->walk_addr);
2987*0Sstevel@tonic-gate 	}
2988*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)tq_head.tq_task.tqent_next;
2989*0Sstevel@tonic-gate 
2990*0Sstevel@tonic-gate 
2991*0Sstevel@tonic-gate 	/*
2992*0Sstevel@tonic-gate 	 * Check for null list (next=head)
2993*0Sstevel@tonic-gate 	 */
2994*0Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data) {
2995*0Sstevel@tonic-gate 		return (WALK_DONE);
2996*0Sstevel@tonic-gate 	}
2997*0Sstevel@tonic-gate 
2998*0Sstevel@tonic-gate 	return (WALK_NEXT);
2999*0Sstevel@tonic-gate }
3000*0Sstevel@tonic-gate 
3001*0Sstevel@tonic-gate 
3002*0Sstevel@tonic-gate int
3003*0Sstevel@tonic-gate taskq_walk_step(mdb_walk_state_t *wsp)
3004*0Sstevel@tonic-gate {
3005*0Sstevel@tonic-gate 	taskq_ent_t	tq_ent;
3006*0Sstevel@tonic-gate 	int		status;
3007*0Sstevel@tonic-gate 
3008*0Sstevel@tonic-gate 
3009*0Sstevel@tonic-gate 	if (mdb_vread((void *)&tq_ent, sizeof (taskq_ent_t), wsp->walk_addr) ==
3010*0Sstevel@tonic-gate 	    -1) {
3011*0Sstevel@tonic-gate 		mdb_warn("failed to read taskq_ent_t at %p", wsp->walk_addr);
3012*0Sstevel@tonic-gate 		return (DCMD_ERR);
3013*0Sstevel@tonic-gate 	}
3014*0Sstevel@tonic-gate 
3015*0Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, (void *)&tq_ent,
3016*0Sstevel@tonic-gate 	    wsp->walk_cbdata);
3017*0Sstevel@tonic-gate 
3018*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)tq_ent.tqent_next;
3019*0Sstevel@tonic-gate 
3020*0Sstevel@tonic-gate 
3021*0Sstevel@tonic-gate 	/* Check if we're at the last element (next=head) */
3022*0Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data) {
3023*0Sstevel@tonic-gate 		return (WALK_DONE);
3024*0Sstevel@tonic-gate 	}
3025*0Sstevel@tonic-gate 
3026*0Sstevel@tonic-gate 	return (status);
3027*0Sstevel@tonic-gate }
3028*0Sstevel@tonic-gate 
3029*0Sstevel@tonic-gate int
3030*0Sstevel@tonic-gate didmatch(uintptr_t addr, const kthread_t *thr, kt_did_t *didp)
3031*0Sstevel@tonic-gate {
3032*0Sstevel@tonic-gate 
3033*0Sstevel@tonic-gate 	if (*didp == thr->t_did) {
3034*0Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
3035*0Sstevel@tonic-gate 		return (WALK_DONE);
3036*0Sstevel@tonic-gate 	} else
3037*0Sstevel@tonic-gate 		return (WALK_NEXT);
3038*0Sstevel@tonic-gate }
3039*0Sstevel@tonic-gate 
3040*0Sstevel@tonic-gate /*ARGSUSED*/
3041*0Sstevel@tonic-gate int
3042*0Sstevel@tonic-gate did2thread(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3043*0Sstevel@tonic-gate {
3044*0Sstevel@tonic-gate 	const mdb_arg_t *argp = &argv[0];
3045*0Sstevel@tonic-gate 	kt_did_t	did;
3046*0Sstevel@tonic-gate 
3047*0Sstevel@tonic-gate 	if (argc != 1)
3048*0Sstevel@tonic-gate 		return (DCMD_USAGE);
3049*0Sstevel@tonic-gate 
3050*0Sstevel@tonic-gate 	did = (kt_did_t)mdb_strtoull(argp->a_un.a_str);
3051*0Sstevel@tonic-gate 
3052*0Sstevel@tonic-gate 	if (mdb_walk("thread", (mdb_walk_cb_t)didmatch, (void *)&did) == -1) {
3053*0Sstevel@tonic-gate 		mdb_warn("failed to walk thread");
3054*0Sstevel@tonic-gate 		return (DCMD_ERR);
3055*0Sstevel@tonic-gate 
3056*0Sstevel@tonic-gate 	}
3057*0Sstevel@tonic-gate 	return (DCMD_OK);
3058*0Sstevel@tonic-gate 
3059*0Sstevel@tonic-gate }
3060*0Sstevel@tonic-gate 
3061*0Sstevel@tonic-gate static int
3062*0Sstevel@tonic-gate errorq_walk_init(mdb_walk_state_t *wsp)
3063*0Sstevel@tonic-gate {
3064*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL &&
3065*0Sstevel@tonic-gate 	    mdb_readvar(&wsp->walk_addr, "errorq_list") == -1) {
3066*0Sstevel@tonic-gate 		mdb_warn("failed to read errorq_list");
3067*0Sstevel@tonic-gate 		return (WALK_ERR);
3068*0Sstevel@tonic-gate 	}
3069*0Sstevel@tonic-gate 
3070*0Sstevel@tonic-gate 	return (WALK_NEXT);
3071*0Sstevel@tonic-gate }
3072*0Sstevel@tonic-gate 
3073*0Sstevel@tonic-gate static int
3074*0Sstevel@tonic-gate errorq_walk_step(mdb_walk_state_t *wsp)
3075*0Sstevel@tonic-gate {
3076*0Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
3077*0Sstevel@tonic-gate 	errorq_t eq;
3078*0Sstevel@tonic-gate 
3079*0Sstevel@tonic-gate 	if (addr == NULL)
3080*0Sstevel@tonic-gate 		return (WALK_DONE);
3081*0Sstevel@tonic-gate 
3082*0Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), addr) == -1) {
3083*0Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", addr);
3084*0Sstevel@tonic-gate 		return (WALK_ERR);
3085*0Sstevel@tonic-gate 	}
3086*0Sstevel@tonic-gate 
3087*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)eq.eq_next;
3088*0Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &eq, wsp->walk_cbdata));
3089*0Sstevel@tonic-gate }
3090*0Sstevel@tonic-gate 
3091*0Sstevel@tonic-gate typedef struct eqd_walk_data {
3092*0Sstevel@tonic-gate 	uintptr_t *eqd_stack;
3093*0Sstevel@tonic-gate 	void *eqd_buf;
3094*0Sstevel@tonic-gate 	ulong_t eqd_qpos;
3095*0Sstevel@tonic-gate 	ulong_t eqd_qlen;
3096*0Sstevel@tonic-gate 	size_t eqd_size;
3097*0Sstevel@tonic-gate } eqd_walk_data_t;
3098*0Sstevel@tonic-gate 
3099*0Sstevel@tonic-gate /*
3100*0Sstevel@tonic-gate  * In order to walk the list of pending error queue elements, we push the
3101*0Sstevel@tonic-gate  * addresses of the corresponding data buffers in to the eqd_stack array.
3102*0Sstevel@tonic-gate  * The error lists are in reverse chronological order when iterating using
3103*0Sstevel@tonic-gate  * eqe_prev, so we then pop things off the top in eqd_walk_step so that the
3104*0Sstevel@tonic-gate  * walker client gets addresses in order from oldest error to newest error.
3105*0Sstevel@tonic-gate  */
3106*0Sstevel@tonic-gate static void
3107*0Sstevel@tonic-gate eqd_push_list(eqd_walk_data_t *eqdp, uintptr_t addr)
3108*0Sstevel@tonic-gate {
3109*0Sstevel@tonic-gate 	errorq_elem_t eqe;
3110*0Sstevel@tonic-gate 
3111*0Sstevel@tonic-gate 	while (addr != NULL) {
3112*0Sstevel@tonic-gate 		if (mdb_vread(&eqe, sizeof (eqe), addr) != sizeof (eqe)) {
3113*0Sstevel@tonic-gate 			mdb_warn("failed to read errorq element at %p", addr);
3114*0Sstevel@tonic-gate 			break;
3115*0Sstevel@tonic-gate 		}
3116*0Sstevel@tonic-gate 
3117*0Sstevel@tonic-gate 		if (eqdp->eqd_qpos == eqdp->eqd_qlen) {
3118*0Sstevel@tonic-gate 			mdb_warn("errorq is overfull -- more than %lu "
3119*0Sstevel@tonic-gate 			    "elems found\n", eqdp->eqd_qlen);
3120*0Sstevel@tonic-gate 			break;
3121*0Sstevel@tonic-gate 		}
3122*0Sstevel@tonic-gate 
3123*0Sstevel@tonic-gate 		eqdp->eqd_stack[eqdp->eqd_qpos++] = (uintptr_t)eqe.eqe_data;
3124*0Sstevel@tonic-gate 		addr = (uintptr_t)eqe.eqe_prev;
3125*0Sstevel@tonic-gate 	}
3126*0Sstevel@tonic-gate }
3127*0Sstevel@tonic-gate 
3128*0Sstevel@tonic-gate static int
3129*0Sstevel@tonic-gate eqd_walk_init(mdb_walk_state_t *wsp)
3130*0Sstevel@tonic-gate {
3131*0Sstevel@tonic-gate 	eqd_walk_data_t *eqdp;
3132*0Sstevel@tonic-gate 	errorq_elem_t eqe, *addr;
3133*0Sstevel@tonic-gate 	errorq_t eq;
3134*0Sstevel@tonic-gate 	ulong_t i;
3135*0Sstevel@tonic-gate 
3136*0Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), wsp->walk_addr) == -1) {
3137*0Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", wsp->walk_addr);
3138*0Sstevel@tonic-gate 		return (WALK_ERR);
3139*0Sstevel@tonic-gate 	}
3140*0Sstevel@tonic-gate 
3141*0Sstevel@tonic-gate 	if (eq.eq_ptail != NULL &&
3142*0Sstevel@tonic-gate 	    mdb_vread(&eqe, sizeof (eqe), (uintptr_t)eq.eq_ptail) == -1) {
3143*0Sstevel@tonic-gate 		mdb_warn("failed to read errorq element at %p", eq.eq_ptail);
3144*0Sstevel@tonic-gate 		return (WALK_ERR);
3145*0Sstevel@tonic-gate 	}
3146*0Sstevel@tonic-gate 
3147*0Sstevel@tonic-gate 	eqdp = mdb_alloc(sizeof (eqd_walk_data_t), UM_SLEEP);
3148*0Sstevel@tonic-gate 	wsp->walk_data = eqdp;
3149*0Sstevel@tonic-gate 
3150*0Sstevel@tonic-gate 	eqdp->eqd_stack = mdb_zalloc(sizeof (uintptr_t) * eq.eq_qlen, UM_SLEEP);
3151*0Sstevel@tonic-gate 	eqdp->eqd_buf = mdb_alloc(eq.eq_size, UM_SLEEP);
3152*0Sstevel@tonic-gate 	eqdp->eqd_qlen = eq.eq_qlen;
3153*0Sstevel@tonic-gate 	eqdp->eqd_qpos = 0;
3154*0Sstevel@tonic-gate 	eqdp->eqd_size = eq.eq_size;
3155*0Sstevel@tonic-gate 
3156*0Sstevel@tonic-gate 	/*
3157*0Sstevel@tonic-gate 	 * The newest elements in the queue are on the pending list, so we
3158*0Sstevel@tonic-gate 	 * push those on to our stack first.
3159*0Sstevel@tonic-gate 	 */
3160*0Sstevel@tonic-gate 	eqd_push_list(eqdp, (uintptr_t)eq.eq_pend);
3161*0Sstevel@tonic-gate 
3162*0Sstevel@tonic-gate 	/*
3163*0Sstevel@tonic-gate 	 * If eq_ptail is set, it may point to a subset of the errors on the
3164*0Sstevel@tonic-gate 	 * pending list in the event a casptr() failed; if ptail's data is
3165*0Sstevel@tonic-gate 	 * already in our stack, NULL out eq_ptail and ignore it.
3166*0Sstevel@tonic-gate 	 */
3167*0Sstevel@tonic-gate 	if (eq.eq_ptail != NULL) {
3168*0Sstevel@tonic-gate 		for (i = 0; i < eqdp->eqd_qpos; i++) {
3169*0Sstevel@tonic-gate 			if (eqdp->eqd_stack[i] == (uintptr_t)eqe.eqe_data) {
3170*0Sstevel@tonic-gate 				eq.eq_ptail = NULL;
3171*0Sstevel@tonic-gate 				break;
3172*0Sstevel@tonic-gate 			}
3173*0Sstevel@tonic-gate 		}
3174*0Sstevel@tonic-gate 	}
3175*0Sstevel@tonic-gate 
3176*0Sstevel@tonic-gate 	/*
3177*0Sstevel@tonic-gate 	 * If eq_phead is set, it has the processing list in order from oldest
3178*0Sstevel@tonic-gate 	 * to newest.  Use this to recompute eq_ptail as best we can and then
3179*0Sstevel@tonic-gate 	 * we nicely fall into eqd_push_list() of eq_ptail below.
3180*0Sstevel@tonic-gate 	 */
3181*0Sstevel@tonic-gate 	for (addr = eq.eq_phead; addr != NULL && mdb_vread(&eqe, sizeof (eqe),
3182*0Sstevel@tonic-gate 	    (uintptr_t)addr) == sizeof (eqe); addr = eqe.eqe_next)
3183*0Sstevel@tonic-gate 		eq.eq_ptail = addr;
3184*0Sstevel@tonic-gate 
3185*0Sstevel@tonic-gate 	/*
3186*0Sstevel@tonic-gate 	 * The oldest elements in the queue are on the processing list, subject
3187*0Sstevel@tonic-gate 	 * to machinations in the if-clauses above.  Push any such elements.
3188*0Sstevel@tonic-gate 	 */
3189*0Sstevel@tonic-gate 	eqd_push_list(eqdp, (uintptr_t)eq.eq_ptail);
3190*0Sstevel@tonic-gate 	return (WALK_NEXT);
3191*0Sstevel@tonic-gate }
3192*0Sstevel@tonic-gate 
3193*0Sstevel@tonic-gate static int
3194*0Sstevel@tonic-gate eqd_walk_step(mdb_walk_state_t *wsp)
3195*0Sstevel@tonic-gate {
3196*0Sstevel@tonic-gate 	eqd_walk_data_t *eqdp = wsp->walk_data;
3197*0Sstevel@tonic-gate 	uintptr_t addr;
3198*0Sstevel@tonic-gate 
3199*0Sstevel@tonic-gate 	if (eqdp->eqd_qpos == 0)
3200*0Sstevel@tonic-gate 		return (WALK_DONE);
3201*0Sstevel@tonic-gate 
3202*0Sstevel@tonic-gate 	addr = eqdp->eqd_stack[--eqdp->eqd_qpos];
3203*0Sstevel@tonic-gate 
3204*0Sstevel@tonic-gate 	if (mdb_vread(eqdp->eqd_buf, eqdp->eqd_size, addr) != eqdp->eqd_size) {
3205*0Sstevel@tonic-gate 		mdb_warn("failed to read errorq data at %p", addr);
3206*0Sstevel@tonic-gate 		return (WALK_ERR);
3207*0Sstevel@tonic-gate 	}
3208*0Sstevel@tonic-gate 
3209*0Sstevel@tonic-gate 	return (wsp->walk_callback(addr, eqdp->eqd_buf, wsp->walk_cbdata));
3210*0Sstevel@tonic-gate }
3211*0Sstevel@tonic-gate 
3212*0Sstevel@tonic-gate static void
3213*0Sstevel@tonic-gate eqd_walk_fini(mdb_walk_state_t *wsp)
3214*0Sstevel@tonic-gate {
3215*0Sstevel@tonic-gate 	eqd_walk_data_t *eqdp = wsp->walk_data;
3216*0Sstevel@tonic-gate 
3217*0Sstevel@tonic-gate 	mdb_free(eqdp->eqd_stack, sizeof (uintptr_t) * eqdp->eqd_qlen);
3218*0Sstevel@tonic-gate 	mdb_free(eqdp->eqd_buf, eqdp->eqd_size);
3219*0Sstevel@tonic-gate 	mdb_free(eqdp, sizeof (eqd_walk_data_t));
3220*0Sstevel@tonic-gate }
3221*0Sstevel@tonic-gate 
3222*0Sstevel@tonic-gate #define	EQKSVAL(eqv, what) (eqv.eq_kstat.what.value.ui64)
3223*0Sstevel@tonic-gate 
3224*0Sstevel@tonic-gate static int
3225*0Sstevel@tonic-gate errorq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3226*0Sstevel@tonic-gate {
3227*0Sstevel@tonic-gate 	int i;
3228*0Sstevel@tonic-gate 	errorq_t eq;
3229*0Sstevel@tonic-gate 	uint_t opt_v = FALSE;
3230*0Sstevel@tonic-gate 
3231*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
3232*0Sstevel@tonic-gate 		if (mdb_walk_dcmd("errorq", "errorq", argc, argv) == -1) {
3233*0Sstevel@tonic-gate 			mdb_warn("can't walk 'errorq'");
3234*0Sstevel@tonic-gate 			return (DCMD_ERR);
3235*0Sstevel@tonic-gate 		}
3236*0Sstevel@tonic-gate 		return (DCMD_OK);
3237*0Sstevel@tonic-gate 	}
3238*0Sstevel@tonic-gate 
3239*0Sstevel@tonic-gate 	i = mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &opt_v, NULL);
3240*0Sstevel@tonic-gate 	argc -= i;
3241*0Sstevel@tonic-gate 	argv += i;
3242*0Sstevel@tonic-gate 
3243*0Sstevel@tonic-gate 	if (argc != 0)
3244*0Sstevel@tonic-gate 		return (DCMD_USAGE);
3245*0Sstevel@tonic-gate 
3246*0Sstevel@tonic-gate 	if (opt_v || DCMD_HDRSPEC(flags)) {
3247*0Sstevel@tonic-gate 		mdb_printf("%<u>%-11s %-16s %1s %1s %1s ",
3248*0Sstevel@tonic-gate 		    "ADDR", "NAME", "S", "V", "N");
3249*0Sstevel@tonic-gate 		if (!opt_v) {
3250*0Sstevel@tonic-gate 			mdb_printf("%7s %7s %7s%</u>\n",
3251*0Sstevel@tonic-gate 			    "ACCEPT", "DROP", "LOG");
3252*0Sstevel@tonic-gate 		} else {
3253*0Sstevel@tonic-gate 			mdb_printf("%5s %6s %6s %3s %16s%</u>\n",
3254*0Sstevel@tonic-gate 			    "KSTAT", "QLEN", "SIZE", "IPL", "FUNC");
3255*0Sstevel@tonic-gate 		}
3256*0Sstevel@tonic-gate 	}
3257*0Sstevel@tonic-gate 
3258*0Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), addr) != sizeof (eq)) {
3259*0Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", addr);
3260*0Sstevel@tonic-gate 		return (DCMD_ERR);
3261*0Sstevel@tonic-gate 	}
3262*0Sstevel@tonic-gate 
3263*0Sstevel@tonic-gate 	mdb_printf("%-11p %-16s %c %c %c ", addr, eq.eq_name,
3264*0Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_ACTIVE) ? '+' : '-',
3265*0Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_VITAL) ? '!' : ' ',
3266*0Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_NVLIST) ? '*' : ' ');
3267*0Sstevel@tonic-gate 
3268*0Sstevel@tonic-gate 	if (!opt_v) {
3269*0Sstevel@tonic-gate 		mdb_printf("%7llu %7llu %7llu\n",
3270*0Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_dispatched) + EQKSVAL(eq, eqk_committed),
3271*0Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_dropped) + EQKSVAL(eq, eqk_reserve_fail) +
3272*0Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_commit_fail), EQKSVAL(eq, eqk_logged));
3273*0Sstevel@tonic-gate 	} else {
3274*0Sstevel@tonic-gate 		mdb_printf("%5s %6lu %6lu %3u %a\n",
3275*0Sstevel@tonic-gate 		    "  |  ", eq.eq_qlen, eq.eq_size, eq.eq_ipl, eq.eq_func);
3276*0Sstevel@tonic-gate 		mdb_printf("%38s\n%41s"
3277*0Sstevel@tonic-gate 		    "%12s %llu\n"
3278*0Sstevel@tonic-gate 		    "%53s %llu\n"
3279*0Sstevel@tonic-gate 		    "%53s %llu\n"
3280*0Sstevel@tonic-gate 		    "%53s %llu\n"
3281*0Sstevel@tonic-gate 		    "%53s %llu\n"
3282*0Sstevel@tonic-gate 		    "%53s %llu\n"
3283*0Sstevel@tonic-gate 		    "%53s %llu\n"
3284*0Sstevel@tonic-gate 		    "%53s %llu\n\n",
3285*0Sstevel@tonic-gate 		    "|", "+-> ",
3286*0Sstevel@tonic-gate 		    "DISPATCHED",	EQKSVAL(eq, eqk_dispatched),
3287*0Sstevel@tonic-gate 		    "DROPPED",		EQKSVAL(eq, eqk_dropped),
3288*0Sstevel@tonic-gate 		    "LOGGED",		EQKSVAL(eq, eqk_logged),
3289*0Sstevel@tonic-gate 		    "RESERVED",		EQKSVAL(eq, eqk_reserved),
3290*0Sstevel@tonic-gate 		    "RESERVE FAIL",	EQKSVAL(eq, eqk_reserve_fail),
3291*0Sstevel@tonic-gate 		    "COMMITTED",	EQKSVAL(eq, eqk_committed),
3292*0Sstevel@tonic-gate 		    "COMMIT FAIL",	EQKSVAL(eq, eqk_commit_fail),
3293*0Sstevel@tonic-gate 		    "CANCELLED",	EQKSVAL(eq, eqk_cancelled));
3294*0Sstevel@tonic-gate 	}
3295*0Sstevel@tonic-gate 
3296*0Sstevel@tonic-gate 	return (DCMD_OK);
3297*0Sstevel@tonic-gate }
3298*0Sstevel@tonic-gate 
3299*0Sstevel@tonic-gate /*ARGSUSED*/
3300*0Sstevel@tonic-gate static int
3301*0Sstevel@tonic-gate panicinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3302*0Sstevel@tonic-gate {
3303*0Sstevel@tonic-gate 	cpu_t panic_cpu;
3304*0Sstevel@tonic-gate 	kthread_t *panic_thread;
3305*0Sstevel@tonic-gate 	void *panicbuf;
3306*0Sstevel@tonic-gate 	panic_data_t *pd;
3307*0Sstevel@tonic-gate 	int i, n;
3308*0Sstevel@tonic-gate 
3309*0Sstevel@tonic-gate 	if (!mdb_prop_postmortem) {
3310*0Sstevel@tonic-gate 		mdb_warn("panicinfo can only be run on a system "
3311*0Sstevel@tonic-gate 		    "dump; see dumpadm(1M)\n");
3312*0Sstevel@tonic-gate 		return (DCMD_ERR);
3313*0Sstevel@tonic-gate 	}
3314*0Sstevel@tonic-gate 
3315*0Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC || argc != 0)
3316*0Sstevel@tonic-gate 		return (DCMD_USAGE);
3317*0Sstevel@tonic-gate 
3318*0Sstevel@tonic-gate 	if (mdb_readsym(&panic_cpu, sizeof (cpu_t), "panic_cpu") == -1)
3319*0Sstevel@tonic-gate 		mdb_warn("failed to read 'panic_cpu'");
3320*0Sstevel@tonic-gate 	else
3321*0Sstevel@tonic-gate 		mdb_printf("%16s %?d\n", "cpu", panic_cpu.cpu_id);
3322*0Sstevel@tonic-gate 
3323*0Sstevel@tonic-gate 	if (mdb_readvar(&panic_thread, "panic_thread") == -1)
3324*0Sstevel@tonic-gate 		mdb_warn("failed to read 'panic_thread'");
3325*0Sstevel@tonic-gate 	else
3326*0Sstevel@tonic-gate 		mdb_printf("%16s %?p\n", "thread", panic_thread);
3327*0Sstevel@tonic-gate 
3328*0Sstevel@tonic-gate 	panicbuf = mdb_alloc(PANICBUFSIZE, UM_SLEEP);
3329*0Sstevel@tonic-gate 	pd = (panic_data_t *)panicbuf;
3330*0Sstevel@tonic-gate 
3331*0Sstevel@tonic-gate 	if (mdb_readsym(panicbuf, PANICBUFSIZE, "panicbuf") == -1 ||
3332*0Sstevel@tonic-gate 	    pd->pd_version != PANICBUFVERS) {
3333*0Sstevel@tonic-gate 		mdb_warn("failed to read 'panicbuf'");
3334*0Sstevel@tonic-gate 		mdb_free(panicbuf, PANICBUFSIZE);
3335*0Sstevel@tonic-gate 		return (DCMD_ERR);
3336*0Sstevel@tonic-gate 	}
3337*0Sstevel@tonic-gate 
3338*0Sstevel@tonic-gate 	mdb_printf("%16s %s\n", "message",  (char *)panicbuf + pd->pd_msgoff);
3339*0Sstevel@tonic-gate 
3340*0Sstevel@tonic-gate 	n = (pd->pd_msgoff - (sizeof (panic_data_t) -
3341*0Sstevel@tonic-gate 	    sizeof (panic_nv_t))) / sizeof (panic_nv_t);
3342*0Sstevel@tonic-gate 
3343*0Sstevel@tonic-gate 	for (i = 0; i < n; i++)
3344*0Sstevel@tonic-gate 		mdb_printf("%16s %?llx\n",
3345*0Sstevel@tonic-gate 		    pd->pd_nvdata[i].pnv_name, pd->pd_nvdata[i].pnv_value);
3346*0Sstevel@tonic-gate 
3347*0Sstevel@tonic-gate 	mdb_free(panicbuf, PANICBUFSIZE);
3348*0Sstevel@tonic-gate 	return (DCMD_OK);
3349*0Sstevel@tonic-gate }
3350*0Sstevel@tonic-gate 
3351*0Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
3352*0Sstevel@tonic-gate 
3353*0Sstevel@tonic-gate 	/* from genunix.c */
3354*0Sstevel@tonic-gate 	{ "addr2smap", ":[offset]", "translate address to smap", addr2smap },
3355*0Sstevel@tonic-gate 	{ "as2proc", ":", "convert as to proc_t address", as2proc },
3356*0Sstevel@tonic-gate 	{ "binding_hash_entry", ":", "print driver names hash table entry",
3357*0Sstevel@tonic-gate 		binding_hash_entry },
3358*0Sstevel@tonic-gate 	{ "callout", NULL, "print callout table", callout },
3359*0Sstevel@tonic-gate 	{ "class", NULL, "print process scheduler classes", class },
3360*0Sstevel@tonic-gate 	{ "cpuinfo", "?[-v]", "print CPUs and runnable threads", cpuinfo },
3361*0Sstevel@tonic-gate 	{ "did2thread", "? kt_did", "find kernel thread for this id",
3362*0Sstevel@tonic-gate 		did2thread },
3363*0Sstevel@tonic-gate 	{ "errorq", "?[-v]", "display kernel error queues", errorq },
3364*0Sstevel@tonic-gate 	{ "fd", ":[fd num]", "get a file pointer from an fd", fd },
3365*0Sstevel@tonic-gate 	{ "flipone", ":", "the vik_rev_level 2 special", flipone },
3366*0Sstevel@tonic-gate 	{ "lminfo", NULL, "print lock manager information", lminfo },
3367*0Sstevel@tonic-gate 	{ "ndi_event_hdl", "?", "print ndi_event_hdl", ndi_event_hdl },
3368*0Sstevel@tonic-gate 	{ "panicinfo", NULL, "print panic information", panicinfo },
3369*0Sstevel@tonic-gate 	{ "pid2proc", "?", "convert PID to proc_t address", pid2proc },
3370*0Sstevel@tonic-gate 	{ "pmap", ":[-q]", "print process memory map", pmap },
3371*0Sstevel@tonic-gate 	{ "project", NULL, "display kernel project(s)", project },
3372*0Sstevel@tonic-gate 	{ "ps", "[-fltzTP]", "list processes (and associated thr,lwp)", ps },
3373*0Sstevel@tonic-gate 	{ "pgrep", "[-n | -o] pattern", "pattern match against all processes",
3374*0Sstevel@tonic-gate 		pgrep },
3375*0Sstevel@tonic-gate 	{ "ptree", NULL, "print process tree", ptree },
3376*0Sstevel@tonic-gate 	{ "seg", ":", "print address space segment", seg },
3377*0Sstevel@tonic-gate 	{ "sysevent", "?[-sv]", "print sysevent pending or sent queue",
3378*0Sstevel@tonic-gate 		sysevent},
3379*0Sstevel@tonic-gate 	{ "sysevent_channel", "?", "print sysevent channel database",
3380*0Sstevel@tonic-gate 		sysevent_channel},
3381*0Sstevel@tonic-gate 	{ "sysevent_class_list", ":", "print sysevent class list",
3382*0Sstevel@tonic-gate 		sysevent_class_list},
3383*0Sstevel@tonic-gate 	{ "sysevent_subclass_list", ":",
3384*0Sstevel@tonic-gate 		"print sysevent subclass list", sysevent_subclass_list},
3385*0Sstevel@tonic-gate 	{ "system", NULL, "print contents of /etc/system file", sysfile },
3386*0Sstevel@tonic-gate 	{ "task", NULL, "display kernel task(s)", task },
3387*0Sstevel@tonic-gate 	{ "taskq_entry", ":", "display a taskq_ent_t", taskq_ent },
3388*0Sstevel@tonic-gate 	{ "vnode2path", ":[-F]", "vnode address to pathname", vnode2path },
3389*0Sstevel@tonic-gate 	{ "vnode2smap", ":[offset]", "translate vnode to smap", vnode2smap },
3390*0Sstevel@tonic-gate 	{ "whereopen", ":", "given a vnode, dumps procs which have it open",
3391*0Sstevel@tonic-gate 	    whereopen },
3392*0Sstevel@tonic-gate 
3393*0Sstevel@tonic-gate 	/* from zone.c */
3394*0Sstevel@tonic-gate 	{ "zone", "?", "display kernel zone(s)", zoneprt },
3395*0Sstevel@tonic-gate 	{ "zsd", ":[zsd key]", "lookup zsd value from a key", zsd },
3396*0Sstevel@tonic-gate 
3397*0Sstevel@tonic-gate 	/* from bio.c */
3398*0Sstevel@tonic-gate 	{ "bufpagefind", ":addr", "find page_t on buf_t list", bufpagefind },
3399*0Sstevel@tonic-gate 
3400*0Sstevel@tonic-gate 	/* from contract.c */
3401*0Sstevel@tonic-gate 	{ "contract", "?", "display a contract", cmd_contract },
3402*0Sstevel@tonic-gate 	{ "ctevent", ":", "display a contract event", cmd_ctevent },
3403*0Sstevel@tonic-gate 	{ "ctid", ":", "convert id to a contract pointer", cmd_ctid },
3404*0Sstevel@tonic-gate 
3405*0Sstevel@tonic-gate 	/* from cpupart.c */
3406*0Sstevel@tonic-gate 	{ "cpupart", "?", "print cpu partition info", cpupart },
3407*0Sstevel@tonic-gate 
3408*0Sstevel@tonic-gate 	/* from cyclic.c */
3409*0Sstevel@tonic-gate 	{ "cyccover", NULL, "dump cyclic coverage information", cyccover },
3410*0Sstevel@tonic-gate 	{ "cycid", "?", "dump a cyclic id", cycid },
3411*0Sstevel@tonic-gate 	{ "cycinfo", "?", "dump cyc_cpu info", cycinfo },
3412*0Sstevel@tonic-gate 	{ "cyclic", ":", "developer information", cyclic },
3413*0Sstevel@tonic-gate 	{ "cyctrace", "?", "dump cyclic trace buffer", cyctrace },
3414*0Sstevel@tonic-gate 
3415*0Sstevel@tonic-gate 	/* from devinfo.c */
3416*0Sstevel@tonic-gate 	{ "devbindings", "?[-qs] [device-name | major-num]",
3417*0Sstevel@tonic-gate 	    "print devinfo nodes bound to device-name or major-num",
3418*0Sstevel@tonic-gate 	    devbindings, devinfo_help },
3419*0Sstevel@tonic-gate 	{ "devinfo", ":[-qs]", "detailed devinfo of one node", devinfo,
3420*0Sstevel@tonic-gate 	    devinfo_help },
3421*0Sstevel@tonic-gate 	{ "devinfo_audit", ":[-v]", "devinfo configuration audit record",
3422*0Sstevel@tonic-gate 	    devinfo_audit },
3423*0Sstevel@tonic-gate 	{ "devinfo_audit_log", "?[-v]", "system wide devinfo configuration log",
3424*0Sstevel@tonic-gate 	    devinfo_audit_log },
3425*0Sstevel@tonic-gate 	{ "devinfo_audit_node", ":[-v]", "devinfo node configuration history",
3426*0Sstevel@tonic-gate 	    devinfo_audit_node },
3427*0Sstevel@tonic-gate 	{ "devinfo2driver", ":", "find driver name for this devinfo node",
3428*0Sstevel@tonic-gate 	    devinfo2driver },
3429*0Sstevel@tonic-gate 	{ "devnames", "?[-vm] [num]", "print devnames array", devnames },
3430*0Sstevel@tonic-gate 	{ "dev2major", "?<dev_t>", "convert dev_t to a major number",
3431*0Sstevel@tonic-gate 	    dev2major },
3432*0Sstevel@tonic-gate 	{ "dev2minor", "?<dev_t>", "convert dev_t to a minor number",
3433*0Sstevel@tonic-gate 	    dev2minor },
3434*0Sstevel@tonic-gate 	{ "devt", "?<dev_t>", "display a dev_t's major and minor numbers",
3435*0Sstevel@tonic-gate 	    devt },
3436*0Sstevel@tonic-gate 	{ "major2name", "?<major-num>", "convert major number to dev name",
3437*0Sstevel@tonic-gate 	    major2name },
3438*0Sstevel@tonic-gate 	{ "minornodes", ":", "given a devinfo node, print its minor nodes",
3439*0Sstevel@tonic-gate 	    minornodes },
3440*0Sstevel@tonic-gate 	{ "modctl2devinfo", ":", "given a modctl, list its devinfos",
3441*0Sstevel@tonic-gate 	    modctl2devinfo },
3442*0Sstevel@tonic-gate 	{ "name2major", "<dev-name>", "convert dev name to major number",
3443*0Sstevel@tonic-gate 	    name2major },
3444*0Sstevel@tonic-gate 	{ "prtconf", "?[-vpc]", "print devinfo tree", prtconf, prtconf_help },
3445*0Sstevel@tonic-gate 	{ "softstate", ":<instance>", "retrieve soft-state pointer",
3446*0Sstevel@tonic-gate 	    softstate },
3447*0Sstevel@tonic-gate 	{ "devinfo_fm", ":", "devinfo fault managment configuration",
3448*0Sstevel@tonic-gate 	    devinfo_fm },
3449*0Sstevel@tonic-gate 	{ "devinfo_fmce", ":", "devinfo fault managment cache entry",
3450*0Sstevel@tonic-gate 	    devinfo_fmce},
3451*0Sstevel@tonic-gate 
3452*0Sstevel@tonic-gate 	/* from findstack.c */
3453*0Sstevel@tonic-gate 	{ "findstack", ":[-v]", "find kernel thread stack", findstack },
3454*0Sstevel@tonic-gate 	{ "findstack_debug", NULL, "toggle findstack debugging",
3455*0Sstevel@tonic-gate 		findstack_debug },
3456*0Sstevel@tonic-gate 
3457*0Sstevel@tonic-gate 	/* from kgrep.c + genunix.c */
3458*0Sstevel@tonic-gate 	{ "kgrep", KGREP_USAGE, "search kernel as for a pointer", kgrep },
3459*0Sstevel@tonic-gate 
3460*0Sstevel@tonic-gate 	/* from kmem.c */
3461*0Sstevel@tonic-gate 	{ "allocdby", ":", "given a thread, print its allocated buffers",
3462*0Sstevel@tonic-gate 		allocdby },
3463*0Sstevel@tonic-gate 	{ "bufctl", ":[-vh] [-a addr] [-c caller] [-e earliest] [-l latest] "
3464*0Sstevel@tonic-gate 		"[-t thd]", "print or filter a bufctl", bufctl, bufctl_help },
3465*0Sstevel@tonic-gate 	{ "freedby", ":", "given a thread, print its freed buffers", freedby },
3466*0Sstevel@tonic-gate 	{ "kmalog", "?[ fail | slab ]",
3467*0Sstevel@tonic-gate 	    "display kmem transaction log and stack traces", kmalog },
3468*0Sstevel@tonic-gate 	{ "kmastat", NULL, "kernel memory allocator stats", kmastat },
3469*0Sstevel@tonic-gate 	{ "kmausers", "?[-ef] [cache ...]", "current medium and large users "
3470*0Sstevel@tonic-gate 		"of the kmem allocator", kmausers, kmausers_help },
3471*0Sstevel@tonic-gate 	{ "kmem_cache", "?", "print kernel memory caches", kmem_cache },
3472*0Sstevel@tonic-gate 	{ "kmem_debug", NULL, "toggle kmem dcmd/walk debugging", kmem_debug },
3473*0Sstevel@tonic-gate 	{ "kmem_log", "?[-b]", "dump kmem transaction log", kmem_log },
3474*0Sstevel@tonic-gate 	{ "kmem_verify", "?", "check integrity of kmem-managed memory",
3475*0Sstevel@tonic-gate 		kmem_verify },
3476*0Sstevel@tonic-gate 	{ "vmem", "?", "print a vmem_t", vmem },
3477*0Sstevel@tonic-gate 	{ "vmem_seg", ":[-sv] [-c caller] [-e earliest] [-l latest] "
3478*0Sstevel@tonic-gate 		"[-m minsize] [-M maxsize] [-t thread] [-T type]",
3479*0Sstevel@tonic-gate 		"print or filter a vmem_seg", vmem_seg, vmem_seg_help },
3480*0Sstevel@tonic-gate 	{ "whatis", ":[-abiv]", "given an address, return information", whatis,
3481*0Sstevel@tonic-gate 		whatis_help },
3482*0Sstevel@tonic-gate 	{ "whatthread", ":[-v]", "print threads whose stack contains the "
3483*0Sstevel@tonic-gate 		"given address", whatthread },
3484*0Sstevel@tonic-gate 
3485*0Sstevel@tonic-gate 	/* from ldi.c */
3486*0Sstevel@tonic-gate 	{ "ldi_handle", "?[-i]", "display a layered driver handle",
3487*0Sstevel@tonic-gate 	    ldi_handle, ldi_handle_help },
3488*0Sstevel@tonic-gate 	{ "ldi_ident", NULL, "display a layered driver identifier",
3489*0Sstevel@tonic-gate 	    ldi_ident, ldi_ident_help },
3490*0Sstevel@tonic-gate 
3491*0Sstevel@tonic-gate 	/* from leaky.c + leaky_subr.c */
3492*0Sstevel@tonic-gate 	{ "findleaks", FINDLEAKS_USAGE,
3493*0Sstevel@tonic-gate 	    "search for potential kernel memory leaks", findleaks,
3494*0Sstevel@tonic-gate 	    findleaks_help },
3495*0Sstevel@tonic-gate 
3496*0Sstevel@tonic-gate 	/* from lgrp.c */
3497*0Sstevel@tonic-gate 	{ "lgrp", "?[-q] [-p | -Pih]", "display an lgrp", lgrp},
3498*0Sstevel@tonic-gate 
3499*0Sstevel@tonic-gate 	/* from log.c */
3500*0Sstevel@tonic-gate 	{ "msgbuf", "?[-v]", "print most recent console messages", msgbuf },
3501*0Sstevel@tonic-gate 
3502*0Sstevel@tonic-gate 	/* from memory.c */
3503*0Sstevel@tonic-gate 	{ "page", "?", "display a summarized page_t", page },
3504*0Sstevel@tonic-gate 	{ "memstat", NULL, "display memory usage summary", memstat },
3505*0Sstevel@tonic-gate 	{ "memlist", "?[-iav]", "display a struct memlist", memlist },
3506*0Sstevel@tonic-gate 	{ "swapinfo", "?", "display a struct swapinfo", swapinfof },
3507*0Sstevel@tonic-gate 
3508*0Sstevel@tonic-gate 	/* from mmd.c */
3509*0Sstevel@tonic-gate 	{ "multidata", ":[-sv]", "display a summarized multidata_t",
3510*0Sstevel@tonic-gate 		multidata },
3511*0Sstevel@tonic-gate 	{ "pattbl", ":", "display a summarized multidata attribute table",
3512*0Sstevel@tonic-gate 		pattbl },
3513*0Sstevel@tonic-gate 	{ "pattr2multidata", ":", "print multidata pointer from pattr_t",
3514*0Sstevel@tonic-gate 		pattr2multidata },
3515*0Sstevel@tonic-gate 	{ "pdesc2slab", ":", "print pdesc slab pointer from pdesc_t",
3516*0Sstevel@tonic-gate 		pdesc2slab },
3517*0Sstevel@tonic-gate 	{ "pdesc_verify", ":", "verify integrity of a pdesc_t", pdesc_verify },
3518*0Sstevel@tonic-gate 	{ "slab2multidata", ":", "print multidata pointer from pdesc_slab_t",
3519*0Sstevel@tonic-gate 		slab2multidata },
3520*0Sstevel@tonic-gate 
3521*0Sstevel@tonic-gate 	/* from modhash.c */
3522*0Sstevel@tonic-gate 	{ "modhash", "?[-ceht] [-k key] [-v val] [-i index]",
3523*0Sstevel@tonic-gate 		"display information about one or all mod_hash structures",
3524*0Sstevel@tonic-gate 		modhash, modhash_help },
3525*0Sstevel@tonic-gate 	{ "modent", ":[-k | -v | -t type]",
3526*0Sstevel@tonic-gate 		"display information about a mod_hash_entry", modent,
3527*0Sstevel@tonic-gate 		modent_help },
3528*0Sstevel@tonic-gate 
3529*0Sstevel@tonic-gate 	/* from net.c */
3530*0Sstevel@tonic-gate 	{ "mi", ":[-p] [-d | -m]", "filter and display MI object or payload",
3531*0Sstevel@tonic-gate 		mi },
3532*0Sstevel@tonic-gate 	{ "netstat", "[-av] [-f inet | inet6 | unix] [-P tcp | udp]",
3533*0Sstevel@tonic-gate 		"show network statistics", netstat },
3534*0Sstevel@tonic-gate 	{ "sonode", "?[-f inet | inet6 | unix | #] "
3535*0Sstevel@tonic-gate 		"[-t stream | dgram | raw | #] [-p #]",
3536*0Sstevel@tonic-gate 		"filter and display sonode", sonode },
3537*0Sstevel@tonic-gate 
3538*0Sstevel@tonic-gate 	/* from nvpair.c */
3539*0Sstevel@tonic-gate 	{ NVPAIR_DCMD_NAME, NVPAIR_DCMD_USAGE, NVPAIR_DCMD_DESCR,
3540*0Sstevel@tonic-gate 		nvpair_print },
3541*0Sstevel@tonic-gate 
3542*0Sstevel@tonic-gate 	/* from rctl.c */
3543*0Sstevel@tonic-gate 	{ "rctl_dict", "?", "print systemwide default rctl definitions",
3544*0Sstevel@tonic-gate 		rctl_dict },
3545*0Sstevel@tonic-gate 	{ "rctl_list", ":[handle]", "print rctls for the given proc",
3546*0Sstevel@tonic-gate 		rctl_list },
3547*0Sstevel@tonic-gate 	{ "rctl", ":[handle]", "print a rctl_t, only if it matches the handle",
3548*0Sstevel@tonic-gate 		rctl },
3549*0Sstevel@tonic-gate 	{ "rctl_validate", ":[-v] [-n #]", "test resource control value "
3550*0Sstevel@tonic-gate 		"sequence", rctl_validate },
3551*0Sstevel@tonic-gate 
3552*0Sstevel@tonic-gate 	/* from sobj.c */
3553*0Sstevel@tonic-gate 	{ "rwlock", ":", "dump out a readers/writer lock", rwlock },
3554*0Sstevel@tonic-gate 	{ "mutex", ":[-f]", "dump out an adaptive or spin mutex", mutex,
3555*0Sstevel@tonic-gate 		mutex_help },
3556*0Sstevel@tonic-gate 	{ "sobj2ts", ":", "perform turnstile lookup on synch object", sobj2ts },
3557*0Sstevel@tonic-gate 	{ "wchaninfo", "?[-v]", "dump condition variable", wchaninfo },
3558*0Sstevel@tonic-gate 	{ "turnstile", "?", "display a turnstile", turnstile },
3559*0Sstevel@tonic-gate 
3560*0Sstevel@tonic-gate 	/* from stream.c */
3561*0Sstevel@tonic-gate 	{ "mblk", ":[-q|v] [-f|F flag] [-t|T type] [-l|L|B len] [-d dbaddr]",
3562*0Sstevel@tonic-gate 		"print an mblk", mblk_prt, mblk_help },
3563*0Sstevel@tonic-gate 	{ "mblk_verify", "?", "verify integrity of an mblk", mblk_verify },
3564*0Sstevel@tonic-gate 	{ "mblk2dblk", ":", "convert mblk_t address to dblk_t address",
3565*0Sstevel@tonic-gate 		mblk2dblk },
3566*0Sstevel@tonic-gate 	{ "q2otherq", ":", "print peer queue for a given queue", q2otherq },
3567*0Sstevel@tonic-gate 	{ "q2rdq", ":", "print read queue for a given queue", q2rdq },
3568*0Sstevel@tonic-gate 	{ "q2syncq", ":", "print syncq for a given queue", q2syncq },
3569*0Sstevel@tonic-gate 	{ "q2stream", ":", "print stream pointer for a given queue", q2stream },
3570*0Sstevel@tonic-gate 	{ "q2wrq", ":", "print write queue for a given queue", q2wrq },
3571*0Sstevel@tonic-gate 	{ "queue", ":[-q|v] [-m mod] [-f flag] [-F flag] [-s syncq_addr]",
3572*0Sstevel@tonic-gate 		"filter and display STREAM queue", queue, queue_help },
3573*0Sstevel@tonic-gate 	{ "stdata", ":[-q|v] [-f flag] [-F flag]",
3574*0Sstevel@tonic-gate 		"filter and display STREAM head", stdata, stdata_help },
3575*0Sstevel@tonic-gate 	{ "str2mate", ":", "print mate of this stream", str2mate },
3576*0Sstevel@tonic-gate 	{ "str2wrq", ":", "print write queue of this stream", str2wrq },
3577*0Sstevel@tonic-gate 	{ "stream", ":", "display STREAM", stream },
3578*0Sstevel@tonic-gate 	{ "strftevent", ":", "print STREAMS flow trace event", strftevent },
3579*0Sstevel@tonic-gate 	{ "syncq", ":[-q|v] [-f flag] [-F flag] [-t type] [-T type]",
3580*0Sstevel@tonic-gate 		"filter and display STREAM sync queue", syncq, syncq_help },
3581*0Sstevel@tonic-gate 	{ "syncq2q", ":", "print queue for a given syncq", syncq2q },
3582*0Sstevel@tonic-gate 
3583*0Sstevel@tonic-gate 	/* from thread.c */
3584*0Sstevel@tonic-gate 	{ "thread", "?[-bdfimps]", "display a summarized kthread_t", thread,
3585*0Sstevel@tonic-gate 		thread_help },
3586*0Sstevel@tonic-gate 	{ "threadlist", "?[-v [count]]",
3587*0Sstevel@tonic-gate 		"display threads and associated C stack traces", threadlist,
3588*0Sstevel@tonic-gate 		threadlist_help },
3589*0Sstevel@tonic-gate 
3590*0Sstevel@tonic-gate 	/* from tsd.c */
3591*0Sstevel@tonic-gate 	{ "tsd", ":-k key", "print tsd[key-1] for this thread", ttotsd },
3592*0Sstevel@tonic-gate 	{ "tsdtot", ":", "find thread with this tsd", tsdtot },
3593*0Sstevel@tonic-gate 
3594*0Sstevel@tonic-gate 	/*
3595*0Sstevel@tonic-gate 	 * typegraph does not work under kmdb, as it requires too much memory
3596*0Sstevel@tonic-gate 	 * for its internal data structures.
3597*0Sstevel@tonic-gate 	 */
3598*0Sstevel@tonic-gate #ifndef _KMDB
3599*0Sstevel@tonic-gate 	/* from typegraph.c */
3600*0Sstevel@tonic-gate 	{ "findlocks", ":", "find locks held by specified thread", findlocks },
3601*0Sstevel@tonic-gate 	{ "findfalse", "?[-v]", "find potentially falsely shared structures",
3602*0Sstevel@tonic-gate 		findfalse },
3603*0Sstevel@tonic-gate 	{ "typegraph", NULL, "build type graph", typegraph },
3604*0Sstevel@tonic-gate 	{ "istype", ":type", "manually set object type", istype },
3605*0Sstevel@tonic-gate 	{ "notype", ":", "manually clear object type", notype },
3606*0Sstevel@tonic-gate 	{ "whattype", ":", "determine object type", whattype },
3607*0Sstevel@tonic-gate #endif
3608*0Sstevel@tonic-gate 
3609*0Sstevel@tonic-gate 	/* from vfs.c */
3610*0Sstevel@tonic-gate 	{ "fsinfo", "?[-v]", "print mounted filesystems", fsinfo },
3611*0Sstevel@tonic-gate 	{ "pfiles", ":[-fp]", "print process file information", pfiles,
3612*0Sstevel@tonic-gate 		pfiles_help },
3613*0Sstevel@tonic-gate 
3614*0Sstevel@tonic-gate 	{ NULL }
3615*0Sstevel@tonic-gate };
3616*0Sstevel@tonic-gate 
3617*0Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
3618*0Sstevel@tonic-gate 
3619*0Sstevel@tonic-gate 	/* from genunix.c */
3620*0Sstevel@tonic-gate 	{ "avl", "given any avl_tree_t *, forward walk all entries in tree",
3621*0Sstevel@tonic-gate 		avl_walk_init, avl_walk_step, avl_walk_fini },
3622*0Sstevel@tonic-gate 	{ "anon", "given an amp, list of anon structures",
3623*0Sstevel@tonic-gate 		anon_walk_init, anon_walk_step, anon_walk_fini },
3624*0Sstevel@tonic-gate 	{ "cpu", "walk cpu structures", cpu_walk_init, cpu_walk_step },
3625*0Sstevel@tonic-gate 	{ "errorq", "walk list of system error queues",
3626*0Sstevel@tonic-gate 		errorq_walk_init, errorq_walk_step, NULL },
3627*0Sstevel@tonic-gate 	{ "errorq_data", "walk pending error queue data buffers",
3628*0Sstevel@tonic-gate 		eqd_walk_init, eqd_walk_step, eqd_walk_fini },
3629*0Sstevel@tonic-gate 	{ "allfile", "given a proc pointer, list all file pointers",
3630*0Sstevel@tonic-gate 		file_walk_init, allfile_walk_step, file_walk_fini },
3631*0Sstevel@tonic-gate 	{ "file", "given a proc pointer, list of open file pointers",
3632*0Sstevel@tonic-gate 		file_walk_init, file_walk_step, file_walk_fini },
3633*0Sstevel@tonic-gate 	{ "lock_descriptor", "walk lock_descriptor_t structures",
3634*0Sstevel@tonic-gate 		ld_walk_init, ld_walk_step, NULL },
3635*0Sstevel@tonic-gate 	{ "lock_graph", "walk lock graph",
3636*0Sstevel@tonic-gate 		lg_walk_init, lg_walk_step, NULL },
3637*0Sstevel@tonic-gate 	{ "port", "given a proc pointer, list of created event ports",
3638*0Sstevel@tonic-gate 		port_walk_init, port_walk_step, NULL },
3639*0Sstevel@tonic-gate 	{ "portev", "given a port pointer, list of events in the queue",
3640*0Sstevel@tonic-gate 		portev_walk_init, portev_walk_step, portev_walk_fini },
3641*0Sstevel@tonic-gate 	{ "proc", "list of active proc_t structures",
3642*0Sstevel@tonic-gate 		proc_walk_init, proc_walk_step, proc_walk_fini },
3643*0Sstevel@tonic-gate 	{ "projects", "walk a list of kernel projects",
3644*0Sstevel@tonic-gate 		project_walk_init, project_walk_step, NULL },
3645*0Sstevel@tonic-gate 	{ "seg", "given an as, list of segments",
3646*0Sstevel@tonic-gate 		seg_walk_init, avl_walk_step, avl_walk_fini },
3647*0Sstevel@tonic-gate 	{ "sysevent_pend", "walk sysevent pending queue",
3648*0Sstevel@tonic-gate 		sysevent_pend_walk_init, sysevent_walk_step,
3649*0Sstevel@tonic-gate 		sysevent_walk_fini},
3650*0Sstevel@tonic-gate 	{ "sysevent_sent", "walk sysevent sent queue", sysevent_sent_walk_init,
3651*0Sstevel@tonic-gate 		sysevent_walk_step, sysevent_walk_fini},
3652*0Sstevel@tonic-gate 	{ "sysevent_channel", "walk sysevent channel subscriptions",
3653*0Sstevel@tonic-gate 		sysevent_channel_walk_init, sysevent_channel_walk_step,
3654*0Sstevel@tonic-gate 		sysevent_channel_walk_fini},
3655*0Sstevel@tonic-gate 	{ "sysevent_class_list", "walk sysevent subscription's class list",
3656*0Sstevel@tonic-gate 		sysevent_class_list_walk_init, sysevent_class_list_walk_step,
3657*0Sstevel@tonic-gate 		sysevent_class_list_walk_fini},
3658*0Sstevel@tonic-gate 	{ "sysevent_subclass_list",
3659*0Sstevel@tonic-gate 		"walk sysevent subscription's subclass list",
3660*0Sstevel@tonic-gate 		sysevent_subclass_list_walk_init,
3661*0Sstevel@tonic-gate 		sysevent_subclass_list_walk_step,
3662*0Sstevel@tonic-gate 		sysevent_subclass_list_walk_fini},
3663*0Sstevel@tonic-gate 	{ "task", "given a task pointer, walk its processes",
3664*0Sstevel@tonic-gate 		task_walk_init, task_walk_step, NULL },
3665*0Sstevel@tonic-gate 	{ "taskq_entry", "given a taskq_t*, list all taskq_ent_t in the list",
3666*0Sstevel@tonic-gate 		taskq_walk_init, taskq_walk_step, NULL, NULL },
3667*0Sstevel@tonic-gate 
3668*0Sstevel@tonic-gate 	/* from zone.c */
3669*0Sstevel@tonic-gate 	{ "zone", "walk a list of kernel zones",
3670*0Sstevel@tonic-gate 		zone_walk_init, zone_walk_step, NULL },
3671*0Sstevel@tonic-gate 	{ "zsd", "walk list of zsd entries for a zone",
3672*0Sstevel@tonic-gate 		zsd_walk_init, zsd_walk_step, NULL },
3673*0Sstevel@tonic-gate 
3674*0Sstevel@tonic-gate 	/* from bio.c */
3675*0Sstevel@tonic-gate 	{ "buf", "walk the bio buf hash",
3676*0Sstevel@tonic-gate 		buf_walk_init, buf_walk_step, buf_walk_fini },
3677*0Sstevel@tonic-gate 
3678*0Sstevel@tonic-gate 	/* from contract.c */
3679*0Sstevel@tonic-gate 	{ "contract", "walk all contracts, or those of the specified type",
3680*0Sstevel@tonic-gate 		ct_walk_init, generic_walk_step, NULL },
3681*0Sstevel@tonic-gate 	{ "ct_event", "walk events on a contract event queue",
3682*0Sstevel@tonic-gate 		ct_event_walk_init, generic_walk_step, NULL },
3683*0Sstevel@tonic-gate 	{ "ct_listener", "walk contract event queue listeners",
3684*0Sstevel@tonic-gate 		ct_listener_walk_init, generic_walk_step, NULL },
3685*0Sstevel@tonic-gate 
3686*0Sstevel@tonic-gate 	/* from cpupart.c */
3687*0Sstevel@tonic-gate 	{ "cpupart_cpulist", "given an cpupart_t, walk cpus in partition",
3688*0Sstevel@tonic-gate 		cpupart_cpulist_walk_init, cpupart_cpulist_walk_step,
3689*0Sstevel@tonic-gate 		NULL },
3690*0Sstevel@tonic-gate 	{ "cpupart_walk", "walk the set of cpu partitions",
3691*0Sstevel@tonic-gate 		cpupart_walk_init, cpupart_walk_step, NULL },
3692*0Sstevel@tonic-gate 
3693*0Sstevel@tonic-gate 	/* from ctxop.c */
3694*0Sstevel@tonic-gate 	{ "ctxop", "walk list of context ops on a thread",
3695*0Sstevel@tonic-gate 		ctxop_walk_init, ctxop_walk_step, ctxop_walk_fini },
3696*0Sstevel@tonic-gate 
3697*0Sstevel@tonic-gate 	/* from cyclic.c */
3698*0Sstevel@tonic-gate 	{ "cyccpu", "walk per-CPU cyc_cpu structures",
3699*0Sstevel@tonic-gate 		cyccpu_walk_init, cyccpu_walk_step, NULL },
3700*0Sstevel@tonic-gate 	{ "cycomni", "for an omnipresent cyclic, walk cyc_omni_cpu list",
3701*0Sstevel@tonic-gate 		cycomni_walk_init, cycomni_walk_step, NULL },
3702*0Sstevel@tonic-gate 	{ "cyctrace", "walk cyclic trace buffer",
3703*0Sstevel@tonic-gate 		cyctrace_walk_init, cyctrace_walk_step, cyctrace_walk_fini },
3704*0Sstevel@tonic-gate 
3705*0Sstevel@tonic-gate 	/* from devinfo.c */
3706*0Sstevel@tonic-gate 	{ "binding_hash", "walk all entries in binding hash table",
3707*0Sstevel@tonic-gate 		binding_hash_walk_init, binding_hash_walk_step, NULL },
3708*0Sstevel@tonic-gate 	{ "devinfo", "walk devinfo tree or subtree",
3709*0Sstevel@tonic-gate 		devinfo_walk_init, devinfo_walk_step, devinfo_walk_fini },
3710*0Sstevel@tonic-gate 	{ "devinfo_audit_log", "walk devinfo audit system-wide log",
3711*0Sstevel@tonic-gate 		devinfo_audit_log_walk_init, devinfo_audit_log_walk_step,
3712*0Sstevel@tonic-gate 		devinfo_audit_log_walk_fini},
3713*0Sstevel@tonic-gate 	{ "devinfo_audit_node", "walk per-devinfo audit history",
3714*0Sstevel@tonic-gate 		devinfo_audit_node_walk_init, devinfo_audit_node_walk_step,
3715*0Sstevel@tonic-gate 		devinfo_audit_node_walk_fini},
3716*0Sstevel@tonic-gate 	{ "devinfo_children", "walk children of devinfo node",
3717*0Sstevel@tonic-gate 		devinfo_children_walk_init, devinfo_children_walk_step,
3718*0Sstevel@tonic-gate 		devinfo_children_walk_fini },
3719*0Sstevel@tonic-gate 	{ "devinfo_parents", "walk ancestors of devinfo node",
3720*0Sstevel@tonic-gate 		devinfo_parents_walk_init, devinfo_parents_walk_step,
3721*0Sstevel@tonic-gate 		devinfo_parents_walk_fini },
3722*0Sstevel@tonic-gate 	{ "devinfo_siblings", "walk siblings of devinfo node",
3723*0Sstevel@tonic-gate 		devinfo_siblings_walk_init, devinfo_siblings_walk_step, NULL },
3724*0Sstevel@tonic-gate 	{ "devi_next", "walk devinfo list",
3725*0Sstevel@tonic-gate 		NULL, devi_next_walk_step, NULL },
3726*0Sstevel@tonic-gate 	{ "devnames", "walk devnames array",
3727*0Sstevel@tonic-gate 		devnames_walk_init, devnames_walk_step, devnames_walk_fini },
3728*0Sstevel@tonic-gate 	{ "minornode", "given a devinfo node, walk minor nodes",
3729*0Sstevel@tonic-gate 		minornode_walk_init, minornode_walk_step, NULL },
3730*0Sstevel@tonic-gate 	{ "softstate",
3731*0Sstevel@tonic-gate 		"given an i_ddi_soft_state*, list all in-use driver stateps",
3732*0Sstevel@tonic-gate 		soft_state_walk_init, soft_state_walk_step,
3733*0Sstevel@tonic-gate 		NULL, NULL },
3734*0Sstevel@tonic-gate 	{ "softstate_all",
3735*0Sstevel@tonic-gate 		"given an i_ddi_soft_state*, list all driver stateps",
3736*0Sstevel@tonic-gate 		soft_state_walk_init, soft_state_all_walk_step,
3737*0Sstevel@tonic-gate 		NULL, NULL },
3738*0Sstevel@tonic-gate 	{ "devinfo_fmc",
3739*0Sstevel@tonic-gate 		"walk a fault management handle cache active list",
3740*0Sstevel@tonic-gate 		devinfo_fmc_walk_init, devinfo_fmc_walk_step, NULL },
3741*0Sstevel@tonic-gate 
3742*0Sstevel@tonic-gate 	/* from kmem.c */
3743*0Sstevel@tonic-gate 	{ "allocdby", "given a thread, walk its allocated bufctls",
3744*0Sstevel@tonic-gate 		allocdby_walk_init, allocdby_walk_step, allocdby_walk_fini },
3745*0Sstevel@tonic-gate 	{ "bufctl", "walk a kmem cache's bufctls",
3746*0Sstevel@tonic-gate 		bufctl_walk_init, kmem_walk_step, kmem_walk_fini },
3747*0Sstevel@tonic-gate 	{ "bufctl_history", "walk the available history of a bufctl",
3748*0Sstevel@tonic-gate 		bufctl_history_walk_init, bufctl_history_walk_step,
3749*0Sstevel@tonic-gate 		bufctl_history_walk_fini },
3750*0Sstevel@tonic-gate 	{ "freedby", "given a thread, walk its freed bufctls",
3751*0Sstevel@tonic-gate 		freedby_walk_init, allocdby_walk_step, allocdby_walk_fini },
3752*0Sstevel@tonic-gate 	{ "freectl", "walk a kmem cache's free bufctls",
3753*0Sstevel@tonic-gate 		freectl_walk_init, kmem_walk_step, kmem_walk_fini },
3754*0Sstevel@tonic-gate 	{ "freectl_constructed", "walk a kmem cache's constructed free bufctls",
3755*0Sstevel@tonic-gate 		freectl_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
3756*0Sstevel@tonic-gate 	{ "freemem", "walk a kmem cache's free memory",
3757*0Sstevel@tonic-gate 		freemem_walk_init, kmem_walk_step, kmem_walk_fini },
3758*0Sstevel@tonic-gate 	{ "freemem_constructed", "walk a kmem cache's constructed free memory",
3759*0Sstevel@tonic-gate 		freemem_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
3760*0Sstevel@tonic-gate 	{ "kmem", "walk a kmem cache",
3761*0Sstevel@tonic-gate 		kmem_walk_init, kmem_walk_step, kmem_walk_fini },
3762*0Sstevel@tonic-gate 	{ "kmem_cpu_cache", "given a kmem cache, walk its per-CPU caches",
3763*0Sstevel@tonic-gate 		kmem_cpu_cache_walk_init, kmem_cpu_cache_walk_step, NULL },
3764*0Sstevel@tonic-gate 	{ "kmem_hash", "given a kmem cache, walk its allocated hash table",
3765*0Sstevel@tonic-gate 		kmem_hash_walk_init, kmem_hash_walk_step, kmem_hash_walk_fini },
3766*0Sstevel@tonic-gate 	{ "kmem_log", "walk the kmem transaction log",
3767*0Sstevel@tonic-gate 		kmem_log_walk_init, kmem_log_walk_step, kmem_log_walk_fini },
3768*0Sstevel@tonic-gate 	{ "kmem_slab", "given a kmem cache, walk its slabs",
3769*0Sstevel@tonic-gate 		kmem_slab_walk_init, kmem_slab_walk_step, NULL },
3770*0Sstevel@tonic-gate 	{ "kmem_slab_partial",
3771*0Sstevel@tonic-gate 	    "given a kmem cache, walk its partially allocated slabs (min 1)",
3772*0Sstevel@tonic-gate 		kmem_slab_walk_partial_init, kmem_slab_walk_step, NULL },
3773*0Sstevel@tonic-gate 	{ "vmem", "walk vmem structures in pre-fix, depth-first order",
3774*0Sstevel@tonic-gate 		vmem_walk_init, vmem_walk_step, vmem_walk_fini },
3775*0Sstevel@tonic-gate 	{ "vmem_alloc", "given a vmem_t, walk its allocated vmem_segs",
3776*0Sstevel@tonic-gate 		vmem_alloc_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
3777*0Sstevel@tonic-gate 	{ "vmem_free", "given a vmem_t, walk its free vmem_segs",
3778*0Sstevel@tonic-gate 		vmem_free_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
3779*0Sstevel@tonic-gate 	{ "vmem_postfix", "walk vmem structures in post-fix, depth-first order",
3780*0Sstevel@tonic-gate 		vmem_walk_init, vmem_postfix_walk_step, vmem_walk_fini },
3781*0Sstevel@tonic-gate 	{ "vmem_seg", "given a vmem_t, walk all of its vmem_segs",
3782*0Sstevel@tonic-gate 		vmem_seg_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
3783*0Sstevel@tonic-gate 	{ "vmem_span", "given a vmem_t, walk its spanning vmem_segs",
3784*0Sstevel@tonic-gate 		vmem_span_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
3785*0Sstevel@tonic-gate 
3786*0Sstevel@tonic-gate 	/* from ldi.c */
3787*0Sstevel@tonic-gate 	{ "ldi_handle", "walk the layered driver handle hash",
3788*0Sstevel@tonic-gate 		ldi_handle_walk_init, ldi_handle_walk_step, NULL },
3789*0Sstevel@tonic-gate 	{ "ldi_ident", "walk the layered driver identifier hash",
3790*0Sstevel@tonic-gate 		ldi_ident_walk_init, ldi_ident_walk_step, NULL },
3791*0Sstevel@tonic-gate 
3792*0Sstevel@tonic-gate 	/* from leaky.c + leaky_subr.c */
3793*0Sstevel@tonic-gate 	{ "leak", "given a leaked bufctl or vmem_seg, find leaks w/ same "
3794*0Sstevel@tonic-gate 	    "stack trace",
3795*0Sstevel@tonic-gate 		leaky_walk_init, leaky_walk_step, leaky_walk_fini },
3796*0Sstevel@tonic-gate 	{ "leakbuf", "given a leaked bufctl or vmem_seg, walk buffers for "
3797*0Sstevel@tonic-gate 	    "leaks w/ same stack trace",
3798*0Sstevel@tonic-gate 		leaky_walk_init, leaky_buf_walk_step, leaky_walk_fini },
3799*0Sstevel@tonic-gate 
3800*0Sstevel@tonic-gate 	/* from lgrp.c */
3801*0Sstevel@tonic-gate 	{ "lgrp_cpulist", "given an lgrp, walk cpus",
3802*0Sstevel@tonic-gate 		lgrp_cpulist_walk_init, lgrp_cpulist_walk_step,
3803*0Sstevel@tonic-gate 		NULL },
3804*0Sstevel@tonic-gate 	{ "lgrptbl", "walk the lgrp table",
3805*0Sstevel@tonic-gate 		lgrp_walk_init, lgrp_walk_step, NULL },
3806*0Sstevel@tonic-gate 
3807*0Sstevel@tonic-gate 	/* from list.c */
3808*0Sstevel@tonic-gate 	{ "list", "walk a linked list",
3809*0Sstevel@tonic-gate 		list_walk_init, list_walk_step, list_walk_fini },
3810*0Sstevel@tonic-gate 
3811*0Sstevel@tonic-gate 	/* from memory.c */
3812*0Sstevel@tonic-gate 	{ "page", "walk all pages, or those from the specified vnode",
3813*0Sstevel@tonic-gate 		page_walk_init, page_walk_step, page_walk_fini },
3814*0Sstevel@tonic-gate 	{ "memlist", "walk specified memlist",
3815*0Sstevel@tonic-gate 		NULL, memlist_walk_step, NULL },
3816*0Sstevel@tonic-gate 	{ "swapinfo", "walk swapinfo structures",
3817*0Sstevel@tonic-gate 		swap_walk_init, swap_walk_step, NULL },
3818*0Sstevel@tonic-gate 
3819*0Sstevel@tonic-gate 	/* from mmd.c */
3820*0Sstevel@tonic-gate 	{ "pattr", "walk pattr_t structures", pattr_walk_init,
3821*0Sstevel@tonic-gate 		mmdq_walk_step, mmdq_walk_fini },
3822*0Sstevel@tonic-gate 	{ "pdesc", "walk pdesc_t structures",
3823*0Sstevel@tonic-gate 		pdesc_walk_init, mmdq_walk_step, mmdq_walk_fini },
3824*0Sstevel@tonic-gate 	{ "pdesc_slab", "walk pdesc_slab_t structures",
3825*0Sstevel@tonic-gate 		pdesc_slab_walk_init, mmdq_walk_step, mmdq_walk_fini },
3826*0Sstevel@tonic-gate 
3827*0Sstevel@tonic-gate 	/* from modhash.c */
3828*0Sstevel@tonic-gate 	{ "modhash", "walk list of mod_hash structures", modhash_walk_init,
3829*0Sstevel@tonic-gate 		modhash_walk_step, NULL },
3830*0Sstevel@tonic-gate 	{ "modent", "walk list of entries in a given mod_hash",
3831*0Sstevel@tonic-gate 		modent_walk_init, modent_walk_step, modent_walk_fini },
3832*0Sstevel@tonic-gate 	{ "modchain", "walk list of entries in a given mod_hash_entry",
3833*0Sstevel@tonic-gate 		NULL, modchain_walk_step, NULL },
3834*0Sstevel@tonic-gate 
3835*0Sstevel@tonic-gate 	/* from net.c */
3836*0Sstevel@tonic-gate 	{ "ar", "walk ar_t structures using MI",
3837*0Sstevel@tonic-gate 		mi_payload_walk_init, mi_payload_walk_step,
3838*0Sstevel@tonic-gate 		mi_payload_walk_fini, &mi_ar_arg },
3839*0Sstevel@tonic-gate 	{ "icmp", "walk ICMP control structures using MI",
3840*0Sstevel@tonic-gate 		mi_payload_walk_init, mi_payload_walk_step,
3841*0Sstevel@tonic-gate 		mi_payload_walk_fini, &mi_icmp_arg },
3842*0Sstevel@tonic-gate 	{ "ill", "walk ill_t structures using MI",
3843*0Sstevel@tonic-gate 		mi_payload_walk_init, mi_payload_walk_step,
3844*0Sstevel@tonic-gate 		mi_payload_walk_fini, &mi_ill_arg },
3845*0Sstevel@tonic-gate 	{ "mi", "given a MI_O, walk the MI",
3846*0Sstevel@tonic-gate 		mi_walk_init, mi_walk_step, mi_walk_fini, NULL },
3847*0Sstevel@tonic-gate 	{ "sonode", "given a sonode, walk its children",
3848*0Sstevel@tonic-gate 		sonode_walk_init, sonode_walk_step, sonode_walk_fini, NULL },
3849*0Sstevel@tonic-gate 	{ "udp", "walk UDP connections using MI",
3850*0Sstevel@tonic-gate 		mi_payload_walk_init, mi_payload_walk_step,
3851*0Sstevel@tonic-gate 		mi_payload_walk_fini, &mi_udp_arg },
3852*0Sstevel@tonic-gate 
3853*0Sstevel@tonic-gate 	/* from nvpair.c */
3854*0Sstevel@tonic-gate 	{ NVPAIR_WALKER_NAME, NVPAIR_WALKER_DESCR,
3855*0Sstevel@tonic-gate 		nvpair_walk_init, nvpair_walk_step, NULL },
3856*0Sstevel@tonic-gate 
3857*0Sstevel@tonic-gate 	/* from rctl.c */
3858*0Sstevel@tonic-gate 	{ "rctl_dict_list", "walk all rctl_dict_entry_t's from rctl_lists",
3859*0Sstevel@tonic-gate 		rctl_dict_walk_init, rctl_dict_walk_step, NULL },
3860*0Sstevel@tonic-gate 	{ "rctl_set", "given a rctl_set, walk all rctls", rctl_set_walk_init,
3861*0Sstevel@tonic-gate 		rctl_set_walk_step, NULL },
3862*0Sstevel@tonic-gate 	{ "rctl_val", "given a rctl_t, walk all rctl_val entries associated",
3863*0Sstevel@tonic-gate 		rctl_val_walk_init, rctl_val_walk_step },
3864*0Sstevel@tonic-gate 
3865*0Sstevel@tonic-gate 	/* from sobj.c */
3866*0Sstevel@tonic-gate 	{ "blocked", "walk threads blocked on a given sobj",
3867*0Sstevel@tonic-gate 		blocked_walk_init, blocked_walk_step, NULL },
3868*0Sstevel@tonic-gate 	{ "wchan", "given a wchan, list of blocked threads",
3869*0Sstevel@tonic-gate 		wchan_walk_init, wchan_walk_step, wchan_walk_fini },
3870*0Sstevel@tonic-gate 
3871*0Sstevel@tonic-gate 	/* from stream.c */
3872*0Sstevel@tonic-gate 	{ "b_cont", "walk mblk_t list using b_cont",
3873*0Sstevel@tonic-gate 		mblk_walk_init, b_cont_step, mblk_walk_fini },
3874*0Sstevel@tonic-gate 	{ "b_next", "walk mblk_t list using b_next",
3875*0Sstevel@tonic-gate 		mblk_walk_init, b_next_step, mblk_walk_fini },
3876*0Sstevel@tonic-gate 	{ "qlink", "walk queue_t list using q_link",
3877*0Sstevel@tonic-gate 		queue_walk_init, queue_link_step, queue_walk_fini },
3878*0Sstevel@tonic-gate 	{ "qnext", "walk queue_t list using q_next",
3879*0Sstevel@tonic-gate 		queue_walk_init, queue_next_step, queue_walk_fini },
3880*0Sstevel@tonic-gate 	{ "strftblk", "given a dblk_t, walk STREAMS flow trace event list",
3881*0Sstevel@tonic-gate 		strftblk_walk_init, strftblk_step, strftblk_walk_fini },
3882*0Sstevel@tonic-gate 	{ "readq", "walk read queue side of stdata",
3883*0Sstevel@tonic-gate 		str_walk_init, strr_walk_step, str_walk_fini },
3884*0Sstevel@tonic-gate 	{ "writeq", "walk write queue side of stdata",
3885*0Sstevel@tonic-gate 		str_walk_init, strw_walk_step, str_walk_fini },
3886*0Sstevel@tonic-gate 
3887*0Sstevel@tonic-gate 	/* from thread.c */
3888*0Sstevel@tonic-gate 	{ "deathrow", "walk threads on both lwp_ and thread_deathrow",
3889*0Sstevel@tonic-gate 		deathrow_walk_init, deathrow_walk_step, NULL },
3890*0Sstevel@tonic-gate 	{ "cpu_dispq", "given a cpu_t, walk threads in dispatcher queues",
3891*0Sstevel@tonic-gate 		cpu_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
3892*0Sstevel@tonic-gate 	{ "cpupart_dispq",
3893*0Sstevel@tonic-gate 		"given a cpupart_t, walk threads in dispatcher queues",
3894*0Sstevel@tonic-gate 		cpupart_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
3895*0Sstevel@tonic-gate 	{ "lwp_deathrow", "walk lwp_deathrow",
3896*0Sstevel@tonic-gate 		lwp_deathrow_walk_init, deathrow_walk_step, NULL },
3897*0Sstevel@tonic-gate 	{ "thread", "global or per-process kthread_t structures",
3898*0Sstevel@tonic-gate 		thread_walk_init, thread_walk_step, thread_walk_fini },
3899*0Sstevel@tonic-gate 	{ "thread_deathrow", "walk threads on thread_deathrow",
3900*0Sstevel@tonic-gate 		thread_deathrow_walk_init, deathrow_walk_step, NULL },
3901*0Sstevel@tonic-gate 
3902*0Sstevel@tonic-gate 	/* from tsd.c */
3903*0Sstevel@tonic-gate 	{ "tsd", "walk list of thread-specific data",
3904*0Sstevel@tonic-gate 		tsd_walk_init, tsd_walk_step, tsd_walk_fini },
3905*0Sstevel@tonic-gate 
3906*0Sstevel@tonic-gate 	/*
3907*0Sstevel@tonic-gate 	 * typegraph does not work under kmdb, as it requires too much memory
3908*0Sstevel@tonic-gate 	 * for its internal data structures.
3909*0Sstevel@tonic-gate 	 */
3910*0Sstevel@tonic-gate #ifndef _KMDB
3911*0Sstevel@tonic-gate 	/* from typegraph.c */
3912*0Sstevel@tonic-gate 	{ "typeconflict", "walk buffers with conflicting type inferences",
3913*0Sstevel@tonic-gate 		typegraph_walk_init, typeconflict_walk_step },
3914*0Sstevel@tonic-gate 	{ "typeunknown", "walk buffers with unknown types",
3915*0Sstevel@tonic-gate 		typegraph_walk_init, typeunknown_walk_step },
3916*0Sstevel@tonic-gate #endif
3917*0Sstevel@tonic-gate 
3918*0Sstevel@tonic-gate 	/* from vfs.c */
3919*0Sstevel@tonic-gate 	{ "vfs", "walk file system list",
3920*0Sstevel@tonic-gate 		vfs_walk_init, vfs_walk_step },
3921*0Sstevel@tonic-gate 	{ NULL }
3922*0Sstevel@tonic-gate };
3923*0Sstevel@tonic-gate 
3924*0Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
3925*0Sstevel@tonic-gate 
3926*0Sstevel@tonic-gate const mdb_modinfo_t *
3927*0Sstevel@tonic-gate _mdb_init(void)
3928*0Sstevel@tonic-gate {
3929*0Sstevel@tonic-gate 	if (mdb_readvar(&devinfo_root, "top_devinfo") == -1) {
3930*0Sstevel@tonic-gate 		mdb_warn("failed to read 'top_devinfo'");
3931*0Sstevel@tonic-gate 		return (NULL);
3932*0Sstevel@tonic-gate 	}
3933*0Sstevel@tonic-gate 
3934*0Sstevel@tonic-gate 	if (findstack_init() != DCMD_OK)
3935*0Sstevel@tonic-gate 		return (NULL);
3936*0Sstevel@tonic-gate 
3937*0Sstevel@tonic-gate 	kmem_init();
3938*0Sstevel@tonic-gate 
3939*0Sstevel@tonic-gate 	return (&modinfo);
3940*0Sstevel@tonic-gate }
3941*0Sstevel@tonic-gate 
3942*0Sstevel@tonic-gate void
3943*0Sstevel@tonic-gate _mdb_fini(void)
3944*0Sstevel@tonic-gate {
3945*0Sstevel@tonic-gate 	/*
3946*0Sstevel@tonic-gate 	 * Force ::findleaks to let go any cached memory
3947*0Sstevel@tonic-gate 	 */
3948*0Sstevel@tonic-gate 	leaky_cleanup(1);
3949*0Sstevel@tonic-gate }
3950