10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51580Sjwadams  * Common Development and Distribution License (the "License").
61580Sjwadams  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
225839Sdmick  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <mdb/mdb_param.h>
270Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
280Sstevel@tonic-gate #include <mdb/mdb_ks.h>
290Sstevel@tonic-gate #include <mdb/mdb_ctf.h>
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/thread.h>
330Sstevel@tonic-gate #include <sys/session.h>
340Sstevel@tonic-gate #include <sys/user.h>
350Sstevel@tonic-gate #include <sys/proc.h>
360Sstevel@tonic-gate #include <sys/var.h>
370Sstevel@tonic-gate #include <sys/t_lock.h>
380Sstevel@tonic-gate #include <sys/callo.h>
390Sstevel@tonic-gate #include <sys/priocntl.h>
400Sstevel@tonic-gate #include <sys/class.h>
410Sstevel@tonic-gate #include <sys/regset.h>
420Sstevel@tonic-gate #include <sys/stack.h>
430Sstevel@tonic-gate #include <sys/cpuvar.h>
440Sstevel@tonic-gate #include <sys/vnode.h>
450Sstevel@tonic-gate #include <sys/vfs.h>
460Sstevel@tonic-gate #include <sys/flock_impl.h>
470Sstevel@tonic-gate #include <sys/kmem_impl.h>
480Sstevel@tonic-gate #include <sys/vmem_impl.h>
490Sstevel@tonic-gate #include <sys/kstat.h>
500Sstevel@tonic-gate #include <vm/seg_vn.h>
510Sstevel@tonic-gate #include <vm/anon.h>
520Sstevel@tonic-gate #include <vm/as.h>
530Sstevel@tonic-gate #include <vm/seg_map.h>
540Sstevel@tonic-gate #include <sys/dditypes.h>
550Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
560Sstevel@tonic-gate #include <sys/sysmacros.h>
570Sstevel@tonic-gate #include <sys/sysconf.h>
580Sstevel@tonic-gate #include <sys/task.h>
590Sstevel@tonic-gate #include <sys/project.h>
600Sstevel@tonic-gate #include <sys/taskq.h>
610Sstevel@tonic-gate #include <sys/taskq_impl.h>
620Sstevel@tonic-gate #include <sys/errorq_impl.h>
630Sstevel@tonic-gate #include <sys/cred_impl.h>
640Sstevel@tonic-gate #include <sys/zone.h>
650Sstevel@tonic-gate #include <sys/panic.h>
660Sstevel@tonic-gate #include <regex.h>
670Sstevel@tonic-gate #include <sys/port_impl.h>
680Sstevel@tonic-gate 
69789Sahrens #include "avl.h"
706712Stomee #include "combined.h"
710Sstevel@tonic-gate #include "contract.h"
720Sstevel@tonic-gate #include "cpupart_mdb.h"
730Sstevel@tonic-gate #include "devinfo.h"
740Sstevel@tonic-gate #include "leaky.h"
750Sstevel@tonic-gate #include "lgrp.h"
763434Sesaxe #include "pg.h"
773434Sesaxe #include "group.h"
780Sstevel@tonic-gate #include "list.h"
790Sstevel@tonic-gate #include "log.h"
800Sstevel@tonic-gate #include "kgrep.h"
810Sstevel@tonic-gate #include "kmem.h"
820Sstevel@tonic-gate #include "bio.h"
830Sstevel@tonic-gate #include "streams.h"
840Sstevel@tonic-gate #include "cyclic.h"
850Sstevel@tonic-gate #include "findstack.h"
860Sstevel@tonic-gate #include "ndievents.h"
870Sstevel@tonic-gate #include "mmd.h"
880Sstevel@tonic-gate #include "net.h"
893448Sdh155122 #include "netstack.h"
900Sstevel@tonic-gate #include "nvpair.h"
910Sstevel@tonic-gate #include "ctxop.h"
920Sstevel@tonic-gate #include "tsd.h"
930Sstevel@tonic-gate #include "thread.h"
940Sstevel@tonic-gate #include "memory.h"
950Sstevel@tonic-gate #include "sobj.h"
960Sstevel@tonic-gate #include "sysevent.h"
970Sstevel@tonic-gate #include "rctl.h"
981676Sjpk #include "tsol.h"
990Sstevel@tonic-gate #include "typegraph.h"
1000Sstevel@tonic-gate #include "ldi.h"
1010Sstevel@tonic-gate #include "vfs.h"
1020Sstevel@tonic-gate #include "zone.h"
1030Sstevel@tonic-gate #include "modhash.h"
1042577Sramat #include "mdi.h"
1053323Scindi #include "fm.h"
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate /*
1080Sstevel@tonic-gate  * Surely this is defined somewhere...
1090Sstevel@tonic-gate  */
1100Sstevel@tonic-gate #define	NINTR		16
1110Sstevel@tonic-gate 
1124808Sek110237 #define	KILOS		10
1134808Sek110237 #define	MEGS		20
1144808Sek110237 #define	GIGS		30
1154808Sek110237 
1160Sstevel@tonic-gate #ifndef STACK_BIAS
1170Sstevel@tonic-gate #define	STACK_BIAS	0
1180Sstevel@tonic-gate #endif
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate static char
1210Sstevel@tonic-gate pstat2ch(uchar_t state)
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate 	switch (state) {
1240Sstevel@tonic-gate 		case SSLEEP: return ('S');
1250Sstevel@tonic-gate 		case SRUN: return ('R');
1260Sstevel@tonic-gate 		case SZOMB: return ('Z');
1270Sstevel@tonic-gate 		case SIDL: return ('I');
1280Sstevel@tonic-gate 		case SONPROC: return ('O');
1290Sstevel@tonic-gate 		case SSTOP: return ('T');
1303792Sakolb 		case SWAIT: return ('W');
1310Sstevel@tonic-gate 		default: return ('?');
1320Sstevel@tonic-gate 	}
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate #define	PS_PRTTHREADS	0x1
1360Sstevel@tonic-gate #define	PS_PRTLWPS	0x2
1370Sstevel@tonic-gate #define	PS_PSARGS	0x4
1380Sstevel@tonic-gate #define	PS_TASKS	0x8
1390Sstevel@tonic-gate #define	PS_PROJECTS	0x10
1400Sstevel@tonic-gate #define	PS_ZONES	0x20
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate static int
1430Sstevel@tonic-gate ps_threadprint(uintptr_t addr, const void *data, void *private)
1440Sstevel@tonic-gate {
1450Sstevel@tonic-gate 	const kthread_t *t = (const kthread_t *)data;
1460Sstevel@tonic-gate 	uint_t prt_flags = *((uint_t *)private);
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 	static const mdb_bitmask_t t_state_bits[] = {
1490Sstevel@tonic-gate 		{ "TS_FREE",	UINT_MAX,	TS_FREE		},
1500Sstevel@tonic-gate 		{ "TS_SLEEP",	TS_SLEEP,	TS_SLEEP	},
1510Sstevel@tonic-gate 		{ "TS_RUN",	TS_RUN,		TS_RUN		},
1520Sstevel@tonic-gate 		{ "TS_ONPROC",	TS_ONPROC,	TS_ONPROC	},
1530Sstevel@tonic-gate 		{ "TS_ZOMB",	TS_ZOMB,	TS_ZOMB		},
1540Sstevel@tonic-gate 		{ "TS_STOPPED",	TS_STOPPED,	TS_STOPPED	},
1553792Sakolb 		{ "TS_WAIT",	TS_WAIT,	TS_WAIT		},
1560Sstevel@tonic-gate 		{ NULL,		0,		0		}
1570Sstevel@tonic-gate 	};
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	if (prt_flags & PS_PRTTHREADS)
1600Sstevel@tonic-gate 		mdb_printf("\tT  %?a <%b>\n", addr, t->t_state, t_state_bits);
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	if (prt_flags & PS_PRTLWPS)
1630Sstevel@tonic-gate 		mdb_printf("\tL  %?a ID: %u\n", t->t_lwp, t->t_tid);
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	return (WALK_NEXT);
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate int
1690Sstevel@tonic-gate ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1700Sstevel@tonic-gate {
1710Sstevel@tonic-gate 	uint_t prt_flags = 0;
1720Sstevel@tonic-gate 	proc_t pr;
1730Sstevel@tonic-gate 	struct pid pid, pgid, sid;
1740Sstevel@tonic-gate 	sess_t session;
1750Sstevel@tonic-gate 	cred_t cred;
1760Sstevel@tonic-gate 	task_t tk;
1770Sstevel@tonic-gate 	kproject_t pj;
1780Sstevel@tonic-gate 	zone_t zn;
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
1810Sstevel@tonic-gate 		if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) {
1820Sstevel@tonic-gate 			mdb_warn("can't walk 'proc'");
1830Sstevel@tonic-gate 			return (DCMD_ERR);
1840Sstevel@tonic-gate 		}
1850Sstevel@tonic-gate 		return (DCMD_OK);
1860Sstevel@tonic-gate 	}
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
1890Sstevel@tonic-gate 	    'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags,
1900Sstevel@tonic-gate 	    'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags,
1910Sstevel@tonic-gate 	    'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags,
1920Sstevel@tonic-gate 	    'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags,
1930Sstevel@tonic-gate 	    'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags,
1940Sstevel@tonic-gate 	    't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc)
1950Sstevel@tonic-gate 		return (DCMD_USAGE);
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
1980Sstevel@tonic-gate 		mdb_printf("%<u>%1s %6s %6s %6s %6s ",
1990Sstevel@tonic-gate 		    "S", "PID", "PPID", "PGID", "SID");
2000Sstevel@tonic-gate 		if (prt_flags & PS_TASKS)
2010Sstevel@tonic-gate 			mdb_printf("%5s ", "TASK");
2020Sstevel@tonic-gate 		if (prt_flags & PS_PROJECTS)
2030Sstevel@tonic-gate 			mdb_printf("%5s ", "PROJ");
2040Sstevel@tonic-gate 		if (prt_flags & PS_ZONES)
2050Sstevel@tonic-gate 			mdb_printf("%5s ", "ZONE");
2060Sstevel@tonic-gate 		mdb_printf("%6s %10s %?s %s%</u>\n",
2070Sstevel@tonic-gate 		    "UID", "FLAGS", "ADDR", "NAME");
2080Sstevel@tonic-gate 	}
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate 	mdb_vread(&pr, sizeof (pr), addr);
2110Sstevel@tonic-gate 	mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp);
2120Sstevel@tonic-gate 	mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp);
2130Sstevel@tonic-gate 	mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred);
2140Sstevel@tonic-gate 	mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp);
2150Sstevel@tonic-gate 	mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp);
2160Sstevel@tonic-gate 	if (prt_flags & (PS_TASKS | PS_PROJECTS))
2170Sstevel@tonic-gate 		mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task);
2180Sstevel@tonic-gate 	if (prt_flags & PS_PROJECTS)
2190Sstevel@tonic-gate 		mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj);
2200Sstevel@tonic-gate 	if (prt_flags & PS_ZONES)
2210Sstevel@tonic-gate 		mdb_vread(&zn, sizeof (zone_t), (uintptr_t)pr.p_zone);
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate 	mdb_printf("%c %6d %6d %6d %6d ",
2240Sstevel@tonic-gate 	    pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id,
2250Sstevel@tonic-gate 	    sid.pid_id);
2260Sstevel@tonic-gate 	if (prt_flags & PS_TASKS)
2270Sstevel@tonic-gate 		mdb_printf("%5d ", tk.tk_tkid);
2280Sstevel@tonic-gate 	if (prt_flags & PS_PROJECTS)
2290Sstevel@tonic-gate 		mdb_printf("%5d ", pj.kpj_id);
2300Sstevel@tonic-gate 	if (prt_flags & PS_ZONES)
2310Sstevel@tonic-gate 		mdb_printf("%5d ", zn.zone_id);
2320Sstevel@tonic-gate 	mdb_printf("%6d 0x%08x %0?p %s\n",
2330Sstevel@tonic-gate 	    cred.cr_uid, pr.p_flag, addr,
2340Sstevel@tonic-gate 	    (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm);
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate 	if (prt_flags & ~PS_PSARGS)
2370Sstevel@tonic-gate 		(void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr);
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate 	return (DCMD_OK);
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate #define	PG_NEWEST	0x0001
2430Sstevel@tonic-gate #define	PG_OLDEST	0x0002
2440Sstevel@tonic-gate #define	PG_PIPE_OUT	0x0004
2451014Svb160487 #define	PG_EXACT_MATCH	0x0008
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate typedef struct pgrep_data {
2480Sstevel@tonic-gate 	uint_t pg_flags;
2490Sstevel@tonic-gate 	uint_t pg_psflags;
2500Sstevel@tonic-gate 	uintptr_t pg_xaddr;
2510Sstevel@tonic-gate 	hrtime_t pg_xstart;
2520Sstevel@tonic-gate 	const char *pg_pat;
2530Sstevel@tonic-gate #ifndef _KMDB
2540Sstevel@tonic-gate 	regex_t pg_reg;
2550Sstevel@tonic-gate #endif
2560Sstevel@tonic-gate } pgrep_data_t;
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate /*ARGSUSED*/
2590Sstevel@tonic-gate static int
2600Sstevel@tonic-gate pgrep_cb(uintptr_t addr, const void *pdata, void *data)
2610Sstevel@tonic-gate {
2620Sstevel@tonic-gate 	const proc_t *prp = pdata;
2630Sstevel@tonic-gate 	pgrep_data_t *pgp = data;
2640Sstevel@tonic-gate #ifndef _KMDB
2650Sstevel@tonic-gate 	regmatch_t pmatch;
2660Sstevel@tonic-gate #endif
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate 	/*
2690Sstevel@tonic-gate 	 * kmdb doesn't have access to the reg* functions, so we fall back
2701014Svb160487 	 * to strstr/strcmp.
2710Sstevel@tonic-gate 	 */
2720Sstevel@tonic-gate #ifdef _KMDB
2731014Svb160487 	if ((pgp->pg_flags & PG_EXACT_MATCH) ?
2741014Svb160487 	    (strcmp(prp->p_user.u_comm, pgp->pg_pat) != 0) :
2751014Svb160487 	    (strstr(prp->p_user.u_comm, pgp->pg_pat) == NULL))
2760Sstevel@tonic-gate 		return (WALK_NEXT);
2770Sstevel@tonic-gate #else
2780Sstevel@tonic-gate 	if (regexec(&pgp->pg_reg, prp->p_user.u_comm, 1, &pmatch, 0) != 0)
2790Sstevel@tonic-gate 		return (WALK_NEXT);
2801014Svb160487 
2811014Svb160487 	if ((pgp->pg_flags & PG_EXACT_MATCH) &&
2821014Svb160487 	    (pmatch.rm_so != 0 || prp->p_user.u_comm[pmatch.rm_eo] != '\0'))
2831014Svb160487 		return (WALK_NEXT);
2840Sstevel@tonic-gate #endif
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate 	if (pgp->pg_flags & (PG_NEWEST | PG_OLDEST)) {
2870Sstevel@tonic-gate 		hrtime_t start;
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 		start = (hrtime_t)prp->p_user.u_start.tv_sec * NANOSEC +
2900Sstevel@tonic-gate 		    prp->p_user.u_start.tv_nsec;
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate 		if (pgp->pg_flags & PG_NEWEST) {
2930Sstevel@tonic-gate 			if (pgp->pg_xaddr == NULL || start > pgp->pg_xstart) {
2940Sstevel@tonic-gate 				pgp->pg_xaddr = addr;
2950Sstevel@tonic-gate 				pgp->pg_xstart = start;
2960Sstevel@tonic-gate 			}
2970Sstevel@tonic-gate 		} else {
2980Sstevel@tonic-gate 			if (pgp->pg_xaddr == NULL || start < pgp->pg_xstart) {
2990Sstevel@tonic-gate 				pgp->pg_xaddr = addr;
3000Sstevel@tonic-gate 				pgp->pg_xstart = start;
3010Sstevel@tonic-gate 			}
3020Sstevel@tonic-gate 		}
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate 	} else if (pgp->pg_flags & PG_PIPE_OUT) {
3050Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate 	} else {
3080Sstevel@tonic-gate 		if (mdb_call_dcmd("ps", addr, pgp->pg_psflags, 0, NULL) != 0) {
3090Sstevel@tonic-gate 			mdb_warn("can't invoke 'ps'");
3100Sstevel@tonic-gate 			return (WALK_DONE);
3110Sstevel@tonic-gate 		}
3120Sstevel@tonic-gate 		pgp->pg_psflags &= ~DCMD_LOOPFIRST;
3130Sstevel@tonic-gate 	}
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate 	return (WALK_NEXT);
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate /*ARGSUSED*/
3190Sstevel@tonic-gate int
3200Sstevel@tonic-gate pgrep(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3210Sstevel@tonic-gate {
3220Sstevel@tonic-gate 	pgrep_data_t pg;
3230Sstevel@tonic-gate 	int i;
3240Sstevel@tonic-gate #ifndef _KMDB
3250Sstevel@tonic-gate 	int err;
3260Sstevel@tonic-gate #endif
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
3290Sstevel@tonic-gate 		return (DCMD_USAGE);
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate 	pg.pg_flags = 0;
3320Sstevel@tonic-gate 	pg.pg_xaddr = 0;
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate 	i = mdb_getopts(argc, argv,
3350Sstevel@tonic-gate 	    'n', MDB_OPT_SETBITS, PG_NEWEST, &pg.pg_flags,
3360Sstevel@tonic-gate 	    'o', MDB_OPT_SETBITS, PG_OLDEST, &pg.pg_flags,
3371014Svb160487 	    'x', MDB_OPT_SETBITS, PG_EXACT_MATCH, &pg.pg_flags,
3380Sstevel@tonic-gate 	    NULL);
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate 	argc -= i;
3410Sstevel@tonic-gate 	argv += i;
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	if (argc != 1)
3440Sstevel@tonic-gate 		return (DCMD_USAGE);
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate 	/*
3470Sstevel@tonic-gate 	 * -n and -o are mutually exclusive.
3480Sstevel@tonic-gate 	 */
3490Sstevel@tonic-gate 	if ((pg.pg_flags & PG_NEWEST) && (pg.pg_flags & PG_OLDEST))
3500Sstevel@tonic-gate 		return (DCMD_USAGE);
3510Sstevel@tonic-gate 
3520Sstevel@tonic-gate 	if (argv->a_type != MDB_TYPE_STRING)
3530Sstevel@tonic-gate 		return (DCMD_USAGE);
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	if (flags & DCMD_PIPE_OUT)
3560Sstevel@tonic-gate 		pg.pg_flags |= PG_PIPE_OUT;
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 	pg.pg_pat = argv->a_un.a_str;
3590Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
3600Sstevel@tonic-gate 		pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP | DCMD_LOOPFIRST;
3610Sstevel@tonic-gate 	else
3620Sstevel@tonic-gate 		pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP;
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate #ifndef _KMDB
3650Sstevel@tonic-gate 	if ((err = regcomp(&pg.pg_reg, pg.pg_pat, REG_EXTENDED)) != 0) {
3660Sstevel@tonic-gate 		size_t nbytes;
3670Sstevel@tonic-gate 		char *buf;
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 		nbytes = regerror(err, &pg.pg_reg, NULL, 0);
3700Sstevel@tonic-gate 		buf = mdb_alloc(nbytes + 1, UM_SLEEP | UM_GC);
3710Sstevel@tonic-gate 		(void) regerror(err, &pg.pg_reg, buf, nbytes);
3720Sstevel@tonic-gate 		mdb_warn("%s\n", buf);
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate 		return (DCMD_ERR);
3750Sstevel@tonic-gate 	}
3760Sstevel@tonic-gate #endif
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate 	if (mdb_walk("proc", pgrep_cb, &pg) != 0) {
3790Sstevel@tonic-gate 		mdb_warn("can't walk 'proc'");
3800Sstevel@tonic-gate 		return (DCMD_ERR);
3810Sstevel@tonic-gate 	}
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate 	if (pg.pg_xaddr != 0 && (pg.pg_flags & (PG_NEWEST | PG_OLDEST))) {
3840Sstevel@tonic-gate 		if (pg.pg_flags & PG_PIPE_OUT) {
3850Sstevel@tonic-gate 			mdb_printf("%p\n", pg.pg_xaddr);
3860Sstevel@tonic-gate 		} else {
3870Sstevel@tonic-gate 			if (mdb_call_dcmd("ps", pg.pg_xaddr, pg.pg_psflags,
3880Sstevel@tonic-gate 			    0, NULL) != 0) {
3890Sstevel@tonic-gate 				mdb_warn("can't invoke 'ps'");
3900Sstevel@tonic-gate 				return (DCMD_ERR);
3910Sstevel@tonic-gate 			}
3920Sstevel@tonic-gate 		}
3930Sstevel@tonic-gate 	}
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate 	return (DCMD_OK);
3960Sstevel@tonic-gate }
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate int
3990Sstevel@tonic-gate task(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4000Sstevel@tonic-gate {
4010Sstevel@tonic-gate 	task_t tk;
4020Sstevel@tonic-gate 	kproject_t pj;
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
4050Sstevel@tonic-gate 		if (mdb_walk_dcmd("task_cache", "task", argc, argv) == -1) {
4060Sstevel@tonic-gate 			mdb_warn("can't walk task_cache");
4070Sstevel@tonic-gate 			return (DCMD_ERR);
4080Sstevel@tonic-gate 		}
4090Sstevel@tonic-gate 		return (DCMD_OK);
4100Sstevel@tonic-gate 	}
4110Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
4120Sstevel@tonic-gate 		mdb_printf("%<u>%?s %6s %6s %6s %6s %10s%</u>\n",
4130Sstevel@tonic-gate 		    "ADDR", "TASKID", "PROJID", "ZONEID", "REFCNT", "FLAGS");
4140Sstevel@tonic-gate 	}
4150Sstevel@tonic-gate 	if (mdb_vread(&tk, sizeof (task_t), addr) == -1) {
4160Sstevel@tonic-gate 		mdb_warn("can't read task_t structure at %p", addr);
4170Sstevel@tonic-gate 		return (DCMD_ERR);
4180Sstevel@tonic-gate 	}
4190Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), (uintptr_t)tk.tk_proj) == -1) {
4200Sstevel@tonic-gate 		mdb_warn("can't read project_t structure at %p", addr);
4210Sstevel@tonic-gate 		return (DCMD_ERR);
4220Sstevel@tonic-gate 	}
4230Sstevel@tonic-gate 	mdb_printf("%0?p %6d %6d %6d %6u 0x%08x\n",
4240Sstevel@tonic-gate 	    addr, tk.tk_tkid, pj.kpj_id, pj.kpj_zoneid, tk.tk_hold_count,
4250Sstevel@tonic-gate 	    tk.tk_flags);
4260Sstevel@tonic-gate 	return (DCMD_OK);
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate 
4290Sstevel@tonic-gate int
4300Sstevel@tonic-gate project(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4310Sstevel@tonic-gate {
4320Sstevel@tonic-gate 	kproject_t pj;
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
4350Sstevel@tonic-gate 		if (mdb_walk_dcmd("projects", "project", argc, argv) == -1) {
4360Sstevel@tonic-gate 			mdb_warn("can't walk projects");
4370Sstevel@tonic-gate 			return (DCMD_ERR);
4380Sstevel@tonic-gate 		}
4390Sstevel@tonic-gate 		return (DCMD_OK);
4400Sstevel@tonic-gate 	}
4410Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
4420Sstevel@tonic-gate 		mdb_printf("%<u>%?s %6s %6s %6s%</u>\n",
4430Sstevel@tonic-gate 		    "ADDR", "PROJID", "ZONEID", "REFCNT");
4440Sstevel@tonic-gate 	}
4450Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
4460Sstevel@tonic-gate 		mdb_warn("can't read kproject_t structure at %p", addr);
4470Sstevel@tonic-gate 		return (DCMD_ERR);
4480Sstevel@tonic-gate 	}
4490Sstevel@tonic-gate 	mdb_printf("%0?p %6d %6d %6u\n", addr, pj.kpj_id, pj.kpj_zoneid,
4500Sstevel@tonic-gate 	    pj.kpj_count);
4510Sstevel@tonic-gate 	return (DCMD_OK);
4520Sstevel@tonic-gate }
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate /*ARGSUSED*/
4550Sstevel@tonic-gate int
4560Sstevel@tonic-gate callout(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4570Sstevel@tonic-gate {
4580Sstevel@tonic-gate 	callout_table_t	*co_ktable[CALLOUT_TABLES];
4590Sstevel@tonic-gate 	int co_kfanout;
4600Sstevel@tonic-gate 	callout_table_t co_table;
4610Sstevel@tonic-gate 	callout_t co_callout;
4620Sstevel@tonic-gate 	callout_t *co_ptr;
4630Sstevel@tonic-gate 	int co_id;
4640Sstevel@tonic-gate 	clock_t lbolt;
4650Sstevel@tonic-gate 	int i, j, k;
4660Sstevel@tonic-gate 	const char *lbolt_sym;
4675084Sjohnlev 	uintptr_t panicstr;
4680Sstevel@tonic-gate 
4690Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) || argc != 0)
4700Sstevel@tonic-gate 		return (DCMD_USAGE);
4710Sstevel@tonic-gate 
4725084Sjohnlev 	if (mdb_readvar(&panicstr, "panicstr") == -1 ||
4735084Sjohnlev 	    panicstr == NULL) {
4745084Sjohnlev 		lbolt_sym = "lbolt";
4755084Sjohnlev 	} else {
4760Sstevel@tonic-gate 		lbolt_sym = "panic_lbolt";
4775084Sjohnlev 	}
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate 	if (mdb_readvar(&lbolt, lbolt_sym) == -1) {
4800Sstevel@tonic-gate 		mdb_warn("failed to read '%s'", lbolt_sym);
4810Sstevel@tonic-gate 		return (DCMD_ERR);
4820Sstevel@tonic-gate 	}
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate 	if (mdb_readvar(&co_kfanout, "callout_fanout") == -1) {
4850Sstevel@tonic-gate 		mdb_warn("failed to read callout_fanout");
4860Sstevel@tonic-gate 		return (DCMD_ERR);
4870Sstevel@tonic-gate 	}
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate 	if (mdb_readvar(&co_ktable, "callout_table") == -1) {
4900Sstevel@tonic-gate 		mdb_warn("failed to read callout_table");
4910Sstevel@tonic-gate 		return (DCMD_ERR);
4920Sstevel@tonic-gate 	}
4930Sstevel@tonic-gate 
4940Sstevel@tonic-gate 	mdb_printf("%<u>%-24s %-?s %-?s %-?s%</u>\n",
4950Sstevel@tonic-gate 	    "FUNCTION", "ARGUMENT", "ID", "TIME");
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate 	for (i = 0; i < CALLOUT_NTYPES; i++) {
4980Sstevel@tonic-gate 		for (j = 0; j < co_kfanout; j++) {
4990Sstevel@tonic-gate 
5000Sstevel@tonic-gate 			co_id = CALLOUT_TABLE(i, j);
5010Sstevel@tonic-gate 
5020Sstevel@tonic-gate 			if (mdb_vread(&co_table, sizeof (co_table),
5030Sstevel@tonic-gate 			    (uintptr_t)co_ktable[co_id]) == -1) {
5040Sstevel@tonic-gate 				mdb_warn("failed to read table at %p",
5050Sstevel@tonic-gate 				    (uintptr_t)co_ktable[co_id]);
5060Sstevel@tonic-gate 				continue;
5070Sstevel@tonic-gate 			}
5080Sstevel@tonic-gate 
5090Sstevel@tonic-gate 			for (k = 0; k < CALLOUT_BUCKETS; k++) {
5100Sstevel@tonic-gate 				co_ptr = co_table.ct_idhash[k];
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate 				while (co_ptr != NULL) {
5130Sstevel@tonic-gate 					mdb_vread(&co_callout,
5140Sstevel@tonic-gate 					    sizeof (co_callout),
5150Sstevel@tonic-gate 					    (uintptr_t)co_ptr);
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate 					mdb_printf("%-24a %0?p %0?lx %?lx "
5180Sstevel@tonic-gate 					    "(T%+ld)\n", co_callout.c_func,
5190Sstevel@tonic-gate 					    co_callout.c_arg, co_callout.c_xid,
5200Sstevel@tonic-gate 					    co_callout.c_runtime,
5210Sstevel@tonic-gate 					    co_callout.c_runtime - lbolt);
5220Sstevel@tonic-gate 
5230Sstevel@tonic-gate 					co_ptr = co_callout.c_idnext;
5240Sstevel@tonic-gate 				}
5250Sstevel@tonic-gate 			}
5260Sstevel@tonic-gate 		}
5270Sstevel@tonic-gate 	}
5280Sstevel@tonic-gate 
5290Sstevel@tonic-gate 	return (DCMD_OK);
5300Sstevel@tonic-gate }
5310Sstevel@tonic-gate 
5320Sstevel@tonic-gate /*ARGSUSED*/
5330Sstevel@tonic-gate int
5340Sstevel@tonic-gate class(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5350Sstevel@tonic-gate {
5360Sstevel@tonic-gate 	long num_classes, i;
5370Sstevel@tonic-gate 	sclass_t *class_tbl;
5380Sstevel@tonic-gate 	GElf_Sym g_sclass;
5390Sstevel@tonic-gate 	char class_name[PC_CLNMSZ];
5400Sstevel@tonic-gate 	size_t tbl_size;
5410Sstevel@tonic-gate 
5420Sstevel@tonic-gate 	if (mdb_lookup_by_name("sclass", &g_sclass) == -1) {
5430Sstevel@tonic-gate 		mdb_warn("failed to find symbol sclass\n");
5440Sstevel@tonic-gate 		return (DCMD_ERR);
5450Sstevel@tonic-gate 	}
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate 	tbl_size = (size_t)g_sclass.st_size;
5480Sstevel@tonic-gate 	num_classes = tbl_size / (sizeof (sclass_t));
5490Sstevel@tonic-gate 	class_tbl = mdb_alloc(tbl_size, UM_SLEEP | UM_GC);
5500Sstevel@tonic-gate 
5510Sstevel@tonic-gate 	if (mdb_readsym(class_tbl, tbl_size, "sclass") == -1) {
5520Sstevel@tonic-gate 		mdb_warn("failed to read sclass");
5530Sstevel@tonic-gate 		return (DCMD_ERR);
5540Sstevel@tonic-gate 	}
5550Sstevel@tonic-gate 
5560Sstevel@tonic-gate 	mdb_printf("%<u>%4s %-10s %-24s %-24s%</u>\n", "SLOT", "NAME",
5570Sstevel@tonic-gate 	    "INIT FCN", "CLASS FCN");
5580Sstevel@tonic-gate 
5590Sstevel@tonic-gate 	for (i = 0; i < num_classes; i++) {
5600Sstevel@tonic-gate 		if (mdb_vread(class_name, sizeof (class_name),
5610Sstevel@tonic-gate 		    (uintptr_t)class_tbl[i].cl_name) == -1)
5620Sstevel@tonic-gate 			(void) strcpy(class_name, "???");
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate 		mdb_printf("%4ld %-10s %-24a %-24a\n", i, class_name,
5650Sstevel@tonic-gate 		    class_tbl[i].cl_init, class_tbl[i].cl_funcs);
5660Sstevel@tonic-gate 	}
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate 	return (DCMD_OK);
5690Sstevel@tonic-gate }
5700Sstevel@tonic-gate 
5710Sstevel@tonic-gate #define	FSNAMELEN	32	/* Max len of FS name we read from vnodeops */
5720Sstevel@tonic-gate 
5730Sstevel@tonic-gate int
5740Sstevel@tonic-gate vnode2path(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5750Sstevel@tonic-gate {
5760Sstevel@tonic-gate 	uintptr_t rootdir;
5770Sstevel@tonic-gate 	vnode_t vn;
5780Sstevel@tonic-gate 	char buf[MAXPATHLEN];
5790Sstevel@tonic-gate 
5800Sstevel@tonic-gate 	uint_t opt_F = FALSE;
5810Sstevel@tonic-gate 
5820Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
5830Sstevel@tonic-gate 	    'F', MDB_OPT_SETBITS, TRUE, &opt_F, NULL) != argc)
5840Sstevel@tonic-gate 		return (DCMD_USAGE);
5850Sstevel@tonic-gate 
5860Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
5870Sstevel@tonic-gate 		mdb_warn("expected explicit vnode_t address before ::\n");
5880Sstevel@tonic-gate 		return (DCMD_USAGE);
5890Sstevel@tonic-gate 	}
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate 	if (mdb_readvar(&rootdir, "rootdir") == -1) {
5920Sstevel@tonic-gate 		mdb_warn("failed to read rootdir");
5930Sstevel@tonic-gate 		return (DCMD_ERR);
5940Sstevel@tonic-gate 	}
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate 	if (mdb_vnode2path(addr, buf, sizeof (buf)) == -1)
5970Sstevel@tonic-gate 		return (DCMD_ERR);
5980Sstevel@tonic-gate 
5990Sstevel@tonic-gate 	if (*buf == '\0') {
6000Sstevel@tonic-gate 		mdb_printf("??\n");
6010Sstevel@tonic-gate 		return (DCMD_OK);
6020Sstevel@tonic-gate 	}
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate 	mdb_printf("%s", buf);
6050Sstevel@tonic-gate 	if (opt_F && buf[strlen(buf)-1] != '/' &&
6060Sstevel@tonic-gate 	    mdb_vread(&vn, sizeof (vn), addr) == sizeof (vn))
6070Sstevel@tonic-gate 		mdb_printf("%c", mdb_vtype2chr(vn.v_type, 0));
6080Sstevel@tonic-gate 	mdb_printf("\n");
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate 	return (DCMD_OK);
6110Sstevel@tonic-gate }
6120Sstevel@tonic-gate 
6130Sstevel@tonic-gate int
6140Sstevel@tonic-gate ld_walk_init(mdb_walk_state_t *wsp)
6150Sstevel@tonic-gate {
6160Sstevel@tonic-gate 	wsp->walk_data = (void *)wsp->walk_addr;
6170Sstevel@tonic-gate 	return (WALK_NEXT);
6180Sstevel@tonic-gate }
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate int
6210Sstevel@tonic-gate ld_walk_step(mdb_walk_state_t *wsp)
6220Sstevel@tonic-gate {
6230Sstevel@tonic-gate 	int status;
6240Sstevel@tonic-gate 	lock_descriptor_t ld;
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate 	if (mdb_vread(&ld, sizeof (lock_descriptor_t), wsp->walk_addr) == -1) {
6270Sstevel@tonic-gate 		mdb_warn("couldn't read lock_descriptor_t at %p\n",
6280Sstevel@tonic-gate 		    wsp->walk_addr);
6290Sstevel@tonic-gate 		return (WALK_ERR);
6300Sstevel@tonic-gate 	}
6310Sstevel@tonic-gate 
6320Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, &ld, wsp->walk_cbdata);
6330Sstevel@tonic-gate 	if (status == WALK_ERR)
6340Sstevel@tonic-gate 		return (WALK_ERR);
6350Sstevel@tonic-gate 
6360Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)ld.l_next;
6370Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data)
6380Sstevel@tonic-gate 		return (WALK_DONE);
6390Sstevel@tonic-gate 
6400Sstevel@tonic-gate 	return (status);
6410Sstevel@tonic-gate }
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate int
6440Sstevel@tonic-gate lg_walk_init(mdb_walk_state_t *wsp)
6450Sstevel@tonic-gate {
6460Sstevel@tonic-gate 	GElf_Sym sym;
6470Sstevel@tonic-gate 
6480Sstevel@tonic-gate 	if (mdb_lookup_by_name("lock_graph", &sym) == -1) {
6490Sstevel@tonic-gate 		mdb_warn("failed to find symbol 'lock_graph'\n");
6500Sstevel@tonic-gate 		return (WALK_ERR);
6510Sstevel@tonic-gate 	}
6520Sstevel@tonic-gate 
6530Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)sym.st_value;
654436Sdmick 	wsp->walk_data = (void *)(uintptr_t)(sym.st_value + sym.st_size);
6550Sstevel@tonic-gate 
6560Sstevel@tonic-gate 	return (WALK_NEXT);
6570Sstevel@tonic-gate }
6580Sstevel@tonic-gate 
6590Sstevel@tonic-gate typedef struct lg_walk_data {
6600Sstevel@tonic-gate 	uintptr_t startaddr;
6610Sstevel@tonic-gate 	mdb_walk_cb_t callback;
6620Sstevel@tonic-gate 	void *data;
6630Sstevel@tonic-gate } lg_walk_data_t;
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate /*
6660Sstevel@tonic-gate  * We can't use ::walk lock_descriptor directly, because the head of each graph
6670Sstevel@tonic-gate  * is really a dummy lock.  Rather than trying to dynamically determine if this
6680Sstevel@tonic-gate  * is a dummy node or not, we just filter out the initial element of the
6690Sstevel@tonic-gate  * list.
6700Sstevel@tonic-gate  */
6710Sstevel@tonic-gate static int
6720Sstevel@tonic-gate lg_walk_cb(uintptr_t addr, const void *data, void *priv)
6730Sstevel@tonic-gate {
6740Sstevel@tonic-gate 	lg_walk_data_t *lw = priv;
6750Sstevel@tonic-gate 
6760Sstevel@tonic-gate 	if (addr != lw->startaddr)
6770Sstevel@tonic-gate 		return (lw->callback(addr, data, lw->data));
6780Sstevel@tonic-gate 
6790Sstevel@tonic-gate 	return (WALK_NEXT);
6800Sstevel@tonic-gate }
6810Sstevel@tonic-gate 
6820Sstevel@tonic-gate int
6830Sstevel@tonic-gate lg_walk_step(mdb_walk_state_t *wsp)
6840Sstevel@tonic-gate {
6850Sstevel@tonic-gate 	graph_t *graph;
6860Sstevel@tonic-gate 	lg_walk_data_t lw;
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate 	if (wsp->walk_addr >= (uintptr_t)wsp->walk_data)
6890Sstevel@tonic-gate 		return (WALK_DONE);
6900Sstevel@tonic-gate 
6910Sstevel@tonic-gate 	if (mdb_vread(&graph, sizeof (graph), wsp->walk_addr) == -1) {
6920Sstevel@tonic-gate 		mdb_warn("failed to read graph_t at %p", wsp->walk_addr);
6930Sstevel@tonic-gate 		return (WALK_ERR);
6940Sstevel@tonic-gate 	}
6950Sstevel@tonic-gate 
6960Sstevel@tonic-gate 	wsp->walk_addr += sizeof (graph);
6970Sstevel@tonic-gate 
6980Sstevel@tonic-gate 	if (graph == NULL)
6990Sstevel@tonic-gate 		return (WALK_NEXT);
7000Sstevel@tonic-gate 
7010Sstevel@tonic-gate 	lw.callback = wsp->walk_callback;
7020Sstevel@tonic-gate 	lw.data = wsp->walk_cbdata;
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate 	lw.startaddr = (uintptr_t)&(graph->active_locks);
7050Sstevel@tonic-gate 	if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
7060Sstevel@tonic-gate 		mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
7070Sstevel@tonic-gate 		return (WALK_ERR);
7080Sstevel@tonic-gate 	}
7090Sstevel@tonic-gate 
7100Sstevel@tonic-gate 	lw.startaddr = (uintptr_t)&(graph->sleeping_locks);
7110Sstevel@tonic-gate 	if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
7120Sstevel@tonic-gate 		mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
7130Sstevel@tonic-gate 		return (WALK_ERR);
7140Sstevel@tonic-gate 	}
7150Sstevel@tonic-gate 
7160Sstevel@tonic-gate 	return (WALK_NEXT);
7170Sstevel@tonic-gate }
7180Sstevel@tonic-gate 
7190Sstevel@tonic-gate /*
7200Sstevel@tonic-gate  * The space available for the path corresponding to the locked vnode depends
7210Sstevel@tonic-gate  * on whether we are printing 32- or 64-bit addresses.
7220Sstevel@tonic-gate  */
7230Sstevel@tonic-gate #ifdef _LP64
7240Sstevel@tonic-gate #define	LM_VNPATHLEN	20
7250Sstevel@tonic-gate #else
7260Sstevel@tonic-gate #define	LM_VNPATHLEN	30
7270Sstevel@tonic-gate #endif
7280Sstevel@tonic-gate 
7290Sstevel@tonic-gate /*ARGSUSED*/
7300Sstevel@tonic-gate static int
7310Sstevel@tonic-gate lminfo_cb(uintptr_t addr, const void *data, void *priv)
7320Sstevel@tonic-gate {
7330Sstevel@tonic-gate 	const lock_descriptor_t *ld = data;
7340Sstevel@tonic-gate 	char buf[LM_VNPATHLEN];
7350Sstevel@tonic-gate 	proc_t p;
7360Sstevel@tonic-gate 
7370Sstevel@tonic-gate 	mdb_printf("%-?p %2s %04x %6d %-16s %-?p ",
7380Sstevel@tonic-gate 	    addr, ld->l_type == F_RDLCK ? "RD" :
7390Sstevel@tonic-gate 	    ld->l_type == F_WRLCK ? "WR" : "??",
7400Sstevel@tonic-gate 	    ld->l_state, ld->l_flock.l_pid,
7410Sstevel@tonic-gate 	    ld->l_flock.l_pid == 0 ? "<kernel>" :
7420Sstevel@tonic-gate 	    mdb_pid2proc(ld->l_flock.l_pid, &p) == NULL ?
7430Sstevel@tonic-gate 	    "<defunct>" : p.p_user.u_comm,
7440Sstevel@tonic-gate 	    ld->l_vnode);
7450Sstevel@tonic-gate 
7460Sstevel@tonic-gate 	mdb_vnode2path((uintptr_t)ld->l_vnode, buf,
7470Sstevel@tonic-gate 	    sizeof (buf));
7480Sstevel@tonic-gate 	mdb_printf("%s\n", buf);
7490Sstevel@tonic-gate 
7500Sstevel@tonic-gate 	return (WALK_NEXT);
7510Sstevel@tonic-gate }
7520Sstevel@tonic-gate 
7530Sstevel@tonic-gate /*ARGSUSED*/
7540Sstevel@tonic-gate int
7550Sstevel@tonic-gate lminfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7560Sstevel@tonic-gate {
7570Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
7580Sstevel@tonic-gate 		mdb_printf("%<u>%-?s %2s %4s %6s %-16s %-?s %s%</u>\n",
7590Sstevel@tonic-gate 		    "ADDR", "TP", "FLAG", "PID", "COMM", "VNODE", "PATH");
7600Sstevel@tonic-gate 
7610Sstevel@tonic-gate 	return (mdb_pwalk("lock_graph", lminfo_cb, NULL, NULL));
7620Sstevel@tonic-gate }
7630Sstevel@tonic-gate 
7640Sstevel@tonic-gate /*ARGSUSED*/
7650Sstevel@tonic-gate int
7660Sstevel@tonic-gate seg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7670Sstevel@tonic-gate {
7680Sstevel@tonic-gate 	struct seg s;
7690Sstevel@tonic-gate 
7700Sstevel@tonic-gate 	if (argc != 0)
7710Sstevel@tonic-gate 		return (DCMD_USAGE);
7720Sstevel@tonic-gate 
7730Sstevel@tonic-gate 	if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
7740Sstevel@tonic-gate 		mdb_printf("%<u>%?s %?s %?s %?s %s%</u>\n",
7750Sstevel@tonic-gate 		    "SEG", "BASE", "SIZE", "DATA", "OPS");
7760Sstevel@tonic-gate 	}
7770Sstevel@tonic-gate 
7780Sstevel@tonic-gate 	if (mdb_vread(&s, sizeof (s), addr) == -1) {
7790Sstevel@tonic-gate 		mdb_warn("failed to read seg at %p", addr);
7800Sstevel@tonic-gate 		return (DCMD_ERR);
7810Sstevel@tonic-gate 	}
7820Sstevel@tonic-gate 
7830Sstevel@tonic-gate 	mdb_printf("%?p %?p %?lx %?p %a\n",
7840Sstevel@tonic-gate 	    addr, s.s_base, s.s_size, s.s_data, s.s_ops);
7850Sstevel@tonic-gate 
7860Sstevel@tonic-gate 	return (DCMD_OK);
7870Sstevel@tonic-gate }
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate /*ARGSUSED*/
7900Sstevel@tonic-gate static int
7910Sstevel@tonic-gate pmap_walk_anon(uintptr_t addr, const struct anon *anon, int *nres)
7920Sstevel@tonic-gate {
7930Sstevel@tonic-gate 	uintptr_t pp =
7940Sstevel@tonic-gate 	    mdb_vnode2page((uintptr_t)anon->an_vp, (uintptr_t)anon->an_off);
7950Sstevel@tonic-gate 
7960Sstevel@tonic-gate 	if (pp != NULL)
7970Sstevel@tonic-gate 		(*nres)++;
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate 	return (WALK_NEXT);
8000Sstevel@tonic-gate }
8010Sstevel@tonic-gate 
8020Sstevel@tonic-gate static int
8030Sstevel@tonic-gate pmap_walk_seg(uintptr_t addr, const struct seg *seg, uintptr_t segvn)
8040Sstevel@tonic-gate {
8050Sstevel@tonic-gate 
8060Sstevel@tonic-gate 	mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024);
8070Sstevel@tonic-gate 
8080Sstevel@tonic-gate 	if (segvn == (uintptr_t)seg->s_ops) {
8090Sstevel@tonic-gate 		struct segvn_data svn;
8100Sstevel@tonic-gate 		int nres = 0;
8110Sstevel@tonic-gate 
8120Sstevel@tonic-gate 		(void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data);
8130Sstevel@tonic-gate 
8140Sstevel@tonic-gate 		if (svn.amp == NULL) {
8150Sstevel@tonic-gate 			mdb_printf(" %8s", "");
8160Sstevel@tonic-gate 			goto drive_on;
8170Sstevel@tonic-gate 		}
8180Sstevel@tonic-gate 
8190Sstevel@tonic-gate 		/*
8200Sstevel@tonic-gate 		 * We've got an amp for this segment; walk through
8210Sstevel@tonic-gate 		 * the amp, and determine mappings.
8220Sstevel@tonic-gate 		 */
8230Sstevel@tonic-gate 		if (mdb_pwalk("anon", (mdb_walk_cb_t)pmap_walk_anon,
8240Sstevel@tonic-gate 		    &nres, (uintptr_t)svn.amp) == -1)
8250Sstevel@tonic-gate 			mdb_warn("failed to walk anon (amp=%p)", svn.amp);
8260Sstevel@tonic-gate 
8270Sstevel@tonic-gate 		mdb_printf(" %7dk", (nres * PAGESIZE) / 1024);
8280Sstevel@tonic-gate drive_on:
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate 		if (svn.vp != NULL) {
8310Sstevel@tonic-gate 			char buf[29];
8320Sstevel@tonic-gate 
8330Sstevel@tonic-gate 			mdb_vnode2path((uintptr_t)svn.vp, buf, sizeof (buf));
8340Sstevel@tonic-gate 			mdb_printf(" %s", buf);
8350Sstevel@tonic-gate 		} else
8360Sstevel@tonic-gate 			mdb_printf(" [ anon ]");
8370Sstevel@tonic-gate 	}
8380Sstevel@tonic-gate 
8390Sstevel@tonic-gate 	mdb_printf("\n");
8400Sstevel@tonic-gate 	return (WALK_NEXT);
8410Sstevel@tonic-gate }
8420Sstevel@tonic-gate 
8430Sstevel@tonic-gate static int
8440Sstevel@tonic-gate pmap_walk_seg_quick(uintptr_t addr, const struct seg *seg, uintptr_t segvn)
8450Sstevel@tonic-gate {
8460Sstevel@tonic-gate 	mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024);
8470Sstevel@tonic-gate 
8480Sstevel@tonic-gate 	if (segvn == (uintptr_t)seg->s_ops) {
8490Sstevel@tonic-gate 		struct segvn_data svn;
8500Sstevel@tonic-gate 
8510Sstevel@tonic-gate 		(void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data);
8520Sstevel@tonic-gate 
8530Sstevel@tonic-gate 		if (svn.vp != NULL) {
8540Sstevel@tonic-gate 			mdb_printf(" %0?p", svn.vp);
8550Sstevel@tonic-gate 		} else {
8560Sstevel@tonic-gate 			mdb_printf(" [ anon ]");
8570Sstevel@tonic-gate 		}
8580Sstevel@tonic-gate 	}
8590Sstevel@tonic-gate 
8600Sstevel@tonic-gate 	mdb_printf("\n");
8610Sstevel@tonic-gate 	return (WALK_NEXT);
8620Sstevel@tonic-gate }
8630Sstevel@tonic-gate 
8640Sstevel@tonic-gate /*ARGSUSED*/
8650Sstevel@tonic-gate int
8660Sstevel@tonic-gate pmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
8670Sstevel@tonic-gate {
8680Sstevel@tonic-gate 	uintptr_t segvn;
8690Sstevel@tonic-gate 	proc_t proc;
8700Sstevel@tonic-gate 	uint_t quick = FALSE;
8710Sstevel@tonic-gate 	mdb_walk_cb_t cb = (mdb_walk_cb_t)pmap_walk_seg;
8720Sstevel@tonic-gate 
8730Sstevel@tonic-gate 	GElf_Sym sym;
8740Sstevel@tonic-gate 
8750Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
8760Sstevel@tonic-gate 		return (DCMD_USAGE);
8770Sstevel@tonic-gate 
8780Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
8790Sstevel@tonic-gate 	    'q', MDB_OPT_SETBITS, TRUE, &quick, NULL) != argc)
8800Sstevel@tonic-gate 		return (DCMD_USAGE);
8810Sstevel@tonic-gate 
8820Sstevel@tonic-gate 	if (mdb_vread(&proc, sizeof (proc), addr) == -1) {
8830Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", addr);
8840Sstevel@tonic-gate 		return (DCMD_ERR);
8850Sstevel@tonic-gate 	}
8860Sstevel@tonic-gate 
8870Sstevel@tonic-gate 	if (mdb_lookup_by_name("segvn_ops", &sym) == 0)
8880Sstevel@tonic-gate 		segvn = (uintptr_t)sym.st_value;
8890Sstevel@tonic-gate 	else
8900Sstevel@tonic-gate 		segvn = NULL;
8910Sstevel@tonic-gate 
8920Sstevel@tonic-gate 	mdb_printf("%?s %?s %8s ", "SEG", "BASE", "SIZE");
8930Sstevel@tonic-gate 
8940Sstevel@tonic-gate 	if (quick) {
8950Sstevel@tonic-gate 		mdb_printf("VNODE\n");
8960Sstevel@tonic-gate 		cb = (mdb_walk_cb_t)pmap_walk_seg_quick;
8970Sstevel@tonic-gate 	} else {
8980Sstevel@tonic-gate 		mdb_printf("%8s %s\n", "RES", "PATH");
8990Sstevel@tonic-gate 	}
9000Sstevel@tonic-gate 
9010Sstevel@tonic-gate 	if (mdb_pwalk("seg", cb, (void *)segvn, (uintptr_t)proc.p_as) == -1) {
9020Sstevel@tonic-gate 		mdb_warn("failed to walk segments of as %p", proc.p_as);
9030Sstevel@tonic-gate 		return (DCMD_ERR);
9040Sstevel@tonic-gate 	}
9050Sstevel@tonic-gate 
9060Sstevel@tonic-gate 	return (DCMD_OK);
9070Sstevel@tonic-gate }
9080Sstevel@tonic-gate 
9090Sstevel@tonic-gate typedef struct anon_walk_data {
9100Sstevel@tonic-gate 	uintptr_t *aw_levone;
9110Sstevel@tonic-gate 	uintptr_t *aw_levtwo;
9120Sstevel@tonic-gate 	int aw_nlevone;
9130Sstevel@tonic-gate 	int aw_levone_ndx;
9140Sstevel@tonic-gate 	int aw_levtwo_ndx;
9150Sstevel@tonic-gate 	struct anon_map aw_amp;
9160Sstevel@tonic-gate 	struct anon_hdr aw_ahp;
9170Sstevel@tonic-gate } anon_walk_data_t;
9180Sstevel@tonic-gate 
9190Sstevel@tonic-gate int
9200Sstevel@tonic-gate anon_walk_init(mdb_walk_state_t *wsp)
9210Sstevel@tonic-gate {
9220Sstevel@tonic-gate 	anon_walk_data_t *aw;
9230Sstevel@tonic-gate 
9240Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
9250Sstevel@tonic-gate 		mdb_warn("anon walk doesn't support global walks\n");
9260Sstevel@tonic-gate 		return (WALK_ERR);
9270Sstevel@tonic-gate 	}
9280Sstevel@tonic-gate 
9290Sstevel@tonic-gate 	aw = mdb_alloc(sizeof (anon_walk_data_t), UM_SLEEP);
9300Sstevel@tonic-gate 
9310Sstevel@tonic-gate 	if (mdb_vread(&aw->aw_amp, sizeof (aw->aw_amp), wsp->walk_addr) == -1) {
9320Sstevel@tonic-gate 		mdb_warn("failed to read anon map at %p", wsp->walk_addr);
9330Sstevel@tonic-gate 		mdb_free(aw, sizeof (anon_walk_data_t));
9340Sstevel@tonic-gate 		return (WALK_ERR);
9350Sstevel@tonic-gate 	}
9360Sstevel@tonic-gate 
9370Sstevel@tonic-gate 	if (mdb_vread(&aw->aw_ahp, sizeof (aw->aw_ahp),
9380Sstevel@tonic-gate 	    (uintptr_t)(aw->aw_amp.ahp)) == -1) {
9390Sstevel@tonic-gate 		mdb_warn("failed to read anon hdr ptr at %p", aw->aw_amp.ahp);
9400Sstevel@tonic-gate 		mdb_free(aw, sizeof (anon_walk_data_t));
9410Sstevel@tonic-gate 		return (WALK_ERR);
9420Sstevel@tonic-gate 	}
9430Sstevel@tonic-gate 
9440Sstevel@tonic-gate 	if (aw->aw_ahp.size <= ANON_CHUNK_SIZE ||
9450Sstevel@tonic-gate 	    (aw->aw_ahp.flags & ANON_ALLOC_FORCE)) {
9460Sstevel@tonic-gate 		aw->aw_nlevone = aw->aw_ahp.size;
9470Sstevel@tonic-gate 		aw->aw_levtwo = NULL;
9480Sstevel@tonic-gate 	} else {
9490Sstevel@tonic-gate 		aw->aw_nlevone =
9500Sstevel@tonic-gate 		    (aw->aw_ahp.size + ANON_CHUNK_OFF) >> ANON_CHUNK_SHIFT;
9510Sstevel@tonic-gate 		aw->aw_levtwo =
9520Sstevel@tonic-gate 		    mdb_zalloc(ANON_CHUNK_SIZE * sizeof (uintptr_t), UM_SLEEP);
9530Sstevel@tonic-gate 	}
9540Sstevel@tonic-gate 
9550Sstevel@tonic-gate 	aw->aw_levone =
9560Sstevel@tonic-gate 	    mdb_alloc(aw->aw_nlevone * sizeof (uintptr_t), UM_SLEEP);
9570Sstevel@tonic-gate 
9580Sstevel@tonic-gate 	aw->aw_levone_ndx = 0;
9590Sstevel@tonic-gate 	aw->aw_levtwo_ndx = 0;
9600Sstevel@tonic-gate 
9610Sstevel@tonic-gate 	mdb_vread(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t),
9620Sstevel@tonic-gate 	    (uintptr_t)aw->aw_ahp.array_chunk);
9630Sstevel@tonic-gate 
9640Sstevel@tonic-gate 	if (aw->aw_levtwo != NULL) {
9650Sstevel@tonic-gate 		while (aw->aw_levone[aw->aw_levone_ndx] == NULL) {
9660Sstevel@tonic-gate 			aw->aw_levone_ndx++;
9670Sstevel@tonic-gate 			if (aw->aw_levone_ndx == aw->aw_nlevone) {
9680Sstevel@tonic-gate 				mdb_warn("corrupt anon; couldn't"
9690Sstevel@tonic-gate 				    "find ptr to lev two map");
9700Sstevel@tonic-gate 				goto out;
9710Sstevel@tonic-gate 			}
9720Sstevel@tonic-gate 		}
9730Sstevel@tonic-gate 
9740Sstevel@tonic-gate 		mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t),
9750Sstevel@tonic-gate 		    aw->aw_levone[aw->aw_levone_ndx]);
9760Sstevel@tonic-gate 	}
9770Sstevel@tonic-gate 
9780Sstevel@tonic-gate out:
9790Sstevel@tonic-gate 	wsp->walk_data = aw;
9800Sstevel@tonic-gate 	return (0);
9810Sstevel@tonic-gate }
9820Sstevel@tonic-gate 
9830Sstevel@tonic-gate int
9840Sstevel@tonic-gate anon_walk_step(mdb_walk_state_t *wsp)
9850Sstevel@tonic-gate {
9860Sstevel@tonic-gate 	int status;
9870Sstevel@tonic-gate 	anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data;
9880Sstevel@tonic-gate 	struct anon anon;
9890Sstevel@tonic-gate 	uintptr_t anonptr;
9900Sstevel@tonic-gate 
9910Sstevel@tonic-gate again:
9920Sstevel@tonic-gate 	/*
9930Sstevel@tonic-gate 	 * Once we've walked through level one, we're done.
9940Sstevel@tonic-gate 	 */
9950Sstevel@tonic-gate 	if (aw->aw_levone_ndx == aw->aw_nlevone)
9960Sstevel@tonic-gate 		return (WALK_DONE);
9970Sstevel@tonic-gate 
9980Sstevel@tonic-gate 	if (aw->aw_levtwo == NULL) {
9990Sstevel@tonic-gate 		anonptr = aw->aw_levone[aw->aw_levone_ndx];
10000Sstevel@tonic-gate 		aw->aw_levone_ndx++;
10010Sstevel@tonic-gate 	} else {
10020Sstevel@tonic-gate 		anonptr = aw->aw_levtwo[aw->aw_levtwo_ndx];
10030Sstevel@tonic-gate 		aw->aw_levtwo_ndx++;
10040Sstevel@tonic-gate 
10050Sstevel@tonic-gate 		if (aw->aw_levtwo_ndx == ANON_CHUNK_SIZE) {
10060Sstevel@tonic-gate 			aw->aw_levtwo_ndx = 0;
10070Sstevel@tonic-gate 
10080Sstevel@tonic-gate 			do {
10090Sstevel@tonic-gate 				aw->aw_levone_ndx++;
10100Sstevel@tonic-gate 
10110Sstevel@tonic-gate 				if (aw->aw_levone_ndx == aw->aw_nlevone)
10120Sstevel@tonic-gate 					return (WALK_DONE);
10130Sstevel@tonic-gate 			} while (aw->aw_levone[aw->aw_levone_ndx] == NULL);
10140Sstevel@tonic-gate 
10150Sstevel@tonic-gate 			mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE *
10160Sstevel@tonic-gate 			    sizeof (uintptr_t),
10170Sstevel@tonic-gate 			    aw->aw_levone[aw->aw_levone_ndx]);
10180Sstevel@tonic-gate 		}
10190Sstevel@tonic-gate 	}
10200Sstevel@tonic-gate 
10210Sstevel@tonic-gate 	if (anonptr != NULL) {
10220Sstevel@tonic-gate 		mdb_vread(&anon, sizeof (anon), anonptr);
10230Sstevel@tonic-gate 		status = wsp->walk_callback(anonptr, &anon, wsp->walk_cbdata);
10240Sstevel@tonic-gate 	} else
10250Sstevel@tonic-gate 		goto again;
10260Sstevel@tonic-gate 
10270Sstevel@tonic-gate 	return (status);
10280Sstevel@tonic-gate }
10290Sstevel@tonic-gate 
10300Sstevel@tonic-gate void
10310Sstevel@tonic-gate anon_walk_fini(mdb_walk_state_t *wsp)
10320Sstevel@tonic-gate {
10330Sstevel@tonic-gate 	anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data;
10340Sstevel@tonic-gate 
10350Sstevel@tonic-gate 	if (aw->aw_levtwo != NULL)
10360Sstevel@tonic-gate 		mdb_free(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t));
10370Sstevel@tonic-gate 
10380Sstevel@tonic-gate 	mdb_free(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t));
10390Sstevel@tonic-gate 	mdb_free(aw, sizeof (anon_walk_data_t));
10400Sstevel@tonic-gate }
10410Sstevel@tonic-gate 
10420Sstevel@tonic-gate /*ARGSUSED*/
10430Sstevel@tonic-gate int
10440Sstevel@tonic-gate whereopen_fwalk(uintptr_t addr, struct file *f, uintptr_t *target)
10450Sstevel@tonic-gate {
10460Sstevel@tonic-gate 	if ((uintptr_t)f->f_vnode == *target) {
10470Sstevel@tonic-gate 		mdb_printf("file %p\n", addr);
10480Sstevel@tonic-gate 		*target = NULL;
10490Sstevel@tonic-gate 	}
10500Sstevel@tonic-gate 
10510Sstevel@tonic-gate 	return (WALK_NEXT);
10520Sstevel@tonic-gate }
10530Sstevel@tonic-gate 
10540Sstevel@tonic-gate /*ARGSUSED*/
10550Sstevel@tonic-gate int
10560Sstevel@tonic-gate whereopen_pwalk(uintptr_t addr, void *ignored, uintptr_t *target)
10570Sstevel@tonic-gate {
10580Sstevel@tonic-gate 	uintptr_t t = *target;
10590Sstevel@tonic-gate 
10600Sstevel@tonic-gate 	if (mdb_pwalk("file", (mdb_walk_cb_t)whereopen_fwalk, &t, addr) == -1) {
10610Sstevel@tonic-gate 		mdb_warn("couldn't file walk proc %p", addr);
10620Sstevel@tonic-gate 		return (WALK_ERR);
10630Sstevel@tonic-gate 	}
10640Sstevel@tonic-gate 
10650Sstevel@tonic-gate 	if (t == NULL)
10660Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
10670Sstevel@tonic-gate 
10680Sstevel@tonic-gate 	return (WALK_NEXT);
10690Sstevel@tonic-gate }
10700Sstevel@tonic-gate 
10710Sstevel@tonic-gate /*ARGSUSED*/
10720Sstevel@tonic-gate int
10730Sstevel@tonic-gate whereopen(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
10740Sstevel@tonic-gate {
10750Sstevel@tonic-gate 	uintptr_t target = addr;
10760Sstevel@tonic-gate 
10770Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC) || addr == NULL)
10780Sstevel@tonic-gate 		return (DCMD_USAGE);
10790Sstevel@tonic-gate 
10800Sstevel@tonic-gate 	if (mdb_walk("proc", (mdb_walk_cb_t)whereopen_pwalk, &target) == -1) {
10810Sstevel@tonic-gate 		mdb_warn("can't proc walk");
10820Sstevel@tonic-gate 		return (DCMD_ERR);
10830Sstevel@tonic-gate 	}
10840Sstevel@tonic-gate 
10850Sstevel@tonic-gate 	return (DCMD_OK);
10860Sstevel@tonic-gate }
10870Sstevel@tonic-gate 
10880Sstevel@tonic-gate typedef struct datafmt {
10890Sstevel@tonic-gate 	char	*hdr1;
10900Sstevel@tonic-gate 	char	*hdr2;
10910Sstevel@tonic-gate 	char	*dashes;
10920Sstevel@tonic-gate 	char	*fmt;
10930Sstevel@tonic-gate } datafmt_t;
10940Sstevel@tonic-gate 
10950Sstevel@tonic-gate static datafmt_t kmemfmt[] = {
10960Sstevel@tonic-gate 	{ "cache                    ", "name                     ",
10970Sstevel@tonic-gate 	"-------------------------", "%-25s "				},
10980Sstevel@tonic-gate 	{ "   buf",	"  size",	"------",	"%6u "		},
10990Sstevel@tonic-gate 	{ "   buf",	"in use",	"------",	"%6u "		},
11000Sstevel@tonic-gate 	{ "   buf",	" total",	"------",	"%6u "		},
11014808Sek110237 	{ "   memory",	"   in use",	"----------",	"%9u%c "	},
11020Sstevel@tonic-gate 	{ "    alloc",	"  succeed",	"---------",	"%9u "		},
11030Sstevel@tonic-gate 	{ "alloc",	" fail",	"-----",	"%5u "		},
11040Sstevel@tonic-gate 	{ NULL,		NULL,		NULL,		NULL		}
11050Sstevel@tonic-gate };
11060Sstevel@tonic-gate 
11070Sstevel@tonic-gate static datafmt_t vmemfmt[] = {
11080Sstevel@tonic-gate 	{ "vmem                     ", "name                     ",
11090Sstevel@tonic-gate 	"-------------------------", "%-*s "				},
11104808Sek110237 	{ "   memory",	"   in use",	"----------",	"%9llu%c "	},
11114808Sek110237 	{ "    memory",	"     total",	"-----------",	"%10llu%c "	},
11124808Sek110237 	{ "   memory",	"   import",	"----------",	"%9llu%c "	},
11130Sstevel@tonic-gate 	{ "    alloc",	"  succeed",	"---------",	"%9llu "	},
11140Sstevel@tonic-gate 	{ "alloc",	" fail",	"-----",	"%5llu "	},
11150Sstevel@tonic-gate 	{ NULL,		NULL,		NULL,		NULL		}
11160Sstevel@tonic-gate };
11170Sstevel@tonic-gate 
11180Sstevel@tonic-gate /*ARGSUSED*/
11190Sstevel@tonic-gate static int
11200Sstevel@tonic-gate kmastat_cpu_avail(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *avail)
11210Sstevel@tonic-gate {
11220Sstevel@tonic-gate 	if (ccp->cc_rounds > 0)
11230Sstevel@tonic-gate 		*avail += ccp->cc_rounds;
11240Sstevel@tonic-gate 	if (ccp->cc_prounds > 0)
11250Sstevel@tonic-gate 		*avail += ccp->cc_prounds;
11260Sstevel@tonic-gate 
11270Sstevel@tonic-gate 	return (WALK_NEXT);
11280Sstevel@tonic-gate }
11290Sstevel@tonic-gate 
11300Sstevel@tonic-gate /*ARGSUSED*/
11310Sstevel@tonic-gate static int
11320Sstevel@tonic-gate kmastat_cpu_alloc(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *alloc)
11330Sstevel@tonic-gate {
11340Sstevel@tonic-gate 	*alloc += ccp->cc_alloc;
11350Sstevel@tonic-gate 
11360Sstevel@tonic-gate 	return (WALK_NEXT);
11370Sstevel@tonic-gate }
11380Sstevel@tonic-gate 
11390Sstevel@tonic-gate /*ARGSUSED*/
11400Sstevel@tonic-gate static int
11410Sstevel@tonic-gate kmastat_slab_avail(uintptr_t addr, const kmem_slab_t *sp, int *avail)
11420Sstevel@tonic-gate {
11430Sstevel@tonic-gate 	*avail += sp->slab_chunks - sp->slab_refcnt;
11440Sstevel@tonic-gate 
11450Sstevel@tonic-gate 	return (WALK_NEXT);
11460Sstevel@tonic-gate }
11470Sstevel@tonic-gate 
11480Sstevel@tonic-gate typedef struct kmastat_vmem {
11490Sstevel@tonic-gate 	uintptr_t kv_addr;
11500Sstevel@tonic-gate 	struct kmastat_vmem *kv_next;
11510Sstevel@tonic-gate 	int kv_meminuse;
11520Sstevel@tonic-gate 	int kv_alloc;
11530Sstevel@tonic-gate 	int kv_fail;
11540Sstevel@tonic-gate } kmastat_vmem_t;
11550Sstevel@tonic-gate 
11563095Sek110237 typedef struct kmastat_args {
11573095Sek110237 	kmastat_vmem_t **ka_kvpp;
11583095Sek110237 	uint_t ka_shift;
11593095Sek110237 } kmastat_args_t;
11603095Sek110237 
11610Sstevel@tonic-gate static int
11623095Sek110237 kmastat_cache(uintptr_t addr, const kmem_cache_t *cp, kmastat_args_t *kap)
11630Sstevel@tonic-gate {
11643095Sek110237 	kmastat_vmem_t **kvp = kap->ka_kvpp;
11650Sstevel@tonic-gate 	kmastat_vmem_t *kv;
11660Sstevel@tonic-gate 	datafmt_t *dfp = kmemfmt;
11670Sstevel@tonic-gate 	int magsize;
11680Sstevel@tonic-gate 
11690Sstevel@tonic-gate 	int avail, alloc, total;
11700Sstevel@tonic-gate 	size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) *
11710Sstevel@tonic-gate 	    cp->cache_slabsize;
11720Sstevel@tonic-gate 
11730Sstevel@tonic-gate 	mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)kmastat_cpu_avail;
11740Sstevel@tonic-gate 	mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)kmastat_cpu_alloc;
11750Sstevel@tonic-gate 	mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)kmastat_slab_avail;
11760Sstevel@tonic-gate 
11770Sstevel@tonic-gate 	magsize = kmem_get_magsize(cp);
11780Sstevel@tonic-gate 
11790Sstevel@tonic-gate 	alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc;
11800Sstevel@tonic-gate 	avail = cp->cache_full.ml_total * magsize;
11810Sstevel@tonic-gate 	total = cp->cache_buftotal;
11820Sstevel@tonic-gate 
11830Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_cpu_cache", cpu_alloc, &alloc, addr);
11840Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_cpu_cache", cpu_avail, &avail, addr);
11850Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_slab_partial", slab_avail, &avail, addr);
11860Sstevel@tonic-gate 
11870Sstevel@tonic-gate 	for (kv = *kvp; kv != NULL; kv = kv->kv_next) {
11880Sstevel@tonic-gate 		if (kv->kv_addr == (uintptr_t)cp->cache_arena)
11890Sstevel@tonic-gate 			goto out;
11900Sstevel@tonic-gate 	}
11910Sstevel@tonic-gate 
11920Sstevel@tonic-gate 	kv = mdb_zalloc(sizeof (kmastat_vmem_t), UM_SLEEP | UM_GC);
11930Sstevel@tonic-gate 	kv->kv_next = *kvp;
11940Sstevel@tonic-gate 	kv->kv_addr = (uintptr_t)cp->cache_arena;
11950Sstevel@tonic-gate 	*kvp = kv;
11960Sstevel@tonic-gate out:
11970Sstevel@tonic-gate 	kv->kv_meminuse += meminuse;
11980Sstevel@tonic-gate 	kv->kv_alloc += alloc;
11990Sstevel@tonic-gate 	kv->kv_fail += cp->cache_alloc_fail;
12000Sstevel@tonic-gate 
12010Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_name);
12020Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_bufsize);
12030Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, total - avail);
12040Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, total);
12054808Sek110237 	mdb_printf((dfp++)->fmt, meminuse >> kap->ka_shift,
12064808Sek110237 	    kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' :
12074808Sek110237 	    kap->ka_shift == KILOS ? 'K' : 'B');
12080Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, alloc);
12090Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_alloc_fail);
12100Sstevel@tonic-gate 	mdb_printf("\n");
12110Sstevel@tonic-gate 
12120Sstevel@tonic-gate 	return (WALK_NEXT);
12130Sstevel@tonic-gate }
12140Sstevel@tonic-gate 
12150Sstevel@tonic-gate static int
12163095Sek110237 kmastat_vmem_totals(uintptr_t addr, const vmem_t *v, kmastat_args_t *kap)
12170Sstevel@tonic-gate {
12183095Sek110237 	kmastat_vmem_t *kv = *kap->ka_kvpp;
12190Sstevel@tonic-gate 	size_t len;
12200Sstevel@tonic-gate 
12210Sstevel@tonic-gate 	while (kv != NULL && kv->kv_addr != addr)
12220Sstevel@tonic-gate 		kv = kv->kv_next;
12230Sstevel@tonic-gate 
12240Sstevel@tonic-gate 	if (kv == NULL || kv->kv_alloc == 0)
12250Sstevel@tonic-gate 		return (WALK_NEXT);
12260Sstevel@tonic-gate 
12270Sstevel@tonic-gate 	len = MIN(17, strlen(v->vm_name));
12280Sstevel@tonic-gate 
12294808Sek110237 	mdb_printf("Total [%s]%*s %6s %6s %6s %9u%c %9u %5u\n", v->vm_name,
12300Sstevel@tonic-gate 	    17 - len, "", "", "", "",
12314808Sek110237 	    kv->kv_meminuse >> kap->ka_shift,
12324808Sek110237 	    kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' :
12334808Sek110237 	    kap->ka_shift == KILOS ? 'K' : 'B', kv->kv_alloc, kv->kv_fail);
12340Sstevel@tonic-gate 
12350Sstevel@tonic-gate 	return (WALK_NEXT);
12360Sstevel@tonic-gate }
12370Sstevel@tonic-gate 
12380Sstevel@tonic-gate /*ARGSUSED*/
12390Sstevel@tonic-gate static int
12403095Sek110237 kmastat_vmem(uintptr_t addr, const vmem_t *v, const uint_t *shiftp)
12410Sstevel@tonic-gate {
12420Sstevel@tonic-gate 	datafmt_t *dfp = vmemfmt;
12430Sstevel@tonic-gate 	const vmem_kstat_t *vkp = &v->vm_kstat;
12440Sstevel@tonic-gate 	uintptr_t paddr;
12450Sstevel@tonic-gate 	vmem_t parent;
12460Sstevel@tonic-gate 	int ident = 0;
12470Sstevel@tonic-gate 
12480Sstevel@tonic-gate 	for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) {
12490Sstevel@tonic-gate 		if (mdb_vread(&parent, sizeof (parent), paddr) == -1) {
12500Sstevel@tonic-gate 			mdb_warn("couldn't trace %p's ancestry", addr);
12510Sstevel@tonic-gate 			ident = 0;
12520Sstevel@tonic-gate 			break;
12530Sstevel@tonic-gate 		}
12540Sstevel@tonic-gate 		paddr = (uintptr_t)parent.vm_source;
12550Sstevel@tonic-gate 	}
12560Sstevel@tonic-gate 
12570Sstevel@tonic-gate 	mdb_printf("%*s", ident, "");
12580Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name);
12594808Sek110237 	mdb_printf((dfp++)->fmt, vkp->vk_mem_inuse.value.ui64 >> *shiftp,
12604808Sek110237 	    *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
12614808Sek110237 	    *shiftp == KILOS ? 'K' : 'B');
12624808Sek110237 	mdb_printf((dfp++)->fmt, vkp->vk_mem_total.value.ui64 >> *shiftp,
12634808Sek110237 	    *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
12644808Sek110237 	    *shiftp == KILOS ? 'K' : 'B');
12654808Sek110237 	mdb_printf((dfp++)->fmt, vkp->vk_mem_import.value.ui64 >> *shiftp,
12664808Sek110237 	    *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
12674808Sek110237 	    *shiftp == KILOS ? 'K' : 'B');
12680Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_alloc.value.ui64);
12690Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_fail.value.ui64);
12700Sstevel@tonic-gate 
12710Sstevel@tonic-gate 	mdb_printf("\n");
12720Sstevel@tonic-gate 
12730Sstevel@tonic-gate 	return (WALK_NEXT);
12740Sstevel@tonic-gate }
12750Sstevel@tonic-gate 
12760Sstevel@tonic-gate /*ARGSUSED*/
12770Sstevel@tonic-gate int
12780Sstevel@tonic-gate kmastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
12790Sstevel@tonic-gate {
12800Sstevel@tonic-gate 	kmastat_vmem_t *kv = NULL;
12810Sstevel@tonic-gate 	datafmt_t *dfp;
12823095Sek110237 	kmastat_args_t ka;
12833095Sek110237 
12843095Sek110237 	ka.ka_shift = 0;
12853095Sek110237 	if (mdb_getopts(argc, argv,
12864808Sek110237 	    'k', MDB_OPT_SETBITS, KILOS, &ka.ka_shift,
12874808Sek110237 	    'm', MDB_OPT_SETBITS, MEGS, &ka.ka_shift,
12884808Sek110237 	    'g', MDB_OPT_SETBITS, GIGS, &ka.ka_shift, NULL) != argc)
12890Sstevel@tonic-gate 		return (DCMD_USAGE);
12900Sstevel@tonic-gate 
12910Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
12920Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr1);
12930Sstevel@tonic-gate 	mdb_printf("\n");
12940Sstevel@tonic-gate 
12950Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
12960Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr2);
12970Sstevel@tonic-gate 	mdb_printf("\n");
12980Sstevel@tonic-gate 
12990Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
13000Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
13010Sstevel@tonic-gate 	mdb_printf("\n");
13020Sstevel@tonic-gate 
13033095Sek110237 	ka.ka_kvpp = &kv;
13043095Sek110237 	if (mdb_walk("kmem_cache", (mdb_walk_cb_t)kmastat_cache, &ka) == -1) {
13050Sstevel@tonic-gate 		mdb_warn("can't walk 'kmem_cache'");
13060Sstevel@tonic-gate 		return (DCMD_ERR);
13070Sstevel@tonic-gate 	}
13080Sstevel@tonic-gate 
13090Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
13100Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
13110Sstevel@tonic-gate 	mdb_printf("\n");
13120Sstevel@tonic-gate 
13133095Sek110237 	if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem_totals, &ka) == -1) {
13140Sstevel@tonic-gate 		mdb_warn("can't walk 'vmem'");
13150Sstevel@tonic-gate 		return (DCMD_ERR);
13160Sstevel@tonic-gate 	}
13170Sstevel@tonic-gate 
13180Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
13190Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
13200Sstevel@tonic-gate 	mdb_printf("\n");
13210Sstevel@tonic-gate 
13220Sstevel@tonic-gate 	mdb_printf("\n");
13230Sstevel@tonic-gate 
13240Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
13250Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr1);
13260Sstevel@tonic-gate 	mdb_printf("\n");
13270Sstevel@tonic-gate 
13280Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
13290Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr2);
13300Sstevel@tonic-gate 	mdb_printf("\n");
13310Sstevel@tonic-gate 
13320Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
13330Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
13340Sstevel@tonic-gate 	mdb_printf("\n");
13350Sstevel@tonic-gate 
13363095Sek110237 	if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem, &ka.ka_shift) == -1) {
13370Sstevel@tonic-gate 		mdb_warn("can't walk 'vmem'");
13380Sstevel@tonic-gate 		return (DCMD_ERR);
13390Sstevel@tonic-gate 	}
13400Sstevel@tonic-gate 
13410Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
13420Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
13430Sstevel@tonic-gate 	mdb_printf("\n");
13440Sstevel@tonic-gate 	return (DCMD_OK);
13450Sstevel@tonic-gate }
13460Sstevel@tonic-gate 
13470Sstevel@tonic-gate /*
13480Sstevel@tonic-gate  * Our ::kgrep callback scans the entire kernel VA space (kas).  kas is made
13490Sstevel@tonic-gate  * up of a set of 'struct seg's.  We could just scan each seg en masse, but
13500Sstevel@tonic-gate  * unfortunately, a few of the segs are both large and sparse, so we could
13510Sstevel@tonic-gate  * spend quite a bit of time scanning VAs which have no backing pages.
13520Sstevel@tonic-gate  *
13530Sstevel@tonic-gate  * So for the few very sparse segs, we skip the segment itself, and scan
13540Sstevel@tonic-gate  * the allocated vmem_segs in the vmem arena which manages that part of kas.
13550Sstevel@tonic-gate  * Currently, we do this for:
13560Sstevel@tonic-gate  *
13570Sstevel@tonic-gate  *	SEG		VMEM ARENA
13580Sstevel@tonic-gate  *	kvseg		heap_arena
13590Sstevel@tonic-gate  *	kvseg32		heap32_arena
13600Sstevel@tonic-gate  *	kvseg_core	heap_core_arena
13610Sstevel@tonic-gate  *
13620Sstevel@tonic-gate  * In addition, we skip the segkpm segment in its entirety, since it is very
13630Sstevel@tonic-gate  * sparse, and contains no new kernel data.
13640Sstevel@tonic-gate  */
13650Sstevel@tonic-gate typedef struct kgrep_walk_data {
13660Sstevel@tonic-gate 	kgrep_cb_func *kg_cb;
13670Sstevel@tonic-gate 	void *kg_cbdata;
13680Sstevel@tonic-gate 	uintptr_t kg_kvseg;
13690Sstevel@tonic-gate 	uintptr_t kg_kvseg32;
13700Sstevel@tonic-gate 	uintptr_t kg_kvseg_core;
13710Sstevel@tonic-gate 	uintptr_t kg_segkpm;
13725Seg155566 	uintptr_t kg_heap_lp_base;
13735Seg155566 	uintptr_t kg_heap_lp_end;
13740Sstevel@tonic-gate } kgrep_walk_data_t;
13750Sstevel@tonic-gate 
13760Sstevel@tonic-gate static int
13770Sstevel@tonic-gate kgrep_walk_seg(uintptr_t addr, const struct seg *seg, kgrep_walk_data_t *kg)
13780Sstevel@tonic-gate {
13790Sstevel@tonic-gate 	uintptr_t base = (uintptr_t)seg->s_base;
13800Sstevel@tonic-gate 
13810Sstevel@tonic-gate 	if (addr == kg->kg_kvseg || addr == kg->kg_kvseg32 ||
13820Sstevel@tonic-gate 	    addr == kg->kg_kvseg_core)
13830Sstevel@tonic-gate 		return (WALK_NEXT);
13840Sstevel@tonic-gate 
13850Sstevel@tonic-gate 	if ((uintptr_t)seg->s_ops == kg->kg_segkpm)
13860Sstevel@tonic-gate 		return (WALK_NEXT);
13870Sstevel@tonic-gate 
13880Sstevel@tonic-gate 	return (kg->kg_cb(base, base + seg->s_size, kg->kg_cbdata));
13890Sstevel@tonic-gate }
13900Sstevel@tonic-gate 
13910Sstevel@tonic-gate /*ARGSUSED*/
13920Sstevel@tonic-gate static int
13930Sstevel@tonic-gate kgrep_walk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
13940Sstevel@tonic-gate {
13955Seg155566 	/*
13965Seg155566 	 * skip large page heap address range - it is scanned by walking
13975Seg155566 	 * allocated vmem_segs in the heap_lp_arena
13985Seg155566 	 */
13995Seg155566 	if (seg->vs_start == kg->kg_heap_lp_base &&
14005Seg155566 	    seg->vs_end == kg->kg_heap_lp_end)
14015Seg155566 		return (WALK_NEXT);
14025Seg155566 
14035Seg155566 	return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
14045Seg155566 }
14055Seg155566 
14065Seg155566 /*ARGSUSED*/
14075Seg155566 static int
14085Seg155566 kgrep_xwalk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
14095Seg155566 {
14100Sstevel@tonic-gate 	return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
14110Sstevel@tonic-gate }
14120Sstevel@tonic-gate 
14130Sstevel@tonic-gate static int
14140Sstevel@tonic-gate kgrep_walk_vmem(uintptr_t addr, const vmem_t *vmem, kgrep_walk_data_t *kg)
14150Sstevel@tonic-gate {
14165Seg155566 	mdb_walk_cb_t walk_vseg = (mdb_walk_cb_t)kgrep_walk_vseg;
14175Seg155566 
14180Sstevel@tonic-gate 	if (strcmp(vmem->vm_name, "heap") != 0 &&
14190Sstevel@tonic-gate 	    strcmp(vmem->vm_name, "heap32") != 0 &&
14205Seg155566 	    strcmp(vmem->vm_name, "heap_core") != 0 &&
14215Seg155566 	    strcmp(vmem->vm_name, "heap_lp") != 0)
14220Sstevel@tonic-gate 		return (WALK_NEXT);
14230Sstevel@tonic-gate 
14245Seg155566 	if (strcmp(vmem->vm_name, "heap_lp") == 0)
14255Seg155566 		walk_vseg = (mdb_walk_cb_t)kgrep_xwalk_vseg;
14265Seg155566 
14275Seg155566 	if (mdb_pwalk("vmem_alloc", walk_vseg, kg, addr) == -1) {
14280Sstevel@tonic-gate 		mdb_warn("couldn't walk vmem_alloc for vmem %p", addr);
14290Sstevel@tonic-gate 		return (WALK_ERR);
14300Sstevel@tonic-gate 	}
14310Sstevel@tonic-gate 
14320Sstevel@tonic-gate 	return (WALK_NEXT);
14330Sstevel@tonic-gate }
14340Sstevel@tonic-gate 
14350Sstevel@tonic-gate int
14360Sstevel@tonic-gate kgrep_subr(kgrep_cb_func *cb, void *cbdata)
14370Sstevel@tonic-gate {
14380Sstevel@tonic-gate 	GElf_Sym kas, kvseg, kvseg32, kvseg_core, segkpm;
14390Sstevel@tonic-gate 	kgrep_walk_data_t kg;
14400Sstevel@tonic-gate 
14410Sstevel@tonic-gate 	if (mdb_get_state() == MDB_STATE_RUNNING) {
14420Sstevel@tonic-gate 		mdb_warn("kgrep can only be run on a system "
14430Sstevel@tonic-gate 		    "dump or under kmdb; see dumpadm(1M)\n");
14440Sstevel@tonic-gate 		return (DCMD_ERR);
14450Sstevel@tonic-gate 	}
14460Sstevel@tonic-gate 
14470Sstevel@tonic-gate 	if (mdb_lookup_by_name("kas", &kas) == -1) {
14480Sstevel@tonic-gate 		mdb_warn("failed to locate 'kas' symbol\n");
14490Sstevel@tonic-gate 		return (DCMD_ERR);
14500Sstevel@tonic-gate 	}
14510Sstevel@tonic-gate 
14520Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg", &kvseg) == -1) {
14530Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg' symbol\n");
14540Sstevel@tonic-gate 		return (DCMD_ERR);
14550Sstevel@tonic-gate 	}
14560Sstevel@tonic-gate 
14570Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg32", &kvseg32) == -1) {
14580Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg32' symbol\n");
14590Sstevel@tonic-gate 		return (DCMD_ERR);
14600Sstevel@tonic-gate 	}
14610Sstevel@tonic-gate 
14620Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg_core", &kvseg_core) == -1) {
14630Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg_core' symbol\n");
14640Sstevel@tonic-gate 		return (DCMD_ERR);
14650Sstevel@tonic-gate 	}
14660Sstevel@tonic-gate 
14670Sstevel@tonic-gate 	if (mdb_lookup_by_name("segkpm_ops", &segkpm) == -1) {
14680Sstevel@tonic-gate 		mdb_warn("failed to locate 'segkpm_ops' symbol\n");
14690Sstevel@tonic-gate 		return (DCMD_ERR);
14700Sstevel@tonic-gate 	}
14710Sstevel@tonic-gate 
14725Seg155566 	if (mdb_readvar(&kg.kg_heap_lp_base, "heap_lp_base") == -1) {
14735Seg155566 		mdb_warn("failed to read 'heap_lp_base'\n");
14745Seg155566 		return (DCMD_ERR);
14755Seg155566 	}
14765Seg155566 
14775Seg155566 	if (mdb_readvar(&kg.kg_heap_lp_end, "heap_lp_end") == -1) {
14785Seg155566 		mdb_warn("failed to read 'heap_lp_end'\n");
14795Seg155566 		return (DCMD_ERR);
14805Seg155566 	}
14815Seg155566 
14820Sstevel@tonic-gate 	kg.kg_cb = cb;
14830Sstevel@tonic-gate 	kg.kg_cbdata = cbdata;
14840Sstevel@tonic-gate 	kg.kg_kvseg = (uintptr_t)kvseg.st_value;
14850Sstevel@tonic-gate 	kg.kg_kvseg32 = (uintptr_t)kvseg32.st_value;
14860Sstevel@tonic-gate 	kg.kg_kvseg_core = (uintptr_t)kvseg_core.st_value;
14870Sstevel@tonic-gate 	kg.kg_segkpm = (uintptr_t)segkpm.st_value;
14880Sstevel@tonic-gate 
14890Sstevel@tonic-gate 	if (mdb_pwalk("seg", (mdb_walk_cb_t)kgrep_walk_seg,
14900Sstevel@tonic-gate 	    &kg, kas.st_value) == -1) {
14910Sstevel@tonic-gate 		mdb_warn("failed to walk kas segments");
14920Sstevel@tonic-gate 		return (DCMD_ERR);
14930Sstevel@tonic-gate 	}
14940Sstevel@tonic-gate 
14950Sstevel@tonic-gate 	if (mdb_walk("vmem", (mdb_walk_cb_t)kgrep_walk_vmem, &kg) == -1) {
14960Sstevel@tonic-gate 		mdb_warn("failed to walk heap/heap32 vmem arenas");
14970Sstevel@tonic-gate 		return (DCMD_ERR);
14980Sstevel@tonic-gate 	}
14990Sstevel@tonic-gate 
15000Sstevel@tonic-gate 	return (DCMD_OK);
15010Sstevel@tonic-gate }
15020Sstevel@tonic-gate 
15030Sstevel@tonic-gate size_t
15040Sstevel@tonic-gate kgrep_subr_pagesize(void)
15050Sstevel@tonic-gate {
15060Sstevel@tonic-gate 	return (PAGESIZE);
15070Sstevel@tonic-gate }
15080Sstevel@tonic-gate 
15090Sstevel@tonic-gate typedef struct file_walk_data {
15100Sstevel@tonic-gate 	struct uf_entry *fw_flist;
15110Sstevel@tonic-gate 	int fw_flistsz;
15120Sstevel@tonic-gate 	int fw_ndx;
15130Sstevel@tonic-gate 	int fw_nofiles;
15140Sstevel@tonic-gate } file_walk_data_t;
15150Sstevel@tonic-gate 
15160Sstevel@tonic-gate int
15170Sstevel@tonic-gate file_walk_init(mdb_walk_state_t *wsp)
15180Sstevel@tonic-gate {
15190Sstevel@tonic-gate 	file_walk_data_t *fw;
15200Sstevel@tonic-gate 	proc_t p;
15210Sstevel@tonic-gate 
15220Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
15230Sstevel@tonic-gate 		mdb_warn("file walk doesn't support global walks\n");
15240Sstevel@tonic-gate 		return (WALK_ERR);
15250Sstevel@tonic-gate 	}
15260Sstevel@tonic-gate 
15270Sstevel@tonic-gate 	fw = mdb_alloc(sizeof (file_walk_data_t), UM_SLEEP);
15280Sstevel@tonic-gate 
15290Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (p), wsp->walk_addr) == -1) {
15300Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
15310Sstevel@tonic-gate 		mdb_warn("failed to read proc structure at %p", wsp->walk_addr);
15320Sstevel@tonic-gate 		return (WALK_ERR);
15330Sstevel@tonic-gate 	}
15340Sstevel@tonic-gate 
15350Sstevel@tonic-gate 	if (p.p_user.u_finfo.fi_nfiles == 0) {
15360Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
15370Sstevel@tonic-gate 		return (WALK_DONE);
15380Sstevel@tonic-gate 	}
15390Sstevel@tonic-gate 
15400Sstevel@tonic-gate 	fw->fw_nofiles = p.p_user.u_finfo.fi_nfiles;
15410Sstevel@tonic-gate 	fw->fw_flistsz = sizeof (struct uf_entry) * fw->fw_nofiles;
15420Sstevel@tonic-gate 	fw->fw_flist = mdb_alloc(fw->fw_flistsz, UM_SLEEP);
15430Sstevel@tonic-gate 
15440Sstevel@tonic-gate 	if (mdb_vread(fw->fw_flist, fw->fw_flistsz,
15450Sstevel@tonic-gate 	    (uintptr_t)p.p_user.u_finfo.fi_list) == -1) {
15460Sstevel@tonic-gate 		mdb_warn("failed to read file array at %p",
15470Sstevel@tonic-gate 		    p.p_user.u_finfo.fi_list);
15480Sstevel@tonic-gate 		mdb_free(fw->fw_flist, fw->fw_flistsz);
15490Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
15500Sstevel@tonic-gate 		return (WALK_ERR);
15510Sstevel@tonic-gate 	}
15520Sstevel@tonic-gate 
15530Sstevel@tonic-gate 	fw->fw_ndx = 0;
15540Sstevel@tonic-gate 	wsp->walk_data = fw;
15550Sstevel@tonic-gate 
15560Sstevel@tonic-gate 	return (WALK_NEXT);
15570Sstevel@tonic-gate }
15580Sstevel@tonic-gate 
15590Sstevel@tonic-gate int
15600Sstevel@tonic-gate file_walk_step(mdb_walk_state_t *wsp)
15610Sstevel@tonic-gate {
15620Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
15630Sstevel@tonic-gate 	struct file file;
15640Sstevel@tonic-gate 	uintptr_t fp;
15650Sstevel@tonic-gate 
15660Sstevel@tonic-gate again:
15670Sstevel@tonic-gate 	if (fw->fw_ndx == fw->fw_nofiles)
15680Sstevel@tonic-gate 		return (WALK_DONE);
15690Sstevel@tonic-gate 
15700Sstevel@tonic-gate 	if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) == NULL)
15710Sstevel@tonic-gate 		goto again;
15720Sstevel@tonic-gate 
15730Sstevel@tonic-gate 	(void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
15740Sstevel@tonic-gate 	return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
15750Sstevel@tonic-gate }
15760Sstevel@tonic-gate 
15770Sstevel@tonic-gate int
15780Sstevel@tonic-gate allfile_walk_step(mdb_walk_state_t *wsp)
15790Sstevel@tonic-gate {
15800Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
15810Sstevel@tonic-gate 	struct file file;
15820Sstevel@tonic-gate 	uintptr_t fp;
15830Sstevel@tonic-gate 
15840Sstevel@tonic-gate 	if (fw->fw_ndx == fw->fw_nofiles)
15850Sstevel@tonic-gate 		return (WALK_DONE);
15860Sstevel@tonic-gate 
15870Sstevel@tonic-gate 	if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) != NULL)
15880Sstevel@tonic-gate 		(void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
15890Sstevel@tonic-gate 	else
15900Sstevel@tonic-gate 		bzero(&file, sizeof (file));
15910Sstevel@tonic-gate 
15920Sstevel@tonic-gate 	return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
15930Sstevel@tonic-gate }
15940Sstevel@tonic-gate 
15950Sstevel@tonic-gate void
15960Sstevel@tonic-gate file_walk_fini(mdb_walk_state_t *wsp)
15970Sstevel@tonic-gate {
15980Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
15990Sstevel@tonic-gate 
16000Sstevel@tonic-gate 	mdb_free(fw->fw_flist, fw->fw_flistsz);
16010Sstevel@tonic-gate 	mdb_free(fw, sizeof (file_walk_data_t));
16020Sstevel@tonic-gate }
16030Sstevel@tonic-gate 
16040Sstevel@tonic-gate int
16050Sstevel@tonic-gate port_walk_init(mdb_walk_state_t *wsp)
16060Sstevel@tonic-gate {
16070Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
16080Sstevel@tonic-gate 		mdb_warn("port walk doesn't support global walks\n");
16090Sstevel@tonic-gate 		return (WALK_ERR);
16100Sstevel@tonic-gate 	}
16110Sstevel@tonic-gate 
16120Sstevel@tonic-gate 	if (mdb_layered_walk("file", wsp) == -1) {
16130Sstevel@tonic-gate 		mdb_warn("couldn't walk 'file'");
16140Sstevel@tonic-gate 		return (WALK_ERR);
16150Sstevel@tonic-gate 	}
16160Sstevel@tonic-gate 	return (WALK_NEXT);
16170Sstevel@tonic-gate }
16180Sstevel@tonic-gate 
16190Sstevel@tonic-gate int
16200Sstevel@tonic-gate port_walk_step(mdb_walk_state_t *wsp)
16210Sstevel@tonic-gate {
16220Sstevel@tonic-gate 	struct vnode	vn;
16230Sstevel@tonic-gate 	uintptr_t	vp;
16240Sstevel@tonic-gate 	uintptr_t	pp;
16250Sstevel@tonic-gate 	struct port	port;
16260Sstevel@tonic-gate 
16270Sstevel@tonic-gate 	vp = (uintptr_t)((struct file *)wsp->walk_layer)->f_vnode;
16280Sstevel@tonic-gate 	if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
16290Sstevel@tonic-gate 		mdb_warn("failed to read vnode_t at %p", vp);
16300Sstevel@tonic-gate 		return (WALK_ERR);
16310Sstevel@tonic-gate 	}
16320Sstevel@tonic-gate 	if (vn.v_type != VPORT)
16330Sstevel@tonic-gate 		return (WALK_NEXT);
16340Sstevel@tonic-gate 
16350Sstevel@tonic-gate 	pp = (uintptr_t)vn.v_data;
16360Sstevel@tonic-gate 	if (mdb_vread(&port, sizeof (port), pp) == -1) {
16370Sstevel@tonic-gate 		mdb_warn("failed to read port_t at %p", pp);
16380Sstevel@tonic-gate 		return (WALK_ERR);
16390Sstevel@tonic-gate 	}
16400Sstevel@tonic-gate 	return (wsp->walk_callback(pp, &port, wsp->walk_cbdata));
16410Sstevel@tonic-gate }
16420Sstevel@tonic-gate 
16430Sstevel@tonic-gate typedef struct portev_walk_data {
16440Sstevel@tonic-gate 	list_node_t	*pev_node;
16450Sstevel@tonic-gate 	list_node_t	*pev_last;
16460Sstevel@tonic-gate 	size_t		pev_offset;
16470Sstevel@tonic-gate } portev_walk_data_t;
16480Sstevel@tonic-gate 
16490Sstevel@tonic-gate int
16500Sstevel@tonic-gate portev_walk_init(mdb_walk_state_t *wsp)
16510Sstevel@tonic-gate {
16520Sstevel@tonic-gate 	portev_walk_data_t *pevd;
16530Sstevel@tonic-gate 	struct port	port;
16540Sstevel@tonic-gate 	struct vnode	vn;
16550Sstevel@tonic-gate 	struct list	*list;
16560Sstevel@tonic-gate 	uintptr_t	vp;
16570Sstevel@tonic-gate 
16580Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
16590Sstevel@tonic-gate 		mdb_warn("portev walk doesn't support global walks\n");
16600Sstevel@tonic-gate 		return (WALK_ERR);
16610Sstevel@tonic-gate 	}
16620Sstevel@tonic-gate 
16630Sstevel@tonic-gate 	pevd = mdb_alloc(sizeof (portev_walk_data_t), UM_SLEEP);
16640Sstevel@tonic-gate 
16650Sstevel@tonic-gate 	if (mdb_vread(&port, sizeof (port), wsp->walk_addr) == -1) {
16660Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
16670Sstevel@tonic-gate 		mdb_warn("failed to read port structure at %p", wsp->walk_addr);
16680Sstevel@tonic-gate 		return (WALK_ERR);
16690Sstevel@tonic-gate 	}
16700Sstevel@tonic-gate 
16710Sstevel@tonic-gate 	vp = (uintptr_t)port.port_vnode;
16720Sstevel@tonic-gate 	if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
16730Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
16740Sstevel@tonic-gate 		mdb_warn("failed to read vnode_t at %p", vp);
16750Sstevel@tonic-gate 		return (WALK_ERR);
16760Sstevel@tonic-gate 	}
16770Sstevel@tonic-gate 
16780Sstevel@tonic-gate 	if (vn.v_type != VPORT) {
16790Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
16800Sstevel@tonic-gate 		mdb_warn("input address (%p) does not point to an event port",
16810Sstevel@tonic-gate 		    wsp->walk_addr);
16820Sstevel@tonic-gate 		return (WALK_ERR);
16830Sstevel@tonic-gate 	}
16840Sstevel@tonic-gate 
16850Sstevel@tonic-gate 	if (port.port_queue.portq_nent == 0) {
16860Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
16870Sstevel@tonic-gate 		return (WALK_DONE);
16880Sstevel@tonic-gate 	}
16890Sstevel@tonic-gate 	list = &port.port_queue.portq_list;
16900Sstevel@tonic-gate 	pevd->pev_offset = list->list_offset;
16910Sstevel@tonic-gate 	pevd->pev_last = list->list_head.list_prev;
16920Sstevel@tonic-gate 	pevd->pev_node = list->list_head.list_next;
16930Sstevel@tonic-gate 	wsp->walk_data = pevd;
16940Sstevel@tonic-gate 	return (WALK_NEXT);
16950Sstevel@tonic-gate }
16960Sstevel@tonic-gate 
16970Sstevel@tonic-gate int
16980Sstevel@tonic-gate portev_walk_step(mdb_walk_state_t *wsp)
16990Sstevel@tonic-gate {
17000Sstevel@tonic-gate 	portev_walk_data_t	*pevd;
17010Sstevel@tonic-gate 	struct port_kevent	ev;
17020Sstevel@tonic-gate 	uintptr_t		evp;
17030Sstevel@tonic-gate 
17040Sstevel@tonic-gate 	pevd = (portev_walk_data_t *)wsp->walk_data;
17050Sstevel@tonic-gate 
17060Sstevel@tonic-gate 	if (pevd->pev_last == NULL)
17070Sstevel@tonic-gate 		return (WALK_DONE);
17080Sstevel@tonic-gate 	if (pevd->pev_node == pevd->pev_last)
17090Sstevel@tonic-gate 		pevd->pev_last = NULL;		/* last round */
17100Sstevel@tonic-gate 
17110Sstevel@tonic-gate 	evp = ((uintptr_t)(((char *)pevd->pev_node) - pevd->pev_offset));
17120Sstevel@tonic-gate 	if (mdb_vread(&ev, sizeof (ev), evp) == -1) {
17130Sstevel@tonic-gate 		mdb_warn("failed to read port_kevent at %p", evp);
17140Sstevel@tonic-gate 		return (WALK_DONE);
17150Sstevel@tonic-gate 	}
17160Sstevel@tonic-gate 	pevd->pev_node = ev.portkev_node.list_next;
17170Sstevel@tonic-gate 	return (wsp->walk_callback(evp, &ev, wsp->walk_cbdata));
17180Sstevel@tonic-gate }
17190Sstevel@tonic-gate 
17200Sstevel@tonic-gate void
17210Sstevel@tonic-gate portev_walk_fini(mdb_walk_state_t *wsp)
17220Sstevel@tonic-gate {
17230Sstevel@tonic-gate 	portev_walk_data_t *pevd = (portev_walk_data_t *)wsp->walk_data;
17240Sstevel@tonic-gate 
17250Sstevel@tonic-gate 	if (pevd != NULL)
17260Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
17270Sstevel@tonic-gate }
17280Sstevel@tonic-gate 
17290Sstevel@tonic-gate typedef struct proc_walk_data {
17300Sstevel@tonic-gate 	uintptr_t *pw_stack;
17310Sstevel@tonic-gate 	int pw_depth;
17320Sstevel@tonic-gate 	int pw_max;
17330Sstevel@tonic-gate } proc_walk_data_t;
17340Sstevel@tonic-gate 
17350Sstevel@tonic-gate int
17360Sstevel@tonic-gate proc_walk_init(mdb_walk_state_t *wsp)
17370Sstevel@tonic-gate {
17380Sstevel@tonic-gate 	GElf_Sym sym;
17390Sstevel@tonic-gate 	proc_walk_data_t *pw;
17400Sstevel@tonic-gate 
17410Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
17420Sstevel@tonic-gate 		if (mdb_lookup_by_name("p0", &sym) == -1) {
17430Sstevel@tonic-gate 			mdb_warn("failed to read 'practive'");
17440Sstevel@tonic-gate 			return (WALK_ERR);
17450Sstevel@tonic-gate 		}
17460Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)sym.st_value;
17470Sstevel@tonic-gate 	}
17480Sstevel@tonic-gate 
17490Sstevel@tonic-gate 	pw = mdb_zalloc(sizeof (proc_walk_data_t), UM_SLEEP);
17500Sstevel@tonic-gate 
17510Sstevel@tonic-gate 	if (mdb_readvar(&pw->pw_max, "nproc") == -1) {
17520Sstevel@tonic-gate 		mdb_warn("failed to read 'nproc'");
17530Sstevel@tonic-gate 		mdb_free(pw, sizeof (pw));
17540Sstevel@tonic-gate 		return (WALK_ERR);
17550Sstevel@tonic-gate 	}
17560Sstevel@tonic-gate 
17570Sstevel@tonic-gate 	pw->pw_stack = mdb_alloc(pw->pw_max * sizeof (uintptr_t), UM_SLEEP);
17580Sstevel@tonic-gate 	wsp->walk_data = pw;
17590Sstevel@tonic-gate 
17600Sstevel@tonic-gate 	return (WALK_NEXT);
17610Sstevel@tonic-gate }
17620Sstevel@tonic-gate 
17630Sstevel@tonic-gate int
17640Sstevel@tonic-gate proc_walk_step(mdb_walk_state_t *wsp)
17650Sstevel@tonic-gate {
17660Sstevel@tonic-gate 	proc_walk_data_t *pw = wsp->walk_data;
17670Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
17680Sstevel@tonic-gate 	uintptr_t cld, sib;
17690Sstevel@tonic-gate 
17700Sstevel@tonic-gate 	int status;
17710Sstevel@tonic-gate 	proc_t pr;
17720Sstevel@tonic-gate 
17730Sstevel@tonic-gate 	if (mdb_vread(&pr, sizeof (proc_t), addr) == -1) {
17740Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", addr);
17750Sstevel@tonic-gate 		return (WALK_DONE);
17760Sstevel@tonic-gate 	}
17770Sstevel@tonic-gate 
17780Sstevel@tonic-gate 	cld = (uintptr_t)pr.p_child;
17790Sstevel@tonic-gate 	sib = (uintptr_t)pr.p_sibling;
17800Sstevel@tonic-gate 
17810Sstevel@tonic-gate 	if (pw->pw_depth > 0 && addr == pw->pw_stack[pw->pw_depth - 1]) {
17820Sstevel@tonic-gate 		pw->pw_depth--;
17830Sstevel@tonic-gate 		goto sib;
17840Sstevel@tonic-gate 	}
17850Sstevel@tonic-gate 
17860Sstevel@tonic-gate 	status = wsp->walk_callback(addr, &pr, wsp->walk_cbdata);
17870Sstevel@tonic-gate 
17880Sstevel@tonic-gate 	if (status != WALK_NEXT)
17890Sstevel@tonic-gate 		return (status);
17900Sstevel@tonic-gate 
17910Sstevel@tonic-gate 	if ((wsp->walk_addr = cld) != NULL) {
17920Sstevel@tonic-gate 		if (mdb_vread(&pr, sizeof (proc_t), cld) == -1) {
17930Sstevel@tonic-gate 			mdb_warn("proc %p has invalid p_child %p; skipping\n",
17940Sstevel@tonic-gate 			    addr, cld);
17950Sstevel@tonic-gate 			goto sib;
17960Sstevel@tonic-gate 		}
17970Sstevel@tonic-gate 
17980Sstevel@tonic-gate 		pw->pw_stack[pw->pw_depth++] = addr;
17990Sstevel@tonic-gate 
18000Sstevel@tonic-gate 		if (pw->pw_depth == pw->pw_max) {
18010Sstevel@tonic-gate 			mdb_warn("depth %d exceeds max depth; try again\n",
18020Sstevel@tonic-gate 			    pw->pw_depth);
18030Sstevel@tonic-gate 			return (WALK_DONE);
18040Sstevel@tonic-gate 		}
18050Sstevel@tonic-gate 		return (WALK_NEXT);
18060Sstevel@tonic-gate 	}
18070Sstevel@tonic-gate 
18080Sstevel@tonic-gate sib:
18090Sstevel@tonic-gate 	/*
18100Sstevel@tonic-gate 	 * We know that p0 has no siblings, and if another starting proc
18110Sstevel@tonic-gate 	 * was given, we don't want to walk its siblings anyway.
18120Sstevel@tonic-gate 	 */
18130Sstevel@tonic-gate 	if (pw->pw_depth == 0)
18140Sstevel@tonic-gate 		return (WALK_DONE);
18150Sstevel@tonic-gate 
18160Sstevel@tonic-gate 	if (sib != NULL && mdb_vread(&pr, sizeof (proc_t), sib) == -1) {
18170Sstevel@tonic-gate 		mdb_warn("proc %p has invalid p_sibling %p; skipping\n",
18180Sstevel@tonic-gate 		    addr, sib);
18190Sstevel@tonic-gate 		sib = NULL;
18200Sstevel@tonic-gate 	}
18210Sstevel@tonic-gate 
18220Sstevel@tonic-gate 	if ((wsp->walk_addr = sib) == NULL) {
18230Sstevel@tonic-gate 		if (pw->pw_depth > 0) {
18240Sstevel@tonic-gate 			wsp->walk_addr = pw->pw_stack[pw->pw_depth - 1];
18250Sstevel@tonic-gate 			return (WALK_NEXT);
18260Sstevel@tonic-gate 		}
18270Sstevel@tonic-gate 		return (WALK_DONE);
18280Sstevel@tonic-gate 	}
18290Sstevel@tonic-gate 
18300Sstevel@tonic-gate 	return (WALK_NEXT);
18310Sstevel@tonic-gate }
18320Sstevel@tonic-gate 
18330Sstevel@tonic-gate void
18340Sstevel@tonic-gate proc_walk_fini(mdb_walk_state_t *wsp)
18350Sstevel@tonic-gate {
18360Sstevel@tonic-gate 	proc_walk_data_t *pw = wsp->walk_data;
18370Sstevel@tonic-gate 
18380Sstevel@tonic-gate 	mdb_free(pw->pw_stack, pw->pw_max * sizeof (uintptr_t));
18390Sstevel@tonic-gate 	mdb_free(pw, sizeof (proc_walk_data_t));
18400Sstevel@tonic-gate }
18410Sstevel@tonic-gate 
18420Sstevel@tonic-gate int
18430Sstevel@tonic-gate task_walk_init(mdb_walk_state_t *wsp)
18440Sstevel@tonic-gate {
18450Sstevel@tonic-gate 	task_t task;
18460Sstevel@tonic-gate 
18470Sstevel@tonic-gate 	if (mdb_vread(&task, sizeof (task_t), wsp->walk_addr) == -1) {
18480Sstevel@tonic-gate 		mdb_warn("failed to read task at %p", wsp->walk_addr);
18490Sstevel@tonic-gate 		return (WALK_ERR);
18500Sstevel@tonic-gate 	}
18510Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)task.tk_memb_list;
18520Sstevel@tonic-gate 	wsp->walk_data = task.tk_memb_list;
18530Sstevel@tonic-gate 	return (WALK_NEXT);
18540Sstevel@tonic-gate }
18550Sstevel@tonic-gate 
18560Sstevel@tonic-gate int
18570Sstevel@tonic-gate task_walk_step(mdb_walk_state_t *wsp)
18580Sstevel@tonic-gate {
18590Sstevel@tonic-gate 	proc_t proc;
18600Sstevel@tonic-gate 	int status;
18610Sstevel@tonic-gate 
18620Sstevel@tonic-gate 	if (mdb_vread(&proc, sizeof (proc_t), wsp->walk_addr) == -1) {
18630Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", wsp->walk_addr);
18640Sstevel@tonic-gate 		return (WALK_DONE);
18650Sstevel@tonic-gate 	}
18660Sstevel@tonic-gate 
18670Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata);
18680Sstevel@tonic-gate 
18690Sstevel@tonic-gate 	if (proc.p_tasknext == wsp->walk_data)
18700Sstevel@tonic-gate 		return (WALK_DONE);
18710Sstevel@tonic-gate 
18720Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)proc.p_tasknext;
18730Sstevel@tonic-gate 	return (status);
18740Sstevel@tonic-gate }
18750Sstevel@tonic-gate 
18760Sstevel@tonic-gate int
18770Sstevel@tonic-gate project_walk_init(mdb_walk_state_t *wsp)
18780Sstevel@tonic-gate {
18790Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
18800Sstevel@tonic-gate 		if (mdb_readvar(&wsp->walk_addr, "proj0p") == -1) {
18810Sstevel@tonic-gate 			mdb_warn("failed to read 'proj0p'");
18820Sstevel@tonic-gate 			return (WALK_ERR);
18830Sstevel@tonic-gate 		}
18840Sstevel@tonic-gate 	}
18850Sstevel@tonic-gate 	wsp->walk_data = (void *)wsp->walk_addr;
18860Sstevel@tonic-gate 	return (WALK_NEXT);
18870Sstevel@tonic-gate }
18880Sstevel@tonic-gate 
18890Sstevel@tonic-gate int
18900Sstevel@tonic-gate project_walk_step(mdb_walk_state_t *wsp)
18910Sstevel@tonic-gate {
18920Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
18930Sstevel@tonic-gate 	kproject_t pj;
18940Sstevel@tonic-gate 	int status;
18950Sstevel@tonic-gate 
18960Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
18970Sstevel@tonic-gate 		mdb_warn("failed to read project at %p", addr);
18980Sstevel@tonic-gate 		return (WALK_DONE);
18990Sstevel@tonic-gate 	}
19000Sstevel@tonic-gate 	status = wsp->walk_callback(addr, &pj, wsp->walk_cbdata);
19010Sstevel@tonic-gate 	if (status != WALK_NEXT)
19020Sstevel@tonic-gate 		return (status);
19030Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)pj.kpj_next;
19040Sstevel@tonic-gate 	if ((void *)wsp->walk_addr == wsp->walk_data)
19050Sstevel@tonic-gate 		return (WALK_DONE);
19060Sstevel@tonic-gate 	return (WALK_NEXT);
19070Sstevel@tonic-gate }
19080Sstevel@tonic-gate 
19090Sstevel@tonic-gate static int
19100Sstevel@tonic-gate generic_walk_step(mdb_walk_state_t *wsp)
19110Sstevel@tonic-gate {
19120Sstevel@tonic-gate 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
19130Sstevel@tonic-gate 	    wsp->walk_cbdata));
19140Sstevel@tonic-gate }
19150Sstevel@tonic-gate 
19160Sstevel@tonic-gate int
19170Sstevel@tonic-gate seg_walk_init(mdb_walk_state_t *wsp)
19180Sstevel@tonic-gate {
19190Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
19200Sstevel@tonic-gate 		mdb_warn("seg walk must begin at struct as *\n");
19210Sstevel@tonic-gate 		return (WALK_ERR);
19220Sstevel@tonic-gate 	}
19230Sstevel@tonic-gate 
19240Sstevel@tonic-gate 	/*
19250Sstevel@tonic-gate 	 * this is really just a wrapper to AVL tree walk
19260Sstevel@tonic-gate 	 */
19270Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)&((struct as *)wsp->walk_addr)->a_segtree;
19280Sstevel@tonic-gate 	return (avl_walk_init(wsp));
19290Sstevel@tonic-gate }
19300Sstevel@tonic-gate 
19310Sstevel@tonic-gate static int
19320Sstevel@tonic-gate cpu_walk_cmp(const void *l, const void *r)
19330Sstevel@tonic-gate {
19340Sstevel@tonic-gate 	uintptr_t lhs = *((uintptr_t *)l);
19350Sstevel@tonic-gate 	uintptr_t rhs = *((uintptr_t *)r);
19360Sstevel@tonic-gate 	cpu_t lcpu, rcpu;
19370Sstevel@tonic-gate 
19380Sstevel@tonic-gate 	(void) mdb_vread(&lcpu, sizeof (lcpu), lhs);
19390Sstevel@tonic-gate 	(void) mdb_vread(&rcpu, sizeof (rcpu), rhs);
19400Sstevel@tonic-gate 
19410Sstevel@tonic-gate 	if (lcpu.cpu_id < rcpu.cpu_id)
19420Sstevel@tonic-gate 		return (-1);
19430Sstevel@tonic-gate 
19440Sstevel@tonic-gate 	if (lcpu.cpu_id > rcpu.cpu_id)
19450Sstevel@tonic-gate 		return (1);
19460Sstevel@tonic-gate 
19470Sstevel@tonic-gate 	return (0);
19480Sstevel@tonic-gate }
19490Sstevel@tonic-gate 
19500Sstevel@tonic-gate typedef struct cpu_walk {
19510Sstevel@tonic-gate 	uintptr_t *cw_array;
19520Sstevel@tonic-gate 	int cw_ndx;
19530Sstevel@tonic-gate } cpu_walk_t;
19540Sstevel@tonic-gate 
19550Sstevel@tonic-gate int
19560Sstevel@tonic-gate cpu_walk_init(mdb_walk_state_t *wsp)
19570Sstevel@tonic-gate {
19580Sstevel@tonic-gate 	cpu_walk_t *cw;
19590Sstevel@tonic-gate 	int max_ncpus, i = 0;
19600Sstevel@tonic-gate 	uintptr_t current, first;
19610Sstevel@tonic-gate 	cpu_t cpu, panic_cpu;
19620Sstevel@tonic-gate 	uintptr_t panicstr, addr;
19630Sstevel@tonic-gate 	GElf_Sym sym;
19640Sstevel@tonic-gate 
19650Sstevel@tonic-gate 	cw = mdb_zalloc(sizeof (cpu_walk_t), UM_SLEEP | UM_GC);
19660Sstevel@tonic-gate 
19670Sstevel@tonic-gate 	if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
19680Sstevel@tonic-gate 		mdb_warn("failed to read 'max_ncpus'");
19690Sstevel@tonic-gate 		return (WALK_ERR);
19700Sstevel@tonic-gate 	}
19710Sstevel@tonic-gate 
19720Sstevel@tonic-gate 	if (mdb_readvar(&panicstr, "panicstr") == -1) {
19730Sstevel@tonic-gate 		mdb_warn("failed to read 'panicstr'");
19740Sstevel@tonic-gate 		return (WALK_ERR);
19750Sstevel@tonic-gate 	}
19760Sstevel@tonic-gate 
19770Sstevel@tonic-gate 	if (panicstr != NULL) {
19780Sstevel@tonic-gate 		if (mdb_lookup_by_name("panic_cpu", &sym) == -1) {
19790Sstevel@tonic-gate 			mdb_warn("failed to find 'panic_cpu'");
19800Sstevel@tonic-gate 			return (WALK_ERR);
19810Sstevel@tonic-gate 		}
19820Sstevel@tonic-gate 
19830Sstevel@tonic-gate 		addr = (uintptr_t)sym.st_value;
19840Sstevel@tonic-gate 
19850Sstevel@tonic-gate 		if (mdb_vread(&panic_cpu, sizeof (cpu_t), addr) == -1) {
19860Sstevel@tonic-gate 			mdb_warn("failed to read 'panic_cpu'");
19870Sstevel@tonic-gate 			return (WALK_ERR);
19880Sstevel@tonic-gate 		}
19890Sstevel@tonic-gate 	}
19900Sstevel@tonic-gate 
19910Sstevel@tonic-gate 	/*
19920Sstevel@tonic-gate 	 * Unfortunately, there is no platform-independent way to walk
19930Sstevel@tonic-gate 	 * CPUs in ID order.  We therefore loop through in cpu_next order,
19940Sstevel@tonic-gate 	 * building an array of CPU pointers which will subsequently be
19950Sstevel@tonic-gate 	 * sorted.
19960Sstevel@tonic-gate 	 */
19970Sstevel@tonic-gate 	cw->cw_array =
19980Sstevel@tonic-gate 	    mdb_zalloc((max_ncpus + 1) * sizeof (uintptr_t), UM_SLEEP | UM_GC);
19990Sstevel@tonic-gate 
20000Sstevel@tonic-gate 	if (mdb_readvar(&first, "cpu_list") == -1) {
20010Sstevel@tonic-gate 		mdb_warn("failed to read 'cpu_list'");
20020Sstevel@tonic-gate 		return (WALK_ERR);
20030Sstevel@tonic-gate 	}
20040Sstevel@tonic-gate 
20050Sstevel@tonic-gate 	current = first;
20060Sstevel@tonic-gate 	do {
20070Sstevel@tonic-gate 		if (mdb_vread(&cpu, sizeof (cpu), current) == -1) {
20080Sstevel@tonic-gate 			mdb_warn("failed to read cpu at %p", current);
20090Sstevel@tonic-gate 			return (WALK_ERR);
20100Sstevel@tonic-gate 		}
20110Sstevel@tonic-gate 
20120Sstevel@tonic-gate 		if (panicstr != NULL && panic_cpu.cpu_id == cpu.cpu_id) {
20130Sstevel@tonic-gate 			cw->cw_array[i++] = addr;
20140Sstevel@tonic-gate 		} else {
20150Sstevel@tonic-gate 			cw->cw_array[i++] = current;
20160Sstevel@tonic-gate 		}
20170Sstevel@tonic-gate 	} while ((current = (uintptr_t)cpu.cpu_next) != first);
20180Sstevel@tonic-gate 
20190Sstevel@tonic-gate 	qsort(cw->cw_array, i, sizeof (uintptr_t), cpu_walk_cmp);
20200Sstevel@tonic-gate 	wsp->walk_data = cw;
20210Sstevel@tonic-gate 
20220Sstevel@tonic-gate 	return (WALK_NEXT);
20230Sstevel@tonic-gate }
20240Sstevel@tonic-gate 
20250Sstevel@tonic-gate int
20260Sstevel@tonic-gate cpu_walk_step(mdb_walk_state_t *wsp)
20270Sstevel@tonic-gate {
20280Sstevel@tonic-gate 	cpu_walk_t *cw = wsp->walk_data;
20290Sstevel@tonic-gate 	cpu_t cpu;
20300Sstevel@tonic-gate 	uintptr_t addr = cw->cw_array[cw->cw_ndx++];
20310Sstevel@tonic-gate 
20320Sstevel@tonic-gate 	if (addr == NULL)
20330Sstevel@tonic-gate 		return (WALK_DONE);
20340Sstevel@tonic-gate 
20350Sstevel@tonic-gate 	if (mdb_vread(&cpu, sizeof (cpu), addr) == -1) {
20360Sstevel@tonic-gate 		mdb_warn("failed to read cpu at %p", addr);
20370Sstevel@tonic-gate 		return (WALK_DONE);
20380Sstevel@tonic-gate 	}
20390Sstevel@tonic-gate 
20400Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &cpu, wsp->walk_cbdata));
20410Sstevel@tonic-gate }
20420Sstevel@tonic-gate 
20430Sstevel@tonic-gate typedef struct cpuinfo_data {
20440Sstevel@tonic-gate 	intptr_t cid_cpu;
20450Sstevel@tonic-gate 	uintptr_t cid_lbolt;
20460Sstevel@tonic-gate 	uintptr_t **cid_ithr;
20470Sstevel@tonic-gate 	char	cid_print_head;
20480Sstevel@tonic-gate 	char	cid_print_thr;
20490Sstevel@tonic-gate 	char	cid_print_ithr;
20500Sstevel@tonic-gate 	char	cid_print_flags;
20510Sstevel@tonic-gate } cpuinfo_data_t;
20520Sstevel@tonic-gate 
20530Sstevel@tonic-gate int
20540Sstevel@tonic-gate cpuinfo_walk_ithread(uintptr_t addr, const kthread_t *thr, cpuinfo_data_t *cid)
20550Sstevel@tonic-gate {
20560Sstevel@tonic-gate 	cpu_t c;
20570Sstevel@tonic-gate 	int id;
20580Sstevel@tonic-gate 	uint8_t pil;
20590Sstevel@tonic-gate 
20600Sstevel@tonic-gate 	if (!(thr->t_flag & T_INTR_THREAD) || thr->t_state == TS_FREE)
20610Sstevel@tonic-gate 		return (WALK_NEXT);
20620Sstevel@tonic-gate 
20630Sstevel@tonic-gate 	if (thr->t_bound_cpu == NULL) {
20640Sstevel@tonic-gate 		mdb_warn("thr %p is intr thread w/out a CPU\n", addr);
20650Sstevel@tonic-gate 		return (WALK_NEXT);
20660Sstevel@tonic-gate 	}
20670Sstevel@tonic-gate 
20680Sstevel@tonic-gate 	(void) mdb_vread(&c, sizeof (c), (uintptr_t)thr->t_bound_cpu);
20690Sstevel@tonic-gate 
20700Sstevel@tonic-gate 	if ((id = c.cpu_id) >= NCPU) {
20710Sstevel@tonic-gate 		mdb_warn("CPU %p has id (%d) greater than NCPU (%d)\n",
20720Sstevel@tonic-gate 		    thr->t_bound_cpu, id, NCPU);
20730Sstevel@tonic-gate 		return (WALK_NEXT);
20740Sstevel@tonic-gate 	}
20750Sstevel@tonic-gate 
20760Sstevel@tonic-gate 	if ((pil = thr->t_pil) >= NINTR) {
20770Sstevel@tonic-gate 		mdb_warn("thread %p has pil (%d) greater than %d\n",
20780Sstevel@tonic-gate 		    addr, pil, NINTR);
20790Sstevel@tonic-gate 		return (WALK_NEXT);
20800Sstevel@tonic-gate 	}
20810Sstevel@tonic-gate 
20820Sstevel@tonic-gate 	if (cid->cid_ithr[id][pil] != NULL) {
20830Sstevel@tonic-gate 		mdb_warn("CPU %d has multiple threads at pil %d (at least "
20840Sstevel@tonic-gate 		    "%p and %p)\n", id, pil, addr, cid->cid_ithr[id][pil]);
20850Sstevel@tonic-gate 		return (WALK_NEXT);
20860Sstevel@tonic-gate 	}
20870Sstevel@tonic-gate 
20880Sstevel@tonic-gate 	cid->cid_ithr[id][pil] = addr;
20890Sstevel@tonic-gate 
20900Sstevel@tonic-gate 	return (WALK_NEXT);
20910Sstevel@tonic-gate }
20920Sstevel@tonic-gate 
20930Sstevel@tonic-gate #define	CPUINFO_IDWIDTH		3
20940Sstevel@tonic-gate #define	CPUINFO_FLAGWIDTH	9
20950Sstevel@tonic-gate 
20960Sstevel@tonic-gate #ifdef _LP64
2097537Smishra #if defined(__amd64)
2098537Smishra #define	CPUINFO_TWIDTH		16
2099537Smishra #define	CPUINFO_CPUWIDTH	16
2100537Smishra #else
21010Sstevel@tonic-gate #define	CPUINFO_CPUWIDTH	11
21020Sstevel@tonic-gate #define	CPUINFO_TWIDTH		11
2103537Smishra #endif
21040Sstevel@tonic-gate #else
21050Sstevel@tonic-gate #define	CPUINFO_CPUWIDTH	8
21060Sstevel@tonic-gate #define	CPUINFO_TWIDTH		8
21070Sstevel@tonic-gate #endif
21080Sstevel@tonic-gate 
21090Sstevel@tonic-gate #define	CPUINFO_THRDELT		(CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 9)
21100Sstevel@tonic-gate #define	CPUINFO_FLAGDELT	(CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 4)
21110Sstevel@tonic-gate #define	CPUINFO_ITHRDELT	4
21120Sstevel@tonic-gate 
21130Sstevel@tonic-gate #define	CPUINFO_INDENT	mdb_printf("%*s", CPUINFO_THRDELT, \
21140Sstevel@tonic-gate     flagline < nflaglines ? flagbuf[flagline++] : "")
21150Sstevel@tonic-gate 
21160Sstevel@tonic-gate int
21170Sstevel@tonic-gate cpuinfo_walk_cpu(uintptr_t addr, const cpu_t *cpu, cpuinfo_data_t *cid)
21180Sstevel@tonic-gate {
21190Sstevel@tonic-gate 	kthread_t t;
21200Sstevel@tonic-gate 	disp_t disp;
21210Sstevel@tonic-gate 	proc_t p;
21220Sstevel@tonic-gate 	uintptr_t pinned;
21230Sstevel@tonic-gate 	char **flagbuf;
21240Sstevel@tonic-gate 	int nflaglines = 0, flagline = 0, bspl, rval = WALK_NEXT;
21250Sstevel@tonic-gate 
21260Sstevel@tonic-gate 	const char *flags[] = {
21270Sstevel@tonic-gate 	    "RUNNING", "READY", "QUIESCED", "EXISTS",
21280Sstevel@tonic-gate 	    "ENABLE", "OFFLINE", "POWEROFF", "FROZEN",
21290Sstevel@tonic-gate 	    "SPARE", "FAULTED", NULL
21300Sstevel@tonic-gate 	};
21310Sstevel@tonic-gate 
21320Sstevel@tonic-gate 	if (cid->cid_cpu != -1) {
21330Sstevel@tonic-gate 		if (addr != cid->cid_cpu && cpu->cpu_id != cid->cid_cpu)
21340Sstevel@tonic-gate 			return (WALK_NEXT);
21350Sstevel@tonic-gate 
21360Sstevel@tonic-gate 		/*
21370Sstevel@tonic-gate 		 * Set cid_cpu to -1 to indicate that we found a matching CPU.
21380Sstevel@tonic-gate 		 */
21390Sstevel@tonic-gate 		cid->cid_cpu = -1;
21400Sstevel@tonic-gate 		rval = WALK_DONE;
21410Sstevel@tonic-gate 	}
21420Sstevel@tonic-gate 
21430Sstevel@tonic-gate 	if (cid->cid_print_head) {
21440Sstevel@tonic-gate 		mdb_printf("%3s %-*s %3s %4s %4s %3s %4s %5s %-6s %-*s %s\n",
21450Sstevel@tonic-gate 		    "ID", CPUINFO_CPUWIDTH, "ADDR", "FLG", "NRUN", "BSPL",
21460Sstevel@tonic-gate 		    "PRI", "RNRN", "KRNRN", "SWITCH", CPUINFO_TWIDTH, "THREAD",
21470Sstevel@tonic-gate 		    "PROC");
21480Sstevel@tonic-gate 		cid->cid_print_head = FALSE;
21490Sstevel@tonic-gate 	}
21500Sstevel@tonic-gate 
21510Sstevel@tonic-gate 	bspl = cpu->cpu_base_spl;
21520Sstevel@tonic-gate 
21530Sstevel@tonic-gate 	if (mdb_vread(&disp, sizeof (disp_t), (uintptr_t)cpu->cpu_disp) == -1) {
21540Sstevel@tonic-gate 		mdb_warn("failed to read disp_t at %p", cpu->cpu_disp);
21550Sstevel@tonic-gate 		return (WALK_ERR);
21560Sstevel@tonic-gate 	}
21570Sstevel@tonic-gate 
21580Sstevel@tonic-gate 	mdb_printf("%3d %0*p %3x %4d %4d ",
21590Sstevel@tonic-gate 	    cpu->cpu_id, CPUINFO_CPUWIDTH, addr, cpu->cpu_flags,
21600Sstevel@tonic-gate 	    disp.disp_nrunnable, bspl);
21610Sstevel@tonic-gate 
21620Sstevel@tonic-gate 	if (mdb_vread(&t, sizeof (t), (uintptr_t)cpu->cpu_thread) != -1) {
21630Sstevel@tonic-gate 		mdb_printf("%3d ", t.t_pri);
21640Sstevel@tonic-gate 	} else {
21650Sstevel@tonic-gate 		mdb_printf("%3s ", "-");
21660Sstevel@tonic-gate 	}
21670Sstevel@tonic-gate 
21680Sstevel@tonic-gate 	mdb_printf("%4s %5s ", cpu->cpu_runrun ? "yes" : "no",
21690Sstevel@tonic-gate 	    cpu->cpu_kprunrun ? "yes" : "no");
21700Sstevel@tonic-gate 
21710Sstevel@tonic-gate 	if (cpu->cpu_last_swtch) {
21720Sstevel@tonic-gate 		clock_t lbolt;
21730Sstevel@tonic-gate 
21740Sstevel@tonic-gate 		if (mdb_vread(&lbolt, sizeof (lbolt), cid->cid_lbolt) == -1) {
21750Sstevel@tonic-gate 			mdb_warn("failed to read lbolt at %p", cid->cid_lbolt);
21760Sstevel@tonic-gate 			return (WALK_ERR);
21770Sstevel@tonic-gate 		}
21780Sstevel@tonic-gate 		mdb_printf("t-%-4d ", lbolt - cpu->cpu_last_swtch);
21790Sstevel@tonic-gate 	} else {
21800Sstevel@tonic-gate 		mdb_printf("%-6s ", "-");
21810Sstevel@tonic-gate 	}
21820Sstevel@tonic-gate 
21830Sstevel@tonic-gate 	mdb_printf("%0*p", CPUINFO_TWIDTH, cpu->cpu_thread);
21840Sstevel@tonic-gate 
21850Sstevel@tonic-gate 	if (cpu->cpu_thread == cpu->cpu_idle_thread)
21860Sstevel@tonic-gate 		mdb_printf(" (idle)\n");
21870Sstevel@tonic-gate 	else if (cpu->cpu_thread == NULL)
21880Sstevel@tonic-gate 		mdb_printf(" -\n");
21890Sstevel@tonic-gate 	else {
21900Sstevel@tonic-gate 		if (mdb_vread(&p, sizeof (p), (uintptr_t)t.t_procp) != -1) {
21910Sstevel@tonic-gate 			mdb_printf(" %s\n", p.p_user.u_comm);
21920Sstevel@tonic-gate 		} else {
21930Sstevel@tonic-gate 			mdb_printf(" ?\n");
21940Sstevel@tonic-gate 		}
21950Sstevel@tonic-gate 	}
21960Sstevel@tonic-gate 
21970Sstevel@tonic-gate 	flagbuf = mdb_zalloc(sizeof (flags), UM_SLEEP | UM_GC);
21980Sstevel@tonic-gate 
21990Sstevel@tonic-gate 	if (cid->cid_print_flags) {
22000Sstevel@tonic-gate 		int first = 1, i, j, k;
22010Sstevel@tonic-gate 		char *s;
22020Sstevel@tonic-gate 
22030Sstevel@tonic-gate 		cid->cid_print_head = TRUE;
22040Sstevel@tonic-gate 
22050Sstevel@tonic-gate 		for (i = 1, j = 0; flags[j] != NULL; i <<= 1, j++) {
22060Sstevel@tonic-gate 			if (!(cpu->cpu_flags & i))
22070Sstevel@tonic-gate 				continue;
22080Sstevel@tonic-gate 
22090Sstevel@tonic-gate 			if (first) {
22100Sstevel@tonic-gate 				s = mdb_alloc(CPUINFO_THRDELT + 1,
22110Sstevel@tonic-gate 				    UM_GC | UM_SLEEP);
22120Sstevel@tonic-gate 
22130Sstevel@tonic-gate 				(void) mdb_snprintf(s, CPUINFO_THRDELT + 1,
22140Sstevel@tonic-gate 				    "%*s|%*s", CPUINFO_FLAGDELT, "",
22150Sstevel@tonic-gate 				    CPUINFO_THRDELT - 1 - CPUINFO_FLAGDELT, "");
22160Sstevel@tonic-gate 				flagbuf[nflaglines++] = s;
22170Sstevel@tonic-gate 			}
22180Sstevel@tonic-gate 
22190Sstevel@tonic-gate 			s = mdb_alloc(CPUINFO_THRDELT + 1, UM_GC | UM_SLEEP);
22200Sstevel@tonic-gate 			(void) mdb_snprintf(s, CPUINFO_THRDELT + 1, "%*s%*s %s",
22210Sstevel@tonic-gate 			    CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH -
22220Sstevel@tonic-gate 			    CPUINFO_FLAGWIDTH, "", CPUINFO_FLAGWIDTH, flags[j],
22230Sstevel@tonic-gate 			    first ? "<--+" : "");
22240Sstevel@tonic-gate 
22250Sstevel@tonic-gate 			for (k = strlen(s); k < CPUINFO_THRDELT; k++)
22260Sstevel@tonic-gate 				s[k] = ' ';
22270Sstevel@tonic-gate 			s[k] = '\0';
22280Sstevel@tonic-gate 
22290Sstevel@tonic-gate 			flagbuf[nflaglines++] = s;
22300Sstevel@tonic-gate 			first = 0;
22310Sstevel@tonic-gate 		}
22320Sstevel@tonic-gate 	}
22330Sstevel@tonic-gate 
22340Sstevel@tonic-gate 	if (cid->cid_print_ithr) {
22350Sstevel@tonic-gate 		int i, found_one = FALSE;
22360Sstevel@tonic-gate 		int print_thr = disp.disp_nrunnable && cid->cid_print_thr;
22370Sstevel@tonic-gate 
22380Sstevel@tonic-gate 		for (i = NINTR - 1; i >= 0; i--) {
22390Sstevel@tonic-gate 			uintptr_t iaddr = cid->cid_ithr[cpu->cpu_id][i];
22400Sstevel@tonic-gate 
22410Sstevel@tonic-gate 			if (iaddr == NULL)
22420Sstevel@tonic-gate 				continue;
22430Sstevel@tonic-gate 
22440Sstevel@tonic-gate 			if (!found_one) {
22450Sstevel@tonic-gate 				found_one = TRUE;
22460Sstevel@tonic-gate 
22470Sstevel@tonic-gate 				CPUINFO_INDENT;
22480Sstevel@tonic-gate 				mdb_printf("%c%*s|\n", print_thr ? '|' : ' ',
22490Sstevel@tonic-gate 				    CPUINFO_ITHRDELT, "");
22500Sstevel@tonic-gate 
22510Sstevel@tonic-gate 				CPUINFO_INDENT;
22520Sstevel@tonic-gate 				mdb_printf("%c%*s+--> %3s %s\n",
22530Sstevel@tonic-gate 				    print_thr ? '|' : ' ', CPUINFO_ITHRDELT,
22540Sstevel@tonic-gate 				    "", "PIL", "THREAD");
22550Sstevel@tonic-gate 			}
22560Sstevel@tonic-gate 
22570Sstevel@tonic-gate 			if (mdb_vread(&t, sizeof (t), iaddr) == -1) {
22580Sstevel@tonic-gate 				mdb_warn("failed to read kthread_t at %p",
22590Sstevel@tonic-gate 				    iaddr);
22600Sstevel@tonic-gate 				return (WALK_ERR);
22610Sstevel@tonic-gate 			}
22620Sstevel@tonic-gate 
22630Sstevel@tonic-gate 			CPUINFO_INDENT;
22640Sstevel@tonic-gate 			mdb_printf("%c%*s     %3d %0*p\n",
22650Sstevel@tonic-gate 			    print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "",
22660Sstevel@tonic-gate 			    t.t_pil, CPUINFO_TWIDTH, iaddr);
22670Sstevel@tonic-gate 
22680Sstevel@tonic-gate 			pinned = (uintptr_t)t.t_intr;
22690Sstevel@tonic-gate 		}
22700Sstevel@tonic-gate 
22710Sstevel@tonic-gate 		if (found_one && pinned != NULL) {
22720Sstevel@tonic-gate 			cid->cid_print_head = TRUE;
22730Sstevel@tonic-gate 			(void) strcpy(p.p_user.u_comm, "?");
22740Sstevel@tonic-gate 
22750Sstevel@tonic-gate 			if (mdb_vread(&t, sizeof (t),
22760Sstevel@tonic-gate 			    (uintptr_t)pinned) == -1) {
22770Sstevel@tonic-gate 				mdb_warn("failed to read kthread_t at %p",
22780Sstevel@tonic-gate 				    pinned);
22790Sstevel@tonic-gate 				return (WALK_ERR);
22800Sstevel@tonic-gate 			}
22810Sstevel@tonic-gate 			if (mdb_vread(&p, sizeof (p),
22820Sstevel@tonic-gate 			    (uintptr_t)t.t_procp) == -1) {
22830Sstevel@tonic-gate 				mdb_warn("failed to read proc_t at %p",
22840Sstevel@tonic-gate 				    t.t_procp);
22850Sstevel@tonic-gate 				return (WALK_ERR);
22860Sstevel@tonic-gate 			}
22870Sstevel@tonic-gate 
22880Sstevel@tonic-gate 			CPUINFO_INDENT;
22890Sstevel@tonic-gate 			mdb_printf("%c%*s     %3s %0*p %s\n",
22900Sstevel@tonic-gate 			    print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", "-",
22910Sstevel@tonic-gate 			    CPUINFO_TWIDTH, pinned,
22920Sstevel@tonic-gate 			    pinned == (uintptr_t)cpu->cpu_idle_thread ?
22930Sstevel@tonic-gate 			    "(idle)" : p.p_user.u_comm);
22940Sstevel@tonic-gate 		}
22950Sstevel@tonic-gate 	}
22960Sstevel@tonic-gate 
22970Sstevel@tonic-gate 	if (disp.disp_nrunnable && cid->cid_print_thr) {
22980Sstevel@tonic-gate 		dispq_t *dq;
22990Sstevel@tonic-gate 
23000Sstevel@tonic-gate 		int i, npri = disp.disp_npri;
23010Sstevel@tonic-gate 
23020Sstevel@tonic-gate 		dq = mdb_alloc(sizeof (dispq_t) * npri, UM_SLEEP | UM_GC);
23030Sstevel@tonic-gate 
23040Sstevel@tonic-gate 		if (mdb_vread(dq, sizeof (dispq_t) * npri,
23050Sstevel@tonic-gate 		    (uintptr_t)disp.disp_q) == -1) {
23060Sstevel@tonic-gate 			mdb_warn("failed to read dispq_t at %p", disp.disp_q);
23070Sstevel@tonic-gate 			return (WALK_ERR);
23080Sstevel@tonic-gate 		}
23090Sstevel@tonic-gate 
23100Sstevel@tonic-gate 		CPUINFO_INDENT;
23110Sstevel@tonic-gate 		mdb_printf("|\n");
23120Sstevel@tonic-gate 
23130Sstevel@tonic-gate 		CPUINFO_INDENT;
23140Sstevel@tonic-gate 		mdb_printf("+-->  %3s %-*s %s\n", "PRI",
23150Sstevel@tonic-gate 		    CPUINFO_TWIDTH, "THREAD", "PROC");
23160Sstevel@tonic-gate 
23170Sstevel@tonic-gate 		for (i = npri - 1; i >= 0; i--) {
23180Sstevel@tonic-gate 			uintptr_t taddr = (uintptr_t)dq[i].dq_first;
23190Sstevel@tonic-gate 
23200Sstevel@tonic-gate 			while (taddr != NULL) {
23210Sstevel@tonic-gate 				if (mdb_vread(&t, sizeof (t), taddr) == -1) {
23220Sstevel@tonic-gate 					mdb_warn("failed to read kthread_t "
23230Sstevel@tonic-gate 					    "at %p", taddr);
23240Sstevel@tonic-gate 					return (WALK_ERR);
23250Sstevel@tonic-gate 				}
23260Sstevel@tonic-gate 				if (mdb_vread(&p, sizeof (p),
23270Sstevel@tonic-gate 				    (uintptr_t)t.t_procp) == -1) {
23280Sstevel@tonic-gate 					mdb_warn("failed to read proc_t at %p",
23290Sstevel@tonic-gate 					    t.t_procp);
23300Sstevel@tonic-gate 					return (WALK_ERR);
23310Sstevel@tonic-gate 				}
23320Sstevel@tonic-gate 
23330Sstevel@tonic-gate 				CPUINFO_INDENT;
23340Sstevel@tonic-gate 				mdb_printf("      %3d %0*p %s\n", t.t_pri,
23350Sstevel@tonic-gate 				    CPUINFO_TWIDTH, taddr, p.p_user.u_comm);
23360Sstevel@tonic-gate 
23370Sstevel@tonic-gate 				taddr = (uintptr_t)t.t_link;
23380Sstevel@tonic-gate 			}
23390Sstevel@tonic-gate 		}
23400Sstevel@tonic-gate 		cid->cid_print_head = TRUE;
23410Sstevel@tonic-gate 	}
23420Sstevel@tonic-gate 
23430Sstevel@tonic-gate 	while (flagline < nflaglines)
23440Sstevel@tonic-gate 		mdb_printf("%s\n", flagbuf[flagline++]);
23450Sstevel@tonic-gate 
23460Sstevel@tonic-gate 	if (cid->cid_print_head)
23470Sstevel@tonic-gate 		mdb_printf("\n");
23480Sstevel@tonic-gate 
23490Sstevel@tonic-gate 	return (rval);
23500Sstevel@tonic-gate }
23510Sstevel@tonic-gate 
23520Sstevel@tonic-gate int
23530Sstevel@tonic-gate cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
23540Sstevel@tonic-gate {
23550Sstevel@tonic-gate 	uint_t verbose = FALSE;
23560Sstevel@tonic-gate 	cpuinfo_data_t cid;
23570Sstevel@tonic-gate 	GElf_Sym sym;
23580Sstevel@tonic-gate 	clock_t lbolt;
23590Sstevel@tonic-gate 
23600Sstevel@tonic-gate 	cid.cid_print_ithr = FALSE;
23610Sstevel@tonic-gate 	cid.cid_print_thr = FALSE;
23620Sstevel@tonic-gate 	cid.cid_print_flags = FALSE;
23630Sstevel@tonic-gate 	cid.cid_print_head = DCMD_HDRSPEC(flags) ? TRUE : FALSE;
23640Sstevel@tonic-gate 	cid.cid_cpu = -1;
23650Sstevel@tonic-gate 
23660Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
23670Sstevel@tonic-gate 		cid.cid_cpu = addr;
23680Sstevel@tonic-gate 
23690Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
23700Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc)
23710Sstevel@tonic-gate 		return (DCMD_USAGE);
23720Sstevel@tonic-gate 
23730Sstevel@tonic-gate 	if (verbose) {
23740Sstevel@tonic-gate 		cid.cid_print_ithr = TRUE;
23750Sstevel@tonic-gate 		cid.cid_print_thr = TRUE;
23760Sstevel@tonic-gate 		cid.cid_print_flags = TRUE;
23770Sstevel@tonic-gate 		cid.cid_print_head = TRUE;
23780Sstevel@tonic-gate 	}
23790Sstevel@tonic-gate 
23800Sstevel@tonic-gate 	if (cid.cid_print_ithr) {
23810Sstevel@tonic-gate 		int i;
23820Sstevel@tonic-gate 
23830Sstevel@tonic-gate 		cid.cid_ithr = mdb_alloc(sizeof (uintptr_t **)
23840Sstevel@tonic-gate 		    * NCPU, UM_SLEEP | UM_GC);
23850Sstevel@tonic-gate 
23860Sstevel@tonic-gate 		for (i = 0; i < NCPU; i++)
23870Sstevel@tonic-gate 			cid.cid_ithr[i] = mdb_zalloc(sizeof (uintptr_t *) *
23880Sstevel@tonic-gate 			    NINTR, UM_SLEEP | UM_GC);
23890Sstevel@tonic-gate 
23900Sstevel@tonic-gate 		if (mdb_walk("thread", (mdb_walk_cb_t)cpuinfo_walk_ithread,
23910Sstevel@tonic-gate 		    &cid) == -1) {
23920Sstevel@tonic-gate 			mdb_warn("couldn't walk thread");
23930Sstevel@tonic-gate 			return (DCMD_ERR);
23940Sstevel@tonic-gate 		}
23950Sstevel@tonic-gate 	}
23960Sstevel@tonic-gate 
23970Sstevel@tonic-gate 	if (mdb_lookup_by_name("panic_lbolt", &sym) == -1) {
23980Sstevel@tonic-gate 		mdb_warn("failed to find panic_lbolt");
23990Sstevel@tonic-gate 		return (DCMD_ERR);
24000Sstevel@tonic-gate 	}
24010Sstevel@tonic-gate 
24020Sstevel@tonic-gate 	cid.cid_lbolt = (uintptr_t)sym.st_value;
24030Sstevel@tonic-gate 
24040Sstevel@tonic-gate 	if (mdb_vread(&lbolt, sizeof (lbolt), cid.cid_lbolt) == -1) {
24050Sstevel@tonic-gate 		mdb_warn("failed to read panic_lbolt");
24060Sstevel@tonic-gate 		return (DCMD_ERR);
24070Sstevel@tonic-gate 	}
24080Sstevel@tonic-gate 
24090Sstevel@tonic-gate 	if (lbolt == 0) {
24100Sstevel@tonic-gate 		if (mdb_lookup_by_name("lbolt", &sym) == -1) {
24110Sstevel@tonic-gate 			mdb_warn("failed to find lbolt");
24120Sstevel@tonic-gate 			return (DCMD_ERR);
24130Sstevel@tonic-gate 		}
24140Sstevel@tonic-gate 		cid.cid_lbolt = (uintptr_t)sym.st_value;
24150Sstevel@tonic-gate 	}
24160Sstevel@tonic-gate 
24170Sstevel@tonic-gate 	if (mdb_walk("cpu", (mdb_walk_cb_t)cpuinfo_walk_cpu, &cid) == -1) {
24180Sstevel@tonic-gate 		mdb_warn("can't walk cpus");
24190Sstevel@tonic-gate 		return (DCMD_ERR);
24200Sstevel@tonic-gate 	}
24210Sstevel@tonic-gate 
24220Sstevel@tonic-gate 	if (cid.cid_cpu != -1) {
24230Sstevel@tonic-gate 		/*
24240Sstevel@tonic-gate 		 * We didn't find this CPU when we walked through the CPUs
24250Sstevel@tonic-gate 		 * (i.e. the address specified doesn't show up in the "cpu"
24260Sstevel@tonic-gate 		 * walk).  However, the specified address may still correspond
24270Sstevel@tonic-gate 		 * to a valid cpu_t (for example, if the specified address is
24280Sstevel@tonic-gate 		 * the actual panicking cpu_t and not the cached panic_cpu).
24290Sstevel@tonic-gate 		 * Point is:  even if we didn't find it, we still want to try
24300Sstevel@tonic-gate 		 * to print the specified address as a cpu_t.
24310Sstevel@tonic-gate 		 */
24320Sstevel@tonic-gate 		cpu_t cpu;
24330Sstevel@tonic-gate 
24340Sstevel@tonic-gate 		if (mdb_vread(&cpu, sizeof (cpu), cid.cid_cpu) == -1) {
24350Sstevel@tonic-gate 			mdb_warn("%p is neither a valid CPU ID nor a "
24360Sstevel@tonic-gate 			    "valid cpu_t address\n", cid.cid_cpu);
24370Sstevel@tonic-gate 			return (DCMD_ERR);
24380Sstevel@tonic-gate 		}
24390Sstevel@tonic-gate 
24400Sstevel@tonic-gate 		(void) cpuinfo_walk_cpu(cid.cid_cpu, &cpu, &cid);
24410Sstevel@tonic-gate 	}
24420Sstevel@tonic-gate 
24430Sstevel@tonic-gate 	return (DCMD_OK);
24440Sstevel@tonic-gate }
24450Sstevel@tonic-gate 
24460Sstevel@tonic-gate /*ARGSUSED*/
24470Sstevel@tonic-gate int
24480Sstevel@tonic-gate flipone(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
24490Sstevel@tonic-gate {
24500Sstevel@tonic-gate 	int i;
24510Sstevel@tonic-gate 
24520Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
24530Sstevel@tonic-gate 		return (DCMD_USAGE);
24540Sstevel@tonic-gate 
24550Sstevel@tonic-gate 	for (i = 0; i < sizeof (addr) * NBBY; i++)
24560Sstevel@tonic-gate 		mdb_printf("%p\n", addr ^ (1UL << i));
24570Sstevel@tonic-gate 
24580Sstevel@tonic-gate 	return (DCMD_OK);
24590Sstevel@tonic-gate }
24600Sstevel@tonic-gate 
24610Sstevel@tonic-gate /*
24620Sstevel@tonic-gate  * Grumble, grumble.
24630Sstevel@tonic-gate  */
24640Sstevel@tonic-gate #define	SMAP_HASHFUNC(vp, off)	\
24650Sstevel@tonic-gate 	((((uintptr_t)(vp) >> 6) + ((uintptr_t)(vp) >> 3) + \
24660Sstevel@tonic-gate 	((off) >> MAXBSHIFT)) & smd_hashmsk)
24670Sstevel@tonic-gate 
24680Sstevel@tonic-gate int
24690Sstevel@tonic-gate vnode2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
24700Sstevel@tonic-gate {
24710Sstevel@tonic-gate 	long smd_hashmsk;
24720Sstevel@tonic-gate 	int hash;
24730Sstevel@tonic-gate 	uintptr_t offset = 0;
24740Sstevel@tonic-gate 	struct smap smp;
24750Sstevel@tonic-gate 	uintptr_t saddr, kaddr;
24760Sstevel@tonic-gate 	uintptr_t smd_hash, smd_smap;
24770Sstevel@tonic-gate 	struct seg seg;
24780Sstevel@tonic-gate 
24790Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
24800Sstevel@tonic-gate 		return (DCMD_USAGE);
24810Sstevel@tonic-gate 
24820Sstevel@tonic-gate 	if (mdb_readvar(&smd_hashmsk, "smd_hashmsk") == -1) {
24830Sstevel@tonic-gate 		mdb_warn("failed to read smd_hashmsk");
24840Sstevel@tonic-gate 		return (DCMD_ERR);
24850Sstevel@tonic-gate 	}
24860Sstevel@tonic-gate 
24870Sstevel@tonic-gate 	if (mdb_readvar(&smd_hash, "smd_hash") == -1) {
24880Sstevel@tonic-gate 		mdb_warn("failed to read smd_hash");
24890Sstevel@tonic-gate 		return (DCMD_ERR);
24900Sstevel@tonic-gate 	}
24910Sstevel@tonic-gate 
24920Sstevel@tonic-gate 	if (mdb_readvar(&smd_smap, "smd_smap") == -1) {
24930Sstevel@tonic-gate 		mdb_warn("failed to read smd_hash");
24940Sstevel@tonic-gate 		return (DCMD_ERR);
24950Sstevel@tonic-gate 	}
24960Sstevel@tonic-gate 
24970Sstevel@tonic-gate 	if (mdb_readvar(&kaddr, "segkmap") == -1) {
24980Sstevel@tonic-gate 		mdb_warn("failed to read segkmap");
24990Sstevel@tonic-gate 		return (DCMD_ERR);
25000Sstevel@tonic-gate 	}
25010Sstevel@tonic-gate 
25020Sstevel@tonic-gate 	if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) {
25030Sstevel@tonic-gate 		mdb_warn("failed to read segkmap at %p", kaddr);
25040Sstevel@tonic-gate 		return (DCMD_ERR);
25050Sstevel@tonic-gate 	}
25060Sstevel@tonic-gate 
25070Sstevel@tonic-gate 	if (argc != 0) {
25080Sstevel@tonic-gate 		const mdb_arg_t *arg = &argv[0];
25090Sstevel@tonic-gate 
25100Sstevel@tonic-gate 		if (arg->a_type == MDB_TYPE_IMMEDIATE)
25110Sstevel@tonic-gate 			offset = arg->a_un.a_val;
25120Sstevel@tonic-gate 		else
25130Sstevel@tonic-gate 			offset = (uintptr_t)mdb_strtoull(arg->a_un.a_str);
25140Sstevel@tonic-gate 	}
25150Sstevel@tonic-gate 
25160Sstevel@tonic-gate 	hash = SMAP_HASHFUNC(addr, offset);
25170Sstevel@tonic-gate 
25180Sstevel@tonic-gate 	if (mdb_vread(&saddr, sizeof (saddr),
25190Sstevel@tonic-gate 	    smd_hash + hash * sizeof (uintptr_t)) == -1) {
25200Sstevel@tonic-gate 		mdb_warn("couldn't read smap at %p",
25210Sstevel@tonic-gate 		    smd_hash + hash * sizeof (uintptr_t));
25220Sstevel@tonic-gate 		return (DCMD_ERR);
25230Sstevel@tonic-gate 	}
25240Sstevel@tonic-gate 
25250Sstevel@tonic-gate 	do {
25260Sstevel@tonic-gate 		if (mdb_vread(&smp, sizeof (smp), saddr) == -1) {
25270Sstevel@tonic-gate 			mdb_warn("couldn't read smap at %p", saddr);
25280Sstevel@tonic-gate 			return (DCMD_ERR);
25290Sstevel@tonic-gate 		}
25300Sstevel@tonic-gate 
25310Sstevel@tonic-gate 		if ((uintptr_t)smp.sm_vp == addr && smp.sm_off == offset) {
25320Sstevel@tonic-gate 			mdb_printf("vnode %p, offs %p is smap %p, vaddr %p\n",
25330Sstevel@tonic-gate 			    addr, offset, saddr, ((saddr - smd_smap) /
25340Sstevel@tonic-gate 			    sizeof (smp)) * MAXBSIZE + seg.s_base);
25350Sstevel@tonic-gate 			return (DCMD_OK);
25360Sstevel@tonic-gate 		}
25370Sstevel@tonic-gate 
25380Sstevel@tonic-gate 		saddr = (uintptr_t)smp.sm_hash;
25390Sstevel@tonic-gate 	} while (saddr != NULL);
25400Sstevel@tonic-gate 
25410Sstevel@tonic-gate 	mdb_printf("no smap for vnode %p, offs %p\n", addr, offset);
25420Sstevel@tonic-gate 	return (DCMD_OK);
25430Sstevel@tonic-gate }
25440Sstevel@tonic-gate 
25450Sstevel@tonic-gate /*ARGSUSED*/
25460Sstevel@tonic-gate int
25470Sstevel@tonic-gate addr2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
25480Sstevel@tonic-gate {
25490Sstevel@tonic-gate 	uintptr_t kaddr;
25500Sstevel@tonic-gate 	struct seg seg;
25510Sstevel@tonic-gate 	struct segmap_data sd;
25520Sstevel@tonic-gate 
25530Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
25540Sstevel@tonic-gate 		return (DCMD_USAGE);
25550Sstevel@tonic-gate 
25560Sstevel@tonic-gate 	if (mdb_readvar(&kaddr, "segkmap") == -1) {
25570Sstevel@tonic-gate 		mdb_warn("failed to read segkmap");
25580Sstevel@tonic-gate 		return (DCMD_ERR);
25590Sstevel@tonic-gate 	}
25600Sstevel@tonic-gate 
25610Sstevel@tonic-gate 	if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) {
25620Sstevel@tonic-gate 		mdb_warn("failed to read segkmap at %p", kaddr);
25630Sstevel@tonic-gate 		return (DCMD_ERR);
25640Sstevel@tonic-gate 	}
25650Sstevel@tonic-gate 
25660Sstevel@tonic-gate 	if (mdb_vread(&sd, sizeof (sd), (uintptr_t)seg.s_data) == -1) {
25670Sstevel@tonic-gate 		mdb_warn("failed to read segmap_data at %p", seg.s_data);
25680Sstevel@tonic-gate 		return (DCMD_ERR);
25690Sstevel@tonic-gate 	}
25700Sstevel@tonic-gate 
25710Sstevel@tonic-gate 	mdb_printf("%p is smap %p\n", addr,
25720Sstevel@tonic-gate 	    ((addr - (uintptr_t)seg.s_base) >> MAXBSHIFT) *
25730Sstevel@tonic-gate 	    sizeof (struct smap) + (uintptr_t)sd.smd_sm);
25740Sstevel@tonic-gate 
25750Sstevel@tonic-gate 	return (DCMD_OK);
25760Sstevel@tonic-gate }
25770Sstevel@tonic-gate 
25780Sstevel@tonic-gate int
25790Sstevel@tonic-gate as2proc_walk(uintptr_t addr, const proc_t *p, struct as **asp)
25800Sstevel@tonic-gate {
25810Sstevel@tonic-gate 	if (p->p_as == *asp)
25820Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
25830Sstevel@tonic-gate 	return (WALK_NEXT);
25840Sstevel@tonic-gate }
25850Sstevel@tonic-gate 
25860Sstevel@tonic-gate /*ARGSUSED*/
25870Sstevel@tonic-gate int
25880Sstevel@tonic-gate as2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
25890Sstevel@tonic-gate {
25900Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC) || argc != 0)
25910Sstevel@tonic-gate 		return (DCMD_USAGE);
25920Sstevel@tonic-gate 
25930Sstevel@tonic-gate 	if (mdb_walk("proc", (mdb_walk_cb_t)as2proc_walk, &addr) == -1) {
25940Sstevel@tonic-gate 		mdb_warn("failed to walk proc");
25950Sstevel@tonic-gate 		return (DCMD_ERR);
25960Sstevel@tonic-gate 	}
25970Sstevel@tonic-gate 
25980Sstevel@tonic-gate 	return (DCMD_OK);
25990Sstevel@tonic-gate }
26000Sstevel@tonic-gate 
26010Sstevel@tonic-gate /*ARGSUSED*/
26020Sstevel@tonic-gate int
26030Sstevel@tonic-gate ptree_walk(uintptr_t addr, const proc_t *p, void *ignored)
26040Sstevel@tonic-gate {
26050Sstevel@tonic-gate 	proc_t parent;
26060Sstevel@tonic-gate 	int ident = 0;
26070Sstevel@tonic-gate 	uintptr_t paddr;
26080Sstevel@tonic-gate 
26090Sstevel@tonic-gate 	for (paddr = (uintptr_t)p->p_parent; paddr != NULL; ident += 5) {
26100Sstevel@tonic-gate 		mdb_vread(&parent, sizeof (parent), paddr);
26110Sstevel@tonic-gate 		paddr = (uintptr_t)parent.p_parent;
26120Sstevel@tonic-gate 	}
26130Sstevel@tonic-gate 
26140Sstevel@tonic-gate 	mdb_inc_indent(ident);
26150Sstevel@tonic-gate 	mdb_printf("%0?p  %s\n", addr, p->p_user.u_comm);
26160Sstevel@tonic-gate 	mdb_dec_indent(ident);
26170Sstevel@tonic-gate 
26180Sstevel@tonic-gate 	return (WALK_NEXT);
26190Sstevel@tonic-gate }
26200Sstevel@tonic-gate 
26210Sstevel@tonic-gate void
26220Sstevel@tonic-gate ptree_ancestors(uintptr_t addr, uintptr_t start)
26230Sstevel@tonic-gate {
26240Sstevel@tonic-gate 	proc_t p;
26250Sstevel@tonic-gate 
26260Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (p), addr) == -1) {
26270Sstevel@tonic-gate 		mdb_warn("couldn't read ancestor at %p", addr);
26280Sstevel@tonic-gate 		return;
26290Sstevel@tonic-gate 	}
26300Sstevel@tonic-gate 
26310Sstevel@tonic-gate 	if (p.p_parent != NULL)
26320Sstevel@tonic-gate 		ptree_ancestors((uintptr_t)p.p_parent, start);
26330Sstevel@tonic-gate 
26340Sstevel@tonic-gate 	if (addr != start)
26350Sstevel@tonic-gate 		(void) ptree_walk(addr, &p, NULL);
26360Sstevel@tonic-gate }
26370Sstevel@tonic-gate 
26380Sstevel@tonic-gate /*ARGSUSED*/
26390Sstevel@tonic-gate int
26400Sstevel@tonic-gate ptree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
26410Sstevel@tonic-gate {
26420Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
26430Sstevel@tonic-gate 		addr = NULL;
26440Sstevel@tonic-gate 	else
26450Sstevel@tonic-gate 		ptree_ancestors(addr, addr);
26460Sstevel@tonic-gate 
26470Sstevel@tonic-gate 	if (mdb_pwalk("proc", (mdb_walk_cb_t)ptree_walk, NULL, addr) == -1) {
26480Sstevel@tonic-gate 		mdb_warn("couldn't walk 'proc'");
26490Sstevel@tonic-gate 		return (DCMD_ERR);
26500Sstevel@tonic-gate 	}
26510Sstevel@tonic-gate 
26520Sstevel@tonic-gate 	return (DCMD_OK);
26530Sstevel@tonic-gate }
26540Sstevel@tonic-gate 
26550Sstevel@tonic-gate /*ARGSUSED*/
26560Sstevel@tonic-gate static int
26570Sstevel@tonic-gate fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
26580Sstevel@tonic-gate {
26590Sstevel@tonic-gate 	int fdnum;
26600Sstevel@tonic-gate 	const mdb_arg_t *argp = &argv[0];
26610Sstevel@tonic-gate 	proc_t p;
26620Sstevel@tonic-gate 	uf_entry_t uf;
26630Sstevel@tonic-gate 
26640Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
26650Sstevel@tonic-gate 		mdb_warn("fd doesn't give global information\n");
26660Sstevel@tonic-gate 		return (DCMD_ERR);
26670Sstevel@tonic-gate 	}
26680Sstevel@tonic-gate 	if (argc != 1)
26690Sstevel@tonic-gate 		return (DCMD_USAGE);
26700Sstevel@tonic-gate 
26710Sstevel@tonic-gate 	if (argp->a_type == MDB_TYPE_IMMEDIATE)
26720Sstevel@tonic-gate 		fdnum = argp->a_un.a_val;
26730Sstevel@tonic-gate 	else
26740Sstevel@tonic-gate 		fdnum = mdb_strtoull(argp->a_un.a_str);
26750Sstevel@tonic-gate 
26760Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (struct proc), addr) == -1) {
26770Sstevel@tonic-gate 		mdb_warn("couldn't read proc_t at %p", addr);
26780Sstevel@tonic-gate 		return (DCMD_ERR);
26790Sstevel@tonic-gate 	}
26800Sstevel@tonic-gate 	if (fdnum > p.p_user.u_finfo.fi_nfiles) {
26810Sstevel@tonic-gate 		mdb_warn("process %p only has %d files open.\n",
26820Sstevel@tonic-gate 		    addr, p.p_user.u_finfo.fi_nfiles);
26830Sstevel@tonic-gate 		return (DCMD_ERR);
26840Sstevel@tonic-gate 	}
26850Sstevel@tonic-gate 	if (mdb_vread(&uf, sizeof (uf_entry_t),
26860Sstevel@tonic-gate 	    (uintptr_t)&p.p_user.u_finfo.fi_list[fdnum]) == -1) {
26870Sstevel@tonic-gate 		mdb_warn("couldn't read uf_entry_t at %p",
26880Sstevel@tonic-gate 		    &p.p_user.u_finfo.fi_list[fdnum]);
26890Sstevel@tonic-gate 		return (DCMD_ERR);
26900Sstevel@tonic-gate 	}
26910Sstevel@tonic-gate 
26920Sstevel@tonic-gate 	mdb_printf("%p\n", uf.uf_file);
26930Sstevel@tonic-gate 	return (DCMD_OK);
26940Sstevel@tonic-gate }
26950Sstevel@tonic-gate 
26960Sstevel@tonic-gate /*ARGSUSED*/
26970Sstevel@tonic-gate static int
26980Sstevel@tonic-gate pid2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
26990Sstevel@tonic-gate {
27000Sstevel@tonic-gate 	pid_t pid = (pid_t)addr;
27010Sstevel@tonic-gate 
27020Sstevel@tonic-gate 	if (argc != 0)
27030Sstevel@tonic-gate 		return (DCMD_USAGE);
27040Sstevel@tonic-gate 
27050Sstevel@tonic-gate 	if ((addr = mdb_pid2proc(pid, NULL)) == NULL) {
27060Sstevel@tonic-gate 		mdb_warn("PID 0t%d not found\n", pid);
27070Sstevel@tonic-gate 		return (DCMD_ERR);
27080Sstevel@tonic-gate 	}
27090Sstevel@tonic-gate 
27100Sstevel@tonic-gate 	mdb_printf("%p\n", addr);
27110Sstevel@tonic-gate 	return (DCMD_OK);
27120Sstevel@tonic-gate }
27130Sstevel@tonic-gate 
27140Sstevel@tonic-gate static char *sysfile_cmd[] = {
27150Sstevel@tonic-gate 	"exclude:",
27160Sstevel@tonic-gate 	"include:",
27170Sstevel@tonic-gate 	"forceload:",
27180Sstevel@tonic-gate 	"rootdev:",
27190Sstevel@tonic-gate 	"rootfs:",
27200Sstevel@tonic-gate 	"swapdev:",
27210Sstevel@tonic-gate 	"swapfs:",
27220Sstevel@tonic-gate 	"moddir:",
27230Sstevel@tonic-gate 	"set",
27240Sstevel@tonic-gate 	"unknown",
27250Sstevel@tonic-gate };
27260Sstevel@tonic-gate 
27270Sstevel@tonic-gate static char *sysfile_ops[] = { "", "=", "&", "|" };
27280Sstevel@tonic-gate 
27290Sstevel@tonic-gate /*ARGSUSED*/
27300Sstevel@tonic-gate static int
27310Sstevel@tonic-gate sysfile_vmem_seg(uintptr_t addr, const vmem_seg_t *vsp, void **target)
27320Sstevel@tonic-gate {
27330Sstevel@tonic-gate 	if (vsp->vs_type == VMEM_ALLOC && (void *)vsp->vs_start == *target) {
27340Sstevel@tonic-gate 		*target = NULL;
27350Sstevel@tonic-gate 		return (WALK_DONE);
27360Sstevel@tonic-gate 	}
27370Sstevel@tonic-gate 	return (WALK_NEXT);
27380Sstevel@tonic-gate }
27390Sstevel@tonic-gate 
27400Sstevel@tonic-gate /*ARGSUSED*/
27410Sstevel@tonic-gate static int
27420Sstevel@tonic-gate sysfile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
27430Sstevel@tonic-gate {
27440Sstevel@tonic-gate 	struct sysparam *sysp, sys;
27450Sstevel@tonic-gate 	char var[256];
27460Sstevel@tonic-gate 	char modname[256];
27470Sstevel@tonic-gate 	char val[256];
27480Sstevel@tonic-gate 	char strval[256];
27490Sstevel@tonic-gate 	vmem_t *mod_sysfile_arena;
27500Sstevel@tonic-gate 	void *straddr;
27510Sstevel@tonic-gate 
27520Sstevel@tonic-gate 	if (mdb_readvar(&sysp, "sysparam_hd") == -1) {
27530Sstevel@tonic-gate 		mdb_warn("failed to read sysparam_hd");
27540Sstevel@tonic-gate 		return (DCMD_ERR);
27550Sstevel@tonic-gate 	}
27560Sstevel@tonic-gate 
27570Sstevel@tonic-gate 	if (mdb_readvar(&mod_sysfile_arena, "mod_sysfile_arena") == -1) {
27580Sstevel@tonic-gate 		mdb_warn("failed to read mod_sysfile_arena");
27590Sstevel@tonic-gate 		return (DCMD_ERR);
27600Sstevel@tonic-gate 	}
27610Sstevel@tonic-gate 
27620Sstevel@tonic-gate 	while (sysp != NULL) {
27630Sstevel@tonic-gate 		var[0] = '\0';
27640Sstevel@tonic-gate 		val[0] = '\0';
27650Sstevel@tonic-gate 		modname[0] = '\0';
27660Sstevel@tonic-gate 		if (mdb_vread(&sys, sizeof (sys), (uintptr_t)sysp) == -1) {
27670Sstevel@tonic-gate 			mdb_warn("couldn't read sysparam %p", sysp);
27680Sstevel@tonic-gate 			return (DCMD_ERR);
27690Sstevel@tonic-gate 		}
27700Sstevel@tonic-gate 		if (sys.sys_modnam != NULL &&
27710Sstevel@tonic-gate 		    mdb_readstr(modname, 256,
27720Sstevel@tonic-gate 		    (uintptr_t)sys.sys_modnam) == -1) {
27730Sstevel@tonic-gate 			mdb_warn("couldn't read modname in %p", sysp);
27740Sstevel@tonic-gate 			return (DCMD_ERR);
27750Sstevel@tonic-gate 		}
27760Sstevel@tonic-gate 		if (sys.sys_ptr != NULL &&
27770Sstevel@tonic-gate 		    mdb_readstr(var, 256, (uintptr_t)sys.sys_ptr) == -1) {
27780Sstevel@tonic-gate 			mdb_warn("couldn't read ptr in %p", sysp);
27790Sstevel@tonic-gate 			return (DCMD_ERR);
27800Sstevel@tonic-gate 		}
27810Sstevel@tonic-gate 		if (sys.sys_op != SETOP_NONE) {
27820Sstevel@tonic-gate 			/*
27830Sstevel@tonic-gate 			 * Is this an int or a string?  We determine this
27840Sstevel@tonic-gate 			 * by checking whether straddr is contained in
27850Sstevel@tonic-gate 			 * mod_sysfile_arena.  If so, the walker will set
27860Sstevel@tonic-gate 			 * straddr to NULL.
27870Sstevel@tonic-gate 			 */
27880Sstevel@tonic-gate 			straddr = (void *)(uintptr_t)sys.sys_info;
27890Sstevel@tonic-gate 			if (sys.sys_op == SETOP_ASSIGN &&
27900Sstevel@tonic-gate 			    sys.sys_info != 0 &&
27910Sstevel@tonic-gate 			    mdb_pwalk("vmem_seg",
27920Sstevel@tonic-gate 			    (mdb_walk_cb_t)sysfile_vmem_seg, &straddr,
27930Sstevel@tonic-gate 			    (uintptr_t)mod_sysfile_arena) == 0 &&
27940Sstevel@tonic-gate 			    straddr == NULL &&
27950Sstevel@tonic-gate 			    mdb_readstr(strval, 256,
27960Sstevel@tonic-gate 			    (uintptr_t)sys.sys_info) != -1) {
27970Sstevel@tonic-gate 				(void) mdb_snprintf(val, sizeof (val), "\"%s\"",
27980Sstevel@tonic-gate 				    strval);
27990Sstevel@tonic-gate 			} else {
28000Sstevel@tonic-gate 				(void) mdb_snprintf(val, sizeof (val),
28010Sstevel@tonic-gate 				    "0x%llx [0t%llu]", sys.sys_info,
28020Sstevel@tonic-gate 				    sys.sys_info);
28030Sstevel@tonic-gate 			}
28040Sstevel@tonic-gate 		}
28050Sstevel@tonic-gate 		mdb_printf("%s %s%s%s%s%s\n", sysfile_cmd[sys.sys_type],
28060Sstevel@tonic-gate 		    modname, modname[0] == '\0' ? "" : ":",
28070Sstevel@tonic-gate 		    var, sysfile_ops[sys.sys_op], val);
28080Sstevel@tonic-gate 
28090Sstevel@tonic-gate 		sysp = sys.sys_next;
28100Sstevel@tonic-gate 	}
28110Sstevel@tonic-gate 
28120Sstevel@tonic-gate 	return (DCMD_OK);
28130Sstevel@tonic-gate }
28140Sstevel@tonic-gate 
28150Sstevel@tonic-gate /*
28160Sstevel@tonic-gate  * Dump a taskq_ent_t given its address.
28170Sstevel@tonic-gate  */
28180Sstevel@tonic-gate /*ARGSUSED*/
28190Sstevel@tonic-gate int
28200Sstevel@tonic-gate taskq_ent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
28210Sstevel@tonic-gate {
28220Sstevel@tonic-gate 	taskq_ent_t	taskq_ent;
28230Sstevel@tonic-gate 	GElf_Sym	sym;
28240Sstevel@tonic-gate 	char		buf[MDB_SYM_NAMLEN+1];
28250Sstevel@tonic-gate 
28260Sstevel@tonic-gate 
28270Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
28280Sstevel@tonic-gate 		mdb_warn("expected explicit taskq_ent_t address before ::\n");
28290Sstevel@tonic-gate 		return (DCMD_USAGE);
28300Sstevel@tonic-gate 	}
28310Sstevel@tonic-gate 
28320Sstevel@tonic-gate 	if (mdb_vread(&taskq_ent, sizeof (taskq_ent_t), addr) == -1) {
28330Sstevel@tonic-gate 		mdb_warn("failed to read taskq_ent_t at %p", addr);
28340Sstevel@tonic-gate 		return (DCMD_ERR);
28350Sstevel@tonic-gate 	}
28360Sstevel@tonic-gate 
28370Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
28380Sstevel@tonic-gate 		mdb_printf("%<u>%-?s    %-?s    %-s%</u>\n",
28390Sstevel@tonic-gate 		"ENTRY", "ARG", "FUNCTION");
28400Sstevel@tonic-gate 	}
28410Sstevel@tonic-gate 
28420Sstevel@tonic-gate 	if (mdb_lookup_by_addr((uintptr_t)taskq_ent.tqent_func, MDB_SYM_EXACT,
28430Sstevel@tonic-gate 	    buf, sizeof (buf), &sym) == -1) {
28440Sstevel@tonic-gate 		(void) strcpy(buf, "????");
28450Sstevel@tonic-gate 	}
28460Sstevel@tonic-gate 
28470Sstevel@tonic-gate 	mdb_printf("%-?p    %-?p    %s\n", addr, taskq_ent.tqent_arg, buf);
28480Sstevel@tonic-gate 
28490Sstevel@tonic-gate 	return (DCMD_OK);
28500Sstevel@tonic-gate }
28510Sstevel@tonic-gate 
28520Sstevel@tonic-gate /*
28530Sstevel@tonic-gate  * Given the address of the (taskq_t) task queue head, walk the queue listing
28540Sstevel@tonic-gate  * the address of every taskq_ent_t.
28550Sstevel@tonic-gate  */
28560Sstevel@tonic-gate int
28570Sstevel@tonic-gate taskq_walk_init(mdb_walk_state_t *wsp)
28580Sstevel@tonic-gate {
28590Sstevel@tonic-gate 	taskq_t	tq_head;
28600Sstevel@tonic-gate 
28610Sstevel@tonic-gate 
28620Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
28630Sstevel@tonic-gate 		mdb_warn("start address required\n");
28640Sstevel@tonic-gate 		return (WALK_ERR);
28650Sstevel@tonic-gate 	}
28660Sstevel@tonic-gate 
28670Sstevel@tonic-gate 
28680Sstevel@tonic-gate 	/*
28690Sstevel@tonic-gate 	 * Save the address of the list head entry.  This terminates the list.
28700Sstevel@tonic-gate 	 */
28710Sstevel@tonic-gate 	wsp->walk_data = (void *)
28720Sstevel@tonic-gate 	    ((size_t)wsp->walk_addr + offsetof(taskq_t, tq_task));
28730Sstevel@tonic-gate 
28740Sstevel@tonic-gate 
28750Sstevel@tonic-gate 	/*
28760Sstevel@tonic-gate 	 * Read in taskq head, set walk_addr to point to first taskq_ent_t.
28770Sstevel@tonic-gate 	 */
28780Sstevel@tonic-gate 	if (mdb_vread((void *)&tq_head, sizeof (taskq_t), wsp->walk_addr) ==
28790Sstevel@tonic-gate 	    -1) {
28800Sstevel@tonic-gate 		mdb_warn("failed to read taskq list head at %p",
28810Sstevel@tonic-gate 		    wsp->walk_addr);
28820Sstevel@tonic-gate 	}
28830Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)tq_head.tq_task.tqent_next;
28840Sstevel@tonic-gate 
28850Sstevel@tonic-gate 
28860Sstevel@tonic-gate 	/*
28870Sstevel@tonic-gate 	 * Check for null list (next=head)
28880Sstevel@tonic-gate 	 */
28890Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data) {
28900Sstevel@tonic-gate 		return (WALK_DONE);
28910Sstevel@tonic-gate 	}
28920Sstevel@tonic-gate 
28930Sstevel@tonic-gate 	return (WALK_NEXT);
28940Sstevel@tonic-gate }
28950Sstevel@tonic-gate 
28960Sstevel@tonic-gate 
28970Sstevel@tonic-gate int
28980Sstevel@tonic-gate taskq_walk_step(mdb_walk_state_t *wsp)
28990Sstevel@tonic-gate {
29000Sstevel@tonic-gate 	taskq_ent_t	tq_ent;
29010Sstevel@tonic-gate 	int		status;
29020Sstevel@tonic-gate 
29030Sstevel@tonic-gate 
29040Sstevel@tonic-gate 	if (mdb_vread((void *)&tq_ent, sizeof (taskq_ent_t), wsp->walk_addr) ==
29050Sstevel@tonic-gate 	    -1) {
29060Sstevel@tonic-gate 		mdb_warn("failed to read taskq_ent_t at %p", wsp->walk_addr);
29070Sstevel@tonic-gate 		return (DCMD_ERR);
29080Sstevel@tonic-gate 	}
29090Sstevel@tonic-gate 
29100Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, (void *)&tq_ent,
29110Sstevel@tonic-gate 	    wsp->walk_cbdata);
29120Sstevel@tonic-gate 
29130Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)tq_ent.tqent_next;
29140Sstevel@tonic-gate 
29150Sstevel@tonic-gate 
29160Sstevel@tonic-gate 	/* Check if we're at the last element (next=head) */
29170Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data) {
29180Sstevel@tonic-gate 		return (WALK_DONE);
29190Sstevel@tonic-gate 	}
29200Sstevel@tonic-gate 
29210Sstevel@tonic-gate 	return (status);
29220Sstevel@tonic-gate }
29230Sstevel@tonic-gate 
29240Sstevel@tonic-gate int
29250Sstevel@tonic-gate didmatch(uintptr_t addr, const kthread_t *thr, kt_did_t *didp)
29260Sstevel@tonic-gate {
29270Sstevel@tonic-gate 
29280Sstevel@tonic-gate 	if (*didp == thr->t_did) {
29290Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
29300Sstevel@tonic-gate 		return (WALK_DONE);
29310Sstevel@tonic-gate 	} else
29320Sstevel@tonic-gate 		return (WALK_NEXT);
29330Sstevel@tonic-gate }
29340Sstevel@tonic-gate 
29350Sstevel@tonic-gate /*ARGSUSED*/
29360Sstevel@tonic-gate int
29370Sstevel@tonic-gate did2thread(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
29380Sstevel@tonic-gate {
29390Sstevel@tonic-gate 	const mdb_arg_t *argp = &argv[0];
29400Sstevel@tonic-gate 	kt_did_t	did;
29410Sstevel@tonic-gate 
29420Sstevel@tonic-gate 	if (argc != 1)
29430Sstevel@tonic-gate 		return (DCMD_USAGE);
29440Sstevel@tonic-gate 
29450Sstevel@tonic-gate 	did = (kt_did_t)mdb_strtoull(argp->a_un.a_str);
29460Sstevel@tonic-gate 
29470Sstevel@tonic-gate 	if (mdb_walk("thread", (mdb_walk_cb_t)didmatch, (void *)&did) == -1) {
29480Sstevel@tonic-gate 		mdb_warn("failed to walk thread");
29490Sstevel@tonic-gate 		return (DCMD_ERR);
29500Sstevel@tonic-gate 
29510Sstevel@tonic-gate 	}
29520Sstevel@tonic-gate 	return (DCMD_OK);
29530Sstevel@tonic-gate 
29540Sstevel@tonic-gate }
29550Sstevel@tonic-gate 
29560Sstevel@tonic-gate static int
29570Sstevel@tonic-gate errorq_walk_init(mdb_walk_state_t *wsp)
29580Sstevel@tonic-gate {
29590Sstevel@tonic-gate 	if (wsp->walk_addr == NULL &&
29600Sstevel@tonic-gate 	    mdb_readvar(&wsp->walk_addr, "errorq_list") == -1) {
29610Sstevel@tonic-gate 		mdb_warn("failed to read errorq_list");
29620Sstevel@tonic-gate 		return (WALK_ERR);
29630Sstevel@tonic-gate 	}
29640Sstevel@tonic-gate 
29650Sstevel@tonic-gate 	return (WALK_NEXT);
29660Sstevel@tonic-gate }
29670Sstevel@tonic-gate 
29680Sstevel@tonic-gate static int
29690Sstevel@tonic-gate errorq_walk_step(mdb_walk_state_t *wsp)
29700Sstevel@tonic-gate {
29710Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
29720Sstevel@tonic-gate 	errorq_t eq;
29730Sstevel@tonic-gate 
29740Sstevel@tonic-gate 	if (addr == NULL)
29750Sstevel@tonic-gate 		return (WALK_DONE);
29760Sstevel@tonic-gate 
29770Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), addr) == -1) {
29780Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", addr);
29790Sstevel@tonic-gate 		return (WALK_ERR);
29800Sstevel@tonic-gate 	}
29810Sstevel@tonic-gate 
29820Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)eq.eq_next;
29830Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &eq, wsp->walk_cbdata));
29840Sstevel@tonic-gate }
29850Sstevel@tonic-gate 
29860Sstevel@tonic-gate typedef struct eqd_walk_data {
29870Sstevel@tonic-gate 	uintptr_t *eqd_stack;
29880Sstevel@tonic-gate 	void *eqd_buf;
29890Sstevel@tonic-gate 	ulong_t eqd_qpos;
29900Sstevel@tonic-gate 	ulong_t eqd_qlen;
29910Sstevel@tonic-gate 	size_t eqd_size;
29920Sstevel@tonic-gate } eqd_walk_data_t;
29930Sstevel@tonic-gate 
29940Sstevel@tonic-gate /*
29950Sstevel@tonic-gate  * In order to walk the list of pending error queue elements, we push the
29960Sstevel@tonic-gate  * addresses of the corresponding data buffers in to the eqd_stack array.
29970Sstevel@tonic-gate  * The error lists are in reverse chronological order when iterating using
29980Sstevel@tonic-gate  * eqe_prev, so we then pop things off the top in eqd_walk_step so that the
29990Sstevel@tonic-gate  * walker client gets addresses in order from oldest error to newest error.
30000Sstevel@tonic-gate  */
30010Sstevel@tonic-gate static void
30020Sstevel@tonic-gate eqd_push_list(eqd_walk_data_t *eqdp, uintptr_t addr)
30030Sstevel@tonic-gate {
30040Sstevel@tonic-gate 	errorq_elem_t eqe;
30050Sstevel@tonic-gate 
30060Sstevel@tonic-gate 	while (addr != NULL) {
30070Sstevel@tonic-gate 		if (mdb_vread(&eqe, sizeof (eqe), addr) != sizeof (eqe)) {
30080Sstevel@tonic-gate 			mdb_warn("failed to read errorq element at %p", addr);
30090Sstevel@tonic-gate 			break;
30100Sstevel@tonic-gate 		}
30110Sstevel@tonic-gate 
30120Sstevel@tonic-gate 		if (eqdp->eqd_qpos == eqdp->eqd_qlen) {
30130Sstevel@tonic-gate 			mdb_warn("errorq is overfull -- more than %lu "
30140Sstevel@tonic-gate 			    "elems found\n", eqdp->eqd_qlen);
30150Sstevel@tonic-gate 			break;
30160Sstevel@tonic-gate 		}
30170Sstevel@tonic-gate 
30180Sstevel@tonic-gate 		eqdp->eqd_stack[eqdp->eqd_qpos++] = (uintptr_t)eqe.eqe_data;
30190Sstevel@tonic-gate 		addr = (uintptr_t)eqe.eqe_prev;
30200Sstevel@tonic-gate 	}
30210Sstevel@tonic-gate }
30220Sstevel@tonic-gate 
30230Sstevel@tonic-gate static int
30240Sstevel@tonic-gate eqd_walk_init(mdb_walk_state_t *wsp)
30250Sstevel@tonic-gate {
30260Sstevel@tonic-gate 	eqd_walk_data_t *eqdp;
30270Sstevel@tonic-gate 	errorq_elem_t eqe, *addr;
30280Sstevel@tonic-gate 	errorq_t eq;
30290Sstevel@tonic-gate 	ulong_t i;
30300Sstevel@tonic-gate 
30310Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), wsp->walk_addr) == -1) {
30320Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", wsp->walk_addr);
30330Sstevel@tonic-gate 		return (WALK_ERR);
30340Sstevel@tonic-gate 	}
30350Sstevel@tonic-gate 
30360Sstevel@tonic-gate 	if (eq.eq_ptail != NULL &&
30370Sstevel@tonic-gate 	    mdb_vread(&eqe, sizeof (eqe), (uintptr_t)eq.eq_ptail) == -1) {
30380Sstevel@tonic-gate 		mdb_warn("failed to read errorq element at %p", eq.eq_ptail);
30390Sstevel@tonic-gate 		return (WALK_ERR);
30400Sstevel@tonic-gate 	}
30410Sstevel@tonic-gate 
30420Sstevel@tonic-gate 	eqdp = mdb_alloc(sizeof (eqd_walk_data_t), UM_SLEEP);
30430Sstevel@tonic-gate 	wsp->walk_data = eqdp;
30440Sstevel@tonic-gate 
30450Sstevel@tonic-gate 	eqdp->eqd_stack = mdb_zalloc(sizeof (uintptr_t) * eq.eq_qlen, UM_SLEEP);
30460Sstevel@tonic-gate 	eqdp->eqd_buf = mdb_alloc(eq.eq_size, UM_SLEEP);
30470Sstevel@tonic-gate 	eqdp->eqd_qlen = eq.eq_qlen;
30480Sstevel@tonic-gate 	eqdp->eqd_qpos = 0;
30490Sstevel@tonic-gate 	eqdp->eqd_size = eq.eq_size;
30500Sstevel@tonic-gate 
30510Sstevel@tonic-gate 	/*
30520Sstevel@tonic-gate 	 * The newest elements in the queue are on the pending list, so we
30530Sstevel@tonic-gate 	 * push those on to our stack first.
30540Sstevel@tonic-gate 	 */
30550Sstevel@tonic-gate 	eqd_push_list(eqdp, (uintptr_t)eq.eq_pend);
30560Sstevel@tonic-gate 
30570Sstevel@tonic-gate 	/*
30580Sstevel@tonic-gate 	 * If eq_ptail is set, it may point to a subset of the errors on the
30590Sstevel@tonic-gate 	 * pending list in the event a casptr() failed; if ptail's data is
30600Sstevel@tonic-gate 	 * already in our stack, NULL out eq_ptail and ignore it.
30610Sstevel@tonic-gate 	 */
30620Sstevel@tonic-gate 	if (eq.eq_ptail != NULL) {
30630Sstevel@tonic-gate 		for (i = 0; i < eqdp->eqd_qpos; i++) {
30640Sstevel@tonic-gate 			if (eqdp->eqd_stack[i] == (uintptr_t)eqe.eqe_data) {
30650Sstevel@tonic-gate 				eq.eq_ptail = NULL;
30660Sstevel@tonic-gate 				break;
30670Sstevel@tonic-gate 			}
30680Sstevel@tonic-gate 		}
30690Sstevel@tonic-gate 	}
30700Sstevel@tonic-gate 
30710Sstevel@tonic-gate 	/*
30720Sstevel@tonic-gate 	 * If eq_phead is set, it has the processing list in order from oldest
30730Sstevel@tonic-gate 	 * to newest.  Use this to recompute eq_ptail as best we can and then
30740Sstevel@tonic-gate 	 * we nicely fall into eqd_push_list() of eq_ptail below.
30750Sstevel@tonic-gate 	 */
30760Sstevel@tonic-gate 	for (addr = eq.eq_phead; addr != NULL && mdb_vread(&eqe, sizeof (eqe),
30770Sstevel@tonic-gate 	    (uintptr_t)addr) == sizeof (eqe); addr = eqe.eqe_next)
30780Sstevel@tonic-gate 		eq.eq_ptail = addr;
30790Sstevel@tonic-gate 
30800Sstevel@tonic-gate 	/*
30810Sstevel@tonic-gate 	 * The oldest elements in the queue are on the processing list, subject
30820Sstevel@tonic-gate 	 * to machinations in the if-clauses above.  Push any such elements.
30830Sstevel@tonic-gate 	 */
30840Sstevel@tonic-gate 	eqd_push_list(eqdp, (uintptr_t)eq.eq_ptail);
30850Sstevel@tonic-gate 	return (WALK_NEXT);
30860Sstevel@tonic-gate }
30870Sstevel@tonic-gate 
30880Sstevel@tonic-gate static int
30890Sstevel@tonic-gate eqd_walk_step(mdb_walk_state_t *wsp)
30900Sstevel@tonic-gate {
30910Sstevel@tonic-gate 	eqd_walk_data_t *eqdp = wsp->walk_data;
30920Sstevel@tonic-gate 	uintptr_t addr;
30930Sstevel@tonic-gate 
30940Sstevel@tonic-gate 	if (eqdp->eqd_qpos == 0)
30950Sstevel@tonic-gate 		return (WALK_DONE);
30960Sstevel@tonic-gate 
30970Sstevel@tonic-gate 	addr = eqdp->eqd_stack[--eqdp->eqd_qpos];
30980Sstevel@tonic-gate 
30990Sstevel@tonic-gate 	if (mdb_vread(eqdp->eqd_buf, eqdp->eqd_size, addr) != eqdp->eqd_size) {
31000Sstevel@tonic-gate 		mdb_warn("failed to read errorq data at %p", addr);
31010Sstevel@tonic-gate 		return (WALK_ERR);
31020Sstevel@tonic-gate 	}
31030Sstevel@tonic-gate 
31040Sstevel@tonic-gate 	return (wsp->walk_callback(addr, eqdp->eqd_buf, wsp->walk_cbdata));
31050Sstevel@tonic-gate }
31060Sstevel@tonic-gate 
31070Sstevel@tonic-gate static void
31080Sstevel@tonic-gate eqd_walk_fini(mdb_walk_state_t *wsp)
31090Sstevel@tonic-gate {
31100Sstevel@tonic-gate 	eqd_walk_data_t *eqdp = wsp->walk_data;
31110Sstevel@tonic-gate 
31120Sstevel@tonic-gate 	mdb_free(eqdp->eqd_stack, sizeof (uintptr_t) * eqdp->eqd_qlen);
31130Sstevel@tonic-gate 	mdb_free(eqdp->eqd_buf, eqdp->eqd_size);
31140Sstevel@tonic-gate 	mdb_free(eqdp, sizeof (eqd_walk_data_t));
31150Sstevel@tonic-gate }
31160Sstevel@tonic-gate 
31170Sstevel@tonic-gate #define	EQKSVAL(eqv, what) (eqv.eq_kstat.what.value.ui64)
31180Sstevel@tonic-gate 
31190Sstevel@tonic-gate static int
31200Sstevel@tonic-gate errorq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
31210Sstevel@tonic-gate {
31220Sstevel@tonic-gate 	int i;
31230Sstevel@tonic-gate 	errorq_t eq;
31240Sstevel@tonic-gate 	uint_t opt_v = FALSE;
31250Sstevel@tonic-gate 
31260Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
31270Sstevel@tonic-gate 		if (mdb_walk_dcmd("errorq", "errorq", argc, argv) == -1) {
31280Sstevel@tonic-gate 			mdb_warn("can't walk 'errorq'");
31290Sstevel@tonic-gate 			return (DCMD_ERR);
31300Sstevel@tonic-gate 		}
31310Sstevel@tonic-gate 		return (DCMD_OK);
31320Sstevel@tonic-gate 	}
31330Sstevel@tonic-gate 
31340Sstevel@tonic-gate 	i = mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &opt_v, NULL);
31350Sstevel@tonic-gate 	argc -= i;
31360Sstevel@tonic-gate 	argv += i;
31370Sstevel@tonic-gate 
31380Sstevel@tonic-gate 	if (argc != 0)
31390Sstevel@tonic-gate 		return (DCMD_USAGE);
31400Sstevel@tonic-gate 
31410Sstevel@tonic-gate 	if (opt_v || DCMD_HDRSPEC(flags)) {
31420Sstevel@tonic-gate 		mdb_printf("%<u>%-11s %-16s %1s %1s %1s ",
31430Sstevel@tonic-gate 		    "ADDR", "NAME", "S", "V", "N");
31440Sstevel@tonic-gate 		if (!opt_v) {
31450Sstevel@tonic-gate 			mdb_printf("%7s %7s %7s%</u>\n",
31460Sstevel@tonic-gate 			    "ACCEPT", "DROP", "LOG");
31470Sstevel@tonic-gate 		} else {
31480Sstevel@tonic-gate 			mdb_printf("%5s %6s %6s %3s %16s%</u>\n",
31490Sstevel@tonic-gate 			    "KSTAT", "QLEN", "SIZE", "IPL", "FUNC");
31500Sstevel@tonic-gate 		}
31510Sstevel@tonic-gate 	}
31520Sstevel@tonic-gate 
31530Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), addr) != sizeof (eq)) {
31540Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", addr);
31550Sstevel@tonic-gate 		return (DCMD_ERR);
31560Sstevel@tonic-gate 	}
31570Sstevel@tonic-gate 
31580Sstevel@tonic-gate 	mdb_printf("%-11p %-16s %c %c %c ", addr, eq.eq_name,
31590Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_ACTIVE) ? '+' : '-',
31600Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_VITAL) ? '!' : ' ',
31610Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_NVLIST) ? '*' : ' ');
31620Sstevel@tonic-gate 
31630Sstevel@tonic-gate 	if (!opt_v) {
31640Sstevel@tonic-gate 		mdb_printf("%7llu %7llu %7llu\n",
31650Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_dispatched) + EQKSVAL(eq, eqk_committed),
31660Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_dropped) + EQKSVAL(eq, eqk_reserve_fail) +
31670Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_commit_fail), EQKSVAL(eq, eqk_logged));
31680Sstevel@tonic-gate 	} else {
31690Sstevel@tonic-gate 		mdb_printf("%5s %6lu %6lu %3u %a\n",
31700Sstevel@tonic-gate 		    "  |  ", eq.eq_qlen, eq.eq_size, eq.eq_ipl, eq.eq_func);
31710Sstevel@tonic-gate 		mdb_printf("%38s\n%41s"
31720Sstevel@tonic-gate 		    "%12s %llu\n"
31730Sstevel@tonic-gate 		    "%53s %llu\n"
31740Sstevel@tonic-gate 		    "%53s %llu\n"
31750Sstevel@tonic-gate 		    "%53s %llu\n"
31760Sstevel@tonic-gate 		    "%53s %llu\n"
31770Sstevel@tonic-gate 		    "%53s %llu\n"
31780Sstevel@tonic-gate 		    "%53s %llu\n"
31790Sstevel@tonic-gate 		    "%53s %llu\n\n",
31800Sstevel@tonic-gate 		    "|", "+-> ",
31810Sstevel@tonic-gate 		    "DISPATCHED",	EQKSVAL(eq, eqk_dispatched),
31820Sstevel@tonic-gate 		    "DROPPED",		EQKSVAL(eq, eqk_dropped),
31830Sstevel@tonic-gate 		    "LOGGED",		EQKSVAL(eq, eqk_logged),
31840Sstevel@tonic-gate 		    "RESERVED",		EQKSVAL(eq, eqk_reserved),
31850Sstevel@tonic-gate 		    "RESERVE FAIL",	EQKSVAL(eq, eqk_reserve_fail),
31860Sstevel@tonic-gate 		    "COMMITTED",	EQKSVAL(eq, eqk_committed),
31870Sstevel@tonic-gate 		    "COMMIT FAIL",	EQKSVAL(eq, eqk_commit_fail),
31880Sstevel@tonic-gate 		    "CANCELLED",	EQKSVAL(eq, eqk_cancelled));
31890Sstevel@tonic-gate 	}
31900Sstevel@tonic-gate 
31910Sstevel@tonic-gate 	return (DCMD_OK);
31920Sstevel@tonic-gate }
31930Sstevel@tonic-gate 
31940Sstevel@tonic-gate /*ARGSUSED*/
31950Sstevel@tonic-gate static int
31960Sstevel@tonic-gate panicinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
31970Sstevel@tonic-gate {
31980Sstevel@tonic-gate 	cpu_t panic_cpu;
31990Sstevel@tonic-gate 	kthread_t *panic_thread;
32004256Spetede 	void *buf;
32010Sstevel@tonic-gate 	panic_data_t *pd;
32020Sstevel@tonic-gate 	int i, n;
32030Sstevel@tonic-gate 
32040Sstevel@tonic-gate 	if (!mdb_prop_postmortem) {
32050Sstevel@tonic-gate 		mdb_warn("panicinfo can only be run on a system "
32060Sstevel@tonic-gate 		    "dump; see dumpadm(1M)\n");
32070Sstevel@tonic-gate 		return (DCMD_ERR);
32080Sstevel@tonic-gate 	}
32090Sstevel@tonic-gate 
32100Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC || argc != 0)
32110Sstevel@tonic-gate 		return (DCMD_USAGE);
32120Sstevel@tonic-gate 
32130Sstevel@tonic-gate 	if (mdb_readsym(&panic_cpu, sizeof (cpu_t), "panic_cpu") == -1)
32140Sstevel@tonic-gate 		mdb_warn("failed to read 'panic_cpu'");
32150Sstevel@tonic-gate 	else
32160Sstevel@tonic-gate 		mdb_printf("%16s %?d\n", "cpu", panic_cpu.cpu_id);
32170Sstevel@tonic-gate 
32180Sstevel@tonic-gate 	if (mdb_readvar(&panic_thread, "panic_thread") == -1)
32190Sstevel@tonic-gate 		mdb_warn("failed to read 'panic_thread'");
32200Sstevel@tonic-gate 	else
32210Sstevel@tonic-gate 		mdb_printf("%16s %?p\n", "thread", panic_thread);
32220Sstevel@tonic-gate 
32234256Spetede 	buf = mdb_alloc(PANICBUFSIZE, UM_SLEEP);
32244256Spetede 	pd = (panic_data_t *)buf;
32254256Spetede 
32264256Spetede 	if (mdb_readsym(buf, PANICBUFSIZE, "panicbuf") == -1 ||
32270Sstevel@tonic-gate 	    pd->pd_version != PANICBUFVERS) {
32280Sstevel@tonic-gate 		mdb_warn("failed to read 'panicbuf'");
32294256Spetede 		mdb_free(buf, PANICBUFSIZE);
32300Sstevel@tonic-gate 		return (DCMD_ERR);
32310Sstevel@tonic-gate 	}
32320Sstevel@tonic-gate 
32334256Spetede 	mdb_printf("%16s %s\n", "message",  (char *)buf + pd->pd_msgoff);
32340Sstevel@tonic-gate 
32350Sstevel@tonic-gate 	n = (pd->pd_msgoff - (sizeof (panic_data_t) -
32360Sstevel@tonic-gate 	    sizeof (panic_nv_t))) / sizeof (panic_nv_t);
32370Sstevel@tonic-gate 
32380Sstevel@tonic-gate 	for (i = 0; i < n; i++)
32390Sstevel@tonic-gate 		mdb_printf("%16s %?llx\n",
32400Sstevel@tonic-gate 		    pd->pd_nvdata[i].pnv_name, pd->pd_nvdata[i].pnv_value);
32410Sstevel@tonic-gate 
32424256Spetede 	mdb_free(buf, PANICBUFSIZE);
32430Sstevel@tonic-gate 	return (DCMD_OK);
32440Sstevel@tonic-gate }
32450Sstevel@tonic-gate 
32460Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
32470Sstevel@tonic-gate 
32480Sstevel@tonic-gate 	/* from genunix.c */
32490Sstevel@tonic-gate 	{ "addr2smap", ":[offset]", "translate address to smap", addr2smap },
32500Sstevel@tonic-gate 	{ "as2proc", ":", "convert as to proc_t address", as2proc },
32510Sstevel@tonic-gate 	{ "binding_hash_entry", ":", "print driver names hash table entry",
32520Sstevel@tonic-gate 		binding_hash_entry },
32530Sstevel@tonic-gate 	{ "callout", NULL, "print callout table", callout },
32540Sstevel@tonic-gate 	{ "class", NULL, "print process scheduler classes", class },
32550Sstevel@tonic-gate 	{ "cpuinfo", "?[-v]", "print CPUs and runnable threads", cpuinfo },
32560Sstevel@tonic-gate 	{ "did2thread", "? kt_did", "find kernel thread for this id",
32570Sstevel@tonic-gate 		did2thread },
32580Sstevel@tonic-gate 	{ "errorq", "?[-v]", "display kernel error queues", errorq },
32590Sstevel@tonic-gate 	{ "fd", ":[fd num]", "get a file pointer from an fd", fd },
32600Sstevel@tonic-gate 	{ "flipone", ":", "the vik_rev_level 2 special", flipone },
32610Sstevel@tonic-gate 	{ "lminfo", NULL, "print lock manager information", lminfo },
32620Sstevel@tonic-gate 	{ "ndi_event_hdl", "?", "print ndi_event_hdl", ndi_event_hdl },
32630Sstevel@tonic-gate 	{ "panicinfo", NULL, "print panic information", panicinfo },
32640Sstevel@tonic-gate 	{ "pid2proc", "?", "convert PID to proc_t address", pid2proc },
32650Sstevel@tonic-gate 	{ "pmap", ":[-q]", "print process memory map", pmap },
32660Sstevel@tonic-gate 	{ "project", NULL, "display kernel project(s)", project },
32670Sstevel@tonic-gate 	{ "ps", "[-fltzTP]", "list processes (and associated thr,lwp)", ps },
32681014Svb160487 	{ "pgrep", "[-x] [-n | -o] pattern",
32691014Svb160487 		"pattern match against all processes", pgrep },
32700Sstevel@tonic-gate 	{ "ptree", NULL, "print process tree", ptree },
32710Sstevel@tonic-gate 	{ "seg", ":", "print address space segment", seg },
32720Sstevel@tonic-gate 	{ "sysevent", "?[-sv]", "print sysevent pending or sent queue",
32730Sstevel@tonic-gate 		sysevent},
32740Sstevel@tonic-gate 	{ "sysevent_channel", "?", "print sysevent channel database",
32750Sstevel@tonic-gate 		sysevent_channel},
32760Sstevel@tonic-gate 	{ "sysevent_class_list", ":", "print sysevent class list",
32770Sstevel@tonic-gate 		sysevent_class_list},
32780Sstevel@tonic-gate 	{ "sysevent_subclass_list", ":",
32790Sstevel@tonic-gate 		"print sysevent subclass list", sysevent_subclass_list},
32800Sstevel@tonic-gate 	{ "system", NULL, "print contents of /etc/system file", sysfile },
32810Sstevel@tonic-gate 	{ "task", NULL, "display kernel task(s)", task },
32820Sstevel@tonic-gate 	{ "taskq_entry", ":", "display a taskq_ent_t", taskq_ent },
32830Sstevel@tonic-gate 	{ "vnode2path", ":[-F]", "vnode address to pathname", vnode2path },
32840Sstevel@tonic-gate 	{ "vnode2smap", ":[offset]", "translate vnode to smap", vnode2smap },
32850Sstevel@tonic-gate 	{ "whereopen", ":", "given a vnode, dumps procs which have it open",
32860Sstevel@tonic-gate 	    whereopen },
32870Sstevel@tonic-gate 
32880Sstevel@tonic-gate 	/* from zone.c */
32890Sstevel@tonic-gate 	{ "zone", "?", "display kernel zone(s)", zoneprt },
32900Sstevel@tonic-gate 	{ "zsd", ":[zsd key]", "lookup zsd value from a key", zsd },
32910Sstevel@tonic-gate 
32920Sstevel@tonic-gate 	/* from bio.c */
32930Sstevel@tonic-gate 	{ "bufpagefind", ":addr", "find page_t on buf_t list", bufpagefind },
32940Sstevel@tonic-gate 
32950Sstevel@tonic-gate 	/* from contract.c */
32960Sstevel@tonic-gate 	{ "contract", "?", "display a contract", cmd_contract },
32970Sstevel@tonic-gate 	{ "ctevent", ":", "display a contract event", cmd_ctevent },
32980Sstevel@tonic-gate 	{ "ctid", ":", "convert id to a contract pointer", cmd_ctid },
32990Sstevel@tonic-gate 
33000Sstevel@tonic-gate 	/* from cpupart.c */
3301537Smishra 	{ "cpupart", "?[-v]", "print cpu partition info", cpupart },
33020Sstevel@tonic-gate 
33030Sstevel@tonic-gate 	/* from cyclic.c */
33040Sstevel@tonic-gate 	{ "cyccover", NULL, "dump cyclic coverage information", cyccover },
33050Sstevel@tonic-gate 	{ "cycid", "?", "dump a cyclic id", cycid },
33060Sstevel@tonic-gate 	{ "cycinfo", "?", "dump cyc_cpu info", cycinfo },
33070Sstevel@tonic-gate 	{ "cyclic", ":", "developer information", cyclic },
33080Sstevel@tonic-gate 	{ "cyctrace", "?", "dump cyclic trace buffer", cyctrace },
33090Sstevel@tonic-gate 
33100Sstevel@tonic-gate 	/* from devinfo.c */
33110Sstevel@tonic-gate 	{ "devbindings", "?[-qs] [device-name | major-num]",
33120Sstevel@tonic-gate 	    "print devinfo nodes bound to device-name or major-num",
33130Sstevel@tonic-gate 	    devbindings, devinfo_help },
33140Sstevel@tonic-gate 	{ "devinfo", ":[-qs]", "detailed devinfo of one node", devinfo,
33150Sstevel@tonic-gate 	    devinfo_help },
33160Sstevel@tonic-gate 	{ "devinfo_audit", ":[-v]", "devinfo configuration audit record",
33170Sstevel@tonic-gate 	    devinfo_audit },
33180Sstevel@tonic-gate 	{ "devinfo_audit_log", "?[-v]", "system wide devinfo configuration log",
33190Sstevel@tonic-gate 	    devinfo_audit_log },
33200Sstevel@tonic-gate 	{ "devinfo_audit_node", ":[-v]", "devinfo node configuration history",
33210Sstevel@tonic-gate 	    devinfo_audit_node },
33220Sstevel@tonic-gate 	{ "devinfo2driver", ":", "find driver name for this devinfo node",
33230Sstevel@tonic-gate 	    devinfo2driver },
33240Sstevel@tonic-gate 	{ "devnames", "?[-vm] [num]", "print devnames array", devnames },
33250Sstevel@tonic-gate 	{ "dev2major", "?<dev_t>", "convert dev_t to a major number",
33260Sstevel@tonic-gate 	    dev2major },
33270Sstevel@tonic-gate 	{ "dev2minor", "?<dev_t>", "convert dev_t to a minor number",
33280Sstevel@tonic-gate 	    dev2minor },
33290Sstevel@tonic-gate 	{ "devt", "?<dev_t>", "display a dev_t's major and minor numbers",
33300Sstevel@tonic-gate 	    devt },
33310Sstevel@tonic-gate 	{ "major2name", "?<major-num>", "convert major number to dev name",
33320Sstevel@tonic-gate 	    major2name },
33330Sstevel@tonic-gate 	{ "minornodes", ":", "given a devinfo node, print its minor nodes",
33340Sstevel@tonic-gate 	    minornodes },
33350Sstevel@tonic-gate 	{ "modctl2devinfo", ":", "given a modctl, list its devinfos",
33360Sstevel@tonic-gate 	    modctl2devinfo },
33370Sstevel@tonic-gate 	{ "name2major", "<dev-name>", "convert dev name to major number",
33380Sstevel@tonic-gate 	    name2major },
33390Sstevel@tonic-gate 	{ "prtconf", "?[-vpc]", "print devinfo tree", prtconf, prtconf_help },
33400Sstevel@tonic-gate 	{ "softstate", ":<instance>", "retrieve soft-state pointer",
33410Sstevel@tonic-gate 	    softstate },
33420Sstevel@tonic-gate 	{ "devinfo_fm", ":", "devinfo fault managment configuration",
33430Sstevel@tonic-gate 	    devinfo_fm },
33440Sstevel@tonic-gate 	{ "devinfo_fmce", ":", "devinfo fault managment cache entry",
33450Sstevel@tonic-gate 	    devinfo_fmce},
33460Sstevel@tonic-gate 
33473323Scindi 	/* from fm.c */
33483323Scindi 	{ "ereport", "[-v]", "print ereports logged in dump",
33493323Scindi 	    ereport },
33503323Scindi 
33510Sstevel@tonic-gate 	/* from findstack.c */
33520Sstevel@tonic-gate 	{ "findstack", ":[-v]", "find kernel thread stack", findstack },
33530Sstevel@tonic-gate 	{ "findstack_debug", NULL, "toggle findstack debugging",
33540Sstevel@tonic-gate 		findstack_debug },
33550Sstevel@tonic-gate 
33560Sstevel@tonic-gate 	/* from kgrep.c + genunix.c */
33571580Sjwadams 	{ "kgrep", KGREP_USAGE, "search kernel as for a pointer", kgrep,
33581580Sjwadams 		kgrep_help },
33590Sstevel@tonic-gate 
33600Sstevel@tonic-gate 	/* from kmem.c */
33610Sstevel@tonic-gate 	{ "allocdby", ":", "given a thread, print its allocated buffers",
33620Sstevel@tonic-gate 		allocdby },
33630Sstevel@tonic-gate 	{ "bufctl", ":[-vh] [-a addr] [-c caller] [-e earliest] [-l latest] "
33640Sstevel@tonic-gate 		"[-t thd]", "print or filter a bufctl", bufctl, bufctl_help },
33650Sstevel@tonic-gate 	{ "freedby", ":", "given a thread, print its freed buffers", freedby },
33660Sstevel@tonic-gate 	{ "kmalog", "?[ fail | slab ]",
33670Sstevel@tonic-gate 	    "display kmem transaction log and stack traces", kmalog },
33683095Sek110237 	{ "kmastat", "[-kmg]", "kernel memory allocator stats",
33693095Sek110237 	    kmastat },
33700Sstevel@tonic-gate 	{ "kmausers", "?[-ef] [cache ...]", "current medium and large users "
33710Sstevel@tonic-gate 		"of the kmem allocator", kmausers, kmausers_help },
33726712Stomee 	{ "kmem_cache", "?[-n name]",
33736712Stomee 		"print kernel memory caches", kmem_cache, kmem_cache_help},
33746712Stomee 	{ "kmem_slabs", "?[-v] [-n cache] [-N cache] [-b maxbins] "
33756712Stomee 		"[-B minbinsize]", "display slab usage per kmem cache",
33764688Stomee 		kmem_slabs, kmem_slabs_help },
33770Sstevel@tonic-gate 	{ "kmem_debug", NULL, "toggle kmem dcmd/walk debugging", kmem_debug },
33780Sstevel@tonic-gate 	{ "kmem_log", "?[-b]", "dump kmem transaction log", kmem_log },
33790Sstevel@tonic-gate 	{ "kmem_verify", "?", "check integrity of kmem-managed memory",
33800Sstevel@tonic-gate 		kmem_verify },
33810Sstevel@tonic-gate 	{ "vmem", "?", "print a vmem_t", vmem },
33820Sstevel@tonic-gate 	{ "vmem_seg", ":[-sv] [-c caller] [-e earliest] [-l latest] "
33830Sstevel@tonic-gate 		"[-m minsize] [-M maxsize] [-t thread] [-T type]",
33840Sstevel@tonic-gate 		"print or filter a vmem_seg", vmem_seg, vmem_seg_help },
33850Sstevel@tonic-gate 	{ "whatis", ":[-abiv]", "given an address, return information", whatis,
33860Sstevel@tonic-gate 		whatis_help },
33870Sstevel@tonic-gate 	{ "whatthread", ":[-v]", "print threads whose stack contains the "
33880Sstevel@tonic-gate 		"given address", whatthread },
33890Sstevel@tonic-gate 
33900Sstevel@tonic-gate 	/* from ldi.c */
33910Sstevel@tonic-gate 	{ "ldi_handle", "?[-i]", "display a layered driver handle",
33920Sstevel@tonic-gate 	    ldi_handle, ldi_handle_help },
33930Sstevel@tonic-gate 	{ "ldi_ident", NULL, "display a layered driver identifier",
33940Sstevel@tonic-gate 	    ldi_ident, ldi_ident_help },
33950Sstevel@tonic-gate 
33960Sstevel@tonic-gate 	/* from leaky.c + leaky_subr.c */
33970Sstevel@tonic-gate 	{ "findleaks", FINDLEAKS_USAGE,
33980Sstevel@tonic-gate 	    "search for potential kernel memory leaks", findleaks,
33990Sstevel@tonic-gate 	    findleaks_help },
34000Sstevel@tonic-gate 
34010Sstevel@tonic-gate 	/* from lgrp.c */
34020Sstevel@tonic-gate 	{ "lgrp", "?[-q] [-p | -Pih]", "display an lgrp", lgrp},
34032685Sakolb 	{ "lgrp_set", "", "display bitmask of lgroups as a list", lgrp_set},
34040Sstevel@tonic-gate 
34050Sstevel@tonic-gate 	/* from log.c */
34060Sstevel@tonic-gate 	{ "msgbuf", "?[-v]", "print most recent console messages", msgbuf },
34070Sstevel@tonic-gate 
34080Sstevel@tonic-gate 	/* from memory.c */
34090Sstevel@tonic-gate 	{ "page", "?", "display a summarized page_t", page },
34100Sstevel@tonic-gate 	{ "memstat", NULL, "display memory usage summary", memstat },
34110Sstevel@tonic-gate 	{ "memlist", "?[-iav]", "display a struct memlist", memlist },
34120Sstevel@tonic-gate 	{ "swapinfo", "?", "display a struct swapinfo", swapinfof },
34130Sstevel@tonic-gate 
34140Sstevel@tonic-gate 	/* from mmd.c */
34150Sstevel@tonic-gate 	{ "multidata", ":[-sv]", "display a summarized multidata_t",
34160Sstevel@tonic-gate 		multidata },
34170Sstevel@tonic-gate 	{ "pattbl", ":", "display a summarized multidata attribute table",
34180Sstevel@tonic-gate 		pattbl },
34190Sstevel@tonic-gate 	{ "pattr2multidata", ":", "print multidata pointer from pattr_t",
34200Sstevel@tonic-gate 		pattr2multidata },
34210Sstevel@tonic-gate 	{ "pdesc2slab", ":", "print pdesc slab pointer from pdesc_t",
34220Sstevel@tonic-gate 		pdesc2slab },
34230Sstevel@tonic-gate 	{ "pdesc_verify", ":", "verify integrity of a pdesc_t", pdesc_verify },
34240Sstevel@tonic-gate 	{ "slab2multidata", ":", "print multidata pointer from pdesc_slab_t",
34250Sstevel@tonic-gate 		slab2multidata },
34260Sstevel@tonic-gate 
34270Sstevel@tonic-gate 	/* from modhash.c */
34280Sstevel@tonic-gate 	{ "modhash", "?[-ceht] [-k key] [-v val] [-i index]",
34290Sstevel@tonic-gate 		"display information about one or all mod_hash structures",
34300Sstevel@tonic-gate 		modhash, modhash_help },
34310Sstevel@tonic-gate 	{ "modent", ":[-k | -v | -t type]",
34320Sstevel@tonic-gate 		"display information about a mod_hash_entry", modent,
34330Sstevel@tonic-gate 		modent_help },
34340Sstevel@tonic-gate 
34350Sstevel@tonic-gate 	/* from net.c */
34360Sstevel@tonic-gate 	{ "mi", ":[-p] [-d | -m]", "filter and display MI object or payload",
34370Sstevel@tonic-gate 		mi },
34381676Sjpk 	{ "netstat", "[-arv] [-f inet | inet6 | unix] [-P tcp | udp]",
34390Sstevel@tonic-gate 		"show network statistics", netstat },
34400Sstevel@tonic-gate 	{ "sonode", "?[-f inet | inet6 | unix | #] "
34410Sstevel@tonic-gate 		"[-t stream | dgram | raw | #] [-p #]",
34420Sstevel@tonic-gate 		"filter and display sonode", sonode },
34430Sstevel@tonic-gate 
34443448Sdh155122 	/* from netstack.c */
34453448Sdh155122 	{ "netstack", "", "show stack instances", netstack },
34463448Sdh155122 
34470Sstevel@tonic-gate 	/* from nvpair.c */
34480Sstevel@tonic-gate 	{ NVPAIR_DCMD_NAME, NVPAIR_DCMD_USAGE, NVPAIR_DCMD_DESCR,
34490Sstevel@tonic-gate 		nvpair_print },
3450789Sahrens 	{ NVLIST_DCMD_NAME, NVLIST_DCMD_USAGE, NVLIST_DCMD_DESCR,
34512869Sgavinm 		print_nvlist },
34520Sstevel@tonic-gate 
34533434Sesaxe 	/* from pg.c */
34543434Sesaxe 	{ "pg", "?[-q]", "display a pg", pg},
34553434Sesaxe 	/* from group.c */
34563434Sesaxe 	{ "group", "?[-q]", "display a group", group},
34573434Sesaxe 
34583434Sesaxe 	/* from log.c */
34590Sstevel@tonic-gate 	/* from rctl.c */
34600Sstevel@tonic-gate 	{ "rctl_dict", "?", "print systemwide default rctl definitions",
34610Sstevel@tonic-gate 		rctl_dict },
34620Sstevel@tonic-gate 	{ "rctl_list", ":[handle]", "print rctls for the given proc",
34630Sstevel@tonic-gate 		rctl_list },
34640Sstevel@tonic-gate 	{ "rctl", ":[handle]", "print a rctl_t, only if it matches the handle",
34650Sstevel@tonic-gate 		rctl },
34660Sstevel@tonic-gate 	{ "rctl_validate", ":[-v] [-n #]", "test resource control value "
34670Sstevel@tonic-gate 		"sequence", rctl_validate },
34680Sstevel@tonic-gate 
34690Sstevel@tonic-gate 	/* from sobj.c */
34700Sstevel@tonic-gate 	{ "rwlock", ":", "dump out a readers/writer lock", rwlock },
34710Sstevel@tonic-gate 	{ "mutex", ":[-f]", "dump out an adaptive or spin mutex", mutex,
34720Sstevel@tonic-gate 		mutex_help },
34730Sstevel@tonic-gate 	{ "sobj2ts", ":", "perform turnstile lookup on synch object", sobj2ts },
34740Sstevel@tonic-gate 	{ "wchaninfo", "?[-v]", "dump condition variable", wchaninfo },
34750Sstevel@tonic-gate 	{ "turnstile", "?", "display a turnstile", turnstile },
34760Sstevel@tonic-gate 
34770Sstevel@tonic-gate 	/* from stream.c */
34780Sstevel@tonic-gate 	{ "mblk", ":[-q|v] [-f|F flag] [-t|T type] [-l|L|B len] [-d dbaddr]",
34790Sstevel@tonic-gate 		"print an mblk", mblk_prt, mblk_help },
34800Sstevel@tonic-gate 	{ "mblk_verify", "?", "verify integrity of an mblk", mblk_verify },
34810Sstevel@tonic-gate 	{ "mblk2dblk", ":", "convert mblk_t address to dblk_t address",
34820Sstevel@tonic-gate 		mblk2dblk },
34830Sstevel@tonic-gate 	{ "q2otherq", ":", "print peer queue for a given queue", q2otherq },
34840Sstevel@tonic-gate 	{ "q2rdq", ":", "print read queue for a given queue", q2rdq },
34850Sstevel@tonic-gate 	{ "q2syncq", ":", "print syncq for a given queue", q2syncq },
34860Sstevel@tonic-gate 	{ "q2stream", ":", "print stream pointer for a given queue", q2stream },
34870Sstevel@tonic-gate 	{ "q2wrq", ":", "print write queue for a given queue", q2wrq },
34880Sstevel@tonic-gate 	{ "queue", ":[-q|v] [-m mod] [-f flag] [-F flag] [-s syncq_addr]",
34890Sstevel@tonic-gate 		"filter and display STREAM queue", queue, queue_help },
34900Sstevel@tonic-gate 	{ "stdata", ":[-q|v] [-f flag] [-F flag]",
34910Sstevel@tonic-gate 		"filter and display STREAM head", stdata, stdata_help },
34920Sstevel@tonic-gate 	{ "str2mate", ":", "print mate of this stream", str2mate },
34930Sstevel@tonic-gate 	{ "str2wrq", ":", "print write queue of this stream", str2wrq },
34940Sstevel@tonic-gate 	{ "stream", ":", "display STREAM", stream },
34950Sstevel@tonic-gate 	{ "strftevent", ":", "print STREAMS flow trace event", strftevent },
34960Sstevel@tonic-gate 	{ "syncq", ":[-q|v] [-f flag] [-F flag] [-t type] [-T type]",
34970Sstevel@tonic-gate 		"filter and display STREAM sync queue", syncq, syncq_help },
34980Sstevel@tonic-gate 	{ "syncq2q", ":", "print queue for a given syncq", syncq2q },
34990Sstevel@tonic-gate 
35000Sstevel@tonic-gate 	/* from thread.c */
35010Sstevel@tonic-gate 	{ "thread", "?[-bdfimps]", "display a summarized kthread_t", thread,
35020Sstevel@tonic-gate 		thread_help },
35035316Sjohnlev 	{ "threadlist", "?[-t] [-v [count]]",
35040Sstevel@tonic-gate 		"display threads and associated C stack traces", threadlist,
35050Sstevel@tonic-gate 		threadlist_help },
3506*7854SPhilippe.Jung@Sun.COM 	{ "stackinfo", "?[-h|-a]", "display kthread_t stack usage", stackinfo,
3507*7854SPhilippe.Jung@Sun.COM 		stackinfo_help },
35080Sstevel@tonic-gate 
35090Sstevel@tonic-gate 	/* from tsd.c */
35100Sstevel@tonic-gate 	{ "tsd", ":-k key", "print tsd[key-1] for this thread", ttotsd },
35110Sstevel@tonic-gate 	{ "tsdtot", ":", "find thread with this tsd", tsdtot },
35120Sstevel@tonic-gate 
35130Sstevel@tonic-gate 	/*
35140Sstevel@tonic-gate 	 * typegraph does not work under kmdb, as it requires too much memory
35150Sstevel@tonic-gate 	 * for its internal data structures.
35160Sstevel@tonic-gate 	 */
35170Sstevel@tonic-gate #ifndef _KMDB
35180Sstevel@tonic-gate 	/* from typegraph.c */
35190Sstevel@tonic-gate 	{ "findlocks", ":", "find locks held by specified thread", findlocks },
35200Sstevel@tonic-gate 	{ "findfalse", "?[-v]", "find potentially falsely shared structures",
35210Sstevel@tonic-gate 		findfalse },
35220Sstevel@tonic-gate 	{ "typegraph", NULL, "build type graph", typegraph },
35230Sstevel@tonic-gate 	{ "istype", ":type", "manually set object type", istype },
35240Sstevel@tonic-gate 	{ "notype", ":", "manually clear object type", notype },
35250Sstevel@tonic-gate 	{ "whattype", ":", "determine object type", whattype },
35260Sstevel@tonic-gate #endif
35270Sstevel@tonic-gate 
35280Sstevel@tonic-gate 	/* from vfs.c */
35290Sstevel@tonic-gate 	{ "fsinfo", "?[-v]", "print mounted filesystems", fsinfo },
35300Sstevel@tonic-gate 	{ "pfiles", ":[-fp]", "print process file information", pfiles,
35310Sstevel@tonic-gate 		pfiles_help },
35320Sstevel@tonic-gate 
35332577Sramat 	/* from mdi.c */
35342577Sramat 	{ "mdipi", NULL, "given a path, dump mdi_pathinfo "
35352577Sramat 		"and detailed pi_prop list", mdipi },
35362577Sramat 	{ "mdiprops", NULL, "given a pi_prop, dump the pi_prop list",
35372577Sramat 		mdiprops },
35382577Sramat 	{ "mdiphci", NULL, "given a phci, dump mdi_phci and "
35392577Sramat 		"list all paths", mdiphci },
35402577Sramat 	{ "mdivhci", NULL, "given a vhci, dump mdi_vhci and list "
35412577Sramat 		"all phcis", mdivhci },
35422577Sramat 	{ "mdiclient_paths", NULL, "given a path, walk mdi_pathinfo "
35432577Sramat 		"client links", mdiclient_paths },
35442577Sramat 	{ "mdiphci_paths", NULL, "given a path, walk through mdi_pathinfo "
35452577Sramat 		"phci links", mdiphci_paths },
35462577Sramat 	{ "mdiphcis", NULL, "given a phci, walk through mdi_phci ph_next links",
35472577Sramat 		mdiphcis },
35482577Sramat 
35490Sstevel@tonic-gate 	{ NULL }
35500Sstevel@tonic-gate };
35510Sstevel@tonic-gate 
35520Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
35530Sstevel@tonic-gate 
35540Sstevel@tonic-gate 	/* from genunix.c */
35550Sstevel@tonic-gate 	{ "anon", "given an amp, list of anon structures",
35560Sstevel@tonic-gate 		anon_walk_init, anon_walk_step, anon_walk_fini },
35570Sstevel@tonic-gate 	{ "cpu", "walk cpu structures", cpu_walk_init, cpu_walk_step },
35583323Scindi 	{ "ereportq_dump", "walk list of ereports in dump error queue",
35593323Scindi 		ereportq_dump_walk_init, ereportq_dump_walk_step, NULL },
35603323Scindi 	{ "ereportq_pend", "walk list of ereports in pending error queue",
35613323Scindi 		ereportq_pend_walk_init, ereportq_pend_walk_step, NULL },
35620Sstevel@tonic-gate 	{ "errorq", "walk list of system error queues",
35630Sstevel@tonic-gate 		errorq_walk_init, errorq_walk_step, NULL },
35640Sstevel@tonic-gate 	{ "errorq_data", "walk pending error queue data buffers",
35650Sstevel@tonic-gate 		eqd_walk_init, eqd_walk_step, eqd_walk_fini },
35660Sstevel@tonic-gate 	{ "allfile", "given a proc pointer, list all file pointers",
35670Sstevel@tonic-gate 		file_walk_init, allfile_walk_step, file_walk_fini },
35680Sstevel@tonic-gate 	{ "file", "given a proc pointer, list of open file pointers",
35690Sstevel@tonic-gate 		file_walk_init, file_walk_step, file_walk_fini },
35700Sstevel@tonic-gate 	{ "lock_descriptor", "walk lock_descriptor_t structures",
35710Sstevel@tonic-gate 		ld_walk_init, ld_walk_step, NULL },
35720Sstevel@tonic-gate 	{ "lock_graph", "walk lock graph",
35730Sstevel@tonic-gate 		lg_walk_init, lg_walk_step, NULL },
35740Sstevel@tonic-gate 	{ "port", "given a proc pointer, list of created event ports",
35750Sstevel@tonic-gate 		port_walk_init, port_walk_step, NULL },
35760Sstevel@tonic-gate 	{ "portev", "given a port pointer, list of events in the queue",
35770Sstevel@tonic-gate 		portev_walk_init, portev_walk_step, portev_walk_fini },
35780Sstevel@tonic-gate 	{ "proc", "list of active proc_t structures",
35790Sstevel@tonic-gate 		proc_walk_init, proc_walk_step, proc_walk_fini },
35800Sstevel@tonic-gate 	{ "projects", "walk a list of kernel projects",
35810Sstevel@tonic-gate 		project_walk_init, project_walk_step, NULL },
35820Sstevel@tonic-gate 	{ "seg", "given an as, list of segments",
35830Sstevel@tonic-gate 		seg_walk_init, avl_walk_step, avl_walk_fini },
35840Sstevel@tonic-gate 	{ "sysevent_pend", "walk sysevent pending queue",
35850Sstevel@tonic-gate 		sysevent_pend_walk_init, sysevent_walk_step,
35860Sstevel@tonic-gate 		sysevent_walk_fini},
35870Sstevel@tonic-gate 	{ "sysevent_sent", "walk sysevent sent queue", sysevent_sent_walk_init,
35880Sstevel@tonic-gate 		sysevent_walk_step, sysevent_walk_fini},
35890Sstevel@tonic-gate 	{ "sysevent_channel", "walk sysevent channel subscriptions",
35900Sstevel@tonic-gate 		sysevent_channel_walk_init, sysevent_channel_walk_step,
35910Sstevel@tonic-gate 		sysevent_channel_walk_fini},
35920Sstevel@tonic-gate 	{ "sysevent_class_list", "walk sysevent subscription's class list",
35930Sstevel@tonic-gate 		sysevent_class_list_walk_init, sysevent_class_list_walk_step,
35940Sstevel@tonic-gate 		sysevent_class_list_walk_fini},
35950Sstevel@tonic-gate 	{ "sysevent_subclass_list",
35960Sstevel@tonic-gate 		"walk sysevent subscription's subclass list",
35970Sstevel@tonic-gate 		sysevent_subclass_list_walk_init,
35980Sstevel@tonic-gate 		sysevent_subclass_list_walk_step,
35990Sstevel@tonic-gate 		sysevent_subclass_list_walk_fini},
36000Sstevel@tonic-gate 	{ "task", "given a task pointer, walk its processes",
36010Sstevel@tonic-gate 		task_walk_init, task_walk_step, NULL },
36020Sstevel@tonic-gate 	{ "taskq_entry", "given a taskq_t*, list all taskq_ent_t in the list",
36030Sstevel@tonic-gate 		taskq_walk_init, taskq_walk_step, NULL, NULL },
36040Sstevel@tonic-gate 
3605789Sahrens 	/* from avl.c */
3606789Sahrens 	{ AVL_WALK_NAME, AVL_WALK_DESC,
3607789Sahrens 		avl_walk_init, avl_walk_step, avl_walk_fini },
3608789Sahrens 
36090Sstevel@tonic-gate 	/* from zone.c */
36100Sstevel@tonic-gate 	{ "zone", "walk a list of kernel zones",
36110Sstevel@tonic-gate 		zone_walk_init, zone_walk_step, NULL },
36120Sstevel@tonic-gate 	{ "zsd", "walk list of zsd entries for a zone",
36130Sstevel@tonic-gate 		zsd_walk_init, zsd_walk_step, NULL },
36140Sstevel@tonic-gate 
36150Sstevel@tonic-gate 	/* from bio.c */
36160Sstevel@tonic-gate 	{ "buf", "walk the bio buf hash",
36170Sstevel@tonic-gate 		buf_walk_init, buf_walk_step, buf_walk_fini },
36180Sstevel@tonic-gate 
36190Sstevel@tonic-gate 	/* from contract.c */
36200Sstevel@tonic-gate 	{ "contract", "walk all contracts, or those of the specified type",
36210Sstevel@tonic-gate 		ct_walk_init, generic_walk_step, NULL },
36220Sstevel@tonic-gate 	{ "ct_event", "walk events on a contract event queue",
36230Sstevel@tonic-gate 		ct_event_walk_init, generic_walk_step, NULL },
36240Sstevel@tonic-gate 	{ "ct_listener", "walk contract event queue listeners",
36250Sstevel@tonic-gate 		ct_listener_walk_init, generic_walk_step, NULL },
36260Sstevel@tonic-gate 
36270Sstevel@tonic-gate 	/* from cpupart.c */
36280Sstevel@tonic-gate 	{ "cpupart_cpulist", "given an cpupart_t, walk cpus in partition",
36290Sstevel@tonic-gate 		cpupart_cpulist_walk_init, cpupart_cpulist_walk_step,
36300Sstevel@tonic-gate 		NULL },
36310Sstevel@tonic-gate 	{ "cpupart_walk", "walk the set of cpu partitions",
36320Sstevel@tonic-gate 		cpupart_walk_init, cpupart_walk_step, NULL },
36330Sstevel@tonic-gate 
36340Sstevel@tonic-gate 	/* from ctxop.c */
36350Sstevel@tonic-gate 	{ "ctxop", "walk list of context ops on a thread",
36360Sstevel@tonic-gate 		ctxop_walk_init, ctxop_walk_step, ctxop_walk_fini },
36370Sstevel@tonic-gate 
36380Sstevel@tonic-gate 	/* from cyclic.c */
36390Sstevel@tonic-gate 	{ "cyccpu", "walk per-CPU cyc_cpu structures",
36400Sstevel@tonic-gate 		cyccpu_walk_init, cyccpu_walk_step, NULL },
36410Sstevel@tonic-gate 	{ "cycomni", "for an omnipresent cyclic, walk cyc_omni_cpu list",
36420Sstevel@tonic-gate 		cycomni_walk_init, cycomni_walk_step, NULL },
36430Sstevel@tonic-gate 	{ "cyctrace", "walk cyclic trace buffer",
36440Sstevel@tonic-gate 		cyctrace_walk_init, cyctrace_walk_step, cyctrace_walk_fini },
36450Sstevel@tonic-gate 
36460Sstevel@tonic-gate 	/* from devinfo.c */
36470Sstevel@tonic-gate 	{ "binding_hash", "walk all entries in binding hash table",
36480Sstevel@tonic-gate 		binding_hash_walk_init, binding_hash_walk_step, NULL },
36490Sstevel@tonic-gate 	{ "devinfo", "walk devinfo tree or subtree",
36500Sstevel@tonic-gate 		devinfo_walk_init, devinfo_walk_step, devinfo_walk_fini },
36510Sstevel@tonic-gate 	{ "devinfo_audit_log", "walk devinfo audit system-wide log",
36520Sstevel@tonic-gate 		devinfo_audit_log_walk_init, devinfo_audit_log_walk_step,
36530Sstevel@tonic-gate 		devinfo_audit_log_walk_fini},
36540Sstevel@tonic-gate 	{ "devinfo_audit_node", "walk per-devinfo audit history",
36550Sstevel@tonic-gate 		devinfo_audit_node_walk_init, devinfo_audit_node_walk_step,
36560Sstevel@tonic-gate 		devinfo_audit_node_walk_fini},
36570Sstevel@tonic-gate 	{ "devinfo_children", "walk children of devinfo node",
36580Sstevel@tonic-gate 		devinfo_children_walk_init, devinfo_children_walk_step,
36590Sstevel@tonic-gate 		devinfo_children_walk_fini },
36600Sstevel@tonic-gate 	{ "devinfo_parents", "walk ancestors of devinfo node",
36610Sstevel@tonic-gate 		devinfo_parents_walk_init, devinfo_parents_walk_step,
36620Sstevel@tonic-gate 		devinfo_parents_walk_fini },
36630Sstevel@tonic-gate 	{ "devinfo_siblings", "walk siblings of devinfo node",
36640Sstevel@tonic-gate 		devinfo_siblings_walk_init, devinfo_siblings_walk_step, NULL },
36650Sstevel@tonic-gate 	{ "devi_next", "walk devinfo list",
36660Sstevel@tonic-gate 		NULL, devi_next_walk_step, NULL },
36670Sstevel@tonic-gate 	{ "devnames", "walk devnames array",
36680Sstevel@tonic-gate 		devnames_walk_init, devnames_walk_step, devnames_walk_fini },
36690Sstevel@tonic-gate 	{ "minornode", "given a devinfo node, walk minor nodes",
36700Sstevel@tonic-gate 		minornode_walk_init, minornode_walk_step, NULL },
36710Sstevel@tonic-gate 	{ "softstate",
36720Sstevel@tonic-gate 		"given an i_ddi_soft_state*, list all in-use driver stateps",
36730Sstevel@tonic-gate 		soft_state_walk_init, soft_state_walk_step,
36740Sstevel@tonic-gate 		NULL, NULL },
36750Sstevel@tonic-gate 	{ "softstate_all",
36760Sstevel@tonic-gate 		"given an i_ddi_soft_state*, list all driver stateps",
36770Sstevel@tonic-gate 		soft_state_walk_init, soft_state_all_walk_step,
36780Sstevel@tonic-gate 		NULL, NULL },
36790Sstevel@tonic-gate 	{ "devinfo_fmc",
36800Sstevel@tonic-gate 		"walk a fault management handle cache active list",
36810Sstevel@tonic-gate 		devinfo_fmc_walk_init, devinfo_fmc_walk_step, NULL },
36820Sstevel@tonic-gate 
36830Sstevel@tonic-gate 	/* from kmem.c */
36840Sstevel@tonic-gate 	{ "allocdby", "given a thread, walk its allocated bufctls",
36850Sstevel@tonic-gate 		allocdby_walk_init, allocdby_walk_step, allocdby_walk_fini },
36860Sstevel@tonic-gate 	{ "bufctl", "walk a kmem cache's bufctls",
36870Sstevel@tonic-gate 		bufctl_walk_init, kmem_walk_step, kmem_walk_fini },
36880Sstevel@tonic-gate 	{ "bufctl_history", "walk the available history of a bufctl",
36890Sstevel@tonic-gate 		bufctl_history_walk_init, bufctl_history_walk_step,
36900Sstevel@tonic-gate 		bufctl_history_walk_fini },
36910Sstevel@tonic-gate 	{ "freedby", "given a thread, walk its freed bufctls",
36920Sstevel@tonic-gate 		freedby_walk_init, allocdby_walk_step, allocdby_walk_fini },
36930Sstevel@tonic-gate 	{ "freectl", "walk a kmem cache's free bufctls",
36940Sstevel@tonic-gate 		freectl_walk_init, kmem_walk_step, kmem_walk_fini },
36950Sstevel@tonic-gate 	{ "freectl_constructed", "walk a kmem cache's constructed free bufctls",
36960Sstevel@tonic-gate 		freectl_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
36970Sstevel@tonic-gate 	{ "freemem", "walk a kmem cache's free memory",
36980Sstevel@tonic-gate 		freemem_walk_init, kmem_walk_step, kmem_walk_fini },
36990Sstevel@tonic-gate 	{ "freemem_constructed", "walk a kmem cache's constructed free memory",
37000Sstevel@tonic-gate 		freemem_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
37010Sstevel@tonic-gate 	{ "kmem", "walk a kmem cache",
37020Sstevel@tonic-gate 		kmem_walk_init, kmem_walk_step, kmem_walk_fini },
37030Sstevel@tonic-gate 	{ "kmem_cpu_cache", "given a kmem cache, walk its per-CPU caches",
37040Sstevel@tonic-gate 		kmem_cpu_cache_walk_init, kmem_cpu_cache_walk_step, NULL },
37050Sstevel@tonic-gate 	{ "kmem_hash", "given a kmem cache, walk its allocated hash table",
37060Sstevel@tonic-gate 		kmem_hash_walk_init, kmem_hash_walk_step, kmem_hash_walk_fini },
37070Sstevel@tonic-gate 	{ "kmem_log", "walk the kmem transaction log",
37080Sstevel@tonic-gate 		kmem_log_walk_init, kmem_log_walk_step, kmem_log_walk_fini },
37090Sstevel@tonic-gate 	{ "kmem_slab", "given a kmem cache, walk its slabs",
37106712Stomee 		kmem_slab_walk_init, combined_walk_step, combined_walk_fini },
37110Sstevel@tonic-gate 	{ "kmem_slab_partial",
37120Sstevel@tonic-gate 	    "given a kmem cache, walk its partially allocated slabs (min 1)",
37136712Stomee 		kmem_slab_walk_partial_init, combined_walk_step,
37146712Stomee 		combined_walk_fini },
37150Sstevel@tonic-gate 	{ "vmem", "walk vmem structures in pre-fix, depth-first order",
37160Sstevel@tonic-gate 		vmem_walk_init, vmem_walk_step, vmem_walk_fini },
37170Sstevel@tonic-gate 	{ "vmem_alloc", "given a vmem_t, walk its allocated vmem_segs",
37180Sstevel@tonic-gate 		vmem_alloc_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
37190Sstevel@tonic-gate 	{ "vmem_free", "given a vmem_t, walk its free vmem_segs",
37200Sstevel@tonic-gate 		vmem_free_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
37210Sstevel@tonic-gate 	{ "vmem_postfix", "walk vmem structures in post-fix, depth-first order",
37220Sstevel@tonic-gate 		vmem_walk_init, vmem_postfix_walk_step, vmem_walk_fini },
37230Sstevel@tonic-gate 	{ "vmem_seg", "given a vmem_t, walk all of its vmem_segs",
37240Sstevel@tonic-gate 		vmem_seg_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
37250Sstevel@tonic-gate 	{ "vmem_span", "given a vmem_t, walk its spanning vmem_segs",
37260Sstevel@tonic-gate 		vmem_span_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
37270Sstevel@tonic-gate 
37280Sstevel@tonic-gate 	/* from ldi.c */
37290Sstevel@tonic-gate 	{ "ldi_handle", "walk the layered driver handle hash",
37300Sstevel@tonic-gate 		ldi_handle_walk_init, ldi_handle_walk_step, NULL },
37310Sstevel@tonic-gate 	{ "ldi_ident", "walk the layered driver identifier hash",
37320Sstevel@tonic-gate 		ldi_ident_walk_init, ldi_ident_walk_step, NULL },
37330Sstevel@tonic-gate 
37340Sstevel@tonic-gate 	/* from leaky.c + leaky_subr.c */
37350Sstevel@tonic-gate 	{ "leak", "given a leaked bufctl or vmem_seg, find leaks w/ same "
37360Sstevel@tonic-gate 	    "stack trace",
37370Sstevel@tonic-gate 		leaky_walk_init, leaky_walk_step, leaky_walk_fini },
37380Sstevel@tonic-gate 	{ "leakbuf", "given a leaked bufctl or vmem_seg, walk buffers for "
37390Sstevel@tonic-gate 	    "leaks w/ same stack trace",
37400Sstevel@tonic-gate 		leaky_walk_init, leaky_buf_walk_step, leaky_walk_fini },
37410Sstevel@tonic-gate 
37420Sstevel@tonic-gate 	/* from lgrp.c */
37432685Sakolb 	{ "lgrp_cpulist", "walk CPUs in a given lgroup",
37442685Sakolb 		lgrp_cpulist_walk_init, lgrp_cpulist_walk_step, NULL },
37452685Sakolb 	{ "lgrptbl", "walk lgroup table",
37460Sstevel@tonic-gate 		lgrp_walk_init, lgrp_walk_step, NULL },
37472685Sakolb 	{ "lgrp_parents", "walk up lgroup lineage from given lgroup",
37482685Sakolb 		lgrp_parents_walk_init, lgrp_parents_walk_step, NULL },
37492685Sakolb 	{ "lgrp_rsrc_mem", "walk lgroup memory resources of given lgroup",
37502685Sakolb 		lgrp_rsrc_mem_walk_init, lgrp_set_walk_step, NULL },
37512685Sakolb 	{ "lgrp_rsrc_cpu", "walk lgroup CPU resources of given lgroup",
37522685Sakolb 		lgrp_rsrc_cpu_walk_init, lgrp_set_walk_step, NULL },
37530Sstevel@tonic-gate 
37543434Sesaxe 	/* from group.c */
37553434Sesaxe 	{ "group", "walk all elements of a group",
37563434Sesaxe 		group_walk_init, group_walk_step, NULL },
37573434Sesaxe 
37580Sstevel@tonic-gate 	/* from list.c */
3759789Sahrens 	{ LIST_WALK_NAME, LIST_WALK_DESC,
37600Sstevel@tonic-gate 		list_walk_init, list_walk_step, list_walk_fini },
37610Sstevel@tonic-gate 
37620Sstevel@tonic-gate 	/* from memory.c */
37630Sstevel@tonic-gate 	{ "page", "walk all pages, or those from the specified vnode",
37640Sstevel@tonic-gate 		page_walk_init, page_walk_step, page_walk_fini },
37650Sstevel@tonic-gate 	{ "memlist", "walk specified memlist",
37660Sstevel@tonic-gate 		NULL, memlist_walk_step, NULL },
37670Sstevel@tonic-gate 	{ "swapinfo", "walk swapinfo structures",
37680Sstevel@tonic-gate 		swap_walk_init, swap_walk_step, NULL },
37690Sstevel@tonic-gate 
37700Sstevel@tonic-gate 	/* from mmd.c */
37710Sstevel@tonic-gate 	{ "pattr", "walk pattr_t structures", pattr_walk_init,
37720Sstevel@tonic-gate 		mmdq_walk_step, mmdq_walk_fini },
37730Sstevel@tonic-gate 	{ "pdesc", "walk pdesc_t structures",
37740Sstevel@tonic-gate 		pdesc_walk_init, mmdq_walk_step, mmdq_walk_fini },
37750Sstevel@tonic-gate 	{ "pdesc_slab", "walk pdesc_slab_t structures",
37760Sstevel@tonic-gate 		pdesc_slab_walk_init, mmdq_walk_step, mmdq_walk_fini },
37770Sstevel@tonic-gate 
37780Sstevel@tonic-gate 	/* from modhash.c */
37790Sstevel@tonic-gate 	{ "modhash", "walk list of mod_hash structures", modhash_walk_init,
37800Sstevel@tonic-gate 		modhash_walk_step, NULL },
37810Sstevel@tonic-gate 	{ "modent", "walk list of entries in a given mod_hash",
37820Sstevel@tonic-gate 		modent_walk_init, modent_walk_step, modent_walk_fini },
37830Sstevel@tonic-gate 	{ "modchain", "walk list of entries in a given mod_hash_entry",
37840Sstevel@tonic-gate 		NULL, modchain_walk_step, NULL },
37850Sstevel@tonic-gate 
37860Sstevel@tonic-gate 	/* from net.c */
37873448Sdh155122 	{ "ar", "walk ar_t structures using MI for all stacks",
37883448Sdh155122 		mi_payload_walk_init, mi_payload_walk_step, NULL, &mi_ar_arg },
37893448Sdh155122 	{ "icmp", "walk ICMP control structures using MI for all stacks",
37903448Sdh155122 		mi_payload_walk_init, mi_payload_walk_step, NULL,
37913448Sdh155122 		&mi_icmp_arg },
37923448Sdh155122 	{ "ill", "walk ill_t structures using MI for all stacks",
37933448Sdh155122 		mi_payload_walk_init, mi_payload_walk_step, NULL, &mi_ill_arg },
37943448Sdh155122 
37950Sstevel@tonic-gate 	{ "mi", "given a MI_O, walk the MI",
37960Sstevel@tonic-gate 		mi_walk_init, mi_walk_step, mi_walk_fini, NULL },
37970Sstevel@tonic-gate 	{ "sonode", "given a sonode, walk its children",
37980Sstevel@tonic-gate 		sonode_walk_init, sonode_walk_step, sonode_walk_fini, NULL },
37990Sstevel@tonic-gate 
38003448Sdh155122 	{ "ar_stacks", "walk all the ar_stack_t",
38013448Sdh155122 		ar_stacks_walk_init, ar_stacks_walk_step, NULL },
38023448Sdh155122 	{ "icmp_stacks", "walk all the icmp_stack_t",
38033448Sdh155122 		icmp_stacks_walk_init, icmp_stacks_walk_step, NULL },
38043448Sdh155122 	{ "tcp_stacks", "walk all the tcp_stack_t",
38053448Sdh155122 		tcp_stacks_walk_init, tcp_stacks_walk_step, NULL },
38063448Sdh155122 	{ "udp_stacks", "walk all the udp_stack_t",
38073448Sdh155122 		udp_stacks_walk_init, udp_stacks_walk_step, NULL },
38083448Sdh155122 
38090Sstevel@tonic-gate 	/* from nvpair.c */
38100Sstevel@tonic-gate 	{ NVPAIR_WALKER_NAME, NVPAIR_WALKER_DESCR,
38110Sstevel@tonic-gate 		nvpair_walk_init, nvpair_walk_step, NULL },
38120Sstevel@tonic-gate 
38130Sstevel@tonic-gate 	/* from rctl.c */
38140Sstevel@tonic-gate 	{ "rctl_dict_list", "walk all rctl_dict_entry_t's from rctl_lists",
38150Sstevel@tonic-gate 		rctl_dict_walk_init, rctl_dict_walk_step, NULL },
38160Sstevel@tonic-gate 	{ "rctl_set", "given a rctl_set, walk all rctls", rctl_set_walk_init,
38170Sstevel@tonic-gate 		rctl_set_walk_step, NULL },
38180Sstevel@tonic-gate 	{ "rctl_val", "given a rctl_t, walk all rctl_val entries associated",
38190Sstevel@tonic-gate 		rctl_val_walk_init, rctl_val_walk_step },
38200Sstevel@tonic-gate 
38210Sstevel@tonic-gate 	/* from sobj.c */
38220Sstevel@tonic-gate 	{ "blocked", "walk threads blocked on a given sobj",
38230Sstevel@tonic-gate 		blocked_walk_init, blocked_walk_step, NULL },
38240Sstevel@tonic-gate 	{ "wchan", "given a wchan, list of blocked threads",
38250Sstevel@tonic-gate 		wchan_walk_init, wchan_walk_step, wchan_walk_fini },
38260Sstevel@tonic-gate 
38270Sstevel@tonic-gate 	/* from stream.c */
38280Sstevel@tonic-gate 	{ "b_cont", "walk mblk_t list using b_cont",
38290Sstevel@tonic-gate 		mblk_walk_init, b_cont_step, mblk_walk_fini },
38300Sstevel@tonic-gate 	{ "b_next", "walk mblk_t list using b_next",
38310Sstevel@tonic-gate 		mblk_walk_init, b_next_step, mblk_walk_fini },
38320Sstevel@tonic-gate 	{ "qlink", "walk queue_t list using q_link",
38330Sstevel@tonic-gate 		queue_walk_init, queue_link_step, queue_walk_fini },
38340Sstevel@tonic-gate 	{ "qnext", "walk queue_t list using q_next",
38350Sstevel@tonic-gate 		queue_walk_init, queue_next_step, queue_walk_fini },
38360Sstevel@tonic-gate 	{ "strftblk", "given a dblk_t, walk STREAMS flow trace event list",
38370Sstevel@tonic-gate 		strftblk_walk_init, strftblk_step, strftblk_walk_fini },
38380Sstevel@tonic-gate 	{ "readq", "walk read queue side of stdata",
38390Sstevel@tonic-gate 		str_walk_init, strr_walk_step, str_walk_fini },
38400Sstevel@tonic-gate 	{ "writeq", "walk write queue side of stdata",
38410Sstevel@tonic-gate 		str_walk_init, strw_walk_step, str_walk_fini },
38420Sstevel@tonic-gate 
38430Sstevel@tonic-gate 	/* from thread.c */
38440Sstevel@tonic-gate 	{ "deathrow", "walk threads on both lwp_ and thread_deathrow",
38450Sstevel@tonic-gate 		deathrow_walk_init, deathrow_walk_step, NULL },
38460Sstevel@tonic-gate 	{ "cpu_dispq", "given a cpu_t, walk threads in dispatcher queues",
38470Sstevel@tonic-gate 		cpu_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
38480Sstevel@tonic-gate 	{ "cpupart_dispq",
38490Sstevel@tonic-gate 		"given a cpupart_t, walk threads in dispatcher queues",
38500Sstevel@tonic-gate 		cpupart_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
38510Sstevel@tonic-gate 	{ "lwp_deathrow", "walk lwp_deathrow",
38520Sstevel@tonic-gate 		lwp_deathrow_walk_init, deathrow_walk_step, NULL },
38530Sstevel@tonic-gate 	{ "thread", "global or per-process kthread_t structures",
38540Sstevel@tonic-gate 		thread_walk_init, thread_walk_step, thread_walk_fini },
38550Sstevel@tonic-gate 	{ "thread_deathrow", "walk threads on thread_deathrow",
38560Sstevel@tonic-gate 		thread_deathrow_walk_init, deathrow_walk_step, NULL },
38570Sstevel@tonic-gate 
38580Sstevel@tonic-gate 	/* from tsd.c */
38590Sstevel@tonic-gate 	{ "tsd", "walk list of thread-specific data",
38600Sstevel@tonic-gate 		tsd_walk_init, tsd_walk_step, tsd_walk_fini },
38610Sstevel@tonic-gate 
38621676Sjpk 	/* from tsol.c */
38631676Sjpk 	{ "tnrh", "walk remote host cache structures",
38641676Sjpk 	    tnrh_walk_init, tnrh_walk_step, tnrh_walk_fini },
38651676Sjpk 	{ "tnrhtp", "walk remote host template structures",
38661676Sjpk 	    tnrhtp_walk_init, tnrhtp_walk_step, tnrhtp_walk_fini },
38671676Sjpk 
38680Sstevel@tonic-gate 	/*
38690Sstevel@tonic-gate 	 * typegraph does not work under kmdb, as it requires too much memory
38700Sstevel@tonic-gate 	 * for its internal data structures.
38710Sstevel@tonic-gate 	 */
38720Sstevel@tonic-gate #ifndef _KMDB
38730Sstevel@tonic-gate 	/* from typegraph.c */
38740Sstevel@tonic-gate 	{ "typeconflict", "walk buffers with conflicting type inferences",
38750Sstevel@tonic-gate 		typegraph_walk_init, typeconflict_walk_step },
38760Sstevel@tonic-gate 	{ "typeunknown", "walk buffers with unknown types",
38770Sstevel@tonic-gate 		typegraph_walk_init, typeunknown_walk_step },
38780Sstevel@tonic-gate #endif
38790Sstevel@tonic-gate 
38800Sstevel@tonic-gate 	/* from vfs.c */
38810Sstevel@tonic-gate 	{ "vfs", "walk file system list",
38820Sstevel@tonic-gate 		vfs_walk_init, vfs_walk_step },
38832577Sramat 
38842577Sramat 	/* from mdi.c */
38852577Sramat 	{ "mdipi_client_list", "Walker for mdi_pathinfo pi_client_link",
38862577Sramat 		mdi_pi_client_link_walk_init,
38872577Sramat 		mdi_pi_client_link_walk_step,
38882577Sramat 		mdi_pi_client_link_walk_fini },
38892577Sramat 
38902577Sramat 	{ "mdipi_phci_list", "Walker for mdi_pathinfo pi_phci_link",
38912577Sramat 		mdi_pi_phci_link_walk_init,
38922577Sramat 		mdi_pi_phci_link_walk_step,
38932577Sramat 		mdi_pi_phci_link_walk_fini },
38942577Sramat 
38952577Sramat 	{ "mdiphci_list", "Walker for mdi_phci ph_next link",
38962577Sramat 		mdi_phci_ph_next_walk_init,
38972577Sramat 		mdi_phci_ph_next_walk_step,
38982577Sramat 		mdi_phci_ph_next_walk_fini },
38992577Sramat 
39003448Sdh155122 	/* from netstack.c */
39013448Sdh155122 	{ "netstack", "walk a list of kernel netstacks",
39023448Sdh155122 		netstack_walk_init, netstack_walk_step, NULL },
39033448Sdh155122 
39040Sstevel@tonic-gate 	{ NULL }
39050Sstevel@tonic-gate };
39060Sstevel@tonic-gate 
39070Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
39080Sstevel@tonic-gate 
39090Sstevel@tonic-gate const mdb_modinfo_t *
39100Sstevel@tonic-gate _mdb_init(void)
39110Sstevel@tonic-gate {
39120Sstevel@tonic-gate 	if (findstack_init() != DCMD_OK)
39130Sstevel@tonic-gate 		return (NULL);
39140Sstevel@tonic-gate 
39150Sstevel@tonic-gate 	kmem_init();
39160Sstevel@tonic-gate 
39170Sstevel@tonic-gate 	return (&modinfo);
39180Sstevel@tonic-gate }
39190Sstevel@tonic-gate 
39200Sstevel@tonic-gate void
39210Sstevel@tonic-gate _mdb_fini(void)
39220Sstevel@tonic-gate {
39230Sstevel@tonic-gate 	/*
39240Sstevel@tonic-gate 	 * Force ::findleaks to let go any cached memory
39250Sstevel@tonic-gate 	 */
39260Sstevel@tonic-gate 	leaky_cleanup(1);
39270Sstevel@tonic-gate }
3928