4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
40 #define DT_MASK_LO 0x00000000FFFFFFFFULL
43 * We declare this here because (1) we need it and (2) we want to avoid a
44 * dependency on libm in libdtrace.
47 dt_fabsl(long double x)
56 * 128-bit arithmetic functions needed to support the stddev() aggregating
60 dt_gt_128(uint64_t *a, uint64_t *b)
62 return (a[1] > b[1] || (a[1] == b[1] && a[0] > b[0]));
66 dt_ge_128(uint64_t *a, uint64_t *b)
68 return (a[1] > b[1] || (a[1] == b[1] && a[0] >= b[0]));
72 dt_le_128(uint64_t *a, uint64_t *b)
74 return (a[1] < b[1] || (a[1] == b[1] && a[0] <= b[0]));
78 * Shift the 128-bit value in a by b. If b is positive, shift left.
79 * If b is negative, shift right.
82 dt_shift_128(uint64_t *a, int b)
92 a[0] = a[1] >> (b - 64);
96 mask = 1LL << (64 - b);
98 a[0] |= ((a[1] & mask) << (64 - b));
103 a[1] = a[0] << (b - 64);
107 mask = a[0] >> (64 - b);
115 dt_nbits_128(uint64_t *a)
119 uint64_t zero[2] = { 0, 0 };
124 dt_shift_128(tmp, -1);
125 while (dt_gt_128(tmp, zero)) {
126 dt_shift_128(tmp, -1);
134 dt_subtract_128(uint64_t *minuend, uint64_t *subtrahend, uint64_t *difference)
138 result[0] = minuend[0] - subtrahend[0];
139 result[1] = minuend[1] - subtrahend[1] -
140 (minuend[0] < subtrahend[0] ? 1 : 0);
142 difference[0] = result[0];
143 difference[1] = result[1];
147 dt_add_128(uint64_t *addend1, uint64_t *addend2, uint64_t *sum)
151 result[0] = addend1[0] + addend2[0];
152 result[1] = addend1[1] + addend2[1] +
153 (result[0] < addend1[0] || result[0] < addend2[0] ? 1 : 0);
160 * The basic idea is to break the 2 64-bit values into 4 32-bit values,
161 * use native multiplication on those, and then re-combine into the
162 * resulting 128-bit value.
164 * (hi1 << 32 + lo1) * (hi2 << 32 + lo2) =
171 dt_multiply_128(uint64_t factor1, uint64_t factor2, uint64_t *product)
173 uint64_t hi1, hi2, lo1, lo2;
179 lo1 = factor1 & DT_MASK_LO;
180 lo2 = factor2 & DT_MASK_LO;
182 product[0] = lo1 * lo2;
183 product[1] = hi1 * hi2;
187 dt_shift_128(tmp, 32);
188 dt_add_128(product, tmp, product);
192 dt_shift_128(tmp, 32);
193 dt_add_128(product, tmp, product);
197 * This is long-hand division.
199 * We initialize subtrahend by shifting divisor left as far as possible. We
200 * loop, comparing subtrahend to dividend: if subtrahend is smaller, we
201 * subtract and set the appropriate bit in the result. We then shift
202 * subtrahend right by one bit for the next comparison.
205 dt_divide_128(uint64_t *dividend, uint64_t divisor, uint64_t *quotient)
207 uint64_t result[2] = { 0, 0 };
208 uint64_t remainder[2];
209 uint64_t subtrahend[2];
210 uint64_t divisor_128[2];
211 uint64_t mask[2] = { 1, 0 };
214 assert(divisor != 0);
216 divisor_128[0] = divisor;
219 remainder[0] = dividend[0];
220 remainder[1] = dividend[1];
222 subtrahend[0] = divisor;
225 while (divisor > 0) {
230 dt_shift_128(subtrahend, 128 - log);
231 dt_shift_128(mask, 128 - log);
233 while (dt_ge_128(remainder, divisor_128)) {
234 if (dt_ge_128(remainder, subtrahend)) {
235 dt_subtract_128(remainder, subtrahend, remainder);
236 result[0] |= mask[0];
237 result[1] |= mask[1];
240 dt_shift_128(subtrahend, -1);
241 dt_shift_128(mask, -1);
244 quotient[0] = result[0];
245 quotient[1] = result[1];
249 * This is the long-hand method of calculating a square root.
250 * The algorithm is as follows:
252 * 1. Group the digits by 2 from the right.
253 * 2. Over the leftmost group, find the largest single-digit number
254 * whose square is less than that group.
255 * 3. Subtract the result of the previous step (2 or 4, depending) and
256 * bring down the next two-digit group.
257 * 4. For the result R we have so far, find the largest single-digit number
258 * x such that 2 * R * 10 * x + x^2 is less than the result from step 3.
259 * (Note that this is doubling R and performing a decimal left-shift by 1
260 * and searching for the appropriate decimal to fill the one's place.)
261 * The value x is the next digit in the square root.
262 * Repeat steps 3 and 4 until the desired precision is reached. (We're
263 * dealing with integers, so the above is sufficient.)
265 * In decimal, the square root of 582,734 would be calculated as so:
269 * -49 (7^2 == 49 => 7 is the first digit in the square root)
271 * 9 27 (Subtract and bring down the next group.)
272 * 146 8 76 (2 * 7 * 10 * 6 + 6^2 == 876 => 6 is the next digit in
273 * ----- the square root)
274 * 51 34 (Subtract and bring down the next group.)
275 * 1523 45 69 (2 * 76 * 10 * 3 + 3^2 == 4569 => 3 is the next digit in
276 * ----- the square root)
279 * The above algorithm applies similarly in binary, but note that the
280 * only possible non-zero value for x in step 4 is 1, so step 4 becomes a
281 * simple decision: is 2 * R * 2 * 1 + 1^2 (aka R << 2 + 1) less than the
282 * preceding difference?
284 * In binary, the square root of 11011011 would be calculated as so:
288 * 01 (0 << 2 + 1 == 1 < 11 => this bit is 1)
291 * 101 1 01 (1 << 2 + 1 == 101 < 1001 => next bit is 1)
294 * 1101 11 01 (11 << 2 + 1 == 1101 < 10010 => next bit is 1)
297 * 11101 1 11 01 (111 << 2 + 1 == 11101 > 10111 => last bit is 0)
301 dt_sqrt_128(uint64_t *square)
303 uint64_t result[2] = { 0, 0 };
304 uint64_t diff[2] = { 0, 0 };
305 uint64_t one[2] = { 1, 0 };
306 uint64_t next_pair[2];
307 uint64_t next_try[2];
308 uint64_t bit_pairs, pair_shift;
311 bit_pairs = dt_nbits_128(square) / 2;
312 pair_shift = bit_pairs * 2;
314 for (i = 0; i <= bit_pairs; i++) {
316 * Bring down the next pair of bits.
318 next_pair[0] = square[0];
319 next_pair[1] = square[1];
320 dt_shift_128(next_pair, -pair_shift);
324 dt_shift_128(diff, 2);
325 dt_add_128(diff, next_pair, diff);
328 * next_try = R << 2 + 1
330 next_try[0] = result[0];
331 next_try[1] = result[1];
332 dt_shift_128(next_try, 2);
333 dt_add_128(next_try, one, next_try);
335 if (dt_le_128(next_try, diff)) {
336 dt_subtract_128(diff, next_try, diff);
337 dt_shift_128(result, 1);
338 dt_add_128(result, one, result);
340 dt_shift_128(result, 1);
346 assert(result[1] == 0);
352 dt_stddev(uint64_t *data, uint64_t normal)
354 uint64_t avg_of_squares[2];
355 uint64_t square_of_avg[2];
360 * The standard approximation for standard deviation is
361 * sqrt(average(x**2) - average(x)**2), i.e. the square root
362 * of the average of the squares minus the square of the average.
364 dt_divide_128(data + 2, normal, avg_of_squares);
365 dt_divide_128(avg_of_squares, data[0], avg_of_squares);
367 norm_avg = (int64_t)data[1] / (int64_t)normal / (int64_t)data[0];
370 norm_avg = -norm_avg;
372 dt_multiply_128((uint64_t)norm_avg, (uint64_t)norm_avg, square_of_avg);
374 dt_subtract_128(avg_of_squares, square_of_avg, diff);
376 return (dt_sqrt_128(diff));
380 dt_flowindent(dtrace_hdl_t *dtp, dtrace_probedata_t *data, dtrace_epid_t last,
381 dtrace_bufdesc_t *buf, size_t offs)
383 dtrace_probedesc_t *pd = data->dtpda_pdesc, *npd;
384 dtrace_eprobedesc_t *epd = data->dtpda_edesc, *nepd;
385 char *p = pd->dtpd_provider, *n = pd->dtpd_name, *sub;
386 dtrace_flowkind_t flow = DTRACEFLOW_NONE;
387 const char *str = NULL;
388 static const char *e_str[2] = { " -> ", " => " };
389 static const char *r_str[2] = { " <- ", " <= " };
390 static const char *ent = "entry", *ret = "return";
391 static int entlen = 0, retlen = 0;
392 dtrace_epid_t next, id = epd->dtepd_epid;
397 entlen = strlen(ent);
398 retlen = strlen(ret);
402 * If the name of the probe is "entry" or ends with "-entry", we
403 * treat it as an entry; if it is "return" or ends with "-return",
404 * we treat it as a return. (This allows application-provided probes
405 * like "method-entry" or "function-entry" to participate in flow
406 * indentation -- without accidentally misinterpreting popular probe
407 * names like "carpentry", "gentry" or "Coventry".)
409 if ((sub = strstr(n, ent)) != NULL && sub[entlen] == '\0' &&
410 (sub == n || sub[-1] == '-')) {
411 flow = DTRACEFLOW_ENTRY;
412 str = e_str[strcmp(p, "syscall") == 0];
413 } else if ((sub = strstr(n, ret)) != NULL && sub[retlen] == '\0' &&
414 (sub == n || sub[-1] == '-')) {
415 flow = DTRACEFLOW_RETURN;
416 str = r_str[strcmp(p, "syscall") == 0];
420 * If we're going to indent this, we need to check the ID of our last
421 * call. If we're looking at the same probe ID but a different EPID,
422 * we _don't_ want to indent. (Yes, there are some minor holes in
423 * this scheme -- it's a heuristic.)
425 if (flow == DTRACEFLOW_ENTRY) {
426 if ((last != DTRACE_EPIDNONE && id != last &&
427 pd->dtpd_id == dtp->dt_pdesc[last]->dtpd_id))
428 flow = DTRACEFLOW_NONE;
432 * If we're going to unindent this, it's more difficult to see if
433 * we don't actually want to unindent it -- we need to look at the
436 if (flow == DTRACEFLOW_RETURN) {
437 offs += epd->dtepd_size;
440 if (offs >= buf->dtbd_size) {
442 * We're at the end -- maybe. If the oldest
443 * record is non-zero, we need to wrap.
445 if (buf->dtbd_oldest != 0) {
452 next = *(uint32_t *)((uintptr_t)buf->dtbd_data + offs);
454 if (next == DTRACE_EPIDNONE)
456 } while (next == DTRACE_EPIDNONE);
458 if ((rval = dt_epid_lookup(dtp, next, &nepd, &npd)) != 0)
461 if (next != id && npd->dtpd_id == pd->dtpd_id)
462 flow = DTRACEFLOW_NONE;
466 if (flow == DTRACEFLOW_ENTRY || flow == DTRACEFLOW_RETURN) {
467 data->dtpda_prefix = str;
469 data->dtpda_prefix = "| ";
472 if (flow == DTRACEFLOW_RETURN && data->dtpda_indent > 0)
473 data->dtpda_indent -= 2;
475 data->dtpda_flow = flow;
483 return (DTRACE_CONSUME_THIS);
489 return (DTRACE_CONSUME_NEXT);
493 dt_print_quantline(dtrace_hdl_t *dtp, FILE *fp, int64_t val,
494 uint64_t normal, long double total, char positives, char negatives)
497 uint_t depth, len = 40;
499 const char *ats = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
500 const char *spaces = " ";
502 assert(strlen(ats) == len && strlen(spaces) == len);
503 assert(!(total == 0 && (positives || negatives)));
504 assert(!(val < 0 && !negatives));
505 assert(!(val > 0 && !positives));
506 assert(!(val != 0 && total == 0));
510 f = (dt_fabsl((long double)val) * len) / total;
511 depth = (uint_t)(f + 0.5);
516 return (dt_printf(dtp, fp, "|%s%s %-9lld\n", ats + len - depth,
517 spaces + depth, (long long)val / normal));
521 f = (dt_fabsl((long double)val) * len) / total;
522 depth = (uint_t)(f + 0.5);
524 return (dt_printf(dtp, fp, "%s%s| %-9lld\n", spaces + depth,
525 ats + len - depth, (long long)val / normal));
529 * If we're here, we have both positive and negative bucket values.
530 * To express this graphically, we're going to generate both positive
531 * and negative bars separated by a centerline. These bars are half
532 * the size of normal quantize()/lquantize() bars, so we divide the
533 * length in half before calculating the bar length.
537 spaces = &spaces[len];
539 f = (dt_fabsl((long double)val) * len) / total;
540 depth = (uint_t)(f + 0.5);
543 return (dt_printf(dtp, fp, "%s%s|%*s %-9lld\n", spaces + depth,
544 ats + len - depth, len, "", (long long)val / normal));
546 return (dt_printf(dtp, fp, "%20s|%s%s %-9lld\n", "",
547 ats + len - depth, spaces + depth,
548 (long long)val / normal));
553 dt_print_quantize(dtrace_hdl_t *dtp, FILE *fp, const void *addr,
554 size_t size, uint64_t normal)
556 const int64_t *data = addr;
557 int i, first_bin = 0, last_bin = DTRACE_QUANTIZE_NBUCKETS - 1;
558 long double total = 0;
559 char positives = 0, negatives = 0;
561 if (size != DTRACE_QUANTIZE_NBUCKETS * sizeof (uint64_t))
562 return (dt_set_errno(dtp, EDT_DMISMATCH));
564 while (first_bin < DTRACE_QUANTIZE_NBUCKETS - 1 && data[first_bin] == 0)
567 if (first_bin == DTRACE_QUANTIZE_NBUCKETS - 1) {
569 * There isn't any data. This is possible if (and only if)
570 * negative increment values have been used. In this case,
571 * we'll print the buckets around 0.
573 first_bin = DTRACE_QUANTIZE_ZEROBUCKET - 1;
574 last_bin = DTRACE_QUANTIZE_ZEROBUCKET + 1;
579 while (last_bin > 0 && data[last_bin] == 0)
582 if (last_bin < DTRACE_QUANTIZE_NBUCKETS - 1)
586 for (i = first_bin; i <= last_bin; i++) {
587 positives |= (data[i] > 0);
588 negatives |= (data[i] < 0);
589 total += dt_fabsl((long double)data[i]);
592 if (dt_printf(dtp, fp, "\n%16s %41s %-9s\n", "value",
593 "------------- Distribution -------------", "count") < 0)
596 for (i = first_bin; i <= last_bin; i++) {
597 if (dt_printf(dtp, fp, "%16lld ",
598 (long long)DTRACE_QUANTIZE_BUCKETVAL(i)) < 0)
601 if (dt_print_quantline(dtp, fp, data[i], normal, total,
602 positives, negatives) < 0)
610 dt_print_lquantize(dtrace_hdl_t *dtp, FILE *fp, const void *addr,
611 size_t size, uint64_t normal)
613 const int64_t *data = addr;
614 int i, first_bin, last_bin, base;
616 long double total = 0;
617 uint16_t step, levels;
618 char positives = 0, negatives = 0;
620 if (size < sizeof (uint64_t))
621 return (dt_set_errno(dtp, EDT_DMISMATCH));
624 size -= sizeof (uint64_t);
626 base = DTRACE_LQUANTIZE_BASE(arg);
627 step = DTRACE_LQUANTIZE_STEP(arg);
628 levels = DTRACE_LQUANTIZE_LEVELS(arg);
631 last_bin = levels + 1;
633 if (size != sizeof (uint64_t) * (levels + 2))
634 return (dt_set_errno(dtp, EDT_DMISMATCH));
636 while (first_bin <= levels + 1 && data[first_bin] == 0)
639 if (first_bin > levels + 1) {
646 while (last_bin > 0 && data[last_bin] == 0)
649 if (last_bin < levels + 1)
653 for (i = first_bin; i <= last_bin; i++) {
654 positives |= (data[i] > 0);
655 negatives |= (data[i] < 0);
656 total += dt_fabsl((long double)data[i]);
659 if (dt_printf(dtp, fp, "\n%16s %41s %-9s\n", "value",
660 "------------- Distribution -------------", "count") < 0)
663 for (i = first_bin; i <= last_bin; i++) {
668 (void) snprintf(c, sizeof (c), "< %d",
669 base / (uint32_t)normal);
670 err = dt_printf(dtp, fp, "%16s ", c);
671 } else if (i == levels + 1) {
672 (void) snprintf(c, sizeof (c), ">= %d",
673 base + (levels * step));
674 err = dt_printf(dtp, fp, "%16s ", c);
676 err = dt_printf(dtp, fp, "%16d ",
677 base + (i - 1) * step);
680 if (err < 0 || dt_print_quantline(dtp, fp, data[i], normal,
681 total, positives, negatives) < 0)
690 dt_print_average(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr,
691 size_t size, uint64_t normal)
693 /* LINTED - alignment */
694 int64_t *data = (int64_t *)addr;
696 return (dt_printf(dtp, fp, " %16lld", data[0] ?
697 (long long)(data[1] / (int64_t)normal / data[0]) : 0));
702 dt_print_stddev(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr,
703 size_t size, uint64_t normal)
705 /* LINTED - alignment */
706 uint64_t *data = (uint64_t *)addr;
708 return (dt_printf(dtp, fp, " %16llu", data[0] ?
709 (unsigned long long) dt_stddev(data, normal) : 0));
714 dt_print_bytes(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr,
715 size_t nbytes, int width, int quiet, int raw)
718 * If the byte stream is a series of printable characters, followed by
719 * a terminating byte, we print it out as a string. Otherwise, we
720 * assume that it's something else and just print the bytes.
722 int i, j, margin = 5;
723 char *c = (char *)addr;
728 if (raw || dtp->dt_options[DTRACEOPT_RAWBYTES] != DTRACEOPT_UNSET)
731 for (i = 0; i < nbytes; i++) {
733 * We define a "printable character" to be one for which
734 * isprint(3C) returns non-zero, isspace(3C) returns non-zero,
735 * or a character which is either backspace or the bell.
736 * Backspace and the bell are regrettably special because
737 * they fail the first two tests -- and yet they are entirely
738 * printable. These are the only two control characters that
739 * have meaning for the terminal and for which isprint(3C) and
740 * isspace(3C) return 0.
742 if (isprint(c[i]) || isspace(c[i]) ||
743 c[i] == '\b' || c[i] == '\a')
746 if (c[i] == '\0' && i > 0) {
748 * This looks like it might be a string. Before we
749 * assume that it is indeed a string, check the
750 * remainder of the byte range; if it contains
751 * additional non-nul characters, we'll assume that
752 * it's a binary stream that just happens to look like
753 * a string, and we'll print out the individual bytes.
755 for (j = i + 1; j < nbytes; j++) {
764 return (dt_printf(dtp, fp, "%s", c));
766 return (dt_printf(dtp, fp, " %-*s", width, c));
774 * The byte range is all printable characters, but there is
775 * no trailing nul byte. We'll assume that it's a string and
778 char *s = alloca(nbytes + 1);
781 return (dt_printf(dtp, fp, " %-*s", width, s));
785 if (dt_printf(dtp, fp, "\n%*s ", margin, "") < 0)
788 for (i = 0; i < 16; i++)
789 if (dt_printf(dtp, fp, " %c", "0123456789abcdef"[i]) < 0)
792 if (dt_printf(dtp, fp, " 0123456789abcdef\n") < 0)
796 for (i = 0; i < nbytes; i += 16) {
797 if (dt_printf(dtp, fp, "%*s%5x:", margin, "", i) < 0)
800 for (j = i; j < i + 16 && j < nbytes; j++) {
801 if (dt_printf(dtp, fp, " %02x", (uchar_t)c[j]) < 0)
806 if (dt_printf(dtp, fp, " ") < 0)
810 if (dt_printf(dtp, fp, " ") < 0)
813 for (j = i; j < i + 16 && j < nbytes; j++) {
814 if (dt_printf(dtp, fp, "%c",
815 c[j] < ' ' || c[j] > '~' ? '.' : c[j]) < 0)
819 if (dt_printf(dtp, fp, "\n") < 0)
827 dt_print_stack(dtrace_hdl_t *dtp, FILE *fp, const char *format,
828 caddr_t addr, int depth, int size)
830 dtrace_syminfo_t dts;
833 char c[PATH_MAX * 2];
836 if (dt_printf(dtp, fp, "\n") < 0)
842 if (dtp->dt_options[DTRACEOPT_STACKINDENT] != DTRACEOPT_UNSET)
843 indent = (int)dtp->dt_options[DTRACEOPT_STACKINDENT];
845 indent = _dtrace_stkindent;
847 for (i = 0; i < depth; i++) {
849 case sizeof (uint32_t):
850 /* LINTED - alignment */
851 pc = *((uint32_t *)addr);
854 case sizeof (uint64_t):
855 /* LINTED - alignment */
856 pc = *((uint64_t *)addr);
860 return (dt_set_errno(dtp, EDT_BADSTACKPC));
868 if (dt_printf(dtp, fp, "%*s", indent, "") < 0)
871 if (dtrace_lookup_by_addr(dtp, pc, &sym, &dts) == 0) {
872 if (pc > sym.st_value) {
873 (void) snprintf(c, sizeof (c), "%s`%s+0x%llx",
874 dts.dts_object, dts.dts_name,
877 (void) snprintf(c, sizeof (c), "%s`%s",
878 dts.dts_object, dts.dts_name);
882 * We'll repeat the lookup, but this time we'll specify
883 * a NULL GElf_Sym -- indicating that we're only
884 * interested in the containing module.
886 if (dtrace_lookup_by_addr(dtp, pc, NULL, &dts) == 0) {
887 (void) snprintf(c, sizeof (c), "%s`0x%llx",
890 (void) snprintf(c, sizeof (c), "0x%llx", pc);
894 if (dt_printf(dtp, fp, format, c) < 0)
897 if (dt_printf(dtp, fp, "\n") < 0)
905 dt_print_ustack(dtrace_hdl_t *dtp, FILE *fp, const char *format,
906 caddr_t addr, uint64_t arg)
908 /* LINTED - alignment */
909 uint64_t *pc = (uint64_t *)addr;
910 uint32_t depth = DTRACE_USTACK_NFRAMES(arg);
911 uint32_t strsize = DTRACE_USTACK_STRSIZE(arg);
912 const char *strbase = addr + (depth + 1) * sizeof (uint64_t);
913 const char *str = strsize ? strbase : NULL;
916 char name[PATH_MAX], objname[PATH_MAX], c[PATH_MAX * 2];
917 struct ps_prochandle *P;
927 if (dt_printf(dtp, fp, "\n") < 0)
933 if (dtp->dt_options[DTRACEOPT_STACKINDENT] != DTRACEOPT_UNSET)
934 indent = (int)dtp->dt_options[DTRACEOPT_STACKINDENT];
936 indent = _dtrace_stkindent;
939 * Ultimately, we need to add an entry point in the library vector for
940 * determining <symbol, offset> from <pid, address>. For now, if
941 * this is a vector open, we just print the raw address or string.
943 if (dtp->dt_vector == NULL)
944 P = dt_proc_grab(dtp, pid, PGRAB_RDONLY | PGRAB_FORCE, 0);
949 dt_proc_lock(dtp, P); /* lock handle while we perform lookups */
951 for (i = 0; i < depth && pc[i] != 0; i++) {
954 if ((err = dt_printf(dtp, fp, "%*s", indent, "")) < 0)
958 if (P != NULL && Plookup_by_addr(P, pc[i],
960 if (P != NULL && proc_addr2sym(P, pc[i],
962 name, sizeof (name), &sym) == 0) {
964 (void) Pobjname(P, pc[i], objname, sizeof (objname));
966 (void) proc_objname(P, pc[i], objname, sizeof (objname));
969 if (pc[i] > sym.st_value) {
970 (void) snprintf(c, sizeof (c),
971 "%s`%s+0x%llx", dt_basename(objname), name,
972 (u_longlong_t)(pc[i] - sym.st_value));
974 (void) snprintf(c, sizeof (c),
975 "%s`%s", dt_basename(objname), name);
977 } else if (str != NULL && str[0] != '\0' && str[0] != '@' &&
979 (P != NULL && ((map = Paddr_to_map(P, pc[i])) == NULL ||
980 (map->pr_mflags & MA_WRITE)))) {
982 (P != NULL && ((map = proc_addr2map(P, pc[i])) == NULL))) {
985 * If the current string pointer in the string table
986 * does not point to an empty string _and_ the program
987 * counter falls in a writable region, we'll use the
988 * string from the string table instead of the raw
989 * address. This last condition is necessary because
990 * some (broken) ustack helpers will return a string
991 * even for a program counter that they can't
992 * identify. If we have a string for a program
993 * counter that falls in a segment that isn't
994 * writable, we assume that we have fallen into this
995 * case and we refuse to use the string.
997 (void) snprintf(c, sizeof (c), "%s", str);
1000 if (P != NULL && Pobjname(P, pc[i], objname,
1002 if (P != NULL && proc_objname(P, pc[i], objname,
1004 sizeof (objname)) != 0) {
1005 (void) snprintf(c, sizeof (c), "%s`0x%llx",
1006 dt_basename(objname), (u_longlong_t)pc[i]);
1008 (void) snprintf(c, sizeof (c), "0x%llx",
1009 (u_longlong_t)pc[i]);
1013 if ((err = dt_printf(dtp, fp, format, c)) < 0)
1016 if ((err = dt_printf(dtp, fp, "\n")) < 0)
1019 if (str != NULL && str[0] == '@') {
1021 * If the first character of the string is an "at" sign,
1022 * then the string is inferred to be an annotation --
1023 * and it is printed out beneath the frame and offset
1026 if ((err = dt_printf(dtp, fp, "%*s", indent, "")) < 0)
1029 (void) snprintf(c, sizeof (c), " [ %s ]", &str[1]);
1031 if ((err = dt_printf(dtp, fp, format, c)) < 0)
1034 if ((err = dt_printf(dtp, fp, "\n")) < 0)
1039 str += strlen(str) + 1;
1040 if (str - strbase >= strsize)
1046 dt_proc_unlock(dtp, P);
1047 dt_proc_release(dtp, P);
1054 dt_print_usym(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr, dtrace_actkind_t act)
1056 /* LINTED - alignment */
1057 uint64_t pid = ((uint64_t *)addr)[0];
1058 /* LINTED - alignment */
1059 uint64_t pc = ((uint64_t *)addr)[1];
1060 const char *format = " %-50s";
1064 if (act == DTRACEACT_USYM && dtp->dt_vector == NULL) {
1065 struct ps_prochandle *P;
1067 if ((P = dt_proc_grab(dtp, pid,
1068 PGRAB_RDONLY | PGRAB_FORCE, 0)) != NULL) {
1071 dt_proc_lock(dtp, P);
1074 if (Plookup_by_addr(P, pc, NULL, 0, &sym) == 0)
1076 if (proc_addr2sym(P, pc, NULL, 0, &sym) == 0)
1080 dt_proc_unlock(dtp, P);
1081 dt_proc_release(dtp, P);
1088 } while ((len = dtrace_uaddr2str(dtp, pid, pc, s, n)) >= n);
1090 return (dt_printf(dtp, fp, format, s));
1094 dt_print_umod(dtrace_hdl_t *dtp, FILE *fp, const char *format, caddr_t addr)
1096 /* LINTED - alignment */
1097 uint64_t pid = ((uint64_t *)addr)[0];
1098 /* LINTED - alignment */
1099 uint64_t pc = ((uint64_t *)addr)[1];
1102 char objname[PATH_MAX], c[PATH_MAX * 2];
1103 struct ps_prochandle *P;
1109 * See the comment in dt_print_ustack() for the rationale for
1110 * printing raw addresses in the vectored case.
1112 if (dtp->dt_vector == NULL)
1113 P = dt_proc_grab(dtp, pid, PGRAB_RDONLY | PGRAB_FORCE, 0);
1118 dt_proc_lock(dtp, P); /* lock handle while we perform lookups */
1121 if (P != NULL && Pobjname(P, pc, objname, sizeof (objname)) != 0) {
1123 if (P != NULL && proc_objname(P, pc, objname, sizeof (objname)) != 0) {
1125 (void) snprintf(c, sizeof (c), "%s", dt_basename(objname));
1127 (void) snprintf(c, sizeof (c), "0x%llx", (u_longlong_t)pc);
1130 err = dt_printf(dtp, fp, format, c);
1133 dt_proc_unlock(dtp, P);
1134 dt_proc_release(dtp, P);
1141 dt_print_memory(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr)
1143 int quiet = (dtp->dt_options[DTRACEOPT_QUIET] != DTRACEOPT_UNSET);
1144 size_t nbytes = *((uintptr_t *) addr);
1146 return (dt_print_bytes(dtp, fp, addr + sizeof(uintptr_t),
1147 nbytes, 50, quiet, 1));
1150 typedef struct dt_type_cbdata {
1152 dtrace_typeinfo_t dtt;
1163 static int dt_print_type_data(dt_type_cbdata_t *, ctf_id_t);
1166 dt_print_type_member(const char *name, ctf_id_t type, ulong_t off, void *arg)
1168 dt_type_cbdata_t cbdata;
1169 dt_type_cbdata_t *cbdatap = arg;
1172 if ((ssz = ctf_type_size(cbdatap->dtt.dtt_ctfp, type)) <= 0)
1180 cbdata.addrend = cbdata.addr + ssz;
1182 return (dt_print_type_data(&cbdata, type));
1186 dt_print_type_width(const char *name, ctf_id_t type, ulong_t off, void *arg)
1188 char buf[DT_TYPE_NAMELEN];
1190 dt_type_cbdata_t *cbdatap = arg;
1191 size_t sz = strlen(name);
1193 ctf_type_name(cbdatap->dtt.dtt_ctfp, type, buf, sizeof (buf));
1195 if ((p = strchr(buf, '[')) != NULL)
1202 if (sz > cbdatap->name_width)
1203 cbdatap->name_width = sz;
1207 if (sz > cbdatap->type_width)
1208 cbdatap->type_width = sz;
1214 dt_print_type_data(dt_type_cbdata_t *cbdatap, ctf_id_t type)
1216 caddr_t addr = cbdatap->addr;
1217 caddr_t addrend = cbdatap->addrend;
1218 char buf[DT_TYPE_NAMELEN];
1221 uint_t kind = ctf_type_kind(cbdatap->dtt.dtt_ctfp, type);
1222 ssize_t ssz = ctf_type_size(cbdatap->dtt.dtt_ctfp, type);
1224 ctf_type_name(cbdatap->dtt.dtt_ctfp, type, buf, sizeof (buf));
1226 if ((p = strchr(buf, '[')) != NULL)
1231 if (cbdatap->f_type) {
1232 int type_width = roundup(cbdatap->type_width + 1, 4);
1233 int name_width = roundup(cbdatap->name_width + 1, 4);
1235 name_width -= strlen(cbdatap->name);
1237 dt_printf(cbdatap->dtp, cbdatap->fp, "%*s%-*s%s%-*s = ",cbdatap->indent * 4,"",type_width,buf,cbdatap->name,name_width,p);
1240 while (addr < addrend) {
1241 dt_type_cbdata_t cbdata;
1242 ctf_arinfo_t arinfo;
1249 cbdata.addrend = addr + ssz;
1252 cbdata.type_width = 0;
1253 cbdata.name_width = 0;
1256 dt_printf(cbdatap->dtp, cbdatap->fp, "%*s", cbdatap->indent * 4,"");
1260 if (ctf_type_encoding(cbdatap->dtt.dtt_ctfp, type, &cte) != 0)
1262 if ((cte.cte_format & CTF_INT_SIGNED) != 0)
1263 switch (cte.cte_bits) {
1265 if (isprint(*((char *) vp)))
1266 dt_printf(cbdatap->dtp, cbdatap->fp, "'%c', ", *((char *) vp));
1267 dt_printf(cbdatap->dtp, cbdatap->fp, "%d (0x%x);\n", *((char *) vp), *((char *) vp));
1270 dt_printf(cbdatap->dtp, cbdatap->fp, "%hd (0x%hx);\n", *((short *) vp), *((u_short *) vp));
1273 dt_printf(cbdatap->dtp, cbdatap->fp, "%d (0x%x);\n", *((int *) vp), *((u_int *) vp));
1276 dt_printf(cbdatap->dtp, cbdatap->fp, "%jd (0x%jx);\n", *((long long *) vp), *((unsigned long long *) vp));
1279 dt_printf(cbdatap->dtp, cbdatap->fp, "CTF_K_INTEGER: format %x offset %u bits %u\n",cte.cte_format,cte.cte_offset,cte.cte_bits);
1283 switch (cte.cte_bits) {
1285 dt_printf(cbdatap->dtp, cbdatap->fp, "%u (0x%x);\n", *((uint8_t *) vp) & 0xff, *((uint8_t *) vp) & 0xff);
1288 dt_printf(cbdatap->dtp, cbdatap->fp, "%hu (0x%hx);\n", *((u_short *) vp), *((u_short *) vp));
1291 dt_printf(cbdatap->dtp, cbdatap->fp, "%u (0x%x);\n", *((u_int *) vp), *((u_int *) vp));
1294 dt_printf(cbdatap->dtp, cbdatap->fp, "%ju (0x%jx);\n", *((unsigned long long *) vp), *((unsigned long long *) vp));
1297 dt_printf(cbdatap->dtp, cbdatap->fp, "CTF_K_INTEGER: format %x offset %u bits %u\n",cte.cte_format,cte.cte_offset,cte.cte_bits);
1302 dt_printf(cbdatap->dtp, cbdatap->fp, "CTF_K_FLOAT: format %x offset %u bits %u\n",cte.cte_format,cte.cte_offset,cte.cte_bits);
1305 dt_printf(cbdatap->dtp, cbdatap->fp, "%p;\n", *((void **) addr));
1308 if (ctf_array_info(cbdatap->dtt.dtt_ctfp, type, &arinfo) != 0)
1310 dt_printf(cbdatap->dtp, cbdatap->fp, "{\n%*s",cbdata.indent * 4,"");
1311 dt_print_type_data(&cbdata, arinfo.ctr_contents);
1312 dt_printf(cbdatap->dtp, cbdatap->fp, "%*s};\n",cbdatap->indent * 4,"");
1314 case CTF_K_FUNCTION:
1315 dt_printf(cbdatap->dtp, cbdatap->fp, "CTF_K_FUNCTION:\n");
1319 if (ctf_member_iter(cbdatap->dtt.dtt_ctfp, type,
1320 dt_print_type_width, &cbdata) != 0)
1322 dt_printf(cbdatap->dtp, cbdatap->fp, "{\n");
1323 if (ctf_member_iter(cbdatap->dtt.dtt_ctfp, type,
1324 dt_print_type_member, &cbdata) != 0)
1326 dt_printf(cbdatap->dtp, cbdatap->fp, "%*s};\n",cbdatap->indent * 4,"");
1330 if (ctf_member_iter(cbdatap->dtt.dtt_ctfp, type,
1331 dt_print_type_width, &cbdata) != 0)
1333 dt_printf(cbdatap->dtp, cbdatap->fp, "{\n");
1334 if (ctf_member_iter(cbdatap->dtt.dtt_ctfp, type,
1335 dt_print_type_member, &cbdata) != 0)
1337 dt_printf(cbdatap->dtp, cbdatap->fp, "%*s};\n",cbdatap->indent * 4,"");
1340 dt_printf(cbdatap->dtp, cbdatap->fp, "%s;\n", ctf_enum_name(cbdatap->dtt.dtt_ctfp, type, *((int *) vp)));
1343 dt_print_type_data(&cbdata, ctf_type_reference(cbdatap->dtt.dtt_ctfp,type));
1345 case CTF_K_VOLATILE:
1346 if (cbdatap->f_type)
1347 dt_printf(cbdatap->dtp, cbdatap->fp, "volatile ");
1348 dt_print_type_data(&cbdata, ctf_type_reference(cbdatap->dtt.dtt_ctfp,type));
1351 if (cbdatap->f_type)
1352 dt_printf(cbdatap->dtp, cbdatap->fp, "const ");
1353 dt_print_type_data(&cbdata, ctf_type_reference(cbdatap->dtt.dtt_ctfp,type));
1355 case CTF_K_RESTRICT:
1356 if (cbdatap->f_type)
1357 dt_printf(cbdatap->dtp, cbdatap->fp, "restrict ");
1358 dt_print_type_data(&cbdata, ctf_type_reference(cbdatap->dtt.dtt_ctfp,type));
1372 dt_print_type(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr)
1376 dtrace_typeinfo_t dtt;
1377 dt_type_cbdata_t cbdata;
1379 int quiet = (dtp->dt_options[DTRACEOPT_QUIET] != DTRACEOPT_UNSET);
1383 dt_printf(dtp, fp, "\n");
1385 /* Get the total number of bytes of data buffered. */
1386 size_t nbytes = *((uintptr_t *) addr);
1387 addr += sizeof(uintptr_t);
1390 * Get the size of the type so that we can check that it matches
1391 * the CTF data we look up and so that we can figure out how many
1392 * type elements are buffered.
1394 size_t typs = *((uintptr_t *) addr);
1395 addr += sizeof(uintptr_t);
1398 * Point to the type string in the buffer. Get it's string
1399 * length and round it up to become the offset to the start
1400 * of the buffered type data which we would like to be aligned
1403 char *strp = (char *) addr;
1404 int offset = roundup(strlen(strp) + 1, sizeof(uintptr_t));
1407 * The type string might have a format such as 'int [20]'.
1408 * Check if there is an array dimension present.
1410 if ((p = strchr(strp, '[')) != NULL) {
1411 /* Strip off the array dimension. */
1414 for (; *p != '\0' && *p != ']'; p++)
1415 num = num * 10 + *p - '0';
1417 /* No array dimension, so default. */
1420 /* Lookup the CTF type from the type string. */
1421 if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY, strp, &dtt) < 0)
1424 /* Offset the buffer address to the start of the data... */
1427 ssz = ctf_type_size(dtt.dtt_ctfp, dtt.dtt_type);
1430 printf("Expected type size from buffer (%lu) to match type size looked up now (%ld)\n", (u_long) typs, (long) ssz);
1438 cbdata.addrend = addr + nbytes;
1441 cbdata.type_width = 0;
1442 cbdata.name_width = 0;
1445 return (dt_print_type_data(&cbdata, dtt.dtt_type));
1449 dt_print_sym(dtrace_hdl_t *dtp, FILE *fp, const char *format, caddr_t addr)
1451 /* LINTED - alignment */
1452 uint64_t pc = *((uint64_t *)addr);
1453 dtrace_syminfo_t dts;
1455 char c[PATH_MAX * 2];
1460 if (dtrace_lookup_by_addr(dtp, pc, &sym, &dts) == 0) {
1461 (void) snprintf(c, sizeof (c), "%s`%s",
1462 dts.dts_object, dts.dts_name);
1465 * We'll repeat the lookup, but this time we'll specify a
1466 * NULL GElf_Sym -- indicating that we're only interested in
1467 * the containing module.
1469 if (dtrace_lookup_by_addr(dtp, pc, NULL, &dts) == 0) {
1470 (void) snprintf(c, sizeof (c), "%s`0x%llx",
1471 dts.dts_object, (u_longlong_t)pc);
1473 (void) snprintf(c, sizeof (c), "0x%llx",
1478 if (dt_printf(dtp, fp, format, c) < 0)
1485 dt_print_mod(dtrace_hdl_t *dtp, FILE *fp, const char *format, caddr_t addr)
1487 /* LINTED - alignment */
1488 uint64_t pc = *((uint64_t *)addr);
1489 dtrace_syminfo_t dts;
1490 char c[PATH_MAX * 2];
1495 if (dtrace_lookup_by_addr(dtp, pc, NULL, &dts) == 0) {
1496 (void) snprintf(c, sizeof (c), "%s", dts.dts_object);
1498 (void) snprintf(c, sizeof (c), "0x%llx", (u_longlong_t)pc);
1501 if (dt_printf(dtp, fp, format, c) < 0)
1507 typedef struct dt_normal {
1508 dtrace_aggvarid_t dtnd_id;
1509 uint64_t dtnd_normal;
1513 dt_normalize_agg(const dtrace_aggdata_t *aggdata, void *arg)
1515 dt_normal_t *normal = arg;
1516 dtrace_aggdesc_t *agg = aggdata->dtada_desc;
1517 dtrace_aggvarid_t id = normal->dtnd_id;
1519 if (agg->dtagd_nrecs == 0)
1520 return (DTRACE_AGGWALK_NEXT);
1522 if (agg->dtagd_varid != id)
1523 return (DTRACE_AGGWALK_NEXT);
1525 ((dtrace_aggdata_t *)aggdata)->dtada_normal = normal->dtnd_normal;
1526 return (DTRACE_AGGWALK_NORMALIZE);
1530 dt_normalize(dtrace_hdl_t *dtp, caddr_t base, dtrace_recdesc_t *rec)
1536 * We (should) have two records: the aggregation ID followed by the
1537 * normalization value.
1539 addr = base + rec->dtrd_offset;
1541 if (rec->dtrd_size != sizeof (dtrace_aggvarid_t))
1542 return (dt_set_errno(dtp, EDT_BADNORMAL));
1544 /* LINTED - alignment */
1545 normal.dtnd_id = *((dtrace_aggvarid_t *)addr);
1548 if (rec->dtrd_action != DTRACEACT_LIBACT)
1549 return (dt_set_errno(dtp, EDT_BADNORMAL));
1551 if (rec->dtrd_arg != DT_ACT_NORMALIZE)
1552 return (dt_set_errno(dtp, EDT_BADNORMAL));
1554 addr = base + rec->dtrd_offset;
1556 switch (rec->dtrd_size) {
1557 case sizeof (uint64_t):
1558 /* LINTED - alignment */
1559 normal.dtnd_normal = *((uint64_t *)addr);
1561 case sizeof (uint32_t):
1562 /* LINTED - alignment */
1563 normal.dtnd_normal = *((uint32_t *)addr);
1565 case sizeof (uint16_t):
1566 /* LINTED - alignment */
1567 normal.dtnd_normal = *((uint16_t *)addr);
1569 case sizeof (uint8_t):
1570 normal.dtnd_normal = *((uint8_t *)addr);
1573 return (dt_set_errno(dtp, EDT_BADNORMAL));
1576 (void) dtrace_aggregate_walk(dtp, dt_normalize_agg, &normal);
1582 dt_denormalize_agg(const dtrace_aggdata_t *aggdata, void *arg)
1584 dtrace_aggdesc_t *agg = aggdata->dtada_desc;
1585 dtrace_aggvarid_t id = *((dtrace_aggvarid_t *)arg);
1587 if (agg->dtagd_nrecs == 0)
1588 return (DTRACE_AGGWALK_NEXT);
1590 if (agg->dtagd_varid != id)
1591 return (DTRACE_AGGWALK_NEXT);
1593 return (DTRACE_AGGWALK_DENORMALIZE);
1597 dt_clear_agg(const dtrace_aggdata_t *aggdata, void *arg)
1599 dtrace_aggdesc_t *agg = aggdata->dtada_desc;
1600 dtrace_aggvarid_t id = *((dtrace_aggvarid_t *)arg);
1602 if (agg->dtagd_nrecs == 0)
1603 return (DTRACE_AGGWALK_NEXT);
1605 if (agg->dtagd_varid != id)
1606 return (DTRACE_AGGWALK_NEXT);
1608 return (DTRACE_AGGWALK_CLEAR);
1611 typedef struct dt_trunc {
1612 dtrace_aggvarid_t dttd_id;
1613 uint64_t dttd_remaining;
1617 dt_trunc_agg(const dtrace_aggdata_t *aggdata, void *arg)
1619 dt_trunc_t *trunc = arg;
1620 dtrace_aggdesc_t *agg = aggdata->dtada_desc;
1621 dtrace_aggvarid_t id = trunc->dttd_id;
1623 if (agg->dtagd_nrecs == 0)
1624 return (DTRACE_AGGWALK_NEXT);
1626 if (agg->dtagd_varid != id)
1627 return (DTRACE_AGGWALK_NEXT);
1629 if (trunc->dttd_remaining == 0)
1630 return (DTRACE_AGGWALK_REMOVE);
1632 trunc->dttd_remaining--;
1633 return (DTRACE_AGGWALK_NEXT);
1637 dt_trunc(dtrace_hdl_t *dtp, caddr_t base, dtrace_recdesc_t *rec)
1642 int (*func)(dtrace_hdl_t *, dtrace_aggregate_f *, void *);
1645 * We (should) have two records: the aggregation ID followed by the
1646 * number of aggregation entries after which the aggregation is to be
1649 addr = base + rec->dtrd_offset;
1651 if (rec->dtrd_size != sizeof (dtrace_aggvarid_t))
1652 return (dt_set_errno(dtp, EDT_BADTRUNC));
1654 /* LINTED - alignment */
1655 trunc.dttd_id = *((dtrace_aggvarid_t *)addr);
1658 if (rec->dtrd_action != DTRACEACT_LIBACT)
1659 return (dt_set_errno(dtp, EDT_BADTRUNC));
1661 if (rec->dtrd_arg != DT_ACT_TRUNC)
1662 return (dt_set_errno(dtp, EDT_BADTRUNC));
1664 addr = base + rec->dtrd_offset;
1666 switch (rec->dtrd_size) {
1667 case sizeof (uint64_t):
1668 /* LINTED - alignment */
1669 remaining = *((int64_t *)addr);
1671 case sizeof (uint32_t):
1672 /* LINTED - alignment */
1673 remaining = *((int32_t *)addr);
1675 case sizeof (uint16_t):
1676 /* LINTED - alignment */
1677 remaining = *((int16_t *)addr);
1679 case sizeof (uint8_t):
1680 remaining = *((int8_t *)addr);
1683 return (dt_set_errno(dtp, EDT_BADNORMAL));
1686 if (remaining < 0) {
1687 func = dtrace_aggregate_walk_valsorted;
1688 remaining = -remaining;
1690 func = dtrace_aggregate_walk_valrevsorted;
1693 assert(remaining >= 0);
1694 trunc.dttd_remaining = remaining;
1696 (void) func(dtp, dt_trunc_agg, &trunc);
1702 dt_print_datum(dtrace_hdl_t *dtp, FILE *fp, dtrace_recdesc_t *rec,
1703 caddr_t addr, size_t size, uint64_t normal)
1706 dtrace_actkind_t act = rec->dtrd_action;
1709 case DTRACEACT_STACK:
1710 return (dt_print_stack(dtp, fp, NULL, addr,
1711 rec->dtrd_arg, rec->dtrd_size / rec->dtrd_arg));
1713 case DTRACEACT_USTACK:
1714 case DTRACEACT_JSTACK:
1715 return (dt_print_ustack(dtp, fp, NULL, addr, rec->dtrd_arg));
1717 case DTRACEACT_USYM:
1718 case DTRACEACT_UADDR:
1719 return (dt_print_usym(dtp, fp, addr, act));
1721 case DTRACEACT_UMOD:
1722 return (dt_print_umod(dtp, fp, NULL, addr));
1725 return (dt_print_sym(dtp, fp, NULL, addr));
1728 return (dt_print_mod(dtp, fp, NULL, addr));
1730 case DTRACEAGG_QUANTIZE:
1731 return (dt_print_quantize(dtp, fp, addr, size, normal));
1733 case DTRACEAGG_LQUANTIZE:
1734 return (dt_print_lquantize(dtp, fp, addr, size, normal));
1737 return (dt_print_average(dtp, fp, addr, size, normal));
1739 case DTRACEAGG_STDDEV:
1740 return (dt_print_stddev(dtp, fp, addr, size, normal));
1747 case sizeof (uint64_t):
1748 err = dt_printf(dtp, fp, " %16lld",
1749 /* LINTED - alignment */
1750 (long long)*((uint64_t *)addr) / normal);
1752 case sizeof (uint32_t):
1753 /* LINTED - alignment */
1754 err = dt_printf(dtp, fp, " %8d", *((uint32_t *)addr) /
1757 case sizeof (uint16_t):
1758 /* LINTED - alignment */
1759 err = dt_printf(dtp, fp, " %5d", *((uint16_t *)addr) /
1762 case sizeof (uint8_t):
1763 err = dt_printf(dtp, fp, " %3d", *((uint8_t *)addr) /
1767 err = dt_print_bytes(dtp, fp, addr, size, 50, 0, 0);
1775 dt_print_aggs(const dtrace_aggdata_t **aggsdata, int naggvars, void *arg)
1778 dt_print_aggdata_t *pd = arg;
1779 const dtrace_aggdata_t *aggdata = aggsdata[0];
1780 dtrace_aggdesc_t *agg = aggdata->dtada_desc;
1781 FILE *fp = pd->dtpa_fp;
1782 dtrace_hdl_t *dtp = pd->dtpa_dtp;
1783 dtrace_recdesc_t *rec;
1784 dtrace_actkind_t act;
1789 * Iterate over each record description in the key, printing the traced
1790 * data, skipping the first datum (the tuple member created by the
1793 for (i = 1; i < agg->dtagd_nrecs; i++) {
1794 rec = &agg->dtagd_rec[i];
1795 act = rec->dtrd_action;
1796 addr = aggdata->dtada_data + rec->dtrd_offset;
1797 size = rec->dtrd_size;
1799 if (DTRACEACT_ISAGG(act)) {
1804 if (dt_print_datum(dtp, fp, rec, addr, size, 1) < 0)
1807 if (dt_buffered_flush(dtp, NULL, rec, aggdata,
1808 DTRACE_BUFDATA_AGGKEY) < 0)
1812 assert(aggact != 0);
1814 for (i = (naggvars == 1 ? 0 : 1); i < naggvars; i++) {
1817 aggdata = aggsdata[i];
1818 agg = aggdata->dtada_desc;
1819 rec = &agg->dtagd_rec[aggact];
1820 act = rec->dtrd_action;
1821 addr = aggdata->dtada_data + rec->dtrd_offset;
1822 size = rec->dtrd_size;
1824 assert(DTRACEACT_ISAGG(act));
1825 normal = aggdata->dtada_normal;
1827 if (dt_print_datum(dtp, fp, rec, addr, size, normal) < 0)
1830 if (dt_buffered_flush(dtp, NULL, rec, aggdata,
1831 DTRACE_BUFDATA_AGGVAL) < 0)
1834 if (!pd->dtpa_allunprint)
1835 agg->dtagd_flags |= DTRACE_AGD_PRINTED;
1838 if (dt_printf(dtp, fp, "\n") < 0)
1841 if (dt_buffered_flush(dtp, NULL, NULL, aggdata,
1842 DTRACE_BUFDATA_AGGFORMAT | DTRACE_BUFDATA_AGGLAST) < 0)
1849 dt_print_agg(const dtrace_aggdata_t *aggdata, void *arg)
1851 dt_print_aggdata_t *pd = arg;
1852 dtrace_aggdesc_t *agg = aggdata->dtada_desc;
1853 dtrace_aggvarid_t aggvarid = pd->dtpa_id;
1855 if (pd->dtpa_allunprint) {
1856 if (agg->dtagd_flags & DTRACE_AGD_PRINTED)
1860 * If we're not printing all unprinted aggregations, then the
1861 * aggregation variable ID denotes a specific aggregation
1862 * variable that we should print -- skip any other aggregations
1863 * that we encounter.
1865 if (agg->dtagd_nrecs == 0)
1868 if (aggvarid != agg->dtagd_varid)
1872 return (dt_print_aggs(&aggdata, 1, arg));
1876 dt_setopt(dtrace_hdl_t *dtp, const dtrace_probedata_t *data,
1877 const char *option, const char *value)
1882 dtrace_setoptdata_t optdata;
1884 bzero(&optdata, sizeof (optdata));
1885 (void) dtrace_getopt(dtp, option, &optdata.dtsda_oldval);
1887 if (dtrace_setopt(dtp, option, value) == 0) {
1888 (void) dtrace_getopt(dtp, option, &optdata.dtsda_newval);
1889 optdata.dtsda_probe = data;
1890 optdata.dtsda_option = option;
1891 optdata.dtsda_handle = dtp;
1893 if ((rval = dt_handle_setopt(dtp, &optdata)) != 0)
1899 errstr = dtrace_errmsg(dtp, dtrace_errno(dtp));
1900 len = strlen(option) + strlen(value) + strlen(errstr) + 80;
1903 (void) snprintf(msg, len, "couldn't set option \"%s\" to \"%s\": %s\n",
1904 option, value, errstr);
1906 if ((rval = dt_handle_liberr(dtp, data, msg)) == 0)
1913 dt_consume_cpu(dtrace_hdl_t *dtp, FILE *fp, int cpu, dtrace_bufdesc_t *buf,
1914 dtrace_consume_probe_f *efunc, dtrace_consume_rec_f *rfunc, void *arg)
1917 size_t offs, start = buf->dtbd_oldest, end = buf->dtbd_size;
1918 int flow = (dtp->dt_options[DTRACEOPT_FLOWINDENT] != DTRACEOPT_UNSET);
1919 int quiet = (dtp->dt_options[DTRACEOPT_QUIET] != DTRACEOPT_UNSET);
1921 dtrace_epid_t last = DTRACE_EPIDNONE;
1922 dtrace_probedata_t data;
1926 bzero(&data, sizeof (data));
1927 data.dtpda_handle = dtp;
1928 data.dtpda_cpu = cpu;
1931 for (offs = start; offs < end; ) {
1932 dtrace_eprobedesc_t *epd;
1935 * We're guaranteed to have an ID.
1937 id = *(uint32_t *)((uintptr_t)buf->dtbd_data + offs);
1939 if (id == DTRACE_EPIDNONE) {
1941 * This is filler to assure proper alignment of the
1942 * next record; we simply ignore it.
1944 offs += sizeof (id);
1948 if ((rval = dt_epid_lookup(dtp, id, &data.dtpda_edesc,
1949 &data.dtpda_pdesc)) != 0)
1952 epd = data.dtpda_edesc;
1953 data.dtpda_data = buf->dtbd_data + offs;
1955 if (data.dtpda_edesc->dtepd_uarg != DT_ECB_DEFAULT) {
1956 rval = dt_handle(dtp, &data);
1958 if (rval == DTRACE_CONSUME_NEXT)
1961 if (rval == DTRACE_CONSUME_ERROR)
1966 (void) dt_flowindent(dtp, &data, last, buf, offs);
1968 rval = (*efunc)(&data, arg);
1971 if (data.dtpda_flow == DTRACEFLOW_ENTRY)
1972 data.dtpda_indent += 2;
1975 if (rval == DTRACE_CONSUME_NEXT)
1978 if (rval == DTRACE_CONSUME_ABORT)
1979 return (dt_set_errno(dtp, EDT_DIRABORT));
1981 if (rval != DTRACE_CONSUME_THIS)
1982 return (dt_set_errno(dtp, EDT_BADRVAL));
1984 for (i = 0; i < epd->dtepd_nrecs; i++) {
1985 dtrace_recdesc_t *rec = &epd->dtepd_rec[i];
1986 dtrace_actkind_t act = rec->dtrd_action;
1988 data.dtpda_data = buf->dtbd_data + offs +
1990 addr = data.dtpda_data;
1992 if (act == DTRACEACT_LIBACT) {
1993 uint64_t arg = rec->dtrd_arg;
1994 dtrace_aggvarid_t id;
1998 /* LINTED - alignment */
1999 id = *((dtrace_aggvarid_t *)addr);
2000 (void) dtrace_aggregate_walk(dtp,
2004 case DT_ACT_DENORMALIZE:
2005 /* LINTED - alignment */
2006 id = *((dtrace_aggvarid_t *)addr);
2007 (void) dtrace_aggregate_walk(dtp,
2008 dt_denormalize_agg, &id);
2011 case DT_ACT_FTRUNCATE:
2016 (void) ftruncate(fileno(fp), 0);
2017 (void) fseeko(fp, 0, SEEK_SET);
2020 case DT_ACT_NORMALIZE:
2021 if (i == epd->dtepd_nrecs - 1)
2022 return (dt_set_errno(dtp,
2025 if (dt_normalize(dtp,
2026 buf->dtbd_data + offs, rec) != 0)
2032 case DT_ACT_SETOPT: {
2033 uint64_t *opts = dtp->dt_options;
2034 dtrace_recdesc_t *valrec;
2039 if (i == epd->dtepd_nrecs - 1) {
2040 return (dt_set_errno(dtp,
2044 valrec = &epd->dtepd_rec[++i];
2045 valsize = valrec->dtrd_size;
2047 if (valrec->dtrd_action != act ||
2048 valrec->dtrd_arg != arg) {
2049 return (dt_set_errno(dtp,
2053 if (valsize > sizeof (uint64_t)) {
2054 val = buf->dtbd_data + offs +
2055 valrec->dtrd_offset;
2060 rv = dt_setopt(dtp, &data, addr, val);
2065 flow = (opts[DTRACEOPT_FLOWINDENT] !=
2067 quiet = (opts[DTRACEOPT_QUIET] !=
2074 if (i == epd->dtepd_nrecs - 1)
2075 return (dt_set_errno(dtp,
2079 buf->dtbd_data + offs, rec) != 0)
2090 rval = (*rfunc)(&data, rec, arg);
2092 if (rval == DTRACE_CONSUME_NEXT)
2095 if (rval == DTRACE_CONSUME_ABORT)
2096 return (dt_set_errno(dtp, EDT_DIRABORT));
2098 if (rval != DTRACE_CONSUME_THIS)
2099 return (dt_set_errno(dtp, EDT_BADRVAL));
2101 if (act == DTRACEACT_STACK) {
2102 int depth = rec->dtrd_arg;
2104 if (dt_print_stack(dtp, fp, NULL, addr, depth,
2105 rec->dtrd_size / depth) < 0)
2110 if (act == DTRACEACT_USTACK ||
2111 act == DTRACEACT_JSTACK) {
2112 if (dt_print_ustack(dtp, fp, NULL,
2113 addr, rec->dtrd_arg) < 0)
2118 if (act == DTRACEACT_SYM) {
2119 if (dt_print_sym(dtp, fp, NULL, addr) < 0)
2124 if (act == DTRACEACT_MOD) {
2125 if (dt_print_mod(dtp, fp, NULL, addr) < 0)
2130 if (act == DTRACEACT_USYM || act == DTRACEACT_UADDR) {
2131 if (dt_print_usym(dtp, fp, addr, act) < 0)
2136 if (act == DTRACEACT_UMOD) {
2137 if (dt_print_umod(dtp, fp, NULL, addr) < 0)
2142 if (act == DTRACEACT_PRINTM) {
2143 if (dt_print_memory(dtp, fp, addr) < 0)
2148 if (act == DTRACEACT_PRINTT) {
2149 if (dt_print_type(dtp, fp, addr) < 0)
2154 if (DTRACEACT_ISPRINTFLIKE(act)) {
2156 int (*func)(dtrace_hdl_t *, FILE *, void *,
2157 const dtrace_probedata_t *,
2158 const dtrace_recdesc_t *, uint_t,
2159 const void *buf, size_t);
2161 if ((fmtdata = dt_format_lookup(dtp,
2162 rec->dtrd_format)) == NULL)
2166 case DTRACEACT_PRINTF:
2167 func = dtrace_fprintf;
2169 case DTRACEACT_PRINTA:
2170 func = dtrace_fprinta;
2172 case DTRACEACT_SYSTEM:
2173 func = dtrace_system;
2175 case DTRACEACT_FREOPEN:
2176 func = dtrace_freopen;
2180 n = (*func)(dtp, fp, fmtdata, &data,
2181 rec, epd->dtepd_nrecs - i,
2182 (uchar_t *)buf->dtbd_data + offs,
2183 buf->dtbd_size - offs);
2186 return (-1); /* errno is set for us */
2194 if (act == DTRACEACT_PRINTA) {
2195 dt_print_aggdata_t pd;
2196 dtrace_aggvarid_t *aggvars;
2197 int j, naggvars = 0;
2198 size_t size = ((epd->dtepd_nrecs - i) *
2199 sizeof (dtrace_aggvarid_t));
2201 if ((aggvars = dt_alloc(dtp, size)) == NULL)
2205 * This might be a printa() with multiple
2206 * aggregation variables. We need to scan
2207 * forward through the records until we find
2208 * a record from a different statement.
2210 for (j = i; j < epd->dtepd_nrecs; j++) {
2211 dtrace_recdesc_t *nrec;
2214 nrec = &epd->dtepd_rec[j];
2216 if (nrec->dtrd_uarg != rec->dtrd_uarg)
2219 if (nrec->dtrd_action != act) {
2220 return (dt_set_errno(dtp,
2224 naddr = buf->dtbd_data + offs +
2227 aggvars[naggvars++] =
2228 /* LINTED - alignment */
2229 *((dtrace_aggvarid_t *)naddr);
2233 bzero(&pd, sizeof (pd));
2237 assert(naggvars >= 1);
2239 if (naggvars == 1) {
2240 pd.dtpa_id = aggvars[0];
2241 dt_free(dtp, aggvars);
2243 if (dt_printf(dtp, fp, "\n") < 0 ||
2244 dtrace_aggregate_walk_sorted(dtp,
2245 dt_print_agg, &pd) < 0)
2250 if (dt_printf(dtp, fp, "\n") < 0 ||
2251 dtrace_aggregate_walk_joined(dtp, aggvars,
2252 naggvars, dt_print_aggs, &pd) < 0) {
2253 dt_free(dtp, aggvars);
2257 dt_free(dtp, aggvars);
2261 switch (rec->dtrd_size) {
2262 case sizeof (uint64_t):
2263 n = dt_printf(dtp, fp,
2264 quiet ? "%lld" : " %16lld",
2265 /* LINTED - alignment */
2266 *((unsigned long long *)addr));
2268 case sizeof (uint32_t):
2269 n = dt_printf(dtp, fp, quiet ? "%d" : " %8d",
2270 /* LINTED - alignment */
2271 *((uint32_t *)addr));
2273 case sizeof (uint16_t):
2274 n = dt_printf(dtp, fp, quiet ? "%d" : " %5d",
2275 /* LINTED - alignment */
2276 *((uint16_t *)addr));
2278 case sizeof (uint8_t):
2279 n = dt_printf(dtp, fp, quiet ? "%d" : " %3d",
2280 *((uint8_t *)addr));
2283 n = dt_print_bytes(dtp, fp, addr,
2284 rec->dtrd_size, 33, quiet, 0);
2289 return (-1); /* errno is set for us */
2292 if (dt_buffered_flush(dtp, &data, rec, NULL, 0) < 0)
2293 return (-1); /* errno is set for us */
2297 * Call the record callback with a NULL record to indicate
2298 * that we're done processing this EPID.
2300 rval = (*rfunc)(&data, NULL, arg);
2302 offs += epd->dtepd_size;
2306 if (buf->dtbd_oldest != 0 && start == buf->dtbd_oldest) {
2307 end = buf->dtbd_oldest;
2312 if ((drops = buf->dtbd_drops) == 0)
2316 * Explicitly zero the drops to prevent us from processing them again.
2318 buf->dtbd_drops = 0;
2320 return (dt_handle_cpudrop(dtp, cpu, DTRACEDROP_PRINCIPAL, drops));
2323 typedef struct dt_begin {
2324 dtrace_consume_probe_f *dtbgn_probefunc;
2325 dtrace_consume_rec_f *dtbgn_recfunc;
2327 dtrace_handle_err_f *dtbgn_errhdlr;
2329 int dtbgn_beginonly;
2333 dt_consume_begin_probe(const dtrace_probedata_t *data, void *arg)
2335 dt_begin_t *begin = (dt_begin_t *)arg;
2336 dtrace_probedesc_t *pd = data->dtpda_pdesc;
2338 int r1 = (strcmp(pd->dtpd_provider, "dtrace") == 0);
2339 int r2 = (strcmp(pd->dtpd_name, "BEGIN") == 0);
2341 if (begin->dtbgn_beginonly) {
2343 return (DTRACE_CONSUME_NEXT);
2346 return (DTRACE_CONSUME_NEXT);
2350 * We have a record that we're interested in. Now call the underlying
2353 return (begin->dtbgn_probefunc(data, begin->dtbgn_arg));
2357 dt_consume_begin_record(const dtrace_probedata_t *data,
2358 const dtrace_recdesc_t *rec, void *arg)
2360 dt_begin_t *begin = (dt_begin_t *)arg;
2362 return (begin->dtbgn_recfunc(data, rec, begin->dtbgn_arg));
2366 dt_consume_begin_error(const dtrace_errdata_t *data, void *arg)
2368 dt_begin_t *begin = (dt_begin_t *)arg;
2369 dtrace_probedesc_t *pd = data->dteda_pdesc;
2371 int r1 = (strcmp(pd->dtpd_provider, "dtrace") == 0);
2372 int r2 = (strcmp(pd->dtpd_name, "BEGIN") == 0);
2374 if (begin->dtbgn_beginonly) {
2376 return (DTRACE_HANDLE_OK);
2379 return (DTRACE_HANDLE_OK);
2382 return (begin->dtbgn_errhdlr(data, begin->dtbgn_errarg));
2386 dt_consume_begin(dtrace_hdl_t *dtp, FILE *fp, dtrace_bufdesc_t *buf,
2387 dtrace_consume_probe_f *pf, dtrace_consume_rec_f *rf, void *arg)
2390 * There's this idea that the BEGIN probe should be processed before
2391 * everything else, and that the END probe should be processed after
2392 * anything else. In the common case, this is pretty easy to deal
2393 * with. However, a situation may arise where the BEGIN enabling and
2394 * END enabling are on the same CPU, and some enabling in the middle
2395 * occurred on a different CPU. To deal with this (blech!) we need to
2396 * consume the BEGIN buffer up until the end of the BEGIN probe, and
2397 * then set it aside. We will then process every other CPU, and then
2398 * we'll return to the BEGIN CPU and process the rest of the data
2399 * (which will inevitably include the END probe, if any). Making this
2400 * even more complicated (!) is the library's ERROR enabling. Because
2401 * this enabling is processed before we even get into the consume call
2402 * back, any ERROR firing would result in the library's ERROR enabling
2403 * being processed twice -- once in our first pass (for BEGIN probes),
2404 * and again in our second pass (for everything but BEGIN probes). To
2405 * deal with this, we interpose on the ERROR handler to assure that we
2406 * only process ERROR enablings induced by BEGIN enablings in the
2407 * first pass, and that we only process ERROR enablings _not_ induced
2408 * by BEGIN enablings in the second pass.
2411 processorid_t cpu = dtp->dt_beganon;
2412 dtrace_bufdesc_t nbuf;
2414 dtrace_bufdesc_t *pbuf;
2417 static int max_ncpus;
2418 dtrace_optval_t size;
2420 dtp->dt_beganon = -1;
2423 if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, buf) == -1) {
2425 if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, &buf) == -1) {
2428 * We really don't expect this to fail, but it is at least
2429 * technically possible for this to fail with ENOENT. In this
2430 * case, we just drive on...
2432 if (errno == ENOENT)
2435 return (dt_set_errno(dtp, errno));
2438 if (!dtp->dt_stopped || buf->dtbd_cpu != dtp->dt_endedon) {
2440 * This is the simple case. We're either not stopped, or if
2441 * we are, we actually processed any END probes on another
2442 * CPU. We can simply consume this buffer and return.
2444 return (dt_consume_cpu(dtp, fp, cpu, buf, pf, rf, arg));
2447 begin.dtbgn_probefunc = pf;
2448 begin.dtbgn_recfunc = rf;
2449 begin.dtbgn_arg = arg;
2450 begin.dtbgn_beginonly = 1;
2453 * We need to interpose on the ERROR handler to be sure that we
2454 * only process ERRORs induced by BEGIN.
2456 begin.dtbgn_errhdlr = dtp->dt_errhdlr;
2457 begin.dtbgn_errarg = dtp->dt_errarg;
2458 dtp->dt_errhdlr = dt_consume_begin_error;
2459 dtp->dt_errarg = &begin;
2461 rval = dt_consume_cpu(dtp, fp, cpu, buf, dt_consume_begin_probe,
2462 dt_consume_begin_record, &begin);
2464 dtp->dt_errhdlr = begin.dtbgn_errhdlr;
2465 dtp->dt_errarg = begin.dtbgn_errarg;
2471 * Now allocate a new buffer. We'll use this to deal with every other
2474 bzero(&nbuf, sizeof (dtrace_bufdesc_t));
2475 (void) dtrace_getopt(dtp, "bufsize", &size);
2476 if ((nbuf.dtbd_data = malloc(size)) == NULL)
2477 return (dt_set_errno(dtp, EDT_NOMEM));
2480 max_ncpus = dt_sysconf(dtp, _SC_CPUID_MAX) + 1;
2482 for (i = 0; i < max_ncpus; i++) {
2489 if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, &nbuf) == -1) {
2492 if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, &pbuf) == -1) {
2495 * If we failed with ENOENT, it may be because the
2496 * CPU was unconfigured -- this is okay. Any other
2497 * error, however, is unexpected.
2499 if (errno == ENOENT)
2502 free(nbuf.dtbd_data);
2504 return (dt_set_errno(dtp, errno));
2507 if ((rval = dt_consume_cpu(dtp, fp,
2508 i, &nbuf, pf, rf, arg)) != 0) {
2509 free(nbuf.dtbd_data);
2514 free(nbuf.dtbd_data);
2517 * Okay -- we're done with the other buffers. Now we want to
2518 * reconsume the first buffer -- but this time we're looking for
2519 * everything _but_ BEGIN. And of course, in order to only consume
2520 * those ERRORs _not_ associated with BEGIN, we need to reinstall our
2521 * ERROR interposition function...
2523 begin.dtbgn_beginonly = 0;
2525 assert(begin.dtbgn_errhdlr == dtp->dt_errhdlr);
2526 assert(begin.dtbgn_errarg == dtp->dt_errarg);
2527 dtp->dt_errhdlr = dt_consume_begin_error;
2528 dtp->dt_errarg = &begin;
2530 rval = dt_consume_cpu(dtp, fp, cpu, buf, dt_consume_begin_probe,
2531 dt_consume_begin_record, &begin);
2533 dtp->dt_errhdlr = begin.dtbgn_errhdlr;
2534 dtp->dt_errarg = begin.dtbgn_errarg;
2540 dtrace_consume(dtrace_hdl_t *dtp, FILE *fp,
2541 dtrace_consume_probe_f *pf, dtrace_consume_rec_f *rf, void *arg)
2543 dtrace_bufdesc_t *buf = &dtp->dt_buf;
2544 dtrace_optval_t size;
2545 static int max_ncpus;
2547 dtrace_optval_t interval = dtp->dt_options[DTRACEOPT_SWITCHRATE];
2548 hrtime_t now = gethrtime();
2550 if (dtp->dt_lastswitch != 0) {
2551 if (now - dtp->dt_lastswitch < interval)
2554 dtp->dt_lastswitch += interval;
2556 dtp->dt_lastswitch = now;
2559 if (!dtp->dt_active)
2560 return (dt_set_errno(dtp, EINVAL));
2563 max_ncpus = dt_sysconf(dtp, _SC_CPUID_MAX) + 1;
2566 pf = (dtrace_consume_probe_f *)dt_nullprobe;
2569 rf = (dtrace_consume_rec_f *)dt_nullrec;
2571 if (buf->dtbd_data == NULL) {
2572 (void) dtrace_getopt(dtp, "bufsize", &size);
2573 if ((buf->dtbd_data = malloc(size)) == NULL)
2574 return (dt_set_errno(dtp, EDT_NOMEM));
2576 buf->dtbd_size = size;
2580 * If we have just begun, we want to first process the CPU that
2581 * executed the BEGIN probe (if any).
2583 if (dtp->dt_active && dtp->dt_beganon != -1) {
2584 buf->dtbd_cpu = dtp->dt_beganon;
2585 if ((rval = dt_consume_begin(dtp, fp, buf, pf, rf, arg)) != 0)
2589 for (i = 0; i < max_ncpus; i++) {
2593 * If we have stopped, we want to process the CPU on which the
2594 * END probe was processed only _after_ we have processed
2597 if (dtp->dt_stopped && (i == dtp->dt_endedon))
2601 if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, buf) == -1) {
2603 if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, &buf) == -1) {
2606 * If we failed with ENOENT, it may be because the
2607 * CPU was unconfigured -- this is okay. Any other
2608 * error, however, is unexpected.
2610 if (errno == ENOENT)
2613 return (dt_set_errno(dtp, errno));
2616 if ((rval = dt_consume_cpu(dtp, fp, i, buf, pf, rf, arg)) != 0)
2620 if (!dtp->dt_stopped)
2623 buf->dtbd_cpu = dtp->dt_endedon;
2626 if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, buf) == -1) {
2628 if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, &buf) == -1) {
2631 * This _really_ shouldn't fail, but it is strictly speaking
2632 * possible for this to return ENOENT if the CPU that called
2633 * the END enabling somehow managed to become unconfigured.
2634 * It's unclear how the user can possibly expect anything
2635 * rational to happen in this case -- the state has been thrown
2636 * out along with the unconfigured CPU -- so we'll just drive
2639 if (errno == ENOENT)
2642 return (dt_set_errno(dtp, errno));
2645 return (dt_consume_cpu(dtp, fp, dtp->dt_endedon, buf, pf, rf, arg));