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