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