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