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