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