Print this page
libdtrace: attempt to resolve FORWARD types to concrete types
libdtrace: treat DTT_FL_USER properly in the parser


1352 
1353         /*
1354          * If 'ddp' is NULL, we get a decl by popping the decl stack.  This
1355          * form of dt_node_type() is used by parameter rules in dt_grammar.y.
1356          */
1357         if (ddp == NULL)
1358                 ddp = dt_decl_pop_param(&name);
1359 
1360         err = dt_decl_type(ddp, &dtt);
1361         dt_decl_free(ddp);
1362 
1363         if (err != 0) {
1364                 free(name);
1365                 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1366         }
1367 
1368         dnp = dt_node_alloc(DT_NODE_TYPE);
1369         dnp->dn_op = DT_TOK_IDENT;
1370         dnp->dn_string = name;
1371 
1372         dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, dtt.dtt_flags);

1373 
1374         if (dtt.dtt_ctfp == dtp->dt_cdefs->dm_ctfp ||
1375             dtt.dtt_ctfp == dtp->dt_ddefs->dm_ctfp)
1376                 dt_node_attr_assign(dnp, _dtrace_defattr);
1377         else
1378                 dt_node_attr_assign(dnp, _dtrace_typattr);
1379 
1380         return (dnp);
1381 }
1382 
1383 /*
1384  * Create a type node corresponding to a varargs (...) parameter by just
1385  * assigning it type CTF_ERR.  The decl processing code will handle this.
1386  */
1387 dt_node_t *
1388 dt_node_vatype(void)
1389 {
1390         dt_node_t *dnp = dt_node_alloc(DT_NODE_TYPE);
1391 
1392         dnp->dn_op = DT_TOK_IDENT;


1781         dnp->dn_list = NULL;
1782 
1783         return (dnp);
1784 }
1785 
1786 /*
1787  * The offsetof() function is special because it takes a type name as an
1788  * argument.  It does not actually construct its own node; after looking up the
1789  * structure or union offset, we just return an integer node with the offset.
1790  */
1791 dt_node_t *
1792 dt_node_offsetof(dt_decl_t *ddp, char *s)
1793 {
1794         dtrace_typeinfo_t dtt;
1795         dt_node_t dn;
1796         char *name;
1797         int err;
1798 
1799         ctf_membinfo_t ctm;
1800         ctf_id_t type;

1801         uint_t kind;
1802 
1803         name = strdupa(s);
1804         free(s);
1805 
1806         err = dt_decl_type(ddp, &dtt);
1807         dt_decl_free(ddp);
1808 
1809         if (err != 0)
1810                 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1811 
1812         type = ctf_type_resolve(dtt.dtt_ctfp, dtt.dtt_type);
1813         kind = ctf_type_kind(dtt.dtt_ctfp, type);
1814 
1815         if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) {
1816                 xyerror(D_OFFSETOF_TYPE,
1817                     "offsetof operand must be a struct or union type\n");
1818         }
1819 
1820         if (ctf_member_info(dtt.dtt_ctfp, type, name, &ctm) == CTF_ERR) {
1821                 xyerror(D_UNKNOWN, "failed to determine offset of %s: %s\n",
1822                     name, ctf_errmsg(ctf_errno(dtt.dtt_ctfp)));
1823         }
1824 
1825         bzero(&dn, sizeof (dn));
1826         dt_node_type_assign(&dn, dtt.dtt_ctfp, ctm.ctm_type, B_FALSE);








