14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The contents of this file are subject to the terms of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Common Development and Distribution License (the "License").
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You may not use this file except in compliance with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * When distributing Covered Code, include this CDDL HEADER in each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If applicable, add the following below this CDDL HEADER, with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * fields enclosed by brackets "[]" replaced with your own identifying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * information: Portions Copyright [yyyy] [name of copyright owner]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#else /* VBOX */
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif /* VBOX */
0fea9bc4af28518049902cca68d209af223a8e13vboxsync{ "Jan", "Feb", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
0fea9bc4af28518049902cca68d209af223a8e13vboxsync{ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_addr(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_pointer(dnp) || dt_node_is_integer(dnp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_kaddr(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_pointer(dnp) || dt_node_is_integer(dnp) ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_uaddr(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_ident_t *idp = dt_idhash_lookup(dtp->dt_macros, "target");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_pointer(dnp) || dt_node_is_integer(dnp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_stack(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_time(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_str(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (kind == CTF_K_ARRAY && ctf_array_info(ctfp, base, &r) == 0 &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (base = ctf_type_resolve(ctfp, r.ctr_contents)) != CTF_ERR &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_type_encoding(ctfp, base, &e) == 0 && IS_CHAR(e));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_wstr(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_id_t base = ctf_type_resolve(ctfp, dnp->dn_type);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (kind == CTF_K_ARRAY && ctf_array_info(ctfp, base, &r) == 0 &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (base = ctf_type_resolve(ctfp, r.ctr_contents)) != CTF_ERR &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_type_encoding(ctfp, base, &e) == 0 && e.cte_bits == 32);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_csi(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_fp(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_xint(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_dint(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_xshort(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_id_t type = ctf_type_resolve(ctfp, dnp->dn_type);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (ctf_type_name(ctfp, type, n, sizeof (n)) != NULL && (
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strcmp(n, "short") == 0 || strcmp(n, "signed short") == 0 ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_xlong(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_id_t type = ctf_type_resolve(ctfp, dnp->dn_type);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (ctf_type_name(ctfp, type, n, sizeof (n)) != NULL && (
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strcmp(n, "long") == 0 || strcmp(n, "signed long") == 0 ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_xlonglong(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ctf_type_name(ctfp, ctf_type_resolve(ctfp, type), n,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync sizeof (n)) != NULL && (strcmp(n, "long long") == 0 ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If the type used for %llx or %llX is not an [unsigned] long long, we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * also permit it to be a [u]int64_t or any typedef thereof. We know
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * that these typedefs are guaranteed to work with %ll[xX] in either
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * compilation environment even though they alias to "long" in LP64.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync while (ctf_type_kind(ctfp, type) == CTF_K_TYPEDEF) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ctf_type_name(ctfp, type, n, sizeof (n)) != NULL &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (strcmp(n, "int64_t") == 0 || strcmp(n, "uint64_t") == 0))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_type(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (ctf_type_compat(dnp->dn_ctfp, ctf_type_resolve(dnp->dn_ctfp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnp->dn_type), pfd->pfd_conv->pfc_dctfp, pfd->pfd_conv->pfc_dtype));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_sint(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t unormal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int8_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int16_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int64_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_uint(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint8_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint16_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint64_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_dint(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfprint_sint(dtp, fp, format, pfd, addr, size, normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfprint_uint(dtp, fp, format, pfd, addr, size, normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_fp(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync double n = (double)normal;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (float):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (double)*((float *)addr) / n));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (double):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *((double *)addr) / n));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (long double):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_addr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint64_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } while ((len = dtrace_addr2str(dtp, val, s, n)) > n);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_mod(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_print_mod(dtp, fp, format, (caddr_t)addr));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_umod(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_print_umod(dtp, fp, format, (caddr_t)addr));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_uaddr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_ident_t *idp = dt_idhash_lookup(dtp->dt_macros, "target");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint64_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pid == 0 && dtp->dt_vector == NULL && idp != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } while ((len = dtrace_uaddr2str(dtp, pid, val, s, n)) > n);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_stack(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *vaddr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_optval_t saved = dtp->dt_options[DTRACEOPT_STACKINDENT];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We have stashed the value of the STACKINDENT option, and we will
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * now override it for the purposes of formatting the stack. If the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * field has been specified as left-aligned (i.e. (%-#), we set the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * indentation to be the width. This is a slightly odd semantic, but
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * it's useful functionality -- and it's slightly odd to begin with to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * be using a single format specifier to be formatting multiple lines
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * of text...
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync width = pfd->pfd_dynwidth ? pfd->pfd_dynwidth : pfd->pfd_width;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync err = dt_print_ustack(dtp, fp, format, addr, rec->dtrd_arg);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync err = dt_print_stack(dtp, fp, format, addr, rec->dtrd_arg,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_time(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * ctime(3C) returns a string of the form "Dec 3 17:20:00 1973\n\0".
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Below, we turn this into the canonical adb/mdb /[yY] format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * "1973 Dec 3 17:20:00".
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Place the 4-digit year at the head of the string...
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * ...and follow it with the remainder (month, day, hh:mm:ss).
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTTimeLocalExplode(&Time, RTTimeSpecSetNano(&TimeSpec, *(uint64_t *)addr));
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTStrPrintf(buf, sizeof(buf), "%u %s %2u %02u:%02u:%02u",
0fea9bc4af28518049902cca68d209af223a8e13vboxsync Time.u8MonthDay, Time.u8Hour, Time.u8Minute, Time.u8Second);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * This prints the time in RFC 822 standard form. This is useful for emitting
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * notions of time that are consumed by standard tools (e.g., as part of an
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * RSS feed).
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_time822(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strftime(buf, sizeof (buf), "%a, %d %b %G %T %Z", &tm);
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTTimeLocalExplode(&Time, RTTimeSpecSetNano(&TimeSpec, *(uint64_t *)addr));
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTStrPrintf(buf, sizeof(buf), "%s, %u %s %u %02u:%02u:%02u %s%u%s",
0fea9bc4af28518049902cca68d209af223a8e13vboxsync g_aszDay[Time.u8WeekDay], Time.u8MonthDay, g_aszMonth[Time.u8Month - 1],
0fea9bc4af28518049902cca68d209af223a8e13vboxsync Time.offUTC >= 0 ? "UTC+" : "UTC", Time.offUTC / 60,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_port(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((sv = getservbyport_r(port, NULL, &res, buf, sizeof (buf))) != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(buf, sizeof (buf), "%d", *((uint16_t *)addr));
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTStrPrintf(buf, sizeof(buf), "%d", RT_N2H_U16(uPortNet));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_inetaddr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strchr(s, ':') == NULL && inet_pton(AF_INET, s, inetaddr) != -1) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else if (inet_pton(AF_INET6, s, inetaddr) != -1) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((host = getipnodebyaddr(inetaddr, NS_IN6ADDRSZ,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_cstr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_wstr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_estr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (n);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_echr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int8_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int16_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfprint_estr(dtp, fp, format, pfd, &c, 1, normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_pct(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const char pfproto_xint[] = "char, short, int, long, or long long";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const char pfproto_csi[] = "char, short, or int";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const char pfproto_fp[] = "float, double, or long double";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const char pfproto_addr[] = "pointer or integer";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "pointer or integer (with -p/-c) or _usymaddr (without -p/-c)";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const char pfproto_cstr[] = "char [] or string (or use stringof)";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Printf format conversion dictionary. This table should match the set of
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * conversions offered by printf(3C), as well as some additional extensions.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The second parameter is an ASCII string which is either an actual type
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * name we should look up (if pfcheck_type is specified), or just a descriptive
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * string of the types expected for use in error messages.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "a", "s", pfproto_addr, pfcheck_kaddr, pfprint_addr },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "A", "s", pfproto_uaddr, pfcheck_uaddr, pfprint_uaddr },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "c", "c", pfproto_csi, pfcheck_csi, pfprint_sint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "C", "s", pfproto_csi, pfcheck_csi, pfprint_echr },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "d", "d", pfproto_xint, pfcheck_dint, pfprint_dint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "ho", "o", "unsigned short", pfcheck_type, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "hu", "u", "unsigned short", pfcheck_type, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "hx", "x", "short", pfcheck_xshort, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "hX", "X", "short", pfcheck_xshort, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "i", "i", pfproto_xint, pfcheck_dint, pfprint_dint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "I", "s", pfproto_cstr, pfcheck_str, pfprint_inetaddr },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "k", "s", "stack", pfcheck_stack, pfprint_stack },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "lc", "lc", "int", pfcheck_type, pfprint_sint }, /* a.k.a. wint_t */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "lo", "o", "unsigned long", pfcheck_type, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "lu", "u", "unsigned long", pfcheck_type, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "ls", "ls", pfproto_wstr, pfcheck_wstr, pfprint_wstr },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "lld", "d", "long long", pfcheck_type, pfprint_sint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "lli", "i", "long long", pfcheck_type, pfprint_sint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "llo", "o", "unsigned long long", pfcheck_type, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "llu", "u", "unsigned long long", pfcheck_type, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "llx", "x", "long long", pfcheck_xlonglong, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "llX", "X", "long long", pfcheck_xlonglong, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "Le", "e", "long double", pfcheck_type, pfprint_fp },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "LE", "E", "long double", pfcheck_type, pfprint_fp },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "Lf", "f", "long double", pfcheck_type, pfprint_fp },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "Lg", "g", "long double", pfcheck_type, pfprint_fp },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "LG", "G", "long double", pfcheck_type, pfprint_fp },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "o", "o", pfproto_xint, pfcheck_xint, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "p", "x", pfproto_addr, pfcheck_addr, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "P", "s", "uint16_t", pfcheck_type, pfprint_port },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "s", "s", "char [] or string (or use stringof)", pfcheck_str, pfprint_cstr },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "S", "s", pfproto_cstr, pfcheck_str, pfprint_estr },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "T", "s", "int64_t", pfcheck_time, pfprint_time822 },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "u", "u", pfproto_xint, pfcheck_xint, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "wc", "wc", "int", pfcheck_type, pfprint_sint }, /* a.k.a. wchar_t */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "ws", "ws", pfproto_wstr, pfcheck_wstr, pfprint_wstr },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "x", "x", pfproto_xint, pfcheck_xint, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "X", "X", pfproto_xint, pfcheck_xint, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "Y", "s", "int64_t", pfcheck_time, pfprint_time },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pdi = malloc(sizeof (dt_pfdict_t))) == NULL ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (pdi->pdi_buckets = malloc(sizeof (dt_pfconv_t *) * n)) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bzero(pdi->pdi_buckets, sizeof (dt_pfconv_t *) * n);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (pfd = _dtrace_conversions; pfd->pfc_name != NULL; pfd++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfc = malloc(sizeof (dt_pfconv_t))) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The "D" container or its parent must contain a definition of
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * any type referenced by a printf conversion. If none can be
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * found, we fail to initialize the printf dictionary.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_check == &pfcheck_type && dtrace_lookup_by_type(
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp, DTRACE_OBJ_DDEFS, pfc->pfc_tstr, &dtt) != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The "C" container may contain an alternate definition of an
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * explicit conversion type. If it does, use it; otherwise
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * just set pfc_ctype to pfc_dtype so it is always valid.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_check == &pfcheck_type && dtrace_lookup_by_type(
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp, DTRACE_OBJ_CDEFS, pfc->pfc_tstr, &dtt) == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_check == NULL || pfc->pfc_print == NULL ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("loaded printf conversion %%%s\n", pfc->pfc_name);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (pfc = pdi->pdi_buckets[i]; pfc != NULL; pfc = nfc) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const dt_pfconv_t *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_pfdict_lookup(dtrace_hdl_t *dtp, const char *name)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t h = dt_strtab_hash(name, NULL) % pdi->pdi_nbuckets;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (pfc = pdi->pdi_buckets[h]; pfc != NULL; pfc = pfc->pfc_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *p, *q;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfv = malloc(sizeof (dt_pfargv_t))) == NULL ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (q = format; (p = strchr(q, '%')) != NULL; q = *p ? p + 1 : p) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfd = malloc(sizeof (dt_pfargd_t))) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (p > q) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (c = *++p) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (n = 0; isdigit(c); c = *++p)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "one '*' specified for the output %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dot++ != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yywarn("format conversion #%u name expected before "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yywarn("format conversion #%u is undefined: %%%s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfd = malloc(sizeof (dt_pfargd_t))) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (pfd = pfv->pfv_argv; pfd != NULL; pfd = nfd) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_ident_t *idp, int foff, dtrace_actkind_t kind, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We fake up a parse node representing the type that can be used with
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * an aggregation result conversion, which -- for all but count() --
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * is a signed quantity.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_TYPE_ERR, "failed to lookup agg type %s\n", aggtype);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_type_assign(&aggnode, dtt.dtt_ctfp, dtt.dtt_type);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0, j = 0; i < pfv->pfv_argc; i++, pfd = pfd->pfd_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue; /* no checking if argd is just a prefix */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) prototype mismatch: conversion "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "#%d (%%%s) is missing a corresponding "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) argument #%d is incompatible "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "with conversion #%d prototype:\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "\tconversion: %% %s %s\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "\t prototype: int\n\t argument: %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If this conversion is consuming the aggregation data, set
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * the value node pointer (vnp) to a fake node based on the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * aggregating function result type. Otherwise assign vnp to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * the next parse node in the argument list, if there is one.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%%@ conversion requires an aggregation"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) prototype mismatch: conversion #%d (%%"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s) is missing a corresponding value argument\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Fill in the proposed final format string by prepending any
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * size-related prefixes to the pfconv's format string. The
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * pfc_check() function below may optionally modify the format
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * as part of validating the type of the input argument.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_node_type_size(vnp) == sizeof (long double))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Validate the format conversion against the value node type.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If the conversion is good, create the descriptor format
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * string by concatenating together any required printf(3C)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * size prefixes with the conversion's native format string.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) %s is incompatible with "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "conversion #%d prototype:\n\tconversion: %%%s\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) prototype mismatch: only %d arguments "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * First, get an argument count on each side. These must match.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (largc = 0; lproto != NULL; lproto = lproto->dn_list)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (rargc = 0; rproto != NULL; rproto = rproto->dn_list)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PRINTA_AGGKEY, "printa( ): @%s and @%s do not have "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "matching key signatures: @%s has %d key%s, @%s has %d "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Now iterate over the keys to verify that each type matches.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (argn = 1; lproto != NULL; argn++, lproto = lproto->dn_list,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PRINTA_AGGPROTO, "printa( ): @%s[ ] key #%d is "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "incompatible with @%s:\n%9s key #%d: %s\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%9s key #%d: %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rid->di_name, argn, lid->di_name, lid->di_name, argn,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_type_name(lproto, n1, sizeof (n1)), rid->di_name,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_printf_getint(dtrace_hdl_t *dtp, const dtrace_recdesc_t *recp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t nrecs, const void *buf, size_t len, int *ip)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int8_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int16_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int64_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_average(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_stddev(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_quantize(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_print_quantize(dtp, fp, addr, size, normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfprint_lquantize(dtrace_hdl_t *dtp, FILE *fp, const char *format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_print_lquantize(dtp, fp, addr, size, normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_printf_format(dtrace_hdl_t *dtp, FILE *fp, const dt_pfargv_t *pfv,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_recdesc_t *recs, uint_t nrecs, const void *buf,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync size_t len, const dtrace_aggdata_t **aggsdata, int naggvars)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If we are formatting an aggregation, set 'aggrec' to the index of
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * the final record description (the aggregation result) so we can use
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * this record index with any conversion where DT_PFCONV_AGG is set.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (The actual aggregation used will vary as we increment through the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * aggregation variables that we have been passed.) Finally, we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * decrement nrecs to prevent this record from being used with any
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * other conversion.
0fea9bc4af28518049902cca68d209af223a8e13vboxsync for (i = 0; VBDTCAST(uint_t)i < pfv->pfv_argc; i++, pfd = pfd->pfd_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * For printa(), we flush the buffer after each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * prefix, setting the flags to indicate that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * this is part of the printa() format string.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (nrecs != 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If the conversion is %%, just invoke the print callback
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * with no data record and continue; it consumes no record.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_print(dtp, fp, NULL, pfd, NULL, 0, 1) >= 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfd->pfd_flags & DT_PFCONV_DYNPREC) && dt_printf_getint(
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * This should be impossible -- the compiler shouldn't
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * create a DT_PFCONV_AGG conversion without an
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * aggregation present. Still, we'd rather fail
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * gracefully than blow up...
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We increment the current aggregation variable, but
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * not beyond the number of aggregation variables that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * we're printing. This has the (desired) effect that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * DT_PFCONV_AGG conversions beyond the number of
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * aggregation variables (re-)convert the aggregation
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * value of the last aggregation variable.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * When printing aggregation keys, we always
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * set the aggdata to be the representative
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (zeroth) aggregation. The aggdata isn't
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * actually used here in this case, but it is
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * passed to the buffer handler and must
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * therefore still be correct.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ((uintptr_t)addr & (rec->dtrd_alignment - 1)) != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("bad align: addr=%p size=0x%x align=0x%x\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void *)addr, rec->dtrd_size, rec->dtrd_alignment);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '#';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '0';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (width < 0 || (pfd->pfd_flags & DT_PFCONV_LEFT))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '-';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '+';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '\'';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = ' ';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If we're printing a stack and DT_PFCONV_LEFT is set, we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * don't add the width to the format string. See the block
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * comment in pfprint_stack() for a description of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * behavior in this case.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (func == pfprint_stack && (pfd->pfd_flags & DT_PFCONV_LEFT))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync f += snprintf(f, sizeof (format), "%d", ABS(width));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (func(dtp, fp, format, pfd, addr, size, normal) < 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * For printa(), we flush the buffer after each tuple
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * element, inidicating that this is the last record
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * as appropriate.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_sprintf(dtrace_hdl_t *dtp, FILE *fp, void *fmtdata,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_recdesc_t *recp, uint_t nrecs, const void *buf, size_t len)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rval = dt_printf_format(dtp, fp, fmtdata, recp, nrecs, buf, len,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_system(dtrace_hdl_t *dtp, FILE *fp, void *fmtdata,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_probedata_t *data, const dtrace_recdesc_t *recp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int rval = dtrace_sprintf(dtp, fp, fmtdata, recp, nrecs, buf, len);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Before we execute the specified command, flush fp to assure that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * any prior dt_printf()'s appear before the output of the command
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * not after it.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_freopen(dtrace_hdl_t *dtp, FILE *fp, void *fmtdata,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_probedata_t *data, const dtrace_recdesc_t *recp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rval = dtrace_sprintf(dtp, fp, fmtdata, recp, nrecs, buf, len);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strcmp(pfd->pfd_prefix, DT_FREOPEN_RESTORE) == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The only way to have the format string set to the value
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * DT_FREOPEN_RESTORE is via the empty freopen() string --
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * denoting that we should restore the old stdout.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(strcmp(dtp->dt_sprintf_buf, DT_FREOPEN_RESTORE) == 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We could complain here by generating an error,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * but it seems like overkill: it seems that calling
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * freopen() to restore stdout when freopen() has
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * never before been called should just be a no-op,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * so we just return in this case.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * freopen(3C) will always close the specified stream and underlying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * file descriptor -- even if the specified file can't be opened.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Even for the semantic cesspool that is standard I/O, this is
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * surprisingly brain-dead behavior: it means that any failure to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * open the specified file destroys the specified stream in the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * process -- which is particularly relevant when the specified stream
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * happens (or rather, happened) to be stdout. This could be resolved
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * were there an "fdreopen()" equivalent of freopen() that allowed one
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * to pass a file descriptor instead of the name of a file, but there
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * is no such thing. However, we can effect this ourselves by first
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * fopen()'ing the desired file, and then (assuming that that works),
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * freopen()'ing "/dev/fd/[fileno]", where [fileno] is the underlying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * file descriptor for the fopen()'d file. This way, if the fopen()
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * fails, we can fail the operation without destroying stdout.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(faultstr, len, "couldn't freopen() \"%s\": %s",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((errval = dt_handle_liberr(dtp, data, faultstr)) == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(selfbuf, sizeof (selfbuf), "/dev/fd/%d", fileno(nfp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If this is the first time that we're calling freopen(),
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * we're going to stash away the file descriptor for stdout.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We don't expect the dup(2) to fail, so if it does we must
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * return failure.
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#else /* VBOX - the above is not easily portable because of /dev/fd/xxx. */
0fea9bc4af28518049902cca68d209af223a8e13vboxsync if ((errval = dt_handle_liberr(dtp, data, "reopening stdout is not implemented")) == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_fprintf(dtrace_hdl_t *dtp, FILE *fp, void *fmtdata,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_probedata_t *data, const dtrace_recdesc_t *recp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_printf_create(dtrace_hdl_t *dtp, const char *s)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; i < pfv->pfv_argc; i++, pfd = pfd->pfd_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If the output format is not %s then we assume that we have
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * been given a correctly-sized format string, so we copy the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * true format name including the size modifier. If the output
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * format is %s, then either the input format is %s as well or
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * it is one of our custom formats (e.g. pfprint_addr), so we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * must set pfd_fmt to be the output format conversion "s".
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_printa_create(dtrace_hdl_t *dtp, const char *s)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_printf_format(dtrace_hdl_t *dtp, void *fmtdata, char *s, size_t len)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * An upper bound on the string length is the length of the original
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * format string, plus three times the number of conversions (each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * conversion could add up an additional "ll" and/or pfd_width digit
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * in the case of converting %? to %16) plus one for a terminating \0.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync size_t formatlen = strlen(pfv->pfv_format) + 3 * pfv->pfv_argc + 1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; i < pfv->pfv_argc; i++, pfd = pfd->pfd_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '%';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '#';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '0';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '-';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '+';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '*';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '.';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '*';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '\'';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = ' ';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '@';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If the output format is %s, then either %s is the underlying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * conversion or the conversion is one of our customized ones,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * e.g. pfprint_addr. In these cases, put the original string
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * name of the conversion (pfc_name) into the pickled format
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * string rather than the derived conversion (pfd_fmt).
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f = '\0'; /* insert nul byte; do not count in return value */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync adp->dtada_data, adp->dtada_size, &id) != 0 || pfw->pfw_aid != id)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0); /* no aggregation id or id does not match */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_printf_format(dtp, pfw->pfw_fp, pfw->pfw_argv,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync recp, nrecs, adp->dtada_data, adp->dtada_size, &adp, 1) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Cast away the const to set the bit indicating that this aggregation
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * has been printed.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ((dtrace_aggdesc_t *)agg)->dtagd_flags |= DTRACE_AGD_PRINTED;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_fprintas(const dtrace_aggdata_t **aggsdata, int naggvars, void *arg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_printf_format(dtp, pfw->pfw_fp, pfw->pfw_argv,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rec, nrecs, aggdata->dtada_data, aggdata->dtada_size,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * For each aggregation, indicate that it has been printed, casting
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * away the const as necessary.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ((dtrace_aggdesc_t *)agg)->dtagd_flags |= DTRACE_AGD_PRINTED;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_fprinta(dtrace_hdl_t *dtp, FILE *fp, void *fmtdata,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_probedata_t *data, const dtrace_recdesc_t *recs,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggvars = alloca(nrecs * sizeof (dtrace_aggvarid_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * This might be a printa() with multiple aggregation variables. We
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * need to scan forward through the records until we find a record from
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * a different statement.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /* LINTED - alignment */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *((dtrace_aggvarid_t *)((caddr_t)buf + nrec->dtrd_offset));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_aggregate_walk_joined(dtp, aggvars, naggvars,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (i);