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