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