xref: /illumos-gate/usr/src/cmd/mdb/common/modules/genunix/genunix.c (revision bb8b5132cbf0e1d3fd47148d13c12ace41e302bb)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5154eb83fSjwadams  * Common Development and Distribution License (the "License").
6154eb83fSjwadams  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22fb2f18f8Sesaxe  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <mdb/mdb_param.h>
297c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
307c478bd9Sstevel@tonic-gate #include <mdb/mdb_ks.h>
317c478bd9Sstevel@tonic-gate #include <mdb/mdb_ctf.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/thread.h>
357c478bd9Sstevel@tonic-gate #include <sys/session.h>
367c478bd9Sstevel@tonic-gate #include <sys/user.h>
377c478bd9Sstevel@tonic-gate #include <sys/proc.h>
387c478bd9Sstevel@tonic-gate #include <sys/var.h>
397c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
407c478bd9Sstevel@tonic-gate #include <sys/callo.h>
417c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
427c478bd9Sstevel@tonic-gate #include <sys/class.h>
437c478bd9Sstevel@tonic-gate #include <sys/regset.h>
447c478bd9Sstevel@tonic-gate #include <sys/stack.h>
457c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
467c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
477c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
487c478bd9Sstevel@tonic-gate #include <sys/flock_impl.h>
497c478bd9Sstevel@tonic-gate #include <sys/kmem_impl.h>
507c478bd9Sstevel@tonic-gate #include <sys/vmem_impl.h>
517c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
527c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
537c478bd9Sstevel@tonic-gate #include <vm/anon.h>
547c478bd9Sstevel@tonic-gate #include <vm/as.h>
557c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
567c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
577c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
587c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
597c478bd9Sstevel@tonic-gate #include <sys/sysconf.h>
607c478bd9Sstevel@tonic-gate #include <sys/task.h>
617c478bd9Sstevel@tonic-gate #include <sys/project.h>
627c478bd9Sstevel@tonic-gate #include <sys/taskq.h>
637c478bd9Sstevel@tonic-gate #include <sys/taskq_impl.h>
647c478bd9Sstevel@tonic-gate #include <sys/errorq_impl.h>
657c478bd9Sstevel@tonic-gate #include <sys/cred_impl.h>
667c478bd9Sstevel@tonic-gate #include <sys/zone.h>
677c478bd9Sstevel@tonic-gate #include <sys/panic.h>
687c478bd9Sstevel@tonic-gate #include <regex.h>
697c478bd9Sstevel@tonic-gate #include <sys/port_impl.h>
707c478bd9Sstevel@tonic-gate 
71fa9e4066Sahrens #include "avl.h"
727c478bd9Sstevel@tonic-gate #include "contract.h"
737c478bd9Sstevel@tonic-gate #include "cpupart_mdb.h"
747c478bd9Sstevel@tonic-gate #include "devinfo.h"
757c478bd9Sstevel@tonic-gate #include "leaky.h"
767c478bd9Sstevel@tonic-gate #include "lgrp.h"
77fb2f18f8Sesaxe #include "pg.h"
78fb2f18f8Sesaxe #include "group.h"
797c478bd9Sstevel@tonic-gate #include "list.h"
807c478bd9Sstevel@tonic-gate #include "log.h"
817c478bd9Sstevel@tonic-gate #include "kgrep.h"
827c478bd9Sstevel@tonic-gate #include "kmem.h"
837c478bd9Sstevel@tonic-gate #include "bio.h"
847c478bd9Sstevel@tonic-gate #include "streams.h"
857c478bd9Sstevel@tonic-gate #include "cyclic.h"
867c478bd9Sstevel@tonic-gate #include "findstack.h"
877c478bd9Sstevel@tonic-gate #include "ndievents.h"
887c478bd9Sstevel@tonic-gate #include "mmd.h"
897c478bd9Sstevel@tonic-gate #include "net.h"
90f4b3ec61Sdh #include "netstack.h"
917c478bd9Sstevel@tonic-gate #include "nvpair.h"
927c478bd9Sstevel@tonic-gate #include "ctxop.h"
937c478bd9Sstevel@tonic-gate #include "tsd.h"
947c478bd9Sstevel@tonic-gate #include "thread.h"
957c478bd9Sstevel@tonic-gate #include "memory.h"
967c478bd9Sstevel@tonic-gate #include "sobj.h"
977c478bd9Sstevel@tonic-gate #include "sysevent.h"
987c478bd9Sstevel@tonic-gate #include "rctl.h"
9945916cd2Sjpk #include "tsol.h"
1007c478bd9Sstevel@tonic-gate #include "typegraph.h"
1017c478bd9Sstevel@tonic-gate #include "ldi.h"
1027c478bd9Sstevel@tonic-gate #include "vfs.h"
1037c478bd9Sstevel@tonic-gate #include "zone.h"
1047c478bd9Sstevel@tonic-gate #include "modhash.h"
10570ab954aSramat #include "mdi.h"
1069dd0f810Scindi #include "fm.h"
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * Surely this is defined somewhere...
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate #define	NINTR		16
1127c478bd9Sstevel@tonic-gate 
113*bb8b5132Sek #define	KILOS		10
114*bb8b5132Sek #define	MEGS		20
115*bb8b5132Sek #define	GIGS		30
116*bb8b5132Sek 
1177c478bd9Sstevel@tonic-gate #ifndef STACK_BIAS
1187c478bd9Sstevel@tonic-gate #define	STACK_BIAS	0
1197c478bd9Sstevel@tonic-gate #endif
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate static char
1227c478bd9Sstevel@tonic-gate pstat2ch(uchar_t state)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	switch (state) {
1257c478bd9Sstevel@tonic-gate 		case SSLEEP: return ('S');
1267c478bd9Sstevel@tonic-gate 		case SRUN: return ('R');
1277c478bd9Sstevel@tonic-gate 		case SZOMB: return ('Z');
1287c478bd9Sstevel@tonic-gate 		case SIDL: return ('I');
1297c478bd9Sstevel@tonic-gate 		case SONPROC: return ('O');
1307c478bd9Sstevel@tonic-gate 		case SSTOP: return ('T');
131c97ad5cdSakolb 		case SWAIT: return ('W');
1327c478bd9Sstevel@tonic-gate 		default: return ('?');
1337c478bd9Sstevel@tonic-gate 	}
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #define	PS_PRTTHREADS	0x1
1377c478bd9Sstevel@tonic-gate #define	PS_PRTLWPS	0x2
1387c478bd9Sstevel@tonic-gate #define	PS_PSARGS	0x4
1397c478bd9Sstevel@tonic-gate #define	PS_TASKS	0x8
1407c478bd9Sstevel@tonic-gate #define	PS_PROJECTS	0x10
1417c478bd9Sstevel@tonic-gate #define	PS_ZONES	0x20
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate static int
1447c478bd9Sstevel@tonic-gate ps_threadprint(uintptr_t addr, const void *data, void *private)
1457c478bd9Sstevel@tonic-gate {
1467c478bd9Sstevel@tonic-gate 	const kthread_t *t = (const kthread_t *)data;
1477c478bd9Sstevel@tonic-gate 	uint_t prt_flags = *((uint_t *)private);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	static const mdb_bitmask_t t_state_bits[] = {
1507c478bd9Sstevel@tonic-gate 		{ "TS_FREE",	UINT_MAX,	TS_FREE		},
1517c478bd9Sstevel@tonic-gate 		{ "TS_SLEEP",	TS_SLEEP,	TS_SLEEP	},
1527c478bd9Sstevel@tonic-gate 		{ "TS_RUN",	TS_RUN,		TS_RUN		},
1537c478bd9Sstevel@tonic-gate 		{ "TS_ONPROC",	TS_ONPROC,	TS_ONPROC	},
1547c478bd9Sstevel@tonic-gate 		{ "TS_ZOMB",	TS_ZOMB,	TS_ZOMB		},
1557c478bd9Sstevel@tonic-gate 		{ "TS_STOPPED",	TS_STOPPED,	TS_STOPPED	},
156c97ad5cdSakolb 		{ "TS_WAIT",	TS_WAIT,	TS_WAIT		},
1577c478bd9Sstevel@tonic-gate 		{ NULL,		0,		0		}
1587c478bd9Sstevel@tonic-gate 	};
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	if (prt_flags & PS_PRTTHREADS)
1617c478bd9Sstevel@tonic-gate 		mdb_printf("\tT  %?a <%b>\n", addr, t->t_state, t_state_bits);
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	if (prt_flags & PS_PRTLWPS)
1647c478bd9Sstevel@tonic-gate 		mdb_printf("\tL  %?a ID: %u\n", t->t_lwp, t->t_tid);
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate int
1707c478bd9Sstevel@tonic-gate ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1717c478bd9Sstevel@tonic-gate {
1727c478bd9Sstevel@tonic-gate 	uint_t prt_flags = 0;
1737c478bd9Sstevel@tonic-gate 	proc_t pr;
1747c478bd9Sstevel@tonic-gate 	struct pid pid, pgid, sid;
1757c478bd9Sstevel@tonic-gate 	sess_t session;
1767c478bd9Sstevel@tonic-gate 	cred_t cred;
1777c478bd9Sstevel@tonic-gate 	task_t tk;
1787c478bd9Sstevel@tonic-gate 	kproject_t pj;
1797c478bd9Sstevel@tonic-gate 	zone_t zn;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
1827c478bd9Sstevel@tonic-gate 		if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) {
1837c478bd9Sstevel@tonic-gate 			mdb_warn("can't walk 'proc'");
1847c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
1857c478bd9Sstevel@tonic-gate 		}
1867c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
1877c478bd9Sstevel@tonic-gate 	}
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
1907c478bd9Sstevel@tonic-gate 	    'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags,
1917c478bd9Sstevel@tonic-gate 	    'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags,
1927c478bd9Sstevel@tonic-gate 	    'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags,
1937c478bd9Sstevel@tonic-gate 	    'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags,
1947c478bd9Sstevel@tonic-gate 	    'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags,
1957c478bd9Sstevel@tonic-gate 	    't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc)
1967c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
1997c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%1s %6s %6s %6s %6s ",
2007c478bd9Sstevel@tonic-gate 		    "S", "PID", "PPID", "PGID", "SID");
2017c478bd9Sstevel@tonic-gate 		if (prt_flags & PS_TASKS)
2027c478bd9Sstevel@tonic-gate 			mdb_printf("%5s ", "TASK");
2037c478bd9Sstevel@tonic-gate 		if (prt_flags & PS_PROJECTS)
2047c478bd9Sstevel@tonic-gate 			mdb_printf("%5s ", "PROJ");
2057c478bd9Sstevel@tonic-gate 		if (prt_flags & PS_ZONES)
2067c478bd9Sstevel@tonic-gate 			mdb_printf("%5s ", "ZONE");
2077c478bd9Sstevel@tonic-gate 		mdb_printf("%6s %10s %?s %s%</u>\n",
2087c478bd9Sstevel@tonic-gate 		    "UID", "FLAGS", "ADDR", "NAME");
2097c478bd9Sstevel@tonic-gate 	}
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	mdb_vread(&pr, sizeof (pr), addr);
2127c478bd9Sstevel@tonic-gate 	mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp);
2137c478bd9Sstevel@tonic-gate 	mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp);
2147c478bd9Sstevel@tonic-gate 	mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred);
2157c478bd9Sstevel@tonic-gate 	mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp);
2167c478bd9Sstevel@tonic-gate 	mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp);
2177c478bd9Sstevel@tonic-gate 	if (prt_flags & (PS_TASKS | PS_PROJECTS))
2187c478bd9Sstevel@tonic-gate 		mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task);
2197c478bd9Sstevel@tonic-gate 	if (prt_flags & PS_PROJECTS)
2207c478bd9Sstevel@tonic-gate 		mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj);
2217c478bd9Sstevel@tonic-gate 	if (prt_flags & PS_ZONES)
2227c478bd9Sstevel@tonic-gate 		mdb_vread(&zn, sizeof (zone_t), (uintptr_t)pr.p_zone);
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	mdb_printf("%c %6d %6d %6d %6d ",
2257c478bd9Sstevel@tonic-gate 	    pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id,
2267c478bd9Sstevel@tonic-gate 	    sid.pid_id);
2277c478bd9Sstevel@tonic-gate 	if (prt_flags & PS_TASKS)
2287c478bd9Sstevel@tonic-gate 		mdb_printf("%5d ", tk.tk_tkid);
2297c478bd9Sstevel@tonic-gate 	if (prt_flags & PS_PROJECTS)
2307c478bd9Sstevel@tonic-gate 		mdb_printf("%5d ", pj.kpj_id);
2317c478bd9Sstevel@tonic-gate 	if (prt_flags & PS_ZONES)
2327c478bd9Sstevel@tonic-gate 		mdb_printf("%5d ", zn.zone_id);
2337c478bd9Sstevel@tonic-gate 	mdb_printf("%6d 0x%08x %0?p %s\n",
2347c478bd9Sstevel@tonic-gate 	    cred.cr_uid, pr.p_flag, addr,
2357c478bd9Sstevel@tonic-gate 	    (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm);
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 	if (prt_flags & ~PS_PSARGS)
2387c478bd9Sstevel@tonic-gate 		(void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr);
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate #define	PG_NEWEST	0x0001
2447c478bd9Sstevel@tonic-gate #define	PG_OLDEST	0x0002
2457c478bd9Sstevel@tonic-gate #define	PG_PIPE_OUT	0x0004
246adb664e2Svb #define	PG_EXACT_MATCH	0x0008
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate typedef struct pgrep_data {
2497c478bd9Sstevel@tonic-gate 	uint_t pg_flags;
2507c478bd9Sstevel@tonic-gate 	uint_t pg_psflags;
2517c478bd9Sstevel@tonic-gate 	uintptr_t pg_xaddr;
2527c478bd9Sstevel@tonic-gate 	hrtime_t pg_xstart;
2537c478bd9Sstevel@tonic-gate 	const char *pg_pat;
2547c478bd9Sstevel@tonic-gate #ifndef _KMDB
2557c478bd9Sstevel@tonic-gate 	regex_t pg_reg;
2567c478bd9Sstevel@tonic-gate #endif
2577c478bd9Sstevel@tonic-gate } pgrep_data_t;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2607c478bd9Sstevel@tonic-gate static int
2617c478bd9Sstevel@tonic-gate pgrep_cb(uintptr_t addr, const void *pdata, void *data)
2627c478bd9Sstevel@tonic-gate {
2637c478bd9Sstevel@tonic-gate 	const proc_t *prp = pdata;
2647c478bd9Sstevel@tonic-gate 	pgrep_data_t *pgp = data;
2657c478bd9Sstevel@tonic-gate #ifndef _KMDB
2667c478bd9Sstevel@tonic-gate 	regmatch_t pmatch;
2677c478bd9Sstevel@tonic-gate #endif
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	/*
2707c478bd9Sstevel@tonic-gate 	 * kmdb doesn't have access to the reg* functions, so we fall back
271adb664e2Svb 	 * to strstr/strcmp.
2727c478bd9Sstevel@tonic-gate 	 */
2737c478bd9Sstevel@tonic-gate #ifdef _KMDB
274adb664e2Svb 	if ((pgp->pg_flags & PG_EXACT_MATCH) ?
275adb664e2Svb 	    (strcmp(prp->p_user.u_comm, pgp->pg_pat) != 0) :
276adb664e2Svb 	    (strstr(prp->p_user.u_comm, pgp->pg_pat) == NULL))
2777c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
2787c478bd9Sstevel@tonic-gate #else
2797c478bd9Sstevel@tonic-gate 	if (regexec(&pgp->pg_reg, prp->p_user.u_comm, 1, &pmatch, 0) != 0)
2807c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
281adb664e2Svb 
282adb664e2Svb 	if ((pgp->pg_flags & PG_EXACT_MATCH) &&
283adb664e2Svb 	    (pmatch.rm_so != 0 || prp->p_user.u_comm[pmatch.rm_eo] != '\0'))
284adb664e2Svb 		return (WALK_NEXT);
2857c478bd9Sstevel@tonic-gate #endif
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	if (pgp->pg_flags & (PG_NEWEST | PG_OLDEST)) {
2887c478bd9Sstevel@tonic-gate 		hrtime_t start;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 		start = (hrtime_t)prp->p_user.u_start.tv_sec * NANOSEC +
2917c478bd9Sstevel@tonic-gate 		    prp->p_user.u_start.tv_nsec;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 		if (pgp->pg_flags & PG_NEWEST) {
2947c478bd9Sstevel@tonic-gate 			if (pgp->pg_xaddr == NULL || start > pgp->pg_xstart) {
2957c478bd9Sstevel@tonic-gate 				pgp->pg_xaddr = addr;
2967c478bd9Sstevel@tonic-gate 				pgp->pg_xstart = start;
2977c478bd9Sstevel@tonic-gate 			}
2987c478bd9Sstevel@tonic-gate 		} else {
2997c478bd9Sstevel@tonic-gate 			if (pgp->pg_xaddr == NULL || start < pgp->pg_xstart) {
3007c478bd9Sstevel@tonic-gate 				pgp->pg_xaddr = addr;
3017c478bd9Sstevel@tonic-gate 				pgp->pg_xstart = start;
3027c478bd9Sstevel@tonic-gate 			}
3037c478bd9Sstevel@tonic-gate 		}
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	} else if (pgp->pg_flags & PG_PIPE_OUT) {
3067c478bd9Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	} else {
3097c478bd9Sstevel@tonic-gate 		if (mdb_call_dcmd("ps", addr, pgp->pg_psflags, 0, NULL) != 0) {
3107c478bd9Sstevel@tonic-gate 			mdb_warn("can't invoke 'ps'");
3117c478bd9Sstevel@tonic-gate 			return (WALK_DONE);
3127c478bd9Sstevel@tonic-gate 		}
3137c478bd9Sstevel@tonic-gate 		pgp->pg_psflags &= ~DCMD_LOOPFIRST;
3147c478bd9Sstevel@tonic-gate 	}
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3207c478bd9Sstevel@tonic-gate int
3217c478bd9Sstevel@tonic-gate pgrep(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3227c478bd9Sstevel@tonic-gate {
3237c478bd9Sstevel@tonic-gate 	pgrep_data_t pg;
3247c478bd9Sstevel@tonic-gate 	int i;
3257c478bd9Sstevel@tonic-gate #ifndef _KMDB
3267c478bd9Sstevel@tonic-gate 	int err;
3277c478bd9Sstevel@tonic-gate #endif
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
3307c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	pg.pg_flags = 0;
3337c478bd9Sstevel@tonic-gate 	pg.pg_xaddr = 0;
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	i = mdb_getopts(argc, argv,
3367c478bd9Sstevel@tonic-gate 	    'n', MDB_OPT_SETBITS, PG_NEWEST, &pg.pg_flags,
3377c478bd9Sstevel@tonic-gate 	    'o', MDB_OPT_SETBITS, PG_OLDEST, &pg.pg_flags,
338adb664e2Svb 	    'x', MDB_OPT_SETBITS, PG_EXACT_MATCH, &pg.pg_flags,
3397c478bd9Sstevel@tonic-gate 	    NULL);
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	argc -= i;
3427c478bd9Sstevel@tonic-gate 	argv += i;
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 	if (argc != 1)
3457c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	/*
3487c478bd9Sstevel@tonic-gate 	 * -n and -o are mutually exclusive.
3497c478bd9Sstevel@tonic-gate 	 */
3507c478bd9Sstevel@tonic-gate 	if ((pg.pg_flags & PG_NEWEST) && (pg.pg_flags & PG_OLDEST))
3517c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 	if (argv->a_type != MDB_TYPE_STRING)
3547c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	if (flags & DCMD_PIPE_OUT)
3577c478bd9Sstevel@tonic-gate 		pg.pg_flags |= PG_PIPE_OUT;
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	pg.pg_pat = argv->a_un.a_str;
3607c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
3617c478bd9Sstevel@tonic-gate 		pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP | DCMD_LOOPFIRST;
3627c478bd9Sstevel@tonic-gate 	else
3637c478bd9Sstevel@tonic-gate 		pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP;
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate #ifndef _KMDB
3667c478bd9Sstevel@tonic-gate 	if ((err = regcomp(&pg.pg_reg, pg.pg_pat, REG_EXTENDED)) != 0) {
3677c478bd9Sstevel@tonic-gate 		size_t nbytes;
3687c478bd9Sstevel@tonic-gate 		char *buf;
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 		nbytes = regerror(err, &pg.pg_reg, NULL, 0);
3717c478bd9Sstevel@tonic-gate 		buf = mdb_alloc(nbytes + 1, UM_SLEEP | UM_GC);
3727c478bd9Sstevel@tonic-gate 		(void) regerror(err, &pg.pg_reg, buf, nbytes);
3737c478bd9Sstevel@tonic-gate 		mdb_warn("%s\n", buf);
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
3767c478bd9Sstevel@tonic-gate 	}
3777c478bd9Sstevel@tonic-gate #endif
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 	if (mdb_walk("proc", pgrep_cb, &pg) != 0) {
3807c478bd9Sstevel@tonic-gate 		mdb_warn("can't walk 'proc'");
3817c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
3827c478bd9Sstevel@tonic-gate 	}
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	if (pg.pg_xaddr != 0 && (pg.pg_flags & (PG_NEWEST | PG_OLDEST))) {
3857c478bd9Sstevel@tonic-gate 		if (pg.pg_flags & PG_PIPE_OUT) {
3867c478bd9Sstevel@tonic-gate 			mdb_printf("%p\n", pg.pg_xaddr);
3877c478bd9Sstevel@tonic-gate 		} else {
3887c478bd9Sstevel@tonic-gate 			if (mdb_call_dcmd("ps", pg.pg_xaddr, pg.pg_psflags,
3897c478bd9Sstevel@tonic-gate 			    0, NULL) != 0) {
3907c478bd9Sstevel@tonic-gate 				mdb_warn("can't invoke 'ps'");
3917c478bd9Sstevel@tonic-gate 				return (DCMD_ERR);
3927c478bd9Sstevel@tonic-gate 			}
3937c478bd9Sstevel@tonic-gate 		}
3947c478bd9Sstevel@tonic-gate 	}
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate int
4007c478bd9Sstevel@tonic-gate task(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4017c478bd9Sstevel@tonic-gate {
4027c478bd9Sstevel@tonic-gate 	task_t tk;
4037c478bd9Sstevel@tonic-gate 	kproject_t pj;
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
4067c478bd9Sstevel@tonic-gate 		if (mdb_walk_dcmd("task_cache", "task", argc, argv) == -1) {
4077c478bd9Sstevel@tonic-gate 			mdb_warn("can't walk task_cache");
4087c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
4097c478bd9Sstevel@tonic-gate 		}
4107c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
4117c478bd9Sstevel@tonic-gate 	}
4127c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
4137c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%?s %6s %6s %6s %6s %10s%</u>\n",
4147c478bd9Sstevel@tonic-gate 		    "ADDR", "TASKID", "PROJID", "ZONEID", "REFCNT", "FLAGS");
4157c478bd9Sstevel@tonic-gate 	}
4167c478bd9Sstevel@tonic-gate 	if (mdb_vread(&tk, sizeof (task_t), addr) == -1) {
4177c478bd9Sstevel@tonic-gate 		mdb_warn("can't read task_t structure at %p", addr);
4187c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4197c478bd9Sstevel@tonic-gate 	}
4207c478bd9Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), (uintptr_t)tk.tk_proj) == -1) {
4217c478bd9Sstevel@tonic-gate 		mdb_warn("can't read project_t structure at %p", addr);
4227c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4237c478bd9Sstevel@tonic-gate 	}
4247c478bd9Sstevel@tonic-gate 	mdb_printf("%0?p %6d %6d %6d %6u 0x%08x\n",
4257c478bd9Sstevel@tonic-gate 	    addr, tk.tk_tkid, pj.kpj_id, pj.kpj_zoneid, tk.tk_hold_count,
4267c478bd9Sstevel@tonic-gate 	    tk.tk_flags);
4277c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
4287c478bd9Sstevel@tonic-gate }
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate int
4317c478bd9Sstevel@tonic-gate project(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4327c478bd9Sstevel@tonic-gate {
4337c478bd9Sstevel@tonic-gate 	kproject_t pj;
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
4367c478bd9Sstevel@tonic-gate 		if (mdb_walk_dcmd("projects", "project", argc, argv) == -1) {
4377c478bd9Sstevel@tonic-gate 			mdb_warn("can't walk projects");
4387c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
4397c478bd9Sstevel@tonic-gate 		}
4407c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
4417c478bd9Sstevel@tonic-gate 	}
4427c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
4437c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%?s %6s %6s %6s%</u>\n",
4447c478bd9Sstevel@tonic-gate 		    "ADDR", "PROJID", "ZONEID", "REFCNT");
4457c478bd9Sstevel@tonic-gate 	}
4467c478bd9Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
4477c478bd9Sstevel@tonic-gate 		mdb_warn("can't read kproject_t structure at %p", addr);
4487c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4497c478bd9Sstevel@tonic-gate 	}
4507c478bd9Sstevel@tonic-gate 	mdb_printf("%0?p %6d %6d %6u\n", addr, pj.kpj_id, pj.kpj_zoneid,
4517c478bd9Sstevel@tonic-gate 	    pj.kpj_count);
4527c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
4537c478bd9Sstevel@tonic-gate }
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4567c478bd9Sstevel@tonic-gate int
4577c478bd9Sstevel@tonic-gate callout(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4587c478bd9Sstevel@tonic-gate {
4597c478bd9Sstevel@tonic-gate 	callout_table_t	*co_ktable[CALLOUT_TABLES];
4607c478bd9Sstevel@tonic-gate 	int co_kfanout;
4617c478bd9Sstevel@tonic-gate 	callout_table_t co_table;
4627c478bd9Sstevel@tonic-gate 	callout_t co_callout;
4637c478bd9Sstevel@tonic-gate 	callout_t *co_ptr;
4647c478bd9Sstevel@tonic-gate 	int co_id;
4657c478bd9Sstevel@tonic-gate 	clock_t lbolt;
4667c478bd9Sstevel@tonic-gate 	int i, j, k;
4677c478bd9Sstevel@tonic-gate 	const char *lbolt_sym;
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) || argc != 0)
4707c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	if (mdb_prop_postmortem)
4737c478bd9Sstevel@tonic-gate 		lbolt_sym = "panic_lbolt";
4747c478bd9Sstevel@tonic-gate 	else
4757c478bd9Sstevel@tonic-gate 		lbolt_sym = "lbolt";
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&lbolt, lbolt_sym) == -1) {
4787c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read '%s'", lbolt_sym);
4797c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4807c478bd9Sstevel@tonic-gate 	}
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&co_kfanout, "callout_fanout") == -1) {
4837c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read callout_fanout");
4847c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4857c478bd9Sstevel@tonic-gate 	}
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&co_ktable, "callout_table") == -1) {
4887c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read callout_table");
4897c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4907c478bd9Sstevel@tonic-gate 	}
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 	mdb_printf("%<u>%-24s %-?s %-?s %-?s%</u>\n",
4937c478bd9Sstevel@tonic-gate 	    "FUNCTION", "ARGUMENT", "ID", "TIME");
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate 	for (i = 0; i < CALLOUT_NTYPES; i++) {
4967c478bd9Sstevel@tonic-gate 		for (j = 0; j < co_kfanout; j++) {
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 			co_id = CALLOUT_TABLE(i, j);
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate 			if (mdb_vread(&co_table, sizeof (co_table),
5017c478bd9Sstevel@tonic-gate 			    (uintptr_t)co_ktable[co_id]) == -1) {
5027c478bd9Sstevel@tonic-gate 				mdb_warn("failed to read table at %p",
5037c478bd9Sstevel@tonic-gate 				    (uintptr_t)co_ktable[co_id]);
5047c478bd9Sstevel@tonic-gate 				continue;
5057c478bd9Sstevel@tonic-gate 			}
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 			for (k = 0; k < CALLOUT_BUCKETS; k++) {
5087c478bd9Sstevel@tonic-gate 				co_ptr = co_table.ct_idhash[k];
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 				while (co_ptr != NULL) {
5117c478bd9Sstevel@tonic-gate 					mdb_vread(&co_callout,
5127c478bd9Sstevel@tonic-gate 					    sizeof (co_callout),
5137c478bd9Sstevel@tonic-gate 					    (uintptr_t)co_ptr);
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 					mdb_printf("%-24a %0?p %0?lx %?lx "
5167c478bd9Sstevel@tonic-gate 					    "(T%+ld)\n", co_callout.c_func,
5177c478bd9Sstevel@tonic-gate 					    co_callout.c_arg, co_callout.c_xid,
5187c478bd9Sstevel@tonic-gate 					    co_callout.c_runtime,
5197c478bd9Sstevel@tonic-gate 					    co_callout.c_runtime - lbolt);
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 					co_ptr = co_callout.c_idnext;
5227c478bd9Sstevel@tonic-gate 				}
5237c478bd9Sstevel@tonic-gate 			}
5247c478bd9Sstevel@tonic-gate 		}
5257c478bd9Sstevel@tonic-gate 	}
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
5287c478bd9Sstevel@tonic-gate }
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5317c478bd9Sstevel@tonic-gate int
5327c478bd9Sstevel@tonic-gate class(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5337c478bd9Sstevel@tonic-gate {
5347c478bd9Sstevel@tonic-gate 	long num_classes, i;
5357c478bd9Sstevel@tonic-gate 	sclass_t *class_tbl;
5367c478bd9Sstevel@tonic-gate 	GElf_Sym g_sclass;
5377c478bd9Sstevel@tonic-gate 	char class_name[PC_CLNMSZ];
5387c478bd9Sstevel@tonic-gate 	size_t tbl_size;
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("sclass", &g_sclass) == -1) {
5417c478bd9Sstevel@tonic-gate 		mdb_warn("failed to find symbol sclass\n");
5427c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5437c478bd9Sstevel@tonic-gate 	}
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	tbl_size = (size_t)g_sclass.st_size;
5467c478bd9Sstevel@tonic-gate 	num_classes = tbl_size / (sizeof (sclass_t));
5477c478bd9Sstevel@tonic-gate 	class_tbl = mdb_alloc(tbl_size, UM_SLEEP | UM_GC);
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	if (mdb_readsym(class_tbl, tbl_size, "sclass") == -1) {
5507c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read sclass");
5517c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5527c478bd9Sstevel@tonic-gate 	}
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 	mdb_printf("%<u>%4s %-10s %-24s %-24s%</u>\n", "SLOT", "NAME",
5557c478bd9Sstevel@tonic-gate 	    "INIT FCN", "CLASS FCN");
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate 	for (i = 0; i < num_classes; i++) {
5587c478bd9Sstevel@tonic-gate 		if (mdb_vread(class_name, sizeof (class_name),
5597c478bd9Sstevel@tonic-gate 		    (uintptr_t)class_tbl[i].cl_name) == -1)
5607c478bd9Sstevel@tonic-gate 			(void) strcpy(class_name, "???");
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 		mdb_printf("%4ld %-10s %-24a %-24a\n", i, class_name,
5637c478bd9Sstevel@tonic-gate 		    class_tbl[i].cl_init, class_tbl[i].cl_funcs);
5647c478bd9Sstevel@tonic-gate 	}
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
5677c478bd9Sstevel@tonic-gate }
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate #define	FSNAMELEN	32	/* Max len of FS name we read from vnodeops */
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate int
5727c478bd9Sstevel@tonic-gate vnode2path(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5737c478bd9Sstevel@tonic-gate {
5747c478bd9Sstevel@tonic-gate 	uintptr_t rootdir;
5757c478bd9Sstevel@tonic-gate 	vnode_t vn;
5767c478bd9Sstevel@tonic-gate 	char buf[MAXPATHLEN];
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate 	uint_t opt_F = FALSE;
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
5817c478bd9Sstevel@tonic-gate 	    'F', MDB_OPT_SETBITS, TRUE, &opt_F, NULL) != argc)
5827c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
5857c478bd9Sstevel@tonic-gate 		mdb_warn("expected explicit vnode_t address before ::\n");
5867c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
5877c478bd9Sstevel@tonic-gate 	}
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&rootdir, "rootdir") == -1) {
5907c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read rootdir");
5917c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5927c478bd9Sstevel@tonic-gate 	}
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 	if (mdb_vnode2path(addr, buf, sizeof (buf)) == -1)
5957c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 	if (*buf == '\0') {
5987c478bd9Sstevel@tonic-gate 		mdb_printf("??\n");
5997c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
6007c478bd9Sstevel@tonic-gate 	}
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate 	mdb_printf("%s", buf);
6037c478bd9Sstevel@tonic-gate 	if (opt_F && buf[strlen(buf)-1] != '/' &&
6047c478bd9Sstevel@tonic-gate 	    mdb_vread(&vn, sizeof (vn), addr) == sizeof (vn))
6057c478bd9Sstevel@tonic-gate 		mdb_printf("%c", mdb_vtype2chr(vn.v_type, 0));
6067c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate int
6127c478bd9Sstevel@tonic-gate ld_walk_init(mdb_walk_state_t *wsp)
6137c478bd9Sstevel@tonic-gate {
6147c478bd9Sstevel@tonic-gate 	wsp->walk_data = (void *)wsp->walk_addr;
6157c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
6167c478bd9Sstevel@tonic-gate }
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate int
6197c478bd9Sstevel@tonic-gate ld_walk_step(mdb_walk_state_t *wsp)
6207c478bd9Sstevel@tonic-gate {
6217c478bd9Sstevel@tonic-gate 	int status;
6227c478bd9Sstevel@tonic-gate 	lock_descriptor_t ld;
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ld, sizeof (lock_descriptor_t), wsp->walk_addr) == -1) {
6257c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't read lock_descriptor_t at %p\n",
6267c478bd9Sstevel@tonic-gate 		    wsp->walk_addr);
6277c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
6287c478bd9Sstevel@tonic-gate 	}
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, &ld, wsp->walk_cbdata);
6317c478bd9Sstevel@tonic-gate 	if (status == WALK_ERR)
6327c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)ld.l_next;
6357c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data)
6367c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate 	return (status);
6397c478bd9Sstevel@tonic-gate }
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate int
6427c478bd9Sstevel@tonic-gate lg_walk_init(mdb_walk_state_t *wsp)
6437c478bd9Sstevel@tonic-gate {
6447c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("lock_graph", &sym) == -1) {
6477c478bd9Sstevel@tonic-gate 		mdb_warn("failed to find symbol 'lock_graph'\n");
6487c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
6497c478bd9Sstevel@tonic-gate 	}
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)sym.st_value;
65289518a1cSdmick 	wsp->walk_data = (void *)(uintptr_t)(sym.st_value + sym.st_size);
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
6557c478bd9Sstevel@tonic-gate }
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate typedef struct lg_walk_data {
6587c478bd9Sstevel@tonic-gate 	uintptr_t startaddr;
6597c478bd9Sstevel@tonic-gate 	mdb_walk_cb_t callback;
6607c478bd9Sstevel@tonic-gate 	void *data;
6617c478bd9Sstevel@tonic-gate } lg_walk_data_t;
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate /*
6647c478bd9Sstevel@tonic-gate  * We can't use ::walk lock_descriptor directly, because the head of each graph
6657c478bd9Sstevel@tonic-gate  * is really a dummy lock.  Rather than trying to dynamically determine if this
6667c478bd9Sstevel@tonic-gate  * is a dummy node or not, we just filter out the initial element of the
6677c478bd9Sstevel@tonic-gate  * list.
6687c478bd9Sstevel@tonic-gate  */
6697c478bd9Sstevel@tonic-gate static int
6707c478bd9Sstevel@tonic-gate lg_walk_cb(uintptr_t addr, const void *data, void *priv)
6717c478bd9Sstevel@tonic-gate {
6727c478bd9Sstevel@tonic-gate 	lg_walk_data_t *lw = priv;
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 	if (addr != lw->startaddr)
6757c478bd9Sstevel@tonic-gate 		return (lw->callback(addr, data, lw->data));
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
6787c478bd9Sstevel@tonic-gate }
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate int
6817c478bd9Sstevel@tonic-gate lg_walk_step(mdb_walk_state_t *wsp)
6827c478bd9Sstevel@tonic-gate {
6837c478bd9Sstevel@tonic-gate 	graph_t *graph;
6847c478bd9Sstevel@tonic-gate 	lg_walk_data_t lw;
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr >= (uintptr_t)wsp->walk_data)
6877c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate 	if (mdb_vread(&graph, sizeof (graph), wsp->walk_addr) == -1) {
6907c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read graph_t at %p", wsp->walk_addr);
6917c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
6927c478bd9Sstevel@tonic-gate 	}
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate 	wsp->walk_addr += sizeof (graph);
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate 	if (graph == NULL)
6977c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
6987c478bd9Sstevel@tonic-gate 
6997c478bd9Sstevel@tonic-gate 	lw.callback = wsp->walk_callback;
7007c478bd9Sstevel@tonic-gate 	lw.data = wsp->walk_cbdata;
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate 	lw.startaddr = (uintptr_t)&(graph->active_locks);
7037c478bd9Sstevel@tonic-gate 	if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
7047c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
7057c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
7067c478bd9Sstevel@tonic-gate 	}
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate 	lw.startaddr = (uintptr_t)&(graph->sleeping_locks);
7097c478bd9Sstevel@tonic-gate 	if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
7107c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
7117c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
7127c478bd9Sstevel@tonic-gate 	}
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
7157c478bd9Sstevel@tonic-gate }
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate /*
7187c478bd9Sstevel@tonic-gate  * The space available for the path corresponding to the locked vnode depends
7197c478bd9Sstevel@tonic-gate  * on whether we are printing 32- or 64-bit addresses.
7207c478bd9Sstevel@tonic-gate  */
7217c478bd9Sstevel@tonic-gate #ifdef _LP64
7227c478bd9Sstevel@tonic-gate #define	LM_VNPATHLEN	20
7237c478bd9Sstevel@tonic-gate #else
7247c478bd9Sstevel@tonic-gate #define	LM_VNPATHLEN	30
7257c478bd9Sstevel@tonic-gate #endif
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7287c478bd9Sstevel@tonic-gate static int
7297c478bd9Sstevel@tonic-gate lminfo_cb(uintptr_t addr, const void *data, void *priv)
7307c478bd9Sstevel@tonic-gate {
7317c478bd9Sstevel@tonic-gate 	const lock_descriptor_t *ld = data;
7327c478bd9Sstevel@tonic-gate 	char buf[LM_VNPATHLEN];
7337c478bd9Sstevel@tonic-gate 	proc_t p;
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate 	mdb_printf("%-?p %2s %04x %6d %-16s %-?p ",
7367c478bd9Sstevel@tonic-gate 	    addr, ld->l_type == F_RDLCK ? "RD" :
7377c478bd9Sstevel@tonic-gate 	    ld->l_type == F_WRLCK ? "WR" : "??",
7387c478bd9Sstevel@tonic-gate 	    ld->l_state, ld->l_flock.l_pid,
7397c478bd9Sstevel@tonic-gate 	    ld->l_flock.l_pid == 0 ? "<kernel>" :
7407c478bd9Sstevel@tonic-gate 	    mdb_pid2proc(ld->l_flock.l_pid, &p) == NULL ?
7417c478bd9Sstevel@tonic-gate 	    "<defunct>" : p.p_user.u_comm,
7427c478bd9Sstevel@tonic-gate 	    ld->l_vnode);
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 	mdb_vnode2path((uintptr_t)ld->l_vnode, buf,
7457c478bd9Sstevel@tonic-gate 	    sizeof (buf));
7467c478bd9Sstevel@tonic-gate 	mdb_printf("%s\n", buf);
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
7497c478bd9Sstevel@tonic-gate }
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7527c478bd9Sstevel@tonic-gate int
7537c478bd9Sstevel@tonic-gate lminfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7547c478bd9Sstevel@tonic-gate {
7557c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
7567c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%-?s %2s %4s %6s %-16s %-?s %s%</u>\n",
7577c478bd9Sstevel@tonic-gate 		    "ADDR", "TP", "FLAG", "PID", "COMM", "VNODE", "PATH");
7587c478bd9Sstevel@tonic-gate 
7597c478bd9Sstevel@tonic-gate 	return (mdb_pwalk("lock_graph", lminfo_cb, NULL, NULL));
7607c478bd9Sstevel@tonic-gate }
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7637c478bd9Sstevel@tonic-gate int
7647c478bd9Sstevel@tonic-gate seg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7657c478bd9Sstevel@tonic-gate {
7667c478bd9Sstevel@tonic-gate 	struct seg s;
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate 	if (argc != 0)
7697c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
7727c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%?s %?s %?s %?s %s%</u>\n",
7737c478bd9Sstevel@tonic-gate 		    "SEG", "BASE", "SIZE", "DATA", "OPS");
7747c478bd9Sstevel@tonic-gate 	}
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate 	if (mdb_vread(&s, sizeof (s), addr) == -1) {
7777c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read seg at %p", addr);
7787c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
7797c478bd9Sstevel@tonic-gate 	}
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate 	mdb_printf("%?p %?p %?lx %?p %a\n",
7827c478bd9Sstevel@tonic-gate 	    addr, s.s_base, s.s_size, s.s_data, s.s_ops);
7837c478bd9Sstevel@tonic-gate 
7847c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
7857c478bd9Sstevel@tonic-gate }
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7887c478bd9Sstevel@tonic-gate static int
7897c478bd9Sstevel@tonic-gate pmap_walk_anon(uintptr_t addr, const struct anon *anon, int *nres)
7907c478bd9Sstevel@tonic-gate {
7917c478bd9Sstevel@tonic-gate 	uintptr_t pp =
7927c478bd9Sstevel@tonic-gate 	    mdb_vnode2page((uintptr_t)anon->an_vp, (uintptr_t)anon->an_off);
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 	if (pp != NULL)
7957c478bd9Sstevel@tonic-gate 		(*nres)++;
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
7987c478bd9Sstevel@tonic-gate }
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate static int
8017c478bd9Sstevel@tonic-gate pmap_walk_seg(uintptr_t addr, const struct seg *seg, uintptr_t segvn)
8027c478bd9Sstevel@tonic-gate {
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 	mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024);
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate 	if (segvn == (uintptr_t)seg->s_ops) {
8077c478bd9Sstevel@tonic-gate 		struct segvn_data svn;
8087c478bd9Sstevel@tonic-gate 		int nres = 0;
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate 		(void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data);
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate 		if (svn.amp == NULL) {
8137c478bd9Sstevel@tonic-gate 			mdb_printf(" %8s", "");
8147c478bd9Sstevel@tonic-gate 			goto drive_on;
8157c478bd9Sstevel@tonic-gate 		}
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate 		/*
8187c478bd9Sstevel@tonic-gate 		 * We've got an amp for this segment; walk through
8197c478bd9Sstevel@tonic-gate 		 * the amp, and determine mappings.
8207c478bd9Sstevel@tonic-gate 		 */
8217c478bd9Sstevel@tonic-gate 		if (mdb_pwalk("anon", (mdb_walk_cb_t)pmap_walk_anon,
8227c478bd9Sstevel@tonic-gate 		    &nres, (uintptr_t)svn.amp) == -1)
8237c478bd9Sstevel@tonic-gate 			mdb_warn("failed to walk anon (amp=%p)", svn.amp);
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate 		mdb_printf(" %7dk", (nres * PAGESIZE) / 1024);
8267c478bd9Sstevel@tonic-gate drive_on:
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate 		if (svn.vp != NULL) {
8297c478bd9Sstevel@tonic-gate 			char buf[29];
8307c478bd9Sstevel@tonic-gate 
8317c478bd9Sstevel@tonic-gate 			mdb_vnode2path((uintptr_t)svn.vp, buf, sizeof (buf));
8327c478bd9Sstevel@tonic-gate 			mdb_printf(" %s", buf);
8337c478bd9Sstevel@tonic-gate 		} else
8347c478bd9Sstevel@tonic-gate 			mdb_printf(" [ anon ]");
8357c478bd9Sstevel@tonic-gate 	}
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
8387c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
8397c478bd9Sstevel@tonic-gate }
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate static int
8427c478bd9Sstevel@tonic-gate pmap_walk_seg_quick(uintptr_t addr, const struct seg *seg, uintptr_t segvn)
8437c478bd9Sstevel@tonic-gate {
8447c478bd9Sstevel@tonic-gate 	mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024);
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate 	if (segvn == (uintptr_t)seg->s_ops) {
8477c478bd9Sstevel@tonic-gate 		struct segvn_data svn;
8487c478bd9Sstevel@tonic-gate 
8497c478bd9Sstevel@tonic-gate 		(void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data);
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate 		if (svn.vp != NULL) {
8527c478bd9Sstevel@tonic-gate 			mdb_printf(" %0?p", svn.vp);
8537c478bd9Sstevel@tonic-gate 		} else {
8547c478bd9Sstevel@tonic-gate 			mdb_printf(" [ anon ]");
8557c478bd9Sstevel@tonic-gate 		}
8567c478bd9Sstevel@tonic-gate 	}
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
8597c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
8607c478bd9Sstevel@tonic-gate }
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8637c478bd9Sstevel@tonic-gate int
8647c478bd9Sstevel@tonic-gate pmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
8657c478bd9Sstevel@tonic-gate {
8667c478bd9Sstevel@tonic-gate 	uintptr_t segvn;
8677c478bd9Sstevel@tonic-gate 	proc_t proc;
8687c478bd9Sstevel@tonic-gate 	uint_t quick = FALSE;
8697c478bd9Sstevel@tonic-gate 	mdb_walk_cb_t cb = (mdb_walk_cb_t)pmap_walk_seg;
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
8727c478bd9Sstevel@tonic-gate 
8737c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
8747c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
8777c478bd9Sstevel@tonic-gate 	    'q', MDB_OPT_SETBITS, TRUE, &quick, NULL) != argc)
8787c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 	if (mdb_vread(&proc, sizeof (proc), addr) == -1) {
8817c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", addr);
8827c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
8837c478bd9Sstevel@tonic-gate 	}
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("segvn_ops", &sym) == 0)
8867c478bd9Sstevel@tonic-gate 		segvn = (uintptr_t)sym.st_value;
8877c478bd9Sstevel@tonic-gate 	else
8887c478bd9Sstevel@tonic-gate 		segvn = NULL;
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 	mdb_printf("%?s %?s %8s ", "SEG", "BASE", "SIZE");
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate 	if (quick) {
8937c478bd9Sstevel@tonic-gate 		mdb_printf("VNODE\n");
8947c478bd9Sstevel@tonic-gate 		cb = (mdb_walk_cb_t)pmap_walk_seg_quick;
8957c478bd9Sstevel@tonic-gate 	} else {
8967c478bd9Sstevel@tonic-gate 		mdb_printf("%8s %s\n", "RES", "PATH");
8977c478bd9Sstevel@tonic-gate 	}
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate 	if (mdb_pwalk("seg", cb, (void *)segvn, (uintptr_t)proc.p_as) == -1) {
9007c478bd9Sstevel@tonic-gate 		mdb_warn("failed to walk segments of as %p", proc.p_as);
9017c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
9027c478bd9Sstevel@tonic-gate 	}
9037c478bd9Sstevel@tonic-gate 
9047c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
9057c478bd9Sstevel@tonic-gate }
9067c478bd9Sstevel@tonic-gate 
9077c478bd9Sstevel@tonic-gate typedef struct anon_walk_data {
9087c478bd9Sstevel@tonic-gate 	uintptr_t *aw_levone;
9097c478bd9Sstevel@tonic-gate 	uintptr_t *aw_levtwo;
9107c478bd9Sstevel@tonic-gate 	int aw_nlevone;
9117c478bd9Sstevel@tonic-gate 	int aw_levone_ndx;
9127c478bd9Sstevel@tonic-gate 	int aw_levtwo_ndx;
9137c478bd9Sstevel@tonic-gate 	struct anon_map aw_amp;
9147c478bd9Sstevel@tonic-gate 	struct anon_hdr aw_ahp;
9157c478bd9Sstevel@tonic-gate } anon_walk_data_t;
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate int
9187c478bd9Sstevel@tonic-gate anon_walk_init(mdb_walk_state_t *wsp)
9197c478bd9Sstevel@tonic-gate {
9207c478bd9Sstevel@tonic-gate 	anon_walk_data_t *aw;
9217c478bd9Sstevel@tonic-gate 
9227c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
9237c478bd9Sstevel@tonic-gate 		mdb_warn("anon walk doesn't support global walks\n");
9247c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
9257c478bd9Sstevel@tonic-gate 	}
9267c478bd9Sstevel@tonic-gate 
9277c478bd9Sstevel@tonic-gate 	aw = mdb_alloc(sizeof (anon_walk_data_t), UM_SLEEP);
9287c478bd9Sstevel@tonic-gate 
9297c478bd9Sstevel@tonic-gate 	if (mdb_vread(&aw->aw_amp, sizeof (aw->aw_amp), wsp->walk_addr) == -1) {
9307c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read anon map at %p", wsp->walk_addr);
9317c478bd9Sstevel@tonic-gate 		mdb_free(aw, sizeof (anon_walk_data_t));
9327c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
9337c478bd9Sstevel@tonic-gate 	}
9347c478bd9Sstevel@tonic-gate 
9357c478bd9Sstevel@tonic-gate 	if (mdb_vread(&aw->aw_ahp, sizeof (aw->aw_ahp),
9367c478bd9Sstevel@tonic-gate 	    (uintptr_t)(aw->aw_amp.ahp)) == -1) {
9377c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read anon hdr ptr at %p", aw->aw_amp.ahp);
9387c478bd9Sstevel@tonic-gate 		mdb_free(aw, sizeof (anon_walk_data_t));
9397c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
9407c478bd9Sstevel@tonic-gate 	}
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 	if (aw->aw_ahp.size <= ANON_CHUNK_SIZE ||
9437c478bd9Sstevel@tonic-gate 	    (aw->aw_ahp.flags & ANON_ALLOC_FORCE)) {
9447c478bd9Sstevel@tonic-gate 		aw->aw_nlevone = aw->aw_ahp.size;
9457c478bd9Sstevel@tonic-gate 		aw->aw_levtwo = NULL;
9467c478bd9Sstevel@tonic-gate 	} else {
9477c478bd9Sstevel@tonic-gate 		aw->aw_nlevone =
9487c478bd9Sstevel@tonic-gate 		    (aw->aw_ahp.size + ANON_CHUNK_OFF) >> ANON_CHUNK_SHIFT;
9497c478bd9Sstevel@tonic-gate 		aw->aw_levtwo =
9507c478bd9Sstevel@tonic-gate 		    mdb_zalloc(ANON_CHUNK_SIZE * sizeof (uintptr_t), UM_SLEEP);
9517c478bd9Sstevel@tonic-gate 	}
9527c478bd9Sstevel@tonic-gate 
9537c478bd9Sstevel@tonic-gate 	aw->aw_levone =
9547c478bd9Sstevel@tonic-gate 	    mdb_alloc(aw->aw_nlevone * sizeof (uintptr_t), UM_SLEEP);
9557c478bd9Sstevel@tonic-gate 
9567c478bd9Sstevel@tonic-gate 	aw->aw_levone_ndx = 0;
9577c478bd9Sstevel@tonic-gate 	aw->aw_levtwo_ndx = 0;
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate 	mdb_vread(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t),
9607c478bd9Sstevel@tonic-gate 	    (uintptr_t)aw->aw_ahp.array_chunk);
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate 	if (aw->aw_levtwo != NULL) {
9637c478bd9Sstevel@tonic-gate 		while (aw->aw_levone[aw->aw_levone_ndx] == NULL) {
9647c478bd9Sstevel@tonic-gate 			aw->aw_levone_ndx++;
9657c478bd9Sstevel@tonic-gate 			if (aw->aw_levone_ndx == aw->aw_nlevone) {
9667c478bd9Sstevel@tonic-gate 				mdb_warn("corrupt anon; couldn't"
9677c478bd9Sstevel@tonic-gate 				    "find ptr to lev two map");
9687c478bd9Sstevel@tonic-gate 				goto out;
9697c478bd9Sstevel@tonic-gate 			}
9707c478bd9Sstevel@tonic-gate 		}
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 		mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t),
9737c478bd9Sstevel@tonic-gate 		    aw->aw_levone[aw->aw_levone_ndx]);
9747c478bd9Sstevel@tonic-gate 	}
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate out:
9777c478bd9Sstevel@tonic-gate 	wsp->walk_data = aw;
9787c478bd9Sstevel@tonic-gate 	return (0);
9797c478bd9Sstevel@tonic-gate }
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate int
9827c478bd9Sstevel@tonic-gate anon_walk_step(mdb_walk_state_t *wsp)
9837c478bd9Sstevel@tonic-gate {
9847c478bd9Sstevel@tonic-gate 	int status;
9857c478bd9Sstevel@tonic-gate 	anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data;
9867c478bd9Sstevel@tonic-gate 	struct anon anon;
9877c478bd9Sstevel@tonic-gate 	uintptr_t anonptr;
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate again:
9907c478bd9Sstevel@tonic-gate 	/*
9917c478bd9Sstevel@tonic-gate 	 * Once we've walked through level one, we're done.
9927c478bd9Sstevel@tonic-gate 	 */
9937c478bd9Sstevel@tonic-gate 	if (aw->aw_levone_ndx == aw->aw_nlevone)
9947c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
9957c478bd9Sstevel@tonic-gate 
9967c478bd9Sstevel@tonic-gate 	if (aw->aw_levtwo == NULL) {
9977c478bd9Sstevel@tonic-gate 		anonptr = aw->aw_levone[aw->aw_levone_ndx];
9987c478bd9Sstevel@tonic-gate 		aw->aw_levone_ndx++;
9997c478bd9Sstevel@tonic-gate 	} else {
10007c478bd9Sstevel@tonic-gate 		anonptr = aw->aw_levtwo[aw->aw_levtwo_ndx];
10017c478bd9Sstevel@tonic-gate 		aw->aw_levtwo_ndx++;
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 		if (aw->aw_levtwo_ndx == ANON_CHUNK_SIZE) {
10047c478bd9Sstevel@tonic-gate 			aw->aw_levtwo_ndx = 0;
10057c478bd9Sstevel@tonic-gate 
10067c478bd9Sstevel@tonic-gate 			do {
10077c478bd9Sstevel@tonic-gate 				aw->aw_levone_ndx++;
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate 				if (aw->aw_levone_ndx == aw->aw_nlevone)
10107c478bd9Sstevel@tonic-gate 					return (WALK_DONE);
10117c478bd9Sstevel@tonic-gate 			} while (aw->aw_levone[aw->aw_levone_ndx] == NULL);
10127c478bd9Sstevel@tonic-gate 
10137c478bd9Sstevel@tonic-gate 			mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE *
10147c478bd9Sstevel@tonic-gate 			    sizeof (uintptr_t),
10157c478bd9Sstevel@tonic-gate 			    aw->aw_levone[aw->aw_levone_ndx]);
10167c478bd9Sstevel@tonic-gate 		}
10177c478bd9Sstevel@tonic-gate 	}
10187c478bd9Sstevel@tonic-gate 
10197c478bd9Sstevel@tonic-gate 	if (anonptr != NULL) {
10207c478bd9Sstevel@tonic-gate 		mdb_vread(&anon, sizeof (anon), anonptr);
10217c478bd9Sstevel@tonic-gate 		status = wsp->walk_callback(anonptr, &anon, wsp->walk_cbdata);
10227c478bd9Sstevel@tonic-gate 	} else
10237c478bd9Sstevel@tonic-gate 		goto again;
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 	return (status);
10267c478bd9Sstevel@tonic-gate }
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate void
10297c478bd9Sstevel@tonic-gate anon_walk_fini(mdb_walk_state_t *wsp)
10307c478bd9Sstevel@tonic-gate {
10317c478bd9Sstevel@tonic-gate 	anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data;
10327c478bd9Sstevel@tonic-gate 
10337c478bd9Sstevel@tonic-gate 	if (aw->aw_levtwo != NULL)
10347c478bd9Sstevel@tonic-gate 		mdb_free(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t));
10357c478bd9Sstevel@tonic-gate 
10367c478bd9Sstevel@tonic-gate 	mdb_free(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t));
10377c478bd9Sstevel@tonic-gate 	mdb_free(aw, sizeof (anon_walk_data_t));
10387c478bd9Sstevel@tonic-gate }
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10417c478bd9Sstevel@tonic-gate int
10427c478bd9Sstevel@tonic-gate whereopen_fwalk(uintptr_t addr, struct file *f, uintptr_t *target)
10437c478bd9Sstevel@tonic-gate {
10447c478bd9Sstevel@tonic-gate 	if ((uintptr_t)f->f_vnode == *target) {
10457c478bd9Sstevel@tonic-gate 		mdb_printf("file %p\n", addr);
10467c478bd9Sstevel@tonic-gate 		*target = NULL;
10477c478bd9Sstevel@tonic-gate 	}
10487c478bd9Sstevel@tonic-gate 
10497c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
10507c478bd9Sstevel@tonic-gate }
10517c478bd9Sstevel@tonic-gate 
10527c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10537c478bd9Sstevel@tonic-gate int
10547c478bd9Sstevel@tonic-gate whereopen_pwalk(uintptr_t addr, void *ignored, uintptr_t *target)
10557c478bd9Sstevel@tonic-gate {
10567c478bd9Sstevel@tonic-gate 	uintptr_t t = *target;
10577c478bd9Sstevel@tonic-gate 
10587c478bd9Sstevel@tonic-gate 	if (mdb_pwalk("file", (mdb_walk_cb_t)whereopen_fwalk, &t, addr) == -1) {
10597c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't file walk proc %p", addr);
10607c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
10617c478bd9Sstevel@tonic-gate 	}
10627c478bd9Sstevel@tonic-gate 
10637c478bd9Sstevel@tonic-gate 	if (t == NULL)
10647c478bd9Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
10677c478bd9Sstevel@tonic-gate }
10687c478bd9Sstevel@tonic-gate 
10697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10707c478bd9Sstevel@tonic-gate int
10717c478bd9Sstevel@tonic-gate whereopen(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
10727c478bd9Sstevel@tonic-gate {
10737c478bd9Sstevel@tonic-gate 	uintptr_t target = addr;
10747c478bd9Sstevel@tonic-gate 
10757c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC) || addr == NULL)
10767c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
10777c478bd9Sstevel@tonic-gate 
10787c478bd9Sstevel@tonic-gate 	if (mdb_walk("proc", (mdb_walk_cb_t)whereopen_pwalk, &target) == -1) {
10797c478bd9Sstevel@tonic-gate 		mdb_warn("can't proc walk");
10807c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
10817c478bd9Sstevel@tonic-gate 	}
10827c478bd9Sstevel@tonic-gate 
10837c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
10847c478bd9Sstevel@tonic-gate }
10857c478bd9Sstevel@tonic-gate 
10867c478bd9Sstevel@tonic-gate typedef struct datafmt {
10877c478bd9Sstevel@tonic-gate 	char	*hdr1;
10887c478bd9Sstevel@tonic-gate 	char	*hdr2;
10897c478bd9Sstevel@tonic-gate 	char	*dashes;
10907c478bd9Sstevel@tonic-gate 	char	*fmt;
10917c478bd9Sstevel@tonic-gate } datafmt_t;
10927c478bd9Sstevel@tonic-gate 
10937c478bd9Sstevel@tonic-gate static datafmt_t kmemfmt[] = {
10947c478bd9Sstevel@tonic-gate 	{ "cache                    ", "name                     ",
10957c478bd9Sstevel@tonic-gate 	"-------------------------", "%-25s "				},
10967c478bd9Sstevel@tonic-gate 	{ "   buf",	"  size",	"------",	"%6u "		},
10977c478bd9Sstevel@tonic-gate 	{ "   buf",	"in use",	"------",	"%6u "		},
10987c478bd9Sstevel@tonic-gate 	{ "   buf",	" total",	"------",	"%6u "		},
1099*bb8b5132Sek 	{ "   memory",	"   in use",	"----------",	"%9u%c "	},
11007c478bd9Sstevel@tonic-gate 	{ "    alloc",	"  succeed",	"---------",	"%9u "		},
11017c478bd9Sstevel@tonic-gate 	{ "alloc",	" fail",	"-----",	"%5u "		},
11027c478bd9Sstevel@tonic-gate 	{ NULL,		NULL,		NULL,		NULL		}
11037c478bd9Sstevel@tonic-gate };
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate static datafmt_t vmemfmt[] = {
11067c478bd9Sstevel@tonic-gate 	{ "vmem                     ", "name                     ",
11077c478bd9Sstevel@tonic-gate 	"-------------------------", "%-*s "				},
1108*bb8b5132Sek 	{ "   memory",	"   in use",	"----------",	"%9llu%c "	},
1109*bb8b5132Sek 	{ "    memory",	"     total",	"-----------",	"%10llu%c "	},
1110*bb8b5132Sek 	{ "   memory",	"   import",	"----------",	"%9llu%c "	},
11117c478bd9Sstevel@tonic-gate 	{ "    alloc",	"  succeed",	"---------",	"%9llu "	},
11127c478bd9Sstevel@tonic-gate 	{ "alloc",	" fail",	"-----",	"%5llu "	},
11137c478bd9Sstevel@tonic-gate 	{ NULL,		NULL,		NULL,		NULL		}
11147c478bd9Sstevel@tonic-gate };
11157c478bd9Sstevel@tonic-gate 
11167c478bd9Sstevel@tonic-gate /*ARGSUSED*/
11177c478bd9Sstevel@tonic-gate static int
11187c478bd9Sstevel@tonic-gate kmastat_cpu_avail(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *avail)
11197c478bd9Sstevel@tonic-gate {
11207c478bd9Sstevel@tonic-gate 	if (ccp->cc_rounds > 0)
11217c478bd9Sstevel@tonic-gate 		*avail += ccp->cc_rounds;
11227c478bd9Sstevel@tonic-gate 	if (ccp->cc_prounds > 0)
11237c478bd9Sstevel@tonic-gate 		*avail += ccp->cc_prounds;
11247c478bd9Sstevel@tonic-gate 
11257c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
11267c478bd9Sstevel@tonic-gate }
11277c478bd9Sstevel@tonic-gate 
11287c478bd9Sstevel@tonic-gate /*ARGSUSED*/
11297c478bd9Sstevel@tonic-gate static int
11307c478bd9Sstevel@tonic-gate kmastat_cpu_alloc(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *alloc)
11317c478bd9Sstevel@tonic-gate {
11327c478bd9Sstevel@tonic-gate 	*alloc += ccp->cc_alloc;
11337c478bd9Sstevel@tonic-gate 
11347c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
11357c478bd9Sstevel@tonic-gate }
11367c478bd9Sstevel@tonic-gate 
11377c478bd9Sstevel@tonic-gate /*ARGSUSED*/
11387c478bd9Sstevel@tonic-gate static int
11397c478bd9Sstevel@tonic-gate kmastat_slab_avail(uintptr_t addr, const kmem_slab_t *sp, int *avail)
11407c478bd9Sstevel@tonic-gate {
11417c478bd9Sstevel@tonic-gate 	*avail += sp->slab_chunks - sp->slab_refcnt;
11427c478bd9Sstevel@tonic-gate 
11437c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
11447c478bd9Sstevel@tonic-gate }
11457c478bd9Sstevel@tonic-gate 
11467c478bd9Sstevel@tonic-gate typedef struct kmastat_vmem {
11477c478bd9Sstevel@tonic-gate 	uintptr_t kv_addr;
11487c478bd9Sstevel@tonic-gate 	struct kmastat_vmem *kv_next;
11497c478bd9Sstevel@tonic-gate 	int kv_meminuse;
11507c478bd9Sstevel@tonic-gate 	int kv_alloc;
11517c478bd9Sstevel@tonic-gate 	int kv_fail;
11527c478bd9Sstevel@tonic-gate } kmastat_vmem_t;
11537c478bd9Sstevel@tonic-gate 
1154c92ff650Sek typedef struct kmastat_args {
1155c92ff650Sek 	kmastat_vmem_t **ka_kvpp;
1156c92ff650Sek 	uint_t ka_shift;
1157c92ff650Sek } kmastat_args_t;
1158c92ff650Sek 
11597c478bd9Sstevel@tonic-gate static int
1160c92ff650Sek kmastat_cache(uintptr_t addr, const kmem_cache_t *cp, kmastat_args_t *kap)
11617c478bd9Sstevel@tonic-gate {
1162c92ff650Sek 	kmastat_vmem_t **kvp = kap->ka_kvpp;
11637c478bd9Sstevel@tonic-gate 	kmastat_vmem_t *kv;
11647c478bd9Sstevel@tonic-gate 	datafmt_t *dfp = kmemfmt;
11657c478bd9Sstevel@tonic-gate 	int magsize;
11667c478bd9Sstevel@tonic-gate 
11677c478bd9Sstevel@tonic-gate 	int avail, alloc, total;
11687c478bd9Sstevel@tonic-gate 	size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) *
11697c478bd9Sstevel@tonic-gate 	    cp->cache_slabsize;
11707c478bd9Sstevel@tonic-gate 
11717c478bd9Sstevel@tonic-gate 	mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)kmastat_cpu_avail;
11727c478bd9Sstevel@tonic-gate 	mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)kmastat_cpu_alloc;
11737c478bd9Sstevel@tonic-gate 	mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)kmastat_slab_avail;
11747c478bd9Sstevel@tonic-gate 
11757c478bd9Sstevel@tonic-gate 	magsize = kmem_get_magsize(cp);
11767c478bd9Sstevel@tonic-gate 
11777c478bd9Sstevel@tonic-gate 	alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc;
11787c478bd9Sstevel@tonic-gate 	avail = cp->cache_full.ml_total * magsize;
11797c478bd9Sstevel@tonic-gate 	total = cp->cache_buftotal;
11807c478bd9Sstevel@tonic-gate 
11817c478bd9Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_cpu_cache", cpu_alloc, &alloc, addr);
11827c478bd9Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_cpu_cache", cpu_avail, &avail, addr);
11837c478bd9Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_slab_partial", slab_avail, &avail, addr);
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate 	for (kv = *kvp; kv != NULL; kv = kv->kv_next) {
11867c478bd9Sstevel@tonic-gate 		if (kv->kv_addr == (uintptr_t)cp->cache_arena)
11877c478bd9Sstevel@tonic-gate 			goto out;
11887c478bd9Sstevel@tonic-gate 	}
11897c478bd9Sstevel@tonic-gate 
11907c478bd9Sstevel@tonic-gate 	kv = mdb_zalloc(sizeof (kmastat_vmem_t), UM_SLEEP | UM_GC);
11917c478bd9Sstevel@tonic-gate 	kv->kv_next = *kvp;
11927c478bd9Sstevel@tonic-gate 	kv->kv_addr = (uintptr_t)cp->cache_arena;
11937c478bd9Sstevel@tonic-gate 	*kvp = kv;
11947c478bd9Sstevel@tonic-gate out:
11957c478bd9Sstevel@tonic-gate 	kv->kv_meminuse += meminuse;
11967c478bd9Sstevel@tonic-gate 	kv->kv_alloc += alloc;
11977c478bd9Sstevel@tonic-gate 	kv->kv_fail += cp->cache_alloc_fail;
11987c478bd9Sstevel@tonic-gate 
11997c478bd9Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_name);
12007c478bd9Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_bufsize);
12017c478bd9Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, total - avail);
12027c478bd9Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, total);
1203*bb8b5132Sek 	mdb_printf((dfp++)->fmt, meminuse >> kap->ka_shift,
1204*bb8b5132Sek 	    kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' :
1205*bb8b5132Sek 	    kap->ka_shift == KILOS ? 'K' : 'B');
12067c478bd9Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, alloc);
12077c478bd9Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_alloc_fail);
12087c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
12097c478bd9Sstevel@tonic-gate 
12107c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
12117c478bd9Sstevel@tonic-gate }
12127c478bd9Sstevel@tonic-gate 
12137c478bd9Sstevel@tonic-gate static int
1214c92ff650Sek kmastat_vmem_totals(uintptr_t addr, const vmem_t *v, kmastat_args_t *kap)
12157c478bd9Sstevel@tonic-gate {
1216c92ff650Sek 	kmastat_vmem_t *kv = *kap->ka_kvpp;
12177c478bd9Sstevel@tonic-gate 	size_t len;
12187c478bd9Sstevel@tonic-gate 
12197c478bd9Sstevel@tonic-gate 	while (kv != NULL && kv->kv_addr != addr)
12207c478bd9Sstevel@tonic-gate 		kv = kv->kv_next;
12217c478bd9Sstevel@tonic-gate 
12227c478bd9Sstevel@tonic-gate 	if (kv == NULL || kv->kv_alloc == 0)
12237c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
12247c478bd9Sstevel@tonic-gate 
12257c478bd9Sstevel@tonic-gate 	len = MIN(17, strlen(v->vm_name));
12267c478bd9Sstevel@tonic-gate 
1227*bb8b5132Sek 	mdb_printf("Total [%s]%*s %6s %6s %6s %9u%c %9u %5u\n", v->vm_name,
12287c478bd9Sstevel@tonic-gate 	    17 - len, "", "", "", "",
1229*bb8b5132Sek 	    kv->kv_meminuse >> kap->ka_shift,
1230*bb8b5132Sek 	    kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' :
1231*bb8b5132Sek 	    kap->ka_shift == KILOS ? 'K' : 'B', kv->kv_alloc, kv->kv_fail);
12327c478bd9Sstevel@tonic-gate 
12337c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
12347c478bd9Sstevel@tonic-gate }
12357c478bd9Sstevel@tonic-gate 
12367c478bd9Sstevel@tonic-gate /*ARGSUSED*/
12377c478bd9Sstevel@tonic-gate static int
1238c92ff650Sek kmastat_vmem(uintptr_t addr, const vmem_t *v, const uint_t *shiftp)
12397c478bd9Sstevel@tonic-gate {
12407c478bd9Sstevel@tonic-gate 	datafmt_t *dfp = vmemfmt;
12417c478bd9Sstevel@tonic-gate 	const vmem_kstat_t *vkp = &v->vm_kstat;
12427c478bd9Sstevel@tonic-gate 	uintptr_t paddr;
12437c478bd9Sstevel@tonic-gate 	vmem_t parent;
12447c478bd9Sstevel@tonic-gate 	int ident = 0;
12457c478bd9Sstevel@tonic-gate 
12467c478bd9Sstevel@tonic-gate 	for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) {
12477c478bd9Sstevel@tonic-gate 		if (mdb_vread(&parent, sizeof (parent), paddr) == -1) {
12487c478bd9Sstevel@tonic-gate 			mdb_warn("couldn't trace %p's ancestry", addr);
12497c478bd9Sstevel@tonic-gate 			ident = 0;
12507c478bd9Sstevel@tonic-gate 			break;
12517c478bd9Sstevel@tonic-gate 		}
12527c478bd9Sstevel@tonic-gate 		paddr = (uintptr_t)parent.vm_source;
12537c478bd9Sstevel@tonic-gate 	}
12547c478bd9Sstevel@tonic-gate 
12557c478bd9Sstevel@tonic-gate 	mdb_printf("%*s", ident, "");
12567c478bd9Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name);
1257*bb8b5132Sek 	mdb_printf((dfp++)->fmt, vkp->vk_mem_inuse.value.ui64 >> *shiftp,
1258*bb8b5132Sek 	    *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
1259*bb8b5132Sek 	    *shiftp == KILOS ? 'K' : 'B');
1260*bb8b5132Sek 	mdb_printf((dfp++)->fmt, vkp->vk_mem_total.value.ui64 >> *shiftp,
1261*bb8b5132Sek 	    *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
1262*bb8b5132Sek 	    *shiftp == KILOS ? 'K' : 'B');
1263*bb8b5132Sek 	mdb_printf((dfp++)->fmt, vkp->vk_mem_import.value.ui64 >> *shiftp,
1264*bb8b5132Sek 	    *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
1265*bb8b5132Sek 	    *shiftp == KILOS ? 'K' : 'B');
12667c478bd9Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_alloc.value.ui64);
12677c478bd9Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_fail.value.ui64);
12687c478bd9Sstevel@tonic-gate 
12697c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
12707c478bd9Sstevel@tonic-gate 
12717c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
12727c478bd9Sstevel@tonic-gate }
12737c478bd9Sstevel@tonic-gate 
12747c478bd9Sstevel@tonic-gate /*ARGSUSED*/
12757c478bd9Sstevel@tonic-gate int
12767c478bd9Sstevel@tonic-gate kmastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
12777c478bd9Sstevel@tonic-gate {
12787c478bd9Sstevel@tonic-gate 	kmastat_vmem_t *kv = NULL;
12797c478bd9Sstevel@tonic-gate 	datafmt_t *dfp;
1280c92ff650Sek 	kmastat_args_t ka;
12817c478bd9Sstevel@tonic-gate 
1282c92ff650Sek 	ka.ka_shift = 0;
1283c92ff650Sek 	if (mdb_getopts(argc, argv,
1284*bb8b5132Sek 	    'k', MDB_OPT_SETBITS, KILOS, &ka.ka_shift,
1285*bb8b5132Sek 	    'm', MDB_OPT_SETBITS, MEGS, &ka.ka_shift,
1286*bb8b5132Sek 	    'g', MDB_OPT_SETBITS, GIGS, &ka.ka_shift, NULL) != argc)
12877c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
12887c478bd9Sstevel@tonic-gate 
12897c478bd9Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
12907c478bd9Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr1);
12917c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
12927c478bd9Sstevel@tonic-gate 
12937c478bd9Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
12947c478bd9Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr2);
12957c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
12967c478bd9Sstevel@tonic-gate 
12977c478bd9Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
12987c478bd9Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
12997c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
13007c478bd9Sstevel@tonic-gate 
1301c92ff650Sek 	ka.ka_kvpp = &kv;
1302c92ff650Sek 	if (mdb_walk("kmem_cache", (mdb_walk_cb_t)kmastat_cache, &ka) == -1) {
13037c478bd9Sstevel@tonic-gate 		mdb_warn("can't walk 'kmem_cache'");
13047c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
13057c478bd9Sstevel@tonic-gate 	}
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
13087c478bd9Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
13097c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
13107c478bd9Sstevel@tonic-gate 
1311c92ff650Sek 	if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem_totals, &ka) == -1) {
13127c478bd9Sstevel@tonic-gate 		mdb_warn("can't walk 'vmem'");
13137c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
13147c478bd9Sstevel@tonic-gate 	}
13157c478bd9Sstevel@tonic-gate 
13167c478bd9Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
13177c478bd9Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
13187c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
13197c478bd9Sstevel@tonic-gate 
13207c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
13217c478bd9Sstevel@tonic-gate 
13227c478bd9Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
13237c478bd9Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr1);
13247c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
13257c478bd9Sstevel@tonic-gate 
13267c478bd9Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
13277c478bd9Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr2);
13287c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
13297c478bd9Sstevel@tonic-gate 
13307c478bd9Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
13317c478bd9Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
13327c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
13337c478bd9Sstevel@tonic-gate 
1334c92ff650Sek 	if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem, &ka.ka_shift) == -1) {
13357c478bd9Sstevel@tonic-gate 		mdb_warn("can't walk 'vmem'");
13367c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
13377c478bd9Sstevel@tonic-gate 	}
13387c478bd9Sstevel@tonic-gate 
13397c478bd9Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
13407c478bd9Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
13417c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
13427c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
13437c478bd9Sstevel@tonic-gate }
13447c478bd9Sstevel@tonic-gate 
13457c478bd9Sstevel@tonic-gate /*
13467c478bd9Sstevel@tonic-gate  * Our ::kgrep callback scans the entire kernel VA space (kas).  kas is made
13477c478bd9Sstevel@tonic-gate  * up of a set of 'struct seg's.  We could just scan each seg en masse, but
13487c478bd9Sstevel@tonic-gate  * unfortunately, a few of the segs are both large and sparse, so we could
13497c478bd9Sstevel@tonic-gate  * spend quite a bit of time scanning VAs which have no backing pages.
13507c478bd9Sstevel@tonic-gate  *
13517c478bd9Sstevel@tonic-gate  * So for the few very sparse segs, we skip the segment itself, and scan
13527c478bd9Sstevel@tonic-gate  * the allocated vmem_segs in the vmem arena which manages that part of kas.
13537c478bd9Sstevel@tonic-gate  * Currently, we do this for:
13547c478bd9Sstevel@tonic-gate  *
13557c478bd9Sstevel@tonic-gate  *	SEG		VMEM ARENA
13567c478bd9Sstevel@tonic-gate  *	kvseg		heap_arena
13577c478bd9Sstevel@tonic-gate  *	kvseg32		heap32_arena
13587c478bd9Sstevel@tonic-gate  *	kvseg_core	heap_core_arena
13597c478bd9Sstevel@tonic-gate  *
13607c478bd9Sstevel@tonic-gate  * In addition, we skip the segkpm segment in its entirety, since it is very
13617c478bd9Sstevel@tonic-gate  * sparse, and contains no new kernel data.
13627c478bd9Sstevel@tonic-gate  */
13637c478bd9Sstevel@tonic-gate typedef struct kgrep_walk_data {
13647c478bd9Sstevel@tonic-gate 	kgrep_cb_func *kg_cb;
13657c478bd9Sstevel@tonic-gate 	void *kg_cbdata;
13667c478bd9Sstevel@tonic-gate 	uintptr_t kg_kvseg;
13677c478bd9Sstevel@tonic-gate 	uintptr_t kg_kvseg32;
13687c478bd9Sstevel@tonic-gate 	uintptr_t kg_kvseg_core;
13697c478bd9Sstevel@tonic-gate 	uintptr_t kg_segkpm;
13707bc98a2eSeg 	uintptr_t kg_heap_lp_base;
13717bc98a2eSeg 	uintptr_t kg_heap_lp_end;
13727c478bd9Sstevel@tonic-gate } kgrep_walk_data_t;
13737c478bd9Sstevel@tonic-gate 
13747c478bd9Sstevel@tonic-gate static int
13757c478bd9Sstevel@tonic-gate kgrep_walk_seg(uintptr_t addr, const struct seg *seg, kgrep_walk_data_t *kg)
13767c478bd9Sstevel@tonic-gate {
13777c478bd9Sstevel@tonic-gate 	uintptr_t base = (uintptr_t)seg->s_base;
13787c478bd9Sstevel@tonic-gate 
13797c478bd9Sstevel@tonic-gate 	if (addr == kg->kg_kvseg || addr == kg->kg_kvseg32 ||
13807c478bd9Sstevel@tonic-gate 	    addr == kg->kg_kvseg_core)
13817c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
13827c478bd9Sstevel@tonic-gate 
13837c478bd9Sstevel@tonic-gate 	if ((uintptr_t)seg->s_ops == kg->kg_segkpm)
13847c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
13857c478bd9Sstevel@tonic-gate 
13867c478bd9Sstevel@tonic-gate 	return (kg->kg_cb(base, base + seg->s_size, kg->kg_cbdata));
13877c478bd9Sstevel@tonic-gate }
13887c478bd9Sstevel@tonic-gate 
13897c478bd9Sstevel@tonic-gate /*ARGSUSED*/
13907c478bd9Sstevel@tonic-gate static int
13917c478bd9Sstevel@tonic-gate kgrep_walk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
13927bc98a2eSeg {
13937bc98a2eSeg 	/*
13947bc98a2eSeg 	 * skip large page heap address range - it is scanned by walking
13957bc98a2eSeg 	 * allocated vmem_segs in the heap_lp_arena
13967bc98a2eSeg 	 */
13977bc98a2eSeg 	if (seg->vs_start == kg->kg_heap_lp_base &&
13987bc98a2eSeg 	    seg->vs_end == kg->kg_heap_lp_end)
13997bc98a2eSeg 		return (WALK_NEXT);
14007bc98a2eSeg 
14017bc98a2eSeg 	return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
14027bc98a2eSeg }
14037bc98a2eSeg 
14047bc98a2eSeg /*ARGSUSED*/
14057bc98a2eSeg static int
14067bc98a2eSeg kgrep_xwalk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
14077c478bd9Sstevel@tonic-gate {
14087c478bd9Sstevel@tonic-gate 	return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
14097c478bd9Sstevel@tonic-gate }
14107c478bd9Sstevel@tonic-gate 
14117c478bd9Sstevel@tonic-gate static int
14127c478bd9Sstevel@tonic-gate kgrep_walk_vmem(uintptr_t addr, const vmem_t *vmem, kgrep_walk_data_t *kg)
14137c478bd9Sstevel@tonic-gate {
14147bc98a2eSeg 	mdb_walk_cb_t walk_vseg = (mdb_walk_cb_t)kgrep_walk_vseg;
14157bc98a2eSeg 
14167c478bd9Sstevel@tonic-gate 	if (strcmp(vmem->vm_name, "heap") != 0 &&
14177c478bd9Sstevel@tonic-gate 	    strcmp(vmem->vm_name, "heap32") != 0 &&
14187bc98a2eSeg 	    strcmp(vmem->vm_name, "heap_core") != 0 &&
14197bc98a2eSeg 	    strcmp(vmem->vm_name, "heap_lp") != 0)
14207c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
14217c478bd9Sstevel@tonic-gate 
14227bc98a2eSeg 	if (strcmp(vmem->vm_name, "heap_lp") == 0)
14237bc98a2eSeg 		walk_vseg = (mdb_walk_cb_t)kgrep_xwalk_vseg;
14247bc98a2eSeg 
14257bc98a2eSeg 	if (mdb_pwalk("vmem_alloc", walk_vseg, kg, addr) == -1) {
14267c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't walk vmem_alloc for vmem %p", addr);
14277c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
14287c478bd9Sstevel@tonic-gate 	}
14297c478bd9Sstevel@tonic-gate 
14307c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
14317c478bd9Sstevel@tonic-gate }
14327c478bd9Sstevel@tonic-gate 
14337c478bd9Sstevel@tonic-gate int
14347c478bd9Sstevel@tonic-gate kgrep_subr(kgrep_cb_func *cb, void *cbdata)
14357c478bd9Sstevel@tonic-gate {
14367c478bd9Sstevel@tonic-gate 	GElf_Sym kas, kvseg, kvseg32, kvseg_core, segkpm;
14377c478bd9Sstevel@tonic-gate 	kgrep_walk_data_t kg;
14387c478bd9Sstevel@tonic-gate 
14397c478bd9Sstevel@tonic-gate 	if (mdb_get_state() == MDB_STATE_RUNNING) {
14407c478bd9Sstevel@tonic-gate 		mdb_warn("kgrep can only be run on a system "
14417c478bd9Sstevel@tonic-gate 		    "dump or under kmdb; see dumpadm(1M)\n");
14427c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
14437c478bd9Sstevel@tonic-gate 	}
14447c478bd9Sstevel@tonic-gate 
14457c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("kas", &kas) == -1) {
14467c478bd9Sstevel@tonic-gate 		mdb_warn("failed to locate 'kas' symbol\n");
14477c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
14487c478bd9Sstevel@tonic-gate 	}
14497c478bd9Sstevel@tonic-gate 
14507c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg", &kvseg) == -1) {
14517c478bd9Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg' symbol\n");
14527c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
14537c478bd9Sstevel@tonic-gate 	}
14547c478bd9Sstevel@tonic-gate 
14557c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg32", &kvseg32) == -1) {
14567c478bd9Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg32' symbol\n");
14577c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
14587c478bd9Sstevel@tonic-gate 	}
14597c478bd9Sstevel@tonic-gate 
14607c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg_core", &kvseg_core) == -1) {
14617c478bd9Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg_core' symbol\n");
14627c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
14637c478bd9Sstevel@tonic-gate 	}
14647c478bd9Sstevel@tonic-gate 
14657c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("segkpm_ops", &segkpm) == -1) {
14667c478bd9Sstevel@tonic-gate 		mdb_warn("failed to locate 'segkpm_ops' symbol\n");
14677c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
14687c478bd9Sstevel@tonic-gate 	}
14697c478bd9Sstevel@tonic-gate 
14707bc98a2eSeg 	if (mdb_readvar(&kg.kg_heap_lp_base, "heap_lp_base") == -1) {
14717bc98a2eSeg 		mdb_warn("failed to read 'heap_lp_base'\n");
14727bc98a2eSeg 		return (DCMD_ERR);
14737bc98a2eSeg 	}
14747bc98a2eSeg 
14757bc98a2eSeg 	if (mdb_readvar(&kg.kg_heap_lp_end, "heap_lp_end") == -1) {
14767bc98a2eSeg 		mdb_warn("failed to read 'heap_lp_end'\n");
14777bc98a2eSeg 		return (DCMD_ERR);
14787bc98a2eSeg 	}
14797bc98a2eSeg 
14807c478bd9Sstevel@tonic-gate 	kg.kg_cb = cb;
14817c478bd9Sstevel@tonic-gate 	kg.kg_cbdata = cbdata;
14827c478bd9Sstevel@tonic-gate 	kg.kg_kvseg = (uintptr_t)kvseg.st_value;
14837c478bd9Sstevel@tonic-gate 	kg.kg_kvseg32 = (uintptr_t)kvseg32.st_value;
14847c478bd9Sstevel@tonic-gate 	kg.kg_kvseg_core = (uintptr_t)kvseg_core.st_value;
14857c478bd9Sstevel@tonic-gate 	kg.kg_segkpm = (uintptr_t)segkpm.st_value;
14867c478bd9Sstevel@tonic-gate 
14877c478bd9Sstevel@tonic-gate 	if (mdb_pwalk("seg", (mdb_walk_cb_t)kgrep_walk_seg,
14887c478bd9Sstevel@tonic-gate 	    &kg, kas.st_value) == -1) {
14897c478bd9Sstevel@tonic-gate 		mdb_warn("failed to walk kas segments");
14907c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
14917c478bd9Sstevel@tonic-gate 	}
14927c478bd9Sstevel@tonic-gate 
14937c478bd9Sstevel@tonic-gate 	if (mdb_walk("vmem", (mdb_walk_cb_t)kgrep_walk_vmem, &kg) == -1) {
14947c478bd9Sstevel@tonic-gate 		mdb_warn("failed to walk heap/heap32 vmem arenas");
14957c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
14967c478bd9Sstevel@tonic-gate 	}
14977c478bd9Sstevel@tonic-gate 
14987c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
14997c478bd9Sstevel@tonic-gate }
15007c478bd9Sstevel@tonic-gate 
15017c478bd9Sstevel@tonic-gate size_t
15027c478bd9Sstevel@tonic-gate kgrep_subr_pagesize(void)
15037c478bd9Sstevel@tonic-gate {
15047c478bd9Sstevel@tonic-gate 	return (PAGESIZE);
15057c478bd9Sstevel@tonic-gate }
15067c478bd9Sstevel@tonic-gate 
15077c478bd9Sstevel@tonic-gate typedef struct file_walk_data {
15087c478bd9Sstevel@tonic-gate 	struct uf_entry *fw_flist;
15097c478bd9Sstevel@tonic-gate 	int fw_flistsz;
15107c478bd9Sstevel@tonic-gate 	int fw_ndx;
15117c478bd9Sstevel@tonic-gate 	int fw_nofiles;
15127c478bd9Sstevel@tonic-gate } file_walk_data_t;
15137c478bd9Sstevel@tonic-gate 
15147c478bd9Sstevel@tonic-gate int
15157c478bd9Sstevel@tonic-gate file_walk_init(mdb_walk_state_t *wsp)
15167c478bd9Sstevel@tonic-gate {
15177c478bd9Sstevel@tonic-gate 	file_walk_data_t *fw;
15187c478bd9Sstevel@tonic-gate 	proc_t p;
15197c478bd9Sstevel@tonic-gate 
15207c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
15217c478bd9Sstevel@tonic-gate 		mdb_warn("file walk doesn't support global walks\n");
15227c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
15237c478bd9Sstevel@tonic-gate 	}
15247c478bd9Sstevel@tonic-gate 
15257c478bd9Sstevel@tonic-gate 	fw = mdb_alloc(sizeof (file_walk_data_t), UM_SLEEP);
15267c478bd9Sstevel@tonic-gate 
15277c478bd9Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (p), wsp->walk_addr) == -1) {
15287c478bd9Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
15297c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read proc structure at %p", wsp->walk_addr);
15307c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
15317c478bd9Sstevel@tonic-gate 	}
15327c478bd9Sstevel@tonic-gate 
15337c478bd9Sstevel@tonic-gate 	if (p.p_user.u_finfo.fi_nfiles == 0) {
15347c478bd9Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
15357c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
15367c478bd9Sstevel@tonic-gate 	}
15377c478bd9Sstevel@tonic-gate 
15387c478bd9Sstevel@tonic-gate 	fw->fw_nofiles = p.p_user.u_finfo.fi_nfiles;
15397c478bd9Sstevel@tonic-gate 	fw->fw_flistsz = sizeof (struct uf_entry) * fw->fw_nofiles;
15407c478bd9Sstevel@tonic-gate 	fw->fw_flist = mdb_alloc(fw->fw_flistsz, UM_SLEEP);
15417c478bd9Sstevel@tonic-gate 
15427c478bd9Sstevel@tonic-gate 	if (mdb_vread(fw->fw_flist, fw->fw_flistsz,
15437c478bd9Sstevel@tonic-gate 	    (uintptr_t)p.p_user.u_finfo.fi_list) == -1) {
15447c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read file array at %p",
15457c478bd9Sstevel@tonic-gate 		    p.p_user.u_finfo.fi_list);
15467c478bd9Sstevel@tonic-gate 		mdb_free(fw->fw_flist, fw->fw_flistsz);
15477c478bd9Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
15487c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
15497c478bd9Sstevel@tonic-gate 	}
15507c478bd9Sstevel@tonic-gate 
15517c478bd9Sstevel@tonic-gate 	fw->fw_ndx = 0;
15527c478bd9Sstevel@tonic-gate 	wsp->walk_data = fw;
15537c478bd9Sstevel@tonic-gate 
15547c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
15557c478bd9Sstevel@tonic-gate }
15567c478bd9Sstevel@tonic-gate 
15577c478bd9Sstevel@tonic-gate int
15587c478bd9Sstevel@tonic-gate file_walk_step(mdb_walk_state_t *wsp)
15597c478bd9Sstevel@tonic-gate {
15607c478bd9Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
15617c478bd9Sstevel@tonic-gate 	struct file file;
15627c478bd9Sstevel@tonic-gate 	uintptr_t fp;
15637c478bd9Sstevel@tonic-gate 
15647c478bd9Sstevel@tonic-gate again:
15657c478bd9Sstevel@tonic-gate 	if (fw->fw_ndx == fw->fw_nofiles)
15667c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
15677c478bd9Sstevel@tonic-gate 
15687c478bd9Sstevel@tonic-gate 	if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) == NULL)
15697c478bd9Sstevel@tonic-gate 		goto again;
15707c478bd9Sstevel@tonic-gate 
15717c478bd9Sstevel@tonic-gate 	(void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
15727c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
15737c478bd9Sstevel@tonic-gate }
15747c478bd9Sstevel@tonic-gate 
15757c478bd9Sstevel@tonic-gate int
15767c478bd9Sstevel@tonic-gate allfile_walk_step(mdb_walk_state_t *wsp)
15777c478bd9Sstevel@tonic-gate {
15787c478bd9Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
15797c478bd9Sstevel@tonic-gate 	struct file file;
15807c478bd9Sstevel@tonic-gate 	uintptr_t fp;
15817c478bd9Sstevel@tonic-gate 
15827c478bd9Sstevel@tonic-gate 	if (fw->fw_ndx == fw->fw_nofiles)
15837c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
15847c478bd9Sstevel@tonic-gate 
15857c478bd9Sstevel@tonic-gate 	if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) != NULL)
15867c478bd9Sstevel@tonic-gate 		(void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
15877c478bd9Sstevel@tonic-gate 	else
15887c478bd9Sstevel@tonic-gate 		bzero(&file, sizeof (file));
15897c478bd9Sstevel@tonic-gate 
15907c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
15917c478bd9Sstevel@tonic-gate }
15927c478bd9Sstevel@tonic-gate 
15937c478bd9Sstevel@tonic-gate void
15947c478bd9Sstevel@tonic-gate file_walk_fini(mdb_walk_state_t *wsp)
15957c478bd9Sstevel@tonic-gate {
15967c478bd9Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
15977c478bd9Sstevel@tonic-gate 
15987c478bd9Sstevel@tonic-gate 	mdb_free(fw->fw_flist, fw->fw_flistsz);
15997c478bd9Sstevel@tonic-gate 	mdb_free(fw, sizeof (file_walk_data_t));
16007c478bd9Sstevel@tonic-gate }
16017c478bd9Sstevel@tonic-gate 
16027c478bd9Sstevel@tonic-gate int
16037c478bd9Sstevel@tonic-gate port_walk_init(mdb_walk_state_t *wsp)
16047c478bd9Sstevel@tonic-gate {
16057c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
16067c478bd9Sstevel@tonic-gate 		mdb_warn("port walk doesn't support global walks\n");
16077c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
16087c478bd9Sstevel@tonic-gate 	}
16097c478bd9Sstevel@tonic-gate 
16107c478bd9Sstevel@tonic-gate 	if (mdb_layered_walk("file", wsp) == -1) {
16117c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't walk 'file'");
16127c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
16137c478bd9Sstevel@tonic-gate 	}
16147c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
16157c478bd9Sstevel@tonic-gate }
16167c478bd9Sstevel@tonic-gate 
16177c478bd9Sstevel@tonic-gate int
16187c478bd9Sstevel@tonic-gate port_walk_step(mdb_walk_state_t *wsp)
16197c478bd9Sstevel@tonic-gate {
16207c478bd9Sstevel@tonic-gate 	struct vnode	vn;
16217c478bd9Sstevel@tonic-gate 	uintptr_t	vp;
16227c478bd9Sstevel@tonic-gate 	uintptr_t	pp;
16237c478bd9Sstevel@tonic-gate 	struct port	port;
16247c478bd9Sstevel@tonic-gate 
16257c478bd9Sstevel@tonic-gate 	vp = (uintptr_t)((struct file *)wsp->walk_layer)->f_vnode;
16267c478bd9Sstevel@tonic-gate 	if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
16277c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read vnode_t at %p", vp);
16287c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
16297c478bd9Sstevel@tonic-gate 	}
16307c478bd9Sstevel@tonic-gate 	if (vn.v_type != VPORT)
16317c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
16327c478bd9Sstevel@tonic-gate 
16337c478bd9Sstevel@tonic-gate 	pp = (uintptr_t)vn.v_data;
16347c478bd9Sstevel@tonic-gate 	if (mdb_vread(&port, sizeof (port), pp) == -1) {
16357c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read port_t at %p", pp);
16367c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
16377c478bd9Sstevel@tonic-gate 	}
16387c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(pp, &port, wsp->walk_cbdata));
16397c478bd9Sstevel@tonic-gate }
16407c478bd9Sstevel@tonic-gate 
16417c478bd9Sstevel@tonic-gate typedef struct portev_walk_data {
16427c478bd9Sstevel@tonic-gate 	list_node_t	*pev_node;
16437c478bd9Sstevel@tonic-gate 	list_node_t	*pev_last;
16447c478bd9Sstevel@tonic-gate 	size_t		pev_offset;
16457c478bd9Sstevel@tonic-gate } portev_walk_data_t;
16467c478bd9Sstevel@tonic-gate 
16477c478bd9Sstevel@tonic-gate int
16487c478bd9Sstevel@tonic-gate portev_walk_init(mdb_walk_state_t *wsp)
16497c478bd9Sstevel@tonic-gate {
16507c478bd9Sstevel@tonic-gate 	portev_walk_data_t *pevd;
16517c478bd9Sstevel@tonic-gate 	struct port	port;
16527c478bd9Sstevel@tonic-gate 	struct vnode	vn;
16537c478bd9Sstevel@tonic-gate 	struct list	*list;
16547c478bd9Sstevel@tonic-gate 	uintptr_t	vp;
16557c478bd9Sstevel@tonic-gate 
16567c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
16577c478bd9Sstevel@tonic-gate 		mdb_warn("portev walk doesn't support global walks\n");
16587c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
16597c478bd9Sstevel@tonic-gate 	}
16607c478bd9Sstevel@tonic-gate 
16617c478bd9Sstevel@tonic-gate 	pevd = mdb_alloc(sizeof (portev_walk_data_t), UM_SLEEP);
16627c478bd9Sstevel@tonic-gate 
16637c478bd9Sstevel@tonic-gate 	if (mdb_vread(&port, sizeof (port), wsp->walk_addr) == -1) {
16647c478bd9Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
16657c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read port structure at %p", wsp->walk_addr);
16667c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
16677c478bd9Sstevel@tonic-gate 	}
16687c478bd9Sstevel@tonic-gate 
16697c478bd9Sstevel@tonic-gate 	vp = (uintptr_t)port.port_vnode;
16707c478bd9Sstevel@tonic-gate 	if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
16717c478bd9Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
16727c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read vnode_t at %p", vp);
16737c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
16747c478bd9Sstevel@tonic-gate 	}
16757c478bd9Sstevel@tonic-gate 
16767c478bd9Sstevel@tonic-gate 	if (vn.v_type != VPORT) {
16777c478bd9Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
16787c478bd9Sstevel@tonic-gate 		mdb_warn("input address (%p) does not point to an event port",
16797c478bd9Sstevel@tonic-gate 		    wsp->walk_addr);
16807c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
16817c478bd9Sstevel@tonic-gate 	}
16827c478bd9Sstevel@tonic-gate 
16837c478bd9Sstevel@tonic-gate 	if (port.port_queue.portq_nent == 0) {
16847c478bd9Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
16857c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
16867c478bd9Sstevel@tonic-gate 	}
16877c478bd9Sstevel@tonic-gate 	list = &port.port_queue.portq_list;
16887c478bd9Sstevel@tonic-gate 	pevd->pev_offset = list->list_offset;
16897c478bd9Sstevel@tonic-gate 	pevd->pev_last = list->list_head.list_prev;
16907c478bd9Sstevel@tonic-gate 	pevd->pev_node = list->list_head.list_next;
16917c478bd9Sstevel@tonic-gate 	wsp->walk_data = pevd;
16927c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
16937c478bd9Sstevel@tonic-gate }
16947c478bd9Sstevel@tonic-gate 
16957c478bd9Sstevel@tonic-gate int
16967c478bd9Sstevel@tonic-gate portev_walk_step(mdb_walk_state_t *wsp)
16977c478bd9Sstevel@tonic-gate {
16987c478bd9Sstevel@tonic-gate 	portev_walk_data_t	*pevd;
16997c478bd9Sstevel@tonic-gate 	struct port_kevent	ev;
17007c478bd9Sstevel@tonic-gate 	uintptr_t		evp;
17017c478bd9Sstevel@tonic-gate 
17027c478bd9Sstevel@tonic-gate 	pevd = (portev_walk_data_t *)wsp->walk_data;
17037c478bd9Sstevel@tonic-gate 
17047c478bd9Sstevel@tonic-gate 	if (pevd->pev_last == NULL)
17057c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
17067c478bd9Sstevel@tonic-gate 	if (pevd->pev_node == pevd->pev_last)
17077c478bd9Sstevel@tonic-gate 		pevd->pev_last = NULL;		/* last round */
17087c478bd9Sstevel@tonic-gate 
17097c478bd9Sstevel@tonic-gate 	evp = ((uintptr_t)(((char *)pevd->pev_node) - pevd->pev_offset));
17107c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ev, sizeof (ev), evp) == -1) {
17117c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read port_kevent at %p", evp);
17127c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
17137c478bd9Sstevel@tonic-gate 	}
17147c478bd9Sstevel@tonic-gate 	pevd->pev_node = ev.portkev_node.list_next;
17157c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(evp, &ev, wsp->walk_cbdata));
17167c478bd9Sstevel@tonic-gate }
17177c478bd9Sstevel@tonic-gate 
17187c478bd9Sstevel@tonic-gate void
17197c478bd9Sstevel@tonic-gate portev_walk_fini(mdb_walk_state_t *wsp)
17207c478bd9Sstevel@tonic-gate {
17217c478bd9Sstevel@tonic-gate 	portev_walk_data_t *pevd = (portev_walk_data_t *)wsp->walk_data;
17227c478bd9Sstevel@tonic-gate 
17237c478bd9Sstevel@tonic-gate 	if (pevd != NULL)
17247c478bd9Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
17257c478bd9Sstevel@tonic-gate }
17267c478bd9Sstevel@tonic-gate 
17277c478bd9Sstevel@tonic-gate typedef struct proc_walk_data {
17287c478bd9Sstevel@tonic-gate 	uintptr_t *pw_stack;
17297c478bd9Sstevel@tonic-gate 	int pw_depth;
17307c478bd9Sstevel@tonic-gate 	int pw_max;
17317c478bd9Sstevel@tonic-gate } proc_walk_data_t;
17327c478bd9Sstevel@tonic-gate 
17337c478bd9Sstevel@tonic-gate int
17347c478bd9Sstevel@tonic-gate proc_walk_init(mdb_walk_state_t *wsp)
17357c478bd9Sstevel@tonic-gate {
17367c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
17377c478bd9Sstevel@tonic-gate 	proc_walk_data_t *pw;
17387c478bd9Sstevel@tonic-gate 
17397c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
17407c478bd9Sstevel@tonic-gate 		if (mdb_lookup_by_name("p0", &sym) == -1) {
17417c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read 'practive'");
17427c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
17437c478bd9Sstevel@tonic-gate 		}
17447c478bd9Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)sym.st_value;
17457c478bd9Sstevel@tonic-gate 	}
17467c478bd9Sstevel@tonic-gate 
17477c478bd9Sstevel@tonic-gate 	pw = mdb_zalloc(sizeof (proc_walk_data_t), UM_SLEEP);
17487c478bd9Sstevel@tonic-gate 
17497c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&pw->pw_max, "nproc") == -1) {
17507c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'nproc'");
17517c478bd9Sstevel@tonic-gate 		mdb_free(pw, sizeof (pw));
17527c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
17537c478bd9Sstevel@tonic-gate 	}
17547c478bd9Sstevel@tonic-gate 
17557c478bd9Sstevel@tonic-gate 	pw->pw_stack = mdb_alloc(pw->pw_max * sizeof (uintptr_t), UM_SLEEP);
17567c478bd9Sstevel@tonic-gate 	wsp->walk_data = pw;
17577c478bd9Sstevel@tonic-gate 
17587c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
17597c478bd9Sstevel@tonic-gate }
17607c478bd9Sstevel@tonic-gate 
17617c478bd9Sstevel@tonic-gate int
17627c478bd9Sstevel@tonic-gate proc_walk_step(mdb_walk_state_t *wsp)
17637c478bd9Sstevel@tonic-gate {
17647c478bd9Sstevel@tonic-gate 	proc_walk_data_t *pw = wsp->walk_data;
17657c478bd9Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
17667c478bd9Sstevel@tonic-gate 	uintptr_t cld, sib;
17677c478bd9Sstevel@tonic-gate 
17687c478bd9Sstevel@tonic-gate 	int status;
17697c478bd9Sstevel@tonic-gate 	proc_t pr;
17707c478bd9Sstevel@tonic-gate 
17717c478bd9Sstevel@tonic-gate 	if (mdb_vread(&pr, sizeof (proc_t), addr) == -1) {
17727c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", addr);
17737c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
17747c478bd9Sstevel@tonic-gate 	}
17757c478bd9Sstevel@tonic-gate 
17767c478bd9Sstevel@tonic-gate 	cld = (uintptr_t)pr.p_child;
17777c478bd9Sstevel@tonic-gate 	sib = (uintptr_t)pr.p_sibling;
17787c478bd9Sstevel@tonic-gate 
17797c478bd9Sstevel@tonic-gate 	if (pw->pw_depth > 0 && addr == pw->pw_stack[pw->pw_depth - 1]) {
17807c478bd9Sstevel@tonic-gate 		pw->pw_depth--;
17817c478bd9Sstevel@tonic-gate 		goto sib;
17827c478bd9Sstevel@tonic-gate 	}
17837c478bd9Sstevel@tonic-gate 
17847c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(addr, &pr, wsp->walk_cbdata);
17857c478bd9Sstevel@tonic-gate 
17867c478bd9Sstevel@tonic-gate 	if (status != WALK_NEXT)
17877c478bd9Sstevel@tonic-gate 		return (status);
17887c478bd9Sstevel@tonic-gate 
17897c478bd9Sstevel@tonic-gate 	if ((wsp->walk_addr = cld) != NULL) {
17907c478bd9Sstevel@tonic-gate 		if (mdb_vread(&pr, sizeof (proc_t), cld) == -1) {
17917c478bd9Sstevel@tonic-gate 			mdb_warn("proc %p has invalid p_child %p; skipping\n",
17927c478bd9Sstevel@tonic-gate 			    addr, cld);
17937c478bd9Sstevel@tonic-gate 			goto sib;
17947c478bd9Sstevel@tonic-gate 		}
17957c478bd9Sstevel@tonic-gate 
17967c478bd9Sstevel@tonic-gate 		pw->pw_stack[pw->pw_depth++] = addr;
17977c478bd9Sstevel@tonic-gate 
17987c478bd9Sstevel@tonic-gate 		if (pw->pw_depth == pw->pw_max) {
17997c478bd9Sstevel@tonic-gate 			mdb_warn("depth %d exceeds max depth; try again\n",
18007c478bd9Sstevel@tonic-gate 			    pw->pw_depth);
18017c478bd9Sstevel@tonic-gate 			return (WALK_DONE);
18027c478bd9Sstevel@tonic-gate 		}
18037c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
18047c478bd9Sstevel@tonic-gate 	}
18057c478bd9Sstevel@tonic-gate 
18067c478bd9Sstevel@tonic-gate sib:
18077c478bd9Sstevel@tonic-gate 	/*
18087c478bd9Sstevel@tonic-gate 	 * We know that p0 has no siblings, and if another starting proc
18097c478bd9Sstevel@tonic-gate 	 * was given, we don't want to walk its siblings anyway.
18107c478bd9Sstevel@tonic-gate 	 */
18117c478bd9Sstevel@tonic-gate 	if (pw->pw_depth == 0)
18127c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
18137c478bd9Sstevel@tonic-gate 
18147c478bd9Sstevel@tonic-gate 	if (sib != NULL && mdb_vread(&pr, sizeof (proc_t), sib) == -1) {
18157c478bd9Sstevel@tonic-gate 		mdb_warn("proc %p has invalid p_sibling %p; skipping\n",
18167c478bd9Sstevel@tonic-gate 		    addr, sib);
18177c478bd9Sstevel@tonic-gate 		sib = NULL;
18187c478bd9Sstevel@tonic-gate 	}
18197c478bd9Sstevel@tonic-gate 
18207c478bd9Sstevel@tonic-gate 	if ((wsp->walk_addr = sib) == NULL) {
18217c478bd9Sstevel@tonic-gate 		if (pw->pw_depth > 0) {
18227c478bd9Sstevel@tonic-gate 			wsp->walk_addr = pw->pw_stack[pw->pw_depth - 1];
18237c478bd9Sstevel@tonic-gate 			return (WALK_NEXT);
18247c478bd9Sstevel@tonic-gate 		}
18257c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
18267c478bd9Sstevel@tonic-gate 	}
18277c478bd9Sstevel@tonic-gate 
18287c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
18297c478bd9Sstevel@tonic-gate }
18307c478bd9Sstevel@tonic-gate 
18317c478bd9Sstevel@tonic-gate void
18327c478bd9Sstevel@tonic-gate proc_walk_fini(mdb_walk_state_t *wsp)
18337c478bd9Sstevel@tonic-gate {
18347c478bd9Sstevel@tonic-gate 	proc_walk_data_t *pw = wsp->walk_data;
18357c478bd9Sstevel@tonic-gate 
18367c478bd9Sstevel@tonic-gate 	mdb_free(pw->pw_stack, pw->pw_max * sizeof (uintptr_t));
18377c478bd9Sstevel@tonic-gate 	mdb_free(pw, sizeof (proc_walk_data_t));
18387c478bd9Sstevel@tonic-gate }
18397c478bd9Sstevel@tonic-gate 
18407c478bd9Sstevel@tonic-gate int
18417c478bd9Sstevel@tonic-gate task_walk_init(mdb_walk_state_t *wsp)
18427c478bd9Sstevel@tonic-gate {
18437c478bd9Sstevel@tonic-gate 	task_t task;
18447c478bd9Sstevel@tonic-gate 
18457c478bd9Sstevel@tonic-gate 	if (mdb_vread(&task, sizeof (task_t), wsp->walk_addr) == -1) {
18467c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read task at %p", wsp->walk_addr);
18477c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
18487c478bd9Sstevel@tonic-gate 	}
18497c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)task.tk_memb_list;
18507c478bd9Sstevel@tonic-gate 	wsp->walk_data = task.tk_memb_list;
18517c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
18527c478bd9Sstevel@tonic-gate }
18537c478bd9Sstevel@tonic-gate 
18547c478bd9Sstevel@tonic-gate int
18557c478bd9Sstevel@tonic-gate task_walk_step(mdb_walk_state_t *wsp)
18567c478bd9Sstevel@tonic-gate {
18577c478bd9Sstevel@tonic-gate 	proc_t proc;
18587c478bd9Sstevel@tonic-gate 	int status;
18597c478bd9Sstevel@tonic-gate 
18607c478bd9Sstevel@tonic-gate 	if (mdb_vread(&proc, sizeof (proc_t), wsp->walk_addr) == -1) {
18617c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", wsp->walk_addr);
18627c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
18637c478bd9Sstevel@tonic-gate 	}
18647c478bd9Sstevel@tonic-gate 
18657c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata);
18667c478bd9Sstevel@tonic-gate 
18677c478bd9Sstevel@tonic-gate 	if (proc.p_tasknext == wsp->walk_data)
18687c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
18697c478bd9Sstevel@tonic-gate 
18707c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)proc.p_tasknext;
18717c478bd9Sstevel@tonic-gate 	return (status);
18727c478bd9Sstevel@tonic-gate }
18737c478bd9Sstevel@tonic-gate 
18747c478bd9Sstevel@tonic-gate int
18757c478bd9Sstevel@tonic-gate project_walk_init(mdb_walk_state_t *wsp)
18767c478bd9Sstevel@tonic-gate {
18777c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
18787c478bd9Sstevel@tonic-gate 		if (mdb_readvar(&wsp->walk_addr, "proj0p") == -1) {
18797c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read 'proj0p'");
18807c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
18817c478bd9Sstevel@tonic-gate 		}
18827c478bd9Sstevel@tonic-gate 	}
18837c478bd9Sstevel@tonic-gate 	wsp->walk_data = (void *)wsp->walk_addr;
18847c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
18857c478bd9Sstevel@tonic-gate }
18867c478bd9Sstevel@tonic-gate 
18877c478bd9Sstevel@tonic-gate int
18887c478bd9Sstevel@tonic-gate project_walk_step(mdb_walk_state_t *wsp)
18897c478bd9Sstevel@tonic-gate {
18907c478bd9Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
18917c478bd9Sstevel@tonic-gate 	kproject_t pj;
18927c478bd9Sstevel@tonic-gate 	int status;
18937c478bd9Sstevel@tonic-gate 
18947c478bd9Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
18957c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read project at %p", addr);
18967c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
18977c478bd9Sstevel@tonic-gate 	}
18987c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(addr, &pj, wsp->walk_cbdata);
18997c478bd9Sstevel@tonic-gate 	if (status != WALK_NEXT)
19007c478bd9Sstevel@tonic-gate 		return (status);
19017c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)pj.kpj_next;
19027c478bd9Sstevel@tonic-gate 	if ((void *)wsp->walk_addr == wsp->walk_data)
19037c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
19047c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
19057c478bd9Sstevel@tonic-gate }
19067c478bd9Sstevel@tonic-gate 
19077c478bd9Sstevel@tonic-gate static int
19087c478bd9Sstevel@tonic-gate generic_walk_step(mdb_walk_state_t *wsp)
19097c478bd9Sstevel@tonic-gate {
19107c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
19117c478bd9Sstevel@tonic-gate 	    wsp->walk_cbdata));
19127c478bd9Sstevel@tonic-gate }
19137c478bd9Sstevel@tonic-gate 
19147c478bd9Sstevel@tonic-gate int
19157c478bd9Sstevel@tonic-gate seg_walk_init(mdb_walk_state_t *wsp)
19167c478bd9Sstevel@tonic-gate {
19177c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
19187c478bd9Sstevel@tonic-gate 		mdb_warn("seg walk must begin at struct as *\n");
19197c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
19207c478bd9Sstevel@tonic-gate 	}
19217c478bd9Sstevel@tonic-gate 
19227c478bd9Sstevel@tonic-gate 	/*
19237c478bd9Sstevel@tonic-gate 	 * this is really just a wrapper to AVL tree walk
19247c478bd9Sstevel@tonic-gate 	 */
19257c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)&((struct as *)wsp->walk_addr)->a_segtree;
19267c478bd9Sstevel@tonic-gate 	return (avl_walk_init(wsp));
19277c478bd9Sstevel@tonic-gate }
19287c478bd9Sstevel@tonic-gate 
19297c478bd9Sstevel@tonic-gate static int
19307c478bd9Sstevel@tonic-gate cpu_walk_cmp(const void *l, const void *r)
19317c478bd9Sstevel@tonic-gate {
19327c478bd9Sstevel@tonic-gate 	uintptr_t lhs = *((uintptr_t *)l);
19337c478bd9Sstevel@tonic-gate 	uintptr_t rhs = *((uintptr_t *)r);
19347c478bd9Sstevel@tonic-gate 	cpu_t lcpu, rcpu;
19357c478bd9Sstevel@tonic-gate 
19367c478bd9Sstevel@tonic-gate 	(void) mdb_vread(&lcpu, sizeof (lcpu), lhs);
19377c478bd9Sstevel@tonic-gate 	(void) mdb_vread(&rcpu, sizeof (rcpu), rhs);
19387c478bd9Sstevel@tonic-gate 
19397c478bd9Sstevel@tonic-gate 	if (lcpu.cpu_id < rcpu.cpu_id)
19407c478bd9Sstevel@tonic-gate 		return (-1);
19417c478bd9Sstevel@tonic-gate 
19427c478bd9Sstevel@tonic-gate 	if (lcpu.cpu_id > rcpu.cpu_id)
19437c478bd9Sstevel@tonic-gate 		return (1);
19447c478bd9Sstevel@tonic-gate 
19457c478bd9Sstevel@tonic-gate 	return (0);
19467c478bd9Sstevel@tonic-gate }
19477c478bd9Sstevel@tonic-gate 
19487c478bd9Sstevel@tonic-gate typedef struct cpu_walk {
19497c478bd9Sstevel@tonic-gate 	uintptr_t *cw_array;
19507c478bd9Sstevel@tonic-gate 	int cw_ndx;
19517c478bd9Sstevel@tonic-gate } cpu_walk_t;
19527c478bd9Sstevel@tonic-gate 
19537c478bd9Sstevel@tonic-gate int
19547c478bd9Sstevel@tonic-gate cpu_walk_init(mdb_walk_state_t *wsp)
19557c478bd9Sstevel@tonic-gate {
19567c478bd9Sstevel@tonic-gate 	cpu_walk_t *cw;
19577c478bd9Sstevel@tonic-gate 	int max_ncpus, i = 0;
19587c478bd9Sstevel@tonic-gate 	uintptr_t current, first;
19597c478bd9Sstevel@tonic-gate 	cpu_t cpu, panic_cpu;
19607c478bd9Sstevel@tonic-gate 	uintptr_t panicstr, addr;
19617c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
19627c478bd9Sstevel@tonic-gate 
19637c478bd9Sstevel@tonic-gate 	cw = mdb_zalloc(sizeof (cpu_walk_t), UM_SLEEP | UM_GC);
19647c478bd9Sstevel@tonic-gate 
19657c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
19667c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'max_ncpus'");
19677c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
19687c478bd9Sstevel@tonic-gate 	}
19697c478bd9Sstevel@tonic-gate 
19707c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&panicstr, "panicstr") == -1) {
19717c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'panicstr'");
19727c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
19737c478bd9Sstevel@tonic-gate 	}
19747c478bd9Sstevel@tonic-gate 
19757c478bd9Sstevel@tonic-gate 	if (panicstr != NULL) {
19767c478bd9Sstevel@tonic-gate 		if (mdb_lookup_by_name("panic_cpu", &sym) == -1) {
19777c478bd9Sstevel@tonic-gate 			mdb_warn("failed to find 'panic_cpu'");
19787c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
19797c478bd9Sstevel@tonic-gate 		}
19807c478bd9Sstevel@tonic-gate 
19817c478bd9Sstevel@tonic-gate 		addr = (uintptr_t)sym.st_value;
19827c478bd9Sstevel@tonic-gate 
19837c478bd9Sstevel@tonic-gate 		if (mdb_vread(&panic_cpu, sizeof (cpu_t), addr) == -1) {
19847c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read 'panic_cpu'");
19857c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
19867c478bd9Sstevel@tonic-gate 		}
19877c478bd9Sstevel@tonic-gate 	}
19887c478bd9Sstevel@tonic-gate 
19897c478bd9Sstevel@tonic-gate 	/*
19907c478bd9Sstevel@tonic-gate 	 * Unfortunately, there is no platform-independent way to walk
19917c478bd9Sstevel@tonic-gate 	 * CPUs in ID order.  We therefore loop through in cpu_next order,
19927c478bd9Sstevel@tonic-gate 	 * building an array of CPU pointers which will subsequently be
19937c478bd9Sstevel@tonic-gate 	 * sorted.
19947c478bd9Sstevel@tonic-gate 	 */
19957c478bd9Sstevel@tonic-gate 	cw->cw_array =
19967c478bd9Sstevel@tonic-gate 	    mdb_zalloc((max_ncpus + 1) * sizeof (uintptr_t), UM_SLEEP | UM_GC);
19977c478bd9Sstevel@tonic-gate 
19987c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&first, "cpu_list") == -1) {
19997c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'cpu_list'");
20007c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
20017c478bd9Sstevel@tonic-gate 	}
20027c478bd9Sstevel@tonic-gate 
20037c478bd9Sstevel@tonic-gate 	current = first;
20047c478bd9Sstevel@tonic-gate 	do {
20057c478bd9Sstevel@tonic-gate 		if (mdb_vread(&cpu, sizeof (cpu), current) == -1) {
20067c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read cpu at %p", current);
20077c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
20087c478bd9Sstevel@tonic-gate 		}
20097c478bd9Sstevel@tonic-gate 
20107c478bd9Sstevel@tonic-gate 		if (panicstr != NULL && panic_cpu.cpu_id == cpu.cpu_id) {
20117c478bd9Sstevel@tonic-gate 			cw->cw_array[i++] = addr;
20127c478bd9Sstevel@tonic-gate 		} else {
20137c478bd9Sstevel@tonic-gate 			cw->cw_array[i++] = current;
20147c478bd9Sstevel@tonic-gate 		}
20157c478bd9Sstevel@tonic-gate 	} while ((current = (uintptr_t)cpu.cpu_next) != first);
20167c478bd9Sstevel@tonic-gate 
20177c478bd9Sstevel@tonic-gate 	qsort(cw->cw_array, i, sizeof (uintptr_t), cpu_walk_cmp);
20187c478bd9Sstevel@tonic-gate 	wsp->walk_data = cw;
20197c478bd9Sstevel@tonic-gate 
20207c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
20217c478bd9Sstevel@tonic-gate }
20227c478bd9Sstevel@tonic-gate 
20237c478bd9Sstevel@tonic-gate int
20247c478bd9Sstevel@tonic-gate cpu_walk_step(mdb_walk_state_t *wsp)
20257c478bd9Sstevel@tonic-gate {
20267c478bd9Sstevel@tonic-gate 	cpu_walk_t *cw = wsp->walk_data;
20277c478bd9Sstevel@tonic-gate 	cpu_t cpu;
20287c478bd9Sstevel@tonic-gate 	uintptr_t addr = cw->cw_array[cw->cw_ndx++];
20297c478bd9Sstevel@tonic-gate 
20307c478bd9Sstevel@tonic-gate 	if (addr == NULL)
20317c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
20327c478bd9Sstevel@tonic-gate 
20337c478bd9Sstevel@tonic-gate 	if (mdb_vread(&cpu, sizeof (cpu), addr) == -1) {
20347c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read cpu at %p", addr);
20357c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
20367c478bd9Sstevel@tonic-gate 	}
20377c478bd9Sstevel@tonic-gate 
20387c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &cpu, wsp->walk_cbdata));
20397c478bd9Sstevel@tonic-gate }
20407c478bd9Sstevel@tonic-gate 
20417c478bd9Sstevel@tonic-gate typedef struct cpuinfo_data {
20427c478bd9Sstevel@tonic-gate 	intptr_t cid_cpu;
20437c478bd9Sstevel@tonic-gate 	uintptr_t cid_lbolt;
20447c478bd9Sstevel@tonic-gate 	uintptr_t **cid_ithr;
20457c478bd9Sstevel@tonic-gate 	char	cid_print_head;
20467c478bd9Sstevel@tonic-gate 	char	cid_print_thr;
20477c478bd9Sstevel@tonic-gate 	char	cid_print_ithr;
20487c478bd9Sstevel@tonic-gate 	char	cid_print_flags;
20497c478bd9Sstevel@tonic-gate } cpuinfo_data_t;
20507c478bd9Sstevel@tonic-gate 
20517c478bd9Sstevel@tonic-gate int
20527c478bd9Sstevel@tonic-gate cpuinfo_walk_ithread(uintptr_t addr, const kthread_t *thr, cpuinfo_data_t *cid)
20537c478bd9Sstevel@tonic-gate {
20547c478bd9Sstevel@tonic-gate 	cpu_t c;
20557c478bd9Sstevel@tonic-gate 	int id;
20567c478bd9Sstevel@tonic-gate 	uint8_t pil;
20577c478bd9Sstevel@tonic-gate 
20587c478bd9Sstevel@tonic-gate 	if (!(thr->t_flag & T_INTR_THREAD) || thr->t_state == TS_FREE)
20597c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
20607c478bd9Sstevel@tonic-gate 
20617c478bd9Sstevel@tonic-gate 	if (thr->t_bound_cpu == NULL) {
20627c478bd9Sstevel@tonic-gate 		mdb_warn("thr %p is intr thread w/out a CPU\n", addr);
20637c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
20647c478bd9Sstevel@tonic-gate 	}
20657c478bd9Sstevel@tonic-gate 
20667c478bd9Sstevel@tonic-gate 	(void) mdb_vread(&c, sizeof (c), (uintptr_t)thr->t_bound_cpu);
20677c478bd9Sstevel@tonic-gate 
20687c478bd9Sstevel@tonic-gate 	if ((id = c.cpu_id) >= NCPU) {
20697c478bd9Sstevel@tonic-gate 		mdb_warn("CPU %p has id (%d) greater than NCPU (%d)\n",
20707c478bd9Sstevel@tonic-gate 		    thr->t_bound_cpu, id, NCPU);
20717c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
20727c478bd9Sstevel@tonic-gate 	}
20737c478bd9Sstevel@tonic-gate 
20747c478bd9Sstevel@tonic-gate 	if ((pil = thr->t_pil) >= NINTR) {
20757c478bd9Sstevel@tonic-gate 		mdb_warn("thread %p has pil (%d) greater than %d\n",
20767c478bd9Sstevel@tonic-gate 		    addr, pil, NINTR);
20777c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
20787c478bd9Sstevel@tonic-gate 	}
20797c478bd9Sstevel@tonic-gate 
20807c478bd9Sstevel@tonic-gate 	if (cid->cid_ithr[id][pil] != NULL) {
20817c478bd9Sstevel@tonic-gate 		mdb_warn("CPU %d has multiple threads at pil %d (at least "
20827c478bd9Sstevel@tonic-gate 		    "%p and %p)\n", id, pil, addr, cid->cid_ithr[id][pil]);
20837c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
20847c478bd9Sstevel@tonic-gate 	}
20857c478bd9Sstevel@tonic-gate 
20867c478bd9Sstevel@tonic-gate 	cid->cid_ithr[id][pil] = addr;
20877c478bd9Sstevel@tonic-gate 
20887c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
20897c478bd9Sstevel@tonic-gate }
20907c478bd9Sstevel@tonic-gate 
20917c478bd9Sstevel@tonic-gate #define	CPUINFO_IDWIDTH		3
20927c478bd9Sstevel@tonic-gate #define	CPUINFO_FLAGWIDTH	9
20937c478bd9Sstevel@tonic-gate 
20947c478bd9Sstevel@tonic-gate #ifdef _LP64
2095f5533078Smishra #if defined(__amd64)
2096f5533078Smishra #define	CPUINFO_TWIDTH		16
2097f5533078Smishra #define	CPUINFO_CPUWIDTH	16
2098f5533078Smishra #else
20997c478bd9Sstevel@tonic-gate #define	CPUINFO_CPUWIDTH	11
21007c478bd9Sstevel@tonic-gate #define	CPUINFO_TWIDTH		11
2101f5533078Smishra #endif
21027c478bd9Sstevel@tonic-gate #else
21037c478bd9Sstevel@tonic-gate #define	CPUINFO_CPUWIDTH	8
21047c478bd9Sstevel@tonic-gate #define	CPUINFO_TWIDTH		8
21057c478bd9Sstevel@tonic-gate #endif
21067c478bd9Sstevel@tonic-gate 
21077c478bd9Sstevel@tonic-gate #define	CPUINFO_THRDELT		(CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 9)
21087c478bd9Sstevel@tonic-gate #define	CPUINFO_FLAGDELT	(CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 4)
21097c478bd9Sstevel@tonic-gate #define	CPUINFO_ITHRDELT	4
21107c478bd9Sstevel@tonic-gate 
21117c478bd9Sstevel@tonic-gate #define	CPUINFO_INDENT	mdb_printf("%*s", CPUINFO_THRDELT, \
21127c478bd9Sstevel@tonic-gate     flagline < nflaglines ? flagbuf[flagline++] : "")
21137c478bd9Sstevel@tonic-gate 
21147c478bd9Sstevel@tonic-gate int
21157c478bd9Sstevel@tonic-gate cpuinfo_walk_cpu(uintptr_t addr, const cpu_t *cpu, cpuinfo_data_t *cid)
21167c478bd9Sstevel@tonic-gate {
21177c478bd9Sstevel@tonic-gate 	kthread_t t;
21187c478bd9Sstevel@tonic-gate 	disp_t disp;
21197c478bd9Sstevel@tonic-gate 	proc_t p;
21207c478bd9Sstevel@tonic-gate 	uintptr_t pinned;
21217c478bd9Sstevel@tonic-gate 	char **flagbuf;
21227c478bd9Sstevel@tonic-gate 	int nflaglines = 0, flagline = 0, bspl, rval = WALK_NEXT;
21237c478bd9Sstevel@tonic-gate 
21247c478bd9Sstevel@tonic-gate 	const char *flags[] = {
21257c478bd9Sstevel@tonic-gate 	    "RUNNING", "READY", "QUIESCED", "EXISTS",
21267c478bd9Sstevel@tonic-gate 	    "ENABLE", "OFFLINE", "POWEROFF", "FROZEN",
21277c478bd9Sstevel@tonic-gate 	    "SPARE", "FAULTED", NULL
21287c478bd9Sstevel@tonic-gate 	};
21297c478bd9Sstevel@tonic-gate 
21307c478bd9Sstevel@tonic-gate 	if (cid->cid_cpu != -1) {
21317c478bd9Sstevel@tonic-gate 		if (addr != cid->cid_cpu && cpu->cpu_id != cid->cid_cpu)
21327c478bd9Sstevel@tonic-gate 			return (WALK_NEXT);
21337c478bd9Sstevel@tonic-gate 
21347c478bd9Sstevel@tonic-gate 		/*
21357c478bd9Sstevel@tonic-gate 		 * Set cid_cpu to -1 to indicate that we found a matching CPU.
21367c478bd9Sstevel@tonic-gate 		 */
21377c478bd9Sstevel@tonic-gate 		cid->cid_cpu = -1;
21387c478bd9Sstevel@tonic-gate 		rval = WALK_DONE;
21397c478bd9Sstevel@tonic-gate 	}
21407c478bd9Sstevel@tonic-gate 
21417c478bd9Sstevel@tonic-gate 	if (cid->cid_print_head) {
21427c478bd9Sstevel@tonic-gate 		mdb_printf("%3s %-*s %3s %4s %4s %3s %4s %5s %-6s %-*s %s\n",
21437c478bd9Sstevel@tonic-gate 		    "ID", CPUINFO_CPUWIDTH, "ADDR", "FLG", "NRUN", "BSPL",
21447c478bd9Sstevel@tonic-gate 		    "PRI", "RNRN", "KRNRN", "SWITCH", CPUINFO_TWIDTH, "THREAD",
21457c478bd9Sstevel@tonic-gate 		    "PROC");
21467c478bd9Sstevel@tonic-gate 		cid->cid_print_head = FALSE;
21477c478bd9Sstevel@tonic-gate 	}
21487c478bd9Sstevel@tonic-gate 
21497c478bd9Sstevel@tonic-gate 	bspl = cpu->cpu_base_spl;
21507c478bd9Sstevel@tonic-gate 
21517c478bd9Sstevel@tonic-gate 	if (mdb_vread(&disp, sizeof (disp_t), (uintptr_t)cpu->cpu_disp) == -1) {
21527c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read disp_t at %p", cpu->cpu_disp);
21537c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
21547c478bd9Sstevel@tonic-gate 	}
21557c478bd9Sstevel@tonic-gate 
21567c478bd9Sstevel@tonic-gate 	mdb_printf("%3d %0*p %3x %4d %4d ",
21577c478bd9Sstevel@tonic-gate 	    cpu->cpu_id, CPUINFO_CPUWIDTH, addr, cpu->cpu_flags,
21587c478bd9Sstevel@tonic-gate 	    disp.disp_nrunnable, bspl);
21597c478bd9Sstevel@tonic-gate 
21607c478bd9Sstevel@tonic-gate 	if (mdb_vread(&t, sizeof (t), (uintptr_t)cpu->cpu_thread) != -1) {
21617c478bd9Sstevel@tonic-gate 		mdb_printf("%3d ", t.t_pri);
21627c478bd9Sstevel@tonic-gate 	} else {
21637c478bd9Sstevel@tonic-gate 		mdb_printf("%3s ", "-");
21647c478bd9Sstevel@tonic-gate 	}
21657c478bd9Sstevel@tonic-gate 
21667c478bd9Sstevel@tonic-gate 	mdb_printf("%4s %5s ", cpu->cpu_runrun ? "yes" : "no",
21677c478bd9Sstevel@tonic-gate 	    cpu->cpu_kprunrun ? "yes" : "no");
21687c478bd9Sstevel@tonic-gate 
21697c478bd9Sstevel@tonic-gate 	if (cpu->cpu_last_swtch) {
21707c478bd9Sstevel@tonic-gate 		clock_t lbolt;
21717c478bd9Sstevel@tonic-gate 
21727c478bd9Sstevel@tonic-gate 		if (mdb_vread(&lbolt, sizeof (lbolt), cid->cid_lbolt) == -1) {
21737c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read lbolt at %p", cid->cid_lbolt);
21747c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
21757c478bd9Sstevel@tonic-gate 		}
21767c478bd9Sstevel@tonic-gate 		mdb_printf("t-%-4d ", lbolt - cpu->cpu_last_swtch);
21777c478bd9Sstevel@tonic-gate 	} else {
21787c478bd9Sstevel@tonic-gate 		mdb_printf("%-6s ", "-");
21797c478bd9Sstevel@tonic-gate 	}
21807c478bd9Sstevel@tonic-gate 
21817c478bd9Sstevel@tonic-gate 	mdb_printf("%0*p", CPUINFO_TWIDTH, cpu->cpu_thread);
21827c478bd9Sstevel@tonic-gate 
21837c478bd9Sstevel@tonic-gate 	if (cpu->cpu_thread == cpu->cpu_idle_thread)
21847c478bd9Sstevel@tonic-gate 		mdb_printf(" (idle)\n");
21857c478bd9Sstevel@tonic-gate 	else if (cpu->cpu_thread == NULL)
21867c478bd9Sstevel@tonic-gate 		mdb_printf(" -\n");
21877c478bd9Sstevel@tonic-gate 	else {
21887c478bd9Sstevel@tonic-gate 		if (mdb_vread(&p, sizeof (p), (uintptr_t)t.t_procp) != -1) {
21897c478bd9Sstevel@tonic-gate 			mdb_printf(" %s\n", p.p_user.u_comm);
21907c478bd9Sstevel@tonic-gate 		} else {
21917c478bd9Sstevel@tonic-gate 			mdb_printf(" ?\n");
21927c478bd9Sstevel@tonic-gate 		}
21937c478bd9Sstevel@tonic-gate 	}
21947c478bd9Sstevel@tonic-gate 
21957c478bd9Sstevel@tonic-gate 	flagbuf = mdb_zalloc(sizeof (flags), UM_SLEEP | UM_GC);
21967c478bd9Sstevel@tonic-gate 
21977c478bd9Sstevel@tonic-gate 	if (cid->cid_print_flags) {
21987c478bd9Sstevel@tonic-gate 		int first = 1, i, j, k;
21997c478bd9Sstevel@tonic-gate 		char *s;
22007c478bd9Sstevel@tonic-gate 
22017c478bd9Sstevel@tonic-gate 		cid->cid_print_head = TRUE;
22027c478bd9Sstevel@tonic-gate 
22037c478bd9Sstevel@tonic-gate 		for (i = 1, j = 0; flags[j] != NULL; i <<= 1, j++) {
22047c478bd9Sstevel@tonic-gate 			if (!(cpu->cpu_flags & i))
22057c478bd9Sstevel@tonic-gate 				continue;
22067c478bd9Sstevel@tonic-gate 
22077c478bd9Sstevel@tonic-gate 			if (first) {
22087c478bd9Sstevel@tonic-gate 				s = mdb_alloc(CPUINFO_THRDELT + 1,
22097c478bd9Sstevel@tonic-gate 				    UM_GC | UM_SLEEP);
22107c478bd9Sstevel@tonic-gate 
22117c478bd9Sstevel@tonic-gate 				(void) mdb_snprintf(s, CPUINFO_THRDELT + 1,
22127c478bd9Sstevel@tonic-gate 				    "%*s|%*s", CPUINFO_FLAGDELT, "",
22137c478bd9Sstevel@tonic-gate 				    CPUINFO_THRDELT - 1 - CPUINFO_FLAGDELT, "");
22147c478bd9Sstevel@tonic-gate 				flagbuf[nflaglines++] = s;
22157c478bd9Sstevel@tonic-gate 			}
22167c478bd9Sstevel@tonic-gate 
22177c478bd9Sstevel@tonic-gate 			s = mdb_alloc(CPUINFO_THRDELT + 1, UM_GC | UM_SLEEP);
22187c478bd9Sstevel@tonic-gate 			(void) mdb_snprintf(s, CPUINFO_THRDELT + 1, "%*s%*s %s",
22197c478bd9Sstevel@tonic-gate 			    CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH -
22207c478bd9Sstevel@tonic-gate 			    CPUINFO_FLAGWIDTH, "", CPUINFO_FLAGWIDTH, flags[j],
22217c478bd9Sstevel@tonic-gate 			    first ? "<--+" : "");
22227c478bd9Sstevel@tonic-gate 
22237c478bd9Sstevel@tonic-gate 			for (k = strlen(s); k < CPUINFO_THRDELT; k++)
22247c478bd9Sstevel@tonic-gate 				s[k] = ' ';
22257c478bd9Sstevel@tonic-gate 			s[k] = '\0';
22267c478bd9Sstevel@tonic-gate 
22277c478bd9Sstevel@tonic-gate 			flagbuf[nflaglines++] = s;
22287c478bd9Sstevel@tonic-gate 			first = 0;
22297c478bd9Sstevel@tonic-gate 		}
22307c478bd9Sstevel@tonic-gate 	}
22317c478bd9Sstevel@tonic-gate 
22327c478bd9Sstevel@tonic-gate 	if (cid->cid_print_ithr) {
22337c478bd9Sstevel@tonic-gate 		int i, found_one = FALSE;
22347c478bd9Sstevel@tonic-gate 		int print_thr = disp.disp_nrunnable && cid->cid_print_thr;
22357c478bd9Sstevel@tonic-gate 
22367c478bd9Sstevel@tonic-gate 		for (i = NINTR - 1; i >= 0; i--) {
22377c478bd9Sstevel@tonic-gate 			uintptr_t iaddr = cid->cid_ithr[cpu->cpu_id][i];
22387c478bd9Sstevel@tonic-gate 
22397c478bd9Sstevel@tonic-gate 			if (iaddr == NULL)
22407c478bd9Sstevel@tonic-gate 				continue;
22417c478bd9Sstevel@tonic-gate 
22427c478bd9Sstevel@tonic-gate 			if (!found_one) {
22437c478bd9Sstevel@tonic-gate 				found_one = TRUE;
22447c478bd9Sstevel@tonic-gate 
22457c478bd9Sstevel@tonic-gate 				CPUINFO_INDENT;
22467c478bd9Sstevel@tonic-gate 				mdb_printf("%c%*s|\n", print_thr ? '|' : ' ',
22477c478bd9Sstevel@tonic-gate 				    CPUINFO_ITHRDELT, "");
22487c478bd9Sstevel@tonic-gate 
22497c478bd9Sstevel@tonic-gate 				CPUINFO_INDENT;
22507c478bd9Sstevel@tonic-gate 				mdb_printf("%c%*s+--> %3s %s\n",
22517c478bd9Sstevel@tonic-gate 				    print_thr ? '|' : ' ', CPUINFO_ITHRDELT,
22527c478bd9Sstevel@tonic-gate 				    "", "PIL", "THREAD");
22537c478bd9Sstevel@tonic-gate 			}
22547c478bd9Sstevel@tonic-gate 
22557c478bd9Sstevel@tonic-gate 			if (mdb_vread(&t, sizeof (t), iaddr) == -1) {
22567c478bd9Sstevel@tonic-gate 				mdb_warn("failed to read kthread_t at %p",
22577c478bd9Sstevel@tonic-gate 				    iaddr);
22587c478bd9Sstevel@tonic-gate 				return (WALK_ERR);
22597c478bd9Sstevel@tonic-gate 			}
22607c478bd9Sstevel@tonic-gate 
22617c478bd9Sstevel@tonic-gate 			CPUINFO_INDENT;
22627c478bd9Sstevel@tonic-gate 			mdb_printf("%c%*s     %3d %0*p\n",
22637c478bd9Sstevel@tonic-gate 			    print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "",
22647c478bd9Sstevel@tonic-gate 			    t.t_pil, CPUINFO_TWIDTH, iaddr);
22657c478bd9Sstevel@tonic-gate 
22667c478bd9Sstevel@tonic-gate 			pinned = (uintptr_t)t.t_intr;
22677c478bd9Sstevel@tonic-gate 		}
22687c478bd9Sstevel@tonic-gate 
22697c478bd9Sstevel@tonic-gate 		if (found_one && pinned != NULL) {
22707c478bd9Sstevel@tonic-gate 			cid->cid_print_head = TRUE;
22717c478bd9Sstevel@tonic-gate 			(void) strcpy(p.p_user.u_comm, "?");
22727c478bd9Sstevel@tonic-gate 
22737c478bd9Sstevel@tonic-gate 			if (mdb_vread(&t, sizeof (t),
22747c478bd9Sstevel@tonic-gate 			    (uintptr_t)pinned) == -1) {
22757c478bd9Sstevel@tonic-gate 				mdb_warn("failed to read kthread_t at %p",
22767c478bd9Sstevel@tonic-gate 				    pinned);
22777c478bd9Sstevel@tonic-gate 				return (WALK_ERR);
22787c478bd9Sstevel@tonic-gate 			}
22797c478bd9Sstevel@tonic-gate 			if (mdb_vread(&p, sizeof (p),
22807c478bd9Sstevel@tonic-gate 			    (uintptr_t)t.t_procp) == -1) {
22817c478bd9Sstevel@tonic-gate 				mdb_warn("failed to read proc_t at %p",
22827c478bd9Sstevel@tonic-gate 				    t.t_procp);
22837c478bd9Sstevel@tonic-gate 				return (WALK_ERR);
22847c478bd9Sstevel@tonic-gate 			}
22857c478bd9Sstevel@tonic-gate 
22867c478bd9Sstevel@tonic-gate 			CPUINFO_INDENT;
22877c478bd9Sstevel@tonic-gate 			mdb_printf("%c%*s     %3s %0*p %s\n",
22887c478bd9Sstevel@tonic-gate 			    print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", "-",
22897c478bd9Sstevel@tonic-gate 			    CPUINFO_TWIDTH, pinned,
22907c478bd9Sstevel@tonic-gate 			    pinned == (uintptr_t)cpu->cpu_idle_thread ?
22917c478bd9Sstevel@tonic-gate 			    "(idle)" : p.p_user.u_comm);
22927c478bd9Sstevel@tonic-gate 		}
22937c478bd9Sstevel@tonic-gate 	}
22947c478bd9Sstevel@tonic-gate 
22957c478bd9Sstevel@tonic-gate 	if (disp.disp_nrunnable && cid->cid_print_thr) {
22967c478bd9Sstevel@tonic-gate 		dispq_t *dq;
22977c478bd9Sstevel@tonic-gate 
22987c478bd9Sstevel@tonic-gate 		int i, npri = disp.disp_npri;
22997c478bd9Sstevel@tonic-gate 
23007c478bd9Sstevel@tonic-gate 		dq = mdb_alloc(sizeof (dispq_t) * npri, UM_SLEEP | UM_GC);
23017c478bd9Sstevel@tonic-gate 
23027c478bd9Sstevel@tonic-gate 		if (mdb_vread(dq, sizeof (dispq_t) * npri,
23037c478bd9Sstevel@tonic-gate 		    (uintptr_t)disp.disp_q) == -1) {
23047c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read dispq_t at %p", disp.disp_q);
23057c478bd9Sstevel@tonic-gate 			return (WALK_ERR);
23067c478bd9Sstevel@tonic-gate 		}
23077c478bd9Sstevel@tonic-gate 
23087c478bd9Sstevel@tonic-gate 		CPUINFO_INDENT;
23097c478bd9Sstevel@tonic-gate 		mdb_printf("|\n");
23107c478bd9Sstevel@tonic-gate 
23117c478bd9Sstevel@tonic-gate 		CPUINFO_INDENT;
23127c478bd9Sstevel@tonic-gate 		mdb_printf("+-->  %3s %-*s %s\n", "PRI",
23137c478bd9Sstevel@tonic-gate 		    CPUINFO_TWIDTH, "THREAD", "PROC");
23147c478bd9Sstevel@tonic-gate 
23157c478bd9Sstevel@tonic-gate 		for (i = npri - 1; i >= 0; i--) {
23167c478bd9Sstevel@tonic-gate 			uintptr_t taddr = (uintptr_t)dq[i].dq_first;
23177c478bd9Sstevel@tonic-gate 
23187c478bd9Sstevel@tonic-gate 			while (taddr != NULL) {
23197c478bd9Sstevel@tonic-gate 				if (mdb_vread(&t, sizeof (t), taddr) == -1) {
23207c478bd9Sstevel@tonic-gate 					mdb_warn("failed to read kthread_t "
23217c478bd9Sstevel@tonic-gate 					    "at %p", taddr);
23227c478bd9Sstevel@tonic-gate 					return (WALK_ERR);
23237c478bd9Sstevel@tonic-gate 				}
23247c478bd9Sstevel@tonic-gate 				if (mdb_vread(&p, sizeof (p),
23257c478bd9Sstevel@tonic-gate 				    (uintptr_t)t.t_procp) == -1) {
23267c478bd9Sstevel@tonic-gate 					mdb_warn("failed to read proc_t at %p",
23277c478bd9Sstevel@tonic-gate 					    t.t_procp);
23287c478bd9Sstevel@tonic-gate 					return (WALK_ERR);
23297c478bd9Sstevel@tonic-gate 				}
23307c478bd9Sstevel@tonic-gate 
23317c478bd9Sstevel@tonic-gate 				CPUINFO_INDENT;
23327c478bd9Sstevel@tonic-gate 				mdb_printf("      %3d %0*p %s\n", t.t_pri,
23337c478bd9Sstevel@tonic-gate 				    CPUINFO_TWIDTH, taddr, p.p_user.u_comm);
23347c478bd9Sstevel@tonic-gate 
23357c478bd9Sstevel@tonic-gate 				taddr = (uintptr_t)t.t_link;
23367c478bd9Sstevel@tonic-gate 			}
23377c478bd9Sstevel@tonic-gate 		}
23387c478bd9Sstevel@tonic-gate 		cid->cid_print_head = TRUE;
23397c478bd9Sstevel@tonic-gate 	}
23407c478bd9Sstevel@tonic-gate 
23417c478bd9Sstevel@tonic-gate 	while (flagline < nflaglines)
23427c478bd9Sstevel@tonic-gate 		mdb_printf("%s\n", flagbuf[flagline++]);
23437c478bd9Sstevel@tonic-gate 
23447c478bd9Sstevel@tonic-gate 	if (cid->cid_print_head)
23457c478bd9Sstevel@tonic-gate 		mdb_printf("\n");
23467c478bd9Sstevel@tonic-gate 
23477c478bd9Sstevel@tonic-gate 	return (rval);
23487c478bd9Sstevel@tonic-gate }
23497c478bd9Sstevel@tonic-gate 
23507c478bd9Sstevel@tonic-gate int
23517c478bd9Sstevel@tonic-gate cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
23527c478bd9Sstevel@tonic-gate {
23537c478bd9Sstevel@tonic-gate 	uint_t verbose = FALSE;
23547c478bd9Sstevel@tonic-gate 	cpuinfo_data_t cid;
23557c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
23567c478bd9Sstevel@tonic-gate 	clock_t lbolt;
23577c478bd9Sstevel@tonic-gate 
23587c478bd9Sstevel@tonic-gate 	cid.cid_print_ithr = FALSE;
23597c478bd9Sstevel@tonic-gate 	cid.cid_print_thr = FALSE;
23607c478bd9Sstevel@tonic-gate 	cid.cid_print_flags = FALSE;
23617c478bd9Sstevel@tonic-gate 	cid.cid_print_head = DCMD_HDRSPEC(flags) ? TRUE : FALSE;
23627c478bd9Sstevel@tonic-gate 	cid.cid_cpu = -1;
23637c478bd9Sstevel@tonic-gate 
23647c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
23657c478bd9Sstevel@tonic-gate 		cid.cid_cpu = addr;
23667c478bd9Sstevel@tonic-gate 
23677c478bd9Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
23687c478bd9Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc)
23697c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
23707c478bd9Sstevel@tonic-gate 
23717c478bd9Sstevel@tonic-gate 	if (verbose) {
23727c478bd9Sstevel@tonic-gate 		cid.cid_print_ithr = TRUE;
23737c478bd9Sstevel@tonic-gate 		cid.cid_print_thr = TRUE;
23747c478bd9Sstevel@tonic-gate 		cid.cid_print_flags = TRUE;
23757c478bd9Sstevel@tonic-gate 		cid.cid_print_head = TRUE;
23767c478bd9Sstevel@tonic-gate 	}
23777c478bd9Sstevel@tonic-gate 
23787c478bd9Sstevel@tonic-gate 	if (cid.cid_print_ithr) {
23797c478bd9Sstevel@tonic-gate 		int i;
23807c478bd9Sstevel@tonic-gate 
23817c478bd9Sstevel@tonic-gate 		cid.cid_ithr = mdb_alloc(sizeof (uintptr_t **)
23827c478bd9Sstevel@tonic-gate 		    * NCPU, UM_SLEEP | UM_GC);
23837c478bd9Sstevel@tonic-gate 
23847c478bd9Sstevel@tonic-gate 		for (i = 0; i < NCPU; i++)
23857c478bd9Sstevel@tonic-gate 			cid.cid_ithr[i] = mdb_zalloc(sizeof (uintptr_t *) *
23867c478bd9Sstevel@tonic-gate 			    NINTR, UM_SLEEP | UM_GC);
23877c478bd9Sstevel@tonic-gate 
23887c478bd9Sstevel@tonic-gate 		if (mdb_walk("thread", (mdb_walk_cb_t)cpuinfo_walk_ithread,
23897c478bd9Sstevel@tonic-gate 		    &cid) == -1) {
23907c478bd9Sstevel@tonic-gate 			mdb_warn("couldn't walk thread");
23917c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
23927c478bd9Sstevel@tonic-gate 		}
23937c478bd9Sstevel@tonic-gate 	}
23947c478bd9Sstevel@tonic-gate 
23957c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("panic_lbolt", &sym) == -1) {
23967c478bd9Sstevel@tonic-gate 		mdb_warn("failed to find panic_lbolt");
23977c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
23987c478bd9Sstevel@tonic-gate 	}
23997c478bd9Sstevel@tonic-gate 
24007c478bd9Sstevel@tonic-gate 	cid.cid_lbolt = (uintptr_t)sym.st_value;
24017c478bd9Sstevel@tonic-gate 
24027c478bd9Sstevel@tonic-gate 	if (mdb_vread(&lbolt, sizeof (lbolt), cid.cid_lbolt) == -1) {
24037c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read panic_lbolt");
24047c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
24057c478bd9Sstevel@tonic-gate 	}
24067c478bd9Sstevel@tonic-gate 
24077c478bd9Sstevel@tonic-gate 	if (lbolt == 0) {
24087c478bd9Sstevel@tonic-gate 		if (mdb_lookup_by_name("lbolt", &sym) == -1) {
24097c478bd9Sstevel@tonic-gate 			mdb_warn("failed to find lbolt");
24107c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
24117c478bd9Sstevel@tonic-gate 		}
24127c478bd9Sstevel@tonic-gate 		cid.cid_lbolt = (uintptr_t)sym.st_value;
24137c478bd9Sstevel@tonic-gate 	}
24147c478bd9Sstevel@tonic-gate 
24157c478bd9Sstevel@tonic-gate 	if (mdb_walk("cpu", (mdb_walk_cb_t)cpuinfo_walk_cpu, &cid) == -1) {
24167c478bd9Sstevel@tonic-gate 		mdb_warn("can't walk cpus");
24177c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
24187c478bd9Sstevel@tonic-gate 	}
24197c478bd9Sstevel@tonic-gate 
24207c478bd9Sstevel@tonic-gate 	if (cid.cid_cpu != -1) {
24217c478bd9Sstevel@tonic-gate 		/*
24227c478bd9Sstevel@tonic-gate 		 * We didn't find this CPU when we walked through the CPUs
24237c478bd9Sstevel@tonic-gate 		 * (i.e. the address specified doesn't show up in the "cpu"
24247c478bd9Sstevel@tonic-gate 		 * walk).  However, the specified address may still correspond
24257c478bd9Sstevel@tonic-gate 		 * to a valid cpu_t (for example, if the specified address is
24267c478bd9Sstevel@tonic-gate 		 * the actual panicking cpu_t and not the cached panic_cpu).
24277c478bd9Sstevel@tonic-gate 		 * Point is:  even if we didn't find it, we still want to try
24287c478bd9Sstevel@tonic-gate 		 * to print the specified address as a cpu_t.
24297c478bd9Sstevel@tonic-gate 		 */
24307c478bd9Sstevel@tonic-gate 		cpu_t cpu;
24317c478bd9Sstevel@tonic-gate 
24327c478bd9Sstevel@tonic-gate 		if (mdb_vread(&cpu, sizeof (cpu), cid.cid_cpu) == -1) {
24337c478bd9Sstevel@tonic-gate 			mdb_warn("%p is neither a valid CPU ID nor a "
24347c478bd9Sstevel@tonic-gate 			    "valid cpu_t address\n", cid.cid_cpu);
24357c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
24367c478bd9Sstevel@tonic-gate 		}
24377c478bd9Sstevel@tonic-gate 
24387c478bd9Sstevel@tonic-gate 		(void) cpuinfo_walk_cpu(cid.cid_cpu, &cpu, &cid);
24397c478bd9Sstevel@tonic-gate 	}
24407c478bd9Sstevel@tonic-gate 
24417c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
24427c478bd9Sstevel@tonic-gate }
24437c478bd9Sstevel@tonic-gate 
24447c478bd9Sstevel@tonic-gate /*ARGSUSED*/
24457c478bd9Sstevel@tonic-gate int
24467c478bd9Sstevel@tonic-gate flipone(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
24477c478bd9Sstevel@tonic-gate {
24487c478bd9Sstevel@tonic-gate 	int i;
24497c478bd9Sstevel@tonic-gate 
24507c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
24517c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
24527c478bd9Sstevel@tonic-gate 
24537c478bd9Sstevel@tonic-gate 	for (i = 0; i < sizeof (addr) * NBBY; i++)
24547c478bd9Sstevel@tonic-gate 		mdb_printf("%p\n", addr ^ (1UL << i));
24557c478bd9Sstevel@tonic-gate 
24567c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
24577c478bd9Sstevel@tonic-gate }
24587c478bd9Sstevel@tonic-gate 
24597c478bd9Sstevel@tonic-gate /*
24607c478bd9Sstevel@tonic-gate  * Grumble, grumble.
24617c478bd9Sstevel@tonic-gate  */
24627c478bd9Sstevel@tonic-gate #define	SMAP_HASHFUNC(vp, off)	\
24637c478bd9Sstevel@tonic-gate 	((((uintptr_t)(vp) >> 6) + ((uintptr_t)(vp) >> 3) + \
24647c478bd9Sstevel@tonic-gate 	((off) >> MAXBSHIFT)) & smd_hashmsk)
24657c478bd9Sstevel@tonic-gate 
24667c478bd9Sstevel@tonic-gate int
24677c478bd9Sstevel@tonic-gate vnode2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
24687c478bd9Sstevel@tonic-gate {
24697c478bd9Sstevel@tonic-gate 	long smd_hashmsk;
24707c478bd9Sstevel@tonic-gate 	int hash;
24717c478bd9Sstevel@tonic-gate 	uintptr_t offset = 0;
24727c478bd9Sstevel@tonic-gate 	struct smap smp;
24737c478bd9Sstevel@tonic-gate 	uintptr_t saddr, kaddr;
24747c478bd9Sstevel@tonic-gate 	uintptr_t smd_hash, smd_smap;
24757c478bd9Sstevel@tonic-gate 	struct seg seg;
24767c478bd9Sstevel@tonic-gate 
24777c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
24787c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
24797c478bd9Sstevel@tonic-gate 
24807c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&smd_hashmsk, "smd_hashmsk") == -1) {
24817c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read smd_hashmsk");
24827c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
24837c478bd9Sstevel@tonic-gate 	}
24847c478bd9Sstevel@tonic-gate 
24857c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&smd_hash, "smd_hash") == -1) {
24867c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read smd_hash");
24877c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
24887c478bd9Sstevel@tonic-gate 	}
24897c478bd9Sstevel@tonic-gate 
24907c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&smd_smap, "smd_smap") == -1) {
24917c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read smd_hash");
24927c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
24937c478bd9Sstevel@tonic-gate 	}
24947c478bd9Sstevel@tonic-gate 
24957c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&kaddr, "segkmap") == -1) {
24967c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read segkmap");
24977c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
24987c478bd9Sstevel@tonic-gate 	}
24997c478bd9Sstevel@tonic-gate 
25007c478bd9Sstevel@tonic-gate 	if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) {
25017c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read segkmap at %p", kaddr);
25027c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
25037c478bd9Sstevel@tonic-gate 	}
25047c478bd9Sstevel@tonic-gate 
25057c478bd9Sstevel@tonic-gate 	if (argc != 0) {
25067c478bd9Sstevel@tonic-gate 		const mdb_arg_t *arg = &argv[0];
25077c478bd9Sstevel@tonic-gate 
25087c478bd9Sstevel@tonic-gate 		if (arg->a_type == MDB_TYPE_IMMEDIATE)
25097c478bd9Sstevel@tonic-gate 			offset = arg->a_un.a_val;
25107c478bd9Sstevel@tonic-gate 		else
25117c478bd9Sstevel@tonic-gate 			offset = (uintptr_t)mdb_strtoull(arg->a_un.a_str);
25127c478bd9Sstevel@tonic-gate 	}
25137c478bd9Sstevel@tonic-gate 
25147c478bd9Sstevel@tonic-gate 	hash = SMAP_HASHFUNC(addr, offset);
25157c478bd9Sstevel@tonic-gate 
25167c478bd9Sstevel@tonic-gate 	if (mdb_vread(&saddr, sizeof (saddr),
25177c478bd9Sstevel@tonic-gate 	    smd_hash + hash * sizeof (uintptr_t)) == -1) {
25187c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't read smap at %p",
25197c478bd9Sstevel@tonic-gate 		    smd_hash + hash * sizeof (uintptr_t));
25207c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
25217c478bd9Sstevel@tonic-gate 	}
25227c478bd9Sstevel@tonic-gate 
25237c478bd9Sstevel@tonic-gate 	do {
25247c478bd9Sstevel@tonic-gate 		if (mdb_vread(&smp, sizeof (smp), saddr) == -1) {
25257c478bd9Sstevel@tonic-gate 			mdb_warn("couldn't read smap at %p", saddr);
25267c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
25277c478bd9Sstevel@tonic-gate 		}
25287c478bd9Sstevel@tonic-gate 
25297c478bd9Sstevel@tonic-gate 		if ((uintptr_t)smp.sm_vp == addr && smp.sm_off == offset) {
25307c478bd9Sstevel@tonic-gate 			mdb_printf("vnode %p, offs %p is smap %p, vaddr %p\n",
25317c478bd9Sstevel@tonic-gate 			    addr, offset, saddr, ((saddr - smd_smap) /
25327c478bd9Sstevel@tonic-gate 			    sizeof (smp)) * MAXBSIZE + seg.s_base);
25337c478bd9Sstevel@tonic-gate 			return (DCMD_OK);
25347c478bd9Sstevel@tonic-gate 		}
25357c478bd9Sstevel@tonic-gate 
25367c478bd9Sstevel@tonic-gate 		saddr = (uintptr_t)smp.sm_hash;
25377c478bd9Sstevel@tonic-gate 	} while (saddr != NULL);
25387c478bd9Sstevel@tonic-gate 
25397c478bd9Sstevel@tonic-gate 	mdb_printf("no smap for vnode %p, offs %p\n", addr, offset);
25407c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
25417c478bd9Sstevel@tonic-gate }
25427c478bd9Sstevel@tonic-gate 
25437c478bd9Sstevel@tonic-gate /*ARGSUSED*/
25447c478bd9Sstevel@tonic-gate int
25457c478bd9Sstevel@tonic-gate addr2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
25467c478bd9Sstevel@tonic-gate {
25477c478bd9Sstevel@tonic-gate 	uintptr_t kaddr;
25487c478bd9Sstevel@tonic-gate 	struct seg seg;
25497c478bd9Sstevel@tonic-gate 	struct segmap_data sd;
25507c478bd9Sstevel@tonic-gate 
25517c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
25527c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
25537c478bd9Sstevel@tonic-gate 
25547c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&kaddr, "segkmap") == -1) {
25557c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read segkmap");
25567c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
25577c478bd9Sstevel@tonic-gate 	}
25587c478bd9Sstevel@tonic-gate 
25597c478bd9Sstevel@tonic-gate 	if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) {
25607c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read segkmap at %p", kaddr);
25617c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
25627c478bd9Sstevel@tonic-gate 	}
25637c478bd9Sstevel@tonic-gate 
25647c478bd9Sstevel@tonic-gate 	if (mdb_vread(&sd, sizeof (sd), (uintptr_t)seg.s_data) == -1) {
25657c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read segmap_data at %p", seg.s_data);
25667c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
25677c478bd9Sstevel@tonic-gate 	}
25687c478bd9Sstevel@tonic-gate 
25697c478bd9Sstevel@tonic-gate 	mdb_printf("%p is smap %p\n", addr,
25707c478bd9Sstevel@tonic-gate 	    ((addr - (uintptr_t)seg.s_base) >> MAXBSHIFT) *
25717c478bd9Sstevel@tonic-gate 	    sizeof (struct smap) + (uintptr_t)sd.smd_sm);
25727c478bd9Sstevel@tonic-gate 
25737c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
25747c478bd9Sstevel@tonic-gate }
25757c478bd9Sstevel@tonic-gate 
25767c478bd9Sstevel@tonic-gate int
25777c478bd9Sstevel@tonic-gate as2proc_walk(uintptr_t addr, const proc_t *p, struct as **asp)
25787c478bd9Sstevel@tonic-gate {
25797c478bd9Sstevel@tonic-gate 	if (p->p_as == *asp)
25807c478bd9Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
25817c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
25827c478bd9Sstevel@tonic-gate }
25837c478bd9Sstevel@tonic-gate 
25847c478bd9Sstevel@tonic-gate /*ARGSUSED*/
25857c478bd9Sstevel@tonic-gate int
25867c478bd9Sstevel@tonic-gate as2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
25877c478bd9Sstevel@tonic-gate {
25887c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC) || argc != 0)
25897c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
25907c478bd9Sstevel@tonic-gate 
25917c478bd9Sstevel@tonic-gate 	if (mdb_walk("proc", (mdb_walk_cb_t)as2proc_walk, &addr) == -1) {
25927c478bd9Sstevel@tonic-gate 		mdb_warn("failed to walk proc");
25937c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
25947c478bd9Sstevel@tonic-gate 	}
25957c478bd9Sstevel@tonic-gate 
25967c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
25977c478bd9Sstevel@tonic-gate }
25987c478bd9Sstevel@tonic-gate 
25997c478bd9Sstevel@tonic-gate /*ARGSUSED*/
26007c478bd9Sstevel@tonic-gate int
26017c478bd9Sstevel@tonic-gate ptree_walk(uintptr_t addr, const proc_t *p, void *ignored)
26027c478bd9Sstevel@tonic-gate {
26037c478bd9Sstevel@tonic-gate 	proc_t parent;
26047c478bd9Sstevel@tonic-gate 	int ident = 0;
26057c478bd9Sstevel@tonic-gate 	uintptr_t paddr;
26067c478bd9Sstevel@tonic-gate 
26077c478bd9Sstevel@tonic-gate 	for (paddr = (uintptr_t)p->p_parent; paddr != NULL; ident += 5) {
26087c478bd9Sstevel@tonic-gate 		mdb_vread(&parent, sizeof (parent), paddr);
26097c478bd9Sstevel@tonic-gate 		paddr = (uintptr_t)parent.p_parent;
26107c478bd9Sstevel@tonic-gate 	}
26117c478bd9Sstevel@tonic-gate 
26127c478bd9Sstevel@tonic-gate 	mdb_inc_indent(ident);
26137c478bd9Sstevel@tonic-gate 	mdb_printf("%0?p  %s\n", addr, p->p_user.u_comm);
26147c478bd9Sstevel@tonic-gate 	mdb_dec_indent(ident);
26157c478bd9Sstevel@tonic-gate 
26167c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
26177c478bd9Sstevel@tonic-gate }
26187c478bd9Sstevel@tonic-gate 
26197c478bd9Sstevel@tonic-gate void
26207c478bd9Sstevel@tonic-gate ptree_ancestors(uintptr_t addr, uintptr_t start)
26217c478bd9Sstevel@tonic-gate {
26227c478bd9Sstevel@tonic-gate 	proc_t p;
26237c478bd9Sstevel@tonic-gate 
26247c478bd9Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (p), addr) == -1) {
26257c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't read ancestor at %p", addr);
26267c478bd9Sstevel@tonic-gate 		return;
26277c478bd9Sstevel@tonic-gate 	}
26287c478bd9Sstevel@tonic-gate 
26297c478bd9Sstevel@tonic-gate 	if (p.p_parent != NULL)
26307c478bd9Sstevel@tonic-gate 		ptree_ancestors((uintptr_t)p.p_parent, start);
26317c478bd9Sstevel@tonic-gate 
26327c478bd9Sstevel@tonic-gate 	if (addr != start)
26337c478bd9Sstevel@tonic-gate 		(void) ptree_walk(addr, &p, NULL);
26347c478bd9Sstevel@tonic-gate }
26357c478bd9Sstevel@tonic-gate 
26367c478bd9Sstevel@tonic-gate /*ARGSUSED*/
26377c478bd9Sstevel@tonic-gate int
26387c478bd9Sstevel@tonic-gate ptree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
26397c478bd9Sstevel@tonic-gate {
26407c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
26417c478bd9Sstevel@tonic-gate 		addr = NULL;
26427c478bd9Sstevel@tonic-gate 	else
26437c478bd9Sstevel@tonic-gate 		ptree_ancestors(addr, addr);
26447c478bd9Sstevel@tonic-gate 
26457c478bd9Sstevel@tonic-gate 	if (mdb_pwalk("proc", (mdb_walk_cb_t)ptree_walk, NULL, addr) == -1) {
26467c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't walk 'proc'");
26477c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
26487c478bd9Sstevel@tonic-gate 	}
26497c478bd9Sstevel@tonic-gate 
26507c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
26517c478bd9Sstevel@tonic-gate }
26527c478bd9Sstevel@tonic-gate 
26537c478bd9Sstevel@tonic-gate /*ARGSUSED*/
26547c478bd9Sstevel@tonic-gate static int
26557c478bd9Sstevel@tonic-gate fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
26567c478bd9Sstevel@tonic-gate {
26577c478bd9Sstevel@tonic-gate 	int fdnum;
26587c478bd9Sstevel@tonic-gate 	const mdb_arg_t *argp = &argv[0];
26597c478bd9Sstevel@tonic-gate 	proc_t p;
26607c478bd9Sstevel@tonic-gate 	uf_entry_t uf;
26617c478bd9Sstevel@tonic-gate 
26627c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
26637c478bd9Sstevel@tonic-gate 		mdb_warn("fd doesn't give global information\n");
26647c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
26657c478bd9Sstevel@tonic-gate 	}
26667c478bd9Sstevel@tonic-gate 	if (argc != 1)
26677c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
26687c478bd9Sstevel@tonic-gate 
26697c478bd9Sstevel@tonic-gate 	if (argp->a_type == MDB_TYPE_IMMEDIATE)
26707c478bd9Sstevel@tonic-gate 		fdnum = argp->a_un.a_val;
26717c478bd9Sstevel@tonic-gate 	else
26727c478bd9Sstevel@tonic-gate 		fdnum = mdb_strtoull(argp->a_un.a_str);
26737c478bd9Sstevel@tonic-gate 
26747c478bd9Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (struct proc), addr) == -1) {
26757c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't read proc_t at %p", addr);
26767c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
26777c478bd9Sstevel@tonic-gate 	}
26787c478bd9Sstevel@tonic-gate 	if (fdnum > p.p_user.u_finfo.fi_nfiles) {
26797c478bd9Sstevel@tonic-gate 		mdb_warn("process %p only has %d files open.\n",
26807c478bd9Sstevel@tonic-gate 		    addr, p.p_user.u_finfo.fi_nfiles);
26817c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
26827c478bd9Sstevel@tonic-gate 	}
26837c478bd9Sstevel@tonic-gate 	if (mdb_vread(&uf, sizeof (uf_entry_t),
26847c478bd9Sstevel@tonic-gate 	    (uintptr_t)&p.p_user.u_finfo.fi_list[fdnum]) == -1) {
26857c478bd9Sstevel@tonic-gate 		mdb_warn("couldn't read uf_entry_t at %p",
26867c478bd9Sstevel@tonic-gate 		    &p.p_user.u_finfo.fi_list[fdnum]);
26877c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
26887c478bd9Sstevel@tonic-gate 	}
26897c478bd9Sstevel@tonic-gate 
26907c478bd9Sstevel@tonic-gate 	mdb_printf("%p\n", uf.uf_file);
26917c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
26927c478bd9Sstevel@tonic-gate }
26937c478bd9Sstevel@tonic-gate 
26947c478bd9Sstevel@tonic-gate /*ARGSUSED*/
26957c478bd9Sstevel@tonic-gate static int
26967c478bd9Sstevel@tonic-gate pid2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
26977c478bd9Sstevel@tonic-gate {
26987c478bd9Sstevel@tonic-gate 	pid_t pid = (pid_t)addr;
26997c478bd9Sstevel@tonic-gate 
27007c478bd9Sstevel@tonic-gate 	if (argc != 0)
27017c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
27027c478bd9Sstevel@tonic-gate 
27037c478bd9Sstevel@tonic-gate 	if ((addr = mdb_pid2proc(pid, NULL)) == NULL) {
27047c478bd9Sstevel@tonic-gate 		mdb_warn("PID 0t%d not found\n", pid);
27057c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
27067c478bd9Sstevel@tonic-gate 	}
27077c478bd9Sstevel@tonic-gate 
27087c478bd9Sstevel@tonic-gate 	mdb_printf("%p\n", addr);
27097c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
27107c478bd9Sstevel@tonic-gate }
27117c478bd9Sstevel@tonic-gate 
27127c478bd9Sstevel@tonic-gate static char *sysfile_cmd[] = {
27137c478bd9Sstevel@tonic-gate 	"exclude:",
27147c478bd9Sstevel@tonic-gate 	"include:",
27157c478bd9Sstevel@tonic-gate 	"forceload:",
27167c478bd9Sstevel@tonic-gate 	"rootdev:",
27177c478bd9Sstevel@tonic-gate 	"rootfs:",
27187c478bd9Sstevel@tonic-gate 	"swapdev:",
27197c478bd9Sstevel@tonic-gate 	"swapfs:",
27207c478bd9Sstevel@tonic-gate 	"moddir:",
27217c478bd9Sstevel@tonic-gate 	"set",
27227c478bd9Sstevel@tonic-gate 	"unknown",
27237c478bd9Sstevel@tonic-gate };
27247c478bd9Sstevel@tonic-gate 
27257c478bd9Sstevel@tonic-gate static char *sysfile_ops[] = { "", "=", "&", "|" };
27267c478bd9Sstevel@tonic-gate 
27277c478bd9Sstevel@tonic-gate /*ARGSUSED*/
27287c478bd9Sstevel@tonic-gate static int
27297c478bd9Sstevel@tonic-gate sysfile_vmem_seg(uintptr_t addr, const vmem_seg_t *vsp, void **target)
27307c478bd9Sstevel@tonic-gate {
27317c478bd9Sstevel@tonic-gate 	if (vsp->vs_type == VMEM_ALLOC && (void *)vsp->vs_start == *target) {
27327c478bd9Sstevel@tonic-gate 		*target = NULL;
27337c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
27347c478bd9Sstevel@tonic-gate 	}
27357c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
27367c478bd9Sstevel@tonic-gate }
27377c478bd9Sstevel@tonic-gate 
27387c478bd9Sstevel@tonic-gate /*ARGSUSED*/
27397c478bd9Sstevel@tonic-gate static int
27407c478bd9Sstevel@tonic-gate sysfile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
27417c478bd9Sstevel@tonic-gate {
27427c478bd9Sstevel@tonic-gate 	struct sysparam *sysp, sys;
27437c478bd9Sstevel@tonic-gate 	char var[256];
27447c478bd9Sstevel@tonic-gate 	char modname[256];
27457c478bd9Sstevel@tonic-gate 	char val[256];
27467c478bd9Sstevel@tonic-gate 	char strval[256];
27477c478bd9Sstevel@tonic-gate 	vmem_t *mod_sysfile_arena;
27487c478bd9Sstevel@tonic-gate 	void *straddr;
27497c478bd9Sstevel@tonic-gate 
27507c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&sysp, "sysparam_hd") == -1) {
27517c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read sysparam_hd");
27527c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
27537c478bd9Sstevel@tonic-gate 	}
27547c478bd9Sstevel@tonic-gate 
27557c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&mod_sysfile_arena, "mod_sysfile_arena") == -1) {
27567c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read mod_sysfile_arena");
27577c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
27587c478bd9Sstevel@tonic-gate 	}
27597c478bd9Sstevel@tonic-gate 
27607c478bd9Sstevel@tonic-gate 	while (sysp != NULL) {
27617c478bd9Sstevel@tonic-gate 		var[0] = '\0';
27627c478bd9Sstevel@tonic-gate 		val[0] = '\0';
27637c478bd9Sstevel@tonic-gate 		modname[0] = '\0';
27647c478bd9Sstevel@tonic-gate 		if (mdb_vread(&sys, sizeof (sys), (uintptr_t)sysp) == -1) {
27657c478bd9Sstevel@tonic-gate 			mdb_warn("couldn't read sysparam %p", sysp);
27667c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
27677c478bd9Sstevel@tonic-gate 		}
27687c478bd9Sstevel@tonic-gate 		if (sys.sys_modnam != NULL &&
27697c478bd9Sstevel@tonic-gate 		    mdb_readstr(modname, 256,
27707c478bd9Sstevel@tonic-gate 		    (uintptr_t)sys.sys_modnam) == -1) {
27717c478bd9Sstevel@tonic-gate 			mdb_warn("couldn't read modname in %p", sysp);
27727c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
27737c478bd9Sstevel@tonic-gate 		}
27747c478bd9Sstevel@tonic-gate 		if (sys.sys_ptr != NULL &&
27757c478bd9Sstevel@tonic-gate 		    mdb_readstr(var, 256, (uintptr_t)sys.sys_ptr) == -1) {
27767c478bd9Sstevel@tonic-gate 			mdb_warn("couldn't read ptr in %p", sysp);
27777c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
27787c478bd9Sstevel@tonic-gate 		}
27797c478bd9Sstevel@tonic-gate 		if (sys.sys_op != SETOP_NONE) {
27807c478bd9Sstevel@tonic-gate 			/*
27817c478bd9Sstevel@tonic-gate 			 * Is this an int or a string?  We determine this
27827c478bd9Sstevel@tonic-gate 			 * by checking whether straddr is contained in
27837c478bd9Sstevel@tonic-gate 			 * mod_sysfile_arena.  If so, the walker will set
27847c478bd9Sstevel@tonic-gate 			 * straddr to NULL.
27857c478bd9Sstevel@tonic-gate 			 */
27867c478bd9Sstevel@tonic-gate 			straddr = (void *)(uintptr_t)sys.sys_info;
27877c478bd9Sstevel@tonic-gate 			if (sys.sys_op == SETOP_ASSIGN &&
27887c478bd9Sstevel@tonic-gate 			    sys.sys_info != 0 &&
27897c478bd9Sstevel@tonic-gate 			    mdb_pwalk("vmem_seg",
27907c478bd9Sstevel@tonic-gate 			    (mdb_walk_cb_t)sysfile_vmem_seg, &straddr,
27917c478bd9Sstevel@tonic-gate 			    (uintptr_t)mod_sysfile_arena) == 0 &&
27927c478bd9Sstevel@tonic-gate 			    straddr == NULL &&
27937c478bd9Sstevel@tonic-gate 			    mdb_readstr(strval, 256,
27947c478bd9Sstevel@tonic-gate 			    (uintptr_t)sys.sys_info) != -1) {
27957c478bd9Sstevel@tonic-gate 				(void) mdb_snprintf(val, sizeof (val), "\"%s\"",
27967c478bd9Sstevel@tonic-gate 				    strval);
27977c478bd9Sstevel@tonic-gate 			} else {
27987c478bd9Sstevel@tonic-gate 				(void) mdb_snprintf(val, sizeof (val),
27997c478bd9Sstevel@tonic-gate 				    "0x%llx [0t%llu]", sys.sys_info,
28007c478bd9Sstevel@tonic-gate 				    sys.sys_info);
28017c478bd9Sstevel@tonic-gate 			}
28027c478bd9Sstevel@tonic-gate 		}
28037c478bd9Sstevel@tonic-gate 		mdb_printf("%s %s%s%s%s%s\n", sysfile_cmd[sys.sys_type],
28047c478bd9Sstevel@tonic-gate 		    modname, modname[0] == '\0' ? "" : ":",
28057c478bd9Sstevel@tonic-gate 		    var, sysfile_ops[sys.sys_op], val);
28067c478bd9Sstevel@tonic-gate 
28077c478bd9Sstevel@tonic-gate 		sysp = sys.sys_next;
28087c478bd9Sstevel@tonic-gate 	}
28097c478bd9Sstevel@tonic-gate 
28107c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
28117c478bd9Sstevel@tonic-gate }
28127c478bd9Sstevel@tonic-gate 
28137c478bd9Sstevel@tonic-gate /*
28147c478bd9Sstevel@tonic-gate  * Dump a taskq_ent_t given its address.
28157c478bd9Sstevel@tonic-gate  */
28167c478bd9Sstevel@tonic-gate /*ARGSUSED*/
28177c478bd9Sstevel@tonic-gate int
28187c478bd9Sstevel@tonic-gate taskq_ent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
28197c478bd9Sstevel@tonic-gate {
28207c478bd9Sstevel@tonic-gate 	taskq_ent_t	taskq_ent;
28217c478bd9Sstevel@tonic-gate 	GElf_Sym	sym;
28227c478bd9Sstevel@tonic-gate 	char		buf[MDB_SYM_NAMLEN+1];
28237c478bd9Sstevel@tonic-gate 
28247c478bd9Sstevel@tonic-gate 
28257c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
28267c478bd9Sstevel@tonic-gate 		mdb_warn("expected explicit taskq_ent_t address before ::\n");
28277c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
28287c478bd9Sstevel@tonic-gate 	}
28297c478bd9Sstevel@tonic-gate 
28307c478bd9Sstevel@tonic-gate 	if (mdb_vread(&taskq_ent, sizeof (taskq_ent_t), addr) == -1) {
28317c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read taskq_ent_t at %p", addr);
28327c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
28337c478bd9Sstevel@tonic-gate 	}
28347c478bd9Sstevel@tonic-gate 
28357c478bd9Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
28367c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%-?s    %-?s    %-s%</u>\n",
28377c478bd9Sstevel@tonic-gate 		"ENTRY", "ARG", "FUNCTION");
28387c478bd9Sstevel@tonic-gate 	}
28397c478bd9Sstevel@tonic-gate 
28407c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_addr((uintptr_t)taskq_ent.tqent_func, MDB_SYM_EXACT,
28417c478bd9Sstevel@tonic-gate 	    buf, sizeof (buf), &sym) == -1) {
28427c478bd9Sstevel@tonic-gate 		(void) strcpy(buf, "????");
28437c478bd9Sstevel@tonic-gate 	}
28447c478bd9Sstevel@tonic-gate 
28457c478bd9Sstevel@tonic-gate 	mdb_printf("%-?p    %-?p    %s\n", addr, taskq_ent.tqent_arg, buf);
28467c478bd9Sstevel@tonic-gate 
28477c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
28487c478bd9Sstevel@tonic-gate }
28497c478bd9Sstevel@tonic-gate 
28507c478bd9Sstevel@tonic-gate /*
28517c478bd9Sstevel@tonic-gate  * Given the address of the (taskq_t) task queue head, walk the queue listing
28527c478bd9Sstevel@tonic-gate  * the address of every taskq_ent_t.
28537c478bd9Sstevel@tonic-gate  */
28547c478bd9Sstevel@tonic-gate int
28557c478bd9Sstevel@tonic-gate taskq_walk_init(mdb_walk_state_t *wsp)
28567c478bd9Sstevel@tonic-gate {
28577c478bd9Sstevel@tonic-gate 	taskq_t	tq_head;
28587c478bd9Sstevel@tonic-gate 
28597c478bd9Sstevel@tonic-gate 
28607c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
28617c478bd9Sstevel@tonic-gate 		mdb_warn("start address required\n");
28627c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
28637c478bd9Sstevel@tonic-gate 	}
28647c478bd9Sstevel@tonic-gate 
28657c478bd9Sstevel@tonic-gate 
28667c478bd9Sstevel@tonic-gate 	/*
28677c478bd9Sstevel@tonic-gate 	 * Save the address of the list head entry.  This terminates the list.
28687c478bd9Sstevel@tonic-gate 	 */
28697c478bd9Sstevel@tonic-gate 	wsp->walk_data = (void *)
28707c478bd9Sstevel@tonic-gate 	    ((size_t)wsp->walk_addr + offsetof(taskq_t, tq_task));
28717c478bd9Sstevel@tonic-gate 
28727c478bd9Sstevel@tonic-gate 
28737c478bd9Sstevel@tonic-gate 	/*
28747c478bd9Sstevel@tonic-gate 	 * Read in taskq head, set walk_addr to point to first taskq_ent_t.
28757c478bd9Sstevel@tonic-gate 	 */
28767c478bd9Sstevel@tonic-gate 	if (mdb_vread((void *)&tq_head, sizeof (taskq_t), wsp->walk_addr) ==
28777c478bd9Sstevel@tonic-gate 	    -1) {
28787c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read taskq list head at %p",
28797c478bd9Sstevel@tonic-gate 		    wsp->walk_addr);
28807c478bd9Sstevel@tonic-gate 	}
28817c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)tq_head.tq_task.tqent_next;
28827c478bd9Sstevel@tonic-gate 
28837c478bd9Sstevel@tonic-gate 
28847c478bd9Sstevel@tonic-gate 	/*
28857c478bd9Sstevel@tonic-gate 	 * Check for null list (next=head)
28867c478bd9Sstevel@tonic-gate 	 */
28877c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data) {
28887c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
28897c478bd9Sstevel@tonic-gate 	}
28907c478bd9Sstevel@tonic-gate 
28917c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
28927c478bd9Sstevel@tonic-gate }
28937c478bd9Sstevel@tonic-gate 
28947c478bd9Sstevel@tonic-gate 
28957c478bd9Sstevel@tonic-gate int
28967c478bd9Sstevel@tonic-gate taskq_walk_step(mdb_walk_state_t *wsp)
28977c478bd9Sstevel@tonic-gate {
28987c478bd9Sstevel@tonic-gate 	taskq_ent_t	tq_ent;
28997c478bd9Sstevel@tonic-gate 	int		status;
29007c478bd9Sstevel@tonic-gate 
29017c478bd9Sstevel@tonic-gate 
29027c478bd9Sstevel@tonic-gate 	if (mdb_vread((void *)&tq_ent, sizeof (taskq_ent_t), wsp->walk_addr) ==
29037c478bd9Sstevel@tonic-gate 	    -1) {
29047c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read taskq_ent_t at %p", wsp->walk_addr);
29057c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
29067c478bd9Sstevel@tonic-gate 	}
29077c478bd9Sstevel@tonic-gate 
29087c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, (void *)&tq_ent,
29097c478bd9Sstevel@tonic-gate 	    wsp->walk_cbdata);
29107c478bd9Sstevel@tonic-gate 
29117c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)tq_ent.tqent_next;
29127c478bd9Sstevel@tonic-gate 
29137c478bd9Sstevel@tonic-gate 
29147c478bd9Sstevel@tonic-gate 	/* Check if we're at the last element (next=head) */
29157c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data) {
29167c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
29177c478bd9Sstevel@tonic-gate 	}
29187c478bd9Sstevel@tonic-gate 
29197c478bd9Sstevel@tonic-gate 	return (status);
29207c478bd9Sstevel@tonic-gate }
29217c478bd9Sstevel@tonic-gate 
29227c478bd9Sstevel@tonic-gate int
29237c478bd9Sstevel@tonic-gate didmatch(uintptr_t addr, const kthread_t *thr, kt_did_t *didp)
29247c478bd9Sstevel@tonic-gate {
29257c478bd9Sstevel@tonic-gate 
29267c478bd9Sstevel@tonic-gate 	if (*didp == thr->t_did) {
29277c478bd9Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
29287c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
29297c478bd9Sstevel@tonic-gate 	} else
29307c478bd9Sstevel@tonic-gate 		return (WALK_NEXT);
29317c478bd9Sstevel@tonic-gate }
29327c478bd9Sstevel@tonic-gate 
29337c478bd9Sstevel@tonic-gate /*ARGSUSED*/
29347c478bd9Sstevel@tonic-gate int
29357c478bd9Sstevel@tonic-gate did2thread(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
29367c478bd9Sstevel@tonic-gate {
29377c478bd9Sstevel@tonic-gate 	const mdb_arg_t *argp = &argv[0];
29387c478bd9Sstevel@tonic-gate 	kt_did_t	did;
29397c478bd9Sstevel@tonic-gate 
29407c478bd9Sstevel@tonic-gate 	if (argc != 1)
29417c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
29427c478bd9Sstevel@tonic-gate 
29437c478bd9Sstevel@tonic-gate 	did = (kt_did_t)mdb_strtoull(argp->a_un.a_str);
29447c478bd9Sstevel@tonic-gate 
29457c478bd9Sstevel@tonic-gate 	if (mdb_walk("thread", (mdb_walk_cb_t)didmatch, (void *)&did) == -1) {
29467c478bd9Sstevel@tonic-gate 		mdb_warn("failed to walk thread");
29477c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
29487c478bd9Sstevel@tonic-gate 
29497c478bd9Sstevel@tonic-gate 	}
29507c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
29517c478bd9Sstevel@tonic-gate 
29527c478bd9Sstevel@tonic-gate }
29537c478bd9Sstevel@tonic-gate 
29547c478bd9Sstevel@tonic-gate static int
29557c478bd9Sstevel@tonic-gate errorq_walk_init(mdb_walk_state_t *wsp)
29567c478bd9Sstevel@tonic-gate {
29577c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == NULL &&
29587c478bd9Sstevel@tonic-gate 	    mdb_readvar(&wsp->walk_addr, "errorq_list") == -1) {
29597c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read errorq_list");
29607c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
29617c478bd9Sstevel@tonic-gate 	}
29627c478bd9Sstevel@tonic-gate 
29637c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
29647c478bd9Sstevel@tonic-gate }
29657c478bd9Sstevel@tonic-gate 
29667c478bd9Sstevel@tonic-gate static int
29677c478bd9Sstevel@tonic-gate errorq_walk_step(mdb_walk_state_t *wsp)
29687c478bd9Sstevel@tonic-gate {
29697c478bd9Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
29707c478bd9Sstevel@tonic-gate 	errorq_t eq;
29717c478bd9Sstevel@tonic-gate 
29727c478bd9Sstevel@tonic-gate 	if (addr == NULL)
29737c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
29747c478bd9Sstevel@tonic-gate 
29757c478bd9Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), addr) == -1) {
29767c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", addr);
29777c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
29787c478bd9Sstevel@tonic-gate 	}
29797c478bd9Sstevel@tonic-gate 
29807c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)eq.eq_next;
29817c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &eq, wsp->walk_cbdata));
29827c478bd9Sstevel@tonic-gate }
29837c478bd9Sstevel@tonic-gate 
29847c478bd9Sstevel@tonic-gate typedef struct eqd_walk_data {
29857c478bd9Sstevel@tonic-gate 	uintptr_t *eqd_stack;
29867c478bd9Sstevel@tonic-gate 	void *eqd_buf;
29877c478bd9Sstevel@tonic-gate 	ulong_t eqd_qpos;
29887c478bd9Sstevel@tonic-gate 	ulong_t eqd_qlen;
29897c478bd9Sstevel@tonic-gate 	size_t eqd_size;
29907c478bd9Sstevel@tonic-gate } eqd_walk_data_t;
29917c478bd9Sstevel@tonic-gate 
29927c478bd9Sstevel@tonic-gate /*
29937c478bd9Sstevel@tonic-gate  * In order to walk the list of pending error queue elements, we push the
29947c478bd9Sstevel@tonic-gate  * addresses of the corresponding data buffers in to the eqd_stack array.
29957c478bd9Sstevel@tonic-gate  * The error lists are in reverse chronological order when iterating using
29967c478bd9Sstevel@tonic-gate  * eqe_prev, so we then pop things off the top in eqd_walk_step so that the
29977c478bd9Sstevel@tonic-gate  * walker client gets addresses in order from oldest error to newest error.
29987c478bd9Sstevel@tonic-gate  */
29997c478bd9Sstevel@tonic-gate static void
30007c478bd9Sstevel@tonic-gate eqd_push_list(eqd_walk_data_t *eqdp, uintptr_t addr)
30017c478bd9Sstevel@tonic-gate {
30027c478bd9Sstevel@tonic-gate 	errorq_elem_t eqe;
30037c478bd9Sstevel@tonic-gate 
30047c478bd9Sstevel@tonic-gate 	while (addr != NULL) {
30057c478bd9Sstevel@tonic-gate 		if (mdb_vread(&eqe, sizeof (eqe), addr) != sizeof (eqe)) {
30067c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read errorq element at %p", addr);
30077c478bd9Sstevel@tonic-gate 			break;
30087c478bd9Sstevel@tonic-gate 		}
30097c478bd9Sstevel@tonic-gate 
30107c478bd9Sstevel@tonic-gate 		if (eqdp->eqd_qpos == eqdp->eqd_qlen) {
30117c478bd9Sstevel@tonic-gate 			mdb_warn("errorq is overfull -- more than %lu "
30127c478bd9Sstevel@tonic-gate 			    "elems found\n", eqdp->eqd_qlen);
30137c478bd9Sstevel@tonic-gate 			break;
30147c478bd9Sstevel@tonic-gate 		}
30157c478bd9Sstevel@tonic-gate 
30167c478bd9Sstevel@tonic-gate 		eqdp->eqd_stack[eqdp->eqd_qpos++] = (uintptr_t)eqe.eqe_data;
30177c478bd9Sstevel@tonic-gate 		addr = (uintptr_t)eqe.eqe_prev;
30187c478bd9Sstevel@tonic-gate 	}
30197c478bd9Sstevel@tonic-gate }
30207c478bd9Sstevel@tonic-gate 
30217c478bd9Sstevel@tonic-gate static int
30227c478bd9Sstevel@tonic-gate eqd_walk_init(mdb_walk_state_t *wsp)
30237c478bd9Sstevel@tonic-gate {
30247c478bd9Sstevel@tonic-gate 	eqd_walk_data_t *eqdp;
30257c478bd9Sstevel@tonic-gate 	errorq_elem_t eqe, *addr;
30267c478bd9Sstevel@tonic-gate 	errorq_t eq;
30277c478bd9Sstevel@tonic-gate 	ulong_t i;
30287c478bd9Sstevel@tonic-gate 
30297c478bd9Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), wsp->walk_addr) == -1) {
30307c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", wsp->walk_addr);
30317c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
30327c478bd9Sstevel@tonic-gate 	}
30337c478bd9Sstevel@tonic-gate 
30347c478bd9Sstevel@tonic-gate 	if (eq.eq_ptail != NULL &&
30357c478bd9Sstevel@tonic-gate 	    mdb_vread(&eqe, sizeof (eqe), (uintptr_t)eq.eq_ptail) == -1) {
30367c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read errorq element at %p", eq.eq_ptail);
30377c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
30387c478bd9Sstevel@tonic-gate 	}
30397c478bd9Sstevel@tonic-gate 
30407c478bd9Sstevel@tonic-gate 	eqdp = mdb_alloc(sizeof (eqd_walk_data_t), UM_SLEEP);
30417c478bd9Sstevel@tonic-gate 	wsp->walk_data = eqdp;
30427c478bd9Sstevel@tonic-gate 
30437c478bd9Sstevel@tonic-gate 	eqdp->eqd_stack = mdb_zalloc(sizeof (uintptr_t) * eq.eq_qlen, UM_SLEEP);
30447c478bd9Sstevel@tonic-gate 	eqdp->eqd_buf = mdb_alloc(eq.eq_size, UM_SLEEP);
30457c478bd9Sstevel@tonic-gate 	eqdp->eqd_qlen = eq.eq_qlen;
30467c478bd9Sstevel@tonic-gate 	eqdp->eqd_qpos = 0;
30477c478bd9Sstevel@tonic-gate 	eqdp->eqd_size = eq.eq_size;
30487c478bd9Sstevel@tonic-gate 
30497c478bd9Sstevel@tonic-gate 	/*
30507c478bd9Sstevel@tonic-gate 	 * The newest elements in the queue are on the pending list, so we
30517c478bd9Sstevel@tonic-gate 	 * push those on to our stack first.
30527c478bd9Sstevel@tonic-gate 	 */
30537c478bd9Sstevel@tonic-gate 	eqd_push_list(eqdp, (uintptr_t)eq.eq_pend);
30547c478bd9Sstevel@tonic-gate 
30557c478bd9Sstevel@tonic-gate 	/*
30567c478bd9Sstevel@tonic-gate 	 * If eq_ptail is set, it may point to a subset of the errors on the
30577c478bd9Sstevel@tonic-gate 	 * pending list in the event a casptr() failed; if ptail's data is
30587c478bd9Sstevel@tonic-gate 	 * already in our stack, NULL out eq_ptail and ignore it.
30597c478bd9Sstevel@tonic-gate 	 */
30607c478bd9Sstevel@tonic-gate 	if (eq.eq_ptail != NULL) {
30617c478bd9Sstevel@tonic-gate 		for (i = 0; i < eqdp->eqd_qpos; i++) {
30627c478bd9Sstevel@tonic-gate 			if (eqdp->eqd_stack[i] == (uintptr_t)eqe.eqe_data) {
30637c478bd9Sstevel@tonic-gate 				eq.eq_ptail = NULL;
30647c478bd9Sstevel@tonic-gate 				break;
30657c478bd9Sstevel@tonic-gate 			}
30667c478bd9Sstevel@tonic-gate 		}
30677c478bd9Sstevel@tonic-gate 	}
30687c478bd9Sstevel@tonic-gate 
30697c478bd9Sstevel@tonic-gate 	/*
30707c478bd9Sstevel@tonic-gate 	 * If eq_phead is set, it has the processing list in order from oldest
30717c478bd9Sstevel@tonic-gate 	 * to newest.  Use this to recompute eq_ptail as best we can and then
30727c478bd9Sstevel@tonic-gate 	 * we nicely fall into eqd_push_list() of eq_ptail below.
30737c478bd9Sstevel@tonic-gate 	 */
30747c478bd9Sstevel@tonic-gate 	for (addr = eq.eq_phead; addr != NULL && mdb_vread(&eqe, sizeof (eqe),
30757c478bd9Sstevel@tonic-gate 	    (uintptr_t)addr) == sizeof (eqe); addr = eqe.eqe_next)
30767c478bd9Sstevel@tonic-gate 		eq.eq_ptail = addr;
30777c478bd9Sstevel@tonic-gate 
30787c478bd9Sstevel@tonic-gate 	/*
30797c478bd9Sstevel@tonic-gate 	 * The oldest elements in the queue are on the processing list, subject
30807c478bd9Sstevel@tonic-gate 	 * to machinations in the if-clauses above.  Push any such elements.
30817c478bd9Sstevel@tonic-gate 	 */
30827c478bd9Sstevel@tonic-gate 	eqd_push_list(eqdp, (uintptr_t)eq.eq_ptail);
30837c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
30847c478bd9Sstevel@tonic-gate }
30857c478bd9Sstevel@tonic-gate 
30867c478bd9Sstevel@tonic-gate static int
30877c478bd9Sstevel@tonic-gate eqd_walk_step(mdb_walk_state_t *wsp)
30887c478bd9Sstevel@tonic-gate {
30897c478bd9Sstevel@tonic-gate 	eqd_walk_data_t *eqdp = wsp->walk_data;
30907c478bd9Sstevel@tonic-gate 	uintptr_t addr;
30917c478bd9Sstevel@tonic-gate 
30927c478bd9Sstevel@tonic-gate 	if (eqdp->eqd_qpos == 0)
30937c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
30947c478bd9Sstevel@tonic-gate 
30957c478bd9Sstevel@tonic-gate 	addr = eqdp->eqd_stack[--eqdp->eqd_qpos];
30967c478bd9Sstevel@tonic-gate 
30977c478bd9Sstevel@tonic-gate 	if (mdb_vread(eqdp->eqd_buf, eqdp->eqd_size, addr) != eqdp->eqd_size) {
30987c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read errorq data at %p", addr);
30997c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
31007c478bd9Sstevel@tonic-gate 	}
31017c478bd9Sstevel@tonic-gate 
31027c478bd9Sstevel@tonic-gate 	return (wsp->walk_callback(addr, eqdp->eqd_buf, wsp->walk_cbdata));
31037c478bd9Sstevel@tonic-gate }
31047c478bd9Sstevel@tonic-gate 
31057c478bd9Sstevel@tonic-gate static void
31067c478bd9Sstevel@tonic-gate eqd_walk_fini(mdb_walk_state_t *wsp)
31077c478bd9Sstevel@tonic-gate {
31087c478bd9Sstevel@tonic-gate 	eqd_walk_data_t *eqdp = wsp->walk_data;
31097c478bd9Sstevel@tonic-gate 
31107c478bd9Sstevel@tonic-gate 	mdb_free(eqdp->eqd_stack, sizeof (uintptr_t) * eqdp->eqd_qlen);
31117c478bd9Sstevel@tonic-gate 	mdb_free(eqdp->eqd_buf, eqdp->eqd_size);
31127c478bd9Sstevel@tonic-gate 	mdb_free(eqdp, sizeof (eqd_walk_data_t));
31137c478bd9Sstevel@tonic-gate }
31147c478bd9Sstevel@tonic-gate 
31157c478bd9Sstevel@tonic-gate #define	EQKSVAL(eqv, what) (eqv.eq_kstat.what.value.ui64)
31167c478bd9Sstevel@tonic-gate 
31177c478bd9Sstevel@tonic-gate static int
31187c478bd9Sstevel@tonic-gate errorq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
31197c478bd9Sstevel@tonic-gate {
31207c478bd9Sstevel@tonic-gate 	int i;
31217c478bd9Sstevel@tonic-gate 	errorq_t eq;
31227c478bd9Sstevel@tonic-gate 	uint_t opt_v = FALSE;
31237c478bd9Sstevel@tonic-gate 
31247c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
31257c478bd9Sstevel@tonic-gate 		if (mdb_walk_dcmd("errorq", "errorq", argc, argv) == -1) {
31267c478bd9Sstevel@tonic-gate 			mdb_warn("can't walk 'errorq'");
31277c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
31287c478bd9Sstevel@tonic-gate 		}
31297c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
31307c478bd9Sstevel@tonic-gate 	}
31317c478bd9Sstevel@tonic-gate 
31327c478bd9Sstevel@tonic-gate 	i = mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &opt_v, NULL);
31337c478bd9Sstevel@tonic-gate 	argc -= i;
31347c478bd9Sstevel@tonic-gate 	argv += i;
31357c478bd9Sstevel@tonic-gate 
31367c478bd9Sstevel@tonic-gate 	if (argc != 0)
31377c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
31387c478bd9Sstevel@tonic-gate 
31397c478bd9Sstevel@tonic-gate 	if (opt_v || DCMD_HDRSPEC(flags)) {
31407c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>%-11s %-16s %1s %1s %1s ",
31417c478bd9Sstevel@tonic-gate 		    "ADDR", "NAME", "S", "V", "N");
31427c478bd9Sstevel@tonic-gate 		if (!opt_v) {
31437c478bd9Sstevel@tonic-gate 			mdb_printf("%7s %7s %7s%</u>\n",
31447c478bd9Sstevel@tonic-gate 			    "ACCEPT", "DROP", "LOG");
31457c478bd9Sstevel@tonic-gate 		} else {
31467c478bd9Sstevel@tonic-gate 			mdb_printf("%5s %6s %6s %3s %16s%</u>\n",
31477c478bd9Sstevel@tonic-gate 			    "KSTAT", "QLEN", "SIZE", "IPL", "FUNC");
31487c478bd9Sstevel@tonic-gate 		}
31497c478bd9Sstevel@tonic-gate 	}
31507c478bd9Sstevel@tonic-gate 
31517c478bd9Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), addr) != sizeof (eq)) {
31527c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", addr);
31537c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
31547c478bd9Sstevel@tonic-gate 	}
31557c478bd9Sstevel@tonic-gate 
31567c478bd9Sstevel@tonic-gate 	mdb_printf("%-11p %-16s %c %c %c ", addr, eq.eq_name,
31577c478bd9Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_ACTIVE) ? '+' : '-',
31587c478bd9Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_VITAL) ? '!' : ' ',
31597c478bd9Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_NVLIST) ? '*' : ' ');
31607c478bd9Sstevel@tonic-gate 
31617c478bd9Sstevel@tonic-gate 	if (!opt_v) {
31627c478bd9Sstevel@tonic-gate 		mdb_printf("%7llu %7llu %7llu\n",
31637c478bd9Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_dispatched) + EQKSVAL(eq, eqk_committed),
31647c478bd9Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_dropped) + EQKSVAL(eq, eqk_reserve_fail) +
31657c478bd9Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_commit_fail), EQKSVAL(eq, eqk_logged));
31667c478bd9Sstevel@tonic-gate 	} else {
31677c478bd9Sstevel@tonic-gate 		mdb_printf("%5s %6lu %6lu %3u %a\n",
31687c478bd9Sstevel@tonic-gate 		    "  |  ", eq.eq_qlen, eq.eq_size, eq.eq_ipl, eq.eq_func);
31697c478bd9Sstevel@tonic-gate 		mdb_printf("%38s\n%41s"
31707c478bd9Sstevel@tonic-gate 		    "%12s %llu\n"
31717c478bd9Sstevel@tonic-gate 		    "%53s %llu\n"
31727c478bd9Sstevel@tonic-gate 		    "%53s %llu\n"
31737c478bd9Sstevel@tonic-gate 		    "%53s %llu\n"
31747c478bd9Sstevel@tonic-gate 		    "%53s %llu\n"
31757c478bd9Sstevel@tonic-gate 		    "%53s %llu\n"
31767c478bd9Sstevel@tonic-gate 		    "%53s %llu\n"
31777c478bd9Sstevel@tonic-gate 		    "%53s %llu\n\n",
31787c478bd9Sstevel@tonic-gate 		    "|", "+-> ",
31797c478bd9Sstevel@tonic-gate 		    "DISPATCHED",	EQKSVAL(eq, eqk_dispatched),
31807c478bd9Sstevel@tonic-gate 		    "DROPPED",		EQKSVAL(eq, eqk_dropped),
31817c478bd9Sstevel@tonic-gate 		    "LOGGED",		EQKSVAL(eq, eqk_logged),
31827c478bd9Sstevel@tonic-gate 		    "RESERVED",		EQKSVAL(eq, eqk_reserved),
31837c478bd9Sstevel@tonic-gate 		    "RESERVE FAIL",	EQKSVAL(eq, eqk_reserve_fail),
31847c478bd9Sstevel@tonic-gate 		    "COMMITTED",	EQKSVAL(eq, eqk_committed),
31857c478bd9Sstevel@tonic-gate 		    "COMMIT FAIL",	EQKSVAL(eq, eqk_commit_fail),
31867c478bd9Sstevel@tonic-gate 		    "CANCELLED",	EQKSVAL(eq, eqk_cancelled));
31877c478bd9Sstevel@tonic-gate 	}
31887c478bd9Sstevel@tonic-gate 
31897c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
31907c478bd9Sstevel@tonic-gate }
31917c478bd9Sstevel@tonic-gate 
31927c478bd9Sstevel@tonic-gate /*ARGSUSED*/
31937c478bd9Sstevel@tonic-gate static int
31947c478bd9Sstevel@tonic-gate panicinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
31957c478bd9Sstevel@tonic-gate {
31967c478bd9Sstevel@tonic-gate 	cpu_t panic_cpu;
31977c478bd9Sstevel@tonic-gate 	kthread_t *panic_thread;
319849795412Spetede 	void *buf;
31997c478bd9Sstevel@tonic-gate 	panic_data_t *pd;
32007c478bd9Sstevel@tonic-gate 	int i, n;
32017c478bd9Sstevel@tonic-gate 
32027c478bd9Sstevel@tonic-gate 	if (!mdb_prop_postmortem) {
32037c478bd9Sstevel@tonic-gate 		mdb_warn("panicinfo can only be run on a system "
32047c478bd9Sstevel@tonic-gate 		    "dump; see dumpadm(1M)\n");
32057c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
32067c478bd9Sstevel@tonic-gate 	}
32077c478bd9Sstevel@tonic-gate 
32087c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC || argc != 0)
32097c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
32107c478bd9Sstevel@tonic-gate 
32117c478bd9Sstevel@tonic-gate 	if (mdb_readsym(&panic_cpu, sizeof (cpu_t), "panic_cpu") == -1)
32127c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'panic_cpu'");
32137c478bd9Sstevel@tonic-gate 	else
32147c478bd9Sstevel@tonic-gate 		mdb_printf("%16s %?d\n", "cpu", panic_cpu.cpu_id);
32157c478bd9Sstevel@tonic-gate 
32167c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&panic_thread, "panic_thread") == -1)
32177c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'panic_thread'");
32187c478bd9Sstevel@tonic-gate 	else
32197c478bd9Sstevel@tonic-gate 		mdb_printf("%16s %?p\n", "thread", panic_thread);
32207c478bd9Sstevel@tonic-gate 
322149795412Spetede 	buf = mdb_alloc(PANICBUFSIZE, UM_SLEEP);
322249795412Spetede 	pd = (panic_data_t *)buf;
32237c478bd9Sstevel@tonic-gate 
322449795412Spetede 	if (mdb_readsym(buf, PANICBUFSIZE, "panicbuf") == -1 ||
32257c478bd9Sstevel@tonic-gate 	    pd->pd_version != PANICBUFVERS) {
32267c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'panicbuf'");
322749795412Spetede 		mdb_free(buf, PANICBUFSIZE);
32287c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
32297c478bd9Sstevel@tonic-gate 	}
32307c478bd9Sstevel@tonic-gate 
323149795412Spetede 	mdb_printf("%16s %s\n", "message",  (char *)buf + pd->pd_msgoff);
32327c478bd9Sstevel@tonic-gate 
32337c478bd9Sstevel@tonic-gate 	n = (pd->pd_msgoff - (sizeof (panic_data_t) -
32347c478bd9Sstevel@tonic-gate 	    sizeof (panic_nv_t))) / sizeof (panic_nv_t);
32357c478bd9Sstevel@tonic-gate 
32367c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; i++)
32377c478bd9Sstevel@tonic-gate 		mdb_printf("%16s %?llx\n",
32387c478bd9Sstevel@tonic-gate 		    pd->pd_nvdata[i].pnv_name, pd->pd_nvdata[i].pnv_value);
32397c478bd9Sstevel@tonic-gate 
324049795412Spetede 	mdb_free(buf, PANICBUFSIZE);
32417c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
32427c478bd9Sstevel@tonic-gate }
32437c478bd9Sstevel@tonic-gate 
32447c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
32457c478bd9Sstevel@tonic-gate 
32467c478bd9Sstevel@tonic-gate 	/* from genunix.c */
32477c478bd9Sstevel@tonic-gate 	{ "addr2smap", ":[offset]", "translate address to smap", addr2smap },
32487c478bd9Sstevel@tonic-gate 	{ "as2proc", ":", "convert as to proc_t address", as2proc },
32497c478bd9Sstevel@tonic-gate 	{ "binding_hash_entry", ":", "print driver names hash table entry",
32507c478bd9Sstevel@tonic-gate 		binding_hash_entry },
32517c478bd9Sstevel@tonic-gate 	{ "callout", NULL, "print callout table", callout },
32527c478bd9Sstevel@tonic-gate 	{ "class", NULL, "print process scheduler classes", class },
32537c478bd9Sstevel@tonic-gate 	{ "cpuinfo", "?[-v]", "print CPUs and runnable threads", cpuinfo },
32547c478bd9Sstevel@tonic-gate 	{ "did2thread", "? kt_did", "find kernel thread for this id",
32557c478bd9Sstevel@tonic-gate 		did2thread },
32567c478bd9Sstevel@tonic-gate 	{ "errorq", "?[-v]", "display kernel error queues", errorq },
32577c478bd9Sstevel@tonic-gate 	{ "fd", ":[fd num]", "get a file pointer from an fd", fd },
32587c478bd9Sstevel@tonic-gate 	{ "flipone", ":", "the vik_rev_level 2 special", flipone },
32597c478bd9Sstevel@tonic-gate 	{ "lminfo", NULL, "print lock manager information", lminfo },
32607c478bd9Sstevel@tonic-gate 	{ "ndi_event_hdl", "?", "print ndi_event_hdl", ndi_event_hdl },
32617c478bd9Sstevel@tonic-gate 	{ "panicinfo", NULL, "print panic information", panicinfo },
32627c478bd9Sstevel@tonic-gate 	{ "pid2proc", "?", "convert PID to proc_t address", pid2proc },
32637c478bd9Sstevel@tonic-gate 	{ "pmap", ":[-q]", "print process memory map", pmap },
32647c478bd9Sstevel@tonic-gate 	{ "project", NULL, "display kernel project(s)", project },
32657c478bd9Sstevel@tonic-gate 	{ "ps", "[-fltzTP]", "list processes (and associated thr,lwp)", ps },
3266adb664e2Svb 	{ "pgrep", "[-x] [-n | -o] pattern",
3267adb664e2Svb 		"pattern match against all processes", pgrep },
32687c478bd9Sstevel@tonic-gate 	{ "ptree", NULL, "print process tree", ptree },
32697c478bd9Sstevel@tonic-gate 	{ "seg", ":", "print address space segment", seg },
32707c478bd9Sstevel@tonic-gate 	{ "sysevent", "?[-sv]", "print sysevent pending or sent queue",
32717c478bd9Sstevel@tonic-gate 		sysevent},
32727c478bd9Sstevel@tonic-gate 	{ "sysevent_channel", "?", "print sysevent channel database",
32737c478bd9Sstevel@tonic-gate 		sysevent_channel},
32747c478bd9Sstevel@tonic-gate 	{ "sysevent_class_list", ":", "print sysevent class list",
32757c478bd9Sstevel@tonic-gate 		sysevent_class_list},
32767c478bd9Sstevel@tonic-gate 	{ "sysevent_subclass_list", ":",
32777c478bd9Sstevel@tonic-gate 		"print sysevent subclass list", sysevent_subclass_list},
32787c478bd9Sstevel@tonic-gate 	{ "system", NULL, "print contents of /etc/system file", sysfile },
32797c478bd9Sstevel@tonic-gate 	{ "task", NULL, "display kernel task(s)", task },
32807c478bd9Sstevel@tonic-gate 	{ "taskq_entry", ":", "display a taskq_ent_t", taskq_ent },
32817c478bd9Sstevel@tonic-gate 	{ "vnode2path", ":[-F]", "vnode address to pathname", vnode2path },
32827c478bd9Sstevel@tonic-gate 	{ "vnode2smap", ":[offset]", "translate vnode to smap", vnode2smap },
32837c478bd9Sstevel@tonic-gate 	{ "whereopen", ":", "given a vnode, dumps procs which have it open",
32847c478bd9Sstevel@tonic-gate 	    whereopen },
32857c478bd9Sstevel@tonic-gate 
32867c478bd9Sstevel@tonic-gate 	/* from zone.c */
32877c478bd9Sstevel@tonic-gate 	{ "zone", "?", "display kernel zone(s)", zoneprt },
32887c478bd9Sstevel@tonic-gate 	{ "zsd", ":[zsd key]", "lookup zsd value from a key", zsd },
32897c478bd9Sstevel@tonic-gate 
32907c478bd9Sstevel@tonic-gate 	/* from bio.c */
32917c478bd9Sstevel@tonic-gate 	{ "bufpagefind", ":addr", "find page_t on buf_t list", bufpagefind },
32927c478bd9Sstevel@tonic-gate 
32937c478bd9Sstevel@tonic-gate 	/* from contract.c */
32947c478bd9Sstevel@tonic-gate 	{ "contract", "?", "display a contract", cmd_contract },
32957c478bd9Sstevel@tonic-gate 	{ "ctevent", ":", "display a contract event", cmd_ctevent },
32967c478bd9Sstevel@tonic-gate 	{ "ctid", ":", "convert id to a contract pointer", cmd_ctid },
32977c478bd9Sstevel@tonic-gate 
32987c478bd9Sstevel@tonic-gate 	/* from cpupart.c */
3299f5533078Smishra 	{ "cpupart", "?[-v]", "print cpu partition info", cpupart },
33007c478bd9Sstevel@tonic-gate 
33017c478bd9Sstevel@tonic-gate 	/* from cyclic.c */
33027c478bd9Sstevel@tonic-gate 	{ "cyccover", NULL, "dump cyclic coverage information", cyccover },
33037c478bd9Sstevel@tonic-gate 	{ "cycid", "?", "dump a cyclic id", cycid },
33047c478bd9Sstevel@tonic-gate 	{ "cycinfo", "?", "dump cyc_cpu info", cycinfo },
33057c478bd9Sstevel@tonic-gate 	{ "cyclic", ":", "developer information", cyclic },
33067c478bd9Sstevel@tonic-gate 	{ "cyctrace", "?", "dump cyclic trace buffer", cyctrace },
33077c478bd9Sstevel@tonic-gate 
33087c478bd9Sstevel@tonic-gate 	/* from devinfo.c */
33097c478bd9Sstevel@tonic-gate 	{ "devbindings", "?[-qs] [device-name | major-num]",
33107c478bd9Sstevel@tonic-gate 	    "print devinfo nodes bound to device-name or major-num",
33117c478bd9Sstevel@tonic-gate 	    devbindings, devinfo_help },
33127c478bd9Sstevel@tonic-gate 	{ "devinfo", ":[-qs]", "detailed devinfo of one node", devinfo,
33137c478bd9Sstevel@tonic-gate 	    devinfo_help },
33147c478bd9Sstevel@tonic-gate 	{ "devinfo_audit", ":[-v]", "devinfo configuration audit record",
33157c478bd9Sstevel@tonic-gate 	    devinfo_audit },
33167c478bd9Sstevel@tonic-gate 	{ "devinfo_audit_log", "?[-v]", "system wide devinfo configuration log",
33177c478bd9Sstevel@tonic-gate 	    devinfo_audit_log },
33187c478bd9Sstevel@tonic-gate 	{ "devinfo_audit_node", ":[-v]", "devinfo node configuration history",
33197c478bd9Sstevel@tonic-gate 	    devinfo_audit_node },
33207c478bd9Sstevel@tonic-gate 	{ "devinfo2driver", ":", "find driver name for this devinfo node",
33217c478bd9Sstevel@tonic-gate 	    devinfo2driver },
33227c478bd9Sstevel@tonic-gate 	{ "devnames", "?[-vm] [num]", "print devnames array", devnames },
33237c478bd9Sstevel@tonic-gate 	{ "dev2major", "?<dev_t>", "convert dev_t to a major number",
33247c478bd9Sstevel@tonic-gate 	    dev2major },
33257c478bd9Sstevel@tonic-gate 	{ "dev2minor", "?<dev_t>", "convert dev_t to a minor number",
33267c478bd9Sstevel@tonic-gate 	    dev2minor },
33277c478bd9Sstevel@tonic-gate 	{ "devt", "?<dev_t>", "display a dev_t's major and minor numbers",
33287c478bd9Sstevel@tonic-gate 	    devt },
33297c478bd9Sstevel@tonic-gate 	{ "major2name", "?<major-num>", "convert major number to dev name",
33307c478bd9Sstevel@tonic-gate 	    major2name },
33317c478bd9Sstevel@tonic-gate 	{ "minornodes", ":", "given a devinfo node, print its minor nodes",
33327c478bd9Sstevel@tonic-gate 	    minornodes },
33337c478bd9Sstevel@tonic-gate 	{ "modctl2devinfo", ":", "given a modctl, list its devinfos",
33347c478bd9Sstevel@tonic-gate 	    modctl2devinfo },
33357c478bd9Sstevel@tonic-gate 	{ "name2major", "<dev-name>", "convert dev name to major number",
33367c478bd9Sstevel@tonic-gate 	    name2major },
33377c478bd9Sstevel@tonic-gate 	{ "prtconf", "?[-vpc]", "print devinfo tree", prtconf, prtconf_help },
33387c478bd9Sstevel@tonic-gate 	{ "softstate", ":<instance>", "retrieve soft-state pointer",
33397c478bd9Sstevel@tonic-gate 	    softstate },
33407c478bd9Sstevel@tonic-gate 	{ "devinfo_fm", ":", "devinfo fault managment configuration",
33417c478bd9Sstevel@tonic-gate 	    devinfo_fm },
33427c478bd9Sstevel@tonic-gate 	{ "devinfo_fmce", ":", "devinfo fault managment cache entry",
33437c478bd9Sstevel@tonic-gate 	    devinfo_fmce},
33447c478bd9Sstevel@tonic-gate 
33459dd0f810Scindi 	/* from fm.c */
33469dd0f810Scindi 	{ "ereport", "[-v]", "print ereports logged in dump",
33479dd0f810Scindi 	    ereport },
33489dd0f810Scindi 
33497c478bd9Sstevel@tonic-gate 	/* from findstack.c */
33507c478bd9Sstevel@tonic-gate 	{ "findstack", ":[-v]", "find kernel thread stack", findstack },
33517c478bd9Sstevel@tonic-gate 	{ "findstack_debug", NULL, "toggle findstack debugging",
33527c478bd9Sstevel@tonic-gate 		findstack_debug },
33537c478bd9Sstevel@tonic-gate 
33547c478bd9Sstevel@tonic-gate 	/* from kgrep.c + genunix.c */
3355154eb83fSjwadams 	{ "kgrep", KGREP_USAGE, "search kernel as for a pointer", kgrep,
3356154eb83fSjwadams 		kgrep_help },
33577c478bd9Sstevel@tonic-gate 
33587c478bd9Sstevel@tonic-gate 	/* from kmem.c */
33597c478bd9Sstevel@tonic-gate 	{ "allocdby", ":", "given a thread, print its allocated buffers",
33607c478bd9Sstevel@tonic-gate 		allocdby },
33617c478bd9Sstevel@tonic-gate 	{ "bufctl", ":[-vh] [-a addr] [-c caller] [-e earliest] [-l latest] "
33627c478bd9Sstevel@tonic-gate 		"[-t thd]", "print or filter a bufctl", bufctl, bufctl_help },
33637c478bd9Sstevel@tonic-gate 	{ "freedby", ":", "given a thread, print its freed buffers", freedby },
33647c478bd9Sstevel@tonic-gate 	{ "kmalog", "?[ fail | slab ]",
33657c478bd9Sstevel@tonic-gate 	    "display kmem transaction log and stack traces", kmalog },
3366c92ff650Sek 	{ "kmastat", "[-kmg]", "kernel memory allocator stats",
3367c92ff650Sek 	    kmastat },
33687c478bd9Sstevel@tonic-gate 	{ "kmausers", "?[-ef] [cache ...]", "current medium and large users "
33697c478bd9Sstevel@tonic-gate 		"of the kmem allocator", kmausers, kmausers_help },
33707c478bd9Sstevel@tonic-gate 	{ "kmem_cache", "?", "print kernel memory caches", kmem_cache },
33713893cb7fStomee 	{ "kmem_slabs", "?[-v] [-n cache] [-b maxbins] [-B minbinsize]",
33723893cb7fStomee 		"display slab usage per kmem cache",
33733893cb7fStomee 		kmem_slabs, kmem_slabs_help },
33747c478bd9Sstevel@tonic-gate 	{ "kmem_debug", NULL, "toggle kmem dcmd/walk debugging", kmem_debug },
33757c478bd9Sstevel@tonic-gate 	{ "kmem_log", "?[-b]", "dump kmem transaction log", kmem_log },
33767c478bd9Sstevel@tonic-gate 	{ "kmem_verify", "?", "check integrity of kmem-managed memory",
33777c478bd9Sstevel@tonic-gate 		kmem_verify },
33787c478bd9Sstevel@tonic-gate 	{ "vmem", "?", "print a vmem_t", vmem },
33797c478bd9Sstevel@tonic-gate 	{ "vmem_seg", ":[-sv] [-c caller] [-e earliest] [-l latest] "
33807c478bd9Sstevel@tonic-gate 		"[-m minsize] [-M maxsize] [-t thread] [-T type]",
33817c478bd9Sstevel@tonic-gate 		"print or filter a vmem_seg", vmem_seg, vmem_seg_help },
33827c478bd9Sstevel@tonic-gate 	{ "whatis", ":[-abiv]", "given an address, return information", whatis,
33837c478bd9Sstevel@tonic-gate 		whatis_help },
33847c478bd9Sstevel@tonic-gate 	{ "whatthread", ":[-v]", "print threads whose stack contains the "
33857c478bd9Sstevel@tonic-gate 		"given address", whatthread },
33867c478bd9Sstevel@tonic-gate 
33877c478bd9Sstevel@tonic-gate 	/* from ldi.c */
33887c478bd9Sstevel@tonic-gate 	{ "ldi_handle", "?[-i]", "display a layered driver handle",
33897c478bd9Sstevel@tonic-gate 	    ldi_handle, ldi_handle_help },
33907c478bd9Sstevel@tonic-gate 	{ "ldi_ident", NULL, "display a layered driver identifier",
33917c478bd9Sstevel@tonic-gate 	    ldi_ident, ldi_ident_help },
33927c478bd9Sstevel@tonic-gate 
33937c478bd9Sstevel@tonic-gate 	/* from leaky.c + leaky_subr.c */
33947c478bd9Sstevel@tonic-gate 	{ "findleaks", FINDLEAKS_USAGE,
33957c478bd9Sstevel@tonic-gate 	    "search for potential kernel memory leaks", findleaks,
33967c478bd9Sstevel@tonic-gate 	    findleaks_help },
33977c478bd9Sstevel@tonic-gate 
33987c478bd9Sstevel@tonic-gate 	/* from lgrp.c */
33997c478bd9Sstevel@tonic-gate 	{ "lgrp", "?[-q] [-p | -Pih]", "display an lgrp", lgrp},
3400c6402783Sakolb 	{ "lgrp_set", "", "display bitmask of lgroups as a list", lgrp_set},
34017c478bd9Sstevel@tonic-gate 
34027c478bd9Sstevel@tonic-gate 	/* from log.c */
34037c478bd9Sstevel@tonic-gate 	{ "msgbuf", "?[-v]", "print most recent console messages", msgbuf },
34047c478bd9Sstevel@tonic-gate 
34057c478bd9Sstevel@tonic-gate 	/* from memory.c */
34067c478bd9Sstevel@tonic-gate 	{ "page", "?", "display a summarized page_t", page },
34077c478bd9Sstevel@tonic-gate 	{ "memstat", NULL, "display memory usage summary", memstat },
34087c478bd9Sstevel@tonic-gate 	{ "memlist", "?[-iav]", "display a struct memlist", memlist },
34097c478bd9Sstevel@tonic-gate 	{ "swapinfo", "?", "display a struct swapinfo", swapinfof },
34107c478bd9Sstevel@tonic-gate 
34117c478bd9Sstevel@tonic-gate 	/* from mmd.c */
34127c478bd9Sstevel@tonic-gate 	{ "multidata", ":[-sv]", "display a summarized multidata_t",
34137c478bd9Sstevel@tonic-gate 		multidata },
34147c478bd9Sstevel@tonic-gate 	{ "pattbl", ":", "display a summarized multidata attribute table",
34157c478bd9Sstevel@tonic-gate 		pattbl },
34167c478bd9Sstevel@tonic-gate 	{ "pattr2multidata", ":", "print multidata pointer from pattr_t",
34177c478bd9Sstevel@tonic-gate 		pattr2multidata },
34187c478bd9Sstevel@tonic-gate 	{ "pdesc2slab", ":", "print pdesc slab pointer from pdesc_t",
34197c478bd9Sstevel@tonic-gate 		pdesc2slab },
34207c478bd9Sstevel@tonic-gate 	{ "pdesc_verify", ":", "verify integrity of a pdesc_t", pdesc_verify },
34217c478bd9Sstevel@tonic-gate 	{ "slab2multidata", ":", "print multidata pointer from pdesc_slab_t",
34227c478bd9Sstevel@tonic-gate 		slab2multidata },
34237c478bd9Sstevel@tonic-gate 
34247c478bd9Sstevel@tonic-gate 	/* from modhash.c */
34257c478bd9Sstevel@tonic-gate 	{ "modhash", "?[-ceht] [-k key] [-v val] [-i index]",
34267c478bd9Sstevel@tonic-gate 		"display information about one or all mod_hash structures",
34277c478bd9Sstevel@tonic-gate 		modhash, modhash_help },
34287c478bd9Sstevel@tonic-gate 	{ "modent", ":[-k | -v | -t type]",
34297c478bd9Sstevel@tonic-gate 		"display information about a mod_hash_entry", modent,
34307c478bd9Sstevel@tonic-gate 		modent_help },
34317c478bd9Sstevel@tonic-gate 
34327c478bd9Sstevel@tonic-gate 	/* from net.c */
34337c478bd9Sstevel@tonic-gate 	{ "mi", ":[-p] [-d | -m]", "filter and display MI object or payload",
34347c478bd9Sstevel@tonic-gate 		mi },
343545916cd2Sjpk 	{ "netstat", "[-arv] [-f inet | inet6 | unix] [-P tcp | udp]",
34367c478bd9Sstevel@tonic-gate 		"show network statistics", netstat },
34377c478bd9Sstevel@tonic-gate 	{ "sonode", "?[-f inet | inet6 | unix | #] "
34387c478bd9Sstevel@tonic-gate 		"[-t stream | dgram | raw | #] [-p #]",
34397c478bd9Sstevel@tonic-gate 		"filter and display sonode", sonode },
34407c478bd9Sstevel@tonic-gate 
3441f4b3ec61Sdh 	/* from netstack.c */
3442f4b3ec61Sdh 	{ "netstack", "", "show stack instances", netstack },
3443f4b3ec61Sdh 
34447c478bd9Sstevel@tonic-gate 	/* from nvpair.c */
34457c478bd9Sstevel@tonic-gate 	{ NVPAIR_DCMD_NAME, NVPAIR_DCMD_USAGE, NVPAIR_DCMD_DESCR,
34467c478bd9Sstevel@tonic-gate 		nvpair_print },
3447fa9e4066Sahrens 	{ NVLIST_DCMD_NAME, NVLIST_DCMD_USAGE, NVLIST_DCMD_DESCR,
34488a40a695Sgavinm 		print_nvlist },
34497c478bd9Sstevel@tonic-gate 
3450fb2f18f8Sesaxe 	/* from pg.c */
3451fb2f18f8Sesaxe 	{ "pg", "?[-q]", "display a pg", pg},
3452fb2f18f8Sesaxe 	/* from group.c */
3453fb2f18f8Sesaxe 	{ "group", "?[-q]", "display a group", group},
3454fb2f18f8Sesaxe 
3455fb2f18f8Sesaxe 	/* from log.c */
34567c478bd9Sstevel@tonic-gate 	/* from rctl.c */
34577c478bd9Sstevel@tonic-gate 	{ "rctl_dict", "?", "print systemwide default rctl definitions",
34587c478bd9Sstevel@tonic-gate 		rctl_dict },
34597c478bd9Sstevel@tonic-gate 	{ "rctl_list", ":[handle]", "print rctls for the given proc",
34607c478bd9Sstevel@tonic-gate 		rctl_list },
34617c478bd9Sstevel@tonic-gate 	{ "rctl", ":[handle]", "print a rctl_t, only if it matches the handle",
34627c478bd9Sstevel@tonic-gate 		rctl },
34637c478bd9Sstevel@tonic-gate 	{ "rctl_validate", ":[-v] [-n #]", "test resource control value "
34647c478bd9Sstevel@tonic-gate 		"sequence", rctl_validate },
34657c478bd9Sstevel@tonic-gate 
34667c478bd9Sstevel@tonic-gate 	/* from sobj.c */
34677c478bd9Sstevel@tonic-gate 	{ "rwlock", ":", "dump out a readers/writer lock", rwlock },
34687c478bd9Sstevel@tonic-gate 	{ "mutex", ":[-f]", "dump out an adaptive or spin mutex", mutex,
34697c478bd9Sstevel@tonic-gate 		mutex_help },
34707c478bd9Sstevel@tonic-gate 	{ "sobj2ts", ":", "perform turnstile lookup on synch object", sobj2ts },
34717c478bd9Sstevel@tonic-gate 	{ "wchaninfo", "?[-v]", "dump condition variable", wchaninfo },
34727c478bd9Sstevel@tonic-gate 	{ "turnstile", "?", "display a turnstile", turnstile },
34737c478bd9Sstevel@tonic-gate 
34747c478bd9Sstevel@tonic-gate 	/* from stream.c */
34757c478bd9Sstevel@tonic-gate 	{ "mblk", ":[-q|v] [-f|F flag] [-t|T type] [-l|L|B len] [-d dbaddr]",
34767c478bd9Sstevel@tonic-gate 		"print an mblk", mblk_prt, mblk_help },
34777c478bd9Sstevel@tonic-gate 	{ "mblk_verify", "?", "verify integrity of an mblk", mblk_verify },
34787c478bd9Sstevel@tonic-gate 	{ "mblk2dblk", ":", "convert mblk_t address to dblk_t address",
34797c478bd9Sstevel@tonic-gate 		mblk2dblk },
34807c478bd9Sstevel@tonic-gate 	{ "q2otherq", ":", "print peer queue for a given queue", q2otherq },
34817c478bd9Sstevel@tonic-gate 	{ "q2rdq", ":", "print read queue for a given queue", q2rdq },
34827c478bd9Sstevel@tonic-gate 	{ "q2syncq", ":", "print syncq for a given queue", q2syncq },
34837c478bd9Sstevel@tonic-gate 	{ "q2stream", ":", "print stream pointer for a given queue", q2stream },
34847c478bd9Sstevel@tonic-gate 	{ "q2wrq", ":", "print write queue for a given queue", q2wrq },
34857c478bd9Sstevel@tonic-gate 	{ "queue", ":[-q|v] [-m mod] [-f flag] [-F flag] [-s syncq_addr]",
34867c478bd9Sstevel@tonic-gate 		"filter and display STREAM queue", queue, queue_help },
34877c478bd9Sstevel@tonic-gate 	{ "stdata", ":[-q|v] [-f flag] [-F flag]",
34887c478bd9Sstevel@tonic-gate 		"filter and display STREAM head", stdata, stdata_help },
34897c478bd9Sstevel@tonic-gate 	{ "str2mate", ":", "print mate of this stream", str2mate },
34907c478bd9Sstevel@tonic-gate 	{ "str2wrq", ":", "print write queue of this stream", str2wrq },
34917c478bd9Sstevel@tonic-gate 	{ "stream", ":", "display STREAM", stream },
34927c478bd9Sstevel@tonic-gate 	{ "strftevent", ":", "print STREAMS flow trace event", strftevent },
34937c478bd9Sstevel@tonic-gate 	{ "syncq", ":[-q|v] [-f flag] [-F flag] [-t type] [-T type]",
34947c478bd9Sstevel@tonic-gate 		"filter and display STREAM sync queue", syncq, syncq_help },
34957c478bd9Sstevel@tonic-gate 	{ "syncq2q", ":", "print queue for a given syncq", syncq2q },
34967c478bd9Sstevel@tonic-gate 
34977c478bd9Sstevel@tonic-gate 	/* from thread.c */
34987c478bd9Sstevel@tonic-gate 	{ "thread", "?[-bdfimps]", "display a summarized kthread_t", thread,
34997c478bd9Sstevel@tonic-gate 		thread_help },
35007c478bd9Sstevel@tonic-gate 	{ "threadlist", "?[-v [count]]",
35017c478bd9Sstevel@tonic-gate 		"display threads and associated C stack traces", threadlist,
35027c478bd9Sstevel@tonic-gate 		threadlist_help },
35037c478bd9Sstevel@tonic-gate 
35047c478bd9Sstevel@tonic-gate 	/* from tsd.c */
35057c478bd9Sstevel@tonic-gate 	{ "tsd", ":-k key", "print tsd[key-1] for this thread", ttotsd },
35067c478bd9Sstevel@tonic-gate 	{ "tsdtot", ":", "find thread with this tsd", tsdtot },
35077c478bd9Sstevel@tonic-gate 
35087c478bd9Sstevel@tonic-gate 	/*
35097c478bd9Sstevel@tonic-gate 	 * typegraph does not work under kmdb, as it requires too much memory
35107c478bd9Sstevel@tonic-gate 	 * for its internal data structures.
35117c478bd9Sstevel@tonic-gate 	 */
35127c478bd9Sstevel@tonic-gate #ifndef _KMDB
35137c478bd9Sstevel@tonic-gate 	/* from typegraph.c */
35147c478bd9Sstevel@tonic-gate 	{ "findlocks", ":", "find locks held by specified thread", findlocks },
35157c478bd9Sstevel@tonic-gate 	{ "findfalse", "?[-v]", "find potentially falsely shared structures",
35167c478bd9Sstevel@tonic-gate 		findfalse },
35177c478bd9Sstevel@tonic-gate 	{ "typegraph", NULL, "build type graph", typegraph },
35187c478bd9Sstevel@tonic-gate 	{ "istype", ":type", "manually set object type", istype },
35197c478bd9Sstevel@tonic-gate 	{ "notype", ":", "manually clear object type", notype },
35207c478bd9Sstevel@tonic-gate 	{ "whattype", ":", "determine object type", whattype },
35217c478bd9Sstevel@tonic-gate #endif
35227c478bd9Sstevel@tonic-gate 
35237c478bd9Sstevel@tonic-gate 	/* from vfs.c */
35247c478bd9Sstevel@tonic-gate 	{ "fsinfo", "?[-v]", "print mounted filesystems", fsinfo },
35257c478bd9Sstevel@tonic-gate 	{ "pfiles", ":[-fp]", "print process file information", pfiles,
35267c478bd9Sstevel@tonic-gate 		pfiles_help },
35277c478bd9Sstevel@tonic-gate 
352870ab954aSramat 	/* from mdi.c */
352970ab954aSramat 	{ "mdipi", NULL, "given a path, dump mdi_pathinfo "
353070ab954aSramat 		"and detailed pi_prop list", mdipi },
353170ab954aSramat 	{ "mdiprops", NULL, "given a pi_prop, dump the pi_prop list",
353270ab954aSramat 		mdiprops },
353370ab954aSramat 	{ "mdiphci", NULL, "given a phci, dump mdi_phci and "
353470ab954aSramat 		"list all paths", mdiphci },
353570ab954aSramat 	{ "mdivhci", NULL, "given a vhci, dump mdi_vhci and list "
353670ab954aSramat 		"all phcis", mdivhci },
353770ab954aSramat 	{ "mdiclient_paths", NULL, "given a path, walk mdi_pathinfo "
353870ab954aSramat 		"client links", mdiclient_paths },
353970ab954aSramat 	{ "mdiphci_paths", NULL, "given a path, walk through mdi_pathinfo "
354070ab954aSramat 		"phci links", mdiphci_paths },
354170ab954aSramat 	{ "mdiphcis", NULL, "given a phci, walk through mdi_phci ph_next links",
354270ab954aSramat 		mdiphcis },
354370ab954aSramat 
35447c478bd9Sstevel@tonic-gate 	{ NULL }
35457c478bd9Sstevel@tonic-gate };
35467c478bd9Sstevel@tonic-gate 
35477c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
35487c478bd9Sstevel@tonic-gate 
35497c478bd9Sstevel@tonic-gate 	/* from genunix.c */
35507c478bd9Sstevel@tonic-gate 	{ "anon", "given an amp, list of anon structures",
35517c478bd9Sstevel@tonic-gate 		anon_walk_init, anon_walk_step, anon_walk_fini },
35527c478bd9Sstevel@tonic-gate 	{ "cpu", "walk cpu structures", cpu_walk_init, cpu_walk_step },
35539dd0f810Scindi 	{ "ereportq_dump", "walk list of ereports in dump error queue",
35549dd0f810Scindi 		ereportq_dump_walk_init, ereportq_dump_walk_step, NULL },
35559dd0f810Scindi 	{ "ereportq_pend", "walk list of ereports in pending error queue",
35569dd0f810Scindi 		ereportq_pend_walk_init, ereportq_pend_walk_step, NULL },
35577c478bd9Sstevel@tonic-gate 	{ "errorq", "walk list of system error queues",
35587c478bd9Sstevel@tonic-gate 		errorq_walk_init, errorq_walk_step, NULL },
35597c478bd9Sstevel@tonic-gate 	{ "errorq_data", "walk pending error queue data buffers",
35607c478bd9Sstevel@tonic-gate 		eqd_walk_init, eqd_walk_step, eqd_walk_fini },
35617c478bd9Sstevel@tonic-gate 	{ "allfile", "given a proc pointer, list all file pointers",
35627c478bd9Sstevel@tonic-gate 		file_walk_init, allfile_walk_step, file_walk_fini },
35637c478bd9Sstevel@tonic-gate 	{ "file", "given a proc pointer, list of open file pointers",
35647c478bd9Sstevel@tonic-gate 		file_walk_init, file_walk_step, file_walk_fini },
35657c478bd9Sstevel@tonic-gate 	{ "lock_descriptor", "walk lock_descriptor_t structures",
35667c478bd9Sstevel@tonic-gate 		ld_walk_init, ld_walk_step, NULL },
35677c478bd9Sstevel@tonic-gate 	{ "lock_graph", "walk lock graph",
35687c478bd9Sstevel@tonic-gate 		lg_walk_init, lg_walk_step, NULL },
35697c478bd9Sstevel@tonic-gate 	{ "port", "given a proc pointer, list of created event ports",
35707c478bd9Sstevel@tonic-gate 		port_walk_init, port_walk_step, NULL },
35717c478bd9Sstevel@tonic-gate 	{ "portev", "given a port pointer, list of events in the queue",
35727c478bd9Sstevel@tonic-gate 		portev_walk_init, portev_walk_step, portev_walk_fini },
35737c478bd9Sstevel@tonic-gate 	{ "proc", "list of active proc_t structures",
35747c478bd9Sstevel@tonic-gate 		proc_walk_init, proc_walk_step, proc_walk_fini },
35757c478bd9Sstevel@tonic-gate 	{ "projects", "walk a list of kernel projects",
35767c478bd9Sstevel@tonic-gate 		project_walk_init, project_walk_step, NULL },
35777c478bd9Sstevel@tonic-gate 	{ "seg", "given an as, list of segments",
35787c478bd9Sstevel@tonic-gate 		seg_walk_init, avl_walk_step, avl_walk_fini },
35797c478bd9Sstevel@tonic-gate 	{ "sysevent_pend", "walk sysevent pending queue",
35807c478bd9Sstevel@tonic-gate 		sysevent_pend_walk_init, sysevent_walk_step,
35817c478bd9Sstevel@tonic-gate 		sysevent_walk_fini},
35827c478bd9Sstevel@tonic-gate 	{ "sysevent_sent", "walk sysevent sent queue", sysevent_sent_walk_init,
35837c478bd9Sstevel@tonic-gate 		sysevent_walk_step, sysevent_walk_fini},
35847c478bd9Sstevel@tonic-gate 	{ "sysevent_channel", "walk sysevent channel subscriptions",
35857c478bd9Sstevel@tonic-gate 		sysevent_channel_walk_init, sysevent_channel_walk_step,
35867c478bd9Sstevel@tonic-gate 		sysevent_channel_walk_fini},
35877c478bd9Sstevel@tonic-gate 	{ "sysevent_class_list", "walk sysevent subscription's class list",
35887c478bd9Sstevel@tonic-gate 		sysevent_class_list_walk_init, sysevent_class_list_walk_step,
35897c478bd9Sstevel@tonic-gate 		sysevent_class_list_walk_fini},
35907c478bd9Sstevel@tonic-gate 	{ "sysevent_subclass_list",
35917c478bd9Sstevel@tonic-gate 		"walk sysevent subscription's subclass list",
35927c478bd9Sstevel@tonic-gate 		sysevent_subclass_list_walk_init,
35937c478bd9Sstevel@tonic-gate 		sysevent_subclass_list_walk_step,
35947c478bd9Sstevel@tonic-gate 		sysevent_subclass_list_walk_fini},
35957c478bd9Sstevel@tonic-gate 	{ "task", "given a task pointer, walk its processes",
35967c478bd9Sstevel@tonic-gate 		task_walk_init, task_walk_step, NULL },
35977c478bd9Sstevel@tonic-gate 	{ "taskq_entry", "given a taskq_t*, list all taskq_ent_t in the list",
35987c478bd9Sstevel@tonic-gate 		taskq_walk_init, taskq_walk_step, NULL, NULL },
35997c478bd9Sstevel@tonic-gate 
3600fa9e4066Sahrens 	/* from avl.c */
3601fa9e4066Sahrens 	{ AVL_WALK_NAME, AVL_WALK_DESC,
3602fa9e4066Sahrens 		avl_walk_init, avl_walk_step, avl_walk_fini },
3603fa9e4066Sahrens 
36047c478bd9Sstevel@tonic-gate 	/* from zone.c */
36057c478bd9Sstevel@tonic-gate 	{ "zone", "walk a list of kernel zones",
36067c478bd9Sstevel@tonic-gate 		zone_walk_init, zone_walk_step, NULL },
36077c478bd9Sstevel@tonic-gate 	{ "zsd", "walk list of zsd entries for a zone",
36087c478bd9Sstevel@tonic-gate 		zsd_walk_init, zsd_walk_step, NULL },
36097c478bd9Sstevel@tonic-gate 
36107c478bd9Sstevel@tonic-gate 	/* from bio.c */
36117c478bd9Sstevel@tonic-gate 	{ "buf", "walk the bio buf hash",
36127c478bd9Sstevel@tonic-gate 		buf_walk_init, buf_walk_step, buf_walk_fini },
36137c478bd9Sstevel@tonic-gate 
36147c478bd9Sstevel@tonic-gate 	/* from contract.c */
36157c478bd9Sstevel@tonic-gate 	{ "contract", "walk all contracts, or those of the specified type",
36167c478bd9Sstevel@tonic-gate 		ct_walk_init, generic_walk_step, NULL },
36177c478bd9Sstevel@tonic-gate 	{ "ct_event", "walk events on a contract event queue",
36187c478bd9Sstevel@tonic-gate 		ct_event_walk_init, generic_walk_step, NULL },
36197c478bd9Sstevel@tonic-gate 	{ "ct_listener", "walk contract event queue listeners",
36207c478bd9Sstevel@tonic-gate 		ct_listener_walk_init, generic_walk_step, NULL },
36217c478bd9Sstevel@tonic-gate 
36227c478bd9Sstevel@tonic-gate 	/* from cpupart.c */
36237c478bd9Sstevel@tonic-gate 	{ "cpupart_cpulist", "given an cpupart_t, walk cpus in partition",
36247c478bd9Sstevel@tonic-gate 		cpupart_cpulist_walk_init, cpupart_cpulist_walk_step,
36257c478bd9Sstevel@tonic-gate 		NULL },
36267c478bd9Sstevel@tonic-gate 	{ "cpupart_walk", "walk the set of cpu partitions",
36277c478bd9Sstevel@tonic-gate 		cpupart_walk_init, cpupart_walk_step, NULL },
36287c478bd9Sstevel@tonic-gate 
36297c478bd9Sstevel@tonic-gate 	/* from ctxop.c */
36307c478bd9Sstevel@tonic-gate 	{ "ctxop", "walk list of context ops on a thread",
36317c478bd9Sstevel@tonic-gate 		ctxop_walk_init, ctxop_walk_step, ctxop_walk_fini },
36327c478bd9Sstevel@tonic-gate 
36337c478bd9Sstevel@tonic-gate 	/* from cyclic.c */
36347c478bd9Sstevel@tonic-gate 	{ "cyccpu", "walk per-CPU cyc_cpu structures",
36357c478bd9Sstevel@tonic-gate 		cyccpu_walk_init, cyccpu_walk_step, NULL },
36367c478bd9Sstevel@tonic-gate 	{ "cycomni", "for an omnipresent cyclic, walk cyc_omni_cpu list",
36377c478bd9Sstevel@tonic-gate 		cycomni_walk_init, cycomni_walk_step, NULL },
36387c478bd9Sstevel@tonic-gate 	{ "cyctrace", "walk cyclic trace buffer",
36397c478bd9Sstevel@tonic-gate 		cyctrace_walk_init, cyctrace_walk_step, cyctrace_walk_fini },
36407c478bd9Sstevel@tonic-gate 
36417c478bd9Sstevel@tonic-gate 	/* from devinfo.c */
36427c478bd9Sstevel@tonic-gate 	{ "binding_hash", "walk all entries in binding hash table",
36437c478bd9Sstevel@tonic-gate 		binding_hash_walk_init, binding_hash_walk_step, NULL },
36447c478bd9Sstevel@tonic-gate 	{ "devinfo", "walk devinfo tree or subtree",
36457c478bd9Sstevel@tonic-gate 		devinfo_walk_init, devinfo_walk_step, devinfo_walk_fini },
36467c478bd9Sstevel@tonic-gate 	{ "devinfo_audit_log", "walk devinfo audit system-wide log",
36477c478bd9Sstevel@tonic-gate 		devinfo_audit_log_walk_init, devinfo_audit_log_walk_step,
36487c478bd9Sstevel@tonic-gate 		devinfo_audit_log_walk_fini},
36497c478bd9Sstevel@tonic-gate 	{ "devinfo_audit_node", "walk per-devinfo audit history",
36507c478bd9Sstevel@tonic-gate 		devinfo_audit_node_walk_init, devinfo_audit_node_walk_step,
36517c478bd9Sstevel@tonic-gate 		devinfo_audit_node_walk_fini},
36527c478bd9Sstevel@tonic-gate 	{ "devinfo_children", "walk children of devinfo node",
36537c478bd9Sstevel@tonic-gate 		devinfo_children_walk_init, devinfo_children_walk_step,
36547c478bd9Sstevel@tonic-gate 		devinfo_children_walk_fini },
36557c478bd9Sstevel@tonic-gate 	{ "devinfo_parents", "walk ancestors of devinfo node",
36567c478bd9Sstevel@tonic-gate 		devinfo_parents_walk_init, devinfo_parents_walk_step,
36577c478bd9Sstevel@tonic-gate 		devinfo_parents_walk_fini },
36587c478bd9Sstevel@tonic-gate 	{ "devinfo_siblings", "walk siblings of devinfo node",
36597c478bd9Sstevel@tonic-gate 		devinfo_siblings_walk_init, devinfo_siblings_walk_step, NULL },
36607c478bd9Sstevel@tonic-gate 	{ "devi_next", "walk devinfo list",
36617c478bd9Sstevel@tonic-gate 		NULL, devi_next_walk_step, NULL },
36627c478bd9Sstevel@tonic-gate 	{ "devnames", "walk devnames array",
36637c478bd9Sstevel@tonic-gate 		devnames_walk_init, devnames_walk_step, devnames_walk_fini },
36647c478bd9Sstevel@tonic-gate 	{ "minornode", "given a devinfo node, walk minor nodes",
36657c478bd9Sstevel@tonic-gate 		minornode_walk_init, minornode_walk_step, NULL },
36667c478bd9Sstevel@tonic-gate 	{ "softstate",
36677c478bd9Sstevel@tonic-gate 		"given an i_ddi_soft_state*, list all in-use driver stateps",
36687c478bd9Sstevel@tonic-gate 		soft_state_walk_init, soft_state_walk_step,
36697c478bd9Sstevel@tonic-gate 		NULL, NULL },
36707c478bd9Sstevel@tonic-gate 	{ "softstate_all",
36717c478bd9Sstevel@tonic-gate 		"given an i_ddi_soft_state*, list all driver stateps",
36727c478bd9Sstevel@tonic-gate 		soft_state_walk_init, soft_state_all_walk_step,
36737c478bd9Sstevel@tonic-gate 		NULL, NULL },
36747c478bd9Sstevel@tonic-gate 	{ "devinfo_fmc",
36757c478bd9Sstevel@tonic-gate 		"walk a fault management handle cache active list",
36767c478bd9Sstevel@tonic-gate 		devinfo_fmc_walk_init, devinfo_fmc_walk_step, NULL },
36777c478bd9Sstevel@tonic-gate 
36787c478bd9Sstevel@tonic-gate 	/* from kmem.c */
36797c478bd9Sstevel@tonic-gate 	{ "allocdby", "given a thread, walk its allocated bufctls",
36807c478bd9Sstevel@tonic-gate 		allocdby_walk_init, allocdby_walk_step, allocdby_walk_fini },
36817c478bd9Sstevel@tonic-gate 	{ "bufctl", "walk a kmem cache's bufctls",
36827c478bd9Sstevel@tonic-gate 		bufctl_walk_init, kmem_walk_step, kmem_walk_fini },
36837c478bd9Sstevel@tonic-gate 	{ "bufctl_history", "walk the available history of a bufctl",
36847c478bd9Sstevel@tonic-gate 		bufctl_history_walk_init, bufctl_history_walk_step,
36857c478bd9Sstevel@tonic-gate 		bufctl_history_walk_fini },
36867c478bd9Sstevel@tonic-gate 	{ "freedby", "given a thread, walk its freed bufctls",
36877c478bd9Sstevel@tonic-gate 		freedby_walk_init, allocdby_walk_step, allocdby_walk_fini },
36887c478bd9Sstevel@tonic-gate 	{ "freectl", "walk a kmem cache's free bufctls",
36897c478bd9Sstevel@tonic-gate 		freectl_walk_init, kmem_walk_step, kmem_walk_fini },
36907c478bd9Sstevel@tonic-gate 	{ "freectl_constructed", "walk a kmem cache's constructed free bufctls",
36917c478bd9Sstevel@tonic-gate 		freectl_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
36927c478bd9Sstevel@tonic-gate 	{ "freemem", "walk a kmem cache's free memory",
36937c478bd9Sstevel@tonic-gate 		freemem_walk_init, kmem_walk_step, kmem_walk_fini },
36947c478bd9Sstevel@tonic-gate 	{ "freemem_constructed", "walk a kmem cache's constructed free memory",
36957c478bd9Sstevel@tonic-gate 		freemem_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
36967c478bd9Sstevel@tonic-gate 	{ "kmem", "walk a kmem cache",
36977c478bd9Sstevel@tonic-gate 		kmem_walk_init, kmem_walk_step, kmem_walk_fini },
36987c478bd9Sstevel@tonic-gate 	{ "kmem_cpu_cache", "given a kmem cache, walk its per-CPU caches",
36997c478bd9Sstevel@tonic-gate 		kmem_cpu_cache_walk_init, kmem_cpu_cache_walk_step, NULL },
37007c478bd9Sstevel@tonic-gate 	{ "kmem_hash", "given a kmem cache, walk its allocated hash table",
37017c478bd9Sstevel@tonic-gate 		kmem_hash_walk_init, kmem_hash_walk_step, kmem_hash_walk_fini },
37027c478bd9Sstevel@tonic-gate 	{ "kmem_log", "walk the kmem transaction log",
37037c478bd9Sstevel@tonic-gate 		kmem_log_walk_init, kmem_log_walk_step, kmem_log_walk_fini },
37047c478bd9Sstevel@tonic-gate 	{ "kmem_slab", "given a kmem cache, walk its slabs",
37057c478bd9Sstevel@tonic-gate 		kmem_slab_walk_init, kmem_slab_walk_step, NULL },
37067c478bd9Sstevel@tonic-gate 	{ "kmem_slab_partial",
37077c478bd9Sstevel@tonic-gate 	    "given a kmem cache, walk its partially allocated slabs (min 1)",
37087c478bd9Sstevel@tonic-gate 		kmem_slab_walk_partial_init, kmem_slab_walk_step, NULL },
37097c478bd9Sstevel@tonic-gate 	{ "vmem", "walk vmem structures in pre-fix, depth-first order",
37107c478bd9Sstevel@tonic-gate 		vmem_walk_init, vmem_walk_step, vmem_walk_fini },
37117c478bd9Sstevel@tonic-gate 	{ "vmem_alloc", "given a vmem_t, walk its allocated vmem_segs",
37127c478bd9Sstevel@tonic-gate 		vmem_alloc_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
37137c478bd9Sstevel@tonic-gate 	{ "vmem_free", "given a vmem_t, walk its free vmem_segs",
37147c478bd9Sstevel@tonic-gate 		vmem_free_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
37157c478bd9Sstevel@tonic-gate 	{ "vmem_postfix", "walk vmem structures in post-fix, depth-first order",
37167c478bd9Sstevel@tonic-gate 		vmem_walk_init, vmem_postfix_walk_step, vmem_walk_fini },
37177c478bd9Sstevel@tonic-gate 	{ "vmem_seg", "given a vmem_t, walk all of its vmem_segs",
37187c478bd9Sstevel@tonic-gate 		vmem_seg_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
37197c478bd9Sstevel@tonic-gate 	{ "vmem_span", "given a vmem_t, walk its spanning vmem_segs",
37207c478bd9Sstevel@tonic-gate 		vmem_span_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
37217c478bd9Sstevel@tonic-gate 
37227c478bd9Sstevel@tonic-gate 	/* from ldi.c */
37237c478bd9Sstevel@tonic-gate 	{ "ldi_handle", "walk the layered driver handle hash",
37247c478bd9Sstevel@tonic-gate 		ldi_handle_walk_init, ldi_handle_walk_step, NULL },
37257c478bd9Sstevel@tonic-gate 	{ "ldi_ident", "walk the layered driver identifier hash",
37267c478bd9Sstevel@tonic-gate 		ldi_ident_walk_init, ldi_ident_walk_step, NULL },
37277c478bd9Sstevel@tonic-gate 
37287c478bd9Sstevel@tonic-gate 	/* from leaky.c + leaky_subr.c */
37297c478bd9Sstevel@tonic-gate 	{ "leak", "given a leaked bufctl or vmem_seg, find leaks w/ same "
37307c478bd9Sstevel@tonic-gate 	    "stack trace",
37317c478bd9Sstevel@tonic-gate 		leaky_walk_init, leaky_walk_step, leaky_walk_fini },
37327c478bd9Sstevel@tonic-gate 	{ "leakbuf", "given a leaked bufctl or vmem_seg, walk buffers for "
37337c478bd9Sstevel@tonic-gate 	    "leaks w/ same stack trace",
37347c478bd9Sstevel@tonic-gate 		leaky_walk_init, leaky_buf_walk_step, leaky_walk_fini },
37357c478bd9Sstevel@tonic-gate 
37367c478bd9Sstevel@tonic-gate 	/* from lgrp.c */
3737c6402783Sakolb 	{ "lgrp_cpulist", "walk CPUs in a given lgroup",
3738c6402783Sakolb 		lgrp_cpulist_walk_init, lgrp_cpulist_walk_step, NULL },
3739c6402783Sakolb 	{ "lgrptbl", "walk lgroup table",
37407c478bd9Sstevel@tonic-gate 		lgrp_walk_init, lgrp_walk_step, NULL },
3741c6402783Sakolb 	{ "lgrp_parents", "walk up lgroup lineage from given lgroup",
3742c6402783Sakolb 		lgrp_parents_walk_init, lgrp_parents_walk_step, NULL },
3743c6402783Sakolb 	{ "lgrp_rsrc_mem", "walk lgroup memory resources of given lgroup",
3744c6402783Sakolb 		lgrp_rsrc_mem_walk_init, lgrp_set_walk_step, NULL },
3745c6402783Sakolb 	{ "lgrp_rsrc_cpu", "walk lgroup CPU resources of given lgroup",
3746c6402783Sakolb 		lgrp_rsrc_cpu_walk_init, lgrp_set_walk_step, NULL },
37477c478bd9Sstevel@tonic-gate 
3748fb2f18f8Sesaxe 	/* from group.c */
3749fb2f18f8Sesaxe 	{ "group", "walk all elements of a group",
3750fb2f18f8Sesaxe 		group_walk_init, group_walk_step, NULL },
3751fb2f18f8Sesaxe 
37527c478bd9Sstevel@tonic-gate 	/* from list.c */
3753fa9e4066Sahrens 	{ LIST_WALK_NAME, LIST_WALK_DESC,
37547c478bd9Sstevel@tonic-gate 		list_walk_init, list_walk_step, list_walk_fini },
37557c478bd9Sstevel@tonic-gate 
37567c478bd9Sstevel@tonic-gate 	/* from memory.c */
37577c478bd9Sstevel@tonic-gate 	{ "page", "walk all pages, or those from the specified vnode",
37587c478bd9Sstevel@tonic-gate 		page_walk_init, page_walk_step, page_walk_fini },
37597c478bd9Sstevel@tonic-gate 	{ "memlist", "walk specified memlist",
37607c478bd9Sstevel@tonic-gate 		NULL, memlist_walk_step, NULL },
37617c478bd9Sstevel@tonic-gate 	{ "swapinfo", "walk swapinfo structures",
37627c478bd9Sstevel@tonic-gate 		swap_walk_init, swap_walk_step, NULL },
37637c478bd9Sstevel@tonic-gate 
37647c478bd9Sstevel@tonic-gate 	/* from mmd.c */
37657c478bd9Sstevel@tonic-gate 	{ "pattr", "walk pattr_t structures", pattr_walk_init,
37667c478bd9Sstevel@tonic-gate 		mmdq_walk_step, mmdq_walk_fini },
37677c478bd9Sstevel@tonic-gate 	{ "pdesc", "walk pdesc_t structures",
37687c478bd9Sstevel@tonic-gate 		pdesc_walk_init, mmdq_walk_step, mmdq_walk_fini },
37697c478bd9Sstevel@tonic-gate 	{ "pdesc_slab", "walk pdesc_slab_t structures",
37707c478bd9Sstevel@tonic-gate 		pdesc_slab_walk_init, mmdq_walk_step, mmdq_walk_fini },
37717c478bd9Sstevel@tonic-gate 
37727c478bd9Sstevel@tonic-gate 	/* from modhash.c */
37737c478bd9Sstevel@tonic-gate 	{ "modhash", "walk list of mod_hash structures", modhash_walk_init,
37747c478bd9Sstevel@tonic-gate 		modhash_walk_step, NULL },
37757c478bd9Sstevel@tonic-gate 	{ "modent", "walk list of entries in a given mod_hash",
37767c478bd9Sstevel@tonic-gate 		modent_walk_init, modent_walk_step, modent_walk_fini },
37777c478bd9Sstevel@tonic-gate 	{ "modchain", "walk list of entries in a given mod_hash_entry",
37787c478bd9Sstevel@tonic-gate 		NULL, modchain_walk_step, NULL },
37797c478bd9Sstevel@tonic-gate 
37807c478bd9Sstevel@tonic-gate 	/* from net.c */
3781f4b3ec61Sdh 	{ "ar", "walk ar_t structures using MI for all stacks",
3782f4b3ec61Sdh 		mi_payload_walk_init, mi_payload_walk_step, NULL, &mi_ar_arg },
3783f4b3ec61Sdh 	{ "icmp", "walk ICMP control structures using MI for all stacks",
3784f4b3ec61Sdh 		mi_payload_walk_init, mi_payload_walk_step, NULL,
3785f4b3ec61Sdh 		&mi_icmp_arg },
3786f4b3ec61Sdh 	{ "ill", "walk ill_t structures using MI for all stacks",
3787f4b3ec61Sdh 		mi_payload_walk_init, mi_payload_walk_step, NULL, &mi_ill_arg },
3788f4b3ec61Sdh 
37897c478bd9Sstevel@tonic-gate 	{ "mi", "given a MI_O, walk the MI",
37907c478bd9Sstevel@tonic-gate 		mi_walk_init, mi_walk_step, mi_walk_fini, NULL },
37917c478bd9Sstevel@tonic-gate 	{ "sonode", "given a sonode, walk its children",
37927c478bd9Sstevel@tonic-gate 		sonode_walk_init, sonode_walk_step, sonode_walk_fini, NULL },
37937c478bd9Sstevel@tonic-gate 
3794f4b3ec61Sdh 	{ "ar_stacks", "walk all the ar_stack_t",
3795f4b3ec61Sdh 		ar_stacks_walk_init, ar_stacks_walk_step, NULL },
3796f4b3ec61Sdh 	{ "icmp_stacks", "walk all the icmp_stack_t",
3797f4b3ec61Sdh 		icmp_stacks_walk_init, icmp_stacks_walk_step, NULL },
3798f4b3ec61Sdh 	{ "tcp_stacks", "walk all the tcp_stack_t",
3799f4b3ec61Sdh 		tcp_stacks_walk_init, tcp_stacks_walk_step, NULL },
3800f4b3ec61Sdh 	{ "udp_stacks", "walk all the udp_stack_t",
3801f4b3ec61Sdh 		udp_stacks_walk_init, udp_stacks_walk_step, NULL },
3802f4b3ec61Sdh 
38037c478bd9Sstevel@tonic-gate 	/* from nvpair.c */
38047c478bd9Sstevel@tonic-gate 	{ NVPAIR_WALKER_NAME, NVPAIR_WALKER_DESCR,
38057c478bd9Sstevel@tonic-gate 		nvpair_walk_init, nvpair_walk_step, NULL },
38067c478bd9Sstevel@tonic-gate 
38077c478bd9Sstevel@tonic-gate 	/* from rctl.c */
38087c478bd9Sstevel@tonic-gate 	{ "rctl_dict_list", "walk all rctl_dict_entry_t's from rctl_lists",
38097c478bd9Sstevel@tonic-gate 		rctl_dict_walk_init, rctl_dict_walk_step, NULL },
38107c478bd9Sstevel@tonic-gate 	{ "rctl_set", "given a rctl_set, walk all rctls", rctl_set_walk_init,
38117c478bd9Sstevel@tonic-gate 		rctl_set_walk_step, NULL },
38127c478bd9Sstevel@tonic-gate 	{ "rctl_val", "given a rctl_t, walk all rctl_val entries associated",
38137c478bd9Sstevel@tonic-gate 		rctl_val_walk_init, rctl_val_walk_step },
38147c478bd9Sstevel@tonic-gate 
38157c478bd9Sstevel@tonic-gate 	/* from sobj.c */
38167c478bd9Sstevel@tonic-gate 	{ "blocked", "walk threads blocked on a given sobj",
38177c478bd9Sstevel@tonic-gate 		blocked_walk_init, blocked_walk_step, NULL },
38187c478bd9Sstevel@tonic-gate 	{ "wchan", "given a wchan, list of blocked threads",
38197c478bd9Sstevel@tonic-gate 		wchan_walk_init, wchan_walk_step, wchan_walk_fini },
38207c478bd9Sstevel@tonic-gate 
38217c478bd9Sstevel@tonic-gate 	/* from stream.c */
38227c478bd9Sstevel@tonic-gate 	{ "b_cont", "walk mblk_t list using b_cont",
38237c478bd9Sstevel@tonic-gate 		mblk_walk_init, b_cont_step, mblk_walk_fini },
38247c478bd9Sstevel@tonic-gate 	{ "b_next", "walk mblk_t list using b_next",
38257c478bd9Sstevel@tonic-gate 		mblk_walk_init, b_next_step, mblk_walk_fini },
38267c478bd9Sstevel@tonic-gate 	{ "qlink", "walk queue_t list using q_link",
38277c478bd9Sstevel@tonic-gate 		queue_walk_init, queue_link_step, queue_walk_fini },
38287c478bd9Sstevel@tonic-gate 	{ "qnext", "walk queue_t list using q_next",
38297c478bd9Sstevel@tonic-gate 		queue_walk_init, queue_next_step, queue_walk_fini },
38307c478bd9Sstevel@tonic-gate 	{ "strftblk", "given a dblk_t, walk STREAMS flow trace event list",
38317c478bd9Sstevel@tonic-gate 		strftblk_walk_init, strftblk_step, strftblk_walk_fini },
38327c478bd9Sstevel@tonic-gate 	{ "readq", "walk read queue side of stdata",
38337c478bd9Sstevel@tonic-gate 		str_walk_init, strr_walk_step, str_walk_fini },
38347c478bd9Sstevel@tonic-gate 	{ "writeq", "walk write queue side of stdata",
38357c478bd9Sstevel@tonic-gate 		str_walk_init, strw_walk_step, str_walk_fini },
38367c478bd9Sstevel@tonic-gate 
38377c478bd9Sstevel@tonic-gate 	/* from thread.c */
38387c478bd9Sstevel@tonic-gate 	{ "deathrow", "walk threads on both lwp_ and thread_deathrow",
38397c478bd9Sstevel@tonic-gate 		deathrow_walk_init, deathrow_walk_step, NULL },
38407c478bd9Sstevel@tonic-gate 	{ "cpu_dispq", "given a cpu_t, walk threads in dispatcher queues",
38417c478bd9Sstevel@tonic-gate 		cpu_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
38427c478bd9Sstevel@tonic-gate 	{ "cpupart_dispq",
38437c478bd9Sstevel@tonic-gate 		"given a cpupart_t, walk threads in dispatcher queues",
38447c478bd9Sstevel@tonic-gate 		cpupart_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
38457c478bd9Sstevel@tonic-gate 	{ "lwp_deathrow", "walk lwp_deathrow",
38467c478bd9Sstevel@tonic-gate 		lwp_deathrow_walk_init, deathrow_walk_step, NULL },
38477c478bd9Sstevel@tonic-gate 	{ "thread", "global or per-process kthread_t structures",
38487c478bd9Sstevel@tonic-gate 		thread_walk_init, thread_walk_step, thread_walk_fini },
38497c478bd9Sstevel@tonic-gate 	{ "thread_deathrow", "walk threads on thread_deathrow",
38507c478bd9Sstevel@tonic-gate 		thread_deathrow_walk_init, deathrow_walk_step, NULL },
38517c478bd9Sstevel@tonic-gate 
38527c478bd9Sstevel@tonic-gate 	/* from tsd.c */
38537c478bd9Sstevel@tonic-gate 	{ "tsd", "walk list of thread-specific data",
38547c478bd9Sstevel@tonic-gate 		tsd_walk_init, tsd_walk_step, tsd_walk_fini },
38557c478bd9Sstevel@tonic-gate 
385645916cd2Sjpk 	/* from tsol.c */
385745916cd2Sjpk 	{ "tnrh", "walk remote host cache structures",
385845916cd2Sjpk 	    tnrh_walk_init, tnrh_walk_step, tnrh_walk_fini },
385945916cd2Sjpk 	{ "tnrhtp", "walk remote host template structures",
386045916cd2Sjpk 	    tnrhtp_walk_init, tnrhtp_walk_step, tnrhtp_walk_fini },
386145916cd2Sjpk 
38627c478bd9Sstevel@tonic-gate 	/*
38637c478bd9Sstevel@tonic-gate 	 * typegraph does not work under kmdb, as it requires too much memory
38647c478bd9Sstevel@tonic-gate 	 * for its internal data structures.
38657c478bd9Sstevel@tonic-gate 	 */
38667c478bd9Sstevel@tonic-gate #ifndef _KMDB
38677c478bd9Sstevel@tonic-gate 	/* from typegraph.c */
38687c478bd9Sstevel@tonic-gate 	{ "typeconflict", "walk buffers with conflicting type inferences",
38697c478bd9Sstevel@tonic-gate 		typegraph_walk_init, typeconflict_walk_step },
38707c478bd9Sstevel@tonic-gate 	{ "typeunknown", "walk buffers with unknown types",
38717c478bd9Sstevel@tonic-gate 		typegraph_walk_init, typeunknown_walk_step },
38727c478bd9Sstevel@tonic-gate #endif
38737c478bd9Sstevel@tonic-gate 
38747c478bd9Sstevel@tonic-gate 	/* from vfs.c */
38757c478bd9Sstevel@tonic-gate 	{ "vfs", "walk file system list",
38767c478bd9Sstevel@tonic-gate 		vfs_walk_init, vfs_walk_step },
387770ab954aSramat 
387870ab954aSramat 	/* from mdi.c */
387970ab954aSramat 	{ "mdipi_client_list", "Walker for mdi_pathinfo pi_client_link",
388070ab954aSramat 		mdi_pi_client_link_walk_init,
388170ab954aSramat 		mdi_pi_client_link_walk_step,
388270ab954aSramat 		mdi_pi_client_link_walk_fini },
388370ab954aSramat 
388470ab954aSramat 	{ "mdipi_phci_list", "Walker for mdi_pathinfo pi_phci_link",
388570ab954aSramat 		mdi_pi_phci_link_walk_init,
388670ab954aSramat 		mdi_pi_phci_link_walk_step,
388770ab954aSramat 		mdi_pi_phci_link_walk_fini },
388870ab954aSramat 
388970ab954aSramat 	{ "mdiphci_list", "Walker for mdi_phci ph_next link",
389070ab954aSramat 		mdi_phci_ph_next_walk_init,
389170ab954aSramat 		mdi_phci_ph_next_walk_step,
389270ab954aSramat 		mdi_phci_ph_next_walk_fini },
389370ab954aSramat 
3894f4b3ec61Sdh 	/* from netstack.c */
3895f4b3ec61Sdh 	{ "netstack", "walk a list of kernel netstacks",
3896f4b3ec61Sdh 		netstack_walk_init, netstack_walk_step, NULL },
3897f4b3ec61Sdh 
38987c478bd9Sstevel@tonic-gate 	{ NULL }
38997c478bd9Sstevel@tonic-gate };
39007c478bd9Sstevel@tonic-gate 
39017c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
39027c478bd9Sstevel@tonic-gate 
39037c478bd9Sstevel@tonic-gate const mdb_modinfo_t *
39047c478bd9Sstevel@tonic-gate _mdb_init(void)
39057c478bd9Sstevel@tonic-gate {
39067c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&devinfo_root, "top_devinfo") == -1) {
39077c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read 'top_devinfo'");
39087c478bd9Sstevel@tonic-gate 		return (NULL);
39097c478bd9Sstevel@tonic-gate 	}
39107c478bd9Sstevel@tonic-gate 
39117c478bd9Sstevel@tonic-gate 	if (findstack_init() != DCMD_OK)
39127c478bd9Sstevel@tonic-gate 		return (NULL);
39137c478bd9Sstevel@tonic-gate 
39147c478bd9Sstevel@tonic-gate 	kmem_init();
39157c478bd9Sstevel@tonic-gate 
39167c478bd9Sstevel@tonic-gate 	return (&modinfo);
39177c478bd9Sstevel@tonic-gate }
39187c478bd9Sstevel@tonic-gate 
39197c478bd9Sstevel@tonic-gate void
39207c478bd9Sstevel@tonic-gate _mdb_fini(void)
39217c478bd9Sstevel@tonic-gate {
39227c478bd9Sstevel@tonic-gate 	/*
39237c478bd9Sstevel@tonic-gate 	 * Force ::findleaks to let go any cached memory
39247c478bd9Sstevel@tonic-gate 	 */
39257c478bd9Sstevel@tonic-gate 	leaky_cleanup(1);
39267c478bd9Sstevel@tonic-gate }
3927