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 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #include <mdb/mdb_param.h> 27 #include <mdb/mdb_modapi.h> 28 #include <mdb/mdb_ks.h> 29 #include <mdb/mdb_ctf.h> 30 31 #include <sys/types.h> 32 #include <sys/thread.h> 33 #include <sys/session.h> 34 #include <sys/user.h> 35 #include <sys/proc.h> 36 #include <sys/var.h> 37 #include <sys/t_lock.h> 38 #include <sys/systm.h> 39 #include <sys/callo.h> 40 #include <sys/priocntl.h> 41 #include <sys/class.h> 42 #include <sys/regset.h> 43 #include <sys/stack.h> 44 #include <sys/cpuvar.h> 45 #include <sys/vnode.h> 46 #include <sys/vfs.h> 47 #include <sys/flock_impl.h> 48 #include <sys/kmem_impl.h> 49 #include <sys/vmem_impl.h> 50 #include <sys/kstat.h> 51 #include <vm/seg_vn.h> 52 #include <vm/anon.h> 53 #include <vm/as.h> 54 #include <vm/seg_map.h> 55 #include <sys/dditypes.h> 56 #include <sys/ddi_impldefs.h> 57 #include <sys/sysmacros.h> 58 #include <sys/sysconf.h> 59 #include <sys/task.h> 60 #include <sys/project.h> 61 #include <sys/taskq.h> 62 #include <sys/taskq_impl.h> 63 #include <sys/errorq_impl.h> 64 #include <sys/cred_impl.h> 65 #include <sys/zone.h> 66 #include <sys/panic.h> 67 #include <regex.h> 68 #include <sys/port_impl.h> 69 70 #include "avl.h" 71 #include "combined.h" 72 #include "contract.h" 73 #include "cpupart_mdb.h" 74 #include "devinfo.h" 75 #include "irm.h" 76 #include "leaky.h" 77 #include "lgrp.h" 78 #include "pg.h" 79 #include "group.h" 80 #include "list.h" 81 #include "log.h" 82 #include "kgrep.h" 83 #include "kmem.h" 84 #include "bio.h" 85 #include "streams.h" 86 #include "cyclic.h" 87 #include "findstack.h" 88 #include "ndievents.h" 89 #include "mmd.h" 90 #include "net.h" 91 #include "netstack.h" 92 #include "nvpair.h" 93 #include "ctxop.h" 94 #include "tsd.h" 95 #include "thread.h" 96 #include "memory.h" 97 #include "sobj.h" 98 #include "sysevent.h" 99 #include "rctl.h" 100 #include "tsol.h" 101 #include "typegraph.h" 102 #include "ldi.h" 103 #include "vfs.h" 104 #include "zone.h" 105 #include "modhash.h" 106 #include "mdi.h" 107 #include "fm.h" 108 109 /* 110 * Surely this is defined somewhere... 111 */ 112 #define NINTR 16 113 114 #define KILOS 10 115 #define MEGS 20 116 #define GIGS 30 117 118 #ifndef STACK_BIAS 119 #define STACK_BIAS 0 120 #endif 121 122 static char 123 pstat2ch(uchar_t state) 124 { 125 switch (state) { 126 case SSLEEP: return ('S'); 127 case SRUN: return ('R'); 128 case SZOMB: return ('Z'); 129 case SIDL: return ('I'); 130 case SONPROC: return ('O'); 131 case SSTOP: return ('T'); 132 case SWAIT: return ('W'); 133 default: return ('?'); 134 } 135 } 136 137 #define PS_PRTTHREADS 0x1 138 #define PS_PRTLWPS 0x2 139 #define PS_PSARGS 0x4 140 #define PS_TASKS 0x8 141 #define PS_PROJECTS 0x10 142 #define PS_ZONES 0x20 143 144 static int 145 ps_threadprint(uintptr_t addr, const void *data, void *private) 146 { 147 const kthread_t *t = (const kthread_t *)data; 148 uint_t prt_flags = *((uint_t *)private); 149 150 static const mdb_bitmask_t t_state_bits[] = { 151 { "TS_FREE", UINT_MAX, TS_FREE }, 152 { "TS_SLEEP", TS_SLEEP, TS_SLEEP }, 153 { "TS_RUN", TS_RUN, TS_RUN }, 154 { "TS_ONPROC", TS_ONPROC, TS_ONPROC }, 155 { "TS_ZOMB", TS_ZOMB, TS_ZOMB }, 156 { "TS_STOPPED", TS_STOPPED, TS_STOPPED }, 157 { "TS_WAIT", TS_WAIT, TS_WAIT }, 158 { NULL, 0, 0 } 159 }; 160 161 if (prt_flags & PS_PRTTHREADS) 162 mdb_printf("\tT %?a <%b>\n", addr, t->t_state, t_state_bits); 163 164 if (prt_flags & PS_PRTLWPS) 165 mdb_printf("\tL %?a ID: %u\n", t->t_lwp, t->t_tid); 166 167 return (WALK_NEXT); 168 } 169 170 int 171 ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 172 { 173 uint_t prt_flags = 0; 174 proc_t pr; 175 struct pid pid, pgid, sid; 176 sess_t session; 177 cred_t cred; 178 task_t tk; 179 kproject_t pj; 180 zone_t zn; 181 182 if (!(flags & DCMD_ADDRSPEC)) { 183 if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) { 184 mdb_warn("can't walk 'proc'"); 185 return (DCMD_ERR); 186 } 187 return (DCMD_OK); 188 } 189 190 if (mdb_getopts(argc, argv, 191 'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags, 192 'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags, 193 'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags, 194 'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags, 195 'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags, 196 't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc) 197 return (DCMD_USAGE); 198 199 if (DCMD_HDRSPEC(flags)) { 200 mdb_printf("%<u>%1s %6s %6s %6s %6s ", 201 "S", "PID", "PPID", "PGID", "SID"); 202 if (prt_flags & PS_TASKS) 203 mdb_printf("%5s ", "TASK"); 204 if (prt_flags & PS_PROJECTS) 205 mdb_printf("%5s ", "PROJ"); 206 if (prt_flags & PS_ZONES) 207 mdb_printf("%5s ", "ZONE"); 208 mdb_printf("%6s %10s %?s %s%</u>\n", 209 "UID", "FLAGS", "ADDR", "NAME"); 210 } 211 212 mdb_vread(&pr, sizeof (pr), addr); 213 mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp); 214 mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp); 215 mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred); 216 mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp); 217 mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp); 218 if (prt_flags & (PS_TASKS | PS_PROJECTS)) 219 mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task); 220 if (prt_flags & PS_PROJECTS) 221 mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj); 222 if (prt_flags & PS_ZONES) 223 mdb_vread(&zn, sizeof (zone_t), (uintptr_t)pr.p_zone); 224 225 mdb_printf("%c %6d %6d %6d %6d ", 226 pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id, 227 sid.pid_id); 228 if (prt_flags & PS_TASKS) 229 mdb_printf("%5d ", tk.tk_tkid); 230 if (prt_flags & PS_PROJECTS) 231 mdb_printf("%5d ", pj.kpj_id); 232 if (prt_flags & PS_ZONES) 233 mdb_printf("%5d ", zn.zone_id); 234 mdb_printf("%6d 0x%08x %0?p %s\n", 235 cred.cr_uid, pr.p_flag, addr, 236 (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm); 237 238 if (prt_flags & ~PS_PSARGS) 239 (void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr); 240 241 return (DCMD_OK); 242 } 243 244 #define PG_NEWEST 0x0001 245 #define PG_OLDEST 0x0002 246 #define PG_PIPE_OUT 0x0004 247 #define PG_EXACT_MATCH 0x0008 248 249 typedef struct pgrep_data { 250 uint_t pg_flags; 251 uint_t pg_psflags; 252 uintptr_t pg_xaddr; 253 hrtime_t pg_xstart; 254 const char *pg_pat; 255 #ifndef _KMDB 256 regex_t pg_reg; 257 #endif 258 } pgrep_data_t; 259 260 /*ARGSUSED*/ 261 static int 262 pgrep_cb(uintptr_t addr, const void *pdata, void *data) 263 { 264 const proc_t *prp = pdata; 265 pgrep_data_t *pgp = data; 266 #ifndef _KMDB 267 regmatch_t pmatch; 268 #endif 269 270 /* 271 * kmdb doesn't have access to the reg* functions, so we fall back 272 * to strstr/strcmp. 273 */ 274 #ifdef _KMDB 275 if ((pgp->pg_flags & PG_EXACT_MATCH) ? 276 (strcmp(prp->p_user.u_comm, pgp->pg_pat) != 0) : 277 (strstr(prp->p_user.u_comm, pgp->pg_pat) == NULL)) 278 return (WALK_NEXT); 279 #else 280 if (regexec(&pgp->pg_reg, prp->p_user.u_comm, 1, &pmatch, 0) != 0) 281 return (WALK_NEXT); 282 283 if ((pgp->pg_flags & PG_EXACT_MATCH) && 284 (pmatch.rm_so != 0 || prp->p_user.u_comm[pmatch.rm_eo] != '\0')) 285 return (WALK_NEXT); 286 #endif 287 288 if (pgp->pg_flags & (PG_NEWEST | PG_OLDEST)) { 289 hrtime_t start; 290 291 start = (hrtime_t)prp->p_user.u_start.tv_sec * NANOSEC + 292 prp->p_user.u_start.tv_nsec; 293 294 if (pgp->pg_flags & PG_NEWEST) { 295 if (pgp->pg_xaddr == NULL || start > pgp->pg_xstart) { 296 pgp->pg_xaddr = addr; 297 pgp->pg_xstart = start; 298 } 299 } else { 300 if (pgp->pg_xaddr == NULL || start < pgp->pg_xstart) { 301 pgp->pg_xaddr = addr; 302 pgp->pg_xstart = start; 303 } 304 } 305 306 } else if (pgp->pg_flags & PG_PIPE_OUT) { 307 mdb_printf("%p\n", addr); 308 309 } else { 310 if (mdb_call_dcmd("ps", addr, pgp->pg_psflags, 0, NULL) != 0) { 311 mdb_warn("can't invoke 'ps'"); 312 return (WALK_DONE); 313 } 314 pgp->pg_psflags &= ~DCMD_LOOPFIRST; 315 } 316 317 return (WALK_NEXT); 318 } 319 320 /*ARGSUSED*/ 321 int 322 pgrep(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 323 { 324 pgrep_data_t pg; 325 int i; 326 #ifndef _KMDB 327 int err; 328 #endif 329 330 if (flags & DCMD_ADDRSPEC) 331 return (DCMD_USAGE); 332 333 pg.pg_flags = 0; 334 pg.pg_xaddr = 0; 335 336 i = mdb_getopts(argc, argv, 337 'n', MDB_OPT_SETBITS, PG_NEWEST, &pg.pg_flags, 338 'o', MDB_OPT_SETBITS, PG_OLDEST, &pg.pg_flags, 339 'x', MDB_OPT_SETBITS, PG_EXACT_MATCH, &pg.pg_flags, 340 NULL); 341 342 argc -= i; 343 argv += i; 344 345 if (argc != 1) 346 return (DCMD_USAGE); 347 348 /* 349 * -n and -o are mutually exclusive. 350 */ 351 if ((pg.pg_flags & PG_NEWEST) && (pg.pg_flags & PG_OLDEST)) 352 return (DCMD_USAGE); 353 354 if (argv->a_type != MDB_TYPE_STRING) 355 return (DCMD_USAGE); 356 357 if (flags & DCMD_PIPE_OUT) 358 pg.pg_flags |= PG_PIPE_OUT; 359 360 pg.pg_pat = argv->a_un.a_str; 361 if (DCMD_HDRSPEC(flags)) 362 pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP | DCMD_LOOPFIRST; 363 else 364 pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP; 365 366 #ifndef _KMDB 367 if ((err = regcomp(&pg.pg_reg, pg.pg_pat, REG_EXTENDED)) != 0) { 368 size_t nbytes; 369 char *buf; 370 371 nbytes = regerror(err, &pg.pg_reg, NULL, 0); 372 buf = mdb_alloc(nbytes + 1, UM_SLEEP | UM_GC); 373 (void) regerror(err, &pg.pg_reg, buf, nbytes); 374 mdb_warn("%s\n", buf); 375 376 return (DCMD_ERR); 377 } 378 #endif 379 380 if (mdb_walk("proc", pgrep_cb, &pg) != 0) { 381 mdb_warn("can't walk 'proc'"); 382 return (DCMD_ERR); 383 } 384 385 if (pg.pg_xaddr != 0 && (pg.pg_flags & (PG_NEWEST | PG_OLDEST))) { 386 if (pg.pg_flags & PG_PIPE_OUT) { 387 mdb_printf("%p\n", pg.pg_xaddr); 388 } else { 389 if (mdb_call_dcmd("ps", pg.pg_xaddr, pg.pg_psflags, 390 0, NULL) != 0) { 391 mdb_warn("can't invoke 'ps'"); 392 return (DCMD_ERR); 393 } 394 } 395 } 396 397 return (DCMD_OK); 398 } 399 400 int 401 task(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 402 { 403 task_t tk; 404 kproject_t pj; 405 406 if (!(flags & DCMD_ADDRSPEC)) { 407 if (mdb_walk_dcmd("task_cache", "task", argc, argv) == -1) { 408 mdb_warn("can't walk task_cache"); 409 return (DCMD_ERR); 410 } 411 return (DCMD_OK); 412 } 413 if (DCMD_HDRSPEC(flags)) { 414 mdb_printf("%<u>%?s %6s %6s %6s %6s %10s%</u>\n", 415 "ADDR", "TASKID", "PROJID", "ZONEID", "REFCNT", "FLAGS"); 416 } 417 if (mdb_vread(&tk, sizeof (task_t), addr) == -1) { 418 mdb_warn("can't read task_t structure at %p", addr); 419 return (DCMD_ERR); 420 } 421 if (mdb_vread(&pj, sizeof (kproject_t), (uintptr_t)tk.tk_proj) == -1) { 422 mdb_warn("can't read project_t structure at %p", addr); 423 return (DCMD_ERR); 424 } 425 mdb_printf("%0?p %6d %6d %6d %6u 0x%08x\n", 426 addr, tk.tk_tkid, pj.kpj_id, pj.kpj_zoneid, tk.tk_hold_count, 427 tk.tk_flags); 428 return (DCMD_OK); 429 } 430 431 int 432 project(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 433 { 434 kproject_t pj; 435 436 if (!(flags & DCMD_ADDRSPEC)) { 437 if (mdb_walk_dcmd("projects", "project", argc, argv) == -1) { 438 mdb_warn("can't walk projects"); 439 return (DCMD_ERR); 440 } 441 return (DCMD_OK); 442 } 443 if (DCMD_HDRSPEC(flags)) { 444 mdb_printf("%<u>%?s %6s %6s %6s%</u>\n", 445 "ADDR", "PROJID", "ZONEID", "REFCNT"); 446 } 447 if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) { 448 mdb_warn("can't read kproject_t structure at %p", addr); 449 return (DCMD_ERR); 450 } 451 mdb_printf("%0?p %6d %6d %6u\n", addr, pj.kpj_id, pj.kpj_zoneid, 452 pj.kpj_count); 453 return (DCMD_OK); 454 } 455 456 /* walk callouts themselves, either by list or id hash. */ 457 int 458 callout_walk_init(mdb_walk_state_t *wsp) 459 { 460 if (wsp->walk_addr == NULL) { 461 mdb_warn("callout doesn't support global walk"); 462 return (WALK_ERR); 463 } 464 wsp->walk_data = mdb_alloc(sizeof (callout_t), UM_SLEEP); 465 return (WALK_NEXT); 466 } 467 468 #define CALLOUT_WALK_BYLIST 0 469 #define CALLOUT_WALK_BYID 1 470 471 /* the walker arg switches between walking by list (0) and walking by id (1). */ 472 int 473 callout_walk_step(mdb_walk_state_t *wsp) 474 { 475 int retval; 476 477 if (wsp->walk_addr == NULL) { 478 return (WALK_DONE); 479 } 480 if (mdb_vread(wsp->walk_data, sizeof (callout_t), 481 wsp->walk_addr) == -1) { 482 mdb_warn("failed to read callout at %p", wsp->walk_addr); 483 return (WALK_DONE); 484 } 485 retval = wsp->walk_callback(wsp->walk_addr, wsp->walk_data, 486 wsp->walk_cbdata); 487 488 if ((ulong_t)wsp->walk_arg == CALLOUT_WALK_BYID) { 489 wsp->walk_addr = 490 (uintptr_t)(((callout_t *)wsp->walk_data)->c_idnext); 491 } else { 492 wsp->walk_addr = 493 (uintptr_t)(((callout_t *)wsp->walk_data)->c_clnext); 494 } 495 496 return (retval); 497 } 498 499 void 500 callout_walk_fini(mdb_walk_state_t *wsp) 501 { 502 mdb_free(wsp->walk_data, sizeof (callout_t)); 503 } 504 505 /* 506 * walker for callout lists. This is different from hashes and callouts. 507 * Thankfully, it's also simpler. 508 */ 509 int 510 callout_list_walk_init(mdb_walk_state_t *wsp) 511 { 512 if (wsp->walk_addr == NULL) { 513 mdb_warn("callout list doesn't support global walk"); 514 return (WALK_ERR); 515 } 516 wsp->walk_data = mdb_alloc(sizeof (callout_list_t), UM_SLEEP); 517 return (WALK_NEXT); 518 } 519 520 int 521 callout_list_walk_step(mdb_walk_state_t *wsp) 522 { 523 int retval; 524 525 if (wsp->walk_addr == NULL) { 526 return (WALK_DONE); 527 } 528 if (mdb_vread(wsp->walk_data, sizeof (callout_list_t), 529 wsp->walk_addr) != sizeof (callout_list_t)) { 530 mdb_warn("failed to read callout_list at %p", wsp->walk_addr); 531 return (WALK_ERR); 532 } 533 retval = wsp->walk_callback(wsp->walk_addr, wsp->walk_data, 534 wsp->walk_cbdata); 535 536 wsp->walk_addr = (uintptr_t) 537 (((callout_list_t *)wsp->walk_data)->cl_next); 538 539 return (retval); 540 } 541 542 void 543 callout_list_walk_fini(mdb_walk_state_t *wsp) 544 { 545 mdb_free(wsp->walk_data, sizeof (callout_list_t)); 546 } 547 548 /* routines/structs to walk callout table(s) */ 549 typedef struct cot_data { 550 callout_table_t *ct0; 551 callout_table_t ct; 552 callout_hash_t cot_idhash[CALLOUT_BUCKETS]; 553 callout_hash_t cot_clhash[CALLOUT_BUCKETS]; 554 kstat_named_t ct_kstat_data[CALLOUT_NUM_STATS]; 555 int cotndx; 556 int cotsize; 557 } cot_data_t; 558 559 int 560 callout_table_walk_init(mdb_walk_state_t *wsp) 561 { 562 int max_ncpus; 563 cot_data_t *cot_walk_data; 564 565 cot_walk_data = mdb_alloc(sizeof (cot_data_t), UM_SLEEP); 566 567 if (wsp->walk_addr == NULL) { 568 if (mdb_readvar(&cot_walk_data->ct0, "callout_table") == -1) { 569 mdb_warn("failed to read 'callout_table'"); 570 return (WALK_ERR); 571 } 572 if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) { 573 mdb_warn("failed to get callout_table array size"); 574 return (WALK_ERR); 575 } 576 cot_walk_data->cotsize = CALLOUT_NTYPES * max_ncpus; 577 wsp->walk_addr = (uintptr_t)cot_walk_data->ct0; 578 } else { 579 /* not a global walk */ 580 cot_walk_data->cotsize = 1; 581 } 582 583 cot_walk_data->cotndx = 0; 584 wsp->walk_data = cot_walk_data; 585 586 return (WALK_NEXT); 587 } 588 589 int 590 callout_table_walk_step(mdb_walk_state_t *wsp) 591 { 592 int retval; 593 cot_data_t *cotwd = (cot_data_t *)wsp->walk_data; 594 size_t size; 595 596 if (cotwd->cotndx >= cotwd->cotsize) { 597 return (WALK_DONE); 598 } 599 if (mdb_vread(&(cotwd->ct), sizeof (callout_table_t), 600 wsp->walk_addr) != sizeof (callout_table_t)) { 601 mdb_warn("failed to read callout_table at %p", wsp->walk_addr); 602 return (WALK_ERR); 603 } 604 605 size = sizeof (callout_hash_t) * CALLOUT_BUCKETS; 606 if (cotwd->ct.ct_idhash != NULL) { 607 if (mdb_vread(cotwd->cot_idhash, size, 608 (uintptr_t)(cotwd->ct.ct_idhash)) != size) { 609 mdb_warn("failed to read id_hash at %p", 610 cotwd->ct.ct_idhash); 611 return (WALK_ERR); 612 } 613 } 614 if (cotwd->ct.ct_clhash != NULL) { 615 if (mdb_vread(&(cotwd->cot_clhash), size, 616 (uintptr_t)cotwd->ct.ct_clhash) == -1) { 617 mdb_warn("failed to read cl_hash at %p", 618 cotwd->ct.ct_clhash); 619 return (WALK_ERR); 620 } 621 } 622 size = sizeof (kstat_named_t) * CALLOUT_NUM_STATS; 623 if (cotwd->ct.ct_kstat_data != NULL) { 624 if (mdb_vread(&(cotwd->ct_kstat_data), size, 625 (uintptr_t)cotwd->ct.ct_kstat_data) == -1) { 626 mdb_warn("failed to read kstats at %p", 627 cotwd->ct.ct_kstat_data); 628 return (WALK_ERR); 629 } 630 } 631 retval = wsp->walk_callback(wsp->walk_addr, (void *)cotwd, 632 wsp->walk_cbdata); 633 634 cotwd->cotndx++; 635 if (cotwd->cotndx >= cotwd->cotsize) { 636 return (WALK_DONE); 637 } 638 wsp->walk_addr = (uintptr_t)((char *)wsp->walk_addr + 639 sizeof (callout_table_t)); 640 641 return (retval); 642 } 643 644 void 645 callout_table_walk_fini(mdb_walk_state_t *wsp) 646 { 647 mdb_free(wsp->walk_data, sizeof (cot_data_t)); 648 } 649 650 static const char *co_typenames[] = { "R", "N" }; 651 652 #define CO_PLAIN_ID(xid) ((xid) & CALLOUT_ID_MASK) 653 654 #define TABLE_TO_SEQID(x) ((x) >> CALLOUT_TYPE_BITS) 655 656 /* callout flags, in no particular order */ 657 #define COF_REAL 0x0000001 658 #define COF_NORM 0x0000002 659 #define COF_LONG 0x0000004 660 #define COF_SHORT 0x0000008 661 #define COF_EMPTY 0x0000010 662 #define COF_TIME 0x0000020 663 #define COF_BEFORE 0x0000040 664 #define COF_AFTER 0x0000080 665 #define COF_SEQID 0x0000100 666 #define COF_FUNC 0x0000200 667 #define COF_ADDR 0x0000400 668 #define COF_EXEC 0x0000800 669 #define COF_HIRES 0x0001000 670 #define COF_ABS 0x0002000 671 #define COF_TABLE 0x0004000 672 #define COF_BYIDH 0x0008000 673 #define COF_FREE 0x0010000 674 #define COF_LIST 0x0020000 675 #define COF_EXPREL 0x0040000 676 #define COF_HDR 0x0080000 677 #define COF_VERBOSE 0x0100000 678 #define COF_LONGLIST 0x0200000 679 #define COF_THDR 0x0400000 680 #define COF_LHDR 0x0800000 681 #define COF_CHDR 0x1000000 682 #define COF_PARAM 0x2000000 683 #define COF_DECODE 0x4000000 684 685 /* show real and normal, short and long, expired and unexpired. */ 686 #define COF_DEFAULT (COF_REAL | COF_NORM | COF_LONG | COF_SHORT) 687 688 /* private callout data for callback functions */ 689 typedef struct callout_data { 690 uint_t flags; /* COF_* */ 691 cpu_t *cpu; /* cpu pointer if given */ 692 int seqid; /* cpu seqid, or -1 */ 693 hrtime_t time; /* expiration time value */ 694 hrtime_t atime; /* expiration before value */ 695 hrtime_t btime; /* expiration after value */ 696 uintptr_t funcaddr; /* function address or NULL */ 697 uintptr_t param; /* parameter to function or NULL */ 698 hrtime_t now; /* current system time */ 699 int nsec_per_tick; /* for conversions */ 700 ulong_t ctbits; /* for decoding xid */ 701 callout_table_t *co_table; /* top of callout table array */ 702 int ndx; /* table index. */ 703 int bucket; /* which list/id bucket are we in */ 704 hrtime_t exp; /* expire time */ 705 int list_flags; /* copy of cl_flags */ 706 } callout_data_t; 707 708 /* this callback does the actual callback itself (finally). */ 709 /*ARGSUSED*/ 710 static int 711 callouts_cb(uintptr_t addr, const void *data, void *priv) 712 { 713 callout_data_t *coargs = (callout_data_t *)priv; 714 callout_t *co = (callout_t *)data; 715 int tableid; 716 callout_id_t coid; 717 718 if ((coargs == NULL) || (co == NULL)) { 719 return (WALK_ERR); 720 } 721 722 if ((coargs->flags & COF_FUNC) && 723 (coargs->funcaddr != (uintptr_t)co->c_func)) { 724 return (WALK_NEXT); 725 } 726 if ((coargs->flags & COF_PARAM) && 727 (coargs->param != (uintptr_t)co->c_arg)) { 728 return (WALK_NEXT); 729 } 730 if (!(coargs->flags & COF_LONG) && (co->c_xid & CALLOUT_LONGTERM)) { 731 return (WALK_NEXT); 732 } 733 if (!(coargs->flags & COF_SHORT) && !(co->c_xid & CALLOUT_LONGTERM)) { 734 return (WALK_NEXT); 735 } 736 if ((coargs->flags & COF_EXEC) && !(co->c_xid & CALLOUT_EXECUTING)) { 737 return (WALK_NEXT); 738 } 739 740 /* it is possible we don't have the exp time */ 741 if (coargs->flags & COF_BYIDH) { 742 if (!(coargs->flags & COF_FREE)) { 743 /* we have to fetch the expire time ourselves. */ 744 if (mdb_vread(&coargs->exp, sizeof (hrtime_t), 745 (uintptr_t)co->c_list + offsetof(callout_list_t, 746 cl_expiration)) == -1) { 747 mdb_warn("failed to read expiration " 748 "time from %p", co->c_list); 749 coargs->exp = 0; 750 } 751 /* and flags. */ 752 if (mdb_vread(&coargs->list_flags, sizeof (int), 753 (uintptr_t)co->c_list + offsetof(callout_list_t, 754 cl_flags)) == -1) { 755 mdb_warn("failed to read list flags" 756 "from %p", co->c_list); 757 coargs->list_flags = 0; 758 } 759 } else { 760 /* free callouts can't use list pointer. */ 761 coargs->exp = 0; 762 coargs->list_flags = 0; 763 } 764 if (coargs->exp != 0) { 765 if ((coargs->flags & COF_TIME) && 766 (coargs->exp != coargs->time)) { 767 return (WALK_NEXT); 768 } 769 if ((coargs->flags & COF_BEFORE) && 770 (coargs->exp > coargs->btime)) { 771 return (WALK_NEXT); 772 } 773 if ((coargs->flags & COF_AFTER) && 774 (coargs->exp < coargs->atime)) { 775 return (WALK_NEXT); 776 } 777 } 778 /* tricky part, since both HIRES and ABS can be set */ 779 if ((coargs->flags & COF_HIRES) && (coargs->flags & COF_ABS)) { 780 /* both flags are set, only skip "regular" ones */ 781 if (! (coargs->list_flags & 782 (CALLOUT_FLAG_HRESTIME | CALLOUT_FLAG_ABSOLUTE))) { 783 return (WALK_NEXT); 784 } 785 } else { 786 /* individual flags, or no flags */ 787 if ((coargs->flags & COF_HIRES) && 788 !(coargs->list_flags & CALLOUT_FLAG_HRESTIME)) { 789 return (WALK_NEXT); 790 } 791 if ((coargs->flags & COF_ABS) && 792 !(coargs->list_flags & CALLOUT_FLAG_ABSOLUTE)) { 793 return (WALK_NEXT); 794 } 795 } 796 } 797 798 #define callout_table_mask ((1 << coargs->ctbits) - 1) 799 tableid = CALLOUT_ID_TO_TABLE(co->c_xid); 800 #undef callout_table_mask 801 coid = CO_PLAIN_ID(co->c_xid); 802 803 if ((coargs->flags & COF_CHDR) && !(coargs->flags & COF_ADDR)) { 804 /* 805 * We need to print the headers. If walking by id, then 806 * the list header isn't printed, so we must include 807 * that info here. 808 */ 809 if (!(coargs->flags & COF_VERBOSE)) { 810 mdb_printf("%<u>%3s %-1s %-14s %</u>", 811 "SEQ", "T", "EXP"); 812 } else if (coargs->flags & COF_BYIDH) { 813 mdb_printf("%<u>%-14s %</u>", "EXP"); 814 } 815 mdb_printf("%<u>%-4s %-?s %-20s%</u>", 816 "XHAL", "XID", "FUNC(ARG)"); 817 if (coargs->flags & COF_LONGLIST) { 818 mdb_printf("%<u> %-?s %-?s %-?s %-?s%</u>", 819 "PREVID", "NEXTID", "PREVL", "NEXTL"); 820 mdb_printf("%<u> %-?s %-4s %-?s%</u>", 821 "DONE", "UTOS", "THREAD"); 822 } 823 mdb_printf("\n"); 824 coargs->flags &= ~COF_CHDR; 825 coargs->flags |= (COF_THDR | COF_LHDR); 826 } 827 828 if (!(coargs->flags & COF_ADDR)) { 829 int list_flags = coargs->list_flags; 830 if (!(coargs->flags & COF_VERBOSE)) { 831 mdb_printf("%-3d %1s %-14llx ", 832 TABLE_TO_SEQID(tableid), 833 co_typenames[tableid & CALLOUT_TYPE_MASK], 834 (coargs->flags & COF_EXPREL) ? 835 coargs->exp - coargs->now : coargs->exp); 836 } else if (coargs->flags & COF_BYIDH) { 837 mdb_printf("%-14x ", 838 (coargs->flags & COF_EXPREL) ? 839 coargs->exp - coargs->now : coargs->exp); 840 } 841 mdb_printf("%1s%1s%1s%1s %-?llx %a(%p)", 842 (co->c_xid & CALLOUT_EXECUTING) ? "X" : " ", 843 (list_flags & CALLOUT_FLAG_HRESTIME) ? "H" : " ", 844 (list_flags & CALLOUT_FLAG_ABSOLUTE) ? "A" : " ", 845 (co->c_xid & CALLOUT_LONGTERM) ? "L" : " ", 846 (long long)coid, co->c_func, co->c_arg); 847 if (coargs->flags & COF_LONGLIST) { 848 mdb_printf(" %-?p %-?p %-?p %-?p", 849 co->c_idprev, co->c_idnext, co->c_clprev, 850 co->c_clnext); 851 mdb_printf(" %-?p %-4d %-0?p", 852 co->c_done, co->c_waiting, co->c_executor); 853 } 854 } else { 855 /* address only */ 856 mdb_printf("%-0p", addr); 857 } 858 mdb_printf("\n"); 859 return (WALK_NEXT); 860 } 861 862 /* this callback is for callout list handling. idhash is done by callout_t_cb */ 863 /*ARGSUSED*/ 864 static int 865 callout_list_cb(uintptr_t addr, const void *data, void *priv) 866 { 867 callout_data_t *coargs = (callout_data_t *)priv; 868 callout_list_t *cl = (callout_list_t *)data; 869 callout_t *coptr; 870 871 if ((coargs == NULL) || (cl == NULL)) { 872 return (WALK_ERR); 873 } 874 875 coargs->exp = cl->cl_expiration; 876 coargs->list_flags = cl->cl_flags; 877 878 if ((coargs->flags & COF_TIME) && 879 (cl->cl_expiration != coargs->time)) { 880 return (WALK_NEXT); 881 } 882 if ((coargs->flags & COF_BEFORE) && 883 (cl->cl_expiration > coargs->btime)) { 884 return (WALK_NEXT); 885 } 886 if ((coargs->flags & COF_AFTER) && 887 (cl->cl_expiration < coargs->atime)) { 888 return (WALK_NEXT); 889 } 890 if (!(coargs->flags & COF_EMPTY) && 891 (cl->cl_callouts.ch_head == NULL)) { 892 return (WALK_NEXT); 893 } 894 /* FOUR cases, each different, !A!B, !AB, A!B, AB */ 895 if ((coargs->flags & COF_HIRES) && (coargs->flags & COF_ABS)) { 896 /* both flags are set, only skip "regular" ones */ 897 if (! (cl->cl_flags & 898 (CALLOUT_FLAG_HRESTIME | CALLOUT_FLAG_ABSOLUTE))) { 899 return (WALK_NEXT); 900 } 901 } else { 902 if ((coargs->flags & COF_HIRES) && 903 !(cl->cl_flags & CALLOUT_FLAG_HRESTIME)) { 904 return (WALK_NEXT); 905 } 906 if ((coargs->flags & COF_ABS) && 907 !(cl->cl_flags & CALLOUT_FLAG_ABSOLUTE)) { 908 return (WALK_NEXT); 909 } 910 } 911 912 if ((coargs->flags & COF_LHDR) && !(coargs->flags & COF_ADDR) && 913 (coargs->flags & (COF_LIST | COF_VERBOSE))) { 914 if (!(coargs->flags & COF_VERBOSE)) { 915 /* don't be redundant again */ 916 mdb_printf("%<u>SEQ T %</u>"); 917 } 918 mdb_printf("%<u>EXP HA BUCKET " 919 "CALLOUTS %</u>"); 920 921 if (coargs->flags & COF_LONGLIST) { 922 mdb_printf("%<u> %-?s %-?s%</u>", 923 "PREV", "NEXT"); 924 } 925 mdb_printf("\n"); 926 coargs->flags &= ~COF_LHDR; 927 coargs->flags |= (COF_THDR | COF_CHDR); 928 } 929 if (coargs->flags & (COF_LIST | COF_VERBOSE)) { 930 if (!(coargs->flags & COF_ADDR)) { 931 if (!(coargs->flags & COF_VERBOSE)) { 932 mdb_printf("%3d %1s ", 933 TABLE_TO_SEQID(coargs->ndx), 934 co_typenames[coargs->ndx & 935 CALLOUT_TYPE_MASK]); 936 } 937 938 mdb_printf("%-14llx %1s%1s %-6d %-0?p ", 939 (coargs->flags & COF_EXPREL) ? 940 coargs->exp - coargs->now : coargs->exp, 941 (coargs->list_flags & CALLOUT_FLAG_HRESTIME) ? 942 "H" : " ", 943 (coargs->list_flags & CALLOUT_FLAG_ABSOLUTE) ? 944 "A" : " ", 945 coargs->bucket, cl->cl_callouts.ch_head); 946 947 if (coargs->flags & COF_LONGLIST) { 948 mdb_printf(" %-?p %-?p", 949 cl->cl_prev, cl->cl_next); 950 } 951 } else { 952 /* address only */ 953 mdb_printf("%-0p", addr); 954 } 955 mdb_printf("\n"); 956 if (coargs->flags & COF_LIST) { 957 return (WALK_NEXT); 958 } 959 } 960 /* yet another layer as we walk the actual callouts via list. */ 961 if (cl->cl_callouts.ch_head == NULL) { 962 return (WALK_NEXT); 963 } 964 /* free list structures do not have valid callouts off of them. */ 965 if (coargs->flags & COF_FREE) { 966 return (WALK_NEXT); 967 } 968 coptr = (callout_t *)cl->cl_callouts.ch_head; 969 970 if (coargs->flags & COF_VERBOSE) { 971 mdb_inc_indent(4); 972 } 973 /* 974 * walk callouts using yet another callback routine. 975 * we use callouts_bytime because id hash is handled via 976 * the callout_t_cb callback. 977 */ 978 if (mdb_pwalk("callouts_bytime", callouts_cb, coargs, 979 (uintptr_t)coptr) == -1) { 980 mdb_warn("cannot walk callouts at %p", coptr); 981 return (WALK_ERR); 982 } 983 if (coargs->flags & COF_VERBOSE) { 984 mdb_dec_indent(4); 985 } 986 987 return (WALK_NEXT); 988 } 989 990 /* this callback handles the details of callout table walking. */ 991 static int 992 callout_t_cb(uintptr_t addr, const void *data, void *priv) 993 { 994 callout_data_t *coargs = (callout_data_t *)priv; 995 cot_data_t *cotwd = (cot_data_t *)data; 996 callout_table_t *ct = &(cotwd->ct); 997 int index, seqid, cotype; 998 int i; 999 callout_list_t *clptr; 1000 callout_t *coptr; 1001 1002 if ((coargs == NULL) || (ct == NULL) || (coargs->co_table == NULL)) { 1003 return (WALK_ERR); 1004 } 1005 1006 index = ((char *)addr - (char *)coargs->co_table) / 1007 sizeof (callout_table_t); 1008 cotype = index & CALLOUT_TYPE_MASK; 1009 seqid = TABLE_TO_SEQID(index); 1010 1011 if ((coargs->flags & COF_SEQID) && (coargs->seqid != seqid)) { 1012 return (WALK_NEXT); 1013 } 1014 1015 if (!(coargs->flags & COF_REAL) && (cotype == CALLOUT_REALTIME)) { 1016 return (WALK_NEXT); 1017 } 1018 1019 if (!(coargs->flags & COF_NORM) && (cotype == CALLOUT_NORMAL)) { 1020 return (WALK_NEXT); 1021 } 1022 1023 if (!(coargs->flags & COF_EMPTY) && ( 1024 (ct->ct_heap == NULL) || (ct->ct_cyclic == NULL))) { 1025 return (WALK_NEXT); 1026 } 1027 1028 if ((coargs->flags & COF_THDR) && !(coargs->flags & COF_ADDR) && 1029 (coargs->flags & (COF_TABLE | COF_VERBOSE))) { 1030 /* print table hdr */ 1031 mdb_printf("%<u>%-3s %-1s %-?s %-?s %-?s %-?s%</u>", 1032 "SEQ", "T", "FREE", "LFREE", "CYCLIC", "HEAP"); 1033 coargs->flags &= ~COF_THDR; 1034 coargs->flags |= (COF_LHDR | COF_CHDR); 1035 if (coargs->flags & COF_LONGLIST) { 1036 /* more info! */ 1037 mdb_printf("%<u> %-T%-7s %-7s %-?s %-?s" 1038 " %-?s %-?s %-?s%</u>", 1039 "HEAPNUM", "HEAPMAX", "TASKQ", "EXPQ", 1040 "PEND", "FREE", "LOCK"); 1041 } 1042 mdb_printf("\n"); 1043 } 1044 if (coargs->flags & (COF_TABLE | COF_VERBOSE)) { 1045 if (!(coargs->flags & COF_ADDR)) { 1046 mdb_printf("%-3d %-1s %-0?p %-0?p %-0?p %-?p", 1047 seqid, co_typenames[cotype], 1048 ct->ct_free, ct->ct_lfree, ct->ct_cyclic, 1049 ct->ct_heap); 1050 if (coargs->flags & COF_LONGLIST) { 1051 /* more info! */ 1052 mdb_printf(" %-7d %-7d %-?p %-?p" 1053 " %-?lld %-?lld %-?p", 1054 ct->ct_heap_num, ct->ct_heap_max, 1055 ct->ct_taskq, ct->ct_expired.ch_head, 1056 cotwd->ct_timeouts_pending, 1057 cotwd->ct_allocations - 1058 cotwd->ct_timeouts_pending, 1059 ct->ct_mutex); 1060 } 1061 } else { 1062 /* address only */ 1063 mdb_printf("%-0?p", addr); 1064 } 1065 mdb_printf("\n"); 1066 if (coargs->flags & COF_TABLE) { 1067 return (WALK_NEXT); 1068 } 1069 } 1070 1071 coargs->ndx = index; 1072 if (coargs->flags & COF_VERBOSE) { 1073 mdb_inc_indent(4); 1074 } 1075 /* keep digging. */ 1076 if (!(coargs->flags & COF_BYIDH)) { 1077 /* walk the list hash table */ 1078 if (coargs->flags & COF_FREE) { 1079 clptr = ct->ct_lfree; 1080 coargs->bucket = 0; 1081 if (clptr == NULL) { 1082 return (WALK_NEXT); 1083 } 1084 if (mdb_pwalk("callout_list", callout_list_cb, coargs, 1085 (uintptr_t)clptr) == -1) { 1086 mdb_warn("cannot walk callout free list at %p", 1087 clptr); 1088 return (WALK_ERR); 1089 } 1090 } else { 1091 /* first print the expired list. */ 1092 clptr = (callout_list_t *)ct->ct_expired.ch_head; 1093 if (clptr != NULL) { 1094 coargs->bucket = -1; 1095 if (mdb_pwalk("callout_list", callout_list_cb, 1096 coargs, (uintptr_t)clptr) == -1) { 1097 mdb_warn("cannot walk callout_list" 1098 " at %p", clptr); 1099 return (WALK_ERR); 1100 } 1101 } 1102 for (i = 0; i < CALLOUT_BUCKETS; i++) { 1103 if (ct->ct_clhash == NULL) { 1104 /* nothing to do */ 1105 break; 1106 } 1107 if (cotwd->cot_clhash[i].ch_head == NULL) { 1108 continue; 1109 } 1110 clptr = (callout_list_t *) 1111 cotwd->cot_clhash[i].ch_head; 1112 coargs->bucket = i; 1113 /* walk list with callback routine. */ 1114 if (mdb_pwalk("callout_list", callout_list_cb, 1115 coargs, (uintptr_t)clptr) == -1) { 1116 mdb_warn("cannot walk callout_list" 1117 " at %p", clptr); 1118 return (WALK_ERR); 1119 } 1120 } 1121 } 1122 } else { 1123 /* walk the id hash table. */ 1124 if (coargs->flags & COF_FREE) { 1125 coptr = ct->ct_free; 1126 coargs->bucket = 0; 1127 if (coptr == NULL) { 1128 return (WALK_NEXT); 1129 } 1130 if (mdb_pwalk("callouts_byid", callouts_cb, coargs, 1131 (uintptr_t)coptr) == -1) { 1132 mdb_warn("cannot walk callout id free list" 1133 " at %p", coptr); 1134 return (WALK_ERR); 1135 } 1136 } else { 1137 for (i = 0; i < CALLOUT_BUCKETS; i++) { 1138 if (ct->ct_idhash == NULL) { 1139 break; 1140 } 1141 coptr = (callout_t *) 1142 cotwd->cot_idhash[i].ch_head; 1143 if (coptr == NULL) { 1144 continue; 1145 } 1146 coargs->bucket = i; 1147 1148 /* 1149 * walk callouts directly by id. For id 1150 * chain, the callout list is just a header, 1151 * so there's no need to walk it. 1152 */ 1153 if (mdb_pwalk("callouts_byid", callouts_cb, 1154 coargs, (uintptr_t)coptr) == -1) { 1155 mdb_warn("cannot walk callouts at %p", 1156 coptr); 1157 return (WALK_ERR); 1158 } 1159 } 1160 } 1161 } 1162 if (coargs->flags & COF_VERBOSE) { 1163 mdb_dec_indent(4); 1164 } 1165 return (WALK_NEXT); 1166 } 1167 1168 /* 1169 * initialize some common info for both callout dcmds. 1170 */ 1171 int 1172 callout_common_init(callout_data_t *coargs) 1173 { 1174 /* we need a couple of things */ 1175 if (mdb_readvar(&(coargs->co_table), "callout_table") == -1) { 1176 mdb_warn("failed to read 'callout_table'"); 1177 return (DCMD_ERR); 1178 } 1179 /* need to get now in nsecs. Approximate with hrtime vars */ 1180 if (mdb_readsym(&(coargs->now), sizeof (hrtime_t), "hrtime_last") != 1181 sizeof (hrtime_t)) { 1182 if (mdb_readsym(&(coargs->now), sizeof (hrtime_t), 1183 "hrtime_base") != sizeof (hrtime_t)) { 1184 mdb_warn("Could not determine current system time"); 1185 return (DCMD_ERR); 1186 } 1187 } 1188 1189 if (mdb_readvar(&(coargs->ctbits), "callout_table_bits") == -1) { 1190 mdb_warn("failed to read 'callout_table_bits'"); 1191 return (DCMD_ERR); 1192 } 1193 if (mdb_readvar(&(coargs->nsec_per_tick), "nsec_per_tick") == -1) { 1194 mdb_warn("failed to read 'nsec_per_tick'"); 1195 return (DCMD_ERR); 1196 } 1197 return (DCMD_OK); 1198 } 1199 1200 /* 1201 * dcmd to print callouts. Optional addr limits to specific table. 1202 * Parses lots of options that get passed to callbacks for walkers. 1203 * Has it's own help function. 1204 */ 1205 /*ARGSUSED*/ 1206 int 1207 callout(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1208 { 1209 callout_data_t coargs; 1210 /* getopts doesn't help much with stuff like this */ 1211 boolean_t Sflag, Cflag, tflag, aflag, bflag, dflag, kflag; 1212 char *funcname = NULL; 1213 char *paramstr = NULL; 1214 uintptr_t Stmp, Ctmp; /* for getopt. */ 1215 int retval; 1216 1217 coargs.flags = COF_DEFAULT; 1218 Sflag = Cflag = tflag = bflag = aflag = dflag = kflag = FALSE; 1219 coargs.seqid = -1; 1220 1221 if (mdb_getopts(argc, argv, 1222 'r', MDB_OPT_CLRBITS, COF_NORM, &coargs.flags, 1223 'n', MDB_OPT_CLRBITS, COF_REAL, &coargs.flags, 1224 'l', MDB_OPT_CLRBITS, COF_SHORT, &coargs.flags, 1225 's', MDB_OPT_CLRBITS, COF_LONG, &coargs.flags, 1226 'x', MDB_OPT_SETBITS, COF_EXEC, &coargs.flags, 1227 'h', MDB_OPT_SETBITS, COF_HIRES, &coargs.flags, 1228 'B', MDB_OPT_SETBITS, COF_ABS, &coargs.flags, 1229 'E', MDB_OPT_SETBITS, COF_EMPTY, &coargs.flags, 1230 'd', MDB_OPT_SETBITS, 1, &dflag, 1231 'C', MDB_OPT_UINTPTR_SET, &Cflag, &Ctmp, 1232 'S', MDB_OPT_UINTPTR_SET, &Sflag, &Stmp, 1233 't', MDB_OPT_UINTPTR_SET, &tflag, (uintptr_t *)&coargs.time, 1234 'a', MDB_OPT_UINTPTR_SET, &aflag, (uintptr_t *)&coargs.atime, 1235 'b', MDB_OPT_UINTPTR_SET, &bflag, (uintptr_t *)&coargs.btime, 1236 'k', MDB_OPT_SETBITS, 1, &kflag, 1237 'f', MDB_OPT_STR, &funcname, 1238 'p', MDB_OPT_STR, ¶mstr, 1239 'T', MDB_OPT_SETBITS, COF_TABLE, &coargs.flags, 1240 'D', MDB_OPT_SETBITS, COF_EXPREL, &coargs.flags, 1241 'L', MDB_OPT_SETBITS, COF_LIST, &coargs.flags, 1242 'V', MDB_OPT_SETBITS, COF_VERBOSE, &coargs.flags, 1243 'v', MDB_OPT_SETBITS, COF_LONGLIST, &coargs.flags, 1244 'i', MDB_OPT_SETBITS, COF_BYIDH, &coargs.flags, 1245 'F', MDB_OPT_SETBITS, COF_FREE, &coargs.flags, 1246 'A', MDB_OPT_SETBITS, COF_ADDR, &coargs.flags, 1247 NULL) != argc) { 1248 return (DCMD_USAGE); 1249 } 1250 1251 /* initialize from kernel variables */ 1252 if ((retval = callout_common_init(&coargs)) != DCMD_OK) { 1253 return (retval); 1254 } 1255 1256 /* do some option post-processing */ 1257 if (kflag) { 1258 coargs.time *= coargs.nsec_per_tick; 1259 coargs.atime *= coargs.nsec_per_tick; 1260 coargs.btime *= coargs.nsec_per_tick; 1261 } 1262 1263 if (dflag) { 1264 coargs.time += coargs.now; 1265 coargs.atime += coargs.now; 1266 coargs.btime += coargs.now; 1267 } 1268 if (Sflag) { 1269 if (flags & DCMD_ADDRSPEC) { 1270 mdb_printf("-S option conflicts with explicit" 1271 " address\n"); 1272 return (DCMD_USAGE); 1273 } 1274 coargs.flags |= COF_SEQID; 1275 coargs.seqid = (int)Stmp; 1276 } 1277 if (Cflag) { 1278 if (flags & DCMD_ADDRSPEC) { 1279 mdb_printf("-C option conflicts with explicit" 1280 " address\n"); 1281 return (DCMD_USAGE); 1282 } 1283 if (coargs.flags & COF_SEQID) { 1284 mdb_printf("-C and -S are mutually exclusive\n"); 1285 return (DCMD_USAGE); 1286 } 1287 coargs.cpu = (cpu_t *)Ctmp; 1288 if (mdb_vread(&coargs.seqid, sizeof (processorid_t), 1289 (uintptr_t)&(coargs.cpu->cpu_seqid)) == -1) { 1290 mdb_warn("failed to read cpu_t at %p", Ctmp); 1291 return (DCMD_ERR); 1292 } 1293 coargs.flags |= COF_SEQID; 1294 } 1295 /* avoid null outputs. */ 1296 if (!(coargs.flags & (COF_REAL | COF_NORM))) { 1297 coargs.flags |= COF_REAL | COF_NORM; 1298 } 1299 if (!(coargs.flags & (COF_LONG | COF_SHORT))) { 1300 coargs.flags |= COF_LONG | COF_SHORT; 1301 } 1302 if (tflag) { 1303 if (aflag || bflag) { 1304 mdb_printf("-t and -a|b are mutually exclusive\n"); 1305 return (DCMD_USAGE); 1306 } 1307 coargs.flags |= COF_TIME; 1308 } 1309 if (aflag) { 1310 coargs.flags |= COF_AFTER; 1311 } 1312 if (bflag) { 1313 coargs.flags |= COF_BEFORE; 1314 } 1315 if ((aflag && bflag) && (coargs.btime <= coargs.atime)) { 1316 mdb_printf("value for -a must be earlier than the value" 1317 " for -b.\n"); 1318 return (DCMD_USAGE); 1319 } 1320 1321 if (funcname != NULL) { 1322 GElf_Sym sym; 1323 1324 if (mdb_lookup_by_name(funcname, &sym) != 0) { 1325 coargs.funcaddr = mdb_strtoull(funcname); 1326 } else { 1327 coargs.funcaddr = sym.st_value; 1328 } 1329 coargs.flags |= COF_FUNC; 1330 } 1331 1332 if (paramstr != NULL) { 1333 GElf_Sym sym; 1334 1335 if (mdb_lookup_by_name(paramstr, &sym) != 0) { 1336 coargs.param = mdb_strtoull(paramstr); 1337 } else { 1338 coargs.param = sym.st_value; 1339 } 1340 coargs.flags |= COF_PARAM; 1341 } 1342 1343 if (!(flags & DCMD_ADDRSPEC)) { 1344 /* don't pass "dot" if no addr. */ 1345 addr = NULL; 1346 } 1347 if (addr != NULL) { 1348 /* 1349 * a callout table was specified. Ignore -r|n option 1350 * to avoid null output. 1351 */ 1352 coargs.flags |= (COF_REAL | COF_NORM); 1353 } 1354 1355 if (DCMD_HDRSPEC(flags) || (coargs.flags & COF_VERBOSE)) { 1356 coargs.flags |= COF_THDR | COF_LHDR | COF_CHDR; 1357 } 1358 if (coargs.flags & COF_FREE) { 1359 coargs.flags |= COF_EMPTY; 1360 /* -F = free callouts, -FL = free lists */ 1361 if (!(coargs.flags & COF_LIST)) { 1362 coargs.flags |= COF_BYIDH; 1363 } 1364 } 1365 1366 /* walk table, using specialized callback routine. */ 1367 if (mdb_pwalk("callout_table", callout_t_cb, &coargs, addr) == -1) { 1368 mdb_warn("cannot walk callout_table"); 1369 return (DCMD_ERR); 1370 } 1371 return (DCMD_OK); 1372 } 1373 1374 1375 /* 1376 * Given an extended callout id, dump its information. 1377 */ 1378 /*ARGSUSED*/ 1379 int 1380 calloutid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1381 { 1382 callout_data_t coargs; 1383 callout_table_t *ctptr; 1384 callout_table_t ct; 1385 callout_id_t coid; 1386 callout_t *coptr; 1387 int tableid; 1388 callout_id_t xid; 1389 ulong_t idhash; 1390 int i, retval; 1391 const mdb_arg_t *arg; 1392 size_t size; 1393 callout_hash_t cot_idhash[CALLOUT_BUCKETS]; 1394 1395 coargs.flags = COF_DEFAULT | COF_BYIDH; 1396 i = mdb_getopts(argc, argv, 1397 'd', MDB_OPT_SETBITS, COF_DECODE, &coargs.flags, 1398 'v', MDB_OPT_SETBITS, COF_LONGLIST, &coargs.flags, 1399 NULL); 1400 argc -= i; 1401 argv += i; 1402 1403 if (argc != 1) { 1404 return (DCMD_USAGE); 1405 } 1406 arg = &argv[0]; 1407 1408 if (arg->a_type == MDB_TYPE_IMMEDIATE) { 1409 xid = arg->a_un.a_val; 1410 } else { 1411 xid = (callout_id_t)mdb_strtoull(arg->a_un.a_str); 1412 } 1413 1414 if (DCMD_HDRSPEC(flags)) { 1415 coargs.flags |= COF_CHDR; 1416 } 1417 1418 1419 /* initialize from kernel variables */ 1420 if ((retval = callout_common_init(&coargs)) != DCMD_OK) { 1421 return (retval); 1422 } 1423 1424 /* we must massage the environment so that the macros will play nice */ 1425 #define callout_table_mask ((1 << coargs.ctbits) - 1) 1426 #define callout_table_bits coargs.ctbits 1427 #define nsec_per_tick coargs.nsec_per_tick 1428 tableid = CALLOUT_ID_TO_TABLE(xid); 1429 idhash = CALLOUT_IDHASH(xid); 1430 #undef callouts_table_bits 1431 #undef callout_table_mask 1432 #undef nsec_per_tick 1433 coid = CO_PLAIN_ID(xid); 1434 1435 if (flags & DCMD_ADDRSPEC) { 1436 mdb_printf("calloutid does not accept explicit address.\n"); 1437 return (DCMD_USAGE); 1438 } 1439 1440 if (coargs.flags & COF_DECODE) { 1441 if (DCMD_HDRSPEC(flags)) { 1442 mdb_printf("%<u>%3s %1s %2s %-?s %-6s %</u>\n", 1443 "SEQ", "T", "XL", "XID", "IDHASH"); 1444 } 1445 mdb_printf("%-3d %1s %1s%1s %-?llx %-6d\n", 1446 TABLE_TO_SEQID(tableid), 1447 co_typenames[tableid & CALLOUT_TYPE_MASK], 1448 (xid & CALLOUT_EXECUTING) ? "X" : " ", 1449 (xid & CALLOUT_LONGTERM) ? "L" : " ", 1450 (long long)coid, idhash); 1451 return (DCMD_OK); 1452 } 1453 1454 /* get our table. Note this relies on the types being correct */ 1455 ctptr = coargs.co_table + tableid; 1456 if (mdb_vread(&ct, sizeof (callout_table_t), (uintptr_t)ctptr) == -1) { 1457 mdb_warn("failed to read callout_table at %p", ctptr); 1458 return (DCMD_ERR); 1459 } 1460 size = sizeof (callout_hash_t) * CALLOUT_BUCKETS; 1461 if (ct.ct_idhash != NULL) { 1462 if (mdb_vread(&(cot_idhash), size, 1463 (uintptr_t)ct.ct_idhash) == -1) { 1464 mdb_warn("failed to read id_hash at %p", 1465 ct.ct_idhash); 1466 return (WALK_ERR); 1467 } 1468 } 1469 1470 /* callout at beginning of hash chain */ 1471 if (ct.ct_idhash == NULL) { 1472 mdb_printf("id hash chain for this xid is empty\n"); 1473 return (DCMD_ERR); 1474 } 1475 coptr = (callout_t *)cot_idhash[idhash].ch_head; 1476 if (coptr == NULL) { 1477 mdb_printf("id hash chain for this xid is empty\n"); 1478 return (DCMD_ERR); 1479 } 1480 1481 coargs.ndx = tableid; 1482 coargs.bucket = idhash; 1483 1484 /* use the walker, luke */ 1485 if (mdb_pwalk("callouts_byid", callouts_cb, &coargs, 1486 (uintptr_t)coptr) == -1) { 1487 mdb_warn("cannot walk callouts at %p", coptr); 1488 return (WALK_ERR); 1489 } 1490 1491 return (DCMD_OK); 1492 } 1493 1494 void 1495 callout_help(void) 1496 { 1497 mdb_printf("callout: display callouts.\n" 1498 "Given a callout table address, display callouts from table.\n" 1499 "Without an address, display callouts from all tables.\n" 1500 "options:\n" 1501 " -r|n : limit display to (r)ealtime or (n)ormal type callouts\n" 1502 " -s|l : limit display to (s)hort-term ids or (l)ong-term ids\n" 1503 " -x : limit display to callouts which are executing\n" 1504 " -h : limit display to callouts based on hrestime\n" 1505 " -B : limit display to callouts based on absolute time\n" 1506 " -t|a|b nsec: limit display to callouts that expire a(t) time," 1507 " (a)fter time,\n or (b)efore time. Use -a and -b together " 1508 " to specify a range.\n For \"now\", use -d[t|a|b] 0.\n" 1509 " -d : interpret time option to -t|a|b as delta from current time\n" 1510 " -k : use ticks instead of nanoseconds as arguments to" 1511 " -t|a|b. Note that\n ticks are less accurate and may not" 1512 " match other tick times (ie: lbolt).\n" 1513 " -D : display exiration time as delta from current time\n" 1514 " -S seqid : limit display to callouts for this cpu sequence id\n" 1515 " -C addr : limit display to callouts for this cpu pointer\n" 1516 " -f name|addr : limit display to callouts with this function\n" 1517 " -p name|addr : limit display to callouts functions with this" 1518 " parameter\n" 1519 " -T : display the callout table itself, instead of callouts\n" 1520 " -L : display callout lists instead of callouts\n" 1521 " -E : with -T or L, display empty data structures.\n" 1522 " -i : traverse callouts by id hash instead of list hash\n" 1523 " -F : walk free callout list (free list with -i) instead\n" 1524 " -v : display more info for each item\n" 1525 " -V : show details of each level of info as it is traversed\n" 1526 " -A : show only addresses. Useful for pipelines.\n"); 1527 } 1528 1529 void 1530 calloutid_help(void) 1531 { 1532 mdb_printf("calloutid: display callout by id.\n" 1533 "Given an extended callout id, display the callout infomation.\n" 1534 "options:\n" 1535 " -d : do not dereference callout, just decode the id.\n" 1536 " -v : verbose display more info about the callout\n"); 1537 } 1538 1539 /*ARGSUSED*/ 1540 int 1541 class(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1542 { 1543 long num_classes, i; 1544 sclass_t *class_tbl; 1545 GElf_Sym g_sclass; 1546 char class_name[PC_CLNMSZ]; 1547 size_t tbl_size; 1548 1549 if (mdb_lookup_by_name("sclass", &g_sclass) == -1) { 1550 mdb_warn("failed to find symbol sclass\n"); 1551 return (DCMD_ERR); 1552 } 1553 1554 tbl_size = (size_t)g_sclass.st_size; 1555 num_classes = tbl_size / (sizeof (sclass_t)); 1556 class_tbl = mdb_alloc(tbl_size, UM_SLEEP | UM_GC); 1557 1558 if (mdb_readsym(class_tbl, tbl_size, "sclass") == -1) { 1559 mdb_warn("failed to read sclass"); 1560 return (DCMD_ERR); 1561 } 1562 1563 mdb_printf("%<u>%4s %-10s %-24s %-24s%</u>\n", "SLOT", "NAME", 1564 "INIT FCN", "CLASS FCN"); 1565 1566 for (i = 0; i < num_classes; i++) { 1567 if (mdb_vread(class_name, sizeof (class_name), 1568 (uintptr_t)class_tbl[i].cl_name) == -1) 1569 (void) strcpy(class_name, "???"); 1570 1571 mdb_printf("%4ld %-10s %-24a %-24a\n", i, class_name, 1572 class_tbl[i].cl_init, class_tbl[i].cl_funcs); 1573 } 1574 1575 return (DCMD_OK); 1576 } 1577 1578 #define FSNAMELEN 32 /* Max len of FS name we read from vnodeops */ 1579 1580 int 1581 vnode2path(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1582 { 1583 uintptr_t rootdir; 1584 vnode_t vn; 1585 char buf[MAXPATHLEN]; 1586 1587 uint_t opt_F = FALSE; 1588 1589 if (mdb_getopts(argc, argv, 1590 'F', MDB_OPT_SETBITS, TRUE, &opt_F, NULL) != argc) 1591 return (DCMD_USAGE); 1592 1593 if (!(flags & DCMD_ADDRSPEC)) { 1594 mdb_warn("expected explicit vnode_t address before ::\n"); 1595 return (DCMD_USAGE); 1596 } 1597 1598 if (mdb_readvar(&rootdir, "rootdir") == -1) { 1599 mdb_warn("failed to read rootdir"); 1600 return (DCMD_ERR); 1601 } 1602 1603 if (mdb_vnode2path(addr, buf, sizeof (buf)) == -1) 1604 return (DCMD_ERR); 1605 1606 if (*buf == '\0') { 1607 mdb_printf("??\n"); 1608 return (DCMD_OK); 1609 } 1610 1611 mdb_printf("%s", buf); 1612 if (opt_F && buf[strlen(buf)-1] != '/' && 1613 mdb_vread(&vn, sizeof (vn), addr) == sizeof (vn)) 1614 mdb_printf("%c", mdb_vtype2chr(vn.v_type, 0)); 1615 mdb_printf("\n"); 1616 1617 return (DCMD_OK); 1618 } 1619 1620 int 1621 ld_walk_init(mdb_walk_state_t *wsp) 1622 { 1623 wsp->walk_data = (void *)wsp->walk_addr; 1624 return (WALK_NEXT); 1625 } 1626 1627 int 1628 ld_walk_step(mdb_walk_state_t *wsp) 1629 { 1630 int status; 1631 lock_descriptor_t ld; 1632 1633 if (mdb_vread(&ld, sizeof (lock_descriptor_t), wsp->walk_addr) == -1) { 1634 mdb_warn("couldn't read lock_descriptor_t at %p\n", 1635 wsp->walk_addr); 1636 return (WALK_ERR); 1637 } 1638 1639 status = wsp->walk_callback(wsp->walk_addr, &ld, wsp->walk_cbdata); 1640 if (status == WALK_ERR) 1641 return (WALK_ERR); 1642 1643 wsp->walk_addr = (uintptr_t)ld.l_next; 1644 if (wsp->walk_addr == (uintptr_t)wsp->walk_data) 1645 return (WALK_DONE); 1646 1647 return (status); 1648 } 1649 1650 int 1651 lg_walk_init(mdb_walk_state_t *wsp) 1652 { 1653 GElf_Sym sym; 1654 1655 if (mdb_lookup_by_name("lock_graph", &sym) == -1) { 1656 mdb_warn("failed to find symbol 'lock_graph'\n"); 1657 return (WALK_ERR); 1658 } 1659 1660 wsp->walk_addr = (uintptr_t)sym.st_value; 1661 wsp->walk_data = (void *)(uintptr_t)(sym.st_value + sym.st_size); 1662 1663 return (WALK_NEXT); 1664 } 1665 1666 typedef struct lg_walk_data { 1667 uintptr_t startaddr; 1668 mdb_walk_cb_t callback; 1669 void *data; 1670 } lg_walk_data_t; 1671 1672 /* 1673 * We can't use ::walk lock_descriptor directly, because the head of each graph 1674 * is really a dummy lock. Rather than trying to dynamically determine if this 1675 * is a dummy node or not, we just filter out the initial element of the 1676 * list. 1677 */ 1678 static int 1679 lg_walk_cb(uintptr_t addr, const void *data, void *priv) 1680 { 1681 lg_walk_data_t *lw = priv; 1682 1683 if (addr != lw->startaddr) 1684 return (lw->callback(addr, data, lw->data)); 1685 1686 return (WALK_NEXT); 1687 } 1688 1689 int 1690 lg_walk_step(mdb_walk_state_t *wsp) 1691 { 1692 graph_t *graph; 1693 lg_walk_data_t lw; 1694 1695 if (wsp->walk_addr >= (uintptr_t)wsp->walk_data) 1696 return (WALK_DONE); 1697 1698 if (mdb_vread(&graph, sizeof (graph), wsp->walk_addr) == -1) { 1699 mdb_warn("failed to read graph_t at %p", wsp->walk_addr); 1700 return (WALK_ERR); 1701 } 1702 1703 wsp->walk_addr += sizeof (graph); 1704 1705 if (graph == NULL) 1706 return (WALK_NEXT); 1707 1708 lw.callback = wsp->walk_callback; 1709 lw.data = wsp->walk_cbdata; 1710 1711 lw.startaddr = (uintptr_t)&(graph->active_locks); 1712 if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) { 1713 mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr); 1714 return (WALK_ERR); 1715 } 1716 1717 lw.startaddr = (uintptr_t)&(graph->sleeping_locks); 1718 if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) { 1719 mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr); 1720 return (WALK_ERR); 1721 } 1722 1723 return (WALK_NEXT); 1724 } 1725 1726 /* 1727 * The space available for the path corresponding to the locked vnode depends 1728 * on whether we are printing 32- or 64-bit addresses. 1729 */ 1730 #ifdef _LP64 1731 #define LM_VNPATHLEN 20 1732 #else 1733 #define LM_VNPATHLEN 30 1734 #endif 1735 1736 /*ARGSUSED*/ 1737 static int 1738 lminfo_cb(uintptr_t addr, const void *data, void *priv) 1739 { 1740 const lock_descriptor_t *ld = data; 1741 char buf[LM_VNPATHLEN]; 1742 proc_t p; 1743 1744 mdb_printf("%-?p %2s %04x %6d %-16s %-?p ", 1745 addr, ld->l_type == F_RDLCK ? "RD" : 1746 ld->l_type == F_WRLCK ? "WR" : "??", 1747 ld->l_state, ld->l_flock.l_pid, 1748 ld->l_flock.l_pid == 0 ? "<kernel>" : 1749 mdb_pid2proc(ld->l_flock.l_pid, &p) == NULL ? 1750 "<defunct>" : p.p_user.u_comm, 1751 ld->l_vnode); 1752 1753 mdb_vnode2path((uintptr_t)ld->l_vnode, buf, 1754 sizeof (buf)); 1755 mdb_printf("%s\n", buf); 1756 1757 return (WALK_NEXT); 1758 } 1759 1760 /*ARGSUSED*/ 1761 int 1762 lminfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1763 { 1764 if (DCMD_HDRSPEC(flags)) 1765 mdb_printf("%<u>%-?s %2s %4s %6s %-16s %-?s %s%</u>\n", 1766 "ADDR", "TP", "FLAG", "PID", "COMM", "VNODE", "PATH"); 1767 1768 return (mdb_pwalk("lock_graph", lminfo_cb, NULL, NULL)); 1769 } 1770 1771 /*ARGSUSED*/ 1772 int 1773 seg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1774 { 1775 struct seg s; 1776 1777 if (argc != 0) 1778 return (DCMD_USAGE); 1779 1780 if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) { 1781 mdb_printf("%<u>%?s %?s %?s %?s %s%</u>\n", 1782 "SEG", "BASE", "SIZE", "DATA", "OPS"); 1783 } 1784 1785 if (mdb_vread(&s, sizeof (s), addr) == -1) { 1786 mdb_warn("failed to read seg at %p", addr); 1787 return (DCMD_ERR); 1788 } 1789 1790 mdb_printf("%?p %?p %?lx %?p %a\n", 1791 addr, s.s_base, s.s_size, s.s_data, s.s_ops); 1792 1793 return (DCMD_OK); 1794 } 1795 1796 /*ARGSUSED*/ 1797 static int 1798 pmap_walk_anon(uintptr_t addr, const struct anon *anon, int *nres) 1799 { 1800 uintptr_t pp = 1801 mdb_vnode2page((uintptr_t)anon->an_vp, (uintptr_t)anon->an_off); 1802 1803 if (pp != NULL) 1804 (*nres)++; 1805 1806 return (WALK_NEXT); 1807 } 1808 1809 static int 1810 pmap_walk_seg(uintptr_t addr, const struct seg *seg, uintptr_t segvn) 1811 { 1812 1813 mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024); 1814 1815 if (segvn == (uintptr_t)seg->s_ops) { 1816 struct segvn_data svn; 1817 int nres = 0; 1818 1819 (void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data); 1820 1821 if (svn.amp == NULL) { 1822 mdb_printf(" %8s", ""); 1823 goto drive_on; 1824 } 1825 1826 /* 1827 * We've got an amp for this segment; walk through 1828 * the amp, and determine mappings. 1829 */ 1830 if (mdb_pwalk("anon", (mdb_walk_cb_t)pmap_walk_anon, 1831 &nres, (uintptr_t)svn.amp) == -1) 1832 mdb_warn("failed to walk anon (amp=%p)", svn.amp); 1833 1834 mdb_printf(" %7dk", (nres * PAGESIZE) / 1024); 1835 drive_on: 1836 1837 if (svn.vp != NULL) { 1838 char buf[29]; 1839 1840 mdb_vnode2path((uintptr_t)svn.vp, buf, sizeof (buf)); 1841 mdb_printf(" %s", buf); 1842 } else 1843 mdb_printf(" [ anon ]"); 1844 } 1845 1846 mdb_printf("\n"); 1847 return (WALK_NEXT); 1848 } 1849 1850 static int 1851 pmap_walk_seg_quick(uintptr_t addr, const struct seg *seg, uintptr_t segvn) 1852 { 1853 mdb_printf("%0?p %0?p %7dk", addr, seg->s_base, seg->s_size / 1024); 1854 1855 if (segvn == (uintptr_t)seg->s_ops) { 1856 struct segvn_data svn; 1857 1858 (void) mdb_vread(&svn, sizeof (svn), (uintptr_t)seg->s_data); 1859 1860 if (svn.vp != NULL) { 1861 mdb_printf(" %0?p", svn.vp); 1862 } else { 1863 mdb_printf(" [ anon ]"); 1864 } 1865 } 1866 1867 mdb_printf("\n"); 1868 return (WALK_NEXT); 1869 } 1870 1871 /*ARGSUSED*/ 1872 int 1873 pmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1874 { 1875 uintptr_t segvn; 1876 proc_t proc; 1877 uint_t quick = FALSE; 1878 mdb_walk_cb_t cb = (mdb_walk_cb_t)pmap_walk_seg; 1879 1880 GElf_Sym sym; 1881 1882 if (!(flags & DCMD_ADDRSPEC)) 1883 return (DCMD_USAGE); 1884 1885 if (mdb_getopts(argc, argv, 1886 'q', MDB_OPT_SETBITS, TRUE, &quick, NULL) != argc) 1887 return (DCMD_USAGE); 1888 1889 if (mdb_vread(&proc, sizeof (proc), addr) == -1) { 1890 mdb_warn("failed to read proc at %p", addr); 1891 return (DCMD_ERR); 1892 } 1893 1894 if (mdb_lookup_by_name("segvn_ops", &sym) == 0) 1895 segvn = (uintptr_t)sym.st_value; 1896 else 1897 segvn = NULL; 1898 1899 mdb_printf("%?s %?s %8s ", "SEG", "BASE", "SIZE"); 1900 1901 if (quick) { 1902 mdb_printf("VNODE\n"); 1903 cb = (mdb_walk_cb_t)pmap_walk_seg_quick; 1904 } else { 1905 mdb_printf("%8s %s\n", "RES", "PATH"); 1906 } 1907 1908 if (mdb_pwalk("seg", cb, (void *)segvn, (uintptr_t)proc.p_as) == -1) { 1909 mdb_warn("failed to walk segments of as %p", proc.p_as); 1910 return (DCMD_ERR); 1911 } 1912 1913 return (DCMD_OK); 1914 } 1915 1916 typedef struct anon_walk_data { 1917 uintptr_t *aw_levone; 1918 uintptr_t *aw_levtwo; 1919 int aw_nlevone; 1920 int aw_levone_ndx; 1921 int aw_levtwo_ndx; 1922 struct anon_map aw_amp; 1923 struct anon_hdr aw_ahp; 1924 } anon_walk_data_t; 1925 1926 int 1927 anon_walk_init(mdb_walk_state_t *wsp) 1928 { 1929 anon_walk_data_t *aw; 1930 1931 if (wsp->walk_addr == NULL) { 1932 mdb_warn("anon walk doesn't support global walks\n"); 1933 return (WALK_ERR); 1934 } 1935 1936 aw = mdb_alloc(sizeof (anon_walk_data_t), UM_SLEEP); 1937 1938 if (mdb_vread(&aw->aw_amp, sizeof (aw->aw_amp), wsp->walk_addr) == -1) { 1939 mdb_warn("failed to read anon map at %p", wsp->walk_addr); 1940 mdb_free(aw, sizeof (anon_walk_data_t)); 1941 return (WALK_ERR); 1942 } 1943 1944 if (mdb_vread(&aw->aw_ahp, sizeof (aw->aw_ahp), 1945 (uintptr_t)(aw->aw_amp.ahp)) == -1) { 1946 mdb_warn("failed to read anon hdr ptr at %p", aw->aw_amp.ahp); 1947 mdb_free(aw, sizeof (anon_walk_data_t)); 1948 return (WALK_ERR); 1949 } 1950 1951 if (aw->aw_ahp.size <= ANON_CHUNK_SIZE || 1952 (aw->aw_ahp.flags & ANON_ALLOC_FORCE)) { 1953 aw->aw_nlevone = aw->aw_ahp.size; 1954 aw->aw_levtwo = NULL; 1955 } else { 1956 aw->aw_nlevone = 1957 (aw->aw_ahp.size + ANON_CHUNK_OFF) >> ANON_CHUNK_SHIFT; 1958 aw->aw_levtwo = 1959 mdb_zalloc(ANON_CHUNK_SIZE * sizeof (uintptr_t), UM_SLEEP); 1960 } 1961 1962 aw->aw_levone = 1963 mdb_alloc(aw->aw_nlevone * sizeof (uintptr_t), UM_SLEEP); 1964 1965 aw->aw_levone_ndx = 0; 1966 aw->aw_levtwo_ndx = 0; 1967 1968 mdb_vread(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t), 1969 (uintptr_t)aw->aw_ahp.array_chunk); 1970 1971 if (aw->aw_levtwo != NULL) { 1972 while (aw->aw_levone[aw->aw_levone_ndx] == NULL) { 1973 aw->aw_levone_ndx++; 1974 if (aw->aw_levone_ndx == aw->aw_nlevone) { 1975 mdb_warn("corrupt anon; couldn't" 1976 "find ptr to lev two map"); 1977 goto out; 1978 } 1979 } 1980 1981 mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t), 1982 aw->aw_levone[aw->aw_levone_ndx]); 1983 } 1984 1985 out: 1986 wsp->walk_data = aw; 1987 return (0); 1988 } 1989 1990 int 1991 anon_walk_step(mdb_walk_state_t *wsp) 1992 { 1993 int status; 1994 anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data; 1995 struct anon anon; 1996 uintptr_t anonptr; 1997 1998 again: 1999 /* 2000 * Once we've walked through level one, we're done. 2001 */ 2002 if (aw->aw_levone_ndx == aw->aw_nlevone) 2003 return (WALK_DONE); 2004 2005 if (aw->aw_levtwo == NULL) { 2006 anonptr = aw->aw_levone[aw->aw_levone_ndx]; 2007 aw->aw_levone_ndx++; 2008 } else { 2009 anonptr = aw->aw_levtwo[aw->aw_levtwo_ndx]; 2010 aw->aw_levtwo_ndx++; 2011 2012 if (aw->aw_levtwo_ndx == ANON_CHUNK_SIZE) { 2013 aw->aw_levtwo_ndx = 0; 2014 2015 do { 2016 aw->aw_levone_ndx++; 2017 2018 if (aw->aw_levone_ndx == aw->aw_nlevone) 2019 return (WALK_DONE); 2020 } while (aw->aw_levone[aw->aw_levone_ndx] == NULL); 2021 2022 mdb_vread(aw->aw_levtwo, ANON_CHUNK_SIZE * 2023 sizeof (uintptr_t), 2024 aw->aw_levone[aw->aw_levone_ndx]); 2025 } 2026 } 2027 2028 if (anonptr != NULL) { 2029 mdb_vread(&anon, sizeof (anon), anonptr); 2030 status = wsp->walk_callback(anonptr, &anon, wsp->walk_cbdata); 2031 } else 2032 goto again; 2033 2034 return (status); 2035 } 2036 2037 void 2038 anon_walk_fini(mdb_walk_state_t *wsp) 2039 { 2040 anon_walk_data_t *aw = (anon_walk_data_t *)wsp->walk_data; 2041 2042 if (aw->aw_levtwo != NULL) 2043 mdb_free(aw->aw_levtwo, ANON_CHUNK_SIZE * sizeof (uintptr_t)); 2044 2045 mdb_free(aw->aw_levone, aw->aw_nlevone * sizeof (uintptr_t)); 2046 mdb_free(aw, sizeof (anon_walk_data_t)); 2047 } 2048 2049 /*ARGSUSED*/ 2050 int 2051 whereopen_fwalk(uintptr_t addr, struct file *f, uintptr_t *target) 2052 { 2053 if ((uintptr_t)f->f_vnode == *target) { 2054 mdb_printf("file %p\n", addr); 2055 *target = NULL; 2056 } 2057 2058 return (WALK_NEXT); 2059 } 2060 2061 /*ARGSUSED*/ 2062 int 2063 whereopen_pwalk(uintptr_t addr, void *ignored, uintptr_t *target) 2064 { 2065 uintptr_t t = *target; 2066 2067 if (mdb_pwalk("file", (mdb_walk_cb_t)whereopen_fwalk, &t, addr) == -1) { 2068 mdb_warn("couldn't file walk proc %p", addr); 2069 return (WALK_ERR); 2070 } 2071 2072 if (t == NULL) 2073 mdb_printf("%p\n", addr); 2074 2075 return (WALK_NEXT); 2076 } 2077 2078 /*ARGSUSED*/ 2079 int 2080 whereopen(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2081 { 2082 uintptr_t target = addr; 2083 2084 if (!(flags & DCMD_ADDRSPEC) || addr == NULL) 2085 return (DCMD_USAGE); 2086 2087 if (mdb_walk("proc", (mdb_walk_cb_t)whereopen_pwalk, &target) == -1) { 2088 mdb_warn("can't proc walk"); 2089 return (DCMD_ERR); 2090 } 2091 2092 return (DCMD_OK); 2093 } 2094 2095 typedef struct datafmt { 2096 char *hdr1; 2097 char *hdr2; 2098 char *dashes; 2099 char *fmt; 2100 } datafmt_t; 2101 2102 static datafmt_t kmemfmt[] = { 2103 { "cache ", "name ", 2104 "-------------------------", "%-25s " }, 2105 { " buf", " size", "------", "%6u " }, 2106 { " buf", "in use", "------", "%6u " }, 2107 { " buf", " total", "------", "%6u " }, 2108 { " memory", " in use", "----------", "%9u%c " }, 2109 { " alloc", " succeed", "---------", "%9u " }, 2110 { "alloc", " fail", "-----", "%5u " }, 2111 { NULL, NULL, NULL, NULL } 2112 }; 2113 2114 static datafmt_t vmemfmt[] = { 2115 { "vmem ", "name ", 2116 "-------------------------", "%-*s " }, 2117 { " memory", " in use", "----------", "%9llu%c " }, 2118 { " memory", " total", "-----------", "%10llu%c " }, 2119 { " memory", " import", "----------", "%9llu%c " }, 2120 { " alloc", " succeed", "---------", "%9llu " }, 2121 { "alloc", " fail", "-----", "%5llu " }, 2122 { NULL, NULL, NULL, NULL } 2123 }; 2124 2125 /*ARGSUSED*/ 2126 static int 2127 kmastat_cpu_avail(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *avail) 2128 { 2129 if (ccp->cc_rounds > 0) 2130 *avail += ccp->cc_rounds; 2131 if (ccp->cc_prounds > 0) 2132 *avail += ccp->cc_prounds; 2133 2134 return (WALK_NEXT); 2135 } 2136 2137 /*ARGSUSED*/ 2138 static int 2139 kmastat_cpu_alloc(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *alloc) 2140 { 2141 *alloc += ccp->cc_alloc; 2142 2143 return (WALK_NEXT); 2144 } 2145 2146 /*ARGSUSED*/ 2147 static int 2148 kmastat_slab_avail(uintptr_t addr, const kmem_slab_t *sp, int *avail) 2149 { 2150 *avail += sp->slab_chunks - sp->slab_refcnt; 2151 2152 return (WALK_NEXT); 2153 } 2154 2155 typedef struct kmastat_vmem { 2156 uintptr_t kv_addr; 2157 struct kmastat_vmem *kv_next; 2158 int kv_meminuse; 2159 int kv_alloc; 2160 int kv_fail; 2161 } kmastat_vmem_t; 2162 2163 typedef struct kmastat_args { 2164 kmastat_vmem_t **ka_kvpp; 2165 uint_t ka_shift; 2166 } kmastat_args_t; 2167 2168 static int 2169 kmastat_cache(uintptr_t addr, const kmem_cache_t *cp, kmastat_args_t *kap) 2170 { 2171 kmastat_vmem_t **kvp = kap->ka_kvpp; 2172 kmastat_vmem_t *kv; 2173 datafmt_t *dfp = kmemfmt; 2174 int magsize; 2175 2176 int avail, alloc, total; 2177 size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) * 2178 cp->cache_slabsize; 2179 2180 mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)kmastat_cpu_avail; 2181 mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)kmastat_cpu_alloc; 2182 mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)kmastat_slab_avail; 2183 2184 magsize = kmem_get_magsize(cp); 2185 2186 alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc; 2187 avail = cp->cache_full.ml_total * magsize; 2188 total = cp->cache_buftotal; 2189 2190 (void) mdb_pwalk("kmem_cpu_cache", cpu_alloc, &alloc, addr); 2191 (void) mdb_pwalk("kmem_cpu_cache", cpu_avail, &avail, addr); 2192 (void) mdb_pwalk("kmem_slab_partial", slab_avail, &avail, addr); 2193 2194 for (kv = *kvp; kv != NULL; kv = kv->kv_next) { 2195 if (kv->kv_addr == (uintptr_t)cp->cache_arena) 2196 goto out; 2197 } 2198 2199 kv = mdb_zalloc(sizeof (kmastat_vmem_t), UM_SLEEP | UM_GC); 2200 kv->kv_next = *kvp; 2201 kv->kv_addr = (uintptr_t)cp->cache_arena; 2202 *kvp = kv; 2203 out: 2204 kv->kv_meminuse += meminuse; 2205 kv->kv_alloc += alloc; 2206 kv->kv_fail += cp->cache_alloc_fail; 2207 2208 mdb_printf((dfp++)->fmt, cp->cache_name); 2209 mdb_printf((dfp++)->fmt, cp->cache_bufsize); 2210 mdb_printf((dfp++)->fmt, total - avail); 2211 mdb_printf((dfp++)->fmt, total); 2212 mdb_printf((dfp++)->fmt, meminuse >> kap->ka_shift, 2213 kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' : 2214 kap->ka_shift == KILOS ? 'K' : 'B'); 2215 mdb_printf((dfp++)->fmt, alloc); 2216 mdb_printf((dfp++)->fmt, cp->cache_alloc_fail); 2217 mdb_printf("\n"); 2218 2219 return (WALK_NEXT); 2220 } 2221 2222 static int 2223 kmastat_vmem_totals(uintptr_t addr, const vmem_t *v, kmastat_args_t *kap) 2224 { 2225 kmastat_vmem_t *kv = *kap->ka_kvpp; 2226 size_t len; 2227 2228 while (kv != NULL && kv->kv_addr != addr) 2229 kv = kv->kv_next; 2230 2231 if (kv == NULL || kv->kv_alloc == 0) 2232 return (WALK_NEXT); 2233 2234 len = MIN(17, strlen(v->vm_name)); 2235 2236 mdb_printf("Total [%s]%*s %6s %6s %6s %9u%c %9u %5u\n", v->vm_name, 2237 17 - len, "", "", "", "", 2238 kv->kv_meminuse >> kap->ka_shift, 2239 kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' : 2240 kap->ka_shift == KILOS ? 'K' : 'B', kv->kv_alloc, kv->kv_fail); 2241 2242 return (WALK_NEXT); 2243 } 2244 2245 /*ARGSUSED*/ 2246 static int 2247 kmastat_vmem(uintptr_t addr, const vmem_t *v, const uint_t *shiftp) 2248 { 2249 datafmt_t *dfp = vmemfmt; 2250 const vmem_kstat_t *vkp = &v->vm_kstat; 2251 uintptr_t paddr; 2252 vmem_t parent; 2253 int ident = 0; 2254 2255 for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) { 2256 if (mdb_vread(&parent, sizeof (parent), paddr) == -1) { 2257 mdb_warn("couldn't trace %p's ancestry", addr); 2258 ident = 0; 2259 break; 2260 } 2261 paddr = (uintptr_t)parent.vm_source; 2262 } 2263 2264 mdb_printf("%*s", ident, ""); 2265 mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name); 2266 mdb_printf((dfp++)->fmt, vkp->vk_mem_inuse.value.ui64 >> *shiftp, 2267 *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' : 2268 *shiftp == KILOS ? 'K' : 'B'); 2269 mdb_printf((dfp++)->fmt, vkp->vk_mem_total.value.ui64 >> *shiftp, 2270 *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' : 2271 *shiftp == KILOS ? 'K' : 'B'); 2272 mdb_printf((dfp++)->fmt, vkp->vk_mem_import.value.ui64 >> *shiftp, 2273 *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' : 2274 *shiftp == KILOS ? 'K' : 'B'); 2275 mdb_printf((dfp++)->fmt, vkp->vk_alloc.value.ui64); 2276 mdb_printf((dfp++)->fmt, vkp->vk_fail.value.ui64); 2277 2278 mdb_printf("\n"); 2279 2280 return (WALK_NEXT); 2281 } 2282 2283 /*ARGSUSED*/ 2284 int 2285 kmastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2286 { 2287 kmastat_vmem_t *kv = NULL; 2288 datafmt_t *dfp; 2289 kmastat_args_t ka; 2290 2291 ka.ka_shift = 0; 2292 if (mdb_getopts(argc, argv, 2293 'k', MDB_OPT_SETBITS, KILOS, &ka.ka_shift, 2294 'm', MDB_OPT_SETBITS, MEGS, &ka.ka_shift, 2295 'g', MDB_OPT_SETBITS, GIGS, &ka.ka_shift, NULL) != argc) 2296 return (DCMD_USAGE); 2297 2298 for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 2299 mdb_printf("%s ", dfp->hdr1); 2300 mdb_printf("\n"); 2301 2302 for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 2303 mdb_printf("%s ", dfp->hdr2); 2304 mdb_printf("\n"); 2305 2306 for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 2307 mdb_printf("%s ", dfp->dashes); 2308 mdb_printf("\n"); 2309 2310 ka.ka_kvpp = &kv; 2311 if (mdb_walk("kmem_cache", (mdb_walk_cb_t)kmastat_cache, &ka) == -1) { 2312 mdb_warn("can't walk 'kmem_cache'"); 2313 return (DCMD_ERR); 2314 } 2315 2316 for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 2317 mdb_printf("%s ", dfp->dashes); 2318 mdb_printf("\n"); 2319 2320 if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem_totals, &ka) == -1) { 2321 mdb_warn("can't walk 'vmem'"); 2322 return (DCMD_ERR); 2323 } 2324 2325 for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++) 2326 mdb_printf("%s ", dfp->dashes); 2327 mdb_printf("\n"); 2328 2329 mdb_printf("\n"); 2330 2331 for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 2332 mdb_printf("%s ", dfp->hdr1); 2333 mdb_printf("\n"); 2334 2335 for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 2336 mdb_printf("%s ", dfp->hdr2); 2337 mdb_printf("\n"); 2338 2339 for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 2340 mdb_printf("%s ", dfp->dashes); 2341 mdb_printf("\n"); 2342 2343 if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem, &ka.ka_shift) == -1) { 2344 mdb_warn("can't walk 'vmem'"); 2345 return (DCMD_ERR); 2346 } 2347 2348 for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 2349 mdb_printf("%s ", dfp->dashes); 2350 mdb_printf("\n"); 2351 return (DCMD_OK); 2352 } 2353 2354 /* 2355 * Our ::kgrep callback scans the entire kernel VA space (kas). kas is made 2356 * up of a set of 'struct seg's. We could just scan each seg en masse, but 2357 * unfortunately, a few of the segs are both large and sparse, so we could 2358 * spend quite a bit of time scanning VAs which have no backing pages. 2359 * 2360 * So for the few very sparse segs, we skip the segment itself, and scan 2361 * the allocated vmem_segs in the vmem arena which manages that part of kas. 2362 * Currently, we do this for: 2363 * 2364 * SEG VMEM ARENA 2365 * kvseg heap_arena 2366 * kvseg32 heap32_arena 2367 * kvseg_core heap_core_arena 2368 * 2369 * In addition, we skip the segkpm segment in its entirety, since it is very 2370 * sparse, and contains no new kernel data. 2371 */ 2372 typedef struct kgrep_walk_data { 2373 kgrep_cb_func *kg_cb; 2374 void *kg_cbdata; 2375 uintptr_t kg_kvseg; 2376 uintptr_t kg_kvseg32; 2377 uintptr_t kg_kvseg_core; 2378 uintptr_t kg_segkpm; 2379 uintptr_t kg_heap_lp_base; 2380 uintptr_t kg_heap_lp_end; 2381 } kgrep_walk_data_t; 2382 2383 static int 2384 kgrep_walk_seg(uintptr_t addr, const struct seg *seg, kgrep_walk_data_t *kg) 2385 { 2386 uintptr_t base = (uintptr_t)seg->s_base; 2387 2388 if (addr == kg->kg_kvseg || addr == kg->kg_kvseg32 || 2389 addr == kg->kg_kvseg_core) 2390 return (WALK_NEXT); 2391 2392 if ((uintptr_t)seg->s_ops == kg->kg_segkpm) 2393 return (WALK_NEXT); 2394 2395 return (kg->kg_cb(base, base + seg->s_size, kg->kg_cbdata)); 2396 } 2397 2398 /*ARGSUSED*/ 2399 static int 2400 kgrep_walk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg) 2401 { 2402 /* 2403 * skip large page heap address range - it is scanned by walking 2404 * allocated vmem_segs in the heap_lp_arena 2405 */ 2406 if (seg->vs_start == kg->kg_heap_lp_base && 2407 seg->vs_end == kg->kg_heap_lp_end) 2408 return (WALK_NEXT); 2409 2410 return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata)); 2411 } 2412 2413 /*ARGSUSED*/ 2414 static int 2415 kgrep_xwalk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg) 2416 { 2417 return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata)); 2418 } 2419 2420 static int 2421 kgrep_walk_vmem(uintptr_t addr, const vmem_t *vmem, kgrep_walk_data_t *kg) 2422 { 2423 mdb_walk_cb_t walk_vseg = (mdb_walk_cb_t)kgrep_walk_vseg; 2424 2425 if (strcmp(vmem->vm_name, "heap") != 0 && 2426 strcmp(vmem->vm_name, "heap32") != 0 && 2427 strcmp(vmem->vm_name, "heap_core") != 0 && 2428 strcmp(vmem->vm_name, "heap_lp") != 0) 2429 return (WALK_NEXT); 2430 2431 if (strcmp(vmem->vm_name, "heap_lp") == 0) 2432 walk_vseg = (mdb_walk_cb_t)kgrep_xwalk_vseg; 2433 2434 if (mdb_pwalk("vmem_alloc", walk_vseg, kg, addr) == -1) { 2435 mdb_warn("couldn't walk vmem_alloc for vmem %p", addr); 2436 return (WALK_ERR); 2437 } 2438 2439 return (WALK_NEXT); 2440 } 2441 2442 int 2443 kgrep_subr(kgrep_cb_func *cb, void *cbdata) 2444 { 2445 GElf_Sym kas, kvseg, kvseg32, kvseg_core, segkpm; 2446 kgrep_walk_data_t kg; 2447 2448 if (mdb_get_state() == MDB_STATE_RUNNING) { 2449 mdb_warn("kgrep can only be run on a system " 2450 "dump or under kmdb; see dumpadm(1M)\n"); 2451 return (DCMD_ERR); 2452 } 2453 2454 if (mdb_lookup_by_name("kas", &kas) == -1) { 2455 mdb_warn("failed to locate 'kas' symbol\n"); 2456 return (DCMD_ERR); 2457 } 2458 2459 if (mdb_lookup_by_name("kvseg", &kvseg) == -1) { 2460 mdb_warn("failed to locate 'kvseg' symbol\n"); 2461 return (DCMD_ERR); 2462 } 2463 2464 if (mdb_lookup_by_name("kvseg32", &kvseg32) == -1) { 2465 mdb_warn("failed to locate 'kvseg32' symbol\n"); 2466 return (DCMD_ERR); 2467 } 2468 2469 if (mdb_lookup_by_name("kvseg_core", &kvseg_core) == -1) { 2470 mdb_warn("failed to locate 'kvseg_core' symbol\n"); 2471 return (DCMD_ERR); 2472 } 2473 2474 if (mdb_lookup_by_name("segkpm_ops", &segkpm) == -1) { 2475 mdb_warn("failed to locate 'segkpm_ops' symbol\n"); 2476 return (DCMD_ERR); 2477 } 2478 2479 if (mdb_readvar(&kg.kg_heap_lp_base, "heap_lp_base") == -1) { 2480 mdb_warn("failed to read 'heap_lp_base'\n"); 2481 return (DCMD_ERR); 2482 } 2483 2484 if (mdb_readvar(&kg.kg_heap_lp_end, "heap_lp_end") == -1) { 2485 mdb_warn("failed to read 'heap_lp_end'\n"); 2486 return (DCMD_ERR); 2487 } 2488 2489 kg.kg_cb = cb; 2490 kg.kg_cbdata = cbdata; 2491 kg.kg_kvseg = (uintptr_t)kvseg.st_value; 2492 kg.kg_kvseg32 = (uintptr_t)kvseg32.st_value; 2493 kg.kg_kvseg_core = (uintptr_t)kvseg_core.st_value; 2494 kg.kg_segkpm = (uintptr_t)segkpm.st_value; 2495 2496 if (mdb_pwalk("seg", (mdb_walk_cb_t)kgrep_walk_seg, 2497 &kg, kas.st_value) == -1) { 2498 mdb_warn("failed to walk kas segments"); 2499 return (DCMD_ERR); 2500 } 2501 2502 if (mdb_walk("vmem", (mdb_walk_cb_t)kgrep_walk_vmem, &kg) == -1) { 2503 mdb_warn("failed to walk heap/heap32 vmem arenas"); 2504 return (DCMD_ERR); 2505 } 2506 2507 return (DCMD_OK); 2508 } 2509 2510 size_t 2511 kgrep_subr_pagesize(void) 2512 { 2513 return (PAGESIZE); 2514 } 2515 2516 typedef struct file_walk_data { 2517 struct uf_entry *fw_flist; 2518 int fw_flistsz; 2519 int fw_ndx; 2520 int fw_nofiles; 2521 } file_walk_data_t; 2522 2523 int 2524 file_walk_init(mdb_walk_state_t *wsp) 2525 { 2526 file_walk_data_t *fw; 2527 proc_t p; 2528 2529 if (wsp->walk_addr == NULL) { 2530 mdb_warn("file walk doesn't support global walks\n"); 2531 return (WALK_ERR); 2532 } 2533 2534 fw = mdb_alloc(sizeof (file_walk_data_t), UM_SLEEP); 2535 2536 if (mdb_vread(&p, sizeof (p), wsp->walk_addr) == -1) { 2537 mdb_free(fw, sizeof (file_walk_data_t)); 2538 mdb_warn("failed to read proc structure at %p", wsp->walk_addr); 2539 return (WALK_ERR); 2540 } 2541 2542 if (p.p_user.u_finfo.fi_nfiles == 0) { 2543 mdb_free(fw, sizeof (file_walk_data_t)); 2544 return (WALK_DONE); 2545 } 2546 2547 fw->fw_nofiles = p.p_user.u_finfo.fi_nfiles; 2548 fw->fw_flistsz = sizeof (struct uf_entry) * fw->fw_nofiles; 2549 fw->fw_flist = mdb_alloc(fw->fw_flistsz, UM_SLEEP); 2550 2551 if (mdb_vread(fw->fw_flist, fw->fw_flistsz, 2552 (uintptr_t)p.p_user.u_finfo.fi_list) == -1) { 2553 mdb_warn("failed to read file array at %p", 2554 p.p_user.u_finfo.fi_list); 2555 mdb_free(fw->fw_flist, fw->fw_flistsz); 2556 mdb_free(fw, sizeof (file_walk_data_t)); 2557 return (WALK_ERR); 2558 } 2559 2560 fw->fw_ndx = 0; 2561 wsp->walk_data = fw; 2562 2563 return (WALK_NEXT); 2564 } 2565 2566 int 2567 file_walk_step(mdb_walk_state_t *wsp) 2568 { 2569 file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data; 2570 struct file file; 2571 uintptr_t fp; 2572 2573 again: 2574 if (fw->fw_ndx == fw->fw_nofiles) 2575 return (WALK_DONE); 2576 2577 if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) == NULL) 2578 goto again; 2579 2580 (void) mdb_vread(&file, sizeof (file), (uintptr_t)fp); 2581 return (wsp->walk_callback(fp, &file, wsp->walk_cbdata)); 2582 } 2583 2584 int 2585 allfile_walk_step(mdb_walk_state_t *wsp) 2586 { 2587 file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data; 2588 struct file file; 2589 uintptr_t fp; 2590 2591 if (fw->fw_ndx == fw->fw_nofiles) 2592 return (WALK_DONE); 2593 2594 if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) != NULL) 2595 (void) mdb_vread(&file, sizeof (file), (uintptr_t)fp); 2596 else 2597 bzero(&file, sizeof (file)); 2598 2599 return (wsp->walk_callback(fp, &file, wsp->walk_cbdata)); 2600 } 2601 2602 void 2603 file_walk_fini(mdb_walk_state_t *wsp) 2604 { 2605 file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data; 2606 2607 mdb_free(fw->fw_flist, fw->fw_flistsz); 2608 mdb_free(fw, sizeof (file_walk_data_t)); 2609 } 2610 2611 int 2612 port_walk_init(mdb_walk_state_t *wsp) 2613 { 2614 if (wsp->walk_addr == NULL) { 2615 mdb_warn("port walk doesn't support global walks\n"); 2616 return (WALK_ERR); 2617 } 2618 2619 if (mdb_layered_walk("file", wsp) == -1) { 2620 mdb_warn("couldn't walk 'file'"); 2621 return (WALK_ERR); 2622 } 2623 return (WALK_NEXT); 2624 } 2625 2626 int 2627 port_walk_step(mdb_walk_state_t *wsp) 2628 { 2629 struct vnode vn; 2630 uintptr_t vp; 2631 uintptr_t pp; 2632 struct port port; 2633 2634 vp = (uintptr_t)((struct file *)wsp->walk_layer)->f_vnode; 2635 if (mdb_vread(&vn, sizeof (vn), vp) == -1) { 2636 mdb_warn("failed to read vnode_t at %p", vp); 2637 return (WALK_ERR); 2638 } 2639 if (vn.v_type != VPORT) 2640 return (WALK_NEXT); 2641 2642 pp = (uintptr_t)vn.v_data; 2643 if (mdb_vread(&port, sizeof (port), pp) == -1) { 2644 mdb_warn("failed to read port_t at %p", pp); 2645 return (WALK_ERR); 2646 } 2647 return (wsp->walk_callback(pp, &port, wsp->walk_cbdata)); 2648 } 2649 2650 typedef struct portev_walk_data { 2651 list_node_t *pev_node; 2652 list_node_t *pev_last; 2653 size_t pev_offset; 2654 } portev_walk_data_t; 2655 2656 int 2657 portev_walk_init(mdb_walk_state_t *wsp) 2658 { 2659 portev_walk_data_t *pevd; 2660 struct port port; 2661 struct vnode vn; 2662 struct list *list; 2663 uintptr_t vp; 2664 2665 if (wsp->walk_addr == NULL) { 2666 mdb_warn("portev walk doesn't support global walks\n"); 2667 return (WALK_ERR); 2668 } 2669 2670 pevd = mdb_alloc(sizeof (portev_walk_data_t), UM_SLEEP); 2671 2672 if (mdb_vread(&port, sizeof (port), wsp->walk_addr) == -1) { 2673 mdb_free(pevd, sizeof (portev_walk_data_t)); 2674 mdb_warn("failed to read port structure at %p", wsp->walk_addr); 2675 return (WALK_ERR); 2676 } 2677 2678 vp = (uintptr_t)port.port_vnode; 2679 if (mdb_vread(&vn, sizeof (vn), vp) == -1) { 2680 mdb_free(pevd, sizeof (portev_walk_data_t)); 2681 mdb_warn("failed to read vnode_t at %p", vp); 2682 return (WALK_ERR); 2683 } 2684 2685 if (vn.v_type != VPORT) { 2686 mdb_free(pevd, sizeof (portev_walk_data_t)); 2687 mdb_warn("input address (%p) does not point to an event port", 2688 wsp->walk_addr); 2689 return (WALK_ERR); 2690 } 2691 2692 if (port.port_queue.portq_nent == 0) { 2693 mdb_free(pevd, sizeof (portev_walk_data_t)); 2694 return (WALK_DONE); 2695 } 2696 list = &port.port_queue.portq_list; 2697 pevd->pev_offset = list->list_offset; 2698 pevd->pev_last = list->list_head.list_prev; 2699 pevd->pev_node = list->list_head.list_next; 2700 wsp->walk_data = pevd; 2701 return (WALK_NEXT); 2702 } 2703 2704 int 2705 portev_walk_step(mdb_walk_state_t *wsp) 2706 { 2707 portev_walk_data_t *pevd; 2708 struct port_kevent ev; 2709 uintptr_t evp; 2710 2711 pevd = (portev_walk_data_t *)wsp->walk_data; 2712 2713 if (pevd->pev_last == NULL) 2714 return (WALK_DONE); 2715 if (pevd->pev_node == pevd->pev_last) 2716 pevd->pev_last = NULL; /* last round */ 2717 2718 evp = ((uintptr_t)(((char *)pevd->pev_node) - pevd->pev_offset)); 2719 if (mdb_vread(&ev, sizeof (ev), evp) == -1) { 2720 mdb_warn("failed to read port_kevent at %p", evp); 2721 return (WALK_DONE); 2722 } 2723 pevd->pev_node = ev.portkev_node.list_next; 2724 return (wsp->walk_callback(evp, &ev, wsp->walk_cbdata)); 2725 } 2726 2727 void 2728 portev_walk_fini(mdb_walk_state_t *wsp) 2729 { 2730 portev_walk_data_t *pevd = (portev_walk_data_t *)wsp->walk_data; 2731 2732 if (pevd != NULL) 2733 mdb_free(pevd, sizeof (portev_walk_data_t)); 2734 } 2735 2736 typedef struct proc_walk_data { 2737 uintptr_t *pw_stack; 2738 int pw_depth; 2739 int pw_max; 2740 } proc_walk_data_t; 2741 2742 int 2743 proc_walk_init(mdb_walk_state_t *wsp) 2744 { 2745 GElf_Sym sym; 2746 proc_walk_data_t *pw; 2747 2748 if (wsp->walk_addr == NULL) { 2749 if (mdb_lookup_by_name("p0", &sym) == -1) { 2750 mdb_warn("failed to read 'practive'"); 2751 return (WALK_ERR); 2752 } 2753 wsp->walk_addr = (uintptr_t)sym.st_value; 2754 } 2755 2756 pw = mdb_zalloc(sizeof (proc_walk_data_t), UM_SLEEP); 2757 2758 if (mdb_readvar(&pw->pw_max, "nproc") == -1) { 2759 mdb_warn("failed to read 'nproc'"); 2760 mdb_free(pw, sizeof (pw)); 2761 return (WALK_ERR); 2762 } 2763 2764 pw->pw_stack = mdb_alloc(pw->pw_max * sizeof (uintptr_t), UM_SLEEP); 2765 wsp->walk_data = pw; 2766 2767 return (WALK_NEXT); 2768 } 2769 2770 int 2771 proc_walk_step(mdb_walk_state_t *wsp) 2772 { 2773 proc_walk_data_t *pw = wsp->walk_data; 2774 uintptr_t addr = wsp->walk_addr; 2775 uintptr_t cld, sib; 2776 2777 int status; 2778 proc_t pr; 2779 2780 if (mdb_vread(&pr, sizeof (proc_t), addr) == -1) { 2781 mdb_warn("failed to read proc at %p", addr); 2782 return (WALK_DONE); 2783 } 2784 2785 cld = (uintptr_t)pr.p_child; 2786 sib = (uintptr_t)pr.p_sibling; 2787 2788 if (pw->pw_depth > 0 && addr == pw->pw_stack[pw->pw_depth - 1]) { 2789 pw->pw_depth--; 2790 goto sib; 2791 } 2792 2793 status = wsp->walk_callback(addr, &pr, wsp->walk_cbdata); 2794 2795 if (status != WALK_NEXT) 2796 return (status); 2797 2798 if ((wsp->walk_addr = cld) != NULL) { 2799 if (mdb_vread(&pr, sizeof (proc_t), cld) == -1) { 2800 mdb_warn("proc %p has invalid p_child %p; skipping\n", 2801 addr, cld); 2802 goto sib; 2803 } 2804 2805 pw->pw_stack[pw->pw_depth++] = addr; 2806 2807 if (pw->pw_depth == pw->pw_max) { 2808 mdb_warn("depth %d exceeds max depth; try again\n", 2809 pw->pw_depth); 2810 return (WALK_DONE); 2811 } 2812 return (WALK_NEXT); 2813 } 2814 2815 sib: 2816 /* 2817 * We know that p0 has no siblings, and if another starting proc 2818 * was given, we don't want to walk its siblings anyway. 2819 */ 2820 if (pw->pw_depth == 0) 2821 return (WALK_DONE); 2822 2823 if (sib != NULL && mdb_vread(&pr, sizeof (proc_t), sib) == -1) { 2824 mdb_warn("proc %p has invalid p_sibling %p; skipping\n", 2825 addr, sib); 2826 sib = NULL; 2827 } 2828 2829 if ((wsp->walk_addr = sib) == NULL) { 2830 if (pw->pw_depth > 0) { 2831 wsp->walk_addr = pw->pw_stack[pw->pw_depth - 1]; 2832 return (WALK_NEXT); 2833 } 2834 return (WALK_DONE); 2835 } 2836 2837 return (WALK_NEXT); 2838 } 2839 2840 void 2841 proc_walk_fini(mdb_walk_state_t *wsp) 2842 { 2843 proc_walk_data_t *pw = wsp->walk_data; 2844 2845 mdb_free(pw->pw_stack, pw->pw_max * sizeof (uintptr_t)); 2846 mdb_free(pw, sizeof (proc_walk_data_t)); 2847 } 2848 2849 int 2850 task_walk_init(mdb_walk_state_t *wsp) 2851 { 2852 task_t task; 2853 2854 if (mdb_vread(&task, sizeof (task_t), wsp->walk_addr) == -1) { 2855 mdb_warn("failed to read task at %p", wsp->walk_addr); 2856 return (WALK_ERR); 2857 } 2858 wsp->walk_addr = (uintptr_t)task.tk_memb_list; 2859 wsp->walk_data = task.tk_memb_list; 2860 return (WALK_NEXT); 2861 } 2862 2863 int 2864 task_walk_step(mdb_walk_state_t *wsp) 2865 { 2866 proc_t proc; 2867 int status; 2868 2869 if (mdb_vread(&proc, sizeof (proc_t), wsp->walk_addr) == -1) { 2870 mdb_warn("failed to read proc at %p", wsp->walk_addr); 2871 return (WALK_DONE); 2872 } 2873 2874 status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata); 2875 2876 if (proc.p_tasknext == wsp->walk_data) 2877 return (WALK_DONE); 2878 2879 wsp->walk_addr = (uintptr_t)proc.p_tasknext; 2880 return (status); 2881 } 2882 2883 int 2884 project_walk_init(mdb_walk_state_t *wsp) 2885 { 2886 if (wsp->walk_addr == NULL) { 2887 if (mdb_readvar(&wsp->walk_addr, "proj0p") == -1) { 2888 mdb_warn("failed to read 'proj0p'"); 2889 return (WALK_ERR); 2890 } 2891 } 2892 wsp->walk_data = (void *)wsp->walk_addr; 2893 return (WALK_NEXT); 2894 } 2895 2896 int 2897 project_walk_step(mdb_walk_state_t *wsp) 2898 { 2899 uintptr_t addr = wsp->walk_addr; 2900 kproject_t pj; 2901 int status; 2902 2903 if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) { 2904 mdb_warn("failed to read project at %p", addr); 2905 return (WALK_DONE); 2906 } 2907 status = wsp->walk_callback(addr, &pj, wsp->walk_cbdata); 2908 if (status != WALK_NEXT) 2909 return (status); 2910 wsp->walk_addr = (uintptr_t)pj.kpj_next; 2911 if ((void *)wsp->walk_addr == wsp->walk_data) 2912 return (WALK_DONE); 2913 return (WALK_NEXT); 2914 } 2915 2916 static int 2917 generic_walk_step(mdb_walk_state_t *wsp) 2918 { 2919 return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer, 2920 wsp->walk_cbdata)); 2921 } 2922 2923 int 2924 seg_walk_init(mdb_walk_state_t *wsp) 2925 { 2926 if (wsp->walk_addr == NULL) { 2927 mdb_warn("seg walk must begin at struct as *\n"); 2928 return (WALK_ERR); 2929 } 2930 2931 /* 2932 * this is really just a wrapper to AVL tree walk 2933 */ 2934 wsp->walk_addr = (uintptr_t)&((struct as *)wsp->walk_addr)->a_segtree; 2935 return (avl_walk_init(wsp)); 2936 } 2937 2938 static int 2939 cpu_walk_cmp(const void *l, const void *r) 2940 { 2941 uintptr_t lhs = *((uintptr_t *)l); 2942 uintptr_t rhs = *((uintptr_t *)r); 2943 cpu_t lcpu, rcpu; 2944 2945 (void) mdb_vread(&lcpu, sizeof (lcpu), lhs); 2946 (void) mdb_vread(&rcpu, sizeof (rcpu), rhs); 2947 2948 if (lcpu.cpu_id < rcpu.cpu_id) 2949 return (-1); 2950 2951 if (lcpu.cpu_id > rcpu.cpu_id) 2952 return (1); 2953 2954 return (0); 2955 } 2956 2957 typedef struct cpu_walk { 2958 uintptr_t *cw_array; 2959 int cw_ndx; 2960 } cpu_walk_t; 2961 2962 int 2963 cpu_walk_init(mdb_walk_state_t *wsp) 2964 { 2965 cpu_walk_t *cw; 2966 int max_ncpus, i = 0; 2967 uintptr_t current, first; 2968 cpu_t cpu, panic_cpu; 2969 uintptr_t panicstr, addr; 2970 GElf_Sym sym; 2971 2972 cw = mdb_zalloc(sizeof (cpu_walk_t), UM_SLEEP | UM_GC); 2973 2974 if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) { 2975 mdb_warn("failed to read 'max_ncpus'"); 2976 return (WALK_ERR); 2977 } 2978 2979 if (mdb_readvar(&panicstr, "panicstr") == -1) { 2980 mdb_warn("failed to read 'panicstr'"); 2981 return (WALK_ERR); 2982 } 2983 2984 if (panicstr != NULL) { 2985 if (mdb_lookup_by_name("panic_cpu", &sym) == -1) { 2986 mdb_warn("failed to find 'panic_cpu'"); 2987 return (WALK_ERR); 2988 } 2989 2990 addr = (uintptr_t)sym.st_value; 2991 2992 if (mdb_vread(&panic_cpu, sizeof (cpu_t), addr) == -1) { 2993 mdb_warn("failed to read 'panic_cpu'"); 2994 return (WALK_ERR); 2995 } 2996 } 2997 2998 /* 2999 * Unfortunately, there is no platform-independent way to walk 3000 * CPUs in ID order. We therefore loop through in cpu_next order, 3001 * building an array of CPU pointers which will subsequently be 3002 * sorted. 3003 */ 3004 cw->cw_array = 3005 mdb_zalloc((max_ncpus + 1) * sizeof (uintptr_t), UM_SLEEP | UM_GC); 3006 3007 if (mdb_readvar(&first, "cpu_list") == -1) { 3008 mdb_warn("failed to read 'cpu_list'"); 3009 return (WALK_ERR); 3010 } 3011 3012 current = first; 3013 do { 3014 if (mdb_vread(&cpu, sizeof (cpu), current) == -1) { 3015 mdb_warn("failed to read cpu at %p", current); 3016 return (WALK_ERR); 3017 } 3018 3019 if (panicstr != NULL && panic_cpu.cpu_id == cpu.cpu_id) { 3020 cw->cw_array[i++] = addr; 3021 } else { 3022 cw->cw_array[i++] = current; 3023 } 3024 } while ((current = (uintptr_t)cpu.cpu_next) != first); 3025 3026 qsort(cw->cw_array, i, sizeof (uintptr_t), cpu_walk_cmp); 3027 wsp->walk_data = cw; 3028 3029 return (WALK_NEXT); 3030 } 3031 3032 int 3033 cpu_walk_step(mdb_walk_state_t *wsp) 3034 { 3035 cpu_walk_t *cw = wsp->walk_data; 3036 cpu_t cpu; 3037 uintptr_t addr = cw->cw_array[cw->cw_ndx++]; 3038 3039 if (addr == NULL) 3040 return (WALK_DONE); 3041 3042 if (mdb_vread(&cpu, sizeof (cpu), addr) == -1) { 3043 mdb_warn("failed to read cpu at %p", addr); 3044 return (WALK_DONE); 3045 } 3046 3047 return (wsp->walk_callback(addr, &cpu, wsp->walk_cbdata)); 3048 } 3049 3050 typedef struct cpuinfo_data { 3051 intptr_t cid_cpu; 3052 uintptr_t cid_lbolt; 3053 uintptr_t **cid_ithr; 3054 char cid_print_head; 3055 char cid_print_thr; 3056 char cid_print_ithr; 3057 char cid_print_flags; 3058 } cpuinfo_data_t; 3059 3060 int 3061 cpuinfo_walk_ithread(uintptr_t addr, const kthread_t *thr, cpuinfo_data_t *cid) 3062 { 3063 cpu_t c; 3064 int id; 3065 uint8_t pil; 3066 3067 if (!(thr->t_flag & T_INTR_THREAD) || thr->t_state == TS_FREE) 3068 return (WALK_NEXT); 3069 3070 if (thr->t_bound_cpu == NULL) { 3071 mdb_warn("thr %p is intr thread w/out a CPU\n", addr); 3072 return (WALK_NEXT); 3073 } 3074 3075 (void) mdb_vread(&c, sizeof (c), (uintptr_t)thr->t_bound_cpu); 3076 3077 if ((id = c.cpu_id) >= NCPU) { 3078 mdb_warn("CPU %p has id (%d) greater than NCPU (%d)\n", 3079 thr->t_bound_cpu, id, NCPU); 3080 return (WALK_NEXT); 3081 } 3082 3083 if ((pil = thr->t_pil) >= NINTR) { 3084 mdb_warn("thread %p has pil (%d) greater than %d\n", 3085 addr, pil, NINTR); 3086 return (WALK_NEXT); 3087 } 3088 3089 if (cid->cid_ithr[id][pil] != NULL) { 3090 mdb_warn("CPU %d has multiple threads at pil %d (at least " 3091 "%p and %p)\n", id, pil, addr, cid->cid_ithr[id][pil]); 3092 return (WALK_NEXT); 3093 } 3094 3095 cid->cid_ithr[id][pil] = addr; 3096 3097 return (WALK_NEXT); 3098 } 3099 3100 #define CPUINFO_IDWIDTH 3 3101 #define CPUINFO_FLAGWIDTH 9 3102 3103 #ifdef _LP64 3104 #if defined(__amd64) 3105 #define CPUINFO_TWIDTH 16 3106 #define CPUINFO_CPUWIDTH 16 3107 #else 3108 #define CPUINFO_CPUWIDTH 11 3109 #define CPUINFO_TWIDTH 11 3110 #endif 3111 #else 3112 #define CPUINFO_CPUWIDTH 8 3113 #define CPUINFO_TWIDTH 8 3114 #endif 3115 3116 #define CPUINFO_THRDELT (CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 9) 3117 #define CPUINFO_FLAGDELT (CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 4) 3118 #define CPUINFO_ITHRDELT 4 3119 3120 #define CPUINFO_INDENT mdb_printf("%*s", CPUINFO_THRDELT, \ 3121 flagline < nflaglines ? flagbuf[flagline++] : "") 3122 3123 int 3124 cpuinfo_walk_cpu(uintptr_t addr, const cpu_t *cpu, cpuinfo_data_t *cid) 3125 { 3126 kthread_t t; 3127 disp_t disp; 3128 proc_t p; 3129 uintptr_t pinned; 3130 char **flagbuf; 3131 int nflaglines = 0, flagline = 0, bspl, rval = WALK_NEXT; 3132 3133 const char *flags[] = { 3134 "RUNNING", "READY", "QUIESCED", "EXISTS", 3135 "ENABLE", "OFFLINE", "POWEROFF", "FROZEN", 3136 "SPARE", "FAULTED", NULL 3137 }; 3138 3139 if (cid->cid_cpu != -1) { 3140 if (addr != cid->cid_cpu && cpu->cpu_id != cid->cid_cpu) 3141 return (WALK_NEXT); 3142 3143 /* 3144 * Set cid_cpu to -1 to indicate that we found a matching CPU. 3145 */ 3146 cid->cid_cpu = -1; 3147 rval = WALK_DONE; 3148 } 3149 3150 if (cid->cid_print_head) { 3151 mdb_printf("%3s %-*s %3s %4s %4s %3s %4s %5s %-6s %-*s %s\n", 3152 "ID", CPUINFO_CPUWIDTH, "ADDR", "FLG", "NRUN", "BSPL", 3153 "PRI", "RNRN", "KRNRN", "SWITCH", CPUINFO_TWIDTH, "THREAD", 3154 "PROC"); 3155 cid->cid_print_head = FALSE; 3156 } 3157 3158 bspl = cpu->cpu_base_spl; 3159 3160 if (mdb_vread(&disp, sizeof (disp_t), (uintptr_t)cpu->cpu_disp) == -1) { 3161 mdb_warn("failed to read disp_t at %p", cpu->cpu_disp); 3162 return (WALK_ERR); 3163 } 3164 3165 mdb_printf("%3d %0*p %3x %4d %4d ", 3166 cpu->cpu_id, CPUINFO_CPUWIDTH, addr, cpu->cpu_flags, 3167 disp.disp_nrunnable, bspl); 3168 3169 if (mdb_vread(&t, sizeof (t), (uintptr_t)cpu->cpu_thread) != -1) { 3170 mdb_printf("%3d ", t.t_pri); 3171 } else { 3172 mdb_printf("%3s ", "-"); 3173 } 3174 3175 mdb_printf("%4s %5s ", cpu->cpu_runrun ? "yes" : "no", 3176 cpu->cpu_kprunrun ? "yes" : "no"); 3177 3178 if (cpu->cpu_last_swtch) { 3179 clock_t lbolt; 3180 3181 if (mdb_vread(&lbolt, sizeof (lbolt), cid->cid_lbolt) == -1) { 3182 mdb_warn("failed to read lbolt at %p", cid->cid_lbolt); 3183 return (WALK_ERR); 3184 } 3185 mdb_printf("t-%-4d ", lbolt - cpu->cpu_last_swtch); 3186 } else { 3187 mdb_printf("%-6s ", "-"); 3188 } 3189 3190 mdb_printf("%0*p", CPUINFO_TWIDTH, cpu->cpu_thread); 3191 3192 if (cpu->cpu_thread == cpu->cpu_idle_thread) 3193 mdb_printf(" (idle)\n"); 3194 else if (cpu->cpu_thread == NULL) 3195 mdb_printf(" -\n"); 3196 else { 3197 if (mdb_vread(&p, sizeof (p), (uintptr_t)t.t_procp) != -1) { 3198 mdb_printf(" %s\n", p.p_user.u_comm); 3199 } else { 3200 mdb_printf(" ?\n"); 3201 } 3202 } 3203 3204 flagbuf = mdb_zalloc(sizeof (flags), UM_SLEEP | UM_GC); 3205 3206 if (cid->cid_print_flags) { 3207 int first = 1, i, j, k; 3208 char *s; 3209 3210 cid->cid_print_head = TRUE; 3211 3212 for (i = 1, j = 0; flags[j] != NULL; i <<= 1, j++) { 3213 if (!(cpu->cpu_flags & i)) 3214 continue; 3215 3216 if (first) { 3217 s = mdb_alloc(CPUINFO_THRDELT + 1, 3218 UM_GC | UM_SLEEP); 3219 3220 (void) mdb_snprintf(s, CPUINFO_THRDELT + 1, 3221 "%*s|%*s", CPUINFO_FLAGDELT, "", 3222 CPUINFO_THRDELT - 1 - CPUINFO_FLAGDELT, ""); 3223 flagbuf[nflaglines++] = s; 3224 } 3225 3226 s = mdb_alloc(CPUINFO_THRDELT + 1, UM_GC | UM_SLEEP); 3227 (void) mdb_snprintf(s, CPUINFO_THRDELT + 1, "%*s%*s %s", 3228 CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH - 3229 CPUINFO_FLAGWIDTH, "", CPUINFO_FLAGWIDTH, flags[j], 3230 first ? "<--+" : ""); 3231 3232 for (k = strlen(s); k < CPUINFO_THRDELT; k++) 3233 s[k] = ' '; 3234 s[k] = '\0'; 3235 3236 flagbuf[nflaglines++] = s; 3237 first = 0; 3238 } 3239 } 3240 3241 if (cid->cid_print_ithr) { 3242 int i, found_one = FALSE; 3243 int print_thr = disp.disp_nrunnable && cid->cid_print_thr; 3244 3245 for (i = NINTR - 1; i >= 0; i--) { 3246 uintptr_t iaddr = cid->cid_ithr[cpu->cpu_id][i]; 3247 3248 if (iaddr == NULL) 3249 continue; 3250 3251 if (!found_one) { 3252 found_one = TRUE; 3253 3254 CPUINFO_INDENT; 3255 mdb_printf("%c%*s|\n", print_thr ? '|' : ' ', 3256 CPUINFO_ITHRDELT, ""); 3257 3258 CPUINFO_INDENT; 3259 mdb_printf("%c%*s+--> %3s %s\n", 3260 print_thr ? '|' : ' ', CPUINFO_ITHRDELT, 3261 "", "PIL", "THREAD"); 3262 } 3263 3264 if (mdb_vread(&t, sizeof (t), iaddr) == -1) { 3265 mdb_warn("failed to read kthread_t at %p", 3266 iaddr); 3267 return (WALK_ERR); 3268 } 3269 3270 CPUINFO_INDENT; 3271 mdb_printf("%c%*s %3d %0*p\n", 3272 print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", 3273 t.t_pil, CPUINFO_TWIDTH, iaddr); 3274 3275 pinned = (uintptr_t)t.t_intr; 3276 } 3277 3278 if (found_one && pinned != NULL) { 3279 cid->cid_print_head = TRUE; 3280 (void) strcpy(p.p_user.u_comm, "?"); 3281 3282 if (mdb_vread(&t, sizeof (t), 3283 (uintptr_t)pinned) == -1) { 3284 mdb_warn("failed to read kthread_t at %p", 3285 pinned); 3286 return (WALK_ERR); 3287 } 3288 if (mdb_vread(&p, sizeof (p), 3289 (uintptr_t)t.t_procp) == -1) { 3290 mdb_warn("failed to read proc_t at %p", 3291 t.t_procp); 3292 return (WALK_ERR); 3293 } 3294 3295 CPUINFO_INDENT; 3296 mdb_printf("%c%*s %3s %0*p %s\n", 3297 print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", "-", 3298 CPUINFO_TWIDTH, pinned, 3299 pinned == (uintptr_t)cpu->cpu_idle_thread ? 3300 "(idle)" : p.p_user.u_comm); 3301 } 3302 } 3303 3304 if (disp.disp_nrunnable && cid->cid_print_thr) { 3305 dispq_t *dq; 3306 3307 int i, npri = disp.disp_npri; 3308 3309 dq = mdb_alloc(sizeof (dispq_t) * npri, UM_SLEEP | UM_GC); 3310 3311 if (mdb_vread(dq, sizeof (dispq_t) * npri, 3312 (uintptr_t)disp.disp_q) == -1) { 3313 mdb_warn("failed to read dispq_t at %p", disp.disp_q); 3314 return (WALK_ERR); 3315 } 3316 3317 CPUINFO_INDENT; 3318 mdb_printf("|\n"); 3319 3320 CPUINFO_INDENT; 3321 mdb_printf("+--> %3s %-*s %s\n", "PRI", 3322 CPUINFO_TWIDTH, "THREAD", "PROC"); 3323 3324 for (i = npri - 1; i >= 0; i--) { 3325 uintptr_t taddr = (uintptr_t)dq[i].dq_first; 3326 3327 while (taddr != NULL) { 3328 if (mdb_vread(&t, sizeof (t), taddr) == -1) { 3329 mdb_warn("failed to read kthread_t " 3330 "at %p", taddr); 3331 return (WALK_ERR); 3332 } 3333 if (mdb_vread(&p, sizeof (p), 3334 (uintptr_t)t.t_procp) == -1) { 3335 mdb_warn("failed to read proc_t at %p", 3336 t.t_procp); 3337 return (WALK_ERR); 3338 } 3339 3340 CPUINFO_INDENT; 3341 mdb_printf(" %3d %0*p %s\n", t.t_pri, 3342 CPUINFO_TWIDTH, taddr, p.p_user.u_comm); 3343 3344 taddr = (uintptr_t)t.t_link; 3345 } 3346 } 3347 cid->cid_print_head = TRUE; 3348 } 3349 3350 while (flagline < nflaglines) 3351 mdb_printf("%s\n", flagbuf[flagline++]); 3352 3353 if (cid->cid_print_head) 3354 mdb_printf("\n"); 3355 3356 return (rval); 3357 } 3358 3359 int 3360 cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3361 { 3362 uint_t verbose = FALSE; 3363 cpuinfo_data_t cid; 3364 GElf_Sym sym; 3365 clock_t lbolt; 3366 3367 cid.cid_print_ithr = FALSE; 3368 cid.cid_print_thr = FALSE; 3369 cid.cid_print_flags = FALSE; 3370 cid.cid_print_head = DCMD_HDRSPEC(flags) ? TRUE : FALSE; 3371 cid.cid_cpu = -1; 3372 3373 if (flags & DCMD_ADDRSPEC) 3374 cid.cid_cpu = addr; 3375 3376 if (mdb_getopts(argc, argv, 3377 'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc) 3378 return (DCMD_USAGE); 3379 3380 if (verbose) { 3381 cid.cid_print_ithr = TRUE; 3382 cid.cid_print_thr = TRUE; 3383 cid.cid_print_flags = TRUE; 3384 cid.cid_print_head = TRUE; 3385 } 3386 3387 if (cid.cid_print_ithr) { 3388 int i; 3389 3390 cid.cid_ithr = mdb_alloc(sizeof (uintptr_t **) 3391 * NCPU, UM_SLEEP | UM_GC); 3392 3393 for (i = 0; i < NCPU; i++) 3394 cid.cid_ithr[i] = mdb_zalloc(sizeof (uintptr_t *) * 3395 NINTR, UM_SLEEP | UM_GC); 3396 3397 if (mdb_walk("thread", (mdb_walk_cb_t)cpuinfo_walk_ithread, 3398 &cid) == -1) { 3399 mdb_warn("couldn't walk thread"); 3400 return (DCMD_ERR); 3401 } 3402 } 3403 3404 if (mdb_lookup_by_name("panic_lbolt", &sym) == -1) { 3405 mdb_warn("failed to find panic_lbolt"); 3406 return (DCMD_ERR); 3407 } 3408 3409 cid.cid_lbolt = (uintptr_t)sym.st_value; 3410 3411 if (mdb_vread(&lbolt, sizeof (lbolt), cid.cid_lbolt) == -1) { 3412 mdb_warn("failed to read panic_lbolt"); 3413 return (DCMD_ERR); 3414 } 3415 3416 if (lbolt == 0) { 3417 if (mdb_lookup_by_name("lbolt", &sym) == -1) { 3418 mdb_warn("failed to find lbolt"); 3419 return (DCMD_ERR); 3420 } 3421 cid.cid_lbolt = (uintptr_t)sym.st_value; 3422 } 3423 3424 if (mdb_walk("cpu", (mdb_walk_cb_t)cpuinfo_walk_cpu, &cid) == -1) { 3425 mdb_warn("can't walk cpus"); 3426 return (DCMD_ERR); 3427 } 3428 3429 if (cid.cid_cpu != -1) { 3430 /* 3431 * We didn't find this CPU when we walked through the CPUs 3432 * (i.e. the address specified doesn't show up in the "cpu" 3433 * walk). However, the specified address may still correspond 3434 * to a valid cpu_t (for example, if the specified address is 3435 * the actual panicking cpu_t and not the cached panic_cpu). 3436 * Point is: even if we didn't find it, we still want to try 3437 * to print the specified address as a cpu_t. 3438 */ 3439 cpu_t cpu; 3440 3441 if (mdb_vread(&cpu, sizeof (cpu), cid.cid_cpu) == -1) { 3442 mdb_warn("%p is neither a valid CPU ID nor a " 3443 "valid cpu_t address\n", cid.cid_cpu); 3444 return (DCMD_ERR); 3445 } 3446 3447 (void) cpuinfo_walk_cpu(cid.cid_cpu, &cpu, &cid); 3448 } 3449 3450 return (DCMD_OK); 3451 } 3452 3453 /*ARGSUSED*/ 3454 int 3455 flipone(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3456 { 3457 int i; 3458 3459 if (!(flags & DCMD_ADDRSPEC)) 3460 return (DCMD_USAGE); 3461 3462 for (i = 0; i < sizeof (addr) * NBBY; i++) 3463 mdb_printf("%p\n", addr ^ (1UL << i)); 3464 3465 return (DCMD_OK); 3466 } 3467 3468 /* 3469 * Grumble, grumble. 3470 */ 3471 #define SMAP_HASHFUNC(vp, off) \ 3472 ((((uintptr_t)(vp) >> 6) + ((uintptr_t)(vp) >> 3) + \ 3473 ((off) >> MAXBSHIFT)) & smd_hashmsk) 3474 3475 int 3476 vnode2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3477 { 3478 long smd_hashmsk; 3479 int hash; 3480 uintptr_t offset = 0; 3481 struct smap smp; 3482 uintptr_t saddr, kaddr; 3483 uintptr_t smd_hash, smd_smap; 3484 struct seg seg; 3485 3486 if (!(flags & DCMD_ADDRSPEC)) 3487 return (DCMD_USAGE); 3488 3489 if (mdb_readvar(&smd_hashmsk, "smd_hashmsk") == -1) { 3490 mdb_warn("failed to read smd_hashmsk"); 3491 return (DCMD_ERR); 3492 } 3493 3494 if (mdb_readvar(&smd_hash, "smd_hash") == -1) { 3495 mdb_warn("failed to read smd_hash"); 3496 return (DCMD_ERR); 3497 } 3498 3499 if (mdb_readvar(&smd_smap, "smd_smap") == -1) { 3500 mdb_warn("failed to read smd_hash"); 3501 return (DCMD_ERR); 3502 } 3503 3504 if (mdb_readvar(&kaddr, "segkmap") == -1) { 3505 mdb_warn("failed to read segkmap"); 3506 return (DCMD_ERR); 3507 } 3508 3509 if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) { 3510 mdb_warn("failed to read segkmap at %p", kaddr); 3511 return (DCMD_ERR); 3512 } 3513 3514 if (argc != 0) { 3515 const mdb_arg_t *arg = &argv[0]; 3516 3517 if (arg->a_type == MDB_TYPE_IMMEDIATE) 3518 offset = arg->a_un.a_val; 3519 else 3520 offset = (uintptr_t)mdb_strtoull(arg->a_un.a_str); 3521 } 3522 3523 hash = SMAP_HASHFUNC(addr, offset); 3524 3525 if (mdb_vread(&saddr, sizeof (saddr), 3526 smd_hash + hash * sizeof (uintptr_t)) == -1) { 3527 mdb_warn("couldn't read smap at %p", 3528 smd_hash + hash * sizeof (uintptr_t)); 3529 return (DCMD_ERR); 3530 } 3531 3532 do { 3533 if (mdb_vread(&smp, sizeof (smp), saddr) == -1) { 3534 mdb_warn("couldn't read smap at %p", saddr); 3535 return (DCMD_ERR); 3536 } 3537 3538 if ((uintptr_t)smp.sm_vp == addr && smp.sm_off == offset) { 3539 mdb_printf("vnode %p, offs %p is smap %p, vaddr %p\n", 3540 addr, offset, saddr, ((saddr - smd_smap) / 3541 sizeof (smp)) * MAXBSIZE + seg.s_base); 3542 return (DCMD_OK); 3543 } 3544 3545 saddr = (uintptr_t)smp.sm_hash; 3546 } while (saddr != NULL); 3547 3548 mdb_printf("no smap for vnode %p, offs %p\n", addr, offset); 3549 return (DCMD_OK); 3550 } 3551 3552 /*ARGSUSED*/ 3553 int 3554 addr2smap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3555 { 3556 uintptr_t kaddr; 3557 struct seg seg; 3558 struct segmap_data sd; 3559 3560 if (!(flags & DCMD_ADDRSPEC)) 3561 return (DCMD_USAGE); 3562 3563 if (mdb_readvar(&kaddr, "segkmap") == -1) { 3564 mdb_warn("failed to read segkmap"); 3565 return (DCMD_ERR); 3566 } 3567 3568 if (mdb_vread(&seg, sizeof (seg), kaddr) == -1) { 3569 mdb_warn("failed to read segkmap at %p", kaddr); 3570 return (DCMD_ERR); 3571 } 3572 3573 if (mdb_vread(&sd, sizeof (sd), (uintptr_t)seg.s_data) == -1) { 3574 mdb_warn("failed to read segmap_data at %p", seg.s_data); 3575 return (DCMD_ERR); 3576 } 3577 3578 mdb_printf("%p is smap %p\n", addr, 3579 ((addr - (uintptr_t)seg.s_base) >> MAXBSHIFT) * 3580 sizeof (struct smap) + (uintptr_t)sd.smd_sm); 3581 3582 return (DCMD_OK); 3583 } 3584 3585 int 3586 as2proc_walk(uintptr_t addr, const proc_t *p, struct as **asp) 3587 { 3588 if (p->p_as == *asp) 3589 mdb_printf("%p\n", addr); 3590 return (WALK_NEXT); 3591 } 3592 3593 /*ARGSUSED*/ 3594 int 3595 as2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3596 { 3597 if (!(flags & DCMD_ADDRSPEC) || argc != 0) 3598 return (DCMD_USAGE); 3599 3600 if (mdb_walk("proc", (mdb_walk_cb_t)as2proc_walk, &addr) == -1) { 3601 mdb_warn("failed to walk proc"); 3602 return (DCMD_ERR); 3603 } 3604 3605 return (DCMD_OK); 3606 } 3607 3608 /*ARGSUSED*/ 3609 int 3610 ptree_walk(uintptr_t addr, const proc_t *p, void *ignored) 3611 { 3612 proc_t parent; 3613 int ident = 0; 3614 uintptr_t paddr; 3615 3616 for (paddr = (uintptr_t)p->p_parent; paddr != NULL; ident += 5) { 3617 mdb_vread(&parent, sizeof (parent), paddr); 3618 paddr = (uintptr_t)parent.p_parent; 3619 } 3620 3621 mdb_inc_indent(ident); 3622 mdb_printf("%0?p %s\n", addr, p->p_user.u_comm); 3623 mdb_dec_indent(ident); 3624 3625 return (WALK_NEXT); 3626 } 3627 3628 void 3629 ptree_ancestors(uintptr_t addr, uintptr_t start) 3630 { 3631 proc_t p; 3632 3633 if (mdb_vread(&p, sizeof (p), addr) == -1) { 3634 mdb_warn("couldn't read ancestor at %p", addr); 3635 return; 3636 } 3637 3638 if (p.p_parent != NULL) 3639 ptree_ancestors((uintptr_t)p.p_parent, start); 3640 3641 if (addr != start) 3642 (void) ptree_walk(addr, &p, NULL); 3643 } 3644 3645 /*ARGSUSED*/ 3646 int 3647 ptree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3648 { 3649 if (!(flags & DCMD_ADDRSPEC)) 3650 addr = NULL; 3651 else 3652 ptree_ancestors(addr, addr); 3653 3654 if (mdb_pwalk("proc", (mdb_walk_cb_t)ptree_walk, NULL, addr) == -1) { 3655 mdb_warn("couldn't walk 'proc'"); 3656 return (DCMD_ERR); 3657 } 3658 3659 return (DCMD_OK); 3660 } 3661 3662 /*ARGSUSED*/ 3663 static int 3664 fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3665 { 3666 int fdnum; 3667 const mdb_arg_t *argp = &argv[0]; 3668 proc_t p; 3669 uf_entry_t uf; 3670 3671 if ((flags & DCMD_ADDRSPEC) == 0) { 3672 mdb_warn("fd doesn't give global information\n"); 3673 return (DCMD_ERR); 3674 } 3675 if (argc != 1) 3676 return (DCMD_USAGE); 3677 3678 if (argp->a_type == MDB_TYPE_IMMEDIATE) 3679 fdnum = argp->a_un.a_val; 3680 else 3681 fdnum = mdb_strtoull(argp->a_un.a_str); 3682 3683 if (mdb_vread(&p, sizeof (struct proc), addr) == -1) { 3684 mdb_warn("couldn't read proc_t at %p", addr); 3685 return (DCMD_ERR); 3686 } 3687 if (fdnum > p.p_user.u_finfo.fi_nfiles) { 3688 mdb_warn("process %p only has %d files open.\n", 3689 addr, p.p_user.u_finfo.fi_nfiles); 3690 return (DCMD_ERR); 3691 } 3692 if (mdb_vread(&uf, sizeof (uf_entry_t), 3693 (uintptr_t)&p.p_user.u_finfo.fi_list[fdnum]) == -1) { 3694 mdb_warn("couldn't read uf_entry_t at %p", 3695 &p.p_user.u_finfo.fi_list[fdnum]); 3696 return (DCMD_ERR); 3697 } 3698 3699 mdb_printf("%p\n", uf.uf_file); 3700 return (DCMD_OK); 3701 } 3702 3703 /*ARGSUSED*/ 3704 static int 3705 pid2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3706 { 3707 pid_t pid = (pid_t)addr; 3708 3709 if (argc != 0) 3710 return (DCMD_USAGE); 3711 3712 if ((addr = mdb_pid2proc(pid, NULL)) == NULL) { 3713 mdb_warn("PID 0t%d not found\n", pid); 3714 return (DCMD_ERR); 3715 } 3716 3717 mdb_printf("%p\n", addr); 3718 return (DCMD_OK); 3719 } 3720 3721 static char *sysfile_cmd[] = { 3722 "exclude:", 3723 "include:", 3724 "forceload:", 3725 "rootdev:", 3726 "rootfs:", 3727 "swapdev:", 3728 "swapfs:", 3729 "moddir:", 3730 "set", 3731 "unknown", 3732 }; 3733 3734 static char *sysfile_ops[] = { "", "=", "&", "|" }; 3735 3736 /*ARGSUSED*/ 3737 static int 3738 sysfile_vmem_seg(uintptr_t addr, const vmem_seg_t *vsp, void **target) 3739 { 3740 if (vsp->vs_type == VMEM_ALLOC && (void *)vsp->vs_start == *target) { 3741 *target = NULL; 3742 return (WALK_DONE); 3743 } 3744 return (WALK_NEXT); 3745 } 3746 3747 /*ARGSUSED*/ 3748 static int 3749 sysfile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3750 { 3751 struct sysparam *sysp, sys; 3752 char var[256]; 3753 char modname[256]; 3754 char val[256]; 3755 char strval[256]; 3756 vmem_t *mod_sysfile_arena; 3757 void *straddr; 3758 3759 if (mdb_readvar(&sysp, "sysparam_hd") == -1) { 3760 mdb_warn("failed to read sysparam_hd"); 3761 return (DCMD_ERR); 3762 } 3763 3764 if (mdb_readvar(&mod_sysfile_arena, "mod_sysfile_arena") == -1) { 3765 mdb_warn("failed to read mod_sysfile_arena"); 3766 return (DCMD_ERR); 3767 } 3768 3769 while (sysp != NULL) { 3770 var[0] = '\0'; 3771 val[0] = '\0'; 3772 modname[0] = '\0'; 3773 if (mdb_vread(&sys, sizeof (sys), (uintptr_t)sysp) == -1) { 3774 mdb_warn("couldn't read sysparam %p", sysp); 3775 return (DCMD_ERR); 3776 } 3777 if (sys.sys_modnam != NULL && 3778 mdb_readstr(modname, 256, 3779 (uintptr_t)sys.sys_modnam) == -1) { 3780 mdb_warn("couldn't read modname in %p", sysp); 3781 return (DCMD_ERR); 3782 } 3783 if (sys.sys_ptr != NULL && 3784 mdb_readstr(var, 256, (uintptr_t)sys.sys_ptr) == -1) { 3785 mdb_warn("couldn't read ptr in %p", sysp); 3786 return (DCMD_ERR); 3787 } 3788 if (sys.sys_op != SETOP_NONE) { 3789 /* 3790 * Is this an int or a string? We determine this 3791 * by checking whether straddr is contained in 3792 * mod_sysfile_arena. If so, the walker will set 3793 * straddr to NULL. 3794 */ 3795 straddr = (void *)(uintptr_t)sys.sys_info; 3796 if (sys.sys_op == SETOP_ASSIGN && 3797 sys.sys_info != 0 && 3798 mdb_pwalk("vmem_seg", 3799 (mdb_walk_cb_t)sysfile_vmem_seg, &straddr, 3800 (uintptr_t)mod_sysfile_arena) == 0 && 3801 straddr == NULL && 3802 mdb_readstr(strval, 256, 3803 (uintptr_t)sys.sys_info) != -1) { 3804 (void) mdb_snprintf(val, sizeof (val), "\"%s\"", 3805 strval); 3806 } else { 3807 (void) mdb_snprintf(val, sizeof (val), 3808 "0x%llx [0t%llu]", sys.sys_info, 3809 sys.sys_info); 3810 } 3811 } 3812 mdb_printf("%s %s%s%s%s%s\n", sysfile_cmd[sys.sys_type], 3813 modname, modname[0] == '\0' ? "" : ":", 3814 var, sysfile_ops[sys.sys_op], val); 3815 3816 sysp = sys.sys_next; 3817 } 3818 3819 return (DCMD_OK); 3820 } 3821 3822 /* 3823 * Dump a taskq_ent_t given its address. 3824 */ 3825 /*ARGSUSED*/ 3826 int 3827 taskq_ent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3828 { 3829 taskq_ent_t taskq_ent; 3830 GElf_Sym sym; 3831 char buf[MDB_SYM_NAMLEN+1]; 3832 3833 3834 if (!(flags & DCMD_ADDRSPEC)) { 3835 mdb_warn("expected explicit taskq_ent_t address before ::\n"); 3836 return (DCMD_USAGE); 3837 } 3838 3839 if (mdb_vread(&taskq_ent, sizeof (taskq_ent_t), addr) == -1) { 3840 mdb_warn("failed to read taskq_ent_t at %p", addr); 3841 return (DCMD_ERR); 3842 } 3843 3844 if (DCMD_HDRSPEC(flags)) { 3845 mdb_printf("%<u>%-?s %-?s %-s%</u>\n", 3846 "ENTRY", "ARG", "FUNCTION"); 3847 } 3848 3849 if (mdb_lookup_by_addr((uintptr_t)taskq_ent.tqent_func, MDB_SYM_EXACT, 3850 buf, sizeof (buf), &sym) == -1) { 3851 (void) strcpy(buf, "????"); 3852 } 3853 3854 mdb_printf("%-?p %-?p %s\n", addr, taskq_ent.tqent_arg, buf); 3855 3856 return (DCMD_OK); 3857 } 3858 3859 /* 3860 * Given the address of the (taskq_t) task queue head, walk the queue listing 3861 * the address of every taskq_ent_t. 3862 */ 3863 int 3864 taskq_walk_init(mdb_walk_state_t *wsp) 3865 { 3866 taskq_t tq_head; 3867 3868 3869 if (wsp->walk_addr == NULL) { 3870 mdb_warn("start address required\n"); 3871 return (WALK_ERR); 3872 } 3873 3874 3875 /* 3876 * Save the address of the list head entry. This terminates the list. 3877 */ 3878 wsp->walk_data = (void *) 3879 ((size_t)wsp->walk_addr + offsetof(taskq_t, tq_task)); 3880 3881 3882 /* 3883 * Read in taskq head, set walk_addr to point to first taskq_ent_t. 3884 */ 3885 if (mdb_vread((void *)&tq_head, sizeof (taskq_t), wsp->walk_addr) == 3886 -1) { 3887 mdb_warn("failed to read taskq list head at %p", 3888 wsp->walk_addr); 3889 } 3890 wsp->walk_addr = (uintptr_t)tq_head.tq_task.tqent_next; 3891 3892 3893 /* 3894 * Check for null list (next=head) 3895 */ 3896 if (wsp->walk_addr == (uintptr_t)wsp->walk_data) { 3897 return (WALK_DONE); 3898 } 3899 3900 return (WALK_NEXT); 3901 } 3902 3903 3904 int 3905 taskq_walk_step(mdb_walk_state_t *wsp) 3906 { 3907 taskq_ent_t tq_ent; 3908 int status; 3909 3910 3911 if (mdb_vread((void *)&tq_ent, sizeof (taskq_ent_t), wsp->walk_addr) == 3912 -1) { 3913 mdb_warn("failed to read taskq_ent_t at %p", wsp->walk_addr); 3914 return (DCMD_ERR); 3915 } 3916 3917 status = wsp->walk_callback(wsp->walk_addr, (void *)&tq_ent, 3918 wsp->walk_cbdata); 3919 3920 wsp->walk_addr = (uintptr_t)tq_ent.tqent_next; 3921 3922 3923 /* Check if we're at the last element (next=head) */ 3924 if (wsp->walk_addr == (uintptr_t)wsp->walk_data) { 3925 return (WALK_DONE); 3926 } 3927 3928 return (status); 3929 } 3930 3931 int 3932 didmatch(uintptr_t addr, const kthread_t *thr, kt_did_t *didp) 3933 { 3934 3935 if (*didp == thr->t_did) { 3936 mdb_printf("%p\n", addr); 3937 return (WALK_DONE); 3938 } else 3939 return (WALK_NEXT); 3940 } 3941 3942 /*ARGSUSED*/ 3943 int 3944 did2thread(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3945 { 3946 const mdb_arg_t *argp = &argv[0]; 3947 kt_did_t did; 3948 3949 if (argc != 1) 3950 return (DCMD_USAGE); 3951 3952 did = (kt_did_t)mdb_strtoull(argp->a_un.a_str); 3953 3954 if (mdb_walk("thread", (mdb_walk_cb_t)didmatch, (void *)&did) == -1) { 3955 mdb_warn("failed to walk thread"); 3956 return (DCMD_ERR); 3957 3958 } 3959 return (DCMD_OK); 3960 3961 } 3962 3963 static int 3964 errorq_walk_init(mdb_walk_state_t *wsp) 3965 { 3966 if (wsp->walk_addr == NULL && 3967 mdb_readvar(&wsp->walk_addr, "errorq_list") == -1) { 3968 mdb_warn("failed to read errorq_list"); 3969 return (WALK_ERR); 3970 } 3971 3972 return (WALK_NEXT); 3973 } 3974 3975 static int 3976 errorq_walk_step(mdb_walk_state_t *wsp) 3977 { 3978 uintptr_t addr = wsp->walk_addr; 3979 errorq_t eq; 3980 3981 if (addr == NULL) 3982 return (WALK_DONE); 3983 3984 if (mdb_vread(&eq, sizeof (eq), addr) == -1) { 3985 mdb_warn("failed to read errorq at %p", addr); 3986 return (WALK_ERR); 3987 } 3988 3989 wsp->walk_addr = (uintptr_t)eq.eq_next; 3990 return (wsp->walk_callback(addr, &eq, wsp->walk_cbdata)); 3991 } 3992 3993 typedef struct eqd_walk_data { 3994 uintptr_t *eqd_stack; 3995 void *eqd_buf; 3996 ulong_t eqd_qpos; 3997 ulong_t eqd_qlen; 3998 size_t eqd_size; 3999 } eqd_walk_data_t; 4000 4001 /* 4002 * In order to walk the list of pending error queue elements, we push the 4003 * addresses of the corresponding data buffers in to the eqd_stack array. 4004 * The error lists are in reverse chronological order when iterating using 4005 * eqe_prev, so we then pop things off the top in eqd_walk_step so that the 4006 * walker client gets addresses in order from oldest error to newest error. 4007 */ 4008 static void 4009 eqd_push_list(eqd_walk_data_t *eqdp, uintptr_t addr) 4010 { 4011 errorq_elem_t eqe; 4012 4013 while (addr != NULL) { 4014 if (mdb_vread(&eqe, sizeof (eqe), addr) != sizeof (eqe)) { 4015 mdb_warn("failed to read errorq element at %p", addr); 4016 break; 4017 } 4018 4019 if (eqdp->eqd_qpos == eqdp->eqd_qlen) { 4020 mdb_warn("errorq is overfull -- more than %lu " 4021 "elems found\n", eqdp->eqd_qlen); 4022 break; 4023 } 4024 4025 eqdp->eqd_stack[eqdp->eqd_qpos++] = (uintptr_t)eqe.eqe_data; 4026 addr = (uintptr_t)eqe.eqe_prev; 4027 } 4028 } 4029 4030 static int 4031 eqd_walk_init(mdb_walk_state_t *wsp) 4032 { 4033 eqd_walk_data_t *eqdp; 4034 errorq_elem_t eqe, *addr; 4035 errorq_t eq; 4036 ulong_t i; 4037 4038 if (mdb_vread(&eq, sizeof (eq), wsp->walk_addr) == -1) { 4039 mdb_warn("failed to read errorq at %p", wsp->walk_addr); 4040 return (WALK_ERR); 4041 } 4042 4043 if (eq.eq_ptail != NULL && 4044 mdb_vread(&eqe, sizeof (eqe), (uintptr_t)eq.eq_ptail) == -1) { 4045 mdb_warn("failed to read errorq element at %p", eq.eq_ptail); 4046 return (WALK_ERR); 4047 } 4048 4049 eqdp = mdb_alloc(sizeof (eqd_walk_data_t), UM_SLEEP); 4050 wsp->walk_data = eqdp; 4051 4052 eqdp->eqd_stack = mdb_zalloc(sizeof (uintptr_t) * eq.eq_qlen, UM_SLEEP); 4053 eqdp->eqd_buf = mdb_alloc(eq.eq_size, UM_SLEEP); 4054 eqdp->eqd_qlen = eq.eq_qlen; 4055 eqdp->eqd_qpos = 0; 4056 eqdp->eqd_size = eq.eq_size; 4057 4058 /* 4059 * The newest elements in the queue are on the pending list, so we 4060 * push those on to our stack first. 4061 */ 4062 eqd_push_list(eqdp, (uintptr_t)eq.eq_pend); 4063 4064 /* 4065 * If eq_ptail is set, it may point to a subset of the errors on the 4066 * pending list in the event a casptr() failed; if ptail's data is 4067 * already in our stack, NULL out eq_ptail and ignore it. 4068 */ 4069 if (eq.eq_ptail != NULL) { 4070 for (i = 0; i < eqdp->eqd_qpos; i++) { 4071 if (eqdp->eqd_stack[i] == (uintptr_t)eqe.eqe_data) { 4072 eq.eq_ptail = NULL; 4073 break; 4074 } 4075 } 4076 } 4077 4078 /* 4079 * If eq_phead is set, it has the processing list in order from oldest 4080 * to newest. Use this to recompute eq_ptail as best we can and then 4081 * we nicely fall into eqd_push_list() of eq_ptail below. 4082 */ 4083 for (addr = eq.eq_phead; addr != NULL && mdb_vread(&eqe, sizeof (eqe), 4084 (uintptr_t)addr) == sizeof (eqe); addr = eqe.eqe_next) 4085 eq.eq_ptail = addr; 4086 4087 /* 4088 * The oldest elements in the queue are on the processing list, subject 4089 * to machinations in the if-clauses above. Push any such elements. 4090 */ 4091 eqd_push_list(eqdp, (uintptr_t)eq.eq_ptail); 4092 return (WALK_NEXT); 4093 } 4094 4095 static int 4096 eqd_walk_step(mdb_walk_state_t *wsp) 4097 { 4098 eqd_walk_data_t *eqdp = wsp->walk_data; 4099 uintptr_t addr; 4100 4101 if (eqdp->eqd_qpos == 0) 4102 return (WALK_DONE); 4103 4104 addr = eqdp->eqd_stack[--eqdp->eqd_qpos]; 4105 4106 if (mdb_vread(eqdp->eqd_buf, eqdp->eqd_size, addr) != eqdp->eqd_size) { 4107 mdb_warn("failed to read errorq data at %p", addr); 4108 return (WALK_ERR); 4109 } 4110 4111 return (wsp->walk_callback(addr, eqdp->eqd_buf, wsp->walk_cbdata)); 4112 } 4113 4114 static void 4115 eqd_walk_fini(mdb_walk_state_t *wsp) 4116 { 4117 eqd_walk_data_t *eqdp = wsp->walk_data; 4118 4119 mdb_free(eqdp->eqd_stack, sizeof (uintptr_t) * eqdp->eqd_qlen); 4120 mdb_free(eqdp->eqd_buf, eqdp->eqd_size); 4121 mdb_free(eqdp, sizeof (eqd_walk_data_t)); 4122 } 4123 4124 #define EQKSVAL(eqv, what) (eqv.eq_kstat.what.value.ui64) 4125 4126 static int 4127 errorq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 4128 { 4129 int i; 4130 errorq_t eq; 4131 uint_t opt_v = FALSE; 4132 4133 if (!(flags & DCMD_ADDRSPEC)) { 4134 if (mdb_walk_dcmd("errorq", "errorq", argc, argv) == -1) { 4135 mdb_warn("can't walk 'errorq'"); 4136 return (DCMD_ERR); 4137 } 4138 return (DCMD_OK); 4139 } 4140 4141 i = mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &opt_v, NULL); 4142 argc -= i; 4143 argv += i; 4144 4145 if (argc != 0) 4146 return (DCMD_USAGE); 4147 4148 if (opt_v || DCMD_HDRSPEC(flags)) { 4149 mdb_printf("%<u>%-11s %-16s %1s %1s %1s ", 4150 "ADDR", "NAME", "S", "V", "N"); 4151 if (!opt_v) { 4152 mdb_printf("%7s %7s %7s%</u>\n", 4153 "ACCEPT", "DROP", "LOG"); 4154 } else { 4155 mdb_printf("%5s %6s %6s %3s %16s%</u>\n", 4156 "KSTAT", "QLEN", "SIZE", "IPL", "FUNC"); 4157 } 4158 } 4159 4160 if (mdb_vread(&eq, sizeof (eq), addr) != sizeof (eq)) { 4161 mdb_warn("failed to read errorq at %p", addr); 4162 return (DCMD_ERR); 4163 } 4164 4165 mdb_printf("%-11p %-16s %c %c %c ", addr, eq.eq_name, 4166 (eq.eq_flags & ERRORQ_ACTIVE) ? '+' : '-', 4167 (eq.eq_flags & ERRORQ_VITAL) ? '!' : ' ', 4168 (eq.eq_flags & ERRORQ_NVLIST) ? '*' : ' '); 4169 4170 if (!opt_v) { 4171 mdb_printf("%7llu %7llu %7llu\n", 4172 EQKSVAL(eq, eqk_dispatched) + EQKSVAL(eq, eqk_committed), 4173 EQKSVAL(eq, eqk_dropped) + EQKSVAL(eq, eqk_reserve_fail) + 4174 EQKSVAL(eq, eqk_commit_fail), EQKSVAL(eq, eqk_logged)); 4175 } else { 4176 mdb_printf("%5s %6lu %6lu %3u %a\n", 4177 " | ", eq.eq_qlen, eq.eq_size, eq.eq_ipl, eq.eq_func); 4178 mdb_printf("%38s\n%41s" 4179 "%12s %llu\n" 4180 "%53s %llu\n" 4181 "%53s %llu\n" 4182 "%53s %llu\n" 4183 "%53s %llu\n" 4184 "%53s %llu\n" 4185 "%53s %llu\n" 4186 "%53s %llu\n\n", 4187 "|", "+-> ", 4188 "DISPATCHED", EQKSVAL(eq, eqk_dispatched), 4189 "DROPPED", EQKSVAL(eq, eqk_dropped), 4190 "LOGGED", EQKSVAL(eq, eqk_logged), 4191 "RESERVED", EQKSVAL(eq, eqk_reserved), 4192 "RESERVE FAIL", EQKSVAL(eq, eqk_reserve_fail), 4193 "COMMITTED", EQKSVAL(eq, eqk_committed), 4194 "COMMIT FAIL", EQKSVAL(eq, eqk_commit_fail), 4195 "CANCELLED", EQKSVAL(eq, eqk_cancelled)); 4196 } 4197 4198 return (DCMD_OK); 4199 } 4200 4201 /*ARGSUSED*/ 4202 static int 4203 panicinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 4204 { 4205 cpu_t panic_cpu; 4206 kthread_t *panic_thread; 4207 void *buf; 4208 panic_data_t *pd; 4209 int i, n; 4210 4211 if (!mdb_prop_postmortem) { 4212 mdb_warn("panicinfo can only be run on a system " 4213 "dump; see dumpadm(1M)\n"); 4214 return (DCMD_ERR); 4215 } 4216 4217 if (flags & DCMD_ADDRSPEC || argc != 0) 4218 return (DCMD_USAGE); 4219 4220 if (mdb_readsym(&panic_cpu, sizeof (cpu_t), "panic_cpu") == -1) 4221 mdb_warn("failed to read 'panic_cpu'"); 4222 else 4223 mdb_printf("%16s %?d\n", "cpu", panic_cpu.cpu_id); 4224 4225 if (mdb_readvar(&panic_thread, "panic_thread") == -1) 4226 mdb_warn("failed to read 'panic_thread'"); 4227 else 4228 mdb_printf("%16s %?p\n", "thread", panic_thread); 4229 4230 buf = mdb_alloc(PANICBUFSIZE, UM_SLEEP); 4231 pd = (panic_data_t *)buf; 4232 4233 if (mdb_readsym(buf, PANICBUFSIZE, "panicbuf") == -1 || 4234 pd->pd_version != PANICBUFVERS) { 4235 mdb_warn("failed to read 'panicbuf'"); 4236 mdb_free(buf, PANICBUFSIZE); 4237 return (DCMD_ERR); 4238 } 4239 4240 mdb_printf("%16s %s\n", "message", (char *)buf + pd->pd_msgoff); 4241 4242 n = (pd->pd_msgoff - (sizeof (panic_data_t) - 4243 sizeof (panic_nv_t))) / sizeof (panic_nv_t); 4244 4245 for (i = 0; i < n; i++) 4246 mdb_printf("%16s %?llx\n", 4247 pd->pd_nvdata[i].pnv_name, pd->pd_nvdata[i].pnv_value); 4248 4249 mdb_free(buf, PANICBUFSIZE); 4250 return (DCMD_OK); 4251 } 4252 4253 static const mdb_dcmd_t dcmds[] = { 4254 4255 /* from genunix.c */ 4256 { "addr2smap", ":[offset]", "translate address to smap", addr2smap }, 4257 { "as2proc", ":", "convert as to proc_t address", as2proc }, 4258 { "binding_hash_entry", ":", "print driver names hash table entry", 4259 binding_hash_entry }, 4260 { "callout", "?[-r|n] [-s|l] [-xhB] [-t | -ab nsec [-dkD]]" 4261 " [-C addr | -S seqid] [-f name|addr] [-p name| addr] [-T|L [-E]]" 4262 " [-FivVA]", 4263 "display callouts", callout, callout_help }, 4264 { "calloutid", "[-d|v] xid", "print callout by extended id", 4265 calloutid, calloutid_help }, 4266 { "class", NULL, "print process scheduler classes", class }, 4267 { "cpuinfo", "?[-v]", "print CPUs and runnable threads", cpuinfo }, 4268 { "did2thread", "? kt_did", "find kernel thread for this id", 4269 did2thread }, 4270 { "errorq", "?[-v]", "display kernel error queues", errorq }, 4271 { "fd", ":[fd num]", "get a file pointer from an fd", fd }, 4272 { "flipone", ":", "the vik_rev_level 2 special", flipone }, 4273 { "lminfo", NULL, "print lock manager information", lminfo }, 4274 { "ndi_event_hdl", "?", "print ndi_event_hdl", ndi_event_hdl }, 4275 { "panicinfo", NULL, "print panic information", panicinfo }, 4276 { "pid2proc", "?", "convert PID to proc_t address", pid2proc }, 4277 { "pmap", ":[-q]", "print process memory map", pmap }, 4278 { "project", NULL, "display kernel project(s)", project }, 4279 { "ps", "[-fltzTP]", "list processes (and associated thr,lwp)", ps }, 4280 { "pgrep", "[-x] [-n | -o] pattern", 4281 "pattern match against all processes", pgrep }, 4282 { "ptree", NULL, "print process tree", ptree }, 4283 { "seg", ":", "print address space segment", seg }, 4284 { "sysevent", "?[-sv]", "print sysevent pending or sent queue", 4285 sysevent}, 4286 { "sysevent_channel", "?", "print sysevent channel database", 4287 sysevent_channel}, 4288 { "sysevent_class_list", ":", "print sysevent class list", 4289 sysevent_class_list}, 4290 { "sysevent_subclass_list", ":", 4291 "print sysevent subclass list", sysevent_subclass_list}, 4292 { "system", NULL, "print contents of /etc/system file", sysfile }, 4293 { "task", NULL, "display kernel task(s)", task }, 4294 { "taskq_entry", ":", "display a taskq_ent_t", taskq_ent }, 4295 { "vnode2path", ":[-F]", "vnode address to pathname", vnode2path }, 4296 { "vnode2smap", ":[offset]", "translate vnode to smap", vnode2smap }, 4297 { "whereopen", ":", "given a vnode, dumps procs which have it open", 4298 whereopen }, 4299 4300 /* from zone.c */ 4301 { "zone", "?", "display kernel zone(s)", zoneprt }, 4302 { "zsd", ":[-v] [zsd_key]", "display zone-specific-data entries for " 4303 "selected zones", zsd }, 4304 4305 /* from bio.c */ 4306 { "bufpagefind", ":addr", "find page_t on buf_t list", bufpagefind }, 4307 4308 /* from contract.c */ 4309 { "contract", "?", "display a contract", cmd_contract }, 4310 { "ctevent", ":", "display a contract event", cmd_ctevent }, 4311 { "ctid", ":", "convert id to a contract pointer", cmd_ctid }, 4312 4313 /* from cpupart.c */ 4314 { "cpupart", "?[-v]", "print cpu partition info", cpupart }, 4315 4316 /* from cyclic.c */ 4317 { "cyccover", NULL, "dump cyclic coverage information", cyccover }, 4318 { "cycid", "?", "dump a cyclic id", cycid }, 4319 { "cycinfo", "?", "dump cyc_cpu info", cycinfo }, 4320 { "cyclic", ":", "developer information", cyclic }, 4321 { "cyctrace", "?", "dump cyclic trace buffer", cyctrace }, 4322 4323 /* from devinfo.c */ 4324 { "devbindings", "?[-qs] [device-name | major-num]", 4325 "print devinfo nodes bound to device-name or major-num", 4326 devbindings, devinfo_help }, 4327 { "devinfo", ":[-qs]", "detailed devinfo of one node", devinfo, 4328 devinfo_help }, 4329 { "devinfo_audit", ":[-v]", "devinfo configuration audit record", 4330 devinfo_audit }, 4331 { "devinfo_audit_log", "?[-v]", "system wide devinfo configuration log", 4332 devinfo_audit_log }, 4333 { "devinfo_audit_node", ":[-v]", "devinfo node configuration history", 4334 devinfo_audit_node }, 4335 { "devinfo2driver", ":", "find driver name for this devinfo node", 4336 devinfo2driver }, 4337 { "devnames", "?[-vm] [num]", "print devnames array", devnames }, 4338 { "dev2major", "?<dev_t>", "convert dev_t to a major number", 4339 dev2major }, 4340 { "dev2minor", "?<dev_t>", "convert dev_t to a minor number", 4341 dev2minor }, 4342 { "devt", "?<dev_t>", "display a dev_t's major and minor numbers", 4343 devt }, 4344 { "major2name", "?<major-num>", "convert major number to dev name", 4345 major2name }, 4346 { "minornodes", ":", "given a devinfo node, print its minor nodes", 4347 minornodes }, 4348 { "modctl2devinfo", ":", "given a modctl, list its devinfos", 4349 modctl2devinfo }, 4350 { "name2major", "<dev-name>", "convert dev name to major number", 4351 name2major }, 4352 { "prtconf", "?[-vpc]", "print devinfo tree", prtconf, prtconf_help }, 4353 { "softstate", ":<instance>", "retrieve soft-state pointer", 4354 softstate }, 4355 { "devinfo_fm", ":", "devinfo fault managment configuration", 4356 devinfo_fm }, 4357 { "devinfo_fmce", ":", "devinfo fault managment cache entry", 4358 devinfo_fmce}, 4359 4360 /* from fm.c */ 4361 { "ereport", "[-v]", "print ereports logged in dump", 4362 ereport }, 4363 4364 /* from findstack.c */ 4365 { "findstack", ":[-v]", "find kernel thread stack", findstack }, 4366 { "findstack_debug", NULL, "toggle findstack debugging", 4367 findstack_debug }, 4368 { "stacks", "?[-afiv] [-c func] [-C func] [-m module] [-M module] " 4369 "[-s sobj | -S sobj] [-t tstate | -T tstate]", 4370 "print unique kernel thread stacks", 4371 stacks, stacks_help }, 4372 4373 /* from irm.c */ 4374 { "irmpools", NULL, "display interrupt pools", irmpools_dcmd }, 4375 { "irmreqs", NULL, "display interrupt requests in an interrupt pool", 4376 irmreqs_dcmd }, 4377 { "irmreq", NULL, "display an interrupt request", irmreq_dcmd }, 4378 4379 /* from kgrep.c + genunix.c */ 4380 { "kgrep", KGREP_USAGE, "search kernel as for a pointer", kgrep, 4381 kgrep_help }, 4382 4383 /* from kmem.c */ 4384 { "allocdby", ":", "given a thread, print its allocated buffers", 4385 allocdby }, 4386 { "bufctl", ":[-vh] [-a addr] [-c caller] [-e earliest] [-l latest] " 4387 "[-t thd]", "print or filter a bufctl", bufctl, bufctl_help }, 4388 { "freedby", ":", "given a thread, print its freed buffers", freedby }, 4389 { "kmalog", "?[ fail | slab ]", 4390 "display kmem transaction log and stack traces", kmalog }, 4391 { "kmastat", "[-kmg]", "kernel memory allocator stats", 4392 kmastat }, 4393 { "kmausers", "?[-ef] [cache ...]", "current medium and large users " 4394 "of the kmem allocator", kmausers, kmausers_help }, 4395 { "kmem_cache", "?[-n name]", 4396 "print kernel memory caches", kmem_cache, kmem_cache_help}, 4397 { "kmem_slabs", "?[-v] [-n cache] [-N cache] [-b maxbins] " 4398 "[-B minbinsize]", "display slab usage per kmem cache", 4399 kmem_slabs, kmem_slabs_help }, 4400 { "kmem_debug", NULL, "toggle kmem dcmd/walk debugging", kmem_debug }, 4401 { "kmem_log", "?[-b]", "dump kmem transaction log", kmem_log }, 4402 { "kmem_verify", "?", "check integrity of kmem-managed memory", 4403 kmem_verify }, 4404 { "vmem", "?", "print a vmem_t", vmem }, 4405 { "vmem_seg", ":[-sv] [-c caller] [-e earliest] [-l latest] " 4406 "[-m minsize] [-M maxsize] [-t thread] [-T type]", 4407 "print or filter a vmem_seg", vmem_seg, vmem_seg_help }, 4408 { "whatis", ":[-abiv]", "given an address, return information", whatis, 4409 whatis_help }, 4410 { "whatthread", ":[-v]", "print threads whose stack contains the " 4411 "given address", whatthread }, 4412 4413 /* from ldi.c */ 4414 { "ldi_handle", "?[-i]", "display a layered driver handle", 4415 ldi_handle, ldi_handle_help }, 4416 { "ldi_ident", NULL, "display a layered driver identifier", 4417 ldi_ident, ldi_ident_help }, 4418 4419 /* from leaky.c + leaky_subr.c */ 4420 { "findleaks", FINDLEAKS_USAGE, 4421 "search for potential kernel memory leaks", findleaks, 4422 findleaks_help }, 4423 4424 /* from lgrp.c */ 4425 { "lgrp", "?[-q] [-p | -Pih]", "display an lgrp", lgrp}, 4426 { "lgrp_set", "", "display bitmask of lgroups as a list", lgrp_set}, 4427 4428 /* from log.c */ 4429 { "msgbuf", "?[-v]", "print most recent console messages", msgbuf }, 4430 4431 /* from memory.c */ 4432 { "page", "?", "display a summarized page_t", page }, 4433 { "memstat", NULL, "display memory usage summary", memstat }, 4434 { "memlist", "?[-iav]", "display a struct memlist", memlist }, 4435 { "swapinfo", "?", "display a struct swapinfo", swapinfof }, 4436 4437 /* from mmd.c */ 4438 { "multidata", ":[-sv]", "display a summarized multidata_t", 4439 multidata }, 4440 { "pattbl", ":", "display a summarized multidata attribute table", 4441 pattbl }, 4442 { "pattr2multidata", ":", "print multidata pointer from pattr_t", 4443 pattr2multidata }, 4444 { "pdesc2slab", ":", "print pdesc slab pointer from pdesc_t", 4445 pdesc2slab }, 4446 { "pdesc_verify", ":", "verify integrity of a pdesc_t", pdesc_verify }, 4447 { "slab2multidata", ":", "print multidata pointer from pdesc_slab_t", 4448 slab2multidata }, 4449 4450 /* from modhash.c */ 4451 { "modhash", "?[-ceht] [-k key] [-v val] [-i index]", 4452 "display information about one or all mod_hash structures", 4453 modhash, modhash_help }, 4454 { "modent", ":[-k | -v | -t type]", 4455 "display information about a mod_hash_entry", modent, 4456 modent_help }, 4457 4458 /* from net.c */ 4459 { "mi", ":[-p] [-d | -m]", "filter and display MI object or payload", 4460 mi }, 4461 { "netstat", "[-arv] [-f inet | inet6 | unix] [-P tcp | udp]", 4462 "show network statistics", netstat }, 4463 { "sonode", "?[-f inet | inet6 | unix | #] " 4464 "[-t stream | dgram | raw | #] [-p #]", 4465 "filter and display sonode", sonode }, 4466 4467 /* from netstack.c */ 4468 { "netstack", "", "show stack instances", netstack }, 4469 4470 /* from nvpair.c */ 4471 { NVPAIR_DCMD_NAME, NVPAIR_DCMD_USAGE, NVPAIR_DCMD_DESCR, 4472 nvpair_print }, 4473 { NVLIST_DCMD_NAME, NVLIST_DCMD_USAGE, NVLIST_DCMD_DESCR, 4474 print_nvlist }, 4475 4476 /* from pg.c */ 4477 { "pg", "?[-q]", "display a pg", pg}, 4478 /* from group.c */ 4479 { "group", "?[-q]", "display a group", group}, 4480 4481 /* from log.c */ 4482 /* from rctl.c */ 4483 { "rctl_dict", "?", "print systemwide default rctl definitions", 4484 rctl_dict }, 4485 { "rctl_list", ":[handle]", "print rctls for the given proc", 4486 rctl_list }, 4487 { "rctl", ":[handle]", "print a rctl_t, only if it matches the handle", 4488 rctl }, 4489 { "rctl_validate", ":[-v] [-n #]", "test resource control value " 4490 "sequence", rctl_validate }, 4491 4492 /* from sobj.c */ 4493 { "rwlock", ":", "dump out a readers/writer lock", rwlock }, 4494 { "mutex", ":[-f]", "dump out an adaptive or spin mutex", mutex, 4495 mutex_help }, 4496 { "sobj2ts", ":", "perform turnstile lookup on synch object", sobj2ts }, 4497 { "wchaninfo", "?[-v]", "dump condition variable", wchaninfo }, 4498 { "turnstile", "?", "display a turnstile", turnstile }, 4499 4500 /* from stream.c */ 4501 { "mblk", ":[-q|v] [-f|F flag] [-t|T type] [-l|L|B len] [-d dbaddr]", 4502 "print an mblk", mblk_prt, mblk_help }, 4503 { "mblk_verify", "?", "verify integrity of an mblk", mblk_verify }, 4504 { "mblk2dblk", ":", "convert mblk_t address to dblk_t address", 4505 mblk2dblk }, 4506 { "q2otherq", ":", "print peer queue for a given queue", q2otherq }, 4507 { "q2rdq", ":", "print read queue for a given queue", q2rdq }, 4508 { "q2syncq", ":", "print syncq for a given queue", q2syncq }, 4509 { "q2stream", ":", "print stream pointer for a given queue", q2stream }, 4510 { "q2wrq", ":", "print write queue for a given queue", q2wrq }, 4511 { "queue", ":[-q|v] [-m mod] [-f flag] [-F flag] [-s syncq_addr]", 4512 "filter and display STREAM queue", queue, queue_help }, 4513 { "stdata", ":[-q|v] [-f flag] [-F flag]", 4514 "filter and display STREAM head", stdata, stdata_help }, 4515 { "str2mate", ":", "print mate of this stream", str2mate }, 4516 { "str2wrq", ":", "print write queue of this stream", str2wrq }, 4517 { "stream", ":", "display STREAM", stream }, 4518 { "strftevent", ":", "print STREAMS flow trace event", strftevent }, 4519 { "syncq", ":[-q|v] [-f flag] [-F flag] [-t type] [-T type]", 4520 "filter and display STREAM sync queue", syncq, syncq_help }, 4521 { "syncq2q", ":", "print queue for a given syncq", syncq2q }, 4522 4523 /* from thread.c */ 4524 { "thread", "?[-bdfimps]", "display a summarized kthread_t", thread, 4525 thread_help }, 4526 { "threadlist", "?[-t] [-v [count]]", 4527 "display threads and associated C stack traces", threadlist, 4528 threadlist_help }, 4529 { "stackinfo", "?[-h|-a]", "display kthread_t stack usage", stackinfo, 4530 stackinfo_help }, 4531 4532 /* from tsd.c */ 4533 { "tsd", ":-k key", "print tsd[key-1] for this thread", ttotsd }, 4534 { "tsdtot", ":", "find thread with this tsd", tsdtot }, 4535 4536 /* 4537 * typegraph does not work under kmdb, as it requires too much memory 4538 * for its internal data structures. 4539 */ 4540 #ifndef _KMDB 4541 /* from typegraph.c */ 4542 { "findlocks", ":", "find locks held by specified thread", findlocks }, 4543 { "findfalse", "?[-v]", "find potentially falsely shared structures", 4544 findfalse }, 4545 { "typegraph", NULL, "build type graph", typegraph }, 4546 { "istype", ":type", "manually set object type", istype }, 4547 { "notype", ":", "manually clear object type", notype }, 4548 { "whattype", ":", "determine object type", whattype }, 4549 #endif 4550 4551 /* from vfs.c */ 4552 { "fsinfo", "?[-v]", "print mounted filesystems", fsinfo }, 4553 { "pfiles", ":[-fp]", "print process file information", pfiles, 4554 pfiles_help }, 4555 4556 /* from mdi.c */ 4557 { "mdipi", NULL, "given a path, dump mdi_pathinfo " 4558 "and detailed pi_prop list", mdipi }, 4559 { "mdiprops", NULL, "given a pi_prop, dump the pi_prop list", 4560 mdiprops }, 4561 { "mdiphci", NULL, "given a phci, dump mdi_phci and " 4562 "list all paths", mdiphci }, 4563 { "mdivhci", NULL, "given a vhci, dump mdi_vhci and list " 4564 "all phcis", mdivhci }, 4565 { "mdiclient_paths", NULL, "given a path, walk mdi_pathinfo " 4566 "client links", mdiclient_paths }, 4567 { "mdiphci_paths", NULL, "given a path, walk through mdi_pathinfo " 4568 "phci links", mdiphci_paths }, 4569 { "mdiphcis", NULL, "given a phci, walk through mdi_phci ph_next links", 4570 mdiphcis }, 4571 4572 { NULL } 4573 }; 4574 4575 static const mdb_walker_t walkers[] = { 4576 4577 /* from genunix.c */ 4578 { "anon", "given an amp, list of anon structures", 4579 anon_walk_init, anon_walk_step, anon_walk_fini }, 4580 { "callouts_bytime", "walk callouts by list chain (expiration time)", 4581 callout_walk_init, callout_walk_step, callout_walk_fini, 4582 (void *)CALLOUT_WALK_BYLIST }, 4583 { "callouts_byid", "walk callouts by id hash chain", 4584 callout_walk_init, callout_walk_step, callout_walk_fini, 4585 (void *)CALLOUT_WALK_BYID }, 4586 { "callout_list", "walk a callout list", callout_list_walk_init, 4587 callout_list_walk_step, callout_list_walk_fini }, 4588 { "callout_table", "walk callout table array", callout_table_walk_init, 4589 callout_table_walk_step, callout_table_walk_fini }, 4590 { "cpu", "walk cpu structures", cpu_walk_init, cpu_walk_step }, 4591 { "ereportq_dump", "walk list of ereports in dump error queue", 4592 ereportq_dump_walk_init, ereportq_dump_walk_step, NULL }, 4593 { "ereportq_pend", "walk list of ereports in pending error queue", 4594 ereportq_pend_walk_init, ereportq_pend_walk_step, NULL }, 4595 { "errorq", "walk list of system error queues", 4596 errorq_walk_init, errorq_walk_step, NULL }, 4597 { "errorq_data", "walk pending error queue data buffers", 4598 eqd_walk_init, eqd_walk_step, eqd_walk_fini }, 4599 { "allfile", "given a proc pointer, list all file pointers", 4600 file_walk_init, allfile_walk_step, file_walk_fini }, 4601 { "file", "given a proc pointer, list of open file pointers", 4602 file_walk_init, file_walk_step, file_walk_fini }, 4603 { "lock_descriptor", "walk lock_descriptor_t structures", 4604 ld_walk_init, ld_walk_step, NULL }, 4605 { "lock_graph", "walk lock graph", 4606 lg_walk_init, lg_walk_step, NULL }, 4607 { "port", "given a proc pointer, list of created event ports", 4608 port_walk_init, port_walk_step, NULL }, 4609 { "portev", "given a port pointer, list of events in the queue", 4610 portev_walk_init, portev_walk_step, portev_walk_fini }, 4611 { "proc", "list of active proc_t structures", 4612 proc_walk_init, proc_walk_step, proc_walk_fini }, 4613 { "projects", "walk a list of kernel projects", 4614 project_walk_init, project_walk_step, NULL }, 4615 { "seg", "given an as, list of segments", 4616 seg_walk_init, avl_walk_step, avl_walk_fini }, 4617 { "sysevent_pend", "walk sysevent pending queue", 4618 sysevent_pend_walk_init, sysevent_walk_step, 4619 sysevent_walk_fini}, 4620 { "sysevent_sent", "walk sysevent sent queue", sysevent_sent_walk_init, 4621 sysevent_walk_step, sysevent_walk_fini}, 4622 { "sysevent_channel", "walk sysevent channel subscriptions", 4623 sysevent_channel_walk_init, sysevent_channel_walk_step, 4624 sysevent_channel_walk_fini}, 4625 { "sysevent_class_list", "walk sysevent subscription's class list", 4626 sysevent_class_list_walk_init, sysevent_class_list_walk_step, 4627 sysevent_class_list_walk_fini}, 4628 { "sysevent_subclass_list", 4629 "walk sysevent subscription's subclass list", 4630 sysevent_subclass_list_walk_init, 4631 sysevent_subclass_list_walk_step, 4632 sysevent_subclass_list_walk_fini}, 4633 { "task", "given a task pointer, walk its processes", 4634 task_walk_init, task_walk_step, NULL }, 4635 { "taskq_entry", "given a taskq_t*, list all taskq_ent_t in the list", 4636 taskq_walk_init, taskq_walk_step, NULL, NULL }, 4637 4638 /* from avl.c */ 4639 { AVL_WALK_NAME, AVL_WALK_DESC, 4640 avl_walk_init, avl_walk_step, avl_walk_fini }, 4641 4642 /* from zone.c */ 4643 { "zone", "walk a list of kernel zones", 4644 zone_walk_init, zone_walk_step, NULL }, 4645 { "zsd", "walk list of zsd entries for a zone", 4646 zsd_walk_init, zsd_walk_step, NULL }, 4647 4648 /* from bio.c */ 4649 { "buf", "walk the bio buf hash", 4650 buf_walk_init, buf_walk_step, buf_walk_fini }, 4651 4652 /* from contract.c */ 4653 { "contract", "walk all contracts, or those of the specified type", 4654 ct_walk_init, generic_walk_step, NULL }, 4655 { "ct_event", "walk events on a contract event queue", 4656 ct_event_walk_init, generic_walk_step, NULL }, 4657 { "ct_listener", "walk contract event queue listeners", 4658 ct_listener_walk_init, generic_walk_step, NULL }, 4659 4660 /* from cpupart.c */ 4661 { "cpupart_cpulist", "given an cpupart_t, walk cpus in partition", 4662 cpupart_cpulist_walk_init, cpupart_cpulist_walk_step, 4663 NULL }, 4664 { "cpupart_walk", "walk the set of cpu partitions", 4665 cpupart_walk_init, cpupart_walk_step, NULL }, 4666 4667 /* from ctxop.c */ 4668 { "ctxop", "walk list of context ops on a thread", 4669 ctxop_walk_init, ctxop_walk_step, ctxop_walk_fini }, 4670 4671 /* from cyclic.c */ 4672 { "cyccpu", "walk per-CPU cyc_cpu structures", 4673 cyccpu_walk_init, cyccpu_walk_step, NULL }, 4674 { "cycomni", "for an omnipresent cyclic, walk cyc_omni_cpu list", 4675 cycomni_walk_init, cycomni_walk_step, NULL }, 4676 { "cyctrace", "walk cyclic trace buffer", 4677 cyctrace_walk_init, cyctrace_walk_step, cyctrace_walk_fini }, 4678 4679 /* from devinfo.c */ 4680 { "binding_hash", "walk all entries in binding hash table", 4681 binding_hash_walk_init, binding_hash_walk_step, NULL }, 4682 { "devinfo", "walk devinfo tree or subtree", 4683 devinfo_walk_init, devinfo_walk_step, devinfo_walk_fini }, 4684 { "devinfo_audit_log", "walk devinfo audit system-wide log", 4685 devinfo_audit_log_walk_init, devinfo_audit_log_walk_step, 4686 devinfo_audit_log_walk_fini}, 4687 { "devinfo_audit_node", "walk per-devinfo audit history", 4688 devinfo_audit_node_walk_init, devinfo_audit_node_walk_step, 4689 devinfo_audit_node_walk_fini}, 4690 { "devinfo_children", "walk children of devinfo node", 4691 devinfo_children_walk_init, devinfo_children_walk_step, 4692 devinfo_children_walk_fini }, 4693 { "devinfo_parents", "walk ancestors of devinfo node", 4694 devinfo_parents_walk_init, devinfo_parents_walk_step, 4695 devinfo_parents_walk_fini }, 4696 { "devinfo_siblings", "walk siblings of devinfo node", 4697 devinfo_siblings_walk_init, devinfo_siblings_walk_step, NULL }, 4698 { "devi_next", "walk devinfo list", 4699 NULL, devi_next_walk_step, NULL }, 4700 { "devnames", "walk devnames array", 4701 devnames_walk_init, devnames_walk_step, devnames_walk_fini }, 4702 { "minornode", "given a devinfo node, walk minor nodes", 4703 minornode_walk_init, minornode_walk_step, NULL }, 4704 { "softstate", 4705 "given an i_ddi_soft_state*, list all in-use driver stateps", 4706 soft_state_walk_init, soft_state_walk_step, 4707 NULL, NULL }, 4708 { "softstate_all", 4709 "given an i_ddi_soft_state*, list all driver stateps", 4710 soft_state_walk_init, soft_state_all_walk_step, 4711 NULL, NULL }, 4712 { "devinfo_fmc", 4713 "walk a fault management handle cache active list", 4714 devinfo_fmc_walk_init, devinfo_fmc_walk_step, NULL }, 4715 4716 /* from irm.c */ 4717 { "irmpools", "walk global list of interrupt pools", 4718 irmpools_walk_init, list_walk_step, list_walk_fini }, 4719 { "irmreqs", "walk list of interrupt requests in an interrupt pool", 4720 irmreqs_walk_init, list_walk_step, list_walk_fini }, 4721 4722 /* from kmem.c */ 4723 { "allocdby", "given a thread, walk its allocated bufctls", 4724 allocdby_walk_init, allocdby_walk_step, allocdby_walk_fini }, 4725 { "bufctl", "walk a kmem cache's bufctls", 4726 bufctl_walk_init, kmem_walk_step, kmem_walk_fini }, 4727 { "bufctl_history", "walk the available history of a bufctl", 4728 bufctl_history_walk_init, bufctl_history_walk_step, 4729 bufctl_history_walk_fini }, 4730 { "freedby", "given a thread, walk its freed bufctls", 4731 freedby_walk_init, allocdby_walk_step, allocdby_walk_fini }, 4732 { "freectl", "walk a kmem cache's free bufctls", 4733 freectl_walk_init, kmem_walk_step, kmem_walk_fini }, 4734 { "freectl_constructed", "walk a kmem cache's constructed free bufctls", 4735 freectl_constructed_walk_init, kmem_walk_step, kmem_walk_fini }, 4736 { "freemem", "walk a kmem cache's free memory", 4737 freemem_walk_init, kmem_walk_step, kmem_walk_fini }, 4738 { "freemem_constructed", "walk a kmem cache's constructed free memory", 4739 freemem_constructed_walk_init, kmem_walk_step, kmem_walk_fini }, 4740 { "kmem", "walk a kmem cache", 4741 kmem_walk_init, kmem_walk_step, kmem_walk_fini }, 4742 { "kmem_cpu_cache", "given a kmem cache, walk its per-CPU caches", 4743 kmem_cpu_cache_walk_init, kmem_cpu_cache_walk_step, NULL }, 4744 { "kmem_hash", "given a kmem cache, walk its allocated hash table", 4745 kmem_hash_walk_init, kmem_hash_walk_step, kmem_hash_walk_fini }, 4746 { "kmem_log", "walk the kmem transaction log", 4747 kmem_log_walk_init, kmem_log_walk_step, kmem_log_walk_fini }, 4748 { "kmem_slab", "given a kmem cache, walk its slabs", 4749 kmem_slab_walk_init, combined_walk_step, combined_walk_fini }, 4750 { "kmem_slab_partial", 4751 "given a kmem cache, walk its partially allocated slabs (min 1)", 4752 kmem_slab_walk_partial_init, combined_walk_step, 4753 combined_walk_fini }, 4754 { "vmem", "walk vmem structures in pre-fix, depth-first order", 4755 vmem_walk_init, vmem_walk_step, vmem_walk_fini }, 4756 { "vmem_alloc", "given a vmem_t, walk its allocated vmem_segs", 4757 vmem_alloc_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 4758 { "vmem_free", "given a vmem_t, walk its free vmem_segs", 4759 vmem_free_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 4760 { "vmem_postfix", "walk vmem structures in post-fix, depth-first order", 4761 vmem_walk_init, vmem_postfix_walk_step, vmem_walk_fini }, 4762 { "vmem_seg", "given a vmem_t, walk all of its vmem_segs", 4763 vmem_seg_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 4764 { "vmem_span", "given a vmem_t, walk its spanning vmem_segs", 4765 vmem_span_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 4766 4767 /* from ldi.c */ 4768 { "ldi_handle", "walk the layered driver handle hash", 4769 ldi_handle_walk_init, ldi_handle_walk_step, NULL }, 4770 { "ldi_ident", "walk the layered driver identifier hash", 4771 ldi_ident_walk_init, ldi_ident_walk_step, NULL }, 4772 4773 /* from leaky.c + leaky_subr.c */ 4774 { "leak", "given a leaked bufctl or vmem_seg, find leaks w/ same " 4775 "stack trace", 4776 leaky_walk_init, leaky_walk_step, leaky_walk_fini }, 4777 { "leakbuf", "given a leaked bufctl or vmem_seg, walk buffers for " 4778 "leaks w/ same stack trace", 4779 leaky_walk_init, leaky_buf_walk_step, leaky_walk_fini }, 4780 4781 /* from lgrp.c */ 4782 { "lgrp_cpulist", "walk CPUs in a given lgroup", 4783 lgrp_cpulist_walk_init, lgrp_cpulist_walk_step, NULL }, 4784 { "lgrptbl", "walk lgroup table", 4785 lgrp_walk_init, lgrp_walk_step, NULL }, 4786 { "lgrp_parents", "walk up lgroup lineage from given lgroup", 4787 lgrp_parents_walk_init, lgrp_parents_walk_step, NULL }, 4788 { "lgrp_rsrc_mem", "walk lgroup memory resources of given lgroup", 4789 lgrp_rsrc_mem_walk_init, lgrp_set_walk_step, NULL }, 4790 { "lgrp_rsrc_cpu", "walk lgroup CPU resources of given lgroup", 4791 lgrp_rsrc_cpu_walk_init, lgrp_set_walk_step, NULL }, 4792 4793 /* from group.c */ 4794 { "group", "walk all elements of a group", 4795 group_walk_init, group_walk_step, NULL }, 4796 4797 /* from list.c */ 4798 { LIST_WALK_NAME, LIST_WALK_DESC, 4799 list_walk_init, list_walk_step, list_walk_fini }, 4800 4801 /* from memory.c */ 4802 { "page", "walk all pages, or those from the specified vnode", 4803 page_walk_init, page_walk_step, page_walk_fini }, 4804 { "memlist", "walk specified memlist", 4805 NULL, memlist_walk_step, NULL }, 4806 { "swapinfo", "walk swapinfo structures", 4807 swap_walk_init, swap_walk_step, NULL }, 4808 4809 /* from mmd.c */ 4810 { "pattr", "walk pattr_t structures", pattr_walk_init, 4811 mmdq_walk_step, mmdq_walk_fini }, 4812 { "pdesc", "walk pdesc_t structures", 4813 pdesc_walk_init, mmdq_walk_step, mmdq_walk_fini }, 4814 { "pdesc_slab", "walk pdesc_slab_t structures", 4815 pdesc_slab_walk_init, mmdq_walk_step, mmdq_walk_fini }, 4816 4817 /* from modhash.c */ 4818 { "modhash", "walk list of mod_hash structures", modhash_walk_init, 4819 modhash_walk_step, NULL }, 4820 { "modent", "walk list of entries in a given mod_hash", 4821 modent_walk_init, modent_walk_step, modent_walk_fini }, 4822 { "modchain", "walk list of entries in a given mod_hash_entry", 4823 NULL, modchain_walk_step, NULL }, 4824 4825 /* from net.c */ 4826 { "ar", "walk ar_t structures using MI for all stacks", 4827 mi_payload_walk_init, mi_payload_walk_step, NULL, &mi_ar_arg }, 4828 { "icmp", "walk ICMP control structures using MI for all stacks", 4829 mi_payload_walk_init, mi_payload_walk_step, NULL, 4830 &mi_icmp_arg }, 4831 { "ill", "walk ill_t structures using MI for all stacks", 4832 mi_payload_walk_init, mi_payload_walk_step, NULL, &mi_ill_arg }, 4833 4834 { "mi", "given a MI_O, walk the MI", 4835 mi_walk_init, mi_walk_step, mi_walk_fini, NULL }, 4836 { "sonode", "given a sonode, walk its children", 4837 sonode_walk_init, sonode_walk_step, sonode_walk_fini, NULL }, 4838 4839 { "ar_stacks", "walk all the ar_stack_t", 4840 ar_stacks_walk_init, ar_stacks_walk_step, NULL }, 4841 { "icmp_stacks", "walk all the icmp_stack_t", 4842 icmp_stacks_walk_init, icmp_stacks_walk_step, NULL }, 4843 { "tcp_stacks", "walk all the tcp_stack_t", 4844 tcp_stacks_walk_init, tcp_stacks_walk_step, NULL }, 4845 { "udp_stacks", "walk all the udp_stack_t", 4846 udp_stacks_walk_init, udp_stacks_walk_step, NULL }, 4847 4848 /* from nvpair.c */ 4849 { NVPAIR_WALKER_NAME, NVPAIR_WALKER_DESCR, 4850 nvpair_walk_init, nvpair_walk_step, NULL }, 4851 4852 /* from rctl.c */ 4853 { "rctl_dict_list", "walk all rctl_dict_entry_t's from rctl_lists", 4854 rctl_dict_walk_init, rctl_dict_walk_step, NULL }, 4855 { "rctl_set", "given a rctl_set, walk all rctls", rctl_set_walk_init, 4856 rctl_set_walk_step, NULL }, 4857 { "rctl_val", "given a rctl_t, walk all rctl_val entries associated", 4858 rctl_val_walk_init, rctl_val_walk_step }, 4859 4860 /* from sobj.c */ 4861 { "blocked", "walk threads blocked on a given sobj", 4862 blocked_walk_init, blocked_walk_step, NULL }, 4863 { "wchan", "given a wchan, list of blocked threads", 4864 wchan_walk_init, wchan_walk_step, wchan_walk_fini }, 4865 4866 /* from stream.c */ 4867 { "b_cont", "walk mblk_t list using b_cont", 4868 mblk_walk_init, b_cont_step, mblk_walk_fini }, 4869 { "b_next", "walk mblk_t list using b_next", 4870 mblk_walk_init, b_next_step, mblk_walk_fini }, 4871 { "qlink", "walk queue_t list using q_link", 4872 queue_walk_init, queue_link_step, queue_walk_fini }, 4873 { "qnext", "walk queue_t list using q_next", 4874 queue_walk_init, queue_next_step, queue_walk_fini }, 4875 { "strftblk", "given a dblk_t, walk STREAMS flow trace event list", 4876 strftblk_walk_init, strftblk_step, strftblk_walk_fini }, 4877 { "readq", "walk read queue side of stdata", 4878 str_walk_init, strr_walk_step, str_walk_fini }, 4879 { "writeq", "walk write queue side of stdata", 4880 str_walk_init, strw_walk_step, str_walk_fini }, 4881 4882 /* from thread.c */ 4883 { "deathrow", "walk threads on both lwp_ and thread_deathrow", 4884 deathrow_walk_init, deathrow_walk_step, NULL }, 4885 { "cpu_dispq", "given a cpu_t, walk threads in dispatcher queues", 4886 cpu_dispq_walk_init, dispq_walk_step, dispq_walk_fini }, 4887 { "cpupart_dispq", 4888 "given a cpupart_t, walk threads in dispatcher queues", 4889 cpupart_dispq_walk_init, dispq_walk_step, dispq_walk_fini }, 4890 { "lwp_deathrow", "walk lwp_deathrow", 4891 lwp_deathrow_walk_init, deathrow_walk_step, NULL }, 4892 { "thread", "global or per-process kthread_t structures", 4893 thread_walk_init, thread_walk_step, thread_walk_fini }, 4894 { "thread_deathrow", "walk threads on thread_deathrow", 4895 thread_deathrow_walk_init, deathrow_walk_step, NULL }, 4896 4897 /* from tsd.c */ 4898 { "tsd", "walk list of thread-specific data", 4899 tsd_walk_init, tsd_walk_step, tsd_walk_fini }, 4900 4901 /* from tsol.c */ 4902 { "tnrh", "walk remote host cache structures", 4903 tnrh_walk_init, tnrh_walk_step, tnrh_walk_fini }, 4904 { "tnrhtp", "walk remote host template structures", 4905 tnrhtp_walk_init, tnrhtp_walk_step, tnrhtp_walk_fini }, 4906 4907 /* 4908 * typegraph does not work under kmdb, as it requires too much memory 4909 * for its internal data structures. 4910 */ 4911 #ifndef _KMDB 4912 /* from typegraph.c */ 4913 { "typeconflict", "walk buffers with conflicting type inferences", 4914 typegraph_walk_init, typeconflict_walk_step }, 4915 { "typeunknown", "walk buffers with unknown types", 4916 typegraph_walk_init, typeunknown_walk_step }, 4917 #endif 4918 4919 /* from vfs.c */ 4920 { "vfs", "walk file system list", 4921 vfs_walk_init, vfs_walk_step }, 4922 4923 /* from mdi.c */ 4924 { "mdipi_client_list", "Walker for mdi_pathinfo pi_client_link", 4925 mdi_pi_client_link_walk_init, 4926 mdi_pi_client_link_walk_step, 4927 mdi_pi_client_link_walk_fini }, 4928 4929 { "mdipi_phci_list", "Walker for mdi_pathinfo pi_phci_link", 4930 mdi_pi_phci_link_walk_init, 4931 mdi_pi_phci_link_walk_step, 4932 mdi_pi_phci_link_walk_fini }, 4933 4934 { "mdiphci_list", "Walker for mdi_phci ph_next link", 4935 mdi_phci_ph_next_walk_init, 4936 mdi_phci_ph_next_walk_step, 4937 mdi_phci_ph_next_walk_fini }, 4938 4939 /* from netstack.c */ 4940 { "netstack", "walk a list of kernel netstacks", 4941 netstack_walk_init, netstack_walk_step, NULL }, 4942 4943 { NULL } 4944 }; 4945 4946 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers }; 4947 4948 /*ARGSUSED*/ 4949 static void 4950 genunix_statechange_cb(void *ignored) 4951 { 4952 /* 4953 * Force ::findleaks and ::stacks to let go any cached state. 4954 */ 4955 leaky_cleanup(1); 4956 stacks_cleanup(1); 4957 4958 kmem_statechange(); /* notify kmem */ 4959 } 4960 4961 const mdb_modinfo_t * 4962 _mdb_init(void) 4963 { 4964 kmem_init(); 4965 4966 (void) mdb_callback_add(MDB_CALLBACK_STCHG, 4967 genunix_statechange_cb, NULL); 4968 4969 return (&modinfo); 4970 } 4971 4972 void 4973 _mdb_fini(void) 4974 { 4975 leaky_cleanup(1); 4976 stacks_cleanup(1); 4977 } 4978