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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013 by Delphix. All rights reserved.
25 * Copyright (c) 2013 Joyent, Inc. All rights reserved.
28 #include <sys/sysmacros.h>
35 #include <sys/procfs_isa.h>
39 #include <dt_parser.h>
40 #include <dt_provider.h>
41 #include <dt_strtab.h>
45 * Common code for cooking an identifier that uses a typed signature list (we
46 * use this for associative arrays and functions). If the argument list is
47 * of the same length and types, then return the return type. Otherwise
48 * print an appropriate compiler error message and abort the compile.
51 dt_idcook_sign(dt_node_t
*dnp
, dt_ident_t
*idp
,
52 int argc
, dt_node_t
*args
, const char *prefix
, const char *suffix
)
54 dt_idsig_t
*isp
= idp
->di_data
;
55 int i
, compat
, mismatch
, arglimit
, iskey
;
57 char n1
[DT_TYPE_NAMELEN
];
58 char n2
[DT_TYPE_NAMELEN
];
60 iskey
= idp
->di_kind
== DT_IDENT_ARRAY
|| idp
->di_kind
== DT_IDENT_AGG
;
62 if (isp
->dis_varargs
>= 0) {
63 mismatch
= argc
< isp
->dis_varargs
;
64 arglimit
= isp
->dis_varargs
;
65 } else if (isp
->dis_optargs
>= 0) {
66 mismatch
= (argc
< isp
->dis_optargs
|| argc
> isp
->dis_argc
);
69 mismatch
= argc
!= isp
->dis_argc
;
70 arglimit
= isp
->dis_argc
;
74 xyerror(D_PROTO_LEN
, "%s%s%s prototype mismatch: %d %s%s"
75 "passed, %s%d expected\n", prefix
, idp
->di_name
, suffix
,
76 argc
, iskey
? "key" : "arg", argc
== 1 ? " " : "s ",
77 isp
->dis_optargs
>= 0 ? "at least " : "",
78 isp
->dis_optargs
>= 0 ? isp
->dis_optargs
: arglimit
);
81 for (i
= 0; i
< arglimit
; i
++, args
= args
->dn_list
) {
82 if (isp
->dis_args
[i
].dn_ctfp
!= NULL
)
83 compat
= dt_node_is_argcompat(&isp
->dis_args
[i
], args
);
85 compat
= 1; /* "@" matches any type */
89 "%s%s%s %s #%d is incompatible with "
90 "prototype:\n\tprototype: %s\n\t%9s: %s\n",
91 prefix
, idp
->di_name
, suffix
,
92 iskey
? "key" : "argument", i
+ 1,
93 dt_node_type_name(&isp
->dis_args
[i
], n1
,
95 iskey
? "key" : "argument",
96 dt_node_type_name(args
, n2
, sizeof (n2
)));
100 dt_node_type_assign(dnp
, idp
->di_ctfp
, idp
->di_type
, B_FALSE
);
104 * Cook an associative array identifier. If this is the first time we are
105 * cooking this array, create its signature based on the argument list.
106 * Otherwise validate the argument list against the existing signature.
109 dt_idcook_assc(dt_node_t
*dnp
, dt_ident_t
*idp
, int argc
, dt_node_t
*args
)
111 if (idp
->di_data
== NULL
) {
112 dt_idsig_t
*isp
= idp
->di_data
= malloc(sizeof (dt_idsig_t
));
113 char n
[DT_TYPE_NAMELEN
];
117 longjmp(yypcb
->pcb_jmpbuf
, EDT_NOMEM
);
119 isp
->dis_varargs
= -1;
120 isp
->dis_optargs
= -1;
121 isp
->dis_argc
= argc
;
122 isp
->dis_args
= NULL
;
123 isp
->dis_auxinfo
= 0;
125 if (argc
!= 0 && (isp
->dis_args
= calloc(argc
,
126 sizeof (dt_node_t
))) == NULL
) {
129 longjmp(yypcb
->pcb_jmpbuf
, EDT_NOMEM
);
133 * If this identifier has not been explicitly declared earlier,
134 * set the identifier's base type to be our special type <DYN>.
135 * If this ident is an aggregation, it will remain as is. If
136 * this ident is an associative array, it will be reassigned
137 * based on the result type of the first assignment statement.
139 if (!(idp
->di_flags
& DT_IDFLG_DECL
)) {
140 idp
->di_ctfp
= DT_DYN_CTFP(yypcb
->pcb_hdl
);
141 idp
->di_type
= DT_DYN_TYPE(yypcb
->pcb_hdl
);
144 for (i
= 0; i
< argc
; i
++, args
= args
->dn_list
) {
145 if (dt_node_is_dynamic(args
) || dt_node_is_void(args
)) {
146 xyerror(D_KEY_TYPE
, "%s expression may not be "
147 "used as %s index: key #%d\n",
148 dt_node_type_name(args
, n
, sizeof (n
)),
149 dt_idkind_name(idp
->di_kind
), i
+ 1);
152 dt_node_type_propagate(args
, &isp
->dis_args
[i
]);
153 isp
->dis_args
[i
].dn_list
= &isp
->dis_args
[i
+ 1];
157 isp
->dis_args
[argc
- 1].dn_list
= NULL
;
159 dt_node_type_assign(dnp
, idp
->di_ctfp
, idp
->di_type
, B_FALSE
);
162 dt_idcook_sign(dnp
, idp
, argc
, args
,
163 idp
->di_kind
== DT_IDENT_AGG
? "@" : "", "[ ]");
168 * Cook a function call. If this is the first time we are cooking this
169 * identifier, create its type signature based on predefined prototype stored
170 * in di_iarg. We then validate the argument list against this signature.
173 dt_idcook_func(dt_node_t
*dnp
, dt_ident_t
*idp
, int argc
, dt_node_t
*args
)
175 if (idp
->di_data
== NULL
) {
176 dtrace_hdl_t
*dtp
= yypcb
->pcb_hdl
;
177 dtrace_typeinfo_t dtt
;
182 assert(idp
->di_iarg
!= NULL
);
183 s
= strdupa(idp
->di_iarg
);
185 if ((p2
= strrchr(s
, ')')) != NULL
)
186 *p2
= '\0'; /* mark end of parameter list string */
188 if ((p1
= strchr(s
, '(')) != NULL
)
189 *p1
++ = '\0'; /* mark end of return type string */
191 if (p1
== NULL
|| p2
== NULL
) {
192 xyerror(D_UNKNOWN
, "internal error: malformed entry "
193 "for built-in function %s\n", idp
->di_name
);
196 for (p2
= p1
; *p2
!= '\0'; p2
++) {
203 for (p2
= strchr(p2
, ','); p2
++ != NULL
; i
++)
204 p2
= strchr(p2
, ',');
207 * We first allocate a new ident signature structure with the
208 * appropriate number of argument entries, and then look up
209 * the return type and store its CTF data in di_ctfp/type.
211 if ((isp
= idp
->di_data
= malloc(sizeof (dt_idsig_t
))) == NULL
)
212 longjmp(yypcb
->pcb_jmpbuf
, EDT_NOMEM
);
214 isp
->dis_varargs
= -1;
215 isp
->dis_optargs
= -1;
217 isp
->dis_args
= NULL
;
218 isp
->dis_auxinfo
= 0;
220 if (i
!= 0 && (isp
->dis_args
= calloc(i
,
221 sizeof (dt_node_t
))) == NULL
) {
224 longjmp(yypcb
->pcb_jmpbuf
, EDT_NOMEM
);
227 if (dt_type_lookup(s
, &dtt
) == -1) {
228 xyerror(D_UNKNOWN
, "failed to resolve type of %s (%s):"
229 " %s\n", idp
->di_name
, s
,
230 dtrace_errmsg(dtp
, dtrace_errno(dtp
)));
233 if (idp
->di_kind
== DT_IDENT_AGGFUNC
) {
234 idp
->di_ctfp
= DT_DYN_CTFP(dtp
);
235 idp
->di_type
= DT_DYN_TYPE(dtp
);
237 idp
->di_ctfp
= dtt
.dtt_ctfp
;
238 idp
->di_type
= dtt
.dtt_type
;
242 * For each comma-delimited parameter in the prototype string,
243 * we look up the corresponding type and store its CTF data in
244 * the corresponding location in dis_args[]. We also recognize
245 * the special type string "@" to indicate that the specified
246 * parameter may be a D expression of *any* type (represented
247 * as a dis_args[] element with ctfp = NULL, type == CTF_ERR).
248 * If a varargs "..." is present, we record the argument index
249 * in dis_varargs for the benefit of dt_idcook_sign(), above.
250 * If the type of an argument is enclosed in square brackets
251 * (e.g. "[int]"), the argument is considered optional: the
252 * argument may be absent, but if it is present, it must be of
253 * the specified type. Note that varargs may not optional,
254 * optional arguments may not follow varargs, and non-optional
255 * arguments may not follow optional arguments.
257 for (i
= 0; i
< isp
->dis_argc
; i
++, p1
= p2
) {
259 p1
++; /* skip leading whitespace */
261 if ((p2
= strchr(p1
, ',')) == NULL
)
262 p2
= p1
+ strlen(p1
);
266 if (strcmp(p1
, "@") == 0 || strcmp(p1
, "...") == 0) {
267 isp
->dis_args
[i
].dn_ctfp
= NULL
;
268 isp
->dis_args
[i
].dn_type
= CTF_ERR
;
270 isp
->dis_varargs
= i
;
274 if (*p1
== '[' && p1
[strlen(p1
) - 1] == ']') {
275 if (isp
->dis_varargs
!= -1) {
276 xyerror(D_UNKNOWN
, "optional arg#%d "
277 "may not follow variable arg#%d\n",
278 i
+ 1, isp
->dis_varargs
+ 1);
281 if (isp
->dis_optargs
== -1)
282 isp
->dis_optargs
= i
;
284 p1
[strlen(p1
) - 1] = '\0';
286 } else if (isp
->dis_optargs
!= -1) {
287 xyerror(D_UNKNOWN
, "required arg#%d may not "
288 "follow optional arg#%d\n", i
+ 1,
289 isp
->dis_optargs
+ 1);
292 if (dt_type_lookup(p1
, &dtt
) == -1) {
293 xyerror(D_UNKNOWN
, "failed to resolve type of "
294 "%s arg#%d (%s): %s\n", idp
->di_name
, i
+ 1,
295 p1
, dtrace_errmsg(dtp
, dtrace_errno(dtp
)));
298 dt_node_type_assign(&isp
->dis_args
[i
],
299 dtt
.dtt_ctfp
, dtt
.dtt_type
, B_FALSE
);
303 dt_idcook_sign(dnp
, idp
, argc
, args
, "", "( )");
307 * Cook a reference to the dynamically typed args[] array. We verify that the
308 * reference is using a single integer constant, and then construct a new ident
309 * representing the appropriate type or translation specifically for this node.
312 dt_idcook_args(dt_node_t
*dnp
, dt_ident_t
*idp
, int argc
, dt_node_t
*ap
)
314 dtrace_hdl_t
*dtp
= yypcb
->pcb_hdl
;
315 dt_probe_t
*prp
= yypcb
->pcb_probe
;
317 dt_node_t tag
, *nnp
, *xnp
;
321 char n1
[DT_TYPE_NAMELEN
];
322 char n2
[DT_TYPE_NAMELEN
];
325 xyerror(D_PROTO_LEN
, "%s[ ] prototype mismatch: %d arg%s"
326 "passed, 1 expected\n", idp
->di_name
, argc
,
327 argc
== 1 ? " " : "s ");
330 if (ap
->dn_kind
!= DT_NODE_INT
) {
331 xyerror(D_PROTO_ARG
, "%s[ ] argument #1 is incompatible with "
332 "prototype:\n\tprototype: %s\n\t argument: %s\n",
333 idp
->di_name
, "integer constant",
334 dt_type_name(ap
->dn_ctfp
, ap
->dn_type
, n1
, sizeof (n1
)));
337 if (yypcb
->pcb_pdesc
== NULL
) {
338 xyerror(D_ARGS_NONE
, "%s[ ] may not be referenced outside "
339 "of a probe clause\n", idp
->di_name
);
343 xyerror(D_ARGS_MULTI
,
344 "%s[ ] may not be referenced because probe description %s "
345 "matches an unstable set of probes\n", idp
->di_name
,
346 dtrace_desc2str(yypcb
->pcb_pdesc
, n1
, sizeof (n1
)));
349 if (ap
->dn_value
>= prp
->pr_argc
) {
350 xyerror(D_ARGS_IDX
, "index %lld is out of range for %s %s[ ]\n",
351 (longlong_t
)ap
->dn_value
, dtrace_desc2str(yypcb
->pcb_pdesc
,
352 n1
, sizeof (n1
)), idp
->di_name
);
356 * Look up the native and translated argument types for the probe.
357 * If no translation is needed, these will be the same underlying node.
358 * If translation is needed, look up the appropriate translator. Once
359 * we have the appropriate node, create a new dt_ident_t for this node,
360 * assign it the appropriate attributes, and set the type of 'dnp'.
362 xnp
= prp
->pr_xargv
[ap
->dn_value
];
363 nnp
= prp
->pr_nargv
[prp
->pr_mapping
[ap
->dn_value
]];
365 if (xnp
->dn_type
== CTF_ERR
) {
366 xyerror(D_ARGS_TYPE
, "failed to resolve translated type for "
367 "%s[%lld]\n", idp
->di_name
, (longlong_t
)ap
->dn_value
);
370 if (nnp
->dn_type
== CTF_ERR
) {
371 xyerror(D_ARGS_TYPE
, "failed to resolve native type for "
372 "%s[%lld]\n", idp
->di_name
, (longlong_t
)ap
->dn_value
);
375 if (dtp
->dt_xlatemode
== DT_XL_STATIC
&& (
376 nnp
== xnp
|| dt_node_is_argcompat(nnp
, xnp
))) {
377 dnp
->dn_ident
= dt_ident_create(idp
->di_name
, idp
->di_kind
,
378 idp
->di_flags
| DT_IDFLG_ORPHAN
, idp
->di_id
, idp
->di_attr
,
379 idp
->di_vers
, idp
->di_ops
, idp
->di_iarg
, idp
->di_gen
);
381 if (dnp
->dn_ident
== NULL
)
382 longjmp(yypcb
->pcb_jmpbuf
, EDT_NOMEM
);
384 dt_node_type_assign(dnp
,
385 prp
->pr_argv
[ap
->dn_value
].dtt_ctfp
,
386 prp
->pr_argv
[ap
->dn_value
].dtt_type
,
387 prp
->pr_argv
[ap
->dn_value
].dtt_flags
& DTT_FL_USER
?
390 } else if ((dxp
= dt_xlator_lookup(dtp
,
391 nnp
, xnp
, DT_XLATE_FUZZY
)) != NULL
|| (
392 dxp
= dt_xlator_lookup(dtp
, dt_probe_tag(prp
, ap
->dn_value
, &tag
),
393 xnp
, DT_XLATE_EXACT
| DT_XLATE_EXTERN
)) != NULL
) {
395 xidp
= dt_xlator_ident(dxp
, xnp
->dn_ctfp
, xnp
->dn_type
);
397 dnp
->dn_ident
= dt_ident_create(idp
->di_name
, xidp
->di_kind
,
398 xidp
->di_flags
| DT_IDFLG_ORPHAN
, idp
->di_id
, idp
->di_attr
,
399 idp
->di_vers
, idp
->di_ops
, idp
->di_iarg
, idp
->di_gen
);
401 if (dnp
->dn_ident
== NULL
)
402 longjmp(yypcb
->pcb_jmpbuf
, EDT_NOMEM
);
404 if (dt_xlator_dynamic(dxp
))
405 dxp
->dx_arg
= (int)ap
->dn_value
;
408 * Propagate relevant members from the translator's internal
409 * dt_ident_t. This code must be kept in sync with the state
410 * that is initialized for idents in dt_xlator_create().
412 dnp
->dn_ident
->di_data
= xidp
->di_data
;
413 dnp
->dn_ident
->di_ctfp
= xidp
->di_ctfp
;
414 dnp
->dn_ident
->di_type
= xidp
->di_type
;
416 dt_node_type_assign(dnp
, DT_DYN_CTFP(dtp
), DT_DYN_TYPE(dtp
),
420 xyerror(D_ARGS_XLATOR
, "translator for %s[%lld] from %s to %s "
421 "is not defined\n", idp
->di_name
, (longlong_t
)ap
->dn_value
,
422 dt_node_type_name(nnp
, n1
, sizeof (n1
)),
423 dt_node_type_name(xnp
, n2
, sizeof (n2
)));
426 assert(dnp
->dn_ident
->di_flags
& DT_IDFLG_ORPHAN
);
427 assert(dnp
->dn_ident
->di_id
== idp
->di_id
);
431 dt_idcook_regs(dt_node_t
*dnp
, dt_ident_t
*idp
, int argc
, dt_node_t
*ap
)
433 dtrace_typeinfo_t dtt
;
434 dtrace_hdl_t
*dtp
= yypcb
->pcb_hdl
;
435 char n
[DT_TYPE_NAMELEN
];
438 xyerror(D_PROTO_LEN
, "%s[ ] prototype mismatch: %d arg%s"
439 "passed, 1 expected\n", idp
->di_name
,
440 argc
, argc
== 1 ? " " : "s ");
443 if (ap
->dn_kind
!= DT_NODE_INT
) {
444 xyerror(D_PROTO_ARG
, "%s[ ] argument #1 is incompatible with "
445 "prototype:\n\tprototype: %s\n\t argument: %s\n",
446 idp
->di_name
, "integer constant",
447 dt_type_name(ap
->dn_ctfp
, ap
->dn_type
, n
, sizeof (n
)));
450 if ((ap
->dn_flags
& DT_NF_SIGNED
) && (int64_t)ap
->dn_value
< 0) {
451 xyerror(D_REGS_IDX
, "index %lld is out of range for array %s\n",
452 (longlong_t
)ap
->dn_value
, idp
->di_name
);
455 if (dt_type_lookup("uint64_t", &dtt
) == -1) {
456 xyerror(D_UNKNOWN
, "failed to resolve type of %s: %s\n",
457 idp
->di_name
, dtrace_errmsg(dtp
, dtrace_errno(dtp
)));
460 idp
->di_ctfp
= dtt
.dtt_ctfp
;
461 idp
->di_type
= dtt
.dtt_type
;
463 dt_node_type_assign(dnp
, idp
->di_ctfp
, idp
->di_type
, B_FALSE
);
468 dt_idcook_type(dt_node_t
*dnp
, dt_ident_t
*idp
, int argc
, dt_node_t
*args
)
470 if (idp
->di_type
== CTF_ERR
) {
471 dtrace_hdl_t
*dtp
= yypcb
->pcb_hdl
;
472 dtrace_typeinfo_t dtt
;
474 if (dt_type_lookup(idp
->di_iarg
, &dtt
) == -1) {
476 "failed to resolve type %s for identifier %s: %s\n",
477 (const char *)idp
->di_iarg
, idp
->di_name
,
478 dtrace_errmsg(dtp
, dtrace_errno(dtp
)));
481 idp
->di_ctfp
= dtt
.dtt_ctfp
;
482 idp
->di_type
= dtt
.dtt_type
;
485 dt_node_type_assign(dnp
, idp
->di_ctfp
, idp
->di_type
, B_FALSE
);
490 dt_idcook_thaw(dt_node_t
*dnp
, dt_ident_t
*idp
, int argc
, dt_node_t
*args
)
492 if (idp
->di_ctfp
!= NULL
&& idp
->di_type
!= CTF_ERR
)
493 dt_node_type_assign(dnp
, idp
->di_ctfp
, idp
->di_type
, B_FALSE
);
497 dt_idcook_inline(dt_node_t
*dnp
, dt_ident_t
*idp
, int argc
, dt_node_t
*args
)
499 if (idp
->di_kind
== DT_IDENT_ARRAY
)
500 dt_idcook_assc(dnp
, idp
, argc
, args
);
502 dt_idcook_thaw(dnp
, idp
, argc
, args
);
506 dt_iddtor_sign(dt_ident_t
*idp
)
508 if (idp
->di_data
!= NULL
)
509 free(((dt_idsig_t
*)idp
->di_data
)->dis_args
);
514 dt_iddtor_free(dt_ident_t
*idp
)
520 dt_iddtor_inline(dt_ident_t
*idp
)
522 dt_idnode_t
*inp
= idp
->di_iarg
;
525 dt_node_link_free(&inp
->din_list
);
527 if (inp
->din_hash
!= NULL
)
528 dt_idhash_destroy(inp
->din_hash
);
534 if (idp
->di_kind
== DT_IDENT_ARRAY
)
542 dt_iddtor_none(dt_ident_t
*idp
)
548 dt_iddtor_probe(dt_ident_t
*idp
)
550 if (idp
->di_data
!= NULL
)
551 dt_probe_destroy(idp
->di_data
);
555 dt_idsize_type(dt_ident_t
*idp
)
557 return (ctf_type_size(idp
->di_ctfp
, idp
->di_type
));
562 dt_idsize_none(dt_ident_t
*idp
)
567 const dt_idops_t dt_idops_assc
= {
573 const dt_idops_t dt_idops_func
= {
579 const dt_idops_t dt_idops_args
= {
585 const dt_idops_t dt_idops_regs
= {
591 const dt_idops_t dt_idops_type
= {
597 const dt_idops_t dt_idops_thaw
= {
603 const dt_idops_t dt_idops_inline
= {
609 const dt_idops_t dt_idops_probe
= {
616 dt_idhash_populate(dt_idhash_t
*dhp
)
618 const dt_ident_t
*idp
= dhp
->dh_tmpl
;
620 dhp
->dh_tmpl
= NULL
; /* clear dh_tmpl first to avoid recursion */
621 dt_dprintf("populating %s idhash from %p\n", dhp
->dh_name
, (void *)idp
);
623 for (; idp
->di_name
!= NULL
; idp
++) {
624 if (dt_idhash_insert(dhp
, idp
->di_name
,
625 idp
->di_kind
, idp
->di_flags
, idp
->di_id
, idp
->di_attr
,
626 idp
->di_vers
, idp
->di_ops
? idp
->di_ops
: &dt_idops_thaw
,
627 idp
->di_iarg
, 0) == NULL
)
628 longjmp(yypcb
->pcb_jmpbuf
, EDT_NOMEM
);
633 dt_idhash_create(const char *name
, const dt_ident_t
*tmpl
,
634 uint_t min
, uint_t max
)
641 size
= sizeof (dt_idhash_t
) +
642 sizeof (dt_ident_t
*) * (_dtrace_strbuckets
- 1);
644 if ((dhp
= malloc(size
)) == NULL
)
650 dhp
->dh_nextid
= min
;
653 dhp
->dh_hashsz
= _dtrace_strbuckets
;
659 * Destroy an entire identifier hash. This must be done using two passes with
660 * an inlined version of dt_ident_destroy() to avoid referencing freed memory.
661 * In the first pass di_dtor() is called for all identifiers; then the second
662 * pass frees the actual dt_ident_t's. These must be done separately because
663 * a di_dtor() may operate on data structures which contain references to other
664 * identifiers inside of this hash itself (e.g. a global inline definition
665 * which contains a parse tree that refers to another global variable).
668 dt_idhash_destroy(dt_idhash_t
*dhp
)
670 dt_ident_t
*idp
, *next
;
673 for (i
= 0; i
< dhp
->dh_hashsz
; i
++) {
674 for (idp
= dhp
->dh_hash
[i
]; idp
!= NULL
; idp
= next
) {
676 idp
->di_ops
->di_dtor(idp
);
680 for (i
= 0; i
< dhp
->dh_hashsz
; i
++) {
681 for (idp
= dhp
->dh_hash
[i
]; idp
!= NULL
; idp
= next
) {
692 dt_idhash_update(dt_idhash_t
*dhp
)
694 uint_t nextid
= dhp
->dh_minid
;
698 for (i
= 0; i
< dhp
->dh_hashsz
; i
++) {
699 for (idp
= dhp
->dh_hash
[i
]; idp
!= NULL
; idp
= idp
->di_next
) {
701 * Right now we're hard coding which types need to be
702 * reset, but ideally this would be done dynamically.
704 if (idp
->di_kind
== DT_IDENT_ARRAY
||
705 idp
->di_kind
== DT_IDENT_SCALAR
||
706 idp
->di_kind
== DT_IDENT_AGG
)
707 nextid
= MAX(nextid
, idp
->di_id
+ 1);
711 dhp
->dh_nextid
= nextid
;
715 dt_idhash_lookup(dt_idhash_t
*dhp
, const char *name
)
718 ulong_t h
= dt_strtab_hash(name
, &len
) % dhp
->dh_hashsz
;
721 if (dhp
->dh_tmpl
!= NULL
)
722 dt_idhash_populate(dhp
); /* fill hash w/ initial population */
724 for (idp
= dhp
->dh_hash
[h
]; idp
!= NULL
; idp
= idp
->di_next
) {
725 if (strcmp(idp
->di_name
, name
) == 0)
733 dt_idhash_nextid(dt_idhash_t
*dhp
, uint_t
*p
)
735 if (dhp
->dh_nextid
>= dhp
->dh_maxid
)
736 return (-1); /* no more id's are free to allocate */
738 *p
= dhp
->dh_nextid
++;
743 dt_idhash_size(const dt_idhash_t
*dhp
)
745 return (dhp
->dh_nelems
);
749 dt_idhash_name(const dt_idhash_t
*dhp
)
751 return (dhp
->dh_name
);
755 dt_idhash_insert(dt_idhash_t
*dhp
, const char *name
, ushort_t kind
,
756 ushort_t flags
, uint_t id
, dtrace_attribute_t attr
, uint_t vers
,
757 const dt_idops_t
*ops
, void *iarg
, ulong_t gen
)
762 if (dhp
->dh_tmpl
!= NULL
)
763 dt_idhash_populate(dhp
); /* fill hash w/ initial population */
765 idp
= dt_ident_create(name
, kind
, flags
, id
,
766 attr
, vers
, ops
, iarg
, gen
);
771 h
= dt_strtab_hash(name
, NULL
) % dhp
->dh_hashsz
;
772 idp
->di_next
= dhp
->dh_hash
[h
];
774 dhp
->dh_hash
[h
] = idp
;
777 if (dhp
->dh_defer
!= NULL
)
778 dhp
->dh_defer(dhp
, idp
);
784 dt_idhash_xinsert(dt_idhash_t
*dhp
, dt_ident_t
*idp
)
788 if (dhp
->dh_tmpl
!= NULL
)
789 dt_idhash_populate(dhp
); /* fill hash w/ initial population */
791 h
= dt_strtab_hash(idp
->di_name
, NULL
) % dhp
->dh_hashsz
;
792 idp
->di_next
= dhp
->dh_hash
[h
];
793 idp
->di_flags
&= ~DT_IDFLG_ORPHAN
;
795 dhp
->dh_hash
[h
] = idp
;
798 if (dhp
->dh_defer
!= NULL
)
799 dhp
->dh_defer(dhp
, idp
);
803 dt_idhash_delete(dt_idhash_t
*dhp
, dt_ident_t
*key
)
806 ulong_t h
= dt_strtab_hash(key
->di_name
, &len
) % dhp
->dh_hashsz
;
807 dt_ident_t
**pp
= &dhp
->dh_hash
[h
];
810 for (idp
= dhp
->dh_hash
[h
]; idp
!= NULL
; idp
= idp
->di_next
) {
820 assert(dhp
->dh_nelems
!= 0);
823 if (!(idp
->di_flags
& DT_IDFLG_ORPHAN
))
824 dt_ident_destroy(idp
);
828 dt_idhash_comp(const void *lp
, const void *rp
)
830 const dt_ident_t
*lhs
= *((const dt_ident_t
**)lp
);
831 const dt_ident_t
*rhs
= *((const dt_ident_t
**)rp
);
833 if (lhs
->di_id
!= rhs
->di_id
)
834 return ((int)(lhs
->di_id
- rhs
->di_id
));
836 return (strcmp(lhs
->di_name
, rhs
->di_name
));
840 dt_idhash_iter(dt_idhash_t
*dhp
, dt_idhash_f
*func
, void *data
)
847 if (dhp
->dh_tmpl
!= NULL
)
848 dt_idhash_populate(dhp
); /* fill hash w/ initial population */
851 ids
= alloca(sizeof (dt_ident_t
*) * n
);
853 for (i
= 0, j
= 0; i
< dhp
->dh_hashsz
; i
++) {
854 for (idp
= dhp
->dh_hash
[i
]; idp
!= NULL
; idp
= idp
->di_next
)
858 qsort(ids
, dhp
->dh_nelems
, sizeof (dt_ident_t
*), dt_idhash_comp
);
860 for (i
= 0; i
< n
; i
++) {
861 if ((rv
= func(dhp
, ids
[i
], data
)) != 0)
869 dt_idstack_lookup(dt_idstack_t
*sp
, const char *name
)
874 for (dhp
= dt_list_prev(&sp
->dids_list
);
875 dhp
!= NULL
; dhp
= dt_list_prev(dhp
)) {
876 if ((idp
= dt_idhash_lookup(dhp
, name
)) != NULL
)
884 dt_idstack_push(dt_idstack_t
*sp
, dt_idhash_t
*dhp
)
886 dt_list_append(&sp
->dids_list
, dhp
);
890 dt_idstack_pop(dt_idstack_t
*sp
, dt_idhash_t
*dhp
)
892 assert(dt_list_prev(&sp
->dids_list
) == dhp
);
893 dt_list_delete(&sp
->dids_list
, dhp
);
897 dt_ident_create(const char *name
, ushort_t kind
, ushort_t flags
, uint_t id
,
898 dtrace_attribute_t attr
, uint_t vers
,
899 const dt_idops_t
*ops
, void *iarg
, ulong_t gen
)
904 if ((name
!= NULL
&& (s
= strdup(name
)) == NULL
) ||
905 (idp
= malloc(sizeof (dt_ident_t
))) == NULL
) {
912 idp
->di_flags
= flags
;
920 idp
->di_type
= CTF_ERR
;
923 idp
->di_lineno
= yylineno
;
929 * Destroy an individual identifier. This code must be kept in sync with the
930 * dt_idhash_destroy() function below, which separates out the call to di_dtor.
933 dt_ident_destroy(dt_ident_t
*idp
)
935 idp
->di_ops
->di_dtor(idp
);
941 dt_ident_morph(dt_ident_t
*idp
, ushort_t kind
,
942 const dt_idops_t
*ops
, void *iarg
)
944 idp
->di_ops
->di_dtor(idp
);
952 dt_ident_cook(dt_node_t
*dnp
, dt_ident_t
*idp
, dt_node_t
**pargp
)
954 dtrace_attribute_t attr
;
955 dt_node_t
*args
, *argp
;
958 attr
= dt_node_list_cook(pargp
, DT_IDFLG_REF
);
959 args
= pargp
? *pargp
: NULL
;
961 for (argp
= args
; argp
!= NULL
; argp
= argp
->dn_list
)
964 idp
->di_ops
->di_cook(dnp
, idp
, argc
, args
);
966 if (idp
->di_flags
& DT_IDFLG_USER
)
967 dnp
->dn_flags
|= DT_NF_USERLAND
;
969 return (dt_attr_min(attr
, idp
->di_attr
));
973 dt_ident_type_assign(dt_ident_t
*idp
, ctf_file_t
*fp
, ctf_id_t type
)
980 dt_ident_resolve(dt_ident_t
*idp
)
982 while (idp
->di_flags
& DT_IDFLG_INLINE
) {
983 const dt_node_t
*dnp
= ((dt_idnode_t
*)idp
->di_iarg
)->din_root
;
986 break; /* can't resolve any further yet */
988 switch (dnp
->dn_kind
) {
999 if (dt_node_is_dynamic(dnp
))
1000 idp
= dnp
->dn_ident
;
1009 dt_ident_size(dt_ident_t
*idp
)
1011 idp
= dt_ident_resolve(idp
);
1012 return (idp
->di_ops
->di_size(idp
));
1016 dt_ident_unref(const dt_ident_t
*idp
)
1018 return (idp
->di_gen
== yypcb
->pcb_hdl
->dt_gen
&&
1019 (idp
->di_flags
& (DT_IDFLG_REF
|DT_IDFLG_MOD
|DT_IDFLG_DECL
)) == 0);
1023 dt_idkind_name(uint_t kind
)
1026 case DT_IDENT_ARRAY
: return ("associative array");
1027 case DT_IDENT_SCALAR
: return ("scalar");
1028 case DT_IDENT_PTR
: return ("pointer");
1029 case DT_IDENT_FUNC
: return ("function");
1030 case DT_IDENT_AGG
: return ("aggregation");
1031 case DT_IDENT_AGGFUNC
: return ("aggregating function");
1032 case DT_IDENT_ACTFUNC
: return ("tracing function");
1033 case DT_IDENT_XLSOU
: return ("translated data");
1034 case DT_IDENT_XLPTR
: return ("pointer to translated data");
1035 case DT_IDENT_SYMBOL
: return ("external symbol reference");
1036 case DT_IDENT_ENUM
: return ("enumerator");
1037 case DT_IDENT_PRAGAT
: return ("#pragma attributes");
1038 case DT_IDENT_PRAGBN
: return ("#pragma binding");
1039 case DT_IDENT_PROBE
: return ("probe definition");
1040 default: return ("<?>");