14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
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 *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * or http://www.opensolaris.org/os/licensing.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
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 *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/sysmacros.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <strings.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <stdlib.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <alloca.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <assert.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <ctype.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <errno.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <limits.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/socket.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <netdb.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <netinet/in.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <arpa/inet.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <arpa/nameser.h>
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#else /* VBOX */
0fea9bc4af28518049902cca68d209af223a8e13vboxsync# include <iprt/asm.h>
0fea9bc4af28518049902cca68d209af223a8e13vboxsync# include <ctype.h>
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif /* VBOX */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <dt_printf.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <dt_string.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <dt_impl.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifdef VBOX
0fea9bc4af28518049902cca68d209af223a8e13vboxsyncstatic const char g_aszMonth[12][4] =
0fea9bc4af28518049902cca68d209af223a8e13vboxsync{ "Jan", "Feb", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
0fea9bc4af28518049902cca68d209af223a8e13vboxsyncstatic const char g_aszDay[7][4] =
0fea9bc4af28518049902cca68d209af223a8e13vboxsync{ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif
0fea9bc4af28518049902cca68d209af223a8e13vboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_addr(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_pointer(dnp) || dt_node_is_integer(dnp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_kaddr(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_pointer(dnp) || dt_node_is_integer(dnp) ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_is_symaddr(dnp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_uaddr(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_hdl_t *dtp = pfv->pfv_dtp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_ident_t *idp = dt_idhash_lookup(dtp->dt_macros, "target");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_node_is_usymaddr(dnp))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (idp == NULL || idp->di_id == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_pointer(dnp) || dt_node_is_integer(dnp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_stack(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_stack(dnp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_time(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_integer(dnp) &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_type_size(dnp) == sizeof (uint64_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_str(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_file_t *ctfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_encoding_t e;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_arinfo_t r;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_id_t base;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t kind;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_node_is_string(dnp))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctfp = dnp->dn_ctfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync base = ctf_type_resolve(ctfp, dnp->dn_type);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync kind = ctf_type_kind(ctfp, base);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
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}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_wstr(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_file_t *ctfp = dnp->dn_ctfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_id_t base = ctf_type_resolve(ctfp, dnp->dn_type);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t kind = ctf_type_kind(ctfp, base);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_encoding_t e;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_arinfo_t r;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
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_kind(ctfp, base) == CTF_K_INTEGER &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_type_encoding(ctfp, base, &e) == 0 && e.cte_bits == 32);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_csi(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_integer(dnp) &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_type_size(dnp) <= sizeof (int));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_fp(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_float(dnp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_xint(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_integer(dnp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_dint(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dnp->dn_flags & DT_NF_SIGNED)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags |= DT_PFCONV_SIGNED;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_fmt[strlen(pfd->pfd_fmt) - 1] = 'u';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_node_is_integer(dnp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_xshort(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_file_t *ctfp = dnp->dn_ctfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_id_t type = ctf_type_resolve(ctfp, dnp->dn_type);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char n[DT_TYPE_NAMELEN];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (ctf_type_name(ctfp, type, n, sizeof (n)) != NULL && (
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strcmp(n, "short") == 0 || strcmp(n, "signed short") == 0 ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strcmp(n, "unsigned short") == 0));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_xlong(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_file_t *ctfp = dnp->dn_ctfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_id_t type = ctf_type_resolve(ctfp, dnp->dn_type);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char n[DT_TYPE_NAMELEN];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (ctf_type_name(ctfp, type, n, sizeof (n)) != NULL && (
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strcmp(n, "long") == 0 || strcmp(n, "signed long") == 0 ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strcmp(n, "unsigned long") == 0));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_xlonglong(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_file_t *ctfp = dnp->dn_ctfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_id_t type = dnp->dn_type;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char n[DT_TYPE_NAMELEN];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ctf_type_name(ctfp, ctf_type_resolve(ctfp, type), n,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync sizeof (n)) != NULL && (strcmp(n, "long long") == 0 ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strcmp(n, "signed long long") == 0 ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strcmp(n, "unsigned long long") == 0))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
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
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync type = ctf_type_reference(ctfp, type);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncpfcheck_type(dt_pfargv_t *pfv, dt_pfargd_t *pfd, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
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}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int64_t normal = (int64_t)unormal;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int32_t n = (int32_t)normal;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (size) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int8_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (int32_t)*((int8_t *)addr) / n));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int16_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (int32_t)*((int16_t *)addr) / n));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *((int32_t *)addr) / n));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int64_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *((int64_t *)addr) / normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint32_t n = (uint32_t)normal;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (size) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint8_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (uint32_t)*((uint8_t *)addr) / n));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint16_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (uint32_t)*((uint16_t *)addr) / n));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *((uint32_t *)addr) / n));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint64_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *((uint64_t *)addr) / normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_SIGNED)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfprint_sint(dtp, fp, format, pfd, addr, size, normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfprint_uint(dtp, fp, format, pfd, addr, size, normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync double n = (double)normal;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync long double ldn = (long double)normal;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (size) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (float):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (double)*((float *)addr) / n));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (double):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *((double *)addr) / n));
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifndef _MSC_VER
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (long double):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *((long double *)addr) / ldn));
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *s;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int n, len = 256;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint64_t val;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (size) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync val = *((uint32_t *)addr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint64_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync val = *((uint64_t *)addr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync do {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync n = len;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync s = alloca(n);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } while ((len = dtrace_addr2str(dtp, val, s, n)) > n);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, s));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_print_mod(dtp, fp, format, (caddr_t)addr));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_print_umod(dtp, fp, format, (caddr_t)addr));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *s;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int n, len = 256;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint64_t val, pid = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_ident_t *idp = dt_idhash_lookup(dtp->dt_macros, "target");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (size) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync val = (u_longlong_t)*((uint32_t *)addr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint64_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync val = (u_longlong_t)*((uint64_t *)addr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (uint64_t) * 2:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pid = ((uint64_t *)(uintptr_t)addr)[0];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync val = ((uint64_t *)(uintptr_t)addr)[1];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pid == 0 && dtp->dt_vector == NULL && idp != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pid = idp->di_id;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync do {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync n = len;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync s = alloca(n);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } while ((len = dtrace_uaddr2str(dtp, pid, val, s, n)) > n);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, s));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int width;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_optval_t saved = dtp->dt_options[DTRACEOPT_STACKINDENT];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_recdesc_t *rec = pfd->pfd_rec;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync caddr_t addr = (caddr_t)vaddr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int err = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_dynwidth < 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(pfd->pfd_flags & DT_PFCONV_DYNWIDTH);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync width = -pfd->pfd_dynwidth;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else if (pfd->pfd_flags & DT_PFCONV_LEFT) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync width = pfd->pfd_dynwidth ? pfd->pfd_dynwidth : pfd->pfd_width;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync width = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_options[DTRACEOPT_STACKINDENT] = width;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (rec->dtrd_action) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACEACT_USTACK:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACEACT_JSTACK:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync err = dt_print_ustack(dtp, fp, format, addr, rec->dtrd_arg);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACEACT_STACK:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync err = dt_print_stack(dtp, fp, format, addr, rec->dtrd_arg,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rec->dtrd_size / rec->dtrd_arg);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_options[DTRACEOPT_STACKINDENT] = saved;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (err);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char src[32], buf[32], *dst = buf;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t time = *((uint64_t *)addr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync time_t sec = (time_t)(time / NANOSEC);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int i;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) ctime_r(&sec, src, sizeof (src));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Place the 4-digit year at the head of the string...
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 20; i < 24; i++)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *dst++ = src[i];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * ...and follow it with the remainder (month, day, hh:mm:ss).
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 3; i < 19; i++)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *dst++ = src[i];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *dst = '\0';
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#else
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTTIMESPEC TimeSpec;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTTIME Time;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync char buf[32];
0fea9bc4af28518049902cca68d209af223a8e13vboxsync
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTTimeLocalExplode(&Time, RTTimeSpecSetNano(&TimeSpec, *(uint64_t *)addr));
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTStrPrintf(buf, sizeof(buf), "%u %s %2u %02u:%02u:%02u",
0fea9bc4af28518049902cca68d209af223a8e13vboxsync Time.i32Year, g_aszMonth[Time.u8Month - 1],
0fea9bc4af28518049902cca68d209af223a8e13vboxsync Time.u8MonthDay, Time.u8Hour, Time.u8Minute, Time.u8Second);
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, buf));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hrtime_t time = *((uint64_t *)addr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync time_t sec = (time_t)(time / NANOSEC);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct tm tm;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char buf[64];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) localtime_r(&sec, &tm);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strftime(buf, sizeof (buf), "%a, %d %b %G %T %Z", &tm);
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#else
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTTIMESPEC TimeSpec;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTTIME Time;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync char buf[64];
0fea9bc4af28518049902cca68d209af223a8e13vboxsync
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.u8Hour, Time.u8Minute, Time.u8Second,
0fea9bc4af28518049902cca68d209af223a8e13vboxsync Time.offUTC >= 0 ? "UTC+" : "UTC", Time.offUTC / 60,
0fea9bc4af28518049902cca68d209af223a8e13vboxsync Time.offUTC % 60 == 30 ? ".5" : "");
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, buf));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint16_t port = htons(*((uint16_t *)addr));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char buf[256];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct servent *sv, res;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((sv = getservbyport_r(port, NULL, &res, buf, sizeof (buf))) != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, sv->s_name));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(buf, sizeof (buf), "%d", *((uint16_t *)addr));
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#else
0fea9bc4af28518049902cca68d209af223a8e13vboxsync uint16_t uPortNet = *(uint16_t *)addr;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync char buf[32];
0fea9bc4af28518049902cca68d209af223a8e13vboxsync
0fea9bc4af28518049902cca68d209af223a8e13vboxsync RTStrPrintf(buf, sizeof(buf), "%d", RT_N2H_U16(uPortNet));
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, buf));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *s = alloca(size + 1);
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct hostent *host, res;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char inetaddr[NS_IN6ADDRSZ];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char buf[1024];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int e;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bcopy(addr, s, size);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync s[size] = '\0';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strchr(s, ':') == NULL && inet_pton(AF_INET, s, inetaddr) != -1) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((host = gethostbyaddr_r(inetaddr, NS_INADDRSZ,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync AF_INET, &res, buf, sizeof (buf), &e)) != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, host->h_name));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else if (inet_pton(AF_INET6, s, inetaddr) != -1) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((host = getipnodebyaddr(inetaddr, NS_IN6ADDRSZ,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync AF_INET6, &e)) != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, host->h_name));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, s));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *s = alloca(size + 1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bcopy(addr, s, size);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync s[size] = '\0';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, s));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync wchar_t *ws = alloca(size + sizeof (wchar_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bcopy(addr, ws, size);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ws[size / sizeof (wchar_t)] = L'\0';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format, ws));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *s;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int n;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((s = strchr2esc(addr, size)) == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_NOMEM));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync n = dt_printf(dtp, fp, format, s);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(s);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (n);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char c;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (size) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int8_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync c = *(int8_t *)addr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int16_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync c = *(int16_t *)addr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync c = *(int32_t *)addr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfprint_estr(dtp, fp, format, pfd, &c, 1, normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, "%%"));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
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";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const char pfproto_uaddr[] =
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "pointer or integer (with -p/-c) or _usymaddr (without -p/-c)";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const char pfproto_cstr[] = "char [] or string (or use stringof)";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const char pfproto_wstr[] = "wchar_t []";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const dt_pfconv_t _dtrace_conversions[] = {
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{ "e", "e", pfproto_fp, pfcheck_fp, pfprint_fp },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "E", "E", pfproto_fp, pfcheck_fp, pfprint_fp },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "f", "f", pfproto_fp, pfcheck_fp, pfprint_fp },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "g", "g", pfproto_fp, pfcheck_fp, pfprint_fp },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "G", "G", pfproto_fp, pfcheck_fp, pfprint_fp },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "hd", "d", "short", pfcheck_type, pfprint_sint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "hi", "i", "short", pfcheck_type, pfprint_sint },
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{ "ld", "d", "long", pfcheck_type, pfprint_sint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "li", "i", "long", pfcheck_type, pfprint_sint },
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{ "lx", "x", "long", pfcheck_xlong, pfprint_uint },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ "lX", "X", "long", pfcheck_xlong, pfprint_uint },
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{ "%", "%", "void", pfcheck_type, pfprint_pct },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ NULL, NULL, NULL, NULL, NULL }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_pfdict_create(dtrace_hdl_t *dtp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t n = _dtrace_strbuckets;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfconv_t *pfd;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfdict_t *pdi;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pdi = malloc(sizeof (dt_pfdict_t))) == NULL ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (pdi->pdi_buckets = malloc(sizeof (dt_pfconv_t *) * n)) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(pdi);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_NOMEM));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_pfdict = pdi;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bzero(pdi->pdi_buckets, sizeof (dt_pfconv_t *) * n);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pdi->pdi_nbuckets = n;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (pfd = _dtrace_conversions; pfd->pfc_name != NULL; pfd++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_typeinfo_t dtt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfconv_t *pfc;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t h;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfc = malloc(sizeof (dt_pfconv_t))) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfdict_destroy(dtp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_NOMEM));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bcopy(pfd, pfc, sizeof (dt_pfconv_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync h = dt_strtab_hash(pfc->pfc_name, NULL) % n;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_next = pdi->pdi_buckets[h];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pdi->pdi_buckets[h] = pfc;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtt.dtt_ctfp = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtt.dtt_type = CTF_ERR;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_check == &pfcheck_type && dtrace_lookup_by_type(
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp, DTRACE_OBJ_DDEFS, pfc->pfc_tstr, &dtt) != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfdict_destroy(dtp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_NOCONV));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_dctfp = dtt.dtt_ctfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_dtype = dtt.dtt_type;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_check == &pfcheck_type && dtrace_lookup_by_type(
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp, DTRACE_OBJ_CDEFS, pfc->pfc_tstr, &dtt) == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_cctfp = dtt.dtt_ctfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_ctype = dtt.dtt_type;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_cctfp = pfc->pfc_dctfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_ctype = pfc->pfc_dtype;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_check == NULL || pfc->pfc_print == NULL ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_ofmt == NULL || pfc->pfc_tstr == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfdict_destroy(dtp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_BADCONV));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("loaded printf conversion %%%s\n", pfc->pfc_name);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncvoid
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_pfdict_destroy(dtrace_hdl_t *dtp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfdict_t *pdi = dtp->dt_pfdict;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfconv_t *pfc, *nfc;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t i;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pdi == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; i < pdi->pdi_nbuckets; i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (pfc = pdi->pdi_buckets[i]; pfc != NULL; pfc = nfc) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nfc = pfc->pfc_next;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(pfc);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(pdi->pdi_buckets);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(pdi);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_pfdict = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic const dt_pfconv_t *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_pfdict_lookup(dtrace_hdl_t *dtp, const char *name)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfdict_t *pdi = dtp->dt_pfdict;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t h = dt_strtab_hash(name, NULL) % pdi->pdi_nbuckets;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfconv_t *pfc;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (pfc = pdi->pdi_buckets[h]; pfc != NULL; pfc = pfc->pfc_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strcmp(pfc->pfc_name, name) == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfc);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic dt_pfargv_t *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_printf_error(dtrace_hdl_t *dtp, int err)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (yypcb != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync longjmp(yypcb->pcb_jmpbuf, err);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_set_errno(dtp, err);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_pfargv_t *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_printf_create(dtrace_hdl_t *dtp, const char *s)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargd_t *pfd, *nfd = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargv_t *pfv;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *p, *q;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *format;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfv = malloc(sizeof (dt_pfargv_t))) == NULL ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (format = strdup(s)) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf_error(dtp, EDT_NOMEM));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_format = format;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_argv = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_argc = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_flags = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_dtp = dtp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (q = format; (p = strchr(q, '%')) != NULL; q = *p ? p + 1 : p) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t namelen = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int digits = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int dot = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char name[8];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char c;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int n;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfd = malloc(sizeof (dt_pfargd_t))) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_printf_destroy(pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf_error(dtp, EDT_NOMEM));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfv->pfv_argv != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nfd->pfd_next = pfd;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_argv = pfd;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bzero(pfd, sizeof (dt_pfargd_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_argc++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nfd = pfd;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (p > q) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_preflen = (size_t)(p - q);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_prefix = q;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fmt_switch:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (c = *++p) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '0': case '1': case '2': case '3': case '4':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '5': case '6': case '7': case '8': case '9':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dot == 0 && digits == 0 && c == '0') {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags |= DT_PFCONV_ZPAD;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags &= ~DT_PFCONV_LEFT;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (n = 0; isdigit(c); c = *++p)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync n = n * 10 + c - '0';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dot)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_prec = n;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_width = n;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync p--;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync digits++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '#':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags |= DT_PFCONV_ALT;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '*':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync n = dot ? DT_PFCONV_DYNPREC : DT_PFCONV_DYNWIDTH;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & n) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yywarn("format conversion #%u has more than "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "one '*' specified for the output %s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_argc, n ? "precision" : "width");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_printf_destroy(pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf_error(dtp, EDT_COMPILER));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags |= n;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '+':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags |= DT_PFCONV_SPOS;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '-':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags |= DT_PFCONV_LEFT;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags &= ~DT_PFCONV_ZPAD;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '.':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dot++ != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yywarn("format conversion #%u has more than "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "one '.' specified\n", pfv->pfv_argc);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_printf_destroy(pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf_error(dtp, EDT_COMPILER));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync digits = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '?':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_width = 16;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_width = 8;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '@':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags |= DT_PFCONV_AGG;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '\'':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags |= DT_PFCONV_GROUP;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case ' ':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_flags |= DT_PFCONV_SPACE;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '$':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yywarn("format conversion #%u uses unsupported "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "positional format (%%n$)\n", pfv->pfv_argc);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_printf_destroy(pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf_error(dtp, EDT_COMPILER));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '%':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (p[-1] == '%')
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto default_lbl; /* if %% then use "%" conv */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yywarn("format conversion #%u cannot be combined "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "with other format flags: %%%%\n", pfv->pfv_argc);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_printf_destroy(pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf_error(dtp, EDT_COMPILER));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case '\0':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yywarn("format conversion #%u name expected before "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "end of format string\n", pfv->pfv_argc);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_printf_destroy(pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf_error(dtp, EDT_COMPILER));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case 'h':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case 'l':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case 'L':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case 'w':
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (namelen < sizeof (name) - 2)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync name[namelen++] = c;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto fmt_switch;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default_lbl:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync name[namelen++] = c;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync name[namelen] = '\0';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_conv = dt_pfdict_lookup(dtp, name);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_conv == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync yywarn("format conversion #%u is undefined: %%%s\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_argc, name);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_printf_destroy(pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf_error(dtp, EDT_COMPILER));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (*q != '\0' || *format == '\0') {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfd = malloc(sizeof (dt_pfargd_t))) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_printf_destroy(pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf_error(dtp, EDT_NOMEM));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfv->pfv_argv != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nfd->pfd_next = pfd;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_argv = pfd;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bzero(pfd, sizeof (dt_pfargd_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_argc++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_prefix = q;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_preflen = strlen(q);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncvoid
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_printf_destroy(dt_pfargv_t *pfv)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargd_t *pfd, *nfd;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (pfd = pfv->pfv_argv; pfd != NULL; pfd = nfd) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nfd = pfd->pfd_next;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(pfd);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(pfv->pfv_format);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncvoid
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_printf_validate(dt_pfargv_t *pfv, uint_t flags,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_ident_t *idp, int foff, dtrace_actkind_t kind, dt_node_t *dnp)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargd_t *pfd = pfv->pfv_argv;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *func = idp->di_name;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char n[DT_TYPE_NAMELEN];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_typeinfo_t dtt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *aggtype;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_t aggnode;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync VBDTTYPE(uint_t,int) i, j;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfv->pfv_format[0] == '\0') {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PRINTF_FMT_EMPTY,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) format string is empty\n", func);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_flags = flags;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (kind != DTRACEAGG_COUNT)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggtype = "int64_t";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggtype = "uint64_t";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_type_lookup(aggtype, &dtt) != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_TYPE_ERR, "failed to lookup agg type %s\n", aggtype);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bzero(&aggnode, sizeof (aggnode));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_type_assign(&aggnode, dtt.dtt_ctfp, dtt.dtt_type);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0, j = 0; i < pfv->pfv_argc; i++, pfd = pfd->pfd_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfconv_t *pfc = pfd->pfd_conv;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *dyns[2];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int dync = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char vname[64];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_t *vnp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue; /* no checking if argd is just a prefix */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_print == &pfprint_pct) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strcat(pfd->pfd_fmt, pfc->pfc_ofmt);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_DYNPREC)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dyns[dync++] = ".*";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_DYNWIDTH)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dyns[dync++] = "*";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (; dync != 0; dync--) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dnp == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PRINTF_DYN_PROTO,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) prototype mismatch: conversion "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "#%d (%%%s) is missing a corresponding "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "\"%s\" argument\n", func, i + 1,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_name, dyns[dync - 1]);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_node_is_integer(dnp) == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PRINTF_DYN_TYPE,
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 func, j + foff + 1, i + 1,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dyns[dync - 1], pfc->pfc_name,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_type_name(dnp, n, sizeof (n)));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnp = dnp->dn_list;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync j++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_AGG) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!(flags & DT_PRINTF_AGGREGATION)) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PRINTF_AGG_CONV,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%%@ conversion requires an aggregation"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync " and is not for use with %s( )\n", func);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strlcpy(vname, "aggregating action",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync sizeof (vname));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync vnp = &aggnode;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else if (dnp == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PRINTF_ARG_PROTO,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) prototype mismatch: conversion #%d (%%"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s) is missing a corresponding value argument\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync func, i + 1, pfc->pfc_name);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(vname, sizeof (vname),
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "argument #%d", j + foff + 1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync vnp = dnp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dnp = dnp->dn_list;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync j++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_print == &pfprint_sint ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_print == &pfprint_uint ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfc->pfc_print == &pfprint_dint) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_node_type_size(vnp) == sizeof (uint64_t))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strcpy(pfd->pfd_fmt, "ll");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else if (pfc->pfc_print == &pfprint_fp) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_node_type_size(vnp) == sizeof (long double))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strcpy(pfd->pfd_fmt, "L");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strcat(pfd->pfd_fmt, pfc->pfc_ofmt);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_check(pfv, pfd, vnp) == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PRINTF_ARG_TYPE,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) %s is incompatible with "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "conversion #%d prototype:\n\tconversion: %%%s\n"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "\t prototype: %s\n\t argument: %s\n", func,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync vname, i + 1, pfc->pfc_name, pfc->pfc_tstr,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_type_name(vnp, n, sizeof (n)));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((flags & DT_PRINTF_EXACTLEN) && dnp != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync xyerror(D_PRINTF_ARG_EXTRA,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "%s( ) prototype mismatch: only %d arguments "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "required by this format string\n", func, j);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncvoid
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_printa_validate(dt_node_t *lhs, dt_node_t *rhs)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_ident_t *lid, *rid;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_node_t *lproto, *rproto;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int largc, rargc, argn;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char n1[DT_TYPE_NAMELEN];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char n2[DT_TYPE_NAMELEN];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(lhs->dn_kind == DT_NODE_AGG);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(rhs->dn_kind == DT_NODE_AGG);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync lid = lhs->dn_ident;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rid = rhs->dn_ident;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync lproto = ((dt_idsig_t *)lid->di_data)->dis_args;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rproto = ((dt_idsig_t *)rid->di_data)->dis_args;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * First, get an argument count on each side. These must match.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (largc = 0; lproto != NULL; lproto = lproto->dn_list)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync largc++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (rargc = 0; rproto != NULL; rproto = rproto->dn_list)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rargc++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (largc != rargc) {
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 "key%s", lid->di_name, rid->di_name,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync lid->di_name, largc, largc == 1 ? "" : "s",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rid->di_name, rargc, rargc == 1 ? "" : "s");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Now iterate over the keys to verify that each type matches.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync lproto = ((dt_idsig_t *)lid->di_data)->dis_args;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rproto = ((dt_idsig_t *)rid->di_data)->dis_args;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (argn = 1; lproto != NULL; argn++, lproto = lproto->dn_list,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rproto = rproto->dn_list) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(rproto != NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_node_is_argcompat(lproto, rproto))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
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,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync argn, dt_node_type_name(rproto, n2, sizeof (n2)));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uintptr_t addr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (nrecs == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync addr = (uintptr_t)buf + recp->dtrd_offset;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (addr + sizeof (int) > (uintptr_t)buf + len)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DOFFSET));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (addr & (recp->dtrd_alignment - 1))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DALIGN));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (recp->dtrd_size) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int8_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *ip = (int)*((int8_t *)addr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int16_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *ip = (int)*((int16_t *)addr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int32_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *ip = (int)*((int32_t *)addr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case sizeof (int64_t):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *ip = (int)*((int64_t *)addr);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const uint64_t *data = addr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (size != sizeof (uint64_t) * 2)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync data[0] ? data[1] / normal / data[0] : 0));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const uint64_t *data = addr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (size != sizeof (uint64_t) * 4)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf(dtp, fp, format,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_stddev((uint64_t *)data, normal)));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_print_quantize(dtp, fp, addr, size, normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_print_lquantize(dtp, fp, addr, size, normal));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargd_t *pfd = pfv->pfv_argv;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_recdesc_t *recp = recs;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_aggdata_t *aggdata;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_aggdesc_t *agg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync caddr_t lim = (caddr_t)buf + len, limit;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char format[64] = "%";
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int i, aggrec, curagg = -1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint64_t normal;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfv->pfv_flags & DT_PRINTF_AGGREGATION) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(aggsdata != NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(naggvars > 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (nrecs == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync curagg = naggvars > 1 ? 1 : 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggdata = aggsdata[0];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggrec = aggdata->dtada_desc->dtagd_nrecs - 1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nrecs--;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
0fea9bc4af28518049902cca68d209af223a8e13vboxsync for (i = 0; VBDTCAST(uint_t)i < pfv->pfv_argc; i++, pfd = pfd->pfd_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfconv_t *pfc = pfd->pfd_conv;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int width = pfd->pfd_width;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int prec = pfd->pfd_prec;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int rval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *f = format + 1; /* skip initial '%' */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_recdesc_t *rec;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfprint_f *func;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync caddr_t addr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync size_t size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint32_t flags;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_preflen != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *tmp = alloca(pfd->pfd_preflen + 1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bcopy(pfd->pfd_prefix, tmp, pfd->pfd_preflen);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync tmp[pfd->pfd_preflen] = '\0';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((rval = dt_printf(dtp, fp, tmp)) < 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (rval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfv->pfv_flags & DT_PRINTF_AGGREGATION) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync flags = DTRACE_BUFDATA_AGGFORMAT;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc == NULL && i == pfv->pfv_argc - 1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync flags |= DTRACE_BUFDATA_AGGLAST;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_buffered_flush(dtp, NULL, NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggdata, flags) < 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfv->pfv_argc == 1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (nrecs != 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If the conversion is %%, just invoke the print callback
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * with no data record and continue; it consumes no record.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_print == &pfprint_pct) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc->pfc_print(dtp, fp, NULL, pfd, NULL, 0, 1) >= 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1); /* errno is set for us */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_DYNWIDTH) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_printf_getint(dtp, recp++, nrecs--, buf,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync len, &width) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1); /* errno is set for us */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_dynwidth = width;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_dynwidth = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfd->pfd_flags & DT_PFCONV_DYNPREC) && dt_printf_getint(
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp, recp++, nrecs--, buf, len, &prec) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1); /* errno is set for us */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_AGG) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (aggsdata == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggdata = aggsdata[curagg];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync agg = aggdata->dtada_desc;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (curagg < naggvars - 1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync curagg++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rec = &agg->dtagd_rec[aggrec];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync addr = aggdata->dtada_data + rec->dtrd_offset;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync limit = addr + aggdata->dtada_size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync normal = aggdata->dtada_normal;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync flags = DTRACE_BUFDATA_AGGVAL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (nrecs == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DMISMATCH));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfv->pfv_flags & DT_PRINTF_AGGREGATION) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggdata = aggsdata[0];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync flags = DTRACE_BUFDATA_AGGKEY;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rec = recp++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nrecs--;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync addr = (caddr_t)buf + rec->dtrd_offset;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync limit = lim;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync normal = 1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync size = rec->dtrd_size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (addr + size > limit) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_dprintf("bad size: addr=%p size=0x%x lim=%p\n",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void *)addr, rec->dtrd_size, (void *)lim);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_DOFFSET));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (rec->dtrd_alignment != 0 &&
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 return (dt_set_errno(dtp, EDT_DALIGN));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (rec->dtrd_action) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACEAGG_AVG:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync func = pfprint_average;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACEAGG_STDDEV:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync func = pfprint_stddev;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACEAGG_QUANTIZE:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync func = pfprint_quantize;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACEAGG_LQUANTIZE:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync func = pfprint_lquantize;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACEACT_MOD:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync func = pfprint_mod;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DTRACEACT_UMOD:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync func = pfprint_umod;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync func = pfc->pfc_print;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_ALT)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '#';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_ZPAD)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '0';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (width < 0 || (pfd->pfd_flags & DT_PFCONV_LEFT))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '-';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_SPOS)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '+';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_GROUP)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '\'';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_SPACE)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = ' ';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (func == pfprint_stack && (pfd->pfd_flags & DT_PFCONV_LEFT))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync width = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (width != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync f += snprintf(f, sizeof (format), "%d", ABS(width));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (prec > 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync f += snprintf(f, sizeof (format), ".%d", prec);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strcpy(f, pfd->pfd_fmt);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd->pfd_rec = rec;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (func(dtp, fp, format, pfd, addr, size, normal) < 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1); /* errno is set for us */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfv->pfv_flags & DT_PRINTF_AGGREGATION) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * For printa(), we flush the buffer after each tuple
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * element, inidicating that this is the last record
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * as appropriate.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (i == pfv->pfv_argc - 1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync flags |= DTRACE_BUFDATA_AGGLAST;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_buffered_flush(dtp, NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rec, aggdata, flags) < 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return ((int)(recp - recs));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
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{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_optval_t size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int rval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rval = dtrace_getopt(dtp, "strsize", &size);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(rval == 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(dtp->dt_sprintf_buflen == 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_sprintf_buf != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(dtp->dt_sprintf_buf);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((dtp->dt_sprintf_buf = malloc(size)) == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_NOMEM));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync bzero(dtp->dt_sprintf_buf, size);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_sprintf_buflen = size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rval = dt_printf_format(dtp, fp, fmtdata, recp, nrecs, buf, len,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL, 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtp->dt_sprintf_buflen = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (rval == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync free(dtp->dt_sprintf_buf);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (rval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_system(dtrace_hdl_t *dtp, FILE *fp, void *fmtdata,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_probedata_t *data, const dtrace_recdesc_t *recp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t nrecs, const void *buf, size_t len)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int rval = dtrace_sprintf(dtp, fp, fmtdata, recp, nrecs, buf, len);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (rval == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (rval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) fflush(fp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (system(dtp->dt_sprintf_buf) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (rval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_freopen(dtrace_hdl_t *dtp, FILE *fp, void *fmtdata,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_probedata_t *data, const dtrace_recdesc_t *recp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t nrecs, const void *buf, size_t len)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char selfbuf[40], restorebuf[40], *filename;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync FILE *nfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargv_t *pfv = fmtdata;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargd_t *pfd = pfv->pfv_argv;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#else
0fea9bc4af28518049902cca68d209af223a8e13vboxsync int rval, errval;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rval = dtrace_sprintf(dtp, fp, fmtdata, recp, nrecs, buf, len);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (rval == -1 || fp == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (rval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_preflen != 0 &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strcmp(pfd->pfd_prefix, DT_FREOPEN_RESTORE) == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(strcmp(dtp->dt_sprintf_buf, DT_FREOPEN_RESTORE) == 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_stdout_fd == -1) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (rval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(restorebuf, sizeof (restorebuf),
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "/dev/fd/%d", dtp->dt_stdout_fd);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync filename = restorebuf;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync filename = dtp->dt_sprintf_buf;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((nfp = fopen(filename, "aF")) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *msg = strerror(errno), *faultstr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int len = 80;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync len += strlen(msg) + strlen(filename);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync faultstr = alloca(len);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(faultstr, len, "couldn't freopen() \"%s\": %s",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync filename, strerror(errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((errval = dt_handle_liberr(dtp, data, faultstr)) == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (rval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (errval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) snprintf(selfbuf, sizeof (selfbuf), "/dev/fd/%d", fileno(nfp));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtp->dt_stdout_fd == -1) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((dtp->dt_stdout_fd = dup(fileno(fp))) == -1) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) fclose(nfp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (freopen(selfbuf, "aF", fp) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) fclose(nfp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) fclose(nfp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (rval);
0fea9bc4af28518049902cca68d209af223a8e13vboxsync
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)
0fea9bc4af28518049902cca68d209af223a8e13vboxsync return (rval);
0fea9bc4af28518049902cca68d209af223a8e13vboxsync return (errval);
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_fprintf(dtrace_hdl_t *dtp, FILE *fp, void *fmtdata,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_probedata_t *data, const dtrace_recdesc_t *recp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t nrecs, const void *buf, size_t len)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_printf_format(dtp, fp, fmtdata,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync recp, nrecs, buf, len, NULL, 0));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncvoid *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_printf_create(dtrace_hdl_t *dtp, const char *s)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargv_t *pfv = dt_printf_create(dtp, s);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargd_t *pfd;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync VBDTTYPE(uint_t,int) i;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfv == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (NULL); /* errno has been set for us */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfd = pfv->pfv_argv;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; i < pfv->pfv_argc; i++, pfd = pfd->pfd_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfconv_t *pfc = pfd->pfd_conv;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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".
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strcmp(pfc->pfc_ofmt, "s") != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strcat(pfd->pfd_fmt, pfc->pfc_name);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strcat(pfd->pfd_fmt, pfc->pfc_ofmt);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncvoid *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_printa_create(dtrace_hdl_t *dtp, const char *s)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargv_t *pfv = dtrace_printf_create(dtp, s);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfv == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (NULL); /* errno has been set for us */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfv->pfv_flags |= DT_PRINTF_AGGREGATION;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfv);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncsize_t
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_printf_format(dtrace_hdl_t *dtp, void *fmtdata, char *s, size_t len)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargv_t *pfv = fmtdata;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfargd_t *pfd = pfv->pfv_argv;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync size_t formatlen = strlen(pfv->pfv_format) + 3 * pfv->pfv_argc + 1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *format = alloca(formatlen);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *f = format;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int i, j;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#else
0fea9bc4af28518049902cca68d209af223a8e13vboxsync uint_t i;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync size_t j;
0fea9bc4af28518049902cca68d209af223a8e13vboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 0; i < pfv->pfv_argc; i++, pfd = pfd->pfd_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dt_pfconv_t *pfc = pfd->pfd_conv;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *str;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int width = pfd->pfd_width;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int prec = pfd->pfd_prec;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_preflen != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (j = 0; j < pfd->pfd_preflen; j++)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = pfd->pfd_prefix[j];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfc == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '%';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_ALT)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '#';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_ZPAD)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '0';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_LEFT)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '-';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_SPOS)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '+';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_DYNWIDTH)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '*';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_DYNPREC) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '.';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '*';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_GROUP)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '\'';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_SPACE)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = ' ';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (pfd->pfd_flags & DT_PFCONV_AGG)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = '@';
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (width != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync f += snprintf(f, sizeof (format), "%d", width);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (prec != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync f += snprintf(f, sizeof (format), ".%d", prec);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strcmp(pfc->pfc_ofmt, "s") == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync str = pfc->pfc_name;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync str = pfd->pfd_fmt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (j = 0; str[j] != '\0'; j++)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f++ = str[j];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *f = '\0'; /* insert nul byte; do not count in return value */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync assert(f < format + formatlen);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strncpy(s, format, len);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return ((size_t)(f - format));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_fprinta(const dtrace_aggdata_t *adp, void *arg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_aggdesc_t *agg = adp->dtada_desc;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_recdesc_t *recp = &agg->dtagd_rec[0];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t nrecs = agg->dtagd_nrecs;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfwalk_t *pfw = arg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_hdl_t *dtp = pfw->pfw_argv->pfv_dtp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int id;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_printf_getint(dtp, recp++, nrecs--,
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
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 return (pfw->pfw_err = dtp->dt_errno);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Cast away the const to set the bit indicating that this aggregation
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * has been printed.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ((dtrace_aggdesc_t *)agg)->dtagd_flags |= DTRACE_AGD_PRINTED;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_fprintas(const dtrace_aggdata_t **aggsdata, int naggvars, void *arg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_aggdata_t *aggdata = aggsdata[0];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_aggdesc_t *agg = aggdata->dtada_desc;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_recdesc_t *rec = &agg->dtagd_rec[1];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t nrecs = agg->dtagd_nrecs - 1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfwalk_t *pfw = arg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_hdl_t *dtp = pfw->pfw_argv->pfv_dtp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int i;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dt_printf_format(dtp, pfw->pfw_fp, pfw->pfw_argv,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rec, nrecs, aggdata->dtada_data, aggdata->dtada_size,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggsdata, naggvars) == -1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (pfw->pfw_err = dtp->dt_errno);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * For each aggregation, indicate that it has been printed, casting
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * away the const as necessary.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 1; i < naggvars; i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync agg = aggsdata[i]->dtada_desc;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ((dtrace_aggdesc_t *)agg)->dtagd_flags |= DTRACE_AGD_PRINTED;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdtrace_fprinta(dtrace_hdl_t *dtp, FILE *fp, void *fmtdata,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_probedata_t *data, const dtrace_recdesc_t *recs,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t nrecs, const void *buf, size_t len)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_pfwalk_t pfw;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int i, naggvars = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_aggvarid_t *aggvars;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggvars = alloca(nrecs * sizeof (dtrace_aggvarid_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
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 */
0fea9bc4af28518049902cca68d209af223a8e13vboxsync for (i = 0; VBDTCAST(uint_t)i < nrecs; i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const dtrace_recdesc_t *nrec = &recs[i];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (nrec->dtrd_uarg != recs->dtrd_uarg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (nrec->dtrd_action != recs->dtrd_action)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_BADAGG));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync aggvars[naggvars++] =
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /* LINTED - alignment */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *((dtrace_aggvarid_t *)((caddr_t)buf + nrec->dtrd_offset));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (naggvars == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (dt_set_errno(dtp, EDT_BADAGG));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfw.pfw_argv = fmtdata;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfw.pfw_fp = fp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfw.pfw_err = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (naggvars == 1) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pfw.pfw_aid = aggvars[0];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_aggregate_walk_sorted(dtp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_fprinta, &pfw) == -1 || pfw.pfw_err != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1); /* errno is set for us */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_aggregate_walk_joined(dtp, aggvars, naggvars,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_fprintas, &pfw) == -1 || pfw.pfw_err != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (-1); /* errno is set for us */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (i);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}