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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <mdb/mdb_param.h> 307c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 317c478bd9Sstevel@tonic-gate #include <mdb/mdb_ks.h> 327c478bd9Sstevel@tonic-gate #include <mdb/mdb_ctf.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <sys/thread.h> 367c478bd9Sstevel@tonic-gate #include <sys/session.h> 377c478bd9Sstevel@tonic-gate #include <sys/user.h> 387c478bd9Sstevel@tonic-gate #include <sys/proc.h> 397c478bd9Sstevel@tonic-gate #include <sys/var.h> 407c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 417c478bd9Sstevel@tonic-gate #include <sys/callo.h> 427c478bd9Sstevel@tonic-gate #include <sys/priocntl.h> 437c478bd9Sstevel@tonic-gate #include <sys/class.h> 447c478bd9Sstevel@tonic-gate #include <sys/regset.h> 457c478bd9Sstevel@tonic-gate #include <sys/stack.h> 467c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 477c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 487c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 497c478bd9Sstevel@tonic-gate #include <sys/flock_impl.h> 507c478bd9Sstevel@tonic-gate #include <sys/kmem_impl.h> 517c478bd9Sstevel@tonic-gate #include <sys/vmem_impl.h> 527c478bd9Sstevel@tonic-gate #include <sys/kstat.h> 537c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h> 547c478bd9Sstevel@tonic-gate #include <vm/anon.h> 557c478bd9Sstevel@tonic-gate #include <vm/as.h> 567c478bd9Sstevel@tonic-gate #include <vm/seg_map.h> 577c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 587c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 597c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 607c478bd9Sstevel@tonic-gate #include <sys/sysconf.h> 617c478bd9Sstevel@tonic-gate #include <sys/task.h> 627c478bd9Sstevel@tonic-gate #include <sys/project.h> 637c478bd9Sstevel@tonic-gate #include <sys/taskq.h> 647c478bd9Sstevel@tonic-gate #include <sys/taskq_impl.h> 657c478bd9Sstevel@tonic-gate #include <sys/errorq_impl.h> 667c478bd9Sstevel@tonic-gate #include <sys/cred_impl.h> 677c478bd9Sstevel@tonic-gate #include <sys/zone.h> 687c478bd9Sstevel@tonic-gate #include <sys/panic.h> 697c478bd9Sstevel@tonic-gate #include <regex.h> 707c478bd9Sstevel@tonic-gate #include <sys/port_impl.h> 717c478bd9Sstevel@tonic-gate 72fa9e4066Sahrens #include "avl.h" 737c478bd9Sstevel@tonic-gate #include "contract.h" 747c478bd9Sstevel@tonic-gate #include "cpupart_mdb.h" 757c478bd9Sstevel@tonic-gate #include "devinfo.h" 767c478bd9Sstevel@tonic-gate #include "leaky.h" 777c478bd9Sstevel@tonic-gate #include "lgrp.h" 787c478bd9Sstevel@tonic-gate #include "list.h" 797c478bd9Sstevel@tonic-gate #include "log.h" 807c478bd9Sstevel@tonic-gate #include "kgrep.h" 817c478bd9Sstevel@tonic-gate #include "kmem.h" 827c478bd9Sstevel@tonic-gate #include "bio.h" 837c478bd9Sstevel@tonic-gate #include "streams.h" 847c478bd9Sstevel@tonic-gate #include "cyclic.h" 857c478bd9Sstevel@tonic-gate #include "findstack.h" 867c478bd9Sstevel@tonic-gate #include "ndievents.h" 877c478bd9Sstevel@tonic-gate #include "mmd.h" 887c478bd9Sstevel@tonic-gate #include "net.h" 897c478bd9Sstevel@tonic-gate #include "nvpair.h" 907c478bd9Sstevel@tonic-gate #include "ctxop.h" 917c478bd9Sstevel@tonic-gate #include "tsd.h" 927c478bd9Sstevel@tonic-gate #include "thread.h" 937c478bd9Sstevel@tonic-gate #include "memory.h" 947c478bd9Sstevel@tonic-gate #include "sobj.h" 957c478bd9Sstevel@tonic-gate #include "sysevent.h" 967c478bd9Sstevel@tonic-gate #include "rctl.h" 977c478bd9Sstevel@tonic-gate #include "typegraph.h" 987c478bd9Sstevel@tonic-gate #include "ldi.h" 997c478bd9Sstevel@tonic-gate #include "vfs.h" 1007c478bd9Sstevel@tonic-gate #include "zone.h" 1017c478bd9Sstevel@tonic-gate #include "modhash.h" 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * Surely this is defined somewhere... 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate #define NINTR 16 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #ifndef STACK_BIAS 1097c478bd9Sstevel@tonic-gate #define STACK_BIAS 0 1107c478bd9Sstevel@tonic-gate #endif 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate static char 1137c478bd9Sstevel@tonic-gate pstat2ch(uchar_t state) 1147c478bd9Sstevel@tonic-gate { 1157c478bd9Sstevel@tonic-gate switch (state) { 1167c478bd9Sstevel@tonic-gate case SSLEEP: return ('S'); 1177c478bd9Sstevel@tonic-gate case SRUN: return ('R'); 1187c478bd9Sstevel@tonic-gate case SZOMB: return ('Z'); 1197c478bd9Sstevel@tonic-gate case SIDL: return ('I'); 1207c478bd9Sstevel@tonic-gate case SONPROC: return ('O'); 1217c478bd9Sstevel@tonic-gate case SSTOP: return ('T'); 1227c478bd9Sstevel@tonic-gate default: return ('?'); 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate #define PS_PRTTHREADS 0x1 1277c478bd9Sstevel@tonic-gate #define PS_PRTLWPS 0x2 1287c478bd9Sstevel@tonic-gate #define PS_PSARGS 0x4 1297c478bd9Sstevel@tonic-gate #define PS_TASKS 0x8 1307c478bd9Sstevel@tonic-gate #define PS_PROJECTS 0x10 1317c478bd9Sstevel@tonic-gate #define PS_ZONES 0x20 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate static int 1347c478bd9Sstevel@tonic-gate ps_threadprint(uintptr_t addr, const void *data, void *private) 1357c478bd9Sstevel@tonic-gate { 1367c478bd9Sstevel@tonic-gate const kthread_t *t = (const kthread_t *)data; 1377c478bd9Sstevel@tonic-gate uint_t prt_flags = *((uint_t *)private); 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate static const mdb_bitmask_t t_state_bits[] = { 1407c478bd9Sstevel@tonic-gate { "TS_FREE", UINT_MAX, TS_FREE }, 1417c478bd9Sstevel@tonic-gate { "TS_SLEEP", TS_SLEEP, TS_SLEEP }, 1427c478bd9Sstevel@tonic-gate { "TS_RUN", TS_RUN, TS_RUN }, 1437c478bd9Sstevel@tonic-gate { "TS_ONPROC", TS_ONPROC, TS_ONPROC }, 1447c478bd9Sstevel@tonic-gate { "TS_ZOMB", TS_ZOMB, TS_ZOMB }, 1457c478bd9Sstevel@tonic-gate { "TS_STOPPED", TS_STOPPED, TS_STOPPED }, 1467c478bd9Sstevel@tonic-gate { NULL, 0, 0 } 1477c478bd9Sstevel@tonic-gate }; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate if (prt_flags & PS_PRTTHREADS) 1507c478bd9Sstevel@tonic-gate mdb_printf("\tT %?a <%b>\n", addr, t->t_state, t_state_bits); 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate if (prt_flags & PS_PRTLWPS) 1537c478bd9Sstevel@tonic-gate mdb_printf("\tL %?a ID: %u\n", t->t_lwp, t->t_tid); 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate int 1597c478bd9Sstevel@tonic-gate ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1607c478bd9Sstevel@tonic-gate { 1617c478bd9Sstevel@tonic-gate uint_t prt_flags = 0; 1627c478bd9Sstevel@tonic-gate proc_t pr; 1637c478bd9Sstevel@tonic-gate struct pid pid, pgid, sid; 1647c478bd9Sstevel@tonic-gate sess_t session; 1657c478bd9Sstevel@tonic-gate cred_t cred; 1667c478bd9Sstevel@tonic-gate task_t tk; 1677c478bd9Sstevel@tonic-gate kproject_t pj; 1687c478bd9Sstevel@tonic-gate zone_t zn; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 1717c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) { 1727c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'proc'"); 1737c478bd9Sstevel@tonic-gate return (DCMD_ERR); 1747c478bd9Sstevel@tonic-gate } 1757c478bd9Sstevel@tonic-gate return (DCMD_OK); 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 1797c478bd9Sstevel@tonic-gate 'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags, 1807c478bd9Sstevel@tonic-gate 'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags, 1817c478bd9Sstevel@tonic-gate 'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags, 1827c478bd9Sstevel@tonic-gate 'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags, 1837c478bd9Sstevel@tonic-gate 'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags, 1847c478bd9Sstevel@tonic-gate 't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc) 1857c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 1887c478bd9Sstevel@tonic-gate mdb_printf("%<u>%1s %6s %6s %6s %6s ", 1897c478bd9Sstevel@tonic-gate "S", "PID", "PPID", "PGID", "SID"); 1907c478bd9Sstevel@tonic-gate if (prt_flags & PS_TASKS) 1917c478bd9Sstevel@tonic-gate mdb_printf("%5s ", "TASK"); 1927c478bd9Sstevel@tonic-gate if (prt_flags & PS_PROJECTS) 1937c478bd9Sstevel@tonic-gate mdb_printf("%5s ", "PROJ"); 1947c478bd9Sstevel@tonic-gate if (prt_flags & PS_ZONES) 1957c478bd9Sstevel@tonic-gate mdb_printf("%5s ", "ZONE"); 1967c478bd9Sstevel@tonic-gate mdb_printf("%6s %10s %?s %s%</u>\n", 1977c478bd9Sstevel@tonic-gate "UID", "FLAGS", "ADDR", "NAME"); 1987c478bd9Sstevel@tonic-gate } 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate mdb_vread(&pr, sizeof (pr), addr); 2017c478bd9Sstevel@tonic-gate mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp); 2027c478bd9Sstevel@tonic-gate mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp); 2037c478bd9Sstevel@tonic-gate mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred); 2047c478bd9Sstevel@tonic-gate mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp); 2057c478bd9Sstevel@tonic-gate mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp); 2067c478bd9Sstevel@tonic-gate if (prt_flags & (PS_TASKS | PS_PROJECTS)) 2077c478bd9Sstevel@tonic-gate mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task); 2087c478bd9Sstevel@tonic-gate if (prt_flags & PS_PROJECTS) 2097c478bd9Sstevel@tonic-gate mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj); 2107c478bd9Sstevel@tonic-gate if (prt_flags & PS_ZONES) 2117c478bd9Sstevel@tonic-gate mdb_vread(&zn, sizeof (zone_t), (uintptr_t)pr.p_zone); 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate mdb_printf("%c %6d %6d %6d %6d ", 2147c478bd9Sstevel@tonic-gate pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id, 2157c478bd9Sstevel@tonic-gate sid.pid_id); 2167c478bd9Sstevel@tonic-gate if (prt_flags & PS_TASKS) 2177c478bd9Sstevel@tonic-gate mdb_printf("%5d ", tk.tk_tkid); 2187c478bd9Sstevel@tonic-gate if (prt_flags & PS_PROJECTS) 2197c478bd9Sstevel@tonic-gate mdb_printf("%5d ", pj.kpj_id); 2207c478bd9Sstevel@tonic-gate if (prt_flags & PS_ZONES) 2217c478bd9Sstevel@tonic-gate mdb_printf("%5d ", zn.zone_id); 2227c478bd9Sstevel@tonic-gate mdb_printf("%6d 0x%08x %0?p %s\n", 2237c478bd9Sstevel@tonic-gate cred.cr_uid, pr.p_flag, addr, 2247c478bd9Sstevel@tonic-gate (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm); 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate if (prt_flags & ~PS_PSARGS) 2277c478bd9Sstevel@tonic-gate (void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr); 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate return (DCMD_OK); 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate #define PG_NEWEST 0x0001 2337c478bd9Sstevel@tonic-gate #define PG_OLDEST 0x0002 2347c478bd9Sstevel@tonic-gate #define PG_PIPE_OUT 0x0004 235*adb664e2Svb #define PG_EXACT_MATCH 0x0008 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate typedef struct pgrep_data { 2387c478bd9Sstevel@tonic-gate uint_t pg_flags; 2397c478bd9Sstevel@tonic-gate uint_t pg_psflags; 2407c478bd9Sstevel@tonic-gate uintptr_t pg_xaddr; 2417c478bd9Sstevel@tonic-gate hrtime_t pg_xstart; 2427c478bd9Sstevel@tonic-gate const char *pg_pat; 2437c478bd9Sstevel@tonic-gate #ifndef _KMDB 2447c478bd9Sstevel@tonic-gate regex_t pg_reg; 2457c478bd9Sstevel@tonic-gate #endif 2467c478bd9Sstevel@tonic-gate } pgrep_data_t; 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2497c478bd9Sstevel@tonic-gate static int 2507c478bd9Sstevel@tonic-gate pgrep_cb(uintptr_t addr, const void *pdata, void *data) 2517c478bd9Sstevel@tonic-gate { 2527c478bd9Sstevel@tonic-gate const proc_t *prp = pdata; 2537c478bd9Sstevel@tonic-gate pgrep_data_t *pgp = data; 2547c478bd9Sstevel@tonic-gate #ifndef _KMDB 2557c478bd9Sstevel@tonic-gate regmatch_t pmatch; 2567c478bd9Sstevel@tonic-gate #endif 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate /* 2597c478bd9Sstevel@tonic-gate * kmdb doesn't have access to the reg* functions, so we fall back 260*adb664e2Svb * to strstr/strcmp. 2617c478bd9Sstevel@tonic-gate */ 2627c478bd9Sstevel@tonic-gate #ifdef _KMDB 263*adb664e2Svb if ((pgp->pg_flags & PG_EXACT_MATCH) ? 264*adb664e2Svb (strcmp(prp->p_user.u_comm, pgp->pg_pat) != 0) : 265*adb664e2Svb (strstr(prp->p_user.u_comm, pgp->pg_pat) == NULL)) 2667c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2677c478bd9Sstevel@tonic-gate #else 2687c478bd9Sstevel@tonic-gate if (regexec(&pgp->pg_reg, prp->p_user.u_comm, 1, &pmatch, 0) != 0) 2697c478bd9Sstevel@tonic-gate return (WALK_NEXT); 270*adb664e2Svb 271*adb664e2Svb if ((pgp->pg_flags & PG_EXACT_MATCH) && 272*adb664e2Svb (pmatch.rm_so != 0 || prp->p_user.u_comm[pmatch.rm_eo] != '\0')) 273*adb664e2Svb return (WALK_NEXT); 2747c478bd9Sstevel@tonic-gate #endif 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate if (pgp->pg_flags & (PG_NEWEST | PG_OLDEST)) { 2777c478bd9Sstevel@tonic-gate hrtime_t start; 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate start = (hrtime_t)prp->p_user.u_start.tv_sec * NANOSEC + 2807c478bd9Sstevel@tonic-gate prp->p_user.u_start.tv_nsec; 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate if (pgp->pg_flags & PG_NEWEST) { 2837c478bd9Sstevel@tonic-gate if (pgp->pg_xaddr == NULL || start > pgp->pg_xstart) { 2847c478bd9Sstevel@tonic-gate pgp->pg_xaddr = addr; 2857c478bd9Sstevel@tonic-gate pgp->pg_xstart = start; 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate } else { 2887c478bd9Sstevel@tonic-gate if (pgp->pg_xaddr == NULL || start < pgp->pg_xstart) { 2897c478bd9Sstevel@tonic-gate pgp->pg_xaddr = addr; 2907c478bd9Sstevel@tonic-gate pgp->pg_xstart = start; 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate } else if (pgp->pg_flags & PG_PIPE_OUT) { 2957c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr); 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate } else { 2987c478bd9Sstevel@tonic-gate if (mdb_call_dcmd("ps", addr, pgp->pg_psflags, 0, NULL) != 0) { 2997c478bd9Sstevel@tonic-gate mdb_warn("can't invoke 'ps'"); 3007c478bd9Sstevel@tonic-gate return (WALK_DONE); 3017c478bd9Sstevel@tonic-gate } 3027c478bd9Sstevel@tonic-gate pgp->pg_psflags &= ~DCMD_LOOPFIRST; 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate return (WALK_NEXT); 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3097c478bd9Sstevel@tonic-gate int 3107c478bd9Sstevel@tonic-gate pgrep(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3117c478bd9Sstevel@tonic-gate { 3127c478bd9Sstevel@tonic-gate pgrep_data_t pg; 3137c478bd9Sstevel@tonic-gate int i; 3147c478bd9Sstevel@tonic-gate #ifndef _KMDB 3157c478bd9Sstevel@tonic-gate int err; 3167c478bd9Sstevel@tonic-gate #endif 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) 3197c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate pg.pg_flags = 0; 3227c478bd9Sstevel@tonic-gate pg.pg_xaddr = 0; 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate i = mdb_getopts(argc, argv, 3257c478bd9Sstevel@tonic-gate 'n', MDB_OPT_SETBITS, PG_NEWEST, &pg.pg_flags, 3267c478bd9Sstevel@tonic-gate 'o', MDB_OPT_SETBITS, PG_OLDEST, &pg.pg_flags, 327*adb664e2Svb 'x', MDB_OPT_SETBITS, PG_EXACT_MATCH, &pg.pg_flags, 3287c478bd9Sstevel@tonic-gate NULL); 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate argc -= i; 3317c478bd9Sstevel@tonic-gate argv += i; 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate if (argc != 1) 3347c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate /* 3377c478bd9Sstevel@tonic-gate * -n and -o are mutually exclusive. 3387c478bd9Sstevel@tonic-gate */ 3397c478bd9Sstevel@tonic-gate if ((pg.pg_flags & PG_NEWEST) && (pg.pg_flags & PG_OLDEST)) 3407c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate if (argv->a_type != MDB_TYPE_STRING) 3437c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate if (flags & DCMD_PIPE_OUT) 3467c478bd9Sstevel@tonic-gate pg.pg_flags |= PG_PIPE_OUT; 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate pg.pg_pat = argv->a_un.a_str; 3497c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 3507c478bd9Sstevel@tonic-gate pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP | DCMD_LOOPFIRST; 3517c478bd9Sstevel@tonic-gate else 3527c478bd9Sstevel@tonic-gate pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP; 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate #ifndef _KMDB 3557c478bd9Sstevel@tonic-gate if ((err = regcomp(&pg.pg_reg, pg.pg_pat, REG_EXTENDED)) != 0) { 3567c478bd9Sstevel@tonic-gate size_t nbytes; 3577c478bd9Sstevel@tonic-gate char *buf; 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate nbytes = regerror(err, &pg.pg_reg, NULL, 0); 3607c478bd9Sstevel@tonic-gate buf = mdb_alloc(nbytes + 1, UM_SLEEP | UM_GC); 3617c478bd9Sstevel@tonic-gate (void) regerror(err, &pg.pg_reg, buf, nbytes); 3627c478bd9Sstevel@tonic-gate mdb_warn("%s\n", buf); 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3657c478bd9Sstevel@tonic-gate } 3667c478bd9Sstevel@tonic-gate #endif 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate if (mdb_walk("proc", pgrep_cb, &pg) != 0) { 3697c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'proc'"); 3707c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3717c478bd9Sstevel@tonic-gate } 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate if (pg.pg_xaddr != 0 && (pg.pg_flags & (PG_NEWEST | PG_OLDEST))) { 3747c478bd9Sstevel@tonic-gate if (pg.pg_flags & PG_PIPE_OUT) { 3757c478bd9Sstevel@tonic-gate mdb_printf("%p\n", pg.pg_xaddr); 3767c478bd9Sstevel@tonic-gate } else { 3777c478bd9Sstevel@tonic-gate if (mdb_call_dcmd("ps", pg.pg_xaddr, pg.pg_psflags, 3787c478bd9Sstevel@tonic-gate 0, NULL) != 0) { 3797c478bd9Sstevel@tonic-gate mdb_warn("can't invoke 'ps'"); 3807c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3817c478bd9Sstevel@tonic-gate } 3827c478bd9Sstevel@tonic-gate } 3837c478bd9Sstevel@tonic-gate } 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate return (DCMD_OK); 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate int 3897c478bd9Sstevel@tonic-gate task(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3907c478bd9Sstevel@tonic-gate { 3917c478bd9Sstevel@tonic-gate task_t tk; 3927c478bd9Sstevel@tonic-gate kproject_t pj; 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 3957c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("task_cache", "task", argc, argv) == -1) { 3967c478bd9Sstevel@tonic-gate mdb_warn("can't walk task_cache"); 3977c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate return (DCMD_OK); 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 4027c478bd9Sstevel@tonic-gate mdb_printf("%<u>%?s %6s %6s %6s %6s %10s%</u>\n", 4037c478bd9Sstevel@tonic-gate "ADDR", "TASKID", "PROJID", "ZONEID", "REFCNT", "FLAGS"); 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate if (mdb_vread(&tk, sizeof (task_t), addr) == -1) { 4067c478bd9Sstevel@tonic-gate mdb_warn("can't read task_t structure at %p", addr); 4077c478bd9Sstevel@tonic-gate return (DCMD_ERR); 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate if (mdb_vread(&pj, sizeof (kproject_t), (uintptr_t)tk.tk_proj) == -1) { 4107c478bd9Sstevel@tonic-gate mdb_warn("can't read project_t structure at %p", addr); 4117c478bd9Sstevel@tonic-gate return (DCMD_ERR); 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate mdb_printf("%0?p %6d %6d %6d %6u 0x%08x\n", 4147c478bd9Sstevel@tonic-gate addr, tk.tk_tkid, pj.kpj_id, pj.kpj_zoneid, tk.tk_hold_count, 4157c478bd9Sstevel@tonic-gate tk.tk_flags); 4167c478bd9Sstevel@tonic-gate return (DCMD_OK); 4177c478bd9Sstevel@tonic-gate } 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate int 4207c478bd9Sstevel@tonic-gate project(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 4217c478bd9Sstevel@tonic-gate { 4227c478bd9Sstevel@tonic-gate kproject_t pj; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 4257c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("projects", "project", argc, argv) == -1) { 4267c478bd9Sstevel@tonic-gate mdb_warn("can't walk projects"); 4277c478bd9Sstevel@tonic-gate return (DCMD_ERR); 4287c478bd9Sstevel@tonic-gate } 4297c478bd9Sstevel@tonic-gate return (DCMD_OK); 4307c478bd9Sstevel@tonic-gate } 4317c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 4327c478bd9Sstevel@tonic-gate mdb_printf("%<u>%?s %6s %6s %6s%</u>\n", 4337c478bd9Sstevel@tonic-gate "ADDR", "PROJID", "ZONEID", "REFCNT"); 4347c478bd9Sstevel@tonic-gate } 4357c478bd9Sstevel@tonic-gate if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) { 4367c478bd9Sstevel@tonic-gate mdb_warn("can't read kproject_t structure at %p", addr); 4377c478bd9Sstevel@tonic-gate return (DCMD_ERR); 4387c478bd9Sstevel@tonic-gate } 4397c478bd9Sstevel@tonic-gate mdb_printf("%0?p %6d %6d %6u\n", addr, pj.kpj_id, pj.kpj_zoneid, 4407c478bd9Sstevel@tonic-gate pj.kpj_count); 4417c478bd9Sstevel@tonic-gate return (DCMD_OK); 4427c478bd9Sstevel@tonic-gate } 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4457c478bd9Sstevel@tonic-gate int 4467c478bd9Sstevel@tonic-gate callout(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 4477c478bd9Sstevel@tonic-gate { 4487c478bd9Sstevel@tonic-gate callout_table_t *co_ktable[CALLOUT_TABLES]; 4497c478bd9Sstevel@tonic-gate int co_kfanout; 4507c478bd9Sstevel@tonic-gate callout_table_t co_table; 4517c478bd9Sstevel@tonic-gate callout_t co_callout; 4527c478bd9Sstevel@tonic-gate callout_t *co_ptr; 4537c478bd9Sstevel@tonic-gate int co_id; 4547c478bd9Sstevel@tonic-gate clock_t lbolt; 4557c478bd9Sstevel@tonic-gate int i, j, k; 4567c478bd9Sstevel@tonic-gate const char *lbolt_sym; 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) || argc != 0) 4597c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate if (mdb_prop_postmortem) 4627c478bd9Sstevel@tonic-gate lbolt_sym = "panic_lbolt"; 4637c478bd9Sstevel@tonic-gate else 4647c478bd9Sstevel@tonic-gate lbolt_sym = "lbolt"; 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate if (mdb_readvar(&lbolt, lbolt_sym) == -1) { 4677c478bd9Sstevel@tonic-gate mdb_warn("failed to read '%s'", lbolt_sym); 4687c478bd9Sstevel@tonic-gate return (DCMD_ERR); 4697c478bd9Sstevel@tonic-gate } 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate if (mdb_readvar(&co_kfanout, "callout_fanout") == -1) { 4727c478bd9Sstevel@tonic-gate mdb_warn("failed to read callout_fanout"); 4737c478bd9Sstevel@tonic-gate return (DCMD_ERR); 4747c478bd9Sstevel@tonic-gate } 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate if (mdb_readvar(&co_ktable, "callout_table") == -1) { 4777c478bd9Sstevel@tonic-gate mdb_warn("failed to read callout_table"); 4787c478bd9Sstevel@tonic-gate return (DCMD_ERR); 4797c478bd9Sstevel@tonic-gate } 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-24s %-?s %-?s %-?s%</u>\n", 4827c478bd9Sstevel@tonic-gate "FUNCTION", "ARGUMENT", "ID", "TIME"); 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate for (i = 0; i < CALLOUT_NTYPES; i++) { 4857c478bd9Sstevel@tonic-gate for (j = 0; j < co_kfanout; j++) { 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate co_id = CALLOUT_TABLE(i, j); 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate if (mdb_vread(&co_table, sizeof (co_table), 4907c478bd9Sstevel@tonic-gate (uintptr_t)co_ktable[co_id]) == -1) { 4917c478bd9Sstevel@tonic-gate mdb_warn("failed to read table at %p", 4927c478bd9Sstevel@tonic-gate (uintptr_t)co_ktable[co_id]); 4937c478bd9Sstevel@tonic-gate continue; 4947c478bd9Sstevel@tonic-gate } 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate for (k = 0; k < CALLOUT_BUCKETS; k++) { 4977c478bd9Sstevel@tonic-gate co_ptr = co_table.ct_idhash[k]; 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate while (co_ptr != NULL) { 5007c478bd9Sstevel@tonic-gate mdb_vread(&co_callout, 5017c478bd9Sstevel@tonic-gate sizeof (co_callout), 5027c478bd9Sstevel@tonic-gate (uintptr_t)co_ptr); 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate mdb_printf("%-24a %0?p %0?lx %?lx " 5057c478bd9Sstevel@tonic-gate "(T%+ld)\n", co_callout.c_func, 5067c478bd9Sstevel@tonic-gate co_callout.c_arg, co_callout.c_xid, 5077c478bd9Sstevel@tonic-gate co_callout.c_runtime, 5087c478bd9Sstevel@tonic-gate co_callout.c_runtime - lbolt); 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate co_ptr = co_callout.c_idnext; 5117c478bd9Sstevel@tonic-gate } 5127c478bd9Sstevel@tonic-gate } 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate } 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate return (DCMD_OK); 5177c478bd9Sstevel@tonic-gate } 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5207c478bd9Sstevel@tonic-gate int 5217c478bd9Sstevel@tonic-gate class(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 5227c478bd9Sstevel@tonic-gate { 5237c478bd9Sstevel@tonic-gate long num_classes, i; 5247c478bd9Sstevel@tonic-gate sclass_t *class_tbl; 5257c478bd9Sstevel@tonic-gate GElf_Sym g_sclass; 5267c478bd9Sstevel@tonic-gate char class_name[PC_CLNMSZ]; 5277c478bd9Sstevel@tonic-gate size_t tbl_size; 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("sclass", &g_sclass) == -1) { 5307c478bd9Sstevel@tonic-gate mdb_warn("failed to find symbol sclass\n"); 5317c478bd9Sstevel@tonic-gate return (DCMD_ERR); 5327c478bd9Sstevel@tonic-gate } 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate tbl_size = (size_t)g_sclass.st_size; 5357c478bd9Sstevel@tonic-gate num_classes = tbl_size / (sizeof (sclass_t)); 5367c478bd9Sstevel@tonic-gate class_tbl = mdb_alloc(tbl_size, UM_SLEEP | UM_GC); 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate if (mdb_readsym(class_tbl, tbl_size, "sclass") == -1) { 5397c478bd9Sstevel@tonic-gate mdb_warn("failed to read sclass"); 5407c478bd9Sstevel@tonic-gate return (DCMD_ERR); 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate mdb_printf("%<u>%4s %-10s %-24s %-24s%</u>\n", "SLOT", "NAME", 5447c478bd9Sstevel@tonic-gate "INIT FCN", "CLASS FCN"); 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate for (i = 0; i < num_classes; i++) { 5477c478bd9Sstevel@tonic-gate if (mdb_vread(class_name, sizeof (class_name), 5487c478bd9Sstevel@tonic-gate (uintptr_t)class_tbl[i].cl_name) == -1) 5497c478bd9Sstevel@tonic-gate (void) strcpy(class_name, "???"); 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate mdb_printf("%4ld %-10s %-24a %-24a\n", i, class_name, 5527c478bd9Sstevel@tonic-gate class_tbl[i].cl_init, class_tbl[i].cl_funcs); 5537c478bd9Sstevel@tonic-gate } 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate return (DCMD_OK); 5567c478bd9Sstevel@tonic-gate } 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gate #define FSNAMELEN 32 /* Max len of FS name we read from vnodeops */ 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate int 5617c478bd9Sstevel@tonic-gate vnode2path(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 5627c478bd9Sstevel@tonic-gate { 5637c478bd9Sstevel@tonic-gate uintptr_t rootdir; 5647c478bd9Sstevel@tonic-gate vnode_t vn; 5657c478bd9Sstevel@tonic-gate char buf[MAXPATHLEN]; 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate uint_t opt_F = FALSE; 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 5707c478bd9Sstevel@tonic-gate 'F', MDB_OPT_SETBITS, TRUE, &opt_F, NULL) != argc) 5717c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 5747c478bd9Sstevel@tonic-gate mdb_warn("expected explicit vnode_t address before ::\n"); 5757c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 5767c478bd9Sstevel@tonic-gate } 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate if (mdb_readvar(&rootdir, "rootdir") == -1) { 5797c478bd9Sstevel@tonic-gate mdb_warn("failed to read rootdir"); 5807c478bd9Sstevel@tonic-gate return (DCMD_ERR); 5817c478bd9Sstevel@tonic-gate } 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate if (mdb_vnode2path(addr, buf, sizeof (buf)) == -1) 5847c478bd9Sstevel@tonic-gate return (DCMD_ERR); 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate if (*buf == '\0') { 5877c478bd9Sstevel@tonic-gate mdb_printf("??\n"); 5887c478bd9Sstevel@tonic-gate return (DCMD_OK); 5897c478bd9Sstevel@tonic-gate } 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate mdb_printf("%s", buf); 5927c478bd9Sstevel@tonic-gate if (opt_F && buf[strlen(buf)-1] != '/' && 5937c478bd9Sstevel@tonic-gate mdb_vread(&vn, sizeof (vn), addr) == sizeof (vn)) 5947c478bd9Sstevel@tonic-gate mdb_printf("%c", mdb_vtype2chr(vn.v_type, 0)); 5957c478bd9Sstevel@tonic-gate mdb_printf("\n"); 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate return (DCMD_OK); 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate int 6017c478bd9Sstevel@tonic-gate ld_walk_init(mdb_walk_state_t *wsp) 6027c478bd9Sstevel@tonic-gate { 6037c478bd9Sstevel@tonic-gate wsp->walk_data = (void *)wsp->walk_addr; 6047c478bd9Sstevel@tonic-gate return (WALK_NEXT); 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate int 6087c478bd9Sstevel@tonic-gate ld_walk_step(mdb_walk_state_t *wsp) 6097c478bd9Sstevel@tonic-gate { 6107c478bd9Sstevel@tonic-gate int status; 6117c478bd9Sstevel@tonic-gate lock_descriptor_t ld; 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate if (mdb_vread(&ld, sizeof (lock_descriptor_t), wsp->walk_addr) == -1) { 6147c478bd9Sstevel@tonic-gate mdb_warn("couldn't read lock_descriptor_t at %p\n", 6157c478bd9Sstevel@tonic-gate wsp->walk_addr); 6167c478bd9Sstevel@tonic-gate return (WALK_ERR); 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, &ld, wsp->walk_cbdata); 6207c478bd9Sstevel@tonic-gate if (status == WALK_ERR) 6217c478bd9Sstevel@tonic-gate return (WALK_ERR); 6227c478bd9Sstevel@tonic-gate 6237c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)ld.l_next; 6247c478bd9Sstevel@tonic-gate if (wsp->walk_addr == (uintptr_t)wsp->walk_data) 6257c478bd9Sstevel@tonic-gate return (WALK_DONE); 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate return (status); 6287c478bd9Sstevel@tonic-gate } 6297c478bd9Sstevel@tonic-gate 6307c478bd9Sstevel@tonic-gate int 6317c478bd9Sstevel@tonic-gate lg_walk_init(mdb_walk_state_t *wsp) 6327c478bd9Sstevel@tonic-gate { 6337c478bd9Sstevel@tonic-gate GElf_Sym sym; 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("lock_graph", &sym) == -1) { 6367c478bd9Sstevel@tonic-gate mdb_warn("failed to find symbol 'lock_graph'\n"); 6377c478bd9Sstevel@tonic-gate return (WALK_ERR); 6387c478bd9Sstevel@tonic-gate } 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)sym.st_value; 64189518a1cSdmick wsp->walk_data = (void *)(uintptr_t)(sym.st_value + sym.st_size); 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate return (WALK_NEXT); 6447c478bd9Sstevel@tonic-gate } 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate typedef struct lg_walk_data { 6477c478bd9Sstevel@tonic-gate uintptr_t startaddr; 6487c478bd9Sstevel@tonic-gate mdb_walk_cb_t callback; 6497c478bd9Sstevel@tonic-gate void *data; 6507c478bd9Sstevel@tonic-gate } lg_walk_data_t; 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate /* 6537c478bd9Sstevel@tonic-gate * We can't use ::walk lock_descriptor directly, because the head of each graph 6547c478bd9Sstevel@tonic-gate * is really a dummy lock. Rather than trying to dynamically determine if this 6557c478bd9Sstevel@tonic-gate * is a dummy node or not, we just filter out the initial element of the 6567c478bd9Sstevel@tonic-gate * list. 6577c478bd9Sstevel@tonic-gate */ 6587c478bd9Sstevel@tonic-gate static int 6597c478bd9Sstevel@tonic-gate lg_walk_cb(uintptr_t addr, const void *data, void *priv) 6607c478bd9Sstevel@tonic-gate { 6617c478bd9Sstevel@tonic-gate lg_walk_data_t *lw = priv; 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate if (addr != lw->startaddr) 6647c478bd9Sstevel@tonic-gate return (lw->callback(addr, data, lw->data)); 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate return (WALK_NEXT); 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate int 6707c478bd9Sstevel@tonic-gate lg_walk_step(mdb_walk_state_t *wsp) 6717c478bd9Sstevel@tonic-gate { 6727c478bd9Sstevel@tonic-gate graph_t *graph; 6737c478bd9Sstevel@tonic-gate lg_walk_data_t lw; 6747c478bd9Sstevel@tonic-gate 6757c478bd9Sstevel@tonic-gate if (wsp->walk_addr >= (uintptr_t)wsp->walk_data) 6767c478bd9Sstevel@tonic-gate return (WALK_DONE); 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate if (mdb_vread(&graph, sizeof (graph), wsp->walk_addr) == -1) { 6797c478bd9Sstevel@tonic-gate mdb_warn("failed to read graph_t at %p", wsp->walk_addr); 6807c478bd9Sstevel@tonic-gate return (WALK_ERR); 6817c478bd9Sstevel@tonic-gate } 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate wsp->walk_addr += sizeof (graph); 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate if (graph == NULL) 6867c478bd9Sstevel@tonic-gate return (WALK_NEXT); 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate lw.callback = wsp->walk_callback; 6897c478bd9Sstevel@tonic-gate lw.data = wsp->walk_cbdata; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate lw.startaddr = (uintptr_t)&(graph->active_locks); 6927c478bd9Sstevel@tonic-gate if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) { 6937c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr); 6947c478bd9Sstevel@tonic-gate return (WALK_ERR); 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate lw.startaddr = (uintptr_t)&(graph->sleeping_locks); 6987c478bd9Sstevel@tonic-gate if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) { 6997c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr); 7007c478bd9Sstevel@tonic-gate return (WALK_ERR); 7017c478bd9Sstevel@tonic-gate } 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate return (WALK_NEXT); 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate /* 7077c478bd9Sstevel@tonic-gate * The space available for the path corresponding to the locked vnode depends 7087c478bd9Sstevel@tonic-gate * on whether we are printing 32- or 64-bit addresses. 7097c478bd9Sstevel@tonic-gate */ 7107c478bd9Sstevel@tonic-gate #ifdef _LP64 7117c478bd9Sstevel@tonic-gate #define LM_VNPATHLEN 20 7127c478bd9Sstevel@tonic-gate #else 7137c478bd9Sstevel@tonic-gate #define LM_VNPATHLEN 30 7147c478bd9Sstevel@tonic-gate #endif 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7177c478bd9Sstevel@tonic-gate static int 7187c478bd9Sstevel@tonic-gate lminfo_cb(uintptr_t addr, const void *data, void *priv) 7197c478bd9Sstevel@tonic-gate { 7207c478bd9Sstevel@tonic-gate const lock_descriptor_t *ld = data; 7217c478bd9Sstevel@tonic-gate char buf[LM_VNPATHLEN]; 7227c478bd9Sstevel@tonic-gate proc_t p; 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate mdb_printf("%-?p %2s %04x %6d %-16s %-?p ", 7257c478bd9Sstevel@tonic-gate addr, ld->l_type == F_RDLCK ? "RD" : 7267c478bd9Sstevel@tonic-gate ld->l_type == F_WRLCK ? "WR" : "??", 7277c478bd9Sstevel@tonic-gate ld->l_state, ld->l_flock.l_pid, 7287c478bd9Sstevel@tonic-gate ld->l_flock.l_pid == 0 ? "<kernel>" : 7297c478bd9Sstevel@tonic-gate mdb_pid2proc(ld->l_flock.l_pid, &p) == NULL ? 7307c478bd9Sstevel@tonic-gate "<defunct>" : p.p_user.u_comm, 7317c478bd9Sstevel@tonic-gate ld->l_vnode); 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate mdb_vnode2path((uintptr_t)ld->l_vnode, buf, 7347c478bd9Sstevel@tonic-gate sizeof (buf)); 7357c478bd9Sstevel@tonic-gate mdb_printf("%s\n", buf); 7367c478bd9Sstevel@tonic-gate 7377c478bd9Sstevel@tonic-gate return (WALK_NEXT); 7387c478bd9Sstevel@tonic-gate } 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7417c478bd9Sstevel@tonic-gate int 7427c478bd9Sstevel@tonic-gate lminfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 7437c478bd9Sstevel@tonic-gate { 7447c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 7457c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-?s %2s %4s %6s %-16s %-?s %s%</u>\n", 7467c478bd9Sstevel@tonic-gate "ADDR", "TP", "FLAG", "PID", "COMM", "VNODE", "PATH"); 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate return (mdb_pwalk("lock_graph", lminfo_cb, NULL, NULL)); 7497c478bd9Sstevel@tonic-gate } 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7527c478bd9Sstevel@tonic-gate int 7537c478bd9Sstevel@tonic-gate seg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 7547c478bd9Sstevel@tonic-gate { 7557c478bd9Sstevel@tonic-gate struct seg s; 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate if (argc != 0) 7587c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) { 7617c478bd9Sstevel@tonic-gate mdb_printf("%<u>%?s %?s %?s %?s %s%</u>\n", 7627c478bd9Sstevel@tonic-gate "SEG", "BASE", "SIZE", "DATA", "OPS"); 7637c478bd9Sstevel@tonic-gate } 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate if (mdb_vread(&s, sizeof (s), addr) == -1) { 7667c478bd9Sstevel@tonic-gate mdb_warn("failed to read seg at %p", addr); 7677c478bd9Sstevel@tonic-gate return (DCMD_ERR); 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate mdb_printf("%?p %?p %?lx %?p %a\n", 7717c478bd9Sstevel@tonic-gate addr, s.s_base, s.s_size, s.s_data, s.s_ops); 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate return (DCMD_OK); 7747c478bd9Sstevel@tonic-gate } 7757c478bd9Sstevel@tonic-gate 7767c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7777c478bd9Sstevel@tonic-gate static int 7787c478bd9Sstevel@tonic-gate pmap_walk_anon(uintptr_t addr, const struct anon *anon, int *nres) 7797c478bd9Sstevel@tonic-gate { 7807c478bd9Sstevel@tonic-gate uintptr_t pp = 7817c478bd9Sstevel@tonic-gate mdb_vnode2page((uintptr_t)anon->an_vp, (uintptr_t)anon->an_off); 7827c478bd9Sstevel@tonic-gate 7837c478bd9Sstevel@tonic-gate if (pp != NULL) 7847c478bd9Sstevel@tonic-gate (*nres)++; 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate return (WALK_NEXT); 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate static int 7907c478bd9Sstevel@tonic-gate pmap_walk_seg(uintptr_t addr, const struct seg *seg, uintptr_t segvn) 7917c478bd9Sstevel@tonic-gate { 7927c478bd9Sstevel@tonic-gate 7937c478bd9Sstevel@tonic-gate mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024); 7947c478bd9Sstevel@tonic-gate 7957c478bd9Sstevel@tonic-gate if (segvn == (uintptr_t)seg->s_ops) { 7967c478bd9Sstevel@tonic-gate struct segvn_data svn; 7977c478bd9Sstevel@tonic-gate int nres = 0; 7987c478bd9Sstevel@tonic-gate 7997c478bd9Sstevel@tonic-gate (void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data); 8007c478bd9Sstevel@tonic-gate 8017c478bd9Sstevel@tonic-gate if (svn.amp == NULL) { 8027c478bd9Sstevel@tonic-gate mdb_printf(" %8s", ""); 8037c478bd9Sstevel@tonic-gate goto drive_on; 8047c478bd9Sstevel@tonic-gate } 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate /* 8077c478bd9Sstevel@tonic-gate * We've got an amp for this segment; walk through 8087c478bd9Sstevel@tonic-gate * the amp, and determine mappings. 8097c478bd9Sstevel@tonic-gate */ 8107c478bd9Sstevel@tonic-gate if (mdb_pwalk("anon", (mdb_walk_cb_t)pmap_walk_anon, 8117c478bd9Sstevel@tonic-gate &nres, (uintptr_t)svn.amp) == -1) 8127c478bd9Sstevel@tonic-gate mdb_warn("failed to walk anon (amp=%p)", svn.amp); 8137c478bd9Sstevel@tonic-gate 8147c478bd9Sstevel@tonic-gate mdb_printf(" %7dk", (nres * PAGESIZE) / 1024); 8157c478bd9Sstevel@tonic-gate drive_on: 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate if (svn.vp != NULL) { 8187c478bd9Sstevel@tonic-gate char buf[29]; 8197c478bd9Sstevel@tonic-gate 8207c478bd9Sstevel@tonic-gate mdb_vnode2path((uintptr_t)svn.vp, buf, sizeof (buf)); 8217c478bd9Sstevel@tonic-gate mdb_printf(" %s", buf); 8227c478bd9Sstevel@tonic-gate } else 8237c478bd9Sstevel@tonic-gate mdb_printf(" [ anon ]"); 8247c478bd9Sstevel@tonic-gate } 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate mdb_printf("\n"); 8277c478bd9Sstevel@tonic-gate return (WALK_NEXT); 8287c478bd9Sstevel@tonic-gate } 8297c478bd9Sstevel@tonic-gate 8307c478bd9Sstevel@tonic-gate static int 8317c478bd9Sstevel@tonic-gate pmap_walk_seg_quick(uintptr_t addr, const struct seg *seg, uintptr_t segvn) 8327c478bd9Sstevel@tonic-gate { 8337c478bd9Sstevel@tonic-gate mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024); 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate if (segvn == (uintptr_t)seg->s_ops) { 8367c478bd9Sstevel@tonic-gate struct segvn_data svn; 8377c478bd9Sstevel@tonic-gate 8387c478bd9Sstevel@tonic-gate (void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data); 8397c478bd9Sstevel@tonic-gate 8407c478bd9Sstevel@tonic-gate if (svn.vp != NULL) { 8417c478bd9Sstevel@tonic-gate mdb_printf(" %0?p", svn.vp); 8427c478bd9Sstevel@tonic-gate } else { 8437c478bd9Sstevel@tonic-gate mdb_printf(" [ anon ]"); 8447c478bd9Sstevel@tonic-gate } 8457c478bd9Sstevel@tonic-gate } 8467c478bd9Sstevel@tonic-gate 8477c478bd9Sstevel@tonic-gate mdb_printf("\n"); 8487c478bd9Sstevel@tonic-gate return (WALK_NEXT); 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8527c478bd9Sstevel@tonic-gate int 8537c478bd9Sstevel@tonic-gate pmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 8547c478bd9Sstevel@tonic-gate { 8557c478bd9Sstevel@tonic-gate uintptr_t segvn; 8567c478bd9Sstevel@tonic-gate proc_t proc; 8577c478bd9Sstevel@tonic-gate uint_t quick = FALSE; 8587c478bd9Sstevel@tonic-gate mdb_walk_cb_t cb = (mdb_walk_cb_t)pmap_walk_seg; 8597c478bd9Sstevel@tonic-gate 8607c478bd9Sstevel@tonic-gate GElf_Sym sym; 8617c478bd9Sstevel@tonic-gate 8627c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 8637c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 8647c478bd9Sstevel@tonic-gate 8657c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 8667c478bd9Sstevel@tonic-gate 'q', MDB_OPT_SETBITS, TRUE, &quick, NULL) != argc) 8677c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 8687c478bd9Sstevel@tonic-gate 8697c478bd9Sstevel@tonic-gate if (mdb_vread(&proc, sizeof (proc), addr) == -1) { 8707c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc at %p", addr); 8717c478bd9Sstevel@tonic-gate return (DCMD_ERR); 8727c478bd9Sstevel@tonic-gate } 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("segvn_ops", &sym) == 0) 8757c478bd9Sstevel@tonic-gate segvn = (uintptr_t)sym.st_value; 8767c478bd9Sstevel@tonic-gate else 8777c478bd9Sstevel@tonic-gate segvn = NULL; 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate mdb_printf("%?s %?s %8s ", "SEG", "BASE", "SIZE"); 8807c478bd9Sstevel@tonic-gate 8817c478bd9Sstevel@tonic-gate if (quick) { 8827c478bd9Sstevel@tonic-gate mdb_printf("VNODE\n"); 8837c478bd9Sstevel@tonic-gate cb = (mdb_walk_cb_t)pmap_walk_seg_quick; 8847c478bd9Sstevel@tonic-gate } else { 8857c478bd9Sstevel@tonic-gate mdb_printf("%8s %s\n", "RES", "PATH"); 8867c478bd9Sstevel@tonic-gate } 8877c478bd9Sstevel@tonic-gate 8887c478bd9Sstevel@tonic-gate if (mdb_pwalk("seg", cb, (void *)segvn, (uintptr_t)proc.p_as) == -1) { 8897c478bd9Sstevel@tonic-gate mdb_warn("failed to walk segments of as %p", proc.p_as); 8907c478bd9Sstevel@tonic-gate return (DCMD_ERR); 8917c478bd9Sstevel@tonic-gate } 8927c478bd9Sstevel@tonic-gate 8937c478bd9Sstevel@tonic-gate return (DCMD_OK); 8947c478bd9Sstevel@tonic-gate } 8957c478bd9Sstevel@tonic-gate 8967c478bd9Sstevel@tonic-gate typedef struct anon_walk_data { 8977c478bd9Sstevel@tonic-gate uintptr_t *aw_levone; 8987c478bd9Sstevel@tonic-gate uintptr_t *aw_levtwo; 8997c478bd9Sstevel@tonic-gate int aw_nlevone; 9007c478bd9Sstevel@tonic-gate int aw_levone_ndx; 9017c478bd9Sstevel@tonic-gate int aw_levtwo_ndx; 9027c478bd9Sstevel@tonic-gate struct anon_map aw_amp; 9037c478bd9Sstevel@tonic-gate struct anon_hdr aw_ahp; 9047c478bd9Sstevel@tonic-gate } anon_walk_data_t; 9057c478bd9Sstevel@tonic-gate 9067c478bd9Sstevel@tonic-gate int 9077c478bd9Sstevel@tonic-gate anon_walk_init(mdb_walk_state_t *wsp) 9087c478bd9Sstevel@tonic-gate { 9097c478bd9Sstevel@tonic-gate anon_walk_data_t *aw; 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 9127c478bd9Sstevel@tonic-gate mdb_warn("anon walk doesn't support global walks\n"); 9137c478bd9Sstevel@tonic-gate return (WALK_ERR); 9147c478bd9Sstevel@tonic-gate } 9157c478bd9Sstevel@tonic-gate 9167c478bd9Sstevel@tonic-gate aw = mdb_alloc(sizeof (anon_walk_data_t), UM_SLEEP); 9177c478bd9Sstevel@tonic-gate 9187c478bd9Sstevel@tonic-gate if (mdb_vread(&aw->aw_amp, sizeof (aw->aw_amp), wsp->walk_addr) == -1) { 9197c478bd9Sstevel@tonic-gate mdb_warn("failed to read anon map at %p", wsp->walk_addr); 9207c478bd9Sstevel@tonic-gate mdb_free(aw, sizeof (anon_walk_data_t)); 9217c478bd9Sstevel@tonic-gate return (WALK_ERR); 9227c478bd9Sstevel@tonic-gate } 9237c478bd9Sstevel@tonic-gate 9247c478bd9Sstevel@tonic-gate if (mdb_vread(&aw->aw_ahp, sizeof (aw->aw_ahp), 9257c478bd9Sstevel@tonic-gate (uintptr_t)(aw->aw_amp.ahp)) == -1) { 9267c478bd9Sstevel@tonic-gate mdb_warn("failed to read anon hdr ptr at %p", aw->aw_amp.ahp); 9277c478bd9Sstevel@tonic-gate mdb_free(aw, sizeof (anon_walk_data_t)); 9287c478bd9Sstevel@tonic-gate return (WALK_ERR); 9297c478bd9Sstevel@tonic-gate } 9307c478bd9Sstevel@tonic-gate 9317c478bd9Sstevel@tonic-gate if (aw->aw_ahp.size <= ANON_CHUNK_SIZE || 9327c478bd9Sstevel@tonic-gate (aw->aw_ahp.flags & ANON_ALLOC_FORCE)) { 9337c478bd9Sstevel@tonic-gate aw->aw_nlevone = aw->aw_ahp.size; 9347c478bd9Sstevel@tonic-gate aw->aw_levtwo = NULL; 9357c478bd9Sstevel@tonic-gate } else { 9367c478bd9Sstevel@tonic-gate aw->aw_nlevone = 9377c478bd9Sstevel@tonic-gate (aw->aw_ahp.size + ANON_CHUNK_OFF) >> ANON_CHUNK_SHIFT; 9387c478bd9Sstevel@tonic-gate aw->aw_levtwo = 9397c478bd9Sstevel@tonic-gate mdb_zalloc(ANON_CHUNK_SIZE * sizeof (uintptr_t), UM_SLEEP); 9407c478bd9Sstevel@tonic-gate } 9417c478bd9Sstevel@tonic-gate 9427c478bd9Sstevel@tonic-gate aw->aw_levone = 9437c478bd9Sstevel@tonic-gate mdb_alloc(aw->aw_nlevone * sizeof (uintptr_t), UM_SLEEP); 9447c478bd9Sstevel@tonic-gate 9457c478bd9Sstevel@tonic-gate aw->aw_levone_ndx = 0; 9467c478bd9Sstevel@tonic-gate aw->aw_levtwo_ndx = 0; 9477c478bd9Sstevel@tonic-gate 9487c478bd9Sstevel@tonic-gate mdb_vread(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t), 9497c478bd9Sstevel@tonic-gate (uintptr_t)aw->aw_ahp.array_chunk); 9507c478bd9Sstevel@tonic-gate 9517c478bd9Sstevel@tonic-gate if (aw->aw_levtwo != NULL) { 9527c478bd9Sstevel@tonic-gate while (aw->aw_levone[aw->aw_levone_ndx] == NULL) { 9537c478bd9Sstevel@tonic-gate aw->aw_levone_ndx++; 9547c478bd9Sstevel@tonic-gate if (aw->aw_levone_ndx == aw->aw_nlevone) { 9557c478bd9Sstevel@tonic-gate mdb_warn("corrupt anon; couldn't" 9567c478bd9Sstevel@tonic-gate "find ptr to lev two map"); 9577c478bd9Sstevel@tonic-gate goto out; 9587c478bd9Sstevel@tonic-gate } 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t), 9627c478bd9Sstevel@tonic-gate aw->aw_levone[aw->aw_levone_ndx]); 9637c478bd9Sstevel@tonic-gate } 9647c478bd9Sstevel@tonic-gate 9657c478bd9Sstevel@tonic-gate out: 9667c478bd9Sstevel@tonic-gate wsp->walk_data = aw; 9677c478bd9Sstevel@tonic-gate return (0); 9687c478bd9Sstevel@tonic-gate } 9697c478bd9Sstevel@tonic-gate 9707c478bd9Sstevel@tonic-gate int 9717c478bd9Sstevel@tonic-gate anon_walk_step(mdb_walk_state_t *wsp) 9727c478bd9Sstevel@tonic-gate { 9737c478bd9Sstevel@tonic-gate int status; 9747c478bd9Sstevel@tonic-gate anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data; 9757c478bd9Sstevel@tonic-gate struct anon anon; 9767c478bd9Sstevel@tonic-gate uintptr_t anonptr; 9777c478bd9Sstevel@tonic-gate 9787c478bd9Sstevel@tonic-gate again: 9797c478bd9Sstevel@tonic-gate /* 9807c478bd9Sstevel@tonic-gate * Once we've walked through level one, we're done. 9817c478bd9Sstevel@tonic-gate */ 9827c478bd9Sstevel@tonic-gate if (aw->aw_levone_ndx == aw->aw_nlevone) 9837c478bd9Sstevel@tonic-gate return (WALK_DONE); 9847c478bd9Sstevel@tonic-gate 9857c478bd9Sstevel@tonic-gate if (aw->aw_levtwo == NULL) { 9867c478bd9Sstevel@tonic-gate anonptr = aw->aw_levone[aw->aw_levone_ndx]; 9877c478bd9Sstevel@tonic-gate aw->aw_levone_ndx++; 9887c478bd9Sstevel@tonic-gate } else { 9897c478bd9Sstevel@tonic-gate anonptr = aw->aw_levtwo[aw->aw_levtwo_ndx]; 9907c478bd9Sstevel@tonic-gate aw->aw_levtwo_ndx++; 9917c478bd9Sstevel@tonic-gate 9927c478bd9Sstevel@tonic-gate if (aw->aw_levtwo_ndx == ANON_CHUNK_SIZE) { 9937c478bd9Sstevel@tonic-gate aw->aw_levtwo_ndx = 0; 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate do { 9967c478bd9Sstevel@tonic-gate aw->aw_levone_ndx++; 9977c478bd9Sstevel@tonic-gate 9987c478bd9Sstevel@tonic-gate if (aw->aw_levone_ndx == aw->aw_nlevone) 9997c478bd9Sstevel@tonic-gate return (WALK_DONE); 10007c478bd9Sstevel@tonic-gate } while (aw->aw_levone[aw->aw_levone_ndx] == NULL); 10017c478bd9Sstevel@tonic-gate 10027c478bd9Sstevel@tonic-gate mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE * 10037c478bd9Sstevel@tonic-gate sizeof (uintptr_t), 10047c478bd9Sstevel@tonic-gate aw->aw_levone[aw->aw_levone_ndx]); 10057c478bd9Sstevel@tonic-gate } 10067c478bd9Sstevel@tonic-gate } 10077c478bd9Sstevel@tonic-gate 10087c478bd9Sstevel@tonic-gate if (anonptr != NULL) { 10097c478bd9Sstevel@tonic-gate mdb_vread(&anon, sizeof (anon), anonptr); 10107c478bd9Sstevel@tonic-gate status = wsp->walk_callback(anonptr, &anon, wsp->walk_cbdata); 10117c478bd9Sstevel@tonic-gate } else 10127c478bd9Sstevel@tonic-gate goto again; 10137c478bd9Sstevel@tonic-gate 10147c478bd9Sstevel@tonic-gate return (status); 10157c478bd9Sstevel@tonic-gate } 10167c478bd9Sstevel@tonic-gate 10177c478bd9Sstevel@tonic-gate void 10187c478bd9Sstevel@tonic-gate anon_walk_fini(mdb_walk_state_t *wsp) 10197c478bd9Sstevel@tonic-gate { 10207c478bd9Sstevel@tonic-gate anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data; 10217c478bd9Sstevel@tonic-gate 10227c478bd9Sstevel@tonic-gate if (aw->aw_levtwo != NULL) 10237c478bd9Sstevel@tonic-gate mdb_free(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t)); 10247c478bd9Sstevel@tonic-gate 10257c478bd9Sstevel@tonic-gate mdb_free(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t)); 10267c478bd9Sstevel@tonic-gate mdb_free(aw, sizeof (anon_walk_data_t)); 10277c478bd9Sstevel@tonic-gate } 10287c478bd9Sstevel@tonic-gate 10297c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10307c478bd9Sstevel@tonic-gate int 10317c478bd9Sstevel@tonic-gate whereopen_fwalk(uintptr_t addr, struct file *f, uintptr_t *target) 10327c478bd9Sstevel@tonic-gate { 10337c478bd9Sstevel@tonic-gate if ((uintptr_t)f->f_vnode == *target) { 10347c478bd9Sstevel@tonic-gate mdb_printf("file %p\n", addr); 10357c478bd9Sstevel@tonic-gate *target = NULL; 10367c478bd9Sstevel@tonic-gate } 10377c478bd9Sstevel@tonic-gate 10387c478bd9Sstevel@tonic-gate return (WALK_NEXT); 10397c478bd9Sstevel@tonic-gate } 10407c478bd9Sstevel@tonic-gate 10417c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10427c478bd9Sstevel@tonic-gate int 10437c478bd9Sstevel@tonic-gate whereopen_pwalk(uintptr_t addr, void *ignored, uintptr_t *target) 10447c478bd9Sstevel@tonic-gate { 10457c478bd9Sstevel@tonic-gate uintptr_t t = *target; 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate if (mdb_pwalk("file", (mdb_walk_cb_t)whereopen_fwalk, &t, addr) == -1) { 10487c478bd9Sstevel@tonic-gate mdb_warn("couldn't file walk proc %p", addr); 10497c478bd9Sstevel@tonic-gate return (WALK_ERR); 10507c478bd9Sstevel@tonic-gate } 10517c478bd9Sstevel@tonic-gate 10527c478bd9Sstevel@tonic-gate if (t == NULL) 10537c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr); 10547c478bd9Sstevel@tonic-gate 10557c478bd9Sstevel@tonic-gate return (WALK_NEXT); 10567c478bd9Sstevel@tonic-gate } 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10597c478bd9Sstevel@tonic-gate int 10607c478bd9Sstevel@tonic-gate whereopen(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 10617c478bd9Sstevel@tonic-gate { 10627c478bd9Sstevel@tonic-gate uintptr_t target = addr; 10637c478bd9Sstevel@tonic-gate 10647c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || addr == NULL) 10657c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate if (mdb_walk("proc", (mdb_walk_cb_t)whereopen_pwalk, &target) == -1) { 10687c478bd9Sstevel@tonic-gate mdb_warn("can't proc walk"); 10697c478bd9Sstevel@tonic-gate return (DCMD_ERR); 10707c478bd9Sstevel@tonic-gate } 10717c478bd9Sstevel@tonic-gate 10727c478bd9Sstevel@tonic-gate return (DCMD_OK); 10737c478bd9Sstevel@tonic-gate } 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate typedef struct datafmt { 10767c478bd9Sstevel@tonic-gate char *hdr1; 10777c478bd9Sstevel@tonic-gate char *hdr2; 10787c478bd9Sstevel@tonic-gate char *dashes; 10797c478bd9Sstevel@tonic-gate char *fmt; 10807c478bd9Sstevel@tonic-gate } datafmt_t; 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate static datafmt_t kmemfmt[] = { 10837c478bd9Sstevel@tonic-gate { "cache ", "name ", 10847c478bd9Sstevel@tonic-gate "-------------------------", "%-25s " }, 10857c478bd9Sstevel@tonic-gate { " buf", " size", "------", "%6u " }, 10867c478bd9Sstevel@tonic-gate { " buf", "in use", "------", "%6u " }, 10877c478bd9Sstevel@tonic-gate { " buf", " total", "------", "%6u " }, 10887c478bd9Sstevel@tonic-gate { " memory", " in use", "---------", "%9u " }, 10897c478bd9Sstevel@tonic-gate { " alloc", " succeed", "---------", "%9u " }, 10907c478bd9Sstevel@tonic-gate { "alloc", " fail", "-----", "%5u " }, 10917c478bd9Sstevel@tonic-gate { NULL, NULL, NULL, NULL } 10927c478bd9Sstevel@tonic-gate }; 10937c478bd9Sstevel@tonic-gate 10947c478bd9Sstevel@tonic-gate static datafmt_t vmemfmt[] = { 10957c478bd9Sstevel@tonic-gate { "vmem ", "name ", 10967c478bd9Sstevel@tonic-gate "-------------------------", "%-*s " }, 10977c478bd9Sstevel@tonic-gate { " memory", " in use", "---------", "%9llu " }, 10987c478bd9Sstevel@tonic-gate { " memory", " total", "----------", "%10llu " }, 10997c478bd9Sstevel@tonic-gate { " memory", " import", "---------", "%9llu " }, 11007c478bd9Sstevel@tonic-gate { " alloc", " succeed", "---------", "%9llu " }, 11017c478bd9Sstevel@tonic-gate { "alloc", " fail", "-----", "%5llu " }, 11027c478bd9Sstevel@tonic-gate { NULL, NULL, NULL, NULL } 11037c478bd9Sstevel@tonic-gate }; 11047c478bd9Sstevel@tonic-gate 11057c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11067c478bd9Sstevel@tonic-gate static int 11077c478bd9Sstevel@tonic-gate kmastat_cpu_avail(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *avail) 11087c478bd9Sstevel@tonic-gate { 11097c478bd9Sstevel@tonic-gate if (ccp->cc_rounds > 0) 11107c478bd9Sstevel@tonic-gate *avail += ccp->cc_rounds; 11117c478bd9Sstevel@tonic-gate if (ccp->cc_prounds > 0) 11127c478bd9Sstevel@tonic-gate *avail += ccp->cc_prounds; 11137c478bd9Sstevel@tonic-gate 11147c478bd9Sstevel@tonic-gate return (WALK_NEXT); 11157c478bd9Sstevel@tonic-gate } 11167c478bd9Sstevel@tonic-gate 11177c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11187c478bd9Sstevel@tonic-gate static int 11197c478bd9Sstevel@tonic-gate kmastat_cpu_alloc(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *alloc) 11207c478bd9Sstevel@tonic-gate { 11217c478bd9Sstevel@tonic-gate *alloc += ccp->cc_alloc; 11227c478bd9Sstevel@tonic-gate 11237c478bd9Sstevel@tonic-gate return (WALK_NEXT); 11247c478bd9Sstevel@tonic-gate } 11257c478bd9Sstevel@tonic-gate 11267c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11277c478bd9Sstevel@tonic-gate static int 11287c478bd9Sstevel@tonic-gate kmastat_slab_avail(uintptr_t addr, const kmem_slab_t *sp, int *avail) 11297c478bd9Sstevel@tonic-gate { 11307c478bd9Sstevel@tonic-gate *avail += sp->slab_chunks - sp->slab_refcnt; 11317c478bd9Sstevel@tonic-gate 11327c478bd9Sstevel@tonic-gate return (WALK_NEXT); 11337c478bd9Sstevel@tonic-gate } 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate typedef struct kmastat_vmem { 11367c478bd9Sstevel@tonic-gate uintptr_t kv_addr; 11377c478bd9Sstevel@tonic-gate struct kmastat_vmem *kv_next; 11387c478bd9Sstevel@tonic-gate int kv_meminuse; 11397c478bd9Sstevel@tonic-gate int kv_alloc; 11407c478bd9Sstevel@tonic-gate int kv_fail; 11417c478bd9Sstevel@tonic-gate } kmastat_vmem_t; 11427c478bd9Sstevel@tonic-gate 11437c478bd9Sstevel@tonic-gate static int 11447c478bd9Sstevel@tonic-gate kmastat_cache(uintptr_t addr, const kmem_cache_t *cp, kmastat_vmem_t **kvp) 11457c478bd9Sstevel@tonic-gate { 11467c478bd9Sstevel@tonic-gate kmastat_vmem_t *kv; 11477c478bd9Sstevel@tonic-gate datafmt_t *dfp = kmemfmt; 11487c478bd9Sstevel@tonic-gate int magsize; 11497c478bd9Sstevel@tonic-gate 11507c478bd9Sstevel@tonic-gate int avail, alloc, total; 11517c478bd9Sstevel@tonic-gate size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) * 11527c478bd9Sstevel@tonic-gate cp->cache_slabsize; 11537c478bd9Sstevel@tonic-gate 11547c478bd9Sstevel@tonic-gate mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)kmastat_cpu_avail; 11557c478bd9Sstevel@tonic-gate mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)kmastat_cpu_alloc; 11567c478bd9Sstevel@tonic-gate mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)kmastat_slab_avail; 11577c478bd9Sstevel@tonic-gate 11587c478bd9Sstevel@tonic-gate magsize = kmem_get_magsize(cp); 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc; 11617c478bd9Sstevel@tonic-gate avail = cp->cache_full.ml_total * magsize; 11627c478bd9Sstevel@tonic-gate total = cp->cache_buftotal; 11637c478bd9Sstevel@tonic-gate 11647c478bd9Sstevel@tonic-gate (void) mdb_pwalk("kmem_cpu_cache", cpu_alloc, &alloc, addr); 11657c478bd9Sstevel@tonic-gate (void) mdb_pwalk("kmem_cpu_cache", cpu_avail, &avail, addr); 11667c478bd9Sstevel@tonic-gate (void) mdb_pwalk("kmem_slab_partial", slab_avail, &avail, addr); 11677c478bd9Sstevel@tonic-gate 11687c478bd9Sstevel@tonic-gate for (kv = *kvp; kv != NULL; kv = kv->kv_next) { 11697c478bd9Sstevel@tonic-gate if (kv->kv_addr == (uintptr_t)cp->cache_arena) 11707c478bd9Sstevel@tonic-gate goto out; 11717c478bd9Sstevel@tonic-gate } 11727c478bd9Sstevel@tonic-gate 11737c478bd9Sstevel@tonic-gate kv = mdb_zalloc(sizeof (kmastat_vmem_t), UM_SLEEP | UM_GC); 11747c478bd9Sstevel@tonic-gate kv->kv_next = *kvp; 11757c478bd9Sstevel@tonic-gate kv->kv_addr = (uintptr_t)cp->cache_arena; 11767c478bd9Sstevel@tonic-gate *kvp = kv; 11777c478bd9Sstevel@tonic-gate out: 11787c478bd9Sstevel@tonic-gate kv->kv_meminuse += meminuse; 11797c478bd9Sstevel@tonic-gate kv->kv_alloc += alloc; 11807c478bd9Sstevel@tonic-gate kv->kv_fail += cp->cache_alloc_fail; 11817c478bd9Sstevel@tonic-gate 11827c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_name); 11837c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_bufsize); 11847c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, total - avail); 11857c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, total); 11867c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, meminuse); 11877c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, alloc); 11887c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_alloc_fail); 11897c478bd9Sstevel@tonic-gate mdb_printf("\n"); 11907c478bd9Sstevel@tonic-gate 11917c478bd9Sstevel@tonic-gate return (WALK_NEXT); 11927c478bd9Sstevel@tonic-gate } 11937c478bd9Sstevel@tonic-gate 11947c478bd9Sstevel@tonic-gate static int 11957c478bd9Sstevel@tonic-gate kmastat_vmem_totals(uintptr_t addr, const vmem_t *v, kmastat_vmem_t *kv) 11967c478bd9Sstevel@tonic-gate { 11977c478bd9Sstevel@tonic-gate size_t len; 11987c478bd9Sstevel@tonic-gate 11997c478bd9Sstevel@tonic-gate while (kv != NULL && kv->kv_addr != addr) 12007c478bd9Sstevel@tonic-gate kv = kv->kv_next; 12017c478bd9Sstevel@tonic-gate 12027c478bd9Sstevel@tonic-gate if (kv == NULL || kv->kv_alloc == 0) 12037c478bd9Sstevel@tonic-gate return (WALK_NEXT); 12047c478bd9Sstevel@tonic-gate 12057c478bd9Sstevel@tonic-gate len = MIN(17, strlen(v->vm_name)); 12067c478bd9Sstevel@tonic-gate 12077c478bd9Sstevel@tonic-gate mdb_printf("Total [%s]%*s %6s %6s %6s %9u %9u %5u\n", v->vm_name, 12087c478bd9Sstevel@tonic-gate 17 - len, "", "", "", "", 12097c478bd9Sstevel@tonic-gate kv->kv_meminuse, kv->kv_alloc, kv->kv_fail); 12107c478bd9Sstevel@tonic-gate 12117c478bd9Sstevel@tonic-gate return (WALK_NEXT); 12127c478bd9Sstevel@tonic-gate } 12137c478bd9Sstevel@tonic-gate 12147c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 12157c478bd9Sstevel@tonic-gate static int 12167c478bd9Sstevel@tonic-gate kmastat_vmem(uintptr_t addr, const vmem_t *v, void *ignored) 12177c478bd9Sstevel@tonic-gate { 12187c478bd9Sstevel@tonic-gate datafmt_t *dfp = vmemfmt; 12197c478bd9Sstevel@tonic-gate const vmem_kstat_t *vkp = &v->vm_kstat; 12207c478bd9Sstevel@tonic-gate uintptr_t paddr; 12217c478bd9Sstevel@tonic-gate vmem_t parent; 12227c478bd9Sstevel@tonic-gate int ident = 0; 12237c478bd9Sstevel@tonic-gate 12247c478bd9Sstevel@tonic-gate for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) { 12257c478bd9Sstevel@tonic-gate if (mdb_vread(&parent, sizeof (parent), paddr) == -1) { 12267c478bd9Sstevel@tonic-gate mdb_warn("couldn't trace %p's ancestry", addr); 12277c478bd9Sstevel@tonic-gate ident = 0; 12287c478bd9Sstevel@tonic-gate break; 12297c478bd9Sstevel@tonic-gate } 12307c478bd9Sstevel@tonic-gate paddr = (uintptr_t)parent.vm_source; 12317c478bd9Sstevel@tonic-gate } 12327c478bd9Sstevel@tonic-gate 12337c478bd9Sstevel@tonic-gate mdb_printf("%*s", ident, ""); 12347c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name); 12357c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_mem_inuse.value.ui64); 12367c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_mem_total.value.ui64); 12377c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_mem_import.value.ui64); 12387c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_alloc.value.ui64); 12397c478bd9Sstevel@tonic-gate mdb_printf((dfp++)->fmt, vkp->vk_fail.value.ui64); 12407c478bd9Sstevel@tonic-gate 12417c478bd9Sstevel@tonic-gate mdb_printf("\n"); 12427c478bd9Sstevel@tonic-gate 12437c478bd9Sstevel@tonic-gate return (WALK_NEXT); 12447c478bd9Sstevel@tonic-gate } 12457c478bd9Sstevel@tonic-gate 12467c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 12477c478bd9Sstevel@tonic-gate int 12487c478bd9Sstevel@tonic-gate kmastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 12497c478bd9Sstevel@tonic-gate { 12507c478bd9Sstevel@tonic-gate kmastat_vmem_t *kv = NULL; 12517c478bd9Sstevel@tonic-gate datafmt_t *dfp; 12527c478bd9Sstevel@tonic-gate 12537c478bd9Sstevel@tonic-gate if (argc != 0) 12547c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 12557c478bd9Sstevel@tonic-gate 12567c478bd9Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 12577c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr1); 12587c478bd9Sstevel@tonic-gate mdb_printf("\n"); 12597c478bd9Sstevel@tonic-gate 12607c478bd9Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 12617c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr2); 12627c478bd9Sstevel@tonic-gate mdb_printf("\n"); 12637c478bd9Sstevel@tonic-gate 12647c478bd9Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 12657c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 12667c478bd9Sstevel@tonic-gate mdb_printf("\n"); 12677c478bd9Sstevel@tonic-gate 12687c478bd9Sstevel@tonic-gate if (mdb_walk("kmem_cache", (mdb_walk_cb_t)kmastat_cache, &kv) == -1) { 12697c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'kmem_cache'"); 12707c478bd9Sstevel@tonic-gate return (DCMD_ERR); 12717c478bd9Sstevel@tonic-gate } 12727c478bd9Sstevel@tonic-gate 12737c478bd9Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 12747c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 12757c478bd9Sstevel@tonic-gate mdb_printf("\n"); 12767c478bd9Sstevel@tonic-gate 12777c478bd9Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem_totals, kv) == -1) { 12787c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'vmem'"); 12797c478bd9Sstevel@tonic-gate return (DCMD_ERR); 12807c478bd9Sstevel@tonic-gate } 12817c478bd9Sstevel@tonic-gate 12827c478bd9Sstevel@tonic-gate for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 12837c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 12847c478bd9Sstevel@tonic-gate mdb_printf("\n"); 12857c478bd9Sstevel@tonic-gate 12867c478bd9Sstevel@tonic-gate mdb_printf("\n"); 12877c478bd9Sstevel@tonic-gate 12887c478bd9Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 12897c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr1); 12907c478bd9Sstevel@tonic-gate mdb_printf("\n"); 12917c478bd9Sstevel@tonic-gate 12927c478bd9Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 12937c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr2); 12947c478bd9Sstevel@tonic-gate mdb_printf("\n"); 12957c478bd9Sstevel@tonic-gate 12967c478bd9Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 12977c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 12987c478bd9Sstevel@tonic-gate mdb_printf("\n"); 12997c478bd9Sstevel@tonic-gate 13007c478bd9Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem, NULL) == -1) { 13017c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'vmem'"); 13027c478bd9Sstevel@tonic-gate return (DCMD_ERR); 13037c478bd9Sstevel@tonic-gate } 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 13067c478bd9Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 13077c478bd9Sstevel@tonic-gate mdb_printf("\n"); 13087c478bd9Sstevel@tonic-gate return (DCMD_OK); 13097c478bd9Sstevel@tonic-gate } 13107c478bd9Sstevel@tonic-gate 13117c478bd9Sstevel@tonic-gate /* 13127c478bd9Sstevel@tonic-gate * Our ::kgrep callback scans the entire kernel VA space (kas). kas is made 13137c478bd9Sstevel@tonic-gate * up of a set of 'struct seg's. We could just scan each seg en masse, but 13147c478bd9Sstevel@tonic-gate * unfortunately, a few of the segs are both large and sparse, so we could 13157c478bd9Sstevel@tonic-gate * spend quite a bit of time scanning VAs which have no backing pages. 13167c478bd9Sstevel@tonic-gate * 13177c478bd9Sstevel@tonic-gate * So for the few very sparse segs, we skip the segment itself, and scan 13187c478bd9Sstevel@tonic-gate * the allocated vmem_segs in the vmem arena which manages that part of kas. 13197c478bd9Sstevel@tonic-gate * Currently, we do this for: 13207c478bd9Sstevel@tonic-gate * 13217c478bd9Sstevel@tonic-gate * SEG VMEM ARENA 13227c478bd9Sstevel@tonic-gate * kvseg heap_arena 13237c478bd9Sstevel@tonic-gate * kvseg32 heap32_arena 13247c478bd9Sstevel@tonic-gate * kvseg_core heap_core_arena 13257c478bd9Sstevel@tonic-gate * 13267c478bd9Sstevel@tonic-gate * In addition, we skip the segkpm segment in its entirety, since it is very 13277c478bd9Sstevel@tonic-gate * sparse, and contains no new kernel data. 13287c478bd9Sstevel@tonic-gate */ 13297c478bd9Sstevel@tonic-gate typedef struct kgrep_walk_data { 13307c478bd9Sstevel@tonic-gate kgrep_cb_func *kg_cb; 13317c478bd9Sstevel@tonic-gate void *kg_cbdata; 13327c478bd9Sstevel@tonic-gate uintptr_t kg_kvseg; 13337c478bd9Sstevel@tonic-gate uintptr_t kg_kvseg32; 13347c478bd9Sstevel@tonic-gate uintptr_t kg_kvseg_core; 13357c478bd9Sstevel@tonic-gate uintptr_t kg_segkpm; 13367bc98a2eSeg uintptr_t kg_heap_lp_base; 13377bc98a2eSeg uintptr_t kg_heap_lp_end; 13387c478bd9Sstevel@tonic-gate } kgrep_walk_data_t; 13397c478bd9Sstevel@tonic-gate 13407c478bd9Sstevel@tonic-gate static int 13417c478bd9Sstevel@tonic-gate kgrep_walk_seg(uintptr_t addr, const struct seg *seg, kgrep_walk_data_t *kg) 13427c478bd9Sstevel@tonic-gate { 13437c478bd9Sstevel@tonic-gate uintptr_t base = (uintptr_t)seg->s_base; 13447c478bd9Sstevel@tonic-gate 13457c478bd9Sstevel@tonic-gate if (addr == kg->kg_kvseg || addr == kg->kg_kvseg32 || 13467c478bd9Sstevel@tonic-gate addr == kg->kg_kvseg_core) 13477c478bd9Sstevel@tonic-gate return (WALK_NEXT); 13487c478bd9Sstevel@tonic-gate 13497c478bd9Sstevel@tonic-gate if ((uintptr_t)seg->s_ops == kg->kg_segkpm) 13507c478bd9Sstevel@tonic-gate return (WALK_NEXT); 13517c478bd9Sstevel@tonic-gate 13527c478bd9Sstevel@tonic-gate return (kg->kg_cb(base, base + seg->s_size, kg->kg_cbdata)); 13537c478bd9Sstevel@tonic-gate } 13547c478bd9Sstevel@tonic-gate 13557c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 13567c478bd9Sstevel@tonic-gate static int 13577c478bd9Sstevel@tonic-gate kgrep_walk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg) 13587bc98a2eSeg { 13597bc98a2eSeg /* 13607bc98a2eSeg * skip large page heap address range - it is scanned by walking 13617bc98a2eSeg * allocated vmem_segs in the heap_lp_arena 13627bc98a2eSeg */ 13637bc98a2eSeg if (seg->vs_start == kg->kg_heap_lp_base && 13647bc98a2eSeg seg->vs_end == kg->kg_heap_lp_end) 13657bc98a2eSeg return (WALK_NEXT); 13667bc98a2eSeg 13677bc98a2eSeg return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata)); 13687bc98a2eSeg } 13697bc98a2eSeg 13707bc98a2eSeg /*ARGSUSED*/ 13717bc98a2eSeg static int 13727bc98a2eSeg kgrep_xwalk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg) 13737c478bd9Sstevel@tonic-gate { 13747c478bd9Sstevel@tonic-gate return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata)); 13757c478bd9Sstevel@tonic-gate } 13767c478bd9Sstevel@tonic-gate 13777c478bd9Sstevel@tonic-gate static int 13787c478bd9Sstevel@tonic-gate kgrep_walk_vmem(uintptr_t addr, const vmem_t *vmem, kgrep_walk_data_t *kg) 13797c478bd9Sstevel@tonic-gate { 13807bc98a2eSeg mdb_walk_cb_t walk_vseg = (mdb_walk_cb_t)kgrep_walk_vseg; 13817bc98a2eSeg 13827c478bd9Sstevel@tonic-gate if (strcmp(vmem->vm_name, "heap") != 0 && 13837c478bd9Sstevel@tonic-gate strcmp(vmem->vm_name, "heap32") != 0 && 13847bc98a2eSeg strcmp(vmem->vm_name, "heap_core") != 0 && 13857bc98a2eSeg strcmp(vmem->vm_name, "heap_lp") != 0) 13867c478bd9Sstevel@tonic-gate return (WALK_NEXT); 13877c478bd9Sstevel@tonic-gate 13887bc98a2eSeg if (strcmp(vmem->vm_name, "heap_lp") == 0) 13897bc98a2eSeg walk_vseg = (mdb_walk_cb_t)kgrep_xwalk_vseg; 13907bc98a2eSeg 13917bc98a2eSeg if (mdb_pwalk("vmem_alloc", walk_vseg, kg, addr) == -1) { 13927c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk vmem_alloc for vmem %p", addr); 13937c478bd9Sstevel@tonic-gate return (WALK_ERR); 13947c478bd9Sstevel@tonic-gate } 13957c478bd9Sstevel@tonic-gate 13967c478bd9Sstevel@tonic-gate return (WALK_NEXT); 13977c478bd9Sstevel@tonic-gate } 13987c478bd9Sstevel@tonic-gate 13997c478bd9Sstevel@tonic-gate int 14007c478bd9Sstevel@tonic-gate kgrep_subr(kgrep_cb_func *cb, void *cbdata) 14017c478bd9Sstevel@tonic-gate { 14027c478bd9Sstevel@tonic-gate GElf_Sym kas, kvseg, kvseg32, kvseg_core, segkpm; 14037c478bd9Sstevel@tonic-gate kgrep_walk_data_t kg; 14047c478bd9Sstevel@tonic-gate 14057c478bd9Sstevel@tonic-gate if (mdb_get_state() == MDB_STATE_RUNNING) { 14067c478bd9Sstevel@tonic-gate mdb_warn("kgrep can only be run on a system " 14077c478bd9Sstevel@tonic-gate "dump or under kmdb; see dumpadm(1M)\n"); 14087c478bd9Sstevel@tonic-gate return (DCMD_ERR); 14097c478bd9Sstevel@tonic-gate } 14107c478bd9Sstevel@tonic-gate 14117c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("kas", &kas) == -1) { 14127c478bd9Sstevel@tonic-gate mdb_warn("failed to locate 'kas' symbol\n"); 14137c478bd9Sstevel@tonic-gate return (DCMD_ERR); 14147c478bd9Sstevel@tonic-gate } 14157c478bd9Sstevel@tonic-gate 14167c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("kvseg", &kvseg) == -1) { 14177c478bd9Sstevel@tonic-gate mdb_warn("failed to locate 'kvseg' symbol\n"); 14187c478bd9Sstevel@tonic-gate return (DCMD_ERR); 14197c478bd9Sstevel@tonic-gate } 14207c478bd9Sstevel@tonic-gate 14217c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("kvseg32", &kvseg32) == -1) { 14227c478bd9Sstevel@tonic-gate mdb_warn("failed to locate 'kvseg32' symbol\n"); 14237c478bd9Sstevel@tonic-gate return (DCMD_ERR); 14247c478bd9Sstevel@tonic-gate } 14257c478bd9Sstevel@tonic-gate 14267c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("kvseg_core", &kvseg_core) == -1) { 14277c478bd9Sstevel@tonic-gate mdb_warn("failed to locate 'kvseg_core' symbol\n"); 14287c478bd9Sstevel@tonic-gate return (DCMD_ERR); 14297c478bd9Sstevel@tonic-gate } 14307c478bd9Sstevel@tonic-gate 14317c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("segkpm_ops", &segkpm) == -1) { 14327c478bd9Sstevel@tonic-gate mdb_warn("failed to locate 'segkpm_ops' symbol\n"); 14337c478bd9Sstevel@tonic-gate return (DCMD_ERR); 14347c478bd9Sstevel@tonic-gate } 14357c478bd9Sstevel@tonic-gate 14367bc98a2eSeg if (mdb_readvar(&kg.kg_heap_lp_base, "heap_lp_base") == -1) { 14377bc98a2eSeg mdb_warn("failed to read 'heap_lp_base'\n"); 14387bc98a2eSeg return (DCMD_ERR); 14397bc98a2eSeg } 14407bc98a2eSeg 14417bc98a2eSeg if (mdb_readvar(&kg.kg_heap_lp_end, "heap_lp_end") == -1) { 14427bc98a2eSeg mdb_warn("failed to read 'heap_lp_end'\n"); 14437bc98a2eSeg return (DCMD_ERR); 14447bc98a2eSeg } 14457bc98a2eSeg 14467c478bd9Sstevel@tonic-gate kg.kg_cb = cb; 14477c478bd9Sstevel@tonic-gate kg.kg_cbdata = cbdata; 14487c478bd9Sstevel@tonic-gate kg.kg_kvseg = (uintptr_t)kvseg.st_value; 14497c478bd9Sstevel@tonic-gate kg.kg_kvseg32 = (uintptr_t)kvseg32.st_value; 14507c478bd9Sstevel@tonic-gate kg.kg_kvseg_core = (uintptr_t)kvseg_core.st_value; 14517c478bd9Sstevel@tonic-gate kg.kg_segkpm = (uintptr_t)segkpm.st_value; 14527c478bd9Sstevel@tonic-gate 14537c478bd9Sstevel@tonic-gate if (mdb_pwalk("seg", (mdb_walk_cb_t)kgrep_walk_seg, 14547c478bd9Sstevel@tonic-gate &kg, kas.st_value) == -1) { 14557c478bd9Sstevel@tonic-gate mdb_warn("failed to walk kas segments"); 14567c478bd9Sstevel@tonic-gate return (DCMD_ERR); 14577c478bd9Sstevel@tonic-gate } 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)kgrep_walk_vmem, &kg) == -1) { 14607c478bd9Sstevel@tonic-gate mdb_warn("failed to walk heap/heap32 vmem arenas"); 14617c478bd9Sstevel@tonic-gate return (DCMD_ERR); 14627c478bd9Sstevel@tonic-gate } 14637c478bd9Sstevel@tonic-gate 14647c478bd9Sstevel@tonic-gate return (DCMD_OK); 14657c478bd9Sstevel@tonic-gate } 14667c478bd9Sstevel@tonic-gate 14677c478bd9Sstevel@tonic-gate size_t 14687c478bd9Sstevel@tonic-gate kgrep_subr_pagesize(void) 14697c478bd9Sstevel@tonic-gate { 14707c478bd9Sstevel@tonic-gate return (PAGESIZE); 14717c478bd9Sstevel@tonic-gate } 14727c478bd9Sstevel@tonic-gate 14737c478bd9Sstevel@tonic-gate typedef struct file_walk_data { 14747c478bd9Sstevel@tonic-gate struct uf_entry *fw_flist; 14757c478bd9Sstevel@tonic-gate int fw_flistsz; 14767c478bd9Sstevel@tonic-gate int fw_ndx; 14777c478bd9Sstevel@tonic-gate int fw_nofiles; 14787c478bd9Sstevel@tonic-gate } file_walk_data_t; 14797c478bd9Sstevel@tonic-gate 14807c478bd9Sstevel@tonic-gate int 14817c478bd9Sstevel@tonic-gate file_walk_init(mdb_walk_state_t *wsp) 14827c478bd9Sstevel@tonic-gate { 14837c478bd9Sstevel@tonic-gate file_walk_data_t *fw; 14847c478bd9Sstevel@tonic-gate proc_t p; 14857c478bd9Sstevel@tonic-gate 14867c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 14877c478bd9Sstevel@tonic-gate mdb_warn("file walk doesn't support global walks\n"); 14887c478bd9Sstevel@tonic-gate return (WALK_ERR); 14897c478bd9Sstevel@tonic-gate } 14907c478bd9Sstevel@tonic-gate 14917c478bd9Sstevel@tonic-gate fw = mdb_alloc(sizeof (file_walk_data_t), UM_SLEEP); 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), wsp->walk_addr) == -1) { 14947c478bd9Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t)); 14957c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc structure at %p", wsp->walk_addr); 14967c478bd9Sstevel@tonic-gate return (WALK_ERR); 14977c478bd9Sstevel@tonic-gate } 14987c478bd9Sstevel@tonic-gate 14997c478bd9Sstevel@tonic-gate if (p.p_user.u_finfo.fi_nfiles == 0) { 15007c478bd9Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t)); 15017c478bd9Sstevel@tonic-gate return (WALK_DONE); 15027c478bd9Sstevel@tonic-gate } 15037c478bd9Sstevel@tonic-gate 15047c478bd9Sstevel@tonic-gate fw->fw_nofiles = p.p_user.u_finfo.fi_nfiles; 15057c478bd9Sstevel@tonic-gate fw->fw_flistsz = sizeof (struct uf_entry) * fw->fw_nofiles; 15067c478bd9Sstevel@tonic-gate fw->fw_flist = mdb_alloc(fw->fw_flistsz, UM_SLEEP); 15077c478bd9Sstevel@tonic-gate 15087c478bd9Sstevel@tonic-gate if (mdb_vread(fw->fw_flist, fw->fw_flistsz, 15097c478bd9Sstevel@tonic-gate (uintptr_t)p.p_user.u_finfo.fi_list) == -1) { 15107c478bd9Sstevel@tonic-gate mdb_warn("failed to read file array at %p", 15117c478bd9Sstevel@tonic-gate p.p_user.u_finfo.fi_list); 15127c478bd9Sstevel@tonic-gate mdb_free(fw->fw_flist, fw->fw_flistsz); 15137c478bd9Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t)); 15147c478bd9Sstevel@tonic-gate return (WALK_ERR); 15157c478bd9Sstevel@tonic-gate } 15167c478bd9Sstevel@tonic-gate 15177c478bd9Sstevel@tonic-gate fw->fw_ndx = 0; 15187c478bd9Sstevel@tonic-gate wsp->walk_data = fw; 15197c478bd9Sstevel@tonic-gate 15207c478bd9Sstevel@tonic-gate return (WALK_NEXT); 15217c478bd9Sstevel@tonic-gate } 15227c478bd9Sstevel@tonic-gate 15237c478bd9Sstevel@tonic-gate int 15247c478bd9Sstevel@tonic-gate file_walk_step(mdb_walk_state_t *wsp) 15257c478bd9Sstevel@tonic-gate { 15267c478bd9Sstevel@tonic-gate file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data; 15277c478bd9Sstevel@tonic-gate struct file file; 15287c478bd9Sstevel@tonic-gate uintptr_t fp; 15297c478bd9Sstevel@tonic-gate 15307c478bd9Sstevel@tonic-gate again: 15317c478bd9Sstevel@tonic-gate if (fw->fw_ndx == fw->fw_nofiles) 15327c478bd9Sstevel@tonic-gate return (WALK_DONE); 15337c478bd9Sstevel@tonic-gate 15347c478bd9Sstevel@tonic-gate if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) == NULL) 15357c478bd9Sstevel@tonic-gate goto again; 15367c478bd9Sstevel@tonic-gate 15377c478bd9Sstevel@tonic-gate (void) mdb_vread(&file, sizeof (file), (uintptr_t)fp); 15387c478bd9Sstevel@tonic-gate return (wsp->walk_callback(fp, &file, wsp->walk_cbdata)); 15397c478bd9Sstevel@tonic-gate } 15407c478bd9Sstevel@tonic-gate 15417c478bd9Sstevel@tonic-gate int 15427c478bd9Sstevel@tonic-gate allfile_walk_step(mdb_walk_state_t *wsp) 15437c478bd9Sstevel@tonic-gate { 15447c478bd9Sstevel@tonic-gate file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data; 15457c478bd9Sstevel@tonic-gate struct file file; 15467c478bd9Sstevel@tonic-gate uintptr_t fp; 15477c478bd9Sstevel@tonic-gate 15487c478bd9Sstevel@tonic-gate if (fw->fw_ndx == fw->fw_nofiles) 15497c478bd9Sstevel@tonic-gate return (WALK_DONE); 15507c478bd9Sstevel@tonic-gate 15517c478bd9Sstevel@tonic-gate if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) != NULL) 15527c478bd9Sstevel@tonic-gate (void) mdb_vread(&file, sizeof (file), (uintptr_t)fp); 15537c478bd9Sstevel@tonic-gate else 15547c478bd9Sstevel@tonic-gate bzero(&file, sizeof (file)); 15557c478bd9Sstevel@tonic-gate 15567c478bd9Sstevel@tonic-gate return (wsp->walk_callback(fp, &file, wsp->walk_cbdata)); 15577c478bd9Sstevel@tonic-gate } 15587c478bd9Sstevel@tonic-gate 15597c478bd9Sstevel@tonic-gate void 15607c478bd9Sstevel@tonic-gate file_walk_fini(mdb_walk_state_t *wsp) 15617c478bd9Sstevel@tonic-gate { 15627c478bd9Sstevel@tonic-gate file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data; 15637c478bd9Sstevel@tonic-gate 15647c478bd9Sstevel@tonic-gate mdb_free(fw->fw_flist, fw->fw_flistsz); 15657c478bd9Sstevel@tonic-gate mdb_free(fw, sizeof (file_walk_data_t)); 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate int 15697c478bd9Sstevel@tonic-gate port_walk_init(mdb_walk_state_t *wsp) 15707c478bd9Sstevel@tonic-gate { 15717c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 15727c478bd9Sstevel@tonic-gate mdb_warn("port walk doesn't support global walks\n"); 15737c478bd9Sstevel@tonic-gate return (WALK_ERR); 15747c478bd9Sstevel@tonic-gate } 15757c478bd9Sstevel@tonic-gate 15767c478bd9Sstevel@tonic-gate if (mdb_layered_walk("file", wsp) == -1) { 15777c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk 'file'"); 15787c478bd9Sstevel@tonic-gate return (WALK_ERR); 15797c478bd9Sstevel@tonic-gate } 15807c478bd9Sstevel@tonic-gate return (WALK_NEXT); 15817c478bd9Sstevel@tonic-gate } 15827c478bd9Sstevel@tonic-gate 15837c478bd9Sstevel@tonic-gate int 15847c478bd9Sstevel@tonic-gate port_walk_step(mdb_walk_state_t *wsp) 15857c478bd9Sstevel@tonic-gate { 15867c478bd9Sstevel@tonic-gate struct vnode vn; 15877c478bd9Sstevel@tonic-gate uintptr_t vp; 15887c478bd9Sstevel@tonic-gate uintptr_t pp; 15897c478bd9Sstevel@tonic-gate struct port port; 15907c478bd9Sstevel@tonic-gate 15917c478bd9Sstevel@tonic-gate vp = (uintptr_t)((struct file *)wsp->walk_layer)->f_vnode; 15927c478bd9Sstevel@tonic-gate if (mdb_vread(&vn, sizeof (vn), vp) == -1) { 15937c478bd9Sstevel@tonic-gate mdb_warn("failed to read vnode_t at %p", vp); 15947c478bd9Sstevel@tonic-gate return (WALK_ERR); 15957c478bd9Sstevel@tonic-gate } 15967c478bd9Sstevel@tonic-gate if (vn.v_type != VPORT) 15977c478bd9Sstevel@tonic-gate return (WALK_NEXT); 15987c478bd9Sstevel@tonic-gate 15997c478bd9Sstevel@tonic-gate pp = (uintptr_t)vn.v_data; 16007c478bd9Sstevel@tonic-gate if (mdb_vread(&port, sizeof (port), pp) == -1) { 16017c478bd9Sstevel@tonic-gate mdb_warn("failed to read port_t at %p", pp); 16027c478bd9Sstevel@tonic-gate return (WALK_ERR); 16037c478bd9Sstevel@tonic-gate } 16047c478bd9Sstevel@tonic-gate return (wsp->walk_callback(pp, &port, wsp->walk_cbdata)); 16057c478bd9Sstevel@tonic-gate } 16067c478bd9Sstevel@tonic-gate 16077c478bd9Sstevel@tonic-gate typedef struct portev_walk_data { 16087c478bd9Sstevel@tonic-gate list_node_t *pev_node; 16097c478bd9Sstevel@tonic-gate list_node_t *pev_last; 16107c478bd9Sstevel@tonic-gate size_t pev_offset; 16117c478bd9Sstevel@tonic-gate } portev_walk_data_t; 16127c478bd9Sstevel@tonic-gate 16137c478bd9Sstevel@tonic-gate int 16147c478bd9Sstevel@tonic-gate portev_walk_init(mdb_walk_state_t *wsp) 16157c478bd9Sstevel@tonic-gate { 16167c478bd9Sstevel@tonic-gate portev_walk_data_t *pevd; 16177c478bd9Sstevel@tonic-gate struct port port; 16187c478bd9Sstevel@tonic-gate struct vnode vn; 16197c478bd9Sstevel@tonic-gate struct list *list; 16207c478bd9Sstevel@tonic-gate uintptr_t vp; 16217c478bd9Sstevel@tonic-gate 16227c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 16237c478bd9Sstevel@tonic-gate mdb_warn("portev walk doesn't support global walks\n"); 16247c478bd9Sstevel@tonic-gate return (WALK_ERR); 16257c478bd9Sstevel@tonic-gate } 16267c478bd9Sstevel@tonic-gate 16277c478bd9Sstevel@tonic-gate pevd = mdb_alloc(sizeof (portev_walk_data_t), UM_SLEEP); 16287c478bd9Sstevel@tonic-gate 16297c478bd9Sstevel@tonic-gate if (mdb_vread(&port, sizeof (port), wsp->walk_addr) == -1) { 16307c478bd9Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t)); 16317c478bd9Sstevel@tonic-gate mdb_warn("failed to read port structure at %p", wsp->walk_addr); 16327c478bd9Sstevel@tonic-gate return (WALK_ERR); 16337c478bd9Sstevel@tonic-gate } 16347c478bd9Sstevel@tonic-gate 16357c478bd9Sstevel@tonic-gate vp = (uintptr_t)port.port_vnode; 16367c478bd9Sstevel@tonic-gate if (mdb_vread(&vn, sizeof (vn), vp) == -1) { 16377c478bd9Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t)); 16387c478bd9Sstevel@tonic-gate mdb_warn("failed to read vnode_t at %p", vp); 16397c478bd9Sstevel@tonic-gate return (WALK_ERR); 16407c478bd9Sstevel@tonic-gate } 16417c478bd9Sstevel@tonic-gate 16427c478bd9Sstevel@tonic-gate if (vn.v_type != VPORT) { 16437c478bd9Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t)); 16447c478bd9Sstevel@tonic-gate mdb_warn("input address (%p) does not point to an event port", 16457c478bd9Sstevel@tonic-gate wsp->walk_addr); 16467c478bd9Sstevel@tonic-gate return (WALK_ERR); 16477c478bd9Sstevel@tonic-gate } 16487c478bd9Sstevel@tonic-gate 16497c478bd9Sstevel@tonic-gate if (port.port_queue.portq_nent == 0) { 16507c478bd9Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t)); 16517c478bd9Sstevel@tonic-gate return (WALK_DONE); 16527c478bd9Sstevel@tonic-gate } 16537c478bd9Sstevel@tonic-gate list = &port.port_queue.portq_list; 16547c478bd9Sstevel@tonic-gate pevd->pev_offset = list->list_offset; 16557c478bd9Sstevel@tonic-gate pevd->pev_last = list->list_head.list_prev; 16567c478bd9Sstevel@tonic-gate pevd->pev_node = list->list_head.list_next; 16577c478bd9Sstevel@tonic-gate wsp->walk_data = pevd; 16587c478bd9Sstevel@tonic-gate return (WALK_NEXT); 16597c478bd9Sstevel@tonic-gate } 16607c478bd9Sstevel@tonic-gate 16617c478bd9Sstevel@tonic-gate int 16627c478bd9Sstevel@tonic-gate portev_walk_step(mdb_walk_state_t *wsp) 16637c478bd9Sstevel@tonic-gate { 16647c478bd9Sstevel@tonic-gate portev_walk_data_t *pevd; 16657c478bd9Sstevel@tonic-gate struct port_kevent ev; 16667c478bd9Sstevel@tonic-gate uintptr_t evp; 16677c478bd9Sstevel@tonic-gate 16687c478bd9Sstevel@tonic-gate pevd = (portev_walk_data_t *)wsp->walk_data; 16697c478bd9Sstevel@tonic-gate 16707c478bd9Sstevel@tonic-gate if (pevd->pev_last == NULL) 16717c478bd9Sstevel@tonic-gate return (WALK_DONE); 16727c478bd9Sstevel@tonic-gate if (pevd->pev_node == pevd->pev_last) 16737c478bd9Sstevel@tonic-gate pevd->pev_last = NULL; /* last round */ 16747c478bd9Sstevel@tonic-gate 16757c478bd9Sstevel@tonic-gate evp = ((uintptr_t)(((char *)pevd->pev_node) - pevd->pev_offset)); 16767c478bd9Sstevel@tonic-gate if (mdb_vread(&ev, sizeof (ev), evp) == -1) { 16777c478bd9Sstevel@tonic-gate mdb_warn("failed to read port_kevent at %p", evp); 16787c478bd9Sstevel@tonic-gate return (WALK_DONE); 16797c478bd9Sstevel@tonic-gate } 16807c478bd9Sstevel@tonic-gate pevd->pev_node = ev.portkev_node.list_next; 16817c478bd9Sstevel@tonic-gate return (wsp->walk_callback(evp, &ev, wsp->walk_cbdata)); 16827c478bd9Sstevel@tonic-gate } 16837c478bd9Sstevel@tonic-gate 16847c478bd9Sstevel@tonic-gate void 16857c478bd9Sstevel@tonic-gate portev_walk_fini(mdb_walk_state_t *wsp) 16867c478bd9Sstevel@tonic-gate { 16877c478bd9Sstevel@tonic-gate portev_walk_data_t *pevd = (portev_walk_data_t *)wsp->walk_data; 16887c478bd9Sstevel@tonic-gate 16897c478bd9Sstevel@tonic-gate if (pevd != NULL) 16907c478bd9Sstevel@tonic-gate mdb_free(pevd, sizeof (portev_walk_data_t)); 16917c478bd9Sstevel@tonic-gate } 16927c478bd9Sstevel@tonic-gate 16937c478bd9Sstevel@tonic-gate typedef struct proc_walk_data { 16947c478bd9Sstevel@tonic-gate uintptr_t *pw_stack; 16957c478bd9Sstevel@tonic-gate int pw_depth; 16967c478bd9Sstevel@tonic-gate int pw_max; 16977c478bd9Sstevel@tonic-gate } proc_walk_data_t; 16987c478bd9Sstevel@tonic-gate 16997c478bd9Sstevel@tonic-gate int 17007c478bd9Sstevel@tonic-gate proc_walk_init(mdb_walk_state_t *wsp) 17017c478bd9Sstevel@tonic-gate { 17027c478bd9Sstevel@tonic-gate GElf_Sym sym; 17037c478bd9Sstevel@tonic-gate proc_walk_data_t *pw; 17047c478bd9Sstevel@tonic-gate 17057c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 17067c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("p0", &sym) == -1) { 17077c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'practive'"); 17087c478bd9Sstevel@tonic-gate return (WALK_ERR); 17097c478bd9Sstevel@tonic-gate } 17107c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)sym.st_value; 17117c478bd9Sstevel@tonic-gate } 17127c478bd9Sstevel@tonic-gate 17137c478bd9Sstevel@tonic-gate pw = mdb_zalloc(sizeof (proc_walk_data_t), UM_SLEEP); 17147c478bd9Sstevel@tonic-gate 17157c478bd9Sstevel@tonic-gate if (mdb_readvar(&pw->pw_max, "nproc") == -1) { 17167c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'nproc'"); 17177c478bd9Sstevel@tonic-gate mdb_free(pw, sizeof (pw)); 17187c478bd9Sstevel@tonic-gate return (WALK_ERR); 17197c478bd9Sstevel@tonic-gate } 17207c478bd9Sstevel@tonic-gate 17217c478bd9Sstevel@tonic-gate pw->pw_stack = mdb_alloc(pw->pw_max * sizeof (uintptr_t), UM_SLEEP); 17227c478bd9Sstevel@tonic-gate wsp->walk_data = pw; 17237c478bd9Sstevel@tonic-gate 17247c478bd9Sstevel@tonic-gate return (WALK_NEXT); 17257c478bd9Sstevel@tonic-gate } 17267c478bd9Sstevel@tonic-gate 17277c478bd9Sstevel@tonic-gate int 17287c478bd9Sstevel@tonic-gate proc_walk_step(mdb_walk_state_t *wsp) 17297c478bd9Sstevel@tonic-gate { 17307c478bd9Sstevel@tonic-gate proc_walk_data_t *pw = wsp->walk_data; 17317c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 17327c478bd9Sstevel@tonic-gate uintptr_t cld, sib; 17337c478bd9Sstevel@tonic-gate 17347c478bd9Sstevel@tonic-gate int status; 17357c478bd9Sstevel@tonic-gate proc_t pr; 17367c478bd9Sstevel@tonic-gate 17377c478bd9Sstevel@tonic-gate if (mdb_vread(&pr, sizeof (proc_t), addr) == -1) { 17387c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc at %p", addr); 17397c478bd9Sstevel@tonic-gate return (WALK_DONE); 17407c478bd9Sstevel@tonic-gate } 17417c478bd9Sstevel@tonic-gate 17427c478bd9Sstevel@tonic-gate cld = (uintptr_t)pr.p_child; 17437c478bd9Sstevel@tonic-gate sib = (uintptr_t)pr.p_sibling; 17447c478bd9Sstevel@tonic-gate 17457c478bd9Sstevel@tonic-gate if (pw->pw_depth > 0 && addr == pw->pw_stack[pw->pw_depth - 1]) { 17467c478bd9Sstevel@tonic-gate pw->pw_depth--; 17477c478bd9Sstevel@tonic-gate goto sib; 17487c478bd9Sstevel@tonic-gate } 17497c478bd9Sstevel@tonic-gate 17507c478bd9Sstevel@tonic-gate status = wsp->walk_callback(addr, &pr, wsp->walk_cbdata); 17517c478bd9Sstevel@tonic-gate 17527c478bd9Sstevel@tonic-gate if (status != WALK_NEXT) 17537c478bd9Sstevel@tonic-gate return (status); 17547c478bd9Sstevel@tonic-gate 17557c478bd9Sstevel@tonic-gate if ((wsp->walk_addr = cld) != NULL) { 17567c478bd9Sstevel@tonic-gate if (mdb_vread(&pr, sizeof (proc_t), cld) == -1) { 17577c478bd9Sstevel@tonic-gate mdb_warn("proc %p has invalid p_child %p; skipping\n", 17587c478bd9Sstevel@tonic-gate addr, cld); 17597c478bd9Sstevel@tonic-gate goto sib; 17607c478bd9Sstevel@tonic-gate } 17617c478bd9Sstevel@tonic-gate 17627c478bd9Sstevel@tonic-gate pw->pw_stack[pw->pw_depth++] = addr; 17637c478bd9Sstevel@tonic-gate 17647c478bd9Sstevel@tonic-gate if (pw->pw_depth == pw->pw_max) { 17657c478bd9Sstevel@tonic-gate mdb_warn("depth %d exceeds max depth; try again\n", 17667c478bd9Sstevel@tonic-gate pw->pw_depth); 17677c478bd9Sstevel@tonic-gate return (WALK_DONE); 17687c478bd9Sstevel@tonic-gate } 17697c478bd9Sstevel@tonic-gate return (WALK_NEXT); 17707c478bd9Sstevel@tonic-gate } 17717c478bd9Sstevel@tonic-gate 17727c478bd9Sstevel@tonic-gate sib: 17737c478bd9Sstevel@tonic-gate /* 17747c478bd9Sstevel@tonic-gate * We know that p0 has no siblings, and if another starting proc 17757c478bd9Sstevel@tonic-gate * was given, we don't want to walk its siblings anyway. 17767c478bd9Sstevel@tonic-gate */ 17777c478bd9Sstevel@tonic-gate if (pw->pw_depth == 0) 17787c478bd9Sstevel@tonic-gate return (WALK_DONE); 17797c478bd9Sstevel@tonic-gate 17807c478bd9Sstevel@tonic-gate if (sib != NULL && mdb_vread(&pr, sizeof (proc_t), sib) == -1) { 17817c478bd9Sstevel@tonic-gate mdb_warn("proc %p has invalid p_sibling %p; skipping\n", 17827c478bd9Sstevel@tonic-gate addr, sib); 17837c478bd9Sstevel@tonic-gate sib = NULL; 17847c478bd9Sstevel@tonic-gate } 17857c478bd9Sstevel@tonic-gate 17867c478bd9Sstevel@tonic-gate if ((wsp->walk_addr = sib) == NULL) { 17877c478bd9Sstevel@tonic-gate if (pw->pw_depth > 0) { 17887c478bd9Sstevel@tonic-gate wsp->walk_addr = pw->pw_stack[pw->pw_depth - 1]; 17897c478bd9Sstevel@tonic-gate return (WALK_NEXT); 17907c478bd9Sstevel@tonic-gate } 17917c478bd9Sstevel@tonic-gate return (WALK_DONE); 17927c478bd9Sstevel@tonic-gate } 17937c478bd9Sstevel@tonic-gate 17947c478bd9Sstevel@tonic-gate return (WALK_NEXT); 17957c478bd9Sstevel@tonic-gate } 17967c478bd9Sstevel@tonic-gate 17977c478bd9Sstevel@tonic-gate void 17987c478bd9Sstevel@tonic-gate proc_walk_fini(mdb_walk_state_t *wsp) 17997c478bd9Sstevel@tonic-gate { 18007c478bd9Sstevel@tonic-gate proc_walk_data_t *pw = wsp->walk_data; 18017c478bd9Sstevel@tonic-gate 18027c478bd9Sstevel@tonic-gate mdb_free(pw->pw_stack, pw->pw_max * sizeof (uintptr_t)); 18037c478bd9Sstevel@tonic-gate mdb_free(pw, sizeof (proc_walk_data_t)); 18047c478bd9Sstevel@tonic-gate } 18057c478bd9Sstevel@tonic-gate 18067c478bd9Sstevel@tonic-gate int 18077c478bd9Sstevel@tonic-gate task_walk_init(mdb_walk_state_t *wsp) 18087c478bd9Sstevel@tonic-gate { 18097c478bd9Sstevel@tonic-gate task_t task; 18107c478bd9Sstevel@tonic-gate 18117c478bd9Sstevel@tonic-gate if (mdb_vread(&task, sizeof (task_t), wsp->walk_addr) == -1) { 18127c478bd9Sstevel@tonic-gate mdb_warn("failed to read task at %p", wsp->walk_addr); 18137c478bd9Sstevel@tonic-gate return (WALK_ERR); 18147c478bd9Sstevel@tonic-gate } 18157c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)task.tk_memb_list; 18167c478bd9Sstevel@tonic-gate wsp->walk_data = task.tk_memb_list; 18177c478bd9Sstevel@tonic-gate return (WALK_NEXT); 18187c478bd9Sstevel@tonic-gate } 18197c478bd9Sstevel@tonic-gate 18207c478bd9Sstevel@tonic-gate int 18217c478bd9Sstevel@tonic-gate task_walk_step(mdb_walk_state_t *wsp) 18227c478bd9Sstevel@tonic-gate { 18237c478bd9Sstevel@tonic-gate proc_t proc; 18247c478bd9Sstevel@tonic-gate int status; 18257c478bd9Sstevel@tonic-gate 18267c478bd9Sstevel@tonic-gate if (mdb_vread(&proc, sizeof (proc_t), wsp->walk_addr) == -1) { 18277c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc at %p", wsp->walk_addr); 18287c478bd9Sstevel@tonic-gate return (WALK_DONE); 18297c478bd9Sstevel@tonic-gate } 18307c478bd9Sstevel@tonic-gate 18317c478bd9Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata); 18327c478bd9Sstevel@tonic-gate 18337c478bd9Sstevel@tonic-gate if (proc.p_tasknext == wsp->walk_data) 18347c478bd9Sstevel@tonic-gate return (WALK_DONE); 18357c478bd9Sstevel@tonic-gate 18367c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)proc.p_tasknext; 18377c478bd9Sstevel@tonic-gate return (status); 18387c478bd9Sstevel@tonic-gate } 18397c478bd9Sstevel@tonic-gate 18407c478bd9Sstevel@tonic-gate int 18417c478bd9Sstevel@tonic-gate project_walk_init(mdb_walk_state_t *wsp) 18427c478bd9Sstevel@tonic-gate { 18437c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 18447c478bd9Sstevel@tonic-gate if (mdb_readvar(&wsp->walk_addr, "proj0p") == -1) { 18457c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'proj0p'"); 18467c478bd9Sstevel@tonic-gate return (WALK_ERR); 18477c478bd9Sstevel@tonic-gate } 18487c478bd9Sstevel@tonic-gate } 18497c478bd9Sstevel@tonic-gate wsp->walk_data = (void *)wsp->walk_addr; 18507c478bd9Sstevel@tonic-gate return (WALK_NEXT); 18517c478bd9Sstevel@tonic-gate } 18527c478bd9Sstevel@tonic-gate 18537c478bd9Sstevel@tonic-gate int 18547c478bd9Sstevel@tonic-gate project_walk_step(mdb_walk_state_t *wsp) 18557c478bd9Sstevel@tonic-gate { 18567c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 18577c478bd9Sstevel@tonic-gate kproject_t pj; 18587c478bd9Sstevel@tonic-gate int status; 18597c478bd9Sstevel@tonic-gate 18607c478bd9Sstevel@tonic-gate if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) { 18617c478bd9Sstevel@tonic-gate mdb_warn("failed to read project at %p", addr); 18627c478bd9Sstevel@tonic-gate return (WALK_DONE); 18637c478bd9Sstevel@tonic-gate } 18647c478bd9Sstevel@tonic-gate status = wsp->walk_callback(addr, &pj, wsp->walk_cbdata); 18657c478bd9Sstevel@tonic-gate if (status != WALK_NEXT) 18667c478bd9Sstevel@tonic-gate return (status); 18677c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)pj.kpj_next; 18687c478bd9Sstevel@tonic-gate if ((void *)wsp->walk_addr == wsp->walk_data) 18697c478bd9Sstevel@tonic-gate return (WALK_DONE); 18707c478bd9Sstevel@tonic-gate return (WALK_NEXT); 18717c478bd9Sstevel@tonic-gate } 18727c478bd9Sstevel@tonic-gate 18737c478bd9Sstevel@tonic-gate static int 18747c478bd9Sstevel@tonic-gate generic_walk_step(mdb_walk_state_t *wsp) 18757c478bd9Sstevel@tonic-gate { 18767c478bd9Sstevel@tonic-gate return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer, 18777c478bd9Sstevel@tonic-gate wsp->walk_cbdata)); 18787c478bd9Sstevel@tonic-gate } 18797c478bd9Sstevel@tonic-gate 18807c478bd9Sstevel@tonic-gate int 18817c478bd9Sstevel@tonic-gate seg_walk_init(mdb_walk_state_t *wsp) 18827c478bd9Sstevel@tonic-gate { 18837c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 18847c478bd9Sstevel@tonic-gate mdb_warn("seg walk must begin at struct as *\n"); 18857c478bd9Sstevel@tonic-gate return (WALK_ERR); 18867c478bd9Sstevel@tonic-gate } 18877c478bd9Sstevel@tonic-gate 18887c478bd9Sstevel@tonic-gate /* 18897c478bd9Sstevel@tonic-gate * this is really just a wrapper to AVL tree walk 18907c478bd9Sstevel@tonic-gate */ 18917c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)&((struct as *)wsp->walk_addr)->a_segtree; 18927c478bd9Sstevel@tonic-gate return (avl_walk_init(wsp)); 18937c478bd9Sstevel@tonic-gate } 18947c478bd9Sstevel@tonic-gate 18957c478bd9Sstevel@tonic-gate static int 18967c478bd9Sstevel@tonic-gate cpu_walk_cmp(const void *l, const void *r) 18977c478bd9Sstevel@tonic-gate { 18987c478bd9Sstevel@tonic-gate uintptr_t lhs = *((uintptr_t *)l); 18997c478bd9Sstevel@tonic-gate uintptr_t rhs = *((uintptr_t *)r); 19007c478bd9Sstevel@tonic-gate cpu_t lcpu, rcpu; 19017c478bd9Sstevel@tonic-gate 19027c478bd9Sstevel@tonic-gate (void) mdb_vread(&lcpu, sizeof (lcpu), lhs); 19037c478bd9Sstevel@tonic-gate (void) mdb_vread(&rcpu, sizeof (rcpu), rhs); 19047c478bd9Sstevel@tonic-gate 19057c478bd9Sstevel@tonic-gate if (lcpu.cpu_id < rcpu.cpu_id) 19067c478bd9Sstevel@tonic-gate return (-1); 19077c478bd9Sstevel@tonic-gate 19087c478bd9Sstevel@tonic-gate if (lcpu.cpu_id > rcpu.cpu_id) 19097c478bd9Sstevel@tonic-gate return (1); 19107c478bd9Sstevel@tonic-gate 19117c478bd9Sstevel@tonic-gate return (0); 19127c478bd9Sstevel@tonic-gate } 19137c478bd9Sstevel@tonic-gate 19147c478bd9Sstevel@tonic-gate typedef struct cpu_walk { 19157c478bd9Sstevel@tonic-gate uintptr_t *cw_array; 19167c478bd9Sstevel@tonic-gate int cw_ndx; 19177c478bd9Sstevel@tonic-gate } cpu_walk_t; 19187c478bd9Sstevel@tonic-gate 19197c478bd9Sstevel@tonic-gate int 19207c478bd9Sstevel@tonic-gate cpu_walk_init(mdb_walk_state_t *wsp) 19217c478bd9Sstevel@tonic-gate { 19227c478bd9Sstevel@tonic-gate cpu_walk_t *cw; 19237c478bd9Sstevel@tonic-gate int max_ncpus, i = 0; 19247c478bd9Sstevel@tonic-gate uintptr_t current, first; 19257c478bd9Sstevel@tonic-gate cpu_t cpu, panic_cpu; 19267c478bd9Sstevel@tonic-gate uintptr_t panicstr, addr; 19277c478bd9Sstevel@tonic-gate GElf_Sym sym; 19287c478bd9Sstevel@tonic-gate 19297c478bd9Sstevel@tonic-gate cw = mdb_zalloc(sizeof (cpu_walk_t), UM_SLEEP | UM_GC); 19307c478bd9Sstevel@tonic-gate 19317c478bd9Sstevel@tonic-gate if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) { 19327c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'max_ncpus'"); 19337c478bd9Sstevel@tonic-gate return (WALK_ERR); 19347c478bd9Sstevel@tonic-gate } 19357c478bd9Sstevel@tonic-gate 19367c478bd9Sstevel@tonic-gate if (mdb_readvar(&panicstr, "panicstr") == -1) { 19377c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'panicstr'"); 19387c478bd9Sstevel@tonic-gate return (WALK_ERR); 19397c478bd9Sstevel@tonic-gate } 19407c478bd9Sstevel@tonic-gate 19417c478bd9Sstevel@tonic-gate if (panicstr != NULL) { 19427c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("panic_cpu", &sym) == -1) { 19437c478bd9Sstevel@tonic-gate mdb_warn("failed to find 'panic_cpu'"); 19447c478bd9Sstevel@tonic-gate return (WALK_ERR); 19457c478bd9Sstevel@tonic-gate } 19467c478bd9Sstevel@tonic-gate 19477c478bd9Sstevel@tonic-gate addr = (uintptr_t)sym.st_value; 19487c478bd9Sstevel@tonic-gate 19497c478bd9Sstevel@tonic-gate if (mdb_vread(&panic_cpu, sizeof (cpu_t), addr) == -1) { 19507c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'panic_cpu'"); 19517c478bd9Sstevel@tonic-gate return (WALK_ERR); 19527c478bd9Sstevel@tonic-gate } 19537c478bd9Sstevel@tonic-gate } 19547c478bd9Sstevel@tonic-gate 19557c478bd9Sstevel@tonic-gate /* 19567c478bd9Sstevel@tonic-gate * Unfortunately, there is no platform-independent way to walk 19577c478bd9Sstevel@tonic-gate * CPUs in ID order. We therefore loop through in cpu_next order, 19587c478bd9Sstevel@tonic-gate * building an array of CPU pointers which will subsequently be 19597c478bd9Sstevel@tonic-gate * sorted. 19607c478bd9Sstevel@tonic-gate */ 19617c478bd9Sstevel@tonic-gate cw->cw_array = 19627c478bd9Sstevel@tonic-gate mdb_zalloc((max_ncpus + 1) * sizeof (uintptr_t), UM_SLEEP | UM_GC); 19637c478bd9Sstevel@tonic-gate 19647c478bd9Sstevel@tonic-gate if (mdb_readvar(&first, "cpu_list") == -1) { 19657c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'cpu_list'"); 19667c478bd9Sstevel@tonic-gate return (WALK_ERR); 19677c478bd9Sstevel@tonic-gate } 19687c478bd9Sstevel@tonic-gate 19697c478bd9Sstevel@tonic-gate current = first; 19707c478bd9Sstevel@tonic-gate do { 19717c478bd9Sstevel@tonic-gate if (mdb_vread(&cpu, sizeof (cpu), current) == -1) { 19727c478bd9Sstevel@tonic-gate mdb_warn("failed to read cpu at %p", current); 19737c478bd9Sstevel@tonic-gate return (WALK_ERR); 19747c478bd9Sstevel@tonic-gate } 19757c478bd9Sstevel@tonic-gate 19767c478bd9Sstevel@tonic-gate if (panicstr != NULL && panic_cpu.cpu_id == cpu.cpu_id) { 19777c478bd9Sstevel@tonic-gate cw->cw_array[i++] = addr; 19787c478bd9Sstevel@tonic-gate } else { 19797c478bd9Sstevel@tonic-gate cw->cw_array[i++] = current; 19807c478bd9Sstevel@tonic-gate } 19817c478bd9Sstevel@tonic-gate } while ((current = (uintptr_t)cpu.cpu_next) != first); 19827c478bd9Sstevel@tonic-gate 19837c478bd9Sstevel@tonic-gate qsort(cw->cw_array, i, sizeof (uintptr_t), cpu_walk_cmp); 19847c478bd9Sstevel@tonic-gate wsp->walk_data = cw; 19857c478bd9Sstevel@tonic-gate 19867c478bd9Sstevel@tonic-gate return (WALK_NEXT); 19877c478bd9Sstevel@tonic-gate } 19887c478bd9Sstevel@tonic-gate 19897c478bd9Sstevel@tonic-gate int 19907c478bd9Sstevel@tonic-gate cpu_walk_step(mdb_walk_state_t *wsp) 19917c478bd9Sstevel@tonic-gate { 19927c478bd9Sstevel@tonic-gate cpu_walk_t *cw = wsp->walk_data; 19937c478bd9Sstevel@tonic-gate cpu_t cpu; 19947c478bd9Sstevel@tonic-gate uintptr_t addr = cw->cw_array[cw->cw_ndx++]; 19957c478bd9Sstevel@tonic-gate 19967c478bd9Sstevel@tonic-gate if (addr == NULL) 19977c478bd9Sstevel@tonic-gate return (WALK_DONE); 19987c478bd9Sstevel@tonic-gate 19997c478bd9Sstevel@tonic-gate if (mdb_vread(&cpu, sizeof (cpu), addr) == -1) { 20007c478bd9Sstevel@tonic-gate mdb_warn("failed to read cpu at %p", addr); 20017c478bd9Sstevel@tonic-gate return (WALK_DONE); 20027c478bd9Sstevel@tonic-gate } 20037c478bd9Sstevel@tonic-gate 20047c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, &cpu, wsp->walk_cbdata)); 20057c478bd9Sstevel@tonic-gate } 20067c478bd9Sstevel@tonic-gate 20077c478bd9Sstevel@tonic-gate typedef struct cpuinfo_data { 20087c478bd9Sstevel@tonic-gate intptr_t cid_cpu; 20097c478bd9Sstevel@tonic-gate uintptr_t cid_lbolt; 20107c478bd9Sstevel@tonic-gate uintptr_t **cid_ithr; 20117c478bd9Sstevel@tonic-gate char cid_print_head; 20127c478bd9Sstevel@tonic-gate char cid_print_thr; 20137c478bd9Sstevel@tonic-gate char cid_print_ithr; 20147c478bd9Sstevel@tonic-gate char cid_print_flags; 20157c478bd9Sstevel@tonic-gate } cpuinfo_data_t; 20167c478bd9Sstevel@tonic-gate 20177c478bd9Sstevel@tonic-gate int 20187c478bd9Sstevel@tonic-gate cpuinfo_walk_ithread(uintptr_t addr, const kthread_t *thr, cpuinfo_data_t *cid) 20197c478bd9Sstevel@tonic-gate { 20207c478bd9Sstevel@tonic-gate cpu_t c; 20217c478bd9Sstevel@tonic-gate int id; 20227c478bd9Sstevel@tonic-gate uint8_t pil; 20237c478bd9Sstevel@tonic-gate 20247c478bd9Sstevel@tonic-gate if (!(thr->t_flag & T_INTR_THREAD) || thr->t_state == TS_FREE) 20257c478bd9Sstevel@tonic-gate return (WALK_NEXT); 20267c478bd9Sstevel@tonic-gate 20277c478bd9Sstevel@tonic-gate if (thr->t_bound_cpu == NULL) { 20287c478bd9Sstevel@tonic-gate mdb_warn("thr %p is intr thread w/out a CPU\n", addr); 20297c478bd9Sstevel@tonic-gate return (WALK_NEXT); 20307c478bd9Sstevel@tonic-gate } 20317c478bd9Sstevel@tonic-gate 20327c478bd9Sstevel@tonic-gate (void) mdb_vread(&c, sizeof (c), (uintptr_t)thr->t_bound_cpu); 20337c478bd9Sstevel@tonic-gate 20347c478bd9Sstevel@tonic-gate if ((id = c.cpu_id) >= NCPU) { 20357c478bd9Sstevel@tonic-gate mdb_warn("CPU %p has id (%d) greater than NCPU (%d)\n", 20367c478bd9Sstevel@tonic-gate thr->t_bound_cpu, id, NCPU); 20377c478bd9Sstevel@tonic-gate return (WALK_NEXT); 20387c478bd9Sstevel@tonic-gate } 20397c478bd9Sstevel@tonic-gate 20407c478bd9Sstevel@tonic-gate if ((pil = thr->t_pil) >= NINTR) { 20417c478bd9Sstevel@tonic-gate mdb_warn("thread %p has pil (%d) greater than %d\n", 20427c478bd9Sstevel@tonic-gate addr, pil, NINTR); 20437c478bd9Sstevel@tonic-gate return (WALK_NEXT); 20447c478bd9Sstevel@tonic-gate } 20457c478bd9Sstevel@tonic-gate 20467c478bd9Sstevel@tonic-gate if (cid->cid_ithr[id][pil] != NULL) { 20477c478bd9Sstevel@tonic-gate mdb_warn("CPU %d has multiple threads at pil %d (at least " 20487c478bd9Sstevel@tonic-gate "%p and %p)\n", id, pil, addr, cid->cid_ithr[id][pil]); 20497c478bd9Sstevel@tonic-gate return (WALK_NEXT); 20507c478bd9Sstevel@tonic-gate } 20517c478bd9Sstevel@tonic-gate 20527c478bd9Sstevel@tonic-gate cid->cid_ithr[id][pil] = addr; 20537c478bd9Sstevel@tonic-gate 20547c478bd9Sstevel@tonic-gate return (WALK_NEXT); 20557c478bd9Sstevel@tonic-gate } 20567c478bd9Sstevel@tonic-gate 20577c478bd9Sstevel@tonic-gate #define CPUINFO_IDWIDTH 3 20587c478bd9Sstevel@tonic-gate #define CPUINFO_FLAGWIDTH 9 20597c478bd9Sstevel@tonic-gate 20607c478bd9Sstevel@tonic-gate #ifdef _LP64 2061f5533078Smishra #if defined(__amd64) 2062f5533078Smishra #define CPUINFO_TWIDTH 16 2063f5533078Smishra #define CPUINFO_CPUWIDTH 16 2064f5533078Smishra #else 20657c478bd9Sstevel@tonic-gate #define CPUINFO_CPUWIDTH 11 20667c478bd9Sstevel@tonic-gate #define CPUINFO_TWIDTH 11 2067f5533078Smishra #endif 20687c478bd9Sstevel@tonic-gate #else 20697c478bd9Sstevel@tonic-gate #define CPUINFO_CPUWIDTH 8 20707c478bd9Sstevel@tonic-gate #define CPUINFO_TWIDTH 8 20717c478bd9Sstevel@tonic-gate #endif 20727c478bd9Sstevel@tonic-gate 20737c478bd9Sstevel@tonic-gate #define CPUINFO_THRDELT (CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 9) 20747c478bd9Sstevel@tonic-gate #define CPUINFO_FLAGDELT (CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 4) 20757c478bd9Sstevel@tonic-gate #define CPUINFO_ITHRDELT 4 20767c478bd9Sstevel@tonic-gate 20777c478bd9Sstevel@tonic-gate #define CPUINFO_INDENT mdb_printf("%*s", CPUINFO_THRDELT, \ 20787c478bd9Sstevel@tonic-gate flagline < nflaglines ? flagbuf[flagline++] : "") 20797c478bd9Sstevel@tonic-gate 20807c478bd9Sstevel@tonic-gate int 20817c478bd9Sstevel@tonic-gate cpuinfo_walk_cpu(uintptr_t addr, const cpu_t *cpu, cpuinfo_data_t *cid) 20827c478bd9Sstevel@tonic-gate { 20837c478bd9Sstevel@tonic-gate kthread_t t; 20847c478bd9Sstevel@tonic-gate disp_t disp; 20857c478bd9Sstevel@tonic-gate proc_t p; 20867c478bd9Sstevel@tonic-gate uintptr_t pinned; 20877c478bd9Sstevel@tonic-gate char **flagbuf; 20887c478bd9Sstevel@tonic-gate int nflaglines = 0, flagline = 0, bspl, rval = WALK_NEXT; 20897c478bd9Sstevel@tonic-gate 20907c478bd9Sstevel@tonic-gate const char *flags[] = { 20917c478bd9Sstevel@tonic-gate "RUNNING", "READY", "QUIESCED", "EXISTS", 20927c478bd9Sstevel@tonic-gate "ENABLE", "OFFLINE", "POWEROFF", "FROZEN", 20937c478bd9Sstevel@tonic-gate "SPARE", "FAULTED", NULL 20947c478bd9Sstevel@tonic-gate }; 20957c478bd9Sstevel@tonic-gate 20967c478bd9Sstevel@tonic-gate if (cid->cid_cpu != -1) { 20977c478bd9Sstevel@tonic-gate if (addr != cid->cid_cpu && cpu->cpu_id != cid->cid_cpu) 20987c478bd9Sstevel@tonic-gate return (WALK_NEXT); 20997c478bd9Sstevel@tonic-gate 21007c478bd9Sstevel@tonic-gate /* 21017c478bd9Sstevel@tonic-gate * Set cid_cpu to -1 to indicate that we found a matching CPU. 21027c478bd9Sstevel@tonic-gate */ 21037c478bd9Sstevel@tonic-gate cid->cid_cpu = -1; 21047c478bd9Sstevel@tonic-gate rval = WALK_DONE; 21057c478bd9Sstevel@tonic-gate } 21067c478bd9Sstevel@tonic-gate 21077c478bd9Sstevel@tonic-gate if (cid->cid_print_head) { 21087c478bd9Sstevel@tonic-gate mdb_printf("%3s %-*s %3s %4s %4s %3s %4s %5s %-6s %-*s %s\n", 21097c478bd9Sstevel@tonic-gate "ID", CPUINFO_CPUWIDTH, "ADDR", "FLG", "NRUN", "BSPL", 21107c478bd9Sstevel@tonic-gate "PRI", "RNRN", "KRNRN", "SWITCH", CPUINFO_TWIDTH, "THREAD", 21117c478bd9Sstevel@tonic-gate "PROC"); 21127c478bd9Sstevel@tonic-gate cid->cid_print_head = FALSE; 21137c478bd9Sstevel@tonic-gate } 21147c478bd9Sstevel@tonic-gate 21157c478bd9Sstevel@tonic-gate bspl = cpu->cpu_base_spl; 21167c478bd9Sstevel@tonic-gate 21177c478bd9Sstevel@tonic-gate if (mdb_vread(&disp, sizeof (disp_t), (uintptr_t)cpu->cpu_disp) == -1) { 21187c478bd9Sstevel@tonic-gate mdb_warn("failed to read disp_t at %p", cpu->cpu_disp); 21197c478bd9Sstevel@tonic-gate return (WALK_ERR); 21207c478bd9Sstevel@tonic-gate } 21217c478bd9Sstevel@tonic-gate 21227c478bd9Sstevel@tonic-gate mdb_printf("%3d %0*p %3x %4d %4d ", 21237c478bd9Sstevel@tonic-gate cpu->cpu_id, CPUINFO_CPUWIDTH, addr, cpu->cpu_flags, 21247c478bd9Sstevel@tonic-gate disp.disp_nrunnable, bspl); 21257c478bd9Sstevel@tonic-gate 21267c478bd9Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), (uintptr_t)cpu->cpu_thread) != -1) { 21277c478bd9Sstevel@tonic-gate mdb_printf("%3d ", t.t_pri); 21287c478bd9Sstevel@tonic-gate } else { 21297c478bd9Sstevel@tonic-gate mdb_printf("%3s ", "-"); 21307c478bd9Sstevel@tonic-gate } 21317c478bd9Sstevel@tonic-gate 21327c478bd9Sstevel@tonic-gate mdb_printf("%4s %5s ", cpu->cpu_runrun ? "yes" : "no", 21337c478bd9Sstevel@tonic-gate cpu->cpu_kprunrun ? "yes" : "no"); 21347c478bd9Sstevel@tonic-gate 21357c478bd9Sstevel@tonic-gate if (cpu->cpu_last_swtch) { 21367c478bd9Sstevel@tonic-gate clock_t lbolt; 21377c478bd9Sstevel@tonic-gate 21387c478bd9Sstevel@tonic-gate if (mdb_vread(&lbolt, sizeof (lbolt), cid->cid_lbolt) == -1) { 21397c478bd9Sstevel@tonic-gate mdb_warn("failed to read lbolt at %p", cid->cid_lbolt); 21407c478bd9Sstevel@tonic-gate return (WALK_ERR); 21417c478bd9Sstevel@tonic-gate } 21427c478bd9Sstevel@tonic-gate mdb_printf("t-%-4d ", lbolt - cpu->cpu_last_swtch); 21437c478bd9Sstevel@tonic-gate } else { 21447c478bd9Sstevel@tonic-gate mdb_printf("%-6s ", "-"); 21457c478bd9Sstevel@tonic-gate } 21467c478bd9Sstevel@tonic-gate 21477c478bd9Sstevel@tonic-gate mdb_printf("%0*p", CPUINFO_TWIDTH, cpu->cpu_thread); 21487c478bd9Sstevel@tonic-gate 21497c478bd9Sstevel@tonic-gate if (cpu->cpu_thread == cpu->cpu_idle_thread) 21507c478bd9Sstevel@tonic-gate mdb_printf(" (idle)\n"); 21517c478bd9Sstevel@tonic-gate else if (cpu->cpu_thread == NULL) 21527c478bd9Sstevel@tonic-gate mdb_printf(" -\n"); 21537c478bd9Sstevel@tonic-gate else { 21547c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), (uintptr_t)t.t_procp) != -1) { 21557c478bd9Sstevel@tonic-gate mdb_printf(" %s\n", p.p_user.u_comm); 21567c478bd9Sstevel@tonic-gate } else { 21577c478bd9Sstevel@tonic-gate mdb_printf(" ?\n"); 21587c478bd9Sstevel@tonic-gate } 21597c478bd9Sstevel@tonic-gate } 21607c478bd9Sstevel@tonic-gate 21617c478bd9Sstevel@tonic-gate flagbuf = mdb_zalloc(sizeof (flags), UM_SLEEP | UM_GC); 21627c478bd9Sstevel@tonic-gate 21637c478bd9Sstevel@tonic-gate if (cid->cid_print_flags) { 21647c478bd9Sstevel@tonic-gate int first = 1, i, j, k; 21657c478bd9Sstevel@tonic-gate char *s; 21667c478bd9Sstevel@tonic-gate 21677c478bd9Sstevel@tonic-gate cid->cid_print_head = TRUE; 21687c478bd9Sstevel@tonic-gate 21697c478bd9Sstevel@tonic-gate for (i = 1, j = 0; flags[j] != NULL; i <<= 1, j++) { 21707c478bd9Sstevel@tonic-gate if (!(cpu->cpu_flags & i)) 21717c478bd9Sstevel@tonic-gate continue; 21727c478bd9Sstevel@tonic-gate 21737c478bd9Sstevel@tonic-gate if (first) { 21747c478bd9Sstevel@tonic-gate s = mdb_alloc(CPUINFO_THRDELT + 1, 21757c478bd9Sstevel@tonic-gate UM_GC | UM_SLEEP); 21767c478bd9Sstevel@tonic-gate 21777c478bd9Sstevel@tonic-gate (void) mdb_snprintf(s, CPUINFO_THRDELT + 1, 21787c478bd9Sstevel@tonic-gate "%*s|%*s", CPUINFO_FLAGDELT, "", 21797c478bd9Sstevel@tonic-gate CPUINFO_THRDELT - 1 - CPUINFO_FLAGDELT, ""); 21807c478bd9Sstevel@tonic-gate flagbuf[nflaglines++] = s; 21817c478bd9Sstevel@tonic-gate } 21827c478bd9Sstevel@tonic-gate 21837c478bd9Sstevel@tonic-gate s = mdb_alloc(CPUINFO_THRDELT + 1, UM_GC | UM_SLEEP); 21847c478bd9Sstevel@tonic-gate (void) mdb_snprintf(s, CPUINFO_THRDELT + 1, "%*s%*s %s", 21857c478bd9Sstevel@tonic-gate CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH - 21867c478bd9Sstevel@tonic-gate CPUINFO_FLAGWIDTH, "", CPUINFO_FLAGWIDTH, flags[j], 21877c478bd9Sstevel@tonic-gate first ? "<--+" : ""); 21887c478bd9Sstevel@tonic-gate 21897c478bd9Sstevel@tonic-gate for (k = strlen(s); k < CPUINFO_THRDELT; k++) 21907c478bd9Sstevel@tonic-gate s[k] = ' '; 21917c478bd9Sstevel@tonic-gate s[k] = '\0'; 21927c478bd9Sstevel@tonic-gate 21937c478bd9Sstevel@tonic-gate flagbuf[nflaglines++] = s; 21947c478bd9Sstevel@tonic-gate first = 0; 21957c478bd9Sstevel@tonic-gate } 21967c478bd9Sstevel@tonic-gate } 21977c478bd9Sstevel@tonic-gate 21987c478bd9Sstevel@tonic-gate if (cid->cid_print_ithr) { 21997c478bd9Sstevel@tonic-gate int i, found_one = FALSE; 22007c478bd9Sstevel@tonic-gate int print_thr = disp.disp_nrunnable && cid->cid_print_thr; 22017c478bd9Sstevel@tonic-gate 22027c478bd9Sstevel@tonic-gate for (i = NINTR - 1; i >= 0; i--) { 22037c478bd9Sstevel@tonic-gate uintptr_t iaddr = cid->cid_ithr[cpu->cpu_id][i]; 22047c478bd9Sstevel@tonic-gate 22057c478bd9Sstevel@tonic-gate if (iaddr == NULL) 22067c478bd9Sstevel@tonic-gate continue; 22077c478bd9Sstevel@tonic-gate 22087c478bd9Sstevel@tonic-gate if (!found_one) { 22097c478bd9Sstevel@tonic-gate found_one = TRUE; 22107c478bd9Sstevel@tonic-gate 22117c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 22127c478bd9Sstevel@tonic-gate mdb_printf("%c%*s|\n", print_thr ? '|' : ' ', 22137c478bd9Sstevel@tonic-gate CPUINFO_ITHRDELT, ""); 22147c478bd9Sstevel@tonic-gate 22157c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 22167c478bd9Sstevel@tonic-gate mdb_printf("%c%*s+--> %3s %s\n", 22177c478bd9Sstevel@tonic-gate print_thr ? '|' : ' ', CPUINFO_ITHRDELT, 22187c478bd9Sstevel@tonic-gate "", "PIL", "THREAD"); 22197c478bd9Sstevel@tonic-gate } 22207c478bd9Sstevel@tonic-gate 22217c478bd9Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), iaddr) == -1) { 22227c478bd9Sstevel@tonic-gate mdb_warn("failed to read kthread_t at %p", 22237c478bd9Sstevel@tonic-gate iaddr); 22247c478bd9Sstevel@tonic-gate return (WALK_ERR); 22257c478bd9Sstevel@tonic-gate } 22267c478bd9Sstevel@tonic-gate 22277c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 22287c478bd9Sstevel@tonic-gate mdb_printf("%c%*s %3d %0*p\n", 22297c478bd9Sstevel@tonic-gate print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", 22307c478bd9Sstevel@tonic-gate t.t_pil, CPUINFO_TWIDTH, iaddr); 22317c478bd9Sstevel@tonic-gate 22327c478bd9Sstevel@tonic-gate pinned = (uintptr_t)t.t_intr; 22337c478bd9Sstevel@tonic-gate } 22347c478bd9Sstevel@tonic-gate 22357c478bd9Sstevel@tonic-gate if (found_one && pinned != NULL) { 22367c478bd9Sstevel@tonic-gate cid->cid_print_head = TRUE; 22377c478bd9Sstevel@tonic-gate (void) strcpy(p.p_user.u_comm, "?"); 22387c478bd9Sstevel@tonic-gate 22397c478bd9Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), 22407c478bd9Sstevel@tonic-gate (uintptr_t)pinned) == -1) { 22417c478bd9Sstevel@tonic-gate mdb_warn("failed to read kthread_t at %p", 22427c478bd9Sstevel@tonic-gate pinned); 22437c478bd9Sstevel@tonic-gate return (WALK_ERR); 22447c478bd9Sstevel@tonic-gate } 22457c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), 22467c478bd9Sstevel@tonic-gate (uintptr_t)t.t_procp) == -1) { 22477c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc_t at %p", 22487c478bd9Sstevel@tonic-gate t.t_procp); 22497c478bd9Sstevel@tonic-gate return (WALK_ERR); 22507c478bd9Sstevel@tonic-gate } 22517c478bd9Sstevel@tonic-gate 22527c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 22537c478bd9Sstevel@tonic-gate mdb_printf("%c%*s %3s %0*p %s\n", 22547c478bd9Sstevel@tonic-gate print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", "-", 22557c478bd9Sstevel@tonic-gate CPUINFO_TWIDTH, pinned, 22567c478bd9Sstevel@tonic-gate pinned == (uintptr_t)cpu->cpu_idle_thread ? 22577c478bd9Sstevel@tonic-gate "(idle)" : p.p_user.u_comm); 22587c478bd9Sstevel@tonic-gate } 22597c478bd9Sstevel@tonic-gate } 22607c478bd9Sstevel@tonic-gate 22617c478bd9Sstevel@tonic-gate if (disp.disp_nrunnable && cid->cid_print_thr) { 22627c478bd9Sstevel@tonic-gate dispq_t *dq; 22637c478bd9Sstevel@tonic-gate 22647c478bd9Sstevel@tonic-gate int i, npri = disp.disp_npri; 22657c478bd9Sstevel@tonic-gate 22667c478bd9Sstevel@tonic-gate dq = mdb_alloc(sizeof (dispq_t) * npri, UM_SLEEP | UM_GC); 22677c478bd9Sstevel@tonic-gate 22687c478bd9Sstevel@tonic-gate if (mdb_vread(dq, sizeof (dispq_t) * npri, 22697c478bd9Sstevel@tonic-gate (uintptr_t)disp.disp_q) == -1) { 22707c478bd9Sstevel@tonic-gate mdb_warn("failed to read dispq_t at %p", disp.disp_q); 22717c478bd9Sstevel@tonic-gate return (WALK_ERR); 22727c478bd9Sstevel@tonic-gate } 22737c478bd9Sstevel@tonic-gate 22747c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 22757c478bd9Sstevel@tonic-gate mdb_printf("|\n"); 22767c478bd9Sstevel@tonic-gate 22777c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 22787c478bd9Sstevel@tonic-gate mdb_printf("+--> %3s %-*s %s\n", "PRI", 22797c478bd9Sstevel@tonic-gate CPUINFO_TWIDTH, "THREAD", "PROC"); 22807c478bd9Sstevel@tonic-gate 22817c478bd9Sstevel@tonic-gate for (i = npri - 1; i >= 0; i--) { 22827c478bd9Sstevel@tonic-gate uintptr_t taddr = (uintptr_t)dq[i].dq_first; 22837c478bd9Sstevel@tonic-gate 22847c478bd9Sstevel@tonic-gate while (taddr != NULL) { 22857c478bd9Sstevel@tonic-gate if (mdb_vread(&t, sizeof (t), taddr) == -1) { 22867c478bd9Sstevel@tonic-gate mdb_warn("failed to read kthread_t " 22877c478bd9Sstevel@tonic-gate "at %p", taddr); 22887c478bd9Sstevel@tonic-gate return (WALK_ERR); 22897c478bd9Sstevel@tonic-gate } 22907c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), 22917c478bd9Sstevel@tonic-gate (uintptr_t)t.t_procp) == -1) { 22927c478bd9Sstevel@tonic-gate mdb_warn("failed to read proc_t at %p", 22937c478bd9Sstevel@tonic-gate t.t_procp); 22947c478bd9Sstevel@tonic-gate return (WALK_ERR); 22957c478bd9Sstevel@tonic-gate } 22967c478bd9Sstevel@tonic-gate 22977c478bd9Sstevel@tonic-gate CPUINFO_INDENT; 22987c478bd9Sstevel@tonic-gate mdb_printf(" %3d %0*p %s\n", t.t_pri, 22997c478bd9Sstevel@tonic-gate CPUINFO_TWIDTH, taddr, p.p_user.u_comm); 23007c478bd9Sstevel@tonic-gate 23017c478bd9Sstevel@tonic-gate taddr = (uintptr_t)t.t_link; 23027c478bd9Sstevel@tonic-gate } 23037c478bd9Sstevel@tonic-gate } 23047c478bd9Sstevel@tonic-gate cid->cid_print_head = TRUE; 23057c478bd9Sstevel@tonic-gate } 23067c478bd9Sstevel@tonic-gate 23077c478bd9Sstevel@tonic-gate while (flagline < nflaglines) 23087c478bd9Sstevel@tonic-gate mdb_printf("%s\n", flagbuf[flagline++]); 23097c478bd9Sstevel@tonic-gate 23107c478bd9Sstevel@tonic-gate if (cid->cid_print_head) 23117c478bd9Sstevel@tonic-gate mdb_printf("\n"); 23127c478bd9Sstevel@tonic-gate 23137c478bd9Sstevel@tonic-gate return (rval); 23147c478bd9Sstevel@tonic-gate } 23157c478bd9Sstevel@tonic-gate 23167c478bd9Sstevel@tonic-gate int 23177c478bd9Sstevel@tonic-gate cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 23187c478bd9Sstevel@tonic-gate { 23197c478bd9Sstevel@tonic-gate uint_t verbose = FALSE; 23207c478bd9Sstevel@tonic-gate cpuinfo_data_t cid; 23217c478bd9Sstevel@tonic-gate GElf_Sym sym; 23227c478bd9Sstevel@tonic-gate clock_t lbolt; 23237c478bd9Sstevel@tonic-gate 23247c478bd9Sstevel@tonic-gate cid.cid_print_ithr = FALSE; 23257c478bd9Sstevel@tonic-gate cid.cid_print_thr = FALSE; 23267c478bd9Sstevel@tonic-gate cid.cid_print_flags = FALSE; 23277c478bd9Sstevel@tonic-gate cid.cid_print_head = DCMD_HDRSPEC(flags) ? TRUE : FALSE; 23287c478bd9Sstevel@tonic-gate cid.cid_cpu = -1; 23297c478bd9Sstevel@tonic-gate 23307c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) 23317c478bd9Sstevel@tonic-gate cid.cid_cpu = addr; 23327c478bd9Sstevel@tonic-gate 23337c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 23347c478bd9Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc) 23357c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 23367c478bd9Sstevel@tonic-gate 23377c478bd9Sstevel@tonic-gate if (verbose) { 23387c478bd9Sstevel@tonic-gate cid.cid_print_ithr = TRUE; 23397c478bd9Sstevel@tonic-gate cid.cid_print_thr = TRUE; 23407c478bd9Sstevel@tonic-gate cid.cid_print_flags = TRUE; 23417c478bd9Sstevel@tonic-gate cid.cid_print_head = TRUE; 23427c478bd9Sstevel@tonic-gate } 23437c478bd9Sstevel@tonic-gate 23447c478bd9Sstevel@tonic-gate if (cid.cid_print_ithr) { 23457c478bd9Sstevel@tonic-gate int i; 23467c478bd9Sstevel@tonic-gate 23477c478bd9Sstevel@tonic-gate cid.cid_ithr = mdb_alloc(sizeof (uintptr_t **) 23487c478bd9Sstevel@tonic-gate * NCPU, UM_SLEEP | UM_GC); 23497c478bd9Sstevel@tonic-gate 23507c478bd9Sstevel@tonic-gate for (i = 0; i < NCPU; i++) 23517c478bd9Sstevel@tonic-gate cid.cid_ithr[i] = mdb_zalloc(sizeof (uintptr_t *) * 23527c478bd9Sstevel@tonic-gate NINTR, UM_SLEEP | UM_GC); 23537c478bd9Sstevel@tonic-gate 23547c478bd9Sstevel@tonic-gate if (mdb_walk("thread", (mdb_walk_cb_t)cpuinfo_walk_ithread, 23557c478bd9Sstevel@tonic-gate &cid) == -1) { 23567c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk thread"); 23577c478bd9Sstevel@tonic-gate return (DCMD_ERR); 23587c478bd9Sstevel@tonic-gate } 23597c478bd9Sstevel@tonic-gate } 23607c478bd9Sstevel@tonic-gate 23617c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("panic_lbolt", &sym) == -1) { 23627c478bd9Sstevel@tonic-gate mdb_warn("failed to find panic_lbolt"); 23637c478bd9Sstevel@tonic-gate return (DCMD_ERR); 23647c478bd9Sstevel@tonic-gate } 23657c478bd9Sstevel@tonic-gate 23667c478bd9Sstevel@tonic-gate cid.cid_lbolt = (uintptr_t)sym.st_value; 23677c478bd9Sstevel@tonic-gate 23687c478bd9Sstevel@tonic-gate if (mdb_vread(&lbolt, sizeof (lbolt), cid.cid_lbolt) == -1) { 23697c478bd9Sstevel@tonic-gate mdb_warn("failed to read panic_lbolt"); 23707c478bd9Sstevel@tonic-gate return (DCMD_ERR); 23717c478bd9Sstevel@tonic-gate } 23727c478bd9Sstevel@tonic-gate 23737c478bd9Sstevel@tonic-gate if (lbolt == 0) { 23747c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("lbolt", &sym) == -1) { 23757c478bd9Sstevel@tonic-gate mdb_warn("failed to find lbolt"); 23767c478bd9Sstevel@tonic-gate return (DCMD_ERR); 23777c478bd9Sstevel@tonic-gate } 23787c478bd9Sstevel@tonic-gate cid.cid_lbolt = (uintptr_t)sym.st_value; 23797c478bd9Sstevel@tonic-gate } 23807c478bd9Sstevel@tonic-gate 23817c478bd9Sstevel@tonic-gate if (mdb_walk("cpu", (mdb_walk_cb_t)cpuinfo_walk_cpu, &cid) == -1) { 23827c478bd9Sstevel@tonic-gate mdb_warn("can't walk cpus"); 23837c478bd9Sstevel@tonic-gate return (DCMD_ERR); 23847c478bd9Sstevel@tonic-gate } 23857c478bd9Sstevel@tonic-gate 23867c478bd9Sstevel@tonic-gate if (cid.cid_cpu != -1) { 23877c478bd9Sstevel@tonic-gate /* 23887c478bd9Sstevel@tonic-gate * We didn't find this CPU when we walked through the CPUs 23897c478bd9Sstevel@tonic-gate * (i.e. the address specified doesn't show up in the "cpu" 23907c478bd9Sstevel@tonic-gate * walk). However, the specified address may still correspond 23917c478bd9Sstevel@tonic-gate * to a valid cpu_t (for example, if the specified address is 23927c478bd9Sstevel@tonic-gate * the actual panicking cpu_t and not the cached panic_cpu). 23937c478bd9Sstevel@tonic-gate * Point is: even if we didn't find it, we still want to try 23947c478bd9Sstevel@tonic-gate * to print the specified address as a cpu_t. 23957c478bd9Sstevel@tonic-gate */ 23967c478bd9Sstevel@tonic-gate cpu_t cpu; 23977c478bd9Sstevel@tonic-gate 23987c478bd9Sstevel@tonic-gate if (mdb_vread(&cpu, sizeof (cpu), cid.cid_cpu) == -1) { 23997c478bd9Sstevel@tonic-gate mdb_warn("%p is neither a valid CPU ID nor a " 24007c478bd9Sstevel@tonic-gate "valid cpu_t address\n", cid.cid_cpu); 24017c478bd9Sstevel@tonic-gate return (DCMD_ERR); 24027c478bd9Sstevel@tonic-gate } 24037c478bd9Sstevel@tonic-gate 24047c478bd9Sstevel@tonic-gate (void) cpuinfo_walk_cpu(cid.cid_cpu, &cpu, &cid); 24057c478bd9Sstevel@tonic-gate } 24067c478bd9Sstevel@tonic-gate 24077c478bd9Sstevel@tonic-gate return (DCMD_OK); 24087c478bd9Sstevel@tonic-gate } 24097c478bd9Sstevel@tonic-gate 24107c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 24117c478bd9Sstevel@tonic-gate int 24127c478bd9Sstevel@tonic-gate flipone(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 24137c478bd9Sstevel@tonic-gate { 24147c478bd9Sstevel@tonic-gate int i; 24157c478bd9Sstevel@tonic-gate 24167c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 24177c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 24187c478bd9Sstevel@tonic-gate 24197c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (addr) * NBBY; i++) 24207c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr ^ (1UL << i)); 24217c478bd9Sstevel@tonic-gate 24227c478bd9Sstevel@tonic-gate return (DCMD_OK); 24237c478bd9Sstevel@tonic-gate } 24247c478bd9Sstevel@tonic-gate 24257c478bd9Sstevel@tonic-gate /* 24267c478bd9Sstevel@tonic-gate * Grumble, grumble. 24277c478bd9Sstevel@tonic-gate */ 24287c478bd9Sstevel@tonic-gate #define SMAP_HASHFUNC(vp, off) \ 24297c478bd9Sstevel@tonic-gate ((((uintptr_t)(vp) >> 6) + ((uintptr_t)(vp) >> 3) + \ 24307c478bd9Sstevel@tonic-gate ((off) >> MAXBSHIFT)) & smd_hashmsk) 24317c478bd9Sstevel@tonic-gate 24327c478bd9Sstevel@tonic-gate int 24337c478bd9Sstevel@tonic-gate vnode2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 24347c478bd9Sstevel@tonic-gate { 24357c478bd9Sstevel@tonic-gate long smd_hashmsk; 24367c478bd9Sstevel@tonic-gate int hash; 24377c478bd9Sstevel@tonic-gate uintptr_t offset = 0; 24387c478bd9Sstevel@tonic-gate struct smap smp; 24397c478bd9Sstevel@tonic-gate uintptr_t saddr, kaddr; 24407c478bd9Sstevel@tonic-gate uintptr_t smd_hash, smd_smap; 24417c478bd9Sstevel@tonic-gate struct seg seg; 24427c478bd9Sstevel@tonic-gate 24437c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 24447c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 24457c478bd9Sstevel@tonic-gate 24467c478bd9Sstevel@tonic-gate if (mdb_readvar(&smd_hashmsk, "smd_hashmsk") == -1) { 24477c478bd9Sstevel@tonic-gate mdb_warn("failed to read smd_hashmsk"); 24487c478bd9Sstevel@tonic-gate return (DCMD_ERR); 24497c478bd9Sstevel@tonic-gate } 24507c478bd9Sstevel@tonic-gate 24517c478bd9Sstevel@tonic-gate if (mdb_readvar(&smd_hash, "smd_hash") == -1) { 24527c478bd9Sstevel@tonic-gate mdb_warn("failed to read smd_hash"); 24537c478bd9Sstevel@tonic-gate return (DCMD_ERR); 24547c478bd9Sstevel@tonic-gate } 24557c478bd9Sstevel@tonic-gate 24567c478bd9Sstevel@tonic-gate if (mdb_readvar(&smd_smap, "smd_smap") == -1) { 24577c478bd9Sstevel@tonic-gate mdb_warn("failed to read smd_hash"); 24587c478bd9Sstevel@tonic-gate return (DCMD_ERR); 24597c478bd9Sstevel@tonic-gate } 24607c478bd9Sstevel@tonic-gate 24617c478bd9Sstevel@tonic-gate if (mdb_readvar(&kaddr, "segkmap") == -1) { 24627c478bd9Sstevel@tonic-gate mdb_warn("failed to read segkmap"); 24637c478bd9Sstevel@tonic-gate return (DCMD_ERR); 24647c478bd9Sstevel@tonic-gate } 24657c478bd9Sstevel@tonic-gate 24667c478bd9Sstevel@tonic-gate if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) { 24677c478bd9Sstevel@tonic-gate mdb_warn("failed to read segkmap at %p", kaddr); 24687c478bd9Sstevel@tonic-gate return (DCMD_ERR); 24697c478bd9Sstevel@tonic-gate } 24707c478bd9Sstevel@tonic-gate 24717c478bd9Sstevel@tonic-gate if (argc != 0) { 24727c478bd9Sstevel@tonic-gate const mdb_arg_t *arg = &argv[0]; 24737c478bd9Sstevel@tonic-gate 24747c478bd9Sstevel@tonic-gate if (arg->a_type == MDB_TYPE_IMMEDIATE) 24757c478bd9Sstevel@tonic-gate offset = arg->a_un.a_val; 24767c478bd9Sstevel@tonic-gate else 24777c478bd9Sstevel@tonic-gate offset = (uintptr_t)mdb_strtoull(arg->a_un.a_str); 24787c478bd9Sstevel@tonic-gate } 24797c478bd9Sstevel@tonic-gate 24807c478bd9Sstevel@tonic-gate hash = SMAP_HASHFUNC(addr, offset); 24817c478bd9Sstevel@tonic-gate 24827c478bd9Sstevel@tonic-gate if (mdb_vread(&saddr, sizeof (saddr), 24837c478bd9Sstevel@tonic-gate smd_hash + hash * sizeof (uintptr_t)) == -1) { 24847c478bd9Sstevel@tonic-gate mdb_warn("couldn't read smap at %p", 24857c478bd9Sstevel@tonic-gate smd_hash + hash * sizeof (uintptr_t)); 24867c478bd9Sstevel@tonic-gate return (DCMD_ERR); 24877c478bd9Sstevel@tonic-gate } 24887c478bd9Sstevel@tonic-gate 24897c478bd9Sstevel@tonic-gate do { 24907c478bd9Sstevel@tonic-gate if (mdb_vread(&smp, sizeof (smp), saddr) == -1) { 24917c478bd9Sstevel@tonic-gate mdb_warn("couldn't read smap at %p", saddr); 24927c478bd9Sstevel@tonic-gate return (DCMD_ERR); 24937c478bd9Sstevel@tonic-gate } 24947c478bd9Sstevel@tonic-gate 24957c478bd9Sstevel@tonic-gate if ((uintptr_t)smp.sm_vp == addr && smp.sm_off == offset) { 24967c478bd9Sstevel@tonic-gate mdb_printf("vnode %p, offs %p is smap %p, vaddr %p\n", 24977c478bd9Sstevel@tonic-gate addr, offset, saddr, ((saddr - smd_smap) / 24987c478bd9Sstevel@tonic-gate sizeof (smp)) * MAXBSIZE + seg.s_base); 24997c478bd9Sstevel@tonic-gate return (DCMD_OK); 25007c478bd9Sstevel@tonic-gate } 25017c478bd9Sstevel@tonic-gate 25027c478bd9Sstevel@tonic-gate saddr = (uintptr_t)smp.sm_hash; 25037c478bd9Sstevel@tonic-gate } while (saddr != NULL); 25047c478bd9Sstevel@tonic-gate 25057c478bd9Sstevel@tonic-gate mdb_printf("no smap for vnode %p, offs %p\n", addr, offset); 25067c478bd9Sstevel@tonic-gate return (DCMD_OK); 25077c478bd9Sstevel@tonic-gate } 25087c478bd9Sstevel@tonic-gate 25097c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 25107c478bd9Sstevel@tonic-gate int 25117c478bd9Sstevel@tonic-gate addr2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 25127c478bd9Sstevel@tonic-gate { 25137c478bd9Sstevel@tonic-gate uintptr_t kaddr; 25147c478bd9Sstevel@tonic-gate struct seg seg; 25157c478bd9Sstevel@tonic-gate struct segmap_data sd; 25167c478bd9Sstevel@tonic-gate 25177c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 25187c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 25197c478bd9Sstevel@tonic-gate 25207c478bd9Sstevel@tonic-gate if (mdb_readvar(&kaddr, "segkmap") == -1) { 25217c478bd9Sstevel@tonic-gate mdb_warn("failed to read segkmap"); 25227c478bd9Sstevel@tonic-gate return (DCMD_ERR); 25237c478bd9Sstevel@tonic-gate } 25247c478bd9Sstevel@tonic-gate 25257c478bd9Sstevel@tonic-gate if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) { 25267c478bd9Sstevel@tonic-gate mdb_warn("failed to read segkmap at %p", kaddr); 25277c478bd9Sstevel@tonic-gate return (DCMD_ERR); 25287c478bd9Sstevel@tonic-gate } 25297c478bd9Sstevel@tonic-gate 25307c478bd9Sstevel@tonic-gate if (mdb_vread(&sd, sizeof (sd), (uintptr_t)seg.s_data) == -1) { 25317c478bd9Sstevel@tonic-gate mdb_warn("failed to read segmap_data at %p", seg.s_data); 25327c478bd9Sstevel@tonic-gate return (DCMD_ERR); 25337c478bd9Sstevel@tonic-gate } 25347c478bd9Sstevel@tonic-gate 25357c478bd9Sstevel@tonic-gate mdb_printf("%p is smap %p\n", addr, 25367c478bd9Sstevel@tonic-gate ((addr - (uintptr_t)seg.s_base) >> MAXBSHIFT) * 25377c478bd9Sstevel@tonic-gate sizeof (struct smap) + (uintptr_t)sd.smd_sm); 25387c478bd9Sstevel@tonic-gate 25397c478bd9Sstevel@tonic-gate return (DCMD_OK); 25407c478bd9Sstevel@tonic-gate } 25417c478bd9Sstevel@tonic-gate 25427c478bd9Sstevel@tonic-gate int 25437c478bd9Sstevel@tonic-gate as2proc_walk(uintptr_t addr, const proc_t *p, struct as **asp) 25447c478bd9Sstevel@tonic-gate { 25457c478bd9Sstevel@tonic-gate if (p->p_as == *asp) 25467c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr); 25477c478bd9Sstevel@tonic-gate return (WALK_NEXT); 25487c478bd9Sstevel@tonic-gate } 25497c478bd9Sstevel@tonic-gate 25507c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 25517c478bd9Sstevel@tonic-gate int 25527c478bd9Sstevel@tonic-gate as2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 25537c478bd9Sstevel@tonic-gate { 25547c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || argc != 0) 25557c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 25567c478bd9Sstevel@tonic-gate 25577c478bd9Sstevel@tonic-gate if (mdb_walk("proc", (mdb_walk_cb_t)as2proc_walk, &addr) == -1) { 25587c478bd9Sstevel@tonic-gate mdb_warn("failed to walk proc"); 25597c478bd9Sstevel@tonic-gate return (DCMD_ERR); 25607c478bd9Sstevel@tonic-gate } 25617c478bd9Sstevel@tonic-gate 25627c478bd9Sstevel@tonic-gate return (DCMD_OK); 25637c478bd9Sstevel@tonic-gate } 25647c478bd9Sstevel@tonic-gate 25657c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 25667c478bd9Sstevel@tonic-gate int 25677c478bd9Sstevel@tonic-gate ptree_walk(uintptr_t addr, const proc_t *p, void *ignored) 25687c478bd9Sstevel@tonic-gate { 25697c478bd9Sstevel@tonic-gate proc_t parent; 25707c478bd9Sstevel@tonic-gate int ident = 0; 25717c478bd9Sstevel@tonic-gate uintptr_t paddr; 25727c478bd9Sstevel@tonic-gate 25737c478bd9Sstevel@tonic-gate for (paddr = (uintptr_t)p->p_parent; paddr != NULL; ident += 5) { 25747c478bd9Sstevel@tonic-gate mdb_vread(&parent, sizeof (parent), paddr); 25757c478bd9Sstevel@tonic-gate paddr = (uintptr_t)parent.p_parent; 25767c478bd9Sstevel@tonic-gate } 25777c478bd9Sstevel@tonic-gate 25787c478bd9Sstevel@tonic-gate mdb_inc_indent(ident); 25797c478bd9Sstevel@tonic-gate mdb_printf("%0?p %s\n", addr, p->p_user.u_comm); 25807c478bd9Sstevel@tonic-gate mdb_dec_indent(ident); 25817c478bd9Sstevel@tonic-gate 25827c478bd9Sstevel@tonic-gate return (WALK_NEXT); 25837c478bd9Sstevel@tonic-gate } 25847c478bd9Sstevel@tonic-gate 25857c478bd9Sstevel@tonic-gate void 25867c478bd9Sstevel@tonic-gate ptree_ancestors(uintptr_t addr, uintptr_t start) 25877c478bd9Sstevel@tonic-gate { 25887c478bd9Sstevel@tonic-gate proc_t p; 25897c478bd9Sstevel@tonic-gate 25907c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (p), addr) == -1) { 25917c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ancestor at %p", addr); 25927c478bd9Sstevel@tonic-gate return; 25937c478bd9Sstevel@tonic-gate } 25947c478bd9Sstevel@tonic-gate 25957c478bd9Sstevel@tonic-gate if (p.p_parent != NULL) 25967c478bd9Sstevel@tonic-gate ptree_ancestors((uintptr_t)p.p_parent, start); 25977c478bd9Sstevel@tonic-gate 25987c478bd9Sstevel@tonic-gate if (addr != start) 25997c478bd9Sstevel@tonic-gate (void) ptree_walk(addr, &p, NULL); 26007c478bd9Sstevel@tonic-gate } 26017c478bd9Sstevel@tonic-gate 26027c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 26037c478bd9Sstevel@tonic-gate int 26047c478bd9Sstevel@tonic-gate ptree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 26057c478bd9Sstevel@tonic-gate { 26067c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 26077c478bd9Sstevel@tonic-gate addr = NULL; 26087c478bd9Sstevel@tonic-gate else 26097c478bd9Sstevel@tonic-gate ptree_ancestors(addr, addr); 26107c478bd9Sstevel@tonic-gate 26117c478bd9Sstevel@tonic-gate if (mdb_pwalk("proc", (mdb_walk_cb_t)ptree_walk, NULL, addr) == -1) { 26127c478bd9Sstevel@tonic-gate mdb_warn("couldn't walk 'proc'"); 26137c478bd9Sstevel@tonic-gate return (DCMD_ERR); 26147c478bd9Sstevel@tonic-gate } 26157c478bd9Sstevel@tonic-gate 26167c478bd9Sstevel@tonic-gate return (DCMD_OK); 26177c478bd9Sstevel@tonic-gate } 26187c478bd9Sstevel@tonic-gate 26197c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 26207c478bd9Sstevel@tonic-gate static int 26217c478bd9Sstevel@tonic-gate fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 26227c478bd9Sstevel@tonic-gate { 26237c478bd9Sstevel@tonic-gate int fdnum; 26247c478bd9Sstevel@tonic-gate const mdb_arg_t *argp = &argv[0]; 26257c478bd9Sstevel@tonic-gate proc_t p; 26267c478bd9Sstevel@tonic-gate uf_entry_t uf; 26277c478bd9Sstevel@tonic-gate 26287c478bd9Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0) { 26297c478bd9Sstevel@tonic-gate mdb_warn("fd doesn't give global information\n"); 26307c478bd9Sstevel@tonic-gate return (DCMD_ERR); 26317c478bd9Sstevel@tonic-gate } 26327c478bd9Sstevel@tonic-gate if (argc != 1) 26337c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 26347c478bd9Sstevel@tonic-gate 26357c478bd9Sstevel@tonic-gate if (argp->a_type == MDB_TYPE_IMMEDIATE) 26367c478bd9Sstevel@tonic-gate fdnum = argp->a_un.a_val; 26377c478bd9Sstevel@tonic-gate else 26387c478bd9Sstevel@tonic-gate fdnum = mdb_strtoull(argp->a_un.a_str); 26397c478bd9Sstevel@tonic-gate 26407c478bd9Sstevel@tonic-gate if (mdb_vread(&p, sizeof (struct proc), addr) == -1) { 26417c478bd9Sstevel@tonic-gate mdb_warn("couldn't read proc_t at %p", addr); 26427c478bd9Sstevel@tonic-gate return (DCMD_ERR); 26437c478bd9Sstevel@tonic-gate } 26447c478bd9Sstevel@tonic-gate if (fdnum > p.p_user.u_finfo.fi_nfiles) { 26457c478bd9Sstevel@tonic-gate mdb_warn("process %p only has %d files open.\n", 26467c478bd9Sstevel@tonic-gate addr, p.p_user.u_finfo.fi_nfiles); 26477c478bd9Sstevel@tonic-gate return (DCMD_ERR); 26487c478bd9Sstevel@tonic-gate } 26497c478bd9Sstevel@tonic-gate if (mdb_vread(&uf, sizeof (uf_entry_t), 26507c478bd9Sstevel@tonic-gate (uintptr_t)&p.p_user.u_finfo.fi_list[fdnum]) == -1) { 26517c478bd9Sstevel@tonic-gate mdb_warn("couldn't read uf_entry_t at %p", 26527c478bd9Sstevel@tonic-gate &p.p_user.u_finfo.fi_list[fdnum]); 26537c478bd9Sstevel@tonic-gate return (DCMD_ERR); 26547c478bd9Sstevel@tonic-gate } 26557c478bd9Sstevel@tonic-gate 26567c478bd9Sstevel@tonic-gate mdb_printf("%p\n", uf.uf_file); 26577c478bd9Sstevel@tonic-gate return (DCMD_OK); 26587c478bd9Sstevel@tonic-gate } 26597c478bd9Sstevel@tonic-gate 26607c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 26617c478bd9Sstevel@tonic-gate static int 26627c478bd9Sstevel@tonic-gate pid2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 26637c478bd9Sstevel@tonic-gate { 26647c478bd9Sstevel@tonic-gate pid_t pid = (pid_t)addr; 26657c478bd9Sstevel@tonic-gate 26667c478bd9Sstevel@tonic-gate if (argc != 0) 26677c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 26687c478bd9Sstevel@tonic-gate 26697c478bd9Sstevel@tonic-gate if ((addr = mdb_pid2proc(pid, NULL)) == NULL) { 26707c478bd9Sstevel@tonic-gate mdb_warn("PID 0t%d not found\n", pid); 26717c478bd9Sstevel@tonic-gate return (DCMD_ERR); 26727c478bd9Sstevel@tonic-gate } 26737c478bd9Sstevel@tonic-gate 26747c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr); 26757c478bd9Sstevel@tonic-gate return (DCMD_OK); 26767c478bd9Sstevel@tonic-gate } 26777c478bd9Sstevel@tonic-gate 26787c478bd9Sstevel@tonic-gate static char *sysfile_cmd[] = { 26797c478bd9Sstevel@tonic-gate "exclude:", 26807c478bd9Sstevel@tonic-gate "include:", 26817c478bd9Sstevel@tonic-gate "forceload:", 26827c478bd9Sstevel@tonic-gate "rootdev:", 26837c478bd9Sstevel@tonic-gate "rootfs:", 26847c478bd9Sstevel@tonic-gate "swapdev:", 26857c478bd9Sstevel@tonic-gate "swapfs:", 26867c478bd9Sstevel@tonic-gate "moddir:", 26877c478bd9Sstevel@tonic-gate "set", 26887c478bd9Sstevel@tonic-gate "unknown", 26897c478bd9Sstevel@tonic-gate }; 26907c478bd9Sstevel@tonic-gate 26917c478bd9Sstevel@tonic-gate static char *sysfile_ops[] = { "", "=", "&", "|" }; 26927c478bd9Sstevel@tonic-gate 26937c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 26947c478bd9Sstevel@tonic-gate static int 26957c478bd9Sstevel@tonic-gate sysfile_vmem_seg(uintptr_t addr, const vmem_seg_t *vsp, void **target) 26967c478bd9Sstevel@tonic-gate { 26977c478bd9Sstevel@tonic-gate if (vsp->vs_type == VMEM_ALLOC && (void *)vsp->vs_start == *target) { 26987c478bd9Sstevel@tonic-gate *target = NULL; 26997c478bd9Sstevel@tonic-gate return (WALK_DONE); 27007c478bd9Sstevel@tonic-gate } 27017c478bd9Sstevel@tonic-gate return (WALK_NEXT); 27027c478bd9Sstevel@tonic-gate } 27037c478bd9Sstevel@tonic-gate 27047c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 27057c478bd9Sstevel@tonic-gate static int 27067c478bd9Sstevel@tonic-gate sysfile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 27077c478bd9Sstevel@tonic-gate { 27087c478bd9Sstevel@tonic-gate struct sysparam *sysp, sys; 27097c478bd9Sstevel@tonic-gate char var[256]; 27107c478bd9Sstevel@tonic-gate char modname[256]; 27117c478bd9Sstevel@tonic-gate char val[256]; 27127c478bd9Sstevel@tonic-gate char strval[256]; 27137c478bd9Sstevel@tonic-gate vmem_t *mod_sysfile_arena; 27147c478bd9Sstevel@tonic-gate void *straddr; 27157c478bd9Sstevel@tonic-gate 27167c478bd9Sstevel@tonic-gate if (mdb_readvar(&sysp, "sysparam_hd") == -1) { 27177c478bd9Sstevel@tonic-gate mdb_warn("failed to read sysparam_hd"); 27187c478bd9Sstevel@tonic-gate return (DCMD_ERR); 27197c478bd9Sstevel@tonic-gate } 27207c478bd9Sstevel@tonic-gate 27217c478bd9Sstevel@tonic-gate if (mdb_readvar(&mod_sysfile_arena, "mod_sysfile_arena") == -1) { 27227c478bd9Sstevel@tonic-gate mdb_warn("failed to read mod_sysfile_arena"); 27237c478bd9Sstevel@tonic-gate return (DCMD_ERR); 27247c478bd9Sstevel@tonic-gate } 27257c478bd9Sstevel@tonic-gate 27267c478bd9Sstevel@tonic-gate while (sysp != NULL) { 27277c478bd9Sstevel@tonic-gate var[0] = '\0'; 27287c478bd9Sstevel@tonic-gate val[0] = '\0'; 27297c478bd9Sstevel@tonic-gate modname[0] = '\0'; 27307c478bd9Sstevel@tonic-gate if (mdb_vread(&sys, sizeof (sys), (uintptr_t)sysp) == -1) { 27317c478bd9Sstevel@tonic-gate mdb_warn("couldn't read sysparam %p", sysp); 27327c478bd9Sstevel@tonic-gate return (DCMD_ERR); 27337c478bd9Sstevel@tonic-gate } 27347c478bd9Sstevel@tonic-gate if (sys.sys_modnam != NULL && 27357c478bd9Sstevel@tonic-gate mdb_readstr(modname, 256, 27367c478bd9Sstevel@tonic-gate (uintptr_t)sys.sys_modnam) == -1) { 27377c478bd9Sstevel@tonic-gate mdb_warn("couldn't read modname in %p", sysp); 27387c478bd9Sstevel@tonic-gate return (DCMD_ERR); 27397c478bd9Sstevel@tonic-gate } 27407c478bd9Sstevel@tonic-gate if (sys.sys_ptr != NULL && 27417c478bd9Sstevel@tonic-gate mdb_readstr(var, 256, (uintptr_t)sys.sys_ptr) == -1) { 27427c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ptr in %p", sysp); 27437c478bd9Sstevel@tonic-gate return (DCMD_ERR); 27447c478bd9Sstevel@tonic-gate } 27457c478bd9Sstevel@tonic-gate if (sys.sys_op != SETOP_NONE) { 27467c478bd9Sstevel@tonic-gate /* 27477c478bd9Sstevel@tonic-gate * Is this an int or a string? We determine this 27487c478bd9Sstevel@tonic-gate * by checking whether straddr is contained in 27497c478bd9Sstevel@tonic-gate * mod_sysfile_arena. If so, the walker will set 27507c478bd9Sstevel@tonic-gate * straddr to NULL. 27517c478bd9Sstevel@tonic-gate */ 27527c478bd9Sstevel@tonic-gate straddr = (void *)(uintptr_t)sys.sys_info; 27537c478bd9Sstevel@tonic-gate if (sys.sys_op == SETOP_ASSIGN && 27547c478bd9Sstevel@tonic-gate sys.sys_info != 0 && 27557c478bd9Sstevel@tonic-gate mdb_pwalk("vmem_seg", 27567c478bd9Sstevel@tonic-gate (mdb_walk_cb_t)sysfile_vmem_seg, &straddr, 27577c478bd9Sstevel@tonic-gate (uintptr_t)mod_sysfile_arena) == 0 && 27587c478bd9Sstevel@tonic-gate straddr == NULL && 27597c478bd9Sstevel@tonic-gate mdb_readstr(strval, 256, 27607c478bd9Sstevel@tonic-gate (uintptr_t)sys.sys_info) != -1) { 27617c478bd9Sstevel@tonic-gate (void) mdb_snprintf(val, sizeof (val), "\"%s\"", 27627c478bd9Sstevel@tonic-gate strval); 27637c478bd9Sstevel@tonic-gate } else { 27647c478bd9Sstevel@tonic-gate (void) mdb_snprintf(val, sizeof (val), 27657c478bd9Sstevel@tonic-gate "0x%llx [0t%llu]", sys.sys_info, 27667c478bd9Sstevel@tonic-gate sys.sys_info); 27677c478bd9Sstevel@tonic-gate } 27687c478bd9Sstevel@tonic-gate } 27697c478bd9Sstevel@tonic-gate mdb_printf("%s %s%s%s%s%s\n", sysfile_cmd[sys.sys_type], 27707c478bd9Sstevel@tonic-gate modname, modname[0] == '\0' ? "" : ":", 27717c478bd9Sstevel@tonic-gate var, sysfile_ops[sys.sys_op], val); 27727c478bd9Sstevel@tonic-gate 27737c478bd9Sstevel@tonic-gate sysp = sys.sys_next; 27747c478bd9Sstevel@tonic-gate } 27757c478bd9Sstevel@tonic-gate 27767c478bd9Sstevel@tonic-gate return (DCMD_OK); 27777c478bd9Sstevel@tonic-gate } 27787c478bd9Sstevel@tonic-gate 27797c478bd9Sstevel@tonic-gate /* 27807c478bd9Sstevel@tonic-gate * Dump a taskq_ent_t given its address. 27817c478bd9Sstevel@tonic-gate */ 27827c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 27837c478bd9Sstevel@tonic-gate int 27847c478bd9Sstevel@tonic-gate taskq_ent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 27857c478bd9Sstevel@tonic-gate { 27867c478bd9Sstevel@tonic-gate taskq_ent_t taskq_ent; 27877c478bd9Sstevel@tonic-gate GElf_Sym sym; 27887c478bd9Sstevel@tonic-gate char buf[MDB_SYM_NAMLEN+1]; 27897c478bd9Sstevel@tonic-gate 27907c478bd9Sstevel@tonic-gate 27917c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 27927c478bd9Sstevel@tonic-gate mdb_warn("expected explicit taskq_ent_t address before ::\n"); 27937c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 27947c478bd9Sstevel@tonic-gate } 27957c478bd9Sstevel@tonic-gate 27967c478bd9Sstevel@tonic-gate if (mdb_vread(&taskq_ent, sizeof (taskq_ent_t), addr) == -1) { 27977c478bd9Sstevel@tonic-gate mdb_warn("failed to read taskq_ent_t at %p", addr); 27987c478bd9Sstevel@tonic-gate return (DCMD_ERR); 27997c478bd9Sstevel@tonic-gate } 28007c478bd9Sstevel@tonic-gate 28017c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 28027c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-?s %-?s %-s%</u>\n", 28037c478bd9Sstevel@tonic-gate "ENTRY", "ARG", "FUNCTION"); 28047c478bd9Sstevel@tonic-gate } 28057c478bd9Sstevel@tonic-gate 28067c478bd9Sstevel@tonic-gate if (mdb_lookup_by_addr((uintptr_t)taskq_ent.tqent_func, MDB_SYM_EXACT, 28077c478bd9Sstevel@tonic-gate buf, sizeof (buf), &sym) == -1) { 28087c478bd9Sstevel@tonic-gate (void) strcpy(buf, "????"); 28097c478bd9Sstevel@tonic-gate } 28107c478bd9Sstevel@tonic-gate 28117c478bd9Sstevel@tonic-gate mdb_printf("%-?p %-?p %s\n", addr, taskq_ent.tqent_arg, buf); 28127c478bd9Sstevel@tonic-gate 28137c478bd9Sstevel@tonic-gate return (DCMD_OK); 28147c478bd9Sstevel@tonic-gate } 28157c478bd9Sstevel@tonic-gate 28167c478bd9Sstevel@tonic-gate /* 28177c478bd9Sstevel@tonic-gate * Given the address of the (taskq_t) task queue head, walk the queue listing 28187c478bd9Sstevel@tonic-gate * the address of every taskq_ent_t. 28197c478bd9Sstevel@tonic-gate */ 28207c478bd9Sstevel@tonic-gate int 28217c478bd9Sstevel@tonic-gate taskq_walk_init(mdb_walk_state_t *wsp) 28227c478bd9Sstevel@tonic-gate { 28237c478bd9Sstevel@tonic-gate taskq_t tq_head; 28247c478bd9Sstevel@tonic-gate 28257c478bd9Sstevel@tonic-gate 28267c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 28277c478bd9Sstevel@tonic-gate mdb_warn("start address required\n"); 28287c478bd9Sstevel@tonic-gate return (WALK_ERR); 28297c478bd9Sstevel@tonic-gate } 28307c478bd9Sstevel@tonic-gate 28317c478bd9Sstevel@tonic-gate 28327c478bd9Sstevel@tonic-gate /* 28337c478bd9Sstevel@tonic-gate * Save the address of the list head entry. This terminates the list. 28347c478bd9Sstevel@tonic-gate */ 28357c478bd9Sstevel@tonic-gate wsp->walk_data = (void *) 28367c478bd9Sstevel@tonic-gate ((size_t)wsp->walk_addr + offsetof(taskq_t, tq_task)); 28377c478bd9Sstevel@tonic-gate 28387c478bd9Sstevel@tonic-gate 28397c478bd9Sstevel@tonic-gate /* 28407c478bd9Sstevel@tonic-gate * Read in taskq head, set walk_addr to point to first taskq_ent_t. 28417c478bd9Sstevel@tonic-gate */ 28427c478bd9Sstevel@tonic-gate if (mdb_vread((void *)&tq_head, sizeof (taskq_t), wsp->walk_addr) == 28437c478bd9Sstevel@tonic-gate -1) { 28447c478bd9Sstevel@tonic-gate mdb_warn("failed to read taskq list head at %p", 28457c478bd9Sstevel@tonic-gate wsp->walk_addr); 28467c478bd9Sstevel@tonic-gate } 28477c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)tq_head.tq_task.tqent_next; 28487c478bd9Sstevel@tonic-gate 28497c478bd9Sstevel@tonic-gate 28507c478bd9Sstevel@tonic-gate /* 28517c478bd9Sstevel@tonic-gate * Check for null list (next=head) 28527c478bd9Sstevel@tonic-gate */ 28537c478bd9Sstevel@tonic-gate if (wsp->walk_addr == (uintptr_t)wsp->walk_data) { 28547c478bd9Sstevel@tonic-gate return (WALK_DONE); 28557c478bd9Sstevel@tonic-gate } 28567c478bd9Sstevel@tonic-gate 28577c478bd9Sstevel@tonic-gate return (WALK_NEXT); 28587c478bd9Sstevel@tonic-gate } 28597c478bd9Sstevel@tonic-gate 28607c478bd9Sstevel@tonic-gate 28617c478bd9Sstevel@tonic-gate int 28627c478bd9Sstevel@tonic-gate taskq_walk_step(mdb_walk_state_t *wsp) 28637c478bd9Sstevel@tonic-gate { 28647c478bd9Sstevel@tonic-gate taskq_ent_t tq_ent; 28657c478bd9Sstevel@tonic-gate int status; 28667c478bd9Sstevel@tonic-gate 28677c478bd9Sstevel@tonic-gate 28687c478bd9Sstevel@tonic-gate if (mdb_vread((void *)&tq_ent, sizeof (taskq_ent_t), wsp->walk_addr) == 28697c478bd9Sstevel@tonic-gate -1) { 28707c478bd9Sstevel@tonic-gate mdb_warn("failed to read taskq_ent_t at %p", wsp->walk_addr); 28717c478bd9Sstevel@tonic-gate return (DCMD_ERR); 28727c478bd9Sstevel@tonic-gate } 28737c478bd9Sstevel@tonic-gate 28747c478bd9Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, (void *)&tq_ent, 28757c478bd9Sstevel@tonic-gate wsp->walk_cbdata); 28767c478bd9Sstevel@tonic-gate 28777c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)tq_ent.tqent_next; 28787c478bd9Sstevel@tonic-gate 28797c478bd9Sstevel@tonic-gate 28807c478bd9Sstevel@tonic-gate /* Check if we're at the last element (next=head) */ 28817c478bd9Sstevel@tonic-gate if (wsp->walk_addr == (uintptr_t)wsp->walk_data) { 28827c478bd9Sstevel@tonic-gate return (WALK_DONE); 28837c478bd9Sstevel@tonic-gate } 28847c478bd9Sstevel@tonic-gate 28857c478bd9Sstevel@tonic-gate return (status); 28867c478bd9Sstevel@tonic-gate } 28877c478bd9Sstevel@tonic-gate 28887c478bd9Sstevel@tonic-gate int 28897c478bd9Sstevel@tonic-gate didmatch(uintptr_t addr, const kthread_t *thr, kt_did_t *didp) 28907c478bd9Sstevel@tonic-gate { 28917c478bd9Sstevel@tonic-gate 28927c478bd9Sstevel@tonic-gate if (*didp == thr->t_did) { 28937c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr); 28947c478bd9Sstevel@tonic-gate return (WALK_DONE); 28957c478bd9Sstevel@tonic-gate } else 28967c478bd9Sstevel@tonic-gate return (WALK_NEXT); 28977c478bd9Sstevel@tonic-gate } 28987c478bd9Sstevel@tonic-gate 28997c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 29007c478bd9Sstevel@tonic-gate int 29017c478bd9Sstevel@tonic-gate did2thread(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 29027c478bd9Sstevel@tonic-gate { 29037c478bd9Sstevel@tonic-gate const mdb_arg_t *argp = &argv[0]; 29047c478bd9Sstevel@tonic-gate kt_did_t did; 29057c478bd9Sstevel@tonic-gate 29067c478bd9Sstevel@tonic-gate if (argc != 1) 29077c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 29087c478bd9Sstevel@tonic-gate 29097c478bd9Sstevel@tonic-gate did = (kt_did_t)mdb_strtoull(argp->a_un.a_str); 29107c478bd9Sstevel@tonic-gate 29117c478bd9Sstevel@tonic-gate if (mdb_walk("thread", (mdb_walk_cb_t)didmatch, (void *)&did) == -1) { 29127c478bd9Sstevel@tonic-gate mdb_warn("failed to walk thread"); 29137c478bd9Sstevel@tonic-gate return (DCMD_ERR); 29147c478bd9Sstevel@tonic-gate 29157c478bd9Sstevel@tonic-gate } 29167c478bd9Sstevel@tonic-gate return (DCMD_OK); 29177c478bd9Sstevel@tonic-gate 29187c478bd9Sstevel@tonic-gate } 29197c478bd9Sstevel@tonic-gate 29207c478bd9Sstevel@tonic-gate static int 29217c478bd9Sstevel@tonic-gate errorq_walk_init(mdb_walk_state_t *wsp) 29227c478bd9Sstevel@tonic-gate { 29237c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL && 29247c478bd9Sstevel@tonic-gate mdb_readvar(&wsp->walk_addr, "errorq_list") == -1) { 29257c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq_list"); 29267c478bd9Sstevel@tonic-gate return (WALK_ERR); 29277c478bd9Sstevel@tonic-gate } 29287c478bd9Sstevel@tonic-gate 29297c478bd9Sstevel@tonic-gate return (WALK_NEXT); 29307c478bd9Sstevel@tonic-gate } 29317c478bd9Sstevel@tonic-gate 29327c478bd9Sstevel@tonic-gate static int 29337c478bd9Sstevel@tonic-gate errorq_walk_step(mdb_walk_state_t *wsp) 29347c478bd9Sstevel@tonic-gate { 29357c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 29367c478bd9Sstevel@tonic-gate errorq_t eq; 29377c478bd9Sstevel@tonic-gate 29387c478bd9Sstevel@tonic-gate if (addr == NULL) 29397c478bd9Sstevel@tonic-gate return (WALK_DONE); 29407c478bd9Sstevel@tonic-gate 29417c478bd9Sstevel@tonic-gate if (mdb_vread(&eq, sizeof (eq), addr) == -1) { 29427c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq at %p", addr); 29437c478bd9Sstevel@tonic-gate return (WALK_ERR); 29447c478bd9Sstevel@tonic-gate } 29457c478bd9Sstevel@tonic-gate 29467c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)eq.eq_next; 29477c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, &eq, wsp->walk_cbdata)); 29487c478bd9Sstevel@tonic-gate } 29497c478bd9Sstevel@tonic-gate 29507c478bd9Sstevel@tonic-gate typedef struct eqd_walk_data { 29517c478bd9Sstevel@tonic-gate uintptr_t *eqd_stack; 29527c478bd9Sstevel@tonic-gate void *eqd_buf; 29537c478bd9Sstevel@tonic-gate ulong_t eqd_qpos; 29547c478bd9Sstevel@tonic-gate ulong_t eqd_qlen; 29557c478bd9Sstevel@tonic-gate size_t eqd_size; 29567c478bd9Sstevel@tonic-gate } eqd_walk_data_t; 29577c478bd9Sstevel@tonic-gate 29587c478bd9Sstevel@tonic-gate /* 29597c478bd9Sstevel@tonic-gate * In order to walk the list of pending error queue elements, we push the 29607c478bd9Sstevel@tonic-gate * addresses of the corresponding data buffers in to the eqd_stack array. 29617c478bd9Sstevel@tonic-gate * The error lists are in reverse chronological order when iterating using 29627c478bd9Sstevel@tonic-gate * eqe_prev, so we then pop things off the top in eqd_walk_step so that the 29637c478bd9Sstevel@tonic-gate * walker client gets addresses in order from oldest error to newest error. 29647c478bd9Sstevel@tonic-gate */ 29657c478bd9Sstevel@tonic-gate static void 29667c478bd9Sstevel@tonic-gate eqd_push_list(eqd_walk_data_t *eqdp, uintptr_t addr) 29677c478bd9Sstevel@tonic-gate { 29687c478bd9Sstevel@tonic-gate errorq_elem_t eqe; 29697c478bd9Sstevel@tonic-gate 29707c478bd9Sstevel@tonic-gate while (addr != NULL) { 29717c478bd9Sstevel@tonic-gate if (mdb_vread(&eqe, sizeof (eqe), addr) != sizeof (eqe)) { 29727c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq element at %p", addr); 29737c478bd9Sstevel@tonic-gate break; 29747c478bd9Sstevel@tonic-gate } 29757c478bd9Sstevel@tonic-gate 29767c478bd9Sstevel@tonic-gate if (eqdp->eqd_qpos == eqdp->eqd_qlen) { 29777c478bd9Sstevel@tonic-gate mdb_warn("errorq is overfull -- more than %lu " 29787c478bd9Sstevel@tonic-gate "elems found\n", eqdp->eqd_qlen); 29797c478bd9Sstevel@tonic-gate break; 29807c478bd9Sstevel@tonic-gate } 29817c478bd9Sstevel@tonic-gate 29827c478bd9Sstevel@tonic-gate eqdp->eqd_stack[eqdp->eqd_qpos++] = (uintptr_t)eqe.eqe_data; 29837c478bd9Sstevel@tonic-gate addr = (uintptr_t)eqe.eqe_prev; 29847c478bd9Sstevel@tonic-gate } 29857c478bd9Sstevel@tonic-gate } 29867c478bd9Sstevel@tonic-gate 29877c478bd9Sstevel@tonic-gate static int 29887c478bd9Sstevel@tonic-gate eqd_walk_init(mdb_walk_state_t *wsp) 29897c478bd9Sstevel@tonic-gate { 29907c478bd9Sstevel@tonic-gate eqd_walk_data_t *eqdp; 29917c478bd9Sstevel@tonic-gate errorq_elem_t eqe, *addr; 29927c478bd9Sstevel@tonic-gate errorq_t eq; 29937c478bd9Sstevel@tonic-gate ulong_t i; 29947c478bd9Sstevel@tonic-gate 29957c478bd9Sstevel@tonic-gate if (mdb_vread(&eq, sizeof (eq), wsp->walk_addr) == -1) { 29967c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq at %p", wsp->walk_addr); 29977c478bd9Sstevel@tonic-gate return (WALK_ERR); 29987c478bd9Sstevel@tonic-gate } 29997c478bd9Sstevel@tonic-gate 30007c478bd9Sstevel@tonic-gate if (eq.eq_ptail != NULL && 30017c478bd9Sstevel@tonic-gate mdb_vread(&eqe, sizeof (eqe), (uintptr_t)eq.eq_ptail) == -1) { 30027c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq element at %p", eq.eq_ptail); 30037c478bd9Sstevel@tonic-gate return (WALK_ERR); 30047c478bd9Sstevel@tonic-gate } 30057c478bd9Sstevel@tonic-gate 30067c478bd9Sstevel@tonic-gate eqdp = mdb_alloc(sizeof (eqd_walk_data_t), UM_SLEEP); 30077c478bd9Sstevel@tonic-gate wsp->walk_data = eqdp; 30087c478bd9Sstevel@tonic-gate 30097c478bd9Sstevel@tonic-gate eqdp->eqd_stack = mdb_zalloc(sizeof (uintptr_t) * eq.eq_qlen, UM_SLEEP); 30107c478bd9Sstevel@tonic-gate eqdp->eqd_buf = mdb_alloc(eq.eq_size, UM_SLEEP); 30117c478bd9Sstevel@tonic-gate eqdp->eqd_qlen = eq.eq_qlen; 30127c478bd9Sstevel@tonic-gate eqdp->eqd_qpos = 0; 30137c478bd9Sstevel@tonic-gate eqdp->eqd_size = eq.eq_size; 30147c478bd9Sstevel@tonic-gate 30157c478bd9Sstevel@tonic-gate /* 30167c478bd9Sstevel@tonic-gate * The newest elements in the queue are on the pending list, so we 30177c478bd9Sstevel@tonic-gate * push those on to our stack first. 30187c478bd9Sstevel@tonic-gate */ 30197c478bd9Sstevel@tonic-gate eqd_push_list(eqdp, (uintptr_t)eq.eq_pend); 30207c478bd9Sstevel@tonic-gate 30217c478bd9Sstevel@tonic-gate /* 30227c478bd9Sstevel@tonic-gate * If eq_ptail is set, it may point to a subset of the errors on the 30237c478bd9Sstevel@tonic-gate * pending list in the event a casptr() failed; if ptail's data is 30247c478bd9Sstevel@tonic-gate * already in our stack, NULL out eq_ptail and ignore it. 30257c478bd9Sstevel@tonic-gate */ 30267c478bd9Sstevel@tonic-gate if (eq.eq_ptail != NULL) { 30277c478bd9Sstevel@tonic-gate for (i = 0; i < eqdp->eqd_qpos; i++) { 30287c478bd9Sstevel@tonic-gate if (eqdp->eqd_stack[i] == (uintptr_t)eqe.eqe_data) { 30297c478bd9Sstevel@tonic-gate eq.eq_ptail = NULL; 30307c478bd9Sstevel@tonic-gate break; 30317c478bd9Sstevel@tonic-gate } 30327c478bd9Sstevel@tonic-gate } 30337c478bd9Sstevel@tonic-gate } 30347c478bd9Sstevel@tonic-gate 30357c478bd9Sstevel@tonic-gate /* 30367c478bd9Sstevel@tonic-gate * If eq_phead is set, it has the processing list in order from oldest 30377c478bd9Sstevel@tonic-gate * to newest. Use this to recompute eq_ptail as best we can and then 30387c478bd9Sstevel@tonic-gate * we nicely fall into eqd_push_list() of eq_ptail below. 30397c478bd9Sstevel@tonic-gate */ 30407c478bd9Sstevel@tonic-gate for (addr = eq.eq_phead; addr != NULL && mdb_vread(&eqe, sizeof (eqe), 30417c478bd9Sstevel@tonic-gate (uintptr_t)addr) == sizeof (eqe); addr = eqe.eqe_next) 30427c478bd9Sstevel@tonic-gate eq.eq_ptail = addr; 30437c478bd9Sstevel@tonic-gate 30447c478bd9Sstevel@tonic-gate /* 30457c478bd9Sstevel@tonic-gate * The oldest elements in the queue are on the processing list, subject 30467c478bd9Sstevel@tonic-gate * to machinations in the if-clauses above. Push any such elements. 30477c478bd9Sstevel@tonic-gate */ 30487c478bd9Sstevel@tonic-gate eqd_push_list(eqdp, (uintptr_t)eq.eq_ptail); 30497c478bd9Sstevel@tonic-gate return (WALK_NEXT); 30507c478bd9Sstevel@tonic-gate } 30517c478bd9Sstevel@tonic-gate 30527c478bd9Sstevel@tonic-gate static int 30537c478bd9Sstevel@tonic-gate eqd_walk_step(mdb_walk_state_t *wsp) 30547c478bd9Sstevel@tonic-gate { 30557c478bd9Sstevel@tonic-gate eqd_walk_data_t *eqdp = wsp->walk_data; 30567c478bd9Sstevel@tonic-gate uintptr_t addr; 30577c478bd9Sstevel@tonic-gate 30587c478bd9Sstevel@tonic-gate if (eqdp->eqd_qpos == 0) 30597c478bd9Sstevel@tonic-gate return (WALK_DONE); 30607c478bd9Sstevel@tonic-gate 30617c478bd9Sstevel@tonic-gate addr = eqdp->eqd_stack[--eqdp->eqd_qpos]; 30627c478bd9Sstevel@tonic-gate 30637c478bd9Sstevel@tonic-gate if (mdb_vread(eqdp->eqd_buf, eqdp->eqd_size, addr) != eqdp->eqd_size) { 30647c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq data at %p", addr); 30657c478bd9Sstevel@tonic-gate return (WALK_ERR); 30667c478bd9Sstevel@tonic-gate } 30677c478bd9Sstevel@tonic-gate 30687c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, eqdp->eqd_buf, wsp->walk_cbdata)); 30697c478bd9Sstevel@tonic-gate } 30707c478bd9Sstevel@tonic-gate 30717c478bd9Sstevel@tonic-gate static void 30727c478bd9Sstevel@tonic-gate eqd_walk_fini(mdb_walk_state_t *wsp) 30737c478bd9Sstevel@tonic-gate { 30747c478bd9Sstevel@tonic-gate eqd_walk_data_t *eqdp = wsp->walk_data; 30757c478bd9Sstevel@tonic-gate 30767c478bd9Sstevel@tonic-gate mdb_free(eqdp->eqd_stack, sizeof (uintptr_t) * eqdp->eqd_qlen); 30777c478bd9Sstevel@tonic-gate mdb_free(eqdp->eqd_buf, eqdp->eqd_size); 30787c478bd9Sstevel@tonic-gate mdb_free(eqdp, sizeof (eqd_walk_data_t)); 30797c478bd9Sstevel@tonic-gate } 30807c478bd9Sstevel@tonic-gate 30817c478bd9Sstevel@tonic-gate #define EQKSVAL(eqv, what) (eqv.eq_kstat.what.value.ui64) 30827c478bd9Sstevel@tonic-gate 30837c478bd9Sstevel@tonic-gate static int 30847c478bd9Sstevel@tonic-gate errorq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 30857c478bd9Sstevel@tonic-gate { 30867c478bd9Sstevel@tonic-gate int i; 30877c478bd9Sstevel@tonic-gate errorq_t eq; 30887c478bd9Sstevel@tonic-gate uint_t opt_v = FALSE; 30897c478bd9Sstevel@tonic-gate 30907c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 30917c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("errorq", "errorq", argc, argv) == -1) { 30927c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'errorq'"); 30937c478bd9Sstevel@tonic-gate return (DCMD_ERR); 30947c478bd9Sstevel@tonic-gate } 30957c478bd9Sstevel@tonic-gate return (DCMD_OK); 30967c478bd9Sstevel@tonic-gate } 30977c478bd9Sstevel@tonic-gate 30987c478bd9Sstevel@tonic-gate i = mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &opt_v, NULL); 30997c478bd9Sstevel@tonic-gate argc -= i; 31007c478bd9Sstevel@tonic-gate argv += i; 31017c478bd9Sstevel@tonic-gate 31027c478bd9Sstevel@tonic-gate if (argc != 0) 31037c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 31047c478bd9Sstevel@tonic-gate 31057c478bd9Sstevel@tonic-gate if (opt_v || DCMD_HDRSPEC(flags)) { 31067c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-11s %-16s %1s %1s %1s ", 31077c478bd9Sstevel@tonic-gate "ADDR", "NAME", "S", "V", "N"); 31087c478bd9Sstevel@tonic-gate if (!opt_v) { 31097c478bd9Sstevel@tonic-gate mdb_printf("%7s %7s %7s%</u>\n", 31107c478bd9Sstevel@tonic-gate "ACCEPT", "DROP", "LOG"); 31117c478bd9Sstevel@tonic-gate } else { 31127c478bd9Sstevel@tonic-gate mdb_printf("%5s %6s %6s %3s %16s%</u>\n", 31137c478bd9Sstevel@tonic-gate "KSTAT", "QLEN", "SIZE", "IPL", "FUNC"); 31147c478bd9Sstevel@tonic-gate } 31157c478bd9Sstevel@tonic-gate } 31167c478bd9Sstevel@tonic-gate 31177c478bd9Sstevel@tonic-gate if (mdb_vread(&eq, sizeof (eq), addr) != sizeof (eq)) { 31187c478bd9Sstevel@tonic-gate mdb_warn("failed to read errorq at %p", addr); 31197c478bd9Sstevel@tonic-gate return (DCMD_ERR); 31207c478bd9Sstevel@tonic-gate } 31217c478bd9Sstevel@tonic-gate 31227c478bd9Sstevel@tonic-gate mdb_printf("%-11p %-16s %c %c %c ", addr, eq.eq_name, 31237c478bd9Sstevel@tonic-gate (eq.eq_flags & ERRORQ_ACTIVE) ? '+' : '-', 31247c478bd9Sstevel@tonic-gate (eq.eq_flags & ERRORQ_VITAL) ? '!' : ' ', 31257c478bd9Sstevel@tonic-gate (eq.eq_flags & ERRORQ_NVLIST) ? '*' : ' '); 31267c478bd9Sstevel@tonic-gate 31277c478bd9Sstevel@tonic-gate if (!opt_v) { 31287c478bd9Sstevel@tonic-gate mdb_printf("%7llu %7llu %7llu\n", 31297c478bd9Sstevel@tonic-gate EQKSVAL(eq, eqk_dispatched) + EQKSVAL(eq, eqk_committed), 31307c478bd9Sstevel@tonic-gate EQKSVAL(eq, eqk_dropped) + EQKSVAL(eq, eqk_reserve_fail) + 31317c478bd9Sstevel@tonic-gate EQKSVAL(eq, eqk_commit_fail), EQKSVAL(eq, eqk_logged)); 31327c478bd9Sstevel@tonic-gate } else { 31337c478bd9Sstevel@tonic-gate mdb_printf("%5s %6lu %6lu %3u %a\n", 31347c478bd9Sstevel@tonic-gate " | ", eq.eq_qlen, eq.eq_size, eq.eq_ipl, eq.eq_func); 31357c478bd9Sstevel@tonic-gate mdb_printf("%38s\n%41s" 31367c478bd9Sstevel@tonic-gate "%12s %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" 31437c478bd9Sstevel@tonic-gate "%53s %llu\n\n", 31447c478bd9Sstevel@tonic-gate "|", "+-> ", 31457c478bd9Sstevel@tonic-gate "DISPATCHED", EQKSVAL(eq, eqk_dispatched), 31467c478bd9Sstevel@tonic-gate "DROPPED", EQKSVAL(eq, eqk_dropped), 31477c478bd9Sstevel@tonic-gate "LOGGED", EQKSVAL(eq, eqk_logged), 31487c478bd9Sstevel@tonic-gate "RESERVED", EQKSVAL(eq, eqk_reserved), 31497c478bd9Sstevel@tonic-gate "RESERVE FAIL", EQKSVAL(eq, eqk_reserve_fail), 31507c478bd9Sstevel@tonic-gate "COMMITTED", EQKSVAL(eq, eqk_committed), 31517c478bd9Sstevel@tonic-gate "COMMIT FAIL", EQKSVAL(eq, eqk_commit_fail), 31527c478bd9Sstevel@tonic-gate "CANCELLED", EQKSVAL(eq, eqk_cancelled)); 31537c478bd9Sstevel@tonic-gate } 31547c478bd9Sstevel@tonic-gate 31557c478bd9Sstevel@tonic-gate return (DCMD_OK); 31567c478bd9Sstevel@tonic-gate } 31577c478bd9Sstevel@tonic-gate 31587c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 31597c478bd9Sstevel@tonic-gate static int 31607c478bd9Sstevel@tonic-gate panicinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 31617c478bd9Sstevel@tonic-gate { 31627c478bd9Sstevel@tonic-gate cpu_t panic_cpu; 31637c478bd9Sstevel@tonic-gate kthread_t *panic_thread; 31647c478bd9Sstevel@tonic-gate void *panicbuf; 31657c478bd9Sstevel@tonic-gate panic_data_t *pd; 31667c478bd9Sstevel@tonic-gate int i, n; 31677c478bd9Sstevel@tonic-gate 31687c478bd9Sstevel@tonic-gate if (!mdb_prop_postmortem) { 31697c478bd9Sstevel@tonic-gate mdb_warn("panicinfo can only be run on a system " 31707c478bd9Sstevel@tonic-gate "dump; see dumpadm(1M)\n"); 31717c478bd9Sstevel@tonic-gate return (DCMD_ERR); 31727c478bd9Sstevel@tonic-gate } 31737c478bd9Sstevel@tonic-gate 31747c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC || argc != 0) 31757c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 31767c478bd9Sstevel@tonic-gate 31777c478bd9Sstevel@tonic-gate if (mdb_readsym(&panic_cpu, sizeof (cpu_t), "panic_cpu") == -1) 31787c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'panic_cpu'"); 31797c478bd9Sstevel@tonic-gate else 31807c478bd9Sstevel@tonic-gate mdb_printf("%16s %?d\n", "cpu", panic_cpu.cpu_id); 31817c478bd9Sstevel@tonic-gate 31827c478bd9Sstevel@tonic-gate if (mdb_readvar(&panic_thread, "panic_thread") == -1) 31837c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'panic_thread'"); 31847c478bd9Sstevel@tonic-gate else 31857c478bd9Sstevel@tonic-gate mdb_printf("%16s %?p\n", "thread", panic_thread); 31867c478bd9Sstevel@tonic-gate 31877c478bd9Sstevel@tonic-gate panicbuf = mdb_alloc(PANICBUFSIZE, UM_SLEEP); 31887c478bd9Sstevel@tonic-gate pd = (panic_data_t *)panicbuf; 31897c478bd9Sstevel@tonic-gate 31907c478bd9Sstevel@tonic-gate if (mdb_readsym(panicbuf, PANICBUFSIZE, "panicbuf") == -1 || 31917c478bd9Sstevel@tonic-gate pd->pd_version != PANICBUFVERS) { 31927c478bd9Sstevel@tonic-gate mdb_warn("failed to read 'panicbuf'"); 31937c478bd9Sstevel@tonic-gate mdb_free(panicbuf, PANICBUFSIZE); 31947c478bd9Sstevel@tonic-gate return (DCMD_ERR); 31957c478bd9Sstevel@tonic-gate } 31967c478bd9Sstevel@tonic-gate 31977c478bd9Sstevel@tonic-gate mdb_printf("%16s %s\n", "message", (char *)panicbuf + pd->pd_msgoff); 31987c478bd9Sstevel@tonic-gate 31997c478bd9Sstevel@tonic-gate n = (pd->pd_msgoff - (sizeof (panic_data_t) - 32007c478bd9Sstevel@tonic-gate sizeof (panic_nv_t))) / sizeof (panic_nv_t); 32017c478bd9Sstevel@tonic-gate 32027c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) 32037c478bd9Sstevel@tonic-gate mdb_printf("%16s %?llx\n", 32047c478bd9Sstevel@tonic-gate pd->pd_nvdata[i].pnv_name, pd->pd_nvdata[i].pnv_value); 32057c478bd9Sstevel@tonic-gate 32067c478bd9Sstevel@tonic-gate mdb_free(panicbuf, PANICBUFSIZE); 32077c478bd9Sstevel@tonic-gate return (DCMD_OK); 32087c478bd9Sstevel@tonic-gate } 32097c478bd9Sstevel@tonic-gate 32107c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 32117c478bd9Sstevel@tonic-gate 32127c478bd9Sstevel@tonic-gate /* from genunix.c */ 32137c478bd9Sstevel@tonic-gate { "addr2smap", ":[offset]", "translate address to smap", addr2smap }, 32147c478bd9Sstevel@tonic-gate { "as2proc", ":", "convert as to proc_t address", as2proc }, 32157c478bd9Sstevel@tonic-gate { "binding_hash_entry", ":", "print driver names hash table entry", 32167c478bd9Sstevel@tonic-gate binding_hash_entry }, 32177c478bd9Sstevel@tonic-gate { "callout", NULL, "print callout table", callout }, 32187c478bd9Sstevel@tonic-gate { "class", NULL, "print process scheduler classes", class }, 32197c478bd9Sstevel@tonic-gate { "cpuinfo", "?[-v]", "print CPUs and runnable threads", cpuinfo }, 32207c478bd9Sstevel@tonic-gate { "did2thread", "? kt_did", "find kernel thread for this id", 32217c478bd9Sstevel@tonic-gate did2thread }, 32227c478bd9Sstevel@tonic-gate { "errorq", "?[-v]", "display kernel error queues", errorq }, 32237c478bd9Sstevel@tonic-gate { "fd", ":[fd num]", "get a file pointer from an fd", fd }, 32247c478bd9Sstevel@tonic-gate { "flipone", ":", "the vik_rev_level 2 special", flipone }, 32257c478bd9Sstevel@tonic-gate { "lminfo", NULL, "print lock manager information", lminfo }, 32267c478bd9Sstevel@tonic-gate { "ndi_event_hdl", "?", "print ndi_event_hdl", ndi_event_hdl }, 32277c478bd9Sstevel@tonic-gate { "panicinfo", NULL, "print panic information", panicinfo }, 32287c478bd9Sstevel@tonic-gate { "pid2proc", "?", "convert PID to proc_t address", pid2proc }, 32297c478bd9Sstevel@tonic-gate { "pmap", ":[-q]", "print process memory map", pmap }, 32307c478bd9Sstevel@tonic-gate { "project", NULL, "display kernel project(s)", project }, 32317c478bd9Sstevel@tonic-gate { "ps", "[-fltzTP]", "list processes (and associated thr,lwp)", ps }, 3232*adb664e2Svb { "pgrep", "[-x] [-n | -o] pattern", 3233*adb664e2Svb "pattern match against all processes", pgrep }, 32347c478bd9Sstevel@tonic-gate { "ptree", NULL, "print process tree", ptree }, 32357c478bd9Sstevel@tonic-gate { "seg", ":", "print address space segment", seg }, 32367c478bd9Sstevel@tonic-gate { "sysevent", "?[-sv]", "print sysevent pending or sent queue", 32377c478bd9Sstevel@tonic-gate sysevent}, 32387c478bd9Sstevel@tonic-gate { "sysevent_channel", "?", "print sysevent channel database", 32397c478bd9Sstevel@tonic-gate sysevent_channel}, 32407c478bd9Sstevel@tonic-gate { "sysevent_class_list", ":", "print sysevent class list", 32417c478bd9Sstevel@tonic-gate sysevent_class_list}, 32427c478bd9Sstevel@tonic-gate { "sysevent_subclass_list", ":", 32437c478bd9Sstevel@tonic-gate "print sysevent subclass list", sysevent_subclass_list}, 32447c478bd9Sstevel@tonic-gate { "system", NULL, "print contents of /etc/system file", sysfile }, 32457c478bd9Sstevel@tonic-gate { "task", NULL, "display kernel task(s)", task }, 32467c478bd9Sstevel@tonic-gate { "taskq_entry", ":", "display a taskq_ent_t", taskq_ent }, 32477c478bd9Sstevel@tonic-gate { "vnode2path", ":[-F]", "vnode address to pathname", vnode2path }, 32487c478bd9Sstevel@tonic-gate { "vnode2smap", ":[offset]", "translate vnode to smap", vnode2smap }, 32497c478bd9Sstevel@tonic-gate { "whereopen", ":", "given a vnode, dumps procs which have it open", 32507c478bd9Sstevel@tonic-gate whereopen }, 32517c478bd9Sstevel@tonic-gate 32527c478bd9Sstevel@tonic-gate /* from zone.c */ 32537c478bd9Sstevel@tonic-gate { "zone", "?", "display kernel zone(s)", zoneprt }, 32547c478bd9Sstevel@tonic-gate { "zsd", ":[zsd key]", "lookup zsd value from a key", zsd }, 32557c478bd9Sstevel@tonic-gate 32567c478bd9Sstevel@tonic-gate /* from bio.c */ 32577c478bd9Sstevel@tonic-gate { "bufpagefind", ":addr", "find page_t on buf_t list", bufpagefind }, 32587c478bd9Sstevel@tonic-gate 32597c478bd9Sstevel@tonic-gate /* from contract.c */ 32607c478bd9Sstevel@tonic-gate { "contract", "?", "display a contract", cmd_contract }, 32617c478bd9Sstevel@tonic-gate { "ctevent", ":", "display a contract event", cmd_ctevent }, 32627c478bd9Sstevel@tonic-gate { "ctid", ":", "convert id to a contract pointer", cmd_ctid }, 32637c478bd9Sstevel@tonic-gate 32647c478bd9Sstevel@tonic-gate /* from cpupart.c */ 3265f5533078Smishra { "cpupart", "?[-v]", "print cpu partition info", cpupart }, 32667c478bd9Sstevel@tonic-gate 32677c478bd9Sstevel@tonic-gate /* from cyclic.c */ 32687c478bd9Sstevel@tonic-gate { "cyccover", NULL, "dump cyclic coverage information", cyccover }, 32697c478bd9Sstevel@tonic-gate { "cycid", "?", "dump a cyclic id", cycid }, 32707c478bd9Sstevel@tonic-gate { "cycinfo", "?", "dump cyc_cpu info", cycinfo }, 32717c478bd9Sstevel@tonic-gate { "cyclic", ":", "developer information", cyclic }, 32727c478bd9Sstevel@tonic-gate { "cyctrace", "?", "dump cyclic trace buffer", cyctrace }, 32737c478bd9Sstevel@tonic-gate 32747c478bd9Sstevel@tonic-gate /* from devinfo.c */ 32757c478bd9Sstevel@tonic-gate { "devbindings", "?[-qs] [device-name | major-num]", 32767c478bd9Sstevel@tonic-gate "print devinfo nodes bound to device-name or major-num", 32777c478bd9Sstevel@tonic-gate devbindings, devinfo_help }, 32787c478bd9Sstevel@tonic-gate { "devinfo", ":[-qs]", "detailed devinfo of one node", devinfo, 32797c478bd9Sstevel@tonic-gate devinfo_help }, 32807c478bd9Sstevel@tonic-gate { "devinfo_audit", ":[-v]", "devinfo configuration audit record", 32817c478bd9Sstevel@tonic-gate devinfo_audit }, 32827c478bd9Sstevel@tonic-gate { "devinfo_audit_log", "?[-v]", "system wide devinfo configuration log", 32837c478bd9Sstevel@tonic-gate devinfo_audit_log }, 32847c478bd9Sstevel@tonic-gate { "devinfo_audit_node", ":[-v]", "devinfo node configuration history", 32857c478bd9Sstevel@tonic-gate devinfo_audit_node }, 32867c478bd9Sstevel@tonic-gate { "devinfo2driver", ":", "find driver name for this devinfo node", 32877c478bd9Sstevel@tonic-gate devinfo2driver }, 32887c478bd9Sstevel@tonic-gate { "devnames", "?[-vm] [num]", "print devnames array", devnames }, 32897c478bd9Sstevel@tonic-gate { "dev2major", "?<dev_t>", "convert dev_t to a major number", 32907c478bd9Sstevel@tonic-gate dev2major }, 32917c478bd9Sstevel@tonic-gate { "dev2minor", "?<dev_t>", "convert dev_t to a minor number", 32927c478bd9Sstevel@tonic-gate dev2minor }, 32937c478bd9Sstevel@tonic-gate { "devt", "?<dev_t>", "display a dev_t's major and minor numbers", 32947c478bd9Sstevel@tonic-gate devt }, 32957c478bd9Sstevel@tonic-gate { "major2name", "?<major-num>", "convert major number to dev name", 32967c478bd9Sstevel@tonic-gate major2name }, 32977c478bd9Sstevel@tonic-gate { "minornodes", ":", "given a devinfo node, print its minor nodes", 32987c478bd9Sstevel@tonic-gate minornodes }, 32997c478bd9Sstevel@tonic-gate { "modctl2devinfo", ":", "given a modctl, list its devinfos", 33007c478bd9Sstevel@tonic-gate modctl2devinfo }, 33017c478bd9Sstevel@tonic-gate { "name2major", "<dev-name>", "convert dev name to major number", 33027c478bd9Sstevel@tonic-gate name2major }, 33037c478bd9Sstevel@tonic-gate { "prtconf", "?[-vpc]", "print devinfo tree", prtconf, prtconf_help }, 33047c478bd9Sstevel@tonic-gate { "softstate", ":<instance>", "retrieve soft-state pointer", 33057c478bd9Sstevel@tonic-gate softstate }, 33067c478bd9Sstevel@tonic-gate { "devinfo_fm", ":", "devinfo fault managment configuration", 33077c478bd9Sstevel@tonic-gate devinfo_fm }, 33087c478bd9Sstevel@tonic-gate { "devinfo_fmce", ":", "devinfo fault managment cache entry", 33097c478bd9Sstevel@tonic-gate devinfo_fmce}, 33107c478bd9Sstevel@tonic-gate 33117c478bd9Sstevel@tonic-gate /* from findstack.c */ 33127c478bd9Sstevel@tonic-gate { "findstack", ":[-v]", "find kernel thread stack", findstack }, 33137c478bd9Sstevel@tonic-gate { "findstack_debug", NULL, "toggle findstack debugging", 33147c478bd9Sstevel@tonic-gate findstack_debug }, 33157c478bd9Sstevel@tonic-gate 33167c478bd9Sstevel@tonic-gate /* from kgrep.c + genunix.c */ 33177c478bd9Sstevel@tonic-gate { "kgrep", KGREP_USAGE, "search kernel as for a pointer", kgrep }, 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