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