4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <sys/sysmacros.h>
41 #include <sys/procfs_isa.h>
46 #include <dt_parser.h>
47 #include <dt_provider.h>
48 #include <dt_strtab.h>
52 * Common code for cooking an identifier that uses a typed signature list (we
53 * use this for associative arrays and functions). If the argument list is
54 * of the same length and types, then return the return type. Otherwise
55 * print an appropriate compiler error message and abort the compile.
58 dt_idcook_sign(dt_node_t *dnp, dt_ident_t *idp,
59 int argc, dt_node_t *args, const char *prefix, const char *suffix)
61 dt_idsig_t *isp = idp->di_data;
62 int i, compat, mismatch, arglimit, iskey;
64 char n1[DT_TYPE_NAMELEN];
65 char n2[DT_TYPE_NAMELEN];
67 iskey = idp->di_kind == DT_IDENT_ARRAY || idp->di_kind == DT_IDENT_AGG;
69 if (isp->dis_varargs >= 0) {
70 mismatch = argc < isp->dis_varargs;
71 arglimit = isp->dis_varargs;
72 } else if (isp->dis_optargs >= 0) {
73 mismatch = (argc < isp->dis_optargs || argc > isp->dis_argc);
76 mismatch = argc != isp->dis_argc;
77 arglimit = isp->dis_argc;
81 xyerror(D_PROTO_LEN, "%s%s%s prototype mismatch: %d %s%s"
82 "passed, %s%d expected\n", prefix, idp->di_name, suffix,
83 argc, iskey ? "key" : "arg", argc == 1 ? " " : "s ",
84 isp->dis_optargs >= 0 ? "at least " : "",
85 isp->dis_optargs >= 0 ? isp->dis_optargs : arglimit);
88 for (i = 0; i < arglimit; i++, args = args->dn_list) {
89 if (isp->dis_args[i].dn_ctfp != NULL)
90 compat = dt_node_is_argcompat(&isp->dis_args[i], args);
92 compat = 1; /* "@" matches any type */
96 "%s%s%s %s #%d is incompatible with "
97 "prototype:\n\tprototype: %s\n\t%9s: %s\n",
98 prefix, idp->di_name, suffix,
99 iskey ? "key" : "argument", i + 1,
100 dt_node_type_name(&isp->dis_args[i], n1,
102 iskey ? "key" : "argument",
103 dt_node_type_name(args, n2, sizeof (n2)));
107 dt_node_type_assign(dnp, idp->di_ctfp, idp->di_type);
111 * Cook an associative array identifier. If this is the first time we are
112 * cooking this array, create its signature based on the argument list.
113 * Otherwise validate the argument list against the existing signature.
116 dt_idcook_assc(dt_node_t *dnp, dt_ident_t *idp, int argc, dt_node_t *args)
118 if (idp->di_data == NULL) {
119 dt_idsig_t *isp = idp->di_data = malloc(sizeof (dt_idsig_t));
120 char n[DT_TYPE_NAMELEN];
124 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
126 isp->dis_varargs = -1;
127 isp->dis_optargs = -1;
128 isp->dis_argc = argc;
129 isp->dis_args = NULL;
130 isp->dis_auxinfo = 0;
132 if (argc != 0 && (isp->dis_args = calloc(argc,
133 sizeof (dt_node_t))) == NULL) {
136 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
140 * If this identifier has not been explicitly declared earlier,
141 * set the identifier's base type to be our special type <DYN>.
142 * If this ident is an aggregation, it will remain as is. If
143 * this ident is an associative array, it will be reassigned
144 * based on the result type of the first assignment statement.
146 if (!(idp->di_flags & DT_IDFLG_DECL)) {
147 idp->di_ctfp = DT_DYN_CTFP(yypcb->pcb_hdl);
148 idp->di_type = DT_DYN_TYPE(yypcb->pcb_hdl);
151 for (i = 0; i < argc; i++, args = args->dn_list) {
152 if (dt_node_is_dynamic(args) || dt_node_is_void(args)) {
153 xyerror(D_KEY_TYPE, "%s expression may not be "
154 "used as %s index: key #%d\n",
155 dt_node_type_name(args, n, sizeof (n)),
156 dt_idkind_name(idp->di_kind), i + 1);
159 dt_node_type_propagate(args, &isp->dis_args[i]);
160 isp->dis_args[i].dn_list = &isp->dis_args[i + 1];
164 isp->dis_args[argc - 1].dn_list = NULL;
166 dt_node_type_assign(dnp, idp->di_ctfp, idp->di_type);
169 dt_idcook_sign(dnp, idp, argc, args,
170 idp->di_kind == DT_IDENT_AGG ? "@" : "", "[ ]");
175 * Cook a function call. If this is the first time we are cooking this
176 * identifier, create its type signature based on predefined prototype stored
177 * in di_iarg. We then validate the argument list against this signature.
180 dt_idcook_func(dt_node_t *dnp, dt_ident_t *idp, int argc, dt_node_t *args)
182 if (idp->di_data == NULL) {
183 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
184 dtrace_typeinfo_t dtt;
189 assert(idp->di_iarg != NULL);
190 s = alloca(strlen(idp->di_iarg) + 1);
191 (void) strcpy(s, idp->di_iarg);
193 if ((p2 = strrchr(s, ')')) != NULL)
194 *p2 = '\0'; /* mark end of parameter list string */
196 if ((p1 = strchr(s, '(')) != NULL)
197 *p1++ = '\0'; /* mark end of return type string */
199 if (p1 == NULL || p2 == NULL) {
200 xyerror(D_UNKNOWN, "internal error: malformed entry "
201 "for built-in function %s\n", idp->di_name);
204 for (p2 = p1; *p2 != '\0'; p2++) {
211 for (p2 = strchr(p2, ','); p2++ != NULL; i++)
212 p2 = strchr(p2, ',');
215 * We first allocate a new ident signature structure with the
216 * appropriate number of argument entries, and then look up
217 * the return type and store its CTF data in di_ctfp/type.
219 if ((isp = idp->di_data = malloc(sizeof (dt_idsig_t))) == NULL)
220 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
222 isp->dis_varargs = -1;
223 isp->dis_optargs = -1;
225 isp->dis_args = NULL;
226 isp->dis_auxinfo = 0;
228 if (i != 0 && (isp->dis_args = calloc(i,
229 sizeof (dt_node_t))) == NULL) {
232 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
235 if (dt_type_lookup(s, &dtt) == -1) {
236 xyerror(D_UNKNOWN, "failed to resolve type of %s (%s):"
237 " %s\n", idp->di_name, s,
238 dtrace_errmsg(dtp, dtrace_errno(dtp)));
241 if (idp->di_kind == DT_IDENT_AGGFUNC) {
242 idp->di_ctfp = DT_DYN_CTFP(dtp);
243 idp->di_type = DT_DYN_TYPE(dtp);
245 idp->di_ctfp = dtt.dtt_ctfp;
246 idp->di_type = dtt.dtt_type;
250 * For each comma-delimited parameter in the prototype string,
251 * we look up the corresponding type and store its CTF data in
252 * the corresponding location in dis_args[]. We also recognize
253 * the special type string "@" to indicate that the specified
254 * parameter may be a D expression of *any* type (represented
255 * as a dis_args[] element with ctfp = NULL, type == CTF_ERR).
256 * If a varargs "..." is present, we record the argument index
257 * in dis_varargs for the benefit of dt_idcook_sign(), above.
258 * If the type of an argument is enclosed in square brackets
259 * (e.g. "[int]"), the argument is considered optional: the
260 * argument may be absent, but if it is present, it must be of
261 * the specified type. Note that varargs may not optional,
262 * optional arguments may not follow varargs, and non-optional
263 * arguments may not follow optional arguments.
265 for (i = 0; i < isp->dis_argc; i++, p1 = p2) {
267 p1++; /* skip leading whitespace */
269 if ((p2 = strchr(p1, ',')) == NULL)
270 p2 = p1 + strlen(p1);
274 if (strcmp(p1, "@") == 0 || strcmp(p1, "...") == 0) {
275 isp->dis_args[i].dn_ctfp = NULL;
276 isp->dis_args[i].dn_type = CTF_ERR;
278 isp->dis_varargs = i;
282 if (*p1 == '[' && p1[strlen(p1) - 1] == ']') {
283 if (isp->dis_varargs != -1) {
284 xyerror(D_UNKNOWN, "optional arg#%d "
285 "may not follow variable arg#%d\n",
286 i + 1, isp->dis_varargs + 1);
289 if (isp->dis_optargs == -1)
290 isp->dis_optargs = i;
292 p1[strlen(p1) - 1] = '\0';
294 } else if (isp->dis_optargs != -1) {
295 xyerror(D_UNKNOWN, "required arg#%d may not "
296 "follow optional arg#%d\n", i + 1,
297 isp->dis_optargs + 1);
300 if (dt_type_lookup(p1, &dtt) == -1) {
301 xyerror(D_UNKNOWN, "failed to resolve type of "
302 "%s arg#%d (%s): %s\n", idp->di_name, i + 1,
303 p1, dtrace_errmsg(dtp, dtrace_errno(dtp)));
306 dt_node_type_assign(&isp->dis_args[i],
307 dtt.dtt_ctfp, dtt.dtt_type);
311 dt_idcook_sign(dnp, idp, argc, args, "", "( )");
315 * Cook a reference to the dynamically typed args[] array. We verify that the
316 * reference is using a single integer constant, and then construct a new ident
317 * representing the appropriate type or translation specifically for this node.
320 dt_idcook_args(dt_node_t *dnp, dt_ident_t *idp, int argc, dt_node_t *ap)
322 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
323 dt_probe_t *prp = yypcb->pcb_probe;
325 dt_node_t tag, *nnp, *xnp;
329 char n1[DT_TYPE_NAMELEN];
330 char n2[DT_TYPE_NAMELEN];
333 xyerror(D_PROTO_LEN, "%s[ ] prototype mismatch: %d arg%s"
334 "passed, 1 expected\n", idp->di_name, argc,
335 argc == 1 ? " " : "s ");
338 if (ap->dn_kind != DT_NODE_INT) {
339 xyerror(D_PROTO_ARG, "%s[ ] argument #1 is incompatible with "
340 "prototype:\n\tprototype: %s\n\t argument: %s\n",
341 idp->di_name, "integer constant",
342 dt_type_name(ap->dn_ctfp, ap->dn_type, n1, sizeof (n1)));
345 if (yypcb->pcb_pdesc == NULL) {
346 xyerror(D_ARGS_NONE, "%s[ ] may not be referenced outside "
347 "of a probe clause\n", idp->di_name);
351 xyerror(D_ARGS_MULTI,
352 "%s[ ] may not be referenced because probe description %s "
353 "matches an unstable set of probes\n", idp->di_name,
354 dtrace_desc2str(yypcb->pcb_pdesc, n1, sizeof (n1)));
357 if (ap->dn_value >= prp->pr_argc) {
358 xyerror(D_ARGS_IDX, "index %lld is out of range for %s %s[ ]\n",
359 (longlong_t)ap->dn_value, dtrace_desc2str(yypcb->pcb_pdesc,
360 n1, sizeof (n1)), idp->di_name);
364 * Look up the native and translated argument types for the probe.
365 * If no translation is needed, these will be the same underlying node.
366 * If translation is needed, look up the appropriate translator. Once
367 * we have the appropriate node, create a new dt_ident_t for this node,
368 * assign it the appropriate attributes, and set the type of 'dnp'.
370 xnp = prp->pr_xargv[ap->dn_value];
371 nnp = prp->pr_nargv[prp->pr_mapping[ap->dn_value]];
373 if (xnp->dn_type == CTF_ERR) {
374 xyerror(D_ARGS_TYPE, "failed to resolve translated type for "
375 "%s[%lld]\n", idp->di_name, (longlong_t)ap->dn_value);
378 if (nnp->dn_type == CTF_ERR) {
379 xyerror(D_ARGS_TYPE, "failed to resolve native type for "
380 "%s[%lld]\n", idp->di_name, (longlong_t)ap->dn_value);
383 if (dtp->dt_xlatemode == DT_XL_STATIC && (
384 nnp == xnp || dt_node_is_argcompat(nnp, xnp))) {
385 dnp->dn_ident = dt_ident_create(idp->di_name, idp->di_kind,
386 idp->di_flags | DT_IDFLG_ORPHAN, idp->di_id, idp->di_attr,
387 idp->di_vers, idp->di_ops, idp->di_iarg, idp->di_gen);
389 if (dnp->dn_ident == NULL)
390 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
392 dt_node_type_assign(dnp,
393 prp->pr_argv[ap->dn_value].dtt_ctfp,
394 prp->pr_argv[ap->dn_value].dtt_type);
396 } else if ((dxp = dt_xlator_lookup(dtp,
397 nnp, xnp, DT_XLATE_FUZZY)) != NULL || (
398 dxp = dt_xlator_lookup(dtp, dt_probe_tag(prp, ap->dn_value, &tag),
399 xnp, DT_XLATE_EXACT | DT_XLATE_EXTERN)) != NULL) {
401 xidp = dt_xlator_ident(dxp, xnp->dn_ctfp, xnp->dn_type);
403 dnp->dn_ident = dt_ident_create(idp->di_name, xidp->di_kind,
404 xidp->di_flags | DT_IDFLG_ORPHAN, idp->di_id, idp->di_attr,
405 idp->di_vers, idp->di_ops, idp->di_iarg, idp->di_gen);
407 if (dnp->dn_ident == NULL)
408 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
410 if (dt_xlator_dynamic(dxp))
411 dxp->dx_arg = (int)ap->dn_value;
414 * Propagate relevant members from the translator's internal
415 * dt_ident_t. This code must be kept in sync with the state
416 * that is initialized for idents in dt_xlator_create().
418 dnp->dn_ident->di_data = xidp->di_data;
419 dnp->dn_ident->di_ctfp = xidp->di_ctfp;
420 dnp->dn_ident->di_type = xidp->di_type;
422 dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
425 xyerror(D_ARGS_XLATOR, "translator for %s[%lld] from %s to %s "
426 "is not defined\n", idp->di_name, (longlong_t)ap->dn_value,
427 dt_node_type_name(nnp, n1, sizeof (n1)),
428 dt_node_type_name(xnp, n2, sizeof (n2)));
431 assert(dnp->dn_ident->di_flags & DT_IDFLG_ORPHAN);
432 assert(dnp->dn_ident->di_id == idp->di_id);
436 dt_idcook_regs(dt_node_t *dnp, dt_ident_t *idp, int argc, dt_node_t *ap)
438 dtrace_typeinfo_t dtt;
439 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
440 char n[DT_TYPE_NAMELEN];
443 xyerror(D_PROTO_LEN, "%s[ ] prototype mismatch: %d arg%s"
444 "passed, 1 expected\n", idp->di_name,
445 argc, argc == 1 ? " " : "s ");
448 if (ap->dn_kind != DT_NODE_INT) {
449 xyerror(D_PROTO_ARG, "%s[ ] argument #1 is incompatible with "
450 "prototype:\n\tprototype: %s\n\t argument: %s\n",
451 idp->di_name, "integer constant",
452 dt_type_name(ap->dn_ctfp, ap->dn_type, n, sizeof (n)));
455 if ((ap->dn_flags & DT_NF_SIGNED) && (int64_t)ap->dn_value < 0) {
456 xyerror(D_REGS_IDX, "index %lld is out of range for array %s\n",
457 (longlong_t)ap->dn_value, idp->di_name);
460 if (dt_type_lookup("uint64_t", &dtt) == -1) {
461 xyerror(D_UNKNOWN, "failed to resolve type of %s: %s\n",
462 idp->di_name, dtrace_errmsg(dtp, dtrace_errno(dtp)));
465 idp->di_ctfp = dtt.dtt_ctfp;
466 idp->di_type = dtt.dtt_type;
468 dt_node_type_assign(dnp, idp->di_ctfp, idp->di_type);
473 dt_idcook_type(dt_node_t *dnp, dt_ident_t *idp, int argc, dt_node_t *args)
475 if (idp->di_type == CTF_ERR) {
476 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
477 dtrace_typeinfo_t dtt;
479 if (dt_type_lookup(idp->di_iarg, &dtt) == -1) {
481 "failed to resolve type %s for identifier %s: %s\n",
482 (const char *)idp->di_iarg, idp->di_name,
483 dtrace_errmsg(dtp, dtrace_errno(dtp)));
486 idp->di_ctfp = dtt.dtt_ctfp;
487 idp->di_type = dtt.dtt_type;
490 dt_node_type_assign(dnp, idp->di_ctfp, idp->di_type);
495 dt_idcook_thaw(dt_node_t *dnp, dt_ident_t *idp, int argc, dt_node_t *args)
497 if (idp->di_ctfp != NULL && idp->di_type != CTF_ERR)
498 dt_node_type_assign(dnp, idp->di_ctfp, idp->di_type);
502 dt_idcook_inline(dt_node_t *dnp, dt_ident_t *idp, int argc, dt_node_t *args)
504 if (idp->di_kind == DT_IDENT_ARRAY)
505 dt_idcook_assc(dnp, idp, argc, args);
507 dt_idcook_thaw(dnp, idp, argc, args);
511 dt_iddtor_sign(dt_ident_t *idp)
513 if (idp->di_data != NULL)
514 free(((dt_idsig_t *)idp->di_data)->dis_args);
519 dt_iddtor_free(dt_ident_t *idp)
525 dt_iddtor_inline(dt_ident_t *idp)
527 dt_idnode_t *inp = idp->di_iarg;
530 dt_node_link_free(&inp->din_list);
532 if (inp->din_hash != NULL)
533 dt_idhash_destroy(inp->din_hash);
539 if (idp->di_kind == DT_IDENT_ARRAY)
547 dt_iddtor_none(dt_ident_t *idp)
553 dt_iddtor_probe(dt_ident_t *idp)
555 if (idp->di_data != NULL)
556 dt_probe_destroy(idp->di_data);
560 dt_idsize_type(dt_ident_t *idp)
562 return (ctf_type_size(idp->di_ctfp, idp->di_type));
567 dt_idsize_none(dt_ident_t *idp)
572 const dt_idops_t dt_idops_assc = {
578 const dt_idops_t dt_idops_func = {
584 const dt_idops_t dt_idops_args = {
590 const dt_idops_t dt_idops_regs = {
596 const dt_idops_t dt_idops_type = {
602 const dt_idops_t dt_idops_thaw = {
608 const dt_idops_t dt_idops_inline = {
614 const dt_idops_t dt_idops_probe = {
621 dt_idhash_populate(dt_idhash_t *dhp)
623 const dt_ident_t *idp = dhp->dh_tmpl;
625 dhp->dh_tmpl = NULL; /* clear dh_tmpl first to avoid recursion */
626 dt_dprintf("populating %s idhash from %p\n", dhp->dh_name, (void *)idp);
628 for (; idp->di_name != NULL; idp++) {
629 if (dt_idhash_insert(dhp, idp->di_name,
630 idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr,
631 idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw,
632 idp->di_iarg, 0) == NULL)
633 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
638 dt_idhash_create(const char *name, const dt_ident_t *tmpl,
639 uint_t min, uint_t max)
646 size = sizeof (dt_idhash_t) +
647 sizeof (dt_ident_t *) * (_dtrace_strbuckets - 1);
649 if ((dhp = malloc(size)) == NULL)
655 dhp->dh_nextid = min;
658 dhp->dh_hashsz = _dtrace_strbuckets;
664 * Destroy an entire identifier hash. This must be done using two passes with
665 * an inlined version of dt_ident_destroy() to avoid referencing freed memory.
666 * In the first pass di_dtor() is called for all identifiers; then the second
667 * pass frees the actual dt_ident_t's. These must be done separately because
668 * a di_dtor() may operate on data structures which contain references to other
669 * identifiers inside of this hash itself (e.g. a global inline definition
670 * which contains a parse tree that refers to another global variable).
673 dt_idhash_destroy(dt_idhash_t *dhp)
675 dt_ident_t *idp, *next;
678 for (i = 0; i < dhp->dh_hashsz; i++) {
679 for (idp = dhp->dh_hash[i]; idp != NULL; idp = next) {
681 idp->di_ops->di_dtor(idp);
685 for (i = 0; i < dhp->dh_hashsz; i++) {
686 for (idp = dhp->dh_hash[i]; idp != NULL; idp = next) {
697 dt_idhash_update(dt_idhash_t *dhp)
699 uint_t nextid = dhp->dh_minid;
703 for (i = 0; i < dhp->dh_hashsz; i++) {
704 for (idp = dhp->dh_hash[i]; idp != NULL; idp = idp->di_next) {
706 * Right now we're hard coding which types need to be
707 * reset, but ideally this would be done dynamically.
709 if (idp->di_kind == DT_IDENT_ARRAY ||
710 idp->di_kind == DT_IDENT_SCALAR ||
711 idp->di_kind == DT_IDENT_AGG)
712 nextid = MAX(nextid, idp->di_id + 1);
716 dhp->dh_nextid = nextid;
720 dt_idhash_lookup(dt_idhash_t *dhp, const char *name)
723 ulong_t h = dt_strtab_hash(name, &len) % dhp->dh_hashsz;
726 if (dhp->dh_tmpl != NULL)
727 dt_idhash_populate(dhp); /* fill hash w/ initial population */
729 for (idp = dhp->dh_hash[h]; idp != NULL; idp = idp->di_next) {
730 if (strcmp(idp->di_name, name) == 0)
738 dt_idhash_nextid(dt_idhash_t *dhp, uint_t *p)
740 if (dhp->dh_nextid >= dhp->dh_maxid)
741 return (-1); /* no more id's are free to allocate */
743 *p = dhp->dh_nextid++;
748 dt_idhash_size(const dt_idhash_t *dhp)
750 return (dhp->dh_nelems);
754 dt_idhash_name(const dt_idhash_t *dhp)
756 return (dhp->dh_name);
760 dt_idhash_insert(dt_idhash_t *dhp, const char *name, ushort_t kind,
761 ushort_t flags, uint_t id, dtrace_attribute_t attr, uint_t vers,
762 const dt_idops_t *ops, void *iarg, ulong_t gen)
767 if (dhp->dh_tmpl != NULL)
768 dt_idhash_populate(dhp); /* fill hash w/ initial population */
770 idp = dt_ident_create(name, kind, flags, id,
771 attr, vers, ops, iarg, gen);
776 h = dt_strtab_hash(name, NULL) % dhp->dh_hashsz;
777 idp->di_next = dhp->dh_hash[h];
779 dhp->dh_hash[h] = idp;
782 if (dhp->dh_defer != NULL)
783 dhp->dh_defer(dhp, idp);
789 dt_idhash_xinsert(dt_idhash_t *dhp, dt_ident_t *idp)
793 if (dhp->dh_tmpl != NULL)
794 dt_idhash_populate(dhp); /* fill hash w/ initial population */
796 h = dt_strtab_hash(idp->di_name, NULL) % dhp->dh_hashsz;
797 idp->di_next = dhp->dh_hash[h];
798 idp->di_flags &= ~DT_IDFLG_ORPHAN;
800 dhp->dh_hash[h] = idp;
803 if (dhp->dh_defer != NULL)
804 dhp->dh_defer(dhp, idp);
808 dt_idhash_delete(dt_idhash_t *dhp, dt_ident_t *key)
811 ulong_t h = dt_strtab_hash(key->di_name, &len) % dhp->dh_hashsz;
812 dt_ident_t **pp = &dhp->dh_hash[h];
815 for (idp = dhp->dh_hash[h]; idp != NULL; idp = idp->di_next) {
825 assert(dhp->dh_nelems != 0);
828 if (!(idp->di_flags & DT_IDFLG_ORPHAN))
829 dt_ident_destroy(idp);
833 dt_idhash_comp(const void *lp, const void *rp)
835 const dt_ident_t *lhs = *((const dt_ident_t **)lp);
836 const dt_ident_t *rhs = *((const dt_ident_t **)rp);
838 if (lhs->di_id != rhs->di_id)
839 return ((int)(lhs->di_id - rhs->di_id));
841 return (strcmp(lhs->di_name, rhs->di_name));
845 dt_idhash_iter(dt_idhash_t *dhp, dt_idhash_f *func, void *data)
852 if (dhp->dh_tmpl != NULL)
853 dt_idhash_populate(dhp); /* fill hash w/ initial population */
856 ids = alloca(sizeof (dt_ident_t *) * n);
858 for (i = 0, j = 0; i < dhp->dh_hashsz; i++) {
859 for (idp = dhp->dh_hash[i]; idp != NULL; idp = idp->di_next)
863 qsort(ids, dhp->dh_nelems, sizeof (dt_ident_t *), dt_idhash_comp);
865 for (i = 0; i < n; i++) {
866 if ((rv = func(dhp, ids[i], data)) != 0)
874 dt_idstack_lookup(dt_idstack_t *sp, const char *name)
879 for (dhp = dt_list_prev(&sp->dids_list);
880 dhp != NULL; dhp = dt_list_prev(dhp)) {
881 if ((idp = dt_idhash_lookup(dhp, name)) != NULL)
889 dt_idstack_push(dt_idstack_t *sp, dt_idhash_t *dhp)
891 dt_list_append(&sp->dids_list, dhp);
895 dt_idstack_pop(dt_idstack_t *sp, dt_idhash_t *dhp)
897 assert(dt_list_prev(&sp->dids_list) == dhp);
898 dt_list_delete(&sp->dids_list, dhp);
902 dt_ident_create(const char *name, ushort_t kind, ushort_t flags, uint_t id,
903 dtrace_attribute_t attr, uint_t vers,
904 const dt_idops_t *ops, void *iarg, ulong_t gen)
909 if ((name != NULL && (s = strdup(name)) == NULL) ||
910 (idp = malloc(sizeof (dt_ident_t))) == NULL) {
917 idp->di_flags = flags;
925 idp->di_type = CTF_ERR;
928 idp->di_lineno = yylineno;
934 * Destroy an individual identifier. This code must be kept in sync with the
935 * dt_idhash_destroy() function below, which separates out the call to di_dtor.
938 dt_ident_destroy(dt_ident_t *idp)
940 idp->di_ops->di_dtor(idp);
946 dt_ident_morph(dt_ident_t *idp, ushort_t kind,
947 const dt_idops_t *ops, void *iarg)
949 idp->di_ops->di_dtor(idp);
957 dt_ident_cook(dt_node_t *dnp, dt_ident_t *idp, dt_node_t **pargp)
959 dtrace_attribute_t attr;
960 dt_node_t *args, *argp;
963 attr = dt_node_list_cook(pargp, DT_IDFLG_REF);
964 args = pargp ? *pargp : NULL;
966 for (argp = args; argp != NULL; argp = argp->dn_list)
969 idp->di_ops->di_cook(dnp, idp, argc, args);
971 if (idp->di_flags & DT_IDFLG_USER)
972 dnp->dn_flags |= DT_NF_USERLAND;
974 return (dt_attr_min(attr, idp->di_attr));
978 dt_ident_type_assign(dt_ident_t *idp, ctf_file_t *fp, ctf_id_t type)
985 dt_ident_resolve(dt_ident_t *idp)
987 while (idp->di_flags & DT_IDFLG_INLINE) {
988 const dt_node_t *dnp = ((dt_idnode_t *)idp->di_iarg)->din_root;
991 break; /* can't resolve any further yet */
993 switch (dnp->dn_kind) {
1000 idp = dnp->dn_ident;
1004 if (dt_node_is_dynamic(dnp))
1005 idp = dnp->dn_ident;
1014 dt_ident_size(dt_ident_t *idp)
1016 idp = dt_ident_resolve(idp);
1017 return (idp->di_ops->di_size(idp));
1021 dt_ident_unref(const dt_ident_t *idp)
1023 return (idp->di_gen == yypcb->pcb_hdl->dt_gen &&
1024 (idp->di_flags & (DT_IDFLG_REF|DT_IDFLG_MOD|DT_IDFLG_DECL)) == 0);
1028 dt_idkind_name(uint_t kind)
1031 case DT_IDENT_ARRAY: return ("associative array");
1032 case DT_IDENT_SCALAR: return ("scalar");
1033 case DT_IDENT_PTR: return ("pointer");
1034 case DT_IDENT_FUNC: return ("function");
1035 case DT_IDENT_AGG: return ("aggregation");
1036 case DT_IDENT_AGGFUNC: return ("aggregating function");
1037 case DT_IDENT_ACTFUNC: return ("tracing function");
1038 case DT_IDENT_XLSOU: return ("translated data");
1039 case DT_IDENT_XLPTR: return ("pointer to translated data");
1040 case DT_IDENT_SYMBOL: return ("external symbol reference");
1041 case DT_IDENT_ENUM: return ("enumerator");
1042 case DT_IDENT_PRAGAT: return ("#pragma attributes");
1043 case DT_IDENT_PRAGBN: return ("#pragma binding");
1044 case DT_IDENT_PROBE: return ("probe definition");
1045 default: return ("<?>");