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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libdtrace/common/dt_parser.c
          +++ new/usr/src/lib/libdtrace/common/dt_parser.c
↓ open down ↓ 1361 lines elided ↑ open up ↑
1362 1362  
1363 1363          if (err != 0) {
1364 1364                  free(name);
1365 1365                  longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1366 1366          }
1367 1367  
1368 1368          dnp = dt_node_alloc(DT_NODE_TYPE);
1369 1369          dnp->dn_op = DT_TOK_IDENT;
1370 1370          dnp->dn_string = name;
1371 1371  
1372      -        dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, dtt.dtt_flags);
     1372 +        dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
     1373 +            dtt.dtt_flags & DTT_FL_USER ? B_TRUE : B_FALSE);
1373 1374  
1374 1375          if (dtt.dtt_ctfp == dtp->dt_cdefs->dm_ctfp ||
1375 1376              dtt.dtt_ctfp == dtp->dt_ddefs->dm_ctfp)
1376 1377                  dt_node_attr_assign(dnp, _dtrace_defattr);
1377 1378          else
1378 1379                  dt_node_attr_assign(dnp, _dtrace_typattr);
1379 1380  
1380 1381          return (dnp);
1381 1382  }
1382 1383  
↓ open down ↓ 408 lines elided ↑ open up ↑
1791 1792  dt_node_t *
1792 1793  dt_node_offsetof(dt_decl_t *ddp, char *s)
1793 1794  {
1794 1795          dtrace_typeinfo_t dtt;
1795 1796          dt_node_t dn;
1796 1797          char *name;
1797 1798          int err;
1798 1799  
1799 1800          ctf_membinfo_t ctm;
1800 1801          ctf_id_t type;
     1802 +        ctf_file_t *ctfp;
1801 1803          uint_t kind;
1802 1804  
1803 1805          name = strdupa(s);
1804 1806          free(s);
1805 1807  
1806 1808          err = dt_decl_type(ddp, &dtt);
1807 1809          dt_decl_free(ddp);
1808 1810  
1809 1811          if (err != 0)
1810 1812                  longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
↓ open down ↓ 5 lines elided ↑ open up ↑
1816 1818                  xyerror(D_OFFSETOF_TYPE,
1817 1819                      "offsetof operand must be a struct or union type\n");
1818 1820          }
1819 1821  
1820 1822          if (ctf_member_info(dtt.dtt_ctfp, type, name, &ctm) == CTF_ERR) {
1821 1823                  xyerror(D_UNKNOWN, "failed to determine offset of %s: %s\n",
1822 1824                      name, ctf_errmsg(ctf_errno(dtt.dtt_ctfp)));
1823 1825          }
1824 1826  
1825 1827          bzero(&dn, sizeof (dn));
1826      -        dt_node_type_assign(&dn, dtt.dtt_ctfp, ctm.ctm_type, B_FALSE);
     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);
1827 1837  
1828 1838          if (dn.dn_flags & DT_NF_BITFIELD) {
1829 1839                  xyerror(D_OFFSETOF_BITFIELD,
1830 1840                      "cannot take offset of a bit-field: %s\n", name);
1831 1841          }
1832 1842  
1833 1843          return (dt_node_int(ctm.ctm_offset / NBBY));
1834 1844  }
1835 1845  
1836 1846  dt_node_t *
↓ open down ↓ 579 lines elided ↑ open up ↑
2416 2426                  if (err != 0)
2417 2427                          longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2418 2428          }
2419 2429  
2420 2430          dnp = dt_node_alloc(DT_NODE_MEMBER);
2421 2431          dnp->dn_membname = name;
2422 2432          dnp->dn_membexpr = expr;
2423 2433  
2424 2434          if (ddp != NULL)
2425 2435                  dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
2426      -                    dtt.dtt_flags);
     2436 +                    dtt.dtt_flags & DTT_FL_USER ? B_TRUE : B_FALSE);