1827 
1828         if (dn.dn_flags & DT_NF_BITFIELD) {
1829                 xyerror(D_OFFSETOF_BITFIELD,
1830                     "cannot take offset of a bit-field: %s\n", name);
1831         }
1832 
1833         return (dt_node_int(ctm.ctm_offset / NBBY));
1834 }
1835 
1836 dt_node_t *
1837 dt_node_op1(int op, dt_node_t *cp)
1838 {
1839         dt_node_t *dnp;
1840 
1841         if (cp->dn_kind == DT_NODE_INT) {
1842                 switch (op) {
1843                 case DT_TOK_INEG:
1844                         /*
1845                          * If we're negating an unsigned integer, zero out any
1846                          * extra top bits to truncate the value to the size of


2406 dt_node_member(dt_decl_t *ddp, char *name, dt_node_t *expr)
2407 {
2408         dtrace_typeinfo_t dtt;
2409         dt_node_t *dnp;
2410         int err;
2411 
2412         if (ddp != NULL) {
2413                 err = dt_decl_type(ddp, &dtt);
2414                 dt_decl_free(ddp);
2415 
2416                 if (err != 0)
2417                         longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2418         }
2419 
2420         dnp = dt_node_alloc(DT_NODE_MEMBER);
2421         dnp->dn_membname = name;
2422         dnp->dn_membexpr = expr;
2423 
2424         if (ddp != NULL)
2425                 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
2426                     dtt.dtt_flags);
2427 
2428         return (dnp);
2429 }
2430 
2431 dt_node_t *
2432 dt_node_xlator(dt_decl_t *ddp, dt_decl_t *sdp, char *name, dt_node_t *members)
2433 {
2434         dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2435         dtrace_typeinfo_t src, dst;
2436         dt_node_t sn, dn;
2437         dt_xlator_t *dxp;
2438         dt_node_t *dnp;
2439         int edst, esrc;
2440         uint_t kind;
2441 
2442         char n1[DT_TYPE_NAMELEN];
2443         char n2[DT_TYPE_NAMELEN];
2444 
2445         edst = dt_decl_type(ddp, &dst);
2446         dt_decl_free(ddp);


2763                         idp->di_flags |= DT_IDFLG_PRIM;
2764 
2765                 idp->di_next = dtp->dt_externs;
2766                 dtp->dt_externs = idp;
2767 
2768                 if ((sip = malloc(sizeof (dtrace_syminfo_t))) == NULL)
2769                         longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2770 
2771                 bcopy(&dts, sip, sizeof (dtrace_syminfo_t));
2772                 idp->di_data = sip;
2773                 idp->di_ctfp = dtt.dtt_ctfp;
2774                 idp->di_type = dtt.dtt_type;
2775 
2776                 free(dnp->dn_string);
2777                 dnp->dn_string = NULL;
2778                 dnp->dn_kind = DT_NODE_SYM;
2779                 dnp->dn_ident = idp;
2780                 dnp->dn_flags |= DT_NF_LVALUE;
2781 
2782                 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
2783                     dtt.dtt_flags);
2784                 dt_node_attr_assign(dnp, _dtrace_symattr);
2785 
2786                 if (uref) {
2787                         idp->di_flags |= DT_IDFLG_USER;
2788                         dnp->dn_flags |= DT_NF_USERLAND;
2789                 }
2790 
2791         } else if (scope == DTRACE_OBJ_EXEC && create == B_TRUE) {
2792                 uint_t flags = DT_IDFLG_WRITE;
2793                 uint_t id;
2794 
2795                 if (dt_idhash_nextid(dhp, &id) == -1) {
2796                         xyerror(D_ID_OFLOW, "cannot create %s: limit on number "
2797                             "of %s variables exceeded\n", name, sname);
2798                 }
2799 
2800                 if (dhp == yypcb->pcb_locals)
2801                         flags |= DT_IDFLG_LOCAL;
2802                 else if (dhp == dtp->dt_tls)
2803                         flags |= DT_IDFLG_TLS;


2915             dnp->dn_op == DT_TOK_PREDEC || dnp->dn_op == DT_TOK_POSTDEC)
2916                 idflags = DT_IDFLG_REF | DT_IDFLG_MOD;
2917         else
2918                 idflags = DT_IDFLG_REF;
2919 
2920         /*
2921          * We allow the unary ++ and -- operators to instantiate new scalar
2922          * variables if applied to an identifier; otherwise just cook as usual.
2923          */
2924         if (cp->dn_kind == DT_NODE_IDENT && (idflags & DT_IDFLG_MOD))
2925                 dt_xcook_ident(cp, dtp->dt_globals, DT_IDENT_SCALAR, B_TRUE);
2926 
2927         cp = dnp->dn_child = dt_node_cook(cp, 0); /* don't set idflags yet */
2928 
2929         if (cp->dn_kind == DT_NODE_VAR && dt_ident_unref(cp->dn_ident)) {
2930                 if (dt_type_lookup("int64_t", &dtt) != 0)
2931                         xyerror(D_TYPE_ERR, "failed to lookup int64_t\n");
2932 
2933                 dt_ident_type_assign(cp->dn_ident, dtt.dtt_ctfp, dtt.dtt_type);
2934                 dt_node_type_assign(cp, dtt.dtt_ctfp, dtt.dtt_type,
2935                     dtt.dtt_flags);
2936         }
2937 
2938         if (cp->dn_kind == DT_NODE_VAR)
2939                 cp->dn_ident->di_flags |= idflags;
2940 
2941         switch (dnp->dn_op) {
2942         case DT_TOK_DEREF:
2943                 /*
2944                  * If the deref operator is applied to a translated pointer,
2945                  * we set our output type to the output of the translation.
2946                  */
2947                 if ((idp = dt_node_resolve(cp, DT_IDENT_XLPTR)) != NULL) {
2948                         dt_xlator_t *dxp = idp->di_data;
2949 
2950                         dnp->dn_ident = &dxp->dx_souid;
2951                         dt_node_type_assign(dnp,
2952                             dnp->dn_ident->di_ctfp, dnp->dn_ident->di_type,
2953                             cp->dn_flags & DT_NF_USERLAND);
2954                         break;
2955                 }


3708                         type = ctf_type_resolve(ctfp, lp->dn_type);
3709                         uref = lp->dn_flags & DT_NF_USERLAND;
3710                 }
3711 
3712                 kind = ctf_type_kind(ctfp, type);
3713 
3714                 if (op == DT_TOK_PTR) {
3715                         if (kind != CTF_K_POINTER) {
3716                                 xyerror(D_OP_PTR, "operator %s must be "
3717                                     "applied to a pointer\n", opstr(op));
3718                         }
3719                         type = ctf_type_reference(ctfp, type);
3720                         type = ctf_type_resolve(ctfp, type);
3721                         kind = ctf_type_kind(ctfp, type);
3722                 }
3723 
3724                 /*
3725                  * If we follow a reference to a forward declaration tag,
3726                  * search the entire type space for the actual definition.
3727                  */
3728                 while (kind == CTF_K_FORWARD) {
3729                         char *tag = ctf_type_name(ctfp, type, n1, sizeof (n1));
3730                         dtrace_typeinfo_t dtt;
3731 
3732                         if (tag != NULL && dt_type_lookup(tag, &dtt) == 0 &&
3733                             (dtt.dtt_ctfp != ctfp || dtt.dtt_type != type)) {
3734                                 ctfp = dtt.dtt_ctfp;
3735                                 type = ctf_type_resolve(ctfp, dtt.dtt_type);
3736                                 kind = ctf_type_kind(ctfp, type);
3737                         } else {

3738                                 xyerror(D_OP_INCOMPLETE,
3739                                     "operator %s cannot be applied to a "
3740                                     "forward declaration: no %s definition "
3741                                     "is available\n", opstr(op), tag);
3742                         }
3743                 }
3744 
3745                 if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) {
3746                         if (op == DT_TOK_PTR) {
3747                                 xyerror(D_OP_SOU, "operator -> cannot be "
3748                                     "applied to pointer to type \"%s\"; must "
3749                                     "be applied to a struct or union pointer\n",
3750                                     ctf_type_name(ctfp, type, n1, sizeof (n1)));
3751                         } else {
3752                                 xyerror(D_OP_SOU, "operator %s cannot be "
3753                                     "applied to type \"%s\"; must be applied "
3754                                     "to a struct or union\n", opstr(op),
3755                                     ctf_type_name(ctfp, type, n1, sizeof (n1)));
3756                         }
3757                 }
3758 
3759                 if (ctf_member_info(ctfp, type, rp->dn_string, &m) == CTF_ERR) {
3760                         xyerror(D_TYPE_MEMBER,
3761                             "%s is not a member of %s\n", rp->dn_string,
3762                             ctf_type_name(ctfp, type, n1, sizeof (n1)));
3763                 }
3764 
3765                 type = ctf_type_resolve(ctfp, m.ctm_type);
3766                 kind = ctf_type_kind(ctfp, type);
3767 
3768                 dt_node_type_assign(dnp, ctfp, m.ctm_type, B_FALSE);

3769                 dt_node_attr_assign(dnp, lp->dn_attr);
3770 



3771                 if (op == DT_TOK_PTR && (kind != CTF_K_ARRAY ||
3772                     dt_node_is_string(dnp)))
3773                         dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3774 
3775                 if (op == DT_TOK_DOT && (lp->dn_flags & DT_NF_LVALUE) &&
3776                     (kind != CTF_K_ARRAY || dt_node_is_string(dnp)))
3777                         dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3778 
3779                 if (lp->dn_flags & DT_NF_WRITABLE)
3780                         dnp->dn_flags |= DT_NF_WRITABLE;
3781 
3782                 if (uref && (kind == CTF_K_POINTER ||
3783                     (dnp->dn_flags & DT_NF_REF)))
3784                         dnp->dn_flags |= DT_NF_USERLAND;
3785                 break;
3786 
3787         case DT_TOK_LBRAC: {
3788                 /*
3789                  * If op is DT_TOK_LBRAC, we know from the special-case code at
3790                  * the top that lp is either a D variable or an aggregation.


4258 dt_cook_member(dt_node_t *dnp, uint_t idflags)
4259 {
4260         dnp->dn_membexpr = dt_node_cook(dnp->dn_membexpr, idflags);
4261         dt_node_attr_assign(dnp, dnp->dn_membexpr->dn_attr);
4262         return (dnp);
4263 }
4264 
4265 /*ARGSUSED*/
4266 static dt_node_t *
4267 dt_cook_xlator(dt_node_t *dnp, uint_t idflags)
4268 {
4269         dtrace_hdl_t *dtp = yypcb->pcb_hdl;
4270         dt_xlator_t *dxp = dnp->dn_xlator;
4271         dt_node_t *mnp;
4272 
4273         char n1[DT_TYPE_NAMELEN];
4274         char n2[DT_TYPE_NAMELEN];
4275 
4276         dtrace_attribute_t attr = _dtrace_maxattr;
4277         ctf_membinfo_t ctm;


4278 
4279         /*
4280          * Before cooking each translator member, we push a reference to the
4281          * hash containing translator-local identifiers on to pcb_globals to
4282          * temporarily interpose these identifiers in front of other globals.
4283          */
4284         dt_idstack_push(&yypcb->pcb_globals, dxp->dx_locals);
4285 
4286         for (mnp = dnp->dn_members; mnp != NULL; mnp = mnp->dn_list) {
4287                 if (ctf_member_info(dxp->dx_dst_ctfp, dxp->dx_dst_type,
4288                     mnp->dn_membname, &ctm) == CTF_ERR) {
4289                         xyerror(D_XLATE_MEMB,
4290                             "translator member %s is not a member of %s\n",
4291                             mnp->dn_membname, ctf_type_name(dxp->dx_dst_ctfp,
4292                             dxp->dx_dst_type, n1, sizeof (n1)));
4293                 }
4294 
4295                 (void) dt_node_cook(mnp, DT_IDFLG_REF);
4296                 dt_node_type_assign(mnp, dxp->dx_dst_ctfp, ctm.ctm_type,









4297                     B_FALSE);
4298                 attr = dt_attr_min(attr, mnp->dn_attr);
4299 
4300                 if (dt_node_is_argcompat(mnp, mnp->dn_membexpr) == 0) {
4301                         xyerror(D_XLATE_INCOMPAT,
4302                             "translator member %s definition uses "
4303                             "incompatible types: \"%s\" = \"%s\"\n",
4304                             mnp->dn_membname,
4305                             dt_node_type_name(mnp, n1, sizeof (n1)),
4306                             dt_node_type_name(mnp->dn_membexpr,
4307                             n2, sizeof (n2)));
4308                 }
4309         }
4310 
4311         dt_idstack_pop(&yypcb->pcb_globals, dxp->dx_locals);
4312 
4313         dxp->dx_souid.di_attr = attr;
4314         dxp->dx_ptrid.di_attr = attr;
4315 
4316         dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE);




1352 
1353         /*
1354          * If 'ddp' is NULL, we get a decl by popping the decl stack.  This
1355          * form of dt_node_type() is used by parameter rules in dt_grammar.y.
1356          */
1357         if (ddp == NULL)
1358                 ddp = dt_decl_pop_param(&name);
1359 
1360         err = dt_decl_type(ddp, &dtt);
1361         dt_decl_free(ddp);
1362 
1363         if (err != 0) {
1364                 free(name);
1365                 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1366         }
1367 
1368         dnp = dt_node_alloc(DT_NODE_TYPE);
1369         dnp->dn_op = DT_TOK_IDENT;
1370         dnp->dn_string = name;
1371 
1372         dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
1373             dtt.dtt_flags & DTT_FL_USER ? B_TRUE : B_FALSE);
1374 
1375         if (dtt.dtt_ctfp == dtp->dt_cdefs->dm_ctfp ||
1376             dtt.dtt_ctfp == dtp->dt_ddefs->dm_ctfp)
1377                 dt_node_attr_assign(dnp, _dtrace_defattr);
1378         else
1379                 dt_node_attr_assign(dnp, _dtrace_typattr);
1380 
1381         return (dnp);
1382 }
1383 
1384 /*
1385  * Create a type node corresponding to a varargs (...) parameter by just
1386  * assigning it type CTF_ERR.  The decl processing code will handle this.
1387  */
1388 dt_node_t *
1389 dt_node_vatype(void)
1390 {
1391         dt_node_t *dnp = dt_node_alloc(DT_NODE_TYPE);
1392 
1393         dnp->dn_op = DT_TOK_IDENT;


1782         dnp->dn_list = NULL;
1783 
1784         return (dnp);
1785 }
1786 
1787 /*
1788  * The offsetof() function is special because it takes a type name as an
1789  * argument.  It does not actually construct its own node; after looking up the
1790  * structure or union offset, we just return an integer node with the offset.
1791  */
1792 dt_node_t *
1793 dt_node_offsetof(dt_decl_t *ddp, char *s)
1794 {
1795         dtrace_typeinfo_t dtt;
1796         dt_node_t dn;
1797         char *name;
1798         int err;
1799 
1800         ctf_membinfo_t ctm;
1801         ctf_id_t type;
1802         ctf_file_t *ctfp;
1803         uint_t kind;
1804 
1805         name = strdupa(s);
1806         free(s);
1807 
1808         err = dt_decl_type(ddp, &dtt);
1809         dt_decl_free(ddp);
1810 
1811         if (err != 0)
1812                 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1813 
1814         type = ctf_type_resolve(dtt.dtt_ctfp, dtt.dtt_type);
1815         kind = ctf_type_kind(dtt.dtt_ctfp, type);
1816 
1817         if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) {
1818                 xyerror(D_OFFSETOF_TYPE,
1819                     "offsetof operand must be a struct or union type\n");
1820         }
1821 
1822         if (ctf_member_info(dtt.dtt_ctfp, type, name, &ctm) == CTF_ERR) {
1823                 xyerror(D_UNKNOWN, "failed to determine offset of %s: %s\n",
1824                     name, ctf_errmsg(ctf_errno(dtt.dtt_ctfp)));
1825         }
1826 
1827         bzero(&dn, sizeof (dn));
1828         /*
1829          * Resolution of CTF_K_FORWARD is unnecessary here, since it can't be
1830          * both forward _and_ a bitfield, but is done for completeness.
1831          */
1832         type = ctm.ctm_type;
1833         ctfp = dtt.dtt_ctfp;
1834 
1835         dt_resolve_forward_decl(&ctfp, &type);
1836         dt_node_type_assign(&dn, ctfp, type, B_FALSE);
1837 
1838         if (dn.dn_flags & DT_NF_BITFIELD) {
1839                 xyerror(D_OFFSETOF_BITFIELD,
1840                     "cannot take offset of a bit-field: %s\n", name);
1841         }
1842 
1843         return (dt_node_int(ctm.ctm_offset / NBBY));
1844 }
1845 
1846 dt_node_t *
1847 dt_node_op1(int op, dt_node_t *cp)
1848 {
1849         dt_node_t *dnp;
1850 
1851         if (cp->dn_kind == DT_NODE_INT) {
1852                 switch (op) {
1853                 case DT_TOK_INEG:
1854                         /*
1855                          * If we're negating an unsigned integer, zero out any
1856                          * extra top bits to truncate the value to the size of


2416 dt_node_member(dt_decl_t *ddp, char *name, dt_node_t *expr)
2417 {
2418         dtrace_typeinfo_t dtt;
2419         dt_node_t *dnp;
2420         int err;
2421 
2422         if (ddp != NULL) {
2423                 err = dt_decl_type(ddp, &dtt);
2424                 dt_decl_free(ddp);
2425 
2426                 if (err != 0)
2427                         longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2428         }
2429 
2430         dnp = dt_node_alloc(DT_NODE_MEMBER);
2431         dnp->dn_membname = name;
2432         dnp->dn_membexpr = expr;
2433 
2434         if (ddp != NULL)
2435                 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
2436                     dtt.dtt_flags & DTT_FL_USER ? B_TRUE : B_FALSE);
2437 
2438         return (dnp);
2439 }
2440 
2441 dt_node_t *
2442 dt_node_xlator(dt_decl_t *ddp, dt_decl_t *sdp, char *name, dt_node_t *members)
2443 {
2444         dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2445         dtrace_typeinfo_t src, dst;
2446         dt_node_t sn, dn;
2447         dt_xlator_t *dxp;
2448         dt_node_t *dnp;
2449         int edst, esrc;
2450         uint_t kind;
2451 
2452         char n1[DT_TYPE_NAMELEN];
2453         char n2[DT_TYPE_NAMELEN];
2454 
2455         edst = dt_decl_type(ddp, &dst);
2456         dt_decl_free(ddp);


2773                         idp->di_flags |= DT_IDFLG_PRIM;
2774 
2775                 idp->di_next = dtp->dt_externs;
2776                 dtp->dt_externs = idp;
2777 
2778                 if ((sip = malloc(sizeof (dtrace_syminfo_t))) == NULL)
2779                         longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
2780 
2781                 bcopy(&dts, sip, sizeof (dtrace_syminfo_t));
2782                 idp->di_data = sip;
2783                 idp->di_ctfp = dtt.dtt_ctfp;
2784                 idp->di_type = dtt.dtt_type;
2785 
2786                 free(dnp->dn_string);
2787                 dnp->dn_string = NULL;
2788                 dnp->dn_kind = DT_NODE_SYM;
2789                 dnp->dn_ident = idp;
2790                 dnp->dn_flags |= DT_NF_LVALUE;
2791 
2792                 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
2793                     dtt.dtt_flags & DTT_FL_USER ? B_TRUE : B_FALSE);
2794                 dt_node_attr_assign(dnp, _dtrace_symattr);
2795 
2796                 if (uref) {
2797                         idp->di_flags |= DT_IDFLG_USER;
2798                         dnp->dn_flags |= DT_NF_USERLAND;
2799                 }
2800 
2801         } else if (scope == DTRACE_OBJ_EXEC && create == B_TRUE) {
2802                 uint_t flags = DT_IDFLG_WRITE;
2803                 uint_t id;
2804 
2805                 if (dt_idhash_nextid(dhp, &id) == -1) {
2806                         xyerror(D_ID_OFLOW, "cannot create %s: limit on number "
2807                             "of %s variables exceeded\n", name, sname);
2808                 }
2809 
2810                 if (dhp == yypcb->pcb_locals)
2811                         flags |= DT_IDFLG_LOCAL;
2812                 else if (dhp == dtp->dt_tls)
2813                         flags |= DT_IDFLG_TLS;


2925             dnp->dn_op == DT_TOK_PREDEC || dnp->dn_op == DT_TOK_POSTDEC)
2926                 idflags = DT_IDFLG_REF | DT_IDFLG_MOD;
2927         else
2928                 idflags = DT_IDFLG_REF;
2929 
2930         /*
2931          * We allow the unary ++ and -- operators to instantiate new scalar
2932          * variables if applied to an identifier; otherwise just cook as usual.
2933          */
2934         if (cp->dn_kind == DT_NODE_IDENT && (idflags & DT_IDFLG_MOD))
2935                 dt_xcook_ident(cp, dtp->dt_globals, DT_IDENT_SCALAR, B_TRUE);
2936 
2937         cp = dnp->dn_child = dt_node_cook(cp, 0); /* don't set idflags yet */
2938 
2939         if (cp->dn_kind == DT_NODE_VAR && dt_ident_unref(cp->dn_ident)) {
2940                 if (dt_type_lookup("int64_t", &dtt) != 0)
2941                         xyerror(D_TYPE_ERR, "failed to lookup int64_t\n");
2942 
2943                 dt_ident_type_assign(cp->dn_ident, dtt.dtt_ctfp, dtt.dtt_type);
2944                 dt_node_type_assign(cp, dtt.dtt_ctfp, dtt.dtt_type,
2945                     dtt.dtt_flags & DTT_FL_USER ? B_TRUE : B_FALSE);
2946         }
2947 
2948         if (cp->dn_kind == DT_NODE_VAR)
2949                 cp->dn_ident->di_flags |= idflags;
2950 
2951         switch (dnp->dn_op) {
2952         case DT_TOK_DEREF:
2953                 /*
2954                  * If the deref operator is applied to a translated pointer,
2955                  * we set our output type to the output of the translation.
2956                  */
2957                 if ((idp = dt_node_resolve(cp, DT_IDENT_XLPTR)) != NULL) {
2958                         dt_xlator_t *dxp = idp->di_data;
2959 
2960                         dnp->dn_ident = &dxp->dx_souid;
2961                         dt_node_type_assign(dnp,
2962                             dnp->dn_ident->di_ctfp, dnp->dn_ident->di_type,
2963                             cp->dn_flags & DT_NF_USERLAND);
2964                         break;
2965                 }


3718                         type = ctf_type_resolve(ctfp, lp->dn_type);
3719                         uref = lp->dn_flags & DT_NF_USERLAND;
3720                 }
3721 
3722                 kind = ctf_type_kind(ctfp, type);
3723 
3724                 if (op == DT_TOK_PTR) {
3725                         if (kind != CTF_K_POINTER) {
3726                                 xyerror(D_OP_PTR, "operator %s must be "
3727                                     "applied to a pointer\n", opstr(op));
3728                         }
3729                         type = ctf_type_reference(ctfp, type);
3730                         type = ctf_type_resolve(ctfp, type);
3731                         kind = ctf_type_kind(ctfp, type);
3732                 }
3733 
3734                 /*
3735                  * If we follow a reference to a forward declaration tag,
3736                  * search the entire type space for the actual definition.
3737                  */
3738                 dt_resolve_forward_decl(&ctfp, &type);







3739                 kind = ctf_type_kind(ctfp, type);
3740 
3741                 if (kind == CTF_K_FORWARD) {
3742                         xyerror(D_OP_INCOMPLETE,
3743                             "operator %s cannot be applied to a "
3744                             "forward declaration: no %s definition "
3745                             "is available\n", opstr(op),
3746                             ctf_type_name(ctfp, type, n1, sizeof (n1)));
3747                 } else if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) {


3748                         if (op == DT_TOK_PTR) {
3749                                 xyerror(D_OP_SOU, "operator -> cannot be "
3750                                     "applied to pointer to type \"%s\"; must "
3751                                     "be applied to a struct or union pointer\n",
3752                                     ctf_type_name(ctfp, type, n1, sizeof (n1)));
3753                         } else {
3754                                 xyerror(D_OP_SOU, "operator %s cannot be "
3755                                     "applied to type \"%s\"; must be applied "
3756                                     "to a struct or union\n", opstr(op),
3757                                     ctf_type_name(ctfp, type, n1, sizeof (n1)));
3758                         }
3759                 }
3760 
3761                 if (ctf_member_info(ctfp, type, rp->dn_string, &m) == CTF_ERR) {
3762                         xyerror(D_TYPE_MEMBER,
3763                             "%s is not a member of %s\n", rp->dn_string,
3764                             ctf_type_name(ctfp, type, n1, sizeof (n1)));
3765                 }
3766 
3767                 type = m.ctm_type;

3768 
3769                 dt_resolve_forward_decl(&ctfp, &type);
3770                 dt_node_type_assign(dnp, ctfp, type, B_FALSE);
3771                 dt_node_attr_assign(dnp, lp->dn_attr);
3772 
3773                 type = ctf_type_resolve(ctfp, type);
3774                 kind = ctf_type_kind(ctfp, type);
3775 
3776                 if (op == DT_TOK_PTR && (kind != CTF_K_ARRAY ||
3777                     dt_node_is_string(dnp)))
3778                         dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3779 
3780                 if (op == DT_TOK_DOT && (lp->dn_flags & DT_NF_LVALUE) &&
3781                     (kind != CTF_K_ARRAY || dt_node_is_string(dnp)))
3782                         dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3783 
3784                 if (lp->dn_flags & DT_NF_WRITABLE)
3785                         dnp->dn_flags |= DT_NF_WRITABLE;
3786 
3787                 if (uref && (kind == CTF_K_POINTER ||
3788                     (dnp->dn_flags & DT_NF_REF)))
3789                         dnp->dn_flags |= DT_NF_USERLAND;
3790                 break;
3791 
3792         case DT_TOK_LBRAC: {
3793                 /*
3794                  * If op is DT_TOK_LBRAC, we know from the special-case code at
3795                  * the top that lp is either a D variable or an aggregation.


4263 dt_cook_member(dt_node_t *dnp, uint_t idflags)
4264 {
4265         dnp->dn_membexpr = dt_node_cook(dnp->dn_membexpr, idflags);
4266         dt_node_attr_assign(dnp, dnp->dn_membexpr->dn_attr);
4267         return (dnp);
4268 }
4269 
4270 /*ARGSUSED*/
4271 static dt_node_t *
4272 dt_cook_xlator(dt_node_t *dnp, uint_t idflags)
4273 {
4274         dtrace_hdl_t *dtp = yypcb->pcb_hdl;
4275         dt_xlator_t *dxp = dnp->dn_xlator;
4276         dt_node_t *mnp;
4277 
4278         char n1[DT_TYPE_NAMELEN];
4279         char n2[DT_TYPE_NAMELEN];
4280 
4281         dtrace_attribute_t attr = _dtrace_maxattr;
4282         ctf_membinfo_t ctm;
4283         ctf_id_t type;
4284         ctf_file_t *ctfp;
4285 
4286         /*
4287          * Before cooking each translator member, we push a reference to the
4288          * hash containing translator-local identifiers on to pcb_globals to
4289          * temporarily interpose these identifiers in front of other globals.
4290          */
4291         dt_idstack_push(&yypcb->pcb_globals, dxp->dx_locals);
4292 
4293         for (mnp = dnp->dn_members; mnp != NULL; mnp = mnp->dn_list) {
4294                 if (ctf_member_info(dxp->dx_dst_ctfp, dxp->dx_dst_type,
4295                     mnp->dn_membname, &ctm) == CTF_ERR) {
4296                         xyerror(D_XLATE_MEMB,
4297                             "translator member %s is not a member of %s\n",
4298                             mnp->dn_membname, ctf_type_name(dxp->dx_dst_ctfp,
4299                             dxp->dx_dst_type, n1, sizeof (n1)));
4300                 }
4301 
4302                 (void) dt_node_cook(mnp, DT_IDFLG_REF);
4303                 ctfp = dxp->dx_dst_ctfp;
4304                 type = ctm.ctm_type;
4305 
4306                 /*
4307                  *
4308                  * This probably doesn't need to be resolved, because it's of
4309                  * the translator, but is done for completeness right now.
4310                  */
4311                 dt_resolve_forward_decl(&ctfp, &type);
4312                 dt_node_type_assign(mnp, ctfp, type,
4313                     B_FALSE);
4314                 attr = dt_attr_min(attr, mnp->dn_attr);
4315 
4316                 if (dt_node_is_argcompat(mnp, mnp->dn_membexpr) == 0) {
4317                         xyerror(D_XLATE_INCOMPAT,
4318                             "translator member %s definition uses "
4319                             "incompatible types: \"%s\" = \"%s\"\n",
4320                             mnp->dn_membname,
4321                             dt_node_type_name(mnp, n1, sizeof (n1)),
4322                             dt_node_type_name(mnp->dn_membexpr,
4323                             n2, sizeof (n2)));
4324                 }
4325         }
4326 
4327         dt_idstack_pop(&yypcb->pcb_globals, dxp->dx_locals);
4328 
4329         dxp->dx_souid.di_attr = attr;
4330         dxp->dx_ptrid.di_attr = attr;
4331 
4332         dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE);