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