2427 2437  
2428 2438          return (dnp);
2429 2439  }
2430 2440  
2431 2441  dt_node_t *
2432 2442  dt_node_xlator(dt_decl_t *ddp, dt_decl_t *sdp, char *name, dt_node_t *members)
2433 2443  {
2434 2444          dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2435 2445          dtrace_typeinfo_t src, dst;
2436 2446          dt_node_t sn, dn;
↓ open down ↓ 336 lines elided ↑ open up ↑
2773 2783                  idp->di_ctfp = dtt.dtt_ctfp;
2774 2784                  idp->di_type = dtt.dtt_type;
2775 2785  
2776 2786                  free(dnp->dn_string);
2777 2787                  dnp->dn_string = NULL;
2778 2788                  dnp->dn_kind = DT_NODE_SYM;
2779 2789                  dnp->dn_ident = idp;
2780 2790                  dnp->dn_flags |= DT_NF_LVALUE;
2781 2791  
2782 2792                  dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
2783      -                    dtt.dtt_flags);
     2793 +                    dtt.dtt_flags & DTT_FL_USER ? B_TRUE : B_FALSE);
2784 2794                  dt_node_attr_assign(dnp, _dtrace_symattr);
2785 2795  
2786 2796                  if (uref) {
2787 2797                          idp->di_flags |= DT_IDFLG_USER;
2788 2798                          dnp->dn_flags |= DT_NF_USERLAND;
2789 2799                  }
2790 2800  
2791 2801          } else if (scope == DTRACE_OBJ_EXEC && create == B_TRUE) {
2792 2802                  uint_t flags = DT_IDFLG_WRITE;
2793 2803                  uint_t id;
↓ open down ↓ 131 lines elided ↑ open up ↑
2925 2935                  dt_xcook_ident(cp, dtp->dt_globals, DT_IDENT_SCALAR, B_TRUE);
2926 2936  
2927 2937          cp = dnp->dn_child = dt_node_cook(cp, 0); /* don't set idflags yet */
2928 2938  
2929 2939          if (cp->dn_kind == DT_NODE_VAR && dt_ident_unref(cp->dn_ident)) {
2930 2940                  if (dt_type_lookup("int64_t", &dtt) != 0)
2931 2941                          xyerror(D_TYPE_ERR, "failed to lookup int64_t\n");
2932 2942  
2933 2943                  dt_ident_type_assign(cp->dn_ident, dtt.dtt_ctfp, dtt.dtt_type);
2934 2944                  dt_node_type_assign(cp, dtt.dtt_ctfp, dtt.dtt_type,
2935      -                    dtt.dtt_flags);
     2945 +                    dtt.dtt_flags & DTT_FL_USER ? B_TRUE : B_FALSE);
2936 2946          }
2937 2947  
2938 2948          if (cp->dn_kind == DT_NODE_VAR)
2939 2949                  cp->dn_ident->di_flags |= idflags;
2940 2950  
2941 2951          switch (dnp->dn_op) {
2942 2952          case DT_TOK_DEREF:
2943 2953                  /*
2944 2954                   * If the deref operator is applied to a translated pointer,
2945 2955                   * we set our output type to the output of the translation.
↓ open down ↓ 772 lines elided ↑ open up ↑
3718 3728                          }
3719 3729                          type = ctf_type_reference(ctfp, type);
3720 3730                          type = ctf_type_resolve(ctfp, type);
3721 3731                          kind = ctf_type_kind(ctfp, type);
3722 3732                  }
3723 3733  
3724 3734                  /*
3725 3735                   * If we follow a reference to a forward declaration tag,
3726 3736                   * search the entire type space for the actual definition.
3727 3737                   */
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      -                }
     3738 +                dt_resolve_forward_decl(&ctfp, &type);
     3739 +                kind = ctf_type_kind(ctfp, type);
3744 3740  
3745      -                if (kind != CTF_K_STRUCT && kind != CTF_K_UNION) {
     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) {
3746 3748                          if (op == DT_TOK_PTR) {
3747 3749                                  xyerror(D_OP_SOU, "operator -> cannot be "
3748 3750                                      "applied to pointer to type \"%s\"; must "
3749 3751                                      "be applied to a struct or union pointer\n",
3750 3752                                      ctf_type_name(ctfp, type, n1, sizeof (n1)));
3751 3753                          } else {
3752 3754                                  xyerror(D_OP_SOU, "operator %s cannot be "
3753 3755                                      "applied to type \"%s\"; must be applied "
3754 3756                                      "to a struct or union\n", opstr(op),
3755 3757                                      ctf_type_name(ctfp, type, n1, sizeof (n1)));
3756 3758                          }
3757 3759                  }
3758 3760  
3759 3761                  if (ctf_member_info(ctfp, type, rp->dn_string, &m) == CTF_ERR) {
3760 3762                          xyerror(D_TYPE_MEMBER,
3761 3763                              "%s is not a member of %s\n", rp->dn_string,
3762 3764                              ctf_type_name(ctfp, type, n1, sizeof (n1)));
3763 3765                  }
3764 3766  
3765      -                type = ctf_type_resolve(ctfp, m.ctm_type);
3766      -                kind = ctf_type_kind(ctfp, type);
     3767 +                type = m.ctm_type;
