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 /*
2213077SJonathan.Adams@Sun.COM * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate #include <mdb/mdb_param.h>
260Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
270Sstevel@tonic-gate #include <mdb/mdb_ks.h>
280Sstevel@tonic-gate #include <mdb/mdb_ctf.h>
290Sstevel@tonic-gate
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <sys/thread.h>
320Sstevel@tonic-gate #include <sys/session.h>
330Sstevel@tonic-gate #include <sys/user.h>
340Sstevel@tonic-gate #include <sys/proc.h>
350Sstevel@tonic-gate #include <sys/var.h>
360Sstevel@tonic-gate #include <sys/t_lock.h>
370Sstevel@tonic-gate #include <sys/callo.h>
380Sstevel@tonic-gate #include <sys/priocntl.h>
390Sstevel@tonic-gate #include <sys/class.h>
400Sstevel@tonic-gate #include <sys/regset.h>
410Sstevel@tonic-gate #include <sys/stack.h>
420Sstevel@tonic-gate #include <sys/cpuvar.h>
430Sstevel@tonic-gate #include <sys/vnode.h>
440Sstevel@tonic-gate #include <sys/vfs.h>
450Sstevel@tonic-gate #include <sys/flock_impl.h>
460Sstevel@tonic-gate #include <sys/kmem_impl.h>
470Sstevel@tonic-gate #include <sys/vmem_impl.h>
480Sstevel@tonic-gate #include <sys/kstat.h>
490Sstevel@tonic-gate #include <sys/dditypes.h>
500Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
510Sstevel@tonic-gate #include <sys/sysmacros.h>
520Sstevel@tonic-gate #include <sys/sysconf.h>
530Sstevel@tonic-gate #include <sys/task.h>
540Sstevel@tonic-gate #include <sys/project.h>
550Sstevel@tonic-gate #include <sys/errorq_impl.h>
560Sstevel@tonic-gate #include <sys/cred_impl.h>
570Sstevel@tonic-gate #include <sys/zone.h>
580Sstevel@tonic-gate #include <sys/panic.h>
590Sstevel@tonic-gate #include <regex.h>
600Sstevel@tonic-gate #include <sys/port_impl.h>
610Sstevel@tonic-gate
62789Sahrens #include "avl.h"
6310696SDavid.Hollister@Sun.COM #include "bio.h"
6410696SDavid.Hollister@Sun.COM #include "bitset.h"
656712Stomee #include "combined.h"
660Sstevel@tonic-gate #include "contract.h"
670Sstevel@tonic-gate #include "cpupart_mdb.h"
6810696SDavid.Hollister@Sun.COM #include "ctxop.h"
6910696SDavid.Hollister@Sun.COM #include "cyclic.h"
7010696SDavid.Hollister@Sun.COM #include "damap.h"
710Sstevel@tonic-gate #include "devinfo.h"
7210696SDavid.Hollister@Sun.COM #include "findstack.h"
7310696SDavid.Hollister@Sun.COM #include "fm.h"
7410696SDavid.Hollister@Sun.COM #include "group.h"
758561SScott.Carter@Sun.COM #include "irm.h"
7610696SDavid.Hollister@Sun.COM #include "kgrep.h"
7710696SDavid.Hollister@Sun.COM #include "kmem.h"
7810696SDavid.Hollister@Sun.COM #include "ldi.h"
790Sstevel@tonic-gate #include "leaky.h"
800Sstevel@tonic-gate #include "lgrp.h"
810Sstevel@tonic-gate #include "list.h"
820Sstevel@tonic-gate #include "log.h"
8310696SDavid.Hollister@Sun.COM #include "mdi.h"
8410696SDavid.Hollister@Sun.COM #include "memory.h"
8510696SDavid.Hollister@Sun.COM #include "mmd.h"
8610696SDavid.Hollister@Sun.COM #include "modhash.h"
870Sstevel@tonic-gate #include "ndievents.h"
880Sstevel@tonic-gate #include "net.h"
893448Sdh155122 #include "netstack.h"
900Sstevel@tonic-gate #include "nvpair.h"
9110696SDavid.Hollister@Sun.COM #include "pg.h"
9210696SDavid.Hollister@Sun.COM #include "rctl.h"
9310696SDavid.Hollister@Sun.COM #include "sobj.h"
9410696SDavid.Hollister@Sun.COM #include "streams.h"
9510696SDavid.Hollister@Sun.COM #include "sysevent.h"
9610889SJonathan.Adams@Sun.COM #include "taskq.h"
970Sstevel@tonic-gate #include "thread.h"
9810696SDavid.Hollister@Sun.COM #include "tsd.h"
991676Sjpk #include "tsol.h"
1000Sstevel@tonic-gate #include "typegraph.h"
1010Sstevel@tonic-gate #include "vfs.h"
1020Sstevel@tonic-gate #include "zone.h"
10310923SEvan.Yan@Sun.COM #include "hotplug.h"
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate * Surely this is defined somewhere...
1070Sstevel@tonic-gate */
1080Sstevel@tonic-gate #define NINTR 16
1090Sstevel@tonic-gate
1104808Sek110237 #define KILOS 10
1114808Sek110237 #define MEGS 20
1124808Sek110237 #define GIGS 30
1134808Sek110237
1140Sstevel@tonic-gate #ifndef STACK_BIAS
1150Sstevel@tonic-gate #define STACK_BIAS 0
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate static char
pstat2ch(uchar_t state)1190Sstevel@tonic-gate pstat2ch(uchar_t state)
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate switch (state) {
1220Sstevel@tonic-gate case SSLEEP: return ('S');
1230Sstevel@tonic-gate case SRUN: return ('R');
1240Sstevel@tonic-gate case SZOMB: return ('Z');
1250Sstevel@tonic-gate case SIDL: return ('I');
1260Sstevel@tonic-gate case SONPROC: return ('O');
1270Sstevel@tonic-gate case SSTOP: return ('T');
1283792Sakolb case SWAIT: return ('W');
1290Sstevel@tonic-gate default: return ('?');
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate #define PS_PRTTHREADS 0x1
1340Sstevel@tonic-gate #define PS_PRTLWPS 0x2
1350Sstevel@tonic-gate #define PS_PSARGS 0x4
1360Sstevel@tonic-gate #define PS_TASKS 0x8
1370Sstevel@tonic-gate #define PS_PROJECTS 0x10
1380Sstevel@tonic-gate #define PS_ZONES 0x20
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate static int
ps_threadprint(uintptr_t addr,const void * data,void * private)1410Sstevel@tonic-gate ps_threadprint(uintptr_t addr, const void *data, void *private)
1420Sstevel@tonic-gate {
1430Sstevel@tonic-gate const kthread_t *t = (const kthread_t *)data;
1440Sstevel@tonic-gate uint_t prt_flags = *((uint_t *)private);
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate static const mdb_bitmask_t t_state_bits[] = {
1470Sstevel@tonic-gate { "TS_FREE", UINT_MAX, TS_FREE },
1480Sstevel@tonic-gate { "TS_SLEEP", TS_SLEEP, TS_SLEEP },
1490Sstevel@tonic-gate { "TS_RUN", TS_RUN, TS_RUN },
1500Sstevel@tonic-gate { "TS_ONPROC", TS_ONPROC, TS_ONPROC },
1510Sstevel@tonic-gate { "TS_ZOMB", TS_ZOMB, TS_ZOMB },
1520Sstevel@tonic-gate { "TS_STOPPED", TS_STOPPED, TS_STOPPED },
1533792Sakolb { "TS_WAIT", TS_WAIT, TS_WAIT },
1540Sstevel@tonic-gate { NULL, 0, 0 }
1550Sstevel@tonic-gate };
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate if (prt_flags & PS_PRTTHREADS)
1580Sstevel@tonic-gate mdb_printf("\tT %?a <%b>\n", addr, t->t_state, t_state_bits);
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate if (prt_flags & PS_PRTLWPS)
1610Sstevel@tonic-gate mdb_printf("\tL %?a ID: %u\n", t->t_lwp, t->t_tid);
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate return (WALK_NEXT);
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate int
ps(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1670Sstevel@tonic-gate ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1680Sstevel@tonic-gate {
1690Sstevel@tonic-gate uint_t prt_flags = 0;
1700Sstevel@tonic-gate proc_t pr;
1710Sstevel@tonic-gate struct pid pid, pgid, sid;
1720Sstevel@tonic-gate sess_t session;
1730Sstevel@tonic-gate cred_t cred;
1740Sstevel@tonic-gate task_t tk;
1750Sstevel@tonic-gate kproject_t pj;
1760Sstevel@tonic-gate zone_t zn;
1770Sstevel@tonic-gate
1780Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
1790Sstevel@tonic-gate if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) {
1800Sstevel@tonic-gate mdb_warn("can't walk 'proc'");
1810Sstevel@tonic-gate return (DCMD_ERR);
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate return (DCMD_OK);
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate if (mdb_getopts(argc, argv,
1870Sstevel@tonic-gate 'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags,
1880Sstevel@tonic-gate 'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags,
1890Sstevel@tonic-gate 'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags,
1900Sstevel@tonic-gate 'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags,
1910Sstevel@tonic-gate 'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags,
1920Sstevel@tonic-gate 't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc)
1930Sstevel@tonic-gate return (DCMD_USAGE);
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) {
1960Sstevel@tonic-gate mdb_printf("%<u>%1s %6s %6s %6s %6s ",
1970Sstevel@tonic-gate "S", "PID", "PPID", "PGID", "SID");
1980Sstevel@tonic-gate if (prt_flags & PS_TASKS)
1990Sstevel@tonic-gate mdb_printf("%5s ", "TASK");
2000Sstevel@tonic-gate if (prt_flags & PS_PROJECTS)
2010Sstevel@tonic-gate mdb_printf("%5s ", "PROJ");
2020Sstevel@tonic-gate if (prt_flags & PS_ZONES)
2030Sstevel@tonic-gate mdb_printf("%5s ", "ZONE");
2040Sstevel@tonic-gate mdb_printf("%6s %10s %?s %s%</u>\n",
2050Sstevel@tonic-gate "UID", "FLAGS", "ADDR", "NAME");
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate mdb_vread(&pr, sizeof (pr), addr);
2090Sstevel@tonic-gate mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp);
2100Sstevel@tonic-gate mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp);
2110Sstevel@tonic-gate mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred);
2120Sstevel@tonic-gate mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp);
2130Sstevel@tonic-gate mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp);
2140Sstevel@tonic-gate if (prt_flags & (PS_TASKS | PS_PROJECTS))
2150Sstevel@tonic-gate mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task);
2160Sstevel@tonic-gate if (prt_flags & PS_PROJECTS)
2170Sstevel@tonic-gate mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj);
2180Sstevel@tonic-gate if (prt_flags & PS_ZONES)
2190Sstevel@tonic-gate mdb_vread(&zn, sizeof (zone_t), (uintptr_t)pr.p_zone);
2200Sstevel@tonic-gate
2210Sstevel@tonic-gate mdb_printf("%c %6d %6d %6d %6d ",
2220Sstevel@tonic-gate pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id,
2230Sstevel@tonic-gate sid.pid_id);
2240Sstevel@tonic-gate if (prt_flags & PS_TASKS)
2250Sstevel@tonic-gate mdb_printf("%5d ", tk.tk_tkid);
2260Sstevel@tonic-gate if (prt_flags & PS_PROJECTS)
2270Sstevel@tonic-gate mdb_printf("%5d ", pj.kpj_id);
2280Sstevel@tonic-gate if (prt_flags & PS_ZONES)
2290Sstevel@tonic-gate mdb_printf("%5d ", zn.zone_id);
2300Sstevel@tonic-gate mdb_printf("%6d 0x%08x %0?p %s\n",
2310Sstevel@tonic-gate cred.cr_uid, pr.p_flag, addr,
2320Sstevel@tonic-gate (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm);
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate if (prt_flags & ~PS_PSARGS)
2350Sstevel@tonic-gate (void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr);
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate return (DCMD_OK);
2380Sstevel@tonic-gate }
2390Sstevel@tonic-gate
2400Sstevel@tonic-gate #define PG_NEWEST 0x0001
2410Sstevel@tonic-gate #define PG_OLDEST 0x0002
2420Sstevel@tonic-gate #define PG_PIPE_OUT 0x0004
2431014Svb160487 #define PG_EXACT_MATCH 0x0008
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate typedef struct pgrep_data {
2460Sstevel@tonic-gate uint_t pg_flags;
2470Sstevel@tonic-gate uint_t pg_psflags;
2480Sstevel@tonic-gate uintptr_t pg_xaddr;
2490Sstevel@tonic-gate hrtime_t pg_xstart;
2500Sstevel@tonic-gate const char *pg_pat;
2510Sstevel@tonic-gate #ifndef _KMDB
2520Sstevel@tonic-gate regex_t pg_reg;
2530Sstevel@tonic-gate #endif
2540Sstevel@tonic-gate } pgrep_data_t;
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate /*ARGSUSED*/
2570Sstevel@tonic-gate static int
pgrep_cb(uintptr_t addr,const void * pdata,void * data)2580Sstevel@tonic-gate pgrep_cb(uintptr_t addr, const void *pdata, void *data)
2590Sstevel@tonic-gate {
2600Sstevel@tonic-gate const proc_t *prp = pdata;
2610Sstevel@tonic-gate pgrep_data_t *pgp = data;
2620Sstevel@tonic-gate #ifndef _KMDB
2630Sstevel@tonic-gate regmatch_t pmatch;
2640Sstevel@tonic-gate #endif
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate /*
2670Sstevel@tonic-gate * kmdb doesn't have access to the reg* functions, so we fall back
2681014Svb160487 * to strstr/strcmp.
2690Sstevel@tonic-gate */
2700Sstevel@tonic-gate #ifdef _KMDB
2711014Svb160487 if ((pgp->pg_flags & PG_EXACT_MATCH) ?
2721014Svb160487 (strcmp(prp->p_user.u_comm, pgp->pg_pat) != 0) :
2731014Svb160487 (strstr(prp->p_user.u_comm, pgp->pg_pat) == NULL))
2740Sstevel@tonic-gate return (WALK_NEXT);
2750Sstevel@tonic-gate #else
2760Sstevel@tonic-gate if (regexec(&pgp->pg_reg, prp->p_user.u_comm, 1, &pmatch, 0) != 0)
2770Sstevel@tonic-gate return (WALK_NEXT);
2781014Svb160487
2791014Svb160487 if ((pgp->pg_flags & PG_EXACT_MATCH) &&
2801014Svb160487 (pmatch.rm_so != 0 || prp->p_user.u_comm[pmatch.rm_eo] != '\0'))
2811014Svb160487 return (WALK_NEXT);
2820Sstevel@tonic-gate #endif
2830Sstevel@tonic-gate
2840Sstevel@tonic-gate if (pgp->pg_flags & (PG_NEWEST | PG_OLDEST)) {
2850Sstevel@tonic-gate hrtime_t start;
2860Sstevel@tonic-gate
2870Sstevel@tonic-gate start = (hrtime_t)prp->p_user.u_start.tv_sec * NANOSEC +
2880Sstevel@tonic-gate prp->p_user.u_start.tv_nsec;
2890Sstevel@tonic-gate
2900Sstevel@tonic-gate if (pgp->pg_flags & PG_NEWEST) {
2910Sstevel@tonic-gate if (pgp->pg_xaddr == NULL || start > pgp->pg_xstart) {
2920Sstevel@tonic-gate pgp->pg_xaddr = addr;
2930Sstevel@tonic-gate pgp->pg_xstart = start;
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate } else {
2960Sstevel@tonic-gate if (pgp->pg_xaddr == NULL || start < pgp->pg_xstart) {
2970Sstevel@tonic-gate pgp->pg_xaddr = addr;
2980Sstevel@tonic-gate pgp->pg_xstart = start;
2990Sstevel@tonic-gate }
3000Sstevel@tonic-gate }
3010Sstevel@tonic-gate
3020Sstevel@tonic-gate } else if (pgp->pg_flags & PG_PIPE_OUT) {
3030Sstevel@tonic-gate mdb_printf("%p\n", addr);
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate } else {
3060Sstevel@tonic-gate if (mdb_call_dcmd("ps", addr, pgp->pg_psflags, 0, NULL) != 0) {
3070Sstevel@tonic-gate mdb_warn("can't invoke 'ps'");
3080Sstevel@tonic-gate return (WALK_DONE);
3090Sstevel@tonic-gate }
3100Sstevel@tonic-gate pgp->pg_psflags &= ~DCMD_LOOPFIRST;
3110Sstevel@tonic-gate }
3120Sstevel@tonic-gate
3130Sstevel@tonic-gate return (WALK_NEXT);
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate /*ARGSUSED*/
3170Sstevel@tonic-gate int
pgrep(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)3180Sstevel@tonic-gate pgrep(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3190Sstevel@tonic-gate {
3200Sstevel@tonic-gate pgrep_data_t pg;
3210Sstevel@tonic-gate int i;
3220Sstevel@tonic-gate #ifndef _KMDB
3230Sstevel@tonic-gate int err;
3240Sstevel@tonic-gate #endif
3250Sstevel@tonic-gate
3260Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC)
3270Sstevel@tonic-gate return (DCMD_USAGE);
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate pg.pg_flags = 0;
3300Sstevel@tonic-gate pg.pg_xaddr = 0;
3310Sstevel@tonic-gate
3320Sstevel@tonic-gate i = mdb_getopts(argc, argv,
3330Sstevel@tonic-gate 'n', MDB_OPT_SETBITS, PG_NEWEST, &pg.pg_flags,
3340Sstevel@tonic-gate 'o', MDB_OPT_SETBITS, PG_OLDEST, &pg.pg_flags,
3351014Svb160487 'x', MDB_OPT_SETBITS, PG_EXACT_MATCH, &pg.pg_flags,
3360Sstevel@tonic-gate NULL);
3370Sstevel@tonic-gate
3380Sstevel@tonic-gate argc -= i;
3390Sstevel@tonic-gate argv += i;
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate if (argc != 1)
3420Sstevel@tonic-gate return (DCMD_USAGE);
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate /*
3450Sstevel@tonic-gate * -n and -o are mutually exclusive.
3460Sstevel@tonic-gate */
3470Sstevel@tonic-gate if ((pg.pg_flags & PG_NEWEST) && (pg.pg_flags & PG_OLDEST))
3480Sstevel@tonic-gate return (DCMD_USAGE);
3490Sstevel@tonic-gate
3500Sstevel@tonic-gate if (argv->a_type != MDB_TYPE_STRING)
3510Sstevel@tonic-gate return (DCMD_USAGE);
3520Sstevel@tonic-gate
3530Sstevel@tonic-gate if (flags & DCMD_PIPE_OUT)
3540Sstevel@tonic-gate pg.pg_flags |= PG_PIPE_OUT;
3550Sstevel@tonic-gate
3560Sstevel@tonic-gate pg.pg_pat = argv->a_un.a_str;
3570Sstevel@tonic-gate if (DCMD_HDRSPEC(flags))
3580Sstevel@tonic-gate pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP | DCMD_LOOPFIRST;
3590Sstevel@tonic-gate else
3600Sstevel@tonic-gate pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP;
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate #ifndef _KMDB
3630Sstevel@tonic-gate if ((err = regcomp(&pg.pg_reg, pg.pg_pat, REG_EXTENDED)) != 0) {
3640Sstevel@tonic-gate size_t nbytes;
3650Sstevel@tonic-gate char *buf;
3660Sstevel@tonic-gate
3670Sstevel@tonic-gate nbytes = regerror(err, &pg.pg_reg, NULL, 0);
3680Sstevel@tonic-gate buf = mdb_alloc(nbytes + 1, UM_SLEEP | UM_GC);
3690Sstevel@tonic-gate (void) regerror(err, &pg.pg_reg, buf, nbytes);
3700Sstevel@tonic-gate mdb_warn("%s\n", buf);
3710Sstevel@tonic-gate
3720Sstevel@tonic-gate return (DCMD_ERR);
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate #endif
3750Sstevel@tonic-gate
3760Sstevel@tonic-gate if (mdb_walk("proc", pgrep_cb, &pg) != 0) {
3770Sstevel@tonic-gate mdb_warn("can't walk 'proc'");
3780Sstevel@tonic-gate return (DCMD_ERR);
3790Sstevel@tonic-gate }
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate if (pg.pg_xaddr != 0 && (pg.pg_flags & (PG_NEWEST | PG_OLDEST))) {
3820Sstevel@tonic-gate if (pg.pg_flags & PG_PIPE_OUT) {
3830Sstevel@tonic-gate mdb_printf("%p\n", pg.pg_xaddr);
3840Sstevel@tonic-gate } else {
3850Sstevel@tonic-gate if (mdb_call_dcmd("ps", pg.pg_xaddr, pg.pg_psflags,
3860Sstevel@tonic-gate 0, NULL) != 0) {
3870Sstevel@tonic-gate mdb_warn("can't invoke 'ps'");
3880Sstevel@tonic-gate return (DCMD_ERR);
3890Sstevel@tonic-gate }
3900Sstevel@tonic-gate }
3910Sstevel@tonic-gate }
3920Sstevel@tonic-gate
3930Sstevel@tonic-gate return (DCMD_OK);
3940Sstevel@tonic-gate }
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate int
task(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)3970Sstevel@tonic-gate task(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3980Sstevel@tonic-gate {
3990Sstevel@tonic-gate task_t tk;
4000Sstevel@tonic-gate kproject_t pj;
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
4030Sstevel@tonic-gate if (mdb_walk_dcmd("task_cache", "task", argc, argv) == -1) {
4040Sstevel@tonic-gate mdb_warn("can't walk task_cache");
4050Sstevel@tonic-gate return (DCMD_ERR);
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate return (DCMD_OK);
4080Sstevel@tonic-gate }
4090Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) {
4100Sstevel@tonic-gate mdb_printf("%<u>%?s %6s %6s %6s %6s %10s%</u>\n",
4110Sstevel@tonic-gate "ADDR", "TASKID", "PROJID", "ZONEID", "REFCNT", "FLAGS");
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate if (mdb_vread(&tk, sizeof (task_t), addr) == -1) {
4140Sstevel@tonic-gate mdb_warn("can't read task_t structure at %p", addr);
4150Sstevel@tonic-gate return (DCMD_ERR);
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate if (mdb_vread(&pj, sizeof (kproject_t), (uintptr_t)tk.tk_proj) == -1) {
4180Sstevel@tonic-gate mdb_warn("can't read project_t structure at %p", addr);
4190Sstevel@tonic-gate return (DCMD_ERR);
4200Sstevel@tonic-gate }
4210Sstevel@tonic-gate mdb_printf("%0?p %6d %6d %6d %6u 0x%08x\n",
4220Sstevel@tonic-gate addr, tk.tk_tkid, pj.kpj_id, pj.kpj_zoneid, tk.tk_hold_count,
4230Sstevel@tonic-gate tk.tk_flags);
4240Sstevel@tonic-gate return (DCMD_OK);
4250Sstevel@tonic-gate }
4260Sstevel@tonic-gate
4270Sstevel@tonic-gate int
project(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)4280Sstevel@tonic-gate project(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4290Sstevel@tonic-gate {
4300Sstevel@tonic-gate kproject_t pj;
4310Sstevel@tonic-gate
4320Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
4330Sstevel@tonic-gate if (mdb_walk_dcmd("projects", "project", argc, argv) == -1) {
4340Sstevel@tonic-gate mdb_warn("can't walk projects");
4350Sstevel@tonic-gate return (DCMD_ERR);
4360Sstevel@tonic-gate }
4370Sstevel@tonic-gate return (DCMD_OK);
4380Sstevel@tonic-gate }
4390Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) {
4400Sstevel@tonic-gate mdb_printf("%<u>%?s %6s %6s %6s%</u>\n",
4410Sstevel@tonic-gate "ADDR", "PROJID", "ZONEID", "REFCNT");
4420Sstevel@tonic-gate }
4430Sstevel@tonic-gate if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
4440Sstevel@tonic-gate mdb_warn("can't read kproject_t structure at %p", addr);
4450Sstevel@tonic-gate return (DCMD_ERR);
4460Sstevel@tonic-gate }
4470Sstevel@tonic-gate mdb_printf("%0?p %6d %6d %6u\n", addr, pj.kpj_id, pj.kpj_zoneid,
4480Sstevel@tonic-gate pj.kpj_count);
4490Sstevel@tonic-gate return (DCMD_OK);
4500Sstevel@tonic-gate }
4510Sstevel@tonic-gate
4528048SMadhavan.Venkataraman@Sun.COM /* walk callouts themselves, either by list or id hash. */
4538048SMadhavan.Venkataraman@Sun.COM int
callout_walk_init(mdb_walk_state_t * wsp)4548048SMadhavan.Venkataraman@Sun.COM callout_walk_init(mdb_walk_state_t *wsp)
4558048SMadhavan.Venkataraman@Sun.COM {
4568048SMadhavan.Venkataraman@Sun.COM if (wsp->walk_addr == NULL) {
4578048SMadhavan.Venkataraman@Sun.COM mdb_warn("callout doesn't support global walk");
4588048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
4598048SMadhavan.Venkataraman@Sun.COM }
4608048SMadhavan.Venkataraman@Sun.COM wsp->walk_data = mdb_alloc(sizeof (callout_t), UM_SLEEP);
4618048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
4628048SMadhavan.Venkataraman@Sun.COM }
4638048SMadhavan.Venkataraman@Sun.COM
4648048SMadhavan.Venkataraman@Sun.COM #define CALLOUT_WALK_BYLIST 0
4658048SMadhavan.Venkataraman@Sun.COM #define CALLOUT_WALK_BYID 1
4668048SMadhavan.Venkataraman@Sun.COM
4678048SMadhavan.Venkataraman@Sun.COM /* the walker arg switches between walking by list (0) and walking by id (1). */
4688048SMadhavan.Venkataraman@Sun.COM int
callout_walk_step(mdb_walk_state_t * wsp)4698048SMadhavan.Venkataraman@Sun.COM callout_walk_step(mdb_walk_state_t *wsp)
4708048SMadhavan.Venkataraman@Sun.COM {
4718048SMadhavan.Venkataraman@Sun.COM int retval;
4728048SMadhavan.Venkataraman@Sun.COM
4738048SMadhavan.Venkataraman@Sun.COM if (wsp->walk_addr == NULL) {
4748048SMadhavan.Venkataraman@Sun.COM return (WALK_DONE);
4758048SMadhavan.Venkataraman@Sun.COM }
4768048SMadhavan.Venkataraman@Sun.COM if (mdb_vread(wsp->walk_data, sizeof (callout_t),
4778048SMadhavan.Venkataraman@Sun.COM wsp->walk_addr) == -1) {
4788048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read callout at %p", wsp->walk_addr);
4798048SMadhavan.Venkataraman@Sun.COM return (WALK_DONE);
4808048SMadhavan.Venkataraman@Sun.COM }
4818048SMadhavan.Venkataraman@Sun.COM retval = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
4828048SMadhavan.Venkataraman@Sun.COM wsp->walk_cbdata);
4838048SMadhavan.Venkataraman@Sun.COM
4848048SMadhavan.Venkataraman@Sun.COM if ((ulong_t)wsp->walk_arg == CALLOUT_WALK_BYID) {
4858048SMadhavan.Venkataraman@Sun.COM wsp->walk_addr =
4868048SMadhavan.Venkataraman@Sun.COM (uintptr_t)(((callout_t *)wsp->walk_data)->c_idnext);
4878048SMadhavan.Venkataraman@Sun.COM } else {
4888048SMadhavan.Venkataraman@Sun.COM wsp->walk_addr =
4898048SMadhavan.Venkataraman@Sun.COM (uintptr_t)(((callout_t *)wsp->walk_data)->c_clnext);
4908048SMadhavan.Venkataraman@Sun.COM }
4918048SMadhavan.Venkataraman@Sun.COM
4928048SMadhavan.Venkataraman@Sun.COM return (retval);
4938048SMadhavan.Venkataraman@Sun.COM }
4948048SMadhavan.Venkataraman@Sun.COM
4958048SMadhavan.Venkataraman@Sun.COM void
callout_walk_fini(mdb_walk_state_t * wsp)4968048SMadhavan.Venkataraman@Sun.COM callout_walk_fini(mdb_walk_state_t *wsp)
4978048SMadhavan.Venkataraman@Sun.COM {
4988048SMadhavan.Venkataraman@Sun.COM mdb_free(wsp->walk_data, sizeof (callout_t));
4998048SMadhavan.Venkataraman@Sun.COM }
5008048SMadhavan.Venkataraman@Sun.COM
5018048SMadhavan.Venkataraman@Sun.COM /*
5028048SMadhavan.Venkataraman@Sun.COM * walker for callout lists. This is different from hashes and callouts.
5038048SMadhavan.Venkataraman@Sun.COM * Thankfully, it's also simpler.
5048048SMadhavan.Venkataraman@Sun.COM */
5058048SMadhavan.Venkataraman@Sun.COM int
callout_list_walk_init(mdb_walk_state_t * wsp)5068048SMadhavan.Venkataraman@Sun.COM callout_list_walk_init(mdb_walk_state_t *wsp)
5078048SMadhavan.Venkataraman@Sun.COM {
5088048SMadhavan.Venkataraman@Sun.COM if (wsp->walk_addr == NULL) {
5098048SMadhavan.Venkataraman@Sun.COM mdb_warn("callout list doesn't support global walk");
5108048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
5118048SMadhavan.Venkataraman@Sun.COM }
5128048SMadhavan.Venkataraman@Sun.COM wsp->walk_data = mdb_alloc(sizeof (callout_list_t), UM_SLEEP);
5138048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
5148048SMadhavan.Venkataraman@Sun.COM }
5158048SMadhavan.Venkataraman@Sun.COM
5168048SMadhavan.Venkataraman@Sun.COM int
callout_list_walk_step(mdb_walk_state_t * wsp)5178048SMadhavan.Venkataraman@Sun.COM callout_list_walk_step(mdb_walk_state_t *wsp)
5188048SMadhavan.Venkataraman@Sun.COM {
5198048SMadhavan.Venkataraman@Sun.COM int retval;
5208048SMadhavan.Venkataraman@Sun.COM
5218048SMadhavan.Venkataraman@Sun.COM if (wsp->walk_addr == NULL) {
5228048SMadhavan.Venkataraman@Sun.COM return (WALK_DONE);
5238048SMadhavan.Venkataraman@Sun.COM }
5248048SMadhavan.Venkataraman@Sun.COM if (mdb_vread(wsp->walk_data, sizeof (callout_list_t),
5258048SMadhavan.Venkataraman@Sun.COM wsp->walk_addr) != sizeof (callout_list_t)) {
5268048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read callout_list at %p", wsp->walk_addr);
5278048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
5288048SMadhavan.Venkataraman@Sun.COM }
5298048SMadhavan.Venkataraman@Sun.COM retval = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
5308048SMadhavan.Venkataraman@Sun.COM wsp->walk_cbdata);
5318048SMadhavan.Venkataraman@Sun.COM
5328048SMadhavan.Venkataraman@Sun.COM wsp->walk_addr = (uintptr_t)
5338048SMadhavan.Venkataraman@Sun.COM (((callout_list_t *)wsp->walk_data)->cl_next);
5348048SMadhavan.Venkataraman@Sun.COM
5358048SMadhavan.Venkataraman@Sun.COM return (retval);
5368048SMadhavan.Venkataraman@Sun.COM }
5378048SMadhavan.Venkataraman@Sun.COM
5388048SMadhavan.Venkataraman@Sun.COM void
callout_list_walk_fini(mdb_walk_state_t * wsp)5398048SMadhavan.Venkataraman@Sun.COM callout_list_walk_fini(mdb_walk_state_t *wsp)
5408048SMadhavan.Venkataraman@Sun.COM {
5418048SMadhavan.Venkataraman@Sun.COM mdb_free(wsp->walk_data, sizeof (callout_list_t));
5428048SMadhavan.Venkataraman@Sun.COM }
5438048SMadhavan.Venkataraman@Sun.COM
5448048SMadhavan.Venkataraman@Sun.COM /* routines/structs to walk callout table(s) */
5458048SMadhavan.Venkataraman@Sun.COM typedef struct cot_data {
5468048SMadhavan.Venkataraman@Sun.COM callout_table_t *ct0;
5478048SMadhavan.Venkataraman@Sun.COM callout_table_t ct;
5488048SMadhavan.Venkataraman@Sun.COM callout_hash_t cot_idhash[CALLOUT_BUCKETS];
5498048SMadhavan.Venkataraman@Sun.COM callout_hash_t cot_clhash[CALLOUT_BUCKETS];
5508048SMadhavan.Venkataraman@Sun.COM kstat_named_t ct_kstat_data[CALLOUT_NUM_STATS];
5518048SMadhavan.Venkataraman@Sun.COM int cotndx;
5528048SMadhavan.Venkataraman@Sun.COM int cotsize;
5538048SMadhavan.Venkataraman@Sun.COM } cot_data_t;
5548048SMadhavan.Venkataraman@Sun.COM
5558048SMadhavan.Venkataraman@Sun.COM int
callout_table_walk_init(mdb_walk_state_t * wsp)5568048SMadhavan.Venkataraman@Sun.COM callout_table_walk_init(mdb_walk_state_t *wsp)
5578048SMadhavan.Venkataraman@Sun.COM {
5588048SMadhavan.Venkataraman@Sun.COM int max_ncpus;
5598048SMadhavan.Venkataraman@Sun.COM cot_data_t *cot_walk_data;
5608048SMadhavan.Venkataraman@Sun.COM
5618048SMadhavan.Venkataraman@Sun.COM cot_walk_data = mdb_alloc(sizeof (cot_data_t), UM_SLEEP);
5628048SMadhavan.Venkataraman@Sun.COM
5638048SMadhavan.Venkataraman@Sun.COM if (wsp->walk_addr == NULL) {
5648048SMadhavan.Venkataraman@Sun.COM if (mdb_readvar(&cot_walk_data->ct0, "callout_table") == -1) {
5658048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read 'callout_table'");
5668048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
5678048SMadhavan.Venkataraman@Sun.COM }
5688048SMadhavan.Venkataraman@Sun.COM if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
5698048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to get callout_table array size");
5708048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
5718048SMadhavan.Venkataraman@Sun.COM }
5728048SMadhavan.Venkataraman@Sun.COM cot_walk_data->cotsize = CALLOUT_NTYPES * max_ncpus;
5738048SMadhavan.Venkataraman@Sun.COM wsp->walk_addr = (uintptr_t)cot_walk_data->ct0;
5748048SMadhavan.Venkataraman@Sun.COM } else {
5758048SMadhavan.Venkataraman@Sun.COM /* not a global walk */
5768048SMadhavan.Venkataraman@Sun.COM cot_walk_data->cotsize = 1;
5778048SMadhavan.Venkataraman@Sun.COM }
5788048SMadhavan.Venkataraman@Sun.COM
5798048SMadhavan.Venkataraman@Sun.COM cot_walk_data->cotndx = 0;
5808048SMadhavan.Venkataraman@Sun.COM wsp->walk_data = cot_walk_data;
5818048SMadhavan.Venkataraman@Sun.COM
5828048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
5838048SMadhavan.Venkataraman@Sun.COM }
5848048SMadhavan.Venkataraman@Sun.COM
5858048SMadhavan.Venkataraman@Sun.COM int
callout_table_walk_step(mdb_walk_state_t * wsp)5868048SMadhavan.Venkataraman@Sun.COM callout_table_walk_step(mdb_walk_state_t *wsp)
5878048SMadhavan.Venkataraman@Sun.COM {
5888048SMadhavan.Venkataraman@Sun.COM int retval;
5898048SMadhavan.Venkataraman@Sun.COM cot_data_t *cotwd = (cot_data_t *)wsp->walk_data;
5908048SMadhavan.Venkataraman@Sun.COM size_t size;
5918048SMadhavan.Venkataraman@Sun.COM
5928048SMadhavan.Venkataraman@Sun.COM if (cotwd->cotndx >= cotwd->cotsize) {
5938048SMadhavan.Venkataraman@Sun.COM return (WALK_DONE);
5948048SMadhavan.Venkataraman@Sun.COM }
5958048SMadhavan.Venkataraman@Sun.COM if (mdb_vread(&(cotwd->ct), sizeof (callout_table_t),
5968048SMadhavan.Venkataraman@Sun.COM wsp->walk_addr) != sizeof (callout_table_t)) {
5978048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read callout_table at %p", wsp->walk_addr);
5988048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
5998048SMadhavan.Venkataraman@Sun.COM }
6008048SMadhavan.Venkataraman@Sun.COM
6018048SMadhavan.Venkataraman@Sun.COM size = sizeof (callout_hash_t) * CALLOUT_BUCKETS;
6028048SMadhavan.Venkataraman@Sun.COM if (cotwd->ct.ct_idhash != NULL) {
6038048SMadhavan.Venkataraman@Sun.COM if (mdb_vread(cotwd->cot_idhash, size,
6048048SMadhavan.Venkataraman@Sun.COM (uintptr_t)(cotwd->ct.ct_idhash)) != size) {
6058048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read id_hash at %p",
6068048SMadhavan.Venkataraman@Sun.COM cotwd->ct.ct_idhash);
6078048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
6088048SMadhavan.Venkataraman@Sun.COM }
6098048SMadhavan.Venkataraman@Sun.COM }
6108048SMadhavan.Venkataraman@Sun.COM if (cotwd->ct.ct_clhash != NULL) {
6118048SMadhavan.Venkataraman@Sun.COM if (mdb_vread(&(cotwd->cot_clhash), size,
6128048SMadhavan.Venkataraman@Sun.COM (uintptr_t)cotwd->ct.ct_clhash) == -1) {
6138048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read cl_hash at %p",
6148048SMadhavan.Venkataraman@Sun.COM cotwd->ct.ct_clhash);
6158048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
6168048SMadhavan.Venkataraman@Sun.COM }
6178048SMadhavan.Venkataraman@Sun.COM }
6188048SMadhavan.Venkataraman@Sun.COM size = sizeof (kstat_named_t) * CALLOUT_NUM_STATS;
6198048SMadhavan.Venkataraman@Sun.COM if (cotwd->ct.ct_kstat_data != NULL) {
6208048SMadhavan.Venkataraman@Sun.COM if (mdb_vread(&(cotwd->ct_kstat_data), size,
6218048SMadhavan.Venkataraman@Sun.COM (uintptr_t)cotwd->ct.ct_kstat_data) == -1) {
6228048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read kstats at %p",
6238048SMadhavan.Venkataraman@Sun.COM cotwd->ct.ct_kstat_data);
6248048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
6258048SMadhavan.Venkataraman@Sun.COM }
6268048SMadhavan.Venkataraman@Sun.COM }
6278048SMadhavan.Venkataraman@Sun.COM retval = wsp->walk_callback(wsp->walk_addr, (void *)cotwd,
6288048SMadhavan.Venkataraman@Sun.COM wsp->walk_cbdata);
6298048SMadhavan.Venkataraman@Sun.COM
6308048SMadhavan.Venkataraman@Sun.COM cotwd->cotndx++;
6318048SMadhavan.Venkataraman@Sun.COM if (cotwd->cotndx >= cotwd->cotsize) {
6328048SMadhavan.Venkataraman@Sun.COM return (WALK_DONE);
6338048SMadhavan.Venkataraman@Sun.COM }
6348048SMadhavan.Venkataraman@Sun.COM wsp->walk_addr = (uintptr_t)((char *)wsp->walk_addr +
6358048SMadhavan.Venkataraman@Sun.COM sizeof (callout_table_t));
6368048SMadhavan.Venkataraman@Sun.COM
6378048SMadhavan.Venkataraman@Sun.COM return (retval);
6388048SMadhavan.Venkataraman@Sun.COM }
6398048SMadhavan.Venkataraman@Sun.COM
6408048SMadhavan.Venkataraman@Sun.COM void
callout_table_walk_fini(mdb_walk_state_t * wsp)6418048SMadhavan.Venkataraman@Sun.COM callout_table_walk_fini(mdb_walk_state_t *wsp)
6428048SMadhavan.Venkataraman@Sun.COM {
6438048SMadhavan.Venkataraman@Sun.COM mdb_free(wsp->walk_data, sizeof (cot_data_t));
6448048SMadhavan.Venkataraman@Sun.COM }
6458048SMadhavan.Venkataraman@Sun.COM
6468048SMadhavan.Venkataraman@Sun.COM static const char *co_typenames[] = { "R", "N" };
6478048SMadhavan.Venkataraman@Sun.COM
6489039SMadhavan.Venkataraman@Sun.COM #define CO_PLAIN_ID(xid) ((xid) & CALLOUT_ID_MASK)
6498048SMadhavan.Venkataraman@Sun.COM
6508048SMadhavan.Venkataraman@Sun.COM #define TABLE_TO_SEQID(x) ((x) >> CALLOUT_TYPE_BITS)
6518048SMadhavan.Venkataraman@Sun.COM
6528048SMadhavan.Venkataraman@Sun.COM /* callout flags, in no particular order */
65311745SMadhavan.Venkataraman@Sun.COM #define COF_REAL 0x00000001
65411745SMadhavan.Venkataraman@Sun.COM #define COF_NORM 0x00000002
65511745SMadhavan.Venkataraman@Sun.COM #define COF_LONG 0x00000004
65611745SMadhavan.Venkataraman@Sun.COM #define COF_SHORT 0x00000008
65711745SMadhavan.Venkataraman@Sun.COM #define COF_EMPTY 0x00000010
65811745SMadhavan.Venkataraman@Sun.COM #define COF_TIME 0x00000020
65911745SMadhavan.Venkataraman@Sun.COM #define COF_BEFORE 0x00000040
66011745SMadhavan.Venkataraman@Sun.COM #define COF_AFTER 0x00000080
66111745SMadhavan.Venkataraman@Sun.COM #define COF_SEQID 0x00000100
66211745SMadhavan.Venkataraman@Sun.COM #define COF_FUNC 0x00000200
66311745SMadhavan.Venkataraman@Sun.COM #define COF_ADDR 0x00000400
66411745SMadhavan.Venkataraman@Sun.COM #define COF_EXEC 0x00000800
66511745SMadhavan.Venkataraman@Sun.COM #define COF_HIRES 0x00001000
66611745SMadhavan.Venkataraman@Sun.COM #define COF_ABS 0x00002000
66711745SMadhavan.Venkataraman@Sun.COM #define COF_TABLE 0x00004000
66811745SMadhavan.Venkataraman@Sun.COM #define COF_BYIDH 0x00008000
66911745SMadhavan.Venkataraman@Sun.COM #define COF_FREE 0x00010000
67011745SMadhavan.Venkataraman@Sun.COM #define COF_LIST 0x00020000
67111745SMadhavan.Venkataraman@Sun.COM #define COF_EXPREL 0x00040000
67211745SMadhavan.Venkataraman@Sun.COM #define COF_HDR 0x00080000
67311745SMadhavan.Venkataraman@Sun.COM #define COF_VERBOSE 0x00100000
67411745SMadhavan.Venkataraman@Sun.COM #define COF_LONGLIST 0x00200000
67511745SMadhavan.Venkataraman@Sun.COM #define COF_THDR 0x00400000
67611745SMadhavan.Venkataraman@Sun.COM #define COF_LHDR 0x00800000
67711745SMadhavan.Venkataraman@Sun.COM #define COF_CHDR 0x01000000
67811745SMadhavan.Venkataraman@Sun.COM #define COF_PARAM 0x02000000
67911745SMadhavan.Venkataraman@Sun.COM #define COF_DECODE 0x04000000
68011745SMadhavan.Venkataraman@Sun.COM #define COF_HEAP 0x08000000
68111745SMadhavan.Venkataraman@Sun.COM #define COF_QUEUE 0x10000000
6828048SMadhavan.Venkataraman@Sun.COM
6838048SMadhavan.Venkataraman@Sun.COM /* show real and normal, short and long, expired and unexpired. */
6848048SMadhavan.Venkataraman@Sun.COM #define COF_DEFAULT (COF_REAL | COF_NORM | COF_LONG | COF_SHORT)
6858048SMadhavan.Venkataraman@Sun.COM
6869334SMadhavan.Venkataraman@Sun.COM #define COF_LIST_FLAGS \
6879334SMadhavan.Venkataraman@Sun.COM (CALLOUT_LIST_FLAG_HRESTIME | CALLOUT_LIST_FLAG_ABSOLUTE)
6889334SMadhavan.Venkataraman@Sun.COM
6898048SMadhavan.Venkataraman@Sun.COM /* private callout data for callback functions */
6908048SMadhavan.Venkataraman@Sun.COM typedef struct callout_data {
6918048SMadhavan.Venkataraman@Sun.COM uint_t flags; /* COF_* */
6928048SMadhavan.Venkataraman@Sun.COM cpu_t *cpu; /* cpu pointer if given */
6938048SMadhavan.Venkataraman@Sun.COM int seqid; /* cpu seqid, or -1 */
6948048SMadhavan.Venkataraman@Sun.COM hrtime_t time; /* expiration time value */
6958048SMadhavan.Venkataraman@Sun.COM hrtime_t atime; /* expiration before value */
6968048SMadhavan.Venkataraman@Sun.COM hrtime_t btime; /* expiration after value */
6978048SMadhavan.Venkataraman@Sun.COM uintptr_t funcaddr; /* function address or NULL */
6988048SMadhavan.Venkataraman@Sun.COM uintptr_t param; /* parameter to function or NULL */
6998048SMadhavan.Venkataraman@Sun.COM hrtime_t now; /* current system time */
7008048SMadhavan.Venkataraman@Sun.COM int nsec_per_tick; /* for conversions */
7018048SMadhavan.Venkataraman@Sun.COM ulong_t ctbits; /* for decoding xid */
7028048SMadhavan.Venkataraman@Sun.COM callout_table_t *co_table; /* top of callout table array */
7038048SMadhavan.Venkataraman@Sun.COM int ndx; /* table index. */
7048048SMadhavan.Venkataraman@Sun.COM int bucket; /* which list/id bucket are we in */
7058048SMadhavan.Venkataraman@Sun.COM hrtime_t exp; /* expire time */
7069039SMadhavan.Venkataraman@Sun.COM int list_flags; /* copy of cl_flags */
7078048SMadhavan.Venkataraman@Sun.COM } callout_data_t;
7088048SMadhavan.Venkataraman@Sun.COM
7098048SMadhavan.Venkataraman@Sun.COM /* this callback does the actual callback itself (finally). */
7108048SMadhavan.Venkataraman@Sun.COM /*ARGSUSED*/
7118048SMadhavan.Venkataraman@Sun.COM static int
callouts_cb(uintptr_t addr,const void * data,void * priv)7128048SMadhavan.Venkataraman@Sun.COM callouts_cb(uintptr_t addr, const void *data, void *priv)
7138048SMadhavan.Venkataraman@Sun.COM {
7148048SMadhavan.Venkataraman@Sun.COM callout_data_t *coargs = (callout_data_t *)priv;
7158048SMadhavan.Venkataraman@Sun.COM callout_t *co = (callout_t *)data;
7169334SMadhavan.Venkataraman@Sun.COM int tableid, list_flags;
7178048SMadhavan.Venkataraman@Sun.COM callout_id_t coid;
7188048SMadhavan.Venkataraman@Sun.COM
7198048SMadhavan.Venkataraman@Sun.COM if ((coargs == NULL) || (co == NULL)) {
7208048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
7218048SMadhavan.Venkataraman@Sun.COM }
7228048SMadhavan.Venkataraman@Sun.COM
72311745SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_FREE) && !(co->c_xid & CALLOUT_ID_FREE)) {
7249334SMadhavan.Venkataraman@Sun.COM /*
7259334SMadhavan.Venkataraman@Sun.COM * The callout must have been reallocated. No point in
7269334SMadhavan.Venkataraman@Sun.COM * walking any more.
7279334SMadhavan.Venkataraman@Sun.COM */
7289334SMadhavan.Venkataraman@Sun.COM return (WALK_DONE);
7299334SMadhavan.Venkataraman@Sun.COM }
73011745SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_FREE) && (co->c_xid & CALLOUT_ID_FREE)) {
7319334SMadhavan.Venkataraman@Sun.COM /*
7329334SMadhavan.Venkataraman@Sun.COM * The callout must have been freed. No point in
7339334SMadhavan.Venkataraman@Sun.COM * walking any more.
7349334SMadhavan.Venkataraman@Sun.COM */
7359334SMadhavan.Venkataraman@Sun.COM return (WALK_DONE);
7369334SMadhavan.Venkataraman@Sun.COM }
7378048SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_FUNC) &&
7388048SMadhavan.Venkataraman@Sun.COM (coargs->funcaddr != (uintptr_t)co->c_func)) {
7398048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
7408048SMadhavan.Venkataraman@Sun.COM }
7418048SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_PARAM) &&
7428048SMadhavan.Venkataraman@Sun.COM (coargs->param != (uintptr_t)co->c_arg)) {
7438048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
7448048SMadhavan.Venkataraman@Sun.COM }
7458048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_LONG) && (co->c_xid & CALLOUT_LONGTERM)) {
7468048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
7478048SMadhavan.Venkataraman@Sun.COM }
7488048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_SHORT) && !(co->c_xid & CALLOUT_LONGTERM)) {
7498048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
7508048SMadhavan.Venkataraman@Sun.COM }
7518048SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_EXEC) && !(co->c_xid & CALLOUT_EXECUTING)) {
7528048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
7538048SMadhavan.Venkataraman@Sun.COM }
7549334SMadhavan.Venkataraman@Sun.COM /* it is possible we don't have the exp time or flags */
7558048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_BYIDH) {
7568048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_FREE)) {
7578048SMadhavan.Venkataraman@Sun.COM /* we have to fetch the expire time ourselves. */
7588048SMadhavan.Venkataraman@Sun.COM if (mdb_vread(&coargs->exp, sizeof (hrtime_t),
7598048SMadhavan.Venkataraman@Sun.COM (uintptr_t)co->c_list + offsetof(callout_list_t,
7608048SMadhavan.Venkataraman@Sun.COM cl_expiration)) == -1) {
7618048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read expiration "
7628048SMadhavan.Venkataraman@Sun.COM "time from %p", co->c_list);
7638048SMadhavan.Venkataraman@Sun.COM coargs->exp = 0;
7648048SMadhavan.Venkataraman@Sun.COM }
7659039SMadhavan.Venkataraman@Sun.COM /* and flags. */
7669039SMadhavan.Venkataraman@Sun.COM if (mdb_vread(&coargs->list_flags, sizeof (int),
7679039SMadhavan.Venkataraman@Sun.COM (uintptr_t)co->c_list + offsetof(callout_list_t,
7689039SMadhavan.Venkataraman@Sun.COM cl_flags)) == -1) {
7699039SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read list flags"
7709039SMadhavan.Venkataraman@Sun.COM "from %p", co->c_list);
7719039SMadhavan.Venkataraman@Sun.COM coargs->list_flags = 0;
7729039SMadhavan.Venkataraman@Sun.COM }
7738048SMadhavan.Venkataraman@Sun.COM } else {
7748048SMadhavan.Venkataraman@Sun.COM /* free callouts can't use list pointer. */
7758048SMadhavan.Venkataraman@Sun.COM coargs->exp = 0;
7769039SMadhavan.Venkataraman@Sun.COM coargs->list_flags = 0;
7779039SMadhavan.Venkataraman@Sun.COM }
7789039SMadhavan.Venkataraman@Sun.COM if (coargs->exp != 0) {
7799039SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_TIME) &&
7809039SMadhavan.Venkataraman@Sun.COM (coargs->exp != coargs->time)) {
7819039SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
7829039SMadhavan.Venkataraman@Sun.COM }
7839039SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_BEFORE) &&
7849039SMadhavan.Venkataraman@Sun.COM (coargs->exp > coargs->btime)) {
7859039SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
7869039SMadhavan.Venkataraman@Sun.COM }
7879039SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_AFTER) &&
7889039SMadhavan.Venkataraman@Sun.COM (coargs->exp < coargs->atime)) {
7899039SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
7909039SMadhavan.Venkataraman@Sun.COM }
7919039SMadhavan.Venkataraman@Sun.COM }
7929039SMadhavan.Venkataraman@Sun.COM /* tricky part, since both HIRES and ABS can be set */
7939334SMadhavan.Venkataraman@Sun.COM list_flags = coargs->list_flags;
7949039SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_HIRES) && (coargs->flags & COF_ABS)) {
7959039SMadhavan.Venkataraman@Sun.COM /* both flags are set, only skip "regular" ones */
7969334SMadhavan.Venkataraman@Sun.COM if (! (list_flags & COF_LIST_FLAGS)) {
7979039SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
7989039SMadhavan.Venkataraman@Sun.COM }
7999039SMadhavan.Venkataraman@Sun.COM } else {
8009039SMadhavan.Venkataraman@Sun.COM /* individual flags, or no flags */
8019039SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_HIRES) &&
8029334SMadhavan.Venkataraman@Sun.COM !(list_flags & CALLOUT_LIST_FLAG_HRESTIME)) {
8039039SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
8049039SMadhavan.Venkataraman@Sun.COM }
8059039SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_ABS) &&
8069334SMadhavan.Venkataraman@Sun.COM !(list_flags & CALLOUT_LIST_FLAG_ABSOLUTE)) {
8079039SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
8089039SMadhavan.Venkataraman@Sun.COM }
8098048SMadhavan.Venkataraman@Sun.COM }
81011745SMadhavan.Venkataraman@Sun.COM /*
81111745SMadhavan.Venkataraman@Sun.COM * We do the checks for COF_HEAP and COF_QUEUE here only if we
81211745SMadhavan.Venkataraman@Sun.COM * are traversing BYIDH. If the traversal is by callout list,
81311745SMadhavan.Venkataraman@Sun.COM * we do this check in callout_list_cb() to be more
81411745SMadhavan.Venkataraman@Sun.COM * efficient.
81511745SMadhavan.Venkataraman@Sun.COM */
81611745SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_HEAP) &&
81711745SMadhavan.Venkataraman@Sun.COM !(list_flags & CALLOUT_LIST_FLAG_HEAPED)) {
81811745SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
81911745SMadhavan.Venkataraman@Sun.COM }
82011745SMadhavan.Venkataraman@Sun.COM
82111745SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_QUEUE) &&
82211745SMadhavan.Venkataraman@Sun.COM !(list_flags & CALLOUT_LIST_FLAG_QUEUED)) {
82311745SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
82411745SMadhavan.Venkataraman@Sun.COM }
8258048SMadhavan.Venkataraman@Sun.COM }
8268048SMadhavan.Venkataraman@Sun.COM
8278048SMadhavan.Venkataraman@Sun.COM #define callout_table_mask ((1 << coargs->ctbits) - 1)
8288048SMadhavan.Venkataraman@Sun.COM tableid = CALLOUT_ID_TO_TABLE(co->c_xid);
8298048SMadhavan.Venkataraman@Sun.COM #undef callout_table_mask
8308048SMadhavan.Venkataraman@Sun.COM coid = CO_PLAIN_ID(co->c_xid);
8318048SMadhavan.Venkataraman@Sun.COM
8328048SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_CHDR) && !(coargs->flags & COF_ADDR)) {
8338048SMadhavan.Venkataraman@Sun.COM /*
8348048SMadhavan.Venkataraman@Sun.COM * We need to print the headers. If walking by id, then
8358048SMadhavan.Venkataraman@Sun.COM * the list header isn't printed, so we must include
8368048SMadhavan.Venkataraman@Sun.COM * that info here.
8378048SMadhavan.Venkataraman@Sun.COM */
8388048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_VERBOSE)) {
8398048SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u>%3s %-1s %-14s %</u>",
8408048SMadhavan.Venkataraman@Sun.COM "SEQ", "T", "EXP");
8418048SMadhavan.Venkataraman@Sun.COM } else if (coargs->flags & COF_BYIDH) {
8428048SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u>%-14s %</u>", "EXP");
8438048SMadhavan.Venkataraman@Sun.COM }
8449039SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u>%-4s %-?s %-20s%</u>",
8459039SMadhavan.Venkataraman@Sun.COM "XHAL", "XID", "FUNC(ARG)");
8468048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_LONGLIST) {
8478048SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u> %-?s %-?s %-?s %-?s%</u>",
8488048SMadhavan.Venkataraman@Sun.COM "PREVID", "NEXTID", "PREVL", "NEXTL");
8499039SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u> %-?s %-4s %-?s%</u>",
8509039SMadhavan.Venkataraman@Sun.COM "DONE", "UTOS", "THREAD");
8518048SMadhavan.Venkataraman@Sun.COM }
8528048SMadhavan.Venkataraman@Sun.COM mdb_printf("\n");
8538048SMadhavan.Venkataraman@Sun.COM coargs->flags &= ~COF_CHDR;
8548048SMadhavan.Venkataraman@Sun.COM coargs->flags |= (COF_THDR | COF_LHDR);
8558048SMadhavan.Venkataraman@Sun.COM }
8568048SMadhavan.Venkataraman@Sun.COM
8578048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_ADDR)) {
8588048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_VERBOSE)) {
8598048SMadhavan.Venkataraman@Sun.COM mdb_printf("%-3d %1s %-14llx ",
8608048SMadhavan.Venkataraman@Sun.COM TABLE_TO_SEQID(tableid),
8618048SMadhavan.Venkataraman@Sun.COM co_typenames[tableid & CALLOUT_TYPE_MASK],
8628048SMadhavan.Venkataraman@Sun.COM (coargs->flags & COF_EXPREL) ?
8638048SMadhavan.Venkataraman@Sun.COM coargs->exp - coargs->now : coargs->exp);
8648048SMadhavan.Venkataraman@Sun.COM } else if (coargs->flags & COF_BYIDH) {
8658048SMadhavan.Venkataraman@Sun.COM mdb_printf("%-14x ",
8668048SMadhavan.Venkataraman@Sun.COM (coargs->flags & COF_EXPREL) ?
8678048SMadhavan.Venkataraman@Sun.COM coargs->exp - coargs->now : coargs->exp);
8688048SMadhavan.Venkataraman@Sun.COM }
8699334SMadhavan.Venkataraman@Sun.COM list_flags = coargs->list_flags;
8709039SMadhavan.Venkataraman@Sun.COM mdb_printf("%1s%1s%1s%1s %-?llx %a(%p)",
8718048SMadhavan.Venkataraman@Sun.COM (co->c_xid & CALLOUT_EXECUTING) ? "X" : " ",
8729334SMadhavan.Venkataraman@Sun.COM (list_flags & CALLOUT_LIST_FLAG_HRESTIME) ? "H" : " ",
8739334SMadhavan.Venkataraman@Sun.COM (list_flags & CALLOUT_LIST_FLAG_ABSOLUTE) ? "A" : " ",
8748048SMadhavan.Venkataraman@Sun.COM (co->c_xid & CALLOUT_LONGTERM) ? "L" : " ",
8758048SMadhavan.Venkataraman@Sun.COM (long long)coid, co->c_func, co->c_arg);
8768048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_LONGLIST) {
8778048SMadhavan.Venkataraman@Sun.COM mdb_printf(" %-?p %-?p %-?p %-?p",
8788048SMadhavan.Venkataraman@Sun.COM co->c_idprev, co->c_idnext, co->c_clprev,
8798048SMadhavan.Venkataraman@Sun.COM co->c_clnext);
8809039SMadhavan.Venkataraman@Sun.COM mdb_printf(" %-?p %-4d %-0?p",
8819039SMadhavan.Venkataraman@Sun.COM co->c_done, co->c_waiting, co->c_executor);
8828048SMadhavan.Venkataraman@Sun.COM }
8838048SMadhavan.Venkataraman@Sun.COM } else {
8848048SMadhavan.Venkataraman@Sun.COM /* address only */
8858048SMadhavan.Venkataraman@Sun.COM mdb_printf("%-0p", addr);
8868048SMadhavan.Venkataraman@Sun.COM }
8878048SMadhavan.Venkataraman@Sun.COM mdb_printf("\n");
8888048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
8898048SMadhavan.Venkataraman@Sun.COM }
8908048SMadhavan.Venkataraman@Sun.COM
8918048SMadhavan.Venkataraman@Sun.COM /* this callback is for callout list handling. idhash is done by callout_t_cb */
8928048SMadhavan.Venkataraman@Sun.COM /*ARGSUSED*/
8938048SMadhavan.Venkataraman@Sun.COM static int
callout_list_cb(uintptr_t addr,const void * data,void * priv)8948048SMadhavan.Venkataraman@Sun.COM callout_list_cb(uintptr_t addr, const void *data, void *priv)
8958048SMadhavan.Venkataraman@Sun.COM {
8968048SMadhavan.Venkataraman@Sun.COM callout_data_t *coargs = (callout_data_t *)priv;
8978048SMadhavan.Venkataraman@Sun.COM callout_list_t *cl = (callout_list_t *)data;
8988048SMadhavan.Venkataraman@Sun.COM callout_t *coptr;
8999334SMadhavan.Venkataraman@Sun.COM int list_flags;
9008048SMadhavan.Venkataraman@Sun.COM
9018048SMadhavan.Venkataraman@Sun.COM if ((coargs == NULL) || (cl == NULL)) {
9028048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
9038048SMadhavan.Venkataraman@Sun.COM }
9048048SMadhavan.Venkataraman@Sun.COM
9058048SMadhavan.Venkataraman@Sun.COM coargs->exp = cl->cl_expiration;
9069039SMadhavan.Venkataraman@Sun.COM coargs->list_flags = cl->cl_flags;
9079334SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_FREE) &&
9089334SMadhavan.Venkataraman@Sun.COM !(cl->cl_flags & CALLOUT_LIST_FLAG_FREE)) {
9099334SMadhavan.Venkataraman@Sun.COM /*
9109334SMadhavan.Venkataraman@Sun.COM * The callout list must have been reallocated. No point in
9119334SMadhavan.Venkataraman@Sun.COM * walking any more.
9129334SMadhavan.Venkataraman@Sun.COM */
9139334SMadhavan.Venkataraman@Sun.COM return (WALK_DONE);
9149334SMadhavan.Venkataraman@Sun.COM }
9159334SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_FREE) &&
9169334SMadhavan.Venkataraman@Sun.COM (cl->cl_flags & CALLOUT_LIST_FLAG_FREE)) {
9179334SMadhavan.Venkataraman@Sun.COM /*
9189334SMadhavan.Venkataraman@Sun.COM * The callout list must have been freed. No point in
9199334SMadhavan.Venkataraman@Sun.COM * walking any more.
9209334SMadhavan.Venkataraman@Sun.COM */
9219334SMadhavan.Venkataraman@Sun.COM return (WALK_DONE);
9229334SMadhavan.Venkataraman@Sun.COM }
9238048SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_TIME) &&
9248048SMadhavan.Venkataraman@Sun.COM (cl->cl_expiration != coargs->time)) {
9258048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
9268048SMadhavan.Venkataraman@Sun.COM }
9278048SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_BEFORE) &&
9288048SMadhavan.Venkataraman@Sun.COM (cl->cl_expiration > coargs->btime)) {
9298048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
9308048SMadhavan.Venkataraman@Sun.COM }
9318048SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_AFTER) &&
9328048SMadhavan.Venkataraman@Sun.COM (cl->cl_expiration < coargs->atime)) {
9338048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
9348048SMadhavan.Venkataraman@Sun.COM }
9358048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_EMPTY) &&
9368048SMadhavan.Venkataraman@Sun.COM (cl->cl_callouts.ch_head == NULL)) {
9378048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
9388048SMadhavan.Venkataraman@Sun.COM }
9399039SMadhavan.Venkataraman@Sun.COM /* FOUR cases, each different, !A!B, !AB, A!B, AB */
9409039SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_HIRES) && (coargs->flags & COF_ABS)) {
9419039SMadhavan.Venkataraman@Sun.COM /* both flags are set, only skip "regular" ones */
9429334SMadhavan.Venkataraman@Sun.COM if (! (cl->cl_flags & COF_LIST_FLAGS)) {
9439039SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
9449039SMadhavan.Venkataraman@Sun.COM }
9459039SMadhavan.Venkataraman@Sun.COM } else {
9469039SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_HIRES) &&
9479334SMadhavan.Venkataraman@Sun.COM !(cl->cl_flags & CALLOUT_LIST_FLAG_HRESTIME)) {
9489039SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
9499039SMadhavan.Venkataraman@Sun.COM }
9509039SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_ABS) &&
9519334SMadhavan.Venkataraman@Sun.COM !(cl->cl_flags & CALLOUT_LIST_FLAG_ABSOLUTE)) {
9529039SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
9539039SMadhavan.Venkataraman@Sun.COM }
9549039SMadhavan.Venkataraman@Sun.COM }
9558048SMadhavan.Venkataraman@Sun.COM
95611745SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_HEAP) &&
95711745SMadhavan.Venkataraman@Sun.COM !(coargs->list_flags & CALLOUT_LIST_FLAG_HEAPED)) {
95811745SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
95911745SMadhavan.Venkataraman@Sun.COM }
96011745SMadhavan.Venkataraman@Sun.COM
96111745SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_QUEUE) &&
96211745SMadhavan.Venkataraman@Sun.COM !(coargs->list_flags & CALLOUT_LIST_FLAG_QUEUED)) {
96311745SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
96411745SMadhavan.Venkataraman@Sun.COM }
96511745SMadhavan.Venkataraman@Sun.COM
9668048SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_LHDR) && !(coargs->flags & COF_ADDR) &&
9678048SMadhavan.Venkataraman@Sun.COM (coargs->flags & (COF_LIST | COF_VERBOSE))) {
9688048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_VERBOSE)) {
9698048SMadhavan.Venkataraman@Sun.COM /* don't be redundant again */
9708048SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u>SEQ T %</u>");
9718048SMadhavan.Venkataraman@Sun.COM }
9729039SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u>EXP HA BUCKET "
9739039SMadhavan.Venkataraman@Sun.COM "CALLOUTS %</u>");
9748048SMadhavan.Venkataraman@Sun.COM
9758048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_LONGLIST) {
9769039SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u> %-?s %-?s%</u>",
9779039SMadhavan.Venkataraman@Sun.COM "PREV", "NEXT");
9788048SMadhavan.Venkataraman@Sun.COM }
9798048SMadhavan.Venkataraman@Sun.COM mdb_printf("\n");
9808048SMadhavan.Venkataraman@Sun.COM coargs->flags &= ~COF_LHDR;
9818048SMadhavan.Venkataraman@Sun.COM coargs->flags |= (COF_THDR | COF_CHDR);
9828048SMadhavan.Venkataraman@Sun.COM }
9838048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & (COF_LIST | COF_VERBOSE)) {
9848048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_ADDR)) {
9858048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_VERBOSE)) {
9868048SMadhavan.Venkataraman@Sun.COM mdb_printf("%3d %1s ",
9878048SMadhavan.Venkataraman@Sun.COM TABLE_TO_SEQID(coargs->ndx),
9888048SMadhavan.Venkataraman@Sun.COM co_typenames[coargs->ndx &
9898048SMadhavan.Venkataraman@Sun.COM CALLOUT_TYPE_MASK]);
9908048SMadhavan.Venkataraman@Sun.COM }
9918048SMadhavan.Venkataraman@Sun.COM
9929334SMadhavan.Venkataraman@Sun.COM list_flags = coargs->list_flags;
9939039SMadhavan.Venkataraman@Sun.COM mdb_printf("%-14llx %1s%1s %-6d %-0?p ",
9948048SMadhavan.Venkataraman@Sun.COM (coargs->flags & COF_EXPREL) ?
9958048SMadhavan.Venkataraman@Sun.COM coargs->exp - coargs->now : coargs->exp,
9969334SMadhavan.Venkataraman@Sun.COM (list_flags & CALLOUT_LIST_FLAG_HRESTIME) ?
9979039SMadhavan.Venkataraman@Sun.COM "H" : " ",
9989334SMadhavan.Venkataraman@Sun.COM (list_flags & CALLOUT_LIST_FLAG_ABSOLUTE) ?
9999039SMadhavan.Venkataraman@Sun.COM "A" : " ",
10009039SMadhavan.Venkataraman@Sun.COM coargs->bucket, cl->cl_callouts.ch_head);
10018048SMadhavan.Venkataraman@Sun.COM
10028048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_LONGLIST) {
10039039SMadhavan.Venkataraman@Sun.COM mdb_printf(" %-?p %-?p",
10049039SMadhavan.Venkataraman@Sun.COM cl->cl_prev, cl->cl_next);
10058048SMadhavan.Venkataraman@Sun.COM }
10068048SMadhavan.Venkataraman@Sun.COM } else {
10078048SMadhavan.Venkataraman@Sun.COM /* address only */
10088048SMadhavan.Venkataraman@Sun.COM mdb_printf("%-0p", addr);
10098048SMadhavan.Venkataraman@Sun.COM }
10108048SMadhavan.Venkataraman@Sun.COM mdb_printf("\n");
10118048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_LIST) {
10128048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
10138048SMadhavan.Venkataraman@Sun.COM }
10148048SMadhavan.Venkataraman@Sun.COM }
10158048SMadhavan.Venkataraman@Sun.COM /* yet another layer as we walk the actual callouts via list. */
10168048SMadhavan.Venkataraman@Sun.COM if (cl->cl_callouts.ch_head == NULL) {
10178048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
10188048SMadhavan.Venkataraman@Sun.COM }
10198048SMadhavan.Venkataraman@Sun.COM /* free list structures do not have valid callouts off of them. */
10208048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_FREE) {
10218048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
10228048SMadhavan.Venkataraman@Sun.COM }
10238048SMadhavan.Venkataraman@Sun.COM coptr = (callout_t *)cl->cl_callouts.ch_head;
10248048SMadhavan.Venkataraman@Sun.COM
10258048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_VERBOSE) {
10268048SMadhavan.Venkataraman@Sun.COM mdb_inc_indent(4);
10278048SMadhavan.Venkataraman@Sun.COM }
10288048SMadhavan.Venkataraman@Sun.COM /*
10298048SMadhavan.Venkataraman@Sun.COM * walk callouts using yet another callback routine.
10308048SMadhavan.Venkataraman@Sun.COM * we use callouts_bytime because id hash is handled via
10318048SMadhavan.Venkataraman@Sun.COM * the callout_t_cb callback.
10328048SMadhavan.Venkataraman@Sun.COM */
10338048SMadhavan.Venkataraman@Sun.COM if (mdb_pwalk("callouts_bytime", callouts_cb, coargs,
10348048SMadhavan.Venkataraman@Sun.COM (uintptr_t)coptr) == -1) {
10358048SMadhavan.Venkataraman@Sun.COM mdb_warn("cannot walk callouts at %p", coptr);
10368048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
10378048SMadhavan.Venkataraman@Sun.COM }
10388048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_VERBOSE) {
10398048SMadhavan.Venkataraman@Sun.COM mdb_dec_indent(4);
10408048SMadhavan.Venkataraman@Sun.COM }
10418048SMadhavan.Venkataraman@Sun.COM
10428048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
10438048SMadhavan.Venkataraman@Sun.COM }
10448048SMadhavan.Venkataraman@Sun.COM
10458048SMadhavan.Venkataraman@Sun.COM /* this callback handles the details of callout table walking. */
10468048SMadhavan.Venkataraman@Sun.COM static int
callout_t_cb(uintptr_t addr,const void * data,void * priv)10478048SMadhavan.Venkataraman@Sun.COM callout_t_cb(uintptr_t addr, const void *data, void *priv)
10488048SMadhavan.Venkataraman@Sun.COM {
10498048SMadhavan.Venkataraman@Sun.COM callout_data_t *coargs = (callout_data_t *)priv;
10508048SMadhavan.Venkataraman@Sun.COM cot_data_t *cotwd = (cot_data_t *)data;
10518048SMadhavan.Venkataraman@Sun.COM callout_table_t *ct = &(cotwd->ct);
10528048SMadhavan.Venkataraman@Sun.COM int index, seqid, cotype;
10538048SMadhavan.Venkataraman@Sun.COM int i;
10548048SMadhavan.Venkataraman@Sun.COM callout_list_t *clptr;
10558048SMadhavan.Venkataraman@Sun.COM callout_t *coptr;
10568048SMadhavan.Venkataraman@Sun.COM
10578048SMadhavan.Venkataraman@Sun.COM if ((coargs == NULL) || (ct == NULL) || (coargs->co_table == NULL)) {
10588048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
10598048SMadhavan.Venkataraman@Sun.COM }
10608048SMadhavan.Venkataraman@Sun.COM
10618048SMadhavan.Venkataraman@Sun.COM index = ((char *)addr - (char *)coargs->co_table) /
10628048SMadhavan.Venkataraman@Sun.COM sizeof (callout_table_t);
10638048SMadhavan.Venkataraman@Sun.COM cotype = index & CALLOUT_TYPE_MASK;
10648048SMadhavan.Venkataraman@Sun.COM seqid = TABLE_TO_SEQID(index);
10658048SMadhavan.Venkataraman@Sun.COM
10668048SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_SEQID) && (coargs->seqid != seqid)) {
10678048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
10688048SMadhavan.Venkataraman@Sun.COM }
10698048SMadhavan.Venkataraman@Sun.COM
10708048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_REAL) && (cotype == CALLOUT_REALTIME)) {
10718048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
10728048SMadhavan.Venkataraman@Sun.COM }
10738048SMadhavan.Venkataraman@Sun.COM
10748048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_NORM) && (cotype == CALLOUT_NORMAL)) {
10758048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
10768048SMadhavan.Venkataraman@Sun.COM }
10778048SMadhavan.Venkataraman@Sun.COM
10788048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_EMPTY) && (
10798048SMadhavan.Venkataraman@Sun.COM (ct->ct_heap == NULL) || (ct->ct_cyclic == NULL))) {
10808048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
10818048SMadhavan.Venkataraman@Sun.COM }
10828048SMadhavan.Venkataraman@Sun.COM
10838048SMadhavan.Venkataraman@Sun.COM if ((coargs->flags & COF_THDR) && !(coargs->flags & COF_ADDR) &&
10848048SMadhavan.Venkataraman@Sun.COM (coargs->flags & (COF_TABLE | COF_VERBOSE))) {
10858048SMadhavan.Venkataraman@Sun.COM /* print table hdr */
10868048SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u>%-3s %-1s %-?s %-?s %-?s %-?s%</u>",
10878048SMadhavan.Venkataraman@Sun.COM "SEQ", "T", "FREE", "LFREE", "CYCLIC", "HEAP");
10888048SMadhavan.Venkataraman@Sun.COM coargs->flags &= ~COF_THDR;
10898048SMadhavan.Venkataraman@Sun.COM coargs->flags |= (COF_LHDR | COF_CHDR);
10908048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_LONGLIST) {
10918048SMadhavan.Venkataraman@Sun.COM /* more info! */
109211745SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u> %-T%-7s %-7s %-?s %-?s %-?s"
10938048SMadhavan.Venkataraman@Sun.COM " %-?s %-?s %-?s%</u>",
109411745SMadhavan.Venkataraman@Sun.COM "HEAPNUM", "HEAPMAX", "TASKQ", "EXPQ", "QUE",
10958048SMadhavan.Venkataraman@Sun.COM "PEND", "FREE", "LOCK");
10968048SMadhavan.Venkataraman@Sun.COM }
10978048SMadhavan.Venkataraman@Sun.COM mdb_printf("\n");
10988048SMadhavan.Venkataraman@Sun.COM }
10998048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & (COF_TABLE | COF_VERBOSE)) {
11008048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_ADDR)) {
11018048SMadhavan.Venkataraman@Sun.COM mdb_printf("%-3d %-1s %-0?p %-0?p %-0?p %-?p",
11028048SMadhavan.Venkataraman@Sun.COM seqid, co_typenames[cotype],
11038048SMadhavan.Venkataraman@Sun.COM ct->ct_free, ct->ct_lfree, ct->ct_cyclic,
11048048SMadhavan.Venkataraman@Sun.COM ct->ct_heap);
11058048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_LONGLIST) {
11068048SMadhavan.Venkataraman@Sun.COM /* more info! */
110711745SMadhavan.Venkataraman@Sun.COM mdb_printf(" %-7d %-7d %-?p %-?p %-?p"
11088048SMadhavan.Venkataraman@Sun.COM " %-?lld %-?lld %-?p",
11098048SMadhavan.Venkataraman@Sun.COM ct->ct_heap_num, ct->ct_heap_max,
11108048SMadhavan.Venkataraman@Sun.COM ct->ct_taskq, ct->ct_expired.ch_head,
111111745SMadhavan.Venkataraman@Sun.COM ct->ct_queue.ch_head,
11128048SMadhavan.Venkataraman@Sun.COM cotwd->ct_timeouts_pending,
11138048SMadhavan.Venkataraman@Sun.COM cotwd->ct_allocations -
11148048SMadhavan.Venkataraman@Sun.COM cotwd->ct_timeouts_pending,
11158048SMadhavan.Venkataraman@Sun.COM ct->ct_mutex);
11168048SMadhavan.Venkataraman@Sun.COM }
11178048SMadhavan.Venkataraman@Sun.COM } else {
11188048SMadhavan.Venkataraman@Sun.COM /* address only */
11198048SMadhavan.Venkataraman@Sun.COM mdb_printf("%-0?p", addr);
11208048SMadhavan.Venkataraman@Sun.COM }
11218048SMadhavan.Venkataraman@Sun.COM mdb_printf("\n");
11228048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_TABLE) {
11238048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
11248048SMadhavan.Venkataraman@Sun.COM }
11258048SMadhavan.Venkataraman@Sun.COM }
11268048SMadhavan.Venkataraman@Sun.COM
11278048SMadhavan.Venkataraman@Sun.COM coargs->ndx = index;
11288048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_VERBOSE) {
11298048SMadhavan.Venkataraman@Sun.COM mdb_inc_indent(4);
11308048SMadhavan.Venkataraman@Sun.COM }
11318048SMadhavan.Venkataraman@Sun.COM /* keep digging. */
11328048SMadhavan.Venkataraman@Sun.COM if (!(coargs->flags & COF_BYIDH)) {
11338048SMadhavan.Venkataraman@Sun.COM /* walk the list hash table */
11348048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_FREE) {
11358048SMadhavan.Venkataraman@Sun.COM clptr = ct->ct_lfree;
11368048SMadhavan.Venkataraman@Sun.COM coargs->bucket = 0;
11378048SMadhavan.Venkataraman@Sun.COM if (clptr == NULL) {
11388048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
11398048SMadhavan.Venkataraman@Sun.COM }
11408048SMadhavan.Venkataraman@Sun.COM if (mdb_pwalk("callout_list", callout_list_cb, coargs,
11418048SMadhavan.Venkataraman@Sun.COM (uintptr_t)clptr) == -1) {
11428048SMadhavan.Venkataraman@Sun.COM mdb_warn("cannot walk callout free list at %p",
11438048SMadhavan.Venkataraman@Sun.COM clptr);
11448048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
11458048SMadhavan.Venkataraman@Sun.COM }
11468048SMadhavan.Venkataraman@Sun.COM } else {
11478048SMadhavan.Venkataraman@Sun.COM /* first print the expired list. */
11488048SMadhavan.Venkataraman@Sun.COM clptr = (callout_list_t *)ct->ct_expired.ch_head;
11498048SMadhavan.Venkataraman@Sun.COM if (clptr != NULL) {
11508048SMadhavan.Venkataraman@Sun.COM coargs->bucket = -1;
11518048SMadhavan.Venkataraman@Sun.COM if (mdb_pwalk("callout_list", callout_list_cb,
11528048SMadhavan.Venkataraman@Sun.COM coargs, (uintptr_t)clptr) == -1) {
11538048SMadhavan.Venkataraman@Sun.COM mdb_warn("cannot walk callout_list"
11548048SMadhavan.Venkataraman@Sun.COM " at %p", clptr);
11558048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
11568048SMadhavan.Venkataraman@Sun.COM }
11578048SMadhavan.Venkataraman@Sun.COM }
115811745SMadhavan.Venkataraman@Sun.COM /* then, print the callout queue */
115911745SMadhavan.Venkataraman@Sun.COM clptr = (callout_list_t *)ct->ct_queue.ch_head;
116011745SMadhavan.Venkataraman@Sun.COM if (clptr != NULL) {
116111745SMadhavan.Venkataraman@Sun.COM coargs->bucket = -1;
116211745SMadhavan.Venkataraman@Sun.COM if (mdb_pwalk("callout_list", callout_list_cb,
116311745SMadhavan.Venkataraman@Sun.COM coargs, (uintptr_t)clptr) == -1) {
116411745SMadhavan.Venkataraman@Sun.COM mdb_warn("cannot walk callout_list"
116511745SMadhavan.Venkataraman@Sun.COM " at %p", clptr);
116611745SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
116711745SMadhavan.Venkataraman@Sun.COM }
116811745SMadhavan.Venkataraman@Sun.COM }
11698048SMadhavan.Venkataraman@Sun.COM for (i = 0; i < CALLOUT_BUCKETS; i++) {
11708048SMadhavan.Venkataraman@Sun.COM if (ct->ct_clhash == NULL) {
11718048SMadhavan.Venkataraman@Sun.COM /* nothing to do */
11728048SMadhavan.Venkataraman@Sun.COM break;
11738048SMadhavan.Venkataraman@Sun.COM }
11748048SMadhavan.Venkataraman@Sun.COM if (cotwd->cot_clhash[i].ch_head == NULL) {
11758048SMadhavan.Venkataraman@Sun.COM continue;
11768048SMadhavan.Venkataraman@Sun.COM }
11778048SMadhavan.Venkataraman@Sun.COM clptr = (callout_list_t *)
11788048SMadhavan.Venkataraman@Sun.COM cotwd->cot_clhash[i].ch_head;
11798048SMadhavan.Venkataraman@Sun.COM coargs->bucket = i;
11808048SMadhavan.Venkataraman@Sun.COM /* walk list with callback routine. */
11818048SMadhavan.Venkataraman@Sun.COM if (mdb_pwalk("callout_list", callout_list_cb,
11828048SMadhavan.Venkataraman@Sun.COM coargs, (uintptr_t)clptr) == -1) {
11838048SMadhavan.Venkataraman@Sun.COM mdb_warn("cannot walk callout_list"
11848048SMadhavan.Venkataraman@Sun.COM " at %p", clptr);
11858048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
11868048SMadhavan.Venkataraman@Sun.COM }
11878048SMadhavan.Venkataraman@Sun.COM }
11888048SMadhavan.Venkataraman@Sun.COM }
11898048SMadhavan.Venkataraman@Sun.COM } else {
11908048SMadhavan.Venkataraman@Sun.COM /* walk the id hash table. */
11918048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_FREE) {
11928048SMadhavan.Venkataraman@Sun.COM coptr = ct->ct_free;
11938048SMadhavan.Venkataraman@Sun.COM coargs->bucket = 0;
11948048SMadhavan.Venkataraman@Sun.COM if (coptr == NULL) {
11958048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
11968048SMadhavan.Venkataraman@Sun.COM }
11978048SMadhavan.Venkataraman@Sun.COM if (mdb_pwalk("callouts_byid", callouts_cb, coargs,
11988048SMadhavan.Venkataraman@Sun.COM (uintptr_t)coptr) == -1) {
11998048SMadhavan.Venkataraman@Sun.COM mdb_warn("cannot walk callout id free list"
12008048SMadhavan.Venkataraman@Sun.COM " at %p", coptr);
12018048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
12028048SMadhavan.Venkataraman@Sun.COM }
12038048SMadhavan.Venkataraman@Sun.COM } else {
12048048SMadhavan.Venkataraman@Sun.COM for (i = 0; i < CALLOUT_BUCKETS; i++) {
12058048SMadhavan.Venkataraman@Sun.COM if (ct->ct_idhash == NULL) {
12068048SMadhavan.Venkataraman@Sun.COM break;
12078048SMadhavan.Venkataraman@Sun.COM }
12088048SMadhavan.Venkataraman@Sun.COM coptr = (callout_t *)
12098048SMadhavan.Venkataraman@Sun.COM cotwd->cot_idhash[i].ch_head;
12108048SMadhavan.Venkataraman@Sun.COM if (coptr == NULL) {
12118048SMadhavan.Venkataraman@Sun.COM continue;
12128048SMadhavan.Venkataraman@Sun.COM }
12138048SMadhavan.Venkataraman@Sun.COM coargs->bucket = i;
12148048SMadhavan.Venkataraman@Sun.COM
12158048SMadhavan.Venkataraman@Sun.COM /*
12168048SMadhavan.Venkataraman@Sun.COM * walk callouts directly by id. For id
12178048SMadhavan.Venkataraman@Sun.COM * chain, the callout list is just a header,
12188048SMadhavan.Venkataraman@Sun.COM * so there's no need to walk it.
12198048SMadhavan.Venkataraman@Sun.COM */
12208048SMadhavan.Venkataraman@Sun.COM if (mdb_pwalk("callouts_byid", callouts_cb,
12218048SMadhavan.Venkataraman@Sun.COM coargs, (uintptr_t)coptr) == -1) {
12228048SMadhavan.Venkataraman@Sun.COM mdb_warn("cannot walk callouts at %p",
12238048SMadhavan.Venkataraman@Sun.COM coptr);
12248048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
12258048SMadhavan.Venkataraman@Sun.COM }
12268048SMadhavan.Venkataraman@Sun.COM }
12278048SMadhavan.Venkataraman@Sun.COM }
12288048SMadhavan.Venkataraman@Sun.COM }
12298048SMadhavan.Venkataraman@Sun.COM if (coargs->flags & COF_VERBOSE) {
12308048SMadhavan.Venkataraman@Sun.COM mdb_dec_indent(4);
12318048SMadhavan.Venkataraman@Sun.COM }
12328048SMadhavan.Venkataraman@Sun.COM return (WALK_NEXT);
12338048SMadhavan.Venkataraman@Sun.COM }
12348048SMadhavan.Venkataraman@Sun.COM
12358048SMadhavan.Venkataraman@Sun.COM /*
12368048SMadhavan.Venkataraman@Sun.COM * initialize some common info for both callout dcmds.
12378048SMadhavan.Venkataraman@Sun.COM */
12388048SMadhavan.Venkataraman@Sun.COM int
callout_common_init(callout_data_t * coargs)12398048SMadhavan.Venkataraman@Sun.COM callout_common_init(callout_data_t *coargs)
12408048SMadhavan.Venkataraman@Sun.COM {
12418048SMadhavan.Venkataraman@Sun.COM /* we need a couple of things */
12428048SMadhavan.Venkataraman@Sun.COM if (mdb_readvar(&(coargs->co_table), "callout_table") == -1) {
12438048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read 'callout_table'");
12448048SMadhavan.Venkataraman@Sun.COM return (DCMD_ERR);
12458048SMadhavan.Venkataraman@Sun.COM }
12468048SMadhavan.Venkataraman@Sun.COM /* need to get now in nsecs. Approximate with hrtime vars */
12478048SMadhavan.Venkataraman@Sun.COM if (mdb_readsym(&(coargs->now), sizeof (hrtime_t), "hrtime_last") !=
12488048SMadhavan.Venkataraman@Sun.COM sizeof (hrtime_t)) {
12498048SMadhavan.Venkataraman@Sun.COM if (mdb_readsym(&(coargs->now), sizeof (hrtime_t),
12508048SMadhavan.Venkataraman@Sun.COM "hrtime_base") != sizeof (hrtime_t)) {
12518048SMadhavan.Venkataraman@Sun.COM mdb_warn("Could not determine current system time");
12528048SMadhavan.Venkataraman@Sun.COM return (DCMD_ERR);
12538048SMadhavan.Venkataraman@Sun.COM }
12548048SMadhavan.Venkataraman@Sun.COM }
12558048SMadhavan.Venkataraman@Sun.COM
12568048SMadhavan.Venkataraman@Sun.COM if (mdb_readvar(&(coargs->ctbits), "callout_table_bits") == -1) {
12578048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read 'callout_table_bits'");
12588048SMadhavan.Venkataraman@Sun.COM return (DCMD_ERR);
12598048SMadhavan.Venkataraman@Sun.COM }
12608048SMadhavan.Venkataraman@Sun.COM if (mdb_readvar(&(coargs->nsec_per_tick), "nsec_per_tick") == -1) {
12618048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read 'nsec_per_tick'");
12628048SMadhavan.Venkataraman@Sun.COM return (DCMD_ERR);
12638048SMadhavan.Venkataraman@Sun.COM }
12648048SMadhavan.Venkataraman@Sun.COM return (DCMD_OK);
12658048SMadhavan.Venkataraman@Sun.COM }
12668048SMadhavan.Venkataraman@Sun.COM
12678048SMadhavan.Venkataraman@Sun.COM /*
12688048SMadhavan.Venkataraman@Sun.COM * dcmd to print callouts. Optional addr limits to specific table.
12698048SMadhavan.Venkataraman@Sun.COM * Parses lots of options that get passed to callbacks for walkers.
12708048SMadhavan.Venkataraman@Sun.COM * Has it's own help function.
12718048SMadhavan.Venkataraman@Sun.COM */
12720Sstevel@tonic-gate /*ARGSUSED*/
12730Sstevel@tonic-gate int
callout(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)12740Sstevel@tonic-gate callout(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
12750Sstevel@tonic-gate {
12768048SMadhavan.Venkataraman@Sun.COM callout_data_t coargs;
12778048SMadhavan.Venkataraman@Sun.COM /* getopts doesn't help much with stuff like this */
12788048SMadhavan.Venkataraman@Sun.COM boolean_t Sflag, Cflag, tflag, aflag, bflag, dflag, kflag;
12798048SMadhavan.Venkataraman@Sun.COM char *funcname = NULL;
12808048SMadhavan.Venkataraman@Sun.COM char *paramstr = NULL;
12818048SMadhavan.Venkataraman@Sun.COM uintptr_t Stmp, Ctmp; /* for getopt. */
12828048SMadhavan.Venkataraman@Sun.COM int retval;
12838048SMadhavan.Venkataraman@Sun.COM
12848048SMadhavan.Venkataraman@Sun.COM coargs.flags = COF_DEFAULT;
12858048SMadhavan.Venkataraman@Sun.COM Sflag = Cflag = tflag = bflag = aflag = dflag = kflag = FALSE;
12868048SMadhavan.Venkataraman@Sun.COM coargs.seqid = -1;
12878048SMadhavan.Venkataraman@Sun.COM
12888048SMadhavan.Venkataraman@Sun.COM if (mdb_getopts(argc, argv,
12898048SMadhavan.Venkataraman@Sun.COM 'r', MDB_OPT_CLRBITS, COF_NORM, &coargs.flags,
12908048SMadhavan.Venkataraman@Sun.COM 'n', MDB_OPT_CLRBITS, COF_REAL, &coargs.flags,
12918048SMadhavan.Venkataraman@Sun.COM 'l', MDB_OPT_CLRBITS, COF_SHORT, &coargs.flags,
12928048SMadhavan.Venkataraman@Sun.COM 's', MDB_OPT_CLRBITS, COF_LONG, &coargs.flags,
12938048SMadhavan.Venkataraman@Sun.COM 'x', MDB_OPT_SETBITS, COF_EXEC, &coargs.flags,
12948048SMadhavan.Venkataraman@Sun.COM 'h', MDB_OPT_SETBITS, COF_HIRES, &coargs.flags,
12959039SMadhavan.Venkataraman@Sun.COM 'B', MDB_OPT_SETBITS, COF_ABS, &coargs.flags,
12968048SMadhavan.Venkataraman@Sun.COM 'E', MDB_OPT_SETBITS, COF_EMPTY, &coargs.flags,
12978048SMadhavan.Venkataraman@Sun.COM 'd', MDB_OPT_SETBITS, 1, &dflag,
12988048SMadhavan.Venkataraman@Sun.COM 'C', MDB_OPT_UINTPTR_SET, &Cflag, &Ctmp,
12998048SMadhavan.Venkataraman@Sun.COM 'S', MDB_OPT_UINTPTR_SET, &Sflag, &Stmp,
13008048SMadhavan.Venkataraman@Sun.COM 't', MDB_OPT_UINTPTR_SET, &tflag, (uintptr_t *)&coargs.time,
13018048SMadhavan.Venkataraman@Sun.COM 'a', MDB_OPT_UINTPTR_SET, &aflag, (uintptr_t *)&coargs.atime,
13028048SMadhavan.Venkataraman@Sun.COM 'b', MDB_OPT_UINTPTR_SET, &bflag, (uintptr_t *)&coargs.btime,
13038048SMadhavan.Venkataraman@Sun.COM 'k', MDB_OPT_SETBITS, 1, &kflag,
13048048SMadhavan.Venkataraman@Sun.COM 'f', MDB_OPT_STR, &funcname,
13058048SMadhavan.Venkataraman@Sun.COM 'p', MDB_OPT_STR, ¶mstr,
13068048SMadhavan.Venkataraman@Sun.COM 'T', MDB_OPT_SETBITS, COF_TABLE, &coargs.flags,
13078048SMadhavan.Venkataraman@Sun.COM 'D', MDB_OPT_SETBITS, COF_EXPREL, &coargs.flags,
13088048SMadhavan.Venkataraman@Sun.COM 'L', MDB_OPT_SETBITS, COF_LIST, &coargs.flags,
13098048SMadhavan.Venkataraman@Sun.COM 'V', MDB_OPT_SETBITS, COF_VERBOSE, &coargs.flags,
13108048SMadhavan.Venkataraman@Sun.COM 'v', MDB_OPT_SETBITS, COF_LONGLIST, &coargs.flags,
13118048SMadhavan.Venkataraman@Sun.COM 'i', MDB_OPT_SETBITS, COF_BYIDH, &coargs.flags,
13128048SMadhavan.Venkataraman@Sun.COM 'F', MDB_OPT_SETBITS, COF_FREE, &coargs.flags,
131311745SMadhavan.Venkataraman@Sun.COM 'H', MDB_OPT_SETBITS, COF_HEAP, &coargs.flags,
131411745SMadhavan.Venkataraman@Sun.COM 'Q', MDB_OPT_SETBITS, COF_QUEUE, &coargs.flags,
13158048SMadhavan.Venkataraman@Sun.COM 'A', MDB_OPT_SETBITS, COF_ADDR, &coargs.flags,
13168048SMadhavan.Venkataraman@Sun.COM NULL) != argc) {
13170Sstevel@tonic-gate return (DCMD_USAGE);
13188048SMadhavan.Venkataraman@Sun.COM }
13198048SMadhavan.Venkataraman@Sun.COM
13208048SMadhavan.Venkataraman@Sun.COM /* initialize from kernel variables */
13218048SMadhavan.Venkataraman@Sun.COM if ((retval = callout_common_init(&coargs)) != DCMD_OK) {
13228048SMadhavan.Venkataraman@Sun.COM return (retval);
13238048SMadhavan.Venkataraman@Sun.COM }
13248048SMadhavan.Venkataraman@Sun.COM
13258048SMadhavan.Venkataraman@Sun.COM /* do some option post-processing */
13268048SMadhavan.Venkataraman@Sun.COM if (kflag) {
13278048SMadhavan.Venkataraman@Sun.COM coargs.time *= coargs.nsec_per_tick;
13288048SMadhavan.Venkataraman@Sun.COM coargs.atime *= coargs.nsec_per_tick;
13298048SMadhavan.Venkataraman@Sun.COM coargs.btime *= coargs.nsec_per_tick;
13308048SMadhavan.Venkataraman@Sun.COM }
13318048SMadhavan.Venkataraman@Sun.COM
13328048SMadhavan.Venkataraman@Sun.COM if (dflag) {
13338048SMadhavan.Venkataraman@Sun.COM coargs.time += coargs.now;
13348048SMadhavan.Venkataraman@Sun.COM coargs.atime += coargs.now;
13358048SMadhavan.Venkataraman@Sun.COM coargs.btime += coargs.now;
13368048SMadhavan.Venkataraman@Sun.COM }
13378048SMadhavan.Venkataraman@Sun.COM if (Sflag) {
13388048SMadhavan.Venkataraman@Sun.COM if (flags & DCMD_ADDRSPEC) {
13398048SMadhavan.Venkataraman@Sun.COM mdb_printf("-S option conflicts with explicit"
13408048SMadhavan.Venkataraman@Sun.COM " address\n");
13418048SMadhavan.Venkataraman@Sun.COM return (DCMD_USAGE);
13428048SMadhavan.Venkataraman@Sun.COM }
13438048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_SEQID;
13448048SMadhavan.Venkataraman@Sun.COM coargs.seqid = (int)Stmp;
13458048SMadhavan.Venkataraman@Sun.COM }
13468048SMadhavan.Venkataraman@Sun.COM if (Cflag) {
13478048SMadhavan.Venkataraman@Sun.COM if (flags & DCMD_ADDRSPEC) {
13488048SMadhavan.Venkataraman@Sun.COM mdb_printf("-C option conflicts with explicit"
13498048SMadhavan.Venkataraman@Sun.COM " address\n");
13508048SMadhavan.Venkataraman@Sun.COM return (DCMD_USAGE);
13518048SMadhavan.Venkataraman@Sun.COM }
13528048SMadhavan.Venkataraman@Sun.COM if (coargs.flags & COF_SEQID) {
13538048SMadhavan.Venkataraman@Sun.COM mdb_printf("-C and -S are mutually exclusive\n");
13548048SMadhavan.Venkataraman@Sun.COM return (DCMD_USAGE);
13558048SMadhavan.Venkataraman@Sun.COM }
13568048SMadhavan.Venkataraman@Sun.COM coargs.cpu = (cpu_t *)Ctmp;
13578048SMadhavan.Venkataraman@Sun.COM if (mdb_vread(&coargs.seqid, sizeof (processorid_t),
13588048SMadhavan.Venkataraman@Sun.COM (uintptr_t)&(coargs.cpu->cpu_seqid)) == -1) {
13598048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read cpu_t at %p", Ctmp);
13608048SMadhavan.Venkataraman@Sun.COM return (DCMD_ERR);
13618048SMadhavan.Venkataraman@Sun.COM }
13628048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_SEQID;
13638048SMadhavan.Venkataraman@Sun.COM }
13648048SMadhavan.Venkataraman@Sun.COM /* avoid null outputs. */
13658048SMadhavan.Venkataraman@Sun.COM if (!(coargs.flags & (COF_REAL | COF_NORM))) {
13668048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_REAL | COF_NORM;
13678048SMadhavan.Venkataraman@Sun.COM }
13688048SMadhavan.Venkataraman@Sun.COM if (!(coargs.flags & (COF_LONG | COF_SHORT))) {
13698048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_LONG | COF_SHORT;
13708048SMadhavan.Venkataraman@Sun.COM }
13718048SMadhavan.Venkataraman@Sun.COM if (tflag) {
13728048SMadhavan.Venkataraman@Sun.COM if (aflag || bflag) {
13738048SMadhavan.Venkataraman@Sun.COM mdb_printf("-t and -a|b are mutually exclusive\n");
13748048SMadhavan.Venkataraman@Sun.COM return (DCMD_USAGE);
13758048SMadhavan.Venkataraman@Sun.COM }
13768048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_TIME;
13778048SMadhavan.Venkataraman@Sun.COM }
13788048SMadhavan.Venkataraman@Sun.COM if (aflag) {
13798048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_AFTER;
13808048SMadhavan.Venkataraman@Sun.COM }
13818048SMadhavan.Venkataraman@Sun.COM if (bflag) {
13828048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_BEFORE;
13838048SMadhavan.Venkataraman@Sun.COM }
13848048SMadhavan.Venkataraman@Sun.COM if ((aflag && bflag) && (coargs.btime <= coargs.atime)) {
13858048SMadhavan.Venkataraman@Sun.COM mdb_printf("value for -a must be earlier than the value"
13868048SMadhavan.Venkataraman@Sun.COM " for -b.\n");
13878048SMadhavan.Venkataraman@Sun.COM return (DCMD_USAGE);
13888048SMadhavan.Venkataraman@Sun.COM }
13898048SMadhavan.Venkataraman@Sun.COM
139011745SMadhavan.Venkataraman@Sun.COM if ((coargs.flags & COF_HEAP) && (coargs.flags & COF_QUEUE)) {
139111745SMadhavan.Venkataraman@Sun.COM mdb_printf("-H and -Q are mutually exclusive\n");
139211745SMadhavan.Venkataraman@Sun.COM return (DCMD_USAGE);
139311745SMadhavan.Venkataraman@Sun.COM }
139411745SMadhavan.Venkataraman@Sun.COM
13958048SMadhavan.Venkataraman@Sun.COM if (funcname != NULL) {
13968048SMadhavan.Venkataraman@Sun.COM GElf_Sym sym;
13978048SMadhavan.Venkataraman@Sun.COM
13988048SMadhavan.Venkataraman@Sun.COM if (mdb_lookup_by_name(funcname, &sym) != 0) {
13998048SMadhavan.Venkataraman@Sun.COM coargs.funcaddr = mdb_strtoull(funcname);
14008048SMadhavan.Venkataraman@Sun.COM } else {
14018048SMadhavan.Venkataraman@Sun.COM coargs.funcaddr = sym.st_value;
14028048SMadhavan.Venkataraman@Sun.COM }
14038048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_FUNC;
14048048SMadhavan.Venkataraman@Sun.COM }
14058048SMadhavan.Venkataraman@Sun.COM
14068048SMadhavan.Venkataraman@Sun.COM if (paramstr != NULL) {
14078048SMadhavan.Venkataraman@Sun.COM GElf_Sym sym;
14088048SMadhavan.Venkataraman@Sun.COM
14098048SMadhavan.Venkataraman@Sun.COM if (mdb_lookup_by_name(paramstr, &sym) != 0) {
14108048SMadhavan.Venkataraman@Sun.COM coargs.param = mdb_strtoull(paramstr);
14118048SMadhavan.Venkataraman@Sun.COM } else {
14128048SMadhavan.Venkataraman@Sun.COM coargs.param = sym.st_value;
14138048SMadhavan.Venkataraman@Sun.COM }
14148048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_PARAM;
14158048SMadhavan.Venkataraman@Sun.COM }
14168048SMadhavan.Venkataraman@Sun.COM
14178048SMadhavan.Venkataraman@Sun.COM if (!(flags & DCMD_ADDRSPEC)) {
14188048SMadhavan.Venkataraman@Sun.COM /* don't pass "dot" if no addr. */
14198048SMadhavan.Venkataraman@Sun.COM addr = NULL;
14208048SMadhavan.Venkataraman@Sun.COM }
14218048SMadhavan.Venkataraman@Sun.COM if (addr != NULL) {
14228048SMadhavan.Venkataraman@Sun.COM /*
14238048SMadhavan.Venkataraman@Sun.COM * a callout table was specified. Ignore -r|n option
14248048SMadhavan.Venkataraman@Sun.COM * to avoid null output.
14258048SMadhavan.Venkataraman@Sun.COM */
14268048SMadhavan.Venkataraman@Sun.COM coargs.flags |= (COF_REAL | COF_NORM);
14278048SMadhavan.Venkataraman@Sun.COM }
14288048SMadhavan.Venkataraman@Sun.COM
14298048SMadhavan.Venkataraman@Sun.COM if (DCMD_HDRSPEC(flags) || (coargs.flags & COF_VERBOSE)) {
14308048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_THDR | COF_LHDR | COF_CHDR;
14318048SMadhavan.Venkataraman@Sun.COM }
14328048SMadhavan.Venkataraman@Sun.COM if (coargs.flags & COF_FREE) {
14338048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_EMPTY;
14348048SMadhavan.Venkataraman@Sun.COM /* -F = free callouts, -FL = free lists */
14358048SMadhavan.Venkataraman@Sun.COM if (!(coargs.flags & COF_LIST)) {
14368048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_BYIDH;
14378048SMadhavan.Venkataraman@Sun.COM }
14388048SMadhavan.Venkataraman@Sun.COM }
14398048SMadhavan.Venkataraman@Sun.COM
14408048SMadhavan.Venkataraman@Sun.COM /* walk table, using specialized callback routine. */
14418048SMadhavan.Venkataraman@Sun.COM if (mdb_pwalk("callout_table", callout_t_cb, &coargs, addr) == -1) {
14428048SMadhavan.Venkataraman@Sun.COM mdb_warn("cannot walk callout_table");
14430Sstevel@tonic-gate return (DCMD_ERR);
14440Sstevel@tonic-gate }
14458048SMadhavan.Venkataraman@Sun.COM return (DCMD_OK);
14468048SMadhavan.Venkataraman@Sun.COM }
14478048SMadhavan.Venkataraman@Sun.COM
14488048SMadhavan.Venkataraman@Sun.COM
14498048SMadhavan.Venkataraman@Sun.COM /*
14508048SMadhavan.Venkataraman@Sun.COM * Given an extended callout id, dump its information.
14518048SMadhavan.Venkataraman@Sun.COM */
14528048SMadhavan.Venkataraman@Sun.COM /*ARGSUSED*/
14538048SMadhavan.Venkataraman@Sun.COM int
calloutid(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)14548048SMadhavan.Venkataraman@Sun.COM calloutid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
14558048SMadhavan.Venkataraman@Sun.COM {
14568048SMadhavan.Venkataraman@Sun.COM callout_data_t coargs;
14578048SMadhavan.Venkataraman@Sun.COM callout_table_t *ctptr;
14588048SMadhavan.Venkataraman@Sun.COM callout_table_t ct;
14598048SMadhavan.Venkataraman@Sun.COM callout_id_t coid;
14608048SMadhavan.Venkataraman@Sun.COM callout_t *coptr;
14618048SMadhavan.Venkataraman@Sun.COM int tableid;
14628048SMadhavan.Venkataraman@Sun.COM callout_id_t xid;
14638048SMadhavan.Venkataraman@Sun.COM ulong_t idhash;
14648048SMadhavan.Venkataraman@Sun.COM int i, retval;
14658048SMadhavan.Venkataraman@Sun.COM const mdb_arg_t *arg;
14668048SMadhavan.Venkataraman@Sun.COM size_t size;
14678048SMadhavan.Venkataraman@Sun.COM callout_hash_t cot_idhash[CALLOUT_BUCKETS];
14688048SMadhavan.Venkataraman@Sun.COM
14698048SMadhavan.Venkataraman@Sun.COM coargs.flags = COF_DEFAULT | COF_BYIDH;
14708048SMadhavan.Venkataraman@Sun.COM i = mdb_getopts(argc, argv,
14718048SMadhavan.Venkataraman@Sun.COM 'd', MDB_OPT_SETBITS, COF_DECODE, &coargs.flags,
14728048SMadhavan.Venkataraman@Sun.COM 'v', MDB_OPT_SETBITS, COF_LONGLIST, &coargs.flags,
14738048SMadhavan.Venkataraman@Sun.COM NULL);
14748048SMadhavan.Venkataraman@Sun.COM argc -= i;
14758048SMadhavan.Venkataraman@Sun.COM argv += i;
14768048SMadhavan.Venkataraman@Sun.COM
14778048SMadhavan.Venkataraman@Sun.COM if (argc != 1) {
14788048SMadhavan.Venkataraman@Sun.COM return (DCMD_USAGE);
14798048SMadhavan.Venkataraman@Sun.COM }
14808048SMadhavan.Venkataraman@Sun.COM arg = &argv[0];
14818048SMadhavan.Venkataraman@Sun.COM
14828048SMadhavan.Venkataraman@Sun.COM if (arg->a_type == MDB_TYPE_IMMEDIATE) {
14838048SMadhavan.Venkataraman@Sun.COM xid = arg->a_un.a_val;
14848048SMadhavan.Venkataraman@Sun.COM } else {
14858048SMadhavan.Venkataraman@Sun.COM xid = (callout_id_t)mdb_strtoull(arg->a_un.a_str);
14868048SMadhavan.Venkataraman@Sun.COM }
14878048SMadhavan.Venkataraman@Sun.COM
14888048SMadhavan.Venkataraman@Sun.COM if (DCMD_HDRSPEC(flags)) {
14898048SMadhavan.Venkataraman@Sun.COM coargs.flags |= COF_CHDR;
14908048SMadhavan.Venkataraman@Sun.COM }
14918048SMadhavan.Venkataraman@Sun.COM
14928048SMadhavan.Venkataraman@Sun.COM
14938048SMadhavan.Venkataraman@Sun.COM /* initialize from kernel variables */
14948048SMadhavan.Venkataraman@Sun.COM if ((retval = callout_common_init(&coargs)) != DCMD_OK) {
14958048SMadhavan.Venkataraman@Sun.COM return (retval);
14968048SMadhavan.Venkataraman@Sun.COM }
14978048SMadhavan.Venkataraman@Sun.COM
14988048SMadhavan.Venkataraman@Sun.COM /* we must massage the environment so that the macros will play nice */
14998048SMadhavan.Venkataraman@Sun.COM #define callout_table_mask ((1 << coargs.ctbits) - 1)
15008048SMadhavan.Venkataraman@Sun.COM #define callout_table_bits coargs.ctbits
15018048SMadhavan.Venkataraman@Sun.COM #define nsec_per_tick coargs.nsec_per_tick
15028048SMadhavan.Venkataraman@Sun.COM tableid = CALLOUT_ID_TO_TABLE(xid);
15038048SMadhavan.Venkataraman@Sun.COM idhash = CALLOUT_IDHASH(xid);
15048048SMadhavan.Venkataraman@Sun.COM #undef callouts_table_bits
15058048SMadhavan.Venkataraman@Sun.COM #undef callout_table_mask
15068048SMadhavan.Venkataraman@Sun.COM #undef nsec_per_tick
15078048SMadhavan.Venkataraman@Sun.COM coid = CO_PLAIN_ID(xid);
15088048SMadhavan.Venkataraman@Sun.COM
15098048SMadhavan.Venkataraman@Sun.COM if (flags & DCMD_ADDRSPEC) {
15108048SMadhavan.Venkataraman@Sun.COM mdb_printf("calloutid does not accept explicit address.\n");
15118048SMadhavan.Venkataraman@Sun.COM return (DCMD_USAGE);
15128048SMadhavan.Venkataraman@Sun.COM }
15138048SMadhavan.Venkataraman@Sun.COM
15148048SMadhavan.Venkataraman@Sun.COM if (coargs.flags & COF_DECODE) {
15158048SMadhavan.Venkataraman@Sun.COM if (DCMD_HDRSPEC(flags)) {
15169039SMadhavan.Venkataraman@Sun.COM mdb_printf("%<u>%3s %1s %2s %-?s %-6s %</u>\n",
15179039SMadhavan.Venkataraman@Sun.COM "SEQ", "T", "XL", "XID", "IDHASH");
15180Sstevel@tonic-gate }
15199039SMadhavan.Venkataraman@Sun.COM mdb_printf("%-3d %1s %1s%1s %-?llx %-6d\n",
15208048SMadhavan.Venkataraman@Sun.COM TABLE_TO_SEQID(tableid),
15218048SMadhavan.Venkataraman@Sun.COM co_typenames[tableid & CALLOUT_TYPE_MASK],
15228048SMadhavan.Venkataraman@Sun.COM (xid & CALLOUT_EXECUTING) ? "X" : " ",
15238048SMadhavan.Venkataraman@Sun.COM (xid & CALLOUT_LONGTERM) ? "L" : " ",
15248048SMadhavan.Venkataraman@Sun.COM (long long)coid, idhash);
15258048SMadhavan.Venkataraman@Sun.COM return (DCMD_OK);
15268048SMadhavan.Venkataraman@Sun.COM }
15278048SMadhavan.Venkataraman@Sun.COM
15288048SMadhavan.Venkataraman@Sun.COM /* get our table. Note this relies on the types being correct */
15298048SMadhavan.Venkataraman@Sun.COM ctptr = coargs.co_table + tableid;
15308048SMadhavan.Venkataraman@Sun.COM if (mdb_vread(&ct, sizeof (callout_table_t), (uintptr_t)ctptr) == -1) {
15318048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read callout_table at %p", ctptr);
15328048SMadhavan.Venkataraman@Sun.COM return (DCMD_ERR);
15338048SMadhavan.Venkataraman@Sun.COM }
15348048SMadhavan.Venkataraman@Sun.COM size = sizeof (callout_hash_t) * CALLOUT_BUCKETS;
15358048SMadhavan.Venkataraman@Sun.COM if (ct.ct_idhash != NULL) {
15368048SMadhavan.Venkataraman@Sun.COM if (mdb_vread(&(cot_idhash), size,
15378048SMadhavan.Venkataraman@Sun.COM (uintptr_t)ct.ct_idhash) == -1) {
15388048SMadhavan.Venkataraman@Sun.COM mdb_warn("failed to read id_hash at %p",
15398048SMadhavan.Venkataraman@Sun.COM ct.ct_idhash);
15408048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
15418048SMadhavan.Venkataraman@Sun.COM }
15428048SMadhavan.Venkataraman@Sun.COM }
15438048SMadhavan.Venkataraman@Sun.COM
15448048SMadhavan.Venkataraman@Sun.COM /* callout at beginning of hash chain */
15458048SMadhavan.Venkataraman@Sun.COM if (ct.ct_idhash == NULL) {
15468048SMadhavan.Venkataraman@Sun.COM mdb_printf("id hash chain for this xid is empty\n");
15478048SMadhavan.Venkataraman@Sun.COM return (DCMD_ERR);
15488048SMadhavan.Venkataraman@Sun.COM }
15498048SMadhavan.Venkataraman@Sun.COM coptr = (callout_t *)cot_idhash[idhash].ch_head;
15508048SMadhavan.Venkataraman@Sun.COM if (coptr == NULL) {
15518048SMadhavan.Venkataraman@Sun.COM mdb_printf("id hash chain for this xid is empty\n");
15528048SMadhavan.Venkataraman@Sun.COM return (DCMD_ERR);
15538048SMadhavan.Venkataraman@Sun.COM }
15548048SMadhavan.Venkataraman@Sun.COM
15558048SMadhavan.Venkataraman@Sun.COM coargs.ndx = tableid;
15568048SMadhavan.Venkataraman@Sun.COM coargs.bucket = idhash;
15578048SMadhavan.Venkataraman@Sun.COM
15588048SMadhavan.Venkataraman@Sun.COM /* use the walker, luke */
15598048SMadhavan.Venkataraman@Sun.COM if (mdb_pwalk("callouts_byid", callouts_cb, &coargs,
15608048SMadhavan.Venkataraman@Sun.COM (uintptr_t)coptr) == -1) {
15618048SMadhavan.Venkataraman@Sun.COM mdb_warn("cannot walk callouts at %p", coptr);
15628048SMadhavan.Venkataraman@Sun.COM return (WALK_ERR);
15630Sstevel@tonic-gate }
15640Sstevel@tonic-gate
15650Sstevel@tonic-gate return (DCMD_OK);
15660Sstevel@tonic-gate }
15670Sstevel@tonic-gate
15688048SMadhavan.Venkataraman@Sun.COM void
callout_help(void)15698048SMadhavan.Venkataraman@Sun.COM callout_help(void)
15708048SMadhavan.Venkataraman@Sun.COM {
15718048SMadhavan.Venkataraman@Sun.COM mdb_printf("callout: display callouts.\n"
15728048SMadhavan.Venkataraman@Sun.COM "Given a callout table address, display callouts from table.\n"
15738048SMadhavan.Venkataraman@Sun.COM "Without an address, display callouts from all tables.\n"
15748048SMadhavan.Venkataraman@Sun.COM "options:\n"
15758048SMadhavan.Venkataraman@Sun.COM " -r|n : limit display to (r)ealtime or (n)ormal type callouts\n"
15768048SMadhavan.Venkataraman@Sun.COM " -s|l : limit display to (s)hort-term ids or (l)ong-term ids\n"
15778048SMadhavan.Venkataraman@Sun.COM " -x : limit display to callouts which are executing\n"
15788048SMadhavan.Venkataraman@Sun.COM " -h : limit display to callouts based on hrestime\n"
15799039SMadhavan.Venkataraman@Sun.COM " -B : limit display to callouts based on absolute time\n"
15808048SMadhavan.Venkataraman@Sun.COM " -t|a|b nsec: limit display to callouts that expire a(t) time,"
15818048SMadhavan.Venkataraman@Sun.COM " (a)fter time,\n or (b)efore time. Use -a and -b together "
15828048SMadhavan.Venkataraman@Sun.COM " to specify a range.\n For \"now\", use -d[t|a|b] 0.\n"
15838048SMadhavan.Venkataraman@Sun.COM " -d : interpret time option to -t|a|b as delta from current time\n"
15848048SMadhavan.Venkataraman@Sun.COM " -k : use ticks instead of nanoseconds as arguments to"
15858048SMadhavan.Venkataraman@Sun.COM " -t|a|b. Note that\n ticks are less accurate and may not"
15868048SMadhavan.Venkataraman@Sun.COM " match other tick times (ie: lbolt).\n"
15878048SMadhavan.Venkataraman@Sun.COM " -D : display exiration time as delta from current time\n"
15888048SMadhavan.Venkataraman@Sun.COM " -S seqid : limit display to callouts for this cpu sequence id\n"
15898048SMadhavan.Venkataraman@Sun.COM " -C addr : limit display to callouts for this cpu pointer\n"
15908048SMadhavan.Venkataraman@Sun.COM " -f name|addr : limit display to callouts with this function\n"
15918048SMadhavan.Venkataraman@Sun.COM " -p name|addr : limit display to callouts functions with this"
15928048SMadhavan.Venkataraman@Sun.COM " parameter\n"
15938048SMadhavan.Venkataraman@Sun.COM " -T : display the callout table itself, instead of callouts\n"
15948048SMadhavan.Venkataraman@Sun.COM " -L : display callout lists instead of callouts\n"
15958048SMadhavan.Venkataraman@Sun.COM " -E : with -T or L, display empty data structures.\n"
15968048SMadhavan.Venkataraman@Sun.COM " -i : traverse callouts by id hash instead of list hash\n"
15978048SMadhavan.Venkataraman@Sun.COM " -F : walk free callout list (free list with -i) instead\n"
15988048SMadhavan.Venkataraman@Sun.COM " -v : display more info for each item\n"
15998048SMadhavan.Venkataraman@Sun.COM " -V : show details of each level of info as it is traversed\n"
160011745SMadhavan.Venkataraman@Sun.COM " -H : limit display to callouts in the callout heap\n"
160111745SMadhavan.Venkataraman@Sun.COM " -Q : limit display to callouts in the callout queue\n"
16028048SMadhavan.Venkataraman@Sun.COM " -A : show only addresses. Useful for pipelines.\n");
16038048SMadhavan.Venkataraman@Sun.COM }
16048048SMadhavan.Venkataraman@Sun.COM
16058048SMadhavan.Venkataraman@Sun.COM void
calloutid_help(void)16068048SMadhavan.Venkataraman@Sun.COM calloutid_help(void)
16078048SMadhavan.Venkataraman@Sun.COM {
16088048SMadhavan.Venkataraman@Sun.COM mdb_printf("calloutid: display callout by id.\n"
16098048SMadhavan.Venkataraman@Sun.COM "Given an extended callout id, display the callout infomation.\n"
16108048SMadhavan.Venkataraman@Sun.COM "options:\n"
16118048SMadhavan.Venkataraman@Sun.COM " -d : do not dereference callout, just decode the id.\n"
16128048SMadhavan.Venkataraman@Sun.COM " -v : verbose display more info about the callout\n");
16138048SMadhavan.Venkataraman@Sun.COM }
16148048SMadhavan.Venkataraman@Sun.COM
16150Sstevel@tonic-gate /*ARGSUSED*/
16160Sstevel@tonic-gate int
class(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)16170Sstevel@tonic-gate class(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
16180Sstevel@tonic-gate {
16190Sstevel@tonic-gate long num_classes, i;
16200Sstevel@tonic-gate sclass_t *class_tbl;
16210Sstevel@tonic-gate GElf_Sym g_sclass;
16220Sstevel@tonic-gate char class_name[PC_CLNMSZ];
16230Sstevel@tonic-gate size_t tbl_size;
16240Sstevel@tonic-gate
16250Sstevel@tonic-gate if (mdb_lookup_by_name("sclass", &g_sclass) == -1) {
16260Sstevel@tonic-gate mdb_warn("failed to find symbol sclass\n");
16270Sstevel@tonic-gate return (DCMD_ERR);
16280Sstevel@tonic-gate }
16290Sstevel@tonic-gate
16300Sstevel@tonic-gate tbl_size = (size_t)g_sclass.st_size;
16310Sstevel@tonic-gate num_classes = tbl_size / (sizeof (sclass_t));
16320Sstevel@tonic-gate class_tbl = mdb_alloc(tbl_size, UM_SLEEP | UM_GC);
16330Sstevel@tonic-gate
16340Sstevel@tonic-gate if (mdb_readsym(class_tbl, tbl_size, "sclass") == -1) {
16350Sstevel@tonic-gate mdb_warn("failed to read sclass");
16360Sstevel@tonic-gate return (DCMD_ERR);
16370Sstevel@tonic-gate }
16380Sstevel@tonic-gate
16390Sstevel@tonic-gate mdb_printf("%<u>%4s %-10s %-24s %-24s%</u>\n", "SLOT", "NAME",
16400Sstevel@tonic-gate "INIT FCN", "CLASS FCN");
16410Sstevel@tonic-gate
16420Sstevel@tonic-gate for (i = 0; i < num_classes; i++) {
16430Sstevel@tonic-gate if (mdb_vread(class_name, sizeof (class_name),
16440Sstevel@tonic-gate (uintptr_t)class_tbl[i].cl_name) == -1)
16450Sstevel@tonic-gate (void) strcpy(class_name, "???");
16460Sstevel@tonic-gate
16470Sstevel@tonic-gate mdb_printf("%4ld %-10s %-24a %-24a\n", i, class_name,
16480Sstevel@tonic-gate class_tbl[i].cl_init, class_tbl[i].cl_funcs);
16490Sstevel@tonic-gate }
16500Sstevel@tonic-gate
16510Sstevel@tonic-gate return (DCMD_OK);
16520Sstevel@tonic-gate }
16530Sstevel@tonic-gate
16540Sstevel@tonic-gate #define FSNAMELEN 32 /* Max len of FS name we read from vnodeops */
16550Sstevel@tonic-gate
16560Sstevel@tonic-gate int
vnode2path(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)16570Sstevel@tonic-gate vnode2path(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
16580Sstevel@tonic-gate {
16590Sstevel@tonic-gate uintptr_t rootdir;
16600Sstevel@tonic-gate vnode_t vn;
16610Sstevel@tonic-gate char buf[MAXPATHLEN];
16620Sstevel@tonic-gate
16630Sstevel@tonic-gate uint_t opt_F = FALSE;
16640Sstevel@tonic-gate
16650Sstevel@tonic-gate if (mdb_getopts(argc, argv,
16660Sstevel@tonic-gate 'F', MDB_OPT_SETBITS, TRUE, &opt_F, NULL) != argc)
16670Sstevel@tonic-gate return (DCMD_USAGE);
16680Sstevel@tonic-gate
16690Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
16700Sstevel@tonic-gate mdb_warn("expected explicit vnode_t address before ::\n");
16710Sstevel@tonic-gate return (DCMD_USAGE);
16720Sstevel@tonic-gate }
16730Sstevel@tonic-gate
16740Sstevel@tonic-gate if (mdb_readvar(&rootdir, "rootdir") == -1) {
16750Sstevel@tonic-gate mdb_warn("failed to read rootdir");
16760Sstevel@tonic-gate return (DCMD_ERR);
16770Sstevel@tonic-gate }
16780Sstevel@tonic-gate
16790Sstevel@tonic-gate if (mdb_vnode2path(addr, buf, sizeof (buf)) == -1)
16800Sstevel@tonic-gate return (DCMD_ERR);
16810Sstevel@tonic-gate
16820Sstevel@tonic-gate if (*buf == '\0') {
16830Sstevel@tonic-gate mdb_printf("??\n");
16840Sstevel@tonic-gate return (DCMD_OK);
16850Sstevel@tonic-gate }
16860Sstevel@tonic-gate
16870Sstevel@tonic-gate mdb_printf("%s", buf);
16880Sstevel@tonic-gate if (opt_F && buf[strlen(buf)-1] != '/' &&
16890Sstevel@tonic-gate mdb_vread(&vn, sizeof (vn), addr) == sizeof (vn))
16900Sstevel@tonic-gate mdb_printf("%c", mdb_vtype2chr(vn.v_type, 0));
16910Sstevel@tonic-gate mdb_printf("\n");
16920Sstevel@tonic-gate
16930Sstevel@tonic-gate return (DCMD_OK);
16940Sstevel@tonic-gate }
16950Sstevel@tonic-gate
16960Sstevel@tonic-gate int
ld_walk_init(mdb_walk_state_t * wsp)16970Sstevel@tonic-gate ld_walk_init(mdb_walk_state_t *wsp)
16980Sstevel@tonic-gate {
16990Sstevel@tonic-gate wsp->walk_data = (void *)wsp->walk_addr;
17000Sstevel@tonic-gate return (WALK_NEXT);
17010Sstevel@tonic-gate }
17020Sstevel@tonic-gate
17030Sstevel@tonic-gate int
ld_walk_step(mdb_walk_state_t * wsp)17040Sstevel@tonic-gate ld_walk_step(mdb_walk_state_t *wsp)
17050Sstevel@tonic-gate {
17060Sstevel@tonic-gate int status;
17070Sstevel@tonic-gate lock_descriptor_t ld;
17080Sstevel@tonic-gate
17090Sstevel@tonic-gate if (mdb_vread(&ld, sizeof (lock_descriptor_t), wsp->walk_addr) == -1) {
17100Sstevel@tonic-gate mdb_warn("couldn't read lock_descriptor_t at %p\n",
17110Sstevel@tonic-gate wsp->walk_addr);
17120Sstevel@tonic-gate return (WALK_ERR);
17130Sstevel@tonic-gate }
17140Sstevel@tonic-gate
17150Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, &ld, wsp->walk_cbdata);
17160Sstevel@tonic-gate if (status == WALK_ERR)
17170Sstevel@tonic-gate return (WALK_ERR);
17180Sstevel@tonic-gate
17190Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)ld.l_next;
17200Sstevel@tonic-gate if (wsp->walk_addr == (uintptr_t)wsp->walk_data)
17210Sstevel@tonic-gate return (WALK_DONE);
17220Sstevel@tonic-gate
17230Sstevel@tonic-gate return (status);
17240Sstevel@tonic-gate }
17250Sstevel@tonic-gate
17260Sstevel@tonic-gate int
lg_walk_init(mdb_walk_state_t * wsp)17270Sstevel@tonic-gate lg_walk_init(mdb_walk_state_t *wsp)
17280Sstevel@tonic-gate {
17290Sstevel@tonic-gate GElf_Sym sym;
17300Sstevel@tonic-gate
17310Sstevel@tonic-gate if (mdb_lookup_by_name("lock_graph", &sym) == -1) {
17320Sstevel@tonic-gate mdb_warn("failed to find symbol 'lock_graph'\n");
17330Sstevel@tonic-gate return (WALK_ERR);
17340Sstevel@tonic-gate }
17350Sstevel@tonic-gate
17360Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)sym.st_value;
1737436Sdmick wsp->walk_data = (void *)(uintptr_t)(sym.st_value + sym.st_size);
17380Sstevel@tonic-gate
17390Sstevel@tonic-gate return (WALK_NEXT);
17400Sstevel@tonic-gate }
17410Sstevel@tonic-gate
17420Sstevel@tonic-gate typedef struct lg_walk_data {
17430Sstevel@tonic-gate uintptr_t startaddr;
17440Sstevel@tonic-gate mdb_walk_cb_t callback;
17450Sstevel@tonic-gate void *data;
17460Sstevel@tonic-gate } lg_walk_data_t;
17470Sstevel@tonic-gate
17480Sstevel@tonic-gate /*
17490Sstevel@tonic-gate * We can't use ::walk lock_descriptor directly, because the head of each graph
17500Sstevel@tonic-gate * is really a dummy lock. Rather than trying to dynamically determine if this
17510Sstevel@tonic-gate * is a dummy node or not, we just filter out the initial element of the
17520Sstevel@tonic-gate * list.
17530Sstevel@tonic-gate */
17540Sstevel@tonic-gate static int
lg_walk_cb(uintptr_t addr,const void * data,void * priv)17550Sstevel@tonic-gate lg_walk_cb(uintptr_t addr, const void *data, void *priv)
17560Sstevel@tonic-gate {
17570Sstevel@tonic-gate lg_walk_data_t *lw = priv;
17580Sstevel@tonic-gate
17590Sstevel@tonic-gate if (addr != lw->startaddr)
17600Sstevel@tonic-gate return (lw->callback(addr, data, lw->data));
17610Sstevel@tonic-gate
17620Sstevel@tonic-gate return (WALK_NEXT);
17630Sstevel@tonic-gate }
17640Sstevel@tonic-gate
17650Sstevel@tonic-gate int
lg_walk_step(mdb_walk_state_t * wsp)17660Sstevel@tonic-gate lg_walk_step(mdb_walk_state_t *wsp)
17670Sstevel@tonic-gate {
17680Sstevel@tonic-gate graph_t *graph;
17690Sstevel@tonic-gate lg_walk_data_t lw;
17700Sstevel@tonic-gate
17710Sstevel@tonic-gate if (wsp->walk_addr >= (uintptr_t)wsp->walk_data)
17720Sstevel@tonic-gate return (WALK_DONE);
17730Sstevel@tonic-gate
17740Sstevel@tonic-gate if (mdb_vread(&graph, sizeof (graph), wsp->walk_addr) == -1) {
17750Sstevel@tonic-gate mdb_warn("failed to read graph_t at %p", wsp->walk_addr);
17760Sstevel@tonic-gate return (WALK_ERR);
17770Sstevel@tonic-gate }
17780Sstevel@tonic-gate
17790Sstevel@tonic-gate wsp->walk_addr += sizeof (graph);
17800Sstevel@tonic-gate
17810Sstevel@tonic-gate if (graph == NULL)
17820Sstevel@tonic-gate return (WALK_NEXT);
17830Sstevel@tonic-gate
17840Sstevel@tonic-gate lw.callback = wsp->walk_callback;
17850Sstevel@tonic-gate lw.data = wsp->walk_cbdata;
17860Sstevel@tonic-gate
17870Sstevel@tonic-gate lw.startaddr = (uintptr_t)&(graph->active_locks);
17880Sstevel@tonic-gate if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
17890Sstevel@tonic-gate mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
17900Sstevel@tonic-gate return (WALK_ERR);
17910Sstevel@tonic-gate }
17920Sstevel@tonic-gate
17930Sstevel@tonic-gate lw.startaddr = (uintptr_t)&(graph->sleeping_locks);
17940Sstevel@tonic-gate if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
17950Sstevel@tonic-gate mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
17960Sstevel@tonic-gate return (WALK_ERR);
17970Sstevel@tonic-gate }
17980Sstevel@tonic-gate
17990Sstevel@tonic-gate return (WALK_NEXT);
18000Sstevel@tonic-gate }
18010Sstevel@tonic-gate
18020Sstevel@tonic-gate /*
18030Sstevel@tonic-gate * The space available for the path corresponding to the locked vnode depends
18040Sstevel@tonic-gate * on whether we are printing 32- or 64-bit addresses.
18050Sstevel@tonic-gate */
18060Sstevel@tonic-gate #ifdef _LP64
18070Sstevel@tonic-gate #define LM_VNPATHLEN 20
18080Sstevel@tonic-gate #else
18090Sstevel@tonic-gate #define LM_VNPATHLEN 30
18100Sstevel@tonic-gate #endif
18110Sstevel@tonic-gate
18120Sstevel@tonic-gate /*ARGSUSED*/
18130Sstevel@tonic-gate static int
lminfo_cb(uintptr_t addr,const void * data,void * priv)18140Sstevel@tonic-gate lminfo_cb(uintptr_t addr, const void *data, void *priv)
18150Sstevel@tonic-gate {
18160Sstevel@tonic-gate const lock_descriptor_t *ld = data;
18170Sstevel@tonic-gate char buf[LM_VNPATHLEN];
18180Sstevel@tonic-gate proc_t p;
18190Sstevel@tonic-gate
18200Sstevel@tonic-gate mdb_printf("%-?p %2s %04x %6d %-16s %-?p ",
18210Sstevel@tonic-gate addr, ld->l_type == F_RDLCK ? "RD" :
18220Sstevel@tonic-gate ld->l_type == F_WRLCK ? "WR" : "??",
18230Sstevel@tonic-gate ld->l_state, ld->l_flock.l_pid,
18240Sstevel@tonic-gate ld->l_flock.l_pid == 0 ? "<kernel>" :
18250Sstevel@tonic-gate mdb_pid2proc(ld->l_flock.l_pid, &p) == NULL ?
18260Sstevel@tonic-gate "<defunct>" : p.p_user.u_comm,
18270Sstevel@tonic-gate ld->l_vnode);
18280Sstevel@tonic-gate
18290Sstevel@tonic-gate mdb_vnode2path((uintptr_t)ld->l_vnode, buf,
18300Sstevel@tonic-gate sizeof (buf));
18310Sstevel@tonic-gate mdb_printf("%s\n", buf);
18320Sstevel@tonic-gate
18330Sstevel@tonic-gate return (WALK_NEXT);
18340Sstevel@tonic-gate }
18350Sstevel@tonic-gate
18360Sstevel@tonic-gate /*ARGSUSED*/
18370Sstevel@tonic-gate int
lminfo(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)18380Sstevel@tonic-gate lminfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
18390Sstevel@tonic-gate {
18400Sstevel@tonic-gate if (DCMD_HDRSPEC(flags))
18410Sstevel@tonic-gate mdb_printf("%<u>%-?s %2s %4s %6s %-16s %-?s %s%</u>\n",
18420Sstevel@tonic-gate "ADDR", "TP", "FLAG", "PID", "COMM", "VNODE", "PATH");
18430Sstevel@tonic-gate
18440Sstevel@tonic-gate return (mdb_pwalk("lock_graph", lminfo_cb, NULL, NULL));
18450Sstevel@tonic-gate }
18460Sstevel@tonic-gate
18470Sstevel@tonic-gate /*ARGSUSED*/
18480Sstevel@tonic-gate int
whereopen_fwalk(uintptr_t addr,struct file * f,uintptr_t * target)18490Sstevel@tonic-gate whereopen_fwalk(uintptr_t addr, struct file *f, uintptr_t *target)
18500Sstevel@tonic-gate {
18510Sstevel@tonic-gate if ((uintptr_t)f->f_vnode == *target) {
18520Sstevel@tonic-gate mdb_printf("file %p\n", addr);
18530Sstevel@tonic-gate *target = NULL;
18540Sstevel@tonic-gate }
18550Sstevel@tonic-gate
18560Sstevel@tonic-gate return (WALK_NEXT);
18570Sstevel@tonic-gate }
18580Sstevel@tonic-gate
18590Sstevel@tonic-gate /*ARGSUSED*/
18600Sstevel@tonic-gate int
whereopen_pwalk(uintptr_t addr,void * ignored,uintptr_t * target)18610Sstevel@tonic-gate whereopen_pwalk(uintptr_t addr, void *ignored, uintptr_t *target)
18620Sstevel@tonic-gate {
18630Sstevel@tonic-gate uintptr_t t = *target;
18640Sstevel@tonic-gate
18650Sstevel@tonic-gate if (mdb_pwalk("file", (mdb_walk_cb_t)whereopen_fwalk, &t, addr) == -1) {
18660Sstevel@tonic-gate mdb_warn("couldn't file walk proc %p", addr);
18670Sstevel@tonic-gate return (WALK_ERR);
18680Sstevel@tonic-gate }
18690Sstevel@tonic-gate
18700Sstevel@tonic-gate if (t == NULL)
18710Sstevel@tonic-gate mdb_printf("%p\n", addr);
18720Sstevel@tonic-gate
18730Sstevel@tonic-gate return (WALK_NEXT);
18740Sstevel@tonic-gate }
18750Sstevel@tonic-gate
18760Sstevel@tonic-gate /*ARGSUSED*/
18770Sstevel@tonic-gate int
whereopen(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)18780Sstevel@tonic-gate whereopen(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
18790Sstevel@tonic-gate {
18800Sstevel@tonic-gate uintptr_t target = addr;
18810Sstevel@tonic-gate
18820Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || addr == NULL)
18830Sstevel@tonic-gate return (DCMD_USAGE);
18840Sstevel@tonic-gate
18850Sstevel@tonic-gate if (mdb_walk("proc", (mdb_walk_cb_t)whereopen_pwalk, &target) == -1) {
18860Sstevel@tonic-gate mdb_warn("can't proc walk");
18870Sstevel@tonic-gate return (DCMD_ERR);
18880Sstevel@tonic-gate }
18890Sstevel@tonic-gate
18900Sstevel@tonic-gate return (DCMD_OK);
18910Sstevel@tonic-gate }
18920Sstevel@tonic-gate
18930Sstevel@tonic-gate typedef struct datafmt {
18940Sstevel@tonic-gate char *hdr1;
18950Sstevel@tonic-gate char *hdr2;
18960Sstevel@tonic-gate char *dashes;
18970Sstevel@tonic-gate char *fmt;
18980Sstevel@tonic-gate } datafmt_t;
18990Sstevel@tonic-gate
19000Sstevel@tonic-gate static datafmt_t kmemfmt[] = {
19010Sstevel@tonic-gate { "cache ", "name ",
19020Sstevel@tonic-gate "-------------------------", "%-25s " },
19030Sstevel@tonic-gate { " buf", " size", "------", "%6u " },
19040Sstevel@tonic-gate { " buf", "in use", "------", "%6u " },
19050Sstevel@tonic-gate { " buf", " total", "------", "%6u " },
190611470SJonathan.Haslam@Sun.COM { " memory", " in use", "----------", "%10lu%c " },
19070Sstevel@tonic-gate { " alloc", " succeed", "---------", "%9u " },
19080Sstevel@tonic-gate { "alloc", " fail", "-----", "%5u " },
19090Sstevel@tonic-gate { NULL, NULL, NULL, NULL }
19100Sstevel@tonic-gate };
19110Sstevel@tonic-gate
19120Sstevel@tonic-gate static datafmt_t vmemfmt[] = {
19130Sstevel@tonic-gate { "vmem ", "name ",
19140Sstevel@tonic-gate "-------------------------", "%-*s " },
19154808Sek110237 { " memory", " in use", "----------", "%9llu%c " },
19164808Sek110237 { " memory", " total", "-----------", "%10llu%c " },
19174808Sek110237 { " memory", " import", "----------", "%9llu%c " },
19180Sstevel@tonic-gate { " alloc", " succeed", "---------", "%9llu " },
19190Sstevel@tonic-gate { "alloc", " fail", "-----", "%5llu " },
19200Sstevel@tonic-gate { NULL, NULL, NULL, NULL }
19210Sstevel@tonic-gate };
19220Sstevel@tonic-gate
19230Sstevel@tonic-gate /*ARGSUSED*/
19240Sstevel@tonic-gate static int
kmastat_cpu_avail(uintptr_t addr,const kmem_cpu_cache_t * ccp,int * avail)19250Sstevel@tonic-gate kmastat_cpu_avail(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *avail)
19260Sstevel@tonic-gate {
192711178SDave.Plauger@Sun.COM short rounds, prounds;
192811178SDave.Plauger@Sun.COM
192911178SDave.Plauger@Sun.COM if (KMEM_DUMPCC(ccp)) {
193011178SDave.Plauger@Sun.COM rounds = ccp->cc_dump_rounds;
193111178SDave.Plauger@Sun.COM prounds = ccp->cc_dump_prounds;
193211178SDave.Plauger@Sun.COM } else {
193311178SDave.Plauger@Sun.COM rounds = ccp->cc_rounds;
193411178SDave.Plauger@Sun.COM prounds = ccp->cc_prounds;
193511178SDave.Plauger@Sun.COM }
193611178SDave.Plauger@Sun.COM if (rounds > 0)
193711178SDave.Plauger@Sun.COM *avail += rounds;
193811178SDave.Plauger@Sun.COM if (prounds > 0)
193911178SDave.Plauger@Sun.COM *avail += prounds;
19400Sstevel@tonic-gate
19410Sstevel@tonic-gate return (WALK_NEXT);
19420Sstevel@tonic-gate }
19430Sstevel@tonic-gate
19440Sstevel@tonic-gate /*ARGSUSED*/
19450Sstevel@tonic-gate static int
kmastat_cpu_alloc(uintptr_t addr,const kmem_cpu_cache_t * ccp,int * alloc)19460Sstevel@tonic-gate kmastat_cpu_alloc(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *alloc)
19470Sstevel@tonic-gate {
19480Sstevel@tonic-gate *alloc += ccp->cc_alloc;
19490Sstevel@tonic-gate
19500Sstevel@tonic-gate return (WALK_NEXT);
19510Sstevel@tonic-gate }
19520Sstevel@tonic-gate
19530Sstevel@tonic-gate /*ARGSUSED*/
19540Sstevel@tonic-gate static int
kmastat_slab_avail(uintptr_t addr,const kmem_slab_t * sp,int * avail)19550Sstevel@tonic-gate kmastat_slab_avail(uintptr_t addr, const kmem_slab_t *sp, int *avail)
19560Sstevel@tonic-gate {
19570Sstevel@tonic-gate *avail += sp->slab_chunks - sp->slab_refcnt;
19580Sstevel@tonic-gate
19590Sstevel@tonic-gate return (WALK_NEXT);
19600Sstevel@tonic-gate }
19610Sstevel@tonic-gate
19620Sstevel@tonic-gate typedef struct kmastat_vmem {
19630Sstevel@tonic-gate uintptr_t kv_addr;
19640Sstevel@tonic-gate struct kmastat_vmem *kv_next;
196511470SJonathan.Haslam@Sun.COM size_t kv_meminuse;
19660Sstevel@tonic-gate int kv_alloc;
19670Sstevel@tonic-gate int kv_fail;
19680Sstevel@tonic-gate } kmastat_vmem_t;
19690Sstevel@tonic-gate
19703095Sek110237 typedef struct kmastat_args {
19713095Sek110237 kmastat_vmem_t **ka_kvpp;
19723095Sek110237 uint_t ka_shift;
19733095Sek110237 } kmastat_args_t;
19743095Sek110237
19750Sstevel@tonic-gate static int
kmastat_cache(uintptr_t addr,const kmem_cache_t * cp,kmastat_args_t * kap)19763095Sek110237 kmastat_cache(uintptr_t addr, const kmem_cache_t *cp, kmastat_args_t *kap)
19770Sstevel@tonic-gate {
197811185SSean.McEnroe@Sun.COM kmastat_vmem_t **kvpp = kap->ka_kvpp;
19790Sstevel@tonic-gate kmastat_vmem_t *kv;
19800Sstevel@tonic-gate datafmt_t *dfp = kmemfmt;
19810Sstevel@tonic-gate int magsize;
19820Sstevel@tonic-gate
19830Sstevel@tonic-gate int avail, alloc, total;
19840Sstevel@tonic-gate size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) *
19850Sstevel@tonic-gate cp->cache_slabsize;
19860Sstevel@tonic-gate
19870Sstevel@tonic-gate mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)kmastat_cpu_avail;
19880Sstevel@tonic-gate mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)kmastat_cpu_alloc;
19890Sstevel@tonic-gate mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)kmastat_slab_avail;
19900Sstevel@tonic-gate
19910Sstevel@tonic-gate magsize = kmem_get_magsize(cp);
19920Sstevel@tonic-gate
19930Sstevel@tonic-gate alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc;
19940Sstevel@tonic-gate avail = cp->cache_full.ml_total * magsize;
19950Sstevel@tonic-gate total = cp->cache_buftotal;
19960Sstevel@tonic-gate
19970Sstevel@tonic-gate (void) mdb_pwalk("kmem_cpu_cache", cpu_alloc, &alloc, addr);
19980Sstevel@tonic-gate (void) mdb_pwalk("kmem_cpu_cache", cpu_avail, &avail, addr);
19990Sstevel@tonic-gate (void) mdb_pwalk("kmem_slab_partial", slab_avail, &avail, addr);
20000Sstevel@tonic-gate
200111185SSean.McEnroe@Sun.COM for (kv = *kvpp; kv != NULL; kv = kv->kv_next) {
20020Sstevel@tonic-gate if (kv->kv_addr == (uintptr_t)cp->cache_arena)
20030Sstevel@tonic-gate goto out;
20040Sstevel@tonic-gate }
20050Sstevel@tonic-gate
20060Sstevel@tonic-gate kv = mdb_zalloc(sizeof (kmastat_vmem_t), UM_SLEEP | UM_GC);
200711185SSean.McEnroe@Sun.COM kv->kv_next = *kvpp;
20080Sstevel@tonic-gate kv->kv_addr = (uintptr_t)cp->cache_arena;
200911185SSean.McEnroe@Sun.COM *kvpp = kv;
20100Sstevel@tonic-gate out:
20110Sstevel@tonic-gate kv->kv_meminuse += meminuse;
20120Sstevel@tonic-gate kv->kv_alloc += alloc;
20130Sstevel@tonic-gate kv->kv_fail += cp->cache_alloc_fail;
20140Sstevel@tonic-gate
20150Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_name);
20160Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_bufsize);
20170Sstevel@tonic-gate mdb_printf((dfp++)->fmt, total - avail);
20180Sstevel@tonic-gate mdb_printf((dfp++)->fmt, total);
20194808Sek110237 mdb_printf((dfp++)->fmt, meminuse >> kap->ka_shift,
20204808Sek110237 kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' :
20214808Sek110237 kap->ka_shift == KILOS ? 'K' : 'B');
20220Sstevel@tonic-gate mdb_printf((dfp++)->fmt, alloc);
20230Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_alloc_fail);
20240Sstevel@tonic-gate mdb_printf("\n");
20250Sstevel@tonic-gate
20260Sstevel@tonic-gate return (WALK_NEXT);
20270Sstevel@tonic-gate }
20280Sstevel@tonic-gate
20290Sstevel@tonic-gate static int
kmastat_vmem_totals(uintptr_t addr,const vmem_t * v,kmastat_args_t * kap)20303095Sek110237 kmastat_vmem_totals(uintptr_t addr, const vmem_t *v, kmastat_args_t *kap)
20310Sstevel@tonic-gate {
20323095Sek110237 kmastat_vmem_t *kv = *kap->ka_kvpp;
20330Sstevel@tonic-gate size_t len;
20340Sstevel@tonic-gate
20350Sstevel@tonic-gate while (kv != NULL && kv->kv_addr != addr)
20360Sstevel@tonic-gate kv = kv->kv_next;
20370Sstevel@tonic-gate
20380Sstevel@tonic-gate if (kv == NULL || kv->kv_alloc == 0)
20390Sstevel@tonic-gate return (WALK_NEXT);
20400Sstevel@tonic-gate
20410Sstevel@tonic-gate len = MIN(17, strlen(v->vm_name));
20420Sstevel@tonic-gate
204311470SJonathan.Haslam@Sun.COM mdb_printf("Total [%s]%*s %6s %6s %6s %10lu%c %9u %5u\n", v->vm_name,
20440Sstevel@tonic-gate 17 - len, "", "", "", "",
20454808Sek110237 kv->kv_meminuse >> kap->ka_shift,
20464808Sek110237 kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' :
20474808Sek110237 kap->ka_shift == KILOS ? 'K' : 'B', kv->kv_alloc, kv->kv_fail);
20480Sstevel@tonic-gate
20490Sstevel@tonic-gate return (WALK_NEXT);
20500Sstevel@tonic-gate }
20510Sstevel@tonic-gate
20520Sstevel@tonic-gate /*ARGSUSED*/
20530Sstevel@tonic-gate static int
kmastat_vmem(uintptr_t addr,const vmem_t * v,const uint_t * shiftp)20543095Sek110237 kmastat_vmem(uintptr_t addr, const vmem_t *v, const uint_t *shiftp)
20550Sstevel@tonic-gate {
20560Sstevel@tonic-gate datafmt_t *dfp = vmemfmt;
20570Sstevel@tonic-gate const vmem_kstat_t *vkp = &v->vm_kstat;
20580Sstevel@tonic-gate uintptr_t paddr;
20590Sstevel@tonic-gate vmem_t parent;
20600Sstevel@tonic-gate int ident = 0;
20610Sstevel@tonic-gate
20620Sstevel@tonic-gate for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) {
20630Sstevel@tonic-gate if (mdb_vread(&parent, sizeof (parent), paddr) == -1) {
20640Sstevel@tonic-gate mdb_warn("couldn't trace %p's ancestry", addr);
20650Sstevel@tonic-gate ident = 0;
20660Sstevel@tonic-gate break;
20670Sstevel@tonic-gate }
20680Sstevel@tonic-gate paddr = (uintptr_t)parent.vm_source;
20690Sstevel@tonic-gate }
20700Sstevel@tonic-gate
20710Sstevel@tonic-gate mdb_printf("%*s", ident, "");
20720Sstevel@tonic-gate mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name);
20734808Sek110237 mdb_printf((dfp++)->fmt, vkp->vk_mem_inuse.value.ui64 >> *shiftp,
20744808Sek110237 *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
20754808Sek110237 *shiftp == KILOS ? 'K' : 'B');
20764808Sek110237 mdb_printf((dfp++)->fmt, vkp->vk_mem_total.value.ui64 >> *shiftp,
20774808Sek110237 *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
20784808Sek110237 *shiftp == KILOS ? 'K' : 'B');
20794808Sek110237 mdb_printf((dfp++)->fmt, vkp->vk_mem_import.value.ui64 >> *shiftp,
20804808Sek110237 *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
20814808Sek110237 *shiftp == KILOS ? 'K' : 'B');
20820Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_alloc.value.ui64);
20830Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_fail.value.ui64);
20840Sstevel@tonic-gate
20850Sstevel@tonic-gate mdb_printf("\n");
20860Sstevel@tonic-gate
20870Sstevel@tonic-gate return (WALK_NEXT);
20880Sstevel@tonic-gate }
20890Sstevel@tonic-gate
20900Sstevel@tonic-gate /*ARGSUSED*/
20910Sstevel@tonic-gate int
kmastat(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)20920Sstevel@tonic-gate kmastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
20930Sstevel@tonic-gate {
20940Sstevel@tonic-gate kmastat_vmem_t *kv = NULL;
20950Sstevel@tonic-gate datafmt_t *dfp;
20963095Sek110237 kmastat_args_t ka;
20973095Sek110237
20983095Sek110237 ka.ka_shift = 0;
20993095Sek110237 if (mdb_getopts(argc, argv,
21004808Sek110237 'k', MDB_OPT_SETBITS, KILOS, &ka.ka_shift,
21014808Sek110237 'm', MDB_OPT_SETBITS, MEGS, &ka.ka_shift,
21024808Sek110237 'g', MDB_OPT_SETBITS, GIGS, &ka.ka_shift, NULL) != argc)
21030Sstevel@tonic-gate return (DCMD_USAGE);
21040Sstevel@tonic-gate
21050Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
21060Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr1);
21070Sstevel@tonic-gate mdb_printf("\n");
21080Sstevel@tonic-gate
21090Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
21100Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr2);
21110Sstevel@tonic-gate mdb_printf("\n");
21120Sstevel@tonic-gate
21130Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
21140Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes);
21150Sstevel@tonic-gate mdb_printf("\n");
21160Sstevel@tonic-gate
21173095Sek110237 ka.ka_kvpp = &kv;
21183095Sek110237 if (mdb_walk("kmem_cache", (mdb_walk_cb_t)kmastat_cache, &ka) == -1) {
21190Sstevel@tonic-gate mdb_warn("can't walk 'kmem_cache'");
21200Sstevel@tonic-gate return (DCMD_ERR);
21210Sstevel@tonic-gate }
21220Sstevel@tonic-gate
21230Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
21240Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes);
21250Sstevel@tonic-gate mdb_printf("\n");
21260Sstevel@tonic-gate
21273095Sek110237 if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem_totals, &ka) == -1) {
21280Sstevel@tonic-gate mdb_warn("can't walk 'vmem'");
21290Sstevel@tonic-gate return (DCMD_ERR);
21300Sstevel@tonic-gate }
21310Sstevel@tonic-gate
21320Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
21330Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes);
21340Sstevel@tonic-gate mdb_printf("\n");
21350Sstevel@tonic-gate
21360Sstevel@tonic-gate mdb_printf("\n");
21370Sstevel@tonic-gate
21380Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
21390Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr1);
21400Sstevel@tonic-gate mdb_printf("\n");
21410Sstevel@tonic-gate
21420Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
21430Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr2);
21440Sstevel@tonic-gate mdb_printf("\n");
21450Sstevel@tonic-gate
21460Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
21470Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes);
21480Sstevel@tonic-gate mdb_printf("\n");
21490Sstevel@tonic-gate
21503095Sek110237 if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem, &ka.ka_shift) == -1) {
21510Sstevel@tonic-gate mdb_warn("can't walk 'vmem'");
21520Sstevel@tonic-gate return (DCMD_ERR);
21530Sstevel@tonic-gate }
21540Sstevel@tonic-gate
21550Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
21560Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes);
21570Sstevel@tonic-gate mdb_printf("\n");
21580Sstevel@tonic-gate return (DCMD_OK);
21590Sstevel@tonic-gate }
21600Sstevel@tonic-gate
21610Sstevel@tonic-gate /*
21620Sstevel@tonic-gate * Our ::kgrep callback scans the entire kernel VA space (kas). kas is made
21630Sstevel@tonic-gate * up of a set of 'struct seg's. We could just scan each seg en masse, but
21640Sstevel@tonic-gate * unfortunately, a few of the segs are both large and sparse, so we could
21650Sstevel@tonic-gate * spend quite a bit of time scanning VAs which have no backing pages.
21660Sstevel@tonic-gate *
21670Sstevel@tonic-gate * So for the few very sparse segs, we skip the segment itself, and scan
21680Sstevel@tonic-gate * the allocated vmem_segs in the vmem arena which manages that part of kas.
21690Sstevel@tonic-gate * Currently, we do this for:
21700Sstevel@tonic-gate *
21710Sstevel@tonic-gate * SEG VMEM ARENA
21720Sstevel@tonic-gate * kvseg heap_arena
21730Sstevel@tonic-gate * kvseg32 heap32_arena
21740Sstevel@tonic-gate * kvseg_core heap_core_arena
21750Sstevel@tonic-gate *
21760Sstevel@tonic-gate * In addition, we skip the segkpm segment in its entirety, since it is very
21770Sstevel@tonic-gate * sparse, and contains no new kernel data.
21780Sstevel@tonic-gate */
21790Sstevel@tonic-gate typedef struct kgrep_walk_data {
21800Sstevel@tonic-gate kgrep_cb_func *kg_cb;
21810Sstevel@tonic-gate void *kg_cbdata;
21820Sstevel@tonic-gate uintptr_t kg_kvseg;
21830Sstevel@tonic-gate uintptr_t kg_kvseg32;
21840Sstevel@tonic-gate uintptr_t kg_kvseg_core;
21850Sstevel@tonic-gate uintptr_t kg_segkpm;
21865Seg155566 uintptr_t kg_heap_lp_base;
21875Seg155566 uintptr_t kg_heap_lp_end;
21880Sstevel@tonic-gate } kgrep_walk_data_t;
21890Sstevel@tonic-gate
21900Sstevel@tonic-gate static int
kgrep_walk_seg(uintptr_t addr,const struct seg * seg,kgrep_walk_data_t * kg)21910Sstevel@tonic-gate kgrep_walk_seg(uintptr_t addr, const struct seg *seg, kgrep_walk_data_t *kg)
21920Sstevel@tonic-gate {
21930Sstevel@tonic-gate uintptr_t base = (uintptr_t)seg->s_base;
21940Sstevel@tonic-gate
21950Sstevel@tonic-gate if (addr == kg->kg_kvseg || addr == kg->kg_kvseg32 ||
21960Sstevel@tonic-gate addr == kg->kg_kvseg_core)
21970Sstevel@tonic-gate return (WALK_NEXT);
21980Sstevel@tonic-gate
21990Sstevel@tonic-gate if ((uintptr_t)seg->s_ops == kg->kg_segkpm)
22000Sstevel@tonic-gate return (WALK_NEXT);
22010Sstevel@tonic-gate
22020Sstevel@tonic-gate return (kg->kg_cb(base, base + seg->s_size, kg->kg_cbdata));
22030Sstevel@tonic-gate }
22040Sstevel@tonic-gate
22050Sstevel@tonic-gate /*ARGSUSED*/
22060Sstevel@tonic-gate static int
kgrep_walk_vseg(uintptr_t addr,const vmem_seg_t * seg,kgrep_walk_data_t * kg)22070Sstevel@tonic-gate kgrep_walk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
22080Sstevel@tonic-gate {
22095Seg155566 /*
22105Seg155566 * skip large page heap address range - it is scanned by walking
22115Seg155566 * allocated vmem_segs in the heap_lp_arena
22125Seg155566 */
22135Seg155566 if (seg->vs_start == kg->kg_heap_lp_base &&
22145Seg155566 seg->vs_end == kg->kg_heap_lp_end)
22155Seg155566 return (WALK_NEXT);
22165Seg155566
22175Seg155566 return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
22185Seg155566 }
22195Seg155566
22205Seg155566 /*ARGSUSED*/
22215Seg155566 static int
kgrep_xwalk_vseg(uintptr_t addr,const vmem_seg_t * seg,kgrep_walk_data_t * kg)22225Seg155566 kgrep_xwalk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
22235Seg155566 {
22240Sstevel@tonic-gate return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
22250Sstevel@tonic-gate }
22260Sstevel@tonic-gate
22270Sstevel@tonic-gate static int
kgrep_walk_vmem(uintptr_t addr,const vmem_t * vmem,kgrep_walk_data_t * kg)22280Sstevel@tonic-gate kgrep_walk_vmem(uintptr_t addr, const vmem_t *vmem, kgrep_walk_data_t *kg)
22290Sstevel@tonic-gate {
22305Seg155566 mdb_walk_cb_t walk_vseg = (mdb_walk_cb_t)kgrep_walk_vseg;
22315Seg155566
22320Sstevel@tonic-gate if (strcmp(vmem->vm_name, "heap") != 0 &&
22330Sstevel@tonic-gate strcmp(vmem->vm_name, "heap32") != 0 &&
22345Seg155566 strcmp(vmem->vm_name, "heap_core") != 0 &&
22355Seg155566 strcmp(vmem->vm_name, "heap_lp") != 0)
22360Sstevel@tonic-gate return (WALK_NEXT);
22370Sstevel@tonic-gate
22385Seg155566 if (strcmp(vmem->vm_name, "heap_lp") == 0)
22395Seg155566 walk_vseg = (mdb_walk_cb_t)kgrep_xwalk_vseg;
22405Seg155566
22415Seg155566 if (mdb_pwalk("vmem_alloc", walk_vseg, kg, addr) == -1) {
22420Sstevel@tonic-gate mdb_warn("couldn't walk vmem_alloc for vmem %p", addr);
22430Sstevel@tonic-gate return (WALK_ERR);
22440Sstevel@tonic-gate }
22450Sstevel@tonic-gate
22460Sstevel@tonic-gate return (WALK_NEXT);
22470Sstevel@tonic-gate }
22480Sstevel@tonic-gate
22490Sstevel@tonic-gate int
kgrep_subr(kgrep_cb_func * cb,void * cbdata)22500Sstevel@tonic-gate kgrep_subr(kgrep_cb_func *cb, void *cbdata)
22510Sstevel@tonic-gate {
22520Sstevel@tonic-gate GElf_Sym kas, kvseg, kvseg32, kvseg_core, segkpm;
22530Sstevel@tonic-gate kgrep_walk_data_t kg;
22540Sstevel@tonic-gate
22550Sstevel@tonic-gate if (mdb_get_state() == MDB_STATE_RUNNING) {
22560Sstevel@tonic-gate mdb_warn("kgrep can only be run on a system "
22570Sstevel@tonic-gate "dump or under kmdb; see dumpadm(1M)\n");
22580Sstevel@tonic-gate return (DCMD_ERR);
22590Sstevel@tonic-gate }
22600Sstevel@tonic-gate
22610Sstevel@tonic-gate if (mdb_lookup_by_name("kas", &kas) == -1) {
22620Sstevel@tonic-gate mdb_warn("failed to locate 'kas' symbol\n");
22630Sstevel@tonic-gate return (DCMD_ERR);
22640Sstevel@tonic-gate }
22650Sstevel@tonic-gate
22660Sstevel@tonic-gate if (mdb_lookup_by_name("kvseg", &kvseg) == -1) {
22670Sstevel@tonic-gate mdb_warn("failed to locate 'kvseg' symbol\n");
22680Sstevel@tonic-gate return (DCMD_ERR);
22690Sstevel@tonic-gate }
22700Sstevel@tonic-gate
22710Sstevel@tonic-gate if (mdb_lookup_by_name("kvseg32", &kvseg32) == -1) {
22720Sstevel@tonic-gate mdb_warn("failed to locate 'kvseg32' symbol\n");
22730Sstevel@tonic-gate return (DCMD_ERR);
22740Sstevel@tonic-gate }
22750Sstevel@tonic-gate
22760Sstevel@tonic-gate if (mdb_lookup_by_name("kvseg_core", &kvseg_core) == -1) {
22770Sstevel@tonic-gate mdb_warn("failed to locate 'kvseg_core' symbol\n");
22780Sstevel@tonic-gate return (DCMD_ERR);
22790Sstevel@tonic-gate }
22800Sstevel@tonic-gate
22810Sstevel@tonic-gate if (mdb_lookup_by_name("segkpm_ops", &segkpm) == -1) {
22820Sstevel@tonic-gate mdb_warn("failed to locate 'segkpm_ops' symbol\n");
22830Sstevel@tonic-gate return (DCMD_ERR);
22840Sstevel@tonic-gate }
22850Sstevel@tonic-gate
22865Seg155566 if (mdb_readvar(&kg.kg_heap_lp_base, "heap_lp_base") == -1) {
22875Seg155566 mdb_warn("failed to read 'heap_lp_base'\n");
22885Seg155566 return (DCMD_ERR);
22895Seg155566 }
22905Seg155566
22915Seg155566 if (mdb_readvar(&kg.kg_heap_lp_end, "heap_lp_end") == -1) {
22925Seg155566 mdb_warn("failed to read 'heap_lp_end'\n");
22935Seg155566 return (DCMD_ERR);
22945Seg155566 }
22955Seg155566
22960Sstevel@tonic-gate kg.kg_cb = cb;
22970Sstevel@tonic-gate kg.kg_cbdata = cbdata;
22980Sstevel@tonic-gate kg.kg_kvseg = (uintptr_t)kvseg.st_value;
22990Sstevel@tonic-gate kg.kg_kvseg32 = (uintptr_t)kvseg32.st_value;
23000Sstevel@tonic-gate kg.kg_kvseg_core = (uintptr_t)kvseg_core.st_value;
23010Sstevel@tonic-gate kg.kg_segkpm = (uintptr_t)segkpm.st_value;
23020Sstevel@tonic-gate
23030Sstevel@tonic-gate if (mdb_pwalk("seg", (mdb_walk_cb_t)kgrep_walk_seg,
23040Sstevel@tonic-gate &kg, kas.st_value) == -1) {
23050Sstevel@tonic-gate mdb_warn("failed to walk kas segments");
23060Sstevel@tonic-gate return (DCMD_ERR);
23070Sstevel@tonic-gate }
23080Sstevel@tonic-gate
23090Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)kgrep_walk_vmem, &kg) == -1) {
23100Sstevel@tonic-gate mdb_warn("failed to walk heap/heap32 vmem arenas");
23110Sstevel@tonic-gate return (DCMD_ERR);
23120Sstevel@tonic-gate }
23130Sstevel@tonic-gate
23140Sstevel@tonic-gate return (DCMD_OK);
23150Sstevel@tonic-gate }
23160Sstevel@tonic-gate
23170Sstevel@tonic-gate size_t
kgrep_subr_pagesize(void)23180Sstevel@tonic-gate kgrep_subr_pagesize(void)
23190Sstevel@tonic-gate {
23200Sstevel@tonic-gate return (PAGESIZE);
23210Sstevel@tonic-gate }
23220Sstevel@tonic-gate
23230Sstevel@tonic-gate typedef struct file_walk_data {
23240Sstevel@tonic-gate struct uf_entry *fw_flist;
23250Sstevel@tonic-gate int fw_flistsz;
23260Sstevel@tonic-gate int fw_ndx;
23270Sstevel@tonic-gate int fw_nofiles;
23280Sstevel@tonic-gate } file_walk_data_t;
23290Sstevel@tonic-gate
23300Sstevel@tonic-gate int
file_walk_init(mdb_walk_state_t * wsp)23310Sstevel@tonic-gate file_walk_init(mdb_walk_state_t *wsp)
23320Sstevel@tonic-gate {
23330Sstevel@tonic-gate file_walk_data_t *fw;
23340Sstevel@tonic-gate proc_t p;
23350Sstevel@tonic-gate
23360Sstevel@tonic-gate if (wsp->walk_addr == NULL) {
23370Sstevel@tonic-gate mdb_warn("file walk doesn't support global walks\n");
23380Sstevel@tonic-gate return (WALK_ERR);
23390Sstevel@tonic-gate }
23400Sstevel@tonic-gate
23410Sstevel@tonic-gate fw = mdb_alloc(sizeof (file_walk_data_t), UM_SLEEP);
23420Sstevel@tonic-gate
23430Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), wsp->walk_addr) == -1) {
23440Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t));
23450Sstevel@tonic-gate mdb_warn("failed to read proc structure at %p", wsp->walk_addr);
23460Sstevel@tonic-gate return (WALK_ERR);
23470Sstevel@tonic-gate }
23480Sstevel@tonic-gate
23490Sstevel@tonic-gate if (p.p_user.u_finfo.fi_nfiles == 0) {
23500Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t));
23510Sstevel@tonic-gate return (WALK_DONE);
23520Sstevel@tonic-gate }
23530Sstevel@tonic-gate
23540Sstevel@tonic-gate fw->fw_nofiles = p.p_user.u_finfo.fi_nfiles;
23550Sstevel@tonic-gate fw->fw_flistsz = sizeof (struct uf_entry) * fw->fw_nofiles;
23560Sstevel@tonic-gate fw->fw_flist = mdb_alloc(fw->fw_flistsz, UM_SLEEP);
23570Sstevel@tonic-gate
23580Sstevel@tonic-gate if (mdb_vread(fw->fw_flist, fw->fw_flistsz,
23590Sstevel@tonic-gate (uintptr_t)p.p_user.u_finfo.fi_list) == -1) {
23600Sstevel@tonic-gate mdb_warn("failed to read file array at %p",
23610Sstevel@tonic-gate p.p_user.u_finfo.fi_list);
23620Sstevel@tonic-gate mdb_free(fw->fw_flist, fw->fw_flistsz);
23630Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t));
23640Sstevel@tonic-gate return (WALK_ERR);
23650Sstevel@tonic-gate }
23660Sstevel@tonic-gate
23670Sstevel@tonic-gate fw->fw_ndx = 0;
23680Sstevel@tonic-gate wsp->walk_data = fw;
23690Sstevel@tonic-gate
23700Sstevel@tonic-gate return (WALK_NEXT);
23710Sstevel@tonic-gate }
23720Sstevel@tonic-gate
23730Sstevel@tonic-gate int
file_walk_step(mdb_walk_state_t * wsp)23740Sstevel@tonic-gate file_walk_step(mdb_walk_state_t *wsp)
23750Sstevel@tonic-gate {
23760Sstevel@tonic-gate file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
23770Sstevel@tonic-gate struct file file;
23780Sstevel@tonic-gate uintptr_t fp;
23790Sstevel@tonic-gate
23800Sstevel@tonic-gate again:
23810Sstevel@tonic-gate if (fw->fw_ndx == fw->fw_nofiles)
23820Sstevel@tonic-gate return (WALK_DONE);
23830Sstevel@tonic-gate
23840Sstevel@tonic-gate if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) == NULL)
23850Sstevel@tonic-gate goto again;
23860Sstevel@tonic-gate
23870Sstevel@tonic-gate (void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
23880Sstevel@tonic-gate return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
23890Sstevel@tonic-gate }
23900Sstevel@tonic-gate
23910Sstevel@tonic-gate int
allfile_walk_step(mdb_walk_state_t * wsp)23920Sstevel@tonic-gate allfile_walk_step(mdb_walk_state_t *wsp)
23930Sstevel@tonic-gate {
23940Sstevel@tonic-gate file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
23950Sstevel@tonic-gate struct file file;
23960Sstevel@tonic-gate uintptr_t fp;
23970Sstevel@tonic-gate
23980Sstevel@tonic-gate if (fw->fw_ndx == fw->fw_nofiles)
23990Sstevel@tonic-gate return (WALK_DONE);
24000Sstevel@tonic-gate
24010Sstevel@tonic-gate if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) != NULL)
24020Sstevel@tonic-gate (void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
24030Sstevel@tonic-gate else
24040Sstevel@tonic-gate bzero(&file, sizeof (file));
24050Sstevel@tonic-gate
24060Sstevel@tonic-gate return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
24070Sstevel@tonic-gate }
24080Sstevel@tonic-gate
24090Sstevel@tonic-gate void
file_walk_fini(mdb_walk_state_t * wsp)24100Sstevel@tonic-gate file_walk_fini(mdb_walk_state_t *wsp)
24110Sstevel@tonic-gate {
24120Sstevel@tonic-gate file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
24130Sstevel@tonic-gate
24140Sstevel@tonic-gate mdb_free(fw->fw_flist, fw->fw_flistsz);
24150Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t));
24160Sstevel@tonic-gate }
24170Sstevel@tonic-gate
24180Sstevel@tonic-gate int
port_walk_init(mdb_walk_state_t * wsp)24190Sstevel@tonic-gate port_walk_init(mdb_walk_state_t *wsp)
24200Sstevel@tonic-gate {
24210Sstevel@tonic-gate if (wsp->walk_addr == NULL) {
24220Sstevel@tonic-gate mdb_warn("port walk doesn't support global walks\n");
24230Sstevel@tonic-gate return (WALK_ERR);
24240Sstevel@tonic-gate }
24250Sstevel@tonic-gate
24260Sstevel@tonic-gate if (mdb_layered_walk("file", wsp) == -1) {
24270Sstevel@tonic-gate mdb_warn("couldn't walk 'file'");
24280Sstevel@tonic-gate return (WALK_ERR);
24290Sstevel@tonic-gate }
24300Sstevel@tonic-gate return (WALK_NEXT);
24310Sstevel@tonic-gate }
24320Sstevel@tonic-gate
24330Sstevel@tonic-gate int
port_walk_step(mdb_walk_state_t * wsp)24340Sstevel@tonic-gate port_walk_step(mdb_walk_state_t *wsp)
24350Sstevel@tonic-gate {
24360Sstevel@tonic-gate struct vnode vn;
24370Sstevel@tonic-gate uintptr_t vp;
24380Sstevel@tonic-gate uintptr_t pp;
24390Sstevel@tonic-gate struct port port;
24400Sstevel@tonic-gate
24410Sstevel@tonic-gate vp = (uintptr_t)((struct file *)wsp->walk_layer)->f_vnode;
24420Sstevel@tonic-gate if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
24430Sstevel@tonic-gate mdb_warn("failed to read vnode_t at %p", vp);
24440Sstevel@tonic-gate return (WALK_ERR);
24450Sstevel@tonic-gate }
24460Sstevel@tonic-gate if (vn.v_type != VPORT)
24470Sstevel@tonic-gate return (WALK_NEXT);
24480Sstevel@tonic-gate
24490Sstevel@tonic-gate pp = (uintptr_t)vn.v_data;
24500Sstevel@tonic-gate if (mdb_vread(&port, sizeof (port), pp) == -1) {
24510Sstevel@tonic-gate mdb_warn("failed to read port_t at %p", pp);
24520Sstevel@tonic-gate return (WALK_ERR);
24530Sstevel@tonic-gate }
24540Sstevel@tonic-gate return (wsp->walk_callback(pp, &port, wsp->walk_cbdata));
24550Sstevel@tonic-gate }
24560Sstevel@tonic-gate
24570Sstevel@tonic-gate typedef struct portev_walk_data {
24580Sstevel@tonic-gate list_node_t *pev_node;
24590Sstevel@tonic-gate list_node_t *pev_last;
24600Sstevel@tonic-gate size_t pev_offset;
24610Sstevel@tonic-gate } portev_walk_data_t;
24620Sstevel@tonic-gate
24630Sstevel@tonic-gate int
portev_walk_init(mdb_walk_state_t * wsp)24640Sstevel@tonic-gate portev_walk_init(mdb_walk_state_t *wsp)
24650Sstevel@tonic-gate {
24660Sstevel@tonic-gate portev_walk_data_t *pevd;
24670Sstevel@tonic-gate struct port port;
24680Sstevel@tonic-gate struct vnode vn;
24690Sstevel@tonic-gate struct list *list;
24700Sstevel@tonic-gate uintptr_t vp;
24710Sstevel@tonic-gate
24720Sstevel@tonic-gate if (wsp->walk_addr == NULL) {
24730Sstevel@tonic-gate mdb_warn("portev walk doesn't support global walks\n");
24740Sstevel@tonic-gate return (WALK_ERR);
24750Sstevel@tonic-gate }
24760Sstevel@tonic-gate
24770Sstevel@tonic-gate pevd = mdb_alloc(sizeof (portev_walk_data_t), UM_SLEEP);
24780Sstevel@tonic-gate
24790Sstevel@tonic-gate if (mdb_vread(&port, sizeof (port), wsp->walk_addr) == -1) {
24800Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t));
24810Sstevel@tonic-gate mdb_warn("failed to read port structure at %p", wsp->walk_addr);
24820Sstevel@tonic-gate return (WALK_ERR);
24830Sstevel@tonic-gate }
24840Sstevel@tonic-gate
24850Sstevel@tonic-gate vp = (uintptr_t)port.port_vnode;
24860Sstevel@tonic-gate if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
24870Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t));
24880Sstevel@tonic-gate mdb_warn("failed to read vnode_t at %p", vp);
24890Sstevel@tonic-gate return (WALK_ERR);
24900Sstevel@tonic-gate }
24910Sstevel@tonic-gate
24920Sstevel@tonic-gate if (vn.v_type != VPORT) {
24930Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t));
24940Sstevel@tonic-gate mdb_warn("input address (%p) does not point to an event port",
24950Sstevel@tonic-gate wsp->walk_addr);
24960Sstevel@tonic-gate return (WALK_ERR);
24970Sstevel@tonic-gate }
24980Sstevel@tonic-gate
24990Sstevel@tonic-gate if (port.port_queue.portq_nent == 0) {
25000Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t));
25010Sstevel@tonic-gate return (WALK_DONE);
25020Sstevel@tonic-gate }
25030Sstevel@tonic-gate list = &port.port_queue.portq_list;
25040Sstevel@tonic-gate pevd->pev_offset = list->list_offset;
25050Sstevel@tonic-gate pevd->pev_last = list->list_head.list_prev;
25060Sstevel@tonic-gate pevd->pev_node = list->list_head.list_next;
25070Sstevel@tonic-gate wsp->walk_data = pevd;
25080Sstevel@tonic-gate return (WALK_NEXT);
25090Sstevel@tonic-gate }
25100Sstevel@tonic-gate
25110Sstevel@tonic-gate int
portev_walk_step(mdb_walk_state_t * wsp)25120Sstevel@tonic-gate portev_walk_step(mdb_walk_state_t *wsp)
25130Sstevel@tonic-gate {
25140Sstevel@tonic-gate portev_walk_data_t *pevd;
25150Sstevel@tonic-gate struct port_kevent ev;
25160Sstevel@tonic-gate uintptr_t evp;
25170Sstevel@tonic-gate
25180Sstevel@tonic-gate pevd = (portev_walk_data_t *)wsp->walk_data;
25190Sstevel@tonic-gate
25200Sstevel@tonic-gate if (pevd->pev_last == NULL)
25210Sstevel@tonic-gate return (WALK_DONE);
25220Sstevel@tonic-gate if (pevd->pev_node == pevd->pev_last)
25230Sstevel@tonic-gate pevd->pev_last = NULL; /* last round */
25240Sstevel@tonic-gate
25250Sstevel@tonic-gate evp = ((uintptr_t)(((char *)pevd->pev_node) - pevd->pev_offset));
25260Sstevel@tonic-gate if (mdb_vread(&ev, sizeof (ev), evp) == -1) {
25270Sstevel@tonic-gate mdb_warn("failed to read port_kevent at %p", evp);
25280Sstevel@tonic-gate return (WALK_DONE);
25290Sstevel@tonic-gate }
25300Sstevel@tonic-gate pevd->pev_node = ev.portkev_node.list_next;
25310Sstevel@tonic-gate return (wsp->walk_callback(evp, &ev, wsp->walk_cbdata));
25320Sstevel@tonic-gate }
25330Sstevel@tonic-gate
25340Sstevel@tonic-gate void
portev_walk_fini(mdb_walk_state_t * wsp)25350Sstevel@tonic-gate portev_walk_fini(mdb_walk_state_t *wsp)
25360Sstevel@tonic-gate {
25370Sstevel@tonic-gate portev_walk_data_t *pevd = (portev_walk_data_t *)wsp->walk_data;
25380Sstevel@tonic-gate
25390Sstevel@tonic-gate if (pevd != NULL)
25400Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t));
25410Sstevel@tonic-gate }
25420Sstevel@tonic-gate
25430Sstevel@tonic-gate typedef struct proc_walk_data {
25440Sstevel@tonic-gate uintptr_t *pw_stack;
25450Sstevel@tonic-gate int pw_depth;
25460Sstevel@tonic-gate int pw_max;
25470Sstevel@tonic-gate } proc_walk_data_t;
25480Sstevel@tonic-gate
25490Sstevel@tonic-gate int
proc_walk_init(mdb_walk_state_t * wsp)25500Sstevel@tonic-gate proc_walk_init(mdb_walk_state_t *wsp)
25510Sstevel@tonic-gate {
25520Sstevel@tonic-gate GElf_Sym sym;
25530Sstevel@tonic-gate proc_walk_data_t *pw;
25540Sstevel@tonic-gate
25550Sstevel@tonic-gate if (wsp->walk_addr == NULL) {
25560Sstevel@tonic-gate if (mdb_lookup_by_name("p0", &sym) == -1) {
25570Sstevel@tonic-gate mdb_warn("failed to read 'practive'");
25580Sstevel@tonic-gate return (WALK_ERR);
25590Sstevel@tonic-gate }
25600Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)sym.st_value;
25610Sstevel@tonic-gate }
25620Sstevel@tonic-gate
25630Sstevel@tonic-gate pw = mdb_zalloc(sizeof (proc_walk_data_t), UM_SLEEP);
25640Sstevel@tonic-gate
25650Sstevel@tonic-gate if (mdb_readvar(&pw->pw_max, "nproc") == -1) {
25660Sstevel@tonic-gate mdb_warn("failed to read 'nproc'");
25670Sstevel@tonic-gate mdb_free(pw, sizeof (pw));
25680Sstevel@tonic-gate return (WALK_ERR);
25690Sstevel@tonic-gate }
25700Sstevel@tonic-gate
25710Sstevel@tonic-gate pw->pw_stack = mdb_alloc(pw->pw_max * sizeof (uintptr_t), UM_SLEEP);
25720Sstevel@tonic-gate wsp->walk_data = pw;
25730Sstevel@tonic-gate
25740Sstevel@tonic-gate return (WALK_NEXT);
25750Sstevel@tonic-gate }
25760Sstevel@tonic-gate
25770Sstevel@tonic-gate int
proc_walk_step(mdb_walk_state_t * wsp)25780Sstevel@tonic-gate proc_walk_step(mdb_walk_state_t *wsp)
25790Sstevel@tonic-gate {
25800Sstevel@tonic-gate proc_walk_data_t *pw = wsp->walk_data;
25810Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr;
25820Sstevel@tonic-gate uintptr_t cld, sib;
25830Sstevel@tonic-gate
25840Sstevel@tonic-gate int status;
25850Sstevel@tonic-gate proc_t pr;
25860Sstevel@tonic-gate
25870Sstevel@tonic-gate if (mdb_vread(&pr, sizeof (proc_t), addr) == -1) {
25880Sstevel@tonic-gate mdb_warn("failed to read proc at %p", addr);
25890Sstevel@tonic-gate return (WALK_DONE);
25900Sstevel@tonic-gate }
25910Sstevel@tonic-gate
25920Sstevel@tonic-gate cld = (uintptr_t)pr.p_child;
25930Sstevel@tonic-gate sib = (uintptr_t)pr.p_sibling;
25940Sstevel@tonic-gate
25950Sstevel@tonic-gate if (pw->pw_depth > 0 && addr == pw->pw_stack[pw->pw_depth - 1]) {
25960Sstevel@tonic-gate pw->pw_depth--;
25970Sstevel@tonic-gate goto sib;
25980Sstevel@tonic-gate }
25990Sstevel@tonic-gate
26000Sstevel@tonic-gate status = wsp->walk_callback(addr, &pr, wsp->walk_cbdata);
26010Sstevel@tonic-gate
26020Sstevel@tonic-gate if (status != WALK_NEXT)
26030Sstevel@tonic-gate return (status);
26040Sstevel@tonic-gate
26050Sstevel@tonic-gate if ((wsp->walk_addr = cld) != NULL) {
26060Sstevel@tonic-gate if (mdb_vread(&pr, sizeof (proc_t), cld) == -1) {
26070Sstevel@tonic-gate mdb_warn("proc %p has invalid p_child %p; skipping\n",
26080Sstevel@tonic-gate addr, cld);
26090Sstevel@tonic-gate goto sib;
26100Sstevel@tonic-gate }
26110Sstevel@tonic-gate
26120Sstevel@tonic-gate pw->pw_stack[pw->pw_depth++] = addr;
26130Sstevel@tonic-gate
26140Sstevel@tonic-gate if (pw->pw_depth == pw->pw_max) {
26150Sstevel@tonic-gate mdb_warn("depth %d exceeds max depth; try again\n",
26160Sstevel@tonic-gate pw->pw_depth);
26170Sstevel@tonic-gate return (WALK_DONE);
26180Sstevel@tonic-gate }
26190Sstevel@tonic-gate return (WALK_NEXT);
26200Sstevel@tonic-gate }
26210Sstevel@tonic-gate
26220Sstevel@tonic-gate sib:
26230Sstevel@tonic-gate /*
26240Sstevel@tonic-gate * We know that p0 has no siblings, and if another starting proc
26250Sstevel@tonic-gate * was given, we don't want to walk its siblings anyway.
26260Sstevel@tonic-gate */
26270Sstevel@tonic-gate if (pw->pw_depth == 0)
26280Sstevel@tonic-gate return (WALK_DONE);
26290Sstevel@tonic-gate
26300Sstevel@tonic-gate if (sib != NULL && mdb_vread(&pr, sizeof (proc_t), sib) == -1) {
26310Sstevel@tonic-gate mdb_warn("proc %p has invalid p_sibling %p; skipping\n",
26320Sstevel@tonic-gate addr, sib);
26330Sstevel@tonic-gate sib = NULL;
26340Sstevel@tonic-gate }
26350Sstevel@tonic-gate
26360Sstevel@tonic-gate if ((wsp->walk_addr = sib) == NULL) {
26370Sstevel@tonic-gate if (pw->pw_depth > 0) {
26380Sstevel@tonic-gate wsp->walk_addr = pw->pw_stack[pw->pw_depth - 1];
26390Sstevel@tonic-gate return (WALK_NEXT);
26400Sstevel@tonic-gate }
26410Sstevel@tonic-gate return (WALK_DONE);
26420Sstevel@tonic-gate }
26430Sstevel@tonic-gate
26440Sstevel@tonic-gate return (WALK_NEXT);
26450Sstevel@tonic-gate }
26460Sstevel@tonic-gate
26470Sstevel@tonic-gate void
proc_walk_fini(mdb_walk_state_t * wsp)26480Sstevel@tonic-gate proc_walk_fini(mdb_walk_state_t *wsp)
26490Sstevel@tonic-gate {
26500Sstevel@tonic-gate proc_walk_data_t *pw = wsp->walk_data;
26510Sstevel@tonic-gate
26520Sstevel@tonic-gate mdb_free(pw->pw_stack, pw->pw_max * sizeof (uintptr_t));
26530Sstevel@tonic-gate mdb_free(pw, sizeof (proc_walk_data_t));
26540Sstevel@tonic-gate }
26550Sstevel@tonic-gate
26560Sstevel@tonic-gate int
task_walk_init(mdb_walk_state_t * wsp)26570Sstevel@tonic-gate task_walk_init(mdb_walk_state_t *wsp)
26580Sstevel@tonic-gate {
26590Sstevel@tonic-gate task_t task;
26600Sstevel@tonic-gate
26610Sstevel@tonic-gate if (mdb_vread(&task, sizeof (task_t), wsp->walk_addr) == -1) {
26620Sstevel@tonic-gate mdb_warn("failed to read task at %p", wsp->walk_addr);
26630Sstevel@tonic-gate return (WALK_ERR);
26640Sstevel@tonic-gate }
26650Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)task.tk_memb_list;
26660Sstevel@tonic-gate wsp->walk_data = task.tk_memb_list;
26670Sstevel@tonic-gate return (WALK_NEXT);
26680Sstevel@tonic-gate }
26690Sstevel@tonic-gate
26700Sstevel@tonic-gate int
task_walk_step(mdb_walk_state_t * wsp)26710Sstevel@tonic-gate task_walk_step(mdb_walk_state_t *wsp)
26720Sstevel@tonic-gate {
26730Sstevel@tonic-gate proc_t proc;
26740Sstevel@tonic-gate int status;
26750Sstevel@tonic-gate
26760Sstevel@tonic-gate if (mdb_vread(&proc, sizeof (proc_t), wsp->walk_addr) == -1) {
26770Sstevel@tonic-gate mdb_warn("failed to read proc at %p", wsp->walk_addr);
26780Sstevel@tonic-gate return (WALK_DONE);
26790Sstevel@tonic-gate }
26800Sstevel@tonic-gate
26810Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata);
26820Sstevel@tonic-gate
26830Sstevel@tonic-gate if (proc.p_tasknext == wsp->walk_data)
26840Sstevel@tonic-gate return (WALK_DONE);
26850Sstevel@tonic-gate
26860Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)proc.p_tasknext;
26870Sstevel@tonic-gate return (status);
26880Sstevel@tonic-gate }
26890Sstevel@tonic-gate
26900Sstevel@tonic-gate int
project_walk_init(mdb_walk_state_t * wsp)26910Sstevel@tonic-gate project_walk_init(mdb_walk_state_t *wsp)
26920Sstevel@tonic-gate {
26930Sstevel@tonic-gate if (wsp->walk_addr == NULL) {
26940Sstevel@tonic-gate if (mdb_readvar(&wsp->walk_addr, "proj0p") == -1) {
26950Sstevel@tonic-gate mdb_warn("failed to read 'proj0p'");
26960Sstevel@tonic-gate return (WALK_ERR);
26970Sstevel@tonic-gate }
26980Sstevel@tonic-gate }
26990Sstevel@tonic-gate wsp->walk_data = (void *)wsp->walk_addr;
27000Sstevel@tonic-gate return (WALK_NEXT);
27010Sstevel@tonic-gate }
27020Sstevel@tonic-gate
27030Sstevel@tonic-gate int
project_walk_step(mdb_walk_state_t * wsp)27040Sstevel@tonic-gate project_walk_step(mdb_walk_state_t *wsp)
27050Sstevel@tonic-gate {
27060Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr;
27070Sstevel@tonic-gate kproject_t pj;
27080Sstevel@tonic-gate int status;
27090Sstevel@tonic-gate
27100Sstevel@tonic-gate if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
27110Sstevel@tonic-gate mdb_warn("failed to read project at %p", addr);
27120Sstevel@tonic-gate return (WALK_DONE);
27130Sstevel@tonic-gate }
27140Sstevel@tonic-gate status = wsp->walk_callback(addr, &pj, wsp->walk_cbdata);
27150Sstevel@tonic-gate if (status != WALK_NEXT)
27160Sstevel@tonic-gate return (status);
27170Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)pj.kpj_next;
27180Sstevel@tonic-gate if ((void *)wsp->walk_addr == wsp->walk_data)
27190Sstevel@tonic-gate return (WALK_DONE);
27200Sstevel@tonic-gate return (WALK_NEXT);
27210Sstevel@tonic-gate }
27220Sstevel@tonic-gate
27230Sstevel@tonic-gate static int
generic_walk_step(mdb_walk_state_t * wsp)27240Sstevel@tonic-gate generic_walk_step(mdb_walk_state_t *wsp)
27250Sstevel@tonic-gate {
27260Sstevel@tonic-gate return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
27270Sstevel@tonic-gate wsp->walk_cbdata));
27280Sstevel@tonic-gate }
27290Sstevel@tonic-gate
27300Sstevel@tonic-gate static int
cpu_walk_cmp(const void * l,const void * r)27310Sstevel@tonic-gate cpu_walk_cmp(const void *l, const void *r)
27320Sstevel@tonic-gate {
27330Sstevel@tonic-gate uintptr_t lhs = *((uintptr_t *)l);
27340Sstevel@tonic-gate uintptr_t rhs = *((uintptr_t *)r);
27350Sstevel@tonic-gate cpu_t lcpu, rcpu;
27360Sstevel@tonic-gate
27370Sstevel@tonic-gate (void) mdb_vread(&lcpu, sizeof (lcpu), lhs);
27380Sstevel@tonic-gate (void) mdb_vread(&rcpu, sizeof (rcpu), rhs);
27390Sstevel@tonic-gate
27400Sstevel@tonic-gate if (lcpu.cpu_id < rcpu.cpu_id)
27410Sstevel@tonic-gate return (-1);
27420Sstevel@tonic-gate
27430Sstevel@tonic-gate if (lcpu.cpu_id > rcpu.cpu_id)
27440Sstevel@tonic-gate return (1);
27450Sstevel@tonic-gate
27460Sstevel@tonic-gate return (0);
27470Sstevel@tonic-gate }
27480Sstevel@tonic-gate
27490Sstevel@tonic-gate typedef struct cpu_walk {
27500Sstevel@tonic-gate uintptr_t *cw_array;
27510Sstevel@tonic-gate int cw_ndx;
27520Sstevel@tonic-gate } cpu_walk_t;
27530Sstevel@tonic-gate
27540Sstevel@tonic-gate int
cpu_walk_init(mdb_walk_state_t * wsp)27550Sstevel@tonic-gate cpu_walk_init(mdb_walk_state_t *wsp)
27560Sstevel@tonic-gate {
27570Sstevel@tonic-gate cpu_walk_t *cw;
27580Sstevel@tonic-gate int max_ncpus, i = 0;
27590Sstevel@tonic-gate uintptr_t current, first;
27600Sstevel@tonic-gate cpu_t cpu, panic_cpu;
27610Sstevel@tonic-gate uintptr_t panicstr, addr;
27620Sstevel@tonic-gate GElf_Sym sym;
27630Sstevel@tonic-gate
27640Sstevel@tonic-gate cw = mdb_zalloc(sizeof (cpu_walk_t), UM_SLEEP | UM_GC);
27650Sstevel@tonic-gate
27660Sstevel@tonic-gate if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
27670Sstevel@tonic-gate mdb_warn("failed to read 'max_ncpus'");
27680Sstevel@tonic-gate return (WALK_ERR);
27690Sstevel@tonic-gate }
27700Sstevel@tonic-gate
27710Sstevel@tonic-gate if (mdb_readvar(&panicstr, "panicstr") == -1) {
27720Sstevel@tonic-gate mdb_warn("failed to read 'panicstr'");
27730Sstevel@tonic-gate return (WALK_ERR);
27740Sstevel@tonic-gate }
27750Sstevel@tonic-gate
27760Sstevel@tonic-gate if (panicstr != NULL) {
27770Sstevel@tonic-gate if (mdb_lookup_by_name("panic_cpu", &sym) == -1) {
27780Sstevel@tonic-gate mdb_warn("failed to find 'panic_cpu'");
27790Sstevel@tonic-gate return (WALK_ERR);
27800Sstevel@tonic-gate }
27810Sstevel@tonic-gate
27820Sstevel@tonic-gate addr = (uintptr_t)sym.st_value;
27830Sstevel@tonic-gate
27840Sstevel@tonic-gate if (mdb_vread(&panic_cpu, sizeof (cpu_t), addr) == -1) {
27850Sstevel@tonic-gate mdb_warn("failed to read 'panic_cpu'");
27860Sstevel@tonic-gate return (WALK_ERR);
27870Sstevel@tonic-gate }
27880Sstevel@tonic-gate }
27890Sstevel@tonic-gate
27900Sstevel@tonic-gate /*
27910Sstevel@tonic-gate * Unfortunately, there is no platform-independent way to walk
27920Sstevel@tonic-gate * CPUs in ID order. We therefore loop through in cpu_next order,
27930Sstevel@tonic-gate * building an array of CPU pointers which will subsequently be
27940Sstevel@tonic-gate * sorted.
27950Sstevel@tonic-gate */
27960Sstevel@tonic-gate cw->cw_array =
27970Sstevel@tonic-gate mdb_zalloc((max_ncpus + 1) * sizeof (uintptr_t), UM_SLEEP | UM_GC);
27980Sstevel@tonic-gate
27990Sstevel@tonic-gate if (mdb_readvar(&first, "cpu_list") == -1) {
28000Sstevel@tonic-gate mdb_warn("failed to read 'cpu_list'");
28010Sstevel@tonic-gate return (WALK_ERR);
28020Sstevel@tonic-gate }
28030Sstevel@tonic-gate
28040Sstevel@tonic-gate current = first;
28050Sstevel@tonic-gate do {
28060Sstevel@tonic-gate if (mdb_vread(&cpu, sizeof (cpu), current) == -1) {
28070Sstevel@tonic-gate mdb_warn("failed to read cpu at %p", current);
28080Sstevel@tonic-gate return (WALK_ERR);
28090Sstevel@tonic-gate }
28100Sstevel@tonic-gate
28110Sstevel@tonic-gate if (panicstr != NULL && panic_cpu.cpu_id == cpu.cpu_id) {
28120Sstevel@tonic-gate cw->cw_array[i++] = addr;
28130Sstevel@tonic-gate } else {
28140Sstevel@tonic-gate cw->cw_array[i++] = current;
28150Sstevel@tonic-gate }
28160Sstevel@tonic-gate } while ((current = (uintptr_t)cpu.cpu_next) != first);
28170Sstevel@tonic-gate
28180Sstevel@tonic-gate qsort(cw->cw_array, i, sizeof (uintptr_t), cpu_walk_cmp);
28190Sstevel@tonic-gate wsp->walk_data = cw;
28200Sstevel@tonic-gate
28210Sstevel@tonic-gate return (WALK_NEXT);
28220Sstevel@tonic-gate }
28230Sstevel@tonic-gate
28240Sstevel@tonic-gate int
cpu_walk_step(mdb_walk_state_t * wsp)28250Sstevel@tonic-gate cpu_walk_step(mdb_walk_state_t *wsp)
28260Sstevel@tonic-gate {
28270Sstevel@tonic-gate cpu_walk_t *cw = wsp->walk_data;
28280Sstevel@tonic-gate cpu_t cpu;
28290Sstevel@tonic-gate uintptr_t addr = cw->cw_array[cw->cw_ndx++];
28300Sstevel@tonic-gate
28310Sstevel@tonic-gate if (addr == NULL)
28320Sstevel@tonic-gate return (WALK_DONE);
28330Sstevel@tonic-gate
28340Sstevel@tonic-gate if (mdb_vread(&cpu, sizeof (cpu), addr) == -1) {
28350Sstevel@tonic-gate mdb_warn("failed to read cpu at %p", addr);
28360Sstevel@tonic-gate return (WALK_DONE);
28370Sstevel@tonic-gate }
28380Sstevel@tonic-gate
28390Sstevel@tonic-gate return (wsp->walk_callback(addr, &cpu, wsp->walk_cbdata));
28400Sstevel@tonic-gate }
28410Sstevel@tonic-gate
28420Sstevel@tonic-gate typedef struct cpuinfo_data {
28430Sstevel@tonic-gate intptr_t cid_cpu;
28440Sstevel@tonic-gate uintptr_t **cid_ithr;
28450Sstevel@tonic-gate char cid_print_head;
28460Sstevel@tonic-gate char cid_print_thr;
28470Sstevel@tonic-gate char cid_print_ithr;
28480Sstevel@tonic-gate char cid_print_flags;
28490Sstevel@tonic-gate } cpuinfo_data_t;
28500Sstevel@tonic-gate
28510Sstevel@tonic-gate int
cpuinfo_walk_ithread(uintptr_t addr,const kthread_t * thr,cpuinfo_data_t * cid)28520Sstevel@tonic-gate cpuinfo_walk_ithread(uintptr_t addr, const kthread_t *thr, cpuinfo_data_t *cid)
28530Sstevel@tonic-gate {
28540Sstevel@tonic-gate cpu_t c;
28550Sstevel@tonic-gate int id;
28560Sstevel@tonic-gate uint8_t pil;
28570Sstevel@tonic-gate
28580Sstevel@tonic-gate if (!(thr->t_flag & T_INTR_THREAD) || thr->t_state == TS_FREE)
28590Sstevel@tonic-gate return (WALK_NEXT);
28600Sstevel@tonic-gate
28610Sstevel@tonic-gate if (thr->t_bound_cpu == NULL) {
28620Sstevel@tonic-gate mdb_warn("thr %p is intr thread w/out a CPU\n", addr);
28630Sstevel@tonic-gate return (WALK_NEXT);
28640Sstevel@tonic-gate }
28650Sstevel@tonic-gate
28660Sstevel@tonic-gate (void) mdb_vread(&c, sizeof (c), (uintptr_t)thr->t_bound_cpu);
28670Sstevel@tonic-gate
28680Sstevel@tonic-gate if ((id = c.cpu_id) >= NCPU) {
28690Sstevel@tonic-gate mdb_warn("CPU %p has id (%d) greater than NCPU (%d)\n",
28700Sstevel@tonic-gate thr->t_bound_cpu, id, NCPU);
28710Sstevel@tonic-gate return (WALK_NEXT);
28720Sstevel@tonic-gate }
28730Sstevel@tonic-gate
28740Sstevel@tonic-gate if ((pil = thr->t_pil) >= NINTR) {
28750Sstevel@tonic-gate mdb_warn("thread %p has pil (%d) greater than %d\n",
28760Sstevel@tonic-gate addr, pil, NINTR);
28770Sstevel@tonic-gate return (WALK_NEXT);
28780Sstevel@tonic-gate }
28790Sstevel@tonic-gate
28800Sstevel@tonic-gate if (cid->cid_ithr[id][pil] != NULL) {
28810Sstevel@tonic-gate mdb_warn("CPU %d has multiple threads at pil %d (at least "
28820Sstevel@tonic-gate "%p and %p)\n", id, pil, addr, cid->cid_ithr[id][pil]);
28830Sstevel@tonic-gate return (WALK_NEXT);
28840Sstevel@tonic-gate }
28850Sstevel@tonic-gate
28860Sstevel@tonic-gate cid->cid_ithr[id][pil] = addr;
28870Sstevel@tonic-gate
28880Sstevel@tonic-gate return (WALK_NEXT);
28890Sstevel@tonic-gate }
28900Sstevel@tonic-gate
28910Sstevel@tonic-gate #define CPUINFO_IDWIDTH 3
28920Sstevel@tonic-gate #define CPUINFO_FLAGWIDTH 9
28930Sstevel@tonic-gate
28940Sstevel@tonic-gate #ifdef _LP64
2895537Smishra #if defined(__amd64)
2896537Smishra #define CPUINFO_TWIDTH 16
2897537Smishra #define CPUINFO_CPUWIDTH 16
2898537Smishra #else
28990Sstevel@tonic-gate #define CPUINFO_CPUWIDTH 11
29000Sstevel@tonic-gate #define CPUINFO_TWIDTH 11
2901537Smishra #endif
29020Sstevel@tonic-gate #else
29030Sstevel@tonic-gate #define CPUINFO_CPUWIDTH 8
29040Sstevel@tonic-gate #define CPUINFO_TWIDTH 8
29050Sstevel@tonic-gate #endif
29060Sstevel@tonic-gate
29070Sstevel@tonic-gate #define CPUINFO_THRDELT (CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 9)
29080Sstevel@tonic-gate #define CPUINFO_FLAGDELT (CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 4)
29090Sstevel@tonic-gate #define CPUINFO_ITHRDELT 4
29100Sstevel@tonic-gate
29110Sstevel@tonic-gate #define CPUINFO_INDENT mdb_printf("%*s", CPUINFO_THRDELT, \
29120Sstevel@tonic-gate flagline < nflaglines ? flagbuf[flagline++] : "")
29130Sstevel@tonic-gate
29140Sstevel@tonic-gate int
cpuinfo_walk_cpu(uintptr_t addr,const cpu_t * cpu,cpuinfo_data_t * cid)29150Sstevel@tonic-gate cpuinfo_walk_cpu(uintptr_t addr, const cpu_t *cpu, cpuinfo_data_t *cid)
29160Sstevel@tonic-gate {
29170Sstevel@tonic-gate kthread_t t;
29180Sstevel@tonic-gate disp_t disp;
29190Sstevel@tonic-gate proc_t p;
29200Sstevel@tonic-gate uintptr_t pinned;
29210Sstevel@tonic-gate char **flagbuf;
29220Sstevel@tonic-gate int nflaglines = 0, flagline = 0, bspl, rval = WALK_NEXT;
29230Sstevel@tonic-gate
29240Sstevel@tonic-gate const char *flags[] = {
29250Sstevel@tonic-gate "RUNNING", "READY", "QUIESCED", "EXISTS",
29260Sstevel@tonic-gate "ENABLE", "OFFLINE", "POWEROFF", "FROZEN",
29270Sstevel@tonic-gate "SPARE", "FAULTED", NULL
29280Sstevel@tonic-gate };
29290Sstevel@tonic-gate
29300Sstevel@tonic-gate if (cid->cid_cpu != -1) {
29310Sstevel@tonic-gate if (addr != cid->cid_cpu && cpu->cpu_id != cid->cid_cpu)
29320Sstevel@tonic-gate return (WALK_NEXT);
29330Sstevel@tonic-gate
29340Sstevel@tonic-gate /*
29350Sstevel@tonic-gate * Set cid_cpu to -1 to indicate that we found a matching CPU.
29360Sstevel@tonic-gate */
29370Sstevel@tonic-gate cid->cid_cpu = -1;
29380Sstevel@tonic-gate rval = WALK_DONE;
29390Sstevel@tonic-gate }
29400Sstevel@tonic-gate
29410Sstevel@tonic-gate if (cid->cid_print_head) {
29420Sstevel@tonic-gate mdb_printf("%3s %-*s %3s %4s %4s %3s %4s %5s %-6s %-*s %s\n",
29430Sstevel@tonic-gate "ID", CPUINFO_CPUWIDTH, "ADDR", "FLG", "NRUN", "BSPL",
29440Sstevel@tonic-gate "PRI", "RNRN", "KRNRN", "SWITCH", CPUINFO_TWIDTH, "THREAD",
29450Sstevel@tonic-gate "PROC");
29460Sstevel@tonic-gate cid->cid_print_head = FALSE;
29470Sstevel@tonic-gate }
29480Sstevel@tonic-gate
29490Sstevel@tonic-gate bspl = cpu->cpu_base_spl;
29500Sstevel@tonic-gate
29510Sstevel@tonic-gate if (mdb_vread(&disp, sizeof (disp_t), (uintptr_t)cpu->cpu_disp) == -1) {
29520Sstevel@tonic-gate mdb_warn("failed to read disp_t at %p", cpu->cpu_disp);
29530Sstevel@tonic-gate return (WALK_ERR);
29540Sstevel@tonic-gate }
29550Sstevel@tonic-gate
29560Sstevel@tonic-gate mdb_printf("%3d %0*p %3x %4d %4d ",
29570Sstevel@tonic-gate cpu->cpu_id, CPUINFO_CPUWIDTH, addr, cpu->cpu_flags,
29580Sstevel@tonic-gate disp.disp_nrunnable, bspl);
29590Sstevel@tonic-gate
29600Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), (uintptr_t)cpu->cpu_thread) != -1) {
29610Sstevel@tonic-gate mdb_printf("%3d ", t.t_pri);
29620Sstevel@tonic-gate } else {
29630Sstevel@tonic-gate mdb_printf("%3s ", "-");
29640Sstevel@tonic-gate }
29650Sstevel@tonic-gate
29660Sstevel@tonic-gate mdb_printf("%4s %5s ", cpu->cpu_runrun ? "yes" : "no",
29670Sstevel@tonic-gate cpu->cpu_kprunrun ? "yes" : "no");
29680Sstevel@tonic-gate
29690Sstevel@tonic-gate if (cpu->cpu_last_swtch) {
297011066Srafael.vanoni@sun.com mdb_printf("t-%-4d ",
297111066Srafael.vanoni@sun.com (clock_t)mdb_get_lbolt() - cpu->cpu_last_swtch);
29720Sstevel@tonic-gate } else {
29730Sstevel@tonic-gate mdb_printf("%-6s ", "-");
29740Sstevel@tonic-gate }
29750Sstevel@tonic-gate
29760Sstevel@tonic-gate mdb_printf("%0*p", CPUINFO_TWIDTH, cpu->cpu_thread);
29770Sstevel@tonic-gate
29780Sstevel@tonic-gate if (cpu->cpu_thread == cpu->cpu_idle_thread)
29790Sstevel@tonic-gate mdb_printf(" (idle)\n");
29800Sstevel@tonic-gate else if (cpu->cpu_thread == NULL)
29810Sstevel@tonic-gate mdb_printf(" -\n");
29820Sstevel@tonic-gate else {
29830Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), (uintptr_t)t.t_procp) != -1) {
29840Sstevel@tonic-gate mdb_printf(" %s\n", p.p_user.u_comm);
29850Sstevel@tonic-gate } else {
29860Sstevel@tonic-gate mdb_printf(" ?\n");
29870Sstevel@tonic-gate }
29880Sstevel@tonic-gate }
29890Sstevel@tonic-gate
29900Sstevel@tonic-gate flagbuf = mdb_zalloc(sizeof (flags), UM_SLEEP | UM_GC);
29910Sstevel@tonic-gate
29920Sstevel@tonic-gate if (cid->cid_print_flags) {
29930Sstevel@tonic-gate int first = 1, i, j, k;
29940Sstevel@tonic-gate char *s;
29950Sstevel@tonic-gate
29960Sstevel@tonic-gate cid->cid_print_head = TRUE;
29970Sstevel@tonic-gate
29980Sstevel@tonic-gate for (i = 1, j = 0; flags[j] != NULL; i <<= 1, j++) {
29990Sstevel@tonic-gate if (!(cpu->cpu_flags & i))
30000Sstevel@tonic-gate continue;
30010Sstevel@tonic-gate
30020Sstevel@tonic-gate if (first) {
30030Sstevel@tonic-gate s = mdb_alloc(CPUINFO_THRDELT + 1,
30040Sstevel@tonic-gate UM_GC | UM_SLEEP);
30050Sstevel@tonic-gate
30060Sstevel@tonic-gate (void) mdb_snprintf(s, CPUINFO_THRDELT + 1,
30070Sstevel@tonic-gate "%*s|%*s", CPUINFO_FLAGDELT, "",
30080Sstevel@tonic-gate CPUINFO_THRDELT - 1 - CPUINFO_FLAGDELT, "");
30090Sstevel@tonic-gate flagbuf[nflaglines++] = s;
30100Sstevel@tonic-gate }
30110Sstevel@tonic-gate
30120Sstevel@tonic-gate s = mdb_alloc(CPUINFO_THRDELT + 1, UM_GC | UM_SLEEP);
30130Sstevel@tonic-gate (void) mdb_snprintf(s, CPUINFO_THRDELT + 1, "%*s%*s %s",
30140Sstevel@tonic-gate CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH -
30150Sstevel@tonic-gate CPUINFO_FLAGWIDTH, "", CPUINFO_FLAGWIDTH, flags[j],
30160Sstevel@tonic-gate first ? "<--+" : "");
30170Sstevel@tonic-gate
30180Sstevel@tonic-gate for (k = strlen(s); k < CPUINFO_THRDELT; k++)
30190Sstevel@tonic-gate s[k] = ' ';
30200Sstevel@tonic-gate s[k] = '\0';
30210Sstevel@tonic-gate
30220Sstevel@tonic-gate flagbuf[nflaglines++] = s;
30230Sstevel@tonic-gate first = 0;
30240Sstevel@tonic-gate }
30250Sstevel@tonic-gate }
30260Sstevel@tonic-gate
30270Sstevel@tonic-gate if (cid->cid_print_ithr) {
30280Sstevel@tonic-gate int i, found_one = FALSE;
30290Sstevel@tonic-gate int print_thr = disp.disp_nrunnable && cid->cid_print_thr;
30300Sstevel@tonic-gate
30310Sstevel@tonic-gate for (i = NINTR - 1; i >= 0; i--) {
30320Sstevel@tonic-gate uintptr_t iaddr = cid->cid_ithr[cpu->cpu_id][i];
30330Sstevel@tonic-gate
30340Sstevel@tonic-gate if (iaddr == NULL)
30350Sstevel@tonic-gate continue;
30360Sstevel@tonic-gate
30370Sstevel@tonic-gate if (!found_one) {
30380Sstevel@tonic-gate found_one = TRUE;
30390Sstevel@tonic-gate
30400Sstevel@tonic-gate CPUINFO_INDENT;
30410Sstevel@tonic-gate mdb_printf("%c%*s|\n", print_thr ? '|' : ' ',
30420Sstevel@tonic-gate CPUINFO_ITHRDELT, "");
30430Sstevel@tonic-gate
30440Sstevel@tonic-gate CPUINFO_INDENT;
30450Sstevel@tonic-gate mdb_printf("%c%*s+--> %3s %s\n",
30460Sstevel@tonic-gate print_thr ? '|' : ' ', CPUINFO_ITHRDELT,
30470Sstevel@tonic-gate "", "PIL", "THREAD");
30480Sstevel@tonic-gate }
30490Sstevel@tonic-gate
30500Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), iaddr) == -1) {
30510Sstevel@tonic-gate mdb_warn("failed to read kthread_t at %p",
30520Sstevel@tonic-gate iaddr);
30530Sstevel@tonic-gate return (WALK_ERR);
30540Sstevel@tonic-gate }
30550Sstevel@tonic-gate
30560Sstevel@tonic-gate CPUINFO_INDENT;
30570Sstevel@tonic-gate mdb_printf("%c%*s %3d %0*p\n",
30580Sstevel@tonic-gate print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "",
30590Sstevel@tonic-gate t.t_pil, CPUINFO_TWIDTH, iaddr);
30600Sstevel@tonic-gate
30610Sstevel@tonic-gate pinned = (uintptr_t)t.t_intr;
30620Sstevel@tonic-gate }
30630Sstevel@tonic-gate
30640Sstevel@tonic-gate if (found_one && pinned != NULL) {
30650Sstevel@tonic-gate cid->cid_print_head = TRUE;
30660Sstevel@tonic-gate (void) strcpy(p.p_user.u_comm, "?");
30670Sstevel@tonic-gate
30680Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t),
30690Sstevel@tonic-gate (uintptr_t)pinned) == -1) {
30700Sstevel@tonic-gate mdb_warn("failed to read kthread_t at %p",
30710Sstevel@tonic-gate pinned);
30720Sstevel@tonic-gate return (WALK_ERR);
30730Sstevel@tonic-gate }
30740Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p),
30750Sstevel@tonic-gate (uintptr_t)t.t_procp) == -1) {
30760Sstevel@tonic-gate mdb_warn("failed to read proc_t at %p",
30770Sstevel@tonic-gate t.t_procp);
30780Sstevel@tonic-gate return (WALK_ERR);
30790Sstevel@tonic-gate }
30800Sstevel@tonic-gate
30810Sstevel@tonic-gate CPUINFO_INDENT;
30820Sstevel@tonic-gate mdb_printf("%c%*s %3s %0*p %s\n",
30830Sstevel@tonic-gate print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", "-",
30840Sstevel@tonic-gate CPUINFO_TWIDTH, pinned,
30850Sstevel@tonic-gate pinned == (uintptr_t)cpu->cpu_idle_thread ?
30860Sstevel@tonic-gate "(idle)" : p.p_user.u_comm);
30870Sstevel@tonic-gate }
30880Sstevel@tonic-gate }
30890Sstevel@tonic-gate
30900Sstevel@tonic-gate if (disp.disp_nrunnable && cid->cid_print_thr) {
30910Sstevel@tonic-gate dispq_t *dq;
30920Sstevel@tonic-gate
30930Sstevel@tonic-gate int i, npri = disp.disp_npri;
30940Sstevel@tonic-gate
30950Sstevel@tonic-gate dq = mdb_alloc(sizeof (dispq_t) * npri, UM_SLEEP | UM_GC);
30960Sstevel@tonic-gate
30970Sstevel@tonic-gate if (mdb_vread(dq, sizeof (dispq_t) * npri,
30980Sstevel@tonic-gate (uintptr_t)disp.disp_q) == -1) {
30990Sstevel@tonic-gate mdb_warn("failed to read dispq_t at %p", disp.disp_q);
31000Sstevel@tonic-gate return (WALK_ERR);
31010Sstevel@tonic-gate }
31020Sstevel@tonic-gate
31030Sstevel@tonic-gate CPUINFO_INDENT;
31040Sstevel@tonic-gate mdb_printf("|\n");
31050Sstevel@tonic-gate
31060Sstevel@tonic-gate CPUINFO_INDENT;
31070Sstevel@tonic-gate mdb_printf("+--> %3s %-*s %s\n", "PRI",
31080Sstevel@tonic-gate CPUINFO_TWIDTH, "THREAD", "PROC");
31090Sstevel@tonic-gate
31100Sstevel@tonic-gate for (i = npri - 1; i >= 0; i--) {
31110Sstevel@tonic-gate uintptr_t taddr = (uintptr_t)dq[i].dq_first;
31120Sstevel@tonic-gate
31130Sstevel@tonic-gate while (taddr != NULL) {
31140Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), taddr) == -1) {
31150Sstevel@tonic-gate mdb_warn("failed to read kthread_t "
31160Sstevel@tonic-gate "at %p", taddr);
31170Sstevel@tonic-gate return (WALK_ERR);
31180Sstevel@tonic-gate }
31190Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p),
31200Sstevel@tonic-gate (uintptr_t)t.t_procp) == -1) {
31210Sstevel@tonic-gate mdb_warn("failed to read proc_t at %p",
31220Sstevel@tonic-gate t.t_procp);
31230Sstevel@tonic-gate return (WALK_ERR);
31240Sstevel@tonic-gate }
31250Sstevel@tonic-gate
31260Sstevel@tonic-gate CPUINFO_INDENT;
31270Sstevel@tonic-gate mdb_printf(" %3d %0*p %s\n", t.t_pri,
31280Sstevel@tonic-gate CPUINFO_TWIDTH, taddr, p.p_user.u_comm);
31290Sstevel@tonic-gate
31300Sstevel@tonic-gate taddr = (uintptr_t)t.t_link;
31310Sstevel@tonic-gate }
31320Sstevel@tonic-gate }
31330Sstevel@tonic-gate cid->cid_print_head = TRUE;
31340Sstevel@tonic-gate }
31350Sstevel@tonic-gate
31360Sstevel@tonic-gate while (flagline < nflaglines)
31370Sstevel@tonic-gate mdb_printf("%s\n", flagbuf[flagline++]);
31380Sstevel@tonic-gate
31390Sstevel@tonic-gate if (cid->cid_print_head)
31400Sstevel@tonic-gate mdb_printf("\n");
31410Sstevel@tonic-gate
31420Sstevel@tonic-gate return (rval);
31430Sstevel@tonic-gate }
31440Sstevel@tonic-gate
31450Sstevel@tonic-gate int
cpuinfo(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)31460Sstevel@tonic-gate cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
31470Sstevel@tonic-gate {
31480Sstevel@tonic-gate uint_t verbose = FALSE;
31490Sstevel@tonic-gate cpuinfo_data_t cid;
31500Sstevel@tonic-gate
31510Sstevel@tonic-gate cid.cid_print_ithr = FALSE;
31520Sstevel@tonic-gate cid.cid_print_thr = FALSE;
31530Sstevel@tonic-gate cid.cid_print_flags = FALSE;
31540Sstevel@tonic-gate cid.cid_print_head = DCMD_HDRSPEC(flags) ? TRUE : FALSE;
31550Sstevel@tonic-gate cid.cid_cpu = -1;
31560Sstevel@tonic-gate
31570Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC)
31580Sstevel@tonic-gate cid.cid_cpu = addr;
31590Sstevel@tonic-gate
31600Sstevel@tonic-gate if (mdb_getopts(argc, argv,
31610Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc)
31620Sstevel@tonic-gate return (DCMD_USAGE);
31630Sstevel@tonic-gate
31640Sstevel@tonic-gate if (verbose) {
31650Sstevel@tonic-gate cid.cid_print_ithr = TRUE;
31660Sstevel@tonic-gate cid.cid_print_thr = TRUE;
31670Sstevel@tonic-gate cid.cid_print_flags = TRUE;
31680Sstevel@tonic-gate cid.cid_print_head = TRUE;
31690Sstevel@tonic-gate }
31700Sstevel@tonic-gate
31710Sstevel@tonic-gate if (cid.cid_print_ithr) {
31720Sstevel@tonic-gate int i;
31730Sstevel@tonic-gate
31740Sstevel@tonic-gate cid.cid_ithr = mdb_alloc(sizeof (uintptr_t **)
31750Sstevel@tonic-gate * NCPU, UM_SLEEP | UM_GC);
31760Sstevel@tonic-gate
31770Sstevel@tonic-gate for (i = 0; i < NCPU; i++)
31780Sstevel@tonic-gate cid.cid_ithr[i] = mdb_zalloc(sizeof (uintptr_t *) *
31790Sstevel@tonic-gate NINTR, UM_SLEEP | UM_GC);
31800Sstevel@tonic-gate
31810Sstevel@tonic-gate if (mdb_walk("thread", (mdb_walk_cb_t)cpuinfo_walk_ithread,
31820Sstevel@tonic-gate &cid) == -1) {
31830Sstevel@tonic-gate mdb_warn("couldn't walk thread");
31840Sstevel@tonic-gate return (DCMD_ERR);
31850Sstevel@tonic-gate }
31860Sstevel@tonic-gate }
31870Sstevel@tonic-gate
31880Sstevel@tonic-gate if (mdb_walk("cpu", (mdb_walk_cb_t)cpuinfo_walk_cpu, &cid) == -1) {
31890Sstevel@tonic-gate mdb_warn("can't walk cpus");
31900Sstevel@tonic-gate return (DCMD_ERR);
31910Sstevel@tonic-gate }
31920Sstevel@tonic-gate
31930Sstevel@tonic-gate if (cid.cid_cpu != -1) {
31940Sstevel@tonic-gate /*
31950Sstevel@tonic-gate * We didn't find this CPU when we walked through the CPUs
31960Sstevel@tonic-gate * (i.e. the address specified doesn't show up in the "cpu"
31970Sstevel@tonic-gate * walk). However, the specified address may still correspond
31980Sstevel@tonic-gate * to a valid cpu_t (for example, if the specified address is
31990Sstevel@tonic-gate * the actual panicking cpu_t and not the cached panic_cpu).
32000Sstevel@tonic-gate * Point is: even if we didn't find it, we still want to try
32010Sstevel@tonic-gate * to print the specified address as a cpu_t.
32020Sstevel@tonic-gate */
32030Sstevel@tonic-gate cpu_t cpu;
32040Sstevel@tonic-gate
32050Sstevel@tonic-gate if (mdb_vread(&cpu, sizeof (cpu), cid.cid_cpu) == -1) {
32060Sstevel@tonic-gate mdb_warn("%p is neither a valid CPU ID nor a "
32070Sstevel@tonic-gate "valid cpu_t address\n", cid.cid_cpu);
32080Sstevel@tonic-gate return (DCMD_ERR);
32090Sstevel@tonic-gate }
32100Sstevel@tonic-gate
32110Sstevel@tonic-gate (void) cpuinfo_walk_cpu(cid.cid_cpu, &cpu, &cid);
32120Sstevel@tonic-gate }
32130Sstevel@tonic-gate
32140Sstevel@tonic-gate return (DCMD_OK);
32150Sstevel@tonic-gate }
32160Sstevel@tonic-gate
32170Sstevel@tonic-gate /*ARGSUSED*/
32180Sstevel@tonic-gate int
flipone(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)32190Sstevel@tonic-gate flipone(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
32200Sstevel@tonic-gate {
32210Sstevel@tonic-gate int i;
32220Sstevel@tonic-gate
32230Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC))
32240Sstevel@tonic-gate return (DCMD_USAGE);
32250Sstevel@tonic-gate
32260Sstevel@tonic-gate for (i = 0; i < sizeof (addr) * NBBY; i++)
32270Sstevel@tonic-gate mdb_printf("%p\n", addr ^ (1UL << i));
32280Sstevel@tonic-gate
32290Sstevel@tonic-gate return (DCMD_OK);
32300Sstevel@tonic-gate }
32310Sstevel@tonic-gate
32320Sstevel@tonic-gate int
as2proc_walk(uintptr_t addr,const proc_t * p,struct as ** asp)32330Sstevel@tonic-gate as2proc_walk(uintptr_t addr, const proc_t *p, struct as **asp)
32340Sstevel@tonic-gate {
32350Sstevel@tonic-gate if (p->p_as == *asp)
32360Sstevel@tonic-gate mdb_printf("%p\n", addr);
32370Sstevel@tonic-gate return (WALK_NEXT);
32380Sstevel@tonic-gate }
32390Sstevel@tonic-gate
32400Sstevel@tonic-gate /*ARGSUSED*/
32410Sstevel@tonic-gate int
as2proc(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)32420Sstevel@tonic-gate as2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
32430Sstevel@tonic-gate {
32440Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || argc != 0)
32450Sstevel@tonic-gate return (DCMD_USAGE);
32460Sstevel@tonic-gate
32470Sstevel@tonic-gate if (mdb_walk("proc", (mdb_walk_cb_t)as2proc_walk, &addr) == -1) {
32480Sstevel@tonic-gate mdb_warn("failed to walk proc");
32490Sstevel@tonic-gate return (DCMD_ERR);
32500Sstevel@tonic-gate }
32510Sstevel@tonic-gate
32520Sstevel@tonic-gate return (DCMD_OK);
32530Sstevel@tonic-gate }
32540Sstevel@tonic-gate
32550Sstevel@tonic-gate /*ARGSUSED*/
32560Sstevel@tonic-gate int
ptree_walk(uintptr_t addr,const proc_t * p,void * ignored)32570Sstevel@tonic-gate ptree_walk(uintptr_t addr, const proc_t *p, void *ignored)
32580Sstevel@tonic-gate {
32590Sstevel@tonic-gate proc_t parent;
32600Sstevel@tonic-gate int ident = 0;
32610Sstevel@tonic-gate uintptr_t paddr;
32620Sstevel@tonic-gate
32630Sstevel@tonic-gate for (paddr = (uintptr_t)p->p_parent; paddr != NULL; ident += 5) {
32640Sstevel@tonic-gate mdb_vread(&parent, sizeof (parent), paddr);
32650Sstevel@tonic-gate paddr = (uintptr_t)parent.p_parent;
32660Sstevel@tonic-gate }
32670Sstevel@tonic-gate
32680Sstevel@tonic-gate mdb_inc_indent(ident);
32690Sstevel@tonic-gate mdb_printf("%0?p %s\n", addr, p->p_user.u_comm);
32700Sstevel@tonic-gate mdb_dec_indent(ident);
32710Sstevel@tonic-gate
32720Sstevel@tonic-gate return (WALK_NEXT);
32730Sstevel@tonic-gate }
32740Sstevel@tonic-gate
32750Sstevel@tonic-gate void
ptree_ancestors(uintptr_t addr,uintptr_t start)32760Sstevel@tonic-gate ptree_ancestors(uintptr_t addr, uintptr_t start)
32770Sstevel@tonic-gate {
32780Sstevel@tonic-gate proc_t p;
32790Sstevel@tonic-gate
32800Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), addr) == -1) {
32810Sstevel@tonic-gate mdb_warn("couldn't read ancestor at %p", addr);
32820Sstevel@tonic-gate return;
32830Sstevel@tonic-gate }
32840Sstevel@tonic-gate
32850Sstevel@tonic-gate if (p.p_parent != NULL)
32860Sstevel@tonic-gate ptree_ancestors((uintptr_t)p.p_parent, start);
32870Sstevel@tonic-gate
32880Sstevel@tonic-gate if (addr != start)
32890Sstevel@tonic-gate (void) ptree_walk(addr, &p, NULL);
32900Sstevel@tonic-gate }
32910Sstevel@tonic-gate
32920Sstevel@tonic-gate /*ARGSUSED*/
32930Sstevel@tonic-gate int
ptree(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)32940Sstevel@tonic-gate ptree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
32950Sstevel@tonic-gate {
32960Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC))
32970Sstevel@tonic-gate addr = NULL;
32980Sstevel@tonic-gate else
32990Sstevel@tonic-gate ptree_ancestors(addr, addr);
33000Sstevel@tonic-gate
33010Sstevel@tonic-gate if (mdb_pwalk("proc", (mdb_walk_cb_t)ptree_walk, NULL, addr) == -1) {
33020Sstevel@tonic-gate mdb_warn("couldn't walk 'proc'");
33030Sstevel@tonic-gate return (DCMD_ERR);
33040Sstevel@tonic-gate }
33050Sstevel@tonic-gate
33060Sstevel@tonic-gate return (DCMD_OK);
33070Sstevel@tonic-gate }
33080Sstevel@tonic-gate
33090Sstevel@tonic-gate /*ARGSUSED*/
33100Sstevel@tonic-gate static int
fd(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)33110Sstevel@tonic-gate fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
33120Sstevel@tonic-gate {
33130Sstevel@tonic-gate int fdnum;
33140Sstevel@tonic-gate const mdb_arg_t *argp = &argv[0];
33150Sstevel@tonic-gate proc_t p;
33160Sstevel@tonic-gate uf_entry_t uf;
33170Sstevel@tonic-gate
33180Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0) {
33190Sstevel@tonic-gate mdb_warn("fd doesn't give global information\n");
33200Sstevel@tonic-gate return (DCMD_ERR);
33210Sstevel@tonic-gate }
33220Sstevel@tonic-gate if (argc != 1)
33230Sstevel@tonic-gate return (DCMD_USAGE);
33240Sstevel@tonic-gate
33250Sstevel@tonic-gate if (argp->a_type == MDB_TYPE_IMMEDIATE)
33260Sstevel@tonic-gate fdnum = argp->a_un.a_val;
33270Sstevel@tonic-gate else
33280Sstevel@tonic-gate fdnum = mdb_strtoull(argp->a_un.a_str);
33290Sstevel@tonic-gate
33300Sstevel@tonic-gate if (mdb_vread(&p, sizeof (struct proc), addr) == -1) {
33310Sstevel@tonic-gate mdb_warn("couldn't read proc_t at %p", addr);
33320Sstevel@tonic-gate return (DCMD_ERR);
33330Sstevel@tonic-gate }
33340Sstevel@tonic-gate if (fdnum > p.p_user.u_finfo.fi_nfiles) {
33350Sstevel@tonic-gate mdb_warn("process %p only has %d files open.\n",
33360Sstevel@tonic-gate addr, p.p_user.u_finfo.fi_nfiles);
33370Sstevel@tonic-gate return (DCMD_ERR);
33380Sstevel@tonic-gate }
33390Sstevel@tonic-gate if (mdb_vread(&uf, sizeof (uf_entry_t),
33400Sstevel@tonic-gate (uintptr_t)&p.p_user.u_finfo.fi_list[fdnum]) == -1) {
33410Sstevel@tonic-gate mdb_warn("couldn't read uf_entry_t at %p",
33420Sstevel@tonic-gate &p.p_user.u_finfo.fi_list[fdnum]);
33430Sstevel@tonic-gate return (DCMD_ERR);
33440Sstevel@tonic-gate }
33450Sstevel@tonic-gate
33460Sstevel@tonic-gate mdb_printf("%p\n", uf.uf_file);
33470Sstevel@tonic-gate return (DCMD_OK);
33480Sstevel@tonic-gate }
33490Sstevel@tonic-gate
33500Sstevel@tonic-gate /*ARGSUSED*/
33510Sstevel@tonic-gate static int
pid2proc(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)33520Sstevel@tonic-gate pid2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
33530Sstevel@tonic-gate {
33540Sstevel@tonic-gate pid_t pid = (pid_t)addr;
33550Sstevel@tonic-gate
33560Sstevel@tonic-gate if (argc != 0)
33570Sstevel@tonic-gate return (DCMD_USAGE);
33580Sstevel@tonic-gate
33590Sstevel@tonic-gate if ((addr = mdb_pid2proc(pid, NULL)) == NULL) {
33600Sstevel@tonic-gate mdb_warn("PID 0t%d not found\n", pid);
33610Sstevel@tonic-gate return (DCMD_ERR);
33620Sstevel@tonic-gate }
33630Sstevel@tonic-gate
33640Sstevel@tonic-gate mdb_printf("%p\n", addr);
33650Sstevel@tonic-gate return (DCMD_OK);
33660Sstevel@tonic-gate }
33670Sstevel@tonic-gate
33680Sstevel@tonic-gate static char *sysfile_cmd[] = {
33690Sstevel@tonic-gate "exclude:",
33700Sstevel@tonic-gate "include:",
33710Sstevel@tonic-gate "forceload:",
33720Sstevel@tonic-gate "rootdev:",
33730Sstevel@tonic-gate "rootfs:",
33740Sstevel@tonic-gate "swapdev:",
33750Sstevel@tonic-gate "swapfs:",
33760Sstevel@tonic-gate "moddir:",
33770Sstevel@tonic-gate "set",
33780Sstevel@tonic-gate "unknown",
33790Sstevel@tonic-gate };
33800Sstevel@tonic-gate
33810Sstevel@tonic-gate static char *sysfile_ops[] = { "", "=", "&", "|" };
33820Sstevel@tonic-gate
33830Sstevel@tonic-gate /*ARGSUSED*/
33840Sstevel@tonic-gate static int
sysfile_vmem_seg(uintptr_t addr,const vmem_seg_t * vsp,void ** target)33850Sstevel@tonic-gate sysfile_vmem_seg(uintptr_t addr, const vmem_seg_t *vsp, void **target)
33860Sstevel@tonic-gate {
33870Sstevel@tonic-gate if (vsp->vs_type == VMEM_ALLOC && (void *)vsp->vs_start == *target) {
33880Sstevel@tonic-gate *target = NULL;
33890Sstevel@tonic-gate return (WALK_DONE);
33900Sstevel@tonic-gate }
33910Sstevel@tonic-gate return (WALK_NEXT);
33920Sstevel@tonic-gate }
33930Sstevel@tonic-gate
33940Sstevel@tonic-gate /*ARGSUSED*/
33950Sstevel@tonic-gate static int
sysfile(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)33960Sstevel@tonic-gate sysfile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
33970Sstevel@tonic-gate {
33980Sstevel@tonic-gate struct sysparam *sysp, sys;
33990Sstevel@tonic-gate char var[256];
34000Sstevel@tonic-gate char modname[256];
34010Sstevel@tonic-gate char val[256];
34020Sstevel@tonic-gate char strval[256];
34030Sstevel@tonic-gate vmem_t *mod_sysfile_arena;
34040Sstevel@tonic-gate void *straddr;
34050Sstevel@tonic-gate
34060Sstevel@tonic-gate if (mdb_readvar(&sysp, "sysparam_hd") == -1) {
34070Sstevel@tonic-gate mdb_warn("failed to read sysparam_hd");
34080Sstevel@tonic-gate return (DCMD_ERR);
34090Sstevel@tonic-gate }
34100Sstevel@tonic-gate
34110Sstevel@tonic-gate if (mdb_readvar(&mod_sysfile_arena, "mod_sysfile_arena") == -1) {
34120Sstevel@tonic-gate mdb_warn("failed to read mod_sysfile_arena");
34130Sstevel@tonic-gate return (DCMD_ERR);
34140Sstevel@tonic-gate }
34150Sstevel@tonic-gate
34160Sstevel@tonic-gate while (sysp != NULL) {
34170Sstevel@tonic-gate var[0] = '\0';
34180Sstevel@tonic-gate val[0] = '\0';
34190Sstevel@tonic-gate modname[0] = '\0';
34200Sstevel@tonic-gate if (mdb_vread(&sys, sizeof (sys), (uintptr_t)sysp) == -1) {
34210Sstevel@tonic-gate mdb_warn("couldn't read sysparam %p", sysp);
34220Sstevel@tonic-gate return (DCMD_ERR);
34230Sstevel@tonic-gate }
34240Sstevel@tonic-gate if (sys.sys_modnam != NULL &&
34250Sstevel@tonic-gate mdb_readstr(modname, 256,
34260Sstevel@tonic-gate (uintptr_t)sys.sys_modnam) == -1) {
34270Sstevel@tonic-gate mdb_warn("couldn't read modname in %p", sysp);
34280Sstevel@tonic-gate return (DCMD_ERR);
34290Sstevel@tonic-gate }
34300Sstevel@tonic-gate if (sys.sys_ptr != NULL &&
34310Sstevel@tonic-gate mdb_readstr(var, 256, (uintptr_t)sys.sys_ptr) == -1) {
34320Sstevel@tonic-gate mdb_warn("couldn't read ptr in %p", sysp);
34330Sstevel@tonic-gate return (DCMD_ERR);
34340Sstevel@tonic-gate }
34350Sstevel@tonic-gate if (sys.sys_op != SETOP_NONE) {
34360Sstevel@tonic-gate /*
34370Sstevel@tonic-gate * Is this an int or a string? We determine this
34380Sstevel@tonic-gate * by checking whether straddr is contained in
34390Sstevel@tonic-gate * mod_sysfile_arena. If so, the walker will set
34400Sstevel@tonic-gate * straddr to NULL.
34410Sstevel@tonic-gate */
34420Sstevel@tonic-gate straddr = (void *)(uintptr_t)sys.sys_info;
34430Sstevel@tonic-gate if (sys.sys_op == SETOP_ASSIGN &&
34440Sstevel@tonic-gate sys.sys_info != 0 &&
34450Sstevel@tonic-gate mdb_pwalk("vmem_seg",
34460Sstevel@tonic-gate (mdb_walk_cb_t)sysfile_vmem_seg, &straddr,
34470Sstevel@tonic-gate (uintptr_t)mod_sysfile_arena) == 0 &&
34480Sstevel@tonic-gate straddr == NULL &&
34490Sstevel@tonic-gate mdb_readstr(strval, 256,
34500Sstevel@tonic-gate (uintptr_t)sys.sys_info) != -1) {
34510Sstevel@tonic-gate (void) mdb_snprintf(val, sizeof (val), "\"%s\"",
34520Sstevel@tonic-gate strval);
34530Sstevel@tonic-gate } else {
34540Sstevel@tonic-gate (void) mdb_snprintf(val, sizeof (val),
34550Sstevel@tonic-gate "0x%llx [0t%llu]", sys.sys_info,
34560Sstevel@tonic-gate sys.sys_info);
34570Sstevel@tonic-gate }
34580Sstevel@tonic-gate }
34590Sstevel@tonic-gate mdb_printf("%s %s%s%s%s%s\n", sysfile_cmd[sys.sys_type],
34600Sstevel@tonic-gate modname, modname[0] == '\0' ? "" : ":",
34610Sstevel@tonic-gate var, sysfile_ops[sys.sys_op], val);
34620Sstevel@tonic-gate
34630Sstevel@tonic-gate sysp = sys.sys_next;
34640Sstevel@tonic-gate }
34650Sstevel@tonic-gate
34660Sstevel@tonic-gate return (DCMD_OK);
34670Sstevel@tonic-gate }
34680Sstevel@tonic-gate
34690Sstevel@tonic-gate int
didmatch(uintptr_t addr,const kthread_t * thr,kt_did_t * didp)34700Sstevel@tonic-gate didmatch(uintptr_t addr, const kthread_t *thr, kt_did_t *didp)
34710Sstevel@tonic-gate {
34720Sstevel@tonic-gate
34730Sstevel@tonic-gate if (*didp == thr->t_did) {
34740Sstevel@tonic-gate mdb_printf("%p\n", addr);
34750Sstevel@tonic-gate return (WALK_DONE);
34760Sstevel@tonic-gate } else
34770Sstevel@tonic-gate return (WALK_NEXT);
34780Sstevel@tonic-gate }
34790Sstevel@tonic-gate
34800Sstevel@tonic-gate /*ARGSUSED*/
34810Sstevel@tonic-gate int
did2thread(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)34820Sstevel@tonic-gate did2thread(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
34830Sstevel@tonic-gate {
34840Sstevel@tonic-gate const mdb_arg_t *argp = &argv[0];
34850Sstevel@tonic-gate kt_did_t did;
34860Sstevel@tonic-gate
34870Sstevel@tonic-gate if (argc != 1)
34880Sstevel@tonic-gate return (DCMD_USAGE);
34890Sstevel@tonic-gate
34900Sstevel@tonic-gate did = (kt_did_t)mdb_strtoull(argp->a_un.a_str);
34910Sstevel@tonic-gate
34920Sstevel@tonic-gate if (mdb_walk("thread", (mdb_walk_cb_t)didmatch, (void *)&did) == -1) {
34930Sstevel@tonic-gate mdb_warn("failed to walk thread");
34940Sstevel@tonic-gate return (DCMD_ERR);
34950Sstevel@tonic-gate
34960Sstevel@tonic-gate }
34970Sstevel@tonic-gate return (DCMD_OK);
34980Sstevel@tonic-gate
34990Sstevel@tonic-gate }
35000Sstevel@tonic-gate
35010Sstevel@tonic-gate static int
errorq_walk_init(mdb_walk_state_t * wsp)35020Sstevel@tonic-gate errorq_walk_init(mdb_walk_state_t *wsp)
35030Sstevel@tonic-gate {
35040Sstevel@tonic-gate if (wsp->walk_addr == NULL &&
35050Sstevel@tonic-gate mdb_readvar(&wsp->walk_addr, "errorq_list") == -1) {
35060Sstevel@tonic-gate mdb_warn("failed to read errorq_list");
35070Sstevel@tonic-gate return (WALK_ERR);
35080Sstevel@tonic-gate }
35090Sstevel@tonic-gate
35100Sstevel@tonic-gate return (WALK_NEXT);
35110Sstevel@tonic-gate }
35120Sstevel@tonic-gate
35130Sstevel@tonic-gate static int
errorq_walk_step(mdb_walk_state_t * wsp)35140Sstevel@tonic-gate errorq_walk_step(mdb_walk_state_t *wsp)
35150Sstevel@tonic-gate {
35160Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr;
35170Sstevel@tonic-gate errorq_t eq;
35180Sstevel@tonic-gate
35190Sstevel@tonic-gate if (addr == NULL)
35200Sstevel@tonic-gate return (WALK_DONE);
35210Sstevel@tonic-gate
35220Sstevel@tonic-gate if (mdb_vread(&eq, sizeof (eq), addr) == -1) {
35230Sstevel@tonic-gate mdb_warn("failed to read errorq at %p", addr);
35240Sstevel@tonic-gate return (WALK_ERR);
35250Sstevel@tonic-gate }
35260Sstevel@tonic-gate
35270Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)eq.eq_next;
35280Sstevel@tonic-gate return (wsp->walk_callback(addr, &eq, wsp->walk_cbdata));
35290Sstevel@tonic-gate }
35300Sstevel@tonic-gate
35310Sstevel@tonic-gate typedef struct eqd_walk_data {
35320Sstevel@tonic-gate uintptr_t *eqd_stack;
35330Sstevel@tonic-gate void *eqd_buf;
35340Sstevel@tonic-gate ulong_t eqd_qpos;
35350Sstevel@tonic-gate ulong_t eqd_qlen;
35360Sstevel@tonic-gate size_t eqd_size;
35370Sstevel@tonic-gate } eqd_walk_data_t;
35380Sstevel@tonic-gate
35390Sstevel@tonic-gate /*
35400Sstevel@tonic-gate * In order to walk the list of pending error queue elements, we push the
35410Sstevel@tonic-gate * addresses of the corresponding data buffers in to the eqd_stack array.
35420Sstevel@tonic-gate * The error lists are in reverse chronological order when iterating using
35430Sstevel@tonic-gate * eqe_prev, so we then pop things off the top in eqd_walk_step so that the
35440Sstevel@tonic-gate * walker client gets addresses in order from oldest error to newest error.
35450Sstevel@tonic-gate */
35460Sstevel@tonic-gate static void
eqd_push_list(eqd_walk_data_t * eqdp,uintptr_t addr)35470Sstevel@tonic-gate eqd_push_list(eqd_walk_data_t *eqdp, uintptr_t addr)
35480Sstevel@tonic-gate {
35490Sstevel@tonic-gate errorq_elem_t eqe;
35500Sstevel@tonic-gate
35510Sstevel@tonic-gate while (addr != NULL) {
35520Sstevel@tonic-gate if (mdb_vread(&eqe, sizeof (eqe), addr) != sizeof (eqe)) {
35530Sstevel@tonic-gate mdb_warn("failed to read errorq element at %p", addr);
35540Sstevel@tonic-gate break;
35550Sstevel@tonic-gate }
35560Sstevel@tonic-gate
35570Sstevel@tonic-gate if (eqdp->eqd_qpos == eqdp->eqd_qlen) {
35580Sstevel@tonic-gate mdb_warn("errorq is overfull -- more than %lu "
35590Sstevel@tonic-gate "elems found\n", eqdp->eqd_qlen);
35600Sstevel@tonic-gate break;
35610Sstevel@tonic-gate }
35620Sstevel@tonic-gate
35630Sstevel@tonic-gate eqdp->eqd_stack[eqdp->eqd_qpos++] = (uintptr_t)eqe.eqe_data;
35640Sstevel@tonic-gate addr = (uintptr_t)eqe.eqe_prev;
35650Sstevel@tonic-gate }
35660Sstevel@tonic-gate }
35670Sstevel@tonic-gate
35680Sstevel@tonic-gate static int
eqd_walk_init(mdb_walk_state_t * wsp)35690Sstevel@tonic-gate eqd_walk_init(mdb_walk_state_t *wsp)
35700Sstevel@tonic-gate {
35710Sstevel@tonic-gate eqd_walk_data_t *eqdp;
35720Sstevel@tonic-gate errorq_elem_t eqe, *addr;
35730Sstevel@tonic-gate errorq_t eq;
35740Sstevel@tonic-gate ulong_t i;
35750Sstevel@tonic-gate
35760Sstevel@tonic-gate if (mdb_vread(&eq, sizeof (eq), wsp->walk_addr) == -1) {
35770Sstevel@tonic-gate mdb_warn("failed to read errorq at %p", wsp->walk_addr);
35780Sstevel@tonic-gate return (WALK_ERR);
35790Sstevel@tonic-gate }
35800Sstevel@tonic-gate
35810Sstevel@tonic-gate if (eq.eq_ptail != NULL &&
35820Sstevel@tonic-gate mdb_vread(&eqe, sizeof (eqe), (uintptr_t)eq.eq_ptail) == -1) {
35830Sstevel@tonic-gate mdb_warn("failed to read errorq element at %p", eq.eq_ptail);
35840Sstevel@tonic-gate return (WALK_ERR);
35850Sstevel@tonic-gate }
35860Sstevel@tonic-gate
35870Sstevel@tonic-gate eqdp = mdb_alloc(sizeof (eqd_walk_data_t), UM_SLEEP);
35880Sstevel@tonic-gate wsp->walk_data = eqdp;
35890Sstevel@tonic-gate
35900Sstevel@tonic-gate eqdp->eqd_stack = mdb_zalloc(sizeof (uintptr_t) * eq.eq_qlen, UM_SLEEP);
35910Sstevel@tonic-gate eqdp->eqd_buf = mdb_alloc(eq.eq_size, UM_SLEEP);
35920Sstevel@tonic-gate eqdp->eqd_qlen = eq.eq_qlen;
35930Sstevel@tonic-gate eqdp->eqd_qpos = 0;
35940Sstevel@tonic-gate eqdp->eqd_size = eq.eq_size;
35950Sstevel@tonic-gate
35960Sstevel@tonic-gate /*
35970Sstevel@tonic-gate * The newest elements in the queue are on the pending list, so we
35980Sstevel@tonic-gate * push those on to our stack first.
35990Sstevel@tonic-gate */
36000Sstevel@tonic-gate eqd_push_list(eqdp, (uintptr_t)eq.eq_pend);
36010Sstevel@tonic-gate
36020Sstevel@tonic-gate /*
36030Sstevel@tonic-gate * If eq_ptail is set, it may point to a subset of the errors on the
36040Sstevel@tonic-gate * pending list in the event a casptr() failed; if ptail's data is
36050Sstevel@tonic-gate * already in our stack, NULL out eq_ptail and ignore it.
36060Sstevel@tonic-gate */
36070Sstevel@tonic-gate if (eq.eq_ptail != NULL) {
36080Sstevel@tonic-gate for (i = 0; i < eqdp->eqd_qpos; i++) {
36090Sstevel@tonic-gate if (eqdp->eqd_stack[i] == (uintptr_t)eqe.eqe_data) {
36100Sstevel@tonic-gate eq.eq_ptail = NULL;
36110Sstevel@tonic-gate break;
36120Sstevel@tonic-gate }
36130Sstevel@tonic-gate }
36140Sstevel@tonic-gate }
36150Sstevel@tonic-gate
36160Sstevel@tonic-gate /*
36170Sstevel@tonic-gate * If eq_phead is set, it has the processing list in order from oldest
36180Sstevel@tonic-gate * to newest. Use this to recompute eq_ptail as best we can and then
36190Sstevel@tonic-gate * we nicely fall into eqd_push_list() of eq_ptail below.
36200Sstevel@tonic-gate */
36210Sstevel@tonic-gate for (addr = eq.eq_phead; addr != NULL && mdb_vread(&eqe, sizeof (eqe),
36220Sstevel@tonic-gate (uintptr_t)addr) == sizeof (eqe); addr = eqe.eqe_next)
36230Sstevel@tonic-gate eq.eq_ptail = addr;
36240Sstevel@tonic-gate
36250Sstevel@tonic-gate /*
36260Sstevel@tonic-gate * The oldest elements in the queue are on the processing list, subject
36270Sstevel@tonic-gate * to machinations in the if-clauses above. Push any such elements.
36280Sstevel@tonic-gate */
36290Sstevel@tonic-gate eqd_push_list(eqdp, (uintptr_t)eq.eq_ptail);
36300Sstevel@tonic-gate return (WALK_NEXT);
36310Sstevel@tonic-gate }
36320Sstevel@tonic-gate
36330Sstevel@tonic-gate static int
eqd_walk_step(mdb_walk_state_t * wsp)36340Sstevel@tonic-gate eqd_walk_step(mdb_walk_state_t *wsp)
36350Sstevel@tonic-gate {
36360Sstevel@tonic-gate eqd_walk_data_t *eqdp = wsp->walk_data;
36370Sstevel@tonic-gate uintptr_t addr;
36380Sstevel@tonic-gate
36390Sstevel@tonic-gate if (eqdp->eqd_qpos == 0)
36400Sstevel@tonic-gate return (WALK_DONE);
36410Sstevel@tonic-gate
36420Sstevel@tonic-gate addr = eqdp->eqd_stack[--eqdp->eqd_qpos];
36430Sstevel@tonic-gate
36440Sstevel@tonic-gate if (mdb_vread(eqdp->eqd_buf, eqdp->eqd_size, addr) != eqdp->eqd_size) {
36450Sstevel@tonic-gate mdb_warn("failed to read errorq data at %p", addr);
36460Sstevel@tonic-gate return (WALK_ERR);
36470Sstevel@tonic-gate }
36480Sstevel@tonic-gate
36490Sstevel@tonic-gate return (wsp->walk_callback(addr, eqdp->eqd_buf, wsp->walk_cbdata));
36500Sstevel@tonic-gate }
36510Sstevel@tonic-gate
36520Sstevel@tonic-gate static void
eqd_walk_fini(mdb_walk_state_t * wsp)36530Sstevel@tonic-gate eqd_walk_fini(mdb_walk_state_t *wsp)
36540Sstevel@tonic-gate {
36550Sstevel@tonic-gate eqd_walk_data_t *eqdp = wsp->walk_data;
36560Sstevel@tonic-gate
36570Sstevel@tonic-gate mdb_free(eqdp->eqd_stack, sizeof (uintptr_t) * eqdp->eqd_qlen);
36580Sstevel@tonic-gate mdb_free(eqdp->eqd_buf, eqdp->eqd_size);
36590Sstevel@tonic-gate mdb_free(eqdp, sizeof (eqd_walk_data_t));
36600Sstevel@tonic-gate }
36610Sstevel@tonic-gate
36620Sstevel@tonic-gate #define EQKSVAL(eqv, what) (eqv.eq_kstat.what.value.ui64)
36630Sstevel@tonic-gate
36640Sstevel@tonic-gate static int
errorq(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)36650Sstevel@tonic-gate errorq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
36660Sstevel@tonic-gate {
36670Sstevel@tonic-gate int i;
36680Sstevel@tonic-gate errorq_t eq;
36690Sstevel@tonic-gate uint_t opt_v = FALSE;
36700Sstevel@tonic-gate
36710Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
36720Sstevel@tonic-gate if (mdb_walk_dcmd("errorq", "errorq", argc, argv) == -1) {
36730Sstevel@tonic-gate mdb_warn("can't walk 'errorq'");
36740Sstevel@tonic-gate return (DCMD_ERR);
36750Sstevel@tonic-gate }
36760Sstevel@tonic-gate return (DCMD_OK);
36770Sstevel@tonic-gate }
36780Sstevel@tonic-gate
36790Sstevel@tonic-gate i = mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &opt_v, NULL);
36800Sstevel@tonic-gate argc -= i;
36810Sstevel@tonic-gate argv += i;
36820Sstevel@tonic-gate
36830Sstevel@tonic-gate if (argc != 0)
36840Sstevel@tonic-gate return (DCMD_USAGE);
36850Sstevel@tonic-gate
36860Sstevel@tonic-gate if (opt_v || DCMD_HDRSPEC(flags)) {
36870Sstevel@tonic-gate mdb_printf("%<u>%-11s %-16s %1s %1s %1s ",
36880Sstevel@tonic-gate "ADDR", "NAME", "S", "V", "N");
36890Sstevel@tonic-gate if (!opt_v) {
36900Sstevel@tonic-gate mdb_printf("%7s %7s %7s%</u>\n",
36910Sstevel@tonic-gate "ACCEPT", "DROP", "LOG");
36920Sstevel@tonic-gate } else {
36930Sstevel@tonic-gate mdb_printf("%5s %6s %6s %3s %16s%</u>\n",
36940Sstevel@tonic-gate "KSTAT", "QLEN", "SIZE", "IPL", "FUNC");
36950Sstevel@tonic-gate }
36960Sstevel@tonic-gate }
36970Sstevel@tonic-gate
36980Sstevel@tonic-gate if (mdb_vread(&eq, sizeof (eq), addr) != sizeof (eq)) {
36990Sstevel@tonic-gate mdb_warn("failed to read errorq at %p", addr);
37000Sstevel@tonic-gate return (DCMD_ERR);
37010Sstevel@tonic-gate }
37020Sstevel@tonic-gate
37030Sstevel@tonic-gate mdb_printf("%-11p %-16s %c %c %c ", addr, eq.eq_name,
37040Sstevel@tonic-gate (eq.eq_flags & ERRORQ_ACTIVE) ? '+' : '-',
37050Sstevel@tonic-gate (eq.eq_flags & ERRORQ_VITAL) ? '!' : ' ',
37060Sstevel@tonic-gate (eq.eq_flags & ERRORQ_NVLIST) ? '*' : ' ');
37070Sstevel@tonic-gate
37080Sstevel@tonic-gate if (!opt_v) {
37090Sstevel@tonic-gate mdb_printf("%7llu %7llu %7llu\n",
37100Sstevel@tonic-gate EQKSVAL(eq, eqk_dispatched) + EQKSVAL(eq, eqk_committed),
37110Sstevel@tonic-gate EQKSVAL(eq, eqk_dropped) + EQKSVAL(eq, eqk_reserve_fail) +
37120Sstevel@tonic-gate EQKSVAL(eq, eqk_commit_fail), EQKSVAL(eq, eqk_logged));
37130Sstevel@tonic-gate } else {
37140Sstevel@tonic-gate mdb_printf("%5s %6lu %6lu %3u %a\n",
37150Sstevel@tonic-gate " | ", eq.eq_qlen, eq.eq_size, eq.eq_ipl, eq.eq_func);
37160Sstevel@tonic-gate mdb_printf("%38s\n%41s"
37170Sstevel@tonic-gate "%12s %llu\n"
37180Sstevel@tonic-gate "%53s %llu\n"
37190Sstevel@tonic-gate "%53s %llu\n"
37200Sstevel@tonic-gate "%53s %llu\n"
37210Sstevel@tonic-gate "%53s %llu\n"
37220Sstevel@tonic-gate "%53s %llu\n"
37230Sstevel@tonic-gate "%53s %llu\n"
37240Sstevel@tonic-gate "%53s %llu\n\n",
37250Sstevel@tonic-gate "|", "+-> ",
37260Sstevel@tonic-gate "DISPATCHED", EQKSVAL(eq, eqk_dispatched),
37270Sstevel@tonic-gate "DROPPED", EQKSVAL(eq, eqk_dropped),
37280Sstevel@tonic-gate "LOGGED", EQKSVAL(eq, eqk_logged),
37290Sstevel@tonic-gate "RESERVED", EQKSVAL(eq, eqk_reserved),
37300Sstevel@tonic-gate "RESERVE FAIL", EQKSVAL(eq, eqk_reserve_fail),
37310Sstevel@tonic-gate "COMMITTED", EQKSVAL(eq, eqk_committed),
37320Sstevel@tonic-gate "COMMIT FAIL", EQKSVAL(eq, eqk_commit_fail),
37330Sstevel@tonic-gate "CANCELLED", EQKSVAL(eq, eqk_cancelled));
37340Sstevel@tonic-gate }
37350Sstevel@tonic-gate
37360Sstevel@tonic-gate return (DCMD_OK);
37370Sstevel@tonic-gate }
37380Sstevel@tonic-gate
37390Sstevel@tonic-gate /*ARGSUSED*/
37400Sstevel@tonic-gate static int
panicinfo(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)37410Sstevel@tonic-gate panicinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
37420Sstevel@tonic-gate {
37430Sstevel@tonic-gate cpu_t panic_cpu;
37440Sstevel@tonic-gate kthread_t *panic_thread;
37454256Spetede void *buf;
37460Sstevel@tonic-gate panic_data_t *pd;
37470Sstevel@tonic-gate int i, n;
37480Sstevel@tonic-gate
37490Sstevel@tonic-gate if (!mdb_prop_postmortem) {
37500Sstevel@tonic-gate mdb_warn("panicinfo can only be run on a system "
37510Sstevel@tonic-gate "dump; see dumpadm(1M)\n");
37520Sstevel@tonic-gate return (DCMD_ERR);
37530Sstevel@tonic-gate }
37540Sstevel@tonic-gate
37550Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC || argc != 0)
37560Sstevel@tonic-gate return (DCMD_USAGE);
37570Sstevel@tonic-gate
37580Sstevel@tonic-gate if (mdb_readsym(&panic_cpu, sizeof (cpu_t), "panic_cpu") == -1)
37590Sstevel@tonic-gate mdb_warn("failed to read 'panic_cpu'");
37600Sstevel@tonic-gate else
37610Sstevel@tonic-gate mdb_printf("%16s %?d\n", "cpu", panic_cpu.cpu_id);
37620Sstevel@tonic-gate
37630Sstevel@tonic-gate if (mdb_readvar(&panic_thread, "panic_thread") == -1)
37640Sstevel@tonic-gate mdb_warn("failed to read 'panic_thread'");
37650Sstevel@tonic-gate else
37660Sstevel@tonic-gate mdb_printf("%16s %?p\n", "thread", panic_thread);
37670Sstevel@tonic-gate
37684256Spetede buf = mdb_alloc(PANICBUFSIZE, UM_SLEEP);
37694256Spetede pd = (panic_data_t *)buf;
37704256Spetede
37714256Spetede if (mdb_readsym(buf, PANICBUFSIZE, "panicbuf") == -1 ||
37720Sstevel@tonic-gate pd->pd_version != PANICBUFVERS) {
37730Sstevel@tonic-gate mdb_warn("failed to read 'panicbuf'");
37744256Spetede mdb_free(buf, PANICBUFSIZE);
37750Sstevel@tonic-gate return (DCMD_ERR);
37760Sstevel@tonic-gate }
37770Sstevel@tonic-gate
37784256Spetede mdb_printf("%16s %s\n", "message", (char *)buf + pd->pd_msgoff);
37790Sstevel@tonic-gate
37800Sstevel@tonic-gate n = (pd->pd_msgoff - (sizeof (panic_data_t) -
37810Sstevel@tonic-gate sizeof (panic_nv_t))) / sizeof (panic_nv_t);
37820Sstevel@tonic-gate
37830Sstevel@tonic-gate for (i = 0; i < n; i++)
37840Sstevel@tonic-gate mdb_printf("%16s %?llx\n",
37850Sstevel@tonic-gate pd->pd_nvdata[i].pnv_name, pd->pd_nvdata[i].pnv_value);
37860Sstevel@tonic-gate
37874256Spetede mdb_free(buf, PANICBUFSIZE);
37880Sstevel@tonic-gate return (DCMD_OK);
37890Sstevel@tonic-gate }
37900Sstevel@tonic-gate
379111066Srafael.vanoni@sun.com /*
379211066Srafael.vanoni@sun.com * ::time dcmd, which will print a hires timestamp of when we entered the
379311066Srafael.vanoni@sun.com * debugger, or the lbolt value if used with the -l option.
379411066Srafael.vanoni@sun.com *
379511066Srafael.vanoni@sun.com */
379611066Srafael.vanoni@sun.com /*ARGSUSED*/
379711066Srafael.vanoni@sun.com static int
time(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)379811066Srafael.vanoni@sun.com time(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
379911066Srafael.vanoni@sun.com {
380013077SJonathan.Adams@Sun.COM uint_t opt_dec = FALSE;
380111066Srafael.vanoni@sun.com uint_t opt_lbolt = FALSE;
380213077SJonathan.Adams@Sun.COM uint_t opt_hex = FALSE;
380313077SJonathan.Adams@Sun.COM const char *fmt;
380413077SJonathan.Adams@Sun.COM hrtime_t result;
380513077SJonathan.Adams@Sun.COM
380613077SJonathan.Adams@Sun.COM if (mdb_getopts(argc, argv,
380713077SJonathan.Adams@Sun.COM 'd', MDB_OPT_SETBITS, TRUE, &opt_dec,
380813077SJonathan.Adams@Sun.COM 'l', MDB_OPT_SETBITS, TRUE, &opt_lbolt,
380913077SJonathan.Adams@Sun.COM 'x', MDB_OPT_SETBITS, TRUE, &opt_hex,
381011066Srafael.vanoni@sun.com NULL) != argc)
381111066Srafael.vanoni@sun.com return (DCMD_USAGE);
381211066Srafael.vanoni@sun.com
381313077SJonathan.Adams@Sun.COM if (opt_dec && opt_hex)
381413077SJonathan.Adams@Sun.COM return (DCMD_USAGE);
381513077SJonathan.Adams@Sun.COM
381613077SJonathan.Adams@Sun.COM result = opt_lbolt ? mdb_get_lbolt() : mdb_gethrtime();
381713077SJonathan.Adams@Sun.COM fmt =
381813077SJonathan.Adams@Sun.COM opt_hex ? "0x%llx\n" :
381913077SJonathan.Adams@Sun.COM opt_dec ? "0t%lld\n" : "%#llr\n";
382013077SJonathan.Adams@Sun.COM
382113077SJonathan.Adams@Sun.COM mdb_printf(fmt, result);
382211066Srafael.vanoni@sun.com return (DCMD_OK);
382311066Srafael.vanoni@sun.com }
382411066Srafael.vanoni@sun.com
382511066Srafael.vanoni@sun.com void
time_help(void)382611066Srafael.vanoni@sun.com time_help(void)
382711066Srafael.vanoni@sun.com {
382811066Srafael.vanoni@sun.com mdb_printf("Prints the system time in nanoseconds.\n\n"
382911151Srafael.vanoni@sun.com "::time will return the timestamp at which we dropped into, \n"
383011151Srafael.vanoni@sun.com "if called from, kmdb(1); the core dump's high resolution \n"
383111151Srafael.vanoni@sun.com "time if inspecting one; or the running hires time if we're \n"
383211151Srafael.vanoni@sun.com "looking at a live system.\n\n"
383311066Srafael.vanoni@sun.com "Switches:\n"
383413077SJonathan.Adams@Sun.COM " -d report times in decimal\n"
383513077SJonathan.Adams@Sun.COM " -l prints the number of clock ticks since system boot\n"
383613077SJonathan.Adams@Sun.COM " -x report times in hexadecimal\n");
383711066Srafael.vanoni@sun.com }
383811066Srafael.vanoni@sun.com
38390Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
38400Sstevel@tonic-gate
38410Sstevel@tonic-gate /* from genunix.c */
38420Sstevel@tonic-gate { "as2proc", ":", "convert as to proc_t address", as2proc },
38430Sstevel@tonic-gate { "binding_hash_entry", ":", "print driver names hash table entry",
38440Sstevel@tonic-gate binding_hash_entry },
38459039SMadhavan.Venkataraman@Sun.COM { "callout", "?[-r|n] [-s|l] [-xhB] [-t | -ab nsec [-dkD]]"
38468048SMadhavan.Venkataraman@Sun.COM " [-C addr | -S seqid] [-f name|addr] [-p name| addr] [-T|L [-E]]"
38478048SMadhavan.Venkataraman@Sun.COM " [-FivVA]",
38488048SMadhavan.Venkataraman@Sun.COM "display callouts", callout, callout_help },
38498048SMadhavan.Venkataraman@Sun.COM { "calloutid", "[-d|v] xid", "print callout by extended id",
38508048SMadhavan.Venkataraman@Sun.COM calloutid, calloutid_help },
38510Sstevel@tonic-gate { "class", NULL, "print process scheduler classes", class },
38520Sstevel@tonic-gate { "cpuinfo", "?[-v]", "print CPUs and runnable threads", cpuinfo },
38530Sstevel@tonic-gate { "did2thread", "? kt_did", "find kernel thread for this id",
38540Sstevel@tonic-gate did2thread },
38550Sstevel@tonic-gate { "errorq", "?[-v]", "display kernel error queues", errorq },
38560Sstevel@tonic-gate { "fd", ":[fd num]", "get a file pointer from an fd", fd },
38570Sstevel@tonic-gate { "flipone", ":", "the vik_rev_level 2 special", flipone },
38580Sstevel@tonic-gate { "lminfo", NULL, "print lock manager information", lminfo },
38590Sstevel@tonic-gate { "ndi_event_hdl", "?", "print ndi_event_hdl", ndi_event_hdl },
38600Sstevel@tonic-gate { "panicinfo", NULL, "print panic information", panicinfo },
38610Sstevel@tonic-gate { "pid2proc", "?", "convert PID to proc_t address", pid2proc },
38620Sstevel@tonic-gate { "project", NULL, "display kernel project(s)", project },
38630Sstevel@tonic-gate { "ps", "[-fltzTP]", "list processes (and associated thr,lwp)", ps },
38641014Svb160487 { "pgrep", "[-x] [-n | -o] pattern",
38651014Svb160487 "pattern match against all processes", pgrep },
38660Sstevel@tonic-gate { "ptree", NULL, "print process tree", ptree },
38670Sstevel@tonic-gate { "sysevent", "?[-sv]", "print sysevent pending or sent queue",
38680Sstevel@tonic-gate sysevent},
38690Sstevel@tonic-gate { "sysevent_channel", "?", "print sysevent channel database",
38700Sstevel@tonic-gate sysevent_channel},
38710Sstevel@tonic-gate { "sysevent_class_list", ":", "print sysevent class list",
38720Sstevel@tonic-gate sysevent_class_list},
38730Sstevel@tonic-gate { "sysevent_subclass_list", ":",
38740Sstevel@tonic-gate "print sysevent subclass list", sysevent_subclass_list},
38750Sstevel@tonic-gate { "system", NULL, "print contents of /etc/system file", sysfile },
38760Sstevel@tonic-gate { "task", NULL, "display kernel task(s)", task },
387713077SJonathan.Adams@Sun.COM { "time", "[-dlx]", "display system time", time, time_help },
38780Sstevel@tonic-gate { "vnode2path", ":[-F]", "vnode address to pathname", vnode2path },
38790Sstevel@tonic-gate { "whereopen", ":", "given a vnode, dumps procs which have it open",
38800Sstevel@tonic-gate whereopen },
38810Sstevel@tonic-gate
38820Sstevel@tonic-gate /* from bio.c */
38830Sstevel@tonic-gate { "bufpagefind", ":addr", "find page_t on buf_t list", bufpagefind },
38840Sstevel@tonic-gate
388510696SDavid.Hollister@Sun.COM /* from bitset.c */
388610696SDavid.Hollister@Sun.COM { "bitset", ":", "display a bitset", bitset, bitset_help },
388710696SDavid.Hollister@Sun.COM
38880Sstevel@tonic-gate /* from contract.c */
38890Sstevel@tonic-gate { "contract", "?", "display a contract", cmd_contract },
38900Sstevel@tonic-gate { "ctevent", ":", "display a contract event", cmd_ctevent },
38910Sstevel@tonic-gate { "ctid", ":", "convert id to a contract pointer", cmd_ctid },
38920Sstevel@tonic-gate
38930Sstevel@tonic-gate /* from cpupart.c */
3894537Smishra { "cpupart", "?[-v]", "print cpu partition info", cpupart },
38950Sstevel@tonic-gate
38960Sstevel@tonic-gate /* from cyclic.c */
38970Sstevel@tonic-gate { "cyccover", NULL, "dump cyclic coverage information", cyccover },
38980Sstevel@tonic-gate { "cycid", "?", "dump a cyclic id", cycid },
38990Sstevel@tonic-gate { "cycinfo", "?", "dump cyc_cpu info", cycinfo },
39000Sstevel@tonic-gate { "cyclic", ":", "developer information", cyclic },
39010Sstevel@tonic-gate { "cyctrace", "?", "dump cyclic trace buffer", cyctrace },
39020Sstevel@tonic-gate
390310696SDavid.Hollister@Sun.COM /* from damap.c */
390410696SDavid.Hollister@Sun.COM { "damap", ":", "display a damap_t", damap, damap_help },
390510696SDavid.Hollister@Sun.COM
39060Sstevel@tonic-gate /* from devinfo.c */
39070Sstevel@tonic-gate { "devbindings", "?[-qs] [device-name | major-num]",
39080Sstevel@tonic-gate "print devinfo nodes bound to device-name or major-num",
39090Sstevel@tonic-gate devbindings, devinfo_help },
39100Sstevel@tonic-gate { "devinfo", ":[-qs]", "detailed devinfo of one node", devinfo,
39110Sstevel@tonic-gate devinfo_help },
39120Sstevel@tonic-gate { "devinfo_audit", ":[-v]", "devinfo configuration audit record",
39130Sstevel@tonic-gate devinfo_audit },
39140Sstevel@tonic-gate { "devinfo_audit_log", "?[-v]", "system wide devinfo configuration log",
39150Sstevel@tonic-gate devinfo_audit_log },
39160Sstevel@tonic-gate { "devinfo_audit_node", ":[-v]", "devinfo node configuration history",
39170Sstevel@tonic-gate devinfo_audit_node },
39180Sstevel@tonic-gate { "devinfo2driver", ":", "find driver name for this devinfo node",
39190Sstevel@tonic-gate devinfo2driver },
39200Sstevel@tonic-gate { "devnames", "?[-vm] [num]", "print devnames array", devnames },
39210Sstevel@tonic-gate { "dev2major", "?<dev_t>", "convert dev_t to a major number",
39220Sstevel@tonic-gate dev2major },
39230Sstevel@tonic-gate { "dev2minor", "?<dev_t>", "convert dev_t to a minor number",
39240Sstevel@tonic-gate dev2minor },
39250Sstevel@tonic-gate { "devt", "?<dev_t>", "display a dev_t's major and minor numbers",
39260Sstevel@tonic-gate devt },
39270Sstevel@tonic-gate { "major2name", "?<major-num>", "convert major number to dev name",
39280Sstevel@tonic-gate major2name },
39290Sstevel@tonic-gate { "minornodes", ":", "given a devinfo node, print its minor nodes",
39300Sstevel@tonic-gate minornodes },
39310Sstevel@tonic-gate { "modctl2devinfo", ":", "given a modctl, list its devinfos",
39320Sstevel@tonic-gate modctl2devinfo },
39330Sstevel@tonic-gate { "name2major", "<dev-name>", "convert dev name to major number",
39340Sstevel@tonic-gate name2major },
39350Sstevel@tonic-gate { "prtconf", "?[-vpc]", "print devinfo tree", prtconf, prtconf_help },
39360Sstevel@tonic-gate { "softstate", ":<instance>", "retrieve soft-state pointer",
39370Sstevel@tonic-gate softstate },
39380Sstevel@tonic-gate { "devinfo_fm", ":", "devinfo fault managment configuration",
39390Sstevel@tonic-gate devinfo_fm },
39400Sstevel@tonic-gate { "devinfo_fmce", ":", "devinfo fault managment cache entry",
39410Sstevel@tonic-gate devinfo_fmce},
39420Sstevel@tonic-gate
39430Sstevel@tonic-gate /* from findstack.c */
39440Sstevel@tonic-gate { "findstack", ":[-v]", "find kernel thread stack", findstack },
39450Sstevel@tonic-gate { "findstack_debug", NULL, "toggle findstack debugging",
39460Sstevel@tonic-gate findstack_debug },
39478742Sgap@sun.com { "stacks", "?[-afiv] [-c func] [-C func] [-m module] [-M module] "
39488742Sgap@sun.com "[-s sobj | -S sobj] [-t tstate | -T tstate]",
39498721SJonathan.Adams@Sun.COM "print unique kernel thread stacks",
39508721SJonathan.Adams@Sun.COM stacks, stacks_help },
39510Sstevel@tonic-gate
395211459SJonathan.Adams@Sun.COM /* from fm.c */
395311459SJonathan.Adams@Sun.COM { "ereport", "[-v]", "print ereports logged in dump",
395411459SJonathan.Adams@Sun.COM ereport },
395511459SJonathan.Adams@Sun.COM
395610696SDavid.Hollister@Sun.COM /* from group.c */
395710696SDavid.Hollister@Sun.COM { "group", "?[-q]", "display a group", group},
395810696SDavid.Hollister@Sun.COM
395911459SJonathan.Adams@Sun.COM /* from hotplug.c */
396011459SJonathan.Adams@Sun.COM { "hotplug", "?[-p]", "display a registered hotplug attachment",
396111459SJonathan.Adams@Sun.COM hotplug, hotplug_help },
396211459SJonathan.Adams@Sun.COM
39638561SScott.Carter@Sun.COM /* from irm.c */
39648561SScott.Carter@Sun.COM { "irmpools", NULL, "display interrupt pools", irmpools_dcmd },
39658561SScott.Carter@Sun.COM { "irmreqs", NULL, "display interrupt requests in an interrupt pool",
39668561SScott.Carter@Sun.COM irmreqs_dcmd },
39678561SScott.Carter@Sun.COM { "irmreq", NULL, "display an interrupt request", irmreq_dcmd },
39688561SScott.Carter@Sun.COM
39690Sstevel@tonic-gate /* from kgrep.c + genunix.c */
39701580Sjwadams { "kgrep", KGREP_USAGE, "search kernel as for a pointer", kgrep,
39711580Sjwadams kgrep_help },
39720Sstevel@tonic-gate
39730Sstevel@tonic-gate /* from kmem.c */
39740Sstevel@tonic-gate { "allocdby", ":", "given a thread, print its allocated buffers",
39750Sstevel@tonic-gate allocdby },
39760Sstevel@tonic-gate { "bufctl", ":[-vh] [-a addr] [-c caller] [-e earliest] [-l latest] "
39770Sstevel@tonic-gate "[-t thd]", "print or filter a bufctl", bufctl, bufctl_help },
39780Sstevel@tonic-gate { "freedby", ":", "given a thread, print its freed buffers", freedby },
39790Sstevel@tonic-gate { "kmalog", "?[ fail | slab ]",
39800Sstevel@tonic-gate "display kmem transaction log and stack traces", kmalog },
39813095Sek110237 { "kmastat", "[-kmg]", "kernel memory allocator stats",
39823095Sek110237 kmastat },
39830Sstevel@tonic-gate { "kmausers", "?[-ef] [cache ...]", "current medium and large users "
39840Sstevel@tonic-gate "of the kmem allocator", kmausers, kmausers_help },
39856712Stomee { "kmem_cache", "?[-n name]",
39866712Stomee "print kernel memory caches", kmem_cache, kmem_cache_help},
39876712Stomee { "kmem_slabs", "?[-v] [-n cache] [-N cache] [-b maxbins] "
39886712Stomee "[-B minbinsize]", "display slab usage per kmem cache",
39894688Stomee kmem_slabs, kmem_slabs_help },
39900Sstevel@tonic-gate { "kmem_debug", NULL, "toggle kmem dcmd/walk debugging", kmem_debug },
39910Sstevel@tonic-gate { "kmem_log", "?[-b]", "dump kmem transaction log", kmem_log },
39920Sstevel@tonic-gate { "kmem_verify", "?", "check integrity of kmem-managed memory",
39930Sstevel@tonic-gate kmem_verify },
39940Sstevel@tonic-gate { "vmem", "?", "print a vmem_t", vmem },
39950Sstevel@tonic-gate { "vmem_seg", ":[-sv] [-c caller] [-e earliest] [-l latest] "
39960Sstevel@tonic-gate "[-m minsize] [-M maxsize] [-t thread] [-T type]",
39970Sstevel@tonic-gate "print or filter a vmem_seg", vmem_seg, vmem_seg_help },
39980Sstevel@tonic-gate { "whatthread", ":[-v]", "print threads whose stack contains the "
39990Sstevel@tonic-gate "given address", whatthread },
40000Sstevel@tonic-gate
40010Sstevel@tonic-gate /* from ldi.c */
40020Sstevel@tonic-gate { "ldi_handle", "?[-i]", "display a layered driver handle",
40030Sstevel@tonic-gate ldi_handle, ldi_handle_help },
40040Sstevel@tonic-gate { "ldi_ident", NULL, "display a layered driver identifier",
40050Sstevel@tonic-gate ldi_ident, ldi_ident_help },
40060Sstevel@tonic-gate
40070Sstevel@tonic-gate /* from leaky.c + leaky_subr.c */
40080Sstevel@tonic-gate { "findleaks", FINDLEAKS_USAGE,
40090Sstevel@tonic-gate "search for potential kernel memory leaks", findleaks,
40100Sstevel@tonic-gate findleaks_help },
40110Sstevel@tonic-gate
40120Sstevel@tonic-gate /* from lgrp.c */
40130Sstevel@tonic-gate { "lgrp", "?[-q] [-p | -Pih]", "display an lgrp", lgrp},
40142685Sakolb { "lgrp_set", "", "display bitmask of lgroups as a list", lgrp_set},
40150Sstevel@tonic-gate
40160Sstevel@tonic-gate /* from log.c */
40170Sstevel@tonic-gate { "msgbuf", "?[-v]", "print most recent console messages", msgbuf },
40180Sstevel@tonic-gate
401910696SDavid.Hollister@Sun.COM /* from mdi.c */
402010696SDavid.Hollister@Sun.COM { "mdipi", NULL, "given a path, dump mdi_pathinfo "
402110696SDavid.Hollister@Sun.COM "and detailed pi_prop list", mdipi },
402210696SDavid.Hollister@Sun.COM { "mdiprops", NULL, "given a pi_prop, dump the pi_prop list",
402310696SDavid.Hollister@Sun.COM mdiprops },
402410696SDavid.Hollister@Sun.COM { "mdiphci", NULL, "given a phci, dump mdi_phci and "
402510696SDavid.Hollister@Sun.COM "list all paths", mdiphci },
402610696SDavid.Hollister@Sun.COM { "mdivhci", NULL, "given a vhci, dump mdi_vhci and list "
402710696SDavid.Hollister@Sun.COM "all phcis", mdivhci },
402810696SDavid.Hollister@Sun.COM { "mdiclient_paths", NULL, "given a path, walk mdi_pathinfo "
402910696SDavid.Hollister@Sun.COM "client links", mdiclient_paths },
403010696SDavid.Hollister@Sun.COM { "mdiphci_paths", NULL, "given a path, walk through mdi_pathinfo "
403110696SDavid.Hollister@Sun.COM "phci links", mdiphci_paths },
403210696SDavid.Hollister@Sun.COM { "mdiphcis", NULL, "given a phci, walk through mdi_phci ph_next links",
403310696SDavid.Hollister@Sun.COM mdiphcis },
403410696SDavid.Hollister@Sun.COM
40350Sstevel@tonic-gate /* from memory.c */
403611459SJonathan.Adams@Sun.COM { "addr2smap", ":[offset]", "translate address to smap", addr2smap },
403711459SJonathan.Adams@Sun.COM { "memlist", "?[-iav]", "display a struct memlist", memlist },
40380Sstevel@tonic-gate { "memstat", NULL, "display memory usage summary", memstat },
403911459SJonathan.Adams@Sun.COM { "page", "?", "display a summarized page_t", page },
404011459SJonathan.Adams@Sun.COM { "pagelookup", "?[-v vp] [-o offset]",
404111459SJonathan.Adams@Sun.COM "find the page_t with the name {vp, offset}",
404211459SJonathan.Adams@Sun.COM pagelookup, pagelookup_help },
404311459SJonathan.Adams@Sun.COM { "page_num2pp", ":", "find the page_t for a given page frame number",
404411459SJonathan.Adams@Sun.COM page_num2pp },
404511459SJonathan.Adams@Sun.COM { "pmap", ":[-q]", "print process memory map", pmap },
404611459SJonathan.Adams@Sun.COM { "seg", ":", "print address space segment", seg },
40470Sstevel@tonic-gate { "swapinfo", "?", "display a struct swapinfo", swapinfof },
404811459SJonathan.Adams@Sun.COM { "vnode2smap", ":[offset]", "translate vnode to smap", vnode2smap },
40490Sstevel@tonic-gate
40500Sstevel@tonic-gate /* from mmd.c */
40510Sstevel@tonic-gate { "multidata", ":[-sv]", "display a summarized multidata_t",
40520Sstevel@tonic-gate multidata },
40530Sstevel@tonic-gate { "pattbl", ":", "display a summarized multidata attribute table",
40540Sstevel@tonic-gate pattbl },
40550Sstevel@tonic-gate { "pattr2multidata", ":", "print multidata pointer from pattr_t",
40560Sstevel@tonic-gate pattr2multidata },
40570Sstevel@tonic-gate { "pdesc2slab", ":", "print pdesc slab pointer from pdesc_t",
40580Sstevel@tonic-gate pdesc2slab },
40590Sstevel@tonic-gate { "pdesc_verify", ":", "verify integrity of a pdesc_t", pdesc_verify },
40600Sstevel@tonic-gate { "slab2multidata", ":", "print multidata pointer from pdesc_slab_t",
40610Sstevel@tonic-gate slab2multidata },
40620Sstevel@tonic-gate
40630Sstevel@tonic-gate /* from modhash.c */
40640Sstevel@tonic-gate { "modhash", "?[-ceht] [-k key] [-v val] [-i index]",
40650Sstevel@tonic-gate "display information about one or all mod_hash structures",
40660Sstevel@tonic-gate modhash, modhash_help },
40670Sstevel@tonic-gate { "modent", ":[-k | -v | -t type]",
40680Sstevel@tonic-gate "display information about a mod_hash_entry", modent,
40690Sstevel@tonic-gate modent_help },
40700Sstevel@tonic-gate
40710Sstevel@tonic-gate /* from net.c */
407210491SRishi.Srivatsavai@Sun.COM { "dladm", "?<sub-command> [flags]", "show data link information",
407310491SRishi.Srivatsavai@Sun.COM dladm, dladm_help },
40740Sstevel@tonic-gate { "mi", ":[-p] [-d | -m]", "filter and display MI object or payload",
40750Sstevel@tonic-gate mi },
40769089SVasumathi.Sundaram@Sun.COM { "netstat", "[-arv] [-f inet | inet6 | unix] [-P tcp | udp | icmp]",
40770Sstevel@tonic-gate "show network statistics", netstat },
40780Sstevel@tonic-gate { "sonode", "?[-f inet | inet6 | unix | #] "
40790Sstevel@tonic-gate "[-t stream | dgram | raw | #] [-p #]",
40800Sstevel@tonic-gate "filter and display sonode", sonode },
40810Sstevel@tonic-gate
40823448Sdh155122 /* from netstack.c */
40833448Sdh155122 { "netstack", "", "show stack instances", netstack },
40843448Sdh155122
40850Sstevel@tonic-gate /* from nvpair.c */
40860Sstevel@tonic-gate { NVPAIR_DCMD_NAME, NVPAIR_DCMD_USAGE, NVPAIR_DCMD_DESCR,
40870Sstevel@tonic-gate nvpair_print },
4088789Sahrens { NVLIST_DCMD_NAME, NVLIST_DCMD_USAGE, NVLIST_DCMD_DESCR,
40892869Sgavinm print_nvlist },
40900Sstevel@tonic-gate
40913434Sesaxe /* from pg.c */
40923434Sesaxe { "pg", "?[-q]", "display a pg", pg},
409310696SDavid.Hollister@Sun.COM
40940Sstevel@tonic-gate /* from rctl.c */
40950Sstevel@tonic-gate { "rctl_dict", "?", "print systemwide default rctl definitions",
40960Sstevel@tonic-gate rctl_dict },
40970Sstevel@tonic-gate { "rctl_list", ":[handle]", "print rctls for the given proc",
40980Sstevel@tonic-gate rctl_list },
40990Sstevel@tonic-gate { "rctl", ":[handle]", "print a rctl_t, only if it matches the handle",
41000Sstevel@tonic-gate rctl },
41010Sstevel@tonic-gate { "rctl_validate", ":[-v] [-n #]", "test resource control value "
41020Sstevel@tonic-gate "sequence", rctl_validate },
41030Sstevel@tonic-gate
41040Sstevel@tonic-gate /* from sobj.c */
41050Sstevel@tonic-gate { "rwlock", ":", "dump out a readers/writer lock", rwlock },
41060Sstevel@tonic-gate { "mutex", ":[-f]", "dump out an adaptive or spin mutex", mutex,
41070Sstevel@tonic-gate mutex_help },
41080Sstevel@tonic-gate { "sobj2ts", ":", "perform turnstile lookup on synch object", sobj2ts },
41090Sstevel@tonic-gate { "wchaninfo", "?[-v]", "dump condition variable", wchaninfo },
41100Sstevel@tonic-gate { "turnstile", "?", "display a turnstile", turnstile },
41110Sstevel@tonic-gate
41120Sstevel@tonic-gate /* from stream.c */
41130Sstevel@tonic-gate { "mblk", ":[-q|v] [-f|F flag] [-t|T type] [-l|L|B len] [-d dbaddr]",
41140Sstevel@tonic-gate "print an mblk", mblk_prt, mblk_help },
41150Sstevel@tonic-gate { "mblk_verify", "?", "verify integrity of an mblk", mblk_verify },
41160Sstevel@tonic-gate { "mblk2dblk", ":", "convert mblk_t address to dblk_t address",
41170Sstevel@tonic-gate mblk2dblk },
41180Sstevel@tonic-gate { "q2otherq", ":", "print peer queue for a given queue", q2otherq },
41190Sstevel@tonic-gate { "q2rdq", ":", "print read queue for a given queue", q2rdq },
41200Sstevel@tonic-gate { "q2syncq", ":", "print syncq for a given queue", q2syncq },
41210Sstevel@tonic-gate { "q2stream", ":", "print stream pointer for a given queue", q2stream },
41220Sstevel@tonic-gate { "q2wrq", ":", "print write queue for a given queue", q2wrq },
41230Sstevel@tonic-gate { "queue", ":[-q|v] [-m mod] [-f flag] [-F flag] [-s syncq_addr]",
41240Sstevel@tonic-gate "filter and display STREAM queue", queue, queue_help },
41250Sstevel@tonic-gate { "stdata", ":[-q|v] [-f flag] [-F flag]",
41260Sstevel@tonic-gate "filter and display STREAM head", stdata, stdata_help },
41270Sstevel@tonic-gate { "str2mate", ":", "print mate of this stream", str2mate },
41280Sstevel@tonic-gate { "str2wrq", ":", "print write queue of this stream", str2wrq },
41290Sstevel@tonic-gate { "stream", ":", "display STREAM", stream },
41300Sstevel@tonic-gate { "strftevent", ":", "print STREAMS flow trace event", strftevent },
41310Sstevel@tonic-gate { "syncq", ":[-q|v] [-f flag] [-F flag] [-t type] [-T type]",
41320Sstevel@tonic-gate "filter and display STREAM sync queue", syncq, syncq_help },
41330Sstevel@tonic-gate { "syncq2q", ":", "print queue for a given syncq", syncq2q },
41340Sstevel@tonic-gate
413510889SJonathan.Adams@Sun.COM /* from taskq.c */
413610889SJonathan.Adams@Sun.COM { "taskq", ":[-atT] [-m min_maxq] [-n name]",
413710889SJonathan.Adams@Sun.COM "display a taskq", taskq, taskq_help },
413810889SJonathan.Adams@Sun.COM { "taskq_entry", ":", "display a taskq_ent_t", taskq_ent },
413910889SJonathan.Adams@Sun.COM
41400Sstevel@tonic-gate /* from thread.c */
41410Sstevel@tonic-gate { "thread", "?[-bdfimps]", "display a summarized kthread_t", thread,
41420Sstevel@tonic-gate thread_help },
41435316Sjohnlev { "threadlist", "?[-t] [-v [count]]",
41440Sstevel@tonic-gate "display threads and associated C stack traces", threadlist,
41450Sstevel@tonic-gate threadlist_help },
41467854SPhilippe.Jung@Sun.COM { "stackinfo", "?[-h|-a]", "display kthread_t stack usage", stackinfo,
41477854SPhilippe.Jung@Sun.COM stackinfo_help },
41480Sstevel@tonic-gate
41490Sstevel@tonic-gate /* from tsd.c */
41500Sstevel@tonic-gate { "tsd", ":-k key", "print tsd[key-1] for this thread", ttotsd },
41510Sstevel@tonic-gate { "tsdtot", ":", "find thread with this tsd", tsdtot },
41520Sstevel@tonic-gate
41530Sstevel@tonic-gate /*
41540Sstevel@tonic-gate * typegraph does not work under kmdb, as it requires too much memory
41550Sstevel@tonic-gate * for its internal data structures.
41560Sstevel@tonic-gate */
41570Sstevel@tonic-gate #ifndef _KMDB
41580Sstevel@tonic-gate /* from typegraph.c */
41590Sstevel@tonic-gate { "findlocks", ":", "find locks held by specified thread", findlocks },
41600Sstevel@tonic-gate { "findfalse", "?[-v]", "find potentially falsely shared structures",
41610Sstevel@tonic-gate findfalse },
41620Sstevel@tonic-gate { "typegraph", NULL, "build type graph", typegraph },
41630Sstevel@tonic-gate { "istype", ":type", "manually set object type", istype },
41640Sstevel@tonic-gate { "notype", ":", "manually clear object type", notype },
41650Sstevel@tonic-gate { "whattype", ":", "determine object type", whattype },
41660Sstevel@tonic-gate #endif
41670Sstevel@tonic-gate
41680Sstevel@tonic-gate /* from vfs.c */
41690Sstevel@tonic-gate { "fsinfo", "?[-v]", "print mounted filesystems", fsinfo },
41700Sstevel@tonic-gate { "pfiles", ":[-fp]", "print process file information", pfiles,
41710Sstevel@tonic-gate pfiles_help },
41720Sstevel@tonic-gate
417310696SDavid.Hollister@Sun.COM /* from zone.c */
4174*13096SJordan.Vaughan@Sun.com { "zone", "?[-r [-v]]", "display kernel zone(s)", zoneprt },
417510696SDavid.Hollister@Sun.COM { "zsd", ":[-v] [zsd_key]", "display zone-specific-data entries for "
417610696SDavid.Hollister@Sun.COM "selected zones", zsd },
41772577Sramat
41780Sstevel@tonic-gate { NULL }
41790Sstevel@tonic-gate };
41800Sstevel@tonic-gate
41810Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
41820Sstevel@tonic-gate
41830Sstevel@tonic-gate /* from genunix.c */
41848048SMadhavan.Venkataraman@Sun.COM { "callouts_bytime", "walk callouts by list chain (expiration time)",
41858048SMadhavan.Venkataraman@Sun.COM callout_walk_init, callout_walk_step, callout_walk_fini,
41868048SMadhavan.Venkataraman@Sun.COM (void *)CALLOUT_WALK_BYLIST },
41878048SMadhavan.Venkataraman@Sun.COM { "callouts_byid", "walk callouts by id hash chain",
41888048SMadhavan.Venkataraman@Sun.COM callout_walk_init, callout_walk_step, callout_walk_fini,
41898048SMadhavan.Venkataraman@Sun.COM (void *)CALLOUT_WALK_BYID },
41908048SMadhavan.Venkataraman@Sun.COM { "callout_list", "walk a callout list", callout_list_walk_init,
41918048SMadhavan.Venkataraman@Sun.COM callout_list_walk_step, callout_list_walk_fini },
41928048SMadhavan.Venkataraman@Sun.COM { "callout_table", "walk callout table array", callout_table_walk_init,
41938048SMadhavan.Venkataraman@Sun.COM callout_table_walk_step, callout_table_walk_fini },
41940Sstevel@tonic-gate { "cpu", "walk cpu structures", cpu_walk_init, cpu_walk_step },
41953323Scindi { "ereportq_dump", "walk list of ereports in dump error queue",
41963323Scindi ereportq_dump_walk_init, ereportq_dump_walk_step, NULL },
41973323Scindi { "ereportq_pend", "walk list of ereports in pending error queue",
41983323Scindi ereportq_pend_walk_init, ereportq_pend_walk_step, NULL },
41990Sstevel@tonic-gate { "errorq", "walk list of system error queues",
42000Sstevel@tonic-gate errorq_walk_init, errorq_walk_step, NULL },
42010Sstevel@tonic-gate { "errorq_data", "walk pending error queue data buffers",
42020Sstevel@tonic-gate eqd_walk_init, eqd_walk_step, eqd_walk_fini },
42030Sstevel@tonic-gate { "allfile", "given a proc pointer, list all file pointers",
42040Sstevel@tonic-gate file_walk_init, allfile_walk_step, file_walk_fini },
42050Sstevel@tonic-gate { "file", "given a proc pointer, list of open file pointers",
42060Sstevel@tonic-gate file_walk_init, file_walk_step, file_walk_fini },
42070Sstevel@tonic-gate { "lock_descriptor", "walk lock_descriptor_t structures",
42080Sstevel@tonic-gate ld_walk_init, ld_walk_step, NULL },
42090Sstevel@tonic-gate { "lock_graph", "walk lock graph",
42100Sstevel@tonic-gate lg_walk_init, lg_walk_step, NULL },
42110Sstevel@tonic-gate { "port", "given a proc pointer, list of created event ports",
42120Sstevel@tonic-gate port_walk_init, port_walk_step, NULL },
42130Sstevel@tonic-gate { "portev", "given a port pointer, list of events in the queue",
42140Sstevel@tonic-gate portev_walk_init, portev_walk_step, portev_walk_fini },
42150Sstevel@tonic-gate { "proc", "list of active proc_t structures",
42160Sstevel@tonic-gate proc_walk_init, proc_walk_step, proc_walk_fini },
42170Sstevel@tonic-gate { "projects", "walk a list of kernel projects",
42180Sstevel@tonic-gate project_walk_init, project_walk_step, NULL },
42190Sstevel@tonic-gate { "sysevent_pend", "walk sysevent pending queue",
42200Sstevel@tonic-gate sysevent_pend_walk_init, sysevent_walk_step,
42210Sstevel@tonic-gate sysevent_walk_fini},
42220Sstevel@tonic-gate { "sysevent_sent", "walk sysevent sent queue", sysevent_sent_walk_init,
42230Sstevel@tonic-gate sysevent_walk_step, sysevent_walk_fini},
42240Sstevel@tonic-gate { "sysevent_channel", "walk sysevent channel subscriptions",
42250Sstevel@tonic-gate sysevent_channel_walk_init, sysevent_channel_walk_step,
42260Sstevel@tonic-gate sysevent_channel_walk_fini},
42270Sstevel@tonic-gate { "sysevent_class_list", "walk sysevent subscription's class list",
42280Sstevel@tonic-gate sysevent_class_list_walk_init, sysevent_class_list_walk_step,
42290Sstevel@tonic-gate sysevent_class_list_walk_fini},
42300Sstevel@tonic-gate { "sysevent_subclass_list",
42310Sstevel@tonic-gate "walk sysevent subscription's subclass list",
42320Sstevel@tonic-gate sysevent_subclass_list_walk_init,
42330Sstevel@tonic-gate sysevent_subclass_list_walk_step,
42340Sstevel@tonic-gate sysevent_subclass_list_walk_fini},
42350Sstevel@tonic-gate { "task", "given a task pointer, walk its processes",
42360Sstevel@tonic-gate task_walk_init, task_walk_step, NULL },
42370Sstevel@tonic-gate
4238789Sahrens /* from avl.c */
4239789Sahrens { AVL_WALK_NAME, AVL_WALK_DESC,
4240789Sahrens avl_walk_init, avl_walk_step, avl_walk_fini },
4241789Sahrens
42420Sstevel@tonic-gate /* from bio.c */
42430Sstevel@tonic-gate { "buf", "walk the bio buf hash",
42440Sstevel@tonic-gate buf_walk_init, buf_walk_step, buf_walk_fini },
42450Sstevel@tonic-gate
42460Sstevel@tonic-gate /* from contract.c */
42470Sstevel@tonic-gate { "contract", "walk all contracts, or those of the specified type",
42480Sstevel@tonic-gate ct_walk_init, generic_walk_step, NULL },
42490Sstevel@tonic-gate { "ct_event", "walk events on a contract event queue",
42500Sstevel@tonic-gate ct_event_walk_init, generic_walk_step, NULL },
42510Sstevel@tonic-gate { "ct_listener", "walk contract event queue listeners",
42520Sstevel@tonic-gate ct_listener_walk_init, generic_walk_step, NULL },
42530Sstevel@tonic-gate
42540Sstevel@tonic-gate /* from cpupart.c */
42550Sstevel@tonic-gate { "cpupart_cpulist", "given an cpupart_t, walk cpus in partition",
42560Sstevel@tonic-gate cpupart_cpulist_walk_init, cpupart_cpulist_walk_step,
42570Sstevel@tonic-gate NULL },
42580Sstevel@tonic-gate { "cpupart_walk", "walk the set of cpu partitions",
42590Sstevel@tonic-gate cpupart_walk_init, cpupart_walk_step, NULL },
42600Sstevel@tonic-gate
42610Sstevel@tonic-gate /* from ctxop.c */
42620Sstevel@tonic-gate { "ctxop", "walk list of context ops on a thread",
42630Sstevel@tonic-gate ctxop_walk_init, ctxop_walk_step, ctxop_walk_fini },
42640Sstevel@tonic-gate
42650Sstevel@tonic-gate /* from cyclic.c */
42660Sstevel@tonic-gate { "cyccpu", "walk per-CPU cyc_cpu structures",
42670Sstevel@tonic-gate cyccpu_walk_init, cyccpu_walk_step, NULL },
42680Sstevel@tonic-gate { "cycomni", "for an omnipresent cyclic, walk cyc_omni_cpu list",
42690Sstevel@tonic-gate cycomni_walk_init, cycomni_walk_step, NULL },
42700Sstevel@tonic-gate { "cyctrace", "walk cyclic trace buffer",
42710Sstevel@tonic-gate cyctrace_walk_init, cyctrace_walk_step, cyctrace_walk_fini },
42720Sstevel@tonic-gate
42730Sstevel@tonic-gate /* from devinfo.c */
42740Sstevel@tonic-gate { "binding_hash", "walk all entries in binding hash table",
42750Sstevel@tonic-gate binding_hash_walk_init, binding_hash_walk_step, NULL },
42760Sstevel@tonic-gate { "devinfo", "walk devinfo tree or subtree",
42770Sstevel@tonic-gate devinfo_walk_init, devinfo_walk_step, devinfo_walk_fini },
42780Sstevel@tonic-gate { "devinfo_audit_log", "walk devinfo audit system-wide log",
42790Sstevel@tonic-gate devinfo_audit_log_walk_init, devinfo_audit_log_walk_step,
42800Sstevel@tonic-gate devinfo_audit_log_walk_fini},
42810Sstevel@tonic-gate { "devinfo_audit_node", "walk per-devinfo audit history",
42820Sstevel@tonic-gate devinfo_audit_node_walk_init, devinfo_audit_node_walk_step,
42830Sstevel@tonic-gate devinfo_audit_node_walk_fini},
42840Sstevel@tonic-gate { "devinfo_children", "walk children of devinfo node",
42850Sstevel@tonic-gate devinfo_children_walk_init, devinfo_children_walk_step,
42860Sstevel@tonic-gate devinfo_children_walk_fini },
42870Sstevel@tonic-gate { "devinfo_parents", "walk ancestors of devinfo node",
42880Sstevel@tonic-gate devinfo_parents_walk_init, devinfo_parents_walk_step,
42890Sstevel@tonic-gate devinfo_parents_walk_fini },
42900Sstevel@tonic-gate { "devinfo_siblings", "walk siblings of devinfo node",
42910Sstevel@tonic-gate devinfo_siblings_walk_init, devinfo_siblings_walk_step, NULL },
42920Sstevel@tonic-gate { "devi_next", "walk devinfo list",
42930Sstevel@tonic-gate NULL, devi_next_walk_step, NULL },
42940Sstevel@tonic-gate { "devnames", "walk devnames array",
42950Sstevel@tonic-gate devnames_walk_init, devnames_walk_step, devnames_walk_fini },
42960Sstevel@tonic-gate { "minornode", "given a devinfo node, walk minor nodes",
42970Sstevel@tonic-gate minornode_walk_init, minornode_walk_step, NULL },
42980Sstevel@tonic-gate { "softstate",
42990Sstevel@tonic-gate "given an i_ddi_soft_state*, list all in-use driver stateps",
43000Sstevel@tonic-gate soft_state_walk_init, soft_state_walk_step,
43010Sstevel@tonic-gate NULL, NULL },
43020Sstevel@tonic-gate { "softstate_all",
43030Sstevel@tonic-gate "given an i_ddi_soft_state*, list all driver stateps",
43040Sstevel@tonic-gate soft_state_walk_init, soft_state_all_walk_step,
43050Sstevel@tonic-gate NULL, NULL },
43060Sstevel@tonic-gate { "devinfo_fmc",
43070Sstevel@tonic-gate "walk a fault management handle cache active list",
43080Sstevel@tonic-gate devinfo_fmc_walk_init, devinfo_fmc_walk_step, NULL },
43090Sstevel@tonic-gate
431010696SDavid.Hollister@Sun.COM /* from group.c */
431110696SDavid.Hollister@Sun.COM { "group", "walk all elements of a group",
431210696SDavid.Hollister@Sun.COM group_walk_init, group_walk_step, NULL },
431310696SDavid.Hollister@Sun.COM
43148561SScott.Carter@Sun.COM /* from irm.c */
43158561SScott.Carter@Sun.COM { "irmpools", "walk global list of interrupt pools",
43168561SScott.Carter@Sun.COM irmpools_walk_init, list_walk_step, list_walk_fini },
43178561SScott.Carter@Sun.COM { "irmreqs", "walk list of interrupt requests in an interrupt pool",
43188561SScott.Carter@Sun.COM irmreqs_walk_init, list_walk_step, list_walk_fini },
43198561SScott.Carter@Sun.COM
43200Sstevel@tonic-gate /* from kmem.c */
43210Sstevel@tonic-gate { "allocdby", "given a thread, walk its allocated bufctls",
43220Sstevel@tonic-gate allocdby_walk_init, allocdby_walk_step, allocdby_walk_fini },
43230Sstevel@tonic-gate { "bufctl", "walk a kmem cache's bufctls",
43240Sstevel@tonic-gate bufctl_walk_init, kmem_walk_step, kmem_walk_fini },
43250Sstevel@tonic-gate { "bufctl_history", "walk the available history of a bufctl",
43260Sstevel@tonic-gate bufctl_history_walk_init, bufctl_history_walk_step,
43270Sstevel@tonic-gate bufctl_history_walk_fini },
43280Sstevel@tonic-gate { "freedby", "given a thread, walk its freed bufctls",
43290Sstevel@tonic-gate freedby_walk_init, allocdby_walk_step, allocdby_walk_fini },
43300Sstevel@tonic-gate { "freectl", "walk a kmem cache's free bufctls",
43310Sstevel@tonic-gate freectl_walk_init, kmem_walk_step, kmem_walk_fini },
43320Sstevel@tonic-gate { "freectl_constructed", "walk a kmem cache's constructed free bufctls",
43330Sstevel@tonic-gate freectl_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
43340Sstevel@tonic-gate { "freemem", "walk a kmem cache's free memory",
43350Sstevel@tonic-gate freemem_walk_init, kmem_walk_step, kmem_walk_fini },
43360Sstevel@tonic-gate { "freemem_constructed", "walk a kmem cache's constructed free memory",
43370Sstevel@tonic-gate freemem_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
43380Sstevel@tonic-gate { "kmem", "walk a kmem cache",
43390Sstevel@tonic-gate kmem_walk_init, kmem_walk_step, kmem_walk_fini },
43400Sstevel@tonic-gate { "kmem_cpu_cache", "given a kmem cache, walk its per-CPU caches",
43410Sstevel@tonic-gate kmem_cpu_cache_walk_init, kmem_cpu_cache_walk_step, NULL },
43420Sstevel@tonic-gate { "kmem_hash", "given a kmem cache, walk its allocated hash table",
43430Sstevel@tonic-gate kmem_hash_walk_init, kmem_hash_walk_step, kmem_hash_walk_fini },
43440Sstevel@tonic-gate { "kmem_log", "walk the kmem transaction log",
43450Sstevel@tonic-gate kmem_log_walk_init, kmem_log_walk_step, kmem_log_walk_fini },
43460Sstevel@tonic-gate { "kmem_slab", "given a kmem cache, walk its slabs",
43476712Stomee kmem_slab_walk_init, combined_walk_step, combined_walk_fini },
43480Sstevel@tonic-gate { "kmem_slab_partial",
43490Sstevel@tonic-gate "given a kmem cache, walk its partially allocated slabs (min 1)",
43506712Stomee kmem_slab_walk_partial_init, combined_walk_step,
43516712Stomee combined_walk_fini },
43520Sstevel@tonic-gate { "vmem", "walk vmem structures in pre-fix, depth-first order",
43530Sstevel@tonic-gate vmem_walk_init, vmem_walk_step, vmem_walk_fini },
43540Sstevel@tonic-gate { "vmem_alloc", "given a vmem_t, walk its allocated vmem_segs",
43550Sstevel@tonic-gate vmem_alloc_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
43560Sstevel@tonic-gate { "vmem_free", "given a vmem_t, walk its free vmem_segs",
43570Sstevel@tonic-gate vmem_free_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
43580Sstevel@tonic-gate { "vmem_postfix", "walk vmem structures in post-fix, depth-first order",
43590Sstevel@tonic-gate vmem_walk_init, vmem_postfix_walk_step, vmem_walk_fini },
43600Sstevel@tonic-gate { "vmem_seg", "given a vmem_t, walk all of its vmem_segs",
43610Sstevel@tonic-gate vmem_seg_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
43620Sstevel@tonic-gate { "vmem_span", "given a vmem_t, walk its spanning vmem_segs",
43630Sstevel@tonic-gate vmem_span_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
43640Sstevel@tonic-gate
43650Sstevel@tonic-gate /* from ldi.c */
43660Sstevel@tonic-gate { "ldi_handle", "walk the layered driver handle hash",
43670Sstevel@tonic-gate ldi_handle_walk_init, ldi_handle_walk_step, NULL },
43680Sstevel@tonic-gate { "ldi_ident", "walk the layered driver identifier hash",
43690Sstevel@tonic-gate ldi_ident_walk_init, ldi_ident_walk_step, NULL },
43700Sstevel@tonic-gate
43710Sstevel@tonic-gate /* from leaky.c + leaky_subr.c */
43720Sstevel@tonic-gate { "leak", "given a leaked bufctl or vmem_seg, find leaks w/ same "
43730Sstevel@tonic-gate "stack trace",
43740Sstevel@tonic-gate leaky_walk_init, leaky_walk_step, leaky_walk_fini },
43750Sstevel@tonic-gate { "leakbuf", "given a leaked bufctl or vmem_seg, walk buffers for "
43760Sstevel@tonic-gate "leaks w/ same stack trace",
43770Sstevel@tonic-gate leaky_walk_init, leaky_buf_walk_step, leaky_walk_fini },
43780Sstevel@tonic-gate
43790Sstevel@tonic-gate /* from lgrp.c */
43802685Sakolb { "lgrp_cpulist", "walk CPUs in a given lgroup",
43812685Sakolb lgrp_cpulist_walk_init, lgrp_cpulist_walk_step, NULL },
43822685Sakolb { "lgrptbl", "walk lgroup table",
43830Sstevel@tonic-gate lgrp_walk_init, lgrp_walk_step, NULL },
43842685Sakolb { "lgrp_parents", "walk up lgroup lineage from given lgroup",
43852685Sakolb lgrp_parents_walk_init, lgrp_parents_walk_step, NULL },
43862685Sakolb { "lgrp_rsrc_mem", "walk lgroup memory resources of given lgroup",
43872685Sakolb lgrp_rsrc_mem_walk_init, lgrp_set_walk_step, NULL },
43882685Sakolb { "lgrp_rsrc_cpu", "walk lgroup CPU resources of given lgroup",
43892685Sakolb lgrp_rsrc_cpu_walk_init, lgrp_set_walk_step, NULL },
43900Sstevel@tonic-gate
43910Sstevel@tonic-gate /* from list.c */
4392789Sahrens { LIST_WALK_NAME, LIST_WALK_DESC,
43930Sstevel@tonic-gate list_walk_init, list_walk_step, list_walk_fini },
43940Sstevel@tonic-gate
439510696SDavid.Hollister@Sun.COM /* from mdi.c */
439610696SDavid.Hollister@Sun.COM { "mdipi_client_list", "Walker for mdi_pathinfo pi_client_link",
439710696SDavid.Hollister@Sun.COM mdi_pi_client_link_walk_init,
439810696SDavid.Hollister@Sun.COM mdi_pi_client_link_walk_step,
439910696SDavid.Hollister@Sun.COM mdi_pi_client_link_walk_fini },
440010696SDavid.Hollister@Sun.COM { "mdipi_phci_list", "Walker for mdi_pathinfo pi_phci_link",
440110696SDavid.Hollister@Sun.COM mdi_pi_phci_link_walk_init,
440210696SDavid.Hollister@Sun.COM mdi_pi_phci_link_walk_step,
440310696SDavid.Hollister@Sun.COM mdi_pi_phci_link_walk_fini },
440410696SDavid.Hollister@Sun.COM { "mdiphci_list", "Walker for mdi_phci ph_next link",
440510696SDavid.Hollister@Sun.COM mdi_phci_ph_next_walk_init,
440610696SDavid.Hollister@Sun.COM mdi_phci_ph_next_walk_step,
440710696SDavid.Hollister@Sun.COM mdi_phci_ph_next_walk_fini },
440810696SDavid.Hollister@Sun.COM
44090Sstevel@tonic-gate /* from memory.c */
441011459SJonathan.Adams@Sun.COM { "allpages", "walk all pages, including free pages",
441111459SJonathan.Adams@Sun.COM allpages_walk_init, allpages_walk_step, allpages_walk_fini },
441213078SJonathan.Adams@Sun.COM { "anon", "given an amp, list allocated anon structures",
441313078SJonathan.Adams@Sun.COM anon_walk_init, anon_walk_step, anon_walk_fini,
441413078SJonathan.Adams@Sun.COM ANON_WALK_ALLOC },
441513078SJonathan.Adams@Sun.COM { "anon_all", "given an amp, list contents of all anon slots",
441613078SJonathan.Adams@Sun.COM anon_walk_init, anon_walk_step, anon_walk_fini,
441713078SJonathan.Adams@Sun.COM ANON_WALK_ALL },
441811459SJonathan.Adams@Sun.COM { "memlist", "walk specified memlist",
441911459SJonathan.Adams@Sun.COM NULL, memlist_walk_step, NULL },
44200Sstevel@tonic-gate { "page", "walk all pages, or those from the specified vnode",
44210Sstevel@tonic-gate page_walk_init, page_walk_step, page_walk_fini },
442211459SJonathan.Adams@Sun.COM { "seg", "given an as, list of segments",
442311459SJonathan.Adams@Sun.COM seg_walk_init, avl_walk_step, avl_walk_fini },
442413078SJonathan.Adams@Sun.COM { "segvn_anon",
442513078SJonathan.Adams@Sun.COM "given a struct segvn_data, list allocated anon structures",
442613078SJonathan.Adams@Sun.COM segvn_anon_walk_init, anon_walk_step, anon_walk_fini,
442713078SJonathan.Adams@Sun.COM ANON_WALK_ALLOC },
442813078SJonathan.Adams@Sun.COM { "segvn_anon_all",
442913078SJonathan.Adams@Sun.COM "given a struct segvn_data, list contents of all anon slots",
443013078SJonathan.Adams@Sun.COM segvn_anon_walk_init, anon_walk_step, anon_walk_fini,
443113078SJonathan.Adams@Sun.COM ANON_WALK_ALL },
443213078SJonathan.Adams@Sun.COM { "segvn_pages",
443313078SJonathan.Adams@Sun.COM "given a struct segvn_data, list resident pages in "
443413078SJonathan.Adams@Sun.COM "offset order",
443513078SJonathan.Adams@Sun.COM segvn_pages_walk_init, segvn_pages_walk_step,
443613078SJonathan.Adams@Sun.COM segvn_pages_walk_fini, SEGVN_PAGES_RESIDENT },
443713078SJonathan.Adams@Sun.COM { "segvn_pages_all",
443813078SJonathan.Adams@Sun.COM "for each offset in a struct segvn_data, give page_t pointer "
443913078SJonathan.Adams@Sun.COM "(if resident), or NULL.",
444013078SJonathan.Adams@Sun.COM segvn_pages_walk_init, segvn_pages_walk_step,
444113078SJonathan.Adams@Sun.COM segvn_pages_walk_fini, SEGVN_PAGES_ALL },
44420Sstevel@tonic-gate { "swapinfo", "walk swapinfo structures",
44430Sstevel@tonic-gate swap_walk_init, swap_walk_step, NULL },
44440Sstevel@tonic-gate
44450Sstevel@tonic-gate /* from mmd.c */
44460Sstevel@tonic-gate { "pattr", "walk pattr_t structures", pattr_walk_init,
44470Sstevel@tonic-gate mmdq_walk_step, mmdq_walk_fini },
44480Sstevel@tonic-gate { "pdesc", "walk pdesc_t structures",
44490Sstevel@tonic-gate pdesc_walk_init, mmdq_walk_step, mmdq_walk_fini },
44500Sstevel@tonic-gate { "pdesc_slab", "walk pdesc_slab_t structures",
44510Sstevel@tonic-gate pdesc_slab_walk_init, mmdq_walk_step, mmdq_walk_fini },
44520Sstevel@tonic-gate
44530Sstevel@tonic-gate /* from modhash.c */
44540Sstevel@tonic-gate { "modhash", "walk list of mod_hash structures", modhash_walk_init,
44550Sstevel@tonic-gate modhash_walk_step, NULL },
44560Sstevel@tonic-gate { "modent", "walk list of entries in a given mod_hash",
44570Sstevel@tonic-gate modent_walk_init, modent_walk_step, modent_walk_fini },
44580Sstevel@tonic-gate { "modchain", "walk list of entries in a given mod_hash_entry",
44590Sstevel@tonic-gate NULL, modchain_walk_step, NULL },
44600Sstevel@tonic-gate
44610Sstevel@tonic-gate /* from net.c */
44623448Sdh155122 { "icmp", "walk ICMP control structures using MI for all stacks",
44633448Sdh155122 mi_payload_walk_init, mi_payload_walk_step, NULL,
44643448Sdh155122 &mi_icmp_arg },
44650Sstevel@tonic-gate { "mi", "given a MI_O, walk the MI",
44660Sstevel@tonic-gate mi_walk_init, mi_walk_step, mi_walk_fini, NULL },
44670Sstevel@tonic-gate { "sonode", "given a sonode, walk its children",
44680Sstevel@tonic-gate sonode_walk_init, sonode_walk_step, sonode_walk_fini, NULL },
44693448Sdh155122 { "icmp_stacks", "walk all the icmp_stack_t",
44703448Sdh155122 icmp_stacks_walk_init, icmp_stacks_walk_step, NULL },
44713448Sdh155122 { "tcp_stacks", "walk all the tcp_stack_t",
44723448Sdh155122 tcp_stacks_walk_init, tcp_stacks_walk_step, NULL },
44733448Sdh155122 { "udp_stacks", "walk all the udp_stack_t",
44743448Sdh155122 udp_stacks_walk_init, udp_stacks_walk_step, NULL },
44753448Sdh155122
447610696SDavid.Hollister@Sun.COM /* from netstack.c */
447710696SDavid.Hollister@Sun.COM { "netstack", "walk a list of kernel netstacks",
447810696SDavid.Hollister@Sun.COM netstack_walk_init, netstack_walk_step, NULL },
447910696SDavid.Hollister@Sun.COM
44800Sstevel@tonic-gate /* from nvpair.c */
44810Sstevel@tonic-gate { NVPAIR_WALKER_NAME, NVPAIR_WALKER_DESCR,
44820Sstevel@tonic-gate nvpair_walk_init, nvpair_walk_step, NULL },
44830Sstevel@tonic-gate
44840Sstevel@tonic-gate /* from rctl.c */
44850Sstevel@tonic-gate { "rctl_dict_list", "walk all rctl_dict_entry_t's from rctl_lists",
44860Sstevel@tonic-gate rctl_dict_walk_init, rctl_dict_walk_step, NULL },
44870Sstevel@tonic-gate { "rctl_set", "given a rctl_set, walk all rctls", rctl_set_walk_init,
44880Sstevel@tonic-gate rctl_set_walk_step, NULL },
44890Sstevel@tonic-gate { "rctl_val", "given a rctl_t, walk all rctl_val entries associated",
44900Sstevel@tonic-gate rctl_val_walk_init, rctl_val_walk_step },
44910Sstevel@tonic-gate
44920Sstevel@tonic-gate /* from sobj.c */
44930Sstevel@tonic-gate { "blocked", "walk threads blocked on a given sobj",
44940Sstevel@tonic-gate blocked_walk_init, blocked_walk_step, NULL },
44950Sstevel@tonic-gate { "wchan", "given a wchan, list of blocked threads",
44960Sstevel@tonic-gate wchan_walk_init, wchan_walk_step, wchan_walk_fini },
44970Sstevel@tonic-gate
44980Sstevel@tonic-gate /* from stream.c */
44990Sstevel@tonic-gate { "b_cont", "walk mblk_t list using b_cont",
45000Sstevel@tonic-gate mblk_walk_init, b_cont_step, mblk_walk_fini },
45010Sstevel@tonic-gate { "b_next", "walk mblk_t list using b_next",
45020Sstevel@tonic-gate mblk_walk_init, b_next_step, mblk_walk_fini },
45030Sstevel@tonic-gate { "qlink", "walk queue_t list using q_link",
45040Sstevel@tonic-gate queue_walk_init, queue_link_step, queue_walk_fini },
45050Sstevel@tonic-gate { "qnext", "walk queue_t list using q_next",
45060Sstevel@tonic-gate queue_walk_init, queue_next_step, queue_walk_fini },
45070Sstevel@tonic-gate { "strftblk", "given a dblk_t, walk STREAMS flow trace event list",
45080Sstevel@tonic-gate strftblk_walk_init, strftblk_step, strftblk_walk_fini },
45090Sstevel@tonic-gate { "readq", "walk read queue side of stdata",
45100Sstevel@tonic-gate str_walk_init, strr_walk_step, str_walk_fini },
45110Sstevel@tonic-gate { "writeq", "walk write queue side of stdata",
45120Sstevel@tonic-gate str_walk_init, strw_walk_step, str_walk_fini },
45130Sstevel@tonic-gate
451410889SJonathan.Adams@Sun.COM /* from taskq.c */
451510889SJonathan.Adams@Sun.COM { "taskq_thread", "given a taskq_t, list all of its threads",
451610889SJonathan.Adams@Sun.COM taskq_thread_walk_init,
451710889SJonathan.Adams@Sun.COM taskq_thread_walk_step,
451810889SJonathan.Adams@Sun.COM taskq_thread_walk_fini },
451910889SJonathan.Adams@Sun.COM { "taskq_entry", "given a taskq_t*, list all taskq_ent_t in the list",
452010889SJonathan.Adams@Sun.COM taskq_ent_walk_init, taskq_ent_walk_step, NULL },
452110889SJonathan.Adams@Sun.COM
45220Sstevel@tonic-gate /* from thread.c */
45230Sstevel@tonic-gate { "deathrow", "walk threads on both lwp_ and thread_deathrow",
45240Sstevel@tonic-gate deathrow_walk_init, deathrow_walk_step, NULL },
45250Sstevel@tonic-gate { "cpu_dispq", "given a cpu_t, walk threads in dispatcher queues",
45260Sstevel@tonic-gate cpu_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
45270Sstevel@tonic-gate { "cpupart_dispq",
45280Sstevel@tonic-gate "given a cpupart_t, walk threads in dispatcher queues",
45290Sstevel@tonic-gate cpupart_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
45300Sstevel@tonic-gate { "lwp_deathrow", "walk lwp_deathrow",
45310Sstevel@tonic-gate lwp_deathrow_walk_init, deathrow_walk_step, NULL },
45320Sstevel@tonic-gate { "thread", "global or per-process kthread_t structures",
45330Sstevel@tonic-gate thread_walk_init, thread_walk_step, thread_walk_fini },
45340Sstevel@tonic-gate { "thread_deathrow", "walk threads on thread_deathrow",
45350Sstevel@tonic-gate thread_deathrow_walk_init, deathrow_walk_step, NULL },
45360Sstevel@tonic-gate
45370Sstevel@tonic-gate /* from tsd.c */
45380Sstevel@tonic-gate { "tsd", "walk list of thread-specific data",
45390Sstevel@tonic-gate tsd_walk_init, tsd_walk_step, tsd_walk_fini },
45400Sstevel@tonic-gate
45411676Sjpk /* from tsol.c */
45421676Sjpk { "tnrh", "walk remote host cache structures",
45431676Sjpk tnrh_walk_init, tnrh_walk_step, tnrh_walk_fini },
45441676Sjpk { "tnrhtp", "walk remote host template structures",
45451676Sjpk tnrhtp_walk_init, tnrhtp_walk_step, tnrhtp_walk_fini },
45461676Sjpk
45470Sstevel@tonic-gate /*
45480Sstevel@tonic-gate * typegraph does not work under kmdb, as it requires too much memory
45490Sstevel@tonic-gate * for its internal data structures.
45500Sstevel@tonic-gate */
45510Sstevel@tonic-gate #ifndef _KMDB
45520Sstevel@tonic-gate /* from typegraph.c */
45530Sstevel@tonic-gate { "typeconflict", "walk buffers with conflicting type inferences",
45540Sstevel@tonic-gate typegraph_walk_init, typeconflict_walk_step },
45550Sstevel@tonic-gate { "typeunknown", "walk buffers with unknown types",
45560Sstevel@tonic-gate typegraph_walk_init, typeunknown_walk_step },
45570Sstevel@tonic-gate #endif
45580Sstevel@tonic-gate
45590Sstevel@tonic-gate /* from vfs.c */
45600Sstevel@tonic-gate { "vfs", "walk file system list",
45610Sstevel@tonic-gate vfs_walk_init, vfs_walk_step },
45622577Sramat
456310696SDavid.Hollister@Sun.COM /* from zone.c */
456410696SDavid.Hollister@Sun.COM { "zone", "walk a list of kernel zones",
456510696SDavid.Hollister@Sun.COM zone_walk_init, zone_walk_step, NULL },
456610696SDavid.Hollister@Sun.COM { "zsd", "walk list of zsd entries for a zone",
456710696SDavid.Hollister@Sun.COM zsd_walk_init, zsd_walk_step, NULL },
45683448Sdh155122
45690Sstevel@tonic-gate { NULL }
45700Sstevel@tonic-gate };
45710Sstevel@tonic-gate
45720Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
45730Sstevel@tonic-gate
45748721SJonathan.Adams@Sun.COM /*ARGSUSED*/
45758721SJonathan.Adams@Sun.COM static void
genunix_statechange_cb(void * ignored)45768721SJonathan.Adams@Sun.COM genunix_statechange_cb(void *ignored)
45778721SJonathan.Adams@Sun.COM {
45788721SJonathan.Adams@Sun.COM /*
45798721SJonathan.Adams@Sun.COM * Force ::findleaks and ::stacks to let go any cached state.
45808721SJonathan.Adams@Sun.COM */
45818721SJonathan.Adams@Sun.COM leaky_cleanup(1);
45828721SJonathan.Adams@Sun.COM stacks_cleanup(1);
45838721SJonathan.Adams@Sun.COM
45848721SJonathan.Adams@Sun.COM kmem_statechange(); /* notify kmem */
45858721SJonathan.Adams@Sun.COM }
45868721SJonathan.Adams@Sun.COM
45870Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)45880Sstevel@tonic-gate _mdb_init(void)
45890Sstevel@tonic-gate {
45900Sstevel@tonic-gate kmem_init();
45910Sstevel@tonic-gate
45928721SJonathan.Adams@Sun.COM (void) mdb_callback_add(MDB_CALLBACK_STCHG,
45938721SJonathan.Adams@Sun.COM genunix_statechange_cb, NULL);
45948721SJonathan.Adams@Sun.COM
45950Sstevel@tonic-gate return (&modinfo);
45960Sstevel@tonic-gate }
45970Sstevel@tonic-gate
45980Sstevel@tonic-gate void
_mdb_fini(void)45990Sstevel@tonic-gate _mdb_fini(void)
46000Sstevel@tonic-gate {
46010Sstevel@tonic-gate leaky_cleanup(1);
46028721SJonathan.Adams@Sun.COM stacks_cleanup(1);
46030Sstevel@tonic-gate }
4604