1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_param.h> 30*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 31*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_ks.h> 32*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_ctf.h> 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/thread.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/session.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/user.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/proc.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/var.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/callo.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/priocntl.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/class.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/regset.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/stack.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 49*7c478bd9Sstevel@tonic-gate #include <sys/flock_impl.h> 50*7c478bd9Sstevel@tonic-gate #include <sys/kmem_impl.h> 51*7c478bd9Sstevel@tonic-gate #include <sys/vmem_impl.h> 52*7c478bd9Sstevel@tonic-gate #include <sys/kstat.h> 53*7c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h> 54*7c478bd9Sstevel@tonic-gate #include <vm/anon.h> 55*7c478bd9Sstevel@tonic-gate #include <vm/as.h> 56*7c478bd9Sstevel@tonic-gate #include <vm/seg_map.h> 57*7c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 58*7c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 59*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 60*7c478bd9Sstevel@tonic-gate #include <sys/sysconf.h> 61*7c478bd9Sstevel@tonic-gate #include <sys/task.h> 62*7c478bd9Sstevel@tonic-gate #include <sys/project.h> 63*7c478bd9Sstevel@tonic-gate #include <sys/taskq.h> 64*7c478bd9Sstevel@tonic-gate #include <sys/taskq_impl.h> 65*7c478bd9Sstevel@tonic-gate #include <sys/errorq_impl.h> 66*7c478bd9Sstevel@tonic-gate #include <sys/cred_impl.h> 67*7c478bd9Sstevel@tonic-gate #include <sys/zone.h> 68*7c478bd9Sstevel@tonic-gate #include <sys/panic.h> 69*7c478bd9Sstevel@tonic-gate #include <regex.h> 70*7c478bd9Sstevel@tonic-gate #include <sys/port_impl.h> 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate #include "contract.h" 73*7c478bd9Sstevel@tonic-gate #include "cpupart_mdb.h" 74*7c478bd9Sstevel@tonic-gate #include "devinfo.h" 75*7c478bd9Sstevel@tonic-gate #include "leaky.h" 76*7c478bd9Sstevel@tonic-gate #include "lgrp.h" 77*7c478bd9Sstevel@tonic-gate #include "list.h" 78*7c478bd9Sstevel@tonic-gate #include "log.h" 79*7c478bd9Sstevel@tonic-gate #include "kgrep.h" 80*7c478bd9Sstevel@tonic-gate #include "kmem.h" 81*7c478bd9Sstevel@tonic-gate #include "bio.h" 82*7c478bd9Sstevel@tonic-gate #include "streams.h" 83*7c478bd9Sstevel@tonic-gate #include "cyclic.h" 84*7c478bd9Sstevel@tonic-gate #include "findstack.h" 85*7c478bd9Sstevel@tonic-gate #include "ndievents.h" 86*7c478bd9Sstevel@tonic-gate #include "mmd.h" 87*7c478bd9Sstevel@tonic-gate #include "net.h" 88*7c478bd9Sstevel@tonic-gate #include "nvpair.h" 89*7c478bd9Sstevel@tonic-gate #include "ctxop.h" 90*7c478bd9Sstevel@tonic-gate #include "tsd.h" 91*7c478bd9Sstevel@tonic-gate #include "thread.h" 92*7c478bd9Sstevel@tonic-gate #include "memory.h" 93*7c478bd9Sstevel@tonic-gate #include "sobj.h" 94*7c478bd9Sstevel@tonic-gate #include "sysevent.h" 95*7c478bd9Sstevel@tonic-gate #include "rctl.h" 96*7c478bd9Sstevel@tonic-gate #include "typegraph.h" 97*7c478bd9Sstevel@tonic-gate #include "ldi.h" 98*7c478bd9Sstevel@tonic-gate #include "vfs.h" 99*7c478bd9Sstevel@tonic-gate #include "zone.h" 100*7c478bd9Sstevel@tonic-gate #include "modhash.h" 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate /* 103*7c478bd9Sstevel@tonic-gate * Surely this is defined somewhere... 104*7c478bd9Sstevel@tonic-gate */ 105*7c478bd9Sstevel@tonic-gate #define NINTR 16 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate #ifndef STACK_BIAS 108*7c478bd9Sstevel@tonic-gate #define STACK_BIAS 0 109*7c478bd9Sstevel@tonic-gate #endif 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate static char 112*7c478bd9Sstevel@tonic-gate pstat2ch(uchar_t state) 113*7c478bd9Sstevel@tonic-gate { 114*7c478bd9Sstevel@tonic-gate switch (state) { 115*7c478bd9Sstevel@tonic-gate case SSLEEP: return ('S'); 116*7c478bd9Sstevel@tonic-gate case SRUN: return ('R'); 117*7c478bd9Sstevel@tonic-gate case SZOMB: return ('Z'); 118*7c478bd9Sstevel@tonic-gate case SIDL: return ('I'); 119*7c478bd9Sstevel@tonic-gate case SONPROC: return ('O'); 120*7c478bd9Sstevel@tonic-gate case SSTOP: return ('T'); 121*7c478bd9Sstevel@tonic-gate default: return ('?'); 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate } 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate #define PS_PRTTHREADS 0x1 126*7c478bd9Sstevel@tonic-gate #define PS_PRTLWPS 0x2 127*7c478bd9Sstevel@tonic-gate #define PS_PSARGS 0x4 128*7c478bd9Sstevel@tonic-gate #define PS_TASKS 0x8 129*7c478bd9Sstevel@tonic-gate #define PS_PROJECTS 0x10 130*7c478bd9Sstevel@tonic-gate #define PS_ZONES 0x20 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate static int 133*7c478bd9Sstevel@tonic-gate ps_threadprint(uintptr_t addr, const void *data, void *private) 134*7c478bd9Sstevel@tonic-gate { 135*7c478bd9Sstevel@tonic-gate const kthread_t *t = (const kthread_t *)data; 136*7c478bd9Sstevel@tonic-gate uint_t prt_flags = *((uint_t *)private); 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate static const mdb_bitmask_t t_state_bits[] = { 139*7c478bd9Sstevel@tonic-gate { "TS_FREE", UINT_MAX, TS_FREE }, 140*7c478bd9Sstevel@tonic-gate { "TS_SLEEP", TS_SLEEP, TS_SLEEP }, 141*7c478bd9Sstevel@tonic-gate { "TS_RUN", TS_RUN, TS_RUN }, 142*7c478bd9Sstevel@tonic-gate { "TS_ONPROC", TS_ONPROC, TS_ONPROC }, 143*7c478bd9Sstevel@tonic-gate { "TS_ZOMB", TS_ZOMB, TS_ZOMB }, 144*7c478bd9Sstevel@tonic-gate { "TS_STOPPED", TS_STOPPED, TS_STOPPED }, 145*7c478bd9Sstevel@tonic-gate { NULL, 0, 0 } 146*7c478bd9Sstevel@tonic-gate }; 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate if (prt_flags & PS_PRTTHREADS) 149*7c478bd9Sstevel@tonic-gate mdb_printf("\tT %?a <%b>\n", addr, t->t_state, t_state_bits); 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate if (prt_flags & PS_PRTLWPS) 152*7c478bd9Sstevel@tonic-gate mdb_printf("\tL %?a ID: %u\n", t->t_lwp, t->t_tid); 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 155*7c478bd9Sstevel@tonic-gate } 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate int 158*7c478bd9Sstevel@tonic-gate ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 159*7c478bd9Sstevel@tonic-gate { 160*7c478bd9Sstevel@tonic-gate uint_t prt_flags = 0; 161*7c478bd9Sstevel@tonic-gate proc_t pr; 162*7c478bd9Sstevel@tonic-gate struct pid pid, pgid, sid; 163*7c478bd9Sstevel@tonic-gate sess_t session; 164*7c478bd9Sstevel@tonic-gate cred_t cred; 165*7c478bd9Sstevel@tonic-gate task_t tk; 166*7c478bd9Sstevel@tonic-gate kproject_t pj; 167*7c478bd9Sstevel@tonic-gate zone_t zn; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 170*7c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) { 171*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'proc'"); 172*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 175*7c478bd9Sstevel@tonic-gate } 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 178*7c478bd9Sstevel@tonic-gate 'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags, 179*7c478bd9Sstevel@tonic-gate 'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags, 180*7c478bd9Sstevel@tonic-gate 'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags, 181*7c478bd9Sstevel@tonic-gate 'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags, 182*7c478bd9Sstevel@tonic-gate 'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags, 183*7c478bd9Sstevel@tonic-gate 't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc) 184*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 187*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%1s %6s %6s %6s %6s ", 188*7c478bd9Sstevel@tonic-gate "S", "PID", "PPID", "PGID", "SID"); 189*7c478bd9Sstevel@tonic-gate if (prt_flags & PS_TASKS) 190*7c478bd9Sstevel@tonic-gate mdb_printf("%5s ", "TASK"); 191*7c478bd9Sstevel@tonic-gate if (prt_flags & PS_PROJECTS) 192*7c478bd9Sstevel@tonic-gate mdb_printf("%5s ", "PROJ"); 193*7c478bd9Sstevel@tonic-gate if (prt_flags & PS_ZONES) 194*7c478bd9Sstevel@tonic-gate mdb_printf("%5s ", "ZONE"); 195*7c478bd9Sstevel@tonic-gate mdb_printf("%6s %10s %?s %s%</u>\n", 196*7c478bd9Sstevel@tonic-gate "UID", "FLAGS", "ADDR", "NAME"); 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate mdb_vread(&pr, sizeof (pr), addr); 200*7c478bd9Sstevel@tonic-gate mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp); 201*7c478bd9Sstevel@tonic-gate mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp); 202*7c478bd9Sstevel@tonic-gate mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred); 203*7c478bd9Sstevel@tonic-gate mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp); 204*7c478bd9Sstevel@tonic-gate mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp); 205*7c478bd9Sstevel@tonic-gate if (prt_flags & (PS_TASKS | PS_PROJECTS)) 206*7c478bd9Sstevel@tonic-gate mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task); 207*7c478bd9Sstevel@tonic-gate if (prt_flags & PS_PROJECTS) 208*7c478bd9Sstevel@tonic-gate mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj); 209*7c478bd9Sstevel@tonic-gate if (prt_flags & PS_ZONES) 210*7c478bd9Sstevel@tonic-gate mdb_vread(&zn, sizeof (zone_t), (uintptr_t)pr.p_zone); 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate mdb_printf("%c %6d %6d %6d %6d ", 213*7c478bd9Sstevel@tonic-gate pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id, 214*7c478bd9Sstevel@tonic-gate sid.pid_id); 215*7c478bd9Sstevel@tonic-gate if (prt_flags & PS_TASKS) 216*7c478bd9Sstevel@tonic-gate mdb_printf("%5d ", tk.tk_tkid); 217*7c478bd9Sstevel@tonic-gate if (prt_flags & PS_PROJECTS) 218*7c478bd9Sstevel@tonic-gate mdb_printf("%5d ", pj.kpj_id); 219*7c478bd9Sstevel@tonic-gate if (prt_flags & PS_ZONES) 220*7c478bd9Sstevel@tonic-gate mdb_printf("%5d ", zn.zone_id); 221*7c478bd9Sstevel@tonic-gate mdb_printf("%6d 0x%08x %0?p %s\n", 222*7c478bd9Sstevel@tonic-gate cred.cr_uid, pr.p_flag, addr, 223*7c478bd9Sstevel@tonic-gate (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm); 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate if (prt_flags & ~PS_PSARGS) 226*7c478bd9Sstevel@tonic-gate (void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr); 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 229*7c478bd9Sstevel@tonic-gate } 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate #define PG_NEWEST 0x0001 232*7c478bd9Sstevel@tonic-gate #define PG_OLDEST 0x0002 233*7c478bd9Sstevel@tonic-gate #define PG_PIPE_OUT 0x0004 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate typedef struct pgrep_data { 236*7c478bd9Sstevel@tonic-gate uint_t pg_flags; 237*7c478bd9Sstevel@tonic-gate uint_t pg_psflags; 238*7c478bd9Sstevel@tonic-gate uintptr_t pg_xaddr; 239*7c478bd9Sstevel@tonic-gate hrtime_t pg_xstart; 240*7c478bd9Sstevel@tonic-gate const char *pg_pat; 241*7c478bd9Sstevel@tonic-gate #ifndef _KMDB 242*7c478bd9Sstevel@tonic-gate regex_t pg_reg; 243*7c478bd9Sstevel@tonic-gate #endif 244*7c478bd9Sstevel@tonic-gate } pgrep_data_t; 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 247*7c478bd9Sstevel@tonic-gate static int 248*7c478bd9Sstevel@tonic-gate pgrep_cb(uintptr_t addr, const void *pdata, void *data) 249*7c478bd9Sstevel@tonic-gate { 250*7c478bd9Sstevel@tonic-gate const proc_t *prp = pdata; 251*7c478bd9Sstevel@tonic-gate pgrep_data_t *pgp = data; 252*7c478bd9Sstevel@tonic-gate #ifndef _KMDB 253*7c478bd9Sstevel@tonic-gate regmatch_t pmatch; 254*7c478bd9Sstevel@tonic-gate #endif 255*7c478bd9Sstevel@tonic-gate 256*7c478bd9Sstevel@tonic-gate /* 257*7c478bd9Sstevel@tonic-gate * kmdb doesn't have access to the reg* functions, so we fall back 258*7c478bd9Sstevel@tonic-gate * to strstr. 259*7c478bd9Sstevel@tonic-gate */ 260*7c478bd9Sstevel@tonic-gate #ifdef _KMDB 261*7c478bd9Sstevel@tonic-gate if (strstr(prp->p_user.u_comm, pgp->pg_pat) == NULL) 262*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 263*7c478bd9Sstevel@tonic-gate #else 264*7c478bd9Sstevel@tonic-gate if (regexec(&pgp->pg_reg, prp->p_user.u_comm, 1, &pmatch, 0) != 0) 265*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 266*7c478bd9Sstevel@tonic-gate #endif 267*7c478bd9Sstevel@tonic-gate 268*7c478bd9Sstevel@tonic-gate if (pgp->pg_flags & (PG_NEWEST | PG_OLDEST)) { 269*7c478bd9Sstevel@tonic-gate hrtime_t start; 270*7c478bd9Sstevel@tonic-gate 271*7c478bd9Sstevel@tonic-gate start = (hrtime_t)prp->p_user.u_start.tv_sec * NANOSEC + 272*7c478bd9Sstevel@tonic-gate prp->p_user.u_start.tv_nsec; 273*7c478bd9Sstevel@tonic-gate 274*7c478bd9Sstevel@tonic-gate if (pgp->pg_flags & PG_NEWEST) { 275*7c478bd9Sstevel@tonic-gate if (pgp->pg_xaddr == NULL || start > pgp->pg_xstart) { 276*7c478bd9Sstevel@tonic-gate pgp->pg_xaddr = addr; 277*7c478bd9Sstevel@tonic-gate pgp->pg_xstart = start; 278*7c478bd9Sstevel@tonic-gate } 279*7c478bd9Sstevel@tonic-gate } else { 280*7c478bd9Sstevel@tonic-gate if (pgp->pg_xaddr == NULL || start < pgp->pg_xstart) { 281*7c478bd9Sstevel@tonic-gate pgp->pg_xaddr = addr; 282*7c478bd9Sstevel@tonic-gate pgp->pg_xstart = start; 283*7c478bd9Sstevel@tonic-gate } 284*7c478bd9Sstevel@tonic-gate } 285*7c478bd9Sstevel@tonic-gate 286*7c478bd9Sstevel@tonic-gate } else if (pgp->pg_flags & PG_PIPE_OUT) { 287*7c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr); 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate } else { 290*7c478bd9Sstevel@tonic-gate if (mdb_call_dcmd("ps", addr, pgp->pg_psflags, 0, NULL) != 0) { 291*7c478bd9Sstevel@tonic-gate mdb_warn("can't invoke 'ps'"); 292*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 293*7c478bd9Sstevel@tonic-gate } 294*7c478bd9Sstevel@tonic-gate pgp->pg_psflags &= ~DCMD_LOOPFIRST; 295*7c478bd9Sstevel@tonic-gate } 296*7c478bd9Sstevel@tonic-gate 297*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 298*7c478bd9Sstevel@tonic-gate } 299*7c478bd9Sstevel@tonic-gate 300*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 301*7c478bd9Sstevel@tonic-gate int 302*7c478bd9Sstevel@tonic-gate pgrep(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 303*7c478bd9Sstevel@tonic-gate { 304*7c478bd9Sstevel@tonic-gate pgrep_data_t pg; 305*7c478bd9Sstevel@tonic-gate int i; 306*7c478bd9Sstevel@tonic-gate #ifndef _KMDB 307*7c478bd9Sstevel@tonic-gate int err; 308*7c478bd9Sstevel@tonic-gate #endif 309*7c478bd9Sstevel@tonic-gate 310*7c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) 311*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate pg.pg_flags = 0; 314*7c478bd9Sstevel@tonic-gate pg.pg_xaddr = 0; 315*7c478bd9Sstevel@tonic-gate 316*7c478bd9Sstevel@tonic-gate i = mdb_getopts(argc, argv, 317*7c478bd9Sstevel@tonic-gate 'n', MDB_OPT_SETBITS, PG_NEWEST, &pg.pg_flags, 318*7c478bd9Sstevel@tonic-gate 'o', MDB_OPT_SETBITS, PG_OLDEST, &pg.pg_flags, 319*7c478bd9Sstevel@tonic-gate NULL); 320*7c478bd9Sstevel@tonic-gate 321*7c478bd9Sstevel@tonic-gate argc -= i; 322*7c478bd9Sstevel@tonic-gate argv += i; 323*7c478bd9Sstevel@tonic-gate 324*7c478bd9Sstevel@tonic-gate if (argc != 1) 325*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 326*7c478bd9Sstevel@tonic-gate 327*7c478bd9Sstevel@tonic-gate /* 328*7c478bd9Sstevel@tonic-gate * -n and -o are mutually exclusive. 329*7c478bd9Sstevel@tonic-gate */ 330*7c478bd9Sstevel@tonic-gate if ((pg.pg_flags & PG_NEWEST) && (pg.pg_flags & PG_OLDEST)) 331*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 332*7c478bd9Sstevel@tonic-gate 333*7c478bd9Sstevel@tonic-gate if (argv->a_type != MDB_TYPE_STRING) 334*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 335*7c478bd9Sstevel@tonic-gate 336*7c478bd9Sstevel@tonic-gate if (flags & DCMD_PIPE_OUT) 337*7c478bd9Sstevel@tonic-gate pg.pg_flags |= PG_PIPE_OUT; 338*7c478bd9Sstevel@tonic-gate 339*7c478bd9Sstevel@tonic-gate pg.pg_pat = argv->a_un.a_str; 340*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 341*7c478bd9Sstevel@tonic-gate pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP | DCMD_LOOPFIRST; 342*7c478bd9Sstevel@tonic-gate else 343*7c478bd9Sstevel@tonic-gate pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP; 344*7c478bd9Sstevel@tonic-gate 345*7c478bd9Sstevel@tonic-gate #ifndef _KMDB 346*7c478bd9Sstevel@tonic-gate if ((err = regcomp(&pg.pg_reg, pg.pg_pat, REG_EXTENDED)) != 0) { 347*7c478bd9Sstevel@tonic-gate size_t nbytes; 348*7c478bd9Sstevel@tonic-gate char *buf; 349*7c478bd9Sstevel@tonic-gate 350*7c478bd9Sstevel@tonic-gate nbytes = regerror(err, &pg.pg_reg, NULL, 0); 351*7c478bd9Sstevel@tonic-gate buf = mdb_alloc(nbytes + 1, UM_SLEEP | UM_GC); 352*7c478bd9Sstevel@tonic-gate (void) regerror(err, &pg.pg_reg, buf, nbytes); 353*7c478bd9Sstevel@tonic-gate mdb_warn("%s\n", buf); 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 356*7c478bd9Sstevel@tonic-gate } 357*7c478bd9Sstevel@tonic-gate #endif 358*7c478bd9Sstevel@tonic-gate 359*7c478bd9Sstevel@tonic-gate if (mdb_walk("proc", pgrep_cb, &pg) != 0) { 360*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'proc'"); 361*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 362*7c478bd9Sstevel@tonic-gate } 363*7c478bd9Sstevel@tonic-gate 364*7c478bd9Sstevel@tonic-gate if (pg.pg_xaddr != 0 && (pg.pg_flags & (PG_NEWEST | PG_OLDEST))) { 365*7c478bd9Sstevel@tonic-gate if (pg.pg_flags & PG_PIPE_OUT) { 366*7c478bd9Sstevel@tonic-gate mdb_printf("%p\n", pg.pg_xaddr); 367*7c478bd9Sstevel@tonic-gate } else { 368*7c478bd9Sstevel@tonic-gate if (mdb_call_dcmd("ps", pg.pg_xaddr, pg.pg_psflags, 369*7c478bd9Sstevel@tonic-gate 0, NULL) != 0) { 370*7c478bd9Sstevel@tonic-gate mdb_warn("can't invoke 'ps'"); 371*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 372*7c478bd9Sstevel@tonic-gate } 373*7c478bd9Sstevel@tonic-gate } 374*7c478bd9Sstevel@tonic-gate } 375*7c478bd9Sstevel@tonic-gate 376*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 377*7c478bd9Sstevel@tonic-gate } 378*7c478bd9Sstevel@tonic-gate 379*7c478bd9Sstevel@tonic-gate int 380*7c478bd9Sstevel@tonic-gate task(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 381*7c478bd9Sstevel@tonic-gate { 382*7c478bd9Sstevel@tonic-gate task_t tk; 383*7c478bd9Sstevel@tonic-gate kproject_t pj; 384*7c478bd9Sstevel@tonic-gate 385*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 386*7c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("task_cache", "task", argc, argv) == -1) { 387*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk task_cache"); 388*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 389*7c478bd9Sstevel@tonic-gate } 390*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 391*7c478bd9Sstevel@tonic-gate } 392*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 393*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%?s %6s %6s %6s %6s %10s%</u>\n", 394*7c478bd9Sstevel@tonic-gate "ADDR", "TASKID", "PROJID", "ZONEID", "REFCNT", "FLAGS"); 395*7c478bd9Sstevel@tonic-gate } 396*7c478bd9Sstevel@tonic-gate if (mdb_vread(&tk, sizeof (task_t), addr) == -1) { 397*7c478bd9Sstevel@tonic-gate mdb_warn("can't read task_t structure at %p", addr); 398*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 399*7c478bd9Sstevel@tonic-gate } 400*7c478bd9Sstevel@tonic-gate if (mdb_vread(&pj, sizeof (kproject_t), (uintptr_t)tk.tk_proj) == -1) { 401*7c478bd9Sstevel@tonic-gate mdb_warn("can't read project_t structure at %p", addr); 402*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 403*7c478bd9Sstevel@tonic-gate } 404*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p %6d %6d %6d %6u 0x%08x\n", 405*7c478bd9Sstevel@tonic-gate addr, tk.tk_tkid, pj.kpj_id, pj.kpj_zoneid, tk.tk_hold_count, 406*7c478bd9Sstevel@tonic-gate tk.tk_flags); 407*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 408*7c478bd9Sstevel@tonic-gate } 409*7c478bd9Sstevel@tonic-gate 410*7c478bd9Sstevel@tonic-gate int 411*7c478bd9Sstevel@tonic-gate project(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 412*7c478bd9Sstevel@tonic-gate { 413*7c478bd9Sstevel@tonic-gate kproject_t pj; 414*7c478bd9Sstevel@tonic-gate 415*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 416*7c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("projects", "project", argc, argv) == -1) { 417*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk projects"); 418*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 419*7c478bd9Sstevel@tonic-gate } 420*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 421*7c478bd9Sstevel@tonic-gate } 422*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 423*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%?s %6s %6s %6s%</u>\n", 424*7c478bd9Sstevel@tonic-gate "ADDR", "PROJID", "ZONEID", "REFCNT"); 425*7c478bd9Sstevel@tonic-gate } 426*7c478bd9Sstevel@tonic-gate if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) { 427*7c478bd9Sstevel@tonic-gate mdb_warn("can't read kproject_t structure at %p", addr); 428*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 429*7c478bd9Sstevel@tonic-gate } 430*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p %6d %6d %6u\n", addr, pj.kpj_id, pj.kpj_zoneid, 431*7c478bd9Sstevel@tonic-gate pj.kpj_count); 432*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 433*7c478bd9Sstevel@tonic-gate } 434*7c478bd9Sstevel@tonic-gate 435*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 436*7c478bd9Sstevel@tonic-gate int 437*7c478bd9Sstevel@tonic-gate callout(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 438*7c478bd9Sstevel@tonic-gate { 439*7c478bd9Sstevel@tonic-gate callout_table_t *co_ktable[CALLOUT_TABLES]; 440*7c478bd9Sstevel@tonic-gate int co_kfanout; 441*7c478bd9Sstevel@tonic-gate callout_table_t co_table; 442*7c478bd9Sstevel@tonic-gate callout_t co_callout; 443*7c478bd9Sstevel@tonic-gate callout_t *co_ptr; 444*7c478bd9Sstevel@tonic-gate int co_id; 445*7c478bd9Sstevel@tonic-gate clock_t lbolt; 446*7c478bd9Sstevel@tonic-gate int i, j, k; 447*7c478bd9Sstevel@tonic-gate const char *lbolt_sym; 448*7c478bd9Sstevel@tonic-gate 449*7c478bd9Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) || argc != 0) 450*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 451*7c478bd9Sstevel@tonic-gate 452*7c478bd9Sstevel@tonic-gate if (mdb_prop_postmortem) 453*7c478bd9Sstevel@tonic-gate lbolt_sym = "panic_lbolt"; 454*7c478bd9Sstevel@tonic-gate else 455*7c478bd9Sstevel@tonic-gate lbolt_sym = "lbolt"; 456*7c478bd9Sstevel@tonic-gate 457*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&lbolt, lbolt_sym) == -1) { 458*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read '%s'", lbolt_sym); 459*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 460*7c478bd9Sstevel@tonic-gate } 461*7c478bd9Sstevel@tonic-gate 462*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&co_kfanout, "callout_fanout") == -1) { 463*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read callout_fanout"); 464*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 465*7c478bd9Sstevel@tonic-gate } 466*7c478bd9Sstevel@tonic-gate 467*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&co_ktable, "callout_table") == -1) { 468*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read callout_table"); 469*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 470*7c478bd9Sstevel@tonic-gate } 471*7c478bd9Sstevel@tonic-gate 472*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-24s %-?s %-?s %-?s%</u>\n", 473*7c478bd9Sstevel@tonic-gate "FUNCTION", "ARGUMENT", "ID", "TIME"); 474*7c478bd9Sstevel@tonic-gate 475*7c478bd9Sstevel@tonic-gate for (i = 0; i < CALLOUT_NTYPES; i++) { 476*7c478bd9Sstevel@tonic-gate for (j = 0; j < co_kfanout; j++) { 477*7c478bd9Sstevel@tonic-gate 478*7c478bd9Sstevel@tonic-gate co_id = CALLOUT_TABLE(i, j); 479*7c478bd9Sstevel@tonic-gate 480*7c478bd9Sstevel@tonic-gate if (mdb_vread(&co_table, sizeof (co_table), 481*7c478bd9Sstevel@tonic-gate (uintptr_t)co_ktable[co_id]) == -1) { 482*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read table at %p", 483*7c478bd9Sstevel@tonic-gate (uintptr_t)co_ktable[co_id]); 484*7c478bd9Sstevel@tonic-gate continue; 485*7c478bd9Sstevel@tonic-gate } 486*7c478bd9Sstevel@tonic-gate 487*7c478bd9Sstevel@tonic-gate for (k = 0; k < CALLOUT_BUCKETS; k++) { 488*7c478bd9Sstevel@tonic-gate co_ptr = co_table.ct_idhash[k]; 489*7c478bd9Sstevel@tonic-gate 490*7c478bd9Sstevel@tonic-gate while (co_ptr != NULL) { 491*7c478bd9Sstevel@tonic-gate mdb_vread(&co_callout, 492*7c478bd9Sstevel@tonic-gate sizeof (co_callout), 493*7c478bd9Sstevel@tonic-gate (uintptr_t)co_ptr); 494*7c478bd9Sstevel@tonic-gate 495*7c478bd9Sstevel@tonic-gate mdb_printf("%-24a %0?p %0?lx %?lx " 496*7c478bd9Sstevel@tonic-gate "(T%+ld)\n", co_callout.c_func, 497*7c478bd9Sstevel@tonic-gate co_callout.c_arg, co_callout.c_xid, 498*7c478bd9Sstevel@tonic-gate co_callout.c_runtime, 499*7c478bd9Sstevel@tonic-gate co_callout.c_runtime - lbolt); 500*7c478bd9Sstevel@tonic-gate 501*7c478bd9Sstevel@tonic-gate co_ptr = co_callout.c_idnext; 502*7c478bd9Sstevel@tonic-gate } 503*7c478bd9Sstevel@tonic-gate } 504*7c478bd9Sstevel@tonic-gate } 505*7c478bd9Sstevel@tonic-gate } 506*7c478bd9Sstevel@tonic-gate 507*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 508*7c478bd9Sstevel@tonic-gate } 509*7c478bd9Sstevel@tonic-gate 510*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 511*7c478bd9Sstevel@tonic-gate int 512*7c478bd9Sstevel@tonic-gate class(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 513*7c478bd9Sstevel@tonic-gate { 514*7c478bd9Sstevel@tonic-gate long num_classes, i; 515*7c478bd9Sstevel@tonic-gate sclass_t *class_tbl; 516*7c478bd9Sstevel@tonic-gate GElf_Sym g_sclass; 517*7c478bd9Sstevel@tonic-gate char class_name[PC_CLNMSZ]; 518*7c478bd9Sstevel@tonic-gate size_t tbl_size; 519*7c478bd9Sstevel@tonic-gate 520*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("sclass", &g_sclass) == -1) { 521*7c478bd9Sstevel@tonic-gate mdb_warn("failed to find symbol sclass\n"); 522*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 523*7c478bd9Sstevel@tonic-gate } 524*7c478bd9Sstevel@tonic-gate 525*7c478bd9Sstevel@tonic-gate tbl_size = (size_t)g_sclass.st_size; 526*7c478bd9Sstevel@tonic-gate num_classes = tbl_size / (sizeof (sclass_t)); 527*7c478bd9Sstevel@tonic-gate class_tbl = mdb_alloc(tbl_size, UM_SLEEP | UM_GC); 528*7c478bd9Sstevel@tonic-gate 529*7c478bd9Sstevel@tonic-gate if (mdb_readsym(class_tbl, tbl_size, "sclass") == -1) { 530*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read sclass"); 531*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 532*7c478bd9Sstevel@tonic-gate } 533*7c478bd9Sstevel@tonic-gate 534*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%4s %-10s %-24s %-24s%</u>\n", "SLOT", "NAME", 535*7c478bd9Sstevel@tonic-gate "INIT FCN", "CLASS FCN"); 536*7c478bd9Sstevel@tonic-gate 537*7c478bd9Sstevel@tonic-gate for (i = 0; i < num_classes; i++) { 538*7c478bd9Sstevel@tonic-gate if (mdb_vread(class_name, sizeof (class_name), 539*7c478bd9Sstevel@tonic-gate (uintptr_t)class_tbl[i].cl_name) == -1) 540*7c478bd9Sstevel@tonic-gate (void) strcpy(class_name, "???"); 541*7c478bd9Sstevel@tonic-gate 542*7c478bd9Sstevel@tonic-gate mdb_printf("%4ld %-10s %-24a %-24a\n", i, class_name, 543*7c478bd9Sstevel@tonic-gate class_tbl[i].cl_init, class_tbl[i].cl_funcs); 544*7c478bd9Sstevel@tonic-gate } 545*7c478bd9Sstevel@tonic-gate 546*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 547*7c478bd9Sstevel@tonic-gate } 548*7c478bd9Sstevel@tonic-gate 549*7c478bd9Sstevel@tonic-gate #define FSNAMELEN 32 /* Max len of FS name we read from vnodeops */ 550*7c478bd9Sstevel@tonic-gate 551*7c478bd9Sstevel@tonic-gate int 552*7c478bd9Sstevel@tonic-gate vnode2path(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 553*7c478bd9Sstevel@tonic-gate { 554*7c478bd9Sstevel@tonic-gate uintptr_t rootdir; 555*7c478bd9Sstevel@tonic-gate vnode_t vn; 556*7c478bd9Sstevel@tonic-gate char buf[MAXPATHLEN]; 557*7c478bd9Sstevel@tonic-gate 558*7c478bd9Sstevel@tonic-gate uint_t opt_F = FALSE; 559*7c478bd9Sstevel@tonic-gate 560*7c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 561*7c478bd9Sstevel@tonic-gate 'F', MDB_OPT_SETBITS, TRUE, &opt_F, NULL) != argc) 562*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 563*7c478bd9Sstevel@tonic-gate 564*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 565*7c478bd9Sstevel@tonic-gate mdb_warn("expected explicit vnode_t address before ::\n"); 566*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 567*7c478bd9Sstevel@tonic-gate } 568*7c478bd9Sstevel@tonic-gate 569*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&rootdir, "rootdir") == -1) { 570*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read rootdir"); 571*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 572*7c478bd9Sstevel@tonic-gate } 573*7c478bd9Sstevel@tonic-gate 574*7c478bd9Sstevel@tonic-gate if (mdb_vnode2path(addr, buf, sizeof (buf)) == -1) 575*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 576*7c478bd9Sstevel@tonic-gate 577*7c478bd9Sstevel@tonic-gate if (*buf == '\0') { 578*7c478bd9Sstevel@tonic-gate mdb_printf("??\n"); 579*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 580*7c478bd9Sstevel@tonic-gate } 581*7c478bd9Sstevel@tonic-gate 582*7c478bd9Sstevel@tonic-gate mdb_printf("%s", buf); 583*7c478bd9Sstevel@tonic-gate if (opt_F && buf[strlen(buf)-1] != '/' && 584*7c478bd9Sstevel@tonic-gate mdb_vread(&vn, sizeof (vn), addr) == sizeof (vn)) 585*7c478bd9Sstevel@tonic-gate mdb_printf("%c", mdb_vtype2chr(vn.v_type, 0)); 586*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 587*7c478bd9Sstevel@tonic-gate 588*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 589*7c478bd9Sstevel@tonic-gate } 590*7c478bd9Sstevel@tonic-gate 591*7c478bd9Sstevel@tonic-gate int 592*7c478bd9Sstevel@tonic-gate ld_walk_init(mdb_walk_state_t *wsp) 593*7c478bd9Sstevel@tonic-gate { 594*7c478bd9Sstevel@tonic-gate wsp->walk_data = (void *)wsp->walk_addr; 595*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 596*7c478bd9Sstevel@tonic-gate } 597*7c478bd9Sstevel@tonic-gate 598*7c478bd9Sstevel@tonic-gate int 599*7c478bd9Sstevel@tonic-gate ld_walk_step(mdb_walk_state_t *wsp) 600*7c478bd9Sstevel@tonic-gate { 601*7c478bd9Sstevel@tonic-gate int status; 602*7c478bd9Sstevel@tonic-gate lock_descriptor_t ld; 603*7c478bd9Sstevel@tonic-gate 604*7c478bd9Sstevel@tonic-gate if (mdb_vread(&ld, sizeof (lock_descriptor_t), wsp->walk_addr) == -1) { 605*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read lock_descriptor_t at %p\n", 606*7c478bd9Sstevel@tonic-gate wsp->walk_addr); 607*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 608*7c478bd9Sstevel@tonic-gate } 609*7c478bd9Sstevel@tonic-gate 610*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, &ld, wsp->walk_cbdata); 611*7c478bd9Sstevel@tonic-gate if (status == WALK_ERR) 612*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 613*7c478bd9Sstevel@tonic-gate 614*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)ld.l_next; 615*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == (uintptr_t)wsp->walk_data) 616*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 617*7c478bd9Sstevel@tonic-gate 618*7c478bd9Sstevel@tonic-gate return (status); 619*7c478bd9Sstevel@tonic-gate } 620*7c478bd9Sstevel@tonic-gate 621*7c478bd9Sstevel@tonic-gate int 622*7c478bd9Sstevel@tonic-gate lg_walk_init(mdb_walk_state_t *wsp) 623*7c478bd9Sstevel@tonic-gate { 624*7c478bd9Sstevel@tonic-gate GElf_Sym sym; 625*7c478bd9Sstevel@tonic-gate 626*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("lock_graph", &sym) == -1) { 627*7c478bd9Sstevel@tonic-gate mdb_warn("failed to find symbol 'lock_graph'\n"); 628*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 629*7c478bd9Sstevel@tonic-gate } 630*7c478bd9Sstevel@tonic-gate 631*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)sym.st_value; 632*7c478bd9Sstevel@tonic-gate wsp->walk_data = (void *)(sym.st_value + sym.st_size); 633*7c478bd9Sstevel@tonic-gate 634*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 635*7c478bd9Sstevel@tonic-gate } 636*7c478bd9Sstevel@tonic-gate 637*7c478bd9Sstevel@tonic-gate typedef struct lg_walk_data { 638*7c478bd9Sstevel@tonic-gate uintptr_t startaddr; 639*7c478bd9Sstevel@tonic-gate mdb_walk_cb_t callback; 640*7c478bd9Sstevel@tonic-gate void *data; 641*7c478bd9Sstevel@tonic-gate } lg_walk_data_t; 642*7c478bd9Sstevel@tonic-gate 643*7c478bd9Sstevel@tonic-gate /* 644*7c478bd9Sstevel@tonic-gate * We can't use ::walk lock_descriptor directly, because the head of each graph 645*7c478bd9Sstevel@tonic-gate * is really a dummy lock. Rather than trying to dynamically determine if this 646*7c478bd9Sstevel@tonic-gate * is a dummy node or not, we just filter out the initial element of the 647*7c478bd9Sstevel@tonic-gate * list. 648*7c478bd9Sstevel@tonic-gate */ 649*7c478bd9Sstevel@tonic-gate static int 650*7c478bd9Sstevel@tonic-gate lg_walk_cb(uintptr_t addr, const void *data, void *priv) 651*7c478bd9Sstevel@tonic-gate { 652*7c478bd9Sstevel@tonic-gate lg_walk_data_t *lw = priv; 653*7c478bd9Sstevel@tonic-gate 654*7c478bd9Sstevel@tonic-gate if (addr != lw->startaddr) 655*7c478bd9Sstevel@tonic-gate return (lw->callback(addr, data, lw->data)); 656*7c478bd9Sstevel@tonic-gate 657*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 658*7c478bd9Sstevel@tonic-gate } 659*7c478bd9Sstevel@tonic-gate 660*7c478bd9Sstevel@tonic-gate int 661*7c478bd9Sstevel@tonic-gate lg_walk_step(mdb_walk_state_t *wsp) 662*7c478bd9Sstevel@tonic-gate { 663*7c478bd9Sstevel@tonic-gate graph_t *graph; 664*7c478bd9Sstevel@tonic-gate lg_walk_data_t lw; 665*7c478bd9Sstevel@tonic-gate 666*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr >= (uintptr_t)wsp->walk_data) 667*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 668*7c478bd9Sstevel@tonic-gate 669*7c478bd9Sstevel@tonic-gate if (mdb_vread(&graph, sizeof (graph), wsp->walk_addr) == -1) { 670*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read graph_t at %p", wsp->walk_addr); 671*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 672*7c478bd9Sstevel@tonic-gate } 673*7c478bd9Sstevel@tonic-gate 674*7c478bd9Sstevel@tonic-gate wsp->walk_addr += sizeof (graph); 675*7c478bd9Sstevel@tonic-gate 676*7c478bd9Sstevel@tonic-gate if (graph == NULL) 677*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 678*7c478bd9Sstevel@tonic-gate 679*7c478bd9Sstevel@tonic-gate lw.callback = wsp->walk_callback; 680*7c478bd9Sstevel@tonic-gate lw.data = wsp->walk_cbdata; 681*7c478bd9Sstevel@tonic-gate 682*7c478bd9Sstevel@tonic-gate lw.startaddr = (uintptr_t)&(graph->active_locks); 683*7c478bd9Sstevel@tonic-gate if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) { 684*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr); 685*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 686*7c478bd9Sstevel@tonic-gate } 687*7c478bd9Sstevel@tonic-gate 688*7c478bd9Sstevel@tonic-gate lw.startaddr = (uintptr_t)&(graph->sleeping_locks); 689*7c478bd9Sstevel@tonic-gate if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) { 690*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr); 691*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 692*7c478bd9Sstevel@tonic-gate } 693*7c478bd9Sstevel@tonic-gate 694*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 695*7c478bd9Sstevel@tonic-gate } 696*7c478bd9Sstevel@tonic-gate 697*7c478bd9Sstevel@tonic-gate /* 698*7c478bd9Sstevel@tonic-gate * The space available for the path corresponding to the locked vnode depends 699*7c478bd9Sstevel@tonic-gate * on whether we are printing 32- or 64-bit addresses. 700*7c478bd9Sstevel@tonic-gate */ 701*7c478bd9Sstevel@tonic-gate #ifdef _LP64 702*7c478bd9Sstevel@tonic-gate #define LM_VNPATHLEN 20 703*7c478bd9Sstevel@tonic-gate #else 704*7c478bd9Sstevel@tonic-gate #define LM_VNPATHLEN 30 705*7c478bd9Sstevel@tonic-gate #endif 706*7c478bd9Sstevel@tonic-gate 707*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 708*7c478bd9Sstevel@tonic-gate static int 709*7c478bd9Sstevel@tonic-gate lminfo_cb(uintptr_t addr, const void *data, void *priv) 710*7c478bd9Sstevel@tonic-gate { 711*7c478bd9Sstevel@tonic-gate const lock_descriptor_t *ld = data; 712*7c478bd9Sstevel@tonic-gate char buf[LM_VNPATHLEN]; 713*7c478bd9Sstevel@tonic-gate proc_t p; 714*7c478bd9Sstevel@tonic-gate 715*7c478bd9Sstevel@tonic-gate mdb_printf("%-?p %2s %04x %6d %-16s %-?p ", 716*7c478bd9Sstevel@tonic-gate addr, ld->l_type == F_RDLCK ? "RD" : 717*7c478bd9Sstevel@tonic-gate ld->l_type == F_WRLCK ? "WR" : "??", 718*7c478bd9Sstevel@tonic-gate ld->l_state, ld->l_flock.l_pid, 719*7c478bd9Sstevel@tonic-gate ld->l_flock.l_pid == 0 ? "<kernel>" : 720*7c478bd9Sstevel@tonic-gate mdb_pid2proc(ld->l_flock.l_pid, &p) == NULL ? 721*7c478bd9Sstevel@tonic-gate "<defunct>" : p.p_user.u_comm, 722*7c478bd9Sstevel@tonic-gate ld->l_vnode); 723*7c478bd9Sstevel@tonic-gate 724*7c478bd9Sstevel@tonic-gate mdb_vnode2path((uintptr_t)ld->l_vnode, buf, 725*7c478bd9Sstevel@tonic-gate sizeof (buf)); 726*7c478bd9Sstevel@tonic-gate mdb_printf("%s\n", buf); 727*7c478bd9Sstevel@tonic-gate 728*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 729*7c478bd9Sstevel@tonic-gate } 730*7c478bd9Sstevel@tonic-gate 731*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 732*7c478bd9Sstevel@tonic-gate int 733*7c478bd9Sstevel@tonic-gate lminfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 734*7c478bd9Sstevel@tonic-gate { 735*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 736*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-?s %2s %4s %6s %-16s %-?s %s%</u>\n", 737*7c478bd9Sstevel@tonic-gate "ADDR", "TP", "FLAG", "PID", "COMM", "VNODE", "PATH"); 738*7c478bd9Sstevel@tonic-gate 739*7c478bd9Sstevel@tonic-gate return (mdb_pwalk("lock_graph", lminfo_cb, NULL, NULL)); 740*7c478bd9Sstevel@tonic-gate } 741*7c478bd9Sstevel@tonic-gate 742*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 743*7c478bd9Sstevel@tonic-gate int 744*7c478bd9Sstevel@tonic-gate seg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 745*7c478bd9Sstevel@tonic-gate { 746*7c478bd9Sstevel@tonic-gate struct seg s; 747*7c478bd9Sstevel@tonic-gate 748*7c478bd9Sstevel@tonic-gate if (argc != 0) 749*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 750*7c478bd9Sstevel@tonic-gate 751*7c478bd9Sstevel@tonic-gate if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) { 752*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%?s %?s %?s %?s %s%</u>\n", 753*7c478bd9Sstevel@tonic-gate "SEG", "BASE", "SIZE", "DATA", "OPS"); 754*7c478bd9Sstevel@tonic-gate } 755*7c478bd9Sstevel@tonic-gate 756*7c478bd9Sstevel@tonic-gate if (mdb_vread(&s, sizeof (s), addr) == -1) { 757*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read seg at %p", addr); 758*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 759*7c478bd9Sstevel@tonic-gate } 760*7c478bd9Sstevel@tonic-gate 761*7c478bd9Sstevel@tonic-gate mdb_printf("%?p %?p %?lx %?p %a\n", 762*7c478bd9Sstevel@tonic-gate addr, s.s_base, s.s_size, s.s_data, s.s_ops); 763*7c478bd9Sstevel@tonic-gate 764*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 765*7c478bd9Sstevel@tonic-gate } 766*7c478bd9Sstevel@tonic-gate 767*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 768*7c478bd9Sstevel@tonic-gate static int 769*7c478bd9Sstevel@tonic-gate pmap_walk_anon(uintptr_t addr, const struct anon *anon, int *nres) 770*7c478bd9Sstevel@tonic-gate { 771*7c478bd9Sstevel@tonic-gate uintptr_t pp = 772*7c478bd9Sstevel@tonic-gate mdb_vnode2page((uintptr_t)anon->an_vp, (uintptr_t)anon->an_off); 773*7c478bd9Sstevel@tonic-gate 774*7c478bd9Sstevel@tonic-gate if (pp != NULL) 775*7c478bd9Sstevel@tonic-gate (*nres)++; 776*7c478bd9Sstevel@tonic-gate 777*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 778*7c478bd9Sstevel@tonic-gate } 779*7c478bd9Sstevel@tonic-gate 780*7c478bd9Sstevel@tonic-gate static int 781*7c478bd9Sstevel@tonic-gate pmap_walk_seg(uintptr_t addr, const struct seg *seg, uintptr_t segvn) 782*7c478bd9Sstevel@tonic-gate { 783*7c478bd9Sstevel@tonic-gate 784*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024); 785*7c478bd9Sstevel@tonic-gate 786*7c478bd9Sstevel@tonic-gate if (segvn == (uintptr_t)seg->s_ops) { 787*7c478bd9Sstevel@tonic-gate struct segvn_data svn; 788*7c478bd9Sstevel@tonic-gate int nres = 0; 789*7c478bd9Sstevel@tonic-gate 790*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data); 791*7c478bd9Sstevel@tonic-gate 792*7c478bd9Sstevel@tonic-gate if (svn.amp == NULL) { 793*7c478bd9Sstevel@tonic-gate mdb_printf(" %8s", ""); 794*7c478bd9Sstevel@tonic-gate goto drive_on; 795*7c478bd9Sstevel@tonic-gate } 796*7c478bd9Sstevel@tonic-gate 797*7c478bd9Sstevel@tonic-gate /* 798*7c478bd9Sstevel@tonic-gate * We've got an amp for this segment; walk through 799*7c478bd9Sstevel@tonic-gate * the amp, and determine mappings. 800*7c478bd9Sstevel@tonic-gate */ 801*7c478bd9Sstevel@tonic-gate if (mdb_pwalk("anon", (mdb_walk_cb_t)pmap_walk_anon, 802*7c478bd9Sstevel@tonic-gate &nres, (uintptr_t)svn.amp) == -1) 803*7c478bd9Sstevel@tonic-gate mdb_warn("failed to walk anon (amp=%p)", svn.amp); 804*7c478bd9Sstevel@tonic-gate 805*7c478bd9Sstevel@tonic-gate mdb_printf(" %7dk", (nres * PAGESIZE) / 1024); 806*7c478bd9Sstevel@tonic-gate drive_on: 807*7c478bd9Sstevel@tonic-gate 808*7c478bd9Sstevel@tonic-gate if (svn.vp != NULL) { 809*7c478bd9Sstevel@tonic-gate char buf[29]; 810*7c478bd9Sstevel@tonic-gate 811*7c478bd9Sstevel@tonic-gate mdb_vnode2path((uintptr_t)svn.vp, buf, sizeof (buf)); 812*7c478bd9Sstevel@tonic-gate mdb_printf(" %s", buf); 813*7c478bd9Sstevel@tonic-gate } else 814*7c478bd9Sstevel@tonic-gate mdb_printf(" [ anon ]"); 815*7c478bd9Sstevel@tonic-gate } 816*7c478bd9Sstevel@tonic-gate 817*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 818*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 819*7c478bd9Sstevel@tonic-gate } 820*7c478bd9Sstevel@tonic-gate 821*7c478bd9Sstevel@tonic-gate static int 822*7c478bd9Sstevel@tonic-gate pmap_walk_seg_quick(uintptr_t addr, const struct seg *seg, uintptr_t segvn) 823*7c478bd9Sstevel@tonic-gate { 824*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024); 825*7c478bd9Sstevel@tonic-gate 826*7c478bd9Sstevel@tonic-gate if (segvn == (uintptr_t)seg->s_ops) { 827*7c478bd9Sstevel@tonic-gate struct segvn_data svn; 828*7c478bd9Sstevel@tonic-gate 829*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data); 830*7c478bd9Sstevel@tonic-gate 831*7c478bd9Sstevel@tonic-gate if (svn.vp != NULL) { 832*7c478bd9Sstevel@tonic-gate mdb_printf(" %0?p", svn.vp); 833*7c478bd9Sstevel@tonic-gate } else { 834*7c478bd9Sstevel@tonic-gate mdb_printf(" [ anon ]"); 835*7c478bd9Sstevel@tonic-gate } 836*7c478bd9Sstevel@tonic-gate } 837*7c478bd9Sstevel@tonic-gate 838*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 839*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 840*7c478bd9Sstevel@tonic-gate } 841*7c478bd9Sstevel@tonic-gate 842*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 843*7c478bd9Sstevel@tonic-gate int 844*7c478bd9Sstevel@tonic-gate pmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 845*7c478bd9Sstevel@tonic-gate { 846*7c478bd9Sstevel@tonic-gate uintptr_t segvn; 847*7c478bd9Sstevel@tonic-gate proc_t proc; 848*7c478bd9Sstevel@tonic-gate uint_t quick = FALSE; 849*7c478bd9Sstevel@tonic-gate mdb_walk_cb_t cb = (mdb_walk_cb_t)pmap_walk_seg; 850*7c478bd9Sstevel@tonic-gate 851*7c478bd9Sstevel@tonic-gate GElf_Sym sym; 852*7c478bd9Sstevel@tonic-gate 853*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 854*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 855*7c478bd9Sstevel@tonic-gate 856*7c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 857*7c478bd9Sstevel@tonic-gate 'q', MDB_OPT_SETBITS, TRUE, &quick, NULL) != argc) 858*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 859*7c478bd9Sstevel@tonic-gate 860*7c478bd9Sstevel@tonic-gate if (mdb_vread(&proc, sizeof (proc), addr) == -1) { 861*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc at %p", addr); 862*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 863*7c478bd9Sstevel@tonic-gate } 864*7c478bd9Sstevel@tonic-gate 865*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("segvn_ops", &sym) == 0) 866*7c478bd9Sstevel@tonic-gate segvn = (uintptr_t)sym.st_value; 867*7c478bd9Sstevel@tonic-gate else 868*7c478bd9Sstevel@tonic-gate segvn = NULL; 869*7c478bd9Sstevel@tonic-gate 870*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %?s %8s ", "SEG", "BASE", "SIZE"); 871*7c478bd9Sstevel@tonic-gate 872*7c478bd9Sstevel@tonic-gate if (quick) { 873*7c478bd9Sstevel@tonic-gate mdb_printf("VNODE\n"); 874*7c478bd9Sstevel@tonic-gate cb = (mdb_walk_cb_t)pmap_walk_seg_quick; 875*7c478bd9Sstevel@tonic-gate } else { 876*7c478bd9Sstevel@tonic-gate mdb_printf("%8s %s\n", "RES", "PATH"); 877*7c478bd9Sstevel@tonic-gate } 878*7c478bd9Sstevel@tonic-gate 879*7c478bd9Sstevel@tonic-gate if (mdb_pwalk("seg", cb, (void *)segvn, (uintptr_t)proc.p_as) == -1) { 880*7c478bd9Sstevel@tonic-gate mdb_warn("failed to walk segments of as %p", proc.p_as); 881*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 882*7c478bd9Sstevel@tonic-gate } 883*7c478bd9Sstevel@tonic-gate 884*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 885*7c478bd9Sstevel@tonic-gate } 886*7c478bd9Sstevel@tonic-gate 887*7c478bd9Sstevel@tonic-gate typedef struct anon_walk_data { 888*7c478bd9Sstevel@tonic-gate uintptr_t *aw_levone; 889*7c478bd9Sstevel@tonic-gate uintptr_t *aw_levtwo; 890*7c478bd9Sstevel@tonic-gate int aw_nlevone; 891*7c478bd9Sstevel@tonic-gate int aw_levone_ndx; 892*7c478bd9Sstevel@tonic-gate int aw_levtwo_ndx; 893*7c478bd9Sstevel@tonic-gate struct anon_map aw_amp; 894*7c478bd9Sstevel@tonic-gate struct anon_hdr aw_ahp; 895*7c478bd9Sstevel@tonic-gate } anon_walk_data_t; 896*7c478bd9Sstevel@tonic-gate 897*7c478bd9Sstevel@tonic-gate int 898*7c478bd9Sstevel@tonic-gate anon_walk_init(mdb_walk_state_t *wsp) 899*7c478bd9Sstevel@tonic-gate { 900*7c478bd9Sstevel@tonic-gate anon_walk_data_t *aw; 901*7c478bd9Sstevel@tonic-gate 902*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 903*7c478bd9Sstevel@tonic-gate mdb_warn("anon walk doesn't support global walks\n"); 904*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 905*7c478bd9Sstevel@tonic-gate } 906*7c478bd9Sstevel@tonic-gate 907*7c478bd9Sstevel@tonic-gate aw = mdb_alloc(sizeof (anon_walk_data_t), UM_SLEEP); 908*7c478bd9Sstevel@tonic-gate 909*7c478bd9Sstevel@tonic-gate if (mdb_vread(&aw->aw_amp, sizeof (aw->aw_amp), wsp->walk_addr) == -1) { 910*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read anon map at %p", wsp->walk_addr); 911*7c478bd9Sstevel@tonic-gate mdb_free(aw, sizeof (anon_walk_data_t)); 912*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 913*7c478bd9Sstevel@tonic-gate } 914*7c478bd9Sstevel@tonic-gate 915*7c478bd9Sstevel@tonic-gate if (mdb_vread(&aw->aw_ahp, sizeof (aw->aw_ahp), 916*7c478bd9Sstevel@tonic-gate (uintptr_t)(aw->aw_amp.ahp)) == -1) { 917*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read anon hdr ptr at %p", aw->aw_amp.ahp); 918*7c478bd9Sstevel@tonic-gate mdb_free(aw, sizeof (anon_walk_data_t)); 919*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 920*7c478bd9Sstevel@tonic-gate } 921*7c478bd9Sstevel@tonic-gate 922*7c478bd9Sstevel@tonic-gate if (aw->aw_ahp.size <= ANON_CHUNK_SIZE || 923*7c478bd9Sstevel@tonic-gate (aw->aw_ahp.flags & ANON_ALLOC_FORCE)) { 924*7c478bd9Sstevel@tonic-gate aw->aw_nlevone = aw->aw_ahp.size; 925*7c478bd9Sstevel@tonic-gate aw->aw_levtwo = NULL; 926*7c478bd9Sstevel@tonic-gate } else { 927*7c478bd9Sstevel@tonic-gate aw->aw_nlevone = 928*7c478bd9Sstevel@tonic-gate (aw->aw_ahp.size + ANON_CHUNK_OFF) >> ANON_CHUNK_SHIFT; 929*7c478bd9Sstevel@tonic-gate aw->aw_levtwo = 930*7c478bd9Sstevel@tonic-gate mdb_zalloc(ANON_CHUNK_SIZE * sizeof (uintptr_t), UM_SLEEP); 931*7c478bd9Sstevel@tonic-gate } 932*7c478bd9Sstevel@tonic-gate 933*7c478bd9Sstevel@tonic-gate aw->aw_levone = 934*7c478bd9Sstevel@tonic-gate mdb_alloc(aw->aw_nlevone * sizeof (uintptr_t), UM_SLEEP); 935*7c478bd9Sstevel@tonic-gate 936*7c478bd9Sstevel@tonic-gate aw->aw_levone_ndx = 0; 937*7c478bd9Sstevel@tonic-gate aw->aw_levtwo_ndx = 0; 938*7c478bd9Sstevel@tonic-gate 939*7c478bd9Sstevel@tonic-gate mdb_vread(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t), 940*7c478bd9Sstevel@tonic-gate (uintptr_t)aw->aw_ahp.array_chunk); 941*7c478bd9Sstevel@tonic-gate 942*7c478bd9Sstevel@tonic-gate if (aw->aw_levtwo != NULL) { 943*7c478bd9Sstevel@tonic-gate while (aw->aw_levone[aw->aw_levone_ndx] == NULL) { 944*7c478bd9Sstevel@tonic-gate aw->aw_levone_ndx++; 945*7c478bd9Sstevel@tonic-gate if (aw->aw_levone_ndx == aw->aw_nlevone) { 946*7c478bd9Sstevel@tonic-gate mdb_warn("corrupt anon; couldn't" 947*7c478bd9Sstevel@tonic-gate "find ptr to lev two map"); 948*7c478bd9Sstevel@tonic-gate goto out; 949*7c478bd9Sstevel@tonic-gate } 950*7c478bd9Sstevel@tonic-gate } 951*7c478bd9Sstevel@tonic-gate 952*7c478bd9Sstevel@tonic-gate mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t), 953*7c478bd9Sstevel@tonic-gate aw->aw_levone[aw->aw_levone_ndx]); 954*7c478bd9Sstevel@tonic-gate } 955*7c478bd9Sstevel@tonic-gate 956*7c478bd9Sstevel@tonic-gate out: 957*7c478bd9Sstevel@tonic-gate wsp->walk_data = aw; 958*7c478bd9Sstevel@tonic-gate return (0); 959*7c478bd9Sstevel@tonic-gate } 960*7c478bd9Sstevel@tonic-gate 961*7c478bd9Sstevel@tonic-gate int 962*7c478bd9Sstevel@tonic-gate anon_walk_step(mdb_walk_state_t *wsp) 963*7c478bd9Sstevel@tonic-gate { 964*7c478bd9Sstevel@tonic-gate int status; 965*7c478bd9Sstevel@tonic-gate anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data; 966*7c478bd9Sstevel@tonic-gate struct anon anon; 967*7c478bd9Sstevel@tonic-gate uintptr_t anonptr; 968*7c478bd9Sstevel@tonic-gate 969*7c478bd9Sstevel@tonic-gate again: 970*7c478bd9Sstevel@tonic-gate /* 971*7c478bd9Sstevel@tonic-gate * Once we've walked through level one, we're done. 972*7c478bd9Sstevel@tonic-gate */ 973*7c478bd9Sstevel@tonic-gate if (aw->aw_levone_ndx == aw->aw_nlevone) 974*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 975*7c478bd9Sstevel@tonic-gate 976*7c478bd9Sstevel@tonic-gate if (aw->aw_levtwo == NULL) { 977*7c478bd9Sstevel@tonic-gate anonptr = aw->aw_levone[aw->aw_levone_ndx]; 978*7c478bd9Sstevel@tonic-gate aw->aw_levone_ndx++; 979*7c478bd9Sstevel@tonic-gate } else { 980*7c478bd9Sstevel@tonic-gate anonptr = aw->aw_levtwo[aw->aw_levtwo_ndx]; 981*7c478bd9Sstevel@tonic-gate aw->aw_levtwo_ndx++; 982*7c478bd9Sstevel@tonic-gate 983*7c478bd9Sstevel@tonic-gate if (aw->aw_levtwo_ndx == ANON_CHUNK_SIZE) { 984*7c478bd9Sstevel@tonic-gate aw->aw_levtwo_ndx = 0; 985*7c478bd9Sstevel@tonic-gate 986*7c478bd9Sstevel@tonic-gate do { 987*7c478bd9Sstevel@tonic-gate aw->aw_levone_ndx++; 988*7c478bd9Sstevel@tonic-gate 989*7c478bd9Sstevel@tonic-gate if (aw->aw_levone_ndx == aw->aw_nlevone) 990*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 991*7c478bd9Sstevel@tonic-gate } while (aw->aw_levone[aw->aw_levone_ndx] == NULL); 992*7c478bd9Sstevel@tonic-gate 993*7c478bd9Sstevel@tonic-gate mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE * 994*7c478bd9Sstevel@tonic-gate sizeof (uintptr_t), 995*7c478bd9Sstevel@tonic-gate aw->aw_levone[aw->aw_levone_ndx]); 996*7c478bd9Sstevel@tonic-gate } 997*7c478bd9Sstevel@tonic-gate } 998*7c478bd9Sstevel@tonic-gate 999*7c478bd9Sstevel@tonic-gate if (anonptr != NULL) { 1000*7c478bd9Sstevel@tonic-gate mdb_vread(&anon, sizeof (anon), anonptr); 1001*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback(anonptr, &anon, wsp->walk_cbdata); 1002*7c478bd9Sstevel@tonic-gate } else 1003*7c478bd9Sstevel@tonic-gate goto again; 1004*7c478bd9Sstevel@tonic-gate 1005*7c478bd9Sstevel@tonic-gate return (status); 1006*7c478bd9Sstevel@tonic-gate } 1007*7c478bd9Sstevel@tonic-gate 1008*7c478bd9Sstevel@tonic-gate void 1009*7c478bd9Sstevel@tonic-gate anon_walk_fini(mdb_walk_state_t *wsp) 1010*7c478bd9Sstevel@tonic-gate { 1011*7c478bd9Sstevel@tonic-gate anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data; 1012*7c478bd9Sstevel@tonic-gate 1013*7c478bd9Sstevel@tonic-gate if (aw->aw_levtwo != NULL) 1014*7c478bd9Sstevel@tonic-gate mdb_free(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t)); 1015*7c478bd9Sstevel@tonic-gate 1016*7c478bd9Sstevel@tonic-gate mdb_free(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t)); 1017*7c478bd9Sstevel@tonic-gate mdb_free(aw, sizeof (anon_walk_data_t)); 1018*7c478bd9Sstevel@tonic-gate } 1019*7c478bd9Sstevel@tonic-gate 1020*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1021*7c478bd9Sstevel@tonic-gate int 1022*7c478bd9Sstevel@tonic-gate whereopen_fwalk(uintptr_t addr, struct file *f, uintptr_t *target) 1023*7c478bd9Sstevel@tonic-gate { 1024*7c478bd9Sstevel@tonic-gate if ((uintptr_t)f->f_vnode == *target) { 1025*7c478bd9Sstevel@tonic-gate mdb_printf("file %p\n", addr); 1026*7c478bd9Sstevel@tonic-gate *target = NULL; 1027*7c478bd9Sstevel@tonic-gate } 1028*7c478bd9Sstevel@tonic-gate 1029*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1030*7c478bd9Sstevel@tonic-gate } 1031*7c478bd9Sstevel@tonic-gate 1032*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1033*7c478bd9Sstevel@tonic-gate int 1034*7c478bd9Sstevel@tonic-gate whereopen_pwalk(uintptr_t addr, void *ignored, uintptr_t *target) 1035*7c478bd9Sstevel@tonic-gate { 1036*7c478bd9Sstevel@tonic-gate uintptr_t t = *target; 1037*7c478bd9Sstevel@tonic-gate 1038*7c478bd9Sstevel@tonic-gate if (mdb_pwalk("file", (mdb_walk_cb_t)whereopen_fwalk, &t, addr) == -1) { 1039*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't file walk proc %p", addr); 1040*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1041*7c478bd9Sstevel@tonic-gate } 1042*7c478bd9Sstevel@tonic-gate 1043*7c478bd9Sstevel@tonic-gate if (t == NULL) 1044*7c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr); 1045*7c478bd9Sstevel@tonic-gate 1046*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1047*7c478bd9Sstevel@tonic-gate } 1048*7c478bd9Sstevel@tonic-gate 1049*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1050*7c478bd9Sstevel@tonic-gate int 1051*7c478bd9Sstevel@tonic-gate whereopen(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1052*7c478bd9Sstevel@tonic-gate { 1053*7c478bd9Sstevel@tonic-gate uintptr_t target = addr; 1054*7c478bd9Sstevel@tonic-gate 1055*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || addr == NULL) 1056*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 1057*7c478bd9Sstevel@tonic-gate 1058*7c478bd9Sstevel@tonic-gate if (mdb_walk("proc", (mdb_walk_cb_t)whereopen_pwalk, &target) == -1) { 1059*7c478bd9Sstevel@tonic-gate mdb_warn("can't proc walk"); 1060*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1061*7c478bd9Sstevel@tonic-gate } 1062*7c478bd9Sstevel@tonic-gate 1063*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 1064*7c478bd9Sstevel@tonic-gate } 1065*7c478bd9Sstevel@tonic-gate 1066*7c478bd9Sstevel@tonic-gate typedef struct datafmt { 1067*7c478bd9Sstevel@tonic-gate char *hdr1; 1068*7c478bd9Sstevel@tonic-gate char *hdr2; 1069*7c478bd9Sstevel@tonic-gate char *dashes; 1070*7c478bd9Sstevel@tonic-gate char *fmt; 1071*7c478bd9Sstevel@tonic-gate } datafmt_t; 1072*7c478bd9Sstevel@tonic-gate 1073*7c478bd9Sstevel@tonic-gate static datafmt_t kmemfmt[] = { 1074*7c478bd9Sstevel@tonic-gate { "cache ", "name ", 1075*7c478bd9Sstevel@tonic-gate "-------------------------", "%-25s " }, 1076*7c478bd9Sstevel@tonic-gate { " buf", " size", "------", "%6u " }, 1077*7c478bd9Sstevel@tonic-gate { " buf", "in use", "------", "%6u " }, 1078*7c478bd9Sstevel@tonic-gate { " buf", " total", "------", "%6u " }, 1079*7c478bd9Sstevel@tonic-gate { " memory", " in use", "---------", "%9u " }, 1080*7c478bd9Sstevel@tonic-gate { " alloc", " succeed", "---------", "%9u " }, 1081*7c478bd9Sstevel@tonic-gate { "alloc", " fail", "-----", "%5u " }, 1082*7c478bd9Sstevel@tonic-gate { NULL, NULL, NULL, NULL } 1083*7c478bd9Sstevel@tonic-gate }; 1084*7c478bd9Sstevel@tonic-gate 1085*7c478bd9Sstevel@tonic-gate static datafmt_t vmemfmt[] = { 1086*7c478bd9Sstevel@tonic-gate { "vmem ", "name ", 1087*7c478bd9Sstevel@tonic-gate "-------------------------", "%-*s " }, 1088*7c478bd9Sstevel@tonic-gate { " memory", " in use", "---------", "%9llu " }, 1089*7c478bd9Sstevel@tonic-gate { " memory", " total", "----------", "%10llu " }, 1090*7c478bd9Sstevel@tonic-gate { " memory", " import", "---------", "%9llu " }, 1091*7c478bd9Sstevel@tonic-gate { " alloc", " succeed", "---------", "%9llu " }, 1092*7c478bd9Sstevel@tonic-gate { "alloc", " fail", "-----", "%5llu " }, 1093*7c478bd9Sstevel@tonic-gate { NULL, NULL, NULL, NULL } 1094*7c478bd9Sstevel@tonic-gate }; 1095*7c478bd9Sstevel@tonic-gate 1096*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1097*7c478bd9Sstevel@tonic-gate static int 1098*7c478bd9Sstevel@tonic-gate kmastat_cpu_avail(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *avail) 1099*7c478bd9Sstevel@tonic-gate { 1100*7c478bd9Sstevel@tonic-gate if (ccp->cc_rounds > 0) 1101*7c478bd9Sstevel@tonic-gate *avail += ccp->cc_rounds; 1102*7c478bd9Sstevel@tonic-gate if (ccp->cc_prounds > 0) 1103*7c478bd9Sstevel@tonic-gate *avail += ccp->cc_prounds; 1104*7c478bd9Sstevel@tonic-gate 1105*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1106*7c478bd9Sstevel@tonic-gate } 1107*7c478bd9Sstevel@tonic-gate 1108*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1109*7c478bd9Sstevel@tonic-gate static int 1110*7c478bd9Sstevel@tonic-gate kmastat_cpu_alloc(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *alloc) 1111*7c478bd9Sstevel@tonic-gate { 1112*7c478bd9Sstevel@tonic-gate *alloc += ccp->cc_alloc; 1113*7c478bd9Sstevel@tonic-gate 1114*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1115*7c478bd9Sstevel@tonic-gate } 1116*7c478bd9Sstevel@tonic-gate 1117*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1118*7c478bd9Sstevel@tonic-gate static int 1119*7c478bd9Sstevel@tonic-gate kmastat_slab_avail(uintptr_t addr, const kmem_slab_t *sp, int *avail) 1120*7c478bd9Sstevel@tonic-gate { 1121*7c478bd9Sstevel@tonic-gate *avail += sp->slab_chunks - sp->slab_refcnt; 1122*7c478bd9Sstevel@tonic-gate 1123*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1124*7c478bd9Sstevel@tonic-gate } 1125*7c478bd9Sstevel@tonic-gate 1126*7c478bd9Sstevel@tonic-gate typedef struct kmastat_vmem { 1127*7c478bd9Sstevel@tonic-gate uintptr_t kv_addr; 1128*7c478bd9Sstevel@tonic-gate struct kmastat_vmem *kv_next; 1129*7c478bd9Sstevel@tonic-gate int kv_meminuse; 1130*7c478bd9Sstevel@tonic-gate int kv_alloc; 1131*7c478bd9Sstevel@tonic-gate int kv_fail; 1132*7c478bd9Sstevel@tonic-gate } kmastat_vmem_t; 1133*7c478bd9Sstevel@tonic-gate 1134*7c478bd9Sstevel@tonic-gate static int 1135*7c478bd9Sstevel@tonic-gate kmastat_cache(uintptr_t addr, const kmem_cache_t *cp, kmastat_vmem_t **kvp) 1136*7c478bd9Sstevel@tonic-gate { 1137*7c478bd9Sstevel@tonic-gate kmastat_vmem_t *kv; 1138*7c478bd9Sstevel@tonic-gate datafmt_t *dfp = kmemfmt; 1139*7c478bd9Sstevel@tonic-gate int magsize; 1140*7c478bd9Sstevel@tonic-gate 1141*7c478bd9Sstevel@tonic-gate int avail, alloc, total; 1142*7c478bd9Sstevel@tonic-gate size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) * 1143*7c478bd9Sstevel@tonic-gate cp->cache_slabsize; 1144*7c478bd9Sstevel@tonic-gate 1145*7c478bd9Sstevel@tonic-gate mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)kmastat_cpu_avail; 1146*7c478bd9Sstevel@tonic-gate mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)kmastat_cpu_alloc; 1147*7c478bd9Sstevel@tonic-gate mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)kmastat_slab_avail; 1148*7c478bd9Sstevel@tonic-gate 1149*7c478bd9Sstevel@tonic-gate magsize = kmem_get_magsize(cp); 1150*7c478bd9Sstevel@tonic-gate 1151*7c478bd9Sstevel@tonic-gate alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc; 1152*7c478bd9Sstevel@tonic-gate avail = cp->cache_full.ml_total * magsize; 1153*7c478bd9Sstevel@tonic-gate total = cp->cache_buftotal; 1154*7c478bd9Sstevel@tonic-gate 1155*7c478bd9Sstevel@tonic-gate (void) mdb_pwalk("kmem_cpu_cache", cpu_alloc, &alloc, addr); 1156*7c478bd9Sstevel@tonic-gate (void) mdb_pwalk("kmem_cpu_cache", cpu_avail, &avail, addr); 1157*7c478bd9Sstevel@tonic-gate (void) mdb_pwalk("kmem_slab_partial", slab_avail, &avail, addr); 1158*7c478bd9Sstevel@tonic-gate 1159*7c478bd9Sstevel@tonic-gate for (kv = *kvp; kv != NULL; kv = kv->kv_next) { 1160*7c478bd9Sstevel@tonic-gate if (kv->kv_addr == (uintptr_t)cp->cache_arena) 1161*7c478bd9Sstevel@tonic-gate goto out; 1162*7c478bd9Sstevel@tonic-gate } 1163*7c478bd9Sstevel@tonic-gate 1164*7c478bd9Sstevel@tonic-gate kv = mdb_zalloc(sizeof (kmastat_vmem_t), UM_SLEEP | UM_GC); 1165*7c478bd9Sstevel@tonic-gate kv->kv_next = *kvp; 1166*7c478bd9Sstevel@tonic-gate kv->kv_addr = (uintptr_t)cp->cache_arena; 1167*7c478bd9Sstevel@tonic-gate *kvp = kv; 1168*7c478bd9Sstevel@tonic-gate out: 1169*7c478bd9Sstevel@tonic-gate kv->kv_meminuse += meminuse; 1170*7c478bd9Sstevel@tonic-gate kv->kv_alloc += alloc; 1171*7c478bd9Sstevel@tonic-gate kv->kv_fail += cp->cache_alloc_fail; 1172*7c478bd9Sstevel@tonic-gate 1173*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_name); 1174*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_bufsize); 1175*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, total - avail); 1176*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, total); 1177*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, meminuse); 1178*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, alloc); 1179*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_alloc_fail); 1180*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1181*7c478bd9Sstevel@tonic-gate 1182*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1183*7c478bd9Sstevel@tonic-gate } 1184*7c478bd9Sstevel@tonic-gate 1185*7c478bd9Sstevel@tonic-gate static int 1186*7c478bd9Sstevel@tonic-gate kmastat_vmem_totals(uintptr_t addr, const vmem_t *v, kmastat_vmem_t *kv) 1187*7c478bd9Sstevel@tonic-gate { 1188*7c478bd9Sstevel@tonic-gate size_t len; 1189*7c478bd9Sstevel@tonic-gate 1190*7c478bd9Sstevel@tonic-gate while (kv != NULL && kv->kv_addr != addr) 1191*7c478bd9Sstevel@tonic-gate kv = kv->kv_next; 1192*7c478bd9Sstevel@tonic-gate 1193*7c478bd9Sstevel@tonic-gate if (kv == NULL || kv->kv_alloc == 0) 1194*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1195*7c478bd9Sstevel@tonic-gate 1196*7c478bd9Sstevel@tonic-gate len = MIN(17, strlen(v->vm_name)); 1197*7c478bd9Sstevel@tonic-gate 1198*7c478bd9Sstevel@tonic-gate mdb_printf("Total [%s]%*s %6s %6s %6s %9u %9u %5u\n", v->vm_name, 1199*7c478bd9Sstevel@tonic-gate 17 - len, "", "", "", "", 1200*7c478bd9Sstevel@tonic-gate kv->kv_meminuse, kv->kv_alloc, kv->kv_fail); 1201*7c478bd9Sstevel@tonic-gate 1202*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1203*7c478bd9Sstevel@tonic-gate } 1204*7c478bd9Sstevel@tonic-gate 1205*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1206*7c478bd9Sstevel@tonic-gate static int 1207*7c478bd9Sstevel@tonic-gate kmastat_vmem(uintptr_t addr, const vmem_t *v, void *ignored) 1208*7c478bd9Sstevel@tonic-gate { 1209*7c478bd9Sstevel@tonic-gate datafmt_t *dfp = vmemfmt; 1210*7c478bd9Sstevel@tonic-gate const vmem_kstat_t *vkp = &v->vm_kstat; 1211*7c478bd9Sstevel@tonic-gate uintptr_t paddr; 1212*7c478bd9Sstevel@tonic-gate vmem_t parent; 1213*7c478bd9Sstevel@tonic-gate int ident = 0; 1214*7c478bd9Sstevel@tonic-gate 1215*7c478bd9Sstevel@tonic-gate for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) { 1216*7c478bd9Sstevel@tonic-gate if (mdb_vread(&parent, sizeof (parent), paddr) == -1) { 1217*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't trace %p's ancestry", addr); 1218*7c478bd9Sstevel@tonic-gate ident = 0; 1219*7c478bd9Sstevel@tonic-gate break; 1220*7c478bd9Sstevel@tonic-gate } 1221*7c478bd9Sstevel@tonic-gate paddr = (uintptr_t)parent.vm_source; 1222*7c478bd9Sstevel@tonic-gate } 1223*7c478bd9Sstevel@tonic-gate 1224*7c478bd9Sstevel@tonic-gate mdb_printf("%*s", ident, ""); 1225*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name); 1226*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_mem_inuse.value.ui64); 1227*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_mem_total.value.ui64); 1228*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_mem_import.value.ui64); 1229*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_alloc.value.ui64); 1230*7c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_fail.value.ui64); 1231*7c478bd9Sstevel@tonic-gate 1232*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1233*7c478bd9Sstevel@tonic-gate 1234*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1235*7c478bd9Sstevel@tonic-gate } 1236*7c478bd9Sstevel@tonic-gate 1237*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1238*7c478bd9Sstevel@tonic-gate int 1239*7c478bd9Sstevel@tonic-gate kmastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1240*7c478bd9Sstevel@tonic-gate { 1241*7c478bd9Sstevel@tonic-gate kmastat_vmem_t *kv = NULL; 1242*7c478bd9Sstevel@tonic-gate datafmt_t *dfp; 1243*7c478bd9Sstevel@tonic-gate 1244*7c478bd9Sstevel@tonic-gate if (argc != 0) 1245*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 1246*7c478bd9Sstevel@tonic-gate 1247*7c478bd9Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 1248*7c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr1); 1249*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1250*7c478bd9Sstevel@tonic-gate 1251*7c478bd9Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 1252*7c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr2); 1253*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1254*7c478bd9Sstevel@tonic-gate 1255*7c478bd9Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 1256*7c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 1257*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1258*7c478bd9Sstevel@tonic-gate 1259*7c478bd9Sstevel@tonic-gate if (mdb_walk("kmem_cache", (mdb_walk_cb_t)kmastat_cache, &kv) == -1) { 1260*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'kmem_cache'"); 1261*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1262*7c478bd9Sstevel@tonic-gate } 1263*7c478bd9Sstevel@tonic-gate 1264*7c478bd9Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 1265*7c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 1266*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1267*7c478bd9Sstevel@tonic-gate 1268*7c478bd9Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem_totals, kv) == -1) { 1269*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'vmem'"); 1270*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1271*7c478bd9Sstevel@tonic-gate } 1272*7c478bd9Sstevel@tonic-gate 1273*7c478bd9Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 1274*7c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 1275*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1276*7c478bd9Sstevel@tonic-gate 1277*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1278*7c478bd9Sstevel@tonic-gate 1279*7c478bd9Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 1280*7c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr1); 1281*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1282*7c478bd9Sstevel@tonic-gate 1283*7c478bd9Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 1284*7c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr2); 1285*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1286*7c478bd9Sstevel@tonic-gate 1287*7c478bd9Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 1288*7c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 1289*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1290*7c478bd9Sstevel@tonic-gate 1291*7c478bd9Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem, NULL) == -1) { 1292*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'vmem'"); 1293*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1294*7c478bd9Sstevel@tonic-gate } 1295*7c478bd9Sstevel@tonic-gate 1296*7c478bd9Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 1297*7c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 1298*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 1299*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 1300*7c478bd9Sstevel@tonic-gate } 1301*7c478bd9Sstevel@tonic-gate 1302*7c478bd9Sstevel@tonic-gate /* 1303*7c478bd9Sstevel@tonic-gate * Our ::kgrep callback scans the entire kernel VA space (kas). kas is made 1304*7c478bd9Sstevel@tonic-gate * up of a set of 'struct seg's. We could just scan each seg en masse, but 1305*7c478bd9Sstevel@tonic-gate * unfortunately, a few of the segs are both large and sparse, so we could 1306*7c478bd9Sstevel@tonic-gate * spend quite a bit of time scanning VAs which have no backing pages. 1307*7c478bd9Sstevel@tonic-gate * 1308*7c478bd9Sstevel@tonic-gate * So for the few very sparse segs, we skip the segment itself, and scan 1309*7c478bd9Sstevel@tonic-gate * the allocated vmem_segs in the vmem arena which manages that part of kas. 1310*7c478bd9Sstevel@tonic-gate * Currently, we do this for: 1311*7c478bd9Sstevel@tonic-gate * 1312*7c478bd9Sstevel@tonic-gate * SEG VMEM ARENA 1313*7c478bd9Sstevel@tonic-gate * kvseg heap_arena 1314*7c478bd9Sstevel@tonic-gate * kvseg32 heap32_arena 1315*7c478bd9Sstevel@tonic-gate * kvseg_core heap_core_arena 1316*7c478bd9Sstevel@tonic-gate * 1317*7c478bd9Sstevel@tonic-gate * In addition, we skip the segkpm segment in its entirety, since it is very 1318*7c478bd9Sstevel@tonic-gate * sparse, and contains no new kernel data. 1319*7c478bd9Sstevel@tonic-gate */ 1320*7c478bd9Sstevel@tonic-gate typedef struct kgrep_walk_data { 1321*7c478bd9Sstevel@tonic-gate kgrep_cb_func *kg_cb; 1322*7c478bd9Sstevel@tonic-gate void *kg_cbdata; 1323*7c478bd9Sstevel@tonic-gate uintptr_t kg_kvseg; 1324*7c478bd9Sstevel@tonic-gate uintptr_t kg_kvseg32; 1325*7c478bd9Sstevel@tonic-gate uintptr_t kg_kvseg_core; 1326*7c478bd9Sstevel@tonic-gate uintptr_t kg_segkpm; 1327*7c478bd9Sstevel@tonic-gate } kgrep_walk_data_t; 1328*7c478bd9Sstevel@tonic-gate 1329*7c478bd9Sstevel@tonic-gate static int 1330*7c478bd9Sstevel@tonic-gate kgrep_walk_seg(uintptr_t addr, const struct seg *seg, kgrep_walk_data_t *kg) 1331*7c478bd9Sstevel@tonic-gate { 1332*7c478bd9Sstevel@tonic-gate uintptr_t base = (uintptr_t)seg->s_base; 1333*7c478bd9Sstevel@tonic-gate 1334*7c478bd9Sstevel@tonic-gate if (addr == kg->kg_kvseg || addr == kg->kg_kvseg32 || 1335*7c478bd9Sstevel@tonic-gate addr == kg->kg_kvseg_core) 1336*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1337*7c478bd9Sstevel@tonic-gate 1338*7c478bd9Sstevel@tonic-gate if ((uintptr_t)seg->s_ops == kg->kg_segkpm) 1339*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1340*7c478bd9Sstevel@tonic-gate 1341*7c478bd9Sstevel@tonic-gate return (kg->kg_cb(base, base + seg->s_size, kg->kg_cbdata)); 1342*7c478bd9Sstevel@tonic-gate } 1343*7c478bd9Sstevel@tonic-gate 1344*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1345*7c478bd9Sstevel@tonic-gate static int 1346*7c478bd9Sstevel@tonic-gate kgrep_walk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg) 1347*7c478bd9Sstevel@tonic-gate { 1348*7c478bd9Sstevel@tonic-gate return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata)); 1349*7c478bd9Sstevel@tonic-gate } 1350*7c478bd9Sstevel@tonic-gate 1351*7c478bd9Sstevel@tonic-gate static int 1352*7c478bd9Sstevel@tonic-gate kgrep_walk_vmem(uintptr_t addr, const vmem_t *vmem, kgrep_walk_data_t *kg) 1353*7c478bd9Sstevel@tonic-gate { 1354*7c478bd9Sstevel@tonic-gate if (strcmp(vmem->vm_name, "heap") != 0 && 1355*7c478bd9Sstevel@tonic-gate strcmp(vmem->vm_name, "heap32") != 0 && 1356*7c478bd9Sstevel@tonic-gate strcmp(vmem->vm_name, "heap_core") != 0) 1357*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1358*7c478bd9Sstevel@tonic-gate 1359*7c478bd9Sstevel@tonic-gate if (mdb_pwalk("vmem_alloc", 1360*7c478bd9Sstevel@tonic-gate (mdb_walk_cb_t)kgrep_walk_vseg, kg, addr) == -1) { 1361*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk vmem_alloc for vmem %p", addr); 1362*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1363*7c478bd9Sstevel@tonic-gate } 1364*7c478bd9Sstevel@tonic-gate 1365*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1366*7c478bd9Sstevel@tonic-gate } 1367*7c478bd9Sstevel@tonic-gate 1368*7c478bd9Sstevel@tonic-gate int 1369*7c478bd9Sstevel@tonic-gate kgrep_subr(kgrep_cb_func *cb, void *cbdata) 1370*7c478bd9Sstevel@tonic-gate { 1371*7c478bd9Sstevel@tonic-gate GElf_Sym kas, kvseg, kvseg32, kvseg_core, segkpm; 1372*7c478bd9Sstevel@tonic-gate kgrep_walk_data_t kg; 1373*7c478bd9Sstevel@tonic-gate 1374*7c478bd9Sstevel@tonic-gate if (mdb_get_state() == MDB_STATE_RUNNING) { 1375*7c478bd9Sstevel@tonic-gate mdb_warn("kgrep can only be run on a system " 1376*7c478bd9Sstevel@tonic-gate "dump or under kmdb; see dumpadm(1M)\n"); 1377*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1378*7c478bd9Sstevel@tonic-gate } 1379*7c478bd9Sstevel@tonic-gate 1380*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("kas", &kas) == -1) { 1381*7c478bd9Sstevel@tonic-gate mdb_warn("failed to locate 'kas' symbol\n"); 1382*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1383*7c478bd9Sstevel@tonic-gate } 1384*7c478bd9Sstevel@tonic-gate 1385*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("kvseg", &kvseg) == -1) { 1386*7c478bd9Sstevel@tonic-gate mdb_warn("failed to locate 'kvseg' symbol\n"); 1387*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1388*7c478bd9Sstevel@tonic-gate } 1389*7c478bd9Sstevel@tonic-gate 1390*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("kvseg32", &kvseg32) == -1) { 1391*7c478bd9Sstevel@tonic-gate mdb_warn("failed to locate 'kvseg32' symbol\n"); 1392*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1393*7c478bd9Sstevel@tonic-gate } 1394*7c478bd9Sstevel@tonic-gate 1395*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("kvseg_core", &kvseg_core) == -1) { 1396*7c478bd9Sstevel@tonic-gate mdb_warn("failed to locate 'kvseg_core' symbol\n"); 1397*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1398*7c478bd9Sstevel@tonic-gate } 1399*7c478bd9Sstevel@tonic-gate 1400*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("segkpm_ops", &segkpm) == -1) { 1401*7c478bd9Sstevel@tonic-gate mdb_warn("failed to locate 'segkpm_ops' symbol\n"); 1402*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1403*7c478bd9Sstevel@tonic-gate } 1404*7c478bd9Sstevel@tonic-gate 1405*7c478bd9Sstevel@tonic-gate kg.kg_cb = cb; 1406*7c478bd9Sstevel@tonic-gate kg.kg_cbdata = cbdata; 1407*7c478bd9Sstevel@tonic-gate kg.kg_kvseg = (uintptr_t)kvseg.st_value; 1408*7c478bd9Sstevel@tonic-gate kg.kg_kvseg32 = (uintptr_t)kvseg32.st_value; 1409*7c478bd9Sstevel@tonic-gate kg.kg_kvseg_core = (uintptr_t)kvseg_core.st_value; 1410*7c478bd9Sstevel@tonic-gate kg.kg_segkpm = (uintptr_t)segkpm.st_value; 1411*7c478bd9Sstevel@tonic-gate 1412*7c478bd9Sstevel@tonic-gate if (mdb_pwalk("seg", (mdb_walk_cb_t)kgrep_walk_seg, 1413*7c478bd9Sstevel@tonic-gate &kg, kas.st_value) == -1) { 1414*7c478bd9Sstevel@tonic-gate mdb_warn("failed to walk kas segments"); 1415*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1416*7c478bd9Sstevel@tonic-gate } 1417*7c478bd9Sstevel@tonic-gate 1418*7c478bd9Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)kgrep_walk_vmem, &kg) == -1) { 1419*7c478bd9Sstevel@tonic-gate mdb_warn("failed to walk heap/heap32 vmem arenas"); 1420*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1421*7c478bd9Sstevel@tonic-gate } 1422*7c478bd9Sstevel@tonic-gate 1423*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 1424*7c478bd9Sstevel@tonic-gate } 1425*7c478bd9Sstevel@tonic-gate 1426*7c478bd9Sstevel@tonic-gate size_t 1427*7c478bd9Sstevel@tonic-gate kgrep_subr_pagesize(void) 1428*7c478bd9Sstevel@tonic-gate { 1429*7c478bd9Sstevel@tonic-gate return (PAGESIZE); 1430*7c478bd9Sstevel@tonic-gate } 1431*7c478bd9Sstevel@tonic-gate 1432*7c478bd9Sstevel@tonic-gate typedef struct file_walk_data { 1433*7c478bd9Sstevel@tonic-gate struct uf_entry *fw_flist; 1434*7c478bd9Sstevel@tonic-gate int fw_flistsz; 1435*7c478bd9Sstevel@tonic-gate int fw_ndx; 1436*7c478bd9Sstevel@tonic-gate int fw_nofiles; 1437*7c478bd9Sstevel@tonic-gate } file_walk_data_t; 1438*7c478bd9Sstevel@tonic-gate 1439*7c478bd9Sstevel@tonic-gate int 1440*7c478bd9Sstevel@tonic-gate file_walk_init(mdb_walk_state_t *wsp) 1441*7c478bd9Sstevel@tonic-gate { 1442*7c478bd9Sstevel@tonic-gate file_walk_data_t *fw; 1443*7c478bd9Sstevel@tonic-gate proc_t p; 1444*7c478bd9Sstevel@tonic-gate 1445*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 1446*7c478bd9Sstevel@tonic-gate mdb_warn("file walk doesn't support global walks\n"); 1447*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1448*7c478bd9Sstevel@tonic-gate } 1449*7c478bd9Sstevel@tonic-gate 1450*7c478bd9Sstevel@tonic-gate fw = mdb_alloc(sizeof (file_walk_data_t), UM_SLEEP); 1451*7c478bd9Sstevel@tonic-gate 1452*7c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), wsp->walk_addr) == -1) { 1453*7c478bd9Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t)); 1454*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc structure at %p", wsp->walk_addr); 1455*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1456*7c478bd9Sstevel@tonic-gate } 1457*7c478bd9Sstevel@tonic-gate 1458*7c478bd9Sstevel@tonic-gate if (p.p_user.u_finfo.fi_nfiles == 0) { 1459*7c478bd9Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t)); 1460*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1461*7c478bd9Sstevel@tonic-gate } 1462*7c478bd9Sstevel@tonic-gate 1463*7c478bd9Sstevel@tonic-gate fw->fw_nofiles = p.p_user.u_finfo.fi_nfiles; 1464*7c478bd9Sstevel@tonic-gate fw->fw_flistsz = sizeof (struct uf_entry) * fw->fw_nofiles; 1465*7c478bd9Sstevel@tonic-gate fw->fw_flist = mdb_alloc(fw->fw_flistsz, UM_SLEEP); 1466*7c478bd9Sstevel@tonic-gate 1467*7c478bd9Sstevel@tonic-gate if (mdb_vread(fw->fw_flist, fw->fw_flistsz, 1468*7c478bd9Sstevel@tonic-gate (uintptr_t)p.p_user.u_finfo.fi_list) == -1) { 1469*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read file array at %p", 1470*7c478bd9Sstevel@tonic-gate p.p_user.u_finfo.fi_list); 1471*7c478bd9Sstevel@tonic-gate mdb_free(fw->fw_flist, fw->fw_flistsz); 1472*7c478bd9Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t)); 1473*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1474*7c478bd9Sstevel@tonic-gate } 1475*7c478bd9Sstevel@tonic-gate 1476*7c478bd9Sstevel@tonic-gate fw->fw_ndx = 0; 1477*7c478bd9Sstevel@tonic-gate wsp->walk_data = fw; 1478*7c478bd9Sstevel@tonic-gate 1479*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1480*7c478bd9Sstevel@tonic-gate } 1481*7c478bd9Sstevel@tonic-gate 1482*7c478bd9Sstevel@tonic-gate int 1483*7c478bd9Sstevel@tonic-gate file_walk_step(mdb_walk_state_t *wsp) 1484*7c478bd9Sstevel@tonic-gate { 1485*7c478bd9Sstevel@tonic-gate file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data; 1486*7c478bd9Sstevel@tonic-gate struct file file; 1487*7c478bd9Sstevel@tonic-gate uintptr_t fp; 1488*7c478bd9Sstevel@tonic-gate 1489*7c478bd9Sstevel@tonic-gate again: 1490*7c478bd9Sstevel@tonic-gate if (fw->fw_ndx == fw->fw_nofiles) 1491*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1492*7c478bd9Sstevel@tonic-gate 1493*7c478bd9Sstevel@tonic-gate if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) == NULL) 1494*7c478bd9Sstevel@tonic-gate goto again; 1495*7c478bd9Sstevel@tonic-gate 1496*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&file, sizeof (file), (uintptr_t)fp); 1497*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(fp, &file, wsp->walk_cbdata)); 1498*7c478bd9Sstevel@tonic-gate } 1499*7c478bd9Sstevel@tonic-gate 1500*7c478bd9Sstevel@tonic-gate int 1501*7c478bd9Sstevel@tonic-gate allfile_walk_step(mdb_walk_state_t *wsp) 1502*7c478bd9Sstevel@tonic-gate { 1503*7c478bd9Sstevel@tonic-gate file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data; 1504*7c478bd9Sstevel@tonic-gate struct file file; 1505*7c478bd9Sstevel@tonic-gate uintptr_t fp; 1506*7c478bd9Sstevel@tonic-gate 1507*7c478bd9Sstevel@tonic-gate if (fw->fw_ndx == fw->fw_nofiles) 1508*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1509*7c478bd9Sstevel@tonic-gate 1510*7c478bd9Sstevel@tonic-gate if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) != NULL) 1511*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&file, sizeof (file), (uintptr_t)fp); 1512*7c478bd9Sstevel@tonic-gate else 1513*7c478bd9Sstevel@tonic-gate bzero(&file, sizeof (file)); 1514*7c478bd9Sstevel@tonic-gate 1515*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(fp, &file, wsp->walk_cbdata)); 1516*7c478bd9Sstevel@tonic-gate } 1517*7c478bd9Sstevel@tonic-gate 1518*7c478bd9Sstevel@tonic-gate void 1519*7c478bd9Sstevel@tonic-gate file_walk_fini(mdb_walk_state_t *wsp) 1520*7c478bd9Sstevel@tonic-gate { 1521*7c478bd9Sstevel@tonic-gate file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data; 1522*7c478bd9Sstevel@tonic-gate 1523*7c478bd9Sstevel@tonic-gate mdb_free(fw->fw_flist, fw->fw_flistsz); 1524*7c478bd9Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t)); 1525*7c478bd9Sstevel@tonic-gate } 1526*7c478bd9Sstevel@tonic-gate 1527*7c478bd9Sstevel@tonic-gate int 1528*7c478bd9Sstevel@tonic-gate port_walk_init(mdb_walk_state_t *wsp) 1529*7c478bd9Sstevel@tonic-gate { 1530*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 1531*7c478bd9Sstevel@tonic-gate mdb_warn("port walk doesn't support global walks\n"); 1532*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1533*7c478bd9Sstevel@tonic-gate } 1534*7c478bd9Sstevel@tonic-gate 1535*7c478bd9Sstevel@tonic-gate if (mdb_layered_walk("file", wsp) == -1) { 1536*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk 'file'"); 1537*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1538*7c478bd9Sstevel@tonic-gate } 1539*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1540*7c478bd9Sstevel@tonic-gate } 1541*7c478bd9Sstevel@tonic-gate 1542*7c478bd9Sstevel@tonic-gate int 1543*7c478bd9Sstevel@tonic-gate port_walk_step(mdb_walk_state_t *wsp) 1544*7c478bd9Sstevel@tonic-gate { 1545*7c478bd9Sstevel@tonic-gate struct vnode vn; 1546*7c478bd9Sstevel@tonic-gate uintptr_t vp; 1547*7c478bd9Sstevel@tonic-gate uintptr_t pp; 1548*7c478bd9Sstevel@tonic-gate struct port port; 1549*7c478bd9Sstevel@tonic-gate 1550*7c478bd9Sstevel@tonic-gate vp = (uintptr_t)((struct file *)wsp->walk_layer)->f_vnode; 1551*7c478bd9Sstevel@tonic-gate if (mdb_vread(&vn, sizeof (vn), vp) == -1) { 1552*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read vnode_t at %p", vp); 1553*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1554*7c478bd9Sstevel@tonic-gate } 1555*7c478bd9Sstevel@tonic-gate if (vn.v_type != VPORT) 1556*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1557*7c478bd9Sstevel@tonic-gate 1558*7c478bd9Sstevel@tonic-gate pp = (uintptr_t)vn.v_data; 1559*7c478bd9Sstevel@tonic-gate if (mdb_vread(&port, sizeof (port), pp) == -1) { 1560*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read port_t at %p", pp); 1561*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1562*7c478bd9Sstevel@tonic-gate } 1563*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(pp, &port, wsp->walk_cbdata)); 1564*7c478bd9Sstevel@tonic-gate } 1565*7c478bd9Sstevel@tonic-gate 1566*7c478bd9Sstevel@tonic-gate typedef struct portev_walk_data { 1567*7c478bd9Sstevel@tonic-gate list_node_t *pev_node; 1568*7c478bd9Sstevel@tonic-gate list_node_t *pev_last; 1569*7c478bd9Sstevel@tonic-gate size_t pev_offset; 1570*7c478bd9Sstevel@tonic-gate } portev_walk_data_t; 1571*7c478bd9Sstevel@tonic-gate 1572*7c478bd9Sstevel@tonic-gate int 1573*7c478bd9Sstevel@tonic-gate portev_walk_init(mdb_walk_state_t *wsp) 1574*7c478bd9Sstevel@tonic-gate { 1575*7c478bd9Sstevel@tonic-gate portev_walk_data_t *pevd; 1576*7c478bd9Sstevel@tonic-gate struct port port; 1577*7c478bd9Sstevel@tonic-gate struct vnode vn; 1578*7c478bd9Sstevel@tonic-gate struct list *list; 1579*7c478bd9Sstevel@tonic-gate uintptr_t vp; 1580*7c478bd9Sstevel@tonic-gate 1581*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 1582*7c478bd9Sstevel@tonic-gate mdb_warn("portev walk doesn't support global walks\n"); 1583*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1584*7c478bd9Sstevel@tonic-gate } 1585*7c478bd9Sstevel@tonic-gate 1586*7c478bd9Sstevel@tonic-gate pevd = mdb_alloc(sizeof (portev_walk_data_t), UM_SLEEP); 1587*7c478bd9Sstevel@tonic-gate 1588*7c478bd9Sstevel@tonic-gate if (mdb_vread(&port, sizeof (port), wsp->walk_addr) == -1) { 1589*7c478bd9Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t)); 1590*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read port structure at %p", wsp->walk_addr); 1591*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1592*7c478bd9Sstevel@tonic-gate } 1593*7c478bd9Sstevel@tonic-gate 1594*7c478bd9Sstevel@tonic-gate vp = (uintptr_t)port.port_vnode; 1595*7c478bd9Sstevel@tonic-gate if (mdb_vread(&vn, sizeof (vn), vp) == -1) { 1596*7c478bd9Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t)); 1597*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read vnode_t at %p", vp); 1598*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1599*7c478bd9Sstevel@tonic-gate } 1600*7c478bd9Sstevel@tonic-gate 1601*7c478bd9Sstevel@tonic-gate if (vn.v_type != VPORT) { 1602*7c478bd9Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t)); 1603*7c478bd9Sstevel@tonic-gate mdb_warn("input address (%p) does not point to an event port", 1604*7c478bd9Sstevel@tonic-gate wsp->walk_addr); 1605*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1606*7c478bd9Sstevel@tonic-gate } 1607*7c478bd9Sstevel@tonic-gate 1608*7c478bd9Sstevel@tonic-gate if (port.port_queue.portq_nent == 0) { 1609*7c478bd9Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t)); 1610*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1611*7c478bd9Sstevel@tonic-gate } 1612*7c478bd9Sstevel@tonic-gate list = &port.port_queue.portq_list; 1613*7c478bd9Sstevel@tonic-gate pevd->pev_offset = list->list_offset; 1614*7c478bd9Sstevel@tonic-gate pevd->pev_last = list->list_head.list_prev; 1615*7c478bd9Sstevel@tonic-gate pevd->pev_node = list->list_head.list_next; 1616*7c478bd9Sstevel@tonic-gate wsp->walk_data = pevd; 1617*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1618*7c478bd9Sstevel@tonic-gate } 1619*7c478bd9Sstevel@tonic-gate 1620*7c478bd9Sstevel@tonic-gate int 1621*7c478bd9Sstevel@tonic-gate portev_walk_step(mdb_walk_state_t *wsp) 1622*7c478bd9Sstevel@tonic-gate { 1623*7c478bd9Sstevel@tonic-gate portev_walk_data_t *pevd; 1624*7c478bd9Sstevel@tonic-gate struct port_kevent ev; 1625*7c478bd9Sstevel@tonic-gate uintptr_t evp; 1626*7c478bd9Sstevel@tonic-gate 1627*7c478bd9Sstevel@tonic-gate pevd = (portev_walk_data_t *)wsp->walk_data; 1628*7c478bd9Sstevel@tonic-gate 1629*7c478bd9Sstevel@tonic-gate if (pevd->pev_last == NULL) 1630*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1631*7c478bd9Sstevel@tonic-gate if (pevd->pev_node == pevd->pev_last) 1632*7c478bd9Sstevel@tonic-gate pevd->pev_last = NULL; /* last round */ 1633*7c478bd9Sstevel@tonic-gate 1634*7c478bd9Sstevel@tonic-gate evp = ((uintptr_t)(((char *)pevd->pev_node) - pevd->pev_offset)); 1635*7c478bd9Sstevel@tonic-gate if (mdb_vread(&ev, sizeof (ev), evp) == -1) { 1636*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read port_kevent at %p", evp); 1637*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1638*7c478bd9Sstevel@tonic-gate } 1639*7c478bd9Sstevel@tonic-gate pevd->pev_node = ev.portkev_node.list_next; 1640*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(evp, &ev, wsp->walk_cbdata)); 1641*7c478bd9Sstevel@tonic-gate } 1642*7c478bd9Sstevel@tonic-gate 1643*7c478bd9Sstevel@tonic-gate void 1644*7c478bd9Sstevel@tonic-gate portev_walk_fini(mdb_walk_state_t *wsp) 1645*7c478bd9Sstevel@tonic-gate { 1646*7c478bd9Sstevel@tonic-gate portev_walk_data_t *pevd = (portev_walk_data_t *)wsp->walk_data; 1647*7c478bd9Sstevel@tonic-gate 1648*7c478bd9Sstevel@tonic-gate if (pevd != NULL) 1649*7c478bd9Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t)); 1650*7c478bd9Sstevel@tonic-gate } 1651*7c478bd9Sstevel@tonic-gate 1652*7c478bd9Sstevel@tonic-gate typedef struct proc_walk_data { 1653*7c478bd9Sstevel@tonic-gate uintptr_t *pw_stack; 1654*7c478bd9Sstevel@tonic-gate int pw_depth; 1655*7c478bd9Sstevel@tonic-gate int pw_max; 1656*7c478bd9Sstevel@tonic-gate } proc_walk_data_t; 1657*7c478bd9Sstevel@tonic-gate 1658*7c478bd9Sstevel@tonic-gate int 1659*7c478bd9Sstevel@tonic-gate proc_walk_init(mdb_walk_state_t *wsp) 1660*7c478bd9Sstevel@tonic-gate { 1661*7c478bd9Sstevel@tonic-gate GElf_Sym sym; 1662*7c478bd9Sstevel@tonic-gate proc_walk_data_t *pw; 1663*7c478bd9Sstevel@tonic-gate 1664*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 1665*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("p0", &sym) == -1) { 1666*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'practive'"); 1667*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1668*7c478bd9Sstevel@tonic-gate } 1669*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)sym.st_value; 1670*7c478bd9Sstevel@tonic-gate } 1671*7c478bd9Sstevel@tonic-gate 1672*7c478bd9Sstevel@tonic-gate pw = mdb_zalloc(sizeof (proc_walk_data_t), UM_SLEEP); 1673*7c478bd9Sstevel@tonic-gate 1674*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&pw->pw_max, "nproc") == -1) { 1675*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'nproc'"); 1676*7c478bd9Sstevel@tonic-gate mdb_free(pw, sizeof (pw)); 1677*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1678*7c478bd9Sstevel@tonic-gate } 1679*7c478bd9Sstevel@tonic-gate 1680*7c478bd9Sstevel@tonic-gate pw->pw_stack = mdb_alloc(pw->pw_max * sizeof (uintptr_t), UM_SLEEP); 1681*7c478bd9Sstevel@tonic-gate wsp->walk_data = pw; 1682*7c478bd9Sstevel@tonic-gate 1683*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1684*7c478bd9Sstevel@tonic-gate } 1685*7c478bd9Sstevel@tonic-gate 1686*7c478bd9Sstevel@tonic-gate int 1687*7c478bd9Sstevel@tonic-gate proc_walk_step(mdb_walk_state_t *wsp) 1688*7c478bd9Sstevel@tonic-gate { 1689*7c478bd9Sstevel@tonic-gate proc_walk_data_t *pw = wsp->walk_data; 1690*7c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 1691*7c478bd9Sstevel@tonic-gate uintptr_t cld, sib; 1692*7c478bd9Sstevel@tonic-gate 1693*7c478bd9Sstevel@tonic-gate int status; 1694*7c478bd9Sstevel@tonic-gate proc_t pr; 1695*7c478bd9Sstevel@tonic-gate 1696*7c478bd9Sstevel@tonic-gate if (mdb_vread(&pr, sizeof (proc_t), addr) == -1) { 1697*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc at %p", addr); 1698*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1699*7c478bd9Sstevel@tonic-gate } 1700*7c478bd9Sstevel@tonic-gate 1701*7c478bd9Sstevel@tonic-gate cld = (uintptr_t)pr.p_child; 1702*7c478bd9Sstevel@tonic-gate sib = (uintptr_t)pr.p_sibling; 1703*7c478bd9Sstevel@tonic-gate 1704*7c478bd9Sstevel@tonic-gate if (pw->pw_depth > 0 && addr == pw->pw_stack[pw->pw_depth - 1]) { 1705*7c478bd9Sstevel@tonic-gate pw->pw_depth--; 1706*7c478bd9Sstevel@tonic-gate goto sib; 1707*7c478bd9Sstevel@tonic-gate } 1708*7c478bd9Sstevel@tonic-gate 1709*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback(addr, &pr, wsp->walk_cbdata); 1710*7c478bd9Sstevel@tonic-gate 1711*7c478bd9Sstevel@tonic-gate if (status != WALK_NEXT) 1712*7c478bd9Sstevel@tonic-gate return (status); 1713*7c478bd9Sstevel@tonic-gate 1714*7c478bd9Sstevel@tonic-gate if ((wsp->walk_addr = cld) != NULL) { 1715*7c478bd9Sstevel@tonic-gate if (mdb_vread(&pr, sizeof (proc_t), cld) == -1) { 1716*7c478bd9Sstevel@tonic-gate mdb_warn("proc %p has invalid p_child %p; skipping\n", 1717*7c478bd9Sstevel@tonic-gate addr, cld); 1718*7c478bd9Sstevel@tonic-gate goto sib; 1719*7c478bd9Sstevel@tonic-gate } 1720*7c478bd9Sstevel@tonic-gate 1721*7c478bd9Sstevel@tonic-gate pw->pw_stack[pw->pw_depth++] = addr; 1722*7c478bd9Sstevel@tonic-gate 1723*7c478bd9Sstevel@tonic-gate if (pw->pw_depth == pw->pw_max) { 1724*7c478bd9Sstevel@tonic-gate mdb_warn("depth %d exceeds max depth; try again\n", 1725*7c478bd9Sstevel@tonic-gate pw->pw_depth); 1726*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1727*7c478bd9Sstevel@tonic-gate } 1728*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1729*7c478bd9Sstevel@tonic-gate } 1730*7c478bd9Sstevel@tonic-gate 1731*7c478bd9Sstevel@tonic-gate sib: 1732*7c478bd9Sstevel@tonic-gate /* 1733*7c478bd9Sstevel@tonic-gate * We know that p0 has no siblings, and if another starting proc 1734*7c478bd9Sstevel@tonic-gate * was given, we don't want to walk its siblings anyway. 1735*7c478bd9Sstevel@tonic-gate */ 1736*7c478bd9Sstevel@tonic-gate if (pw->pw_depth == 0) 1737*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1738*7c478bd9Sstevel@tonic-gate 1739*7c478bd9Sstevel@tonic-gate if (sib != NULL && mdb_vread(&pr, sizeof (proc_t), sib) == -1) { 1740*7c478bd9Sstevel@tonic-gate mdb_warn("proc %p has invalid p_sibling %p; skipping\n", 1741*7c478bd9Sstevel@tonic-gate addr, sib); 1742*7c478bd9Sstevel@tonic-gate sib = NULL; 1743*7c478bd9Sstevel@tonic-gate } 1744*7c478bd9Sstevel@tonic-gate 1745*7c478bd9Sstevel@tonic-gate if ((wsp->walk_addr = sib) == NULL) { 1746*7c478bd9Sstevel@tonic-gate if (pw->pw_depth > 0) { 1747*7c478bd9Sstevel@tonic-gate wsp->walk_addr = pw->pw_stack[pw->pw_depth - 1]; 1748*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1749*7c478bd9Sstevel@tonic-gate } 1750*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1751*7c478bd9Sstevel@tonic-gate } 1752*7c478bd9Sstevel@tonic-gate 1753*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1754*7c478bd9Sstevel@tonic-gate } 1755*7c478bd9Sstevel@tonic-gate 1756*7c478bd9Sstevel@tonic-gate void 1757*7c478bd9Sstevel@tonic-gate proc_walk_fini(mdb_walk_state_t *wsp) 1758*7c478bd9Sstevel@tonic-gate { 1759*7c478bd9Sstevel@tonic-gate proc_walk_data_t *pw = wsp->walk_data; 1760*7c478bd9Sstevel@tonic-gate 1761*7c478bd9Sstevel@tonic-gate mdb_free(pw->pw_stack, pw->pw_max * sizeof (uintptr_t)); 1762*7c478bd9Sstevel@tonic-gate mdb_free(pw, sizeof (proc_walk_data_t)); 1763*7c478bd9Sstevel@tonic-gate } 1764*7c478bd9Sstevel@tonic-gate 1765*7c478bd9Sstevel@tonic-gate int 1766*7c478bd9Sstevel@tonic-gate task_walk_init(mdb_walk_state_t *wsp) 1767*7c478bd9Sstevel@tonic-gate { 1768*7c478bd9Sstevel@tonic-gate task_t task; 1769*7c478bd9Sstevel@tonic-gate 1770*7c478bd9Sstevel@tonic-gate if (mdb_vread(&task, sizeof (task_t), wsp->walk_addr) == -1) { 1771*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read task at %p", wsp->walk_addr); 1772*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1773*7c478bd9Sstevel@tonic-gate } 1774*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)task.tk_memb_list; 1775*7c478bd9Sstevel@tonic-gate wsp->walk_data = task.tk_memb_list; 1776*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1777*7c478bd9Sstevel@tonic-gate } 1778*7c478bd9Sstevel@tonic-gate 1779*7c478bd9Sstevel@tonic-gate int 1780*7c478bd9Sstevel@tonic-gate task_walk_step(mdb_walk_state_t *wsp) 1781*7c478bd9Sstevel@tonic-gate { 1782*7c478bd9Sstevel@tonic-gate proc_t proc; 1783*7c478bd9Sstevel@tonic-gate int status; 1784*7c478bd9Sstevel@tonic-gate 1785*7c478bd9Sstevel@tonic-gate if (mdb_vread(&proc, sizeof (proc_t), wsp->walk_addr) == -1) { 1786*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc at %p", wsp->walk_addr); 1787*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1788*7c478bd9Sstevel@tonic-gate } 1789*7c478bd9Sstevel@tonic-gate 1790*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata); 1791*7c478bd9Sstevel@tonic-gate 1792*7c478bd9Sstevel@tonic-gate if (proc.p_tasknext == wsp->walk_data) 1793*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1794*7c478bd9Sstevel@tonic-gate 1795*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)proc.p_tasknext; 1796*7c478bd9Sstevel@tonic-gate return (status); 1797*7c478bd9Sstevel@tonic-gate } 1798*7c478bd9Sstevel@tonic-gate 1799*7c478bd9Sstevel@tonic-gate int 1800*7c478bd9Sstevel@tonic-gate project_walk_init(mdb_walk_state_t *wsp) 1801*7c478bd9Sstevel@tonic-gate { 1802*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 1803*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&wsp->walk_addr, "proj0p") == -1) { 1804*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'proj0p'"); 1805*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1806*7c478bd9Sstevel@tonic-gate } 1807*7c478bd9Sstevel@tonic-gate } 1808*7c478bd9Sstevel@tonic-gate wsp->walk_data = (void *)wsp->walk_addr; 1809*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1810*7c478bd9Sstevel@tonic-gate } 1811*7c478bd9Sstevel@tonic-gate 1812*7c478bd9Sstevel@tonic-gate int 1813*7c478bd9Sstevel@tonic-gate project_walk_step(mdb_walk_state_t *wsp) 1814*7c478bd9Sstevel@tonic-gate { 1815*7c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 1816*7c478bd9Sstevel@tonic-gate kproject_t pj; 1817*7c478bd9Sstevel@tonic-gate int status; 1818*7c478bd9Sstevel@tonic-gate 1819*7c478bd9Sstevel@tonic-gate if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) { 1820*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read project at %p", addr); 1821*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1822*7c478bd9Sstevel@tonic-gate } 1823*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback(addr, &pj, wsp->walk_cbdata); 1824*7c478bd9Sstevel@tonic-gate if (status != WALK_NEXT) 1825*7c478bd9Sstevel@tonic-gate return (status); 1826*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)pj.kpj_next; 1827*7c478bd9Sstevel@tonic-gate if ((void *)wsp->walk_addr == wsp->walk_data) 1828*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1829*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1830*7c478bd9Sstevel@tonic-gate } 1831*7c478bd9Sstevel@tonic-gate 1832*7c478bd9Sstevel@tonic-gate static int 1833*7c478bd9Sstevel@tonic-gate generic_walk_step(mdb_walk_state_t *wsp) 1834*7c478bd9Sstevel@tonic-gate { 1835*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer, 1836*7c478bd9Sstevel@tonic-gate wsp->walk_cbdata)); 1837*7c478bd9Sstevel@tonic-gate } 1838*7c478bd9Sstevel@tonic-gate 1839*7c478bd9Sstevel@tonic-gate struct aw_info { 1840*7c478bd9Sstevel@tonic-gate void *aw_buff; /* buffer to hold the tree's data structure */ 1841*7c478bd9Sstevel@tonic-gate avl_tree_t aw_tree; /* copy of avl_tree_t being walked */ 1842*7c478bd9Sstevel@tonic-gate }; 1843*7c478bd9Sstevel@tonic-gate 1844*7c478bd9Sstevel@tonic-gate /* 1845*7c478bd9Sstevel@tonic-gate * common code used to find the addr of the the leftmost child below 1846*7c478bd9Sstevel@tonic-gate * an AVL node 1847*7c478bd9Sstevel@tonic-gate */ 1848*7c478bd9Sstevel@tonic-gate static uintptr_t 1849*7c478bd9Sstevel@tonic-gate avl_leftmostchild(uintptr_t addr, void * buff, size_t offset, size_t size) 1850*7c478bd9Sstevel@tonic-gate { 1851*7c478bd9Sstevel@tonic-gate avl_node_t *node = (avl_node_t *)((uintptr_t)buff + offset); 1852*7c478bd9Sstevel@tonic-gate 1853*7c478bd9Sstevel@tonic-gate for (;;) { 1854*7c478bd9Sstevel@tonic-gate addr -= offset; 1855*7c478bd9Sstevel@tonic-gate if (mdb_vread(buff, size, addr) == -1) { 1856*7c478bd9Sstevel@tonic-gate mdb_warn("read of avl_node_t failed: %p", addr); 1857*7c478bd9Sstevel@tonic-gate return ((uintptr_t)-1L); 1858*7c478bd9Sstevel@tonic-gate } 1859*7c478bd9Sstevel@tonic-gate if (node->avl_child[0] == NULL) 1860*7c478bd9Sstevel@tonic-gate break; 1861*7c478bd9Sstevel@tonic-gate addr = (uintptr_t)node->avl_child[0]; 1862*7c478bd9Sstevel@tonic-gate } 1863*7c478bd9Sstevel@tonic-gate return (addr); 1864*7c478bd9Sstevel@tonic-gate } 1865*7c478bd9Sstevel@tonic-gate 1866*7c478bd9Sstevel@tonic-gate /* 1867*7c478bd9Sstevel@tonic-gate * initialize a forward walk thru an avl tree. 1868*7c478bd9Sstevel@tonic-gate */ 1869*7c478bd9Sstevel@tonic-gate int 1870*7c478bd9Sstevel@tonic-gate avl_walk_init(mdb_walk_state_t *wsp) 1871*7c478bd9Sstevel@tonic-gate { 1872*7c478bd9Sstevel@tonic-gate struct aw_info *aw; 1873*7c478bd9Sstevel@tonic-gate avl_tree_t *tree; 1874*7c478bd9Sstevel@tonic-gate uintptr_t addr; 1875*7c478bd9Sstevel@tonic-gate 1876*7c478bd9Sstevel@tonic-gate /* 1877*7c478bd9Sstevel@tonic-gate * allocate the AVL walk data 1878*7c478bd9Sstevel@tonic-gate */ 1879*7c478bd9Sstevel@tonic-gate wsp->walk_data = aw = mdb_zalloc(sizeof (struct aw_info), UM_SLEEP); 1880*7c478bd9Sstevel@tonic-gate 1881*7c478bd9Sstevel@tonic-gate /* 1882*7c478bd9Sstevel@tonic-gate * get an mdb copy of the avl_tree_t being walked 1883*7c478bd9Sstevel@tonic-gate */ 1884*7c478bd9Sstevel@tonic-gate tree = &aw->aw_tree; 1885*7c478bd9Sstevel@tonic-gate if (mdb_vread(tree, sizeof (avl_tree_t), wsp->walk_addr) == -1) { 1886*7c478bd9Sstevel@tonic-gate mdb_warn("read of avl_tree_t failed: %p", wsp->walk_addr); 1887*7c478bd9Sstevel@tonic-gate goto error; 1888*7c478bd9Sstevel@tonic-gate } 1889*7c478bd9Sstevel@tonic-gate if (tree->avl_size < tree->avl_offset + sizeof (avl_node_t)) { 1890*7c478bd9Sstevel@tonic-gate mdb_warn("invalid avl_tree_t at %p, avl_size:%d, avl_offset:%d", 1891*7c478bd9Sstevel@tonic-gate wsp->walk_addr, tree->avl_size, tree->avl_offset); 1892*7c478bd9Sstevel@tonic-gate goto error; 1893*7c478bd9Sstevel@tonic-gate } 1894*7c478bd9Sstevel@tonic-gate 1895*7c478bd9Sstevel@tonic-gate /* 1896*7c478bd9Sstevel@tonic-gate * allocate a buffer to hold the mdb copy of tree's structs 1897*7c478bd9Sstevel@tonic-gate * "node" always points at the avl_node_t field inside the struct 1898*7c478bd9Sstevel@tonic-gate */ 1899*7c478bd9Sstevel@tonic-gate aw->aw_buff = mdb_zalloc(tree->avl_size, UM_SLEEP); 1900*7c478bd9Sstevel@tonic-gate 1901*7c478bd9Sstevel@tonic-gate /* 1902*7c478bd9Sstevel@tonic-gate * get the first avl_node_t address, use same algorithm 1903*7c478bd9Sstevel@tonic-gate * as avl_start() -- leftmost child in tree from root 1904*7c478bd9Sstevel@tonic-gate */ 1905*7c478bd9Sstevel@tonic-gate addr = (uintptr_t)tree->avl_root; 1906*7c478bd9Sstevel@tonic-gate if (addr == NULL) { 1907*7c478bd9Sstevel@tonic-gate wsp->walk_addr = NULL; 1908*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1909*7c478bd9Sstevel@tonic-gate } 1910*7c478bd9Sstevel@tonic-gate addr = avl_leftmostchild(addr, aw->aw_buff, tree->avl_offset, 1911*7c478bd9Sstevel@tonic-gate tree->avl_size); 1912*7c478bd9Sstevel@tonic-gate if (addr == (uintptr_t)-1L) 1913*7c478bd9Sstevel@tonic-gate goto error; 1914*7c478bd9Sstevel@tonic-gate 1915*7c478bd9Sstevel@tonic-gate wsp->walk_addr = addr; 1916*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1917*7c478bd9Sstevel@tonic-gate 1918*7c478bd9Sstevel@tonic-gate error: 1919*7c478bd9Sstevel@tonic-gate if (aw->aw_buff != NULL) 1920*7c478bd9Sstevel@tonic-gate mdb_free(aw->aw_buff, sizeof (tree->avl_size)); 1921*7c478bd9Sstevel@tonic-gate mdb_free(aw, sizeof (struct aw_info)); 1922*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1923*7c478bd9Sstevel@tonic-gate } 1924*7c478bd9Sstevel@tonic-gate 1925*7c478bd9Sstevel@tonic-gate /* 1926*7c478bd9Sstevel@tonic-gate * At each step, visit (callback) the current node, then move to the next 1927*7c478bd9Sstevel@tonic-gate * in the AVL tree. Uses the same algorithm as avl_walk(). 1928*7c478bd9Sstevel@tonic-gate */ 1929*7c478bd9Sstevel@tonic-gate int 1930*7c478bd9Sstevel@tonic-gate avl_walk_step(mdb_walk_state_t *wsp) 1931*7c478bd9Sstevel@tonic-gate { 1932*7c478bd9Sstevel@tonic-gate struct aw_info *aw; 1933*7c478bd9Sstevel@tonic-gate size_t offset; 1934*7c478bd9Sstevel@tonic-gate size_t size; 1935*7c478bd9Sstevel@tonic-gate uintptr_t addr; 1936*7c478bd9Sstevel@tonic-gate avl_node_t *node; 1937*7c478bd9Sstevel@tonic-gate int status; 1938*7c478bd9Sstevel@tonic-gate int was_child; 1939*7c478bd9Sstevel@tonic-gate 1940*7c478bd9Sstevel@tonic-gate /* 1941*7c478bd9Sstevel@tonic-gate * don't walk past the end of the tree! 1942*7c478bd9Sstevel@tonic-gate */ 1943*7c478bd9Sstevel@tonic-gate addr = wsp->walk_addr; 1944*7c478bd9Sstevel@tonic-gate if (addr == NULL) 1945*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 1946*7c478bd9Sstevel@tonic-gate 1947*7c478bd9Sstevel@tonic-gate aw = (struct aw_info *)wsp->walk_data; 1948*7c478bd9Sstevel@tonic-gate size = aw->aw_tree.avl_size; 1949*7c478bd9Sstevel@tonic-gate offset = aw->aw_tree.avl_offset; 1950*7c478bd9Sstevel@tonic-gate node = (avl_node_t *)((uintptr_t)aw->aw_buff + offset); 1951*7c478bd9Sstevel@tonic-gate 1952*7c478bd9Sstevel@tonic-gate /* 1953*7c478bd9Sstevel@tonic-gate * must read the current node for the call back to use 1954*7c478bd9Sstevel@tonic-gate */ 1955*7c478bd9Sstevel@tonic-gate if (mdb_vread(aw->aw_buff, size, addr) == -1) { 1956*7c478bd9Sstevel@tonic-gate mdb_warn("read of avl_node_t failed: %p", addr); 1957*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1958*7c478bd9Sstevel@tonic-gate } 1959*7c478bd9Sstevel@tonic-gate 1960*7c478bd9Sstevel@tonic-gate /* 1961*7c478bd9Sstevel@tonic-gate * do the call back 1962*7c478bd9Sstevel@tonic-gate */ 1963*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback(addr, aw->aw_buff, wsp->walk_cbdata); 1964*7c478bd9Sstevel@tonic-gate if (status != WALK_NEXT) 1965*7c478bd9Sstevel@tonic-gate return (status); 1966*7c478bd9Sstevel@tonic-gate 1967*7c478bd9Sstevel@tonic-gate /* 1968*7c478bd9Sstevel@tonic-gate * move to the next node.... 1969*7c478bd9Sstevel@tonic-gate * note we read in new nodes, so the pointer to the buffer is fixed 1970*7c478bd9Sstevel@tonic-gate */ 1971*7c478bd9Sstevel@tonic-gate 1972*7c478bd9Sstevel@tonic-gate /* 1973*7c478bd9Sstevel@tonic-gate * if the node has a right child then go to it and then all the way 1974*7c478bd9Sstevel@tonic-gate * thru as many left children as possible 1975*7c478bd9Sstevel@tonic-gate */ 1976*7c478bd9Sstevel@tonic-gate addr = (uintptr_t)node->avl_child[1]; 1977*7c478bd9Sstevel@tonic-gate if (addr != NULL) { 1978*7c478bd9Sstevel@tonic-gate addr = avl_leftmostchild(addr, aw->aw_buff, offset, size); 1979*7c478bd9Sstevel@tonic-gate if (addr == (uintptr_t)-1L) 1980*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1981*7c478bd9Sstevel@tonic-gate 1982*7c478bd9Sstevel@tonic-gate /* 1983*7c478bd9Sstevel@tonic-gate * othewise return to parent nodes, stopping if we ever return from 1984*7c478bd9Sstevel@tonic-gate * a left child 1985*7c478bd9Sstevel@tonic-gate */ 1986*7c478bd9Sstevel@tonic-gate } else { 1987*7c478bd9Sstevel@tonic-gate for (;;) { 1988*7c478bd9Sstevel@tonic-gate was_child = AVL_XCHILD(node); 1989*7c478bd9Sstevel@tonic-gate addr = (uintptr_t)AVL_XPARENT(node); 1990*7c478bd9Sstevel@tonic-gate if (addr == NULL) 1991*7c478bd9Sstevel@tonic-gate break; 1992*7c478bd9Sstevel@tonic-gate addr -= offset; 1993*7c478bd9Sstevel@tonic-gate if (was_child == 0) /* stop on return from left child */ 1994*7c478bd9Sstevel@tonic-gate break; 1995*7c478bd9Sstevel@tonic-gate if (mdb_vread(aw->aw_buff, size, addr) == -1) { 1996*7c478bd9Sstevel@tonic-gate mdb_warn("read of avl_node_t failed: %p", addr); 1997*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 1998*7c478bd9Sstevel@tonic-gate } 1999*7c478bd9Sstevel@tonic-gate } 2000*7c478bd9Sstevel@tonic-gate } 2001*7c478bd9Sstevel@tonic-gate 2002*7c478bd9Sstevel@tonic-gate wsp->walk_addr = addr; 2003*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2004*7c478bd9Sstevel@tonic-gate } 2005*7c478bd9Sstevel@tonic-gate 2006*7c478bd9Sstevel@tonic-gate /* 2007*7c478bd9Sstevel@tonic-gate * Release the memory allocated for the walk 2008*7c478bd9Sstevel@tonic-gate */ 2009*7c478bd9Sstevel@tonic-gate void 2010*7c478bd9Sstevel@tonic-gate avl_walk_fini(mdb_walk_state_t *wsp) 2011*7c478bd9Sstevel@tonic-gate { 2012*7c478bd9Sstevel@tonic-gate struct aw_info *aw; 2013*7c478bd9Sstevel@tonic-gate 2014*7c478bd9Sstevel@tonic-gate aw = (struct aw_info *)wsp->walk_data; 2015*7c478bd9Sstevel@tonic-gate 2016*7c478bd9Sstevel@tonic-gate if (aw == NULL) 2017*7c478bd9Sstevel@tonic-gate return; 2018*7c478bd9Sstevel@tonic-gate 2019*7c478bd9Sstevel@tonic-gate if (aw->aw_buff != NULL) 2020*7c478bd9Sstevel@tonic-gate mdb_free(aw->aw_buff, aw->aw_tree.avl_size); 2021*7c478bd9Sstevel@tonic-gate 2022*7c478bd9Sstevel@tonic-gate mdb_free(aw, sizeof (struct aw_info)); 2023*7c478bd9Sstevel@tonic-gate } 2024*7c478bd9Sstevel@tonic-gate 2025*7c478bd9Sstevel@tonic-gate 2026*7c478bd9Sstevel@tonic-gate int 2027*7c478bd9Sstevel@tonic-gate seg_walk_init(mdb_walk_state_t *wsp) 2028*7c478bd9Sstevel@tonic-gate { 2029*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 2030*7c478bd9Sstevel@tonic-gate mdb_warn("seg walk must begin at struct as *\n"); 2031*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2032*7c478bd9Sstevel@tonic-gate } 2033*7c478bd9Sstevel@tonic-gate 2034*7c478bd9Sstevel@tonic-gate /* 2035*7c478bd9Sstevel@tonic-gate * this is really just a wrapper to AVL tree walk 2036*7c478bd9Sstevel@tonic-gate */ 2037*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)&((struct as *)wsp->walk_addr)->a_segtree; 2038*7c478bd9Sstevel@tonic-gate return (avl_walk_init(wsp)); 2039*7c478bd9Sstevel@tonic-gate } 2040*7c478bd9Sstevel@tonic-gate 2041*7c478bd9Sstevel@tonic-gate static int 2042*7c478bd9Sstevel@tonic-gate cpu_walk_cmp(const void *l, const void *r) 2043*7c478bd9Sstevel@tonic-gate { 2044*7c478bd9Sstevel@tonic-gate uintptr_t lhs = *((uintptr_t *)l); 2045*7c478bd9Sstevel@tonic-gate uintptr_t rhs = *((uintptr_t *)r); 2046*7c478bd9Sstevel@tonic-gate cpu_t lcpu, rcpu; 2047*7c478bd9Sstevel@tonic-gate 2048*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&lcpu, sizeof (lcpu), lhs); 2049*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&rcpu, sizeof (rcpu), rhs); 2050*7c478bd9Sstevel@tonic-gate 2051*7c478bd9Sstevel@tonic-gate if (lcpu.cpu_id < rcpu.cpu_id) 2052*7c478bd9Sstevel@tonic-gate return (-1); 2053*7c478bd9Sstevel@tonic-gate 2054*7c478bd9Sstevel@tonic-gate if (lcpu.cpu_id > rcpu.cpu_id) 2055*7c478bd9Sstevel@tonic-gate return (1); 2056*7c478bd9Sstevel@tonic-gate 2057*7c478bd9Sstevel@tonic-gate return (0); 2058*7c478bd9Sstevel@tonic-gate } 2059*7c478bd9Sstevel@tonic-gate 2060*7c478bd9Sstevel@tonic-gate typedef struct cpu_walk { 2061*7c478bd9Sstevel@tonic-gate uintptr_t *cw_array; 2062*7c478bd9Sstevel@tonic-gate int cw_ndx; 2063*7c478bd9Sstevel@tonic-gate } cpu_walk_t; 2064*7c478bd9Sstevel@tonic-gate 2065*7c478bd9Sstevel@tonic-gate int 2066*7c478bd9Sstevel@tonic-gate cpu_walk_init(mdb_walk_state_t *wsp) 2067*7c478bd9Sstevel@tonic-gate { 2068*7c478bd9Sstevel@tonic-gate cpu_walk_t *cw; 2069*7c478bd9Sstevel@tonic-gate int max_ncpus, i = 0; 2070*7c478bd9Sstevel@tonic-gate uintptr_t current, first; 2071*7c478bd9Sstevel@tonic-gate cpu_t cpu, panic_cpu; 2072*7c478bd9Sstevel@tonic-gate uintptr_t panicstr, addr; 2073*7c478bd9Sstevel@tonic-gate GElf_Sym sym; 2074*7c478bd9Sstevel@tonic-gate 2075*7c478bd9Sstevel@tonic-gate cw = mdb_zalloc(sizeof (cpu_walk_t), UM_SLEEP | UM_GC); 2076*7c478bd9Sstevel@tonic-gate 2077*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) { 2078*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'max_ncpus'"); 2079*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2080*7c478bd9Sstevel@tonic-gate } 2081*7c478bd9Sstevel@tonic-gate 2082*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&panicstr, "panicstr") == -1) { 2083*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'panicstr'"); 2084*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2085*7c478bd9Sstevel@tonic-gate } 2086*7c478bd9Sstevel@tonic-gate 2087*7c478bd9Sstevel@tonic-gate if (panicstr != NULL) { 2088*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("panic_cpu", &sym) == -1) { 2089*7c478bd9Sstevel@tonic-gate mdb_warn("failed to find 'panic_cpu'"); 2090*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2091*7c478bd9Sstevel@tonic-gate } 2092*7c478bd9Sstevel@tonic-gate 2093*7c478bd9Sstevel@tonic-gate addr = (uintptr_t)sym.st_value; 2094*7c478bd9Sstevel@tonic-gate 2095*7c478bd9Sstevel@tonic-gate if (mdb_vread(&panic_cpu, sizeof (cpu_t), addr) == -1) { 2096*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'panic_cpu'"); 2097*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2098*7c478bd9Sstevel@tonic-gate } 2099*7c478bd9Sstevel@tonic-gate } 2100*7c478bd9Sstevel@tonic-gate 2101*7c478bd9Sstevel@tonic-gate /* 2102*7c478bd9Sstevel@tonic-gate * Unfortunately, there is no platform-independent way to walk 2103*7c478bd9Sstevel@tonic-gate * CPUs in ID order. We therefore loop through in cpu_next order, 2104*7c478bd9Sstevel@tonic-gate * building an array of CPU pointers which will subsequently be 2105*7c478bd9Sstevel@tonic-gate * sorted. 2106*7c478bd9Sstevel@tonic-gate */ 2107*7c478bd9Sstevel@tonic-gate cw->cw_array = 2108*7c478bd9Sstevel@tonic-gate mdb_zalloc((max_ncpus + 1) * sizeof (uintptr_t), UM_SLEEP | UM_GC); 2109*7c478bd9Sstevel@tonic-gate 2110*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&first, "cpu_list") == -1) { 2111*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'cpu_list'"); 2112*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2113*7c478bd9Sstevel@tonic-gate } 2114*7c478bd9Sstevel@tonic-gate 2115*7c478bd9Sstevel@tonic-gate current = first; 2116*7c478bd9Sstevel@tonic-gate do { 2117*7c478bd9Sstevel@tonic-gate if (mdb_vread(&cpu, sizeof (cpu), current) == -1) { 2118*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read cpu at %p", current); 2119*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2120*7c478bd9Sstevel@tonic-gate } 2121*7c478bd9Sstevel@tonic-gate 2122*7c478bd9Sstevel@tonic-gate if (panicstr != NULL && panic_cpu.cpu_id == cpu.cpu_id) { 2123*7c478bd9Sstevel@tonic-gate cw->cw_array[i++] = addr; 2124*7c478bd9Sstevel@tonic-gate } else { 2125*7c478bd9Sstevel@tonic-gate cw->cw_array[i++] = current; 2126*7c478bd9Sstevel@tonic-gate } 2127*7c478bd9Sstevel@tonic-gate } while ((current = (uintptr_t)cpu.cpu_next) != first); 2128*7c478bd9Sstevel@tonic-gate 2129*7c478bd9Sstevel@tonic-gate qsort(cw->cw_array, i, sizeof (uintptr_t), cpu_walk_cmp); 2130*7c478bd9Sstevel@tonic-gate wsp->walk_data = cw; 2131*7c478bd9Sstevel@tonic-gate 2132*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2133*7c478bd9Sstevel@tonic-gate } 2134*7c478bd9Sstevel@tonic-gate 2135*7c478bd9Sstevel@tonic-gate int 2136*7c478bd9Sstevel@tonic-gate cpu_walk_step(mdb_walk_state_t *wsp) 2137*7c478bd9Sstevel@tonic-gate { 2138*7c478bd9Sstevel@tonic-gate cpu_walk_t *cw = wsp->walk_data; 2139*7c478bd9Sstevel@tonic-gate cpu_t cpu; 2140*7c478bd9Sstevel@tonic-gate uintptr_t addr = cw->cw_array[cw->cw_ndx++]; 2141*7c478bd9Sstevel@tonic-gate 2142*7c478bd9Sstevel@tonic-gate if (addr == NULL) 2143*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 2144*7c478bd9Sstevel@tonic-gate 2145*7c478bd9Sstevel@tonic-gate if (mdb_vread(&cpu, sizeof (cpu), addr) == -1) { 2146*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read cpu at %p", addr); 2147*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 2148*7c478bd9Sstevel@tonic-gate } 2149*7c478bd9Sstevel@tonic-gate 2150*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, &cpu, wsp->walk_cbdata)); 2151*7c478bd9Sstevel@tonic-gate } 2152*7c478bd9Sstevel@tonic-gate 2153*7c478bd9Sstevel@tonic-gate typedef struct cpuinfo_data { 2154*7c478bd9Sstevel@tonic-gate intptr_t cid_cpu; 2155*7c478bd9Sstevel@tonic-gate uintptr_t cid_lbolt; 2156*7c478bd9Sstevel@tonic-gate uintptr_t **cid_ithr; 2157*7c478bd9Sstevel@tonic-gate char cid_print_head; 2158*7c478bd9Sstevel@tonic-gate char cid_print_thr; 2159*7c478bd9Sstevel@tonic-gate char cid_print_ithr; 2160*7c478bd9Sstevel@tonic-gate char cid_print_flags; 2161*7c478bd9Sstevel@tonic-gate } cpuinfo_data_t; 2162*7c478bd9Sstevel@tonic-gate 2163*7c478bd9Sstevel@tonic-gate int 2164*7c478bd9Sstevel@tonic-gate cpuinfo_walk_ithread(uintptr_t addr, const kthread_t *thr, cpuinfo_data_t *cid) 2165*7c478bd9Sstevel@tonic-gate { 2166*7c478bd9Sstevel@tonic-gate cpu_t c; 2167*7c478bd9Sstevel@tonic-gate int id; 2168*7c478bd9Sstevel@tonic-gate uint8_t pil; 2169*7c478bd9Sstevel@tonic-gate 2170*7c478bd9Sstevel@tonic-gate if (!(thr->t_flag & T_INTR_THREAD) || thr->t_state == TS_FREE) 2171*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2172*7c478bd9Sstevel@tonic-gate 2173*7c478bd9Sstevel@tonic-gate if (thr->t_bound_cpu == NULL) { 2174*7c478bd9Sstevel@tonic-gate mdb_warn("thr %p is intr thread w/out a CPU\n", addr); 2175*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2176*7c478bd9Sstevel@tonic-gate } 2177*7c478bd9Sstevel@tonic-gate 2178*7c478bd9Sstevel@tonic-gate (void) mdb_vread(&c, sizeof (c), (uintptr_t)thr->t_bound_cpu); 2179*7c478bd9Sstevel@tonic-gate 2180*7c478bd9Sstevel@tonic-gate if ((id = c.cpu_id) >= NCPU) { 2181*7c478bd9Sstevel@tonic-gate mdb_warn("CPU %p has id (%d) greater than NCPU (%d)\n", 2182*7c478bd9Sstevel@tonic-gate thr->t_bound_cpu, id, NCPU); 2183*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2184*7c478bd9Sstevel@tonic-gate } 2185*7c478bd9Sstevel@tonic-gate 2186*7c478bd9Sstevel@tonic-gate if ((pil = thr->t_pil) >= NINTR) { 2187*7c478bd9Sstevel@tonic-gate mdb_warn("thread %p has pil (%d) greater than %d\n", 2188*7c478bd9Sstevel@tonic-gate addr, pil, NINTR); 2189*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2190*7c478bd9Sstevel@tonic-gate } 2191*7c478bd9Sstevel@tonic-gate 2192*7c478bd9Sstevel@tonic-gate if (cid->cid_ithr[id][pil] != NULL) { 2193*7c478bd9Sstevel@tonic-gate mdb_warn("CPU %d has multiple threads at pil %d (at least " 2194*7c478bd9Sstevel@tonic-gate "%p and %p)\n", id, pil, addr, cid->cid_ithr[id][pil]); 2195*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2196*7c478bd9Sstevel@tonic-gate } 2197*7c478bd9Sstevel@tonic-gate 2198*7c478bd9Sstevel@tonic-gate cid->cid_ithr[id][pil] = addr; 2199*7c478bd9Sstevel@tonic-gate 2200*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2201*7c478bd9Sstevel@tonic-gate } 2202*7c478bd9Sstevel@tonic-gate 2203*7c478bd9Sstevel@tonic-gate #define CPUINFO_IDWIDTH 3 2204*7c478bd9Sstevel@tonic-gate #define CPUINFO_FLAGWIDTH 9 2205*7c478bd9Sstevel@tonic-gate 2206*7c478bd9Sstevel@tonic-gate #ifdef _LP64 2207*7c478bd9Sstevel@tonic-gate #define CPUINFO_CPUWIDTH 11 2208*7c478bd9Sstevel@tonic-gate #define CPUINFO_TWIDTH 11 2209*7c478bd9Sstevel@tonic-gate #else 2210*7c478bd9Sstevel@tonic-gate #define CPUINFO_CPUWIDTH 8 2211*7c478bd9Sstevel@tonic-gate #define CPUINFO_TWIDTH 8 2212*7c478bd9Sstevel@tonic-gate #endif 2213*7c478bd9Sstevel@tonic-gate 2214*7c478bd9Sstevel@tonic-gate #define CPUINFO_THRDELT (CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 9) 2215*7c478bd9Sstevel@tonic-gate #define CPUINFO_FLAGDELT (CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 4) 2216*7c478bd9Sstevel@tonic-gate #define CPUINFO_ITHRDELT 4 2217*7c478bd9Sstevel@tonic-gate 2218*7c478bd9Sstevel@tonic-gate #define CPUINFO_INDENT mdb_printf("%*s", CPUINFO_THRDELT, \ 2219*7c478bd9Sstevel@tonic-gate flagline < nflaglines ? flagbuf[flagline++] : "") 2220*7c478bd9Sstevel@tonic-gate 2221*7c478bd9Sstevel@tonic-gate int 2222*7c478bd9Sstevel@tonic-gate cpuinfo_walk_cpu(uintptr_t addr, const cpu_t *cpu, cpuinfo_data_t *cid) 2223*7c478bd9Sstevel@tonic-gate { 2224*7c478bd9Sstevel@tonic-gate kthread_t t; 2225*7c478bd9Sstevel@tonic-gate disp_t disp; 2226*7c478bd9Sstevel@tonic-gate proc_t p; 2227*7c478bd9Sstevel@tonic-gate uintptr_t pinned; 2228*7c478bd9Sstevel@tonic-gate char **flagbuf; 2229*7c478bd9Sstevel@tonic-gate int nflaglines = 0, flagline = 0, bspl, rval = WALK_NEXT; 2230*7c478bd9Sstevel@tonic-gate 2231*7c478bd9Sstevel@tonic-gate const char *flags[] = { 2232*7c478bd9Sstevel@tonic-gate "RUNNING", "READY", "QUIESCED", "EXISTS", 2233*7c478bd9Sstevel@tonic-gate "ENABLE", "OFFLINE", "POWEROFF", "FROZEN", 2234*7c478bd9Sstevel@tonic-gate "SPARE", "FAULTED", NULL 2235*7c478bd9Sstevel@tonic-gate }; 2236*7c478bd9Sstevel@tonic-gate 2237*7c478bd9Sstevel@tonic-gate if (cid->cid_cpu != -1) { 2238*7c478bd9Sstevel@tonic-gate if (addr != cid->cid_cpu && cpu->cpu_id != cid->cid_cpu) 2239*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2240*7c478bd9Sstevel@tonic-gate 2241*7c478bd9Sstevel@tonic-gate /* 2242*7c478bd9Sstevel@tonic-gate * Set cid_cpu to -1 to indicate that we found a matching CPU. 2243*7c478bd9Sstevel@tonic-gate */ 2244*7c478bd9Sstevel@tonic-gate cid->cid_cpu = -1; 2245*7c478bd9Sstevel@tonic-gate rval = WALK_DONE; 2246*7c478bd9Sstevel@tonic-gate } 2247*7c478bd9Sstevel@tonic-gate 2248*7c478bd9Sstevel@tonic-gate if (cid->cid_print_head) { 2249*7c478bd9Sstevel@tonic-gate mdb_printf("%3s %-*s %3s %4s %4s %3s %4s %5s %-6s %-*s %s\n", 2250*7c478bd9Sstevel@tonic-gate "ID", CPUINFO_CPUWIDTH, "ADDR", "FLG", "NRUN", "BSPL", 2251*7c478bd9Sstevel@tonic-gate "PRI", "RNRN", "KRNRN", "SWITCH", CPUINFO_TWIDTH, "THREAD", 2252*7c478bd9Sstevel@tonic-gate "PROC"); 2253*7c478bd9Sstevel@tonic-gate cid->cid_print_head = FALSE; 2254*7c478bd9Sstevel@tonic-gate } 2255*7c478bd9Sstevel@tonic-gate 2256*7c478bd9Sstevel@tonic-gate bspl = cpu->cpu_base_spl; 2257*7c478bd9Sstevel@tonic-gate 2258*7c478bd9Sstevel@tonic-gate if (mdb_vread(&disp, sizeof (disp_t), (uintptr_t)cpu->cpu_disp) == -1) { 2259*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read disp_t at %p", cpu->cpu_disp); 2260*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2261*7c478bd9Sstevel@tonic-gate } 2262*7c478bd9Sstevel@tonic-gate 2263*7c478bd9Sstevel@tonic-gate mdb_printf("%3d %0*p %3x %4d %4d ", 2264*7c478bd9Sstevel@tonic-gate cpu->cpu_id, CPUINFO_CPUWIDTH, addr, cpu->cpu_flags, 2265*7c478bd9Sstevel@tonic-gate disp.disp_nrunnable, bspl); 2266*7c478bd9Sstevel@tonic-gate 2267*7c478bd9Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), (uintptr_t)cpu->cpu_thread) != -1) { 2268*7c478bd9Sstevel@tonic-gate mdb_printf("%3d ", t.t_pri); 2269*7c478bd9Sstevel@tonic-gate } else { 2270*7c478bd9Sstevel@tonic-gate mdb_printf("%3s ", "-"); 2271*7c478bd9Sstevel@tonic-gate } 2272*7c478bd9Sstevel@tonic-gate 2273*7c478bd9Sstevel@tonic-gate mdb_printf("%4s %5s ", cpu->cpu_runrun ? "yes" : "no", 2274*7c478bd9Sstevel@tonic-gate cpu->cpu_kprunrun ? "yes" : "no"); 2275*7c478bd9Sstevel@tonic-gate 2276*7c478bd9Sstevel@tonic-gate if (cpu->cpu_last_swtch) { 2277*7c478bd9Sstevel@tonic-gate clock_t lbolt; 2278*7c478bd9Sstevel@tonic-gate 2279*7c478bd9Sstevel@tonic-gate if (mdb_vread(&lbolt, sizeof (lbolt), cid->cid_lbolt) == -1) { 2280*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read lbolt at %p", cid->cid_lbolt); 2281*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2282*7c478bd9Sstevel@tonic-gate } 2283*7c478bd9Sstevel@tonic-gate mdb_printf("t-%-4d ", lbolt - cpu->cpu_last_swtch); 2284*7c478bd9Sstevel@tonic-gate } else { 2285*7c478bd9Sstevel@tonic-gate mdb_printf("%-6s ", "-"); 2286*7c478bd9Sstevel@tonic-gate } 2287*7c478bd9Sstevel@tonic-gate 2288*7c478bd9Sstevel@tonic-gate mdb_printf("%0*p", CPUINFO_TWIDTH, cpu->cpu_thread); 2289*7c478bd9Sstevel@tonic-gate 2290*7c478bd9Sstevel@tonic-gate if (cpu->cpu_thread == cpu->cpu_idle_thread) 2291*7c478bd9Sstevel@tonic-gate mdb_printf(" (idle)\n"); 2292*7c478bd9Sstevel@tonic-gate else if (cpu->cpu_thread == NULL) 2293*7c478bd9Sstevel@tonic-gate mdb_printf(" -\n"); 2294*7c478bd9Sstevel@tonic-gate else { 2295*7c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), (uintptr_t)t.t_procp) != -1) { 2296*7c478bd9Sstevel@tonic-gate mdb_printf(" %s\n", p.p_user.u_comm); 2297*7c478bd9Sstevel@tonic-gate } else { 2298*7c478bd9Sstevel@tonic-gate mdb_printf(" ?\n"); 2299*7c478bd9Sstevel@tonic-gate } 2300*7c478bd9Sstevel@tonic-gate } 2301*7c478bd9Sstevel@tonic-gate 2302*7c478bd9Sstevel@tonic-gate flagbuf = mdb_zalloc(sizeof (flags), UM_SLEEP | UM_GC); 2303*7c478bd9Sstevel@tonic-gate 2304*7c478bd9Sstevel@tonic-gate if (cid->cid_print_flags) { 2305*7c478bd9Sstevel@tonic-gate int first = 1, i, j, k; 2306*7c478bd9Sstevel@tonic-gate char *s; 2307*7c478bd9Sstevel@tonic-gate 2308*7c478bd9Sstevel@tonic-gate cid->cid_print_head = TRUE; 2309*7c478bd9Sstevel@tonic-gate 2310*7c478bd9Sstevel@tonic-gate for (i = 1, j = 0; flags[j] != NULL; i <<= 1, j++) { 2311*7c478bd9Sstevel@tonic-gate if (!(cpu->cpu_flags & i)) 2312*7c478bd9Sstevel@tonic-gate continue; 2313*7c478bd9Sstevel@tonic-gate 2314*7c478bd9Sstevel@tonic-gate if (first) { 2315*7c478bd9Sstevel@tonic-gate s = mdb_alloc(CPUINFO_THRDELT + 1, 2316*7c478bd9Sstevel@tonic-gate UM_GC | UM_SLEEP); 2317*7c478bd9Sstevel@tonic-gate 2318*7c478bd9Sstevel@tonic-gate (void) mdb_snprintf(s, CPUINFO_THRDELT + 1, 2319*7c478bd9Sstevel@tonic-gate "%*s|%*s", CPUINFO_FLAGDELT, "", 2320*7c478bd9Sstevel@tonic-gate CPUINFO_THRDELT - 1 - CPUINFO_FLAGDELT, ""); 2321*7c478bd9Sstevel@tonic-gate flagbuf[nflaglines++] = s; 2322*7c478bd9Sstevel@tonic-gate } 2323*7c478bd9Sstevel@tonic-gate 2324*7c478bd9Sstevel@tonic-gate s = mdb_alloc(CPUINFO_THRDELT + 1, UM_GC | UM_SLEEP); 2325*7c478bd9Sstevel@tonic-gate (void) mdb_snprintf(s, CPUINFO_THRDELT + 1, "%*s%*s %s", 2326*7c478bd9Sstevel@tonic-gate CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH - 2327*7c478bd9Sstevel@tonic-gate CPUINFO_FLAGWIDTH, "", CPUINFO_FLAGWIDTH, flags[j], 2328*7c478bd9Sstevel@tonic-gate first ? "<--+" : ""); 2329*7c478bd9Sstevel@tonic-gate 2330*7c478bd9Sstevel@tonic-gate for (k = strlen(s); k < CPUINFO_THRDELT; k++) 2331*7c478bd9Sstevel@tonic-gate s[k] = ' '; 2332*7c478bd9Sstevel@tonic-gate s[k] = '\0'; 2333*7c478bd9Sstevel@tonic-gate 2334*7c478bd9Sstevel@tonic-gate flagbuf[nflaglines++] = s; 2335*7c478bd9Sstevel@tonic-gate first = 0; 2336*7c478bd9Sstevel@tonic-gate } 2337*7c478bd9Sstevel@tonic-gate } 2338*7c478bd9Sstevel@tonic-gate 2339*7c478bd9Sstevel@tonic-gate if (cid->cid_print_ithr) { 2340*7c478bd9Sstevel@tonic-gate int i, found_one = FALSE; 2341*7c478bd9Sstevel@tonic-gate int print_thr = disp.disp_nrunnable && cid->cid_print_thr; 2342*7c478bd9Sstevel@tonic-gate 2343*7c478bd9Sstevel@tonic-gate for (i = NINTR - 1; i >= 0; i--) { 2344*7c478bd9Sstevel@tonic-gate uintptr_t iaddr = cid->cid_ithr[cpu->cpu_id][i]; 2345*7c478bd9Sstevel@tonic-gate 2346*7c478bd9Sstevel@tonic-gate if (iaddr == NULL) 2347*7c478bd9Sstevel@tonic-gate continue; 2348*7c478bd9Sstevel@tonic-gate 2349*7c478bd9Sstevel@tonic-gate if (!found_one) { 2350*7c478bd9Sstevel@tonic-gate found_one = TRUE; 2351*7c478bd9Sstevel@tonic-gate 2352*7c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 2353*7c478bd9Sstevel@tonic-gate mdb_printf("%c%*s|\n", print_thr ? '|' : ' ', 2354*7c478bd9Sstevel@tonic-gate CPUINFO_ITHRDELT, ""); 2355*7c478bd9Sstevel@tonic-gate 2356*7c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 2357*7c478bd9Sstevel@tonic-gate mdb_printf("%c%*s+--> %3s %s\n", 2358*7c478bd9Sstevel@tonic-gate print_thr ? '|' : ' ', CPUINFO_ITHRDELT, 2359*7c478bd9Sstevel@tonic-gate "", "PIL", "THREAD"); 2360*7c478bd9Sstevel@tonic-gate } 2361*7c478bd9Sstevel@tonic-gate 2362*7c478bd9Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), iaddr) == -1) { 2363*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read kthread_t at %p", 2364*7c478bd9Sstevel@tonic-gate iaddr); 2365*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2366*7c478bd9Sstevel@tonic-gate } 2367*7c478bd9Sstevel@tonic-gate 2368*7c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 2369*7c478bd9Sstevel@tonic-gate mdb_printf("%c%*s %3d %0*p\n", 2370*7c478bd9Sstevel@tonic-gate print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", 2371*7c478bd9Sstevel@tonic-gate t.t_pil, CPUINFO_TWIDTH, iaddr); 2372*7c478bd9Sstevel@tonic-gate 2373*7c478bd9Sstevel@tonic-gate pinned = (uintptr_t)t.t_intr; 2374*7c478bd9Sstevel@tonic-gate } 2375*7c478bd9Sstevel@tonic-gate 2376*7c478bd9Sstevel@tonic-gate if (found_one && pinned != NULL) { 2377*7c478bd9Sstevel@tonic-gate cid->cid_print_head = TRUE; 2378*7c478bd9Sstevel@tonic-gate (void) strcpy(p.p_user.u_comm, "?"); 2379*7c478bd9Sstevel@tonic-gate 2380*7c478bd9Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), 2381*7c478bd9Sstevel@tonic-gate (uintptr_t)pinned) == -1) { 2382*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read kthread_t at %p", 2383*7c478bd9Sstevel@tonic-gate pinned); 2384*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2385*7c478bd9Sstevel@tonic-gate } 2386*7c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), 2387*7c478bd9Sstevel@tonic-gate (uintptr_t)t.t_procp) == -1) { 2388*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc_t at %p", 2389*7c478bd9Sstevel@tonic-gate t.t_procp); 2390*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2391*7c478bd9Sstevel@tonic-gate } 2392*7c478bd9Sstevel@tonic-gate 2393*7c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 2394*7c478bd9Sstevel@tonic-gate mdb_printf("%c%*s %3s %0*p %s\n", 2395*7c478bd9Sstevel@tonic-gate print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", "-", 2396*7c478bd9Sstevel@tonic-gate CPUINFO_TWIDTH, pinned, 2397*7c478bd9Sstevel@tonic-gate pinned == (uintptr_t)cpu->cpu_idle_thread ? 2398*7c478bd9Sstevel@tonic-gate "(idle)" : p.p_user.u_comm); 2399*7c478bd9Sstevel@tonic-gate } 2400*7c478bd9Sstevel@tonic-gate } 2401*7c478bd9Sstevel@tonic-gate 2402*7c478bd9Sstevel@tonic-gate if (disp.disp_nrunnable && cid->cid_print_thr) { 2403*7c478bd9Sstevel@tonic-gate dispq_t *dq; 2404*7c478bd9Sstevel@tonic-gate 2405*7c478bd9Sstevel@tonic-gate int i, npri = disp.disp_npri; 2406*7c478bd9Sstevel@tonic-gate 2407*7c478bd9Sstevel@tonic-gate dq = mdb_alloc(sizeof (dispq_t) * npri, UM_SLEEP | UM_GC); 2408*7c478bd9Sstevel@tonic-gate 2409*7c478bd9Sstevel@tonic-gate if (mdb_vread(dq, sizeof (dispq_t) * npri, 2410*7c478bd9Sstevel@tonic-gate (uintptr_t)disp.disp_q) == -1) { 2411*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read dispq_t at %p", disp.disp_q); 2412*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2413*7c478bd9Sstevel@tonic-gate } 2414*7c478bd9Sstevel@tonic-gate 2415*7c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 2416*7c478bd9Sstevel@tonic-gate mdb_printf("|\n"); 2417*7c478bd9Sstevel@tonic-gate 2418*7c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 2419*7c478bd9Sstevel@tonic-gate mdb_printf("+--> %3s %-*s %s\n", "PRI", 2420*7c478bd9Sstevel@tonic-gate CPUINFO_TWIDTH, "THREAD", "PROC"); 2421*7c478bd9Sstevel@tonic-gate 2422*7c478bd9Sstevel@tonic-gate for (i = npri - 1; i >= 0; i--) { 2423*7c478bd9Sstevel@tonic-gate uintptr_t taddr = (uintptr_t)dq[i].dq_first; 2424*7c478bd9Sstevel@tonic-gate 2425*7c478bd9Sstevel@tonic-gate while (taddr != NULL) { 2426*7c478bd9Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), taddr) == -1) { 2427*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read kthread_t " 2428*7c478bd9Sstevel@tonic-gate "at %p", taddr); 2429*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2430*7c478bd9Sstevel@tonic-gate } 2431*7c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), 2432*7c478bd9Sstevel@tonic-gate (uintptr_t)t.t_procp) == -1) { 2433*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc_t at %p", 2434*7c478bd9Sstevel@tonic-gate t.t_procp); 2435*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2436*7c478bd9Sstevel@tonic-gate } 2437*7c478bd9Sstevel@tonic-gate 2438*7c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 2439*7c478bd9Sstevel@tonic-gate mdb_printf(" %3d %0*p %s\n", t.t_pri, 2440*7c478bd9Sstevel@tonic-gate CPUINFO_TWIDTH, taddr, p.p_user.u_comm); 2441*7c478bd9Sstevel@tonic-gate 2442*7c478bd9Sstevel@tonic-gate taddr = (uintptr_t)t.t_link; 2443*7c478bd9Sstevel@tonic-gate } 2444*7c478bd9Sstevel@tonic-gate } 2445*7c478bd9Sstevel@tonic-gate cid->cid_print_head = TRUE; 2446*7c478bd9Sstevel@tonic-gate } 2447*7c478bd9Sstevel@tonic-gate 2448*7c478bd9Sstevel@tonic-gate while (flagline < nflaglines) 2449*7c478bd9Sstevel@tonic-gate mdb_printf("%s\n", flagbuf[flagline++]); 2450*7c478bd9Sstevel@tonic-gate 2451*7c478bd9Sstevel@tonic-gate if (cid->cid_print_head) 2452*7c478bd9Sstevel@tonic-gate mdb_printf("\n"); 2453*7c478bd9Sstevel@tonic-gate 2454*7c478bd9Sstevel@tonic-gate return (rval); 2455*7c478bd9Sstevel@tonic-gate } 2456*7c478bd9Sstevel@tonic-gate 2457*7c478bd9Sstevel@tonic-gate int 2458*7c478bd9Sstevel@tonic-gate cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2459*7c478bd9Sstevel@tonic-gate { 2460*7c478bd9Sstevel@tonic-gate uint_t verbose = FALSE; 2461*7c478bd9Sstevel@tonic-gate cpuinfo_data_t cid; 2462*7c478bd9Sstevel@tonic-gate GElf_Sym sym; 2463*7c478bd9Sstevel@tonic-gate clock_t lbolt; 2464*7c478bd9Sstevel@tonic-gate 2465*7c478bd9Sstevel@tonic-gate cid.cid_print_ithr = FALSE; 2466*7c478bd9Sstevel@tonic-gate cid.cid_print_thr = FALSE; 2467*7c478bd9Sstevel@tonic-gate cid.cid_print_flags = FALSE; 2468*7c478bd9Sstevel@tonic-gate cid.cid_print_head = DCMD_HDRSPEC(flags) ? TRUE : FALSE; 2469*7c478bd9Sstevel@tonic-gate cid.cid_cpu = -1; 2470*7c478bd9Sstevel@tonic-gate 2471*7c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) 2472*7c478bd9Sstevel@tonic-gate cid.cid_cpu = addr; 2473*7c478bd9Sstevel@tonic-gate 2474*7c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 2475*7c478bd9Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc) 2476*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 2477*7c478bd9Sstevel@tonic-gate 2478*7c478bd9Sstevel@tonic-gate if (verbose) { 2479*7c478bd9Sstevel@tonic-gate cid.cid_print_ithr = TRUE; 2480*7c478bd9Sstevel@tonic-gate cid.cid_print_thr = TRUE; 2481*7c478bd9Sstevel@tonic-gate cid.cid_print_flags = TRUE; 2482*7c478bd9Sstevel@tonic-gate cid.cid_print_head = TRUE; 2483*7c478bd9Sstevel@tonic-gate } 2484*7c478bd9Sstevel@tonic-gate 2485*7c478bd9Sstevel@tonic-gate if (cid.cid_print_ithr) { 2486*7c478bd9Sstevel@tonic-gate int i; 2487*7c478bd9Sstevel@tonic-gate 2488*7c478bd9Sstevel@tonic-gate cid.cid_ithr = mdb_alloc(sizeof (uintptr_t **) 2489*7c478bd9Sstevel@tonic-gate * NCPU, UM_SLEEP | UM_GC); 2490*7c478bd9Sstevel@tonic-gate 2491*7c478bd9Sstevel@tonic-gate for (i = 0; i < NCPU; i++) 2492*7c478bd9Sstevel@tonic-gate cid.cid_ithr[i] = mdb_zalloc(sizeof (uintptr_t *) * 2493*7c478bd9Sstevel@tonic-gate NINTR, UM_SLEEP | UM_GC); 2494*7c478bd9Sstevel@tonic-gate 2495*7c478bd9Sstevel@tonic-gate if (mdb_walk("thread", (mdb_walk_cb_t)cpuinfo_walk_ithread, 2496*7c478bd9Sstevel@tonic-gate &cid) == -1) { 2497*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk thread"); 2498*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2499*7c478bd9Sstevel@tonic-gate } 2500*7c478bd9Sstevel@tonic-gate } 2501*7c478bd9Sstevel@tonic-gate 2502*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("panic_lbolt", &sym) == -1) { 2503*7c478bd9Sstevel@tonic-gate mdb_warn("failed to find panic_lbolt"); 2504*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2505*7c478bd9Sstevel@tonic-gate } 2506*7c478bd9Sstevel@tonic-gate 2507*7c478bd9Sstevel@tonic-gate cid.cid_lbolt = (uintptr_t)sym.st_value; 2508*7c478bd9Sstevel@tonic-gate 2509*7c478bd9Sstevel@tonic-gate if (mdb_vread(&lbolt, sizeof (lbolt), cid.cid_lbolt) == -1) { 2510*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read panic_lbolt"); 2511*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2512*7c478bd9Sstevel@tonic-gate } 2513*7c478bd9Sstevel@tonic-gate 2514*7c478bd9Sstevel@tonic-gate if (lbolt == 0) { 2515*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("lbolt", &sym) == -1) { 2516*7c478bd9Sstevel@tonic-gate mdb_warn("failed to find lbolt"); 2517*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2518*7c478bd9Sstevel@tonic-gate } 2519*7c478bd9Sstevel@tonic-gate cid.cid_lbolt = (uintptr_t)sym.st_value; 2520*7c478bd9Sstevel@tonic-gate } 2521*7c478bd9Sstevel@tonic-gate 2522*7c478bd9Sstevel@tonic-gate if (mdb_walk("cpu", (mdb_walk_cb_t)cpuinfo_walk_cpu, &cid) == -1) { 2523*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk cpus"); 2524*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2525*7c478bd9Sstevel@tonic-gate } 2526*7c478bd9Sstevel@tonic-gate 2527*7c478bd9Sstevel@tonic-gate if (cid.cid_cpu != -1) { 2528*7c478bd9Sstevel@tonic-gate /* 2529*7c478bd9Sstevel@tonic-gate * We didn't find this CPU when we walked through the CPUs 2530*7c478bd9Sstevel@tonic-gate * (i.e. the address specified doesn't show up in the "cpu" 2531*7c478bd9Sstevel@tonic-gate * walk). However, the specified address may still correspond 2532*7c478bd9Sstevel@tonic-gate * to a valid cpu_t (for example, if the specified address is 2533*7c478bd9Sstevel@tonic-gate * the actual panicking cpu_t and not the cached panic_cpu). 2534*7c478bd9Sstevel@tonic-gate * Point is: even if we didn't find it, we still want to try 2535*7c478bd9Sstevel@tonic-gate * to print the specified address as a cpu_t. 2536*7c478bd9Sstevel@tonic-gate */ 2537*7c478bd9Sstevel@tonic-gate cpu_t cpu; 2538*7c478bd9Sstevel@tonic-gate 2539*7c478bd9Sstevel@tonic-gate if (mdb_vread(&cpu, sizeof (cpu), cid.cid_cpu) == -1) { 2540*7c478bd9Sstevel@tonic-gate mdb_warn("%p is neither a valid CPU ID nor a " 2541*7c478bd9Sstevel@tonic-gate "valid cpu_t address\n", cid.cid_cpu); 2542*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2543*7c478bd9Sstevel@tonic-gate } 2544*7c478bd9Sstevel@tonic-gate 2545*7c478bd9Sstevel@tonic-gate (void) cpuinfo_walk_cpu(cid.cid_cpu, &cpu, &cid); 2546*7c478bd9Sstevel@tonic-gate } 2547*7c478bd9Sstevel@tonic-gate 2548*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2549*7c478bd9Sstevel@tonic-gate } 2550*7c478bd9Sstevel@tonic-gate 2551*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2552*7c478bd9Sstevel@tonic-gate int 2553*7c478bd9Sstevel@tonic-gate flipone(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2554*7c478bd9Sstevel@tonic-gate { 2555*7c478bd9Sstevel@tonic-gate int i; 2556*7c478bd9Sstevel@tonic-gate 2557*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 2558*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 2559*7c478bd9Sstevel@tonic-gate 2560*7c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (addr) * NBBY; i++) 2561*7c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr ^ (1UL << i)); 2562*7c478bd9Sstevel@tonic-gate 2563*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2564*7c478bd9Sstevel@tonic-gate } 2565*7c478bd9Sstevel@tonic-gate 2566*7c478bd9Sstevel@tonic-gate /* 2567*7c478bd9Sstevel@tonic-gate * Grumble, grumble. 2568*7c478bd9Sstevel@tonic-gate */ 2569*7c478bd9Sstevel@tonic-gate #define SMAP_HASHFUNC(vp, off) \ 2570*7c478bd9Sstevel@tonic-gate ((((uintptr_t)(vp) >> 6) + ((uintptr_t)(vp) >> 3) + \ 2571*7c478bd9Sstevel@tonic-gate ((off) >> MAXBSHIFT)) & smd_hashmsk) 2572*7c478bd9Sstevel@tonic-gate 2573*7c478bd9Sstevel@tonic-gate int 2574*7c478bd9Sstevel@tonic-gate vnode2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2575*7c478bd9Sstevel@tonic-gate { 2576*7c478bd9Sstevel@tonic-gate long smd_hashmsk; 2577*7c478bd9Sstevel@tonic-gate int hash; 2578*7c478bd9Sstevel@tonic-gate uintptr_t offset = 0; 2579*7c478bd9Sstevel@tonic-gate struct smap smp; 2580*7c478bd9Sstevel@tonic-gate uintptr_t saddr, kaddr; 2581*7c478bd9Sstevel@tonic-gate uintptr_t smd_hash, smd_smap; 2582*7c478bd9Sstevel@tonic-gate struct seg seg; 2583*7c478bd9Sstevel@tonic-gate 2584*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 2585*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 2586*7c478bd9Sstevel@tonic-gate 2587*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&smd_hashmsk, "smd_hashmsk") == -1) { 2588*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read smd_hashmsk"); 2589*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2590*7c478bd9Sstevel@tonic-gate } 2591*7c478bd9Sstevel@tonic-gate 2592*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&smd_hash, "smd_hash") == -1) { 2593*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read smd_hash"); 2594*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2595*7c478bd9Sstevel@tonic-gate } 2596*7c478bd9Sstevel@tonic-gate 2597*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&smd_smap, "smd_smap") == -1) { 2598*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read smd_hash"); 2599*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2600*7c478bd9Sstevel@tonic-gate } 2601*7c478bd9Sstevel@tonic-gate 2602*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&kaddr, "segkmap") == -1) { 2603*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read segkmap"); 2604*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2605*7c478bd9Sstevel@tonic-gate } 2606*7c478bd9Sstevel@tonic-gate 2607*7c478bd9Sstevel@tonic-gate if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) { 2608*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read segkmap at %p", kaddr); 2609*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2610*7c478bd9Sstevel@tonic-gate } 2611*7c478bd9Sstevel@tonic-gate 2612*7c478bd9Sstevel@tonic-gate if (argc != 0) { 2613*7c478bd9Sstevel@tonic-gate const mdb_arg_t *arg = &argv[0]; 2614*7c478bd9Sstevel@tonic-gate 2615*7c478bd9Sstevel@tonic-gate if (arg->a_type == MDB_TYPE_IMMEDIATE) 2616*7c478bd9Sstevel@tonic-gate offset = arg->a_un.a_val; 2617*7c478bd9Sstevel@tonic-gate else 2618*7c478bd9Sstevel@tonic-gate offset = (uintptr_t)mdb_strtoull(arg->a_un.a_str); 2619*7c478bd9Sstevel@tonic-gate } 2620*7c478bd9Sstevel@tonic-gate 2621*7c478bd9Sstevel@tonic-gate hash = SMAP_HASHFUNC(addr, offset); 2622*7c478bd9Sstevel@tonic-gate 2623*7c478bd9Sstevel@tonic-gate if (mdb_vread(&saddr, sizeof (saddr), 2624*7c478bd9Sstevel@tonic-gate smd_hash + hash * sizeof (uintptr_t)) == -1) { 2625*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read smap at %p", 2626*7c478bd9Sstevel@tonic-gate smd_hash + hash * sizeof (uintptr_t)); 2627*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2628*7c478bd9Sstevel@tonic-gate } 2629*7c478bd9Sstevel@tonic-gate 2630*7c478bd9Sstevel@tonic-gate do { 2631*7c478bd9Sstevel@tonic-gate if (mdb_vread(&smp, sizeof (smp), saddr) == -1) { 2632*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read smap at %p", saddr); 2633*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2634*7c478bd9Sstevel@tonic-gate } 2635*7c478bd9Sstevel@tonic-gate 2636*7c478bd9Sstevel@tonic-gate if ((uintptr_t)smp.sm_vp == addr && smp.sm_off == offset) { 2637*7c478bd9Sstevel@tonic-gate mdb_printf("vnode %p, offs %p is smap %p, vaddr %p\n", 2638*7c478bd9Sstevel@tonic-gate addr, offset, saddr, ((saddr - smd_smap) / 2639*7c478bd9Sstevel@tonic-gate sizeof (smp)) * MAXBSIZE + seg.s_base); 2640*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2641*7c478bd9Sstevel@tonic-gate } 2642*7c478bd9Sstevel@tonic-gate 2643*7c478bd9Sstevel@tonic-gate saddr = (uintptr_t)smp.sm_hash; 2644*7c478bd9Sstevel@tonic-gate } while (saddr != NULL); 2645*7c478bd9Sstevel@tonic-gate 2646*7c478bd9Sstevel@tonic-gate mdb_printf("no smap for vnode %p, offs %p\n", addr, offset); 2647*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2648*7c478bd9Sstevel@tonic-gate } 2649*7c478bd9Sstevel@tonic-gate 2650*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2651*7c478bd9Sstevel@tonic-gate int 2652*7c478bd9Sstevel@tonic-gate addr2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2653*7c478bd9Sstevel@tonic-gate { 2654*7c478bd9Sstevel@tonic-gate uintptr_t kaddr; 2655*7c478bd9Sstevel@tonic-gate struct seg seg; 2656*7c478bd9Sstevel@tonic-gate struct segmap_data sd; 2657*7c478bd9Sstevel@tonic-gate 2658*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 2659*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 2660*7c478bd9Sstevel@tonic-gate 2661*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&kaddr, "segkmap") == -1) { 2662*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read segkmap"); 2663*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2664*7c478bd9Sstevel@tonic-gate } 2665*7c478bd9Sstevel@tonic-gate 2666*7c478bd9Sstevel@tonic-gate if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) { 2667*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read segkmap at %p", kaddr); 2668*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2669*7c478bd9Sstevel@tonic-gate } 2670*7c478bd9Sstevel@tonic-gate 2671*7c478bd9Sstevel@tonic-gate if (mdb_vread(&sd, sizeof (sd), (uintptr_t)seg.s_data) == -1) { 2672*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read segmap_data at %p", seg.s_data); 2673*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2674*7c478bd9Sstevel@tonic-gate } 2675*7c478bd9Sstevel@tonic-gate 2676*7c478bd9Sstevel@tonic-gate mdb_printf("%p is smap %p\n", addr, 2677*7c478bd9Sstevel@tonic-gate ((addr - (uintptr_t)seg.s_base) >> MAXBSHIFT) * 2678*7c478bd9Sstevel@tonic-gate sizeof (struct smap) + (uintptr_t)sd.smd_sm); 2679*7c478bd9Sstevel@tonic-gate 2680*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2681*7c478bd9Sstevel@tonic-gate } 2682*7c478bd9Sstevel@tonic-gate 2683*7c478bd9Sstevel@tonic-gate int 2684*7c478bd9Sstevel@tonic-gate as2proc_walk(uintptr_t addr, const proc_t *p, struct as **asp) 2685*7c478bd9Sstevel@tonic-gate { 2686*7c478bd9Sstevel@tonic-gate if (p->p_as == *asp) 2687*7c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr); 2688*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2689*7c478bd9Sstevel@tonic-gate } 2690*7c478bd9Sstevel@tonic-gate 2691*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2692*7c478bd9Sstevel@tonic-gate int 2693*7c478bd9Sstevel@tonic-gate as2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2694*7c478bd9Sstevel@tonic-gate { 2695*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || argc != 0) 2696*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 2697*7c478bd9Sstevel@tonic-gate 2698*7c478bd9Sstevel@tonic-gate if (mdb_walk("proc", (mdb_walk_cb_t)as2proc_walk, &addr) == -1) { 2699*7c478bd9Sstevel@tonic-gate mdb_warn("failed to walk proc"); 2700*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2701*7c478bd9Sstevel@tonic-gate } 2702*7c478bd9Sstevel@tonic-gate 2703*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2704*7c478bd9Sstevel@tonic-gate } 2705*7c478bd9Sstevel@tonic-gate 2706*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2707*7c478bd9Sstevel@tonic-gate int 2708*7c478bd9Sstevel@tonic-gate ptree_walk(uintptr_t addr, const proc_t *p, void *ignored) 2709*7c478bd9Sstevel@tonic-gate { 2710*7c478bd9Sstevel@tonic-gate proc_t parent; 2711*7c478bd9Sstevel@tonic-gate int ident = 0; 2712*7c478bd9Sstevel@tonic-gate uintptr_t paddr; 2713*7c478bd9Sstevel@tonic-gate 2714*7c478bd9Sstevel@tonic-gate for (paddr = (uintptr_t)p->p_parent; paddr != NULL; ident += 5) { 2715*7c478bd9Sstevel@tonic-gate mdb_vread(&parent, sizeof (parent), paddr); 2716*7c478bd9Sstevel@tonic-gate paddr = (uintptr_t)parent.p_parent; 2717*7c478bd9Sstevel@tonic-gate } 2718*7c478bd9Sstevel@tonic-gate 2719*7c478bd9Sstevel@tonic-gate mdb_inc_indent(ident); 2720*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p %s\n", addr, p->p_user.u_comm); 2721*7c478bd9Sstevel@tonic-gate mdb_dec_indent(ident); 2722*7c478bd9Sstevel@tonic-gate 2723*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2724*7c478bd9Sstevel@tonic-gate } 2725*7c478bd9Sstevel@tonic-gate 2726*7c478bd9Sstevel@tonic-gate void 2727*7c478bd9Sstevel@tonic-gate ptree_ancestors(uintptr_t addr, uintptr_t start) 2728*7c478bd9Sstevel@tonic-gate { 2729*7c478bd9Sstevel@tonic-gate proc_t p; 2730*7c478bd9Sstevel@tonic-gate 2731*7c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), addr) == -1) { 2732*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ancestor at %p", addr); 2733*7c478bd9Sstevel@tonic-gate return; 2734*7c478bd9Sstevel@tonic-gate } 2735*7c478bd9Sstevel@tonic-gate 2736*7c478bd9Sstevel@tonic-gate if (p.p_parent != NULL) 2737*7c478bd9Sstevel@tonic-gate ptree_ancestors((uintptr_t)p.p_parent, start); 2738*7c478bd9Sstevel@tonic-gate 2739*7c478bd9Sstevel@tonic-gate if (addr != start) 2740*7c478bd9Sstevel@tonic-gate (void) ptree_walk(addr, &p, NULL); 2741*7c478bd9Sstevel@tonic-gate } 2742*7c478bd9Sstevel@tonic-gate 2743*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2744*7c478bd9Sstevel@tonic-gate int 2745*7c478bd9Sstevel@tonic-gate ptree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2746*7c478bd9Sstevel@tonic-gate { 2747*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 2748*7c478bd9Sstevel@tonic-gate addr = NULL; 2749*7c478bd9Sstevel@tonic-gate else 2750*7c478bd9Sstevel@tonic-gate ptree_ancestors(addr, addr); 2751*7c478bd9Sstevel@tonic-gate 2752*7c478bd9Sstevel@tonic-gate if (mdb_pwalk("proc", (mdb_walk_cb_t)ptree_walk, NULL, addr) == -1) { 2753*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk 'proc'"); 2754*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2755*7c478bd9Sstevel@tonic-gate } 2756*7c478bd9Sstevel@tonic-gate 2757*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2758*7c478bd9Sstevel@tonic-gate } 2759*7c478bd9Sstevel@tonic-gate 2760*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2761*7c478bd9Sstevel@tonic-gate static int 2762*7c478bd9Sstevel@tonic-gate fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2763*7c478bd9Sstevel@tonic-gate { 2764*7c478bd9Sstevel@tonic-gate int fdnum; 2765*7c478bd9Sstevel@tonic-gate const mdb_arg_t *argp = &argv[0]; 2766*7c478bd9Sstevel@tonic-gate proc_t p; 2767*7c478bd9Sstevel@tonic-gate uf_entry_t uf; 2768*7c478bd9Sstevel@tonic-gate 2769*7c478bd9Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0) { 2770*7c478bd9Sstevel@tonic-gate mdb_warn("fd doesn't give global information\n"); 2771*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2772*7c478bd9Sstevel@tonic-gate } 2773*7c478bd9Sstevel@tonic-gate if (argc != 1) 2774*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 2775*7c478bd9Sstevel@tonic-gate 2776*7c478bd9Sstevel@tonic-gate if (argp->a_type == MDB_TYPE_IMMEDIATE) 2777*7c478bd9Sstevel@tonic-gate fdnum = argp->a_un.a_val; 2778*7c478bd9Sstevel@tonic-gate else 2779*7c478bd9Sstevel@tonic-gate fdnum = mdb_strtoull(argp->a_un.a_str); 2780*7c478bd9Sstevel@tonic-gate 2781*7c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (struct proc), addr) == -1) { 2782*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read proc_t at %p", addr); 2783*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2784*7c478bd9Sstevel@tonic-gate } 2785*7c478bd9Sstevel@tonic-gate if (fdnum > p.p_user.u_finfo.fi_nfiles) { 2786*7c478bd9Sstevel@tonic-gate mdb_warn("process %p only has %d files open.\n", 2787*7c478bd9Sstevel@tonic-gate addr, p.p_user.u_finfo.fi_nfiles); 2788*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2789*7c478bd9Sstevel@tonic-gate } 2790*7c478bd9Sstevel@tonic-gate if (mdb_vread(&uf, sizeof (uf_entry_t), 2791*7c478bd9Sstevel@tonic-gate (uintptr_t)&p.p_user.u_finfo.fi_list[fdnum]) == -1) { 2792*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read uf_entry_t at %p", 2793*7c478bd9Sstevel@tonic-gate &p.p_user.u_finfo.fi_list[fdnum]); 2794*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2795*7c478bd9Sstevel@tonic-gate } 2796*7c478bd9Sstevel@tonic-gate 2797*7c478bd9Sstevel@tonic-gate mdb_printf("%p\n", uf.uf_file); 2798*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2799*7c478bd9Sstevel@tonic-gate } 2800*7c478bd9Sstevel@tonic-gate 2801*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2802*7c478bd9Sstevel@tonic-gate static int 2803*7c478bd9Sstevel@tonic-gate pid2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2804*7c478bd9Sstevel@tonic-gate { 2805*7c478bd9Sstevel@tonic-gate pid_t pid = (pid_t)addr; 2806*7c478bd9Sstevel@tonic-gate 2807*7c478bd9Sstevel@tonic-gate if (argc != 0) 2808*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 2809*7c478bd9Sstevel@tonic-gate 2810*7c478bd9Sstevel@tonic-gate if ((addr = mdb_pid2proc(pid, NULL)) == NULL) { 2811*7c478bd9Sstevel@tonic-gate mdb_warn("PID 0t%d not found\n", pid); 2812*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2813*7c478bd9Sstevel@tonic-gate } 2814*7c478bd9Sstevel@tonic-gate 2815*7c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr); 2816*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2817*7c478bd9Sstevel@tonic-gate } 2818*7c478bd9Sstevel@tonic-gate 2819*7c478bd9Sstevel@tonic-gate static char *sysfile_cmd[] = { 2820*7c478bd9Sstevel@tonic-gate "exclude:", 2821*7c478bd9Sstevel@tonic-gate "include:", 2822*7c478bd9Sstevel@tonic-gate "forceload:", 2823*7c478bd9Sstevel@tonic-gate "rootdev:", 2824*7c478bd9Sstevel@tonic-gate "rootfs:", 2825*7c478bd9Sstevel@tonic-gate "swapdev:", 2826*7c478bd9Sstevel@tonic-gate "swapfs:", 2827*7c478bd9Sstevel@tonic-gate "moddir:", 2828*7c478bd9Sstevel@tonic-gate "set", 2829*7c478bd9Sstevel@tonic-gate "unknown", 2830*7c478bd9Sstevel@tonic-gate }; 2831*7c478bd9Sstevel@tonic-gate 2832*7c478bd9Sstevel@tonic-gate static char *sysfile_ops[] = { "", "=", "&", "|" }; 2833*7c478bd9Sstevel@tonic-gate 2834*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2835*7c478bd9Sstevel@tonic-gate static int 2836*7c478bd9Sstevel@tonic-gate sysfile_vmem_seg(uintptr_t addr, const vmem_seg_t *vsp, void **target) 2837*7c478bd9Sstevel@tonic-gate { 2838*7c478bd9Sstevel@tonic-gate if (vsp->vs_type == VMEM_ALLOC && (void *)vsp->vs_start == *target) { 2839*7c478bd9Sstevel@tonic-gate *target = NULL; 2840*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 2841*7c478bd9Sstevel@tonic-gate } 2842*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2843*7c478bd9Sstevel@tonic-gate } 2844*7c478bd9Sstevel@tonic-gate 2845*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2846*7c478bd9Sstevel@tonic-gate static int 2847*7c478bd9Sstevel@tonic-gate sysfile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2848*7c478bd9Sstevel@tonic-gate { 2849*7c478bd9Sstevel@tonic-gate struct sysparam *sysp, sys; 2850*7c478bd9Sstevel@tonic-gate char var[256]; 2851*7c478bd9Sstevel@tonic-gate char modname[256]; 2852*7c478bd9Sstevel@tonic-gate char val[256]; 2853*7c478bd9Sstevel@tonic-gate char strval[256]; 2854*7c478bd9Sstevel@tonic-gate vmem_t *mod_sysfile_arena; 2855*7c478bd9Sstevel@tonic-gate void *straddr; 2856*7c478bd9Sstevel@tonic-gate 2857*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&sysp, "sysparam_hd") == -1) { 2858*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read sysparam_hd"); 2859*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2860*7c478bd9Sstevel@tonic-gate } 2861*7c478bd9Sstevel@tonic-gate 2862*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&mod_sysfile_arena, "mod_sysfile_arena") == -1) { 2863*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read mod_sysfile_arena"); 2864*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2865*7c478bd9Sstevel@tonic-gate } 2866*7c478bd9Sstevel@tonic-gate 2867*7c478bd9Sstevel@tonic-gate while (sysp != NULL) { 2868*7c478bd9Sstevel@tonic-gate var[0] = '\0'; 2869*7c478bd9Sstevel@tonic-gate val[0] = '\0'; 2870*7c478bd9Sstevel@tonic-gate modname[0] = '\0'; 2871*7c478bd9Sstevel@tonic-gate if (mdb_vread(&sys, sizeof (sys), (uintptr_t)sysp) == -1) { 2872*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read sysparam %p", sysp); 2873*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2874*7c478bd9Sstevel@tonic-gate } 2875*7c478bd9Sstevel@tonic-gate if (sys.sys_modnam != NULL && 2876*7c478bd9Sstevel@tonic-gate mdb_readstr(modname, 256, 2877*7c478bd9Sstevel@tonic-gate (uintptr_t)sys.sys_modnam) == -1) { 2878*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read modname in %p", sysp); 2879*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2880*7c478bd9Sstevel@tonic-gate } 2881*7c478bd9Sstevel@tonic-gate if (sys.sys_ptr != NULL && 2882*7c478bd9Sstevel@tonic-gate mdb_readstr(var, 256, (uintptr_t)sys.sys_ptr) == -1) { 2883*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ptr in %p", sysp); 2884*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2885*7c478bd9Sstevel@tonic-gate } 2886*7c478bd9Sstevel@tonic-gate if (sys.sys_op != SETOP_NONE) { 2887*7c478bd9Sstevel@tonic-gate /* 2888*7c478bd9Sstevel@tonic-gate * Is this an int or a string? We determine this 2889*7c478bd9Sstevel@tonic-gate * by checking whether straddr is contained in 2890*7c478bd9Sstevel@tonic-gate * mod_sysfile_arena. If so, the walker will set 2891*7c478bd9Sstevel@tonic-gate * straddr to NULL. 2892*7c478bd9Sstevel@tonic-gate */ 2893*7c478bd9Sstevel@tonic-gate straddr = (void *)(uintptr_t)sys.sys_info; 2894*7c478bd9Sstevel@tonic-gate if (sys.sys_op == SETOP_ASSIGN && 2895*7c478bd9Sstevel@tonic-gate sys.sys_info != 0 && 2896*7c478bd9Sstevel@tonic-gate mdb_pwalk("vmem_seg", 2897*7c478bd9Sstevel@tonic-gate (mdb_walk_cb_t)sysfile_vmem_seg, &straddr, 2898*7c478bd9Sstevel@tonic-gate (uintptr_t)mod_sysfile_arena) == 0 && 2899*7c478bd9Sstevel@tonic-gate straddr == NULL && 2900*7c478bd9Sstevel@tonic-gate mdb_readstr(strval, 256, 2901*7c478bd9Sstevel@tonic-gate (uintptr_t)sys.sys_info) != -1) { 2902*7c478bd9Sstevel@tonic-gate (void) mdb_snprintf(val, sizeof (val), "\"%s\"", 2903*7c478bd9Sstevel@tonic-gate strval); 2904*7c478bd9Sstevel@tonic-gate } else { 2905*7c478bd9Sstevel@tonic-gate (void) mdb_snprintf(val, sizeof (val), 2906*7c478bd9Sstevel@tonic-gate "0x%llx [0t%llu]", sys.sys_info, 2907*7c478bd9Sstevel@tonic-gate sys.sys_info); 2908*7c478bd9Sstevel@tonic-gate } 2909*7c478bd9Sstevel@tonic-gate } 2910*7c478bd9Sstevel@tonic-gate mdb_printf("%s %s%s%s%s%s\n", sysfile_cmd[sys.sys_type], 2911*7c478bd9Sstevel@tonic-gate modname, modname[0] == '\0' ? "" : ":", 2912*7c478bd9Sstevel@tonic-gate var, sysfile_ops[sys.sys_op], val); 2913*7c478bd9Sstevel@tonic-gate 2914*7c478bd9Sstevel@tonic-gate sysp = sys.sys_next; 2915*7c478bd9Sstevel@tonic-gate } 2916*7c478bd9Sstevel@tonic-gate 2917*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2918*7c478bd9Sstevel@tonic-gate } 2919*7c478bd9Sstevel@tonic-gate 2920*7c478bd9Sstevel@tonic-gate /* 2921*7c478bd9Sstevel@tonic-gate * Dump a taskq_ent_t given its address. 2922*7c478bd9Sstevel@tonic-gate */ 2923*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2924*7c478bd9Sstevel@tonic-gate int 2925*7c478bd9Sstevel@tonic-gate taskq_ent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2926*7c478bd9Sstevel@tonic-gate { 2927*7c478bd9Sstevel@tonic-gate taskq_ent_t taskq_ent; 2928*7c478bd9Sstevel@tonic-gate GElf_Sym sym; 2929*7c478bd9Sstevel@tonic-gate char buf[MDB_SYM_NAMLEN+1]; 2930*7c478bd9Sstevel@tonic-gate 2931*7c478bd9Sstevel@tonic-gate 2932*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 2933*7c478bd9Sstevel@tonic-gate mdb_warn("expected explicit taskq_ent_t address before ::\n"); 2934*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 2935*7c478bd9Sstevel@tonic-gate } 2936*7c478bd9Sstevel@tonic-gate 2937*7c478bd9Sstevel@tonic-gate if (mdb_vread(&taskq_ent, sizeof (taskq_ent_t), addr) == -1) { 2938*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read taskq_ent_t at %p", addr); 2939*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 2940*7c478bd9Sstevel@tonic-gate } 2941*7c478bd9Sstevel@tonic-gate 2942*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 2943*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-?s %-?s %-s%</u>\n", 2944*7c478bd9Sstevel@tonic-gate "ENTRY", "ARG", "FUNCTION"); 2945*7c478bd9Sstevel@tonic-gate } 2946*7c478bd9Sstevel@tonic-gate 2947*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_addr((uintptr_t)taskq_ent.tqent_func, MDB_SYM_EXACT, 2948*7c478bd9Sstevel@tonic-gate buf, sizeof (buf), &sym) == -1) { 2949*7c478bd9Sstevel@tonic-gate (void) strcpy(buf, "????"); 2950*7c478bd9Sstevel@tonic-gate } 2951*7c478bd9Sstevel@tonic-gate 2952*7c478bd9Sstevel@tonic-gate mdb_printf("%-?p %-?p %s\n", addr, taskq_ent.tqent_arg, buf); 2953*7c478bd9Sstevel@tonic-gate 2954*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 2955*7c478bd9Sstevel@tonic-gate } 2956*7c478bd9Sstevel@tonic-gate 2957*7c478bd9Sstevel@tonic-gate /* 2958*7c478bd9Sstevel@tonic-gate * Given the address of the (taskq_t) task queue head, walk the queue listing 2959*7c478bd9Sstevel@tonic-gate * the address of every taskq_ent_t. 2960*7c478bd9Sstevel@tonic-gate */ 2961*7c478bd9Sstevel@tonic-gate int 2962*7c478bd9Sstevel@tonic-gate taskq_walk_init(mdb_walk_state_t *wsp) 2963*7c478bd9Sstevel@tonic-gate { 2964*7c478bd9Sstevel@tonic-gate taskq_t tq_head; 2965*7c478bd9Sstevel@tonic-gate 2966*7c478bd9Sstevel@tonic-gate 2967*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 2968*7c478bd9Sstevel@tonic-gate mdb_warn("start address required\n"); 2969*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 2970*7c478bd9Sstevel@tonic-gate } 2971*7c478bd9Sstevel@tonic-gate 2972*7c478bd9Sstevel@tonic-gate 2973*7c478bd9Sstevel@tonic-gate /* 2974*7c478bd9Sstevel@tonic-gate * Save the address of the list head entry. This terminates the list. 2975*7c478bd9Sstevel@tonic-gate */ 2976*7c478bd9Sstevel@tonic-gate wsp->walk_data = (void *) 2977*7c478bd9Sstevel@tonic-gate ((size_t)wsp->walk_addr + offsetof(taskq_t, tq_task)); 2978*7c478bd9Sstevel@tonic-gate 2979*7c478bd9Sstevel@tonic-gate 2980*7c478bd9Sstevel@tonic-gate /* 2981*7c478bd9Sstevel@tonic-gate * Read in taskq head, set walk_addr to point to first taskq_ent_t. 2982*7c478bd9Sstevel@tonic-gate */ 2983*7c478bd9Sstevel@tonic-gate if (mdb_vread((void *)&tq_head, sizeof (taskq_t), wsp->walk_addr) == 2984*7c478bd9Sstevel@tonic-gate -1) { 2985*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read taskq list head at %p", 2986*7c478bd9Sstevel@tonic-gate wsp->walk_addr); 2987*7c478bd9Sstevel@tonic-gate } 2988*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)tq_head.tq_task.tqent_next; 2989*7c478bd9Sstevel@tonic-gate 2990*7c478bd9Sstevel@tonic-gate 2991*7c478bd9Sstevel@tonic-gate /* 2992*7c478bd9Sstevel@tonic-gate * Check for null list (next=head) 2993*7c478bd9Sstevel@tonic-gate */ 2994*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == (uintptr_t)wsp->walk_data) { 2995*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 2996*7c478bd9Sstevel@tonic-gate } 2997*7c478bd9Sstevel@tonic-gate 2998*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2999*7c478bd9Sstevel@tonic-gate } 3000*7c478bd9Sstevel@tonic-gate 3001*7c478bd9Sstevel@tonic-gate 3002*7c478bd9Sstevel@tonic-gate int 3003*7c478bd9Sstevel@tonic-gate taskq_walk_step(mdb_walk_state_t *wsp) 3004*7c478bd9Sstevel@tonic-gate { 3005*7c478bd9Sstevel@tonic-gate taskq_ent_t tq_ent; 3006*7c478bd9Sstevel@tonic-gate int status; 3007*7c478bd9Sstevel@tonic-gate 3008*7c478bd9Sstevel@tonic-gate 3009*7c478bd9Sstevel@tonic-gate if (mdb_vread((void *)&tq_ent, sizeof (taskq_ent_t), wsp->walk_addr) == 3010*7c478bd9Sstevel@tonic-gate -1) { 3011*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read taskq_ent_t at %p", wsp->walk_addr); 3012*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3013*7c478bd9Sstevel@tonic-gate } 3014*7c478bd9Sstevel@tonic-gate 3015*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, (void *)&tq_ent, 3016*7c478bd9Sstevel@tonic-gate wsp->walk_cbdata); 3017*7c478bd9Sstevel@tonic-gate 3018*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)tq_ent.tqent_next; 3019*7c478bd9Sstevel@tonic-gate 3020*7c478bd9Sstevel@tonic-gate 3021*7c478bd9Sstevel@tonic-gate /* Check if we're at the last element (next=head) */ 3022*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == (uintptr_t)wsp->walk_data) { 3023*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 3024*7c478bd9Sstevel@tonic-gate } 3025*7c478bd9Sstevel@tonic-gate 3026*7c478bd9Sstevel@tonic-gate return (status); 3027*7c478bd9Sstevel@tonic-gate } 3028*7c478bd9Sstevel@tonic-gate 3029*7c478bd9Sstevel@tonic-gate int 3030*7c478bd9Sstevel@tonic-gate didmatch(uintptr_t addr, const kthread_t *thr, kt_did_t *didp) 3031*7c478bd9Sstevel@tonic-gate { 3032*7c478bd9Sstevel@tonic-gate 3033*7c478bd9Sstevel@tonic-gate if (*didp == thr->t_did) { 3034*7c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr); 3035*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 3036*7c478bd9Sstevel@tonic-gate } else 3037*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 3038*7c478bd9Sstevel@tonic-gate } 3039*7c478bd9Sstevel@tonic-gate 3040*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3041*7c478bd9Sstevel@tonic-gate int 3042*7c478bd9Sstevel@tonic-gate did2thread(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3043*7c478bd9Sstevel@tonic-gate { 3044*7c478bd9Sstevel@tonic-gate const mdb_arg_t *argp = &argv[0]; 3045*7c478bd9Sstevel@tonic-gate kt_did_t did; 3046*7c478bd9Sstevel@tonic-gate 3047*7c478bd9Sstevel@tonic-gate if (argc != 1) 3048*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 3049*7c478bd9Sstevel@tonic-gate 3050*7c478bd9Sstevel@tonic-gate did = (kt_did_t)mdb_strtoull(argp->a_un.a_str); 3051*7c478bd9Sstevel@tonic-gate 3052*7c478bd9Sstevel@tonic-gate if (mdb_walk("thread", (mdb_walk_cb_t)didmatch, (void *)&did) == -1) { 3053*7c478bd9Sstevel@tonic-gate mdb_warn("failed to walk thread"); 3054*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3055*7c478bd9Sstevel@tonic-gate 3056*7c478bd9Sstevel@tonic-gate } 3057*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 3058*7c478bd9Sstevel@tonic-gate 3059*7c478bd9Sstevel@tonic-gate } 3060*7c478bd9Sstevel@tonic-gate 3061*7c478bd9Sstevel@tonic-gate static int 3062*7c478bd9Sstevel@tonic-gate errorq_walk_init(mdb_walk_state_t *wsp) 3063*7c478bd9Sstevel@tonic-gate { 3064*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL && 3065*7c478bd9Sstevel@tonic-gate mdb_readvar(&wsp->walk_addr, "errorq_list") == -1) { 3066*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq_list"); 3067*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 3068*7c478bd9Sstevel@tonic-gate } 3069*7c478bd9Sstevel@tonic-gate 3070*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 3071*7c478bd9Sstevel@tonic-gate } 3072*7c478bd9Sstevel@tonic-gate 3073*7c478bd9Sstevel@tonic-gate static int 3074*7c478bd9Sstevel@tonic-gate errorq_walk_step(mdb_walk_state_t *wsp) 3075*7c478bd9Sstevel@tonic-gate { 3076*7c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 3077*7c478bd9Sstevel@tonic-gate errorq_t eq; 3078*7c478bd9Sstevel@tonic-gate 3079*7c478bd9Sstevel@tonic-gate if (addr == NULL) 3080*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 3081*7c478bd9Sstevel@tonic-gate 3082*7c478bd9Sstevel@tonic-gate if (mdb_vread(&eq, sizeof (eq), addr) == -1) { 3083*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq at %p", addr); 3084*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 3085*7c478bd9Sstevel@tonic-gate } 3086*7c478bd9Sstevel@tonic-gate 3087*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)eq.eq_next; 3088*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, &eq, wsp->walk_cbdata)); 3089*7c478bd9Sstevel@tonic-gate } 3090*7c478bd9Sstevel@tonic-gate 3091*7c478bd9Sstevel@tonic-gate typedef struct eqd_walk_data { 3092*7c478bd9Sstevel@tonic-gate uintptr_t *eqd_stack; 3093*7c478bd9Sstevel@tonic-gate void *eqd_buf; 3094*7c478bd9Sstevel@tonic-gate ulong_t eqd_qpos; 3095*7c478bd9Sstevel@tonic-gate ulong_t eqd_qlen; 3096*7c478bd9Sstevel@tonic-gate size_t eqd_size; 3097*7c478bd9Sstevel@tonic-gate } eqd_walk_data_t; 3098*7c478bd9Sstevel@tonic-gate 3099*7c478bd9Sstevel@tonic-gate /* 3100*7c478bd9Sstevel@tonic-gate * In order to walk the list of pending error queue elements, we push the 3101*7c478bd9Sstevel@tonic-gate * addresses of the corresponding data buffers in to the eqd_stack array. 3102*7c478bd9Sstevel@tonic-gate * The error lists are in reverse chronological order when iterating using 3103*7c478bd9Sstevel@tonic-gate * eqe_prev, so we then pop things off the top in eqd_walk_step so that the 3104*7c478bd9Sstevel@tonic-gate * walker client gets addresses in order from oldest error to newest error. 3105*7c478bd9Sstevel@tonic-gate */ 3106*7c478bd9Sstevel@tonic-gate static void 3107*7c478bd9Sstevel@tonic-gate eqd_push_list(eqd_walk_data_t *eqdp, uintptr_t addr) 3108*7c478bd9Sstevel@tonic-gate { 3109*7c478bd9Sstevel@tonic-gate errorq_elem_t eqe; 3110*7c478bd9Sstevel@tonic-gate 3111*7c478bd9Sstevel@tonic-gate while (addr != NULL) { 3112*7c478bd9Sstevel@tonic-gate if (mdb_vread(&eqe, sizeof (eqe), addr) != sizeof (eqe)) { 3113*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq element at %p", addr); 3114*7c478bd9Sstevel@tonic-gate break; 3115*7c478bd9Sstevel@tonic-gate } 3116*7c478bd9Sstevel@tonic-gate 3117*7c478bd9Sstevel@tonic-gate if (eqdp->eqd_qpos == eqdp->eqd_qlen) { 3118*7c478bd9Sstevel@tonic-gate mdb_warn("errorq is overfull -- more than %lu " 3119*7c478bd9Sstevel@tonic-gate "elems found\n", eqdp->eqd_qlen); 3120*7c478bd9Sstevel@tonic-gate break; 3121*7c478bd9Sstevel@tonic-gate } 3122*7c478bd9Sstevel@tonic-gate 3123*7c478bd9Sstevel@tonic-gate eqdp->eqd_stack[eqdp->eqd_qpos++] = (uintptr_t)eqe.eqe_data; 3124*7c478bd9Sstevel@tonic-gate addr = (uintptr_t)eqe.eqe_prev; 3125*7c478bd9Sstevel@tonic-gate } 3126*7c478bd9Sstevel@tonic-gate } 3127*7c478bd9Sstevel@tonic-gate 3128*7c478bd9Sstevel@tonic-gate static int 3129*7c478bd9Sstevel@tonic-gate eqd_walk_init(mdb_walk_state_t *wsp) 3130*7c478bd9Sstevel@tonic-gate { 3131*7c478bd9Sstevel@tonic-gate eqd_walk_data_t *eqdp; 3132*7c478bd9Sstevel@tonic-gate errorq_elem_t eqe, *addr; 3133*7c478bd9Sstevel@tonic-gate errorq_t eq; 3134*7c478bd9Sstevel@tonic-gate ulong_t i; 3135*7c478bd9Sstevel@tonic-gate 3136*7c478bd9Sstevel@tonic-gate if (mdb_vread(&eq, sizeof (eq), wsp->walk_addr) == -1) { 3137*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq at %p", wsp->walk_addr); 3138*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 3139*7c478bd9Sstevel@tonic-gate } 3140*7c478bd9Sstevel@tonic-gate 3141*7c478bd9Sstevel@tonic-gate if (eq.eq_ptail != NULL && 3142*7c478bd9Sstevel@tonic-gate mdb_vread(&eqe, sizeof (eqe), (uintptr_t)eq.eq_ptail) == -1) { 3143*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq element at %p", eq.eq_ptail); 3144*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 3145*7c478bd9Sstevel@tonic-gate } 3146*7c478bd9Sstevel@tonic-gate 3147*7c478bd9Sstevel@tonic-gate eqdp = mdb_alloc(sizeof (eqd_walk_data_t), UM_SLEEP); 3148*7c478bd9Sstevel@tonic-gate wsp->walk_data = eqdp; 3149*7c478bd9Sstevel@tonic-gate 3150*7c478bd9Sstevel@tonic-gate eqdp->eqd_stack = mdb_zalloc(sizeof (uintptr_t) * eq.eq_qlen, UM_SLEEP); 3151*7c478bd9Sstevel@tonic-gate eqdp->eqd_buf = mdb_alloc(eq.eq_size, UM_SLEEP); 3152*7c478bd9Sstevel@tonic-gate eqdp->eqd_qlen = eq.eq_qlen; 3153*7c478bd9Sstevel@tonic-gate eqdp->eqd_qpos = 0; 3154*7c478bd9Sstevel@tonic-gate eqdp->eqd_size = eq.eq_size; 3155*7c478bd9Sstevel@tonic-gate 3156*7c478bd9Sstevel@tonic-gate /* 3157*7c478bd9Sstevel@tonic-gate * The newest elements in the queue are on the pending list, so we 3158*7c478bd9Sstevel@tonic-gate * push those on to our stack first. 3159*7c478bd9Sstevel@tonic-gate */ 3160*7c478bd9Sstevel@tonic-gate eqd_push_list(eqdp, (uintptr_t)eq.eq_pend); 3161*7c478bd9Sstevel@tonic-gate 3162*7c478bd9Sstevel@tonic-gate /* 3163*7c478bd9Sstevel@tonic-gate * If eq_ptail is set, it may point to a subset of the errors on the 3164*7c478bd9Sstevel@tonic-gate * pending list in the event a casptr() failed; if ptail's data is 3165*7c478bd9Sstevel@tonic-gate * already in our stack, NULL out eq_ptail and ignore it. 3166*7c478bd9Sstevel@tonic-gate */ 3167*7c478bd9Sstevel@tonic-gate if (eq.eq_ptail != NULL) { 3168*7c478bd9Sstevel@tonic-gate for (i = 0; i < eqdp->eqd_qpos; i++) { 3169*7c478bd9Sstevel@tonic-gate if (eqdp->eqd_stack[i] == (uintptr_t)eqe.eqe_data) { 3170*7c478bd9Sstevel@tonic-gate eq.eq_ptail = NULL; 3171*7c478bd9Sstevel@tonic-gate break; 3172*7c478bd9Sstevel@tonic-gate } 3173*7c478bd9Sstevel@tonic-gate } 3174*7c478bd9Sstevel@tonic-gate } 3175*7c478bd9Sstevel@tonic-gate 3176*7c478bd9Sstevel@tonic-gate /* 3177*7c478bd9Sstevel@tonic-gate * If eq_phead is set, it has the processing list in order from oldest 3178*7c478bd9Sstevel@tonic-gate * to newest. Use this to recompute eq_ptail as best we can and then 3179*7c478bd9Sstevel@tonic-gate * we nicely fall into eqd_push_list() of eq_ptail below. 3180*7c478bd9Sstevel@tonic-gate */ 3181*7c478bd9Sstevel@tonic-gate for (addr = eq.eq_phead; addr != NULL && mdb_vread(&eqe, sizeof (eqe), 3182*7c478bd9Sstevel@tonic-gate (uintptr_t)addr) == sizeof (eqe); addr = eqe.eqe_next) 3183*7c478bd9Sstevel@tonic-gate eq.eq_ptail = addr; 3184*7c478bd9Sstevel@tonic-gate 3185*7c478bd9Sstevel@tonic-gate /* 3186*7c478bd9Sstevel@tonic-gate * The oldest elements in the queue are on the processing list, subject 3187*7c478bd9Sstevel@tonic-gate * to machinations in the if-clauses above. Push any such elements. 3188*7c478bd9Sstevel@tonic-gate */ 3189*7c478bd9Sstevel@tonic-gate eqd_push_list(eqdp, (uintptr_t)eq.eq_ptail); 3190*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 3191*7c478bd9Sstevel@tonic-gate } 3192*7c478bd9Sstevel@tonic-gate 3193*7c478bd9Sstevel@tonic-gate static int 3194*7c478bd9Sstevel@tonic-gate eqd_walk_step(mdb_walk_state_t *wsp) 3195*7c478bd9Sstevel@tonic-gate { 3196*7c478bd9Sstevel@tonic-gate eqd_walk_data_t *eqdp = wsp->walk_data; 3197*7c478bd9Sstevel@tonic-gate uintptr_t addr; 3198*7c478bd9Sstevel@tonic-gate 3199*7c478bd9Sstevel@tonic-gate if (eqdp->eqd_qpos == 0) 3200*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 3201*7c478bd9Sstevel@tonic-gate 3202*7c478bd9Sstevel@tonic-gate addr = eqdp->eqd_stack[--eqdp->eqd_qpos]; 3203*7c478bd9Sstevel@tonic-gate 3204*7c478bd9Sstevel@tonic-gate if (mdb_vread(eqdp->eqd_buf, eqdp->eqd_size, addr) != eqdp->eqd_size) { 3205*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq data at %p", addr); 3206*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 3207*7c478bd9Sstevel@tonic-gate } 3208*7c478bd9Sstevel@tonic-gate 3209*7c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, eqdp->eqd_buf, wsp->walk_cbdata)); 3210*7c478bd9Sstevel@tonic-gate } 3211*7c478bd9Sstevel@tonic-gate 3212*7c478bd9Sstevel@tonic-gate static void 3213*7c478bd9Sstevel@tonic-gate eqd_walk_fini(mdb_walk_state_t *wsp) 3214*7c478bd9Sstevel@tonic-gate { 3215*7c478bd9Sstevel@tonic-gate eqd_walk_data_t *eqdp = wsp->walk_data; 3216*7c478bd9Sstevel@tonic-gate 3217*7c478bd9Sstevel@tonic-gate mdb_free(eqdp->eqd_stack, sizeof (uintptr_t) * eqdp->eqd_qlen); 3218*7c478bd9Sstevel@tonic-gate mdb_free(eqdp->eqd_buf, eqdp->eqd_size); 3219*7c478bd9Sstevel@tonic-gate mdb_free(eqdp, sizeof (eqd_walk_data_t)); 3220*7c478bd9Sstevel@tonic-gate } 3221*7c478bd9Sstevel@tonic-gate 3222*7c478bd9Sstevel@tonic-gate #define EQKSVAL(eqv, what) (eqv.eq_kstat.what.value.ui64) 3223*7c478bd9Sstevel@tonic-gate 3224*7c478bd9Sstevel@tonic-gate static int 3225*7c478bd9Sstevel@tonic-gate errorq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3226*7c478bd9Sstevel@tonic-gate { 3227*7c478bd9Sstevel@tonic-gate int i; 3228*7c478bd9Sstevel@tonic-gate errorq_t eq; 3229*7c478bd9Sstevel@tonic-gate uint_t opt_v = FALSE; 3230*7c478bd9Sstevel@tonic-gate 3231*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 3232*7c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("errorq", "errorq", argc, argv) == -1) { 3233*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'errorq'"); 3234*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3235*7c478bd9Sstevel@tonic-gate } 3236*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 3237*7c478bd9Sstevel@tonic-gate } 3238*7c478bd9Sstevel@tonic-gate 3239*7c478bd9Sstevel@tonic-gate i = mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &opt_v, NULL); 3240*7c478bd9Sstevel@tonic-gate argc -= i; 3241*7c478bd9Sstevel@tonic-gate argv += i; 3242*7c478bd9Sstevel@tonic-gate 3243*7c478bd9Sstevel@tonic-gate if (argc != 0) 3244*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 3245*7c478bd9Sstevel@tonic-gate 3246*7c478bd9Sstevel@tonic-gate if (opt_v || DCMD_HDRSPEC(flags)) { 3247*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-11s %-16s %1s %1s %1s ", 3248*7c478bd9Sstevel@tonic-gate "ADDR", "NAME", "S", "V", "N"); 3249*7c478bd9Sstevel@tonic-gate if (!opt_v) { 3250*7c478bd9Sstevel@tonic-gate mdb_printf("%7s %7s %7s%</u>\n", 3251*7c478bd9Sstevel@tonic-gate "ACCEPT", "DROP", "LOG"); 3252*7c478bd9Sstevel@tonic-gate } else { 3253*7c478bd9Sstevel@tonic-gate mdb_printf("%5s %6s %6s %3s %16s%</u>\n", 3254*7c478bd9Sstevel@tonic-gate "KSTAT", "QLEN", "SIZE", "IPL", "FUNC"); 3255*7c478bd9Sstevel@tonic-gate } 3256*7c478bd9Sstevel@tonic-gate } 3257*7c478bd9Sstevel@tonic-gate 3258*7c478bd9Sstevel@tonic-gate if (mdb_vread(&eq, sizeof (eq), addr) != sizeof (eq)) { 3259*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq at %p", addr); 3260*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3261*7c478bd9Sstevel@tonic-gate } 3262*7c478bd9Sstevel@tonic-gate 3263*7c478bd9Sstevel@tonic-gate mdb_printf("%-11p %-16s %c %c %c ", addr, eq.eq_name, 3264*7c478bd9Sstevel@tonic-gate (eq.eq_flags & ERRORQ_ACTIVE) ? '+' : '-', 3265*7c478bd9Sstevel@tonic-gate (eq.eq_flags & ERRORQ_VITAL) ? '!' : ' ', 3266*7c478bd9Sstevel@tonic-gate (eq.eq_flags & ERRORQ_NVLIST) ? '*' : ' '); 3267*7c478bd9Sstevel@tonic-gate 3268*7c478bd9Sstevel@tonic-gate if (!opt_v) { 3269*7c478bd9Sstevel@tonic-gate mdb_printf("%7llu %7llu %7llu\n", 3270*7c478bd9Sstevel@tonic-gate EQKSVAL(eq, eqk_dispatched) + EQKSVAL(eq, eqk_committed), 3271*7c478bd9Sstevel@tonic-gate EQKSVAL(eq, eqk_dropped) + EQKSVAL(eq, eqk_reserve_fail) + 3272*7c478bd9Sstevel@tonic-gate EQKSVAL(eq, eqk_commit_fail), EQKSVAL(eq, eqk_logged)); 3273*7c478bd9Sstevel@tonic-gate } else { 3274*7c478bd9Sstevel@tonic-gate mdb_printf("%5s %6lu %6lu %3u %a\n", 3275*7c478bd9Sstevel@tonic-gate " | ", eq.eq_qlen, eq.eq_size, eq.eq_ipl, eq.eq_func); 3276*7c478bd9Sstevel@tonic-gate mdb_printf("%38s\n%41s" 3277*7c478bd9Sstevel@tonic-gate "%12s %llu\n" 3278*7c478bd9Sstevel@tonic-gate "%53s %llu\n" 3279*7c478bd9Sstevel@tonic-gate "%53s %llu\n" 3280*7c478bd9Sstevel@tonic-gate "%53s %llu\n" 3281*7c478bd9Sstevel@tonic-gate "%53s %llu\n" 3282*7c478bd9Sstevel@tonic-gate "%53s %llu\n" 3283*7c478bd9Sstevel@tonic-gate "%53s %llu\n" 3284*7c478bd9Sstevel@tonic-gate "%53s %llu\n\n", 3285*7c478bd9Sstevel@tonic-gate "|", "+-> ", 3286*7c478bd9Sstevel@tonic-gate "DISPATCHED", EQKSVAL(eq, eqk_dispatched), 3287*7c478bd9Sstevel@tonic-gate "DROPPED", EQKSVAL(eq, eqk_dropped), 3288*7c478bd9Sstevel@tonic-gate "LOGGED", EQKSVAL(eq, eqk_logged), 3289*7c478bd9Sstevel@tonic-gate "RESERVED", EQKSVAL(eq, eqk_reserved), 3290*7c478bd9Sstevel@tonic-gate "RESERVE FAIL", EQKSVAL(eq, eqk_reserve_fail), 3291*7c478bd9Sstevel@tonic-gate "COMMITTED", EQKSVAL(eq, eqk_committed), 3292*7c478bd9Sstevel@tonic-gate "COMMIT FAIL", EQKSVAL(eq, eqk_commit_fail), 3293*7c478bd9Sstevel@tonic-gate "CANCELLED", EQKSVAL(eq, eqk_cancelled)); 3294*7c478bd9Sstevel@tonic-gate } 3295*7c478bd9Sstevel@tonic-gate 3296*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 3297*7c478bd9Sstevel@tonic-gate } 3298*7c478bd9Sstevel@tonic-gate 3299*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3300*7c478bd9Sstevel@tonic-gate static int 3301*7c478bd9Sstevel@tonic-gate panicinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3302*7c478bd9Sstevel@tonic-gate { 3303*7c478bd9Sstevel@tonic-gate cpu_t panic_cpu; 3304*7c478bd9Sstevel@tonic-gate kthread_t *panic_thread; 3305*7c478bd9Sstevel@tonic-gate void *panicbuf; 3306*7c478bd9Sstevel@tonic-gate panic_data_t *pd; 3307*7c478bd9Sstevel@tonic-gate int i, n; 3308*7c478bd9Sstevel@tonic-gate 3309*7c478bd9Sstevel@tonic-gate if (!mdb_prop_postmortem) { 3310*7c478bd9Sstevel@tonic-gate mdb_warn("panicinfo can only be run on a system " 3311*7c478bd9Sstevel@tonic-gate "dump; see dumpadm(1M)\n"); 3312*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3313*7c478bd9Sstevel@tonic-gate } 3314*7c478bd9Sstevel@tonic-gate 3315*7c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC || argc != 0) 3316*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 3317*7c478bd9Sstevel@tonic-gate 3318*7c478bd9Sstevel@tonic-gate if (mdb_readsym(&panic_cpu, sizeof (cpu_t), "panic_cpu") == -1) 3319*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'panic_cpu'"); 3320*7c478bd9Sstevel@tonic-gate else 3321*7c478bd9Sstevel@tonic-gate mdb_printf("%16s %?d\n", "cpu", panic_cpu.cpu_id); 3322*7c478bd9Sstevel@tonic-gate 3323*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&panic_thread, "panic_thread") == -1) 3324*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'panic_thread'"); 3325*7c478bd9Sstevel@tonic-gate else 3326*7c478bd9Sstevel@tonic-gate mdb_printf("%16s %?p\n", "thread", panic_thread); 3327*7c478bd9Sstevel@tonic-gate 3328*7c478bd9Sstevel@tonic-gate panicbuf = mdb_alloc(PANICBUFSIZE, UM_SLEEP); 3329*7c478bd9Sstevel@tonic-gate pd = (panic_data_t *)panicbuf; 3330*7c478bd9Sstevel@tonic-gate 3331*7c478bd9Sstevel@tonic-gate if (mdb_readsym(panicbuf, PANICBUFSIZE, "panicbuf") == -1 || 3332*7c478bd9Sstevel@tonic-gate pd->pd_version != PANICBUFVERS) { 3333*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'panicbuf'"); 3334*7c478bd9Sstevel@tonic-gate mdb_free(panicbuf, PANICBUFSIZE); 3335*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3336*7c478bd9Sstevel@tonic-gate } 3337*7c478bd9Sstevel@tonic-gate 3338*7c478bd9Sstevel@tonic-gate mdb_printf("%16s %s\n", "message", (char *)panicbuf + pd->pd_msgoff); 3339*7c478bd9Sstevel@tonic-gate 3340*7c478bd9Sstevel@tonic-gate n = (pd->pd_msgoff - (sizeof (panic_data_t) - 3341*7c478bd9Sstevel@tonic-gate sizeof (panic_nv_t))) / sizeof (panic_nv_t); 3342*7c478bd9Sstevel@tonic-gate 3343*7c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) 3344*7c478bd9Sstevel@tonic-gate mdb_printf("%16s %?llx\n", 3345*7c478bd9Sstevel@tonic-gate pd->pd_nvdata[i].pnv_name, pd->pd_nvdata[i].pnv_value); 3346*7c478bd9Sstevel@tonic-gate 3347*7c478bd9Sstevel@tonic-gate mdb_free(panicbuf, PANICBUFSIZE); 3348*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 3349*7c478bd9Sstevel@tonic-gate } 3350*7c478bd9Sstevel@tonic-gate 3351*7c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 3352*7c478bd9Sstevel@tonic-gate 3353*7c478bd9Sstevel@tonic-gate /* from genunix.c */ 3354*7c478bd9Sstevel@tonic-gate { "addr2smap", ":[offset]", "translate address to smap", addr2smap }, 3355*7c478bd9Sstevel@tonic-gate { "as2proc", ":", "convert as to proc_t address", as2proc }, 3356*7c478bd9Sstevel@tonic-gate { "binding_hash_entry", ":", "print driver names hash table entry", 3357*7c478bd9Sstevel@tonic-gate binding_hash_entry }, 3358*7c478bd9Sstevel@tonic-gate { "callout", NULL, "print callout table", callout }, 3359*7c478bd9Sstevel@tonic-gate { "class", NULL, "print process scheduler classes", class }, 3360*7c478bd9Sstevel@tonic-gate { "cpuinfo", "?[-v]", "print CPUs and runnable threads", cpuinfo }, 3361*7c478bd9Sstevel@tonic-gate { "did2thread", "? kt_did", "find kernel thread for this id", 3362*7c478bd9Sstevel@tonic-gate did2thread }, 3363*7c478bd9Sstevel@tonic-gate { "errorq", "?[-v]", "display kernel error queues", errorq }, 3364*7c478bd9Sstevel@tonic-gate { "fd", ":[fd num]", "get a file pointer from an fd", fd }, 3365*7c478bd9Sstevel@tonic-gate { "flipone", ":", "the vik_rev_level 2 special", flipone }, 3366*7c478bd9Sstevel@tonic-gate { "lminfo", NULL, "print lock manager information", lminfo }, 3367*7c478bd9Sstevel@tonic-gate { "ndi_event_hdl", "?", "print ndi_event_hdl", ndi_event_hdl }, 3368*7c478bd9Sstevel@tonic-gate { "panicinfo", NULL, "print panic information", panicinfo }, 3369*7c478bd9Sstevel@tonic-gate { "pid2proc", "?", "convert PID to proc_t address", pid2proc }, 3370*7c478bd9Sstevel@tonic-gate { "pmap", ":[-q]", "print process memory map", pmap }, 3371*7c478bd9Sstevel@tonic-gate { "project", NULL, "display kernel project(s)", project }, 3372*7c478bd9Sstevel@tonic-gate { "ps", "[-fltzTP]", "list processes (and associated thr,lwp)", ps }, 3373*7c478bd9Sstevel@tonic-gate { "pgrep", "[-n | -o] pattern", "pattern match against all processes", 3374*7c478bd9Sstevel@tonic-gate pgrep }, 3375*7c478bd9Sstevel@tonic-gate { "ptree", NULL, "print process tree", ptree }, 3376*7c478bd9Sstevel@tonic-gate { "seg", ":", "print address space segment", seg }, 3377*7c478bd9Sstevel@tonic-gate { "sysevent", "?[-sv]", "print sysevent pending or sent queue", 3378*7c478bd9Sstevel@tonic-gate sysevent}, 3379*7c478bd9Sstevel@tonic-gate { "sysevent_channel", "?", "print sysevent channel database", 3380*7c478bd9Sstevel@tonic-gate sysevent_channel}, 3381*7c478bd9Sstevel@tonic-gate { "sysevent_class_list", ":", "print sysevent class list", 3382*7c478bd9Sstevel@tonic-gate sysevent_class_list}, 3383*7c478bd9Sstevel@tonic-gate { "sysevent_subclass_list", ":", 3384*7c478bd9Sstevel@tonic-gate "print sysevent subclass list", sysevent_subclass_list}, 3385*7c478bd9Sstevel@tonic-gate { "system", NULL, "print contents of /etc/system file", sysfile }, 3386*7c478bd9Sstevel@tonic-gate { "task", NULL, "display kernel task(s)", task }, 3387*7c478bd9Sstevel@tonic-gate { "taskq_entry", ":", "display a taskq_ent_t", taskq_ent }, 3388*7c478bd9Sstevel@tonic-gate { "vnode2path", ":[-F]", "vnode address to pathname", vnode2path }, 3389*7c478bd9Sstevel@tonic-gate { "vnode2smap", ":[offset]", "translate vnode to smap", vnode2smap }, 3390*7c478bd9Sstevel@tonic-gate { "whereopen", ":", "given a vnode, dumps procs which have it open", 3391*7c478bd9Sstevel@tonic-gate whereopen }, 3392*7c478bd9Sstevel@tonic-gate 3393*7c478bd9Sstevel@tonic-gate /* from zone.c */ 3394*7c478bd9Sstevel@tonic-gate { "zone", "?", "display kernel zone(s)", zoneprt }, 3395*7c478bd9Sstevel@tonic-gate { "zsd", ":[zsd key]", "lookup zsd value from a key", zsd }, 3396*7c478bd9Sstevel@tonic-gate 3397*7c478bd9Sstevel@tonic-gate /* from bio.c */ 3398*7c478bd9Sstevel@tonic-gate { "bufpagefind", ":addr", "find page_t on buf_t list", bufpagefind }, 3399*7c478bd9Sstevel@tonic-gate 3400*7c478bd9Sstevel@tonic-gate /* from contract.c */ 3401*7c478bd9Sstevel@tonic-gate { "contract", "?", "display a contract", cmd_contract }, 3402*7c478bd9Sstevel@tonic-gate { "ctevent", ":", "display a contract event", cmd_ctevent }, 3403*7c478bd9Sstevel@tonic-gate { "ctid", ":", "convert id to a contract pointer", cmd_ctid }, 3404*7c478bd9Sstevel@tonic-gate 3405*7c478bd9Sstevel@tonic-gate /* from cpupart.c */ 3406*7c478bd9Sstevel@tonic-gate { "cpupart", "?", "print cpu partition info", cpupart }, 3407*7c478bd9Sstevel@tonic-gate 3408*7c478bd9Sstevel@tonic-gate /* from cyclic.c */ 3409*7c478bd9Sstevel@tonic-gate { "cyccover", NULL, "dump cyclic coverage information", cyccover }, 3410*7c478bd9Sstevel@tonic-gate { "cycid", "?", "dump a cyclic id", cycid }, 3411*7c478bd9Sstevel@tonic-gate { "cycinfo", "?", "dump cyc_cpu info", cycinfo }, 3412*7c478bd9Sstevel@tonic-gate { "cyclic", ":", "developer information", cyclic }, 3413*7c478bd9Sstevel@tonic-gate { "cyctrace", "?", "dump cyclic trace buffer", cyctrace }, 3414*7c478bd9Sstevel@tonic-gate 3415*7c478bd9Sstevel@tonic-gate /* from devinfo.c */ 3416*7c478bd9Sstevel@tonic-gate { "devbindings", "?[-qs] [device-name | major-num]", 3417*7c478bd9Sstevel@tonic-gate "print devinfo nodes bound to device-name or major-num", 3418*7c478bd9Sstevel@tonic-gate devbindings, devinfo_help }, 3419*7c478bd9Sstevel@tonic-gate { "devinfo", ":[-qs]", "detailed devinfo of one node", devinfo, 3420*7c478bd9Sstevel@tonic-gate devinfo_help }, 3421*7c478bd9Sstevel@tonic-gate { "devinfo_audit", ":[-v]", "devinfo configuration audit record", 3422*7c478bd9Sstevel@tonic-gate devinfo_audit }, 3423*7c478bd9Sstevel@tonic-gate { "devinfo_audit_log", "?[-v]", "system wide devinfo configuration log", 3424*7c478bd9Sstevel@tonic-gate devinfo_audit_log }, 3425*7c478bd9Sstevel@tonic-gate { "devinfo_audit_node", ":[-v]", "devinfo node configuration history", 3426*7c478bd9Sstevel@tonic-gate devinfo_audit_node }, 3427*7c478bd9Sstevel@tonic-gate { "devinfo2driver", ":", "find driver name for this devinfo node", 3428*7c478bd9Sstevel@tonic-gate devinfo2driver }, 3429*7c478bd9Sstevel@tonic-gate { "devnames", "?[-vm] [num]", "print devnames array", devnames }, 3430*7c478bd9Sstevel@tonic-gate { "dev2major", "?<dev_t>", "convert dev_t to a major number", 3431*7c478bd9Sstevel@tonic-gate dev2major }, 3432*7c478bd9Sstevel@tonic-gate { "dev2minor", "?<dev_t>", "convert dev_t to a minor number", 3433*7c478bd9Sstevel@tonic-gate dev2minor }, 3434*7c478bd9Sstevel@tonic-gate { "devt", "?<dev_t>", "display a dev_t's major and minor numbers", 3435*7c478bd9Sstevel@tonic-gate devt }, 3436*7c478bd9Sstevel@tonic-gate { "major2name", "?<major-num>", "convert major number to dev name", 3437*7c478bd9Sstevel@tonic-gate major2name }, 3438*7c478bd9Sstevel@tonic-gate { "minornodes", ":", "given a devinfo node, print its minor nodes", 3439*7c478bd9Sstevel@tonic-gate minornodes }, 3440*7c478bd9Sstevel@tonic-gate { "modctl2devinfo", ":", "given a modctl, list its devinfos", 3441*7c478bd9Sstevel@tonic-gate modctl2devinfo }, 3442*7c478bd9Sstevel@tonic-gate { "name2major", "<dev-name>", "convert dev name to major number", 3443*7c478bd9Sstevel@tonic-gate name2major }, 3444*7c478bd9Sstevel@tonic-gate { "prtconf", "?[-vpc]", "print devinfo tree", prtconf, prtconf_help }, 3445*7c478bd9Sstevel@tonic-gate { "softstate", ":<instance>", "retrieve soft-state pointer", 3446*7c478bd9Sstevel@tonic-gate softstate }, 3447*7c478bd9Sstevel@tonic-gate { "devinfo_fm", ":", "devinfo fault managment configuration", 3448*7c478bd9Sstevel@tonic-gate devinfo_fm }, 3449*7c478bd9Sstevel@tonic-gate { "devinfo_fmce", ":", "devinfo fault managment cache entry", 3450*7c478bd9Sstevel@tonic-gate devinfo_fmce}, 3451*7c478bd9Sstevel@tonic-gate 3452*7c478bd9Sstevel@tonic-gate /* from findstack.c */ 3453*7c478bd9Sstevel@tonic-gate { "findstack", ":[-v]", "find kernel thread stack", findstack }, 3454*7c478bd9Sstevel@tonic-gate { "findstack_debug", NULL, "toggle findstack debugging", 3455*7c478bd9Sstevel@tonic-gate findstack_debug }, 3456*7c478bd9Sstevel@tonic-gate 3457*7c478bd9Sstevel@tonic-gate /* from kgrep.c + genunix.c */ 3458*7c478bd9Sstevel@tonic-gate { "kgrep", KGREP_USAGE, "search kernel as for a pointer", kgrep }, 3459*7c478bd9Sstevel@tonic-gate 3460*7c478bd9Sstevel@tonic-gate /* from kmem.c */ 3461*7c478bd9Sstevel@tonic-gate { "allocdby", ":", "given a thread, print its allocated buffers", 3462*7c478bd9Sstevel@tonic-gate allocdby }, 3463*7c478bd9Sstevel@tonic-gate { "bufctl", ":[-vh] [-a addr] [-c caller] [-e earliest] [-l latest] " 3464*7c478bd9Sstevel@tonic-gate "[-t thd]", "print or filter a bufctl", bufctl, bufctl_help }, 3465*7c478bd9Sstevel@tonic-gate { "freedby", ":", "given a thread, print its freed buffers", freedby }, 3466*7c478bd9Sstevel@tonic-gate { "kmalog", "?[ fail | slab ]", 3467*7c478bd9Sstevel@tonic-gate "display kmem transaction log and stack traces", kmalog }, 3468*7c478bd9Sstevel@tonic-gate { "kmastat", NULL, "kernel memory allocator stats", kmastat }, 3469*7c478bd9Sstevel@tonic-gate { "kmausers", "?[-ef] [cache ...]", "current medium and large users " 3470*7c478bd9Sstevel@tonic-gate "of the kmem allocator", kmausers, kmausers_help }, 3471*7c478bd9Sstevel@tonic-gate { "kmem_cache", "?", "print kernel memory caches", kmem_cache }, 3472*7c478bd9Sstevel@tonic-gate { "kmem_debug", NULL, "toggle kmem dcmd/walk debugging", kmem_debug }, 3473*7c478bd9Sstevel@tonic-gate { "kmem_log", "?[-b]", "dump kmem transaction log", kmem_log }, 3474*7c478bd9Sstevel@tonic-gate { "kmem_verify", "?", "check integrity of kmem-managed memory", 3475*7c478bd9Sstevel@tonic-gate kmem_verify }, 3476*7c478bd9Sstevel@tonic-gate { "vmem", "?", "print a vmem_t", vmem }, 3477*7c478bd9Sstevel@tonic-gate { "vmem_seg", ":[-sv] [-c caller] [-e earliest] [-l latest] " 3478*7c478bd9Sstevel@tonic-gate "[-m minsize] [-M maxsize] [-t thread] [-T type]", 3479*7c478bd9Sstevel@tonic-gate "print or filter a vmem_seg", vmem_seg, vmem_seg_help }, 3480*7c478bd9Sstevel@tonic-gate { "whatis", ":[-abiv]", "given an address, return information", whatis, 3481*7c478bd9Sstevel@tonic-gate whatis_help }, 3482*7c478bd9Sstevel@tonic-gate { "whatthread", ":[-v]", "print threads whose stack contains the " 3483*7c478bd9Sstevel@tonic-gate "given address", whatthread }, 3484*7c478bd9Sstevel@tonic-gate 3485*7c478bd9Sstevel@tonic-gate /* from ldi.c */ 3486*7c478bd9Sstevel@tonic-gate { "ldi_handle", "?[-i]", "display a layered driver handle", 3487*7c478bd9Sstevel@tonic-gate ldi_handle, ldi_handle_help }, 3488*7c478bd9Sstevel@tonic-gate { "ldi_ident", NULL, "display a layered driver identifier", 3489*7c478bd9Sstevel@tonic-gate ldi_ident, ldi_ident_help }, 3490*7c478bd9Sstevel@tonic-gate 3491*7c478bd9Sstevel@tonic-gate /* from leaky.c + leaky_subr.c */ 3492*7c478bd9Sstevel@tonic-gate { "findleaks", FINDLEAKS_USAGE, 3493*7c478bd9Sstevel@tonic-gate "search for potential kernel memory leaks", findleaks, 3494*7c478bd9Sstevel@tonic-gate findleaks_help }, 3495*7c478bd9Sstevel@tonic-gate 3496*7c478bd9Sstevel@tonic-gate /* from lgrp.c */ 3497*7c478bd9Sstevel@tonic-gate { "lgrp", "?[-q] [-p | -Pih]", "display an lgrp", lgrp}, 3498*7c478bd9Sstevel@tonic-gate 3499*7c478bd9Sstevel@tonic-gate /* from log.c */ 3500*7c478bd9Sstevel@tonic-gate { "msgbuf", "?[-v]", "print most recent console messages", msgbuf }, 3501*7c478bd9Sstevel@tonic-gate 3502*7c478bd9Sstevel@tonic-gate /* from memory.c */ 3503*7c478bd9Sstevel@tonic-gate { "page", "?", "display a summarized page_t", page }, 3504*7c478bd9Sstevel@tonic-gate { "memstat", NULL, "display memory usage summary", memstat }, 3505*7c478bd9Sstevel@tonic-gate { "memlist", "?[-iav]", "display a struct memlist", memlist }, 3506*7c478bd9Sstevel@tonic-gate { "swapinfo", "?", "display a struct swapinfo", swapinfof }, 3507*7c478bd9Sstevel@tonic-gate 3508*7c478bd9Sstevel@tonic-gate /* from mmd.c */ 3509*7c478bd9Sstevel@tonic-gate { "multidata", ":[-sv]", "display a summarized multidata_t", 3510*7c478bd9Sstevel@tonic-gate multidata }, 3511*7c478bd9Sstevel@tonic-gate { "pattbl", ":", "display a summarized multidata attribute table", 3512*7c478bd9Sstevel@tonic-gate pattbl }, 3513*7c478bd9Sstevel@tonic-gate { "pattr2multidata", ":", "print multidata pointer from pattr_t", 3514*7c478bd9Sstevel@tonic-gate pattr2multidata }, 3515*7c478bd9Sstevel@tonic-gate { "pdesc2slab", ":", "print pdesc slab pointer from pdesc_t", 3516*7c478bd9Sstevel@tonic-gate pdesc2slab }, 3517*7c478bd9Sstevel@tonic-gate { "pdesc_verify", ":", "verify integrity of a pdesc_t", pdesc_verify }, 3518*7c478bd9Sstevel@tonic-gate { "slab2multidata", ":", "print multidata pointer from pdesc_slab_t", 3519*7c478bd9Sstevel@tonic-gate slab2multidata }, 3520*7c478bd9Sstevel@tonic-gate 3521*7c478bd9Sstevel@tonic-gate /* from modhash.c */ 3522*7c478bd9Sstevel@tonic-gate { "modhash", "?[-ceht] [-k key] [-v val] [-i index]", 3523*7c478bd9Sstevel@tonic-gate "display information about one or all mod_hash structures", 3524*7c478bd9Sstevel@tonic-gate modhash, modhash_help }, 3525*7c478bd9Sstevel@tonic-gate { "modent", ":[-k | -v | -t type]", 3526*7c478bd9Sstevel@tonic-gate "display information about a mod_hash_entry", modent, 3527*7c478bd9Sstevel@tonic-gate modent_help }, 3528*7c478bd9Sstevel@tonic-gate 3529*7c478bd9Sstevel@tonic-gate /* from net.c */ 3530*7c478bd9Sstevel@tonic-gate { "mi", ":[-p] [-d | -m]", "filter and display MI object or payload", 3531*7c478bd9Sstevel@tonic-gate mi }, 3532*7c478bd9Sstevel@tonic-gate { "netstat", "[-av] [-f inet | inet6 | unix] [-P tcp | udp]", 3533*7c478bd9Sstevel@tonic-gate "show network statistics", netstat }, 3534*7c478bd9Sstevel@tonic-gate { "sonode", "?[-f inet | inet6 | unix | #] " 3535*7c478bd9Sstevel@tonic-gate "[-t stream | dgram | raw | #] [-p #]", 3536*7c478bd9Sstevel@tonic-gate "filter and display sonode", sonode }, 3537*7c478bd9Sstevel@tonic-gate 3538*7c478bd9Sstevel@tonic-gate /* from nvpair.c */ 3539*7c478bd9Sstevel@tonic-gate { NVPAIR_DCMD_NAME, NVPAIR_DCMD_USAGE, NVPAIR_DCMD_DESCR, 3540*7c478bd9Sstevel@tonic-gate nvpair_print }, 3541*7c478bd9Sstevel@tonic-gate 3542*7c478bd9Sstevel@tonic-gate /* from rctl.c */ 3543*7c478bd9Sstevel@tonic-gate { "rctl_dict", "?", "print systemwide default rctl definitions", 3544*7c478bd9Sstevel@tonic-gate rctl_dict }, 3545*7c478bd9Sstevel@tonic-gate { "rctl_list", ":[handle]", "print rctls for the given proc", 3546*7c478bd9Sstevel@tonic-gate rctl_list }, 3547*7c478bd9Sstevel@tonic-gate { "rctl", ":[handle]", "print a rctl_t, only if it matches the handle", 3548*7c478bd9Sstevel@tonic-gate rctl }, 3549*7c478bd9Sstevel@tonic-gate { "rctl_validate", ":[-v] [-n #]", "test resource control value " 3550*7c478bd9Sstevel@tonic-gate "sequence", rctl_validate }, 3551*7c478bd9Sstevel@tonic-gate 3552*7c478bd9Sstevel@tonic-gate /* from sobj.c */ 3553*7c478bd9Sstevel@tonic-gate { "rwlock", ":", "dump out a readers/writer lock", rwlock }, 3554*7c478bd9Sstevel@tonic-gate { "mutex", ":[-f]", "dump out an adaptive or spin mutex", mutex, 3555*7c478bd9Sstevel@tonic-gate mutex_help }, 3556*7c478bd9Sstevel@tonic-gate { "sobj2ts", ":", "perform turnstile lookup on synch object", sobj2ts }, 3557*7c478bd9Sstevel@tonic-gate { "wchaninfo", "?[-v]", "dump condition variable", wchaninfo }, 3558*7c478bd9Sstevel@tonic-gate { "turnstile", "?", "display a turnstile", turnstile }, 3559*7c478bd9Sstevel@tonic-gate 3560*7c478bd9Sstevel@tonic-gate /* from stream.c */ 3561*7c478bd9Sstevel@tonic-gate { "mblk", ":[-q|v] [-f|F flag] [-t|T type] [-l|L|B len] [-d dbaddr]", 3562*7c478bd9Sstevel@tonic-gate "print an mblk", mblk_prt, mblk_help }, 3563*7c478bd9Sstevel@tonic-gate { "mblk_verify", "?", "verify integrity of an mblk", mblk_verify }, 3564*7c478bd9Sstevel@tonic-gate { "mblk2dblk", ":", "convert mblk_t address to dblk_t address", 3565*7c478bd9Sstevel@tonic-gate mblk2dblk }, 3566*7c478bd9Sstevel@tonic-gate { "q2otherq", ":", "print peer queue for a given queue", q2otherq }, 3567*7c478bd9Sstevel@tonic-gate { "q2rdq", ":", "print read queue for a given queue", q2rdq }, 3568*7c478bd9Sstevel@tonic-gate { "q2syncq", ":", "print syncq for a given queue", q2syncq }, 3569*7c478bd9Sstevel@tonic-gate { "q2stream", ":", "print stream pointer for a given queue", q2stream }, 3570*7c478bd9Sstevel@tonic-gate { "q2wrq", ":", "print write queue for a given queue", q2wrq }, 3571*7c478bd9Sstevel@tonic-gate { "queue", ":[-q|v] [-m mod] [-f flag] [-F flag] [-s syncq_addr]", 3572*7c478bd9Sstevel@tonic-gate "filter and display STREAM queue", queue, queue_help }, 3573*7c478bd9Sstevel@tonic-gate { "stdata", ":[-q|v] [-f flag] [-F flag]", 3574*7c478bd9Sstevel@tonic-gate "filter and display STREAM head", stdata, stdata_help }, 3575*7c478bd9Sstevel@tonic-gate { "str2mate", ":", "print mate of this stream", str2mate }, 3576*7c478bd9Sstevel@tonic-gate { "str2wrq", ":", "print write queue of this stream", str2wrq }, 3577*7c478bd9Sstevel@tonic-gate { "stream", ":", "display STREAM", stream }, 3578*7c478bd9Sstevel@tonic-gate { "strftevent", ":", "print STREAMS flow trace event", strftevent }, 3579*7c478bd9Sstevel@tonic-gate { "syncq", ":[-q|v] [-f flag] [-F flag] [-t type] [-T type]", 3580*7c478bd9Sstevel@tonic-gate "filter and display STREAM sync queue", syncq, syncq_help }, 3581*7c478bd9Sstevel@tonic-gate { "syncq2q", ":", "print queue for a given syncq", syncq2q }, 3582*7c478bd9Sstevel@tonic-gate 3583*7c478bd9Sstevel@tonic-gate /* from thread.c */ 3584*7c478bd9Sstevel@tonic-gate { "thread", "?[-bdfimps]", "display a summarized kthread_t", thread, 3585*7c478bd9Sstevel@tonic-gate thread_help }, 3586*7c478bd9Sstevel@tonic-gate { "threadlist", "?[-v [count]]", 3587*7c478bd9Sstevel@tonic-gate "display threads and associated C stack traces", threadlist, 3588*7c478bd9Sstevel@tonic-gate threadlist_help }, 3589*7c478bd9Sstevel@tonic-gate 3590*7c478bd9Sstevel@tonic-gate /* from tsd.c */ 3591*7c478bd9Sstevel@tonic-gate { "tsd", ":-k key", "print tsd[key-1] for this thread", ttotsd }, 3592*7c478bd9Sstevel@tonic-gate { "tsdtot", ":", "find thread with this tsd", tsdtot }, 3593*7c478bd9Sstevel@tonic-gate 3594*7c478bd9Sstevel@tonic-gate /* 3595*7c478bd9Sstevel@tonic-gate * typegraph does not work under kmdb, as it requires too much memory 3596*7c478bd9Sstevel@tonic-gate * for its internal data structures. 3597*7c478bd9Sstevel@tonic-gate */ 3598*7c478bd9Sstevel@tonic-gate #ifndef _KMDB 3599*7c478bd9Sstevel@tonic-gate /* from typegraph.c */ 3600*7c478bd9Sstevel@tonic-gate { "findlocks", ":", "find locks held by specified thread", findlocks }, 3601*7c478bd9Sstevel@tonic-gate { "findfalse", "?[-v]", "find potentially falsely shared structures", 3602*7c478bd9Sstevel@tonic-gate findfalse }, 3603*7c478bd9Sstevel@tonic-gate { "typegraph", NULL, "build type graph", typegraph }, 3604*7c478bd9Sstevel@tonic-gate { "istype", ":type", "manually set object type", istype }, 3605*7c478bd9Sstevel@tonic-gate { "notype", ":", "manually clear object type", notype }, 3606*7c478bd9Sstevel@tonic-gate { "whattype", ":", "determine object type", whattype }, 3607*7c478bd9Sstevel@tonic-gate #endif 3608*7c478bd9Sstevel@tonic-gate 3609*7c478bd9Sstevel@tonic-gate /* from vfs.c */ 3610*7c478bd9Sstevel@tonic-gate { "fsinfo", "?[-v]", "print mounted filesystems", fsinfo }, 3611*7c478bd9Sstevel@tonic-gate { "pfiles", ":[-fp]", "print process file information", pfiles, 3612*7c478bd9Sstevel@tonic-gate pfiles_help }, 3613*7c478bd9Sstevel@tonic-gate 3614*7c478bd9Sstevel@tonic-gate { NULL } 3615*7c478bd9Sstevel@tonic-gate }; 3616*7c478bd9Sstevel@tonic-gate 3617*7c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 3618*7c478bd9Sstevel@tonic-gate 3619*7c478bd9Sstevel@tonic-gate /* from genunix.c */ 3620*7c478bd9Sstevel@tonic-gate { "avl", "given any avl_tree_t *, forward walk all entries in tree", 3621*7c478bd9Sstevel@tonic-gate avl_walk_init, avl_walk_step, avl_walk_fini }, 3622*7c478bd9Sstevel@tonic-gate { "anon", "given an amp, list of anon structures", 3623*7c478bd9Sstevel@tonic-gate anon_walk_init, anon_walk_step, anon_walk_fini }, 3624*7c478bd9Sstevel@tonic-gate { "cpu", "walk cpu structures", cpu_walk_init, cpu_walk_step }, 3625*7c478bd9Sstevel@tonic-gate { "errorq", "walk list of system error queues", 3626*7c478bd9Sstevel@tonic-gate errorq_walk_init, errorq_walk_step, NULL }, 3627*7c478bd9Sstevel@tonic-gate { "errorq_data", "walk pending error queue data buffers", 3628*7c478bd9Sstevel@tonic-gate eqd_walk_init, eqd_walk_step, eqd_walk_fini }, 3629*7c478bd9Sstevel@tonic-gate { "allfile", "given a proc pointer, list all file pointers", 3630*7c478bd9Sstevel@tonic-gate file_walk_init, allfile_walk_step, file_walk_fini }, 3631*7c478bd9Sstevel@tonic-gate { "file", "given a proc pointer, list of open file pointers", 3632*7c478bd9Sstevel@tonic-gate file_walk_init, file_walk_step, file_walk_fini }, 3633*7c478bd9Sstevel@tonic-gate { "lock_descriptor", "walk lock_descriptor_t structures", 3634*7c478bd9Sstevel@tonic-gate ld_walk_init, ld_walk_step, NULL }, 3635*7c478bd9Sstevel@tonic-gate { "lock_graph", "walk lock graph", 3636*7c478bd9Sstevel@tonic-gate lg_walk_init, lg_walk_step, NULL }, 3637*7c478bd9Sstevel@tonic-gate { "port", "given a proc pointer, list of created event ports", 3638*7c478bd9Sstevel@tonic-gate port_walk_init, port_walk_step, NULL }, 3639*7c478bd9Sstevel@tonic-gate { "portev", "given a port pointer, list of events in the queue", 3640*7c478bd9Sstevel@tonic-gate portev_walk_init, portev_walk_step, portev_walk_fini }, 3641*7c478bd9Sstevel@tonic-gate { "proc", "list of active proc_t structures", 3642*7c478bd9Sstevel@tonic-gate proc_walk_init, proc_walk_step, proc_walk_fini }, 3643*7c478bd9Sstevel@tonic-gate { "projects", "walk a list of kernel projects", 3644*7c478bd9Sstevel@tonic-gate project_walk_init, project_walk_step, NULL }, 3645*7c478bd9Sstevel@tonic-gate { "seg", "given an as, list of segments", 3646*7c478bd9Sstevel@tonic-gate seg_walk_init, avl_walk_step, avl_walk_fini }, 3647*7c478bd9Sstevel@tonic-gate { "sysevent_pend", "walk sysevent pending queue", 3648*7c478bd9Sstevel@tonic-gate sysevent_pend_walk_init, sysevent_walk_step, 3649*7c478bd9Sstevel@tonic-gate sysevent_walk_fini}, 3650*7c478bd9Sstevel@tonic-gate { "sysevent_sent", "walk sysevent sent queue", sysevent_sent_walk_init, 3651*7c478bd9Sstevel@tonic-gate sysevent_walk_step, sysevent_walk_fini}, 3652*7c478bd9Sstevel@tonic-gate { "sysevent_channel", "walk sysevent channel subscriptions", 3653*7c478bd9Sstevel@tonic-gate sysevent_channel_walk_init, sysevent_channel_walk_step, 3654*7c478bd9Sstevel@tonic-gate sysevent_channel_walk_fini}, 3655*7c478bd9Sstevel@tonic-gate { "sysevent_class_list", "walk sysevent subscription's class list", 3656*7c478bd9Sstevel@tonic-gate sysevent_class_list_walk_init, sysevent_class_list_walk_step, 3657*7c478bd9Sstevel@tonic-gate sysevent_class_list_walk_fini}, 3658*7c478bd9Sstevel@tonic-gate { "sysevent_subclass_list", 3659*7c478bd9Sstevel@tonic-gate "walk sysevent subscription's subclass list", 3660*7c478bd9Sstevel@tonic-gate sysevent_subclass_list_walk_init, 3661*7c478bd9Sstevel@tonic-gate sysevent_subclass_list_walk_step, 3662*7c478bd9Sstevel@tonic-gate sysevent_subclass_list_walk_fini}, 3663*7c478bd9Sstevel@tonic-gate { "task", "given a task pointer, walk its processes", 3664*7c478bd9Sstevel@tonic-gate task_walk_init, task_walk_step, NULL }, 3665*7c478bd9Sstevel@tonic-gate { "taskq_entry", "given a taskq_t*, list all taskq_ent_t in the list", 3666*7c478bd9Sstevel@tonic-gate taskq_walk_init, taskq_walk_step, NULL, NULL }, 3667*7c478bd9Sstevel@tonic-gate 3668*7c478bd9Sstevel@tonic-gate /* from zone.c */ 3669*7c478bd9Sstevel@tonic-gate { "zone", "walk a list of kernel zones", 3670*7c478bd9Sstevel@tonic-gate zone_walk_init, zone_walk_step, NULL }, 3671*7c478bd9Sstevel@tonic-gate { "zsd", "walk list of zsd entries for a zone", 3672*7c478bd9Sstevel@tonic-gate zsd_walk_init, zsd_walk_step, NULL }, 3673*7c478bd9Sstevel@tonic-gate 3674*7c478bd9Sstevel@tonic-gate /* from bio.c */ 3675*7c478bd9Sstevel@tonic-gate { "buf", "walk the bio buf hash", 3676*7c478bd9Sstevel@tonic-gate buf_walk_init, buf_walk_step, buf_walk_fini }, 3677*7c478bd9Sstevel@tonic-gate 3678*7c478bd9Sstevel@tonic-gate /* from contract.c */ 3679*7c478bd9Sstevel@tonic-gate { "contract", "walk all contracts, or those of the specified type", 3680*7c478bd9Sstevel@tonic-gate ct_walk_init, generic_walk_step, NULL }, 3681*7c478bd9Sstevel@tonic-gate { "ct_event", "walk events on a contract event queue", 3682*7c478bd9Sstevel@tonic-gate ct_event_walk_init, generic_walk_step, NULL }, 3683*7c478bd9Sstevel@tonic-gate { "ct_listener", "walk contract event queue listeners", 3684*7c478bd9Sstevel@tonic-gate ct_listener_walk_init, generic_walk_step, NULL }, 3685*7c478bd9Sstevel@tonic-gate 3686*7c478bd9Sstevel@tonic-gate /* from cpupart.c */ 3687*7c478bd9Sstevel@tonic-gate { "cpupart_cpulist", "given an cpupart_t, walk cpus in partition", 3688*7c478bd9Sstevel@tonic-gate cpupart_cpulist_walk_init, cpupart_cpulist_walk_step, 3689*7c478bd9Sstevel@tonic-gate NULL }, 3690*7c478bd9Sstevel@tonic-gate { "cpupart_walk", "walk the set of cpu partitions", 3691*7c478bd9Sstevel@tonic-gate cpupart_walk_init, cpupart_walk_step, NULL }, 3692*7c478bd9Sstevel@tonic-gate 3693*7c478bd9Sstevel@tonic-gate /* from ctxop.c */ 3694*7c478bd9Sstevel@tonic-gate { "ctxop", "walk list of context ops on a thread", 3695*7c478bd9Sstevel@tonic-gate ctxop_walk_init, ctxop_walk_step, ctxop_walk_fini }, 3696*7c478bd9Sstevel@tonic-gate 3697*7c478bd9Sstevel@tonic-gate /* from cyclic.c */ 3698*7c478bd9Sstevel@tonic-gate { "cyccpu", "walk per-CPU cyc_cpu structures", 3699*7c478bd9Sstevel@tonic-gate cyccpu_walk_init, cyccpu_walk_step, NULL }, 3700*7c478bd9Sstevel@tonic-gate { "cycomni", "for an omnipresent cyclic, walk cyc_omni_cpu list", 3701*7c478bd9Sstevel@tonic-gate cycomni_walk_init, cycomni_walk_step, NULL }, 3702*7c478bd9Sstevel@tonic-gate { "cyctrace", "walk cyclic trace buffer", 3703*7c478bd9Sstevel@tonic-gate cyctrace_walk_init, cyctrace_walk_step, cyctrace_walk_fini }, 3704*7c478bd9Sstevel@tonic-gate 3705*7c478bd9Sstevel@tonic-gate /* from devinfo.c */ 3706*7c478bd9Sstevel@tonic-gate { "binding_hash", "walk all entries in binding hash table", 3707*7c478bd9Sstevel@tonic-gate binding_hash_walk_init, binding_hash_walk_step, NULL }, 3708*7c478bd9Sstevel@tonic-gate { "devinfo", "walk devinfo tree or subtree", 3709*7c478bd9Sstevel@tonic-gate devinfo_walk_init, devinfo_walk_step, devinfo_walk_fini }, 3710*7c478bd9Sstevel@tonic-gate { "devinfo_audit_log", "walk devinfo audit system-wide log", 3711*7c478bd9Sstevel@tonic-gate devinfo_audit_log_walk_init, devinfo_audit_log_walk_step, 3712*7c478bd9Sstevel@tonic-gate devinfo_audit_log_walk_fini}, 3713*7c478bd9Sstevel@tonic-gate { "devinfo_audit_node", "walk per-devinfo audit history", 3714*7c478bd9Sstevel@tonic-gate devinfo_audit_node_walk_init, devinfo_audit_node_walk_step, 3715*7c478bd9Sstevel@tonic-gate devinfo_audit_node_walk_fini}, 3716*7c478bd9Sstevel@tonic-gate { "devinfo_children", "walk children of devinfo node", 3717*7c478bd9Sstevel@tonic-gate devinfo_children_walk_init, devinfo_children_walk_step, 3718*7c478bd9Sstevel@tonic-gate devinfo_children_walk_fini }, 3719*7c478bd9Sstevel@tonic-gate { "devinfo_parents", "walk ancestors of devinfo node", 3720*7c478bd9Sstevel@tonic-gate devinfo_parents_walk_init, devinfo_parents_walk_step, 3721*7c478bd9Sstevel@tonic-gate devinfo_parents_walk_fini }, 3722*7c478bd9Sstevel@tonic-gate { "devinfo_siblings", "walk siblings of devinfo node", 3723*7c478bd9Sstevel@tonic-gate devinfo_siblings_walk_init, devinfo_siblings_walk_step, NULL }, 3724*7c478bd9Sstevel@tonic-gate { "devi_next", "walk devinfo list", 3725*7c478bd9Sstevel@tonic-gate NULL, devi_next_walk_step, NULL }, 3726*7c478bd9Sstevel@tonic-gate { "devnames", "walk devnames array", 3727*7c478bd9Sstevel@tonic-gate devnames_walk_init, devnames_walk_step, devnames_walk_fini }, 3728*7c478bd9Sstevel@tonic-gate { "minornode", "given a devinfo node, walk minor nodes", 3729*7c478bd9Sstevel@tonic-gate minornode_walk_init, minornode_walk_step, NULL }, 3730*7c478bd9Sstevel@tonic-gate { "softstate", 3731*7c478bd9Sstevel@tonic-gate "given an i_ddi_soft_state*, list all in-use driver stateps", 3732*7c478bd9Sstevel@tonic-gate soft_state_walk_init, soft_state_walk_step, 3733*7c478bd9Sstevel@tonic-gate NULL, NULL }, 3734*7c478bd9Sstevel@tonic-gate { "softstate_all", 3735*7c478bd9Sstevel@tonic-gate "given an i_ddi_soft_state*, list all driver stateps", 3736*7c478bd9Sstevel@tonic-gate soft_state_walk_init, soft_state_all_walk_step, 3737*7c478bd9Sstevel@tonic-gate NULL, NULL }, 3738*7c478bd9Sstevel@tonic-gate { "devinfo_fmc", 3739*7c478bd9Sstevel@tonic-gate "walk a fault management handle cache active list", 3740*7c478bd9Sstevel@tonic-gate devinfo_fmc_walk_init, devinfo_fmc_walk_step, NULL }, 3741*7c478bd9Sstevel@tonic-gate 3742*7c478bd9Sstevel@tonic-gate /* from kmem.c */ 3743*7c478bd9Sstevel@tonic-gate { "allocdby", "given a thread, walk its allocated bufctls", 3744*7c478bd9Sstevel@tonic-gate allocdby_walk_init, allocdby_walk_step, allocdby_walk_fini }, 3745*7c478bd9Sstevel@tonic-gate { "bufctl", "walk a kmem cache's bufctls", 3746*7c478bd9Sstevel@tonic-gate bufctl_walk_init, kmem_walk_step, kmem_walk_fini }, 3747*7c478bd9Sstevel@tonic-gate { "bufctl_history", "walk the available history of a bufctl", 3748*7c478bd9Sstevel@tonic-gate bufctl_history_walk_init, bufctl_history_walk_step, 3749*7c478bd9Sstevel@tonic-gate bufctl_history_walk_fini }, 3750*7c478bd9Sstevel@tonic-gate { "freedby", "given a thread, walk its freed bufctls", 3751*7c478bd9Sstevel@tonic-gate freedby_walk_init, allocdby_walk_step, allocdby_walk_fini }, 3752*7c478bd9Sstevel@tonic-gate { "freectl", "walk a kmem cache's free bufctls", 3753*7c478bd9Sstevel@tonic-gate freectl_walk_init, kmem_walk_step, kmem_walk_fini }, 3754*7c478bd9Sstevel@tonic-gate { "freectl_constructed", "walk a kmem cache's constructed free bufctls", 3755*7c478bd9Sstevel@tonic-gate freectl_constructed_walk_init, kmem_walk_step, kmem_walk_fini }, 3756*7c478bd9Sstevel@tonic-gate { "freemem", "walk a kmem cache's free memory", 3757*7c478bd9Sstevel@tonic-gate freemem_walk_init, kmem_walk_step, kmem_walk_fini }, 3758*7c478bd9Sstevel@tonic-gate { "freemem_constructed", "walk a kmem cache's constructed free memory", 3759*7c478bd9Sstevel@tonic-gate freemem_constructed_walk_init, kmem_walk_step, kmem_walk_fini }, 3760*7c478bd9Sstevel@tonic-gate { "kmem", "walk a kmem cache", 3761*7c478bd9Sstevel@tonic-gate kmem_walk_init, kmem_walk_step, kmem_walk_fini }, 3762*7c478bd9Sstevel@tonic-gate { "kmem_cpu_cache", "given a kmem cache, walk its per-CPU caches", 3763*7c478bd9Sstevel@tonic-gate kmem_cpu_cache_walk_init, kmem_cpu_cache_walk_step, NULL }, 3764*7c478bd9Sstevel@tonic-gate { "kmem_hash", "given a kmem cache, walk its allocated hash table", 3765*7c478bd9Sstevel@tonic-gate kmem_hash_walk_init, kmem_hash_walk_step, kmem_hash_walk_fini }, 3766*7c478bd9Sstevel@tonic-gate { "kmem_log", "walk the kmem transaction log", 3767*7c478bd9Sstevel@tonic-gate kmem_log_walk_init, kmem_log_walk_step, kmem_log_walk_fini }, 3768*7c478bd9Sstevel@tonic-gate { "kmem_slab", "given a kmem cache, walk its slabs", 3769*7c478bd9Sstevel@tonic-gate kmem_slab_walk_init, kmem_slab_walk_step, NULL }, 3770*7c478bd9Sstevel@tonic-gate { "kmem_slab_partial", 3771*7c478bd9Sstevel@tonic-gate "given a kmem cache, walk its partially allocated slabs (min 1)", 3772*7c478bd9Sstevel@tonic-gate kmem_slab_walk_partial_init, kmem_slab_walk_step, NULL }, 3773*7c478bd9Sstevel@tonic-gate { "vmem", "walk vmem structures in pre-fix, depth-first order", 3774*7c478bd9Sstevel@tonic-gate vmem_walk_init, vmem_walk_step, vmem_walk_fini }, 3775*7c478bd9Sstevel@tonic-gate { "vmem_alloc", "given a vmem_t, walk its allocated vmem_segs", 3776*7c478bd9Sstevel@tonic-gate vmem_alloc_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 3777*7c478bd9Sstevel@tonic-gate { "vmem_free", "given a vmem_t, walk its free vmem_segs", 3778*7c478bd9Sstevel@tonic-gate vmem_free_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 3779*7c478bd9Sstevel@tonic-gate { "vmem_postfix", "walk vmem structures in post-fix, depth-first order", 3780*7c478bd9Sstevel@tonic-gate vmem_walk_init, vmem_postfix_walk_step, vmem_walk_fini }, 3781*7c478bd9Sstevel@tonic-gate { "vmem_seg", "given a vmem_t, walk all of its vmem_segs", 3782*7c478bd9Sstevel@tonic-gate vmem_seg_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 3783*7c478bd9Sstevel@tonic-gate { "vmem_span", "given a vmem_t, walk its spanning vmem_segs", 3784*7c478bd9Sstevel@tonic-gate vmem_span_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 3785*7c478bd9Sstevel@tonic-gate 3786*7c478bd9Sstevel@tonic-gate /* from ldi.c */ 3787*7c478bd9Sstevel@tonic-gate { "ldi_handle", "walk the layered driver handle hash", 3788*7c478bd9Sstevel@tonic-gate ldi_handle_walk_init, ldi_handle_walk_step, NULL }, 3789*7c478bd9Sstevel@tonic-gate { "ldi_ident", "walk the layered driver identifier hash", 3790*7c478bd9Sstevel@tonic-gate ldi_ident_walk_init, ldi_ident_walk_step, NULL }, 3791*7c478bd9Sstevel@tonic-gate 3792*7c478bd9Sstevel@tonic-gate /* from leaky.c + leaky_subr.c */ 3793*7c478bd9Sstevel@tonic-gate { "leak", "given a leaked bufctl or vmem_seg, find leaks w/ same " 3794*7c478bd9Sstevel@tonic-gate "stack trace", 3795*7c478bd9Sstevel@tonic-gate leaky_walk_init, leaky_walk_step, leaky_walk_fini }, 3796*7c478bd9Sstevel@tonic-gate { "leakbuf", "given a leaked bufctl or vmem_seg, walk buffers for " 3797*7c478bd9Sstevel@tonic-gate "leaks w/ same stack trace", 3798*7c478bd9Sstevel@tonic-gate leaky_walk_init, leaky_buf_walk_step, leaky_walk_fini }, 3799*7c478bd9Sstevel@tonic-gate 3800*7c478bd9Sstevel@tonic-gate /* from lgrp.c */ 3801*7c478bd9Sstevel@tonic-gate { "lgrp_cpulist", "given an lgrp, walk cpus", 3802*7c478bd9Sstevel@tonic-gate lgrp_cpulist_walk_init, lgrp_cpulist_walk_step, 3803*7c478bd9Sstevel@tonic-gate NULL }, 3804*7c478bd9Sstevel@tonic-gate { "lgrptbl", "walk the lgrp table", 3805*7c478bd9Sstevel@tonic-gate lgrp_walk_init, lgrp_walk_step, NULL }, 3806*7c478bd9Sstevel@tonic-gate 3807*7c478bd9Sstevel@tonic-gate /* from list.c */ 3808*7c478bd9Sstevel@tonic-gate { "list", "walk a linked list", 3809*7c478bd9Sstevel@tonic-gate list_walk_init, list_walk_step, list_walk_fini }, 3810*7c478bd9Sstevel@tonic-gate 3811*7c478bd9Sstevel@tonic-gate /* from memory.c */ 3812*7c478bd9Sstevel@tonic-gate { "page", "walk all pages, or those from the specified vnode", 3813*7c478bd9Sstevel@tonic-gate page_walk_init, page_walk_step, page_walk_fini }, 3814*7c478bd9Sstevel@tonic-gate { "memlist", "walk specified memlist", 3815*7c478bd9Sstevel@tonic-gate NULL, memlist_walk_step, NULL }, 3816*7c478bd9Sstevel@tonic-gate { "swapinfo", "walk swapinfo structures", 3817*7c478bd9Sstevel@tonic-gate swap_walk_init, swap_walk_step, NULL }, 3818*7c478bd9Sstevel@tonic-gate 3819*7c478bd9Sstevel@tonic-gate /* from mmd.c */ 3820*7c478bd9Sstevel@tonic-gate { "pattr", "walk pattr_t structures", pattr_walk_init, 3821*7c478bd9Sstevel@tonic-gate mmdq_walk_step, mmdq_walk_fini }, 3822*7c478bd9Sstevel@tonic-gate { "pdesc", "walk pdesc_t structures", 3823*7c478bd9Sstevel@tonic-gate pdesc_walk_init, mmdq_walk_step, mmdq_walk_fini }, 3824*7c478bd9Sstevel@tonic-gate { "pdesc_slab", "walk pdesc_slab_t structures", 3825*7c478bd9Sstevel@tonic-gate pdesc_slab_walk_init, mmdq_walk_step, mmdq_walk_fini }, 3826*7c478bd9Sstevel@tonic-gate 3827*7c478bd9Sstevel@tonic-gate /* from modhash.c */ 3828*7c478bd9Sstevel@tonic-gate { "modhash", "walk list of mod_hash structures", modhash_walk_init, 3829*7c478bd9Sstevel@tonic-gate modhash_walk_step, NULL }, 3830*7c478bd9Sstevel@tonic-gate { "modent", "walk list of entries in a given mod_hash", 3831*7c478bd9Sstevel@tonic-gate modent_walk_init, modent_walk_step, modent_walk_fini }, 3832*7c478bd9Sstevel@tonic-gate { "modchain", "walk list of entries in a given mod_hash_entry", 3833*7c478bd9Sstevel@tonic-gate NULL, modchain_walk_step, NULL }, 3834*7c478bd9Sstevel@tonic-gate 3835*7c478bd9Sstevel@tonic-gate /* from net.c */ 3836*7c478bd9Sstevel@tonic-gate { "ar", "walk ar_t structures using MI", 3837*7c478bd9Sstevel@tonic-gate mi_payload_walk_init, mi_payload_walk_step, 3838*7c478bd9Sstevel@tonic-gate mi_payload_walk_fini, &mi_ar_arg }, 3839*7c478bd9Sstevel@tonic-gate { "icmp", "walk ICMP control structures using MI", 3840*7c478bd9Sstevel@tonic-gate mi_payload_walk_init, mi_payload_walk_step, 3841*7c478bd9Sstevel@tonic-gate mi_payload_walk_fini, &mi_icmp_arg }, 3842*7c478bd9Sstevel@tonic-gate { "ill", "walk ill_t structures using MI", 3843*7c478bd9Sstevel@tonic-gate mi_payload_walk_init, mi_payload_walk_step, 3844*7c478bd9Sstevel@tonic-gate mi_payload_walk_fini, &mi_ill_arg }, 3845*7c478bd9Sstevel@tonic-gate { "mi", "given a MI_O, walk the MI", 3846*7c478bd9Sstevel@tonic-gate mi_walk_init, mi_walk_step, mi_walk_fini, NULL }, 3847*7c478bd9Sstevel@tonic-gate { "sonode", "given a sonode, walk its children", 3848*7c478bd9Sstevel@tonic-gate sonode_walk_init, sonode_walk_step, sonode_walk_fini, NULL }, 3849*7c478bd9Sstevel@tonic-gate { "udp", "walk UDP connections using MI", 3850*7c478bd9Sstevel@tonic-gate mi_payload_walk_init, mi_payload_walk_step, 3851*7c478bd9Sstevel@tonic-gate mi_payload_walk_fini, &mi_udp_arg }, 3852*7c478bd9Sstevel@tonic-gate 3853*7c478bd9Sstevel@tonic-gate /* from nvpair.c */ 3854*7c478bd9Sstevel@tonic-gate { NVPAIR_WALKER_NAME, NVPAIR_WALKER_DESCR, 3855*7c478bd9Sstevel@tonic-gate nvpair_walk_init, nvpair_walk_step, NULL }, 3856*7c478bd9Sstevel@tonic-gate 3857*7c478bd9Sstevel@tonic-gate /* from rctl.c */ 3858*7c478bd9Sstevel@tonic-gate { "rctl_dict_list", "walk all rctl_dict_entry_t's from rctl_lists", 3859*7c478bd9Sstevel@tonic-gate rctl_dict_walk_init, rctl_dict_walk_step, NULL }, 3860*7c478bd9Sstevel@tonic-gate { "rctl_set", "given a rctl_set, walk all rctls", rctl_set_walk_init, 3861*7c478bd9Sstevel@tonic-gate rctl_set_walk_step, NULL }, 3862*7c478bd9Sstevel@tonic-gate { "rctl_val", "given a rctl_t, walk all rctl_val entries associated", 3863*7c478bd9Sstevel@tonic-gate rctl_val_walk_init, rctl_val_walk_step }, 3864*7c478bd9Sstevel@tonic-gate 3865*7c478bd9Sstevel@tonic-gate /* from sobj.c */ 3866*7c478bd9Sstevel@tonic-gate { "blocked", "walk threads blocked on a given sobj", 3867*7c478bd9Sstevel@tonic-gate blocked_walk_init, blocked_walk_step, NULL }, 3868*7c478bd9Sstevel@tonic-gate { "wchan", "given a wchan, list of blocked threads", 3869*7c478bd9Sstevel@tonic-gate wchan_walk_init, wchan_walk_step, wchan_walk_fini }, 3870*7c478bd9Sstevel@tonic-gate 3871*7c478bd9Sstevel@tonic-gate /* from stream.c */ 3872*7c478bd9Sstevel@tonic-gate { "b_cont", "walk mblk_t list using b_cont", 3873*7c478bd9Sstevel@tonic-gate mblk_walk_init, b_cont_step, mblk_walk_fini }, 3874*7c478bd9Sstevel@tonic-gate { "b_next", "walk mblk_t list using b_next", 3875*7c478bd9Sstevel@tonic-gate mblk_walk_init, b_next_step, mblk_walk_fini }, 3876*7c478bd9Sstevel@tonic-gate { "qlink", "walk queue_t list using q_link", 3877*7c478bd9Sstevel@tonic-gate queue_walk_init, queue_link_step, queue_walk_fini }, 3878*7c478bd9Sstevel@tonic-gate { "qnext", "walk queue_t list using q_next", 3879*7c478bd9Sstevel@tonic-gate queue_walk_init, queue_next_step, queue_walk_fini }, 3880*7c478bd9Sstevel@tonic-gate { "strftblk", "given a dblk_t, walk STREAMS flow trace event list", 3881*7c478bd9Sstevel@tonic-gate strftblk_walk_init, strftblk_step, strftblk_walk_fini }, 3882*7c478bd9Sstevel@tonic-gate { "readq", "walk read queue side of stdata", 3883*7c478bd9Sstevel@tonic-gate str_walk_init, strr_walk_step, str_walk_fini }, 3884*7c478bd9Sstevel@tonic-gate { "writeq", "walk write queue side of stdata", 3885*7c478bd9Sstevel@tonic-gate str_walk_init, strw_walk_step, str_walk_fini }, 3886*7c478bd9Sstevel@tonic-gate 3887*7c478bd9Sstevel@tonic-gate /* from thread.c */ 3888*7c478bd9Sstevel@tonic-gate { "deathrow", "walk threads on both lwp_ and thread_deathrow", 3889*7c478bd9Sstevel@tonic-gate deathrow_walk_init, deathrow_walk_step, NULL }, 3890*7c478bd9Sstevel@tonic-gate { "cpu_dispq", "given a cpu_t, walk threads in dispatcher queues", 3891*7c478bd9Sstevel@tonic-gate cpu_dispq_walk_init, dispq_walk_step, dispq_walk_fini }, 3892*7c478bd9Sstevel@tonic-gate { "cpupart_dispq", 3893*7c478bd9Sstevel@tonic-gate "given a cpupart_t, walk threads in dispatcher queues", 3894*7c478bd9Sstevel@tonic-gate cpupart_dispq_walk_init, dispq_walk_step, dispq_walk_fini }, 3895*7c478bd9Sstevel@tonic-gate { "lwp_deathrow", "walk lwp_deathrow", 3896*7c478bd9Sstevel@tonic-gate lwp_deathrow_walk_init, deathrow_walk_step, NULL }, 3897*7c478bd9Sstevel@tonic-gate { "thread", "global or per-process kthread_t structures", 3898*7c478bd9Sstevel@tonic-gate thread_walk_init, thread_walk_step, thread_walk_fini }, 3899*7c478bd9Sstevel@tonic-gate { "thread_deathrow", "walk threads on thread_deathrow", 3900*7c478bd9Sstevel@tonic-gate thread_deathrow_walk_init, deathrow_walk_step, NULL }, 3901*7c478bd9Sstevel@tonic-gate 3902*7c478bd9Sstevel@tonic-gate /* from tsd.c */ 3903*7c478bd9Sstevel@tonic-gate { "tsd", "walk list of thread-specific data", 3904*7c478bd9Sstevel@tonic-gate tsd_walk_init, tsd_walk_step, tsd_walk_fini }, 3905*7c478bd9Sstevel@tonic-gate 3906*7c478bd9Sstevel@tonic-gate /* 3907*7c478bd9Sstevel@tonic-gate * typegraph does not work under kmdb, as it requires too much memory 3908*7c478bd9Sstevel@tonic-gate * for its internal data structures. 3909*7c478bd9Sstevel@tonic-gate */ 3910*7c478bd9Sstevel@tonic-gate #ifndef _KMDB 3911*7c478bd9Sstevel@tonic-gate /* from typegraph.c */ 3912*7c478bd9Sstevel@tonic-gate { "typeconflict", "walk buffers with conflicting type inferences", 3913*7c478bd9Sstevel@tonic-gate typegraph_walk_init, typeconflict_walk_step }, 3914*7c478bd9Sstevel@tonic-gate { "typeunknown", "walk buffers with unknown types", 3915*7c478bd9Sstevel@tonic-gate typegraph_walk_init, typeunknown_walk_step }, 3916*7c478bd9Sstevel@tonic-gate #endif 3917*7c478bd9Sstevel@tonic-gate 3918*7c478bd9Sstevel@tonic-gate /* from vfs.c */ 3919*7c478bd9Sstevel@tonic-gate { "vfs", "walk file system list", 3920*7c478bd9Sstevel@tonic-gate vfs_walk_init, vfs_walk_step }, 3921*7c478bd9Sstevel@tonic-gate { NULL } 3922*7c478bd9Sstevel@tonic-gate }; 3923*7c478bd9Sstevel@tonic-gate 3924*7c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers }; 3925*7c478bd9Sstevel@tonic-gate 3926*7c478bd9Sstevel@tonic-gate const mdb_modinfo_t * 3927*7c478bd9Sstevel@tonic-gate _mdb_init(void) 3928*7c478bd9Sstevel@tonic-gate { 3929*7c478bd9Sstevel@tonic-gate if (mdb_readvar(&devinfo_root, "top_devinfo") == -1) { 3930*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'top_devinfo'"); 3931*7c478bd9Sstevel@tonic-gate return (NULL); 3932*7c478bd9Sstevel@tonic-gate } 3933*7c478bd9Sstevel@tonic-gate 3934*7c478bd9Sstevel@tonic-gate if (findstack_init() != DCMD_OK) 3935*7c478bd9Sstevel@tonic-gate return (NULL); 3936*7c478bd9Sstevel@tonic-gate 3937*7c478bd9Sstevel@tonic-gate kmem_init(); 3938*7c478bd9Sstevel@tonic-gate 3939*7c478bd9Sstevel@tonic-gate return (&modinfo); 3940*7c478bd9Sstevel@tonic-gate } 3941*7c478bd9Sstevel@tonic-gate 3942*7c478bd9Sstevel@tonic-gate void 3943*7c478bd9Sstevel@tonic-gate _mdb_fini(void) 3944*7c478bd9Sstevel@tonic-gate { 3945*7c478bd9Sstevel@tonic-gate /* 3946*7c478bd9Sstevel@tonic-gate * Force ::findleaks to let go any cached memory 3947*7c478bd9Sstevel@tonic-gate */ 3948*7c478bd9Sstevel@tonic-gate leaky_cleanup(1); 3949*7c478bd9Sstevel@tonic-gate } 3950