3767 3768  
3768      -                dt_node_type_assign(dnp, ctfp, m.ctm_type, B_FALSE);
     3769 +                dt_resolve_forward_decl(&ctfp, &type);
     3770 +                dt_node_type_assign(dnp, ctfp, type, B_FALSE);
3769 3771                  dt_node_attr_assign(dnp, lp->dn_attr);
3770 3772  
     3773 +                type = ctf_type_resolve(ctfp, type);
     3774 +                kind = ctf_type_kind(ctfp, type);
     3775 +
3771 3776                  if (op == DT_TOK_PTR && (kind != CTF_K_ARRAY ||
3772 3777                      dt_node_is_string(dnp)))
3773 3778                          dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3774 3779  
3775 3780                  if (op == DT_TOK_DOT && (lp->dn_flags & DT_NF_LVALUE) &&
3776 3781                      (kind != CTF_K_ARRAY || dt_node_is_string(dnp)))
3777 3782                          dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3778 3783  
3779 3784                  if (lp->dn_flags & DT_NF_WRITABLE)
3780 3785                          dnp->dn_flags |= DT_NF_WRITABLE;
↓ open down ↓ 487 lines elided ↑ open up ↑
4268 4273  {
4269 4274          dtrace_hdl_t *dtp = yypcb->pcb_hdl;
4270 4275          dt_xlator_t *dxp = dnp->dn_xlator;
4271 4276          dt_node_t *mnp;
4272 4277  
4273 4278          char n1[DT_TYPE_NAMELEN];
4274 4279          char n2[DT_TYPE_NAMELEN];
4275 4280  
4276 4281          dtrace_attribute_t attr = _dtrace_maxattr;
4277 4282          ctf_membinfo_t ctm;
     4283 +        ctf_id_t type;
     4284 +        ctf_file_t *ctfp;
4278 4285  
4279 4286          /*
4280 4287           * Before cooking each translator member, we push a reference to the
4281 4288           * hash containing translator-local identifiers on to pcb_globals to
4282 4289           * temporarily interpose these identifiers in front of other globals.
4283 4290           */
4284 4291          dt_idstack_push(&yypcb->pcb_globals, dxp->dx_locals);
4285 4292  
4286 4293          for (mnp = dnp->dn_members; mnp != NULL; mnp = mnp->dn_list) {
4287 4294                  if (ctf_member_info(dxp->dx_dst_ctfp, dxp->dx_dst_type,
4288 4295                      mnp->dn_membname, &ctm) == CTF_ERR) {
4289 4296                          xyerror(D_XLATE_MEMB,
4290 4297                              "translator member %s is not a member of %s\n",
4291 4298                              mnp->dn_membname, ctf_type_name(dxp->dx_dst_ctfp,
4292 4299                              dxp->dx_dst_type, n1, sizeof (n1)));
4293 4300                  }
4294 4301  
4295 4302                  (void) dt_node_cook(mnp, DT_IDFLG_REF);
4296      -                dt_node_type_assign(mnp, dxp->dx_dst_ctfp, ctm.ctm_type,
     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,
4297 4313                      B_FALSE);
4298 4314                  attr = dt_attr_min(attr, mnp->dn_attr);
4299 4315  
4300 4316                  if (dt_node_is_argcompat(mnp, mnp->dn_membexpr) == 0) {
4301 4317                          xyerror(D_XLATE_INCOMPAT,
4302 4318                              "translator member %s definition uses "
4303 4319                              "incompatible types: \"%s\" = \"%s\"\n",
4304 4320                              mnp->dn_membname,
4305 4321                              dt_node_type_name(mnp, n1, sizeof (n1)),
4306 4322                              dt_node_type_name(mnp->dn_membexpr,
↓ open down ↓ 673 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX