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