/* * Common code for cooking an identifier that uses a typed signature list (we * use this for associative arrays and functions). If the argument list is * of the same length and types, then return the return type. Otherwise * print an appropriate compiler error message and abort the compile. */ static void dt_idcook_sign(dt_node_t *dnp, dt_ident_t *idp, int argc, dt_node_t *args, const char *prefix, const char *suffix) { dt_idsig_t *isp = idp->di_data; int i, compat, mismatch, arglimit, iskey; char n1[DT_TYPE_NAMELEN]; char n2[DT_TYPE_NAMELEN]; iskey = idp->di_kind == DT_IDENT_ARRAY || idp->di_kind == DT_IDENT_AGG; if (isp->dis_varargs >= 0) { mismatch = argc < isp->dis_varargs; arglimit = isp->dis_varargs; } else if (isp->dis_optargs >= 0) { mismatch = (argc < isp->dis_optargs || argc > isp->dis_argc); arglimit = argc; } else { mismatch = argc != isp->dis_argc; arglimit = isp->dis_argc; } if (mismatch) { xyerror(D_PROTO_LEN, "%s%s%s prototype mismatch: %d %s%s" "passed, %s%d expected\n", prefix, idp->di_name, suffix, argc, iskey ? "key" : "arg", argc == 1 ? " " : "s ", isp->dis_optargs >= 0 ? "at least " : "", isp->dis_optargs >= 0 ? isp->dis_optargs : arglimit); } for (i = 0; i < arglimit; i++, args = args->dn_list) { if (isp->dis_args[i].dn_ctfp != NULL) compat = dt_node_is_argcompat(&isp->dis_args[i], args); else compat = 1; /* "@" matches any type */ if (!compat) { xyerror(D_PROTO_ARG, "%s%s%s %s #%d is incompatible with " "prototype:\n\tprototype: %s\n\t%9s: %s\n", prefix, idp->di_name, suffix, iskey ? "key" : "argument", i + 1, dt_node_type_name(&isp->dis_args[i], n1, sizeof (n1)), iskey ? "key" : "argument", dt_node_type_name(args, n2, sizeof (n2))); } } dt_node_type_assign(dnp, idp->di_ctfp, idp->di_type); }
dt_xlator_t * dt_xlator_lookup(dtrace_hdl_t *dtp, dt_node_t *src, dt_node_t *dst, int flags) { ctf_file_t *src_ctfp = src->dn_ctfp; ctf_id_t src_type = src->dn_type; ctf_id_t src_base = ctf_type_resolve(src_ctfp, src_type); ctf_file_t *dst_ctfp = dst->dn_ctfp; ctf_id_t dst_type = dst->dn_type; ctf_id_t dst_base = ctf_type_resolve(dst_ctfp, dst_type); uint_t dst_kind = ctf_type_kind(dst_ctfp, dst_base); int ptr = dst_kind == CTF_K_POINTER; dtrace_typeinfo_t src_dtt, dst_dtt; dt_node_t xn = { 0 }; dt_xlator_t *dxp = NULL; if (src_base == CTF_ERR || dst_base == CTF_ERR) return (NULL); /* fail if these are unresolvable types */ /* * Translators are always defined using a struct or union type, so if * we are attempting to translate to type "T *", we internally look * for a translation to type "T" by following the pointer reference. */ if (ptr) { dst_type = ctf_type_reference(dst_ctfp, dst_type); dst_base = ctf_type_resolve(dst_ctfp, dst_type); dst_kind = ctf_type_kind(dst_ctfp, dst_base); } if (dst_kind != CTF_K_UNION && dst_kind != CTF_K_STRUCT) return (NULL); /* fail if the output isn't a struct or union */ /* * In order to find a matching translator, we iterate over the set of * available translators in three passes. First, we look for a * translation from the exact source type to the resolved destination. * Second, we look for a translation from the resolved source type to * the resolved destination. Third, we look for a translation from a * compatible source type (using the same rules as parameter formals) * to the resolved destination. If all passes fail, return NULL. */ for (dxp = dt_list_next(&dtp->dt_xlators); dxp != NULL; dxp = dt_list_next(dxp)) { if (ctf_type_compat(dxp->dx_src_ctfp, dxp->dx_src_type, src_ctfp, src_type) && ctf_type_compat(dxp->dx_dst_ctfp, dxp->dx_dst_base, dst_ctfp, dst_base)) goto out; } if (flags & DT_XLATE_EXACT) goto out; /* skip remaining passes if exact match required */ for (dxp = dt_list_next(&dtp->dt_xlators); dxp != NULL; dxp = dt_list_next(dxp)) { if (ctf_type_compat(dxp->dx_src_ctfp, dxp->dx_src_base, src_ctfp, src_type) && ctf_type_compat(dxp->dx_dst_ctfp, dxp->dx_dst_base, dst_ctfp, dst_base)) goto out; } for (dxp = dt_list_next(&dtp->dt_xlators); dxp != NULL; dxp = dt_list_next(dxp)) { dt_node_type_assign(&xn, dxp->dx_src_ctfp, dxp->dx_src_type); if (ctf_type_compat(dxp->dx_dst_ctfp, dxp->dx_dst_base, dst_ctfp, dst_base) && dt_node_is_argcompat(src, &xn)) goto out; } out: if (ptr && dxp != NULL && dxp->dx_ptrid.di_type == CTF_ERR) return (NULL); /* no translation available to pointer type */ if (dxp != NULL || !(flags & DT_XLATE_EXTERN) || dtp->dt_xlatemode == DT_XL_STATIC) return (dxp); /* we succeeded or not allowed to extern */ /* * If we get here, then we didn't find an existing translator, but the * caller and xlatemode permit us to create an extern to a dynamic one. */ src_dtt.dtt_object = dt_module_lookup_by_ctf(dtp, src_ctfp)->dm_name; src_dtt.dtt_ctfp = src_ctfp; src_dtt.dtt_type = src_type; dst_dtt.dtt_object = dt_module_lookup_by_ctf(dtp, dst_ctfp)->dm_name; dst_dtt.dtt_ctfp = dst_ctfp; dst_dtt.dtt_type = dst_type; return (dt_xlator_create(dtp, &src_dtt, &dst_dtt, NULL, NULL, NULL)); }
/* * Cook a reference to the dynamically typed args[] array. We verify that the * reference is using a single integer constant, and then construct a new ident * representing the appropriate type or translation specifically for this node. */ static void dt_idcook_args(dt_node_t *dnp, dt_ident_t *idp, int argc, dt_node_t *ap) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_probe_t *prp = yypcb->pcb_probe; dt_node_t tag, *nnp, *xnp; dt_xlator_t *dxp; dt_ident_t *xidp; char n1[DT_TYPE_NAMELEN]; char n2[DT_TYPE_NAMELEN]; if (argc != 1) { xyerror(D_PROTO_LEN, "%s[ ] prototype mismatch: %d arg%s" "passed, 1 expected\n", idp->di_name, argc, argc == 1 ? " " : "s "); } if (ap->dn_kind != DT_NODE_INT) { xyerror(D_PROTO_ARG, "%s[ ] argument #1 is incompatible with " "prototype:\n\tprototype: %s\n\t argument: %s\n", idp->di_name, "integer constant", dt_type_name(ap->dn_ctfp, ap->dn_type, n1, sizeof (n1))); } if (yypcb->pcb_pdesc == NULL) { xyerror(D_ARGS_NONE, "%s[ ] may not be referenced outside " "of a probe clause\n", idp->di_name); } if (prp == NULL) { xyerror(D_ARGS_MULTI, "%s[ ] may not be referenced because probe description %s " "matches an unstable set of probes\n", idp->di_name, dtrace_desc2str(yypcb->pcb_pdesc, n1, sizeof (n1))); } if (ap->dn_value >= prp->pr_argc) { xyerror(D_ARGS_IDX, "index %lld is out of range for %s %s[ ]\n", (longlong_t)ap->dn_value, dtrace_desc2str(yypcb->pcb_pdesc, n1, sizeof (n1)), idp->di_name); } /* * Look up the native and translated argument types for the probe. * If no translation is needed, these will be the same underlying node. * If translation is needed, look up the appropriate translator. Once * we have the appropriate node, create a new dt_ident_t for this node, * assign it the appropriate attributes, and set the type of 'dnp'. */ xnp = prp->pr_xargv[ap->dn_value]; nnp = prp->pr_nargv[prp->pr_mapping[ap->dn_value]]; if (xnp->dn_type == CTF_ERR) { xyerror(D_ARGS_TYPE, "failed to resolve translated type for " "%s[%lld]\n", idp->di_name, (longlong_t)ap->dn_value); } if (nnp->dn_type == CTF_ERR) { xyerror(D_ARGS_TYPE, "failed to resolve native type for " "%s[%lld]\n", idp->di_name, (longlong_t)ap->dn_value); } if (dtp->dt_xlatemode == DT_XL_STATIC && ( nnp == xnp || dt_node_is_argcompat(nnp, xnp))) { dnp->dn_ident = dt_ident_create(idp->di_name, idp->di_kind, idp->di_flags | DT_IDFLG_ORPHAN, idp->di_id, idp->di_attr, idp->di_vers, idp->di_ops, idp->di_iarg, idp->di_gen); if (dnp->dn_ident == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); dt_node_type_assign(dnp, prp->pr_argv[ap->dn_value].dtt_ctfp, prp->pr_argv[ap->dn_value].dtt_type); } else if ((dxp = dt_xlator_lookup(dtp, nnp, xnp, DT_XLATE_FUZZY)) != NULL || ( dxp = dt_xlator_lookup(dtp, dt_probe_tag(prp, ap->dn_value, &tag), xnp, DT_XLATE_EXACT | DT_XLATE_EXTERN)) != NULL) { xidp = dt_xlator_ident(dxp, xnp->dn_ctfp, xnp->dn_type); dnp->dn_ident = dt_ident_create(idp->di_name, xidp->di_kind, xidp->di_flags | DT_IDFLG_ORPHAN, idp->di_id, idp->di_attr, idp->di_vers, idp->di_ops, idp->di_iarg, idp->di_gen); if (dnp->dn_ident == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); if (dt_xlator_dynamic(dxp)) dxp->dx_arg = (int)ap->dn_value; /* * Propagate relevant members from the translator's internal * dt_ident_t. This code must be kept in sync with the state * that is initialized for idents in dt_xlator_create(). */ dnp->dn_ident->di_data = xidp->di_data; dnp->dn_ident->di_ctfp = xidp->di_ctfp; dnp->dn_ident->di_type = xidp->di_type; dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp)); } else { xyerror(D_ARGS_XLATOR, "translator for %s[%lld] from %s to %s " "is not defined\n", idp->di_name, (longlong_t)ap->dn_value, dt_node_type_name(nnp, n1, sizeof (n1)), dt_node_type_name(xnp, n2, sizeof (n2))); } assert(dnp->dn_ident->di_flags & DT_IDFLG_ORPHAN); assert(dnp->dn_ident->di_id == idp->di_id); }