Print this page
4469 DTrace helper tracing should be dynamic
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mdb/common/modules/dtrace/dtrace.c
+++ new/usr/src/cmd/mdb/common/modules/dtrace/dtrace.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright (c) 2013 by Delphix. All rights reserved.
25 + * Copyright (c) 2012, Joyent, Inc. All rights reserved.
25 26 */
26 27
27 28 /*
28 29 * explicitly define DTRACE_ERRDEBUG to pull in definition of dtrace_errhash_t
29 30 * explicitly define _STDARG_H to avoid stdarg.h/varargs.h u/k defn conflict
30 31 */
31 32 #define DTRACE_ERRDEBUG
32 33 #define _STDARG_H
33 34
34 35 #include <mdb/mdb_param.h>
35 36 #include <mdb/mdb_modapi.h>
36 37 #include <mdb/mdb_ks.h>
37 38 #include <sys/dtrace_impl.h>
38 39 #include <sys/vmem_impl.h>
39 40 #include <sys/ddi_impldefs.h>
40 41 #include <sys/sysmacros.h>
41 42 #include <sys/kobj.h>
42 43 #include <dtrace.h>
43 44 #include <alloca.h>
44 45 #include <ctype.h>
45 46 #include <errno.h>
46 47 #include <math.h>
47 48 #include <stdio.h>
48 49 #include <unistd.h>
49 50
50 51 /*ARGSUSED*/
51 52 int
52 53 id2probe(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
53 54 {
54 55 uintptr_t probe = NULL;
55 56 uintptr_t probes;
56 57
57 58 if (!(flags & DCMD_ADDRSPEC))
58 59 return (DCMD_USAGE);
59 60
60 61 if (addr == DTRACE_IDNONE || addr > UINT32_MAX)
61 62 goto out;
62 63
63 64 if (mdb_readvar(&probes, "dtrace_probes") == -1) {
64 65 mdb_warn("failed to read 'dtrace_probes'");
65 66 return (DCMD_ERR);
66 67 }
67 68
68 69 probes += (addr - 1) * sizeof (dtrace_probe_t *);
69 70
70 71 if (mdb_vread(&probe, sizeof (uintptr_t), probes) == -1) {
71 72 mdb_warn("failed to read dtrace_probes[%d]", addr - 1);
72 73 return (DCMD_ERR);
73 74 }
74 75
75 76 out:
76 77 mdb_printf("%p\n", probe);
77 78 return (DCMD_OK);
78 79 }
79 80
80 81 void
81 82 dtrace_help(void)
82 83 {
83 84
84 85 mdb_printf("Given a dtrace_state_t structure that represents a "
85 86 "DTrace consumer, prints\n"
86 87 "dtrace(1M)-like output for in-kernel DTrace data. (The "
87 88 "dtrace_state_t\n"
88 89 "structures for all DTrace consumers may be obtained by running "
89 90 "the \n"
90 91 "::dtrace_state dcmd.) When data is present on multiple CPUs, "
91 92 "data are\n"
92 93 "presented in CPU order, with records within each CPU ordered "
93 94 "oldest to \n"
94 95 "youngest. Options:\n\n"
95 96 "-c cpu Only provide output for specified CPU.\n");
96 97 }
97 98
98 99 static int
99 100 dtracemdb_eprobe(dtrace_state_t *state, dtrace_eprobedesc_t *epd)
100 101 {
101 102 dtrace_epid_t epid = epd->dtepd_epid;
102 103 dtrace_probe_t probe;
103 104 dtrace_ecb_t ecb;
104 105 uintptr_t addr, paddr, ap;
105 106 dtrace_action_t act;
106 107 int nactions, nrecs;
107 108
108 109 addr = (uintptr_t)state->dts_ecbs +
109 110 (epid - 1) * sizeof (dtrace_ecb_t *);
110 111
111 112 if (mdb_vread(&addr, sizeof (addr), addr) == -1) {
112 113 mdb_warn("failed to read ecb for epid %d", epid);
113 114 return (-1);
114 115 }
115 116
116 117 if (addr == NULL) {
117 118 mdb_warn("epid %d doesn't match an ecb\n", epid);
118 119 return (-1);
119 120 }
120 121
121 122 if (mdb_vread(&ecb, sizeof (ecb), addr) == -1) {
122 123 mdb_warn("failed to read ecb at %p", addr);
123 124 return (-1);
124 125 }
125 126
126 127 paddr = (uintptr_t)ecb.dte_probe;
127 128
128 129 if (mdb_vread(&probe, sizeof (probe), paddr) == -1) {
129 130 mdb_warn("failed to read probe for ecb %p", addr);
130 131 return (-1);
131 132 }
132 133
133 134 /*
134 135 * This is a little painful: in order to find the number of actions,
135 136 * we need to first walk through them.
136 137 */
137 138 for (ap = (uintptr_t)ecb.dte_action, nactions = 0; ap != NULL; ) {
138 139 if (mdb_vread(&act, sizeof (act), ap) == -1) {
139 140 mdb_warn("failed to read action %p on ecb %p",
140 141 ap, addr);
141 142 return (-1);
142 143 }
143 144
144 145 if (!DTRACEACT_ISAGG(act.dta_kind) && !act.dta_intuple)
145 146 nactions++;
146 147
147 148 ap = (uintptr_t)act.dta_next;
148 149 }
149 150
150 151 nrecs = epd->dtepd_nrecs;
151 152 epd->dtepd_nrecs = nactions;
152 153 epd->dtepd_probeid = probe.dtpr_id;
153 154 epd->dtepd_uarg = ecb.dte_uarg;
154 155 epd->dtepd_size = ecb.dte_size;
155 156
156 157 for (ap = (uintptr_t)ecb.dte_action, nactions = 0; ap != NULL; ) {
157 158 if (mdb_vread(&act, sizeof (act), ap) == -1) {
158 159 mdb_warn("failed to read action %p on ecb %p",
159 160 ap, addr);
160 161 return (-1);
161 162 }
162 163
163 164 if (!DTRACEACT_ISAGG(act.dta_kind) && !act.dta_intuple) {
164 165 if (nrecs-- == 0)
165 166 break;
166 167
167 168 epd->dtepd_rec[nactions++] = act.dta_rec;
168 169 }
169 170
170 171 ap = (uintptr_t)act.dta_next;
171 172 }
172 173
173 174 return (0);
174 175 }
175 176
176 177 /*ARGSUSED*/
177 178 static int
178 179 dtracemdb_probe(dtrace_state_t *state, dtrace_probedesc_t *pd)
179 180 {
180 181 uintptr_t base, addr, paddr, praddr;
181 182 int nprobes, i;
182 183 dtrace_probe_t probe;
183 184 dtrace_provider_t prov;
184 185
185 186 if (pd->dtpd_id == DTRACE_IDNONE)
186 187 pd->dtpd_id++;
187 188
188 189 if (mdb_readvar(&base, "dtrace_probes") == -1) {
189 190 mdb_warn("failed to read 'dtrace_probes'");
190 191 return (-1);
191 192 }
192 193
193 194 if (mdb_readvar(&nprobes, "dtrace_nprobes") == -1) {
194 195 mdb_warn("failed to read 'dtrace_nprobes'");
195 196 return (-1);
196 197 }
197 198
198 199 for (i = pd->dtpd_id; i <= nprobes; i++) {
199 200 addr = base + (i - 1) * sizeof (dtrace_probe_t *);
200 201
201 202 if (mdb_vread(&paddr, sizeof (paddr), addr) == -1) {
202 203 mdb_warn("couldn't read probe pointer at %p", addr);
203 204 return (-1);
204 205 }
205 206
206 207 if (paddr != NULL)
207 208 break;
208 209 }
209 210
210 211 if (paddr == NULL) {
211 212 errno = ESRCH;
212 213 return (-1);
213 214 }
214 215
215 216 if (mdb_vread(&probe, sizeof (probe), paddr) == -1) {
216 217 mdb_warn("couldn't read probe at %p", paddr);
217 218 return (-1);
218 219 }
219 220
220 221 pd->dtpd_id = probe.dtpr_id;
221 222
222 223 if (mdb_vread(pd->dtpd_name, DTRACE_NAMELEN,
223 224 (uintptr_t)probe.dtpr_name) == -1) {
224 225 mdb_warn("failed to read probe name for probe %p", paddr);
225 226 return (-1);
226 227 }
227 228
228 229 if (mdb_vread(pd->dtpd_func, DTRACE_FUNCNAMELEN,
229 230 (uintptr_t)probe.dtpr_func) == -1) {
230 231 mdb_warn("failed to read function name for probe %p", paddr);
231 232 return (-1);
232 233 }
233 234
234 235 if (mdb_vread(pd->dtpd_mod, DTRACE_MODNAMELEN,
235 236 (uintptr_t)probe.dtpr_mod) == -1) {
236 237 mdb_warn("failed to read module name for probe %p", paddr);
237 238 return (-1);
238 239 }
239 240
240 241 praddr = (uintptr_t)probe.dtpr_provider;
241 242
242 243 if (mdb_vread(&prov, sizeof (prov), praddr) == -1) {
243 244 mdb_warn("failed to read provider for probe %p", paddr);
244 245 return (-1);
245 246 }
246 247
247 248 if (mdb_vread(pd->dtpd_provider, DTRACE_PROVNAMELEN,
248 249 (uintptr_t)prov.dtpv_name) == -1) {
249 250 mdb_warn("failed to read provider name for probe %p", paddr);
250 251 return (-1);
251 252 }
252 253
253 254 return (0);
254 255 }
255 256
256 257 /*ARGSUSED*/
257 258 static int
258 259 dtracemdb_aggdesc(dtrace_state_t *state, dtrace_aggdesc_t *agd)
259 260 {
260 261 dtrace_aggid_t aggid = agd->dtagd_id;
261 262 dtrace_aggregation_t agg;
262 263 dtrace_ecb_t ecb;
263 264 uintptr_t addr, eaddr, ap, last;
264 265 dtrace_action_t act;
265 266 dtrace_recdesc_t *lrec;
266 267 int nactions, nrecs;
267 268
268 269 addr = (uintptr_t)state->dts_aggregations +
269 270 (aggid - 1) * sizeof (dtrace_aggregation_t *);
270 271
271 272 if (mdb_vread(&addr, sizeof (addr), addr) == -1) {
272 273 mdb_warn("failed to read aggregation for aggid %d", aggid);
273 274 return (-1);
274 275 }
275 276
276 277 if (addr == NULL) {
277 278 mdb_warn("aggid %d doesn't match an aggregation\n", aggid);
278 279 return (-1);
279 280 }
280 281
281 282 if (mdb_vread(&agg, sizeof (agg), addr) == -1) {
282 283 mdb_warn("failed to read aggregation at %p", addr);
283 284 return (-1);
284 285 }
285 286
286 287 eaddr = (uintptr_t)agg.dtag_ecb;
287 288
288 289 if (mdb_vread(&ecb, sizeof (ecb), eaddr) == -1) {
289 290 mdb_warn("failed to read ecb for aggregation %p", addr);
290 291 return (-1);
291 292 }
292 293
293 294 last = (uintptr_t)addr + offsetof(dtrace_aggregation_t, dtag_action);
294 295
295 296 /*
296 297 * This is a little painful: in order to find the number of actions,
297 298 * we need to first walk through them.
298 299 */
299 300 ap = (uintptr_t)agg.dtag_first;
300 301 nactions = 0;
301 302
302 303 for (;;) {
303 304 if (mdb_vread(&act, sizeof (act), ap) == -1) {
304 305 mdb_warn("failed to read action %p on aggregation %p",
305 306 ap, addr);
306 307 return (-1);
307 308 }
308 309
309 310 nactions++;
310 311
311 312 if (ap == last)
312 313 break;
313 314
314 315 ap = (uintptr_t)act.dta_next;
315 316 }
316 317
317 318 lrec = &act.dta_rec;
318 319 agd->dtagd_size = lrec->dtrd_offset + lrec->dtrd_size - agg.dtag_base;
319 320
320 321 nrecs = agd->dtagd_nrecs;
321 322 agd->dtagd_nrecs = nactions;
322 323 agd->dtagd_epid = ecb.dte_epid;
323 324
324 325 ap = (uintptr_t)agg.dtag_first;
325 326 nactions = 0;
326 327
327 328 for (;;) {
328 329 dtrace_recdesc_t rec;
329 330
330 331 if (mdb_vread(&act, sizeof (act), ap) == -1) {
331 332 mdb_warn("failed to read action %p on aggregation %p",
332 333 ap, addr);
333 334 return (-1);
334 335 }
335 336
336 337 if (nrecs-- == 0)
337 338 break;
338 339
339 340 rec = act.dta_rec;
340 341 rec.dtrd_offset -= agg.dtag_base;
341 342 rec.dtrd_uarg = 0;
342 343 agd->dtagd_rec[nactions++] = rec;
343 344
344 345 if (ap == last)
345 346 break;
346 347
347 348 ap = (uintptr_t)act.dta_next;
348 349 }
349 350
350 351 return (0);
351 352 }
352 353
353 354 static int
354 355 dtracemdb_bufsnap(dtrace_buffer_t *which, dtrace_bufdesc_t *desc)
355 356 {
356 357 uintptr_t addr;
357 358 size_t bufsize;
358 359 dtrace_buffer_t buf;
359 360 caddr_t data = desc->dtbd_data;
360 361 processorid_t max_cpuid, cpu = desc->dtbd_cpu;
361 362
362 363 if (mdb_readvar(&max_cpuid, "max_cpuid") == -1) {
363 364 mdb_warn("failed to read 'max_cpuid'");
364 365 errno = EIO;
365 366 return (-1);
366 367 }
367 368
368 369 if (cpu < 0 || cpu > max_cpuid) {
369 370 errno = EINVAL;
370 371 return (-1);
371 372 }
372 373
373 374 addr = (uintptr_t)which + cpu * sizeof (dtrace_buffer_t);
374 375
375 376 if (mdb_vread(&buf, sizeof (buf), addr) == -1) {
376 377 mdb_warn("failed to read buffer description at %p", addr);
377 378 errno = EIO;
378 379 return (-1);
379 380 }
380 381
381 382 if (buf.dtb_tomax == NULL) {
382 383 errno = ENOENT;
383 384 return (-1);
384 385 }
385 386
386 387 if (buf.dtb_flags & DTRACEBUF_WRAPPED) {
387 388 bufsize = buf.dtb_size;
388 389 } else {
389 390 bufsize = buf.dtb_offset;
390 391 }
391 392
392 393 if (mdb_vread(data, bufsize, (uintptr_t)buf.dtb_tomax) == -1) {
393 394 mdb_warn("couldn't read buffer for CPU %d", cpu);
394 395 errno = EIO;
395 396 return (-1);
396 397 }
397 398
398 399 if (buf.dtb_offset > buf.dtb_size) {
399 400 mdb_warn("buffer for CPU %d has corrupt offset\n", cpu);
400 401 errno = EIO;
401 402 return (-1);
402 403 }
403 404
404 405 if (buf.dtb_flags & DTRACEBUF_WRAPPED) {
405 406 if (buf.dtb_xamot_offset > buf.dtb_size) {
406 407 mdb_warn("ringbuffer for CPU %d has corrupt "
407 408 "wrapped offset\n", cpu);
408 409 errno = EIO;
409 410 return (-1);
410 411 }
411 412
412 413 /*
413 414 * If the ring buffer has wrapped, it needs to be polished.
414 415 * See the comment in dtrace_buffer_polish() for details.
415 416 */
416 417 if (buf.dtb_offset < buf.dtb_xamot_offset) {
417 418 bzero(data + buf.dtb_offset,
418 419 buf.dtb_xamot_offset - buf.dtb_offset);
419 420 }
420 421
421 422 if (buf.dtb_offset > buf.dtb_xamot_offset) {
422 423 bzero(data + buf.dtb_offset,
423 424 buf.dtb_size - buf.dtb_offset);
424 425 bzero(data, buf.dtb_xamot_offset);
425 426 }
426 427
427 428 desc->dtbd_oldest = buf.dtb_xamot_offset;
428 429 } else {
429 430 desc->dtbd_oldest = 0;
430 431 }
431 432
432 433 desc->dtbd_size = bufsize;
433 434 desc->dtbd_drops = buf.dtb_drops;
434 435 desc->dtbd_errors = buf.dtb_errors;
435 436
436 437 return (0);
437 438 }
438 439
439 440 /*
440 441 * This is essentially identical to its cousin in the kernel -- with the
441 442 * notable exception that we automatically set DTRACEOPT_GRABANON if this
442 443 * state is an anonymous enabling.
443 444 */
444 445 static dof_hdr_t *
445 446 dtracemdb_dof_create(dtrace_state_t *state, int isanon)
446 447 {
447 448 dof_hdr_t *dof;
448 449 dof_sec_t *sec;
449 450 dof_optdesc_t *opt;
450 451 int i, len = sizeof (dof_hdr_t) +
451 452 roundup(sizeof (dof_sec_t), sizeof (uint64_t)) +
452 453 sizeof (dof_optdesc_t) * DTRACEOPT_MAX;
453 454
454 455 dof = mdb_zalloc(len, UM_SLEEP);
455 456 dof->dofh_ident[DOF_ID_MAG0] = DOF_MAG_MAG0;
456 457 dof->dofh_ident[DOF_ID_MAG1] = DOF_MAG_MAG1;
457 458 dof->dofh_ident[DOF_ID_MAG2] = DOF_MAG_MAG2;
458 459 dof->dofh_ident[DOF_ID_MAG3] = DOF_MAG_MAG3;
459 460
460 461 dof->dofh_ident[DOF_ID_MODEL] = DOF_MODEL_NATIVE;
461 462 dof->dofh_ident[DOF_ID_ENCODING] = DOF_ENCODE_NATIVE;
462 463 dof->dofh_ident[DOF_ID_VERSION] = DOF_VERSION;
463 464 dof->dofh_ident[DOF_ID_DIFVERS] = DIF_VERSION;
464 465 dof->dofh_ident[DOF_ID_DIFIREG] = DIF_DIR_NREGS;
465 466 dof->dofh_ident[DOF_ID_DIFTREG] = DIF_DTR_NREGS;
466 467
467 468 dof->dofh_flags = 0;
468 469 dof->dofh_hdrsize = sizeof (dof_hdr_t);
469 470 dof->dofh_secsize = sizeof (dof_sec_t);
470 471 dof->dofh_secnum = 1; /* only DOF_SECT_OPTDESC */
471 472 dof->dofh_secoff = sizeof (dof_hdr_t);
472 473 dof->dofh_loadsz = len;
473 474 dof->dofh_filesz = len;
474 475 dof->dofh_pad = 0;
475 476
476 477 /*
477 478 * Fill in the option section header...
478 479 */
479 480 sec = (dof_sec_t *)((uintptr_t)dof + sizeof (dof_hdr_t));
480 481 sec->dofs_type = DOF_SECT_OPTDESC;
481 482 sec->dofs_align = sizeof (uint64_t);
482 483 sec->dofs_flags = DOF_SECF_LOAD;
483 484 sec->dofs_entsize = sizeof (dof_optdesc_t);
484 485
485 486 opt = (dof_optdesc_t *)((uintptr_t)sec +
486 487 roundup(sizeof (dof_sec_t), sizeof (uint64_t)));
487 488
488 489 sec->dofs_offset = (uintptr_t)opt - (uintptr_t)dof;
489 490 sec->dofs_size = sizeof (dof_optdesc_t) * DTRACEOPT_MAX;
490 491
491 492 for (i = 0; i < DTRACEOPT_MAX; i++) {
492 493 opt[i].dofo_option = i;
493 494 opt[i].dofo_strtab = DOF_SECIDX_NONE;
494 495 opt[i].dofo_value = state->dts_options[i];
495 496 }
496 497
497 498 if (isanon)
498 499 opt[DTRACEOPT_GRABANON].dofo_value = 1;
499 500
500 501 return (dof);
501 502 }
502 503
503 504 static int
504 505 dtracemdb_format(dtrace_state_t *state, dtrace_fmtdesc_t *desc)
505 506 {
506 507 uintptr_t addr, faddr;
507 508 char c;
508 509 int len = 0;
509 510
510 511 if (desc->dtfd_format == 0 || desc->dtfd_format > state->dts_nformats) {
511 512 errno = EINVAL;
512 513 return (-1);
513 514 }
514 515
515 516 faddr = (uintptr_t)state->dts_formats +
516 517 (desc->dtfd_format - 1) * sizeof (char *);
517 518
518 519 if (mdb_vread(&addr, sizeof (addr), faddr) == -1) {
519 520 mdb_warn("failed to read format string pointer at %p", faddr);
520 521 return (-1);
521 522 }
522 523
523 524 do {
524 525 if (mdb_vread(&c, sizeof (c), addr + len++) == -1) {
525 526 mdb_warn("failed to read format string at %p", addr);
526 527 return (-1);
527 528 }
528 529 } while (c != '\0');
529 530
530 531 if (len > desc->dtfd_length) {
531 532 desc->dtfd_length = len;
532 533 return (0);
533 534 }
534 535
535 536 if (mdb_vread(desc->dtfd_string, len, addr) == -1) {
536 537 mdb_warn("failed to reread format string at %p", addr);
537 538 return (-1);
538 539 }
539 540
540 541 return (0);
541 542 }
542 543
543 544 static int
544 545 dtracemdb_status(dtrace_state_t *state, dtrace_status_t *status)
545 546 {
546 547 dtrace_dstate_t *dstate;
547 548 int i, j;
548 549 uint64_t nerrs;
549 550 uintptr_t addr;
550 551 int ncpu;
551 552
552 553 if (mdb_readvar(&ncpu, "_ncpu") == -1) {
553 554 mdb_warn("failed to read '_ncpu'");
554 555 return (DCMD_ERR);
555 556 }
556 557
557 558 bzero(status, sizeof (dtrace_status_t));
558 559
559 560 if (state->dts_activity == DTRACE_ACTIVITY_INACTIVE) {
560 561 errno = ENOENT;
561 562 return (-1);
562 563 }
563 564
564 565 /*
565 566 * For the MDB backend, we never set dtst_exiting or dtst_filled. This
566 567 * is by design: we don't want the library to try to stop tracing,
567 568 * because it doesn't particularly mean anything.
568 569 */
569 570 nerrs = state->dts_errors;
570 571 dstate = &state->dts_vstate.dtvs_dynvars;
571 572
572 573 for (i = 0; i < ncpu; i++) {
573 574 dtrace_dstate_percpu_t dcpu;
574 575 dtrace_buffer_t buf;
575 576
576 577 addr = (uintptr_t)&dstate->dtds_percpu[i];
577 578
578 579 if (mdb_vread(&dcpu, sizeof (dcpu), addr) == -1) {
579 580 mdb_warn("failed to read per-CPU dstate at %p", addr);
580 581 return (-1);
581 582 }
582 583
583 584 status->dtst_dyndrops += dcpu.dtdsc_drops;
584 585 status->dtst_dyndrops_dirty += dcpu.dtdsc_dirty_drops;
585 586 status->dtst_dyndrops_rinsing += dcpu.dtdsc_rinsing_drops;
586 587
587 588 addr = (uintptr_t)&state->dts_buffer[i];
588 589
589 590 if (mdb_vread(&buf, sizeof (buf), addr) == -1) {
590 591 mdb_warn("failed to read per-CPU buffer at %p", addr);
591 592 return (-1);
592 593 }
593 594
594 595 nerrs += buf.dtb_errors;
595 596
596 597 for (j = 0; j < state->dts_nspeculations; j++) {
597 598 dtrace_speculation_t spec;
598 599
599 600 addr = (uintptr_t)&state->dts_speculations[j];
600 601
601 602 if (mdb_vread(&spec, sizeof (spec), addr) == -1) {
602 603 mdb_warn("failed to read "
603 604 "speculation at %p", addr);
604 605 return (-1);
605 606 }
606 607
607 608 addr = (uintptr_t)&spec.dtsp_buffer[i];
608 609
609 610 if (mdb_vread(&buf, sizeof (buf), addr) == -1) {
610 611 mdb_warn("failed to read "
611 612 "speculative buffer at %p", addr);
612 613 return (-1);
613 614 }
614 615
615 616 status->dtst_specdrops += buf.dtb_xamot_drops;
616 617 }
617 618 }
618 619
619 620 status->dtst_specdrops_busy = state->dts_speculations_busy;
620 621 status->dtst_specdrops_unavail = state->dts_speculations_unavail;
621 622 status->dtst_errors = nerrs;
622 623
623 624 return (0);
624 625 }
625 626
626 627 typedef struct dtracemdb_data {
627 628 dtrace_state_t *dtmd_state;
628 629 char *dtmd_symstr;
629 630 char *dtmd_modstr;
630 631 uintptr_t dtmd_addr;
631 632 int dtmd_isanon;
632 633 } dtracemdb_data_t;
633 634
634 635 static int
635 636 dtracemdb_ioctl(void *varg, int cmd, void *arg)
636 637 {
637 638 dtracemdb_data_t *data = varg;
638 639 dtrace_state_t *state = data->dtmd_state;
639 640
640 641 switch (cmd) {
641 642 case DTRACEIOC_CONF: {
642 643 dtrace_conf_t *conf = arg;
643 644
644 645 bzero(conf, sizeof (conf));
645 646 conf->dtc_difversion = DIF_VERSION;
646 647 conf->dtc_difintregs = DIF_DIR_NREGS;
647 648 conf->dtc_diftupregs = DIF_DTR_NREGS;
648 649 conf->dtc_ctfmodel = CTF_MODEL_NATIVE;
649 650
650 651 return (0);
651 652 }
652 653
653 654 case DTRACEIOC_DOFGET: {
654 655 dof_hdr_t *hdr = arg, *dof;
655 656
656 657 dof = dtracemdb_dof_create(state, data->dtmd_isanon);
657 658 bcopy(dof, hdr, MIN(hdr->dofh_loadsz, dof->dofh_loadsz));
658 659 mdb_free(dof, dof->dofh_loadsz);
659 660
660 661 return (0);
661 662 }
662 663
663 664 case DTRACEIOC_BUFSNAP:
664 665 return (dtracemdb_bufsnap(state->dts_buffer, arg));
665 666
666 667 case DTRACEIOC_AGGSNAP:
667 668 return (dtracemdb_bufsnap(state->dts_aggbuffer, arg));
668 669
669 670 case DTRACEIOC_AGGDESC:
670 671 return (dtracemdb_aggdesc(state, arg));
671 672
672 673 case DTRACEIOC_EPROBE:
673 674 return (dtracemdb_eprobe(state, arg));
674 675
675 676 case DTRACEIOC_PROBES:
676 677 return (dtracemdb_probe(state, arg));
677 678
678 679 case DTRACEIOC_FORMAT:
679 680 return (dtracemdb_format(state, arg));
680 681
681 682 case DTRACEIOC_STATUS:
682 683 return (dtracemdb_status(state, arg));
683 684
684 685 case DTRACEIOC_GO:
685 686 *(processorid_t *)arg = -1;
686 687 return (0);
687 688
688 689 case DTRACEIOC_ENABLE:
689 690 errno = ENOTTY; /* see dt_open.c:dtrace_go() */
690 691 return (-1);
691 692
692 693 case DTRACEIOC_PROVIDER:
693 694 case DTRACEIOC_PROBEMATCH:
694 695 errno = ESRCH;
695 696 return (-1);
696 697
697 698 default:
698 699 mdb_warn("unexpected ioctl 0x%x (%s)\n", cmd,
699 700 cmd == DTRACEIOC_PROVIDER ? "DTRACEIOC_PROVIDER" :
700 701 cmd == DTRACEIOC_PROBES ? "DTRACEIOC_PROBES" :
701 702 cmd == DTRACEIOC_BUFSNAP ? "DTRACEIOC_BUFSNAP" :
702 703 cmd == DTRACEIOC_PROBEMATCH ? "DTRACEIOC_PROBEMATCH" :
703 704 cmd == DTRACEIOC_ENABLE ? "DTRACEIOC_ENABLE" :
704 705 cmd == DTRACEIOC_AGGSNAP ? "DTRACEIOC_AGGSNAP" :
705 706 cmd == DTRACEIOC_EPROBE ? "DTRACEIOC_EPROBE" :
706 707 cmd == DTRACEIOC_PROBEARG ? "DTRACEIOC_PROBEARG" :
707 708 cmd == DTRACEIOC_CONF ? "DTRACEIOC_CONF" :
708 709 cmd == DTRACEIOC_STATUS ? "DTRACEIOC_STATUS" :
709 710 cmd == DTRACEIOC_GO ? "DTRACEIOC_GO" :
710 711 cmd == DTRACEIOC_STOP ? "DTRACEIOC_STOP" :
711 712 cmd == DTRACEIOC_AGGDESC ? "DTRACEIOC_AGGDESC" :
712 713 cmd == DTRACEIOC_FORMAT ? "DTRACEIOC_FORMAT" :
713 714 cmd == DTRACEIOC_DOFGET ? "DTRACEIOC_DOFGET" :
714 715 cmd == DTRACEIOC_REPLICATE ? "DTRACEIOC_REPLICATE" :
715 716 "???");
716 717 errno = ENXIO;
717 718 return (-1);
718 719 }
719 720 }
720 721
721 722 static int
722 723 dtracemdb_modctl(uintptr_t addr, const struct modctl *m, dtracemdb_data_t *data)
723 724 {
724 725 struct module mod;
725 726
726 727 if (m->mod_mp == NULL)
727 728 return (WALK_NEXT);
728 729
729 730 if (mdb_vread(&mod, sizeof (mod), (uintptr_t)m->mod_mp) == -1) {
730 731 mdb_warn("couldn't read modctl %p's module", addr);
731 732 return (WALK_NEXT);
732 733 }
733 734
734 735 if ((uintptr_t)mod.text > data->dtmd_addr)
735 736 return (WALK_NEXT);
736 737
737 738 if ((uintptr_t)mod.text + mod.text_size <= data->dtmd_addr)
738 739 return (WALK_NEXT);
739 740
740 741 if (mdb_readstr(data->dtmd_modstr, MDB_SYM_NAMLEN,
741 742 (uintptr_t)m->mod_modname) == -1)
742 743 return (WALK_ERR);
743 744
744 745 return (WALK_DONE);
745 746 }
746 747
747 748 static int
748 749 dtracemdb_lookup_by_addr(void *varg, GElf_Addr addr, GElf_Sym *symp,
749 750 dtrace_syminfo_t *sip)
750 751 {
751 752 dtracemdb_data_t *data = varg;
752 753
753 754 if (data->dtmd_symstr == NULL) {
754 755 data->dtmd_symstr = mdb_zalloc(MDB_SYM_NAMLEN,
755 756 UM_SLEEP | UM_GC);
756 757 }
757 758
758 759 if (data->dtmd_modstr == NULL) {
759 760 data->dtmd_modstr = mdb_zalloc(MDB_SYM_NAMLEN,
760 761 UM_SLEEP | UM_GC);
761 762 }
762 763
763 764 if (symp != NULL) {
764 765 if (mdb_lookup_by_addr(addr, MDB_SYM_FUZZY, data->dtmd_symstr,
765 766 MDB_SYM_NAMLEN, symp) == -1)
766 767 return (-1);
767 768 }
768 769
769 770 if (sip != NULL) {
770 771 data->dtmd_addr = addr;
771 772
772 773 (void) strcpy(data->dtmd_modstr, "???");
773 774
774 775 if (mdb_walk("modctl",
775 776 (mdb_walk_cb_t)dtracemdb_modctl, varg) == -1) {
776 777 mdb_warn("couldn't walk 'modctl'");
777 778 return (-1);
778 779 }
779 780
780 781 sip->dts_object = data->dtmd_modstr;
781 782 sip->dts_id = 0;
782 783 sip->dts_name = symp != NULL ? data->dtmd_symstr : NULL;
783 784 }
784 785
785 786 return (0);
786 787 }
787 788
788 789 /*ARGSUSED*/
789 790 static int
790 791 dtracemdb_stat(void *varg, processorid_t cpu)
791 792 {
792 793 GElf_Sym sym;
793 794 cpu_t c;
794 795 uintptr_t caddr, addr;
795 796
796 797 if (mdb_lookup_by_name("cpu", &sym) == -1) {
797 798 mdb_warn("failed to find symbol for 'cpu'");
798 799 return (-1);
799 800 }
800 801
801 802 if (cpu * sizeof (uintptr_t) > sym.st_size)
802 803 return (-1);
803 804
804 805 addr = (uintptr_t)sym.st_value + cpu * sizeof (uintptr_t);
805 806
806 807 if (mdb_vread(&caddr, sizeof (caddr), addr) == -1) {
807 808 mdb_warn("failed to read cpu[%d]", cpu);
808 809 return (-1);
809 810 }
810 811
811 812 if (caddr == NULL)
812 813 return (-1);
813 814
814 815 if (mdb_vread(&c, sizeof (c), caddr) == -1) {
815 816 mdb_warn("failed to read cpu at %p", caddr);
816 817 return (-1);
817 818 }
818 819
819 820 if (c.cpu_flags & CPU_POWEROFF) {
820 821 return (P_POWEROFF);
821 822 } else if (c.cpu_flags & CPU_SPARE) {
822 823 return (P_SPARE);
823 824 } else if (c.cpu_flags & CPU_FAULTED) {
824 825 return (P_FAULTED);
825 826 } else if ((c.cpu_flags & (CPU_READY | CPU_OFFLINE)) != CPU_READY) {
826 827 return (P_OFFLINE);
827 828 } else if (c.cpu_flags & CPU_ENABLE) {
828 829 return (P_ONLINE);
829 830 } else {
830 831 return (P_NOINTR);
831 832 }
832 833 }
833 834
834 835 /*ARGSUSED*/
835 836 static long
836 837 dtracemdb_sysconf(void *varg, int name)
837 838 {
838 839 int max_ncpus;
839 840 processorid_t max_cpuid;
840 841
841 842 switch (name) {
842 843 case _SC_CPUID_MAX:
843 844 if (mdb_readvar(&max_cpuid, "max_cpuid") == -1) {
844 845 mdb_warn("failed to read 'max_cpuid'");
845 846 return (-1);
846 847 }
847 848
848 849 return (max_cpuid);
849 850
850 851 case _SC_NPROCESSORS_MAX:
851 852 if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
852 853 mdb_warn("failed to read 'max_ncpus'");
853 854 return (-1);
854 855 }
855 856
856 857 return (max_ncpus);
857 858
858 859 default:
859 860 mdb_warn("unexpected sysconf code %d\n", name);
860 861 return (-1);
861 862 }
862 863 }
863 864
864 865 const dtrace_vector_t dtrace_mdbops = {
865 866 dtracemdb_ioctl,
866 867 dtracemdb_lookup_by_addr,
867 868 dtracemdb_stat,
868 869 dtracemdb_sysconf
869 870 };
870 871
871 872 typedef struct dtrace_dcmddata {
872 873 dtrace_hdl_t *dtdd_dtp;
873 874 int dtdd_cpu;
874 875 int dtdd_quiet;
875 876 int dtdd_flowindent;
876 877 int dtdd_heading;
877 878 FILE *dtdd_output;
878 879 } dtrace_dcmddata_t;
879 880
880 881 /*
881 882 * Helper to grab all the content from a file, spit it into a string, and erase
882 883 * and reset the file.
883 884 */
884 885 static void
885 886 print_and_truncate_file(FILE *fp)
886 887 {
887 888 long len;
888 889 char *out;
889 890
890 891 /* flush, find length of file, seek to beginning, initialize buffer */
891 892 if (fflush(fp) || (len = ftell(fp)) < 0 ||
892 893 fseek(fp, 0, SEEK_SET) < 0) {
893 894 mdb_warn("couldn't prepare DTrace output file: %d\n", errno);
894 895 return;
895 896 }
896 897
897 898 out = mdb_alloc(len + 1, UM_SLEEP);
898 899 out[len] = '\0';
899 900
900 901 /* read file into buffer, truncate file, and seek to beginning */
901 902 if ((fread(out, len + 1, sizeof (char), fp) == 0 && ferror(fp)) ||
902 903 ftruncate(fileno(fp), 0) < 0 || fseek(fp, 0, SEEK_SET) < 0) {
903 904 mdb_warn("couldn't read DTrace output file: %d\n", errno);
904 905 mdb_free(out, len + 1);
905 906 return;
906 907 }
907 908
908 909 mdb_printf("%s", out);
909 910 mdb_free(out, len + 1);
910 911 }
911 912
912 913 /*ARGSUSED*/
913 914 static int
914 915 dtrace_dcmdrec(const dtrace_probedata_t *data,
915 916 const dtrace_recdesc_t *rec, void *arg)
916 917 {
917 918 dtrace_dcmddata_t *dd = arg;
918 919
919 920 print_and_truncate_file(dd->dtdd_output);
920 921
921 922 if (rec == NULL) {
922 923 /*
923 924 * We have processed the final record; output the newline if
924 925 * we're not in quiet mode.
925 926 */
926 927 if (!dd->dtdd_quiet)
927 928 mdb_printf("\n");
928 929
929 930 return (DTRACE_CONSUME_NEXT);
930 931 }
931 932
932 933 return (DTRACE_CONSUME_THIS);
933 934 }
934 935
935 936 /*ARGSUSED*/
936 937 static int
937 938 dtrace_dcmdprobe(const dtrace_probedata_t *data, void *arg)
938 939 {
939 940 dtrace_probedesc_t *pd = data->dtpda_pdesc;
940 941 processorid_t cpu = data->dtpda_cpu;
941 942 dtrace_dcmddata_t *dd = arg;
942 943 char name[DTRACE_FUNCNAMELEN + DTRACE_NAMELEN + 2];
943 944
944 945 if (dd->dtdd_cpu != -1UL && dd->dtdd_cpu != cpu)
945 946 return (DTRACE_CONSUME_NEXT);
946 947
947 948 if (dd->dtdd_heading == 0) {
948 949 if (!dd->dtdd_flowindent) {
949 950 if (!dd->dtdd_quiet) {
950 951 mdb_printf("%3s %6s %32s\n",
951 952 "CPU", "ID", "FUNCTION:NAME");
952 953 }
953 954 } else {
954 955 mdb_printf("%3s %-41s\n", "CPU", "FUNCTION");
955 956 }
956 957 dd->dtdd_heading = 1;
957 958 }
958 959
959 960 if (!dd->dtdd_flowindent) {
960 961 if (!dd->dtdd_quiet) {
961 962 (void) mdb_snprintf(name, sizeof (name), "%s:%s",
962 963 pd->dtpd_func, pd->dtpd_name);
963 964
964 965 mdb_printf("%3d %6d %32s ", cpu, pd->dtpd_id, name);
965 966 }
966 967 } else {
967 968 int indent = data->dtpda_indent;
968 969
969 970 if (data->dtpda_flow == DTRACEFLOW_NONE) {
970 971 (void) mdb_snprintf(name, sizeof (name), "%*s%s%s:%s",
971 972 indent, "", data->dtpda_prefix, pd->dtpd_func,
972 973 pd->dtpd_name);
973 974 } else {
974 975 (void) mdb_snprintf(name, sizeof (name), "%*s%s%s",
975 976 indent, "", data->dtpda_prefix, pd->dtpd_func);
976 977 }
977 978
978 979 mdb_printf("%3d %-41s ", cpu, name);
979 980 }
980 981
981 982 return (DTRACE_CONSUME_THIS);
982 983 }
983 984
984 985 /*ARGSUSED*/
985 986 static int
986 987 dtrace_dcmderr(const dtrace_errdata_t *data, void *arg)
987 988 {
988 989 mdb_warn(data->dteda_msg);
989 990 return (DTRACE_HANDLE_OK);
990 991 }
991 992
992 993 /*ARGSUSED*/
993 994 static int
994 995 dtrace_dcmddrop(const dtrace_dropdata_t *data, void *arg)
995 996 {
996 997 mdb_warn(data->dtdda_msg);
997 998 return (DTRACE_HANDLE_OK);
998 999 }
999 1000
1000 1001 /*ARGSUSED*/
1001 1002 static int
1002 1003 dtrace_dcmdbuffered(const dtrace_bufdata_t *bufdata, void *arg)
1003 1004 {
1004 1005 mdb_printf("%s", bufdata->dtbda_buffered);
1005 1006 return (DTRACE_HANDLE_OK);
1006 1007 }
1007 1008
1008 1009 /*ARGSUSED*/
1009 1010 int
1010 1011 dtrace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1011 1012 {
1012 1013 dtrace_state_t state;
1013 1014 dtrace_hdl_t *dtp;
1014 1015 int ncpu, err;
1015 1016 uintptr_t c = -1UL;
1016 1017 dtrace_dcmddata_t dd;
1017 1018 dtrace_optval_t val;
1018 1019 dtracemdb_data_t md;
1019 1020 int rval = DCMD_ERR;
1020 1021 dtrace_anon_t anon;
1021 1022
1022 1023 if (!(flags & DCMD_ADDRSPEC))
1023 1024 return (DCMD_USAGE);
1024 1025
1025 1026 if (mdb_getopts(argc, argv, 'c', MDB_OPT_UINTPTR, &c, NULL) != argc)
1026 1027 return (DCMD_USAGE);
1027 1028
1028 1029 if (mdb_readvar(&ncpu, "_ncpu") == -1) {
1029 1030 mdb_warn("failed to read '_ncpu'");
1030 1031 return (DCMD_ERR);
1031 1032 }
1032 1033
1033 1034 if (mdb_vread(&state, sizeof (state), addr) == -1) {
1034 1035 mdb_warn("couldn't read dtrace_state_t at %p", addr);
1035 1036 return (DCMD_ERR);
1036 1037 }
1037 1038
1038 1039 if (state.dts_anon != NULL) {
1039 1040 addr = (uintptr_t)state.dts_anon;
1040 1041
1041 1042 if (mdb_vread(&state, sizeof (state), addr) == -1) {
1042 1043 mdb_warn("couldn't read anonymous state at %p", addr);
1043 1044 return (DCMD_ERR);
1044 1045 }
1045 1046 }
1046 1047
1047 1048 bzero(&md, sizeof (md));
1048 1049 md.dtmd_state = &state;
1049 1050
1050 1051 if ((dtp = dtrace_vopen(DTRACE_VERSION, DTRACE_O_NOSYS, &err,
1051 1052 &dtrace_mdbops, &md)) == NULL) {
1052 1053 mdb_warn("failed to initialize dtrace: %s\n",
1053 1054 dtrace_errmsg(NULL, err));
1054 1055 return (DCMD_ERR);
1055 1056 }
1056 1057
1057 1058 /*
1058 1059 * If this is the anonymous enabling, we need to set a bit indicating
1059 1060 * that DTRACEOPT_GRABANON should be set.
1060 1061 */
1061 1062 if (mdb_readvar(&anon, "dtrace_anon") == -1) {
1062 1063 mdb_warn("failed to read 'dtrace_anon'");
1063 1064 return (DCMD_ERR);
1064 1065 }
1065 1066
1066 1067 md.dtmd_isanon = ((uintptr_t)anon.dta_state == addr);
1067 1068
1068 1069 if (dtrace_go(dtp) != 0) {
1069 1070 mdb_warn("failed to initialize dtrace: %s\n",
1070 1071 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1071 1072 goto err;
1072 1073 }
1073 1074
1074 1075 bzero(&dd, sizeof (dd));
1075 1076 dd.dtdd_dtp = dtp;
1076 1077 dd.dtdd_cpu = c;
1077 1078
1078 1079 if (dtrace_getopt(dtp, "flowindent", &val) == -1) {
1079 1080 mdb_warn("couldn't get 'flowindent' option: %s\n",
1080 1081 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1081 1082 goto err;
1082 1083 }
1083 1084
1084 1085 dd.dtdd_flowindent = (val != DTRACEOPT_UNSET);
1085 1086
1086 1087 if (dtrace_getopt(dtp, "quiet", &val) == -1) {
1087 1088 mdb_warn("couldn't get 'quiet' option: %s\n",
1088 1089 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1089 1090 goto err;
1090 1091 }
1091 1092
1092 1093 dd.dtdd_quiet = (val != DTRACEOPT_UNSET);
1093 1094
1094 1095 if (dtrace_handle_err(dtp, dtrace_dcmderr, NULL) == -1) {
1095 1096 mdb_warn("couldn't add err handler: %s\n",
1096 1097 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1097 1098 goto err;
1098 1099 }
1099 1100
1100 1101 if (dtrace_handle_drop(dtp, dtrace_dcmddrop, NULL) == -1) {
1101 1102 mdb_warn("couldn't add drop handler: %s\n",
1102 1103 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1103 1104 goto err;
1104 1105 }
1105 1106
1106 1107 if (dtrace_handle_buffered(dtp, dtrace_dcmdbuffered, NULL) == -1) {
1107 1108 mdb_warn("couldn't add buffered handler: %s\n",
1108 1109 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1109 1110 goto err;
1110 1111 }
1111 1112
1112 1113 if (dtrace_status(dtp) == -1) {
1113 1114 mdb_warn("couldn't get status: %s\n",
1114 1115 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1115 1116 goto err;
1116 1117 }
1117 1118
1118 1119 if (dtrace_aggregate_snap(dtp) == -1) {
1119 1120 mdb_warn("couldn't snapshot aggregation: %s\n",
1120 1121 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1121 1122 goto err;
1122 1123 }
1123 1124
1124 1125 if ((dd.dtdd_output = tmpfile()) == NULL) {
1125 1126 mdb_warn("couldn't open DTrace output file: %d\n", errno);
1126 1127 goto err;
1127 1128 }
1128 1129
1129 1130 if (dtrace_consume(dtp, dd.dtdd_output,
1130 1131 dtrace_dcmdprobe, dtrace_dcmdrec, &dd) == -1) {
1131 1132 mdb_warn("couldn't consume DTrace buffers: %s\n",
1132 1133 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1133 1134 }
1134 1135
1135 1136 if (dtrace_aggregate_print(dtp, NULL, NULL) == -1) {
1136 1137 mdb_warn("couldn't print aggregation: %s\n",
1137 1138 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1138 1139 goto err;
1139 1140 }
1140 1141
1141 1142 rval = DCMD_OK;
1142 1143 err:
1143 1144 dtrace_close(dtp);
1144 1145 fclose(dd.dtdd_output);
1145 1146 return (rval);
1146 1147 }
1147 1148
1148 1149 static int
1149 1150 dtrace_errhash_cmp(const void *l, const void *r)
1150 1151 {
1151 1152 uintptr_t lhs = *((uintptr_t *)l);
1152 1153 uintptr_t rhs = *((uintptr_t *)r);
1153 1154 dtrace_errhash_t lerr, rerr;
1154 1155 char lmsg[256], rmsg[256];
1155 1156
1156 1157 (void) mdb_vread(&lerr, sizeof (lerr), lhs);
1157 1158 (void) mdb_vread(&rerr, sizeof (rerr), rhs);
1158 1159
1159 1160 if (lerr.dter_msg == NULL)
1160 1161 return (-1);
1161 1162
1162 1163 if (rerr.dter_msg == NULL)
1163 1164 return (1);
1164 1165
1165 1166 (void) mdb_readstr(lmsg, sizeof (lmsg), (uintptr_t)lerr.dter_msg);
1166 1167 (void) mdb_readstr(rmsg, sizeof (rmsg), (uintptr_t)rerr.dter_msg);
1167 1168
1168 1169 return (strcmp(lmsg, rmsg));
1169 1170 }
1170 1171
1171 1172 int
1172 1173 dtrace_errhash_init(mdb_walk_state_t *wsp)
1173 1174 {
1174 1175 GElf_Sym sym;
1175 1176 uintptr_t *hash, addr;
1176 1177 int i;
1177 1178
1178 1179 if (wsp->walk_addr != NULL) {
1179 1180 mdb_warn("dtrace_errhash walk only supports global walks\n");
1180 1181 return (WALK_ERR);
1181 1182 }
1182 1183
1183 1184 if (mdb_lookup_by_name("dtrace_errhash", &sym) == -1) {
1184 1185 mdb_warn("couldn't find 'dtrace_errhash' (non-DEBUG kernel?)");
1185 1186 return (WALK_ERR);
1186 1187 }
1187 1188
1188 1189 addr = (uintptr_t)sym.st_value;
1189 1190 hash = mdb_alloc(DTRACE_ERRHASHSZ * sizeof (uintptr_t),
1190 1191 UM_SLEEP | UM_GC);
1191 1192
1192 1193 for (i = 0; i < DTRACE_ERRHASHSZ; i++)
1193 1194 hash[i] = addr + i * sizeof (dtrace_errhash_t);
1194 1195
1195 1196 qsort(hash, DTRACE_ERRHASHSZ, sizeof (uintptr_t), dtrace_errhash_cmp);
1196 1197
1197 1198 wsp->walk_addr = 0;
1198 1199 wsp->walk_data = hash;
1199 1200
1200 1201 return (WALK_NEXT);
1201 1202 }
1202 1203
1203 1204 int
1204 1205 dtrace_errhash_step(mdb_walk_state_t *wsp)
1205 1206 {
1206 1207 int ndx = (int)wsp->walk_addr;
1207 1208 uintptr_t *hash = wsp->walk_data;
1208 1209 dtrace_errhash_t err;
1209 1210 uintptr_t addr;
1210 1211
1211 1212 if (ndx >= DTRACE_ERRHASHSZ)
1212 1213 return (WALK_DONE);
1213 1214
1214 1215 wsp->walk_addr = ndx + 1;
1215 1216 addr = hash[ndx];
1216 1217
1217 1218 if (mdb_vread(&err, sizeof (err), addr) == -1) {
1218 1219 mdb_warn("failed to read dtrace_errhash_t at %p", addr);
1219 1220 return (WALK_DONE);
1220 1221 }
1221 1222
1222 1223 if (err.dter_msg == NULL)
1223 1224 return (WALK_NEXT);
1224 1225
1225 1226 return (wsp->walk_callback(addr, &err, wsp->walk_cbdata));
1226 1227 }
1227 1228
1228 1229 /*ARGSUSED*/
1229 1230 int
1230 1231 dtrace_errhash(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1231 1232 {
1232 1233 dtrace_errhash_t err;
1233 1234 char msg[256];
1234 1235
1235 1236 if (!(flags & DCMD_ADDRSPEC)) {
1236 1237 if (mdb_walk_dcmd("dtrace_errhash", "dtrace_errhash",
1237 1238 argc, argv) == -1) {
1238 1239 mdb_warn("can't walk 'dtrace_errhash'");
1239 1240 return (DCMD_ERR);
1240 1241 }
1241 1242
1242 1243 return (DCMD_OK);
1243 1244 }
1244 1245
1245 1246 if (DCMD_HDRSPEC(flags))
1246 1247 mdb_printf("%8s %s\n", "COUNT", "ERROR");
1247 1248
1248 1249 if (mdb_vread(&err, sizeof (err), addr) == -1) {
1249 1250 mdb_warn("failed to read dtrace_errhash_t at %p", addr);
1250 1251 return (DCMD_ERR);
1251 1252 }
1252 1253
1253 1254 addr = (uintptr_t)err.dter_msg;
1254 1255
1255 1256 if (mdb_readstr(msg, sizeof (msg), addr) == -1) {
1256 1257 mdb_warn("failed to read error msg at %p", addr);
1257 1258 return (DCMD_ERR);
1258 1259 }
1259 1260
1260 1261 mdb_printf("%8d %s", err.dter_count, msg);
1261 1262
1262 1263 /*
1263 1264 * Some error messages include a newline -- only print the newline
1264 1265 * if the message doesn't have one.
1265 1266 */
↓ open down ↓ |
1231 lines elided |
↑ open up ↑ |
1266 1267 if (msg[strlen(msg) - 1] != '\n')
1267 1268 mdb_printf("\n");
1268 1269
1269 1270 return (DCMD_OK);
1270 1271 }
1271 1272
1272 1273 int
1273 1274 dtrace_helptrace_init(mdb_walk_state_t *wsp)
1274 1275 {
1275 1276 uint32_t next;
1276 - int enabled;
1277 + uintptr_t buffer;
1277 1278
1278 1279 if (wsp->walk_addr != NULL) {
1279 1280 mdb_warn("dtrace_helptrace only supports global walks\n");
1280 1281 return (WALK_ERR);
1281 1282 }
1282 1283
1283 - if (mdb_readvar(&enabled, "dtrace_helptrace_enabled") == -1) {
1284 - mdb_warn("couldn't read 'dtrace_helptrace_enabled'");
1284 + if (mdb_readvar(&buffer, "dtrace_helptrace_buffer") == -1) {
1285 + mdb_warn("couldn't read 'dtrace_helptrace_buffer'");
1285 1286 return (WALK_ERR);
1286 1287 }
1287 1288
1288 - if (!enabled) {
1289 + if (buffer == NULL) {
1289 1290 mdb_warn("helper tracing is not enabled\n");
1290 1291 return (WALK_ERR);
1291 1292 }
1292 1293
1293 1294 if (mdb_readvar(&next, "dtrace_helptrace_next") == -1) {
1294 1295 mdb_warn("couldn't read 'dtrace_helptrace_next'");
1295 1296 return (WALK_ERR);
1296 1297 }
1297 1298
1298 1299 wsp->walk_addr = next;
1299 1300
1300 1301 return (WALK_NEXT);
1301 1302 }
1302 1303
1303 1304 int
1304 1305 dtrace_helptrace_step(mdb_walk_state_t *wsp)
1305 1306 {
1306 1307 uint32_t next, size, nlocals, bufsize;
1307 1308 uintptr_t buffer, addr;
1308 1309 dtrace_helptrace_t *ht;
1309 1310 int rval;
1310 1311
1311 1312 if (mdb_readvar(&next, "dtrace_helptrace_next") == -1) {
1312 1313 mdb_warn("couldn't read 'dtrace_helptrace_next'");
1313 1314 return (WALK_ERR);
1314 1315 }
1315 1316
1316 1317 if (mdb_readvar(&bufsize, "dtrace_helptrace_bufsize") == -1) {
1317 1318 mdb_warn("couldn't read 'dtrace_helptrace_bufsize'");
1318 1319 return (WALK_ERR);
1319 1320 }
1320 1321
1321 1322 if (mdb_readvar(&buffer, "dtrace_helptrace_buffer") == -1) {
1322 1323 mdb_warn("couldn't read 'dtrace_helptrace_buffer'");
1323 1324 return (WALK_ERR);
1324 1325 }
1325 1326
1326 1327 if (mdb_readvar(&nlocals, "dtrace_helptrace_nlocals") == -1) {
1327 1328 mdb_warn("couldn't read 'dtrace_helptrace_nlocals'");
1328 1329 return (WALK_ERR);
1329 1330 }
1330 1331
1331 1332 size = sizeof (dtrace_helptrace_t) +
1332 1333 nlocals * sizeof (uint64_t) - sizeof (uint64_t);
1333 1334
1334 1335 if (wsp->walk_addr + size > bufsize) {
1335 1336 if (next == 0)
1336 1337 return (WALK_DONE);
1337 1338
1338 1339 wsp->walk_addr = 0;
1339 1340 }
1340 1341
1341 1342 addr = buffer + wsp->walk_addr;
1342 1343 ht = alloca(size);
1343 1344
1344 1345 if (mdb_vread(ht, size, addr) == -1) {
1345 1346 mdb_warn("couldn't read entry at %p", addr);
1346 1347 return (WALK_ERR);
1347 1348 }
1348 1349
1349 1350 if (ht->dtht_helper != NULL) {
1350 1351 rval = wsp->walk_callback(addr, ht, wsp->walk_cbdata);
1351 1352
1352 1353 if (rval != WALK_NEXT)
1353 1354 return (rval);
1354 1355 }
1355 1356
1356 1357 if (wsp->walk_addr < next && wsp->walk_addr + size >= next)
1357 1358 return (WALK_DONE);
1358 1359
1359 1360 wsp->walk_addr += size;
1360 1361 return (WALK_NEXT);
1361 1362 }
1362 1363
1363 1364 int
1364 1365 dtrace_helptrace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1365 1366 {
1366 1367 dtrace_helptrace_t help;
1367 1368 dtrace_helper_action_t helper;
1368 1369 char where[30];
1369 1370 uint_t opt_v = FALSE;
1370 1371 uintptr_t haddr;
1371 1372
1372 1373 if (!(flags & DCMD_ADDRSPEC)) {
1373 1374 if (mdb_walk_dcmd("dtrace_helptrace", "dtrace_helptrace",
1374 1375 argc, argv) == -1) {
1375 1376 mdb_warn("can't walk 'dtrace_helptrace'");
1376 1377 return (DCMD_ERR);
1377 1378 }
1378 1379
1379 1380 return (DCMD_OK);
1380 1381 }
1381 1382
1382 1383 if (mdb_getopts(argc, argv, 'v',
1383 1384 MDB_OPT_SETBITS, TRUE, &opt_v, NULL) != argc)
1384 1385 return (DCMD_USAGE);
1385 1386
1386 1387 if (DCMD_HDRSPEC(flags)) {
1387 1388 mdb_printf(" %?s %?s %12s %s\n",
1388 1389 "ADDR", "HELPER", "WHERE", "DIFO");
1389 1390 }
1390 1391
1391 1392 if (mdb_vread(&help, sizeof (help), addr) == -1) {
1392 1393 mdb_warn("failed to read dtrace_helptrace_t at %p", addr);
1393 1394 return (DCMD_ERR);
1394 1395 }
1395 1396
1396 1397 switch (help.dtht_where) {
1397 1398 case 0:
1398 1399 (void) mdb_snprintf(where, sizeof (where), "predicate");
1399 1400 break;
1400 1401
1401 1402 case DTRACE_HELPTRACE_NEXT:
1402 1403 (void) mdb_snprintf(where, sizeof (where), "next");
1403 1404 break;
1404 1405
1405 1406 case DTRACE_HELPTRACE_DONE:
1406 1407 (void) mdb_snprintf(where, sizeof (where), "done");
1407 1408 break;
1408 1409
1409 1410 case DTRACE_HELPTRACE_ERR:
1410 1411 (void) mdb_snprintf(where, sizeof (where), "err");
1411 1412 break;
1412 1413
1413 1414 default:
1414 1415 (void) mdb_snprintf(where, sizeof (where),
1415 1416 "action #%d", help.dtht_where);
1416 1417 break;
1417 1418 }
1418 1419
1419 1420 mdb_printf(" %?p %?p %12s ", addr, help.dtht_helper, where);
1420 1421
1421 1422 haddr = (uintptr_t)help.dtht_helper;
1422 1423
1423 1424 if (mdb_vread(&helper, sizeof (helper), haddr) == -1) {
1424 1425 /*
1425 1426 * We're not going to warn in this case -- we're just not going
1426 1427 * to print anything exciting.
1427 1428 */
1428 1429 mdb_printf("???\n");
1429 1430 } else {
1430 1431 switch (help.dtht_where) {
1431 1432 case 0:
1432 1433 mdb_printf("%p\n", helper.dtha_predicate);
1433 1434 break;
1434 1435
1435 1436 case DTRACE_HELPTRACE_NEXT:
1436 1437 case DTRACE_HELPTRACE_DONE:
1437 1438 case DTRACE_HELPTRACE_ERR:
1438 1439 mdb_printf("-\n");
1439 1440 break;
1440 1441
1441 1442 default:
1442 1443 haddr = (uintptr_t)helper.dtha_actions +
1443 1444 (help.dtht_where - 1) * sizeof (uintptr_t);
1444 1445
1445 1446 if (mdb_vread(&haddr, sizeof (haddr), haddr) == -1) {
1446 1447 mdb_printf("???\n");
1447 1448 } else {
1448 1449 mdb_printf("%p\n", haddr);
1449 1450 }
1450 1451 }
1451 1452 }
1452 1453
1453 1454 if (opt_v) {
1454 1455 int i;
1455 1456
1456 1457 if (help.dtht_where == DTRACE_HELPTRACE_ERR) {
1457 1458 int f = help.dtht_fault;
1458 1459
1459 1460 mdb_printf("%?s| %?s %10s |\n", "", "", "");
1460 1461 mdb_printf("%?s| %?s %10s +-> fault: %s\n", "", "", "",
1461 1462 f == DTRACEFLT_BADADDR ? "BADADDR" :
1462 1463 f == DTRACEFLT_BADALIGN ? "BADALIGN" :
1463 1464 f == DTRACEFLT_ILLOP ? "ILLOP" :
1464 1465 f == DTRACEFLT_DIVZERO ? "DIVZERO" :
1465 1466 f == DTRACEFLT_NOSCRATCH ? "NOSCRATCH" :
1466 1467 f == DTRACEFLT_KPRIV ? "KPRIV" :
1467 1468 f == DTRACEFLT_UPRIV ? "UPRIV" :
1468 1469 f == DTRACEFLT_TUPOFLOW ? "TUPOFLOW" :
1469 1470 f == DTRACEFLT_BADSTACK ? "BADSTACK" :
1470 1471 "DTRACEFLT_UNKNOWN");
1471 1472 mdb_printf("%?s| %?s %12s addr: 0x%x\n", "", "", "",
1472 1473 help.dtht_illval);
1473 1474 mdb_printf("%?s| %?s %12s offset: %d\n", "", "", "",
1474 1475 help.dtht_fltoffs);
1475 1476 }
1476 1477
1477 1478 mdb_printf("%?s|\n%?s+--> %?s %4s %s\n", "", "",
1478 1479 "ADDR", "NDX", "VALUE");
1479 1480 addr += sizeof (help) - sizeof (uint64_t);
1480 1481
1481 1482 for (i = 0; i < help.dtht_nlocals; i++) {
1482 1483 uint64_t val;
1483 1484
1484 1485 if (mdb_vread(&val, sizeof (val), addr) == -1) {
1485 1486 mdb_warn("couldn't read local at %p", addr);
1486 1487 continue;
1487 1488 }
1488 1489
1489 1490 mdb_printf("%?s %?p %4d %p\n", "", addr, i, val);
1490 1491 addr += sizeof (uint64_t);
1491 1492 }
1492 1493
1493 1494 mdb_printf("\n");
1494 1495 }
1495 1496
1496 1497 return (DCMD_OK);
1497 1498 }
1498 1499
1499 1500 /*ARGSUSED*/
1500 1501 static int
1501 1502 dtrace_state_walk(uintptr_t addr, const vmem_seg_t *seg, minor_t *highest)
1502 1503 {
1503 1504 if (seg->vs_end > *highest)
1504 1505 *highest = seg->vs_end;
1505 1506
1506 1507 return (WALK_NEXT);
1507 1508 }
1508 1509
1509 1510 typedef struct dtrace_state_walk {
1510 1511 uintptr_t dtsw_softstate;
1511 1512 minor_t dtsw_max;
1512 1513 minor_t dtsw_current;
1513 1514 } dtrace_state_walk_t;
1514 1515
1515 1516 int
1516 1517 dtrace_state_init(mdb_walk_state_t *wsp)
1517 1518 {
1518 1519 uintptr_t dtrace_minor;
1519 1520 minor_t max = 0;
1520 1521 dtrace_state_walk_t *dw;
1521 1522
1522 1523 if (wsp->walk_addr != NULL) {
1523 1524 mdb_warn("dtrace_state only supports global walks\n");
1524 1525 return (WALK_ERR);
1525 1526 }
1526 1527
1527 1528 /*
1528 1529 * Find the dtrace_minor vmem arena and walk it to get the maximum
1529 1530 * minor number.
1530 1531 */
1531 1532 if (mdb_readvar(&dtrace_minor, "dtrace_minor") == -1) {
1532 1533 mdb_warn("failed to read 'dtrace_minor'");
1533 1534 return (WALK_ERR);
1534 1535 }
1535 1536
1536 1537 if (mdb_pwalk("vmem_alloc", (mdb_walk_cb_t)dtrace_state_walk,
1537 1538 &max, dtrace_minor) == -1) {
1538 1539 mdb_warn("couldn't walk 'vmem_alloc'");
1539 1540 return (WALK_ERR);
1540 1541 }
1541 1542
1542 1543 dw = mdb_zalloc(sizeof (dtrace_state_walk_t), UM_SLEEP | UM_GC);
1543 1544 dw->dtsw_current = 0;
1544 1545 dw->dtsw_max = max;
1545 1546
1546 1547 if (mdb_readvar(&dw->dtsw_softstate, "dtrace_softstate") == -1) {
1547 1548 mdb_warn("failed to read 'dtrace_softstate'");
1548 1549 return (DCMD_ERR);
1549 1550 }
1550 1551
1551 1552 wsp->walk_data = dw;
1552 1553
1553 1554 return (WALK_NEXT);
1554 1555 }
1555 1556
1556 1557 int
1557 1558 dtrace_state_step(mdb_walk_state_t *wsp)
1558 1559 {
1559 1560 dtrace_state_walk_t *dw = wsp->walk_data;
1560 1561 uintptr_t statep;
1561 1562 dtrace_state_t state;
1562 1563 int rval;
1563 1564
1564 1565 while (mdb_get_soft_state_byaddr(dw->dtsw_softstate, dw->dtsw_current,
1565 1566 &statep, NULL, 0) == -1) {
1566 1567 if (dw->dtsw_current >= dw->dtsw_max)
1567 1568 return (WALK_DONE);
1568 1569
1569 1570 dw->dtsw_current++;
1570 1571 }
1571 1572
1572 1573 if (mdb_vread(&state, sizeof (state), statep) == -1) {
1573 1574 mdb_warn("couldn't read dtrace_state_t at %p", statep);
1574 1575 return (WALK_NEXT);
1575 1576 }
1576 1577
1577 1578 rval = wsp->walk_callback(statep, &state, wsp->walk_cbdata);
1578 1579 dw->dtsw_current++;
1579 1580
1580 1581 return (rval);
1581 1582 }
1582 1583
1583 1584 typedef struct dtrace_state_data {
1584 1585 int dtsd_major;
1585 1586 uintptr_t dtsd_proc;
1586 1587 uintptr_t dtsd_softstate;
1587 1588 uintptr_t dtsd_state;
1588 1589 } dtrace_state_data_t;
1589 1590
1590 1591 static int
1591 1592 dtrace_state_file(uintptr_t addr, struct file *f, dtrace_state_data_t *data)
1592 1593 {
1593 1594 vnode_t vnode;
1594 1595 proc_t proc;
1595 1596 minor_t minor;
1596 1597 uintptr_t statep;
1597 1598
1598 1599 if (mdb_vread(&vnode, sizeof (vnode), (uintptr_t)f->f_vnode) == -1) {
1599 1600 mdb_warn("couldn't read vnode at %p", (uintptr_t)f->f_vnode);
1600 1601 return (WALK_NEXT);
1601 1602 }
1602 1603
1603 1604 if (getmajor(vnode.v_rdev) != data->dtsd_major)
1604 1605 return (WALK_NEXT);
1605 1606
1606 1607 minor = getminor(vnode.v_rdev);
1607 1608
1608 1609 if (mdb_vread(&proc, sizeof (proc), data->dtsd_proc) == -1) {
1609 1610 mdb_warn("failed to read proc at %p", data->dtsd_proc);
1610 1611 return (WALK_NEXT);
1611 1612 }
1612 1613
1613 1614 if (mdb_get_soft_state_byaddr(data->dtsd_softstate, minor,
1614 1615 &statep, NULL, 0) == -1) {
1615 1616 mdb_warn("failed to read softstate for minor %d", minor);
1616 1617 return (WALK_NEXT);
1617 1618 }
1618 1619
1619 1620 if (statep != data->dtsd_state)
1620 1621 return (WALK_NEXT);
1621 1622
1622 1623 mdb_printf("%?p %5d %?p %-*s %?p\n", statep, minor,
1623 1624 data->dtsd_proc, MAXCOMLEN, proc.p_user.u_comm, addr);
1624 1625
1625 1626 return (WALK_NEXT);
1626 1627 }
1627 1628
1628 1629 /*ARGSUSED*/
1629 1630 static int
1630 1631 dtrace_state_proc(uintptr_t addr, void *ignored, dtrace_state_data_t *data)
1631 1632 {
1632 1633 data->dtsd_proc = addr;
1633 1634
1634 1635 if (mdb_pwalk("file",
1635 1636 (mdb_walk_cb_t)dtrace_state_file, data, addr) == -1) {
1636 1637 mdb_warn("couldn't walk 'file' for proc %p", addr);
1637 1638 return (WALK_ERR);
1638 1639 }
1639 1640
1640 1641 return (WALK_NEXT);
1641 1642 }
1642 1643
1643 1644 void
1644 1645 dtrace_state_help(void)
1645 1646 {
1646 1647 mdb_printf("Given a dtrace_state_t structure, displays all "
1647 1648 /*CSTYLED*/
1648 1649 "consumers, or \"<anonymous>\"\nif the consumer is anonymous. If "
1649 1650 "no state structure is provided, iterates\nover all state "
1650 1651 "structures.\n\n"
1651 1652 "Addresses in ADDR column may be provided to ::dtrace to obtain\n"
1652 1653 "dtrace(1M)-like output for in-kernel DTrace data.\n");
1653 1654 }
1654 1655
1655 1656 int
1656 1657 dtrace_state(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1657 1658 {
1658 1659 uintptr_t devi;
1659 1660 struct dev_info info;
1660 1661 dtrace_state_data_t data;
1661 1662 dtrace_anon_t anon;
1662 1663 dtrace_state_t state;
1663 1664
1664 1665 if (!(flags & DCMD_ADDRSPEC)) {
1665 1666 if (mdb_walk_dcmd("dtrace_state",
1666 1667 "dtrace_state", argc, argv) == -1) {
1667 1668 mdb_warn("can't walk dtrace_state");
1668 1669 return (DCMD_ERR);
1669 1670 }
1670 1671 return (DCMD_OK);
1671 1672 }
1672 1673
1673 1674 if (DCMD_HDRSPEC(flags)) {
1674 1675 mdb_printf("%?s %5s %?s %-*s %?s\n", "ADDR", "MINOR", "PROC",
1675 1676 MAXCOMLEN, "NAME", "FILE");
1676 1677 }
1677 1678
1678 1679 /*
1679 1680 * First determine if this is anonymous state.
1680 1681 */
1681 1682 if (mdb_readvar(&anon, "dtrace_anon") == -1) {
1682 1683 mdb_warn("failed to read 'dtrace_anon'");
1683 1684 return (DCMD_ERR);
1684 1685 }
1685 1686
1686 1687 if ((uintptr_t)anon.dta_state == addr) {
1687 1688 if (mdb_vread(&state, sizeof (state), addr) == -1) {
1688 1689 mdb_warn("failed to read anon at %p", addr);
1689 1690 return (DCMD_ERR);
1690 1691 }
1691 1692
1692 1693 mdb_printf("%?p %5d %?s %-*s %?s\n", addr,
1693 1694 getminor(state.dts_dev), "-", MAXCOMLEN,
1694 1695 "<anonymous>", "-");
1695 1696
1696 1697 return (DCMD_OK);
1697 1698 }
1698 1699
1699 1700 if (mdb_readvar(&devi, "dtrace_devi") == -1) {
1700 1701 mdb_warn("failed to read 'dtrace_devi'");
1701 1702 return (DCMD_ERR);
1702 1703 }
1703 1704
1704 1705 if (mdb_vread(&info, sizeof (struct dev_info), devi) == -1) {
1705 1706 mdb_warn("failed to read 'dev_info'");
1706 1707 return (DCMD_ERR);
1707 1708 }
1708 1709
1709 1710 data.dtsd_major = info.devi_major;
1710 1711
1711 1712 if (mdb_readvar(&data.dtsd_softstate, "dtrace_softstate") == -1) {
1712 1713 mdb_warn("failed to read 'dtrace_softstate'");
1713 1714 return (DCMD_ERR);
1714 1715 }
1715 1716
1716 1717 data.dtsd_state = addr;
1717 1718
1718 1719 /*
1719 1720 * Walk through all processes and all open files looking for this
1720 1721 * state. It must be open somewhere...
1721 1722 */
1722 1723 if (mdb_walk("proc", (mdb_walk_cb_t)dtrace_state_proc, &data) == -1) {
1723 1724 mdb_warn("couldn't walk 'proc'");
1724 1725 return (DCMD_ERR);
1725 1726 }
1726 1727
1727 1728 return (DCMD_OK);
1728 1729 }
1729 1730
1730 1731 typedef struct dtrace_aggkey_data {
1731 1732 uintptr_t *dtakd_hash;
1732 1733 uintptr_t dtakd_hashsize;
1733 1734 uintptr_t dtakd_next;
1734 1735 uintptr_t dtakd_ndx;
1735 1736 } dtrace_aggkey_data_t;
1736 1737
1737 1738 int
1738 1739 dtrace_aggkey_init(mdb_walk_state_t *wsp)
1739 1740 {
1740 1741 dtrace_buffer_t buf;
1741 1742 uintptr_t addr;
1742 1743 dtrace_aggbuffer_t agb;
1743 1744 dtrace_aggkey_data_t *data;
1744 1745 size_t hsize;
1745 1746
1746 1747 if ((addr = wsp->walk_addr) == NULL) {
1747 1748 mdb_warn("dtrace_aggkey walk needs aggregation buffer\n");
1748 1749 return (WALK_ERR);
1749 1750 }
1750 1751
1751 1752 if (mdb_vread(&buf, sizeof (buf), addr) == -1) {
1752 1753 mdb_warn("failed to read aggregation buffer at %p", addr);
1753 1754 return (WALK_ERR);
1754 1755 }
1755 1756
1756 1757 addr = (uintptr_t)buf.dtb_tomax +
1757 1758 buf.dtb_size - sizeof (dtrace_aggbuffer_t);
1758 1759
1759 1760 if (mdb_vread(&agb, sizeof (agb), addr) == -1) {
1760 1761 mdb_warn("failed to read dtrace_aggbuffer_t at %p", addr);
1761 1762 return (WALK_ERR);
1762 1763 }
1763 1764
1764 1765 data = mdb_zalloc(sizeof (dtrace_aggkey_data_t), UM_SLEEP);
1765 1766
1766 1767 data->dtakd_hashsize = agb.dtagb_hashsize;
1767 1768 hsize = agb.dtagb_hashsize * sizeof (dtrace_aggkey_t *);
1768 1769 data->dtakd_hash = mdb_alloc(hsize, UM_SLEEP);
1769 1770
1770 1771 if (mdb_vread(data->dtakd_hash, hsize,
1771 1772 (uintptr_t)agb.dtagb_hash) == -1) {
1772 1773 mdb_warn("failed to read hash at %p",
1773 1774 (uintptr_t)agb.dtagb_hash);
1774 1775 mdb_free(data->dtakd_hash, hsize);
1775 1776 mdb_free(data, sizeof (dtrace_aggkey_data_t));
1776 1777 return (WALK_ERR);
1777 1778 }
1778 1779
1779 1780 wsp->walk_data = data;
1780 1781 return (WALK_NEXT);
1781 1782 }
1782 1783
1783 1784 int
1784 1785 dtrace_aggkey_step(mdb_walk_state_t *wsp)
1785 1786 {
1786 1787 dtrace_aggkey_data_t *data = wsp->walk_data;
1787 1788 dtrace_aggkey_t key;
1788 1789 uintptr_t addr;
1789 1790
1790 1791 while ((addr = data->dtakd_next) == NULL) {
1791 1792 if (data->dtakd_ndx == data->dtakd_hashsize)
1792 1793 return (WALK_DONE);
1793 1794
1794 1795 data->dtakd_next = data->dtakd_hash[data->dtakd_ndx++];
1795 1796 }
1796 1797
1797 1798 if (mdb_vread(&key, sizeof (key), addr) == -1) {
1798 1799 mdb_warn("failed to read dtrace_aggkey_t at %p", addr);
1799 1800 return (WALK_ERR);
1800 1801 }
1801 1802
1802 1803 data->dtakd_next = (uintptr_t)key.dtak_next;
1803 1804
1804 1805 return (wsp->walk_callback(addr, &key, wsp->walk_cbdata));
1805 1806 }
1806 1807
1807 1808 void
1808 1809 dtrace_aggkey_fini(mdb_walk_state_t *wsp)
1809 1810 {
1810 1811 dtrace_aggkey_data_t *data = wsp->walk_data;
1811 1812 size_t hsize;
1812 1813
1813 1814 hsize = data->dtakd_hashsize * sizeof (dtrace_aggkey_t *);
1814 1815 mdb_free(data->dtakd_hash, hsize);
1815 1816 mdb_free(data, sizeof (dtrace_aggkey_data_t));
1816 1817 }
1817 1818
1818 1819 typedef struct dtrace_dynvar_data {
1819 1820 dtrace_dynhash_t *dtdvd_hash;
1820 1821 uintptr_t dtdvd_hashsize;
1821 1822 uintptr_t dtdvd_next;
1822 1823 uintptr_t dtdvd_ndx;
1823 1824 uintptr_t dtdvd_sink;
1824 1825 } dtrace_dynvar_data_t;
1825 1826
1826 1827 int
1827 1828 dtrace_dynvar_init(mdb_walk_state_t *wsp)
1828 1829 {
1829 1830 uintptr_t addr;
1830 1831 dtrace_dstate_t dstate;
1831 1832 dtrace_dynvar_data_t *data;
1832 1833 size_t hsize;
1833 1834 GElf_Sym sym;
1834 1835
1835 1836 if ((addr = wsp->walk_addr) == NULL) {
1836 1837 mdb_warn("dtrace_dynvar walk needs dtrace_dstate_t\n");
1837 1838 return (WALK_ERR);
1838 1839 }
1839 1840
1840 1841 if (mdb_vread(&dstate, sizeof (dstate), addr) == -1) {
1841 1842 mdb_warn("failed to read dynamic state at %p", addr);
1842 1843 return (WALK_ERR);
1843 1844 }
1844 1845
1845 1846 if (mdb_lookup_by_name("dtrace_dynhash_sink", &sym) == -1) {
1846 1847 mdb_warn("couldn't find 'dtrace_dynhash_sink'");
1847 1848 return (WALK_ERR);
1848 1849 }
1849 1850
1850 1851 data = mdb_zalloc(sizeof (dtrace_dynvar_data_t), UM_SLEEP);
1851 1852
1852 1853 data->dtdvd_hashsize = dstate.dtds_hashsize;
1853 1854 hsize = dstate.dtds_hashsize * sizeof (dtrace_dynhash_t);
1854 1855 data->dtdvd_hash = mdb_alloc(hsize, UM_SLEEP);
1855 1856 data->dtdvd_sink = (uintptr_t)sym.st_value;
1856 1857
1857 1858 if (mdb_vread(data->dtdvd_hash, hsize,
1858 1859 (uintptr_t)dstate.dtds_hash) == -1) {
1859 1860 mdb_warn("failed to read hash at %p",
1860 1861 (uintptr_t)dstate.dtds_hash);
1861 1862 mdb_free(data->dtdvd_hash, hsize);
1862 1863 mdb_free(data, sizeof (dtrace_dynvar_data_t));
1863 1864 return (WALK_ERR);
1864 1865 }
1865 1866
1866 1867 data->dtdvd_next = (uintptr_t)data->dtdvd_hash[0].dtdh_chain;
1867 1868
1868 1869 wsp->walk_data = data;
1869 1870 return (WALK_NEXT);
1870 1871 }
1871 1872
1872 1873 int
1873 1874 dtrace_dynvar_step(mdb_walk_state_t *wsp)
1874 1875 {
1875 1876 dtrace_dynvar_data_t *data = wsp->walk_data;
1876 1877 dtrace_dynvar_t dynvar, *dvar;
1877 1878 size_t dvarsize;
1878 1879 uintptr_t addr;
1879 1880 int nkeys;
1880 1881
1881 1882 while ((addr = data->dtdvd_next) == data->dtdvd_sink) {
1882 1883 if (data->dtdvd_ndx == data->dtdvd_hashsize)
1883 1884 return (WALK_DONE);
1884 1885
1885 1886 data->dtdvd_next =
1886 1887 (uintptr_t)data->dtdvd_hash[data->dtdvd_ndx++].dtdh_chain;
1887 1888 }
1888 1889
1889 1890 if (mdb_vread(&dynvar, sizeof (dynvar), addr) == -1) {
1890 1891 mdb_warn("failed to read dtrace_dynvar_t at %p", addr);
1891 1892 return (WALK_ERR);
1892 1893 }
1893 1894
1894 1895 /*
1895 1896 * Now we need to allocate the correct size.
1896 1897 */
1897 1898 nkeys = dynvar.dtdv_tuple.dtt_nkeys;
1898 1899 dvarsize = (uintptr_t)&dynvar.dtdv_tuple.dtt_key[nkeys] -
1899 1900 (uintptr_t)&dynvar;
1900 1901
1901 1902 dvar = alloca(dvarsize);
1902 1903
1903 1904 if (mdb_vread(dvar, dvarsize, addr) == -1) {
1904 1905 mdb_warn("failed to read dtrace_dynvar_t at %p", addr);
1905 1906 return (WALK_ERR);
1906 1907 }
1907 1908
1908 1909 data->dtdvd_next = (uintptr_t)dynvar.dtdv_next;
1909 1910
1910 1911 return (wsp->walk_callback(addr, dvar, wsp->walk_cbdata));
1911 1912 }
1912 1913
1913 1914 void
1914 1915 dtrace_dynvar_fini(mdb_walk_state_t *wsp)
1915 1916 {
1916 1917 dtrace_dynvar_data_t *data = wsp->walk_data;
1917 1918 size_t hsize;
1918 1919
1919 1920 hsize = data->dtdvd_hashsize * sizeof (dtrace_dynvar_t *);
1920 1921 mdb_free(data->dtdvd_hash, hsize);
1921 1922 mdb_free(data, sizeof (dtrace_dynvar_data_t));
1922 1923 }
1923 1924
1924 1925 typedef struct dtrace_hashstat_data {
1925 1926 size_t *dthsd_counts;
1926 1927 size_t dthsd_hashsize;
1927 1928 char *dthsd_data;
1928 1929 size_t dthsd_size;
1929 1930 int dthsd_header;
1930 1931 } dtrace_hashstat_data_t;
1931 1932
1932 1933 typedef void (*dtrace_hashstat_func_t)(dtrace_hashstat_data_t *);
1933 1934
1934 1935 static void
1935 1936 dtrace_hashstat_additive(dtrace_hashstat_data_t *data)
1936 1937 {
1937 1938 int i;
1938 1939 int hval = 0;
1939 1940
1940 1941 for (i = 0; i < data->dthsd_size; i++)
1941 1942 hval += data->dthsd_data[i];
1942 1943
1943 1944 data->dthsd_counts[hval % data->dthsd_hashsize]++;
1944 1945 }
1945 1946
1946 1947 static void
1947 1948 dtrace_hashstat_shifty(dtrace_hashstat_data_t *data)
1948 1949 {
1949 1950 uint64_t hval = 0;
1950 1951 int i;
1951 1952
1952 1953 if (data->dthsd_size < sizeof (uint64_t)) {
1953 1954 dtrace_hashstat_additive(data);
1954 1955 return;
1955 1956 }
1956 1957
1957 1958 for (i = 0; i < data->dthsd_size; i += sizeof (uint64_t)) {
1958 1959 /* LINTED - alignment */
1959 1960 uint64_t val = *((uint64_t *)&data->dthsd_data[i]);
1960 1961
1961 1962 hval += (val & ((1 << NBBY) - 1)) +
1962 1963 ((val >> NBBY) & ((1 << NBBY) - 1)) +
1963 1964 ((val >> (NBBY << 1)) & ((1 << NBBY) - 1)) +
1964 1965 ((val >> (NBBY << 2)) & ((1 << NBBY) - 1)) +
1965 1966 (val & USHRT_MAX) + (val >> (NBBY << 1) & USHRT_MAX);
1966 1967 }
1967 1968
1968 1969 data->dthsd_counts[hval % data->dthsd_hashsize]++;
1969 1970 }
1970 1971
1971 1972 static void
1972 1973 dtrace_hashstat_knuth(dtrace_hashstat_data_t *data)
1973 1974 {
1974 1975 int i;
1975 1976 int hval = data->dthsd_size;
1976 1977
1977 1978 for (i = 0; i < data->dthsd_size; i++)
1978 1979 hval = (hval << 4) ^ (hval >> 28) ^ data->dthsd_data[i];
1979 1980
1980 1981 data->dthsd_counts[hval % data->dthsd_hashsize]++;
1981 1982 }
1982 1983
1983 1984 static void
1984 1985 dtrace_hashstat_oneatatime(dtrace_hashstat_data_t *data)
1985 1986 {
1986 1987 int i;
1987 1988 uint32_t hval = 0;
1988 1989
1989 1990 for (i = 0; i < data->dthsd_size; i++) {
1990 1991 hval += data->dthsd_data[i];
1991 1992 hval += (hval << 10);
1992 1993 hval ^= (hval >> 6);
1993 1994 }
1994 1995
1995 1996 hval += (hval << 3);
1996 1997 hval ^= (hval >> 11);
1997 1998 hval += (hval << 15);
1998 1999
1999 2000 data->dthsd_counts[hval % data->dthsd_hashsize]++;
2000 2001 }
2001 2002
2002 2003 static void
2003 2004 dtrace_hashstat_fnv(dtrace_hashstat_data_t *data)
2004 2005 {
2005 2006 static const uint32_t prime = 0x01000193;
2006 2007 uint32_t hval = 0;
2007 2008 int i;
2008 2009
2009 2010 for (i = 0; i < data->dthsd_size; i++) {
2010 2011 hval *= prime;
2011 2012 hval ^= data->dthsd_data[i];
2012 2013 }
2013 2014
2014 2015 data->dthsd_counts[hval % data->dthsd_hashsize]++;
2015 2016 }
2016 2017
2017 2018 static void
2018 2019 dtrace_hashstat_stats(char *name, dtrace_hashstat_data_t *data)
2019 2020 {
2020 2021 size_t nz = 0, i;
2021 2022 int longest = 0;
2022 2023 size_t ttl = 0;
2023 2024 double sum = 0.0;
2024 2025 double avg;
2025 2026 uint_t util, stddev;
2026 2027
2027 2028 if (!data->dthsd_header) {
2028 2029 mdb_printf("%15s %11s %11s %11s %11s %11s\n", "NAME",
2029 2030 "HASHSIZE", "%UTIL", "LONGEST", "AVERAGE", "STDDEV");
2030 2031 data->dthsd_header = 1;
2031 2032 }
2032 2033
2033 2034 for (i = 0; i < data->dthsd_hashsize; i++) {
2034 2035 if (data->dthsd_counts[i] != 0) {
2035 2036 nz++;
2036 2037
2037 2038 if (data->dthsd_counts[i] > longest)
2038 2039 longest = data->dthsd_counts[i];
2039 2040
2040 2041 ttl += data->dthsd_counts[i];
2041 2042 }
2042 2043 }
2043 2044
2044 2045 if (nz == 0) {
2045 2046 mdb_printf("%15s %11d %11s %11s %11s %11s\n", name,
2046 2047 data->dthsd_hashsize, "-", "-", "-", "-");
2047 2048 return;
2048 2049 }
2049 2050
2050 2051 avg = (double)ttl / (double)nz;
2051 2052
2052 2053 for (i = 0; i < data->dthsd_hashsize; i++) {
2053 2054 double delta = (double)data->dthsd_counts[i] - avg;
2054 2055
2055 2056 if (data->dthsd_counts[i] == 0)
2056 2057 continue;
2057 2058
2058 2059 sum += delta * delta;
2059 2060 }
2060 2061
2061 2062 util = (nz * 1000) / data->dthsd_hashsize;
2062 2063 stddev = (uint_t)sqrt(sum / (double)nz) * 10;
2063 2064
2064 2065 mdb_printf("%15s %11d %9u.%1u %11d %11d %9u.%1u\n", name,
2065 2066 data->dthsd_hashsize, util / 10, util % 10, longest, ttl / nz,
2066 2067 stddev / 10, stddev % 10);
2067 2068 }
2068 2069
2069 2070 static struct dtrace_hashstat {
2070 2071 char *dths_name;
2071 2072 dtrace_hashstat_func_t dths_func;
2072 2073 } _dtrace_hashstat[] = {
2073 2074 { "<actual>", NULL },
2074 2075 { "additive", dtrace_hashstat_additive },
2075 2076 { "shifty", dtrace_hashstat_shifty },
2076 2077 { "knuth", dtrace_hashstat_knuth },
2077 2078 { "one-at-a-time", dtrace_hashstat_oneatatime },
2078 2079 { "fnv", dtrace_hashstat_fnv },
2079 2080 { NULL, 0 }
2080 2081 };
2081 2082
2082 2083 typedef struct dtrace_aggstat_data {
2083 2084 dtrace_hashstat_data_t dtagsd_hash;
2084 2085 dtrace_hashstat_func_t dtagsd_func;
2085 2086 } dtrace_aggstat_data_t;
2086 2087
2087 2088 static int
2088 2089 dtrace_aggstat_walk(uintptr_t addr, dtrace_aggkey_t *key,
2089 2090 dtrace_aggstat_data_t *data)
2090 2091 {
2091 2092 dtrace_hashstat_data_t *hdata = &data->dtagsd_hash;
2092 2093 size_t size;
2093 2094
2094 2095 if (data->dtagsd_func == NULL) {
2095 2096 size_t bucket = key->dtak_hashval % hdata->dthsd_hashsize;
2096 2097
2097 2098 hdata->dthsd_counts[bucket]++;
2098 2099 return (WALK_NEXT);
2099 2100 }
2100 2101
2101 2102 /*
2102 2103 * We need to read the data.
2103 2104 */
2104 2105 size = key->dtak_size - sizeof (dtrace_aggid_t);
2105 2106 addr = (uintptr_t)key->dtak_data + sizeof (dtrace_aggid_t);
2106 2107 hdata->dthsd_data = alloca(size);
2107 2108 hdata->dthsd_size = size;
2108 2109
2109 2110 if (mdb_vread(hdata->dthsd_data, size, addr) == -1) {
2110 2111 mdb_warn("couldn't read data at %p", addr);
2111 2112 return (WALK_ERR);
2112 2113 }
2113 2114
2114 2115 data->dtagsd_func(hdata);
2115 2116
2116 2117 return (WALK_NEXT);
2117 2118 }
2118 2119
2119 2120 /*ARGSUSED*/
2120 2121 int
2121 2122 dtrace_aggstat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2122 2123 {
2123 2124 dtrace_buffer_t buf;
2124 2125 uintptr_t aaddr;
2125 2126 dtrace_aggbuffer_t agb;
2126 2127 size_t hsize, i, actual, prime, evenpow;
2127 2128 dtrace_aggstat_data_t data;
2128 2129 dtrace_hashstat_data_t *hdata = &data.dtagsd_hash;
2129 2130
2130 2131 bzero(&data, sizeof (data));
2131 2132
2132 2133 if (!(flags & DCMD_ADDRSPEC))
2133 2134 return (DCMD_USAGE);
2134 2135
2135 2136 if (mdb_vread(&buf, sizeof (buf), addr) == -1) {
2136 2137 mdb_warn("failed to read aggregation buffer at %p", addr);
2137 2138 return (DCMD_ERR);
2138 2139 }
2139 2140
2140 2141 aaddr = (uintptr_t)buf.dtb_tomax +
2141 2142 buf.dtb_size - sizeof (dtrace_aggbuffer_t);
2142 2143
2143 2144 if (mdb_vread(&agb, sizeof (agb), aaddr) == -1) {
2144 2145 mdb_warn("failed to read dtrace_aggbuffer_t at %p", aaddr);
2145 2146 return (DCMD_ERR);
2146 2147 }
2147 2148
2148 2149 hsize = (actual = agb.dtagb_hashsize) * sizeof (size_t);
2149 2150 hdata->dthsd_counts = mdb_alloc(hsize, UM_SLEEP | UM_GC);
2150 2151
2151 2152 /*
2152 2153 * Now pick the largest prime smaller than the hash size. (If the
2153 2154 * existing size is prime, we'll pick a smaller prime just for the
2154 2155 * hell of it.)
2155 2156 */
2156 2157 for (prime = agb.dtagb_hashsize - 1; prime > 7; prime--) {
2157 2158 size_t limit = prime / 7;
2158 2159
2159 2160 for (i = 2; i < limit; i++) {
2160 2161 if ((prime % i) == 0)
2161 2162 break;
2162 2163 }
2163 2164
2164 2165 if (i == limit)
2165 2166 break;
2166 2167 }
2167 2168
2168 2169 /*
2169 2170 * And now we want to pick the largest power of two smaller than the
2170 2171 * hashsize.
2171 2172 */
2172 2173 for (i = 0; (1 << i) < agb.dtagb_hashsize; i++)
2173 2174 continue;
2174 2175
2175 2176 evenpow = (1 << (i - 1));
2176 2177
2177 2178 for (i = 0; _dtrace_hashstat[i].dths_name != NULL; i++) {
2178 2179 data.dtagsd_func = _dtrace_hashstat[i].dths_func;
2179 2180
2180 2181 hdata->dthsd_hashsize = actual;
2181 2182 hsize = hdata->dthsd_hashsize * sizeof (size_t);
2182 2183 bzero(hdata->dthsd_counts, hsize);
2183 2184
2184 2185 if (mdb_pwalk("dtrace_aggkey",
2185 2186 (mdb_walk_cb_t)dtrace_aggstat_walk, &data, addr) == -1) {
2186 2187 mdb_warn("failed to walk dtrace_aggkey at %p", addr);
2187 2188 return (DCMD_ERR);
2188 2189 }
2189 2190
2190 2191 dtrace_hashstat_stats(_dtrace_hashstat[i].dths_name, hdata);
2191 2192
2192 2193 /*
2193 2194 * If we were just printing the actual value, we won't try
2194 2195 * any of the sizing experiments.
2195 2196 */
2196 2197 if (data.dtagsd_func == NULL)
2197 2198 continue;
2198 2199
2199 2200 hdata->dthsd_hashsize = prime;
2200 2201 hsize = hdata->dthsd_hashsize * sizeof (size_t);
2201 2202 bzero(hdata->dthsd_counts, hsize);
2202 2203
2203 2204 if (mdb_pwalk("dtrace_aggkey",
2204 2205 (mdb_walk_cb_t)dtrace_aggstat_walk, &data, addr) == -1) {
2205 2206 mdb_warn("failed to walk dtrace_aggkey at %p", addr);
2206 2207 return (DCMD_ERR);
2207 2208 }
2208 2209
2209 2210 dtrace_hashstat_stats(_dtrace_hashstat[i].dths_name, hdata);
2210 2211
2211 2212 hdata->dthsd_hashsize = evenpow;
2212 2213 hsize = hdata->dthsd_hashsize * sizeof (size_t);
2213 2214 bzero(hdata->dthsd_counts, hsize);
2214 2215
2215 2216 if (mdb_pwalk("dtrace_aggkey",
2216 2217 (mdb_walk_cb_t)dtrace_aggstat_walk, &data, addr) == -1) {
2217 2218 mdb_warn("failed to walk dtrace_aggkey at %p", addr);
2218 2219 return (DCMD_ERR);
2219 2220 }
2220 2221
2221 2222 dtrace_hashstat_stats(_dtrace_hashstat[i].dths_name, hdata);
2222 2223 }
2223 2224
2224 2225 return (DCMD_OK);
2225 2226 }
2226 2227
2227 2228 /*ARGSUSED*/
2228 2229 static int
2229 2230 dtrace_dynstat_walk(uintptr_t addr, dtrace_dynvar_t *dynvar,
2230 2231 dtrace_aggstat_data_t *data)
2231 2232 {
2232 2233 dtrace_hashstat_data_t *hdata = &data->dtagsd_hash;
2233 2234 dtrace_tuple_t *tuple = &dynvar->dtdv_tuple;
2234 2235 dtrace_key_t *key = tuple->dtt_key;
2235 2236 size_t size = 0, offs = 0;
2236 2237 int i, nkeys = tuple->dtt_nkeys;
2237 2238 char *buf;
2238 2239
2239 2240 if (data->dtagsd_func == NULL) {
2240 2241 size_t bucket = dynvar->dtdv_hashval % hdata->dthsd_hashsize;
2241 2242
2242 2243 hdata->dthsd_counts[bucket]++;
2243 2244 return (WALK_NEXT);
2244 2245 }
2245 2246
2246 2247 /*
2247 2248 * We want to hand the hashing algorithm a contiguous buffer. First
2248 2249 * run through the tuple and determine the size.
2249 2250 */
2250 2251 for (i = 0; i < nkeys; i++) {
2251 2252 if (key[i].dttk_size == 0) {
2252 2253 size += sizeof (uint64_t);
2253 2254 } else {
2254 2255 size += key[i].dttk_size;
2255 2256 }
2256 2257 }
2257 2258
2258 2259 buf = alloca(size);
2259 2260
2260 2261 /*
2261 2262 * Now go back through the tuple and copy the data into the buffer.
2262 2263 */
2263 2264 for (i = 0; i < nkeys; i++) {
2264 2265 if (key[i].dttk_size == 0) {
2265 2266 bcopy(&key[i].dttk_value, &buf[offs],
2266 2267 sizeof (uint64_t));
2267 2268 offs += sizeof (uint64_t);
2268 2269 } else {
2269 2270 if (mdb_vread(&buf[offs], key[i].dttk_size,
2270 2271 key[i].dttk_value) == -1) {
2271 2272 mdb_warn("couldn't read tuple data at %p",
2272 2273 key[i].dttk_value);
2273 2274 return (WALK_ERR);
2274 2275 }
2275 2276
2276 2277 offs += key[i].dttk_size;
2277 2278 }
2278 2279 }
2279 2280
2280 2281 hdata->dthsd_data = buf;
2281 2282 hdata->dthsd_size = size;
2282 2283
2283 2284 data->dtagsd_func(hdata);
2284 2285
2285 2286 return (WALK_NEXT);
2286 2287 }
2287 2288
2288 2289 /*ARGSUSED*/
2289 2290 int
2290 2291 dtrace_dynstat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2291 2292 {
2292 2293 dtrace_dstate_t dstate;
2293 2294 size_t hsize, i, actual, prime;
2294 2295 dtrace_aggstat_data_t data;
2295 2296 dtrace_hashstat_data_t *hdata = &data.dtagsd_hash;
2296 2297
2297 2298 bzero(&data, sizeof (data));
2298 2299
2299 2300 if (!(flags & DCMD_ADDRSPEC))
2300 2301 return (DCMD_USAGE);
2301 2302
2302 2303 if (mdb_vread(&dstate, sizeof (dstate), addr) == -1) {
2303 2304 mdb_warn("failed to read dynamic variable state at %p", addr);
2304 2305 return (DCMD_ERR);
2305 2306 }
2306 2307
2307 2308 hsize = (actual = dstate.dtds_hashsize) * sizeof (size_t);
2308 2309 hdata->dthsd_counts = mdb_alloc(hsize, UM_SLEEP | UM_GC);
2309 2310
2310 2311 /*
2311 2312 * Now pick the largest prime smaller than the hash size. (If the
2312 2313 * existing size is prime, we'll pick a smaller prime just for the
2313 2314 * hell of it.)
2314 2315 */
2315 2316 for (prime = dstate.dtds_hashsize - 1; prime > 7; prime--) {
2316 2317 size_t limit = prime / 7;
2317 2318
2318 2319 for (i = 2; i < limit; i++) {
2319 2320 if ((prime % i) == 0)
2320 2321 break;
2321 2322 }
2322 2323
2323 2324 if (i == limit)
2324 2325 break;
2325 2326 }
2326 2327
2327 2328 for (i = 0; _dtrace_hashstat[i].dths_name != NULL; i++) {
2328 2329 data.dtagsd_func = _dtrace_hashstat[i].dths_func;
2329 2330
2330 2331 hdata->dthsd_hashsize = actual;
2331 2332 hsize = hdata->dthsd_hashsize * sizeof (size_t);
2332 2333 bzero(hdata->dthsd_counts, hsize);
2333 2334
2334 2335 if (mdb_pwalk("dtrace_dynvar",
2335 2336 (mdb_walk_cb_t)dtrace_dynstat_walk, &data, addr) == -1) {
2336 2337 mdb_warn("failed to walk dtrace_dynvar at %p", addr);
2337 2338 return (DCMD_ERR);
2338 2339 }
2339 2340
2340 2341 dtrace_hashstat_stats(_dtrace_hashstat[i].dths_name, hdata);
2341 2342
2342 2343 /*
2343 2344 * If we were just printing the actual value, we won't try
2344 2345 * any of the sizing experiments.
2345 2346 */
2346 2347 if (data.dtagsd_func == NULL)
2347 2348 continue;
2348 2349
2349 2350 hdata->dthsd_hashsize = prime;
2350 2351 hsize = hdata->dthsd_hashsize * sizeof (size_t);
2351 2352 bzero(hdata->dthsd_counts, hsize);
2352 2353
2353 2354 if (mdb_pwalk("dtrace_dynvar",
2354 2355 (mdb_walk_cb_t)dtrace_dynstat_walk, &data, addr) == -1) {
2355 2356 mdb_warn("failed to walk dtrace_aggkey at %p", addr);
2356 2357 return (DCMD_ERR);
2357 2358 }
2358 2359
2359 2360 dtrace_hashstat_stats(_dtrace_hashstat[i].dths_name, hdata);
2360 2361 }
2361 2362
2362 2363 return (DCMD_OK);
2363 2364 }
2364 2365
2365 2366 typedef struct dtrace_ecb_walk {
2366 2367 dtrace_ecb_t **dtew_ecbs;
2367 2368 int dtew_necbs;
2368 2369 int dtew_curecb;
2369 2370 } dtrace_ecb_walk_t;
2370 2371
2371 2372 static int
2372 2373 dtrace_ecb_init(mdb_walk_state_t *wsp)
2373 2374 {
2374 2375 uintptr_t addr;
2375 2376 dtrace_state_t state;
2376 2377 dtrace_ecb_walk_t *ecbwp;
2377 2378
2378 2379 if ((addr = wsp->walk_addr) == NULL) {
2379 2380 mdb_warn("dtrace_ecb walk needs dtrace_state_t\n");
2380 2381 return (WALK_ERR);
2381 2382 }
2382 2383
2383 2384 if (mdb_vread(&state, sizeof (state), addr) == -1) {
2384 2385 mdb_warn("failed to read dtrace state pointer at %p", addr);
2385 2386 return (WALK_ERR);
2386 2387 }
2387 2388
2388 2389 ecbwp = mdb_zalloc(sizeof (dtrace_ecb_walk_t), UM_SLEEP | UM_GC);
2389 2390
2390 2391 ecbwp->dtew_ecbs = state.dts_ecbs;
2391 2392 ecbwp->dtew_necbs = state.dts_necbs;
2392 2393 ecbwp->dtew_curecb = 0;
2393 2394
2394 2395 wsp->walk_data = ecbwp;
2395 2396
2396 2397 return (WALK_NEXT);
2397 2398 }
2398 2399
2399 2400 static int
2400 2401 dtrace_ecb_step(mdb_walk_state_t *wsp)
2401 2402 {
2402 2403 uintptr_t ecbp, addr;
2403 2404 dtrace_ecb_walk_t *ecbwp = wsp->walk_data;
2404 2405
2405 2406 addr = (uintptr_t)ecbwp->dtew_ecbs +
2406 2407 ecbwp->dtew_curecb * sizeof (dtrace_ecb_t *);
2407 2408
2408 2409 if (ecbwp->dtew_curecb++ == ecbwp->dtew_necbs)
2409 2410 return (WALK_DONE);
2410 2411
2411 2412 if (mdb_vread(&ecbp, sizeof (addr), addr) == -1) {
2412 2413 mdb_warn("failed to read ecb at entry %d\n",
2413 2414 ecbwp->dtew_curecb);
2414 2415 return (WALK_ERR);
2415 2416 }
2416 2417
2417 2418 if (ecbp == NULL)
2418 2419 return (WALK_NEXT);
2419 2420
2420 2421 return (wsp->walk_callback(ecbp, NULL, wsp->walk_cbdata));
2421 2422 }
2422 2423
2423 2424 static void
2424 2425 dtrace_options_numtostr(uint64_t num, char *buf, size_t len)
2425 2426 {
2426 2427 uint64_t n = num;
2427 2428 int index = 0;
2428 2429 char u;
2429 2430
2430 2431 while (n >= 1024) {
2431 2432 n = (n + (1024 / 2)) / 1024; /* Round up or down */
2432 2433 index++;
2433 2434 }
2434 2435
2435 2436 u = " KMGTPE"[index];
2436 2437
2437 2438 if (index == 0) {
2438 2439 (void) mdb_snprintf(buf, len, "%llu", (u_longlong_t)n);
2439 2440 } else if (n < 10 && (num & (num - 1)) != 0) {
2440 2441 (void) mdb_snprintf(buf, len, "%.2f%c",
2441 2442 (double)num / (1ULL << 10 * index), u);
2442 2443 } else if (n < 100 && (num & (num - 1)) != 0) {
2443 2444 (void) mdb_snprintf(buf, len, "%.1f%c",
2444 2445 (double)num / (1ULL << 10 * index), u);
2445 2446 } else {
2446 2447 (void) mdb_snprintf(buf, len, "%llu%c", (u_longlong_t)n, u);
2447 2448 }
2448 2449 }
2449 2450
2450 2451 static void
2451 2452 dtrace_options_numtohz(uint64_t num, char *buf, size_t len)
2452 2453 {
2453 2454 (void) mdb_snprintf(buf, len, "%dhz", NANOSEC/num);
2454 2455 }
2455 2456
2456 2457 static void
2457 2458 dtrace_options_numtobufpolicy(uint64_t num, char *buf, size_t len)
2458 2459 {
2459 2460 char *policy = "unknown";
2460 2461
2461 2462 switch (num) {
2462 2463 case DTRACEOPT_BUFPOLICY_RING:
2463 2464 policy = "ring";
2464 2465 break;
2465 2466
2466 2467 case DTRACEOPT_BUFPOLICY_FILL:
2467 2468 policy = "fill";
2468 2469 break;
2469 2470
2470 2471 case DTRACEOPT_BUFPOLICY_SWITCH:
2471 2472 policy = "switch";
2472 2473 break;
2473 2474 }
2474 2475
2475 2476 (void) mdb_snprintf(buf, len, "%s", policy);
2476 2477 }
2477 2478
2478 2479 static void
2479 2480 dtrace_options_numtocpu(uint64_t cpu, char *buf, size_t len)
2480 2481 {
2481 2482 if (cpu == DTRACE_CPUALL)
2482 2483 (void) mdb_snprintf(buf, len, "%7s", "unbound");
2483 2484 else
2484 2485 (void) mdb_snprintf(buf, len, "%d", cpu);
2485 2486 }
2486 2487
2487 2488 typedef void (*dtrace_options_func_t)(uint64_t, char *, size_t);
2488 2489
2489 2490 static struct dtrace_options {
2490 2491 char *dtop_optstr;
2491 2492 dtrace_options_func_t dtop_func;
2492 2493 } _dtrace_options[] = {
2493 2494 { "bufsize", dtrace_options_numtostr },
2494 2495 { "bufpolicy", dtrace_options_numtobufpolicy },
2495 2496 { "dynvarsize", dtrace_options_numtostr },
2496 2497 { "aggsize", dtrace_options_numtostr },
2497 2498 { "specsize", dtrace_options_numtostr },
2498 2499 { "nspec", dtrace_options_numtostr },
2499 2500 { "strsize", dtrace_options_numtostr },
2500 2501 { "cleanrate", dtrace_options_numtohz },
2501 2502 { "cpu", dtrace_options_numtocpu },
2502 2503 { "bufresize", dtrace_options_numtostr },
2503 2504 { "grabanon", dtrace_options_numtostr },
2504 2505 { "flowindent", dtrace_options_numtostr },
2505 2506 { "quiet", dtrace_options_numtostr },
2506 2507 { "stackframes", dtrace_options_numtostr },
2507 2508 { "ustackframes", dtrace_options_numtostr },
2508 2509 { "aggrate", dtrace_options_numtohz },
2509 2510 { "switchrate", dtrace_options_numtohz },
2510 2511 { "statusrate", dtrace_options_numtohz },
2511 2512 { "destructive", dtrace_options_numtostr },
2512 2513 { "stackindent", dtrace_options_numtostr },
2513 2514 { "rawbytes", dtrace_options_numtostr },
2514 2515 { "jstackframes", dtrace_options_numtostr },
2515 2516 { "jstackstrsize", dtrace_options_numtostr },
2516 2517 { "aggsortkey", dtrace_options_numtostr },
2517 2518 { "aggsortrev", dtrace_options_numtostr },
2518 2519 { "aggsortpos", dtrace_options_numtostr },
2519 2520 { "aggsortkeypos", dtrace_options_numtostr }
2520 2521 };
2521 2522
2522 2523 static void
2523 2524 dtrace_options_help(void)
2524 2525 {
2525 2526 mdb_printf("Given a dtrace_state_t structure, displays the "
2526 2527 "current tunable option\nsettings.\n");
2527 2528 }
2528 2529
2529 2530 /*ARGSUSED*/
2530 2531 static int
2531 2532 dtrace_options(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2532 2533 {
2533 2534 dtrace_state_t state;
2534 2535 int i = 0;
2535 2536 dtrace_optval_t *options;
2536 2537 char val[32];
2537 2538
2538 2539 if (!(flags & DCMD_ADDRSPEC))
2539 2540 return (DCMD_USAGE);
2540 2541
2541 2542 if (mdb_vread(&state, sizeof (dtrace_state_t), (uintptr_t)addr) == -1) {
2542 2543 mdb_warn("failed to read state pointer at %p\n", addr);
2543 2544 return (DCMD_ERR);
2544 2545 }
2545 2546
2546 2547 options = &state.dts_options[0];
2547 2548
2548 2549 mdb_printf("%<u>%-25s %s%</u>\n", "OPTION", "VALUE");
2549 2550 for (i = 0; i < DTRACEOPT_MAX; i++) {
2550 2551 if (options[i] == DTRACEOPT_UNSET) {
2551 2552 mdb_printf("%-25s %s\n",
2552 2553 _dtrace_options[i].dtop_optstr, "UNSET");
2553 2554 } else {
2554 2555 (void) _dtrace_options[i].dtop_func(options[i],
2555 2556 val, 32);
2556 2557 mdb_printf("%-25s %s\n",
2557 2558 _dtrace_options[i].dtop_optstr, val);
2558 2559 }
2559 2560 }
2560 2561
2561 2562 return (DCMD_OK);
2562 2563 }
2563 2564
2564 2565 static int
2565 2566 pid2state_init(mdb_walk_state_t *wsp)
2566 2567 {
2567 2568 dtrace_state_data_t *data;
2568 2569 uintptr_t devi;
2569 2570 uintptr_t proc;
2570 2571 struct dev_info info;
2571 2572 pid_t pid = (pid_t)wsp->walk_addr;
2572 2573
2573 2574 if (wsp->walk_addr == NULL) {
2574 2575 mdb_warn("pid2state walk requires PID\n");
2575 2576 return (WALK_ERR);
2576 2577 }
2577 2578
2578 2579 data = mdb_zalloc(sizeof (dtrace_state_data_t), UM_SLEEP | UM_GC);
2579 2580
2580 2581 if (mdb_readvar(&data->dtsd_softstate, "dtrace_softstate") == -1) {
2581 2582 mdb_warn("failed to read 'dtrace_softstate'");
2582 2583 return (DCMD_ERR);
2583 2584 }
2584 2585
2585 2586 if ((proc = mdb_pid2proc(pid, NULL)) == NULL) {
2586 2587 mdb_warn("PID 0t%d not found\n", pid);
2587 2588 return (DCMD_ERR);
2588 2589 }
2589 2590
2590 2591 if (mdb_readvar(&devi, "dtrace_devi") == -1) {
2591 2592 mdb_warn("failed to read 'dtrace_devi'");
2592 2593 return (DCMD_ERR);
2593 2594 }
2594 2595
2595 2596 if (mdb_vread(&info, sizeof (struct dev_info), devi) == -1) {
2596 2597 mdb_warn("failed to read 'dev_info'");
2597 2598 return (DCMD_ERR);
2598 2599 }
2599 2600
2600 2601 data->dtsd_major = info.devi_major;
2601 2602 data->dtsd_proc = proc;
2602 2603
2603 2604 wsp->walk_data = data;
2604 2605
2605 2606 return (WALK_NEXT);
2606 2607 }
2607 2608
2608 2609 /*ARGSUSED*/
2609 2610 static int
2610 2611 pid2state_file(uintptr_t addr, struct file *f, dtrace_state_data_t *data)
2611 2612 {
2612 2613 vnode_t vnode;
2613 2614 minor_t minor;
2614 2615 uintptr_t statep;
2615 2616
2616 2617 /* Get the vnode for this file */
2617 2618 if (mdb_vread(&vnode, sizeof (vnode), (uintptr_t)f->f_vnode) == -1) {
2618 2619 mdb_warn("couldn't read vnode at %p", (uintptr_t)f->f_vnode);
2619 2620 return (WALK_NEXT);
2620 2621 }
2621 2622
2622 2623
2623 2624 /* Is this the dtrace device? */
2624 2625 if (getmajor(vnode.v_rdev) != data->dtsd_major)
2625 2626 return (WALK_NEXT);
2626 2627
2627 2628 /* Get the minor number for this device entry */
2628 2629 minor = getminor(vnode.v_rdev);
2629 2630
2630 2631 if (mdb_get_soft_state_byaddr(data->dtsd_softstate, minor,
2631 2632 &statep, NULL, 0) == -1) {
2632 2633 mdb_warn("failed to read softstate for minor %d", minor);
2633 2634 return (WALK_NEXT);
2634 2635 }
2635 2636
2636 2637 mdb_printf("%p\n", statep);
2637 2638
2638 2639 return (WALK_NEXT);
2639 2640 }
2640 2641
2641 2642 static int
2642 2643 pid2state_step(mdb_walk_state_t *wsp)
2643 2644 {
2644 2645 dtrace_state_data_t *ds = wsp->walk_data;
2645 2646
2646 2647 if (mdb_pwalk("file",
2647 2648 (mdb_walk_cb_t)pid2state_file, ds, ds->dtsd_proc) == -1) {
2648 2649 mdb_warn("couldn't walk 'file' for proc %p", ds->dtsd_proc);
2649 2650 return (WALK_ERR);
2650 2651 }
2651 2652
2652 2653 return (WALK_DONE);
2653 2654 }
2654 2655
2655 2656 /*ARGSUSED*/
2656 2657 static int
2657 2658 dtrace_probes_walk(uintptr_t addr, void *ignored, uintptr_t *target)
2658 2659 {
2659 2660 dtrace_ecb_t ecb;
2660 2661 dtrace_probe_t probe;
2661 2662 dtrace_probedesc_t pd;
2662 2663
2663 2664 if (addr == NULL)
2664 2665 return (WALK_ERR);
2665 2666
2666 2667 if (mdb_vread(&ecb, sizeof (dtrace_ecb_t), addr) == -1) {
2667 2668 mdb_warn("failed to read ecb %p\n", addr);
2668 2669 return (WALK_ERR);
2669 2670 }
2670 2671
2671 2672 if (ecb.dte_probe == NULL)
2672 2673 return (WALK_ERR);
2673 2674
2674 2675 if (mdb_vread(&probe, sizeof (dtrace_probe_t),
2675 2676 (uintptr_t)ecb.dte_probe) == -1) {
2676 2677 mdb_warn("failed to read probe %p\n", ecb.dte_probe);
2677 2678 return (WALK_ERR);
2678 2679 }
2679 2680
2680 2681 pd.dtpd_id = probe.dtpr_id;
2681 2682 dtracemdb_probe(NULL, &pd);
2682 2683
2683 2684 mdb_printf("%5d %10s %17s %33s %s\n", pd.dtpd_id, pd.dtpd_provider,
2684 2685 pd.dtpd_mod, pd.dtpd_func, pd.dtpd_name);
2685 2686
2686 2687 return (WALK_NEXT);
2687 2688 }
2688 2689
2689 2690 static void
2690 2691 dtrace_probes_help(void)
2691 2692 {
2692 2693 mdb_printf("Given a dtrace_state_t structure, displays all "
2693 2694 "its active enablings. If no\nstate structure is provided, "
2694 2695 "all available probes are listed.\n");
2695 2696 }
2696 2697
2697 2698 /*ARGSUSED*/
2698 2699 static int
2699 2700 dtrace_probes(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2700 2701 {
2701 2702 dtrace_probedesc_t pd;
2702 2703 uintptr_t caddr, base, paddr;
2703 2704 int nprobes, i;
2704 2705
2705 2706 mdb_printf("%5s %10s %17s %33s %s\n",
2706 2707 "ID", "PROVIDER", "MODULE", "FUNCTION", "NAME");
2707 2708
2708 2709 if (!(flags & DCMD_ADDRSPEC)) {
2709 2710 /*
2710 2711 * If no argument is provided just display all available
2711 2712 * probes.
2712 2713 */
2713 2714 if (mdb_readvar(&base, "dtrace_probes") == -1) {
2714 2715 mdb_warn("failed to read 'dtrace_probes'");
2715 2716 return (-1);
2716 2717 }
2717 2718
2718 2719 if (mdb_readvar(&nprobes, "dtrace_nprobes") == -1) {
2719 2720 mdb_warn("failed to read 'dtrace_nprobes'");
2720 2721 return (-1);
2721 2722 }
2722 2723
2723 2724 for (i = 0; i < nprobes; i++) {
2724 2725 caddr = base + i * sizeof (dtrace_probe_t *);
2725 2726
2726 2727 if (mdb_vread(&paddr, sizeof (paddr), caddr) == -1) {
2727 2728 mdb_warn("couldn't read probe pointer at %p",
2728 2729 caddr);
2729 2730 continue;
2730 2731 }
2731 2732
2732 2733 if (paddr == NULL)
2733 2734 continue;
2734 2735
2735 2736 pd.dtpd_id = i + 1;
2736 2737 if (dtracemdb_probe(NULL, &pd) == 0) {
2737 2738 mdb_printf("%5d %10s %17s %33s %s\n",
2738 2739 pd.dtpd_id, pd.dtpd_provider,
2739 2740 pd.dtpd_mod, pd.dtpd_func, pd.dtpd_name);
2740 2741 }
2741 2742 }
2742 2743 } else {
2743 2744 if (mdb_pwalk("dtrace_ecb", (mdb_walk_cb_t)dtrace_probes_walk,
2744 2745 NULL, addr) == -1) {
2745 2746 mdb_warn("couldn't walk 'dtrace_ecb'");
2746 2747 return (DCMD_ERR);
2747 2748 }
2748 2749 }
2749 2750
2750 2751 return (DCMD_OK);
2751 2752 }
2752 2753
2753 2754 const mdb_dcmd_t kernel_dcmds[] = {
2754 2755 { "id2probe", ":", "translate a dtrace_id_t to a dtrace_probe_t",
2755 2756 id2probe },
2756 2757 { "dtrace", ":[-c cpu]", "print dtrace(1M)-like output",
2757 2758 dtrace, dtrace_help },
2758 2759 { "dtrace_errhash", ":", "print DTrace error hash", dtrace_errhash },
2759 2760 { "dtrace_helptrace", ":", "print DTrace helper trace",
2760 2761 dtrace_helptrace },
2761 2762 { "dtrace_state", ":", "print active DTrace consumers", dtrace_state,
2762 2763 dtrace_state_help },
2763 2764 { "dtrace_aggstat", ":",
2764 2765 "print DTrace aggregation hash statistics", dtrace_aggstat },
2765 2766 { "dtrace_dynstat", ":",
2766 2767 "print DTrace dynamic variable hash statistics", dtrace_dynstat },
2767 2768 { "dtrace_options", ":",
2768 2769 "print a DTrace consumer's current tuneable options",
2769 2770 dtrace_options, dtrace_options_help },
2770 2771 { "dtrace_probes", "?", "print a DTrace consumer's enabled probes",
2771 2772 dtrace_probes, dtrace_probes_help },
2772 2773 { NULL }
2773 2774 };
2774 2775
2775 2776 const mdb_walker_t kernel_walkers[] = {
2776 2777 { "dtrace_errhash", "walk hash of DTrace error messasges",
2777 2778 dtrace_errhash_init, dtrace_errhash_step },
2778 2779 { "dtrace_helptrace", "walk DTrace helper trace entries",
2779 2780 dtrace_helptrace_init, dtrace_helptrace_step },
2780 2781 { "dtrace_state", "walk DTrace per-consumer softstate",
2781 2782 dtrace_state_init, dtrace_state_step },
2782 2783 { "dtrace_aggkey", "walk DTrace aggregation keys",
2783 2784 dtrace_aggkey_init, dtrace_aggkey_step, dtrace_aggkey_fini },
2784 2785 { "dtrace_dynvar", "walk DTrace dynamic variables",
2785 2786 dtrace_dynvar_init, dtrace_dynvar_step, dtrace_dynvar_fini },
2786 2787 { "dtrace_ecb", "walk a DTrace consumer's enabling control blocks",
2787 2788 dtrace_ecb_init, dtrace_ecb_step },
2788 2789 { "pid2state", "walk a processes dtrace_state structures",
2789 2790 pid2state_init, pid2state_step },
2790 2791 { NULL }
2791 2792 };
↓ open down ↓ |
1493 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX