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>
388048SMadhavan.Venkataraman@Sun.COM #include <sys/systm.h>
390Sstevel@tonic-gate #include <sys/callo.h>
400Sstevel@tonic-gate #include <sys/priocntl.h>
410Sstevel@tonic-gate #include <sys/class.h>
420Sstevel@tonic-gate #include <sys/regset.h>
430Sstevel@tonic-gate #include <sys/stack.h>
440Sstevel@tonic-gate #include <sys/cpuvar.h>
450Sstevel@tonic-gate #include <sys/vnode.h>
460Sstevel@tonic-gate #include <sys/vfs.h>
470Sstevel@tonic-gate #include <sys/flock_impl.h>
480Sstevel@tonic-gate #include <sys/kmem_impl.h>
490Sstevel@tonic-gate #include <sys/vmem_impl.h>
500Sstevel@tonic-gate #include <sys/kstat.h>
510Sstevel@tonic-gate #include <vm/seg_vn.h>
520Sstevel@tonic-gate #include <vm/anon.h>
530Sstevel@tonic-gate #include <vm/as.h>
540Sstevel@tonic-gate #include <vm/seg_map.h>
550Sstevel@tonic-gate #include <sys/dditypes.h>
560Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
570Sstevel@tonic-gate #include <sys/sysmacros.h>
580Sstevel@tonic-gate #include <sys/sysconf.h>
590Sstevel@tonic-gate #include <sys/task.h>
600Sstevel@tonic-gate #include <sys/project.h>
610Sstevel@tonic-gate #include <sys/taskq.h>
620Sstevel@tonic-gate #include <sys/taskq_impl.h>
630Sstevel@tonic-gate #include <sys/errorq_impl.h>
640Sstevel@tonic-gate #include <sys/cred_impl.h>
650Sstevel@tonic-gate #include <sys/zone.h>
660Sstevel@tonic-gate #include <sys/panic.h>
670Sstevel@tonic-gate #include <regex.h>
680Sstevel@tonic-gate #include <sys/port_impl.h>
690Sstevel@tonic-gate 
70789Sahrens #include "avl.h"
716712Stomee #include "combined.h"
720Sstevel@tonic-gate #include "contract.h"
730Sstevel@tonic-gate #include "cpupart_mdb.h"
740Sstevel@tonic-gate #include "devinfo.h"
750Sstevel@tonic-gate #include "leaky.h"
760Sstevel@tonic-gate #include "lgrp.h"
773434Sesaxe #include "pg.h"
783434Sesaxe #include "group.h"
790Sstevel@tonic-gate #include "list.h"
800Sstevel@tonic-gate #include "log.h"
810Sstevel@tonic-gate #include "kgrep.h"
820Sstevel@tonic-gate #include "kmem.h"
830Sstevel@tonic-gate #include "bio.h"
840Sstevel@tonic-gate #include "streams.h"
850Sstevel@tonic-gate #include "cyclic.h"
860Sstevel@tonic-gate #include "findstack.h"
870Sstevel@tonic-gate #include "ndievents.h"
880Sstevel@tonic-gate #include "mmd.h"
890Sstevel@tonic-gate #include "net.h"
903448Sdh155122 #include "netstack.h"
910Sstevel@tonic-gate #include "nvpair.h"
920Sstevel@tonic-gate #include "ctxop.h"
930Sstevel@tonic-gate #include "tsd.h"
940Sstevel@tonic-gate #include "thread.h"
950Sstevel@tonic-gate #include "memory.h"
960Sstevel@tonic-gate #include "sobj.h"
970Sstevel@tonic-gate #include "sysevent.h"
980Sstevel@tonic-gate #include "rctl.h"
991676Sjpk #include "tsol.h"
1000Sstevel@tonic-gate #include "typegraph.h"
1010Sstevel@tonic-gate #include "ldi.h"
1020Sstevel@tonic-gate #include "vfs.h"
1030Sstevel@tonic-gate #include "zone.h"
1040Sstevel@tonic-gate #include "modhash.h"
1052577Sramat #include "mdi.h"
1063323Scindi #include "fm.h"
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /*
1090Sstevel@tonic-gate  * Surely this is defined somewhere...
1100Sstevel@tonic-gate  */
1110Sstevel@tonic-gate #define	NINTR		16
1120Sstevel@tonic-gate 
1134808Sek110237 #define	KILOS		10
1144808Sek110237 #define	MEGS		20
1154808Sek110237 #define	GIGS		30
1164808Sek110237 
1170Sstevel@tonic-gate #ifndef STACK_BIAS
1180Sstevel@tonic-gate #define	STACK_BIAS	0
1190Sstevel@tonic-gate #endif
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate static char
1220Sstevel@tonic-gate pstat2ch(uchar_t state)
1230Sstevel@tonic-gate {
1240Sstevel@tonic-gate 	switch (state) {
1250Sstevel@tonic-gate 		case SSLEEP: return ('S');
1260Sstevel@tonic-gate 		case SRUN: return ('R');
1270Sstevel@tonic-gate 		case SZOMB: return ('Z');
1280Sstevel@tonic-gate 		case SIDL: return ('I');
1290Sstevel@tonic-gate 		case SONPROC: return ('O');
1300Sstevel@tonic-gate 		case SSTOP: return ('T');
1313792Sakolb 		case SWAIT: return ('W');
1320Sstevel@tonic-gate 		default: return ('?');
1330Sstevel@tonic-gate 	}
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate #define	PS_PRTTHREADS	0x1
1370Sstevel@tonic-gate #define	PS_PRTLWPS	0x2
1380Sstevel@tonic-gate #define	PS_PSARGS	0x4
1390Sstevel@tonic-gate #define	PS_TASKS	0x8
1400Sstevel@tonic-gate #define	PS_PROJECTS	0x10
1410Sstevel@tonic-gate #define	PS_ZONES	0x20
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate static int
1440Sstevel@tonic-gate ps_threadprint(uintptr_t addr, const void *data, void *private)
1450Sstevel@tonic-gate {
1460Sstevel@tonic-gate 	const kthread_t *t = (const kthread_t *)data;
1470Sstevel@tonic-gate 	uint_t prt_flags = *((uint_t *)private);
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	static const mdb_bitmask_t t_state_bits[] = {
1500Sstevel@tonic-gate 		{ "TS_FREE",	UINT_MAX,	TS_FREE		},
1510Sstevel@tonic-gate 		{ "TS_SLEEP",	TS_SLEEP,	TS_SLEEP	},
1520Sstevel@tonic-gate 		{ "TS_RUN",	TS_RUN,		TS_RUN		},
1530Sstevel@tonic-gate 		{ "TS_ONPROC",	TS_ONPROC,	TS_ONPROC	},
1540Sstevel@tonic-gate 		{ "TS_ZOMB",	TS_ZOMB,	TS_ZOMB		},
1550Sstevel@tonic-gate 		{ "TS_STOPPED",	TS_STOPPED,	TS_STOPPED	},
1563792Sakolb 		{ "TS_WAIT",	TS_WAIT,	TS_WAIT		},
1570Sstevel@tonic-gate 		{ NULL,		0,		0		}
1580Sstevel@tonic-gate 	};
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	if (prt_flags & PS_PRTTHREADS)
1610Sstevel@tonic-gate 		mdb_printf("\tT  %?a <%b>\n", addr, t->t_state, t_state_bits);
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	if (prt_flags & PS_PRTLWPS)
1640Sstevel@tonic-gate 		mdb_printf("\tL  %?a ID: %u\n", t->t_lwp, t->t_tid);
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	return (WALK_NEXT);
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate int
1700Sstevel@tonic-gate ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1710Sstevel@tonic-gate {
1720Sstevel@tonic-gate 	uint_t prt_flags = 0;
1730Sstevel@tonic-gate 	proc_t pr;
1740Sstevel@tonic-gate 	struct pid pid, pgid, sid;
1750Sstevel@tonic-gate 	sess_t session;
1760Sstevel@tonic-gate 	cred_t cred;
1770Sstevel@tonic-gate 	task_t tk;
1780Sstevel@tonic-gate 	kproject_t pj;
1790Sstevel@tonic-gate 	zone_t zn;
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
1820Sstevel@tonic-gate 		if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) {
1830Sstevel@tonic-gate 			mdb_warn("can't walk 'proc'");
1840Sstevel@tonic-gate 			return (DCMD_ERR);
1850Sstevel@tonic-gate 		}
1860Sstevel@tonic-gate 		return (DCMD_OK);
1870Sstevel@tonic-gate 	}
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
1900Sstevel@tonic-gate 	    'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags,
1910Sstevel@tonic-gate 	    'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags,
1920Sstevel@tonic-gate 	    'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags,
1930Sstevel@tonic-gate 	    'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags,
1940Sstevel@tonic-gate 	    'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags,
1950Sstevel@tonic-gate 	    't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc)
1960Sstevel@tonic-gate 		return (DCMD_USAGE);
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
1990Sstevel@tonic-gate 		mdb_printf("%<u>%1s %6s %6s %6s %6s ",
2000Sstevel@tonic-gate 		    "S", "PID", "PPID", "PGID", "SID");
2010Sstevel@tonic-gate 		if (prt_flags & PS_TASKS)
2020Sstevel@tonic-gate 			mdb_printf("%5s ", "TASK");
2030Sstevel@tonic-gate 		if (prt_flags & PS_PROJECTS)
2040Sstevel@tonic-gate 			mdb_printf("%5s ", "PROJ");
2050Sstevel@tonic-gate 		if (prt_flags & PS_ZONES)
2060Sstevel@tonic-gate 			mdb_printf("%5s ", "ZONE");
2070Sstevel@tonic-gate 		mdb_printf("%6s %10s %?s %s%</u>\n",
2080Sstevel@tonic-gate 		    "UID", "FLAGS", "ADDR", "NAME");
2090Sstevel@tonic-gate 	}
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate 	mdb_vread(&pr, sizeof (pr), addr);
2120Sstevel@tonic-gate 	mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp);
2130Sstevel@tonic-gate 	mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp);
2140Sstevel@tonic-gate 	mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred);
2150Sstevel@tonic-gate 	mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp);
2160Sstevel@tonic-gate 	mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp);
2170Sstevel@tonic-gate 	if (prt_flags & (PS_TASKS | PS_PROJECTS))
2180Sstevel@tonic-gate 		mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task);
2190Sstevel@tonic-gate 	if (prt_flags & PS_PROJECTS)
2200Sstevel@tonic-gate 		mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj);
2210Sstevel@tonic-gate 	if (prt_flags & PS_ZONES)
2220Sstevel@tonic-gate 		mdb_vread(&zn, sizeof (zone_t), (uintptr_t)pr.p_zone);
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	mdb_printf("%c %6d %6d %6d %6d ",
2250Sstevel@tonic-gate 	    pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id,
2260Sstevel@tonic-gate 	    sid.pid_id);
2270Sstevel@tonic-gate 	if (prt_flags & PS_TASKS)
2280Sstevel@tonic-gate 		mdb_printf("%5d ", tk.tk_tkid);
2290Sstevel@tonic-gate 	if (prt_flags & PS_PROJECTS)
2300Sstevel@tonic-gate 		mdb_printf("%5d ", pj.kpj_id);
2310Sstevel@tonic-gate 	if (prt_flags & PS_ZONES)
2320Sstevel@tonic-gate 		mdb_printf("%5d ", zn.zone_id);
2330Sstevel@tonic-gate 	mdb_printf("%6d 0x%08x %0?p %s\n",
2340Sstevel@tonic-gate 	    cred.cr_uid, pr.p_flag, addr,
2350Sstevel@tonic-gate 	    (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm);
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 	if (prt_flags & ~PS_PSARGS)
2380Sstevel@tonic-gate 		(void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr);
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	return (DCMD_OK);
2410Sstevel@tonic-gate }
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate #define	PG_NEWEST	0x0001
2440Sstevel@tonic-gate #define	PG_OLDEST	0x0002
2450Sstevel@tonic-gate #define	PG_PIPE_OUT	0x0004
2461014Svb160487 #define	PG_EXACT_MATCH	0x0008
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate typedef struct pgrep_data {
2490Sstevel@tonic-gate 	uint_t pg_flags;
2500Sstevel@tonic-gate 	uint_t pg_psflags;
2510Sstevel@tonic-gate 	uintptr_t pg_xaddr;
2520Sstevel@tonic-gate 	hrtime_t pg_xstart;
2530Sstevel@tonic-gate 	const char *pg_pat;
2540Sstevel@tonic-gate #ifndef _KMDB
2550Sstevel@tonic-gate 	regex_t pg_reg;
2560Sstevel@tonic-gate #endif
2570Sstevel@tonic-gate } pgrep_data_t;
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate /*ARGSUSED*/
2600Sstevel@tonic-gate static int
2610Sstevel@tonic-gate pgrep_cb(uintptr_t addr, const void *pdata, void *data)
2620Sstevel@tonic-gate {
2630Sstevel@tonic-gate 	const proc_t *prp = pdata;
2640Sstevel@tonic-gate 	pgrep_data_t *pgp = data;
2650Sstevel@tonic-gate #ifndef _KMDB
2660Sstevel@tonic-gate 	regmatch_t pmatch;
2670Sstevel@tonic-gate #endif
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 	/*
2700Sstevel@tonic-gate 	 * kmdb doesn't have access to the reg* functions, so we fall back
2711014Svb160487 	 * to strstr/strcmp.
2720Sstevel@tonic-gate 	 */
2730Sstevel@tonic-gate #ifdef _KMDB
2741014Svb160487 	if ((pgp->pg_flags & PG_EXACT_MATCH) ?
2751014Svb160487 	    (strcmp(prp->p_user.u_comm, pgp->pg_pat) != 0) :
2761014Svb160487 	    (strstr(prp->p_user.u_comm, pgp->pg_pat) == NULL))
2770Sstevel@tonic-gate 		return (WALK_NEXT);
2780Sstevel@tonic-gate #else
2790Sstevel@tonic-gate 	if (regexec(&pgp->pg_reg, prp->p_user.u_comm, 1, &pmatch, 0) != 0)
2800Sstevel@tonic-gate 		return (WALK_NEXT);
2811014Svb160487 
2821014Svb160487 	if ((pgp->pg_flags & PG_EXACT_MATCH) &&
2831014Svb160487 	    (pmatch.rm_so != 0 || prp->p_user.u_comm[pmatch.rm_eo] != '\0'))
2841014Svb160487 		return (WALK_NEXT);
2850Sstevel@tonic-gate #endif
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 	if (pgp->pg_flags & (PG_NEWEST | PG_OLDEST)) {
2880Sstevel@tonic-gate 		hrtime_t start;
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 		start = (hrtime_t)prp->p_user.u_start.tv_sec * NANOSEC +
2910Sstevel@tonic-gate 		    prp->p_user.u_start.tv_nsec;
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate 		if (pgp->pg_flags & PG_NEWEST) {
2940Sstevel@tonic-gate 			if (pgp->pg_xaddr == NULL || start > pgp->pg_xstart) {
2950Sstevel@tonic-gate 				pgp->pg_xaddr = addr;
2960Sstevel@tonic-gate 				pgp->pg_xstart = start;
2970Sstevel@tonic-gate 			}
2980Sstevel@tonic-gate 		} else {
2990Sstevel@tonic-gate 			if (pgp->pg_xaddr == NULL || start < pgp->pg_xstart) {
3000Sstevel@tonic-gate 				pgp->pg_xaddr = addr;
3010Sstevel@tonic-gate 				pgp->pg_xstart = start;
3020Sstevel@tonic-gate 			}
3030Sstevel@tonic-gate 		}
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	} else if (pgp->pg_flags & PG_PIPE_OUT) {
3060Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 	} else {
3090Sstevel@tonic-gate 		if (mdb_call_dcmd("ps", addr, pgp->pg_psflags, 0, NULL) != 0) {
3100Sstevel@tonic-gate 			mdb_warn("can't invoke 'ps'");
3110Sstevel@tonic-gate 			return (WALK_DONE);
3120Sstevel@tonic-gate 		}
3130Sstevel@tonic-gate 		pgp->pg_psflags &= ~DCMD_LOOPFIRST;
3140Sstevel@tonic-gate 	}
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate 	return (WALK_NEXT);
3170Sstevel@tonic-gate }
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate /*ARGSUSED*/
3200Sstevel@tonic-gate int
3210Sstevel@tonic-gate pgrep(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3220Sstevel@tonic-gate {
3230Sstevel@tonic-gate 	pgrep_data_t pg;
3240Sstevel@tonic-gate 	int i;
3250Sstevel@tonic-gate #ifndef _KMDB
3260Sstevel@tonic-gate 	int err;
3270Sstevel@tonic-gate #endif
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
3300Sstevel@tonic-gate 		return (DCMD_USAGE);
3310Sstevel@tonic-gate 
3320Sstevel@tonic-gate 	pg.pg_flags = 0;
3330Sstevel@tonic-gate 	pg.pg_xaddr = 0;
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 	i = mdb_getopts(argc, argv,
3360Sstevel@tonic-gate 	    'n', MDB_OPT_SETBITS, PG_NEWEST, &pg.pg_flags,
3370Sstevel@tonic-gate 	    'o', MDB_OPT_SETBITS, PG_OLDEST, &pg.pg_flags,
3381014Svb160487 	    'x', MDB_OPT_SETBITS, PG_EXACT_MATCH, &pg.pg_flags,
3390Sstevel@tonic-gate 	    NULL);
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate 	argc -= i;
3420Sstevel@tonic-gate 	argv += i;
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate 	if (argc != 1)
3450Sstevel@tonic-gate 		return (DCMD_USAGE);
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 	/*
3480Sstevel@tonic-gate 	 * -n and -o are mutually exclusive.
3490Sstevel@tonic-gate 	 */
3500Sstevel@tonic-gate 	if ((pg.pg_flags & PG_NEWEST) && (pg.pg_flags & PG_OLDEST))
3510Sstevel@tonic-gate 		return (DCMD_USAGE);
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate 	if (argv->a_type != MDB_TYPE_STRING)
3540Sstevel@tonic-gate 		return (DCMD_USAGE);
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate 	if (flags & DCMD_PIPE_OUT)
3570Sstevel@tonic-gate 		pg.pg_flags |= PG_PIPE_OUT;
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	pg.pg_pat = argv->a_un.a_str;
3600Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
3610Sstevel@tonic-gate 		pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP | DCMD_LOOPFIRST;
3620Sstevel@tonic-gate 	else
3630Sstevel@tonic-gate 		pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP;
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate #ifndef _KMDB
3660Sstevel@tonic-gate 	if ((err = regcomp(&pg.pg_reg, pg.pg_pat, REG_EXTENDED)) != 0) {
3670Sstevel@tonic-gate 		size_t nbytes;
3680Sstevel@tonic-gate 		char *buf;
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate 		nbytes = regerror(err, &pg.pg_reg, NULL, 0);
3710Sstevel@tonic-gate 		buf = mdb_alloc(nbytes + 1, UM_SLEEP | UM_GC);
3720Sstevel@tonic-gate 		(void) regerror(err, &pg.pg_reg, buf, nbytes);
3730Sstevel@tonic-gate 		mdb_warn("%s\n", buf);
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate 		return (DCMD_ERR);
3760Sstevel@tonic-gate 	}
3770Sstevel@tonic-gate #endif
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 	if (mdb_walk("proc", pgrep_cb, &pg) != 0) {
3800Sstevel@tonic-gate 		mdb_warn("can't walk 'proc'");
3810Sstevel@tonic-gate 		return (DCMD_ERR);
3820Sstevel@tonic-gate 	}
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate 	if (pg.pg_xaddr != 0 && (pg.pg_flags & (PG_NEWEST | PG_OLDEST))) {
3850Sstevel@tonic-gate 		if (pg.pg_flags & PG_PIPE_OUT) {
3860Sstevel@tonic-gate 			mdb_printf("%p\n", pg.pg_xaddr);
3870Sstevel@tonic-gate 		} else {
3880Sstevel@tonic-gate 			if (mdb_call_dcmd("ps", pg.pg_xaddr, pg.pg_psflags,
3890Sstevel@tonic-gate 			    0, NULL) != 0) {
3900Sstevel@tonic-gate 				mdb_warn("can't invoke 'ps'");
3910Sstevel@tonic-gate 				return (DCMD_ERR);
3920Sstevel@tonic-gate 			}
3930Sstevel@tonic-gate 		}
3940Sstevel@tonic-gate 	}
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate 	return (DCMD_OK);
3970Sstevel@tonic-gate }
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate int
4000Sstevel@tonic-gate task(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4010Sstevel@tonic-gate {
4020Sstevel@tonic-gate 	task_t tk;
4030Sstevel@tonic-gate 	kproject_t pj;
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
4060Sstevel@tonic-gate 		if (mdb_walk_dcmd("task_cache", "task", argc, argv) == -1) {
4070Sstevel@tonic-gate 			mdb_warn("can't walk task_cache");
4080Sstevel@tonic-gate 			return (DCMD_ERR);
4090Sstevel@tonic-gate 		}
4100Sstevel@tonic-gate 		return (DCMD_OK);
4110Sstevel@tonic-gate 	}
4120Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
4130Sstevel@tonic-gate 		mdb_printf("%<u>%?s %6s %6s %6s %6s %10s%</u>\n",
4140Sstevel@tonic-gate 		    "ADDR", "TASKID", "PROJID", "ZONEID", "REFCNT", "FLAGS");
4150Sstevel@tonic-gate 	}
4160Sstevel@tonic-gate 	if (mdb_vread(&tk, sizeof (task_t), addr) == -1) {
4170Sstevel@tonic-gate 		mdb_warn("can't read task_t structure at %p", addr);
4180Sstevel@tonic-gate 		return (DCMD_ERR);
4190Sstevel@tonic-gate 	}
4200Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), (uintptr_t)tk.tk_proj) == -1) {
4210Sstevel@tonic-gate 		mdb_warn("can't read project_t structure at %p", addr);
4220Sstevel@tonic-gate 		return (DCMD_ERR);
4230Sstevel@tonic-gate 	}
4240Sstevel@tonic-gate 	mdb_printf("%0?p %6d %6d %6d %6u 0x%08x\n",
4250Sstevel@tonic-gate 	    addr, tk.tk_tkid, pj.kpj_id, pj.kpj_zoneid, tk.tk_hold_count,
4260Sstevel@tonic-gate 	    tk.tk_flags);
4270Sstevel@tonic-gate 	return (DCMD_OK);
4280Sstevel@tonic-gate }
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate int
4310Sstevel@tonic-gate project(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4320Sstevel@tonic-gate {
4330Sstevel@tonic-gate 	kproject_t pj;
4340Sstevel@tonic-gate 
4350Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
4360Sstevel@tonic-gate 		if (mdb_walk_dcmd("projects", "project", argc, argv) == -1) {
4370Sstevel@tonic-gate 			mdb_warn("can't walk projects");
4380Sstevel@tonic-gate 			return (DCMD_ERR);
4390Sstevel@tonic-gate 		}
4400Sstevel@tonic-gate 		return (DCMD_OK);
4410Sstevel@tonic-gate 	}
4420Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
4430Sstevel@tonic-gate 		mdb_printf("%<u>%?s %6s %6s %6s%</u>\n",
4440Sstevel@tonic-gate 		    "ADDR", "PROJID", "ZONEID", "REFCNT");
4450Sstevel@tonic-gate 	}
4460Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
4470Sstevel@tonic-gate 		mdb_warn("can't read kproject_t structure at %p", addr);
4480Sstevel@tonic-gate 		return (DCMD_ERR);
4490Sstevel@tonic-gate 	}
4500Sstevel@tonic-gate 	mdb_printf("%0?p %6d %6d %6u\n", addr, pj.kpj_id, pj.kpj_zoneid,
4510Sstevel@tonic-gate 	    pj.kpj_count);
4520Sstevel@tonic-gate 	return (DCMD_OK);
4530Sstevel@tonic-gate }
4540Sstevel@tonic-gate 
4558048SMadhavan.Venkataraman@Sun.COM /* walk callouts themselves, either by list or id hash. */
4568048SMadhavan.Venkataraman@Sun.COM int
4578048SMadhavan.Venkataraman@Sun.COM callout_walk_init(mdb_walk_state_t *wsp)
4588048SMadhavan.Venkataraman@Sun.COM {
4598048SMadhavan.Venkataraman@Sun.COM 	if (wsp->walk_addr == NULL) {
4608048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("callout doesn't support global walk");
4618048SMadhavan.Venkataraman@Sun.COM 		return (WALK_ERR);
4628048SMadhavan.Venkataraman@Sun.COM 	}
4638048SMadhavan.Venkataraman@Sun.COM 	wsp->walk_data = mdb_alloc(sizeof (callout_t), UM_SLEEP);
4648048SMadhavan.Venkataraman@Sun.COM 	return (WALK_NEXT);
4658048SMadhavan.Venkataraman@Sun.COM }
4668048SMadhavan.Venkataraman@Sun.COM 
4678048SMadhavan.Venkataraman@Sun.COM #define	CALLOUT_WALK_BYLIST	0
4688048SMadhavan.Venkataraman@Sun.COM #define	CALLOUT_WALK_BYID	1
4698048SMadhavan.Venkataraman@Sun.COM 
4708048SMadhavan.Venkataraman@Sun.COM /* the walker arg switches between walking by list (0) and walking by id (1). */
4718048SMadhavan.Venkataraman@Sun.COM int
4728048SMadhavan.Venkataraman@Sun.COM callout_walk_step(mdb_walk_state_t *wsp)
4738048SMadhavan.Venkataraman@Sun.COM {
4748048SMadhavan.Venkataraman@Sun.COM 	int retval;
4758048SMadhavan.Venkataraman@Sun.COM 
4768048SMadhavan.Venkataraman@Sun.COM 	if (wsp->walk_addr == NULL) {
4778048SMadhavan.Venkataraman@Sun.COM 		return (WALK_DONE);
4788048SMadhavan.Venkataraman@Sun.COM 	}
4798048SMadhavan.Venkataraman@Sun.COM 	if (mdb_vread(wsp->walk_data, sizeof (callout_t),
4808048SMadhavan.Venkataraman@Sun.COM 	    wsp->walk_addr) == -1) {
4818048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("failed to read callout at %p", wsp->walk_addr);
4828048SMadhavan.Venkataraman@Sun.COM 		return (WALK_DONE);
4838048SMadhavan.Venkataraman@Sun.COM 	}
4848048SMadhavan.Venkataraman@Sun.COM 	retval = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
4858048SMadhavan.Venkataraman@Sun.COM 	    wsp->walk_cbdata);
4868048SMadhavan.Venkataraman@Sun.COM 
4878048SMadhavan.Venkataraman@Sun.COM 	if ((ulong_t)wsp->walk_arg == CALLOUT_WALK_BYID) {
4888048SMadhavan.Venkataraman@Sun.COM 		wsp->walk_addr =
4898048SMadhavan.Venkataraman@Sun.COM 		    (uintptr_t)(((callout_t *)wsp->walk_data)->c_idnext);
4908048SMadhavan.Venkataraman@Sun.COM 	} else {
4918048SMadhavan.Venkataraman@Sun.COM 		wsp->walk_addr =
4928048SMadhavan.Venkataraman@Sun.COM 		    (uintptr_t)(((callout_t *)wsp->walk_data)->c_clnext);
4938048SMadhavan.Venkataraman@Sun.COM 	}
4948048SMadhavan.Venkataraman@Sun.COM 
4958048SMadhavan.Venkataraman@Sun.COM 	return (retval);
4968048SMadhavan.Venkataraman@Sun.COM }
4978048SMadhavan.Venkataraman@Sun.COM 
4988048SMadhavan.Venkataraman@Sun.COM void
4998048SMadhavan.Venkataraman@Sun.COM callout_walk_fini(mdb_walk_state_t *wsp)
5008048SMadhavan.Venkataraman@Sun.COM {
5018048SMadhavan.Venkataraman@Sun.COM 	mdb_free(wsp->walk_data, sizeof (callout_t));
5028048SMadhavan.Venkataraman@Sun.COM }
5038048SMadhavan.Venkataraman@Sun.COM 
5048048SMadhavan.Venkataraman@Sun.COM /*
5058048SMadhavan.Venkataraman@Sun.COM  * walker for callout lists. This is different from hashes and callouts.
5068048SMadhavan.Venkataraman@Sun.COM  * Thankfully, it's also simpler.
5078048SMadhavan.Venkataraman@Sun.COM  */
5088048SMadhavan.Venkataraman@Sun.COM int
5098048SMadhavan.Venkataraman@Sun.COM callout_list_walk_init(mdb_walk_state_t *wsp)
5108048SMadhavan.Venkataraman@Sun.COM {
5118048SMadhavan.Venkataraman@Sun.COM 	if (wsp->walk_addr == NULL) {
5128048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("callout list doesn't support global walk");
5138048SMadhavan.Venkataraman@Sun.COM 		return (WALK_ERR);
5148048SMadhavan.Venkataraman@Sun.COM 	}
5158048SMadhavan.Venkataraman@Sun.COM 	wsp->walk_data = mdb_alloc(sizeof (callout_list_t), UM_SLEEP);
5168048SMadhavan.Venkataraman@Sun.COM 	return (WALK_NEXT);
5178048SMadhavan.Venkataraman@Sun.COM }
5188048SMadhavan.Venkataraman@Sun.COM 
5198048SMadhavan.Venkataraman@Sun.COM int
5208048SMadhavan.Venkataraman@Sun.COM callout_list_walk_step(mdb_walk_state_t *wsp)
5218048SMadhavan.Venkataraman@Sun.COM {
5228048SMadhavan.Venkataraman@Sun.COM 	int retval;
5238048SMadhavan.Venkataraman@Sun.COM 
5248048SMadhavan.Venkataraman@Sun.COM 	if (wsp->walk_addr == NULL) {
5258048SMadhavan.Venkataraman@Sun.COM 		return (WALK_DONE);
5268048SMadhavan.Venkataraman@Sun.COM 	}
5278048SMadhavan.Venkataraman@Sun.COM 	if (mdb_vread(wsp->walk_data, sizeof (callout_list_t),
5288048SMadhavan.Venkataraman@Sun.COM 	    wsp->walk_addr) != sizeof (callout_list_t)) {
5298048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("failed to read callout_list at %p", wsp->walk_addr);
5308048SMadhavan.Venkataraman@Sun.COM 		return (WALK_ERR);
5318048SMadhavan.Venkataraman@Sun.COM 	}
5328048SMadhavan.Venkataraman@Sun.COM 	retval = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
5338048SMadhavan.Venkataraman@Sun.COM 	    wsp->walk_cbdata);
5348048SMadhavan.Venkataraman@Sun.COM 
5358048SMadhavan.Venkataraman@Sun.COM 	wsp->walk_addr = (uintptr_t)
5368048SMadhavan.Venkataraman@Sun.COM 	    (((callout_list_t *)wsp->walk_data)->cl_next);
5378048SMadhavan.Venkataraman@Sun.COM 
5388048SMadhavan.Venkataraman@Sun.COM 	return (retval);
5398048SMadhavan.Venkataraman@Sun.COM }
5408048SMadhavan.Venkataraman@Sun.COM 
5418048SMadhavan.Venkataraman@Sun.COM void
5428048SMadhavan.Venkataraman@Sun.COM callout_list_walk_fini(mdb_walk_state_t *wsp)
5438048SMadhavan.Venkataraman@Sun.COM {
5448048SMadhavan.Venkataraman@Sun.COM 	mdb_free(wsp->walk_data, sizeof (callout_list_t));
5458048SMadhavan.Venkataraman@Sun.COM }
5468048SMadhavan.Venkataraman@Sun.COM 
5478048SMadhavan.Venkataraman@Sun.COM /* routines/structs to walk callout table(s) */
5488048SMadhavan.Venkataraman@Sun.COM typedef struct cot_data {
5498048SMadhavan.Venkataraman@Sun.COM 	callout_table_t *ct0;
5508048SMadhavan.Venkataraman@Sun.COM 	callout_table_t ct;
5518048SMadhavan.Venkataraman@Sun.COM 	callout_hash_t cot_idhash[CALLOUT_BUCKETS];
5528048SMadhavan.Venkataraman@Sun.COM 	callout_hash_t cot_clhash[CALLOUT_BUCKETS];
5538048SMadhavan.Venkataraman@Sun.COM 	kstat_named_t ct_kstat_data[CALLOUT_NUM_STATS];
5548048SMadhavan.Venkataraman@Sun.COM 	int cotndx;
5558048SMadhavan.Venkataraman@Sun.COM 	int cotsize;
5568048SMadhavan.Venkataraman@Sun.COM } cot_data_t;
5578048SMadhavan.Venkataraman@Sun.COM 
5588048SMadhavan.Venkataraman@Sun.COM int
5598048SMadhavan.Venkataraman@Sun.COM callout_table_walk_init(mdb_walk_state_t *wsp)
5608048SMadhavan.Venkataraman@Sun.COM {
5618048SMadhavan.Venkataraman@Sun.COM 	int max_ncpus;
5628048SMadhavan.Venkataraman@Sun.COM 	cot_data_t *cot_walk_data;
5638048SMadhavan.Venkataraman@Sun.COM 
5648048SMadhavan.Venkataraman@Sun.COM 	cot_walk_data = mdb_alloc(sizeof (cot_data_t), UM_SLEEP);
5658048SMadhavan.Venkataraman@Sun.COM 
5668048SMadhavan.Venkataraman@Sun.COM 	if (wsp->walk_addr == NULL) {
5678048SMadhavan.Venkataraman@Sun.COM 		if (mdb_readvar(&cot_walk_data->ct0, "callout_table") == -1) {
5688048SMadhavan.Venkataraman@Sun.COM 			mdb_warn("failed to read 'callout_table'");
5698048SMadhavan.Venkataraman@Sun.COM 			return (WALK_ERR);
5708048SMadhavan.Venkataraman@Sun.COM 		}
5718048SMadhavan.Venkataraman@Sun.COM 		if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
5728048SMadhavan.Venkataraman@Sun.COM 			mdb_warn("failed to get callout_table array size");
5738048SMadhavan.Venkataraman@Sun.COM 			return (WALK_ERR);
5748048SMadhavan.Venkataraman@Sun.COM 		}
5758048SMadhavan.Venkataraman@Sun.COM 		cot_walk_data->cotsize = CALLOUT_NTYPES * max_ncpus;
5768048SMadhavan.Venkataraman@Sun.COM 		wsp->walk_addr = (uintptr_t)cot_walk_data->ct0;
5778048SMadhavan.Venkataraman@Sun.COM 	} else {
5788048SMadhavan.Venkataraman@Sun.COM 		/* not a global walk */
5798048SMadhavan.Venkataraman@Sun.COM 		cot_walk_data->cotsize = 1;
5808048SMadhavan.Venkataraman@Sun.COM 	}
5818048SMadhavan.Venkataraman@Sun.COM 
5828048SMadhavan.Venkataraman@Sun.COM 	cot_walk_data->cotndx = 0;
5838048SMadhavan.Venkataraman@Sun.COM 	wsp->walk_data = cot_walk_data;
5848048SMadhavan.Venkataraman@Sun.COM 
5858048SMadhavan.Venkataraman@Sun.COM 	return (WALK_NEXT);
5868048SMadhavan.Venkataraman@Sun.COM }
5878048SMadhavan.Venkataraman@Sun.COM 
5888048SMadhavan.Venkataraman@Sun.COM int
5898048SMadhavan.Venkataraman@Sun.COM callout_table_walk_step(mdb_walk_state_t *wsp)
5908048SMadhavan.Venkataraman@Sun.COM {
5918048SMadhavan.Venkataraman@Sun.COM 	int retval;
5928048SMadhavan.Venkataraman@Sun.COM 	cot_data_t *cotwd = (cot_data_t *)wsp->walk_data;
5938048SMadhavan.Venkataraman@Sun.COM 	size_t size;
5948048SMadhavan.Venkataraman@Sun.COM 
5958048SMadhavan.Venkataraman@Sun.COM 	if (cotwd->cotndx >= cotwd->cotsize) {
5968048SMadhavan.Venkataraman@Sun.COM 		return (WALK_DONE);
5978048SMadhavan.Venkataraman@Sun.COM 	}
5988048SMadhavan.Venkataraman@Sun.COM 	if (mdb_vread(&(cotwd->ct), sizeof (callout_table_t),
5998048SMadhavan.Venkataraman@Sun.COM 	    wsp->walk_addr) != sizeof (callout_table_t)) {
6008048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("failed to read callout_table at %p", wsp->walk_addr);
6018048SMadhavan.Venkataraman@Sun.COM 		return (WALK_ERR);
6028048SMadhavan.Venkataraman@Sun.COM 	}
6038048SMadhavan.Venkataraman@Sun.COM 
6048048SMadhavan.Venkataraman@Sun.COM 	size = sizeof (callout_hash_t) * CALLOUT_BUCKETS;
6058048SMadhavan.Venkataraman@Sun.COM 	if (cotwd->ct.ct_idhash != NULL) {
6068048SMadhavan.Venkataraman@Sun.COM 		if (mdb_vread(cotwd->cot_idhash, size,
6078048SMadhavan.Venkataraman@Sun.COM 		    (uintptr_t)(cotwd->ct.ct_idhash)) != size) {
6088048SMadhavan.Venkataraman@Sun.COM 			mdb_warn("failed to read id_hash at %p",
6098048SMadhavan.Venkataraman@Sun.COM 			    cotwd->ct.ct_idhash);
6108048SMadhavan.Venkataraman@Sun.COM 			return (WALK_ERR);
6118048SMadhavan.Venkataraman@Sun.COM 		}
6128048SMadhavan.Venkataraman@Sun.COM 	}
6138048SMadhavan.Venkataraman@Sun.COM 	if (cotwd->ct.ct_clhash != NULL) {
6148048SMadhavan.Venkataraman@Sun.COM 		if (mdb_vread(&(cotwd->cot_clhash), size,
6158048SMadhavan.Venkataraman@Sun.COM 		    (uintptr_t)cotwd->ct.ct_clhash) == -1) {
6168048SMadhavan.Venkataraman@Sun.COM 			mdb_warn("failed to read cl_hash at %p",
6178048SMadhavan.Venkataraman@Sun.COM 			    cotwd->ct.ct_clhash);
6188048SMadhavan.Venkataraman@Sun.COM 			return (WALK_ERR);
6198048SMadhavan.Venkataraman@Sun.COM 		}
6208048SMadhavan.Venkataraman@Sun.COM 	}
6218048SMadhavan.Venkataraman@Sun.COM 	size = sizeof (kstat_named_t) * CALLOUT_NUM_STATS;
6228048SMadhavan.Venkataraman@Sun.COM 	if (cotwd->ct.ct_kstat_data != NULL) {
6238048SMadhavan.Venkataraman@Sun.COM 		if (mdb_vread(&(cotwd->ct_kstat_data), size,
6248048SMadhavan.Venkataraman@Sun.COM 		    (uintptr_t)cotwd->ct.ct_kstat_data) == -1) {
6258048SMadhavan.Venkataraman@Sun.COM 			mdb_warn("failed to read kstats at %p",
6268048SMadhavan.Venkataraman@Sun.COM 			    cotwd->ct.ct_kstat_data);
6278048SMadhavan.Venkataraman@Sun.COM 			return (WALK_ERR);
6288048SMadhavan.Venkataraman@Sun.COM 		}
6298048SMadhavan.Venkataraman@Sun.COM 	}
6308048SMadhavan.Venkataraman@Sun.COM 	retval = wsp->walk_callback(wsp->walk_addr, (void *)cotwd,
6318048SMadhavan.Venkataraman@Sun.COM 	    wsp->walk_cbdata);
6328048SMadhavan.Venkataraman@Sun.COM 
6338048SMadhavan.Venkataraman@Sun.COM 	cotwd->cotndx++;
6348048SMadhavan.Venkataraman@Sun.COM 	if (cotwd->cotndx >= cotwd->cotsize) {
6358048SMadhavan.Venkataraman@Sun.COM 		return (WALK_DONE);
6368048SMadhavan.Venkataraman@Sun.COM 	}
6378048SMadhavan.Venkataraman@Sun.COM 	wsp->walk_addr = (uintptr_t)((char *)wsp->walk_addr +
6388048SMadhavan.Venkataraman@Sun.COM 	    sizeof (callout_table_t));
6398048SMadhavan.Venkataraman@Sun.COM 
6408048SMadhavan.Venkataraman@Sun.COM 	return (retval);
6418048SMadhavan.Venkataraman@Sun.COM }
6428048SMadhavan.Venkataraman@Sun.COM 
6438048SMadhavan.Venkataraman@Sun.COM void
6448048SMadhavan.Venkataraman@Sun.COM callout_table_walk_fini(mdb_walk_state_t *wsp)
6458048SMadhavan.Venkataraman@Sun.COM {
6468048SMadhavan.Venkataraman@Sun.COM 	mdb_free(wsp->walk_data, sizeof (cot_data_t));
6478048SMadhavan.Venkataraman@Sun.COM }
6488048SMadhavan.Venkataraman@Sun.COM 
6498048SMadhavan.Venkataraman@Sun.COM static const char *co_typenames[] = { "R", "N" };
6508048SMadhavan.Venkataraman@Sun.COM 
6518048SMadhavan.Venkataraman@Sun.COM #define	CO_PLAIN_ID(xid)	 ((xid) & ~CALLOUT_EXECUTING)
6528048SMadhavan.Venkataraman@Sun.COM 
6538048SMadhavan.Venkataraman@Sun.COM #define	TABLE_TO_SEQID(x)	((x) >> CALLOUT_TYPE_BITS)
6548048SMadhavan.Venkataraman@Sun.COM 
6558048SMadhavan.Venkataraman@Sun.COM /* callout flags, in no particular order */
6568048SMadhavan.Venkataraman@Sun.COM #define	COF_REAL	0x0000001
6578048SMadhavan.Venkataraman@Sun.COM #define	COF_NORM	0x0000002
6588048SMadhavan.Venkataraman@Sun.COM #define	COF_LONG	0x0000004
6598048SMadhavan.Venkataraman@Sun.COM #define	COF_SHORT	0x0000008
6608048SMadhavan.Venkataraman@Sun.COM #define	COF_EMPTY	0x0000010
6618048SMadhavan.Venkataraman@Sun.COM #define	COF_TIME	0x0000020
6628048SMadhavan.Venkataraman@Sun.COM #define	COF_BEFORE	0x0000040
6638048SMadhavan.Venkataraman@Sun.COM #define	COF_AFTER	0x0000080
6648048SMadhavan.Venkataraman@Sun.COM #define	COF_SEQID	0x0000100
6658048SMadhavan.Venkataraman@Sun.COM #define	COF_FUNC	0x0000200
6668048SMadhavan.Venkataraman@Sun.COM #define	COF_ADDR	0x0000400
6678048SMadhavan.Venkataraman@Sun.COM #define	COF_EXEC	0x0000800
6688048SMadhavan.Venkataraman@Sun.COM #define	COF_HIRES	0x0001000
6698048SMadhavan.Venkataraman@Sun.COM /* 0x0002000 reserved for future flags */
6708048SMadhavan.Venkataraman@Sun.COM #define	COF_TABLE	0x0004000
6718048SMadhavan.Venkataraman@Sun.COM #define	COF_BYIDH	0x0008000
6728048SMadhavan.Venkataraman@Sun.COM #define	COF_FREE	0x0010000
6738048SMadhavan.Venkataraman@Sun.COM #define	COF_LIST	0x0020000
6748048SMadhavan.Venkataraman@Sun.COM #define	COF_EXPREL	0x0040000
6758048SMadhavan.Venkataraman@Sun.COM #define	COF_HDR		0x0080000
6768048SMadhavan.Venkataraman@Sun.COM #define	COF_VERBOSE	0x0100000
6778048SMadhavan.Venkataraman@Sun.COM #define	COF_LONGLIST	0x0200000
6788048SMadhavan.Venkataraman@Sun.COM #define	COF_THDR	0x0400000
6798048SMadhavan.Venkataraman@Sun.COM #define	COF_LHDR	0x0800000
6808048SMadhavan.Venkataraman@Sun.COM #define	COF_CHDR	0x1000000
6818048SMadhavan.Venkataraman@Sun.COM #define	COF_PARAM	0x2000000
6828048SMadhavan.Venkataraman@Sun.COM #define	COF_DECODE	0x4000000
6838048SMadhavan.Venkataraman@Sun.COM 
6848048SMadhavan.Venkataraman@Sun.COM /* show real and normal, short and long, expired and unexpired. */
6858048SMadhavan.Venkataraman@Sun.COM #define	COF_DEFAULT	(COF_REAL | COF_NORM | COF_LONG | COF_SHORT)
6868048SMadhavan.Venkataraman@Sun.COM 
6878048SMadhavan.Venkataraman@Sun.COM /* private callout data for callback functions */
6888048SMadhavan.Venkataraman@Sun.COM typedef struct callout_data {
6898048SMadhavan.Venkataraman@Sun.COM 	uint_t flags;		/* COF_* */
6908048SMadhavan.Venkataraman@Sun.COM 	cpu_t *cpu;		/* cpu pointer if given */
6918048SMadhavan.Venkataraman@Sun.COM 	int seqid;		/* cpu seqid, or -1 */
6928048SMadhavan.Venkataraman@Sun.COM 	hrtime_t time;		/* expiration time value */
6938048SMadhavan.Venkataraman@Sun.COM 	hrtime_t atime;		/* expiration before value */
6948048SMadhavan.Venkataraman@Sun.COM 	hrtime_t btime;		/* expiration after value */
6958048SMadhavan.Venkataraman@Sun.COM 	uintptr_t funcaddr;	/* function address or NULL */
6968048SMadhavan.Venkataraman@Sun.COM 	uintptr_t param;	/* parameter to function or NULL */
6978048SMadhavan.Venkataraman@Sun.COM 	hrtime_t now;		/* current system time */
6988048SMadhavan.Venkataraman@Sun.COM 	int nsec_per_tick;	/* for conversions */
6998048SMadhavan.Venkataraman@Sun.COM 	ulong_t ctbits;		/* for decoding xid */
7008048SMadhavan.Venkataraman@Sun.COM 	callout_table_t *co_table;	/* top of callout table array */
7018048SMadhavan.Venkataraman@Sun.COM 	int ndx;		/* table index. */
7028048SMadhavan.Venkataraman@Sun.COM 	int bucket;		/* which list/id bucket are we in */
7038048SMadhavan.Venkataraman@Sun.COM 	hrtime_t exp;		/* expire time */
7048048SMadhavan.Venkataraman@Sun.COM } callout_data_t;
7058048SMadhavan.Venkataraman@Sun.COM 
7068048SMadhavan.Venkataraman@Sun.COM /* this callback does the actual callback itself (finally). */
7078048SMadhavan.Venkataraman@Sun.COM /*ARGSUSED*/
7088048SMadhavan.Venkataraman@Sun.COM static int
7098048SMadhavan.Venkataraman@Sun.COM callouts_cb(uintptr_t addr, const void *data, void *priv)
7108048SMadhavan.Venkataraman@Sun.COM {
7118048SMadhavan.Venkataraman@Sun.COM 	callout_data_t *coargs = (callout_data_t *)priv;
7128048SMadhavan.Venkataraman@Sun.COM 	callout_t *co = (callout_t *)data;
7138048SMadhavan.Venkataraman@Sun.COM 	int tableid;
7148048SMadhavan.Venkataraman@Sun.COM 	callout_id_t coid;
7158048SMadhavan.Venkataraman@Sun.COM 
7168048SMadhavan.Venkataraman@Sun.COM 	if ((coargs == NULL) || (co == NULL)) {
7178048SMadhavan.Venkataraman@Sun.COM 		return (WALK_ERR);
7188048SMadhavan.Venkataraman@Sun.COM 	}
7198048SMadhavan.Venkataraman@Sun.COM 
7208048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_FUNC) &&
7218048SMadhavan.Venkataraman@Sun.COM 	    (coargs->funcaddr != (uintptr_t)co->c_func)) {
7228048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
7238048SMadhavan.Venkataraman@Sun.COM 	}
7248048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_PARAM) &&
7258048SMadhavan.Venkataraman@Sun.COM 	    (coargs->param != (uintptr_t)co->c_arg)) {
7268048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
7278048SMadhavan.Venkataraman@Sun.COM 	}
7288048SMadhavan.Venkataraman@Sun.COM 
7298048SMadhavan.Venkataraman@Sun.COM 	if (!(coargs->flags & COF_LONG) && (co->c_xid & CALLOUT_LONGTERM)) {
7308048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
7318048SMadhavan.Venkataraman@Sun.COM 	}
7328048SMadhavan.Venkataraman@Sun.COM 	if (!(coargs->flags & COF_SHORT) && !(co->c_xid & CALLOUT_LONGTERM)) {
7338048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
7348048SMadhavan.Venkataraman@Sun.COM 	}
7358048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_EXEC) && !(co->c_xid & CALLOUT_EXECUTING)) {
7368048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
7378048SMadhavan.Venkataraman@Sun.COM 	}
7388048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_HIRES) && !(co->c_xid & CALLOUT_HRESTIME)) {
7398048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
7408048SMadhavan.Venkataraman@Sun.COM 	}
7418048SMadhavan.Venkataraman@Sun.COM 
7428048SMadhavan.Venkataraman@Sun.COM 	/* it is possible we don't have the exp time */
7438048SMadhavan.Venkataraman@Sun.COM 	if (coargs->flags & COF_BYIDH) {
7448048SMadhavan.Venkataraman@Sun.COM 		if (!(coargs->flags & COF_FREE)) {
7458048SMadhavan.Venkataraman@Sun.COM 			/* we have to fetch the expire time ourselves. */
7468048SMadhavan.Venkataraman@Sun.COM 			if (mdb_vread(&coargs->exp, sizeof (hrtime_t),
7478048SMadhavan.Venkataraman@Sun.COM 			    (uintptr_t)co->c_list + offsetof(callout_list_t,
7488048SMadhavan.Venkataraman@Sun.COM 			    cl_expiration)) == -1) {
7498048SMadhavan.Venkataraman@Sun.COM 				mdb_warn("failed to read expiration "
7508048SMadhavan.Venkataraman@Sun.COM 				    "time from %p", co->c_list);
7518048SMadhavan.Venkataraman@Sun.COM 				coargs->exp = 0;
7528048SMadhavan.Venkataraman@Sun.COM 			}
7538048SMadhavan.Venkataraman@Sun.COM 		} else {
7548048SMadhavan.Venkataraman@Sun.COM 			/* free callouts can't use list pointer. */
7558048SMadhavan.Venkataraman@Sun.COM 			coargs->exp = 0;
7568048SMadhavan.Venkataraman@Sun.COM 		}
7578048SMadhavan.Venkataraman@Sun.COM 	}
7588048SMadhavan.Venkataraman@Sun.COM 
7598048SMadhavan.Venkataraman@Sun.COM #define	callout_table_mask	((1 << coargs->ctbits) - 1)
7608048SMadhavan.Venkataraman@Sun.COM 	tableid = CALLOUT_ID_TO_TABLE(co->c_xid);
7618048SMadhavan.Venkataraman@Sun.COM #undef	callout_table_mask
7628048SMadhavan.Venkataraman@Sun.COM 	coid = CO_PLAIN_ID(co->c_xid);
7638048SMadhavan.Venkataraman@Sun.COM 
7648048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_CHDR) && !(coargs->flags & COF_ADDR)) {
7658048SMadhavan.Venkataraman@Sun.COM 		/*
7668048SMadhavan.Venkataraman@Sun.COM 		 * We need to print the headers. If walking by id, then
7678048SMadhavan.Venkataraman@Sun.COM 		 * the list header isn't printed, so we must include
7688048SMadhavan.Venkataraman@Sun.COM 		 * that info here.
7698048SMadhavan.Venkataraman@Sun.COM 		 */
7708048SMadhavan.Venkataraman@Sun.COM 		if (!(coargs->flags & COF_VERBOSE)) {
7718048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%<u>%3s %-1s %-14s %</u>",
7728048SMadhavan.Venkataraman@Sun.COM 			    "SEQ", "T", "EXP");
7738048SMadhavan.Venkataraman@Sun.COM 		} else if (coargs->flags & COF_BYIDH) {
7748048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%<u>%-14s %</u>", "EXP");
7758048SMadhavan.Venkataraman@Sun.COM 		}
7768048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("%<u>%-3s %-?s %-20s%</u>",
7778048SMadhavan.Venkataraman@Sun.COM 		    "XHL", "XID", "FUNC(ARG)");
7788048SMadhavan.Venkataraman@Sun.COM 		if (coargs->flags & COF_LONGLIST) {
7798048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%<u> %-?s %-?s %-?s %-?s%</u>",
7808048SMadhavan.Venkataraman@Sun.COM 			    "PREVID", "NEXTID", "PREVL", "NEXTL");
7818048SMadhavan.Venkataraman@Sun.COM 		}
7828048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("\n");
7838048SMadhavan.Venkataraman@Sun.COM 		coargs->flags &= ~COF_CHDR;
7848048SMadhavan.Venkataraman@Sun.COM 		coargs->flags |= (COF_THDR | COF_LHDR);
7858048SMadhavan.Venkataraman@Sun.COM 	}
7868048SMadhavan.Venkataraman@Sun.COM 
7878048SMadhavan.Venkataraman@Sun.COM 	if (!(coargs->flags & COF_ADDR)) {
7888048SMadhavan.Venkataraman@Sun.COM 		if (!(coargs->flags & COF_VERBOSE)) {
7898048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%-3d %1s %-14llx ",
7908048SMadhavan.Venkataraman@Sun.COM 			    TABLE_TO_SEQID(tableid),
7918048SMadhavan.Venkataraman@Sun.COM 			    co_typenames[tableid & CALLOUT_TYPE_MASK],
7928048SMadhavan.Venkataraman@Sun.COM 			    (coargs->flags & COF_EXPREL) ?
7938048SMadhavan.Venkataraman@Sun.COM 			    coargs->exp - coargs->now : coargs->exp);
7948048SMadhavan.Venkataraman@Sun.COM 		} else if (coargs->flags & COF_BYIDH) {
7958048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%-14x ",
7968048SMadhavan.Venkataraman@Sun.COM 			    (coargs->flags & COF_EXPREL) ?
7978048SMadhavan.Venkataraman@Sun.COM 			    coargs->exp - coargs->now : coargs->exp);
7988048SMadhavan.Venkataraman@Sun.COM 		}
7998048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("%1s%1s%1s %-?llx %a(%p)",
8008048SMadhavan.Venkataraman@Sun.COM 		    (co->c_xid & CALLOUT_EXECUTING) ? "X" : " ",
8018048SMadhavan.Venkataraman@Sun.COM 		    (co->c_xid & CALLOUT_HRESTIME) ? "H" : " ",
8028048SMadhavan.Venkataraman@Sun.COM 		    (co->c_xid & CALLOUT_LONGTERM) ? "L" : " ",
8038048SMadhavan.Venkataraman@Sun.COM 		    (long long)coid, co->c_func, co->c_arg);
8048048SMadhavan.Venkataraman@Sun.COM 		if (coargs->flags & COF_LONGLIST) {
8058048SMadhavan.Venkataraman@Sun.COM 			mdb_printf(" %-?p %-?p %-?p %-?p",
8068048SMadhavan.Venkataraman@Sun.COM 			    co->c_idprev, co->c_idnext, co->c_clprev,
8078048SMadhavan.Venkataraman@Sun.COM 			    co->c_clnext);
8088048SMadhavan.Venkataraman@Sun.COM 		}
8098048SMadhavan.Venkataraman@Sun.COM 	} else {
8108048SMadhavan.Venkataraman@Sun.COM 		/* address only */
8118048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("%-0p", addr);
8128048SMadhavan.Venkataraman@Sun.COM 	}
8138048SMadhavan.Venkataraman@Sun.COM 	mdb_printf("\n");
8148048SMadhavan.Venkataraman@Sun.COM 	return (WALK_NEXT);
8158048SMadhavan.Venkataraman@Sun.COM }
8168048SMadhavan.Venkataraman@Sun.COM 
8178048SMadhavan.Venkataraman@Sun.COM /* this callback is for callout list handling. idhash is done by callout_t_cb */
8188048SMadhavan.Venkataraman@Sun.COM /*ARGSUSED*/
8198048SMadhavan.Venkataraman@Sun.COM static int
8208048SMadhavan.Venkataraman@Sun.COM callout_list_cb(uintptr_t addr, const void *data, void *priv)
8218048SMadhavan.Venkataraman@Sun.COM {
8228048SMadhavan.Venkataraman@Sun.COM 	callout_data_t *coargs = (callout_data_t *)priv;
8238048SMadhavan.Venkataraman@Sun.COM 	callout_list_t *cl = (callout_list_t *)data;
8248048SMadhavan.Venkataraman@Sun.COM 	callout_t *coptr;
8258048SMadhavan.Venkataraman@Sun.COM 
8268048SMadhavan.Venkataraman@Sun.COM 	if ((coargs == NULL) || (cl == NULL)) {
8278048SMadhavan.Venkataraman@Sun.COM 		return (WALK_ERR);
8288048SMadhavan.Venkataraman@Sun.COM 	}
8298048SMadhavan.Venkataraman@Sun.COM 
8308048SMadhavan.Venkataraman@Sun.COM 	coargs->exp = cl->cl_expiration;
8318048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_TIME) &&
8328048SMadhavan.Venkataraman@Sun.COM 	    (cl->cl_expiration != coargs->time)) {
8338048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
8348048SMadhavan.Venkataraman@Sun.COM 	}
8358048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_BEFORE) &&
8368048SMadhavan.Venkataraman@Sun.COM 	    (cl->cl_expiration > coargs->btime)) {
8378048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
8388048SMadhavan.Venkataraman@Sun.COM 	}
8398048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_AFTER) &&
8408048SMadhavan.Venkataraman@Sun.COM 	    (cl->cl_expiration < coargs->atime)) {
8418048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
8428048SMadhavan.Venkataraman@Sun.COM 	}
8438048SMadhavan.Venkataraman@Sun.COM 	if (!(coargs->flags & COF_EMPTY) &&
8448048SMadhavan.Venkataraman@Sun.COM 	    (cl->cl_callouts.ch_head == NULL)) {
8458048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
8468048SMadhavan.Venkataraman@Sun.COM 	}
8478048SMadhavan.Venkataraman@Sun.COM 
8488048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_LHDR) && !(coargs->flags & COF_ADDR) &&
8498048SMadhavan.Venkataraman@Sun.COM 	    (coargs->flags & (COF_LIST | COF_VERBOSE))) {
8508048SMadhavan.Venkataraman@Sun.COM 		if (!(coargs->flags & COF_VERBOSE)) {
8518048SMadhavan.Venkataraman@Sun.COM 			/* don't be redundant again */
8528048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%<u>SEQ T %</u>");
8538048SMadhavan.Venkataraman@Sun.COM 		}
8548048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("%<u>EXP            BUCKET "
8558048SMadhavan.Venkataraman@Sun.COM 		    "CALLOUTS         UTOS THREAD         %</u>");
8568048SMadhavan.Venkataraman@Sun.COM 
8578048SMadhavan.Venkataraman@Sun.COM 		if (coargs->flags & COF_LONGLIST) {
8588048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%<u> %-?s %-?s %-?s%</u>",
8598048SMadhavan.Venkataraman@Sun.COM 			    "DONE", "PREV", "NEXT");
8608048SMadhavan.Venkataraman@Sun.COM 		}
8618048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("\n");
8628048SMadhavan.Venkataraman@Sun.COM 		coargs->flags &= ~COF_LHDR;
8638048SMadhavan.Venkataraman@Sun.COM 		coargs->flags |= (COF_THDR | COF_CHDR);
8648048SMadhavan.Venkataraman@Sun.COM 	}
8658048SMadhavan.Venkataraman@Sun.COM 	if (coargs->flags & (COF_LIST | COF_VERBOSE)) {
8668048SMadhavan.Venkataraman@Sun.COM 		if (!(coargs->flags & COF_ADDR)) {
8678048SMadhavan.Venkataraman@Sun.COM 			if (!(coargs->flags & COF_VERBOSE)) {
8688048SMadhavan.Venkataraman@Sun.COM 				mdb_printf("%3d %1s ",
8698048SMadhavan.Venkataraman@Sun.COM 				    TABLE_TO_SEQID(coargs->ndx),
8708048SMadhavan.Venkataraman@Sun.COM 				    co_typenames[coargs->ndx &
8718048SMadhavan.Venkataraman@Sun.COM 				    CALLOUT_TYPE_MASK]);
8728048SMadhavan.Venkataraman@Sun.COM 			}
8738048SMadhavan.Venkataraman@Sun.COM 
8748048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%-14llx %-6d %-0?p %-4d %-0?p",
8758048SMadhavan.Venkataraman@Sun.COM 			    (coargs->flags & COF_EXPREL) ?
8768048SMadhavan.Venkataraman@Sun.COM 			    coargs->exp - coargs->now : coargs->exp,
8778048SMadhavan.Venkataraman@Sun.COM 			    coargs->bucket, cl->cl_callouts.ch_head,
8788048SMadhavan.Venkataraman@Sun.COM 			    cl->cl_waiting, cl->cl_executor);
8798048SMadhavan.Venkataraman@Sun.COM 
8808048SMadhavan.Venkataraman@Sun.COM 			if (coargs->flags & COF_LONGLIST) {
8818048SMadhavan.Venkataraman@Sun.COM 				mdb_printf(" %-?p %-?p %-?p",
8828048SMadhavan.Venkataraman@Sun.COM 				    cl->cl_done, cl->cl_prev, cl->cl_next);
8838048SMadhavan.Venkataraman@Sun.COM 			}
8848048SMadhavan.Venkataraman@Sun.COM 		} else {
8858048SMadhavan.Venkataraman@Sun.COM 			/* address only */
8868048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%-0p", addr);
8878048SMadhavan.Venkataraman@Sun.COM 		}
8888048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("\n");
8898048SMadhavan.Venkataraman@Sun.COM 		if (coargs->flags & COF_LIST) {
8908048SMadhavan.Venkataraman@Sun.COM 			return (WALK_NEXT);
8918048SMadhavan.Venkataraman@Sun.COM 		}
8928048SMadhavan.Venkataraman@Sun.COM 	}
8938048SMadhavan.Venkataraman@Sun.COM 	/* yet another layer as we walk the actual callouts via list. */
8948048SMadhavan.Venkataraman@Sun.COM 	if (cl->cl_callouts.ch_head == NULL) {
8958048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
8968048SMadhavan.Venkataraman@Sun.COM 	}
8978048SMadhavan.Venkataraman@Sun.COM 	/* free list structures do not have valid callouts off of them. */
8988048SMadhavan.Venkataraman@Sun.COM 	if (coargs->flags & COF_FREE) {
8998048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
9008048SMadhavan.Venkataraman@Sun.COM 	}
9018048SMadhavan.Venkataraman@Sun.COM 	coptr = (callout_t *)cl->cl_callouts.ch_head;
9028048SMadhavan.Venkataraman@Sun.COM 
9038048SMadhavan.Venkataraman@Sun.COM 	if (coargs->flags & COF_VERBOSE) {
9048048SMadhavan.Venkataraman@Sun.COM 		mdb_inc_indent(4);
9058048SMadhavan.Venkataraman@Sun.COM 	}
9068048SMadhavan.Venkataraman@Sun.COM 	/*
9078048SMadhavan.Venkataraman@Sun.COM 	 * walk callouts using yet another callback routine.
9088048SMadhavan.Venkataraman@Sun.COM 	 * we use callouts_bytime because id hash is handled via
9098048SMadhavan.Venkataraman@Sun.COM 	 * the callout_t_cb callback.
9108048SMadhavan.Venkataraman@Sun.COM 	 */
9118048SMadhavan.Venkataraman@Sun.COM 	if (mdb_pwalk("callouts_bytime", callouts_cb, coargs,
9128048SMadhavan.Venkataraman@Sun.COM 	    (uintptr_t)coptr) == -1) {
9138048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("cannot walk callouts at %p", coptr);
9148048SMadhavan.Venkataraman@Sun.COM 		return (WALK_ERR);
9158048SMadhavan.Venkataraman@Sun.COM 	}
9168048SMadhavan.Venkataraman@Sun.COM 	if (coargs->flags & COF_VERBOSE) {
9178048SMadhavan.Venkataraman@Sun.COM 		mdb_dec_indent(4);
9188048SMadhavan.Venkataraman@Sun.COM 	}
9198048SMadhavan.Venkataraman@Sun.COM 
9208048SMadhavan.Venkataraman@Sun.COM 	return (WALK_NEXT);
9218048SMadhavan.Venkataraman@Sun.COM }
9228048SMadhavan.Venkataraman@Sun.COM 
9238048SMadhavan.Venkataraman@Sun.COM /* this callback handles the details of callout table walking. */
9248048SMadhavan.Venkataraman@Sun.COM static int
9258048SMadhavan.Venkataraman@Sun.COM callout_t_cb(uintptr_t addr, const void *data, void *priv)
9268048SMadhavan.Venkataraman@Sun.COM {
9278048SMadhavan.Venkataraman@Sun.COM 	callout_data_t *coargs = (callout_data_t *)priv;
9288048SMadhavan.Venkataraman@Sun.COM 	cot_data_t *cotwd = (cot_data_t *)data;
9298048SMadhavan.Venkataraman@Sun.COM 	callout_table_t *ct = &(cotwd->ct);
9308048SMadhavan.Venkataraman@Sun.COM 	int index, seqid, cotype;
9318048SMadhavan.Venkataraman@Sun.COM 	int i;
9328048SMadhavan.Venkataraman@Sun.COM 	callout_list_t *clptr;
9338048SMadhavan.Venkataraman@Sun.COM 	callout_t *coptr;
9348048SMadhavan.Venkataraman@Sun.COM 
9358048SMadhavan.Venkataraman@Sun.COM 	if ((coargs == NULL) || (ct == NULL) || (coargs->co_table == NULL)) {
9368048SMadhavan.Venkataraman@Sun.COM 		return (WALK_ERR);
9378048SMadhavan.Venkataraman@Sun.COM 	}
9388048SMadhavan.Venkataraman@Sun.COM 
9398048SMadhavan.Venkataraman@Sun.COM 	index =  ((char *)addr - (char *)coargs->co_table) /
9408048SMadhavan.Venkataraman@Sun.COM 	    sizeof (callout_table_t);
9418048SMadhavan.Venkataraman@Sun.COM 	cotype = index & CALLOUT_TYPE_MASK;
9428048SMadhavan.Venkataraman@Sun.COM 	seqid = TABLE_TO_SEQID(index);
9438048SMadhavan.Venkataraman@Sun.COM 
9448048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_SEQID) && (coargs->seqid != seqid)) {
9458048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
9468048SMadhavan.Venkataraman@Sun.COM 	}
9478048SMadhavan.Venkataraman@Sun.COM 
9488048SMadhavan.Venkataraman@Sun.COM 	if (!(coargs->flags & COF_REAL) && (cotype == CALLOUT_REALTIME)) {
9498048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
9508048SMadhavan.Venkataraman@Sun.COM 	}
9518048SMadhavan.Venkataraman@Sun.COM 
9528048SMadhavan.Venkataraman@Sun.COM 	if (!(coargs->flags & COF_NORM) && (cotype == CALLOUT_NORMAL)) {
9538048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
9548048SMadhavan.Venkataraman@Sun.COM 	}
9558048SMadhavan.Venkataraman@Sun.COM 
9568048SMadhavan.Venkataraman@Sun.COM 	if (!(coargs->flags & COF_EMPTY) && (
9578048SMadhavan.Venkataraman@Sun.COM 	    (ct->ct_heap == NULL) || (ct->ct_cyclic == NULL))) {
9588048SMadhavan.Venkataraman@Sun.COM 		return (WALK_NEXT);
9598048SMadhavan.Venkataraman@Sun.COM 	}
9608048SMadhavan.Venkataraman@Sun.COM 
9618048SMadhavan.Venkataraman@Sun.COM 	if ((coargs->flags & COF_THDR) && !(coargs->flags & COF_ADDR) &&
9628048SMadhavan.Venkataraman@Sun.COM 	    (coargs->flags & (COF_TABLE | COF_VERBOSE))) {
9638048SMadhavan.Venkataraman@Sun.COM 		/* print table hdr */
9648048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("%<u>%-3s %-1s %-?s %-?s %-?s %-?s%</u>",
9658048SMadhavan.Venkataraman@Sun.COM 		    "SEQ", "T", "FREE", "LFREE", "CYCLIC", "HEAP");
9668048SMadhavan.Venkataraman@Sun.COM 		coargs->flags &= ~COF_THDR;
9678048SMadhavan.Venkataraman@Sun.COM 		coargs->flags |= (COF_LHDR | COF_CHDR);
9688048SMadhavan.Venkataraman@Sun.COM 		if (coargs->flags & COF_LONGLIST) {
9698048SMadhavan.Venkataraman@Sun.COM 			/* more info! */
9708048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%<u> %-T%-7s %-7s %-?s %-?s"
9718048SMadhavan.Venkataraman@Sun.COM 			    " %-?s %-?s %-?s%</u>",
9728048SMadhavan.Venkataraman@Sun.COM 			    "HEAPNUM", "HEAPMAX", "TASKQ", "EXPQ",
9738048SMadhavan.Venkataraman@Sun.COM 			    "PEND", "FREE", "LOCK");
9748048SMadhavan.Venkataraman@Sun.COM 		}
9758048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("\n");
9768048SMadhavan.Venkataraman@Sun.COM 	}
9778048SMadhavan.Venkataraman@Sun.COM 	if (coargs->flags & (COF_TABLE | COF_VERBOSE)) {
9788048SMadhavan.Venkataraman@Sun.COM 		if (!(coargs->flags & COF_ADDR)) {
9798048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%-3d %-1s %-0?p %-0?p %-0?p %-?p",
9808048SMadhavan.Venkataraman@Sun.COM 			    seqid, co_typenames[cotype],
9818048SMadhavan.Venkataraman@Sun.COM 			    ct->ct_free, ct->ct_lfree, ct->ct_cyclic,
9828048SMadhavan.Venkataraman@Sun.COM 			    ct->ct_heap);
9838048SMadhavan.Venkataraman@Sun.COM 			if (coargs->flags & COF_LONGLIST)  {
9848048SMadhavan.Venkataraman@Sun.COM 				/* more info! */
9858048SMadhavan.Venkataraman@Sun.COM 				mdb_printf(" %-7d %-7d %-?p %-?p"
9868048SMadhavan.Venkataraman@Sun.COM 				    " %-?lld %-?lld %-?p",
9878048SMadhavan.Venkataraman@Sun.COM 				    ct->ct_heap_num,  ct->ct_heap_max,
9888048SMadhavan.Venkataraman@Sun.COM 				    ct->ct_taskq, ct->ct_expired.ch_head,
9898048SMadhavan.Venkataraman@Sun.COM 				    cotwd->ct_timeouts_pending,
9908048SMadhavan.Venkataraman@Sun.COM 				    cotwd->ct_allocations -
9918048SMadhavan.Venkataraman@Sun.COM 				    cotwd->ct_timeouts_pending,
9928048SMadhavan.Venkataraman@Sun.COM 				    ct->ct_mutex);
9938048SMadhavan.Venkataraman@Sun.COM 			}
9948048SMadhavan.Venkataraman@Sun.COM 		} else {
9958048SMadhavan.Venkataraman@Sun.COM 			/* address only */
9968048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%-0?p", addr);
9978048SMadhavan.Venkataraman@Sun.COM 		}
9988048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("\n");
9998048SMadhavan.Venkataraman@Sun.COM 		if (coargs->flags & COF_TABLE) {
10008048SMadhavan.Venkataraman@Sun.COM 			return (WALK_NEXT);
10018048SMadhavan.Venkataraman@Sun.COM 		}
10028048SMadhavan.Venkataraman@Sun.COM 	}
10038048SMadhavan.Venkataraman@Sun.COM 
10048048SMadhavan.Venkataraman@Sun.COM 	coargs->ndx = index;
10058048SMadhavan.Venkataraman@Sun.COM 	if (coargs->flags & COF_VERBOSE) {
10068048SMadhavan.Venkataraman@Sun.COM 		mdb_inc_indent(4);
10078048SMadhavan.Venkataraman@Sun.COM 	}
10088048SMadhavan.Venkataraman@Sun.COM 	/* keep digging. */
10098048SMadhavan.Venkataraman@Sun.COM 	if (!(coargs->flags & COF_BYIDH)) {
10108048SMadhavan.Venkataraman@Sun.COM 		/* walk the list hash table */
10118048SMadhavan.Venkataraman@Sun.COM 		if (coargs->flags & COF_FREE) {
10128048SMadhavan.Venkataraman@Sun.COM 			clptr = ct->ct_lfree;
10138048SMadhavan.Venkataraman@Sun.COM 			coargs->bucket = 0;
10148048SMadhavan.Venkataraman@Sun.COM 			if (clptr == NULL) {
10158048SMadhavan.Venkataraman@Sun.COM 				return (WALK_NEXT);
10168048SMadhavan.Venkataraman@Sun.COM 			}
10178048SMadhavan.Venkataraman@Sun.COM 			if (mdb_pwalk("callout_list", callout_list_cb, coargs,
10188048SMadhavan.Venkataraman@Sun.COM 			    (uintptr_t)clptr) == -1) {
10198048SMadhavan.Venkataraman@Sun.COM 				mdb_warn("cannot walk callout free list at %p",
10208048SMadhavan.Venkataraman@Sun.COM 				    clptr);
10218048SMadhavan.Venkataraman@Sun.COM 				return (WALK_ERR);
10228048SMadhavan.Venkataraman@Sun.COM 			}
10238048SMadhavan.Venkataraman@Sun.COM 		} else {
10248048SMadhavan.Venkataraman@Sun.COM 			/* first print the expired list. */
10258048SMadhavan.Venkataraman@Sun.COM 			clptr = (callout_list_t *)ct->ct_expired.ch_head;
10268048SMadhavan.Venkataraman@Sun.COM 			if (clptr != NULL) {
10278048SMadhavan.Venkataraman@Sun.COM 				coargs->bucket = -1;
10288048SMadhavan.Venkataraman@Sun.COM 				if (mdb_pwalk("callout_list", callout_list_cb,
10298048SMadhavan.Venkataraman@Sun.COM 				    coargs, (uintptr_t)clptr) == -1) {
10308048SMadhavan.Venkataraman@Sun.COM 					mdb_warn("cannot walk callout_list"
10318048SMadhavan.Venkataraman@Sun.COM 					    " at %p", clptr);
10328048SMadhavan.Venkataraman@Sun.COM 					return (WALK_ERR);
10338048SMadhavan.Venkataraman@Sun.COM 				}
10348048SMadhavan.Venkataraman@Sun.COM 			}
10358048SMadhavan.Venkataraman@Sun.COM 			for (i = 0; i < CALLOUT_BUCKETS; i++) {
10368048SMadhavan.Venkataraman@Sun.COM 				if (ct->ct_clhash == NULL) {
10378048SMadhavan.Venkataraman@Sun.COM 					/* nothing to do */
10388048SMadhavan.Venkataraman@Sun.COM 					break;
10398048SMadhavan.Venkataraman@Sun.COM 				}
10408048SMadhavan.Venkataraman@Sun.COM 				if (cotwd->cot_clhash[i].ch_head == NULL) {
10418048SMadhavan.Venkataraman@Sun.COM 					continue;
10428048SMadhavan.Venkataraman@Sun.COM 				}
10438048SMadhavan.Venkataraman@Sun.COM 				clptr = (callout_list_t *)
10448048SMadhavan.Venkataraman@Sun.COM 				    cotwd->cot_clhash[i].ch_head;
10458048SMadhavan.Venkataraman@Sun.COM 				coargs->bucket = i;
10468048SMadhavan.Venkataraman@Sun.COM 				/* walk list with callback routine. */
10478048SMadhavan.Venkataraman@Sun.COM 				if (mdb_pwalk("callout_list", callout_list_cb,
10488048SMadhavan.Venkataraman@Sun.COM 				    coargs, (uintptr_t)clptr) == -1) {
10498048SMadhavan.Venkataraman@Sun.COM 					mdb_warn("cannot walk callout_list"
10508048SMadhavan.Venkataraman@Sun.COM 					    " at %p", clptr);
10518048SMadhavan.Venkataraman@Sun.COM 					return (WALK_ERR);
10528048SMadhavan.Venkataraman@Sun.COM 				}
10538048SMadhavan.Venkataraman@Sun.COM 			}
10548048SMadhavan.Venkataraman@Sun.COM 		}
10558048SMadhavan.Venkataraman@Sun.COM 	} else {
10568048SMadhavan.Venkataraman@Sun.COM 		/* walk the id hash table. */
10578048SMadhavan.Venkataraman@Sun.COM 		if (coargs->flags & COF_FREE) {
10588048SMadhavan.Venkataraman@Sun.COM 			coptr = ct->ct_free;
10598048SMadhavan.Venkataraman@Sun.COM 			coargs->bucket = 0;
10608048SMadhavan.Venkataraman@Sun.COM 			if (coptr == NULL) {
10618048SMadhavan.Venkataraman@Sun.COM 				return (WALK_NEXT);
10628048SMadhavan.Venkataraman@Sun.COM 			}
10638048SMadhavan.Venkataraman@Sun.COM 			if (mdb_pwalk("callouts_byid", callouts_cb, coargs,
10648048SMadhavan.Venkataraman@Sun.COM 			    (uintptr_t)coptr) == -1) {
10658048SMadhavan.Venkataraman@Sun.COM 				mdb_warn("cannot walk callout id free list"
10668048SMadhavan.Venkataraman@Sun.COM 				    " at %p", coptr);
10678048SMadhavan.Venkataraman@Sun.COM 				return (WALK_ERR);
10688048SMadhavan.Venkataraman@Sun.COM 			}
10698048SMadhavan.Venkataraman@Sun.COM 		} else {
10708048SMadhavan.Venkataraman@Sun.COM 			for (i = 0; i < CALLOUT_BUCKETS; i++) {
10718048SMadhavan.Venkataraman@Sun.COM 				if (ct->ct_idhash == NULL) {
10728048SMadhavan.Venkataraman@Sun.COM 					break;
10738048SMadhavan.Venkataraman@Sun.COM 				}
10748048SMadhavan.Venkataraman@Sun.COM 				coptr = (callout_t *)
10758048SMadhavan.Venkataraman@Sun.COM 				    cotwd->cot_idhash[i].ch_head;
10768048SMadhavan.Venkataraman@Sun.COM 				if (coptr == NULL) {
10778048SMadhavan.Venkataraman@Sun.COM 					continue;
10788048SMadhavan.Venkataraman@Sun.COM 				}
10798048SMadhavan.Venkataraman@Sun.COM 				coargs->bucket = i;
10808048SMadhavan.Venkataraman@Sun.COM 
10818048SMadhavan.Venkataraman@Sun.COM 				/*
10828048SMadhavan.Venkataraman@Sun.COM 				 * walk callouts directly by id. For id
10838048SMadhavan.Venkataraman@Sun.COM 				 * chain, the callout list is just a header,
10848048SMadhavan.Venkataraman@Sun.COM 				 * so there's no need to walk it.
10858048SMadhavan.Venkataraman@Sun.COM 				 */
10868048SMadhavan.Venkataraman@Sun.COM 				if (mdb_pwalk("callouts_byid", callouts_cb,
10878048SMadhavan.Venkataraman@Sun.COM 				    coargs, (uintptr_t)coptr) == -1) {
10888048SMadhavan.Venkataraman@Sun.COM 					mdb_warn("cannot walk callouts at %p",
10898048SMadhavan.Venkataraman@Sun.COM 					    coptr);
10908048SMadhavan.Venkataraman@Sun.COM 					return (WALK_ERR);
10918048SMadhavan.Venkataraman@Sun.COM 				}
10928048SMadhavan.Venkataraman@Sun.COM 			}
10938048SMadhavan.Venkataraman@Sun.COM 		}
10948048SMadhavan.Venkataraman@Sun.COM 	}
10958048SMadhavan.Venkataraman@Sun.COM 	if (coargs->flags & COF_VERBOSE) {
10968048SMadhavan.Venkataraman@Sun.COM 		mdb_dec_indent(4);
10978048SMadhavan.Venkataraman@Sun.COM 	}
10988048SMadhavan.Venkataraman@Sun.COM 	return (WALK_NEXT);
10998048SMadhavan.Venkataraman@Sun.COM }
11008048SMadhavan.Venkataraman@Sun.COM 
11018048SMadhavan.Venkataraman@Sun.COM /*
11028048SMadhavan.Venkataraman@Sun.COM  * initialize some common info for both callout dcmds.
11038048SMadhavan.Venkataraman@Sun.COM  */
11048048SMadhavan.Venkataraman@Sun.COM int
11058048SMadhavan.Venkataraman@Sun.COM callout_common_init(callout_data_t *coargs)
11068048SMadhavan.Venkataraman@Sun.COM {
11078048SMadhavan.Venkataraman@Sun.COM 	/* we need a couple of things */
11088048SMadhavan.Venkataraman@Sun.COM 	if (mdb_readvar(&(coargs->co_table), "callout_table") == -1) {
11098048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("failed to read 'callout_table'");
11108048SMadhavan.Venkataraman@Sun.COM 		return (DCMD_ERR);
11118048SMadhavan.Venkataraman@Sun.COM 	}
11128048SMadhavan.Venkataraman@Sun.COM 	/* need to get now in nsecs. Approximate with hrtime vars */
11138048SMadhavan.Venkataraman@Sun.COM 	if (mdb_readsym(&(coargs->now), sizeof (hrtime_t), "hrtime_last") !=
11148048SMadhavan.Venkataraman@Sun.COM 	    sizeof (hrtime_t)) {
11158048SMadhavan.Venkataraman@Sun.COM 		if (mdb_readsym(&(coargs->now), sizeof (hrtime_t),
11168048SMadhavan.Venkataraman@Sun.COM 		    "hrtime_base") != sizeof (hrtime_t)) {
11178048SMadhavan.Venkataraman@Sun.COM 			mdb_warn("Could not determine current system time");
11188048SMadhavan.Venkataraman@Sun.COM 			return (DCMD_ERR);
11198048SMadhavan.Venkataraman@Sun.COM 		}
11208048SMadhavan.Venkataraman@Sun.COM 	}
11218048SMadhavan.Venkataraman@Sun.COM 
11228048SMadhavan.Venkataraman@Sun.COM 	if (mdb_readvar(&(coargs->ctbits), "callout_table_bits") == -1) {
11238048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("failed to read 'callout_table_bits'");
11248048SMadhavan.Venkataraman@Sun.COM 		return (DCMD_ERR);
11258048SMadhavan.Venkataraman@Sun.COM 	}
11268048SMadhavan.Venkataraman@Sun.COM 	if (mdb_readvar(&(coargs->nsec_per_tick), "nsec_per_tick") == -1) {
11278048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("failed to read 'nsec_per_tick'");
11288048SMadhavan.Venkataraman@Sun.COM 		return (DCMD_ERR);
11298048SMadhavan.Venkataraman@Sun.COM 	}
11308048SMadhavan.Venkataraman@Sun.COM 	return (DCMD_OK);
11318048SMadhavan.Venkataraman@Sun.COM }
11328048SMadhavan.Venkataraman@Sun.COM 
11338048SMadhavan.Venkataraman@Sun.COM /*
11348048SMadhavan.Venkataraman@Sun.COM  * dcmd to print callouts.  Optional addr limits to specific table.
11358048SMadhavan.Venkataraman@Sun.COM  * Parses lots of options that get passed to callbacks for walkers.
11368048SMadhavan.Venkataraman@Sun.COM  * Has it's own help function.
11378048SMadhavan.Venkataraman@Sun.COM  */
11380Sstevel@tonic-gate /*ARGSUSED*/
11390Sstevel@tonic-gate int
11400Sstevel@tonic-gate callout(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
11410Sstevel@tonic-gate {
11428048SMadhavan.Venkataraman@Sun.COM 	callout_data_t coargs;
11438048SMadhavan.Venkataraman@Sun.COM 	/* getopts doesn't help much with stuff like this */
11448048SMadhavan.Venkataraman@Sun.COM 	boolean_t Sflag, Cflag, tflag, aflag, bflag, dflag, kflag;
11458048SMadhavan.Venkataraman@Sun.COM 	char *funcname = NULL;
11468048SMadhavan.Venkataraman@Sun.COM 	char *paramstr = NULL;
11478048SMadhavan.Venkataraman@Sun.COM 	uintptr_t Stmp, Ctmp;	/* for getopt. */
11488048SMadhavan.Venkataraman@Sun.COM 	int retval;
11498048SMadhavan.Venkataraman@Sun.COM 
11508048SMadhavan.Venkataraman@Sun.COM 	coargs.flags = COF_DEFAULT;
11518048SMadhavan.Venkataraman@Sun.COM 	Sflag = Cflag = tflag = bflag = aflag = dflag = kflag = FALSE;
11528048SMadhavan.Venkataraman@Sun.COM 	coargs.seqid = -1;
11538048SMadhavan.Venkataraman@Sun.COM 
11548048SMadhavan.Venkataraman@Sun.COM 	if (mdb_getopts(argc, argv,
11558048SMadhavan.Venkataraman@Sun.COM 	    'r', MDB_OPT_CLRBITS, COF_NORM, &coargs.flags,
11568048SMadhavan.Venkataraman@Sun.COM 	    'n', MDB_OPT_CLRBITS, COF_REAL, &coargs.flags,
11578048SMadhavan.Venkataraman@Sun.COM 	    'l', MDB_OPT_CLRBITS, COF_SHORT, &coargs.flags,
11588048SMadhavan.Venkataraman@Sun.COM 	    's', MDB_OPT_CLRBITS, COF_LONG, &coargs.flags,
11598048SMadhavan.Venkataraman@Sun.COM 	    'x', MDB_OPT_SETBITS, COF_EXEC, &coargs.flags,
11608048SMadhavan.Venkataraman@Sun.COM 	    'h', MDB_OPT_SETBITS, COF_HIRES, &coargs.flags,
11618048SMadhavan.Venkataraman@Sun.COM 	    'E', MDB_OPT_SETBITS, COF_EMPTY, &coargs.flags,
11628048SMadhavan.Venkataraman@Sun.COM 	    'd', MDB_OPT_SETBITS, 1, &dflag,
11638048SMadhavan.Venkataraman@Sun.COM 	    'C', MDB_OPT_UINTPTR_SET, &Cflag, &Ctmp,
11648048SMadhavan.Venkataraman@Sun.COM 	    'S', MDB_OPT_UINTPTR_SET, &Sflag, &Stmp,
11658048SMadhavan.Venkataraman@Sun.COM 	    't', MDB_OPT_UINTPTR_SET, &tflag, (uintptr_t *)&coargs.time,
11668048SMadhavan.Venkataraman@Sun.COM 	    'a', MDB_OPT_UINTPTR_SET, &aflag, (uintptr_t *)&coargs.atime,
11678048SMadhavan.Venkataraman@Sun.COM 	    'b', MDB_OPT_UINTPTR_SET, &bflag, (uintptr_t *)&coargs.btime,
11688048SMadhavan.Venkataraman@Sun.COM 	    'k', MDB_OPT_SETBITS, 1, &kflag,
11698048SMadhavan.Venkataraman@Sun.COM 	    'f', MDB_OPT_STR, &funcname,
11708048SMadhavan.Venkataraman@Sun.COM 	    'p', MDB_OPT_STR, &paramstr,
11718048SMadhavan.Venkataraman@Sun.COM 	    'T', MDB_OPT_SETBITS, COF_TABLE, &coargs.flags,
11728048SMadhavan.Venkataraman@Sun.COM 	    'D', MDB_OPT_SETBITS, COF_EXPREL, &coargs.flags,
11738048SMadhavan.Venkataraman@Sun.COM 	    'L', MDB_OPT_SETBITS, COF_LIST, &coargs.flags,
11748048SMadhavan.Venkataraman@Sun.COM 	    'V', MDB_OPT_SETBITS, COF_VERBOSE, &coargs.flags,
11758048SMadhavan.Venkataraman@Sun.COM 	    'v', MDB_OPT_SETBITS, COF_LONGLIST, &coargs.flags,
11768048SMadhavan.Venkataraman@Sun.COM 	    'i', MDB_OPT_SETBITS, COF_BYIDH, &coargs.flags,
11778048SMadhavan.Venkataraman@Sun.COM 	    'F', MDB_OPT_SETBITS, COF_FREE, &coargs.flags,
11788048SMadhavan.Venkataraman@Sun.COM 	    'A', MDB_OPT_SETBITS, COF_ADDR, &coargs.flags,
11798048SMadhavan.Venkataraman@Sun.COM 	    NULL) != argc) {
11800Sstevel@tonic-gate 		return (DCMD_USAGE);
11818048SMadhavan.Venkataraman@Sun.COM 	}
11828048SMadhavan.Venkataraman@Sun.COM 
11838048SMadhavan.Venkataraman@Sun.COM 	/* initialize from kernel variables */
11848048SMadhavan.Venkataraman@Sun.COM 	if ((retval = callout_common_init(&coargs)) != DCMD_OK) {
11858048SMadhavan.Venkataraman@Sun.COM 		return (retval);
11868048SMadhavan.Venkataraman@Sun.COM 	}
11878048SMadhavan.Venkataraman@Sun.COM 
11888048SMadhavan.Venkataraman@Sun.COM 	/* do some option post-processing */
11898048SMadhavan.Venkataraman@Sun.COM 	if (kflag) {
11908048SMadhavan.Venkataraman@Sun.COM 		coargs.time *= coargs.nsec_per_tick;
11918048SMadhavan.Venkataraman@Sun.COM 		coargs.atime *= coargs.nsec_per_tick;
11928048SMadhavan.Venkataraman@Sun.COM 		coargs.btime *= coargs.nsec_per_tick;
11938048SMadhavan.Venkataraman@Sun.COM 	}
11948048SMadhavan.Venkataraman@Sun.COM 
11958048SMadhavan.Venkataraman@Sun.COM 	if (dflag) {
11968048SMadhavan.Venkataraman@Sun.COM 		coargs.time += coargs.now;
11978048SMadhavan.Venkataraman@Sun.COM 		coargs.atime += coargs.now;
11988048SMadhavan.Venkataraman@Sun.COM 		coargs.btime += coargs.now;
11998048SMadhavan.Venkataraman@Sun.COM 	}
12008048SMadhavan.Venkataraman@Sun.COM 	if (Sflag) {
12018048SMadhavan.Venkataraman@Sun.COM 		if (flags & DCMD_ADDRSPEC) {
12028048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("-S option conflicts with explicit"
12038048SMadhavan.Venkataraman@Sun.COM 			    " address\n");
12048048SMadhavan.Venkataraman@Sun.COM 			return (DCMD_USAGE);
12058048SMadhavan.Venkataraman@Sun.COM 		}
12068048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_SEQID;
12078048SMadhavan.Venkataraman@Sun.COM 		coargs.seqid = (int)Stmp;
12088048SMadhavan.Venkataraman@Sun.COM 	}
12098048SMadhavan.Venkataraman@Sun.COM 	if (Cflag) {
12108048SMadhavan.Venkataraman@Sun.COM 		if (flags & DCMD_ADDRSPEC) {
12118048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("-C option conflicts with explicit"
12128048SMadhavan.Venkataraman@Sun.COM 			    " address\n");
12138048SMadhavan.Venkataraman@Sun.COM 			return (DCMD_USAGE);
12148048SMadhavan.Venkataraman@Sun.COM 		}
12158048SMadhavan.Venkataraman@Sun.COM 		if (coargs.flags & COF_SEQID) {
12168048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("-C and -S are mutually exclusive\n");
12178048SMadhavan.Venkataraman@Sun.COM 			return (DCMD_USAGE);
12188048SMadhavan.Venkataraman@Sun.COM 		}
12198048SMadhavan.Venkataraman@Sun.COM 		coargs.cpu = (cpu_t *)Ctmp;
12208048SMadhavan.Venkataraman@Sun.COM 		if (mdb_vread(&coargs.seqid, sizeof (processorid_t),
12218048SMadhavan.Venkataraman@Sun.COM 		    (uintptr_t)&(coargs.cpu->cpu_seqid)) == -1) {
12228048SMadhavan.Venkataraman@Sun.COM 			mdb_warn("failed to read cpu_t at %p", Ctmp);
12238048SMadhavan.Venkataraman@Sun.COM 			return (DCMD_ERR);
12248048SMadhavan.Venkataraman@Sun.COM 		}
12258048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_SEQID;
12268048SMadhavan.Venkataraman@Sun.COM 	}
12278048SMadhavan.Venkataraman@Sun.COM 	/* avoid null outputs. */
12288048SMadhavan.Venkataraman@Sun.COM 	if (!(coargs.flags & (COF_REAL | COF_NORM))) {
12298048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_REAL | COF_NORM;
12308048SMadhavan.Venkataraman@Sun.COM 	}
12318048SMadhavan.Venkataraman@Sun.COM 	if (!(coargs.flags & (COF_LONG | COF_SHORT))) {
12328048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_LONG | COF_SHORT;
12338048SMadhavan.Venkataraman@Sun.COM 	}
12348048SMadhavan.Venkataraman@Sun.COM 	if (tflag) {
12358048SMadhavan.Venkataraman@Sun.COM 		if (aflag || bflag) {
12368048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("-t and -a|b are mutually exclusive\n");
12378048SMadhavan.Venkataraman@Sun.COM 			return (DCMD_USAGE);
12388048SMadhavan.Venkataraman@Sun.COM 		}
12398048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_TIME;
12408048SMadhavan.Venkataraman@Sun.COM 	}
12418048SMadhavan.Venkataraman@Sun.COM 	if (aflag) {
12428048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_AFTER;
12438048SMadhavan.Venkataraman@Sun.COM 	}
12448048SMadhavan.Venkataraman@Sun.COM 	if (bflag) {
12458048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_BEFORE;
12468048SMadhavan.Venkataraman@Sun.COM 	}
12478048SMadhavan.Venkataraman@Sun.COM 	if ((aflag && bflag) && (coargs.btime <= coargs.atime)) {
12488048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("value for -a must be earlier than the value"
12498048SMadhavan.Venkataraman@Sun.COM 		    " for -b.\n");
12508048SMadhavan.Venkataraman@Sun.COM 		return (DCMD_USAGE);
12518048SMadhavan.Venkataraman@Sun.COM 	}
12528048SMadhavan.Venkataraman@Sun.COM 
12538048SMadhavan.Venkataraman@Sun.COM 	if (funcname != NULL) {
12548048SMadhavan.Venkataraman@Sun.COM 		GElf_Sym sym;
12558048SMadhavan.Venkataraman@Sun.COM 
12568048SMadhavan.Venkataraman@Sun.COM 		if (mdb_lookup_by_name(funcname, &sym) != 0) {
12578048SMadhavan.Venkataraman@Sun.COM 			coargs.funcaddr = mdb_strtoull(funcname);
12588048SMadhavan.Venkataraman@Sun.COM 		} else {
12598048SMadhavan.Venkataraman@Sun.COM 			coargs.funcaddr = sym.st_value;
12608048SMadhavan.Venkataraman@Sun.COM 		}
12618048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_FUNC;
12628048SMadhavan.Venkataraman@Sun.COM 	}
12638048SMadhavan.Venkataraman@Sun.COM 
12648048SMadhavan.Venkataraman@Sun.COM 	if (paramstr != NULL) {
12658048SMadhavan.Venkataraman@Sun.COM 		GElf_Sym sym;
12668048SMadhavan.Venkataraman@Sun.COM 
12678048SMadhavan.Venkataraman@Sun.COM 		if (mdb_lookup_by_name(paramstr, &sym) != 0) {
12688048SMadhavan.Venkataraman@Sun.COM 			coargs.param = mdb_strtoull(paramstr);
12698048SMadhavan.Venkataraman@Sun.COM 		} else {
12708048SMadhavan.Venkataraman@Sun.COM 			coargs.param = sym.st_value;
12718048SMadhavan.Venkataraman@Sun.COM 		}
12728048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_PARAM;
12738048SMadhavan.Venkataraman@Sun.COM 	}
12748048SMadhavan.Venkataraman@Sun.COM 
12758048SMadhavan.Venkataraman@Sun.COM 	if (!(flags & DCMD_ADDRSPEC)) {
12768048SMadhavan.Venkataraman@Sun.COM 		/* don't pass "dot" if no addr. */
12778048SMadhavan.Venkataraman@Sun.COM 		addr = NULL;
12788048SMadhavan.Venkataraman@Sun.COM 	}
12798048SMadhavan.Venkataraman@Sun.COM 	if (addr != NULL) {
12808048SMadhavan.Venkataraman@Sun.COM 		/*
12818048SMadhavan.Venkataraman@Sun.COM 		 * a callout table was specified. Ignore -r|n option
12828048SMadhavan.Venkataraman@Sun.COM 		 * to avoid null output.
12838048SMadhavan.Venkataraman@Sun.COM 		 */
12848048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= (COF_REAL | COF_NORM);
12858048SMadhavan.Venkataraman@Sun.COM 	}
12868048SMadhavan.Venkataraman@Sun.COM 
12878048SMadhavan.Venkataraman@Sun.COM 	if (DCMD_HDRSPEC(flags) || (coargs.flags & COF_VERBOSE)) {
12888048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_THDR | COF_LHDR | COF_CHDR;
12898048SMadhavan.Venkataraman@Sun.COM 	}
12908048SMadhavan.Venkataraman@Sun.COM 	if (coargs.flags & COF_FREE) {
12918048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_EMPTY;
12928048SMadhavan.Venkataraman@Sun.COM 		/* -F = free callouts, -FL = free lists */
12938048SMadhavan.Venkataraman@Sun.COM 		if (!(coargs.flags & COF_LIST)) {
12948048SMadhavan.Venkataraman@Sun.COM 			coargs.flags |= COF_BYIDH;
12958048SMadhavan.Venkataraman@Sun.COM 		}
12968048SMadhavan.Venkataraman@Sun.COM 	}
12978048SMadhavan.Venkataraman@Sun.COM 
12988048SMadhavan.Venkataraman@Sun.COM 	/* walk table, using specialized callback routine. */
12998048SMadhavan.Venkataraman@Sun.COM 	if (mdb_pwalk("callout_table", callout_t_cb, &coargs, addr) == -1) {
13008048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("cannot walk callout_table");
13010Sstevel@tonic-gate 		return (DCMD_ERR);
13020Sstevel@tonic-gate 	}
13038048SMadhavan.Venkataraman@Sun.COM 	return (DCMD_OK);
13048048SMadhavan.Venkataraman@Sun.COM }
13058048SMadhavan.Venkataraman@Sun.COM 
13068048SMadhavan.Venkataraman@Sun.COM 
13078048SMadhavan.Venkataraman@Sun.COM /*
13088048SMadhavan.Venkataraman@Sun.COM  * Given an extended callout id, dump its information.
13098048SMadhavan.Venkataraman@Sun.COM  */
13108048SMadhavan.Venkataraman@Sun.COM /*ARGSUSED*/
13118048SMadhavan.Venkataraman@Sun.COM int
13128048SMadhavan.Venkataraman@Sun.COM calloutid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
13138048SMadhavan.Venkataraman@Sun.COM {
13148048SMadhavan.Venkataraman@Sun.COM 	callout_data_t coargs;
13158048SMadhavan.Venkataraman@Sun.COM 	callout_table_t *ctptr;
13168048SMadhavan.Venkataraman@Sun.COM 	callout_table_t ct;
13178048SMadhavan.Venkataraman@Sun.COM 	callout_id_t coid;
13188048SMadhavan.Venkataraman@Sun.COM 	callout_t *coptr;
13198048SMadhavan.Venkataraman@Sun.COM 	int tableid;
13208048SMadhavan.Venkataraman@Sun.COM 	callout_id_t xid;
13218048SMadhavan.Venkataraman@Sun.COM 	ulong_t idhash;
13228048SMadhavan.Venkataraman@Sun.COM 	int i, retval;
13238048SMadhavan.Venkataraman@Sun.COM 	const mdb_arg_t *arg;
13248048SMadhavan.Venkataraman@Sun.COM 	size_t size;
13258048SMadhavan.Venkataraman@Sun.COM 	callout_hash_t cot_idhash[CALLOUT_BUCKETS];
13268048SMadhavan.Venkataraman@Sun.COM 
13278048SMadhavan.Venkataraman@Sun.COM 	coargs.flags = COF_DEFAULT | COF_BYIDH;
13288048SMadhavan.Venkataraman@Sun.COM 	i = mdb_getopts(argc, argv,
13298048SMadhavan.Venkataraman@Sun.COM 	    'd', MDB_OPT_SETBITS, COF_DECODE, &coargs.flags,
13308048SMadhavan.Venkataraman@Sun.COM 	    'v', MDB_OPT_SETBITS, COF_LONGLIST, &coargs.flags,
13318048SMadhavan.Venkataraman@Sun.COM 	    NULL);
13328048SMadhavan.Venkataraman@Sun.COM 	argc -= i;
13338048SMadhavan.Venkataraman@Sun.COM 	argv += i;
13348048SMadhavan.Venkataraman@Sun.COM 
13358048SMadhavan.Venkataraman@Sun.COM 	if (argc != 1) {
13368048SMadhavan.Venkataraman@Sun.COM 		return (DCMD_USAGE);
13378048SMadhavan.Venkataraman@Sun.COM 	}
13388048SMadhavan.Venkataraman@Sun.COM 	arg = &argv[0];
13398048SMadhavan.Venkataraman@Sun.COM 
13408048SMadhavan.Venkataraman@Sun.COM 	if (arg->a_type == MDB_TYPE_IMMEDIATE) {
13418048SMadhavan.Venkataraman@Sun.COM 		xid = arg->a_un.a_val;
13428048SMadhavan.Venkataraman@Sun.COM 	} else {
13438048SMadhavan.Venkataraman@Sun.COM 		xid = (callout_id_t)mdb_strtoull(arg->a_un.a_str);
13448048SMadhavan.Venkataraman@Sun.COM 	}
13458048SMadhavan.Venkataraman@Sun.COM 
13468048SMadhavan.Venkataraman@Sun.COM 	if (DCMD_HDRSPEC(flags)) {
13478048SMadhavan.Venkataraman@Sun.COM 		coargs.flags |= COF_CHDR;
13488048SMadhavan.Venkataraman@Sun.COM 	}
13498048SMadhavan.Venkataraman@Sun.COM 
13508048SMadhavan.Venkataraman@Sun.COM 
13518048SMadhavan.Venkataraman@Sun.COM 	/* initialize from kernel variables */
13528048SMadhavan.Venkataraman@Sun.COM 	if ((retval = callout_common_init(&coargs)) != DCMD_OK) {
13538048SMadhavan.Venkataraman@Sun.COM 		return (retval);
13548048SMadhavan.Venkataraman@Sun.COM 	}
13558048SMadhavan.Venkataraman@Sun.COM 
13568048SMadhavan.Venkataraman@Sun.COM 	/* we must massage the environment so that the macros will play nice */
13578048SMadhavan.Venkataraman@Sun.COM #define	callout_table_mask	((1 << coargs.ctbits) - 1)
13588048SMadhavan.Venkataraman@Sun.COM #define	callout_table_bits	coargs.ctbits
13598048SMadhavan.Venkataraman@Sun.COM #define	nsec_per_tick		coargs.nsec_per_tick
13608048SMadhavan.Venkataraman@Sun.COM 	tableid = CALLOUT_ID_TO_TABLE(xid);
13618048SMadhavan.Venkataraman@Sun.COM 	idhash = CALLOUT_IDHASH(xid);
13628048SMadhavan.Venkataraman@Sun.COM #undef	callouts_table_bits
13638048SMadhavan.Venkataraman@Sun.COM #undef	callout_table_mask
13648048SMadhavan.Venkataraman@Sun.COM #undef	nsec_per_tick
13658048SMadhavan.Venkataraman@Sun.COM 	coid = CO_PLAIN_ID(xid);
13668048SMadhavan.Venkataraman@Sun.COM 
13678048SMadhavan.Venkataraman@Sun.COM 	if (flags & DCMD_ADDRSPEC) {
13688048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("calloutid does not accept explicit address.\n");
13698048SMadhavan.Venkataraman@Sun.COM 		return (DCMD_USAGE);
13708048SMadhavan.Venkataraman@Sun.COM 	}
13718048SMadhavan.Venkataraman@Sun.COM 
13728048SMadhavan.Venkataraman@Sun.COM 	if (coargs.flags & COF_DECODE) {
13738048SMadhavan.Venkataraman@Sun.COM 		if (DCMD_HDRSPEC(flags)) {
13748048SMadhavan.Venkataraman@Sun.COM 			mdb_printf("%<u>%3s %1s %3s %-?s %-6s %</u>\n",
13758048SMadhavan.Venkataraman@Sun.COM 			    "SEQ", "T", "XHL", "XID", "IDHASH");
13760Sstevel@tonic-gate 		}
13778048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("%-3d %1s %1s%1s%1s %-?llx %-6d\n",
13788048SMadhavan.Venkataraman@Sun.COM 		    TABLE_TO_SEQID(tableid),
13798048SMadhavan.Venkataraman@Sun.COM 		    co_typenames[tableid & CALLOUT_TYPE_MASK],
13808048SMadhavan.Venkataraman@Sun.COM 		    (xid & CALLOUT_EXECUTING) ? "X" : " ",
13818048SMadhavan.Venkataraman@Sun.COM 		    (xid & CALLOUT_HRESTIME) ? "H" : " ",
13828048SMadhavan.Venkataraman@Sun.COM 		    (xid & CALLOUT_LONGTERM) ? "L" : " ",
13838048SMadhavan.Venkataraman@Sun.COM 		    (long long)coid, idhash);
13848048SMadhavan.Venkataraman@Sun.COM 		return (DCMD_OK);
13858048SMadhavan.Venkataraman@Sun.COM 	}
13868048SMadhavan.Venkataraman@Sun.COM 
13878048SMadhavan.Venkataraman@Sun.COM 	/* get our table. Note this relies on the types being correct */
13888048SMadhavan.Venkataraman@Sun.COM 	ctptr = coargs.co_table + tableid;
13898048SMadhavan.Venkataraman@Sun.COM 	if (mdb_vread(&ct, sizeof (callout_table_t), (uintptr_t)ctptr) == -1) {
13908048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("failed to read callout_table at %p", ctptr);
13918048SMadhavan.Venkataraman@Sun.COM 		return (DCMD_ERR);
13928048SMadhavan.Venkataraman@Sun.COM 	}
13938048SMadhavan.Venkataraman@Sun.COM 	size = sizeof (callout_hash_t) * CALLOUT_BUCKETS;
13948048SMadhavan.Venkataraman@Sun.COM 	if (ct.ct_idhash != NULL) {
13958048SMadhavan.Venkataraman@Sun.COM 		if (mdb_vread(&(cot_idhash), size,
13968048SMadhavan.Venkataraman@Sun.COM 		    (uintptr_t)ct.ct_idhash) == -1) {
13978048SMadhavan.Venkataraman@Sun.COM 			mdb_warn("failed to read id_hash at %p",
13988048SMadhavan.Venkataraman@Sun.COM 			    ct.ct_idhash);
13998048SMadhavan.Venkataraman@Sun.COM 			return (WALK_ERR);
14008048SMadhavan.Venkataraman@Sun.COM 		}
14018048SMadhavan.Venkataraman@Sun.COM 	}
14028048SMadhavan.Venkataraman@Sun.COM 
14038048SMadhavan.Venkataraman@Sun.COM 	/* callout at beginning of hash chain */
14048048SMadhavan.Venkataraman@Sun.COM 	if (ct.ct_idhash == NULL) {
14058048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("id hash chain for this xid is empty\n");
14068048SMadhavan.Venkataraman@Sun.COM 		return (DCMD_ERR);
14078048SMadhavan.Venkataraman@Sun.COM 	}
14088048SMadhavan.Venkataraman@Sun.COM 	coptr = (callout_t *)cot_idhash[idhash].ch_head;
14098048SMadhavan.Venkataraman@Sun.COM 	if (coptr == NULL) {
14108048SMadhavan.Venkataraman@Sun.COM 		mdb_printf("id hash chain for this xid is empty\n");
14118048SMadhavan.Venkataraman@Sun.COM 		return (DCMD_ERR);
14128048SMadhavan.Venkataraman@Sun.COM 	}
14138048SMadhavan.Venkataraman@Sun.COM 
14148048SMadhavan.Venkataraman@Sun.COM 	coargs.ndx = tableid;
14158048SMadhavan.Venkataraman@Sun.COM 	coargs.bucket = idhash;
14168048SMadhavan.Venkataraman@Sun.COM 
14178048SMadhavan.Venkataraman@Sun.COM 	/* use the walker, luke */
14188048SMadhavan.Venkataraman@Sun.COM 	if (mdb_pwalk("callouts_byid", callouts_cb, &coargs,
14198048SMadhavan.Venkataraman@Sun.COM 	    (uintptr_t)coptr) == -1) {
14208048SMadhavan.Venkataraman@Sun.COM 		mdb_warn("cannot walk callouts at %p", coptr);
14218048SMadhavan.Venkataraman@Sun.COM 		return (WALK_ERR);
14220Sstevel@tonic-gate 	}
14230Sstevel@tonic-gate 
14240Sstevel@tonic-gate 	return (DCMD_OK);
14250Sstevel@tonic-gate }
14260Sstevel@tonic-gate 
14278048SMadhavan.Venkataraman@Sun.COM void
14288048SMadhavan.Venkataraman@Sun.COM callout_help(void)
14298048SMadhavan.Venkataraman@Sun.COM {
14308048SMadhavan.Venkataraman@Sun.COM 	mdb_printf("callout: display callouts.\n"
14318048SMadhavan.Venkataraman@Sun.COM 	    "Given a callout table address, display callouts from table.\n"
14328048SMadhavan.Venkataraman@Sun.COM 	    "Without an address, display callouts from all tables.\n"
14338048SMadhavan.Venkataraman@Sun.COM 	    "options:\n"
14348048SMadhavan.Venkataraman@Sun.COM 	    " -r|n : limit display to (r)ealtime or (n)ormal type callouts\n"
14358048SMadhavan.Venkataraman@Sun.COM 	    " -s|l : limit display to (s)hort-term ids or (l)ong-term ids\n"
14368048SMadhavan.Venkataraman@Sun.COM 	    " -x : limit display to callouts which are executing\n"
14378048SMadhavan.Venkataraman@Sun.COM 	    " -h : limit display to callouts based on hrestime\n"
14388048SMadhavan.Venkataraman@Sun.COM 	    " -t|a|b nsec: limit display to callouts that expire a(t) time,"
14398048SMadhavan.Venkataraman@Sun.COM 	    " (a)fter time,\n     or (b)efore time. Use -a and -b together "
14408048SMadhavan.Venkataraman@Sun.COM 	    " to specify a range.\n     For \"now\", use -d[t|a|b] 0.\n"
14418048SMadhavan.Venkataraman@Sun.COM 	    " -d : interpret time option to -t|a|b as delta from current time\n"
14428048SMadhavan.Venkataraman@Sun.COM 	    " -k : use ticks instead of nanoseconds as arguments to"
14438048SMadhavan.Venkataraman@Sun.COM 	    " -t|a|b. Note that\n     ticks are less accurate and may not"
14448048SMadhavan.Venkataraman@Sun.COM 	    " match other tick times (ie: lbolt).\n"
14458048SMadhavan.Venkataraman@Sun.COM 	    " -D : display exiration time as delta from current time\n"
14468048SMadhavan.Venkataraman@Sun.COM 	    " -S seqid : limit display to callouts for this cpu sequence id\n"
14478048SMadhavan.Venkataraman@Sun.COM 	    " -C addr :  limit display to callouts for this cpu pointer\n"
14488048SMadhavan.Venkataraman@Sun.COM 	    " -f name|addr : limit display to callouts with this function\n"
14498048SMadhavan.Venkataraman@Sun.COM 	    " -p name|addr : limit display to callouts functions with this"
14508048SMadhavan.Venkataraman@Sun.COM 	    " parameter\n"
14518048SMadhavan.Venkataraman@Sun.COM 	    " -T : display the callout table itself, instead of callouts\n"
14528048SMadhavan.Venkataraman@Sun.COM 	    " -L : display callout lists instead of callouts\n"
14538048SMadhavan.Venkataraman@Sun.COM 	    " -E : with -T or L, display empty data structures.\n"
14548048SMadhavan.Venkataraman@Sun.COM 	    " -i : traverse callouts by id hash instead of list hash\n"
14558048SMadhavan.Venkataraman@Sun.COM 	    " -F : walk free callout list (free list with -i) instead\n"
14568048SMadhavan.Venkataraman@Sun.COM 	    " -v : display more info for each item\n"
14578048SMadhavan.Venkataraman@Sun.COM 	    " -V : show details of each level of info as it is traversed\n"
14588048SMadhavan.Venkataraman@Sun.COM 	    " -A : show only addresses. Useful for pipelines.\n");
14598048SMadhavan.Venkataraman@Sun.COM }
14608048SMadhavan.Venkataraman@Sun.COM 
14618048SMadhavan.Venkataraman@Sun.COM void
14628048SMadhavan.Venkataraman@Sun.COM calloutid_help(void)
14638048SMadhavan.Venkataraman@Sun.COM {
14648048SMadhavan.Venkataraman@Sun.COM 	mdb_printf("calloutid: display callout by id.\n"
14658048SMadhavan.Venkataraman@Sun.COM 	    "Given an extended callout id, display the callout infomation.\n"
14668048SMadhavan.Venkataraman@Sun.COM 	    "options:\n"
14678048SMadhavan.Venkataraman@Sun.COM 	    " -d : do not dereference callout, just decode the id.\n"
14688048SMadhavan.Venkataraman@Sun.COM 	    " -v : verbose display more info about the callout\n");
14698048SMadhavan.Venkataraman@Sun.COM }
14708048SMadhavan.Venkataraman@Sun.COM 
14710Sstevel@tonic-gate /*ARGSUSED*/
14720Sstevel@tonic-gate int
14730Sstevel@tonic-gate class(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
14740Sstevel@tonic-gate {
14750Sstevel@tonic-gate 	long num_classes, i;
14760Sstevel@tonic-gate 	sclass_t *class_tbl;
14770Sstevel@tonic-gate 	GElf_Sym g_sclass;
14780Sstevel@tonic-gate 	char class_name[PC_CLNMSZ];
14790Sstevel@tonic-gate 	size_t tbl_size;
14800Sstevel@tonic-gate 
14810Sstevel@tonic-gate 	if (mdb_lookup_by_name("sclass", &g_sclass) == -1) {
14820Sstevel@tonic-gate 		mdb_warn("failed to find symbol sclass\n");
14830Sstevel@tonic-gate 		return (DCMD_ERR);
14840Sstevel@tonic-gate 	}
14850Sstevel@tonic-gate 
14860Sstevel@tonic-gate 	tbl_size = (size_t)g_sclass.st_size;
14870Sstevel@tonic-gate 	num_classes = tbl_size / (sizeof (sclass_t));
14880Sstevel@tonic-gate 	class_tbl = mdb_alloc(tbl_size, UM_SLEEP | UM_GC);
14890Sstevel@tonic-gate 
14900Sstevel@tonic-gate 	if (mdb_readsym(class_tbl, tbl_size, "sclass") == -1) {
14910Sstevel@tonic-gate 		mdb_warn("failed to read sclass");
14920Sstevel@tonic-gate 		return (DCMD_ERR);
14930Sstevel@tonic-gate 	}
14940Sstevel@tonic-gate 
14950Sstevel@tonic-gate 	mdb_printf("%<u>%4s %-10s %-24s %-24s%</u>\n", "SLOT", "NAME",
14960Sstevel@tonic-gate 	    "INIT FCN", "CLASS FCN");
14970Sstevel@tonic-gate 
14980Sstevel@tonic-gate 	for (i = 0; i < num_classes; i++) {
14990Sstevel@tonic-gate 		if (mdb_vread(class_name, sizeof (class_name),
15000Sstevel@tonic-gate 		    (uintptr_t)class_tbl[i].cl_name) == -1)
15010Sstevel@tonic-gate 			(void) strcpy(class_name, "???");
15020Sstevel@tonic-gate 
15030Sstevel@tonic-gate 		mdb_printf("%4ld %-10s %-24a %-24a\n", i, class_name,
15040Sstevel@tonic-gate 		    class_tbl[i].cl_init, class_tbl[i].cl_funcs);
15050Sstevel@tonic-gate 	}
15060Sstevel@tonic-gate 
15070Sstevel@tonic-gate 	return (DCMD_OK);
15080Sstevel@tonic-gate }
15090Sstevel@tonic-gate 
15100Sstevel@tonic-gate #define	FSNAMELEN	32	/* Max len of FS name we read from vnodeops */
15110Sstevel@tonic-gate 
15120Sstevel@tonic-gate int
15130Sstevel@tonic-gate vnode2path(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
15140Sstevel@tonic-gate {
15150Sstevel@tonic-gate 	uintptr_t rootdir;
15160Sstevel@tonic-gate 	vnode_t vn;
15170Sstevel@tonic-gate 	char buf[MAXPATHLEN];
15180Sstevel@tonic-gate 
15190Sstevel@tonic-gate 	uint_t opt_F = FALSE;
15200Sstevel@tonic-gate 
15210Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
15220Sstevel@tonic-gate 	    'F', MDB_OPT_SETBITS, TRUE, &opt_F, NULL) != argc)
15230Sstevel@tonic-gate 		return (DCMD_USAGE);
15240Sstevel@tonic-gate 
15250Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
15260Sstevel@tonic-gate 		mdb_warn("expected explicit vnode_t address before ::\n");
15270Sstevel@tonic-gate 		return (DCMD_USAGE);
15280Sstevel@tonic-gate 	}
15290Sstevel@tonic-gate 
15300Sstevel@tonic-gate 	if (mdb_readvar(&rootdir, "rootdir") == -1) {
15310Sstevel@tonic-gate 		mdb_warn("failed to read rootdir");
15320Sstevel@tonic-gate 		return (DCMD_ERR);
15330Sstevel@tonic-gate 	}
15340Sstevel@tonic-gate 
15350Sstevel@tonic-gate 	if (mdb_vnode2path(addr, buf, sizeof (buf)) == -1)
15360Sstevel@tonic-gate 		return (DCMD_ERR);
15370Sstevel@tonic-gate 
15380Sstevel@tonic-gate 	if (*buf == '\0') {
15390Sstevel@tonic-gate 		mdb_printf("??\n");
15400Sstevel@tonic-gate 		return (DCMD_OK);
15410Sstevel@tonic-gate 	}
15420Sstevel@tonic-gate 
15430Sstevel@tonic-gate 	mdb_printf("%s", buf);
15440Sstevel@tonic-gate 	if (opt_F && buf[strlen(buf)-1] != '/' &&
15450Sstevel@tonic-gate 	    mdb_vread(&vn, sizeof (vn), addr) == sizeof (vn))
15460Sstevel@tonic-gate 		mdb_printf("%c", mdb_vtype2chr(vn.v_type, 0));
15470Sstevel@tonic-gate 	mdb_printf("\n");
15480Sstevel@tonic-gate 
15490Sstevel@tonic-gate 	return (DCMD_OK);
15500Sstevel@tonic-gate }
15510Sstevel@tonic-gate 
15520Sstevel@tonic-gate int
15530Sstevel@tonic-gate ld_walk_init(mdb_walk_state_t *wsp)
15540Sstevel@tonic-gate {
15550Sstevel@tonic-gate 	wsp->walk_data = (void *)wsp->walk_addr;
15560Sstevel@tonic-gate 	return (WALK_NEXT);
15570Sstevel@tonic-gate }
15580Sstevel@tonic-gate 
15590Sstevel@tonic-gate int
15600Sstevel@tonic-gate ld_walk_step(mdb_walk_state_t *wsp)
15610Sstevel@tonic-gate {
15620Sstevel@tonic-gate 	int status;
15630Sstevel@tonic-gate 	lock_descriptor_t ld;
15640Sstevel@tonic-gate 
15650Sstevel@tonic-gate 	if (mdb_vread(&ld, sizeof (lock_descriptor_t), wsp->walk_addr) == -1) {
15660Sstevel@tonic-gate 		mdb_warn("couldn't read lock_descriptor_t at %p\n",
15670Sstevel@tonic-gate 		    wsp->walk_addr);
15680Sstevel@tonic-gate 		return (WALK_ERR);
15690Sstevel@tonic-gate 	}
15700Sstevel@tonic-gate 
15710Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, &ld, wsp->walk_cbdata);
15720Sstevel@tonic-gate 	if (status == WALK_ERR)
15730Sstevel@tonic-gate 		return (WALK_ERR);
15740Sstevel@tonic-gate 
15750Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)ld.l_next;
15760Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data)
15770Sstevel@tonic-gate 		return (WALK_DONE);
15780Sstevel@tonic-gate 
15790Sstevel@tonic-gate 	return (status);
15800Sstevel@tonic-gate }
15810Sstevel@tonic-gate 
15820Sstevel@tonic-gate int
15830Sstevel@tonic-gate lg_walk_init(mdb_walk_state_t *wsp)
15840Sstevel@tonic-gate {
15850Sstevel@tonic-gate 	GElf_Sym sym;
15860Sstevel@tonic-gate 
15870Sstevel@tonic-gate 	if (mdb_lookup_by_name("lock_graph", &sym) == -1) {
15880Sstevel@tonic-gate 		mdb_warn("failed to find symbol 'lock_graph'\n");
15890Sstevel@tonic-gate 		return (WALK_ERR);
15900Sstevel@tonic-gate 	}
15910Sstevel@tonic-gate 
15920Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)sym.st_value;
1593436Sdmick 	wsp->walk_data = (void *)(uintptr_t)(sym.st_value + sym.st_size);
15940Sstevel@tonic-gate 
15950Sstevel@tonic-gate 	return (WALK_NEXT);
15960Sstevel@tonic-gate }
15970Sstevel@tonic-gate 
15980Sstevel@tonic-gate typedef struct lg_walk_data {
15990Sstevel@tonic-gate 	uintptr_t startaddr;
16000Sstevel@tonic-gate 	mdb_walk_cb_t callback;
16010Sstevel@tonic-gate 	void *data;
16020Sstevel@tonic-gate } lg_walk_data_t;
16030Sstevel@tonic-gate 
16040Sstevel@tonic-gate /*
16050Sstevel@tonic-gate  * We can't use ::walk lock_descriptor directly, because the head of each graph
16060Sstevel@tonic-gate  * is really a dummy lock.  Rather than trying to dynamically determine if this
16070Sstevel@tonic-gate  * is a dummy node or not, we just filter out the initial element of the
16080Sstevel@tonic-gate  * list.
16090Sstevel@tonic-gate  */
16100Sstevel@tonic-gate static int
16110Sstevel@tonic-gate lg_walk_cb(uintptr_t addr, const void *data, void *priv)
16120Sstevel@tonic-gate {
16130Sstevel@tonic-gate 	lg_walk_data_t *lw = priv;
16140Sstevel@tonic-gate 
16150Sstevel@tonic-gate 	if (addr != lw->startaddr)
16160Sstevel@tonic-gate 		return (lw->callback(addr, data, lw->data));
16170Sstevel@tonic-gate 
16180Sstevel@tonic-gate 	return (WALK_NEXT);
16190Sstevel@tonic-gate }
16200Sstevel@tonic-gate 
16210Sstevel@tonic-gate int
16220Sstevel@tonic-gate lg_walk_step(mdb_walk_state_t *wsp)
16230Sstevel@tonic-gate {
16240Sstevel@tonic-gate 	graph_t *graph;
16250Sstevel@tonic-gate 	lg_walk_data_t lw;
16260Sstevel@tonic-gate 
16270Sstevel@tonic-gate 	if (wsp->walk_addr >= (uintptr_t)wsp->walk_data)
16280Sstevel@tonic-gate 		return (WALK_DONE);
16290Sstevel@tonic-gate 
16300Sstevel@tonic-gate 	if (mdb_vread(&graph, sizeof (graph), wsp->walk_addr) == -1) {
16310Sstevel@tonic-gate 		mdb_warn("failed to read graph_t at %p", wsp->walk_addr);
16320Sstevel@tonic-gate 		return (WALK_ERR);
16330Sstevel@tonic-gate 	}
16340Sstevel@tonic-gate 
16350Sstevel@tonic-gate 	wsp->walk_addr += sizeof (graph);
16360Sstevel@tonic-gate 
16370Sstevel@tonic-gate 	if (graph == NULL)
16380Sstevel@tonic-gate 		return (WALK_NEXT);
16390Sstevel@tonic-gate 
16400Sstevel@tonic-gate 	lw.callback = wsp->walk_callback;
16410Sstevel@tonic-gate 	lw.data = wsp->walk_cbdata;
16420Sstevel@tonic-gate 
16430Sstevel@tonic-gate 	lw.startaddr = (uintptr_t)&(graph->active_locks);
16440Sstevel@tonic-gate 	if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
16450Sstevel@tonic-gate 		mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
16460Sstevel@tonic-gate 		return (WALK_ERR);
16470Sstevel@tonic-gate 	}
16480Sstevel@tonic-gate 
16490Sstevel@tonic-gate 	lw.startaddr = (uintptr_t)&(graph->sleeping_locks);
16500Sstevel@tonic-gate 	if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
16510Sstevel@tonic-gate 		mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
16520Sstevel@tonic-gate 		return (WALK_ERR);
16530Sstevel@tonic-gate 	}
16540Sstevel@tonic-gate 
16550Sstevel@tonic-gate 	return (WALK_NEXT);
16560Sstevel@tonic-gate }
16570Sstevel@tonic-gate 
16580Sstevel@tonic-gate /*
16590Sstevel@tonic-gate  * The space available for the path corresponding to the locked vnode depends
16600Sstevel@tonic-gate  * on whether we are printing 32- or 64-bit addresses.
16610Sstevel@tonic-gate  */
16620Sstevel@tonic-gate #ifdef _LP64
16630Sstevel@tonic-gate #define	LM_VNPATHLEN	20
16640Sstevel@tonic-gate #else
16650Sstevel@tonic-gate #define	LM_VNPATHLEN	30
16660Sstevel@tonic-gate #endif
16670Sstevel@tonic-gate 
16680Sstevel@tonic-gate /*ARGSUSED*/
16690Sstevel@tonic-gate static int
16700Sstevel@tonic-gate lminfo_cb(uintptr_t addr, const void *data, void *priv)
16710Sstevel@tonic-gate {
16720Sstevel@tonic-gate 	const lock_descriptor_t *ld = data;
16730Sstevel@tonic-gate 	char buf[LM_VNPATHLEN];
16740Sstevel@tonic-gate 	proc_t p;
16750Sstevel@tonic-gate 
16760Sstevel@tonic-gate 	mdb_printf("%-?p %2s %04x %6d %-16s %-?p ",
16770Sstevel@tonic-gate 	    addr, ld->l_type == F_RDLCK ? "RD" :
16780Sstevel@tonic-gate 	    ld->l_type == F_WRLCK ? "WR" : "??",
16790Sstevel@tonic-gate 	    ld->l_state, ld->l_flock.l_pid,
16800Sstevel@tonic-gate 	    ld->l_flock.l_pid == 0 ? "<kernel>" :
16810Sstevel@tonic-gate 	    mdb_pid2proc(ld->l_flock.l_pid, &p) == NULL ?
16820Sstevel@tonic-gate 	    "<defunct>" : p.p_user.u_comm,
16830Sstevel@tonic-gate 	    ld->l_vnode);
16840Sstevel@tonic-gate 
16850Sstevel@tonic-gate 	mdb_vnode2path((uintptr_t)ld->l_vnode, buf,
16860Sstevel@tonic-gate 	    sizeof (buf));
16870Sstevel@tonic-gate 	mdb_printf("%s\n", buf);
16880Sstevel@tonic-gate 
16890Sstevel@tonic-gate 	return (WALK_NEXT);
16900Sstevel@tonic-gate }
16910Sstevel@tonic-gate 
16920Sstevel@tonic-gate /*ARGSUSED*/
16930Sstevel@tonic-gate int
16940Sstevel@tonic-gate lminfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
16950Sstevel@tonic-gate {
16960Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags))
16970Sstevel@tonic-gate 		mdb_printf("%<u>%-?s %2s %4s %6s %-16s %-?s %s%</u>\n",
16980Sstevel@tonic-gate 		    "ADDR", "TP", "FLAG", "PID", "COMM", "VNODE", "PATH");
16990Sstevel@tonic-gate 
17000Sstevel@tonic-gate 	return (mdb_pwalk("lock_graph", lminfo_cb, NULL, NULL));
17010Sstevel@tonic-gate }
17020Sstevel@tonic-gate 
17030Sstevel@tonic-gate /*ARGSUSED*/
17040Sstevel@tonic-gate int
17050Sstevel@tonic-gate seg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
17060Sstevel@tonic-gate {
17070Sstevel@tonic-gate 	struct seg s;
17080Sstevel@tonic-gate 
17090Sstevel@tonic-gate 	if (argc != 0)
17100Sstevel@tonic-gate 		return (DCMD_USAGE);
17110Sstevel@tonic-gate 
17120Sstevel@tonic-gate 	if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
17130Sstevel@tonic-gate 		mdb_printf("%<u>%?s %?s %?s %?s %s%</u>\n",
17140Sstevel@tonic-gate 		    "SEG", "BASE", "SIZE", "DATA", "OPS");
17150Sstevel@tonic-gate 	}
17160Sstevel@tonic-gate 
17170Sstevel@tonic-gate 	if (mdb_vread(&s, sizeof (s), addr) == -1) {
17180Sstevel@tonic-gate 		mdb_warn("failed to read seg at %p", addr);
17190Sstevel@tonic-gate 		return (DCMD_ERR);
17200Sstevel@tonic-gate 	}
17210Sstevel@tonic-gate 
17220Sstevel@tonic-gate 	mdb_printf("%?p %?p %?lx %?p %a\n",
17230Sstevel@tonic-gate 	    addr, s.s_base, s.s_size, s.s_data, s.s_ops);
17240Sstevel@tonic-gate 
17250Sstevel@tonic-gate 	return (DCMD_OK);
17260Sstevel@tonic-gate }
17270Sstevel@tonic-gate 
17280Sstevel@tonic-gate /*ARGSUSED*/
17290Sstevel@tonic-gate static int
17300Sstevel@tonic-gate pmap_walk_anon(uintptr_t addr, const struct anon *anon, int *nres)
17310Sstevel@tonic-gate {
17320Sstevel@tonic-gate 	uintptr_t pp =
17330Sstevel@tonic-gate 	    mdb_vnode2page((uintptr_t)anon->an_vp, (uintptr_t)anon->an_off);
17340Sstevel@tonic-gate 
17350Sstevel@tonic-gate 	if (pp != NULL)
17360Sstevel@tonic-gate 		(*nres)++;
17370Sstevel@tonic-gate 
17380Sstevel@tonic-gate 	return (WALK_NEXT);
17390Sstevel@tonic-gate }
17400Sstevel@tonic-gate 
17410Sstevel@tonic-gate static int
17420Sstevel@tonic-gate pmap_walk_seg(uintptr_t addr, const struct seg *seg, uintptr_t segvn)
17430Sstevel@tonic-gate {
17440Sstevel@tonic-gate 
17450Sstevel@tonic-gate 	mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024);
17460Sstevel@tonic-gate 
17470Sstevel@tonic-gate 	if (segvn == (uintptr_t)seg->s_ops) {
17480Sstevel@tonic-gate 		struct segvn_data svn;
17490Sstevel@tonic-gate 		int nres = 0;
17500Sstevel@tonic-gate 
17510Sstevel@tonic-gate 		(void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data);
17520Sstevel@tonic-gate 
17530Sstevel@tonic-gate 		if (svn.amp == NULL) {
17540Sstevel@tonic-gate 			mdb_printf(" %8s", "");
17550Sstevel@tonic-gate 			goto drive_on;
17560Sstevel@tonic-gate 		}
17570Sstevel@tonic-gate 
17580Sstevel@tonic-gate 		/*
17590Sstevel@tonic-gate 		 * We've got an amp for this segment; walk through
17600Sstevel@tonic-gate 		 * the amp, and determine mappings.
17610Sstevel@tonic-gate 		 */
17620Sstevel@tonic-gate 		if (mdb_pwalk("anon", (mdb_walk_cb_t)pmap_walk_anon,
17630Sstevel@tonic-gate 		    &nres, (uintptr_t)svn.amp) == -1)
17640Sstevel@tonic-gate 			mdb_warn("failed to walk anon (amp=%p)", svn.amp);
17650Sstevel@tonic-gate 
17660Sstevel@tonic-gate 		mdb_printf(" %7dk", (nres * PAGESIZE) / 1024);
17670Sstevel@tonic-gate drive_on:
17680Sstevel@tonic-gate 
17690Sstevel@tonic-gate 		if (svn.vp != NULL) {
17700Sstevel@tonic-gate 			char buf[29];
17710Sstevel@tonic-gate 
17720Sstevel@tonic-gate 			mdb_vnode2path((uintptr_t)svn.vp, buf, sizeof (buf));
17730Sstevel@tonic-gate 			mdb_printf(" %s", buf);
17740Sstevel@tonic-gate 		} else
17750Sstevel@tonic-gate 			mdb_printf(" [ anon ]");
17760Sstevel@tonic-gate 	}
17770Sstevel@tonic-gate 
17780Sstevel@tonic-gate 	mdb_printf("\n");
17790Sstevel@tonic-gate 	return (WALK_NEXT);
17800Sstevel@tonic-gate }
17810Sstevel@tonic-gate 
17820Sstevel@tonic-gate static int
17830Sstevel@tonic-gate pmap_walk_seg_quick(uintptr_t addr, const struct seg *seg, uintptr_t segvn)
17840Sstevel@tonic-gate {
17850Sstevel@tonic-gate 	mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024);
17860Sstevel@tonic-gate 
17870Sstevel@tonic-gate 	if (segvn == (uintptr_t)seg->s_ops) {
17880Sstevel@tonic-gate 		struct segvn_data svn;
17890Sstevel@tonic-gate 
17900Sstevel@tonic-gate 		(void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data);
17910Sstevel@tonic-gate 
17920Sstevel@tonic-gate 		if (svn.vp != NULL) {
17930Sstevel@tonic-gate 			mdb_printf(" %0?p", svn.vp);
17940Sstevel@tonic-gate 		} else {
17950Sstevel@tonic-gate 			mdb_printf(" [ anon ]");
17960Sstevel@tonic-gate 		}
17970Sstevel@tonic-gate 	}
17980Sstevel@tonic-gate 
17990Sstevel@tonic-gate 	mdb_printf("\n");
18000Sstevel@tonic-gate 	return (WALK_NEXT);
18010Sstevel@tonic-gate }
18020Sstevel@tonic-gate 
18030Sstevel@tonic-gate /*ARGSUSED*/
18040Sstevel@tonic-gate int
18050Sstevel@tonic-gate pmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
18060Sstevel@tonic-gate {
18070Sstevel@tonic-gate 	uintptr_t segvn;
18080Sstevel@tonic-gate 	proc_t proc;
18090Sstevel@tonic-gate 	uint_t quick = FALSE;
18100Sstevel@tonic-gate 	mdb_walk_cb_t cb = (mdb_walk_cb_t)pmap_walk_seg;
18110Sstevel@tonic-gate 
18120Sstevel@tonic-gate 	GElf_Sym sym;
18130Sstevel@tonic-gate 
18140Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
18150Sstevel@tonic-gate 		return (DCMD_USAGE);
18160Sstevel@tonic-gate 
18170Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
18180Sstevel@tonic-gate 	    'q', MDB_OPT_SETBITS, TRUE, &quick, NULL) != argc)
18190Sstevel@tonic-gate 		return (DCMD_USAGE);
18200Sstevel@tonic-gate 
18210Sstevel@tonic-gate 	if (mdb_vread(&proc, sizeof (proc), addr) == -1) {
18220Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", addr);
18230Sstevel@tonic-gate 		return (DCMD_ERR);
18240Sstevel@tonic-gate 	}
18250Sstevel@tonic-gate 
18260Sstevel@tonic-gate 	if (mdb_lookup_by_name("segvn_ops", &sym) == 0)
18270Sstevel@tonic-gate 		segvn = (uintptr_t)sym.st_value;
18280Sstevel@tonic-gate 	else
18290Sstevel@tonic-gate 		segvn = NULL;
18300Sstevel@tonic-gate 
18310Sstevel@tonic-gate 	mdb_printf("%?s %?s %8s ", "SEG", "BASE", "SIZE");
18320Sstevel@tonic-gate 
18330Sstevel@tonic-gate 	if (quick) {
18340Sstevel@tonic-gate 		mdb_printf("VNODE\n");
18350Sstevel@tonic-gate 		cb = (mdb_walk_cb_t)pmap_walk_seg_quick;
18360Sstevel@tonic-gate 	} else {
18370Sstevel@tonic-gate 		mdb_printf("%8s %s\n", "RES", "PATH");
18380Sstevel@tonic-gate 	}
18390Sstevel@tonic-gate 
18400Sstevel@tonic-gate 	if (mdb_pwalk("seg", cb, (void *)segvn, (uintptr_t)proc.p_as) == -1) {
18410Sstevel@tonic-gate 		mdb_warn("failed to walk segments of as %p", proc.p_as);
18420Sstevel@tonic-gate 		return (DCMD_ERR);
18430Sstevel@tonic-gate 	}
18440Sstevel@tonic-gate 
18450Sstevel@tonic-gate 	return (DCMD_OK);
18460Sstevel@tonic-gate }
18470Sstevel@tonic-gate 
18480Sstevel@tonic-gate typedef struct anon_walk_data {
18490Sstevel@tonic-gate 	uintptr_t *aw_levone;
18500Sstevel@tonic-gate 	uintptr_t *aw_levtwo;
18510Sstevel@tonic-gate 	int aw_nlevone;
18520Sstevel@tonic-gate 	int aw_levone_ndx;
18530Sstevel@tonic-gate 	int aw_levtwo_ndx;
18540Sstevel@tonic-gate 	struct anon_map aw_amp;
18550Sstevel@tonic-gate 	struct anon_hdr aw_ahp;
18560Sstevel@tonic-gate } anon_walk_data_t;
18570Sstevel@tonic-gate 
18580Sstevel@tonic-gate int
18590Sstevel@tonic-gate anon_walk_init(mdb_walk_state_t *wsp)
18600Sstevel@tonic-gate {
18610Sstevel@tonic-gate 	anon_walk_data_t *aw;
18620Sstevel@tonic-gate 
18630Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
18640Sstevel@tonic-gate 		mdb_warn("anon walk doesn't support global walks\n");
18650Sstevel@tonic-gate 		return (WALK_ERR);
18660Sstevel@tonic-gate 	}
18670Sstevel@tonic-gate 
18680Sstevel@tonic-gate 	aw = mdb_alloc(sizeof (anon_walk_data_t), UM_SLEEP);
18690Sstevel@tonic-gate 
18700Sstevel@tonic-gate 	if (mdb_vread(&aw->aw_amp, sizeof (aw->aw_amp), wsp->walk_addr) == -1) {
18710Sstevel@tonic-gate 		mdb_warn("failed to read anon map at %p", wsp->walk_addr);
18720Sstevel@tonic-gate 		mdb_free(aw, sizeof (anon_walk_data_t));
18730Sstevel@tonic-gate 		return (WALK_ERR);
18740Sstevel@tonic-gate 	}
18750Sstevel@tonic-gate 
18760Sstevel@tonic-gate 	if (mdb_vread(&aw->aw_ahp, sizeof (aw->aw_ahp),
18770Sstevel@tonic-gate 	    (uintptr_t)(aw->aw_amp.ahp)) == -1) {
18780Sstevel@tonic-gate 		mdb_warn("failed to read anon hdr ptr at %p", aw->aw_amp.ahp);
18790Sstevel@tonic-gate 		mdb_free(aw, sizeof (anon_walk_data_t));
18800Sstevel@tonic-gate 		return (WALK_ERR);
18810Sstevel@tonic-gate 	}
18820Sstevel@tonic-gate 
18830Sstevel@tonic-gate 	if (aw->aw_ahp.size <= ANON_CHUNK_SIZE ||
18840Sstevel@tonic-gate 	    (aw->aw_ahp.flags & ANON_ALLOC_FORCE)) {
18850Sstevel@tonic-gate 		aw->aw_nlevone = aw->aw_ahp.size;
18860Sstevel@tonic-gate 		aw->aw_levtwo = NULL;
18870Sstevel@tonic-gate 	} else {
18880Sstevel@tonic-gate 		aw->aw_nlevone =
18890Sstevel@tonic-gate 		    (aw->aw_ahp.size + ANON_CHUNK_OFF) >> ANON_CHUNK_SHIFT;
18900Sstevel@tonic-gate 		aw->aw_levtwo =
18910Sstevel@tonic-gate 		    mdb_zalloc(ANON_CHUNK_SIZE * sizeof (uintptr_t), UM_SLEEP);
18920Sstevel@tonic-gate 	}
18930Sstevel@tonic-gate 
18940Sstevel@tonic-gate 	aw->aw_levone =
18950Sstevel@tonic-gate 	    mdb_alloc(aw->aw_nlevone * sizeof (uintptr_t), UM_SLEEP);
18960Sstevel@tonic-gate 
18970Sstevel@tonic-gate 	aw->aw_levone_ndx = 0;
18980Sstevel@tonic-gate 	aw->aw_levtwo_ndx = 0;
18990Sstevel@tonic-gate 
19000Sstevel@tonic-gate 	mdb_vread(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t),
19010Sstevel@tonic-gate 	    (uintptr_t)aw->aw_ahp.array_chunk);
19020Sstevel@tonic-gate 
19030Sstevel@tonic-gate 	if (aw->aw_levtwo != NULL) {
19040Sstevel@tonic-gate 		while (aw->aw_levone[aw->aw_levone_ndx] == NULL) {
19050Sstevel@tonic-gate 			aw->aw_levone_ndx++;
19060Sstevel@tonic-gate 			if (aw->aw_levone_ndx == aw->aw_nlevone) {
19070Sstevel@tonic-gate 				mdb_warn("corrupt anon; couldn't"
19080Sstevel@tonic-gate 				    "find ptr to lev two map");
19090Sstevel@tonic-gate 				goto out;
19100Sstevel@tonic-gate 			}
19110Sstevel@tonic-gate 		}
19120Sstevel@tonic-gate 
19130Sstevel@tonic-gate 		mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t),
19140Sstevel@tonic-gate 		    aw->aw_levone[aw->aw_levone_ndx]);
19150Sstevel@tonic-gate 	}
19160Sstevel@tonic-gate 
19170Sstevel@tonic-gate out:
19180Sstevel@tonic-gate 	wsp->walk_data = aw;
19190Sstevel@tonic-gate 	return (0);
19200Sstevel@tonic-gate }
19210Sstevel@tonic-gate 
19220Sstevel@tonic-gate int
19230Sstevel@tonic-gate anon_walk_step(mdb_walk_state_t *wsp)
19240Sstevel@tonic-gate {
19250Sstevel@tonic-gate 	int status;
19260Sstevel@tonic-gate 	anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data;
19270Sstevel@tonic-gate 	struct anon anon;
19280Sstevel@tonic-gate 	uintptr_t anonptr;
19290Sstevel@tonic-gate 
19300Sstevel@tonic-gate again:
19310Sstevel@tonic-gate 	/*
19320Sstevel@tonic-gate 	 * Once we've walked through level one, we're done.
19330Sstevel@tonic-gate 	 */
19340Sstevel@tonic-gate 	if (aw->aw_levone_ndx == aw->aw_nlevone)
19350Sstevel@tonic-gate 		return (WALK_DONE);
19360Sstevel@tonic-gate 
19370Sstevel@tonic-gate 	if (aw->aw_levtwo == NULL) {
19380Sstevel@tonic-gate 		anonptr = aw->aw_levone[aw->aw_levone_ndx];
19390Sstevel@tonic-gate 		aw->aw_levone_ndx++;
19400Sstevel@tonic-gate 	} else {
19410Sstevel@tonic-gate 		anonptr = aw->aw_levtwo[aw->aw_levtwo_ndx];
19420Sstevel@tonic-gate 		aw->aw_levtwo_ndx++;
19430Sstevel@tonic-gate 
19440Sstevel@tonic-gate 		if (aw->aw_levtwo_ndx == ANON_CHUNK_SIZE) {
19450Sstevel@tonic-gate 			aw->aw_levtwo_ndx = 0;
19460Sstevel@tonic-gate 
19470Sstevel@tonic-gate 			do {
19480Sstevel@tonic-gate 				aw->aw_levone_ndx++;
19490Sstevel@tonic-gate 
19500Sstevel@tonic-gate 				if (aw->aw_levone_ndx == aw->aw_nlevone)
19510Sstevel@tonic-gate 					return (WALK_DONE);
19520Sstevel@tonic-gate 			} while (aw->aw_levone[aw->aw_levone_ndx] == NULL);
19530Sstevel@tonic-gate 
19540Sstevel@tonic-gate 			mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE *
19550Sstevel@tonic-gate 			    sizeof (uintptr_t),
19560Sstevel@tonic-gate 			    aw->aw_levone[aw->aw_levone_ndx]);
19570Sstevel@tonic-gate 		}
19580Sstevel@tonic-gate 	}
19590Sstevel@tonic-gate 
19600Sstevel@tonic-gate 	if (anonptr != NULL) {
19610Sstevel@tonic-gate 		mdb_vread(&anon, sizeof (anon), anonptr);
19620Sstevel@tonic-gate 		status = wsp->walk_callback(anonptr, &anon, wsp->walk_cbdata);
19630Sstevel@tonic-gate 	} else
19640Sstevel@tonic-gate 		goto again;
19650Sstevel@tonic-gate 
19660Sstevel@tonic-gate 	return (status);
19670Sstevel@tonic-gate }
19680Sstevel@tonic-gate 
19690Sstevel@tonic-gate void
19700Sstevel@tonic-gate anon_walk_fini(mdb_walk_state_t *wsp)
19710Sstevel@tonic-gate {
19720Sstevel@tonic-gate 	anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data;
19730Sstevel@tonic-gate 
19740Sstevel@tonic-gate 	if (aw->aw_levtwo != NULL)
19750Sstevel@tonic-gate 		mdb_free(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t));
19760Sstevel@tonic-gate 
19770Sstevel@tonic-gate 	mdb_free(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t));
19780Sstevel@tonic-gate 	mdb_free(aw, sizeof (anon_walk_data_t));
19790Sstevel@tonic-gate }
19800Sstevel@tonic-gate 
19810Sstevel@tonic-gate /*ARGSUSED*/
19820Sstevel@tonic-gate int
19830Sstevel@tonic-gate whereopen_fwalk(uintptr_t addr, struct file *f, uintptr_t *target)
19840Sstevel@tonic-gate {
19850Sstevel@tonic-gate 	if ((uintptr_t)f->f_vnode == *target) {
19860Sstevel@tonic-gate 		mdb_printf("file %p\n", addr);
19870Sstevel@tonic-gate 		*target = NULL;
19880Sstevel@tonic-gate 	}
19890Sstevel@tonic-gate 
19900Sstevel@tonic-gate 	return (WALK_NEXT);
19910Sstevel@tonic-gate }
19920Sstevel@tonic-gate 
19930Sstevel@tonic-gate /*ARGSUSED*/
19940Sstevel@tonic-gate int
19950Sstevel@tonic-gate whereopen_pwalk(uintptr_t addr, void *ignored, uintptr_t *target)
19960Sstevel@tonic-gate {
19970Sstevel@tonic-gate 	uintptr_t t = *target;
19980Sstevel@tonic-gate 
19990Sstevel@tonic-gate 	if (mdb_pwalk("file", (mdb_walk_cb_t)whereopen_fwalk, &t, addr) == -1) {
20000Sstevel@tonic-gate 		mdb_warn("couldn't file walk proc %p", addr);
20010Sstevel@tonic-gate 		return (WALK_ERR);
20020Sstevel@tonic-gate 	}
20030Sstevel@tonic-gate 
20040Sstevel@tonic-gate 	if (t == NULL)
20050Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
20060Sstevel@tonic-gate 
20070Sstevel@tonic-gate 	return (WALK_NEXT);
20080Sstevel@tonic-gate }
20090Sstevel@tonic-gate 
20100Sstevel@tonic-gate /*ARGSUSED*/
20110Sstevel@tonic-gate int
20120Sstevel@tonic-gate whereopen(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
20130Sstevel@tonic-gate {
20140Sstevel@tonic-gate 	uintptr_t target = addr;
20150Sstevel@tonic-gate 
20160Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC) || addr == NULL)
20170Sstevel@tonic-gate 		return (DCMD_USAGE);
20180Sstevel@tonic-gate 
20190Sstevel@tonic-gate 	if (mdb_walk("proc", (mdb_walk_cb_t)whereopen_pwalk, &target) == -1) {
20200Sstevel@tonic-gate 		mdb_warn("can't proc walk");
20210Sstevel@tonic-gate 		return (DCMD_ERR);
20220Sstevel@tonic-gate 	}
20230Sstevel@tonic-gate 
20240Sstevel@tonic-gate 	return (DCMD_OK);
20250Sstevel@tonic-gate }
20260Sstevel@tonic-gate 
20270Sstevel@tonic-gate typedef struct datafmt {
20280Sstevel@tonic-gate 	char	*hdr1;
20290Sstevel@tonic-gate 	char	*hdr2;
20300Sstevel@tonic-gate 	char	*dashes;
20310Sstevel@tonic-gate 	char	*fmt;
20320Sstevel@tonic-gate } datafmt_t;
20330Sstevel@tonic-gate 
20340Sstevel@tonic-gate static datafmt_t kmemfmt[] = {
20350Sstevel@tonic-gate 	{ "cache                    ", "name                     ",
20360Sstevel@tonic-gate 	"-------------------------", "%-25s "				},
20370Sstevel@tonic-gate 	{ "   buf",	"  size",	"------",	"%6u "		},
20380Sstevel@tonic-gate 	{ "   buf",	"in use",	"------",	"%6u "		},
20390Sstevel@tonic-gate 	{ "   buf",	" total",	"------",	"%6u "		},
20404808Sek110237 	{ "   memory",	"   in use",	"----------",	"%9u%c "	},
20410Sstevel@tonic-gate 	{ "    alloc",	"  succeed",	"---------",	"%9u "		},
20420Sstevel@tonic-gate 	{ "alloc",	" fail",	"-----",	"%5u "		},
20430Sstevel@tonic-gate 	{ NULL,		NULL,		NULL,		NULL		}
20440Sstevel@tonic-gate };
20450Sstevel@tonic-gate 
20460Sstevel@tonic-gate static datafmt_t vmemfmt[] = {
20470Sstevel@tonic-gate 	{ "vmem                     ", "name                     ",
20480Sstevel@tonic-gate 	"-------------------------", "%-*s "				},
20494808Sek110237 	{ "   memory",	"   in use",	"----------",	"%9llu%c "	},
20504808Sek110237 	{ "    memory",	"     total",	"-----------",	"%10llu%c "	},
20514808Sek110237 	{ "   memory",	"   import",	"----------",	"%9llu%c "	},
20520Sstevel@tonic-gate 	{ "    alloc",	"  succeed",	"---------",	"%9llu "	},
20530Sstevel@tonic-gate 	{ "alloc",	" fail",	"-----",	"%5llu "	},
20540Sstevel@tonic-gate 	{ NULL,		NULL,		NULL,		NULL		}
20550Sstevel@tonic-gate };
20560Sstevel@tonic-gate 
20570Sstevel@tonic-gate /*ARGSUSED*/
20580Sstevel@tonic-gate static int
20590Sstevel@tonic-gate kmastat_cpu_avail(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *avail)
20600Sstevel@tonic-gate {
20610Sstevel@tonic-gate 	if (ccp->cc_rounds > 0)
20620Sstevel@tonic-gate 		*avail += ccp->cc_rounds;
20630Sstevel@tonic-gate 	if (ccp->cc_prounds > 0)
20640Sstevel@tonic-gate 		*avail += ccp->cc_prounds;
20650Sstevel@tonic-gate 
20660Sstevel@tonic-gate 	return (WALK_NEXT);
20670Sstevel@tonic-gate }
20680Sstevel@tonic-gate 
20690Sstevel@tonic-gate /*ARGSUSED*/
20700Sstevel@tonic-gate static int
20710Sstevel@tonic-gate kmastat_cpu_alloc(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *alloc)
20720Sstevel@tonic-gate {
20730Sstevel@tonic-gate 	*alloc += ccp->cc_alloc;
20740Sstevel@tonic-gate 
20750Sstevel@tonic-gate 	return (WALK_NEXT);
20760Sstevel@tonic-gate }
20770Sstevel@tonic-gate 
20780Sstevel@tonic-gate /*ARGSUSED*/
20790Sstevel@tonic-gate static int
20800Sstevel@tonic-gate kmastat_slab_avail(uintptr_t addr, const kmem_slab_t *sp, int *avail)
20810Sstevel@tonic-gate {
20820Sstevel@tonic-gate 	*avail += sp->slab_chunks - sp->slab_refcnt;
20830Sstevel@tonic-gate 
20840Sstevel@tonic-gate 	return (WALK_NEXT);
20850Sstevel@tonic-gate }
20860Sstevel@tonic-gate 
20870Sstevel@tonic-gate typedef struct kmastat_vmem {
20880Sstevel@tonic-gate 	uintptr_t kv_addr;
20890Sstevel@tonic-gate 	struct kmastat_vmem *kv_next;
20900Sstevel@tonic-gate 	int kv_meminuse;
20910Sstevel@tonic-gate 	int kv_alloc;
20920Sstevel@tonic-gate 	int kv_fail;
20930Sstevel@tonic-gate } kmastat_vmem_t;
20940Sstevel@tonic-gate 
20953095Sek110237 typedef struct kmastat_args {
20963095Sek110237 	kmastat_vmem_t **ka_kvpp;
20973095Sek110237 	uint_t ka_shift;
20983095Sek110237 } kmastat_args_t;
20993095Sek110237 
21000Sstevel@tonic-gate static int
21013095Sek110237 kmastat_cache(uintptr_t addr, const kmem_cache_t *cp, kmastat_args_t *kap)
21020Sstevel@tonic-gate {
21033095Sek110237 	kmastat_vmem_t **kvp = kap->ka_kvpp;
21040Sstevel@tonic-gate 	kmastat_vmem_t *kv;
21050Sstevel@tonic-gate 	datafmt_t *dfp = kmemfmt;
21060Sstevel@tonic-gate 	int magsize;
21070Sstevel@tonic-gate 
21080Sstevel@tonic-gate 	int avail, alloc, total;
21090Sstevel@tonic-gate 	size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) *
21100Sstevel@tonic-gate 	    cp->cache_slabsize;
21110Sstevel@tonic-gate 
21120Sstevel@tonic-gate 	mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)kmastat_cpu_avail;
21130Sstevel@tonic-gate 	mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)kmastat_cpu_alloc;
21140Sstevel@tonic-gate 	mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)kmastat_slab_avail;
21150Sstevel@tonic-gate 
21160Sstevel@tonic-gate 	magsize = kmem_get_magsize(cp);
21170Sstevel@tonic-gate 
21180Sstevel@tonic-gate 	alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc;
21190Sstevel@tonic-gate 	avail = cp->cache_full.ml_total * magsize;
21200Sstevel@tonic-gate 	total = cp->cache_buftotal;
21210Sstevel@tonic-gate 
21220Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_cpu_cache", cpu_alloc, &alloc, addr);
21230Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_cpu_cache", cpu_avail, &avail, addr);
21240Sstevel@tonic-gate 	(void) mdb_pwalk("kmem_slab_partial", slab_avail, &avail, addr);
21250Sstevel@tonic-gate 
21260Sstevel@tonic-gate 	for (kv = *kvp; kv != NULL; kv = kv->kv_next) {
21270Sstevel@tonic-gate 		if (kv->kv_addr == (uintptr_t)cp->cache_arena)
21280Sstevel@tonic-gate 			goto out;
21290Sstevel@tonic-gate 	}
21300Sstevel@tonic-gate 
21310Sstevel@tonic-gate 	kv = mdb_zalloc(sizeof (kmastat_vmem_t), UM_SLEEP | UM_GC);
21320Sstevel@tonic-gate 	kv->kv_next = *kvp;
21330Sstevel@tonic-gate 	kv->kv_addr = (uintptr_t)cp->cache_arena;
21340Sstevel@tonic-gate 	*kvp = kv;
21350Sstevel@tonic-gate out:
21360Sstevel@tonic-gate 	kv->kv_meminuse += meminuse;
21370Sstevel@tonic-gate 	kv->kv_alloc += alloc;
21380Sstevel@tonic-gate 	kv->kv_fail += cp->cache_alloc_fail;
21390Sstevel@tonic-gate 
21400Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_name);
21410Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_bufsize);
21420Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, total - avail);
21430Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, total);
21444808Sek110237 	mdb_printf((dfp++)->fmt, meminuse >> kap->ka_shift,
21454808Sek110237 	    kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' :
21464808Sek110237 	    kap->ka_shift == KILOS ? 'K' : 'B');
21470Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, alloc);
21480Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, cp->cache_alloc_fail);
21490Sstevel@tonic-gate 	mdb_printf("\n");
21500Sstevel@tonic-gate 
21510Sstevel@tonic-gate 	return (WALK_NEXT);
21520Sstevel@tonic-gate }
21530Sstevel@tonic-gate 
21540Sstevel@tonic-gate static int
21553095Sek110237 kmastat_vmem_totals(uintptr_t addr, const vmem_t *v, kmastat_args_t *kap)
21560Sstevel@tonic-gate {
21573095Sek110237 	kmastat_vmem_t *kv = *kap->ka_kvpp;
21580Sstevel@tonic-gate 	size_t len;
21590Sstevel@tonic-gate 
21600Sstevel@tonic-gate 	while (kv != NULL && kv->kv_addr != addr)
21610Sstevel@tonic-gate 		kv = kv->kv_next;
21620Sstevel@tonic-gate 
21630Sstevel@tonic-gate 	if (kv == NULL || kv->kv_alloc == 0)
21640Sstevel@tonic-gate 		return (WALK_NEXT);
21650Sstevel@tonic-gate 
21660Sstevel@tonic-gate 	len = MIN(17, strlen(v->vm_name));
21670Sstevel@tonic-gate 
21684808Sek110237 	mdb_printf("Total [%s]%*s %6s %6s %6s %9u%c %9u %5u\n", v->vm_name,
21690Sstevel@tonic-gate 	    17 - len, "", "", "", "",
21704808Sek110237 	    kv->kv_meminuse >> kap->ka_shift,
21714808Sek110237 	    kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' :
21724808Sek110237 	    kap->ka_shift == KILOS ? 'K' : 'B', kv->kv_alloc, kv->kv_fail);
21730Sstevel@tonic-gate 
21740Sstevel@tonic-gate 	return (WALK_NEXT);
21750Sstevel@tonic-gate }
21760Sstevel@tonic-gate 
21770Sstevel@tonic-gate /*ARGSUSED*/
21780Sstevel@tonic-gate static int
21793095Sek110237 kmastat_vmem(uintptr_t addr, const vmem_t *v, const uint_t *shiftp)
21800Sstevel@tonic-gate {
21810Sstevel@tonic-gate 	datafmt_t *dfp = vmemfmt;
21820Sstevel@tonic-gate 	const vmem_kstat_t *vkp = &v->vm_kstat;
21830Sstevel@tonic-gate 	uintptr_t paddr;
21840Sstevel@tonic-gate 	vmem_t parent;
21850Sstevel@tonic-gate 	int ident = 0;
21860Sstevel@tonic-gate 
21870Sstevel@tonic-gate 	for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) {
21880Sstevel@tonic-gate 		if (mdb_vread(&parent, sizeof (parent), paddr) == -1) {
21890Sstevel@tonic-gate 			mdb_warn("couldn't trace %p's ancestry", addr);
21900Sstevel@tonic-gate 			ident = 0;
21910Sstevel@tonic-gate 			break;
21920Sstevel@tonic-gate 		}
21930Sstevel@tonic-gate 		paddr = (uintptr_t)parent.vm_source;
21940Sstevel@tonic-gate 	}
21950Sstevel@tonic-gate 
21960Sstevel@tonic-gate 	mdb_printf("%*s", ident, "");
21970Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name);
21984808Sek110237 	mdb_printf((dfp++)->fmt, vkp->vk_mem_inuse.value.ui64 >> *shiftp,
21994808Sek110237 	    *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
22004808Sek110237 	    *shiftp == KILOS ? 'K' : 'B');
22014808Sek110237 	mdb_printf((dfp++)->fmt, vkp->vk_mem_total.value.ui64 >> *shiftp,
22024808Sek110237 	    *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
22034808Sek110237 	    *shiftp == KILOS ? 'K' : 'B');
22044808Sek110237 	mdb_printf((dfp++)->fmt, vkp->vk_mem_import.value.ui64 >> *shiftp,
22054808Sek110237 	    *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
22064808Sek110237 	    *shiftp == KILOS ? 'K' : 'B');
22070Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_alloc.value.ui64);
22080Sstevel@tonic-gate 	mdb_printf((dfp++)->fmt, vkp->vk_fail.value.ui64);
22090Sstevel@tonic-gate 
22100Sstevel@tonic-gate 	mdb_printf("\n");
22110Sstevel@tonic-gate 
22120Sstevel@tonic-gate 	return (WALK_NEXT);
22130Sstevel@tonic-gate }
22140Sstevel@tonic-gate 
22150Sstevel@tonic-gate /*ARGSUSED*/
22160Sstevel@tonic-gate int
22170Sstevel@tonic-gate kmastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
22180Sstevel@tonic-gate {
22190Sstevel@tonic-gate 	kmastat_vmem_t *kv = NULL;
22200Sstevel@tonic-gate 	datafmt_t *dfp;
22213095Sek110237 	kmastat_args_t ka;
22223095Sek110237 
22233095Sek110237 	ka.ka_shift = 0;
22243095Sek110237 	if (mdb_getopts(argc, argv,
22254808Sek110237 	    'k', MDB_OPT_SETBITS, KILOS, &ka.ka_shift,
22264808Sek110237 	    'm', MDB_OPT_SETBITS, MEGS, &ka.ka_shift,
22274808Sek110237 	    'g', MDB_OPT_SETBITS, GIGS, &ka.ka_shift, NULL) != argc)
22280Sstevel@tonic-gate 		return (DCMD_USAGE);
22290Sstevel@tonic-gate 
22300Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
22310Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr1);
22320Sstevel@tonic-gate 	mdb_printf("\n");
22330Sstevel@tonic-gate 
22340Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
22350Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr2);
22360Sstevel@tonic-gate 	mdb_printf("\n");
22370Sstevel@tonic-gate 
22380Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
22390Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
22400Sstevel@tonic-gate 	mdb_printf("\n");
22410Sstevel@tonic-gate 
22423095Sek110237 	ka.ka_kvpp = &kv;
22433095Sek110237 	if (mdb_walk("kmem_cache", (mdb_walk_cb_t)kmastat_cache, &ka) == -1) {
22440Sstevel@tonic-gate 		mdb_warn("can't walk 'kmem_cache'");
22450Sstevel@tonic-gate 		return (DCMD_ERR);
22460Sstevel@tonic-gate 	}
22470Sstevel@tonic-gate 
22480Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
22490Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
22500Sstevel@tonic-gate 	mdb_printf("\n");
22510Sstevel@tonic-gate 
22523095Sek110237 	if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem_totals, &ka) == -1) {
22530Sstevel@tonic-gate 		mdb_warn("can't walk 'vmem'");
22540Sstevel@tonic-gate 		return (DCMD_ERR);
22550Sstevel@tonic-gate 	}
22560Sstevel@tonic-gate 
22570Sstevel@tonic-gate 	for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
22580Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
22590Sstevel@tonic-gate 	mdb_printf("\n");
22600Sstevel@tonic-gate 
22610Sstevel@tonic-gate 	mdb_printf("\n");
22620Sstevel@tonic-gate 
22630Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
22640Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr1);
22650Sstevel@tonic-gate 	mdb_printf("\n");
22660Sstevel@tonic-gate 
22670Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
22680Sstevel@tonic-gate 		mdb_printf("%s ", dfp->hdr2);
22690Sstevel@tonic-gate 	mdb_printf("\n");
22700Sstevel@tonic-gate 
22710Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
22720Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
22730Sstevel@tonic-gate 	mdb_printf("\n");
22740Sstevel@tonic-gate 
22753095Sek110237 	if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem, &ka.ka_shift) == -1) {
22760Sstevel@tonic-gate 		mdb_warn("can't walk 'vmem'");
22770Sstevel@tonic-gate 		return (DCMD_ERR);
22780Sstevel@tonic-gate 	}
22790Sstevel@tonic-gate 
22800Sstevel@tonic-gate 	for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
22810Sstevel@tonic-gate 		mdb_printf("%s ", dfp->dashes);
22820Sstevel@tonic-gate 	mdb_printf("\n");
22830Sstevel@tonic-gate 	return (DCMD_OK);
22840Sstevel@tonic-gate }
22850Sstevel@tonic-gate 
22860Sstevel@tonic-gate /*
22870Sstevel@tonic-gate  * Our ::kgrep callback scans the entire kernel VA space (kas).  kas is made
22880Sstevel@tonic-gate  * up of a set of 'struct seg's.  We could just scan each seg en masse, but
22890Sstevel@tonic-gate  * unfortunately, a few of the segs are both large and sparse, so we could
22900Sstevel@tonic-gate  * spend quite a bit of time scanning VAs which have no backing pages.
22910Sstevel@tonic-gate  *
22920Sstevel@tonic-gate  * So for the few very sparse segs, we skip the segment itself, and scan
22930Sstevel@tonic-gate  * the allocated vmem_segs in the vmem arena which manages that part of kas.
22940Sstevel@tonic-gate  * Currently, we do this for:
22950Sstevel@tonic-gate  *
22960Sstevel@tonic-gate  *	SEG		VMEM ARENA
22970Sstevel@tonic-gate  *	kvseg		heap_arena
22980Sstevel@tonic-gate  *	kvseg32		heap32_arena
22990Sstevel@tonic-gate  *	kvseg_core	heap_core_arena
23000Sstevel@tonic-gate  *
23010Sstevel@tonic-gate  * In addition, we skip the segkpm segment in its entirety, since it is very
23020Sstevel@tonic-gate  * sparse, and contains no new kernel data.
23030Sstevel@tonic-gate  */
23040Sstevel@tonic-gate typedef struct kgrep_walk_data {
23050Sstevel@tonic-gate 	kgrep_cb_func *kg_cb;
23060Sstevel@tonic-gate 	void *kg_cbdata;
23070Sstevel@tonic-gate 	uintptr_t kg_kvseg;
23080Sstevel@tonic-gate 	uintptr_t kg_kvseg32;
23090Sstevel@tonic-gate 	uintptr_t kg_kvseg_core;
23100Sstevel@tonic-gate 	uintptr_t kg_segkpm;
23115Seg155566 	uintptr_t kg_heap_lp_base;
23125Seg155566 	uintptr_t kg_heap_lp_end;
23130Sstevel@tonic-gate } kgrep_walk_data_t;
23140Sstevel@tonic-gate 
23150Sstevel@tonic-gate static int
23160Sstevel@tonic-gate kgrep_walk_seg(uintptr_t addr, const struct seg *seg, kgrep_walk_data_t *kg)
23170Sstevel@tonic-gate {
23180Sstevel@tonic-gate 	uintptr_t base = (uintptr_t)seg->s_base;
23190Sstevel@tonic-gate 
23200Sstevel@tonic-gate 	if (addr == kg->kg_kvseg || addr == kg->kg_kvseg32 ||
23210Sstevel@tonic-gate 	    addr == kg->kg_kvseg_core)
23220Sstevel@tonic-gate 		return (WALK_NEXT);
23230Sstevel@tonic-gate 
23240Sstevel@tonic-gate 	if ((uintptr_t)seg->s_ops == kg->kg_segkpm)
23250Sstevel@tonic-gate 		return (WALK_NEXT);
23260Sstevel@tonic-gate 
23270Sstevel@tonic-gate 	return (kg->kg_cb(base, base + seg->s_size, kg->kg_cbdata));
23280Sstevel@tonic-gate }
23290Sstevel@tonic-gate 
23300Sstevel@tonic-gate /*ARGSUSED*/
23310Sstevel@tonic-gate static int
23320Sstevel@tonic-gate kgrep_walk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
23330Sstevel@tonic-gate {
23345Seg155566 	/*
23355Seg155566 	 * skip large page heap address range - it is scanned by walking
23365Seg155566 	 * allocated vmem_segs in the heap_lp_arena
23375Seg155566 	 */
23385Seg155566 	if (seg->vs_start == kg->kg_heap_lp_base &&
23395Seg155566 	    seg->vs_end == kg->kg_heap_lp_end)
23405Seg155566 		return (WALK_NEXT);
23415Seg155566 
23425Seg155566 	return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
23435Seg155566 }
23445Seg155566 
23455Seg155566 /*ARGSUSED*/
23465Seg155566 static int
23475Seg155566 kgrep_xwalk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
23485Seg155566 {
23490Sstevel@tonic-gate 	return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
23500Sstevel@tonic-gate }
23510Sstevel@tonic-gate 
23520Sstevel@tonic-gate static int
23530Sstevel@tonic-gate kgrep_walk_vmem(uintptr_t addr, const vmem_t *vmem, kgrep_walk_data_t *kg)
23540Sstevel@tonic-gate {
23555Seg155566 	mdb_walk_cb_t walk_vseg = (mdb_walk_cb_t)kgrep_walk_vseg;
23565Seg155566 
23570Sstevel@tonic-gate 	if (strcmp(vmem->vm_name, "heap") != 0 &&
23580Sstevel@tonic-gate 	    strcmp(vmem->vm_name, "heap32") != 0 &&
23595Seg155566 	    strcmp(vmem->vm_name, "heap_core") != 0 &&
23605Seg155566 	    strcmp(vmem->vm_name, "heap_lp") != 0)
23610Sstevel@tonic-gate 		return (WALK_NEXT);
23620Sstevel@tonic-gate 
23635Seg155566 	if (strcmp(vmem->vm_name, "heap_lp") == 0)
23645Seg155566 		walk_vseg = (mdb_walk_cb_t)kgrep_xwalk_vseg;
23655Seg155566 
23665Seg155566 	if (mdb_pwalk("vmem_alloc", walk_vseg, kg, addr) == -1) {
23670Sstevel@tonic-gate 		mdb_warn("couldn't walk vmem_alloc for vmem %p", addr);
23680Sstevel@tonic-gate 		return (WALK_ERR);
23690Sstevel@tonic-gate 	}
23700Sstevel@tonic-gate 
23710Sstevel@tonic-gate 	return (WALK_NEXT);
23720Sstevel@tonic-gate }
23730Sstevel@tonic-gate 
23740Sstevel@tonic-gate int
23750Sstevel@tonic-gate kgrep_subr(kgrep_cb_func *cb, void *cbdata)
23760Sstevel@tonic-gate {
23770Sstevel@tonic-gate 	GElf_Sym kas, kvseg, kvseg32, kvseg_core, segkpm;
23780Sstevel@tonic-gate 	kgrep_walk_data_t kg;
23790Sstevel@tonic-gate 
23800Sstevel@tonic-gate 	if (mdb_get_state() == MDB_STATE_RUNNING) {
23810Sstevel@tonic-gate 		mdb_warn("kgrep can only be run on a system "
23820Sstevel@tonic-gate 		    "dump or under kmdb; see dumpadm(1M)\n");
23830Sstevel@tonic-gate 		return (DCMD_ERR);
23840Sstevel@tonic-gate 	}
23850Sstevel@tonic-gate 
23860Sstevel@tonic-gate 	if (mdb_lookup_by_name("kas", &kas) == -1) {
23870Sstevel@tonic-gate 		mdb_warn("failed to locate 'kas' symbol\n");
23880Sstevel@tonic-gate 		return (DCMD_ERR);
23890Sstevel@tonic-gate 	}
23900Sstevel@tonic-gate 
23910Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg", &kvseg) == -1) {
23920Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg' symbol\n");
23930Sstevel@tonic-gate 		return (DCMD_ERR);
23940Sstevel@tonic-gate 	}
23950Sstevel@tonic-gate 
23960Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg32", &kvseg32) == -1) {
23970Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg32' symbol\n");
23980Sstevel@tonic-gate 		return (DCMD_ERR);
23990Sstevel@tonic-gate 	}
24000Sstevel@tonic-gate 
24010Sstevel@tonic-gate 	if (mdb_lookup_by_name("kvseg_core", &kvseg_core) == -1) {
24020Sstevel@tonic-gate 		mdb_warn("failed to locate 'kvseg_core' symbol\n");
24030Sstevel@tonic-gate 		return (DCMD_ERR);
24040Sstevel@tonic-gate 	}
24050Sstevel@tonic-gate 
24060Sstevel@tonic-gate 	if (mdb_lookup_by_name("segkpm_ops", &segkpm) == -1) {
24070Sstevel@tonic-gate 		mdb_warn("failed to locate 'segkpm_ops' symbol\n");
24080Sstevel@tonic-gate 		return (DCMD_ERR);
24090Sstevel@tonic-gate 	}
24100Sstevel@tonic-gate 
24115Seg155566 	if (mdb_readvar(&kg.kg_heap_lp_base, "heap_lp_base") == -1) {
24125Seg155566 		mdb_warn("failed to read 'heap_lp_base'\n");
24135Seg155566 		return (DCMD_ERR);
24145Seg155566 	}
24155Seg155566 
24165Seg155566 	if (mdb_readvar(&kg.kg_heap_lp_end, "heap_lp_end") == -1) {
24175Seg155566 		mdb_warn("failed to read 'heap_lp_end'\n");
24185Seg155566 		return (DCMD_ERR);
24195Seg155566 	}
24205Seg155566 
24210Sstevel@tonic-gate 	kg.kg_cb = cb;
24220Sstevel@tonic-gate 	kg.kg_cbdata = cbdata;
24230Sstevel@tonic-gate 	kg.kg_kvseg = (uintptr_t)kvseg.st_value;
24240Sstevel@tonic-gate 	kg.kg_kvseg32 = (uintptr_t)kvseg32.st_value;
24250Sstevel@tonic-gate 	kg.kg_kvseg_core = (uintptr_t)kvseg_core.st_value;
24260Sstevel@tonic-gate 	kg.kg_segkpm = (uintptr_t)segkpm.st_value;
24270Sstevel@tonic-gate 
24280Sstevel@tonic-gate 	if (mdb_pwalk("seg", (mdb_walk_cb_t)kgrep_walk_seg,
24290Sstevel@tonic-gate 	    &kg, kas.st_value) == -1) {
24300Sstevel@tonic-gate 		mdb_warn("failed to walk kas segments");
24310Sstevel@tonic-gate 		return (DCMD_ERR);
24320Sstevel@tonic-gate 	}
24330Sstevel@tonic-gate 
24340Sstevel@tonic-gate 	if (mdb_walk("vmem", (mdb_walk_cb_t)kgrep_walk_vmem, &kg) == -1) {
24350Sstevel@tonic-gate 		mdb_warn("failed to walk heap/heap32 vmem arenas");
24360Sstevel@tonic-gate 		return (DCMD_ERR);
24370Sstevel@tonic-gate 	}
24380Sstevel@tonic-gate 
24390Sstevel@tonic-gate 	return (DCMD_OK);
24400Sstevel@tonic-gate }
24410Sstevel@tonic-gate 
24420Sstevel@tonic-gate size_t
24430Sstevel@tonic-gate kgrep_subr_pagesize(void)
24440Sstevel@tonic-gate {
24450Sstevel@tonic-gate 	return (PAGESIZE);
24460Sstevel@tonic-gate }
24470Sstevel@tonic-gate 
24480Sstevel@tonic-gate typedef struct file_walk_data {
24490Sstevel@tonic-gate 	struct uf_entry *fw_flist;
24500Sstevel@tonic-gate 	int fw_flistsz;
24510Sstevel@tonic-gate 	int fw_ndx;
24520Sstevel@tonic-gate 	int fw_nofiles;
24530Sstevel@tonic-gate } file_walk_data_t;
24540Sstevel@tonic-gate 
24550Sstevel@tonic-gate int
24560Sstevel@tonic-gate file_walk_init(mdb_walk_state_t *wsp)
24570Sstevel@tonic-gate {
24580Sstevel@tonic-gate 	file_walk_data_t *fw;
24590Sstevel@tonic-gate 	proc_t p;
24600Sstevel@tonic-gate 
24610Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
24620Sstevel@tonic-gate 		mdb_warn("file walk doesn't support global walks\n");
24630Sstevel@tonic-gate 		return (WALK_ERR);
24640Sstevel@tonic-gate 	}
24650Sstevel@tonic-gate 
24660Sstevel@tonic-gate 	fw = mdb_alloc(sizeof (file_walk_data_t), UM_SLEEP);
24670Sstevel@tonic-gate 
24680Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (p), wsp->walk_addr) == -1) {
24690Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
24700Sstevel@tonic-gate 		mdb_warn("failed to read proc structure at %p", wsp->walk_addr);
24710Sstevel@tonic-gate 		return (WALK_ERR);
24720Sstevel@tonic-gate 	}
24730Sstevel@tonic-gate 
24740Sstevel@tonic-gate 	if (p.p_user.u_finfo.fi_nfiles == 0) {
24750Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
24760Sstevel@tonic-gate 		return (WALK_DONE);
24770Sstevel@tonic-gate 	}
24780Sstevel@tonic-gate 
24790Sstevel@tonic-gate 	fw->fw_nofiles = p.p_user.u_finfo.fi_nfiles;
24800Sstevel@tonic-gate 	fw->fw_flistsz = sizeof (struct uf_entry) * fw->fw_nofiles;
24810Sstevel@tonic-gate 	fw->fw_flist = mdb_alloc(fw->fw_flistsz, UM_SLEEP);
24820Sstevel@tonic-gate 
24830Sstevel@tonic-gate 	if (mdb_vread(fw->fw_flist, fw->fw_flistsz,
24840Sstevel@tonic-gate 	    (uintptr_t)p.p_user.u_finfo.fi_list) == -1) {
24850Sstevel@tonic-gate 		mdb_warn("failed to read file array at %p",
24860Sstevel@tonic-gate 		    p.p_user.u_finfo.fi_list);
24870Sstevel@tonic-gate 		mdb_free(fw->fw_flist, fw->fw_flistsz);
24880Sstevel@tonic-gate 		mdb_free(fw, sizeof (file_walk_data_t));
24890Sstevel@tonic-gate 		return (WALK_ERR);
24900Sstevel@tonic-gate 	}
24910Sstevel@tonic-gate 
24920Sstevel@tonic-gate 	fw->fw_ndx = 0;
24930Sstevel@tonic-gate 	wsp->walk_data = fw;
24940Sstevel@tonic-gate 
24950Sstevel@tonic-gate 	return (WALK_NEXT);
24960Sstevel@tonic-gate }
24970Sstevel@tonic-gate 
24980Sstevel@tonic-gate int
24990Sstevel@tonic-gate file_walk_step(mdb_walk_state_t *wsp)
25000Sstevel@tonic-gate {
25010Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
25020Sstevel@tonic-gate 	struct file file;
25030Sstevel@tonic-gate 	uintptr_t fp;
25040Sstevel@tonic-gate 
25050Sstevel@tonic-gate again:
25060Sstevel@tonic-gate 	if (fw->fw_ndx == fw->fw_nofiles)
25070Sstevel@tonic-gate 		return (WALK_DONE);
25080Sstevel@tonic-gate 
25090Sstevel@tonic-gate 	if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) == NULL)
25100Sstevel@tonic-gate 		goto again;
25110Sstevel@tonic-gate 
25120Sstevel@tonic-gate 	(void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
25130Sstevel@tonic-gate 	return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
25140Sstevel@tonic-gate }
25150Sstevel@tonic-gate 
25160Sstevel@tonic-gate int
25170Sstevel@tonic-gate allfile_walk_step(mdb_walk_state_t *wsp)
25180Sstevel@tonic-gate {
25190Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
25200Sstevel@tonic-gate 	struct file file;
25210Sstevel@tonic-gate 	uintptr_t fp;
25220Sstevel@tonic-gate 
25230Sstevel@tonic-gate 	if (fw->fw_ndx == fw->fw_nofiles)
25240Sstevel@tonic-gate 		return (WALK_DONE);
25250Sstevel@tonic-gate 
25260Sstevel@tonic-gate 	if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) != NULL)
25270Sstevel@tonic-gate 		(void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
25280Sstevel@tonic-gate 	else
25290Sstevel@tonic-gate 		bzero(&file, sizeof (file));
25300Sstevel@tonic-gate 
25310Sstevel@tonic-gate 	return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
25320Sstevel@tonic-gate }
25330Sstevel@tonic-gate 
25340Sstevel@tonic-gate void
25350Sstevel@tonic-gate file_walk_fini(mdb_walk_state_t *wsp)
25360Sstevel@tonic-gate {
25370Sstevel@tonic-gate 	file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
25380Sstevel@tonic-gate 
25390Sstevel@tonic-gate 	mdb_free(fw->fw_flist, fw->fw_flistsz);
25400Sstevel@tonic-gate 	mdb_free(fw, sizeof (file_walk_data_t));
25410Sstevel@tonic-gate }
25420Sstevel@tonic-gate 
25430Sstevel@tonic-gate int
25440Sstevel@tonic-gate port_walk_init(mdb_walk_state_t *wsp)
25450Sstevel@tonic-gate {
25460Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
25470Sstevel@tonic-gate 		mdb_warn("port walk doesn't support global walks\n");
25480Sstevel@tonic-gate 		return (WALK_ERR);
25490Sstevel@tonic-gate 	}
25500Sstevel@tonic-gate 
25510Sstevel@tonic-gate 	if (mdb_layered_walk("file", wsp) == -1) {
25520Sstevel@tonic-gate 		mdb_warn("couldn't walk 'file'");
25530Sstevel@tonic-gate 		return (WALK_ERR);
25540Sstevel@tonic-gate 	}
25550Sstevel@tonic-gate 	return (WALK_NEXT);
25560Sstevel@tonic-gate }
25570Sstevel@tonic-gate 
25580Sstevel@tonic-gate int
25590Sstevel@tonic-gate port_walk_step(mdb_walk_state_t *wsp)
25600Sstevel@tonic-gate {
25610Sstevel@tonic-gate 	struct vnode	vn;
25620Sstevel@tonic-gate 	uintptr_t	vp;
25630Sstevel@tonic-gate 	uintptr_t	pp;
25640Sstevel@tonic-gate 	struct port	port;
25650Sstevel@tonic-gate 
25660Sstevel@tonic-gate 	vp = (uintptr_t)((struct file *)wsp->walk_layer)->f_vnode;
25670Sstevel@tonic-gate 	if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
25680Sstevel@tonic-gate 		mdb_warn("failed to read vnode_t at %p", vp);
25690Sstevel@tonic-gate 		return (WALK_ERR);
25700Sstevel@tonic-gate 	}
25710Sstevel@tonic-gate 	if (vn.v_type != VPORT)
25720Sstevel@tonic-gate 		return (WALK_NEXT);
25730Sstevel@tonic-gate 
25740Sstevel@tonic-gate 	pp = (uintptr_t)vn.v_data;
25750Sstevel@tonic-gate 	if (mdb_vread(&port, sizeof (port), pp) == -1) {
25760Sstevel@tonic-gate 		mdb_warn("failed to read port_t at %p", pp);
25770Sstevel@tonic-gate 		return (WALK_ERR);
25780Sstevel@tonic-gate 	}
25790Sstevel@tonic-gate 	return (wsp->walk_callback(pp, &port, wsp->walk_cbdata));
25800Sstevel@tonic-gate }
25810Sstevel@tonic-gate 
25820Sstevel@tonic-gate typedef struct portev_walk_data {
25830Sstevel@tonic-gate 	list_node_t	*pev_node;
25840Sstevel@tonic-gate 	list_node_t	*pev_last;
25850Sstevel@tonic-gate 	size_t		pev_offset;
25860Sstevel@tonic-gate } portev_walk_data_t;
25870Sstevel@tonic-gate 
25880Sstevel@tonic-gate int
25890Sstevel@tonic-gate portev_walk_init(mdb_walk_state_t *wsp)
25900Sstevel@tonic-gate {
25910Sstevel@tonic-gate 	portev_walk_data_t *pevd;
25920Sstevel@tonic-gate 	struct port	port;
25930Sstevel@tonic-gate 	struct vnode	vn;
25940Sstevel@tonic-gate 	struct list	*list;
25950Sstevel@tonic-gate 	uintptr_t	vp;
25960Sstevel@tonic-gate 
25970Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
25980Sstevel@tonic-gate 		mdb_warn("portev walk doesn't support global walks\n");
25990Sstevel@tonic-gate 		return (WALK_ERR);
26000Sstevel@tonic-gate 	}
26010Sstevel@tonic-gate 
26020Sstevel@tonic-gate 	pevd = mdb_alloc(sizeof (portev_walk_data_t), UM_SLEEP);
26030Sstevel@tonic-gate 
26040Sstevel@tonic-gate 	if (mdb_vread(&port, sizeof (port), wsp->walk_addr) == -1) {
26050Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
26060Sstevel@tonic-gate 		mdb_warn("failed to read port structure at %p", wsp->walk_addr);
26070Sstevel@tonic-gate 		return (WALK_ERR);
26080Sstevel@tonic-gate 	}
26090Sstevel@tonic-gate 
26100Sstevel@tonic-gate 	vp = (uintptr_t)port.port_vnode;
26110Sstevel@tonic-gate 	if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
26120Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
26130Sstevel@tonic-gate 		mdb_warn("failed to read vnode_t at %p", vp);
26140Sstevel@tonic-gate 		return (WALK_ERR);
26150Sstevel@tonic-gate 	}
26160Sstevel@tonic-gate 
26170Sstevel@tonic-gate 	if (vn.v_type != VPORT) {
26180Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
26190Sstevel@tonic-gate 		mdb_warn("input address (%p) does not point to an event port",
26200Sstevel@tonic-gate 		    wsp->walk_addr);
26210Sstevel@tonic-gate 		return (WALK_ERR);
26220Sstevel@tonic-gate 	}
26230Sstevel@tonic-gate 
26240Sstevel@tonic-gate 	if (port.port_queue.portq_nent == 0) {
26250Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
26260Sstevel@tonic-gate 		return (WALK_DONE);
26270Sstevel@tonic-gate 	}
26280Sstevel@tonic-gate 	list = &port.port_queue.portq_list;
26290Sstevel@tonic-gate 	pevd->pev_offset = list->list_offset;
26300Sstevel@tonic-gate 	pevd->pev_last = list->list_head.list_prev;
26310Sstevel@tonic-gate 	pevd->pev_node = list->list_head.list_next;
26320Sstevel@tonic-gate 	wsp->walk_data = pevd;
26330Sstevel@tonic-gate 	return (WALK_NEXT);
26340Sstevel@tonic-gate }
26350Sstevel@tonic-gate 
26360Sstevel@tonic-gate int
26370Sstevel@tonic-gate portev_walk_step(mdb_walk_state_t *wsp)
26380Sstevel@tonic-gate {
26390Sstevel@tonic-gate 	portev_walk_data_t	*pevd;
26400Sstevel@tonic-gate 	struct port_kevent	ev;
26410Sstevel@tonic-gate 	uintptr_t		evp;
26420Sstevel@tonic-gate 
26430Sstevel@tonic-gate 	pevd = (portev_walk_data_t *)wsp->walk_data;
26440Sstevel@tonic-gate 
26450Sstevel@tonic-gate 	if (pevd->pev_last == NULL)
26460Sstevel@tonic-gate 		return (WALK_DONE);
26470Sstevel@tonic-gate 	if (pevd->pev_node == pevd->pev_last)
26480Sstevel@tonic-gate 		pevd->pev_last = NULL;		/* last round */
26490Sstevel@tonic-gate 
26500Sstevel@tonic-gate 	evp = ((uintptr_t)(((char *)pevd->pev_node) - pevd->pev_offset));
26510Sstevel@tonic-gate 	if (mdb_vread(&ev, sizeof (ev), evp) == -1) {
26520Sstevel@tonic-gate 		mdb_warn("failed to read port_kevent at %p", evp);
26530Sstevel@tonic-gate 		return (WALK_DONE);
26540Sstevel@tonic-gate 	}
26550Sstevel@tonic-gate 	pevd->pev_node = ev.portkev_node.list_next;
26560Sstevel@tonic-gate 	return (wsp->walk_callback(evp, &ev, wsp->walk_cbdata));
26570Sstevel@tonic-gate }
26580Sstevel@tonic-gate 
26590Sstevel@tonic-gate void
26600Sstevel@tonic-gate portev_walk_fini(mdb_walk_state_t *wsp)
26610Sstevel@tonic-gate {
26620Sstevel@tonic-gate 	portev_walk_data_t *pevd = (portev_walk_data_t *)wsp->walk_data;
26630Sstevel@tonic-gate 
26640Sstevel@tonic-gate 	if (pevd != NULL)
26650Sstevel@tonic-gate 		mdb_free(pevd, sizeof (portev_walk_data_t));
26660Sstevel@tonic-gate }
26670Sstevel@tonic-gate 
26680Sstevel@tonic-gate typedef struct proc_walk_data {
26690Sstevel@tonic-gate 	uintptr_t *pw_stack;
26700Sstevel@tonic-gate 	int pw_depth;
26710Sstevel@tonic-gate 	int pw_max;
26720Sstevel@tonic-gate } proc_walk_data_t;
26730Sstevel@tonic-gate 
26740Sstevel@tonic-gate int
26750Sstevel@tonic-gate proc_walk_init(mdb_walk_state_t *wsp)
26760Sstevel@tonic-gate {
26770Sstevel@tonic-gate 	GElf_Sym sym;
26780Sstevel@tonic-gate 	proc_walk_data_t *pw;
26790Sstevel@tonic-gate 
26800Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
26810Sstevel@tonic-gate 		if (mdb_lookup_by_name("p0", &sym) == -1) {
26820Sstevel@tonic-gate 			mdb_warn("failed to read 'practive'");
26830Sstevel@tonic-gate 			return (WALK_ERR);
26840Sstevel@tonic-gate 		}
26850Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)sym.st_value;
26860Sstevel@tonic-gate 	}
26870Sstevel@tonic-gate 
26880Sstevel@tonic-gate 	pw = mdb_zalloc(sizeof (proc_walk_data_t), UM_SLEEP);
26890Sstevel@tonic-gate 
26900Sstevel@tonic-gate 	if (mdb_readvar(&pw->pw_max, "nproc") == -1) {
26910Sstevel@tonic-gate 		mdb_warn("failed to read 'nproc'");
26920Sstevel@tonic-gate 		mdb_free(pw, sizeof (pw));
26930Sstevel@tonic-gate 		return (WALK_ERR);
26940Sstevel@tonic-gate 	}
26950Sstevel@tonic-gate 
26960Sstevel@tonic-gate 	pw->pw_stack = mdb_alloc(pw->pw_max * sizeof (uintptr_t), UM_SLEEP);
26970Sstevel@tonic-gate 	wsp->walk_data = pw;
26980Sstevel@tonic-gate 
26990Sstevel@tonic-gate 	return (WALK_NEXT);
27000Sstevel@tonic-gate }
27010Sstevel@tonic-gate 
27020Sstevel@tonic-gate int
27030Sstevel@tonic-gate proc_walk_step(mdb_walk_state_t *wsp)
27040Sstevel@tonic-gate {
27050Sstevel@tonic-gate 	proc_walk_data_t *pw = wsp->walk_data;
27060Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
27070Sstevel@tonic-gate 	uintptr_t cld, sib;
27080Sstevel@tonic-gate 
27090Sstevel@tonic-gate 	int status;
27100Sstevel@tonic-gate 	proc_t pr;
27110Sstevel@tonic-gate 
27120Sstevel@tonic-gate 	if (mdb_vread(&pr, sizeof (proc_t), addr) == -1) {
27130Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", addr);
27140Sstevel@tonic-gate 		return (WALK_DONE);
27150Sstevel@tonic-gate 	}
27160Sstevel@tonic-gate 
27170Sstevel@tonic-gate 	cld = (uintptr_t)pr.p_child;
27180Sstevel@tonic-gate 	sib = (uintptr_t)pr.p_sibling;
27190Sstevel@tonic-gate 
27200Sstevel@tonic-gate 	if (pw->pw_depth > 0 && addr == pw->pw_stack[pw->pw_depth - 1]) {
27210Sstevel@tonic-gate 		pw->pw_depth--;
27220Sstevel@tonic-gate 		goto sib;
27230Sstevel@tonic-gate 	}
27240Sstevel@tonic-gate 
27250Sstevel@tonic-gate 	status = wsp->walk_callback(addr, &pr, wsp->walk_cbdata);
27260Sstevel@tonic-gate 
27270Sstevel@tonic-gate 	if (status != WALK_NEXT)
27280Sstevel@tonic-gate 		return (status);
27290Sstevel@tonic-gate 
27300Sstevel@tonic-gate 	if ((wsp->walk_addr = cld) != NULL) {
27310Sstevel@tonic-gate 		if (mdb_vread(&pr, sizeof (proc_t), cld) == -1) {
27320Sstevel@tonic-gate 			mdb_warn("proc %p has invalid p_child %p; skipping\n",
27330Sstevel@tonic-gate 			    addr, cld);
27340Sstevel@tonic-gate 			goto sib;
27350Sstevel@tonic-gate 		}
27360Sstevel@tonic-gate 
27370Sstevel@tonic-gate 		pw->pw_stack[pw->pw_depth++] = addr;
27380Sstevel@tonic-gate 
27390Sstevel@tonic-gate 		if (pw->pw_depth == pw->pw_max) {
27400Sstevel@tonic-gate 			mdb_warn("depth %d exceeds max depth; try again\n",
27410Sstevel@tonic-gate 			    pw->pw_depth);
27420Sstevel@tonic-gate 			return (WALK_DONE);
27430Sstevel@tonic-gate 		}
27440Sstevel@tonic-gate 		return (WALK_NEXT);
27450Sstevel@tonic-gate 	}
27460Sstevel@tonic-gate 
27470Sstevel@tonic-gate sib:
27480Sstevel@tonic-gate 	/*
27490Sstevel@tonic-gate 	 * We know that p0 has no siblings, and if another starting proc
27500Sstevel@tonic-gate 	 * was given, we don't want to walk its siblings anyway.
27510Sstevel@tonic-gate 	 */
27520Sstevel@tonic-gate 	if (pw->pw_depth == 0)
27530Sstevel@tonic-gate 		return (WALK_DONE);
27540Sstevel@tonic-gate 
27550Sstevel@tonic-gate 	if (sib != NULL && mdb_vread(&pr, sizeof (proc_t), sib) == -1) {
27560Sstevel@tonic-gate 		mdb_warn("proc %p has invalid p_sibling %p; skipping\n",
27570Sstevel@tonic-gate 		    addr, sib);
27580Sstevel@tonic-gate 		sib = NULL;
27590Sstevel@tonic-gate 	}
27600Sstevel@tonic-gate 
27610Sstevel@tonic-gate 	if ((wsp->walk_addr = sib) == NULL) {
27620Sstevel@tonic-gate 		if (pw->pw_depth > 0) {
27630Sstevel@tonic-gate 			wsp->walk_addr = pw->pw_stack[pw->pw_depth - 1];
27640Sstevel@tonic-gate 			return (WALK_NEXT);
27650Sstevel@tonic-gate 		}
27660Sstevel@tonic-gate 		return (WALK_DONE);
27670Sstevel@tonic-gate 	}
27680Sstevel@tonic-gate 
27690Sstevel@tonic-gate 	return (WALK_NEXT);
27700Sstevel@tonic-gate }
27710Sstevel@tonic-gate 
27720Sstevel@tonic-gate void
27730Sstevel@tonic-gate proc_walk_fini(mdb_walk_state_t *wsp)
27740Sstevel@tonic-gate {
27750Sstevel@tonic-gate 	proc_walk_data_t *pw = wsp->walk_data;
27760Sstevel@tonic-gate 
27770Sstevel@tonic-gate 	mdb_free(pw->pw_stack, pw->pw_max * sizeof (uintptr_t));
27780Sstevel@tonic-gate 	mdb_free(pw, sizeof (proc_walk_data_t));
27790Sstevel@tonic-gate }
27800Sstevel@tonic-gate 
27810Sstevel@tonic-gate int
27820Sstevel@tonic-gate task_walk_init(mdb_walk_state_t *wsp)
27830Sstevel@tonic-gate {
27840Sstevel@tonic-gate 	task_t task;
27850Sstevel@tonic-gate 
27860Sstevel@tonic-gate 	if (mdb_vread(&task, sizeof (task_t), wsp->walk_addr) == -1) {
27870Sstevel@tonic-gate 		mdb_warn("failed to read task at %p", wsp->walk_addr);
27880Sstevel@tonic-gate 		return (WALK_ERR);
27890Sstevel@tonic-gate 	}
27900Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)task.tk_memb_list;
27910Sstevel@tonic-gate 	wsp->walk_data = task.tk_memb_list;
27920Sstevel@tonic-gate 	return (WALK_NEXT);
27930Sstevel@tonic-gate }
27940Sstevel@tonic-gate 
27950Sstevel@tonic-gate int
27960Sstevel@tonic-gate task_walk_step(mdb_walk_state_t *wsp)
27970Sstevel@tonic-gate {
27980Sstevel@tonic-gate 	proc_t proc;
27990Sstevel@tonic-gate 	int status;
28000Sstevel@tonic-gate 
28010Sstevel@tonic-gate 	if (mdb_vread(&proc, sizeof (proc_t), wsp->walk_addr) == -1) {
28020Sstevel@tonic-gate 		mdb_warn("failed to read proc at %p", wsp->walk_addr);
28030Sstevel@tonic-gate 		return (WALK_DONE);
28040Sstevel@tonic-gate 	}
28050Sstevel@tonic-gate 
28060Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata);
28070Sstevel@tonic-gate 
28080Sstevel@tonic-gate 	if (proc.p_tasknext == wsp->walk_data)
28090Sstevel@tonic-gate 		return (WALK_DONE);
28100Sstevel@tonic-gate 
28110Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)proc.p_tasknext;
28120Sstevel@tonic-gate 	return (status);
28130Sstevel@tonic-gate }
28140Sstevel@tonic-gate 
28150Sstevel@tonic-gate int
28160Sstevel@tonic-gate project_walk_init(mdb_walk_state_t *wsp)
28170Sstevel@tonic-gate {
28180Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
28190Sstevel@tonic-gate 		if (mdb_readvar(&wsp->walk_addr, "proj0p") == -1) {
28200Sstevel@tonic-gate 			mdb_warn("failed to read 'proj0p'");
28210Sstevel@tonic-gate 			return (WALK_ERR);
28220Sstevel@tonic-gate 		}
28230Sstevel@tonic-gate 	}
28240Sstevel@tonic-gate 	wsp->walk_data = (void *)wsp->walk_addr;
28250Sstevel@tonic-gate 	return (WALK_NEXT);
28260Sstevel@tonic-gate }
28270Sstevel@tonic-gate 
28280Sstevel@tonic-gate int
28290Sstevel@tonic-gate project_walk_step(mdb_walk_state_t *wsp)
28300Sstevel@tonic-gate {
28310Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
28320Sstevel@tonic-gate 	kproject_t pj;
28330Sstevel@tonic-gate 	int status;
28340Sstevel@tonic-gate 
28350Sstevel@tonic-gate 	if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
28360Sstevel@tonic-gate 		mdb_warn("failed to read project at %p", addr);
28370Sstevel@tonic-gate 		return (WALK_DONE);
28380Sstevel@tonic-gate 	}
28390Sstevel@tonic-gate 	status = wsp->walk_callback(addr, &pj, wsp->walk_cbdata);
28400Sstevel@tonic-gate 	if (status != WALK_NEXT)
28410Sstevel@tonic-gate 		return (status);
28420Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)pj.kpj_next;
28430Sstevel@tonic-gate 	if ((void *)wsp->walk_addr == wsp->walk_data)
28440Sstevel@tonic-gate 		return (WALK_DONE);
28450Sstevel@tonic-gate 	return (WALK_NEXT);
28460Sstevel@tonic-gate }
28470Sstevel@tonic-gate 
28480Sstevel@tonic-gate static int
28490Sstevel@tonic-gate generic_walk_step(mdb_walk_state_t *wsp)
28500Sstevel@tonic-gate {
28510Sstevel@tonic-gate 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
28520Sstevel@tonic-gate 	    wsp->walk_cbdata));
28530Sstevel@tonic-gate }
28540Sstevel@tonic-gate 
28550Sstevel@tonic-gate int
28560Sstevel@tonic-gate seg_walk_init(mdb_walk_state_t *wsp)
28570Sstevel@tonic-gate {
28580Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
28590Sstevel@tonic-gate 		mdb_warn("seg walk must begin at struct as *\n");
28600Sstevel@tonic-gate 		return (WALK_ERR);
28610Sstevel@tonic-gate 	}
28620Sstevel@tonic-gate 
28630Sstevel@tonic-gate 	/*
28640Sstevel@tonic-gate 	 * this is really just a wrapper to AVL tree walk
28650Sstevel@tonic-gate 	 */
28660Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)&((struct as *)wsp->walk_addr)->a_segtree;
28670Sstevel@tonic-gate 	return (avl_walk_init(wsp));
28680Sstevel@tonic-gate }
28690Sstevel@tonic-gate 
28700Sstevel@tonic-gate static int
28710Sstevel@tonic-gate cpu_walk_cmp(const void *l, const void *r)
28720Sstevel@tonic-gate {
28730Sstevel@tonic-gate 	uintptr_t lhs = *((uintptr_t *)l);
28740Sstevel@tonic-gate 	uintptr_t rhs = *((uintptr_t *)r);
28750Sstevel@tonic-gate 	cpu_t lcpu, rcpu;
28760Sstevel@tonic-gate 
28770Sstevel@tonic-gate 	(void) mdb_vread(&lcpu, sizeof (lcpu), lhs);
28780Sstevel@tonic-gate 	(void) mdb_vread(&rcpu, sizeof (rcpu), rhs);
28790Sstevel@tonic-gate 
28800Sstevel@tonic-gate 	if (lcpu.cpu_id < rcpu.cpu_id)
28810Sstevel@tonic-gate 		return (-1);
28820Sstevel@tonic-gate 
28830Sstevel@tonic-gate 	if (lcpu.cpu_id > rcpu.cpu_id)
28840Sstevel@tonic-gate 		return (1);
28850Sstevel@tonic-gate 
28860Sstevel@tonic-gate 	return (0);
28870Sstevel@tonic-gate }
28880Sstevel@tonic-gate 
28890Sstevel@tonic-gate typedef struct cpu_walk {
28900Sstevel@tonic-gate 	uintptr_t *cw_array;
28910Sstevel@tonic-gate 	int cw_ndx;
28920Sstevel@tonic-gate } cpu_walk_t;
28930Sstevel@tonic-gate 
28940Sstevel@tonic-gate int
28950Sstevel@tonic-gate cpu_walk_init(mdb_walk_state_t *wsp)
28960Sstevel@tonic-gate {
28970Sstevel@tonic-gate 	cpu_walk_t *cw;
28980Sstevel@tonic-gate 	int max_ncpus, i = 0;
28990Sstevel@tonic-gate 	uintptr_t current, first;
29000Sstevel@tonic-gate 	cpu_t cpu, panic_cpu;
29010Sstevel@tonic-gate 	uintptr_t panicstr, addr;
29020Sstevel@tonic-gate 	GElf_Sym sym;
29030Sstevel@tonic-gate 
29040Sstevel@tonic-gate 	cw = mdb_zalloc(sizeof (cpu_walk_t), UM_SLEEP | UM_GC);
29050Sstevel@tonic-gate 
29060Sstevel@tonic-gate 	if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
29070Sstevel@tonic-gate 		mdb_warn("failed to read 'max_ncpus'");
29080Sstevel@tonic-gate 		return (WALK_ERR);
29090Sstevel@tonic-gate 	}
29100Sstevel@tonic-gate 
29110Sstevel@tonic-gate 	if (mdb_readvar(&panicstr, "panicstr") == -1) {
29120Sstevel@tonic-gate 		mdb_warn("failed to read 'panicstr'");
29130Sstevel@tonic-gate 		return (WALK_ERR);
29140Sstevel@tonic-gate 	}
29150Sstevel@tonic-gate 
29160Sstevel@tonic-gate 	if (panicstr != NULL) {
29170Sstevel@tonic-gate 		if (mdb_lookup_by_name("panic_cpu", &sym) == -1) {
29180Sstevel@tonic-gate 			mdb_warn("failed to find 'panic_cpu'");
29190Sstevel@tonic-gate 			return (WALK_ERR);
29200Sstevel@tonic-gate 		}
29210Sstevel@tonic-gate 
29220Sstevel@tonic-gate 		addr = (uintptr_t)sym.st_value;
29230Sstevel@tonic-gate 
29240Sstevel@tonic-gate 		if (mdb_vread(&panic_cpu, sizeof (cpu_t), addr) == -1) {
29250Sstevel@tonic-gate 			mdb_warn("failed to read 'panic_cpu'");
29260Sstevel@tonic-gate 			return (WALK_ERR);
29270Sstevel@tonic-gate 		}
29280Sstevel@tonic-gate 	}
29290Sstevel@tonic-gate 
29300Sstevel@tonic-gate 	/*
29310Sstevel@tonic-gate 	 * Unfortunately, there is no platform-independent way to walk
29320Sstevel@tonic-gate 	 * CPUs in ID order.  We therefore loop through in cpu_next order,
29330Sstevel@tonic-gate 	 * building an array of CPU pointers which will subsequently be
29340Sstevel@tonic-gate 	 * sorted.
29350Sstevel@tonic-gate 	 */
29360Sstevel@tonic-gate 	cw->cw_array =
29370Sstevel@tonic-gate 	    mdb_zalloc((max_ncpus + 1) * sizeof (uintptr_t), UM_SLEEP | UM_GC);
29380Sstevel@tonic-gate 
29390Sstevel@tonic-gate 	if (mdb_readvar(&first, "cpu_list") == -1) {
29400Sstevel@tonic-gate 		mdb_warn("failed to read 'cpu_list'");
29410Sstevel@tonic-gate 		return (WALK_ERR);
29420Sstevel@tonic-gate 	}
29430Sstevel@tonic-gate 
29440Sstevel@tonic-gate 	current = first;
29450Sstevel@tonic-gate 	do {
29460Sstevel@tonic-gate 		if (mdb_vread(&cpu, sizeof (cpu), current) == -1) {
29470Sstevel@tonic-gate 			mdb_warn("failed to read cpu at %p", current);
29480Sstevel@tonic-gate 			return (WALK_ERR);
29490Sstevel@tonic-gate 		}
29500Sstevel@tonic-gate 
29510Sstevel@tonic-gate 		if (panicstr != NULL && panic_cpu.cpu_id == cpu.cpu_id) {
29520Sstevel@tonic-gate 			cw->cw_array[i++] = addr;
29530Sstevel@tonic-gate 		} else {
29540Sstevel@tonic-gate 			cw->cw_array[i++] = current;
29550Sstevel@tonic-gate 		}
29560Sstevel@tonic-gate 	} while ((current = (uintptr_t)cpu.cpu_next) != first);
29570Sstevel@tonic-gate 
29580Sstevel@tonic-gate 	qsort(cw->cw_array, i, sizeof (uintptr_t), cpu_walk_cmp);
29590Sstevel@tonic-gate 	wsp->walk_data = cw;
29600Sstevel@tonic-gate 
29610Sstevel@tonic-gate 	return (WALK_NEXT);
29620Sstevel@tonic-gate }
29630Sstevel@tonic-gate 
29640Sstevel@tonic-gate int
29650Sstevel@tonic-gate cpu_walk_step(mdb_walk_state_t *wsp)
29660Sstevel@tonic-gate {
29670Sstevel@tonic-gate 	cpu_walk_t *cw = wsp->walk_data;
29680Sstevel@tonic-gate 	cpu_t cpu;
29690Sstevel@tonic-gate 	uintptr_t addr = cw->cw_array[cw->cw_ndx++];
29700Sstevel@tonic-gate 
29710Sstevel@tonic-gate 	if (addr == NULL)
29720Sstevel@tonic-gate 		return (WALK_DONE);
29730Sstevel@tonic-gate 
29740Sstevel@tonic-gate 	if (mdb_vread(&cpu, sizeof (cpu), addr) == -1) {
29750Sstevel@tonic-gate 		mdb_warn("failed to read cpu at %p", addr);
29760Sstevel@tonic-gate 		return (WALK_DONE);
29770Sstevel@tonic-gate 	}
29780Sstevel@tonic-gate 
29790Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &cpu, wsp->walk_cbdata));
29800Sstevel@tonic-gate }
29810Sstevel@tonic-gate 
29820Sstevel@tonic-gate typedef struct cpuinfo_data {
29830Sstevel@tonic-gate 	intptr_t cid_cpu;
29840Sstevel@tonic-gate 	uintptr_t cid_lbolt;
29850Sstevel@tonic-gate 	uintptr_t **cid_ithr;
29860Sstevel@tonic-gate 	char	cid_print_head;
29870Sstevel@tonic-gate 	char	cid_print_thr;
29880Sstevel@tonic-gate 	char	cid_print_ithr;
29890Sstevel@tonic-gate 	char	cid_print_flags;
29900Sstevel@tonic-gate } cpuinfo_data_t;
29910Sstevel@tonic-gate 
29920Sstevel@tonic-gate int
29930Sstevel@tonic-gate cpuinfo_walk_ithread(uintptr_t addr, const kthread_t *thr, cpuinfo_data_t *cid)
29940Sstevel@tonic-gate {
29950Sstevel@tonic-gate 	cpu_t c;
29960Sstevel@tonic-gate 	int id;
29970Sstevel@tonic-gate 	uint8_t pil;
29980Sstevel@tonic-gate 
29990Sstevel@tonic-gate 	if (!(thr->t_flag & T_INTR_THREAD) || thr->t_state == TS_FREE)
30000Sstevel@tonic-gate 		return (WALK_NEXT);
30010Sstevel@tonic-gate 
30020Sstevel@tonic-gate 	if (thr->t_bound_cpu == NULL) {
30030Sstevel@tonic-gate 		mdb_warn("thr %p is intr thread w/out a CPU\n", addr);
30040Sstevel@tonic-gate 		return (WALK_NEXT);
30050Sstevel@tonic-gate 	}
30060Sstevel@tonic-gate 
30070Sstevel@tonic-gate 	(void) mdb_vread(&c, sizeof (c), (uintptr_t)thr->t_bound_cpu);
30080Sstevel@tonic-gate 
30090Sstevel@tonic-gate 	if ((id = c.cpu_id) >= NCPU) {
30100Sstevel@tonic-gate 		mdb_warn("CPU %p has id (%d) greater than NCPU (%d)\n",
30110Sstevel@tonic-gate 		    thr->t_bound_cpu, id, NCPU);
30120Sstevel@tonic-gate 		return (WALK_NEXT);
30130Sstevel@tonic-gate 	}
30140Sstevel@tonic-gate 
30150Sstevel@tonic-gate 	if ((pil = thr->t_pil) >= NINTR) {
30160Sstevel@tonic-gate 		mdb_warn("thread %p has pil (%d) greater than %d\n",
30170Sstevel@tonic-gate 		    addr, pil, NINTR);
30180Sstevel@tonic-gate 		return (WALK_NEXT);
30190Sstevel@tonic-gate 	}
30200Sstevel@tonic-gate 
30210Sstevel@tonic-gate 	if (cid->cid_ithr[id][pil] != NULL) {
30220Sstevel@tonic-gate 		mdb_warn("CPU %d has multiple threads at pil %d (at least "
30230Sstevel@tonic-gate 		    "%p and %p)\n", id, pil, addr, cid->cid_ithr[id][pil]);
30240Sstevel@tonic-gate 		return (WALK_NEXT);
30250Sstevel@tonic-gate 	}
30260Sstevel@tonic-gate 
30270Sstevel@tonic-gate 	cid->cid_ithr[id][pil] = addr;
30280Sstevel@tonic-gate 
30290Sstevel@tonic-gate 	return (WALK_NEXT);
30300Sstevel@tonic-gate }
30310Sstevel@tonic-gate 
30320Sstevel@tonic-gate #define	CPUINFO_IDWIDTH		3
30330Sstevel@tonic-gate #define	CPUINFO_FLAGWIDTH	9
30340Sstevel@tonic-gate 
30350Sstevel@tonic-gate #ifdef _LP64
3036537Smishra #if defined(__amd64)
3037537Smishra #define	CPUINFO_TWIDTH		16
3038537Smishra #define	CPUINFO_CPUWIDTH	16
3039537Smishra #else
30400Sstevel@tonic-gate #define	CPUINFO_CPUWIDTH	11
30410Sstevel@tonic-gate #define	CPUINFO_TWIDTH		11
3042537Smishra #endif
30430Sstevel@tonic-gate #else
30440Sstevel@tonic-gate #define	CPUINFO_CPUWIDTH	8
30450Sstevel@tonic-gate #define	CPUINFO_TWIDTH		8
30460Sstevel@tonic-gate #endif
30470Sstevel@tonic-gate 
30480Sstevel@tonic-gate #define	CPUINFO_THRDELT		(CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 9)
30490Sstevel@tonic-gate #define	CPUINFO_FLAGDELT	(CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 4)
30500Sstevel@tonic-gate #define	CPUINFO_ITHRDELT	4
30510Sstevel@tonic-gate 
30520Sstevel@tonic-gate #define	CPUINFO_INDENT	mdb_printf("%*s", CPUINFO_THRDELT, \
30530Sstevel@tonic-gate     flagline < nflaglines ? flagbuf[flagline++] : "")
30540Sstevel@tonic-gate 
30550Sstevel@tonic-gate int
30560Sstevel@tonic-gate cpuinfo_walk_cpu(uintptr_t addr, const cpu_t *cpu, cpuinfo_data_t *cid)
30570Sstevel@tonic-gate {
30580Sstevel@tonic-gate 	kthread_t t;
30590Sstevel@tonic-gate 	disp_t disp;
30600Sstevel@tonic-gate 	proc_t p;
30610Sstevel@tonic-gate 	uintptr_t pinned;
30620Sstevel@tonic-gate 	char **flagbuf;
30630Sstevel@tonic-gate 	int nflaglines = 0, flagline = 0, bspl, rval = WALK_NEXT;
30640Sstevel@tonic-gate 
30650Sstevel@tonic-gate 	const char *flags[] = {
30660Sstevel@tonic-gate 	    "RUNNING", "READY", "QUIESCED", "EXISTS",
30670Sstevel@tonic-gate 	    "ENABLE", "OFFLINE", "POWEROFF", "FROZEN",
30680Sstevel@tonic-gate 	    "SPARE", "FAULTED", NULL
30690Sstevel@tonic-gate 	};
30700Sstevel@tonic-gate 
30710Sstevel@tonic-gate 	if (cid->cid_cpu != -1) {
30720Sstevel@tonic-gate 		if (addr != cid->cid_cpu && cpu->cpu_id != cid->cid_cpu)
30730Sstevel@tonic-gate 			return (WALK_NEXT);
30740Sstevel@tonic-gate 
30750Sstevel@tonic-gate 		/*
30760Sstevel@tonic-gate 		 * Set cid_cpu to -1 to indicate that we found a matching CPU.
30770Sstevel@tonic-gate 		 */
30780Sstevel@tonic-gate 		cid->cid_cpu = -1;
30790Sstevel@tonic-gate 		rval = WALK_DONE;
30800Sstevel@tonic-gate 	}
30810Sstevel@tonic-gate 
30820Sstevel@tonic-gate 	if (cid->cid_print_head) {
30830Sstevel@tonic-gate 		mdb_printf("%3s %-*s %3s %4s %4s %3s %4s %5s %-6s %-*s %s\n",
30840Sstevel@tonic-gate 		    "ID", CPUINFO_CPUWIDTH, "ADDR", "FLG", "NRUN", "BSPL",
30850Sstevel@tonic-gate 		    "PRI", "RNRN", "KRNRN", "SWITCH", CPUINFO_TWIDTH, "THREAD",
30860Sstevel@tonic-gate 		    "PROC");
30870Sstevel@tonic-gate 		cid->cid_print_head = FALSE;
30880Sstevel@tonic-gate 	}
30890Sstevel@tonic-gate 
30900Sstevel@tonic-gate 	bspl = cpu->cpu_base_spl;
30910Sstevel@tonic-gate 
30920Sstevel@tonic-gate 	if (mdb_vread(&disp, sizeof (disp_t), (uintptr_t)cpu->cpu_disp) == -1) {
30930Sstevel@tonic-gate 		mdb_warn("failed to read disp_t at %p", cpu->cpu_disp);
30940Sstevel@tonic-gate 		return (WALK_ERR);
30950Sstevel@tonic-gate 	}
30960Sstevel@tonic-gate 
30970Sstevel@tonic-gate 	mdb_printf("%3d %0*p %3x %4d %4d ",
30980Sstevel@tonic-gate 	    cpu->cpu_id, CPUINFO_CPUWIDTH, addr, cpu->cpu_flags,
30990Sstevel@tonic-gate 	    disp.disp_nrunnable, bspl);
31000Sstevel@tonic-gate 
31010Sstevel@tonic-gate 	if (mdb_vread(&t, sizeof (t), (uintptr_t)cpu->cpu_thread) != -1) {
31020Sstevel@tonic-gate 		mdb_printf("%3d ", t.t_pri);
31030Sstevel@tonic-gate 	} else {
31040Sstevel@tonic-gate 		mdb_printf("%3s ", "-");
31050Sstevel@tonic-gate 	}
31060Sstevel@tonic-gate 
31070Sstevel@tonic-gate 	mdb_printf("%4s %5s ", cpu->cpu_runrun ? "yes" : "no",
31080Sstevel@tonic-gate 	    cpu->cpu_kprunrun ? "yes" : "no");
31090Sstevel@tonic-gate 
31100Sstevel@tonic-gate 	if (cpu->cpu_last_swtch) {
31110Sstevel@tonic-gate 		clock_t lbolt;
31120Sstevel@tonic-gate 
31130Sstevel@tonic-gate 		if (mdb_vread(&lbolt, sizeof (lbolt), cid->cid_lbolt) == -1) {
31140Sstevel@tonic-gate 			mdb_warn("failed to read lbolt at %p", cid->cid_lbolt);
31150Sstevel@tonic-gate 			return (WALK_ERR);
31160Sstevel@tonic-gate 		}
31170Sstevel@tonic-gate 		mdb_printf("t-%-4d ", lbolt - cpu->cpu_last_swtch);
31180Sstevel@tonic-gate 	} else {
31190Sstevel@tonic-gate 		mdb_printf("%-6s ", "-");
31200Sstevel@tonic-gate 	}
31210Sstevel@tonic-gate 
31220Sstevel@tonic-gate 	mdb_printf("%0*p", CPUINFO_TWIDTH, cpu->cpu_thread);
31230Sstevel@tonic-gate 
31240Sstevel@tonic-gate 	if (cpu->cpu_thread == cpu->cpu_idle_thread)
31250Sstevel@tonic-gate 		mdb_printf(" (idle)\n");
31260Sstevel@tonic-gate 	else if (cpu->cpu_thread == NULL)
31270Sstevel@tonic-gate 		mdb_printf(" -\n");
31280Sstevel@tonic-gate 	else {
31290Sstevel@tonic-gate 		if (mdb_vread(&p, sizeof (p), (uintptr_t)t.t_procp) != -1) {
31300Sstevel@tonic-gate 			mdb_printf(" %s\n", p.p_user.u_comm);
31310Sstevel@tonic-gate 		} else {
31320Sstevel@tonic-gate 			mdb_printf(" ?\n");
31330Sstevel@tonic-gate 		}
31340Sstevel@tonic-gate 	}
31350Sstevel@tonic-gate 
31360Sstevel@tonic-gate 	flagbuf = mdb_zalloc(sizeof (flags), UM_SLEEP | UM_GC);
31370Sstevel@tonic-gate 
31380Sstevel@tonic-gate 	if (cid->cid_print_flags) {
31390Sstevel@tonic-gate 		int first = 1, i, j, k;
31400Sstevel@tonic-gate 		char *s;
31410Sstevel@tonic-gate 
31420Sstevel@tonic-gate 		cid->cid_print_head = TRUE;
31430Sstevel@tonic-gate 
31440Sstevel@tonic-gate 		for (i = 1, j = 0; flags[j] != NULL; i <<= 1, j++) {
31450Sstevel@tonic-gate 			if (!(cpu->cpu_flags & i))
31460Sstevel@tonic-gate 				continue;
31470Sstevel@tonic-gate 
31480Sstevel@tonic-gate 			if (first) {
31490Sstevel@tonic-gate 				s = mdb_alloc(CPUINFO_THRDELT + 1,
31500Sstevel@tonic-gate 				    UM_GC | UM_SLEEP);
31510Sstevel@tonic-gate 
31520Sstevel@tonic-gate 				(void) mdb_snprintf(s, CPUINFO_THRDELT + 1,
31530Sstevel@tonic-gate 				    "%*s|%*s", CPUINFO_FLAGDELT, "",
31540Sstevel@tonic-gate 				    CPUINFO_THRDELT - 1 - CPUINFO_FLAGDELT, "");
31550Sstevel@tonic-gate 				flagbuf[nflaglines++] = s;
31560Sstevel@tonic-gate 			}
31570Sstevel@tonic-gate 
31580Sstevel@tonic-gate 			s = mdb_alloc(CPUINFO_THRDELT + 1, UM_GC | UM_SLEEP);
31590Sstevel@tonic-gate 			(void) mdb_snprintf(s, CPUINFO_THRDELT + 1, "%*s%*s %s",
31600Sstevel@tonic-gate 			    CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH -
31610Sstevel@tonic-gate 			    CPUINFO_FLAGWIDTH, "", CPUINFO_FLAGWIDTH, flags[j],
31620Sstevel@tonic-gate 			    first ? "<--+" : "");
31630Sstevel@tonic-gate 
31640Sstevel@tonic-gate 			for (k = strlen(s); k < CPUINFO_THRDELT; k++)
31650Sstevel@tonic-gate 				s[k] = ' ';
31660Sstevel@tonic-gate 			s[k] = '\0';
31670Sstevel@tonic-gate 
31680Sstevel@tonic-gate 			flagbuf[nflaglines++] = s;
31690Sstevel@tonic-gate 			first = 0;
31700Sstevel@tonic-gate 		}
31710Sstevel@tonic-gate 	}
31720Sstevel@tonic-gate 
31730Sstevel@tonic-gate 	if (cid->cid_print_ithr) {
31740Sstevel@tonic-gate 		int i, found_one = FALSE;
31750Sstevel@tonic-gate 		int print_thr = disp.disp_nrunnable && cid->cid_print_thr;
31760Sstevel@tonic-gate 
31770Sstevel@tonic-gate 		for (i = NINTR - 1; i >= 0; i--) {
31780Sstevel@tonic-gate 			uintptr_t iaddr = cid->cid_ithr[cpu->cpu_id][i];
31790Sstevel@tonic-gate 
31800Sstevel@tonic-gate 			if (iaddr == NULL)
31810Sstevel@tonic-gate 				continue;
31820Sstevel@tonic-gate 
31830Sstevel@tonic-gate 			if (!found_one) {
31840Sstevel@tonic-gate 				found_one = TRUE;
31850Sstevel@tonic-gate 
31860Sstevel@tonic-gate 				CPUINFO_INDENT;
31870Sstevel@tonic-gate 				mdb_printf("%c%*s|\n", print_thr ? '|' : ' ',
31880Sstevel@tonic-gate 				    CPUINFO_ITHRDELT, "");
31890Sstevel@tonic-gate 
31900Sstevel@tonic-gate 				CPUINFO_INDENT;
31910Sstevel@tonic-gate 				mdb_printf("%c%*s+--> %3s %s\n",
31920Sstevel@tonic-gate 				    print_thr ? '|' : ' ', CPUINFO_ITHRDELT,
31930Sstevel@tonic-gate 				    "", "PIL", "THREAD");
31940Sstevel@tonic-gate 			}
31950Sstevel@tonic-gate 
31960Sstevel@tonic-gate 			if (mdb_vread(&t, sizeof (t), iaddr) == -1) {
31970Sstevel@tonic-gate 				mdb_warn("failed to read kthread_t at %p",
31980Sstevel@tonic-gate 				    iaddr);
31990Sstevel@tonic-gate 				return (WALK_ERR);
32000Sstevel@tonic-gate 			}
32010Sstevel@tonic-gate 
32020Sstevel@tonic-gate 			CPUINFO_INDENT;
32030Sstevel@tonic-gate 			mdb_printf("%c%*s     %3d %0*p\n",
32040Sstevel@tonic-gate 			    print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "",
32050Sstevel@tonic-gate 			    t.t_pil, CPUINFO_TWIDTH, iaddr);
32060Sstevel@tonic-gate 
32070Sstevel@tonic-gate 			pinned = (uintptr_t)t.t_intr;
32080Sstevel@tonic-gate 		}
32090Sstevel@tonic-gate 
32100Sstevel@tonic-gate 		if (found_one && pinned != NULL) {
32110Sstevel@tonic-gate 			cid->cid_print_head = TRUE;
32120Sstevel@tonic-gate 			(void) strcpy(p.p_user.u_comm, "?");
32130Sstevel@tonic-gate 
32140Sstevel@tonic-gate 			if (mdb_vread(&t, sizeof (t),
32150Sstevel@tonic-gate 			    (uintptr_t)pinned) == -1) {
32160Sstevel@tonic-gate 				mdb_warn("failed to read kthread_t at %p",
32170Sstevel@tonic-gate 				    pinned);
32180Sstevel@tonic-gate 				return (WALK_ERR);
32190Sstevel@tonic-gate 			}
32200Sstevel@tonic-gate 			if (mdb_vread(&p, sizeof (p),
32210Sstevel@tonic-gate 			    (uintptr_t)t.t_procp) == -1) {
32220Sstevel@tonic-gate 				mdb_warn("failed to read proc_t at %p",
32230Sstevel@tonic-gate 				    t.t_procp);
32240Sstevel@tonic-gate 				return (WALK_ERR);
32250Sstevel@tonic-gate 			}
32260Sstevel@tonic-gate 
32270Sstevel@tonic-gate 			CPUINFO_INDENT;
32280Sstevel@tonic-gate 			mdb_printf("%c%*s     %3s %0*p %s\n",
32290Sstevel@tonic-gate 			    print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", "-",
32300Sstevel@tonic-gate 			    CPUINFO_TWIDTH, pinned,
32310Sstevel@tonic-gate 			    pinned == (uintptr_t)cpu->cpu_idle_thread ?
32320Sstevel@tonic-gate 			    "(idle)" : p.p_user.u_comm);
32330Sstevel@tonic-gate 		}
32340Sstevel@tonic-gate 	}
32350Sstevel@tonic-gate 
32360Sstevel@tonic-gate 	if (disp.disp_nrunnable && cid->cid_print_thr) {
32370Sstevel@tonic-gate 		dispq_t *dq;
32380Sstevel@tonic-gate 
32390Sstevel@tonic-gate 		int i, npri = disp.disp_npri;
32400Sstevel@tonic-gate 
32410Sstevel@tonic-gate 		dq = mdb_alloc(sizeof (dispq_t) * npri, UM_SLEEP | UM_GC);
32420Sstevel@tonic-gate 
32430Sstevel@tonic-gate 		if (mdb_vread(dq, sizeof (dispq_t) * npri,
32440Sstevel@tonic-gate 		    (uintptr_t)disp.disp_q) == -1) {
32450Sstevel@tonic-gate 			mdb_warn("failed to read dispq_t at %p", disp.disp_q);
32460Sstevel@tonic-gate 			return (WALK_ERR);
32470Sstevel@tonic-gate 		}
32480Sstevel@tonic-gate 
32490Sstevel@tonic-gate 		CPUINFO_INDENT;
32500Sstevel@tonic-gate 		mdb_printf("|\n");
32510Sstevel@tonic-gate 
32520Sstevel@tonic-gate 		CPUINFO_INDENT;
32530Sstevel@tonic-gate 		mdb_printf("+-->  %3s %-*s %s\n", "PRI",
32540Sstevel@tonic-gate 		    CPUINFO_TWIDTH, "THREAD", "PROC");
32550Sstevel@tonic-gate 
32560Sstevel@tonic-gate 		for (i = npri - 1; i >= 0; i--) {
32570Sstevel@tonic-gate 			uintptr_t taddr = (uintptr_t)dq[i].dq_first;
32580Sstevel@tonic-gate 
32590Sstevel@tonic-gate 			while (taddr != NULL) {
32600Sstevel@tonic-gate 				if (mdb_vread(&t, sizeof (t), taddr) == -1) {
32610Sstevel@tonic-gate 					mdb_warn("failed to read kthread_t "
32620Sstevel@tonic-gate 					    "at %p", taddr);
32630Sstevel@tonic-gate 					return (WALK_ERR);
32640Sstevel@tonic-gate 				}
32650Sstevel@tonic-gate 				if (mdb_vread(&p, sizeof (p),
32660Sstevel@tonic-gate 				    (uintptr_t)t.t_procp) == -1) {
32670Sstevel@tonic-gate 					mdb_warn("failed to read proc_t at %p",
32680Sstevel@tonic-gate 					    t.t_procp);
32690Sstevel@tonic-gate 					return (WALK_ERR);
32700Sstevel@tonic-gate 				}
32710Sstevel@tonic-gate 
32720Sstevel@tonic-gate 				CPUINFO_INDENT;
32730Sstevel@tonic-gate 				mdb_printf("      %3d %0*p %s\n", t.t_pri,
32740Sstevel@tonic-gate 				    CPUINFO_TWIDTH, taddr, p.p_user.u_comm);
32750Sstevel@tonic-gate 
32760Sstevel@tonic-gate 				taddr = (uintptr_t)t.t_link;
32770Sstevel@tonic-gate 			}
32780Sstevel@tonic-gate 		}
32790Sstevel@tonic-gate 		cid->cid_print_head = TRUE;
32800Sstevel@tonic-gate 	}
32810Sstevel@tonic-gate 
32820Sstevel@tonic-gate 	while (flagline < nflaglines)
32830Sstevel@tonic-gate 		mdb_printf("%s\n", flagbuf[flagline++]);
32840Sstevel@tonic-gate 
32850Sstevel@tonic-gate 	if (cid->cid_print_head)
32860Sstevel@tonic-gate 		mdb_printf("\n");
32870Sstevel@tonic-gate 
32880Sstevel@tonic-gate 	return (rval);
32890Sstevel@tonic-gate }
32900Sstevel@tonic-gate 
32910Sstevel@tonic-gate int
32920Sstevel@tonic-gate cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
32930Sstevel@tonic-gate {
32940Sstevel@tonic-gate 	uint_t verbose = FALSE;
32950Sstevel@tonic-gate 	cpuinfo_data_t cid;
32960Sstevel@tonic-gate 	GElf_Sym sym;
32970Sstevel@tonic-gate 	clock_t lbolt;
32980Sstevel@tonic-gate 
32990Sstevel@tonic-gate 	cid.cid_print_ithr = FALSE;
33000Sstevel@tonic-gate 	cid.cid_print_thr = FALSE;
33010Sstevel@tonic-gate 	cid.cid_print_flags = FALSE;
33020Sstevel@tonic-gate 	cid.cid_print_head = DCMD_HDRSPEC(flags) ? TRUE : FALSE;
33030Sstevel@tonic-gate 	cid.cid_cpu = -1;
33040Sstevel@tonic-gate 
33050Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
33060Sstevel@tonic-gate 		cid.cid_cpu = addr;
33070Sstevel@tonic-gate 
33080Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
33090Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc)
33100Sstevel@tonic-gate 		return (DCMD_USAGE);
33110Sstevel@tonic-gate 
33120Sstevel@tonic-gate 	if (verbose) {
33130Sstevel@tonic-gate 		cid.cid_print_ithr = TRUE;
33140Sstevel@tonic-gate 		cid.cid_print_thr = TRUE;
33150Sstevel@tonic-gate 		cid.cid_print_flags = TRUE;
33160Sstevel@tonic-gate 		cid.cid_print_head = TRUE;
33170Sstevel@tonic-gate 	}
33180Sstevel@tonic-gate 
33190Sstevel@tonic-gate 	if (cid.cid_print_ithr) {
33200Sstevel@tonic-gate 		int i;
33210Sstevel@tonic-gate 
33220Sstevel@tonic-gate 		cid.cid_ithr = mdb_alloc(sizeof (uintptr_t **)
33230Sstevel@tonic-gate 		    * NCPU, UM_SLEEP | UM_GC);
33240Sstevel@tonic-gate 
33250Sstevel@tonic-gate 		for (i = 0; i < NCPU; i++)
33260Sstevel@tonic-gate 			cid.cid_ithr[i] = mdb_zalloc(sizeof (uintptr_t *) *
33270Sstevel@tonic-gate 			    NINTR, UM_SLEEP | UM_GC);
33280Sstevel@tonic-gate 
33290Sstevel@tonic-gate 		if (mdb_walk("thread", (mdb_walk_cb_t)cpuinfo_walk_ithread,
33300Sstevel@tonic-gate 		    &cid) == -1) {
33310Sstevel@tonic-gate 			mdb_warn("couldn't walk thread");
33320Sstevel@tonic-gate 			return (DCMD_ERR);
33330Sstevel@tonic-gate 		}
33340Sstevel@tonic-gate 	}
33350Sstevel@tonic-gate 
33360Sstevel@tonic-gate 	if (mdb_lookup_by_name("panic_lbolt", &sym) == -1) {
33370Sstevel@tonic-gate 		mdb_warn("failed to find panic_lbolt");
33380Sstevel@tonic-gate 		return (DCMD_ERR);
33390Sstevel@tonic-gate 	}
33400Sstevel@tonic-gate 
33410Sstevel@tonic-gate 	cid.cid_lbolt = (uintptr_t)sym.st_value;
33420Sstevel@tonic-gate 
33430Sstevel@tonic-gate 	if (mdb_vread(&lbolt, sizeof (lbolt), cid.cid_lbolt) == -1) {
33440Sstevel@tonic-gate 		mdb_warn("failed to read panic_lbolt");
33450Sstevel@tonic-gate 		return (DCMD_ERR);
33460Sstevel@tonic-gate 	}
33470Sstevel@tonic-gate 
33480Sstevel@tonic-gate 	if (lbolt == 0) {
33490Sstevel@tonic-gate 		if (mdb_lookup_by_name("lbolt", &sym) == -1) {
33500Sstevel@tonic-gate 			mdb_warn("failed to find lbolt");
33510Sstevel@tonic-gate 			return (DCMD_ERR);
33520Sstevel@tonic-gate 		}
33530Sstevel@tonic-gate 		cid.cid_lbolt = (uintptr_t)sym.st_value;
33540Sstevel@tonic-gate 	}
33550Sstevel@tonic-gate 
33560Sstevel@tonic-gate 	if (mdb_walk("cpu", (mdb_walk_cb_t)cpuinfo_walk_cpu, &cid) == -1) {
33570Sstevel@tonic-gate 		mdb_warn("can't walk cpus");
33580Sstevel@tonic-gate 		return (DCMD_ERR);
33590Sstevel@tonic-gate 	}
33600Sstevel@tonic-gate 
33610Sstevel@tonic-gate 	if (cid.cid_cpu != -1) {
33620Sstevel@tonic-gate 		/*
33630Sstevel@tonic-gate 		 * We didn't find this CPU when we walked through the CPUs
33640Sstevel@tonic-gate 		 * (i.e. the address specified doesn't show up in the "cpu"
33650Sstevel@tonic-gate 		 * walk).  However, the specified address may still correspond
33660Sstevel@tonic-gate 		 * to a valid cpu_t (for example, if the specified address is
33670Sstevel@tonic-gate 		 * the actual panicking cpu_t and not the cached panic_cpu).
33680Sstevel@tonic-gate 		 * Point is:  even if we didn't find it, we still want to try
33690Sstevel@tonic-gate 		 * to print the specified address as a cpu_t.
33700Sstevel@tonic-gate 		 */
33710Sstevel@tonic-gate 		cpu_t cpu;
33720Sstevel@tonic-gate 
33730Sstevel@tonic-gate 		if (mdb_vread(&cpu, sizeof (cpu), cid.cid_cpu) == -1) {
33740Sstevel@tonic-gate 			mdb_warn("%p is neither a valid CPU ID nor a "
33750Sstevel@tonic-gate 			    "valid cpu_t address\n", cid.cid_cpu);
33760Sstevel@tonic-gate 			return (DCMD_ERR);
33770Sstevel@tonic-gate 		}
33780Sstevel@tonic-gate 
33790Sstevel@tonic-gate 		(void) cpuinfo_walk_cpu(cid.cid_cpu, &cpu, &cid);
33800Sstevel@tonic-gate 	}
33810Sstevel@tonic-gate 
33820Sstevel@tonic-gate 	return (DCMD_OK);
33830Sstevel@tonic-gate }
33840Sstevel@tonic-gate 
33850Sstevel@tonic-gate /*ARGSUSED*/
33860Sstevel@tonic-gate int
33870Sstevel@tonic-gate flipone(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
33880Sstevel@tonic-gate {
33890Sstevel@tonic-gate 	int i;
33900Sstevel@tonic-gate 
33910Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
33920Sstevel@tonic-gate 		return (DCMD_USAGE);
33930Sstevel@tonic-gate 
33940Sstevel@tonic-gate 	for (i = 0; i < sizeof (addr) * NBBY; i++)
33950Sstevel@tonic-gate 		mdb_printf("%p\n", addr ^ (1UL << i));
33960Sstevel@tonic-gate 
33970Sstevel@tonic-gate 	return (DCMD_OK);
33980Sstevel@tonic-gate }
33990Sstevel@tonic-gate 
34000Sstevel@tonic-gate /*
34010Sstevel@tonic-gate  * Grumble, grumble.
34020Sstevel@tonic-gate  */
34030Sstevel@tonic-gate #define	SMAP_HASHFUNC(vp, off)	\
34040Sstevel@tonic-gate 	((((uintptr_t)(vp) >> 6) + ((uintptr_t)(vp) >> 3) + \
34050Sstevel@tonic-gate 	((off) >> MAXBSHIFT)) & smd_hashmsk)
34060Sstevel@tonic-gate 
34070Sstevel@tonic-gate int
34080Sstevel@tonic-gate vnode2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
34090Sstevel@tonic-gate {
34100Sstevel@tonic-gate 	long smd_hashmsk;
34110Sstevel@tonic-gate 	int hash;
34120Sstevel@tonic-gate 	uintptr_t offset = 0;
34130Sstevel@tonic-gate 	struct smap smp;
34140Sstevel@tonic-gate 	uintptr_t saddr, kaddr;
34150Sstevel@tonic-gate 	uintptr_t smd_hash, smd_smap;
34160Sstevel@tonic-gate 	struct seg seg;
34170Sstevel@tonic-gate 
34180Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
34190Sstevel@tonic-gate 		return (DCMD_USAGE);
34200Sstevel@tonic-gate 
34210Sstevel@tonic-gate 	if (mdb_readvar(&smd_hashmsk, "smd_hashmsk") == -1) {
34220Sstevel@tonic-gate 		mdb_warn("failed to read smd_hashmsk");
34230Sstevel@tonic-gate 		return (DCMD_ERR);
34240Sstevel@tonic-gate 	}
34250Sstevel@tonic-gate 
34260Sstevel@tonic-gate 	if (mdb_readvar(&smd_hash, "smd_hash") == -1) {
34270Sstevel@tonic-gate 		mdb_warn("failed to read smd_hash");
34280Sstevel@tonic-gate 		return (DCMD_ERR);
34290Sstevel@tonic-gate 	}
34300Sstevel@tonic-gate 
34310Sstevel@tonic-gate 	if (mdb_readvar(&smd_smap, "smd_smap") == -1) {
34320Sstevel@tonic-gate 		mdb_warn("failed to read smd_hash");
34330Sstevel@tonic-gate 		return (DCMD_ERR);
34340Sstevel@tonic-gate 	}
34350Sstevel@tonic-gate 
34360Sstevel@tonic-gate 	if (mdb_readvar(&kaddr, "segkmap") == -1) {
34370Sstevel@tonic-gate 		mdb_warn("failed to read segkmap");
34380Sstevel@tonic-gate 		return (DCMD_ERR);
34390Sstevel@tonic-gate 	}
34400Sstevel@tonic-gate 
34410Sstevel@tonic-gate 	if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) {
34420Sstevel@tonic-gate 		mdb_warn("failed to read segkmap at %p", kaddr);
34430Sstevel@tonic-gate 		return (DCMD_ERR);
34440Sstevel@tonic-gate 	}
34450Sstevel@tonic-gate 
34460Sstevel@tonic-gate 	if (argc != 0) {
34470Sstevel@tonic-gate 		const mdb_arg_t *arg = &argv[0];
34480Sstevel@tonic-gate 
34490Sstevel@tonic-gate 		if (arg->a_type == MDB_TYPE_IMMEDIATE)
34500Sstevel@tonic-gate 			offset = arg->a_un.a_val;
34510Sstevel@tonic-gate 		else
34520Sstevel@tonic-gate 			offset = (uintptr_t)mdb_strtoull(arg->a_un.a_str);
34530Sstevel@tonic-gate 	}
34540Sstevel@tonic-gate 
34550Sstevel@tonic-gate 	hash = SMAP_HASHFUNC(addr, offset);
34560Sstevel@tonic-gate 
34570Sstevel@tonic-gate 	if (mdb_vread(&saddr, sizeof (saddr),
34580Sstevel@tonic-gate 	    smd_hash + hash * sizeof (uintptr_t)) == -1) {
34590Sstevel@tonic-gate 		mdb_warn("couldn't read smap at %p",
34600Sstevel@tonic-gate 		    smd_hash + hash * sizeof (uintptr_t));
34610Sstevel@tonic-gate 		return (DCMD_ERR);
34620Sstevel@tonic-gate 	}
34630Sstevel@tonic-gate 
34640Sstevel@tonic-gate 	do {
34650Sstevel@tonic-gate 		if (mdb_vread(&smp, sizeof (smp), saddr) == -1) {
34660Sstevel@tonic-gate 			mdb_warn("couldn't read smap at %p", saddr);
34670Sstevel@tonic-gate 			return (DCMD_ERR);
34680Sstevel@tonic-gate 		}
34690Sstevel@tonic-gate 
34700Sstevel@tonic-gate 		if ((uintptr_t)smp.sm_vp == addr && smp.sm_off == offset) {
34710Sstevel@tonic-gate 			mdb_printf("vnode %p, offs %p is smap %p, vaddr %p\n",
34720Sstevel@tonic-gate 			    addr, offset, saddr, ((saddr - smd_smap) /
34730Sstevel@tonic-gate 			    sizeof (smp)) * MAXBSIZE + seg.s_base);
34740Sstevel@tonic-gate 			return (DCMD_OK);
34750Sstevel@tonic-gate 		}
34760Sstevel@tonic-gate 
34770Sstevel@tonic-gate 		saddr = (uintptr_t)smp.sm_hash;
34780Sstevel@tonic-gate 	} while (saddr != NULL);
34790Sstevel@tonic-gate 
34800Sstevel@tonic-gate 	mdb_printf("no smap for vnode %p, offs %p\n", addr, offset);
34810Sstevel@tonic-gate 	return (DCMD_OK);
34820Sstevel@tonic-gate }
34830Sstevel@tonic-gate 
34840Sstevel@tonic-gate /*ARGSUSED*/
34850Sstevel@tonic-gate int
34860Sstevel@tonic-gate addr2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
34870Sstevel@tonic-gate {
34880Sstevel@tonic-gate 	uintptr_t kaddr;
34890Sstevel@tonic-gate 	struct seg seg;
34900Sstevel@tonic-gate 	struct segmap_data sd;
34910Sstevel@tonic-gate 
34920Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
34930Sstevel@tonic-gate 		return (DCMD_USAGE);
34940Sstevel@tonic-gate 
34950Sstevel@tonic-gate 	if (mdb_readvar(&kaddr, "segkmap") == -1) {
34960Sstevel@tonic-gate 		mdb_warn("failed to read segkmap");
34970Sstevel@tonic-gate 		return (DCMD_ERR);
34980Sstevel@tonic-gate 	}
34990Sstevel@tonic-gate 
35000Sstevel@tonic-gate 	if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) {
35010Sstevel@tonic-gate 		mdb_warn("failed to read segkmap at %p", kaddr);
35020Sstevel@tonic-gate 		return (DCMD_ERR);
35030Sstevel@tonic-gate 	}
35040Sstevel@tonic-gate 
35050Sstevel@tonic-gate 	if (mdb_vread(&sd, sizeof (sd), (uintptr_t)seg.s_data) == -1) {
35060Sstevel@tonic-gate 		mdb_warn("failed to read segmap_data at %p", seg.s_data);
35070Sstevel@tonic-gate 		return (DCMD_ERR);
35080Sstevel@tonic-gate 	}
35090Sstevel@tonic-gate 
35100Sstevel@tonic-gate 	mdb_printf("%p is smap %p\n", addr,
35110Sstevel@tonic-gate 	    ((addr - (uintptr_t)seg.s_base) >> MAXBSHIFT) *
35120Sstevel@tonic-gate 	    sizeof (struct smap) + (uintptr_t)sd.smd_sm);
35130Sstevel@tonic-gate 
35140Sstevel@tonic-gate 	return (DCMD_OK);
35150Sstevel@tonic-gate }
35160Sstevel@tonic-gate 
35170Sstevel@tonic-gate int
35180Sstevel@tonic-gate as2proc_walk(uintptr_t addr, const proc_t *p, struct as **asp)
35190Sstevel@tonic-gate {
35200Sstevel@tonic-gate 	if (p->p_as == *asp)
35210Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
35220Sstevel@tonic-gate 	return (WALK_NEXT);
35230Sstevel@tonic-gate }
35240Sstevel@tonic-gate 
35250Sstevel@tonic-gate /*ARGSUSED*/
35260Sstevel@tonic-gate int
35270Sstevel@tonic-gate as2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
35280Sstevel@tonic-gate {
35290Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC) || argc != 0)
35300Sstevel@tonic-gate 		return (DCMD_USAGE);
35310Sstevel@tonic-gate 
35320Sstevel@tonic-gate 	if (mdb_walk("proc", (mdb_walk_cb_t)as2proc_walk, &addr) == -1) {
35330Sstevel@tonic-gate 		mdb_warn("failed to walk proc");
35340Sstevel@tonic-gate 		return (DCMD_ERR);
35350Sstevel@tonic-gate 	}
35360Sstevel@tonic-gate 
35370Sstevel@tonic-gate 	return (DCMD_OK);
35380Sstevel@tonic-gate }
35390Sstevel@tonic-gate 
35400Sstevel@tonic-gate /*ARGSUSED*/
35410Sstevel@tonic-gate int
35420Sstevel@tonic-gate ptree_walk(uintptr_t addr, const proc_t *p, void *ignored)
35430Sstevel@tonic-gate {
35440Sstevel@tonic-gate 	proc_t parent;
35450Sstevel@tonic-gate 	int ident = 0;
35460Sstevel@tonic-gate 	uintptr_t paddr;
35470Sstevel@tonic-gate 
35480Sstevel@tonic-gate 	for (paddr = (uintptr_t)p->p_parent; paddr != NULL; ident += 5) {
35490Sstevel@tonic-gate 		mdb_vread(&parent, sizeof (parent), paddr);
35500Sstevel@tonic-gate 		paddr = (uintptr_t)parent.p_parent;
35510Sstevel@tonic-gate 	}
35520Sstevel@tonic-gate 
35530Sstevel@tonic-gate 	mdb_inc_indent(ident);
35540Sstevel@tonic-gate 	mdb_printf("%0?p  %s\n", addr, p->p_user.u_comm);
35550Sstevel@tonic-gate 	mdb_dec_indent(ident);
35560Sstevel@tonic-gate 
35570Sstevel@tonic-gate 	return (WALK_NEXT);
35580Sstevel@tonic-gate }
35590Sstevel@tonic-gate 
35600Sstevel@tonic-gate void
35610Sstevel@tonic-gate ptree_ancestors(uintptr_t addr, uintptr_t start)
35620Sstevel@tonic-gate {
35630Sstevel@tonic-gate 	proc_t p;
35640Sstevel@tonic-gate 
35650Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (p), addr) == -1) {
35660Sstevel@tonic-gate 		mdb_warn("couldn't read ancestor at %p", addr);
35670Sstevel@tonic-gate 		return;
35680Sstevel@tonic-gate 	}
35690Sstevel@tonic-gate 
35700Sstevel@tonic-gate 	if (p.p_parent != NULL)
35710Sstevel@tonic-gate 		ptree_ancestors((uintptr_t)p.p_parent, start);
35720Sstevel@tonic-gate 
35730Sstevel@tonic-gate 	if (addr != start)
35740Sstevel@tonic-gate 		(void) ptree_walk(addr, &p, NULL);
35750Sstevel@tonic-gate }
35760Sstevel@tonic-gate 
35770Sstevel@tonic-gate /*ARGSUSED*/
35780Sstevel@tonic-gate int
35790Sstevel@tonic-gate ptree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
35800Sstevel@tonic-gate {
35810Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
35820Sstevel@tonic-gate 		addr = NULL;
35830Sstevel@tonic-gate 	else
35840Sstevel@tonic-gate 		ptree_ancestors(addr, addr);
35850Sstevel@tonic-gate 
35860Sstevel@tonic-gate 	if (mdb_pwalk("proc", (mdb_walk_cb_t)ptree_walk, NULL, addr) == -1) {
35870Sstevel@tonic-gate 		mdb_warn("couldn't walk 'proc'");
35880Sstevel@tonic-gate 		return (DCMD_ERR);
35890Sstevel@tonic-gate 	}
35900Sstevel@tonic-gate 
35910Sstevel@tonic-gate 	return (DCMD_OK);
35920Sstevel@tonic-gate }
35930Sstevel@tonic-gate 
35940Sstevel@tonic-gate /*ARGSUSED*/
35950Sstevel@tonic-gate static int
35960Sstevel@tonic-gate fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
35970Sstevel@tonic-gate {
35980Sstevel@tonic-gate 	int fdnum;
35990Sstevel@tonic-gate 	const mdb_arg_t *argp = &argv[0];
36000Sstevel@tonic-gate 	proc_t p;
36010Sstevel@tonic-gate 	uf_entry_t uf;
36020Sstevel@tonic-gate 
36030Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
36040Sstevel@tonic-gate 		mdb_warn("fd doesn't give global information\n");
36050Sstevel@tonic-gate 		return (DCMD_ERR);
36060Sstevel@tonic-gate 	}
36070Sstevel@tonic-gate 	if (argc != 1)
36080Sstevel@tonic-gate 		return (DCMD_USAGE);
36090Sstevel@tonic-gate 
36100Sstevel@tonic-gate 	if (argp->a_type == MDB_TYPE_IMMEDIATE)
36110Sstevel@tonic-gate 		fdnum = argp->a_un.a_val;
36120Sstevel@tonic-gate 	else
36130Sstevel@tonic-gate 		fdnum = mdb_strtoull(argp->a_un.a_str);
36140Sstevel@tonic-gate 
36150Sstevel@tonic-gate 	if (mdb_vread(&p, sizeof (struct proc), addr) == -1) {
36160Sstevel@tonic-gate 		mdb_warn("couldn't read proc_t at %p", addr);
36170Sstevel@tonic-gate 		return (DCMD_ERR);
36180Sstevel@tonic-gate 	}
36190Sstevel@tonic-gate 	if (fdnum > p.p_user.u_finfo.fi_nfiles) {
36200Sstevel@tonic-gate 		mdb_warn("process %p only has %d files open.\n",
36210Sstevel@tonic-gate 		    addr, p.p_user.u_finfo.fi_nfiles);
36220Sstevel@tonic-gate 		return (DCMD_ERR);
36230Sstevel@tonic-gate 	}
36240Sstevel@tonic-gate 	if (mdb_vread(&uf, sizeof (uf_entry_t),
36250Sstevel@tonic-gate 	    (uintptr_t)&p.p_user.u_finfo.fi_list[fdnum]) == -1) {
36260Sstevel@tonic-gate 		mdb_warn("couldn't read uf_entry_t at %p",
36270Sstevel@tonic-gate 		    &p.p_user.u_finfo.fi_list[fdnum]);
36280Sstevel@tonic-gate 		return (DCMD_ERR);
36290Sstevel@tonic-gate 	}
36300Sstevel@tonic-gate 
36310Sstevel@tonic-gate 	mdb_printf("%p\n", uf.uf_file);
36320Sstevel@tonic-gate 	return (DCMD_OK);
36330Sstevel@tonic-gate }
36340Sstevel@tonic-gate 
36350Sstevel@tonic-gate /*ARGSUSED*/
36360Sstevel@tonic-gate static int
36370Sstevel@tonic-gate pid2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
36380Sstevel@tonic-gate {
36390Sstevel@tonic-gate 	pid_t pid = (pid_t)addr;
36400Sstevel@tonic-gate 
36410Sstevel@tonic-gate 	if (argc != 0)
36420Sstevel@tonic-gate 		return (DCMD_USAGE);
36430Sstevel@tonic-gate 
36440Sstevel@tonic-gate 	if ((addr = mdb_pid2proc(pid, NULL)) == NULL) {
36450Sstevel@tonic-gate 		mdb_warn("PID 0t%d not found\n", pid);
36460Sstevel@tonic-gate 		return (DCMD_ERR);
36470Sstevel@tonic-gate 	}
36480Sstevel@tonic-gate 
36490Sstevel@tonic-gate 	mdb_printf("%p\n", addr);
36500Sstevel@tonic-gate 	return (DCMD_OK);
36510Sstevel@tonic-gate }
36520Sstevel@tonic-gate 
36530Sstevel@tonic-gate static char *sysfile_cmd[] = {
36540Sstevel@tonic-gate 	"exclude:",
36550Sstevel@tonic-gate 	"include:",
36560Sstevel@tonic-gate 	"forceload:",
36570Sstevel@tonic-gate 	"rootdev:",
36580Sstevel@tonic-gate 	"rootfs:",
36590Sstevel@tonic-gate 	"swapdev:",
36600Sstevel@tonic-gate 	"swapfs:",
36610Sstevel@tonic-gate 	"moddir:",
36620Sstevel@tonic-gate 	"set",
36630Sstevel@tonic-gate 	"unknown",
36640Sstevel@tonic-gate };
36650Sstevel@tonic-gate 
36660Sstevel@tonic-gate static char *sysfile_ops[] = { "", "=", "&", "|" };
36670Sstevel@tonic-gate 
36680Sstevel@tonic-gate /*ARGSUSED*/
36690Sstevel@tonic-gate static int
36700Sstevel@tonic-gate sysfile_vmem_seg(uintptr_t addr, const vmem_seg_t *vsp, void **target)
36710Sstevel@tonic-gate {
36720Sstevel@tonic-gate 	if (vsp->vs_type == VMEM_ALLOC && (void *)vsp->vs_start == *target) {
36730Sstevel@tonic-gate 		*target = NULL;
36740Sstevel@tonic-gate 		return (WALK_DONE);
36750Sstevel@tonic-gate 	}
36760Sstevel@tonic-gate 	return (WALK_NEXT);
36770Sstevel@tonic-gate }
36780Sstevel@tonic-gate 
36790Sstevel@tonic-gate /*ARGSUSED*/
36800Sstevel@tonic-gate static int
36810Sstevel@tonic-gate sysfile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
36820Sstevel@tonic-gate {
36830Sstevel@tonic-gate 	struct sysparam *sysp, sys;
36840Sstevel@tonic-gate 	char var[256];
36850Sstevel@tonic-gate 	char modname[256];
36860Sstevel@tonic-gate 	char val[256];
36870Sstevel@tonic-gate 	char strval[256];
36880Sstevel@tonic-gate 	vmem_t *mod_sysfile_arena;
36890Sstevel@tonic-gate 	void *straddr;
36900Sstevel@tonic-gate 
36910Sstevel@tonic-gate 	if (mdb_readvar(&sysp, "sysparam_hd") == -1) {
36920Sstevel@tonic-gate 		mdb_warn("failed to read sysparam_hd");
36930Sstevel@tonic-gate 		return (DCMD_ERR);
36940Sstevel@tonic-gate 	}
36950Sstevel@tonic-gate 
36960Sstevel@tonic-gate 	if (mdb_readvar(&mod_sysfile_arena, "mod_sysfile_arena") == -1) {
36970Sstevel@tonic-gate 		mdb_warn("failed to read mod_sysfile_arena");
36980Sstevel@tonic-gate 		return (DCMD_ERR);
36990Sstevel@tonic-gate 	}
37000Sstevel@tonic-gate 
37010Sstevel@tonic-gate 	while (sysp != NULL) {
37020Sstevel@tonic-gate 		var[0] = '\0';
37030Sstevel@tonic-gate 		val[0] = '\0';
37040Sstevel@tonic-gate 		modname[0] = '\0';
37050Sstevel@tonic-gate 		if (mdb_vread(&sys, sizeof (sys), (uintptr_t)sysp) == -1) {
37060Sstevel@tonic-gate 			mdb_warn("couldn't read sysparam %p", sysp);
37070Sstevel@tonic-gate 			return (DCMD_ERR);
37080Sstevel@tonic-gate 		}
37090Sstevel@tonic-gate 		if (sys.sys_modnam != NULL &&
37100Sstevel@tonic-gate 		    mdb_readstr(modname, 256,
37110Sstevel@tonic-gate 		    (uintptr_t)sys.sys_modnam) == -1) {
37120Sstevel@tonic-gate 			mdb_warn("couldn't read modname in %p", sysp);
37130Sstevel@tonic-gate 			return (DCMD_ERR);
37140Sstevel@tonic-gate 		}
37150Sstevel@tonic-gate 		if (sys.sys_ptr != NULL &&
37160Sstevel@tonic-gate 		    mdb_readstr(var, 256, (uintptr_t)sys.sys_ptr) == -1) {
37170Sstevel@tonic-gate 			mdb_warn("couldn't read ptr in %p", sysp);
37180Sstevel@tonic-gate 			return (DCMD_ERR);
37190Sstevel@tonic-gate 		}
37200Sstevel@tonic-gate 		if (sys.sys_op != SETOP_NONE) {
37210Sstevel@tonic-gate 			/*
37220Sstevel@tonic-gate 			 * Is this an int or a string?  We determine this
37230Sstevel@tonic-gate 			 * by checking whether straddr is contained in
37240Sstevel@tonic-gate 			 * mod_sysfile_arena.  If so, the walker will set
37250Sstevel@tonic-gate 			 * straddr to NULL.
37260Sstevel@tonic-gate 			 */
37270Sstevel@tonic-gate 			straddr = (void *)(uintptr_t)sys.sys_info;
37280Sstevel@tonic-gate 			if (sys.sys_op == SETOP_ASSIGN &&
37290Sstevel@tonic-gate 			    sys.sys_info != 0 &&
37300Sstevel@tonic-gate 			    mdb_pwalk("vmem_seg",
37310Sstevel@tonic-gate 			    (mdb_walk_cb_t)sysfile_vmem_seg, &straddr,
37320Sstevel@tonic-gate 			    (uintptr_t)mod_sysfile_arena) == 0 &&
37330Sstevel@tonic-gate 			    straddr == NULL &&
37340Sstevel@tonic-gate 			    mdb_readstr(strval, 256,
37350Sstevel@tonic-gate 			    (uintptr_t)sys.sys_info) != -1) {
37360Sstevel@tonic-gate 				(void) mdb_snprintf(val, sizeof (val), "\"%s\"",
37370Sstevel@tonic-gate 				    strval);
37380Sstevel@tonic-gate 			} else {
37390Sstevel@tonic-gate 				(void) mdb_snprintf(val, sizeof (val),
37400Sstevel@tonic-gate 				    "0x%llx [0t%llu]", sys.sys_info,
37410Sstevel@tonic-gate 				    sys.sys_info);
37420Sstevel@tonic-gate 			}
37430Sstevel@tonic-gate 		}
37440Sstevel@tonic-gate 		mdb_printf("%s %s%s%s%s%s\n", sysfile_cmd[sys.sys_type],
37450Sstevel@tonic-gate 		    modname, modname[0] == '\0' ? "" : ":",
37460Sstevel@tonic-gate 		    var, sysfile_ops[sys.sys_op], val);
37470Sstevel@tonic-gate 
37480Sstevel@tonic-gate 		sysp = sys.sys_next;
37490Sstevel@tonic-gate 	}
37500Sstevel@tonic-gate 
37510Sstevel@tonic-gate 	return (DCMD_OK);
37520Sstevel@tonic-gate }
37530Sstevel@tonic-gate 
37540Sstevel@tonic-gate /*
37550Sstevel@tonic-gate  * Dump a taskq_ent_t given its address.
37560Sstevel@tonic-gate  */
37570Sstevel@tonic-gate /*ARGSUSED*/
37580Sstevel@tonic-gate int
37590Sstevel@tonic-gate taskq_ent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
37600Sstevel@tonic-gate {
37610Sstevel@tonic-gate 	taskq_ent_t	taskq_ent;
37620Sstevel@tonic-gate 	GElf_Sym	sym;
37630Sstevel@tonic-gate 	char		buf[MDB_SYM_NAMLEN+1];
37640Sstevel@tonic-gate 
37650Sstevel@tonic-gate 
37660Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
37670Sstevel@tonic-gate 		mdb_warn("expected explicit taskq_ent_t address before ::\n");
37680Sstevel@tonic-gate 		return (DCMD_USAGE);
37690Sstevel@tonic-gate 	}
37700Sstevel@tonic-gate 
37710Sstevel@tonic-gate 	if (mdb_vread(&taskq_ent, sizeof (taskq_ent_t), addr) == -1) {
37720Sstevel@tonic-gate 		mdb_warn("failed to read taskq_ent_t at %p", addr);
37730Sstevel@tonic-gate 		return (DCMD_ERR);
37740Sstevel@tonic-gate 	}
37750Sstevel@tonic-gate 
37760Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
37770Sstevel@tonic-gate 		mdb_printf("%<u>%-?s    %-?s    %-s%</u>\n",
37780Sstevel@tonic-gate 		"ENTRY", "ARG", "FUNCTION");
37790Sstevel@tonic-gate 	}
37800Sstevel@tonic-gate 
37810Sstevel@tonic-gate 	if (mdb_lookup_by_addr((uintptr_t)taskq_ent.tqent_func, MDB_SYM_EXACT,
37820Sstevel@tonic-gate 	    buf, sizeof (buf), &sym) == -1) {
37830Sstevel@tonic-gate 		(void) strcpy(buf, "????");
37840Sstevel@tonic-gate 	}
37850Sstevel@tonic-gate 
37860Sstevel@tonic-gate 	mdb_printf("%-?p    %-?p    %s\n", addr, taskq_ent.tqent_arg, buf);
37870Sstevel@tonic-gate 
37880Sstevel@tonic-gate 	return (DCMD_OK);
37890Sstevel@tonic-gate }
37900Sstevel@tonic-gate 
37910Sstevel@tonic-gate /*
37920Sstevel@tonic-gate  * Given the address of the (taskq_t) task queue head, walk the queue listing
37930Sstevel@tonic-gate  * the address of every taskq_ent_t.
37940Sstevel@tonic-gate  */
37950Sstevel@tonic-gate int
37960Sstevel@tonic-gate taskq_walk_init(mdb_walk_state_t *wsp)
37970Sstevel@tonic-gate {
37980Sstevel@tonic-gate 	taskq_t	tq_head;
37990Sstevel@tonic-gate 
38000Sstevel@tonic-gate 
38010Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
38020Sstevel@tonic-gate 		mdb_warn("start address required\n");
38030Sstevel@tonic-gate 		return (WALK_ERR);
38040Sstevel@tonic-gate 	}
38050Sstevel@tonic-gate 
38060Sstevel@tonic-gate 
38070Sstevel@tonic-gate 	/*
38080Sstevel@tonic-gate 	 * Save the address of the list head entry.  This terminates the list.
38090Sstevel@tonic-gate 	 */
38100Sstevel@tonic-gate 	wsp->walk_data = (void *)
38110Sstevel@tonic-gate 	    ((size_t)wsp->walk_addr + offsetof(taskq_t, tq_task));
38120Sstevel@tonic-gate 
38130Sstevel@tonic-gate 
38140Sstevel@tonic-gate 	/*
38150Sstevel@tonic-gate 	 * Read in taskq head, set walk_addr to point to first taskq_ent_t.
38160Sstevel@tonic-gate 	 */
38170Sstevel@tonic-gate 	if (mdb_vread((void *)&tq_head, sizeof (taskq_t), wsp->walk_addr) ==
38180Sstevel@tonic-gate 	    -1) {
38190Sstevel@tonic-gate 		mdb_warn("failed to read taskq list head at %p",
38200Sstevel@tonic-gate 		    wsp->walk_addr);
38210Sstevel@tonic-gate 	}
38220Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)tq_head.tq_task.tqent_next;
38230Sstevel@tonic-gate 
38240Sstevel@tonic-gate 
38250Sstevel@tonic-gate 	/*
38260Sstevel@tonic-gate 	 * Check for null list (next=head)
38270Sstevel@tonic-gate 	 */
38280Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data) {
38290Sstevel@tonic-gate 		return (WALK_DONE);
38300Sstevel@tonic-gate 	}
38310Sstevel@tonic-gate 
38320Sstevel@tonic-gate 	return (WALK_NEXT);
38330Sstevel@tonic-gate }
38340Sstevel@tonic-gate 
38350Sstevel@tonic-gate 
38360Sstevel@tonic-gate int
38370Sstevel@tonic-gate taskq_walk_step(mdb_walk_state_t *wsp)
38380Sstevel@tonic-gate {
38390Sstevel@tonic-gate 	taskq_ent_t	tq_ent;
38400Sstevel@tonic-gate 	int		status;
38410Sstevel@tonic-gate 
38420Sstevel@tonic-gate 
38430Sstevel@tonic-gate 	if (mdb_vread((void *)&tq_ent, sizeof (taskq_ent_t), wsp->walk_addr) ==
38440Sstevel@tonic-gate 	    -1) {
38450Sstevel@tonic-gate 		mdb_warn("failed to read taskq_ent_t at %p", wsp->walk_addr);
38460Sstevel@tonic-gate 		return (DCMD_ERR);
38470Sstevel@tonic-gate 	}
38480Sstevel@tonic-gate 
38490Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, (void *)&tq_ent,
38500Sstevel@tonic-gate 	    wsp->walk_cbdata);
38510Sstevel@tonic-gate 
38520Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)tq_ent.tqent_next;
38530Sstevel@tonic-gate 
38540Sstevel@tonic-gate 
38550Sstevel@tonic-gate 	/* Check if we're at the last element (next=head) */
38560Sstevel@tonic-gate 	if (wsp->walk_addr == (uintptr_t)wsp->walk_data) {
38570Sstevel@tonic-gate 		return (WALK_DONE);
38580Sstevel@tonic-gate 	}
38590Sstevel@tonic-gate 
38600Sstevel@tonic-gate 	return (status);
38610Sstevel@tonic-gate }
38620Sstevel@tonic-gate 
38630Sstevel@tonic-gate int
38640Sstevel@tonic-gate didmatch(uintptr_t addr, const kthread_t *thr, kt_did_t *didp)
38650Sstevel@tonic-gate {
38660Sstevel@tonic-gate 
38670Sstevel@tonic-gate 	if (*didp == thr->t_did) {
38680Sstevel@tonic-gate 		mdb_printf("%p\n", addr);
38690Sstevel@tonic-gate 		return (WALK_DONE);
38700Sstevel@tonic-gate 	} else
38710Sstevel@tonic-gate 		return (WALK_NEXT);
38720Sstevel@tonic-gate }
38730Sstevel@tonic-gate 
38740Sstevel@tonic-gate /*ARGSUSED*/
38750Sstevel@tonic-gate int
38760Sstevel@tonic-gate did2thread(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
38770Sstevel@tonic-gate {
38780Sstevel@tonic-gate 	const mdb_arg_t *argp = &argv[0];
38790Sstevel@tonic-gate 	kt_did_t	did;
38800Sstevel@tonic-gate 
38810Sstevel@tonic-gate 	if (argc != 1)
38820Sstevel@tonic-gate 		return (DCMD_USAGE);
38830Sstevel@tonic-gate 
38840Sstevel@tonic-gate 	did = (kt_did_t)mdb_strtoull(argp->a_un.a_str);
38850Sstevel@tonic-gate 
38860Sstevel@tonic-gate 	if (mdb_walk("thread", (mdb_walk_cb_t)didmatch, (void *)&did) == -1) {
38870Sstevel@tonic-gate 		mdb_warn("failed to walk thread");
38880Sstevel@tonic-gate 		return (DCMD_ERR);
38890Sstevel@tonic-gate 
38900Sstevel@tonic-gate 	}
38910Sstevel@tonic-gate 	return (DCMD_OK);
38920Sstevel@tonic-gate 
38930Sstevel@tonic-gate }
38940Sstevel@tonic-gate 
38950Sstevel@tonic-gate static int
38960Sstevel@tonic-gate errorq_walk_init(mdb_walk_state_t *wsp)
38970Sstevel@tonic-gate {
38980Sstevel@tonic-gate 	if (wsp->walk_addr == NULL &&
38990Sstevel@tonic-gate 	    mdb_readvar(&wsp->walk_addr, "errorq_list") == -1) {
39000Sstevel@tonic-gate 		mdb_warn("failed to read errorq_list");
39010Sstevel@tonic-gate 		return (WALK_ERR);
39020Sstevel@tonic-gate 	}
39030Sstevel@tonic-gate 
39040Sstevel@tonic-gate 	return (WALK_NEXT);
39050Sstevel@tonic-gate }
39060Sstevel@tonic-gate 
39070Sstevel@tonic-gate static int
39080Sstevel@tonic-gate errorq_walk_step(mdb_walk_state_t *wsp)
39090Sstevel@tonic-gate {
39100Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
39110Sstevel@tonic-gate 	errorq_t eq;
39120Sstevel@tonic-gate 
39130Sstevel@tonic-gate 	if (addr == NULL)
39140Sstevel@tonic-gate 		return (WALK_DONE);
39150Sstevel@tonic-gate 
39160Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), addr) == -1) {
39170Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", addr);
39180Sstevel@tonic-gate 		return (WALK_ERR);
39190Sstevel@tonic-gate 	}
39200Sstevel@tonic-gate 
39210Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)eq.eq_next;
39220Sstevel@tonic-gate 	return (wsp->walk_callback(addr, &eq, wsp->walk_cbdata));
39230Sstevel@tonic-gate }
39240Sstevel@tonic-gate 
39250Sstevel@tonic-gate typedef struct eqd_walk_data {
39260Sstevel@tonic-gate 	uintptr_t *eqd_stack;
39270Sstevel@tonic-gate 	void *eqd_buf;
39280Sstevel@tonic-gate 	ulong_t eqd_qpos;
39290Sstevel@tonic-gate 	ulong_t eqd_qlen;
39300Sstevel@tonic-gate 	size_t eqd_size;
39310Sstevel@tonic-gate } eqd_walk_data_t;
39320Sstevel@tonic-gate 
39330Sstevel@tonic-gate /*
39340Sstevel@tonic-gate  * In order to walk the list of pending error queue elements, we push the
39350Sstevel@tonic-gate  * addresses of the corresponding data buffers in to the eqd_stack array.
39360Sstevel@tonic-gate  * The error lists are in reverse chronological order when iterating using
39370Sstevel@tonic-gate  * eqe_prev, so we then pop things off the top in eqd_walk_step so that the
39380Sstevel@tonic-gate  * walker client gets addresses in order from oldest error to newest error.
39390Sstevel@tonic-gate  */
39400Sstevel@tonic-gate static void
39410Sstevel@tonic-gate eqd_push_list(eqd_walk_data_t *eqdp, uintptr_t addr)
39420Sstevel@tonic-gate {
39430Sstevel@tonic-gate 	errorq_elem_t eqe;
39440Sstevel@tonic-gate 
39450Sstevel@tonic-gate 	while (addr != NULL) {
39460Sstevel@tonic-gate 		if (mdb_vread(&eqe, sizeof (eqe), addr) != sizeof (eqe)) {
39470Sstevel@tonic-gate 			mdb_warn("failed to read errorq element at %p", addr);
39480Sstevel@tonic-gate 			break;
39490Sstevel@tonic-gate 		}
39500Sstevel@tonic-gate 
39510Sstevel@tonic-gate 		if (eqdp->eqd_qpos == eqdp->eqd_qlen) {
39520Sstevel@tonic-gate 			mdb_warn("errorq is overfull -- more than %lu "
39530Sstevel@tonic-gate 			    "elems found\n", eqdp->eqd_qlen);
39540Sstevel@tonic-gate 			break;
39550Sstevel@tonic-gate 		}
39560Sstevel@tonic-gate 
39570Sstevel@tonic-gate 		eqdp->eqd_stack[eqdp->eqd_qpos++] = (uintptr_t)eqe.eqe_data;
39580Sstevel@tonic-gate 		addr = (uintptr_t)eqe.eqe_prev;
39590Sstevel@tonic-gate 	}
39600Sstevel@tonic-gate }
39610Sstevel@tonic-gate 
39620Sstevel@tonic-gate static int
39630Sstevel@tonic-gate eqd_walk_init(mdb_walk_state_t *wsp)
39640Sstevel@tonic-gate {
39650Sstevel@tonic-gate 	eqd_walk_data_t *eqdp;
39660Sstevel@tonic-gate 	errorq_elem_t eqe, *addr;
39670Sstevel@tonic-gate 	errorq_t eq;
39680Sstevel@tonic-gate 	ulong_t i;
39690Sstevel@tonic-gate 
39700Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), wsp->walk_addr) == -1) {
39710Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", wsp->walk_addr);
39720Sstevel@tonic-gate 		return (WALK_ERR);
39730Sstevel@tonic-gate 	}
39740Sstevel@tonic-gate 
39750Sstevel@tonic-gate 	if (eq.eq_ptail != NULL &&
39760Sstevel@tonic-gate 	    mdb_vread(&eqe, sizeof (eqe), (uintptr_t)eq.eq_ptail) == -1) {
39770Sstevel@tonic-gate 		mdb_warn("failed to read errorq element at %p", eq.eq_ptail);
39780Sstevel@tonic-gate 		return (WALK_ERR);
39790Sstevel@tonic-gate 	}
39800Sstevel@tonic-gate 
39810Sstevel@tonic-gate 	eqdp = mdb_alloc(sizeof (eqd_walk_data_t), UM_SLEEP);
39820Sstevel@tonic-gate 	wsp->walk_data = eqdp;
39830Sstevel@tonic-gate 
39840Sstevel@tonic-gate 	eqdp->eqd_stack = mdb_zalloc(sizeof (uintptr_t) * eq.eq_qlen, UM_SLEEP);
39850Sstevel@tonic-gate 	eqdp->eqd_buf = mdb_alloc(eq.eq_size, UM_SLEEP);
39860Sstevel@tonic-gate 	eqdp->eqd_qlen = eq.eq_qlen;
39870Sstevel@tonic-gate 	eqdp->eqd_qpos = 0;
39880Sstevel@tonic-gate 	eqdp->eqd_size = eq.eq_size;
39890Sstevel@tonic-gate 
39900Sstevel@tonic-gate 	/*
39910Sstevel@tonic-gate 	 * The newest elements in the queue are on the pending list, so we
39920Sstevel@tonic-gate 	 * push those on to our stack first.
39930Sstevel@tonic-gate 	 */
39940Sstevel@tonic-gate 	eqd_push_list(eqdp, (uintptr_t)eq.eq_pend);
39950Sstevel@tonic-gate 
39960Sstevel@tonic-gate 	/*
39970Sstevel@tonic-gate 	 * If eq_ptail is set, it may point to a subset of the errors on the
39980Sstevel@tonic-gate 	 * pending list in the event a casptr() failed; if ptail's data is
39990Sstevel@tonic-gate 	 * already in our stack, NULL out eq_ptail and ignore it.
40000Sstevel@tonic-gate 	 */
40010Sstevel@tonic-gate 	if (eq.eq_ptail != NULL) {
40020Sstevel@tonic-gate 		for (i = 0; i < eqdp->eqd_qpos; i++) {
40030Sstevel@tonic-gate 			if (eqdp->eqd_stack[i] == (uintptr_t)eqe.eqe_data) {
40040Sstevel@tonic-gate 				eq.eq_ptail = NULL;
40050Sstevel@tonic-gate 				break;
40060Sstevel@tonic-gate 			}
40070Sstevel@tonic-gate 		}
40080Sstevel@tonic-gate 	}
40090Sstevel@tonic-gate 
40100Sstevel@tonic-gate 	/*
40110Sstevel@tonic-gate 	 * If eq_phead is set, it has the processing list in order from oldest
40120Sstevel@tonic-gate 	 * to newest.  Use this to recompute eq_ptail as best we can and then
40130Sstevel@tonic-gate 	 * we nicely fall into eqd_push_list() of eq_ptail below.
40140Sstevel@tonic-gate 	 */
40150Sstevel@tonic-gate 	for (addr = eq.eq_phead; addr != NULL && mdb_vread(&eqe, sizeof (eqe),
40160Sstevel@tonic-gate 	    (uintptr_t)addr) == sizeof (eqe); addr = eqe.eqe_next)
40170Sstevel@tonic-gate 		eq.eq_ptail = addr;
40180Sstevel@tonic-gate 
40190Sstevel@tonic-gate 	/*
40200Sstevel@tonic-gate 	 * The oldest elements in the queue are on the processing list, subject
40210Sstevel@tonic-gate 	 * to machinations in the if-clauses above.  Push any such elements.
40220Sstevel@tonic-gate 	 */
40230Sstevel@tonic-gate 	eqd_push_list(eqdp, (uintptr_t)eq.eq_ptail);
40240Sstevel@tonic-gate 	return (WALK_NEXT);
40250Sstevel@tonic-gate }
40260Sstevel@tonic-gate 
40270Sstevel@tonic-gate static int
40280Sstevel@tonic-gate eqd_walk_step(mdb_walk_state_t *wsp)
40290Sstevel@tonic-gate {
40300Sstevel@tonic-gate 	eqd_walk_data_t *eqdp = wsp->walk_data;
40310Sstevel@tonic-gate 	uintptr_t addr;
40320Sstevel@tonic-gate 
40330Sstevel@tonic-gate 	if (eqdp->eqd_qpos == 0)
40340Sstevel@tonic-gate 		return (WALK_DONE);
40350Sstevel@tonic-gate 
40360Sstevel@tonic-gate 	addr = eqdp->eqd_stack[--eqdp->eqd_qpos];
40370Sstevel@tonic-gate 
40380Sstevel@tonic-gate 	if (mdb_vread(eqdp->eqd_buf, eqdp->eqd_size, addr) != eqdp->eqd_size) {
40390Sstevel@tonic-gate 		mdb_warn("failed to read errorq data at %p", addr);
40400Sstevel@tonic-gate 		return (WALK_ERR);
40410Sstevel@tonic-gate 	}
40420Sstevel@tonic-gate 
40430Sstevel@tonic-gate 	return (wsp->walk_callback(addr, eqdp->eqd_buf, wsp->walk_cbdata));
40440Sstevel@tonic-gate }
40450Sstevel@tonic-gate 
40460Sstevel@tonic-gate static void
40470Sstevel@tonic-gate eqd_walk_fini(mdb_walk_state_t *wsp)
40480Sstevel@tonic-gate {
40490Sstevel@tonic-gate 	eqd_walk_data_t *eqdp = wsp->walk_data;
40500Sstevel@tonic-gate 
40510Sstevel@tonic-gate 	mdb_free(eqdp->eqd_stack, sizeof (uintptr_t) * eqdp->eqd_qlen);
40520Sstevel@tonic-gate 	mdb_free(eqdp->eqd_buf, eqdp->eqd_size);
40530Sstevel@tonic-gate 	mdb_free(eqdp, sizeof (eqd_walk_data_t));
40540Sstevel@tonic-gate }
40550Sstevel@tonic-gate 
40560Sstevel@tonic-gate #define	EQKSVAL(eqv, what) (eqv.eq_kstat.what.value.ui64)
40570Sstevel@tonic-gate 
40580Sstevel@tonic-gate static int
40590Sstevel@tonic-gate errorq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
40600Sstevel@tonic-gate {
40610Sstevel@tonic-gate 	int i;
40620Sstevel@tonic-gate 	errorq_t eq;
40630Sstevel@tonic-gate 	uint_t opt_v = FALSE;
40640Sstevel@tonic-gate 
40650Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
40660Sstevel@tonic-gate 		if (mdb_walk_dcmd("errorq", "errorq", argc, argv) == -1) {
40670Sstevel@tonic-gate 			mdb_warn("can't walk 'errorq'");
40680Sstevel@tonic-gate 			return (DCMD_ERR);
40690Sstevel@tonic-gate 		}
40700Sstevel@tonic-gate 		return (DCMD_OK);
40710Sstevel@tonic-gate 	}
40720Sstevel@tonic-gate 
40730Sstevel@tonic-gate 	i = mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &opt_v, NULL);
40740Sstevel@tonic-gate 	argc -= i;
40750Sstevel@tonic-gate 	argv += i;
40760Sstevel@tonic-gate 
40770Sstevel@tonic-gate 	if (argc != 0)
40780Sstevel@tonic-gate 		return (DCMD_USAGE);
40790Sstevel@tonic-gate 
40800Sstevel@tonic-gate 	if (opt_v || DCMD_HDRSPEC(flags)) {
40810Sstevel@tonic-gate 		mdb_printf("%<u>%-11s %-16s %1s %1s %1s ",
40820Sstevel@tonic-gate 		    "ADDR", "NAME", "S", "V", "N");
40830Sstevel@tonic-gate 		if (!opt_v) {
40840Sstevel@tonic-gate 			mdb_printf("%7s %7s %7s%</u>\n",
40850Sstevel@tonic-gate 			    "ACCEPT", "DROP", "LOG");
40860Sstevel@tonic-gate 		} else {
40870Sstevel@tonic-gate 			mdb_printf("%5s %6s %6s %3s %16s%</u>\n",
40880Sstevel@tonic-gate 			    "KSTAT", "QLEN", "SIZE", "IPL", "FUNC");
40890Sstevel@tonic-gate 		}
40900Sstevel@tonic-gate 	}
40910Sstevel@tonic-gate 
40920Sstevel@tonic-gate 	if (mdb_vread(&eq, sizeof (eq), addr) != sizeof (eq)) {
40930Sstevel@tonic-gate 		mdb_warn("failed to read errorq at %p", addr);
40940Sstevel@tonic-gate 		return (DCMD_ERR);
40950Sstevel@tonic-gate 	}
40960Sstevel@tonic-gate 
40970Sstevel@tonic-gate 	mdb_printf("%-11p %-16s %c %c %c ", addr, eq.eq_name,
40980Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_ACTIVE) ? '+' : '-',
40990Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_VITAL) ? '!' : ' ',
41000Sstevel@tonic-gate 	    (eq.eq_flags & ERRORQ_NVLIST) ? '*' : ' ');
41010Sstevel@tonic-gate 
41020Sstevel@tonic-gate 	if (!opt_v) {
41030Sstevel@tonic-gate 		mdb_printf("%7llu %7llu %7llu\n",
41040Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_dispatched) + EQKSVAL(eq, eqk_committed),
41050Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_dropped) + EQKSVAL(eq, eqk_reserve_fail) +
41060Sstevel@tonic-gate 		    EQKSVAL(eq, eqk_commit_fail), EQKSVAL(eq, eqk_logged));
41070Sstevel@tonic-gate 	} else {
41080Sstevel@tonic-gate 		mdb_printf("%5s %6lu %6lu %3u %a\n",
41090Sstevel@tonic-gate 		    "  |  ", eq.eq_qlen, eq.eq_size, eq.eq_ipl, eq.eq_func);
41100Sstevel@tonic-gate 		mdb_printf("%38s\n%41s"
41110Sstevel@tonic-gate 		    "%12s %llu\n"
41120Sstevel@tonic-gate 		    "%53s %llu\n"
41130Sstevel@tonic-gate 		    "%53s %llu\n"
41140Sstevel@tonic-gate 		    "%53s %llu\n"
41150Sstevel@tonic-gate 		    "%53s %llu\n"
41160Sstevel@tonic-gate 		    "%53s %llu\n"
41170Sstevel@tonic-gate 		    "%53s %llu\n"
41180Sstevel@tonic-gate 		    "%53s %llu\n\n",
41190Sstevel@tonic-gate 		    "|", "+-> ",
41200Sstevel@tonic-gate 		    "DISPATCHED",	EQKSVAL(eq, eqk_dispatched),
41210Sstevel@tonic-gate 		    "DROPPED",		EQKSVAL(eq, eqk_dropped),
41220Sstevel@tonic-gate 		    "LOGGED",		EQKSVAL(eq, eqk_logged),
41230Sstevel@tonic-gate 		    "RESERVED",		EQKSVAL(eq, eqk_reserved),
41240Sstevel@tonic-gate 		    "RESERVE FAIL",	EQKSVAL(eq, eqk_reserve_fail),
41250Sstevel@tonic-gate 		    "COMMITTED",	EQKSVAL(eq, eqk_committed),
41260Sstevel@tonic-gate 		    "COMMIT FAIL",	EQKSVAL(eq, eqk_commit_fail),
41270Sstevel@tonic-gate 		    "CANCELLED",	EQKSVAL(eq, eqk_cancelled));
41280Sstevel@tonic-gate 	}
41290Sstevel@tonic-gate 
41300Sstevel@tonic-gate 	return (DCMD_OK);
41310Sstevel@tonic-gate }
41320Sstevel@tonic-gate 
41330Sstevel@tonic-gate /*ARGSUSED*/
41340Sstevel@tonic-gate static int
41350Sstevel@tonic-gate panicinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
41360Sstevel@tonic-gate {
41370Sstevel@tonic-gate 	cpu_t panic_cpu;
41380Sstevel@tonic-gate 	kthread_t *panic_thread;
41394256Spetede 	void *buf;
41400Sstevel@tonic-gate 	panic_data_t *pd;
41410Sstevel@tonic-gate 	int i, n;
41420Sstevel@tonic-gate 
41430Sstevel@tonic-gate 	if (!mdb_prop_postmortem) {
41440Sstevel@tonic-gate 		mdb_warn("panicinfo can only be run on a system "
41450Sstevel@tonic-gate 		    "dump; see dumpadm(1M)\n");
41460Sstevel@tonic-gate 		return (DCMD_ERR);
41470Sstevel@tonic-gate 	}
41480Sstevel@tonic-gate 
41490Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC || argc != 0)
41500Sstevel@tonic-gate 		return (DCMD_USAGE);
41510Sstevel@tonic-gate 
41520Sstevel@tonic-gate 	if (mdb_readsym(&panic_cpu, sizeof (cpu_t), "panic_cpu") == -1)
41530Sstevel@tonic-gate 		mdb_warn("failed to read 'panic_cpu'");
41540Sstevel@tonic-gate 	else
41550Sstevel@tonic-gate 		mdb_printf("%16s %?d\n", "cpu", panic_cpu.cpu_id);
41560Sstevel@tonic-gate 
41570Sstevel@tonic-gate 	if (mdb_readvar(&panic_thread, "panic_thread") == -1)
41580Sstevel@tonic-gate 		mdb_warn("failed to read 'panic_thread'");
41590Sstevel@tonic-gate 	else
41600Sstevel@tonic-gate 		mdb_printf("%16s %?p\n", "thread", panic_thread);
41610Sstevel@tonic-gate 
41624256Spetede 	buf = mdb_alloc(PANICBUFSIZE, UM_SLEEP);
41634256Spetede 	pd = (panic_data_t *)buf;
41644256Spetede 
41654256Spetede 	if (mdb_readsym(buf, PANICBUFSIZE, "panicbuf") == -1 ||
41660Sstevel@tonic-gate 	    pd->pd_version != PANICBUFVERS) {
41670Sstevel@tonic-gate 		mdb_warn("failed to read 'panicbuf'");
41684256Spetede 		mdb_free(buf, PANICBUFSIZE);
41690Sstevel@tonic-gate 		return (DCMD_ERR);
41700Sstevel@tonic-gate 	}
41710Sstevel@tonic-gate 
41724256Spetede 	mdb_printf("%16s %s\n", "message",  (char *)buf + pd->pd_msgoff);
41730Sstevel@tonic-gate 
41740Sstevel@tonic-gate 	n = (pd->pd_msgoff - (sizeof (panic_data_t) -
41750Sstevel@tonic-gate 	    sizeof (panic_nv_t))) / sizeof (panic_nv_t);
41760Sstevel@tonic-gate 
41770Sstevel@tonic-gate 	for (i = 0; i < n; i++)
41780Sstevel@tonic-gate 		mdb_printf("%16s %?llx\n",
41790Sstevel@tonic-gate 		    pd->pd_nvdata[i].pnv_name, pd->pd_nvdata[i].pnv_value);
41800Sstevel@tonic-gate 
41814256Spetede 	mdb_free(buf, PANICBUFSIZE);
41820Sstevel@tonic-gate 	return (DCMD_OK);
41830Sstevel@tonic-gate }
41840Sstevel@tonic-gate 
41850Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
41860Sstevel@tonic-gate 
41870Sstevel@tonic-gate 	/* from genunix.c */
41880Sstevel@tonic-gate 	{ "addr2smap", ":[offset]", "translate address to smap", addr2smap },
41890Sstevel@tonic-gate 	{ "as2proc", ":", "convert as to proc_t address", as2proc },
41900Sstevel@tonic-gate 	{ "binding_hash_entry", ":", "print driver names hash table entry",
41910Sstevel@tonic-gate 		binding_hash_entry },
41928048SMadhavan.Venkataraman@Sun.COM 	{ "callout", "?[-r|n] [-s|l] [-xh] [-t | -ab nsec [-dkD]]"
41938048SMadhavan.Venkataraman@Sun.COM 	    " [-C addr | -S seqid] [-f name|addr] [-p name| addr] [-T|L [-E]]"
41948048SMadhavan.Venkataraman@Sun.COM 	    " [-FivVA]",
41958048SMadhavan.Venkataraman@Sun.COM 	    "display callouts", callout, callout_help },
41968048SMadhavan.Venkataraman@Sun.COM 	{ "calloutid", "[-d|v] xid", "print callout by extended id",
41978048SMadhavan.Venkataraman@Sun.COM 	    calloutid, calloutid_help },
41980Sstevel@tonic-gate 	{ "class", NULL, "print process scheduler classes", class },
41990Sstevel@tonic-gate 	{ "cpuinfo", "?[-v]", "print CPUs and runnable threads", cpuinfo },
42000Sstevel@tonic-gate 	{ "did2thread", "? kt_did", "find kernel thread for this id",
42010Sstevel@tonic-gate 		did2thread },
42020Sstevel@tonic-gate 	{ "errorq", "?[-v]", "display kernel error queues", errorq },
42030Sstevel@tonic-gate 	{ "fd", ":[fd num]", "get a file pointer from an fd", fd },
42040Sstevel@tonic-gate 	{ "flipone", ":", "the vik_rev_level 2 special", flipone },
42050Sstevel@tonic-gate 	{ "lminfo", NULL, "print lock manager information", lminfo },
42060Sstevel@tonic-gate 	{ "ndi_event_hdl", "?", "print ndi_event_hdl", ndi_event_hdl },
42070Sstevel@tonic-gate 	{ "panicinfo", NULL, "print panic information", panicinfo },
42080Sstevel@tonic-gate 	{ "pid2proc", "?", "convert PID to proc_t address", pid2proc },
42090Sstevel@tonic-gate 	{ "pmap", ":[-q]", "print process memory map", pmap },
42100Sstevel@tonic-gate 	{ "project", NULL, "display kernel project(s)", project },
42110Sstevel@tonic-gate 	{ "ps", "[-fltzTP]", "list processes (and associated thr,lwp)", ps },
42121014Svb160487 	{ "pgrep", "[-x] [-n | -o] pattern",
42131014Svb160487 		"pattern match against all processes", pgrep },
42140Sstevel@tonic-gate 	{ "ptree", NULL, "print process tree", ptree },
42150Sstevel@tonic-gate 	{ "seg", ":", "print address space segment", seg },
42160Sstevel@tonic-gate 	{ "sysevent", "?[-sv]", "print sysevent pending or sent queue",
42170Sstevel@tonic-gate 		sysevent},
42180Sstevel@tonic-gate 	{ "sysevent_channel", "?", "print sysevent channel database",
42190Sstevel@tonic-gate 		sysevent_channel},
42200Sstevel@tonic-gate 	{ "sysevent_class_list", ":", "print sysevent class list",
42210Sstevel@tonic-gate 		sysevent_class_list},
42220Sstevel@tonic-gate 	{ "sysevent_subclass_list", ":",
42230Sstevel@tonic-gate 		"print sysevent subclass list", sysevent_subclass_list},
42240Sstevel@tonic-gate 	{ "system", NULL, "print contents of /etc/system file", sysfile },
42250Sstevel@tonic-gate 	{ "task", NULL, "display kernel task(s)", task },
42260Sstevel@tonic-gate 	{ "taskq_entry", ":", "display a taskq_ent_t", taskq_ent },
42270Sstevel@tonic-gate 	{ "vnode2path", ":[-F]", "vnode address to pathname", vnode2path },
42280Sstevel@tonic-gate 	{ "vnode2smap", ":[offset]", "translate vnode to smap", vnode2smap },
42290Sstevel@tonic-gate 	{ "whereopen", ":", "given a vnode, dumps procs which have it open",
42300Sstevel@tonic-gate 	    whereopen },
42310Sstevel@tonic-gate 
42320Sstevel@tonic-gate 	/* from zone.c */
42330Sstevel@tonic-gate 	{ "zone", "?", "display kernel zone(s)", zoneprt },
4234*8111SJordan.Vaughan@Sun.com 	{ "zsd", ":[-v] [zsd_key]", "display zone-specific-data entries for "
4235*8111SJordan.Vaughan@Sun.com 	    "selected zones", zsd },
42360Sstevel@tonic-gate 
42370Sstevel@tonic-gate 	/* from bio.c */
42380Sstevel@tonic-gate 	{ "bufpagefind", ":addr", "find page_t on buf_t list", bufpagefind },
42390Sstevel@tonic-gate 
42400Sstevel@tonic-gate 	/* from contract.c */
42410Sstevel@tonic-gate 	{ "contract", "?", "display a contract", cmd_contract },
42420Sstevel@tonic-gate 	{ "ctevent", ":", "display a contract event", cmd_ctevent },
42430Sstevel@tonic-gate 	{ "ctid", ":", "convert id to a contract pointer", cmd_ctid },
42440Sstevel@tonic-gate 
42450Sstevel@tonic-gate 	/* from cpupart.c */
4246537Smishra 	{ "cpupart", "?[-v]", "print cpu partition info", cpupart },
42470Sstevel@tonic-gate 
42480Sstevel@tonic-gate 	/* from cyclic.c */
42490Sstevel@tonic-gate 	{ "cyccover", NULL, "dump cyclic coverage information", cyccover },
42500Sstevel@tonic-gate 	{ "cycid", "?", "dump a cyclic id", cycid },
42510Sstevel@tonic-gate 	{ "cycinfo", "?", "dump cyc_cpu info", cycinfo },
42520Sstevel@tonic-gate 	{ "cyclic", ":", "developer information", cyclic },
42530Sstevel@tonic-gate 	{ "cyctrace", "?", "dump cyclic trace buffer", cyctrace },
42540Sstevel@tonic-gate 
42550Sstevel@tonic-gate 	/* from devinfo.c */
42560Sstevel@tonic-gate 	{ "devbindings", "?[-qs] [device-name | major-num]",
42570Sstevel@tonic-gate 	    "print devinfo nodes bound to device-name or major-num",
42580Sstevel@tonic-gate 	    devbindings, devinfo_help },
42590Sstevel@tonic-gate 	{ "devinfo", ":[-qs]", "detailed devinfo of one node", devinfo,
42600Sstevel@tonic-gate 	    devinfo_help },
42610Sstevel@tonic-gate 	{ "devinfo_audit", ":[-v]", "devinfo configuration audit record",
42620Sstevel@tonic-gate 	    devinfo_audit },
42630Sstevel@tonic-gate 	{ "devinfo_audit_log", "?[-v]", "system wide devinfo configuration log",
42640Sstevel@tonic-gate 	    devinfo_audit_log },
42650Sstevel@tonic-gate 	{ "devinfo_audit_node", ":[-v]", "devinfo node configuration history",
42660Sstevel@tonic-gate 	    devinfo_audit_node },
42670Sstevel@tonic-gate 	{ "devinfo2driver", ":", "find driver name for this devinfo node",
42680Sstevel@tonic-gate 	    devinfo2driver },
42690Sstevel@tonic-gate 	{ "devnames", "?[-vm] [num]", "print devnames array", devnames },
42700Sstevel@tonic-gate 	{ "dev2major", "?<dev_t>", "convert dev_t to a major number",
42710Sstevel@tonic-gate 	    dev2major },
42720Sstevel@tonic-gate 	{ "dev2minor", "?<dev_t>", "convert dev_t to a minor number",
42730Sstevel@tonic-gate 	    dev2minor },
42740Sstevel@tonic-gate 	{ "devt", "?<dev_t>", "display a dev_t's major and minor numbers",
42750Sstevel@tonic-gate 	    devt },
42760Sstevel@tonic-gate 	{ "major2name", "?<major-num>", "convert major number to dev name",
42770Sstevel@tonic-gate 	    major2name },
42780Sstevel@tonic-gate 	{ "minornodes", ":", "given a devinfo node, print its minor nodes",
42790Sstevel@tonic-gate 	    minornodes },
42800Sstevel@tonic-gate 	{ "modctl2devinfo", ":", "given a modctl, list its devinfos",
42810Sstevel@tonic-gate 	    modctl2devinfo },
42820Sstevel@tonic-gate 	{ "name2major", "<dev-name>", "convert dev name to major number",
42830Sstevel@tonic-gate 	    name2major },
42840Sstevel@tonic-gate 	{ "prtconf", "?[-vpc]", "print devinfo tree", prtconf, prtconf_help },
42850Sstevel@tonic-gate 	{ "softstate", ":<instance>", "retrieve soft-state pointer",
42860Sstevel@tonic-gate 	    softstate },
42870Sstevel@tonic-gate 	{ "devinfo_fm", ":", "devinfo fault managment configuration",
42880Sstevel@tonic-gate 	    devinfo_fm },
42890Sstevel@tonic-gate 	{ "devinfo_fmce", ":", "devinfo fault managment cache entry",
42900Sstevel@tonic-gate 	    devinfo_fmce},
42910Sstevel@tonic-gate 
42923323Scindi 	/* from fm.c */
42933323Scindi 	{ "ereport", "[-v]", "print ereports logged in dump",
42943323Scindi 	    ereport },
42953323Scindi 
42960Sstevel@tonic-gate 	/* from findstack.c */
42970Sstevel@tonic-gate 	{ "findstack", ":[-v]", "find kernel thread stack", findstack },
42980Sstevel@tonic-gate 	{ "findstack_debug", NULL, "toggle findstack debugging",
42990Sstevel@tonic-gate 		findstack_debug },
43000Sstevel@tonic-gate 
43010Sstevel@tonic-gate 	/* from kgrep.c + genunix.c */
43021580Sjwadams 	{ "kgrep", KGREP_USAGE, "search kernel as for a pointer", kgrep,
43031580Sjwadams 		kgrep_help },
43040Sstevel@tonic-gate 
43050Sstevel@tonic-gate 	/* from kmem.c */
43060Sstevel@tonic-gate 	{ "allocdby", ":", "given a thread, print its allocated buffers",
43070Sstevel@tonic-gate 		allocdby },
43080Sstevel@tonic-gate 	{ "bufctl", ":[-vh] [-a addr] [-c caller] [-e earliest] [-l latest] "
43090Sstevel@tonic-gate 		"[-t thd]", "print or filter a bufctl", bufctl, bufctl_help },
43100Sstevel@tonic-gate 	{ "freedby", ":", "given a thread, print its freed buffers", freedby },
43110Sstevel@tonic-gate 	{ "kmalog", "?[ fail | slab ]",
43120Sstevel@tonic-gate 	    "display kmem transaction log and stack traces", kmalog },
43133095Sek110237 	{ "kmastat", "[-kmg]", "kernel memory allocator stats",
43143095Sek110237 	    kmastat },
43150Sstevel@tonic-gate 	{ "kmausers", "?[-ef] [cache ...]", "current medium and large users "
43160Sstevel@tonic-gate 		"of the kmem allocator", kmausers, kmausers_help },
43176712Stomee 	{ "kmem_cache", "?[-n name]",
43186712Stomee 		"print kernel memory caches", kmem_cache, kmem_cache_help},
43196712Stomee 	{ "kmem_slabs", "?[-v] [-n cache] [-N cache] [-b maxbins] "
43206712Stomee 		"[-B minbinsize]", "display slab usage per kmem cache",
43214688Stomee 		kmem_slabs, kmem_slabs_help },
43220Sstevel@tonic-gate 	{ "kmem_debug", NULL, "toggle kmem dcmd/walk debugging", kmem_debug },
43230Sstevel@tonic-gate 	{ "kmem_log", "?[-b]", "dump kmem transaction log", kmem_log },
43240Sstevel@tonic-gate 	{ "kmem_verify", "?", "check integrity of kmem-managed memory",
43250Sstevel@tonic-gate 		kmem_verify },
43260Sstevel@tonic-gate 	{ "vmem", "?", "print a vmem_t", vmem },
43270Sstevel@tonic-gate 	{ "vmem_seg", ":[-sv] [-c caller] [-e earliest] [-l latest] "
43280Sstevel@tonic-gate 		"[-m minsize] [-M maxsize] [-t thread] [-T type]",
43290Sstevel@tonic-gate 		"print or filter a vmem_seg", vmem_seg, vmem_seg_help },
43300Sstevel@tonic-gate 	{ "whatis", ":[-abiv]", "given an address, return information", whatis,
43310Sstevel@tonic-gate 		whatis_help },
43320Sstevel@tonic-gate 	{ "whatthread", ":[-v]", "print threads whose stack contains the "
43330Sstevel@tonic-gate 		"given address", whatthread },
43340Sstevel@tonic-gate 
43350Sstevel@tonic-gate 	/* from ldi.c */
43360Sstevel@tonic-gate 	{ "ldi_handle", "?[-i]", "display a layered driver handle",
43370Sstevel@tonic-gate 	    ldi_handle, ldi_handle_help },
43380Sstevel@tonic-gate 	{ "ldi_ident", NULL, "display a layered driver identifier",
43390Sstevel@tonic-gate 	    ldi_ident, ldi_ident_help },
43400Sstevel@tonic-gate 
43410Sstevel@tonic-gate 	/* from leaky.c + leaky_subr.c */
43420Sstevel@tonic-gate 	{ "findleaks", FINDLEAKS_USAGE,
43430Sstevel@tonic-gate 	    "search for potential kernel memory leaks", findleaks,
43440Sstevel@tonic-gate 	    findleaks_help },
43450Sstevel@tonic-gate 
43460Sstevel@tonic-gate 	/* from lgrp.c */
43470Sstevel@tonic-gate 	{ "lgrp", "?[-q] [-p | -Pih]", "display an lgrp", lgrp},
43482685Sakolb 	{ "lgrp_set", "", "display bitmask of lgroups as a list", lgrp_set},
43490Sstevel@tonic-gate 
43500Sstevel@tonic-gate 	/* from log.c */
43510Sstevel@tonic-gate 	{ "msgbuf", "?[-v]", "print most recent console messages", msgbuf },
43520Sstevel@tonic-gate 
43530Sstevel@tonic-gate 	/* from memory.c */
43540Sstevel@tonic-gate 	{ "page", "?", "display a summarized page_t", page },
43550Sstevel@tonic-gate 	{ "memstat", NULL, "display memory usage summary", memstat },
43560Sstevel@tonic-gate 	{ "memlist", "?[-iav]", "display a struct memlist", memlist },
43570Sstevel@tonic-gate 	{ "swapinfo", "?", "display a struct swapinfo", swapinfof },
43580Sstevel@tonic-gate 
43590Sstevel@tonic-gate 	/* from mmd.c */
43600Sstevel@tonic-gate 	{ "multidata", ":[-sv]", "display a summarized multidata_t",
43610Sstevel@tonic-gate 		multidata },
43620Sstevel@tonic-gate 	{ "pattbl", ":", "display a summarized multidata attribute table",
43630Sstevel@tonic-gate 		pattbl },
43640Sstevel@tonic-gate 	{ "pattr2multidata", ":", "print multidata pointer from pattr_t",
43650Sstevel@tonic-gate 		pattr2multidata },
43660Sstevel@tonic-gate 	{ "pdesc2slab", ":", "print pdesc slab pointer from pdesc_t",
43670Sstevel@tonic-gate 		pdesc2slab },
43680Sstevel@tonic-gate 	{ "pdesc_verify", ":", "verify integrity of a pdesc_t", pdesc_verify },
43690Sstevel@tonic-gate 	{ "slab2multidata", ":", "print multidata pointer from pdesc_slab_t",
43700Sstevel@tonic-gate 		slab2multidata },
43710Sstevel@tonic-gate 
43720Sstevel@tonic-gate 	/* from modhash.c */
43730Sstevel@tonic-gate 	{ "modhash", "?[-ceht] [-k key] [-v val] [-i index]",
43740Sstevel@tonic-gate 		"display information about one or all mod_hash structures",
43750Sstevel@tonic-gate 		modhash, modhash_help },
43760Sstevel@tonic-gate 	{ "modent", ":[-k | -v | -t type]",
43770Sstevel@tonic-gate 		"display information about a mod_hash_entry", modent,
43780Sstevel@tonic-gate 		modent_help },
43790Sstevel@tonic-gate 
43800Sstevel@tonic-gate 	/* from net.c */
43810Sstevel@tonic-gate 	{ "mi", ":[-p] [-d | -m]", "filter and display MI object or payload",
43820Sstevel@tonic-gate 		mi },
43831676Sjpk 	{ "netstat", "[-arv] [-f inet | inet6 | unix] [-P tcp | udp]",
43840Sstevel@tonic-gate 		"show network statistics", netstat },
43850Sstevel@tonic-gate 	{ "sonode", "?[-f inet | inet6 | unix | #] "
43860Sstevel@tonic-gate 		"[-t stream | dgram | raw | #] [-p #]",
43870Sstevel@tonic-gate 		"filter and display sonode", sonode },
43880Sstevel@tonic-gate 
43893448Sdh155122 	/* from netstack.c */
43903448Sdh155122 	{ "netstack", "", "show stack instances", netstack },
43913448Sdh155122 
43920Sstevel@tonic-gate 	/* from nvpair.c */
43930Sstevel@tonic-gate 	{ NVPAIR_DCMD_NAME, NVPAIR_DCMD_USAGE, NVPAIR_DCMD_DESCR,
43940Sstevel@tonic-gate 		nvpair_print },
4395789Sahrens 	{ NVLIST_DCMD_NAME, NVLIST_DCMD_USAGE, NVLIST_DCMD_DESCR,
43962869Sgavinm 		print_nvlist },
43970Sstevel@tonic-gate 
43983434Sesaxe 	/* from pg.c */
43993434Sesaxe 	{ "pg", "?[-q]", "display a pg", pg},
44003434Sesaxe 	/* from group.c */
44013434Sesaxe 	{ "group", "?[-q]", "display a group", group},
44023434Sesaxe 
44033434Sesaxe 	/* from log.c */
44040Sstevel@tonic-gate 	/* from rctl.c */
44050Sstevel@tonic-gate 	{ "rctl_dict", "?", "print systemwide default rctl definitions",
44060Sstevel@tonic-gate 		rctl_dict },
44070Sstevel@tonic-gate 	{ "rctl_list", ":[handle]", "print rctls for the given proc",
44080Sstevel@tonic-gate 		rctl_list },
44090Sstevel@tonic-gate 	{ "rctl", ":[handle]", "print a rctl_t, only if it matches the handle",
44100Sstevel@tonic-gate 		rctl },
44110Sstevel@tonic-gate 	{ "rctl_validate", ":[-v] [-n #]", "test resource control value "
44120Sstevel@tonic-gate 		"sequence", rctl_validate },
44130Sstevel@tonic-gate 
44140Sstevel@tonic-gate 	/* from sobj.c */
44150Sstevel@tonic-gate 	{ "rwlock", ":", "dump out a readers/writer lock", rwlock },
44160Sstevel@tonic-gate 	{ "mutex", ":[-f]", "dump out an adaptive or spin mutex", mutex,
44170Sstevel@tonic-gate 		mutex_help },
44180Sstevel@tonic-gate 	{ "sobj2ts", ":", "perform turnstile lookup on synch object", sobj2ts },
44190Sstevel@tonic-gate 	{ "wchaninfo", "?[-v]", "dump condition variable", wchaninfo },
44200Sstevel@tonic-gate 	{ "turnstile", "?", "display a turnstile", turnstile },
44210Sstevel@tonic-gate 
44220Sstevel@tonic-gate 	/* from stream.c */
44230Sstevel@tonic-gate 	{ "mblk", ":[-q|v] [-f|F flag] [-t|T type] [-l|L|B len] [-d dbaddr]",
44240Sstevel@tonic-gate 		"print an mblk", mblk_prt, mblk_help },
44250Sstevel@tonic-gate 	{ "mblk_verify", "?", "verify integrity of an mblk", mblk_verify },
44260Sstevel@tonic-gate 	{ "mblk2dblk", ":", "convert mblk_t address to dblk_t address",
44270Sstevel@tonic-gate 		mblk2dblk },
44280Sstevel@tonic-gate 	{ "q2otherq", ":", "print peer queue for a given queue", q2otherq },
44290Sstevel@tonic-gate 	{ "q2rdq", ":", "print read queue for a given queue", q2rdq },
44300Sstevel@tonic-gate 	{ "q2syncq", ":", "print syncq for a given queue", q2syncq },
44310Sstevel@tonic-gate 	{ "q2stream", ":", "print stream pointer for a given queue", q2stream },
44320Sstevel@tonic-gate 	{ "q2wrq", ":", "print write queue for a given queue", q2wrq },
44330Sstevel@tonic-gate 	{ "queue", ":[-q|v] [-m mod] [-f flag] [-F flag] [-s syncq_addr]",
44340Sstevel@tonic-gate 		"filter and display STREAM queue", queue, queue_help },
44350Sstevel@tonic-gate 	{ "stdata", ":[-q|v] [-f flag] [-F flag]",
44360Sstevel@tonic-gate 		"filter and display STREAM head", stdata, stdata_help },
44370Sstevel@tonic-gate 	{ "str2mate", ":", "print mate of this stream", str2mate },
44380Sstevel@tonic-gate 	{ "str2wrq", ":", "print write queue of this stream", str2wrq },
44390Sstevel@tonic-gate 	{ "stream", ":", "display STREAM", stream },
44400Sstevel@tonic-gate 	{ "strftevent", ":", "print STREAMS flow trace event", strftevent },
44410Sstevel@tonic-gate 	{ "syncq", ":[-q|v] [-f flag] [-F flag] [-t type] [-T type]",
44420Sstevel@tonic-gate 		"filter and display STREAM sync queue", syncq, syncq_help },
44430Sstevel@tonic-gate 	{ "syncq2q", ":", "print queue for a given syncq", syncq2q },
44440Sstevel@tonic-gate 
44450Sstevel@tonic-gate 	/* from thread.c */
44460Sstevel@tonic-gate 	{ "thread", "?[-bdfimps]", "display a summarized kthread_t", thread,
44470Sstevel@tonic-gate 		thread_help },
44485316Sjohnlev 	{ "threadlist", "?[-t] [-v [count]]",
44490Sstevel@tonic-gate 		"display threads and associated C stack traces", threadlist,
44500Sstevel@tonic-gate 		threadlist_help },
44517854SPhilippe.Jung@Sun.COM 	{ "stackinfo", "?[-h|-a]", "display kthread_t stack usage", stackinfo,
44527854SPhilippe.Jung@Sun.COM 		stackinfo_help },
44530Sstevel@tonic-gate 
44540Sstevel@tonic-gate 	/* from tsd.c */
44550Sstevel@tonic-gate 	{ "tsd", ":-k key", "print tsd[key-1] for this thread", ttotsd },
44560Sstevel@tonic-gate 	{ "tsdtot", ":", "find thread with this tsd", tsdtot },
44570Sstevel@tonic-gate 
44580Sstevel@tonic-gate 	/*
44590Sstevel@tonic-gate 	 * typegraph does not work under kmdb, as it requires too much memory
44600Sstevel@tonic-gate 	 * for its internal data structures.
44610Sstevel@tonic-gate 	 */
44620Sstevel@tonic-gate #ifndef _KMDB
44630Sstevel@tonic-gate 	/* from typegraph.c */
44640Sstevel@tonic-gate 	{ "findlocks", ":", "find locks held by specified thread", findlocks },
44650Sstevel@tonic-gate 	{ "findfalse", "?[-v]", "find potentially falsely shared structures",
44660Sstevel@tonic-gate 		findfalse },
44670Sstevel@tonic-gate 	{ "typegraph", NULL, "build type graph", typegraph },
44680Sstevel@tonic-gate 	{ "istype", ":type", "manually set object type", istype },
44690Sstevel@tonic-gate 	{ "notype", ":", "manually clear object type", notype },
44700Sstevel@tonic-gate 	{ "whattype", ":", "determine object type", whattype },
44710Sstevel@tonic-gate #endif
44720Sstevel@tonic-gate 
44730Sstevel@tonic-gate 	/* from vfs.c */
44740Sstevel@tonic-gate 	{ "fsinfo", "?[-v]", "print mounted filesystems", fsinfo },
44750Sstevel@tonic-gate 	{ "pfiles", ":[-fp]", "print process file information", pfiles,
44760Sstevel@tonic-gate 		pfiles_help },
44770Sstevel@tonic-gate 
44782577Sramat 	/* from mdi.c */
44792577Sramat 	{ "mdipi", NULL, "given a path, dump mdi_pathinfo "
44802577Sramat 		"and detailed pi_prop list", mdipi },
44812577Sramat 	{ "mdiprops", NULL, "given a pi_prop, dump the pi_prop list",
44822577Sramat 		mdiprops },
44832577Sramat 	{ "mdiphci", NULL, "given a phci, dump mdi_phci and "
44842577Sramat 		"list all paths", mdiphci },
44852577Sramat 	{ "mdivhci", NULL, "given a vhci, dump mdi_vhci and list "
44862577Sramat 		"all phcis", mdivhci },
44872577Sramat 	{ "mdiclient_paths", NULL, "given a path, walk mdi_pathinfo "
44882577Sramat 		"client links", mdiclient_paths },
44892577Sramat 	{ "mdiphci_paths", NULL, "given a path, walk through mdi_pathinfo "
44902577Sramat 		"phci links", mdiphci_paths },
44912577Sramat 	{ "mdiphcis", NULL, "given a phci, walk through mdi_phci ph_next links",
44922577Sramat 		mdiphcis },
44932577Sramat 
44940Sstevel@tonic-gate 	{ NULL }
44950Sstevel@tonic-gate };
44960Sstevel@tonic-gate 
44970Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
44980Sstevel@tonic-gate 
44990Sstevel@tonic-gate 	/* from genunix.c */
45000Sstevel@tonic-gate 	{ "anon", "given an amp, list of anon structures",
45010Sstevel@tonic-gate 		anon_walk_init, anon_walk_step, anon_walk_fini },
45028048SMadhavan.Venkataraman@Sun.COM 	{ "callouts_bytime", "walk callouts by list chain (expiration time)",
45038048SMadhavan.Venkataraman@Sun.COM 		callout_walk_init, callout_walk_step, callout_walk_fini,
45048048SMadhavan.Venkataraman@Sun.COM 		(void *)CALLOUT_WALK_BYLIST },
45058048SMadhavan.Venkataraman@Sun.COM 	{ "callouts_byid", "walk callouts by id hash chain",
45068048SMadhavan.Venkataraman@Sun.COM 		callout_walk_init, callout_walk_step, callout_walk_fini,
45078048SMadhavan.Venkataraman@Sun.COM 		(void *)CALLOUT_WALK_BYID },
45088048SMadhavan.Venkataraman@Sun.COM 	{ "callout_list", "walk a callout list", callout_list_walk_init,
45098048SMadhavan.Venkataraman@Sun.COM 		callout_list_walk_step, callout_list_walk_fini },
45108048SMadhavan.Venkataraman@Sun.COM 	{ "callout_table", "walk callout table array", callout_table_walk_init,
45118048SMadhavan.Venkataraman@Sun.COM 		callout_table_walk_step, callout_table_walk_fini },
45120Sstevel@tonic-gate 	{ "cpu", "walk cpu structures", cpu_walk_init, cpu_walk_step },
45133323Scindi 	{ "ereportq_dump", "walk list of ereports in dump error queue",
45143323Scindi 		ereportq_dump_walk_init, ereportq_dump_walk_step, NULL },
45153323Scindi 	{ "ereportq_pend", "walk list of ereports in pending error queue",
45163323Scindi 		ereportq_pend_walk_init, ereportq_pend_walk_step, NULL },
45170Sstevel@tonic-gate 	{ "errorq", "walk list of system error queues",
45180Sstevel@tonic-gate 		errorq_walk_init, errorq_walk_step, NULL },
45190Sstevel@tonic-gate 	{ "errorq_data", "walk pending error queue data buffers",
45200Sstevel@tonic-gate 		eqd_walk_init, eqd_walk_step, eqd_walk_fini },
45210Sstevel@tonic-gate 	{ "allfile", "given a proc pointer, list all file pointers",
45220Sstevel@tonic-gate 		file_walk_init, allfile_walk_step, file_walk_fini },
45230Sstevel@tonic-gate 	{ "file", "given a proc pointer, list of open file pointers",
45240Sstevel@tonic-gate 		file_walk_init, file_walk_step, file_walk_fini },
45250Sstevel@tonic-gate 	{ "lock_descriptor", "walk lock_descriptor_t structures",
45260Sstevel@tonic-gate 		ld_walk_init, ld_walk_step, NULL },
45270Sstevel@tonic-gate 	{ "lock_graph", "walk lock graph",
45280Sstevel@tonic-gate 		lg_walk_init, lg_walk_step, NULL },
45290Sstevel@tonic-gate 	{ "port", "given a proc pointer, list of created event ports",
45300Sstevel@tonic-gate 		port_walk_init, port_walk_step, NULL },
45310Sstevel@tonic-gate 	{ "portev", "given a port pointer, list of events in the queue",
45320Sstevel@tonic-gate 		portev_walk_init, portev_walk_step, portev_walk_fini },
45330Sstevel@tonic-gate 	{ "proc", "list of active proc_t structures",
45340Sstevel@tonic-gate 		proc_walk_init, proc_walk_step, proc_walk_fini },
45350Sstevel@tonic-gate 	{ "projects", "walk a list of kernel projects",
45360Sstevel@tonic-gate 		project_walk_init, project_walk_step, NULL },
45370Sstevel@tonic-gate 	{ "seg", "given an as, list of segments",
45380Sstevel@tonic-gate 		seg_walk_init, avl_walk_step, avl_walk_fini },
45390Sstevel@tonic-gate 	{ "sysevent_pend", "walk sysevent pending queue",
45400Sstevel@tonic-gate 		sysevent_pend_walk_init, sysevent_walk_step,
45410Sstevel@tonic-gate 		sysevent_walk_fini},
45420Sstevel@tonic-gate 	{ "sysevent_sent", "walk sysevent sent queue", sysevent_sent_walk_init,
45430Sstevel@tonic-gate 		sysevent_walk_step, sysevent_walk_fini},
45440Sstevel@tonic-gate 	{ "sysevent_channel", "walk sysevent channel subscriptions",
45450Sstevel@tonic-gate 		sysevent_channel_walk_init, sysevent_channel_walk_step,
45460Sstevel@tonic-gate 		sysevent_channel_walk_fini},
45470Sstevel@tonic-gate 	{ "sysevent_class_list", "walk sysevent subscription's class list",
45480Sstevel@tonic-gate 		sysevent_class_list_walk_init, sysevent_class_list_walk_step,
45490Sstevel@tonic-gate 		sysevent_class_list_walk_fini},
45500Sstevel@tonic-gate 	{ "sysevent_subclass_list",
45510Sstevel@tonic-gate 		"walk sysevent subscription's subclass list",
45520Sstevel@tonic-gate 		sysevent_subclass_list_walk_init,
45530Sstevel@tonic-gate 		sysevent_subclass_list_walk_step,
45540Sstevel@tonic-gate 		sysevent_subclass_list_walk_fini},
45550Sstevel@tonic-gate 	{ "task", "given a task pointer, walk its processes",
45560Sstevel@tonic-gate 		task_walk_init, task_walk_step, NULL },
45570Sstevel@tonic-gate 	{ "taskq_entry", "given a taskq_t*, list all taskq_ent_t in the list",
45580Sstevel@tonic-gate 		taskq_walk_init, taskq_walk_step, NULL, NULL },
45590Sstevel@tonic-gate 
4560789Sahrens 	/* from avl.c */
4561789Sahrens 	{ AVL_WALK_NAME, AVL_WALK_DESC,
4562789Sahrens 		avl_walk_init, avl_walk_step, avl_walk_fini },
4563789Sahrens 
45640Sstevel@tonic-gate 	/* from zone.c */
45650Sstevel@tonic-gate 	{ "zone", "walk a list of kernel zones",
45660Sstevel@tonic-gate 		zone_walk_init, zone_walk_step, NULL },
45670Sstevel@tonic-gate 	{ "zsd", "walk list of zsd entries for a zone",
45680Sstevel@tonic-gate 		zsd_walk_init, zsd_walk_step, NULL },
45690Sstevel@tonic-gate 
45700Sstevel@tonic-gate 	/* from bio.c */
45710Sstevel@tonic-gate 	{ "buf", "walk the bio buf hash",
45720Sstevel@tonic-gate 		buf_walk_init, buf_walk_step, buf_walk_fini },
45730Sstevel@tonic-gate 
45740Sstevel@tonic-gate 	/* from contract.c */
45750Sstevel@tonic-gate 	{ "contract", "walk all contracts, or those of the specified type",
45760Sstevel@tonic-gate 		ct_walk_init, generic_walk_step, NULL },
45770Sstevel@tonic-gate 	{ "ct_event", "walk events on a contract event queue",
45780Sstevel@tonic-gate 		ct_event_walk_init, generic_walk_step, NULL },
45790Sstevel@tonic-gate 	{ "ct_listener", "walk contract event queue listeners",
45800Sstevel@tonic-gate 		ct_listener_walk_init, generic_walk_step, NULL },
45810Sstevel@tonic-gate 
45820Sstevel@tonic-gate 	/* from cpupart.c */
45830Sstevel@tonic-gate 	{ "cpupart_cpulist", "given an cpupart_t, walk cpus in partition",
45840Sstevel@tonic-gate 		cpupart_cpulist_walk_init, cpupart_cpulist_walk_step,
45850Sstevel@tonic-gate 		NULL },
45860Sstevel@tonic-gate 	{ "cpupart_walk", "walk the set of cpu partitions",
45870Sstevel@tonic-gate 		cpupart_walk_init, cpupart_walk_step, NULL },
45880Sstevel@tonic-gate 
45890Sstevel@tonic-gate 	/* from ctxop.c */
45900Sstevel@tonic-gate 	{ "ctxop", "walk list of context ops on a thread",
45910Sstevel@tonic-gate 		ctxop_walk_init, ctxop_walk_step, ctxop_walk_fini },
45920Sstevel@tonic-gate 
45930Sstevel@tonic-gate 	/* from cyclic.c */
45940Sstevel@tonic-gate 	{ "cyccpu", "walk per-CPU cyc_cpu structures",
45950Sstevel@tonic-gate 		cyccpu_walk_init, cyccpu_walk_step, NULL },
45960Sstevel@tonic-gate 	{ "cycomni", "for an omnipresent cyclic, walk cyc_omni_cpu list",
45970Sstevel@tonic-gate 		cycomni_walk_init, cycomni_walk_step, NULL },
45980Sstevel@tonic-gate 	{ "cyctrace", "walk cyclic trace buffer",
45990Sstevel@tonic-gate 		cyctrace_walk_init, cyctrace_walk_step, cyctrace_walk_fini },
46000Sstevel@tonic-gate 
46010Sstevel@tonic-gate 	/* from devinfo.c */
46020Sstevel@tonic-gate 	{ "binding_hash", "walk all entries in binding hash table",
46030Sstevel@tonic-gate 		binding_hash_walk_init, binding_hash_walk_step, NULL },
46040Sstevel@tonic-gate 	{ "devinfo", "walk devinfo tree or subtree",
46050Sstevel@tonic-gate 		devinfo_walk_init, devinfo_walk_step, devinfo_walk_fini },
46060Sstevel@tonic-gate 	{ "devinfo_audit_log", "walk devinfo audit system-wide log",
46070Sstevel@tonic-gate 		devinfo_audit_log_walk_init, devinfo_audit_log_walk_step,
46080Sstevel@tonic-gate 		devinfo_audit_log_walk_fini},
46090Sstevel@tonic-gate 	{ "devinfo_audit_node", "walk per-devinfo audit history",
46100Sstevel@tonic-gate 		devinfo_audit_node_walk_init, devinfo_audit_node_walk_step,
46110Sstevel@tonic-gate 		devinfo_audit_node_walk_fini},
46120Sstevel@tonic-gate 	{ "devinfo_children", "walk children of devinfo node",
46130Sstevel@tonic-gate 		devinfo_children_walk_init, devinfo_children_walk_step,
46140Sstevel@tonic-gate 		devinfo_children_walk_fini },
46150Sstevel@tonic-gate 	{ "devinfo_parents", "walk ancestors of devinfo node",
46160Sstevel@tonic-gate 		devinfo_parents_walk_init, devinfo_parents_walk_step,
46170Sstevel@tonic-gate 		devinfo_parents_walk_fini },
46180Sstevel@tonic-gate 	{ "devinfo_siblings", "walk siblings of devinfo node",
46190Sstevel@tonic-gate 		devinfo_siblings_walk_init, devinfo_siblings_walk_step, NULL },
46200Sstevel@tonic-gate 	{ "devi_next", "walk devinfo list",
46210Sstevel@tonic-gate 		NULL, devi_next_walk_step, NULL },
46220Sstevel@tonic-gate 	{ "devnames", "walk devnames array",
46230Sstevel@tonic-gate 		devnames_walk_init, devnames_walk_step, devnames_walk_fini },
46240Sstevel@tonic-gate 	{ "minornode", "given a devinfo node, walk minor nodes",
46250Sstevel@tonic-gate 		minornode_walk_init, minornode_walk_step, NULL },
46260Sstevel@tonic-gate 	{ "softstate",
46270Sstevel@tonic-gate 		"given an i_ddi_soft_state*, list all in-use driver stateps",
46280Sstevel@tonic-gate 		soft_state_walk_init, soft_state_walk_step,
46290Sstevel@tonic-gate 		NULL, NULL },
46300Sstevel@tonic-gate 	{ "softstate_all",
46310Sstevel@tonic-gate 		"given an i_ddi_soft_state*, list all driver stateps",
46320Sstevel@tonic-gate 		soft_state_walk_init, soft_state_all_walk_step,
46330Sstevel@tonic-gate 		NULL, NULL },
46340Sstevel@tonic-gate 	{ "devinfo_fmc",
46350Sstevel@tonic-gate 		"walk a fault management handle cache active list",
46360Sstevel@tonic-gate 		devinfo_fmc_walk_init, devinfo_fmc_walk_step, NULL },
46370Sstevel@tonic-gate 
46380Sstevel@tonic-gate 	/* from kmem.c */
46390Sstevel@tonic-gate 	{ "allocdby", "given a thread, walk its allocated bufctls",
46400Sstevel@tonic-gate 		allocdby_walk_init, allocdby_walk_step, allocdby_walk_fini },
46410Sstevel@tonic-gate 	{ "bufctl", "walk a kmem cache's bufctls",
46420Sstevel@tonic-gate 		bufctl_walk_init, kmem_walk_step, kmem_walk_fini },
46430Sstevel@tonic-gate 	{ "bufctl_history", "walk the available history of a bufctl",
46440Sstevel@tonic-gate 		bufctl_history_walk_init, bufctl_history_walk_step,
46450Sstevel@tonic-gate 		bufctl_history_walk_fini },
46460Sstevel@tonic-gate 	{ "freedby", "given a thread, walk its freed bufctls",
46470Sstevel@tonic-gate 		freedby_walk_init, allocdby_walk_step, allocdby_walk_fini },
46480Sstevel@tonic-gate 	{ "freectl", "walk a kmem cache's free bufctls",
46490Sstevel@tonic-gate 		freectl_walk_init, kmem_walk_step, kmem_walk_fini },
46500Sstevel@tonic-gate 	{ "freectl_constructed", "walk a kmem cache's constructed free bufctls",
46510Sstevel@tonic-gate 		freectl_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
46520Sstevel@tonic-gate 	{ "freemem", "walk a kmem cache's free memory",
46530Sstevel@tonic-gate 		freemem_walk_init, kmem_walk_step, kmem_walk_fini },
46540Sstevel@tonic-gate 	{ "freemem_constructed", "walk a kmem cache's constructed free memory",
46550Sstevel@tonic-gate 		freemem_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
46560Sstevel@tonic-gate 	{ "kmem", "walk a kmem cache",
46570Sstevel@tonic-gate 		kmem_walk_init, kmem_walk_step, kmem_walk_fini },
46580Sstevel@tonic-gate 	{ "kmem_cpu_cache", "given a kmem cache, walk its per-CPU caches",
46590Sstevel@tonic-gate 		kmem_cpu_cache_walk_init, kmem_cpu_cache_walk_step, NULL },
46600Sstevel@tonic-gate 	{ "kmem_hash", "given a kmem cache, walk its allocated hash table",
46610Sstevel@tonic-gate 		kmem_hash_walk_init, kmem_hash_walk_step, kmem_hash_walk_fini },
46620Sstevel@tonic-gate 	{ "kmem_log", "walk the kmem transaction log",
46630Sstevel@tonic-gate 		kmem_log_walk_init, kmem_log_walk_step, kmem_log_walk_fini },
46640Sstevel@tonic-gate 	{ "kmem_slab", "given a kmem cache, walk its slabs",
46656712Stomee 		kmem_slab_walk_init, combined_walk_step, combined_walk_fini },
46660Sstevel@tonic-gate 	{ "kmem_slab_partial",
46670Sstevel@tonic-gate 	    "given a kmem cache, walk its partially allocated slabs (min 1)",
46686712Stomee 		kmem_slab_walk_partial_init, combined_walk_step,
46696712Stomee 		combined_walk_fini },
46700Sstevel@tonic-gate 	{ "vmem", "walk vmem structures in pre-fix, depth-first order",
46710Sstevel@tonic-gate 		vmem_walk_init, vmem_walk_step, vmem_walk_fini },
46720Sstevel@tonic-gate 	{ "vmem_alloc", "given a vmem_t, walk its allocated vmem_segs",
46730Sstevel@tonic-gate 		vmem_alloc_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
46740Sstevel@tonic-gate 	{ "vmem_free", "given a vmem_t, walk its free vmem_segs",
46750Sstevel@tonic-gate 		vmem_free_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
46760Sstevel@tonic-gate 	{ "vmem_postfix", "walk vmem structures in post-fix, depth-first order",
46770Sstevel@tonic-gate 		vmem_walk_init, vmem_postfix_walk_step, vmem_walk_fini },
46780Sstevel@tonic-gate 	{ "vmem_seg", "given a vmem_t, walk all of its vmem_segs",
46790Sstevel@tonic-gate 		vmem_seg_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
46800Sstevel@tonic-gate 	{ "vmem_span", "given a vmem_t, walk its spanning vmem_segs",
46810Sstevel@tonic-gate 		vmem_span_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
46820Sstevel@tonic-gate 
46830Sstevel@tonic-gate 	/* from ldi.c */
46840Sstevel@tonic-gate 	{ "ldi_handle", "walk the layered driver handle hash",
46850Sstevel@tonic-gate 		ldi_handle_walk_init, ldi_handle_walk_step, NULL },
46860Sstevel@tonic-gate 	{ "ldi_ident", "walk the layered driver identifier hash",
46870Sstevel@tonic-gate 		ldi_ident_walk_init, ldi_ident_walk_step, NULL },
46880Sstevel@tonic-gate 
46890Sstevel@tonic-gate 	/* from leaky.c + leaky_subr.c */
46900Sstevel@tonic-gate 	{ "leak", "given a leaked bufctl or vmem_seg, find leaks w/ same "
46910Sstevel@tonic-gate 	    "stack trace",
46920Sstevel@tonic-gate 		leaky_walk_init, leaky_walk_step, leaky_walk_fini },
46930Sstevel@tonic-gate 	{ "leakbuf", "given a leaked bufctl or vmem_seg, walk buffers for "
46940Sstevel@tonic-gate 	    "leaks w/ same stack trace",
46950Sstevel@tonic-gate 		leaky_walk_init, leaky_buf_walk_step, leaky_walk_fini },
46960Sstevel@tonic-gate 
46970Sstevel@tonic-gate 	/* from lgrp.c */
46982685Sakolb 	{ "lgrp_cpulist", "walk CPUs in a given lgroup",
46992685Sakolb 		lgrp_cpulist_walk_init, lgrp_cpulist_walk_step, NULL },
47002685Sakolb 	{ "lgrptbl", "walk lgroup table",
47010Sstevel@tonic-gate 		lgrp_walk_init, lgrp_walk_step, NULL },
47022685Sakolb 	{ "lgrp_parents", "walk up lgroup lineage from given lgroup",
47032685Sakolb 		lgrp_parents_walk_init, lgrp_parents_walk_step, NULL },
47042685Sakolb 	{ "lgrp_rsrc_mem", "walk lgroup memory resources of given lgroup",
47052685Sakolb 		lgrp_rsrc_mem_walk_init, lgrp_set_walk_step, NULL },
47062685Sakolb 	{ "lgrp_rsrc_cpu", "walk lgroup CPU resources of given lgroup",
47072685Sakolb 		lgrp_rsrc_cpu_walk_init, lgrp_set_walk_step, NULL },
47080Sstevel@tonic-gate 
47093434Sesaxe 	/* from group.c */
47103434Sesaxe 	{ "group", "walk all elements of a group",
47113434Sesaxe 		group_walk_init, group_walk_step, NULL },
47123434Sesaxe 
47130Sstevel@tonic-gate 	/* from list.c */
4714789Sahrens 	{ LIST_WALK_NAME, LIST_WALK_DESC,
47150Sstevel@tonic-gate 		list_walk_init, list_walk_step, list_walk_fini },
47160Sstevel@tonic-gate 
47170Sstevel@tonic-gate 	/* from memory.c */
47180Sstevel@tonic-gate 	{ "page", "walk all pages, or those from the specified vnode",
47190Sstevel@tonic-gate 		page_walk_init, page_walk_step, page_walk_fini },
47200Sstevel@tonic-gate 	{ "memlist", "walk specified memlist",
47210Sstevel@tonic-gate 		NULL, memlist_walk_step, NULL },
47220Sstevel@tonic-gate 	{ "swapinfo", "walk swapinfo structures",
47230Sstevel@tonic-gate 		swap_walk_init, swap_walk_step, NULL },
47240Sstevel@tonic-gate 
47250Sstevel@tonic-gate 	/* from mmd.c */
47260Sstevel@tonic-gate 	{ "pattr", "walk pattr_t structures", pattr_walk_init,
47270Sstevel@tonic-gate 		mmdq_walk_step, mmdq_walk_fini },
47280Sstevel@tonic-gate 	{ "pdesc", "walk pdesc_t structures",
47290Sstevel@tonic-gate 		pdesc_walk_init, mmdq_walk_step, mmdq_walk_fini },
47300Sstevel@tonic-gate 	{ "pdesc_slab", "walk pdesc_slab_t structures",
47310Sstevel@tonic-gate 		pdesc_slab_walk_init, mmdq_walk_step, mmdq_walk_fini },
47320Sstevel@tonic-gate 
47330Sstevel@tonic-gate 	/* from modhash.c */
47340Sstevel@tonic-gate 	{ "modhash", "walk list of mod_hash structures", modhash_walk_init,
47350Sstevel@tonic-gate 		modhash_walk_step, NULL },
47360Sstevel@tonic-gate 	{ "modent", "walk list of entries in a given mod_hash",
47370Sstevel@tonic-gate 		modent_walk_init, modent_walk_step, modent_walk_fini },
47380Sstevel@tonic-gate 	{ "modchain", "walk list of entries in a given mod_hash_entry",
47390Sstevel@tonic-gate 		NULL, modchain_walk_step, NULL },
47400Sstevel@tonic-gate 
47410Sstevel@tonic-gate 	/* from net.c */
47423448Sdh155122 	{ "ar", "walk ar_t structures using MI for all stacks",
47433448Sdh155122 		mi_payload_walk_init, mi_payload_walk_step, NULL, &mi_ar_arg },
47443448Sdh155122 	{ "icmp", "walk ICMP control structures using MI for all stacks",
47453448Sdh155122 		mi_payload_walk_init, mi_payload_walk_step, NULL,
47463448Sdh155122 		&mi_icmp_arg },
47473448Sdh155122 	{ "ill", "walk ill_t structures using MI for all stacks",
47483448Sdh155122 		mi_payload_walk_init, mi_payload_walk_step, NULL, &mi_ill_arg },
47493448Sdh155122 
47500Sstevel@tonic-gate 	{ "mi", "given a MI_O, walk the MI",
47510Sstevel@tonic-gate 		mi_walk_init, mi_walk_step, mi_walk_fini, NULL },
47520Sstevel@tonic-gate 	{ "sonode", "given a sonode, walk its children",
47530Sstevel@tonic-gate 		sonode_walk_init, sonode_walk_step, sonode_walk_fini, NULL },
47540Sstevel@tonic-gate 
47553448Sdh155122 	{ "ar_stacks", "walk all the ar_stack_t",
47563448Sdh155122 		ar_stacks_walk_init, ar_stacks_walk_step, NULL },
47573448Sdh155122 	{ "icmp_stacks", "walk all the icmp_stack_t",
47583448Sdh155122 		icmp_stacks_walk_init, icmp_stacks_walk_step, NULL },
47593448Sdh155122 	{ "tcp_stacks", "walk all the tcp_stack_t",
47603448Sdh155122 		tcp_stacks_walk_init, tcp_stacks_walk_step, NULL },
47613448Sdh155122 	{ "udp_stacks", "walk all the udp_stack_t",
47623448Sdh155122 		udp_stacks_walk_init, udp_stacks_walk_step, NULL },
47633448Sdh155122 
47640Sstevel@tonic-gate 	/* from nvpair.c */
47650Sstevel@tonic-gate 	{ NVPAIR_WALKER_NAME, NVPAIR_WALKER_DESCR,
47660Sstevel@tonic-gate 		nvpair_walk_init, nvpair_walk_step, NULL },
47670Sstevel@tonic-gate 
47680Sstevel@tonic-gate 	/* from rctl.c */
47690Sstevel@tonic-gate 	{ "rctl_dict_list", "walk all rctl_dict_entry_t's from rctl_lists",
47700Sstevel@tonic-gate 		rctl_dict_walk_init, rctl_dict_walk_step, NULL },
47710Sstevel@tonic-gate 	{ "rctl_set", "given a rctl_set, walk all rctls", rctl_set_walk_init,
47720Sstevel@tonic-gate 		rctl_set_walk_step, NULL },
47730Sstevel@tonic-gate 	{ "rctl_val", "given a rctl_t, walk all rctl_val entries associated",
47740Sstevel@tonic-gate 		rctl_val_walk_init, rctl_val_walk_step },
47750Sstevel@tonic-gate 
47760Sstevel@tonic-gate 	/* from sobj.c */
47770Sstevel@tonic-gate 	{ "blocked", "walk threads blocked on a given sobj",
47780Sstevel@tonic-gate 		blocked_walk_init, blocked_walk_step, NULL },
47790Sstevel@tonic-gate 	{ "wchan", "given a wchan, list of blocked threads",
47800Sstevel@tonic-gate 		wchan_walk_init, wchan_walk_step, wchan_walk_fini },
47810Sstevel@tonic-gate 
47820Sstevel@tonic-gate 	/* from stream.c */
47830Sstevel@tonic-gate 	{ "b_cont", "walk mblk_t list using b_cont",
47840Sstevel@tonic-gate 		mblk_walk_init, b_cont_step, mblk_walk_fini },
47850Sstevel@tonic-gate 	{ "b_next", "walk mblk_t list using b_next",
47860Sstevel@tonic-gate 		mblk_walk_init, b_next_step, mblk_walk_fini },
47870Sstevel@tonic-gate 	{ "qlink", "walk queue_t list using q_link",
47880Sstevel@tonic-gate 		queue_walk_init, queue_link_step, queue_walk_fini },
47890Sstevel@tonic-gate 	{ "qnext", "walk queue_t list using q_next",
47900Sstevel@tonic-gate 		queue_walk_init, queue_next_step, queue_walk_fini },
47910Sstevel@tonic-gate 	{ "strftblk", "given a dblk_t, walk STREAMS flow trace event list",
47920Sstevel@tonic-gate 		strftblk_walk_init, strftblk_step, strftblk_walk_fini },
47930Sstevel@tonic-gate 	{ "readq", "walk read queue side of stdata",
47940Sstevel@tonic-gate 		str_walk_init, strr_walk_step, str_walk_fini },
47950Sstevel@tonic-gate 	{ "writeq", "walk write queue side of stdata",
47960Sstevel@tonic-gate 		str_walk_init, strw_walk_step, str_walk_fini },
47970Sstevel@tonic-gate 
47980Sstevel@tonic-gate 	/* from thread.c */
47990Sstevel@tonic-gate 	{ "deathrow", "walk threads on both lwp_ and thread_deathrow",
48000Sstevel@tonic-gate 		deathrow_walk_init, deathrow_walk_step, NULL },
48010Sstevel@tonic-gate 	{ "cpu_dispq", "given a cpu_t, walk threads in dispatcher queues",
48020Sstevel@tonic-gate 		cpu_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
48030Sstevel@tonic-gate 	{ "cpupart_dispq",
48040Sstevel@tonic-gate 		"given a cpupart_t, walk threads in dispatcher queues",
48050Sstevel@tonic-gate 		cpupart_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
48060Sstevel@tonic-gate 	{ "lwp_deathrow", "walk lwp_deathrow",
48070Sstevel@tonic-gate 		lwp_deathrow_walk_init, deathrow_walk_step, NULL },
48080Sstevel@tonic-gate 	{ "thread", "global or per-process kthread_t structures",
48090Sstevel@tonic-gate 		thread_walk_init, thread_walk_step, thread_walk_fini },
48100Sstevel@tonic-gate 	{ "thread_deathrow", "walk threads on thread_deathrow",
48110Sstevel@tonic-gate 		thread_deathrow_walk_init, deathrow_walk_step, NULL },
48120Sstevel@tonic-gate 
48130Sstevel@tonic-gate 	/* from tsd.c */
48140Sstevel@tonic-gate 	{ "tsd", "walk list of thread-specific data",
48150Sstevel@tonic-gate 		tsd_walk_init, tsd_walk_step, tsd_walk_fini },
48160Sstevel@tonic-gate 
48171676Sjpk 	/* from tsol.c */
48181676Sjpk 	{ "tnrh", "walk remote host cache structures",
48191676Sjpk 	    tnrh_walk_init, tnrh_walk_step, tnrh_walk_fini },
48201676Sjpk 	{ "tnrhtp", "walk remote host template structures",
48211676Sjpk 	    tnrhtp_walk_init, tnrhtp_walk_step, tnrhtp_walk_fini },
48221676Sjpk 
48230Sstevel@tonic-gate 	/*
48240Sstevel@tonic-gate 	 * typegraph does not work under kmdb, as it requires too much memory
48250Sstevel@tonic-gate 	 * for its internal data structures.
48260Sstevel@tonic-gate 	 */
48270Sstevel@tonic-gate #ifndef _KMDB
48280Sstevel@tonic-gate 	/* from typegraph.c */
48290Sstevel@tonic-gate 	{ "typeconflict", "walk buffers with conflicting type inferences",
48300Sstevel@tonic-gate 		typegraph_walk_init, typeconflict_walk_step },
48310Sstevel@tonic-gate 	{ "typeunknown", "walk buffers with unknown types",
48320Sstevel@tonic-gate 		typegraph_walk_init, typeunknown_walk_step },
48330Sstevel@tonic-gate #endif
48340Sstevel@tonic-gate 
48350Sstevel@tonic-gate 	/* from vfs.c */
48360Sstevel@tonic-gate 	{ "vfs", "walk file system list",
48370Sstevel@tonic-gate 		vfs_walk_init, vfs_walk_step },
48382577Sramat 
48392577Sramat 	/* from mdi.c */
48402577Sramat 	{ "mdipi_client_list", "Walker for mdi_pathinfo pi_client_link",
48412577Sramat 		mdi_pi_client_link_walk_init,
48422577Sramat 		mdi_pi_client_link_walk_step,
48432577Sramat 		mdi_pi_client_link_walk_fini },
48442577Sramat 
48452577Sramat 	{ "mdipi_phci_list", "Walker for mdi_pathinfo pi_phci_link",
48462577Sramat 		mdi_pi_phci_link_walk_init,
48472577Sramat 		mdi_pi_phci_link_walk_step,
48482577Sramat 		mdi_pi_phci_link_walk_fini },
48492577Sramat 
48502577Sramat 	{ "mdiphci_list", "Walker for mdi_phci ph_next link",
48512577Sramat 		mdi_phci_ph_next_walk_init,
48522577Sramat 		mdi_phci_ph_next_walk_step,
48532577Sramat 		mdi_phci_ph_next_walk_fini },
48542577Sramat 
48553448Sdh155122 	/* from netstack.c */
48563448Sdh155122 	{ "netstack", "walk a list of kernel netstacks",
48573448Sdh155122 		netstack_walk_init, netstack_walk_step, NULL },
48583448Sdh155122 
48590Sstevel@tonic-gate 	{ NULL }
48600Sstevel@tonic-gate };
48610Sstevel@tonic-gate 
48620Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
48630Sstevel@tonic-gate 
48640Sstevel@tonic-gate const mdb_modinfo_t *
48650Sstevel@tonic-gate _mdb_init(void)
48660Sstevel@tonic-gate {
48670Sstevel@tonic-gate 	if (findstack_init() != DCMD_OK)
48680Sstevel@tonic-gate 		return (NULL);
48690Sstevel@tonic-gate 
48700Sstevel@tonic-gate 	kmem_init();
48710Sstevel@tonic-gate 
48720Sstevel@tonic-gate 	return (&modinfo);
48730Sstevel@tonic-gate }
48740Sstevel@tonic-gate 
48750Sstevel@tonic-gate void
48760Sstevel@tonic-gate _mdb_fini(void)
48770Sstevel@tonic-gate {
48780Sstevel@tonic-gate 	/*
48790Sstevel@tonic-gate 	 * Force ::findleaks to let go any cached memory
48800Sstevel@tonic-gate 	 */
48810Sstevel@tonic-gate 	leaky_cleanup(1);
48820Sstevel@tonic-gate }
4883