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