/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" #include #include #include #include #include #include #include #include /* * This callback function is installed in a given identifier hash to search for * and apply deferred pragmas that are pending for a given new identifier name. * Multiple pragmas may be pending for a given name; we processs all of them. */ /*ARGSUSED*/ static void dt_pragma_apply(dt_idhash_t *dhp, dt_ident_t *idp) { dt_idhash_t *php; dt_ident_t *pdp; if ((php = yypcb->pcb_pragmas) == NULL) return; /* no pragmas pending for current compilation pass */ while ((pdp = dt_idhash_lookup(php, idp->di_name)) != NULL) { switch (pdp->di_kind) { case DT_IDENT_PRAGAT: idp->di_attr = pdp->di_attr; break; case DT_IDENT_PRAGBN: idp->di_vers = pdp->di_vers; break; } dt_idhash_delete(php, pdp); } } /* * The #pragma attributes directive can be used to reset stability attributes * on a global identifier or inline definition. If the identifier is already * defined, we can just change di_attr. If not, we insert the pragma into a * hash table of the current pcb's deferred pragmas for later processing. */ static void dt_pragma_attributes(const char *prname, dt_node_t *dnp) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dtrace_attribute_t attr, *a; dt_provider_t *pvp; const char *name, *part; dt_ident_t *idp; if (dnp == NULL || dnp->dn_kind != DT_NODE_IDENT || dnp->dn_list == NULL || dnp->dn_list->dn_kind != DT_NODE_IDENT) { xyerror(D_PRAGMA_MALFORM, "malformed #pragma %s " " \n", prname); } if (dtrace_str2attr(dnp->dn_string, &attr) == -1) { xyerror(D_PRAGMA_INVAL, "invalid attributes " "specified by #pragma %s\n", prname); } dnp = dnp->dn_list; name = dnp->dn_string; if (strcmp(name, "provider") == 0) { dnp = dnp->dn_list; name = dnp->dn_string; dnp = dnp->dn_list; part = dnp->dn_string; if ((pvp = dt_provider_lookup(dtp, name)) != NULL) { if (strcmp(part, "provider") == 0) { a = &pvp->pv_desc.dtvd_attr.dtpa_provider; } else if (strcmp(part, "module") == 0) { a = &pvp->pv_desc.dtvd_attr.dtpa_mod; } else if (strcmp(part, "function") == 0) { a = &pvp->pv_desc.dtvd_attr.dtpa_func; } else if (strcmp(part, "name") == 0) { a = &pvp->pv_desc.dtvd_attr.dtpa_name; } else if (strcmp(part, "args") == 0) { a = &pvp->pv_desc.dtvd_attr.dtpa_args; } else { xyerror(D_PRAGMA_INVAL, "invalid component " "\"%s\" in attribute #pragma " "for provider %s\n", name, part); } *a = attr; return; } } else if ((idp = dt_idstack_lookup( &yypcb->pcb_globals, name)) != NULL) { if (idp->di_gen != dtp->dt_gen) { xyerror(D_PRAGMA_SCOPE, "#pragma %s cannot modify " "entity defined outside program scope\n", prname); } idp->di_attr = attr; return; } if (yypcb->pcb_pragmas == NULL && (yypcb->pcb_pragmas = dt_idhash_create("pragma", NULL, 0, 0)) == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); idp = dt_idhash_insert(yypcb->pcb_pragmas, name, DT_IDENT_PRAGAT, 0, 0, attr, 0, &dt_idops_thaw, (void *)prname, dtp->dt_gen); if (idp == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); if (dtp->dt_globals->dh_defer == NULL) dtp->dt_globals->dh_defer = &dt_pragma_apply; } /* * The #pragma binding directive can be used to reset the version binding * on a global identifier or inline definition. If the identifier is already * defined, we can just change di_vers. If not, we insert the pragma into a * hash table of the current pcb's deferred pragmas for later processing. */ static void dt_pragma_binding(const char *prname, dt_node_t *dnp) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_version_t vers; const char *name; dt_ident_t *idp; if (dnp == NULL || dnp->dn_kind != DT_NODE_STRING || dnp->dn_list == NULL || dnp->dn_list->dn_kind != DT_NODE_IDENT) { xyerror(D_PRAGMA_MALFORM, "malformed #pragma %s " "\"version\" \n", prname); } if (dt_version_str2num(dnp->dn_string, &vers) == -1) { xyerror(D_PRAGMA_INVAL, "invalid version string " "specified by #pragma %s\n", prname); } name = dnp->dn_list->dn_string; idp = dt_idstack_lookup(&yypcb->pcb_globals, name); if (idp != NULL) { if (idp->di_gen != dtp->dt_gen) { xyerror(D_PRAGMA_SCOPE, "#pragma %s cannot modify " "entity defined outside program scope\n", prname); } idp->di_vers = vers; return; } if (yypcb->pcb_pragmas == NULL && (yypcb->pcb_pragmas = dt_idhash_create("pragma", NULL, 0, 0)) == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); idp = dt_idhash_insert(yypcb->pcb_pragmas, name, DT_IDENT_PRAGBN, 0, 0, _dtrace_defattr, vers, &dt_idops_thaw, (void *)prname, dtp->dt_gen); if (idp == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); if (dtp->dt_globals->dh_defer == NULL) dtp->dt_globals->dh_defer = &dt_pragma_apply; } /* * The #pragma depends_on directive can be used to express a dependency on a * module or provider, which if not present will cause processing to abort. */ static void dt_pragma_depends(const char *prname, dt_node_t *cnp) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_node_t *nnp = cnp ? cnp->dn_list : NULL; int found; if (cnp == NULL || nnp == NULL || cnp->dn_kind != DT_NODE_IDENT || nnp->dn_kind != DT_NODE_IDENT) { xyerror(D_PRAGMA_MALFORM, "malformed #pragma %s " " \n", prname); } if (strcmp(cnp->dn_string, "provider") == 0) found = dt_provider_lookup(dtp, nnp->dn_string) != NULL; else if (strcmp(cnp->dn_string, "module") == 0) { dt_module_t *mp = dt_module_lookup_by_name(dtp, nnp->dn_string); found = mp != NULL && dt_module_getctf(dtp, mp) != NULL; } else { xyerror(D_PRAGMA_INVAL, "invalid class %s " "specified by #pragma %s\n", cnp->dn_string, prname); } if (!found) { xyerror(D_PRAGMA_DEPEND, "program requires %s %s\n", cnp->dn_string, nnp->dn_string); } } /* * The #pragma error directive can be followed by any list of tokens, which we * just concatenate and print as part of our error message. */ static void dt_pragma_error(const char *prname, dt_node_t *dnp) { dt_node_t *enp; size_t n = 0; char *s; for (enp = dnp; enp != NULL; enp = enp->dn_list) { if (enp->dn_kind == DT_NODE_IDENT || enp->dn_kind == DT_NODE_STRING) n += strlen(enp->dn_string) + 1; } s = alloca(n + 1); s[0] = '\0'; for (enp = dnp; enp != NULL; enp = enp->dn_list) { if (enp->dn_kind == DT_NODE_IDENT || enp->dn_kind == DT_NODE_STRING) { (void) strcat(s, enp->dn_string); (void) strcat(s, " "); } } xyerror(D_PRAGERR, "#%s: %s\n", prname, s); } /*ARGSUSED*/ static void dt_pragma_ident(const char *prname, dt_node_t *dnp) { /* ignore any #ident or #pragma ident lines */ } static void dt_pragma_option(const char *prname, dt_node_t *dnp) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; char *opt, *val; if (dnp == NULL || dnp->dn_kind != DT_NODE_IDENT) { xyerror(D_PRAGMA_MALFORM, "malformed #pragma %s