Print this page
4474 DTrace Userland CTF Support
4475 DTrace userland Keyword
4476 DTrace tests should be better citizens
4479 pid provider types
4480 dof emulation missing checks
Reviewed by: Bryan Cantrill <bryan@joyent.com>

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 ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24      - * Copyright (c) 2011, Joyent Inc. All rights reserved.
  25      - * Copyright (c) 2012 by Delphix. All rights reserved.
       24 + * Copyright (c) 2013, Joyent Inc. All rights reserved.
       25 + * Copyright (c) 2013 by Delphix. All rights reserved.
  26   26   */
  27   27  
  28   28  /*
  29   29   * DTrace D Language Parser
  30   30   *
  31   31   * The D Parser is a lex/yacc parser consisting of the lexer dt_lex.l, the
  32   32   * parsing grammar dt_grammar.y, and this file, dt_parser.c, which handles
  33   33   * the construction of the parse tree nodes and their syntactic validation.
  34   34   * The parse tree is constructed of dt_node_t structures (see <dt_parser.h>)
  35   35   * that are built in two passes: (1) the "create" pass, where the parse tree
↓ open down ↓ 149 lines elided ↑ open up ↑
 185  185          case DT_TOK_INT:        return ("<int>");
 186  186          default:                return ("<?>");
 187  187          }
 188  188  }
 189  189  
 190  190  int
 191  191  dt_type_lookup(const char *s, dtrace_typeinfo_t *tip)
 192  192  {
 193  193          static const char delimiters[] = " \t\n\r\v\f*`";
 194  194          dtrace_hdl_t *dtp = yypcb->pcb_hdl;
 195      -        const char *p, *q, *end, *obj;
      195 +        const char *p, *q, *r, *end, *obj;
 196  196  
 197  197          for (p = s, end = s + strlen(s); *p != '\0'; p = q) {
 198  198                  while (isspace(*p))
 199  199                          p++;    /* skip leading whitespace prior to token */
 200  200  
 201  201                  if (p == end || (q = strpbrk(p + 1, delimiters)) == NULL)
 202  202                          break;  /* empty string or single token remaining */
 203  203  
 204  204                  if (*q == '`') {
 205  205                          char *object = alloca((size_t)(q - p) + 1);
↓ open down ↓ 7 lines elided ↑ open up ↑
 213  213                          object[(size_t)(q - p)] = '\0';
 214  214  
 215  215                          /*
 216  216                           * Copy the original string up to the start of this
 217  217                           * token (p) into type, and then concatenate everything
 218  218                           * after q.  This is the type name without the object.
 219  219                           */
 220  220                          bcopy(s, type, (size_t)(p - s));
 221  221                          bcopy(q + 1, type + (size_t)(p - s), strlen(q + 1) + 1);
 222  222  
 223      -                        if (strchr(q + 1, '`') != NULL)
 224      -                                return (dt_set_errno(dtp, EDT_BADSCOPE));
      223 +                        /*
      224 +                         * There may be at most three delimeters. The second
      225 +                         * delimeter is usually used to distinguish the type
      226 +                         * within a given module, however, there could be a link
      227 +                         * map id on the scene in which case that delimeter
      228 +                         * would be the third. We determine presence of the lmid
      229 +                         * if it rouglhly meets the from LM[0-9]
      230 +                         */
      231 +                        if ((r = strchr(q + 1, '`')) != NULL &&
      232 +                            ((r = strchr(r + 1, '`')) != NULL)) {
      233 +                                if (strchr(r + 1, '`') != NULL)
      234 +                                        return (dt_set_errno(dtp,
      235 +                                            EDT_BADSCOPE));
      236 +                                if (q[1] != 'L' || q[2] != 'M')
      237 +                                        return (dt_set_errno(dtp,
      238 +                                            EDT_BADSCOPE));
      239 +                        }
 225  240  
 226  241                          return (dtrace_lookup_by_type(dtp, object, type, tip));
 227  242                  }
 228  243          }
 229  244  
 230  245          if (yypcb->pcb_idepth != 0)
 231  246                  obj = DTRACE_OBJ_CDEFS;
 232  247          else
 233  248                  obj = DTRACE_OBJ_EVERY;
 234  249  
↓ open down ↓ 9 lines elided ↑ open up ↑
 244  259   * or its base (that is, we try both "foo_t *" and "struct foo *"), and also
 245  260   * to potentially construct the required type on-the-fly.
 246  261   */
 247  262  int
 248  263  dt_type_pointer(dtrace_typeinfo_t *tip)
 249  264  {
 250  265          dtrace_hdl_t *dtp = yypcb->pcb_hdl;
 251  266          ctf_file_t *ctfp = tip->dtt_ctfp;
 252  267          ctf_id_t type = tip->dtt_type;
 253  268          ctf_id_t base = ctf_type_resolve(ctfp, type);
      269 +        uint_t bflags = tip->dtt_flags;
 254  270  
 255  271          dt_module_t *dmp;
 256  272          ctf_id_t ptr;
 257  273  
 258  274          if ((ptr = ctf_type_pointer(ctfp, type)) != CTF_ERR ||
 259  275              (ptr = ctf_type_pointer(ctfp, base)) != CTF_ERR) {
 260  276                  tip->dtt_type = ptr;
 261  277                  return (0);
 262  278          }
 263  279  
↓ open down ↓ 11 lines elided ↑ open up ↑
 275  291          ptr = ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, type);
 276  292  
 277  293          if (ptr == CTF_ERR || ctf_update(dmp->dm_ctfp) == CTF_ERR) {
 278  294                  dtp->dt_ctferr = ctf_errno(dmp->dm_ctfp);
 279  295                  return (dt_set_errno(dtp, EDT_CTF));
 280  296          }
 281  297  
 282  298          tip->dtt_object = dmp->dm_name;
 283  299          tip->dtt_ctfp = dmp->dm_ctfp;
 284  300          tip->dtt_type = ptr;
      301 +        tip->dtt_flags = bflags;
 285  302  
 286  303          return (0);
 287  304  }
 288  305  
 289  306  const char *
 290  307  dt_type_name(ctf_file_t *ctfp, ctf_id_t type, char *buf, size_t len)
 291  308  {
 292  309          dtrace_hdl_t *dtp = yypcb->pcb_hdl;
 293  310  
 294  311          if (ctfp == DT_FPTR_CTFP(dtp) && type == DT_FPTR_TYPE(dtp))
↓ open down ↓ 83 lines elided ↑ open up ↑
 378  395  
 379  396  return_rtype:
 380  397          *ofp = rfp;
 381  398          *otype = rtype;
 382  399  }
 383  400  
 384  401  void
 385  402  dt_node_promote(dt_node_t *lp, dt_node_t *rp, dt_node_t *dnp)
 386  403  {
 387  404          dt_type_promote(lp, rp, &dnp->dn_ctfp, &dnp->dn_type);
 388      -        dt_node_type_assign(dnp, dnp->dn_ctfp, dnp->dn_type);
      405 +        dt_node_type_assign(dnp, dnp->dn_ctfp, dnp->dn_type, B_FALSE);
 389  406          dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
 390  407  }
 391  408  
 392  409  const char *
 393  410  dt_node_name(const dt_node_t *dnp, char *buf, size_t len)
 394  411  {
 395  412          char n1[DT_TYPE_NAMELEN];
 396  413          char n2[DT_TYPE_NAMELEN];
 397  414  
 398  415          const char *prefix = "", *suffix = "";
↓ open down ↓ 248 lines elided ↑ open up ↑
 647  664  
 648  665                  dnerror(dnp, D_ATTR_MIN, "attributes for %s (%s) are less than "
 649  666                      "predefined minimum\n", dt_node_name(dnp, s, sizeof (s)),
 650  667                      dtrace_attr2str(attr, a, sizeof (a)));
 651  668          }
 652  669  
 653  670          dnp->dn_attr = attr;
 654  671  }
 655  672  
 656  673  void
 657      -dt_node_type_assign(dt_node_t *dnp, ctf_file_t *fp, ctf_id_t type)
      674 +dt_node_type_assign(dt_node_t *dnp, ctf_file_t *fp, ctf_id_t type,
      675 +    boolean_t user)
 658  676  {
 659  677          ctf_id_t base = ctf_type_resolve(fp, type);
 660  678          uint_t kind = ctf_type_kind(fp, base);
 661  679          ctf_encoding_t e;
 662  680  
 663  681          dnp->dn_flags &=
 664  682              ~(DT_NF_SIGNED | DT_NF_REF | DT_NF_BITFIELD | DT_NF_USERLAND);
 665  683  
 666  684          if (kind == CTF_K_INTEGER && ctf_type_encoding(fp, base, &e) == 0) {
 667  685                  size_t size = e.cte_bits / NBBY;
↓ open down ↓ 11 lines elided ↑ open up ↑
 679  697          }
 680  698  
 681  699          if (kind == CTF_K_STRUCT || kind == CTF_K_UNION ||
 682  700              kind == CTF_K_FORWARD ||
 683  701              kind == CTF_K_ARRAY || kind == CTF_K_FUNCTION)
 684  702                  dnp->dn_flags |= DT_NF_REF;
 685  703          else if (yypcb != NULL && fp == DT_DYN_CTFP(yypcb->pcb_hdl) &&
 686  704              type == DT_DYN_TYPE(yypcb->pcb_hdl))
 687  705                  dnp->dn_flags |= DT_NF_REF;
 688  706  
      707 +        if (user)
      708 +                dnp->dn_flags |= DT_NF_USERLAND;
      709 +
 689  710          dnp->dn_flags |= DT_NF_COOKED;
 690  711          dnp->dn_ctfp = fp;
 691  712          dnp->dn_type = type;
 692  713  }
 693  714  
 694  715  void
 695  716  dt_node_type_propagate(const dt_node_t *src, dt_node_t *dst)
 696  717  {
 697  718          assert(src->dn_flags & DT_NF_COOKED);
 698  719          dst->dn_flags = src->dn_flags & ~DT_NF_LVALUE;
↓ open down ↓ 17 lines elided ↑ open up ↑
 716  737                  return (buf);
 717  738          }
 718  739  
 719  740          return (dt_type_name(dnp->dn_ctfp, dnp->dn_type, buf, len));
 720  741  }
 721  742  
 722  743  size_t
 723  744  dt_node_type_size(const dt_node_t *dnp)
 724  745  {
 725  746          ctf_id_t base;
      747 +        dtrace_hdl_t *dtp = yypcb->pcb_hdl;
 726  748  
 727  749          if (dnp->dn_kind == DT_NODE_STRING)
 728  750                  return (strlen(dnp->dn_string) + 1);
 729  751  
 730  752          if (dt_node_is_dynamic(dnp) && dnp->dn_ident != NULL)
 731  753                  return (dt_ident_size(dnp->dn_ident));
 732  754  
 733  755          base = ctf_type_resolve(dnp->dn_ctfp, dnp->dn_type);
 734  756  
 735  757          if (ctf_type_kind(dnp->dn_ctfp, base) == CTF_K_FORWARD)
 736  758                  return (0);
 737  759  
      760 +        /*
      761 +         * Here we have a 32-bit user pointer that is being used with a 64-bit
      762 +         * kernel. When we're using it and its tagged as a userland reference --
      763 +         * then we need to keep it as a 32-bit pointer. However, if we are
      764 +         * referring to it as a kernel address, eg. being used after a copyin()
      765 +         * then we need to make sure that we actually return the kernel's size
      766 +         * of a pointer, 8 bytes.
      767 +         */
      768 +        if (ctf_type_kind(dnp->dn_ctfp, base) == CTF_K_POINTER &&
      769 +            ctf_getmodel(dnp->dn_ctfp) == CTF_MODEL_ILP32 &&
      770 +            !(dnp->dn_flags & DT_NF_USERLAND) &&
      771 +            dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64)
      772 +                        return (8);
      773 +
 738  774          return (ctf_type_size(dnp->dn_ctfp, dnp->dn_type));
 739  775  }
 740  776  
 741  777  /*
 742  778   * Determine if the specified parse tree node references an identifier of the
 743  779   * specified kind, and if so return a pointer to it; otherwise return NULL.
 744  780   * This function resolves the identifier itself, following through any inlines.
 745  781   */
 746  782  dt_ident_t *
 747  783  dt_node_resolve(const dt_node_t *dnp, uint_t idkind)
↓ open down ↓ 466 lines elided ↑ open up ↑
1214 1250                  if (c == 'U' || c == 'u')
1215 1251                          i += 1;
1216 1252                  else if (c == 'L' || c == 'l')
1217 1253                          i += 2;
1218 1254          }
1219 1255  
1220 1256          for (; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i += n) {
1221 1257                  if (value <= dtp->dt_ints[i].did_limit) {
1222 1258                          dt_node_type_assign(dnp,
1223 1259                              dtp->dt_ints[i].did_ctfp,
1224      -                            dtp->dt_ints[i].did_type);
     1260 +                            dtp->dt_ints[i].did_type, B_FALSE);
1225 1261  
1226 1262                          /*
1227 1263                           * If a prefix character is present in macro text, add
1228 1264                           * in the corresponding operator node (see dt_lex.l).
1229 1265                           */
1230 1266                          switch (yyintprefix) {
1231 1267                          case '+':
1232 1268                                  return (dt_node_op1(DT_TOK_IPOS, dnp));
1233 1269                          case '-':
1234 1270                                  return (dt_node_op1(DT_TOK_INEG, dnp));
↓ open down ↓ 14 lines elided ↑ open up ↑
1249 1285  {
1250 1286          dtrace_hdl_t *dtp = yypcb->pcb_hdl;
1251 1287          dt_node_t *dnp;
1252 1288  
1253 1289          if (string == NULL)
1254 1290                  longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
1255 1291  
1256 1292          dnp = dt_node_alloc(DT_NODE_STRING);
1257 1293          dnp->dn_op = DT_TOK_STRING;
1258 1294          dnp->dn_string = string;
1259      -        dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp));
     1295 +        dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp), B_FALSE);
1260 1296  
1261 1297          return (dnp);
1262 1298  }
1263 1299  
1264 1300  dt_node_t *
1265 1301  dt_node_ident(char *name)
1266 1302  {
1267 1303          dt_ident_t *idp;
1268 1304          dt_node_t *dnp;
1269 1305  
↓ open down ↓ 55 lines elided ↑ open up ↑
1325 1361          dt_decl_free(ddp);
1326 1362  
1327 1363          if (err != 0) {
1328 1364                  free(name);
1329 1365                  longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1330 1366          }
1331 1367  
1332 1368          dnp = dt_node_alloc(DT_NODE_TYPE);
1333 1369          dnp->dn_op = DT_TOK_IDENT;
1334 1370          dnp->dn_string = name;
1335      -        dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
     1371 +
     1372 +        dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, dtt.dtt_flags);
1336 1373  
1337 1374          if (dtt.dtt_ctfp == dtp->dt_cdefs->dm_ctfp ||
1338 1375              dtt.dtt_ctfp == dtp->dt_ddefs->dm_ctfp)
1339 1376                  dt_node_attr_assign(dnp, _dtrace_defattr);
1340 1377          else
1341 1378                  dt_node_attr_assign(dnp, _dtrace_typattr);
1342 1379  
1343 1380          return (dnp);
1344 1381  }
1345 1382  
↓ open down ↓ 223 lines elided ↑ open up ↑
1569 1606                   * Create a fake dt_node_t on the stack so we can determine the
1570 1607                   * type of any matching identifier by assigning to this node.
1571 1608                   * If the pre-existing ident has its di_type set, propagate
1572 1609                   * the type by hand so as not to trigger a prototype check for
1573 1610                   * arrays (yet); otherwise we use dt_ident_cook() on the ident
1574 1611                   * to ensure it is fully initialized before looking at it.
1575 1612                   */
1576 1613                  bzero(&idn, sizeof (dt_node_t));
1577 1614  
1578 1615                  if (idp != NULL && idp->di_type != CTF_ERR)
1579      -                        dt_node_type_assign(&idn, idp->di_ctfp, idp->di_type);
     1616 +                        dt_node_type_assign(&idn, idp->di_ctfp, idp->di_type,
     1617 +                            B_FALSE);
1580 1618                  else if (idp != NULL)
1581 1619                          (void) dt_ident_cook(&idn, idp, NULL);
1582 1620  
1583 1621                  if (assc) {
1584 1622                          if (class == DT_DC_THIS) {
1585 1623                                  xyerror(D_DECL_LOCASSC, "associative arrays "
1586 1624                                      "may not be declared as local variables:"
1587 1625                                      " %s\n", dsp->ds_ident);
1588 1626                          }
1589 1627  
↓ open down ↓ 188 lines elided ↑ open up ↑
1778 1816                  xyerror(D_OFFSETOF_TYPE,
1779 1817                      "offsetof operand must be a struct or union type\n");
1780 1818          }
1781 1819  
1782 1820          if (ctf_member_info(dtt.dtt_ctfp, type, name, &ctm) == CTF_ERR) {
1783 1821                  xyerror(D_UNKNOWN, "failed to determine offset of %s: %s\n",
1784 1822                      name, ctf_errmsg(ctf_errno(dtt.dtt_ctfp)));
1785 1823          }
1786 1824  
1787 1825          bzero(&dn, sizeof (dn));
1788      -        dt_node_type_assign(&dn, dtt.dtt_ctfp, ctm.ctm_type);
     1826 +        dt_node_type_assign(&dn, dtt.dtt_ctfp, ctm.ctm_type, B_FALSE);
1789 1827  
1790 1828          if (dn.dn_flags & DT_NF_BITFIELD) {
1791 1829                  xyerror(D_OFFSETOF_BITFIELD,
1792 1830                      "cannot take offset of a bit-field: %s\n", name);
1793 1831          }
1794 1832  
1795 1833          return (dt_node_int(ctm.ctm_offset / NBBY));
1796 1834  }
1797 1835  
1798 1836  dt_node_t *
↓ open down ↓ 35 lines elided ↑ open up ↑
1834 1872              (cp->dn_kind == DT_NODE_STRING || cp->dn_kind == DT_NODE_TYPE)) {
1835 1873                  dtrace_hdl_t *dtp = yypcb->pcb_hdl;
1836 1874                  size_t size = dt_node_type_size(cp);
1837 1875  
1838 1876                  if (size == 0) {
1839 1877                          xyerror(D_SIZEOF_TYPE, "cannot apply sizeof to an "
1840 1878                              "operand of unknown size\n");
1841 1879                  }
1842 1880  
1843 1881                  dt_node_type_assign(cp, dtp->dt_ddefs->dm_ctfp,
1844      -                    ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"));
     1882 +                    ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"),
     1883 +                    B_FALSE);
1845 1884  
1846 1885                  cp->dn_kind = DT_NODE_INT;
1847 1886                  cp->dn_op = DT_TOK_INT;
1848 1887                  cp->dn_value = size;
1849 1888  
1850 1889                  return (cp);
1851 1890          }
1852 1891  
1853 1892          dnp = dt_node_alloc(DT_NODE_OP1);
1854 1893          assert(op <= USHRT_MAX);
↓ open down ↓ 57 lines elided ↑ open up ↑
1912 1951          if (lp->dn_kind == DT_NODE_INT && rp->dn_kind == DT_NODE_INT) {
1913 1952                  uintmax_t l = lp->dn_value;
1914 1953                  uintmax_t r = rp->dn_value;
1915 1954  
1916 1955                  dnp = dt_node_int(0); /* allocate new integer node for result */
1917 1956  
1918 1957                  switch (op) {
1919 1958                  case DT_TOK_LOR:
1920 1959                          dnp->dn_value = l || r;
1921 1960                          dt_node_type_assign(dnp,
1922      -                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     1961 +                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1923 1962                          break;
1924 1963                  case DT_TOK_LXOR:
1925 1964                          dnp->dn_value = (l != 0) ^ (r != 0);
1926 1965                          dt_node_type_assign(dnp,
1927      -                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     1966 +                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1928 1967                          break;
1929 1968                  case DT_TOK_LAND:
1930 1969                          dnp->dn_value = l && r;
1931 1970                          dt_node_type_assign(dnp,
1932      -                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     1971 +                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1933 1972                          break;
1934 1973                  case DT_TOK_BOR:
1935 1974                          dnp->dn_value = l | r;
1936 1975                          dt_node_promote(lp, rp, dnp);
1937 1976                          break;
1938 1977                  case DT_TOK_XOR:
1939 1978                          dnp->dn_value = l ^ r;
1940 1979                          dt_node_promote(lp, rp, dnp);
1941 1980                          break;
1942 1981                  case DT_TOK_BAND:
1943 1982                          dnp->dn_value = l & r;
1944 1983                          dt_node_promote(lp, rp, dnp);
1945 1984                          break;
1946 1985                  case DT_TOK_EQU:
1947 1986                          dnp->dn_value = l == r;
1948 1987                          dt_node_type_assign(dnp,
1949      -                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     1988 +                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1950 1989                          break;
1951 1990                  case DT_TOK_NEQ:
1952 1991                          dnp->dn_value = l != r;
1953 1992                          dt_node_type_assign(dnp,
1954      -                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     1993 +                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1955 1994                          break;
1956 1995                  case DT_TOK_LT:
1957 1996                          dt_node_promote(lp, rp, dnp);
1958 1997                          if (dnp->dn_flags & DT_NF_SIGNED)
1959 1998                                  dnp->dn_value = (intmax_t)l < (intmax_t)r;
1960 1999                          else
1961 2000                                  dnp->dn_value = l < r;
1962 2001                          dt_node_type_assign(dnp,
1963      -                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     2002 +                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1964 2003                          break;
1965 2004                  case DT_TOK_LE:
1966 2005                          dt_node_promote(lp, rp, dnp);
1967 2006                          if (dnp->dn_flags & DT_NF_SIGNED)
1968 2007                                  dnp->dn_value = (intmax_t)l <= (intmax_t)r;
1969 2008                          else
1970 2009                                  dnp->dn_value = l <= r;
1971 2010                          dt_node_type_assign(dnp,
1972      -                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     2011 +                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1973 2012                          break;
1974 2013                  case DT_TOK_GT:
1975 2014                          dt_node_promote(lp, rp, dnp);
1976 2015                          if (dnp->dn_flags & DT_NF_SIGNED)
1977 2016                                  dnp->dn_value = (intmax_t)l > (intmax_t)r;
1978 2017                          else
1979 2018                                  dnp->dn_value = l > r;
1980 2019                          dt_node_type_assign(dnp,
1981      -                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     2020 +                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1982 2021                          break;
1983 2022                  case DT_TOK_GE:
1984 2023                          dt_node_promote(lp, rp, dnp);
1985 2024                          if (dnp->dn_flags & DT_NF_SIGNED)
1986 2025                                  dnp->dn_value = (intmax_t)l >= (intmax_t)r;
1987 2026                          else
1988 2027                                  dnp->dn_value = l >= r;
1989 2028                          dt_node_type_assign(dnp,
1990      -                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     2029 +                            DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE);
1991 2030                          break;
1992 2031                  case DT_TOK_LSH:
1993 2032                          dnp->dn_value = l << r;
1994 2033                          dt_node_type_propagate(lp, dnp);
1995 2034                          dt_node_attr_assign(rp,
1996 2035                              dt_attr_min(lp->dn_attr, rp->dn_attr));
1997 2036                          break;
1998 2037                  case DT_TOK_RSH:
1999 2038                          dnp->dn_value = l >> r;
2000 2039                          dt_node_type_propagate(lp, dnp);
↓ open down ↓ 220 lines elided ↑ open up ↑
2221 2260                  if (dt_decl_type(ddp->dd_next, &dtt) != 0)
2222 2261                          longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2223 2262          }
2224 2263  
2225 2264          /*
2226 2265           * If the inline identifier is not defined, then create it with the
2227 2266           * orphan flag set.  We do not insert the identifier into dt_globals
2228 2267           * until we have successfully cooked the right-hand expression, below.
2229 2268           */
2230 2269          dnp = dt_node_alloc(DT_NODE_INLINE);
2231      -        dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
     2270 +        dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, B_FALSE);
2232 2271          dt_node_attr_assign(dnp, _dtrace_defattr);
2233 2272  
2234 2273          if (dt_node_is_void(dnp)) {
2235 2274                  xyerror(D_DECL_VOIDOBJ,
2236 2275                      "cannot declare void inline: %s\n", dsp->ds_ident);
2237 2276          }
2238 2277  
2239 2278          if (ctf_type_kind(dnp->dn_ctfp, ctf_type_resolve(
2240 2279              dnp->dn_ctfp, dnp->dn_type)) == CTF_K_FORWARD) {
2241 2280                  xyerror(D_DECL_INCOMPLETE,
↓ open down ↓ 134 lines elided ↑ open up ↑
2376 2415  
2377 2416                  if (err != 0)
2378 2417                          longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2379 2418          }
2380 2419  
2381 2420          dnp = dt_node_alloc(DT_NODE_MEMBER);
2382 2421          dnp->dn_membname = name;
2383 2422          dnp->dn_membexpr = expr;
2384 2423  
2385 2424          if (ddp != NULL)
2386      -                dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
     2425 +                dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
     2426 +                    dtt.dtt_flags);
2387 2427  
2388 2428          return (dnp);
2389 2429  }
2390 2430  
2391 2431  dt_node_t *
2392 2432  dt_node_xlator(dt_decl_t *ddp, dt_decl_t *sdp, char *name, dt_node_t *members)
2393 2433  {
2394 2434          dtrace_hdl_t *dtp = yypcb->pcb_hdl;
2395 2435          dtrace_typeinfo_t src, dst;
2396 2436          dt_node_t sn, dn;
↓ open down ↓ 10 lines elided ↑ open up ↑
2407 2447  
2408 2448          esrc = dt_decl_type(sdp, &src);
2409 2449          dt_decl_free(sdp);
2410 2450  
2411 2451          if (edst != 0 || esrc != 0) {
2412 2452                  free(name);
2413 2453                  longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2414 2454          }
2415 2455  
2416 2456          bzero(&sn, sizeof (sn));
2417      -        dt_node_type_assign(&sn, src.dtt_ctfp, src.dtt_type);
     2457 +        dt_node_type_assign(&sn, src.dtt_ctfp, src.dtt_type, B_FALSE);
2418 2458  
2419 2459          bzero(&dn, sizeof (dn));
2420      -        dt_node_type_assign(&dn, dst.dtt_ctfp, dst.dtt_type);
     2460 +        dt_node_type_assign(&dn, dst.dtt_ctfp, dst.dtt_type, B_FALSE);
2421 2461  
2422 2462          if (dt_xlator_lookup(dtp, &sn, &dn, DT_XLATE_EXACT) != NULL) {
2423 2463                  xyerror(D_XLATE_REDECL,
2424 2464                      "translator from %s to %s has already been declared\n",
2425 2465                      dt_node_type_name(&sn, n1, sizeof (n1)),
2426 2466                      dt_node_type_name(&dn, n2, sizeof (n2)));
2427 2467          }
2428 2468  
2429 2469          kind = ctf_type_kind(dst.dtt_ctfp,
2430 2470              ctf_type_resolve(dst.dtt_ctfp, dst.dtt_type));
↓ open down ↓ 225 lines elided ↑ open up ↑
2656 2696                  /*
2657 2697                   * Arrays and aggregations are not cooked individually. They
2658 2698                   * have dynamic types and must be referenced using operator [].
2659 2699                   * This is handled explicitly by the code for DT_TOK_LBRAC.
2660 2700                   */
2661 2701                  if (idp->di_kind != DT_IDENT_ARRAY &&
2662 2702                      idp->di_kind != DT_IDENT_AGG)
2663 2703                          attr = dt_ident_cook(dnp, idp, NULL);
2664 2704                  else {
2665 2705                          dt_node_type_assign(dnp,
2666      -                            DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
     2706 +                            DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE);
2667 2707                          attr = idp->di_attr;
2668 2708                  }
2669 2709  
2670 2710                  free(dnp->dn_string);
2671 2711                  dnp->dn_string = NULL;
2672 2712                  dnp->dn_kind = dnkind;
2673 2713                  dnp->dn_ident = idp;
2674 2714                  dnp->dn_flags |= DT_NF_LVALUE;
2675 2715  
2676 2716                  if (idp->di_flags & DT_IDFLG_WRITE)
↓ open down ↓ 55 lines elided ↑ open up ↑
2732 2772                  idp->di_data = sip;
2733 2773                  idp->di_ctfp = dtt.dtt_ctfp;
2734 2774                  idp->di_type = dtt.dtt_type;
2735 2775  
2736 2776                  free(dnp->dn_string);
2737 2777                  dnp->dn_string = NULL;
2738 2778                  dnp->dn_kind = DT_NODE_SYM;
2739 2779                  dnp->dn_ident = idp;
2740 2780                  dnp->dn_flags |= DT_NF_LVALUE;
2741 2781  
2742      -                dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
     2782 +                dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
     2783 +                    dtt.dtt_flags);
2743 2784                  dt_node_attr_assign(dnp, _dtrace_symattr);
2744 2785  
2745 2786                  if (uref) {
2746 2787                          idp->di_flags |= DT_IDFLG_USER;
2747 2788                          dnp->dn_flags |= DT_NF_USERLAND;
2748 2789                  }
2749 2790  
2750 2791          } else if (scope == DTRACE_OBJ_EXEC && create == B_TRUE) {
2751 2792                  uint_t flags = DT_IDFLG_WRITE;
2752 2793                  uint_t id;
↓ open down ↓ 27 lines elided ↑ open up ↑
2780 2821                  /*
2781 2822                   * Arrays and aggregations are not cooked individually. They
2782 2823                   * have dynamic types and must be referenced using operator [].
2783 2824                   * This is handled explicitly by the code for DT_TOK_LBRAC.
2784 2825                   */
2785 2826                  if (idp->di_kind != DT_IDENT_ARRAY &&
2786 2827                      idp->di_kind != DT_IDENT_AGG)
2787 2828                          attr = dt_ident_cook(dnp, idp, NULL);
2788 2829                  else {
2789 2830                          dt_node_type_assign(dnp,
2790      -                            DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
     2831 +                            DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE);
2791 2832                          attr = idp->di_attr;
2792 2833                  }
2793 2834  
2794 2835                  free(dnp->dn_string);
2795 2836                  dnp->dn_string = NULL;
2796 2837                  dnp->dn_kind = dnkind;
2797 2838                  dnp->dn_ident = idp;
2798 2839                  dnp->dn_flags |= DT_NF_LVALUE | DT_NF_WRITABLE;
2799 2840  
2800 2841                  dt_node_attr_assign(dnp, attr);
↓ open down ↓ 82 lines elided ↑ open up ↑
2883 2924          if (cp->dn_kind == DT_NODE_IDENT && (idflags & DT_IDFLG_MOD))
2884 2925                  dt_xcook_ident(cp, dtp->dt_globals, DT_IDENT_SCALAR, B_TRUE);
2885 2926  
2886 2927          cp = dnp->dn_child = dt_node_cook(cp, 0); /* don't set idflags yet */
2887 2928  
2888 2929          if (cp->dn_kind == DT_NODE_VAR && dt_ident_unref(cp->dn_ident)) {
2889 2930                  if (dt_type_lookup("int64_t", &dtt) != 0)
2890 2931                          xyerror(D_TYPE_ERR, "failed to lookup int64_t\n");
2891 2932  
2892 2933                  dt_ident_type_assign(cp->dn_ident, dtt.dtt_ctfp, dtt.dtt_type);
2893      -                dt_node_type_assign(cp, dtt.dtt_ctfp, dtt.dtt_type);
     2934 +                dt_node_type_assign(cp, dtt.dtt_ctfp, dtt.dtt_type,
     2935 +                    dtt.dtt_flags);
2894 2936          }
2895 2937  
2896 2938          if (cp->dn_kind == DT_NODE_VAR)
2897 2939                  cp->dn_ident->di_flags |= idflags;
2898 2940  
2899 2941          switch (dnp->dn_op) {
2900 2942          case DT_TOK_DEREF:
2901 2943                  /*
2902 2944                   * If the deref operator is applied to a translated pointer,
2903 2945                   * we set our output type to the output of the translation.
2904 2946                   */
2905 2947                  if ((idp = dt_node_resolve(cp, DT_IDENT_XLPTR)) != NULL) {
2906 2948                          dt_xlator_t *dxp = idp->di_data;
2907 2949  
2908 2950                          dnp->dn_ident = &dxp->dx_souid;
2909 2951                          dt_node_type_assign(dnp,
2910      -                            dnp->dn_ident->di_ctfp, dnp->dn_ident->di_type);
     2952 +                            dnp->dn_ident->di_ctfp, dnp->dn_ident->di_type,
     2953 +                            cp->dn_flags & DT_NF_USERLAND);
2911 2954                          break;
2912 2955                  }
2913 2956  
2914 2957                  type = ctf_type_resolve(cp->dn_ctfp, cp->dn_type);
2915 2958                  kind = ctf_type_kind(cp->dn_ctfp, type);
2916 2959  
2917 2960                  if (kind == CTF_K_ARRAY) {
2918 2961                          if (ctf_array_info(cp->dn_ctfp, type, &r) != 0) {
2919 2962                                  dtp->dt_ctferr = ctf_errno(cp->dn_ctfp);
2920 2963                                  longjmp(yypcb->pcb_jmpbuf, EDT_CTF);
2921 2964                          } else
2922 2965                                  type = r.ctr_contents;
2923 2966                  } else if (kind == CTF_K_POINTER) {
2924 2967                          type = ctf_type_reference(cp->dn_ctfp, type);
2925 2968                  } else {
2926 2969                          xyerror(D_DEREF_NONPTR,
2927 2970                              "cannot dereference non-pointer type\n");
2928 2971                  }
2929 2972  
2930      -                dt_node_type_assign(dnp, cp->dn_ctfp, type);
     2973 +                dt_node_type_assign(dnp, cp->dn_ctfp, type,
     2974 +                    cp->dn_flags & DT_NF_USERLAND);
2931 2975                  base = ctf_type_resolve(cp->dn_ctfp, type);
2932 2976                  kind = ctf_type_kind(cp->dn_ctfp, base);
2933 2977  
2934 2978                  if (kind == CTF_K_INTEGER && ctf_type_encoding(cp->dn_ctfp,
2935 2979                      base, &e) == 0 && IS_VOID(e)) {
2936 2980                          xyerror(D_DEREF_VOID,
2937 2981                              "cannot dereference pointer to void\n");
2938 2982                  }
2939 2983  
2940 2984                  if (kind == CTF_K_FUNCTION) {
↓ open down ↓ 36 lines elided ↑ open up ↑
2977 3021                              "integral type\n", opstr(dnp->dn_op));
2978 3022                  }
2979 3023                  dt_node_type_propagate(cp, dnp); /* see K&R[A7.4.4-6] */
2980 3024                  break;
2981 3025  
2982 3026          case DT_TOK_LNEG:
2983 3027                  if (!dt_node_is_scalar(cp)) {
2984 3028                          xyerror(D_OP_SCALAR, "operator %s requires an operand "
2985 3029                              "of scalar type\n", opstr(dnp->dn_op));
2986 3030                  }
2987      -                dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     3031 +                dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp),
     3032 +                    B_FALSE);
2988 3033                  break;
2989 3034  
2990 3035          case DT_TOK_ADDROF:
2991 3036                  if (cp->dn_kind == DT_NODE_VAR || cp->dn_kind == DT_NODE_AGG) {
2992 3037                          xyerror(D_ADDROF_VAR,
2993 3038                              "cannot take address of dynamic variable\n");
2994 3039                  }
2995 3040  
2996 3041                  if (dt_node_is_dynamic(cp)) {
2997 3042                          xyerror(D_ADDROF_VAR,
↓ open down ↓ 12 lines elided ↑ open up ↑
3010 3055  
3011 3056                  dtt.dtt_object = NULL;
3012 3057                  dtt.dtt_ctfp = cp->dn_ctfp;
3013 3058                  dtt.dtt_type = cp->dn_type;
3014 3059  
3015 3060                  if (dt_type_pointer(&dtt) == -1) {
3016 3061                          xyerror(D_TYPE_ERR, "cannot find type for \"&\": %s*\n",
3017 3062                              dt_node_type_name(cp, n, sizeof (n)));
3018 3063                  }
3019 3064  
3020      -                dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
3021      -
3022      -                if (cp->dn_flags & DT_NF_USERLAND)
3023      -                        dnp->dn_flags |= DT_NF_USERLAND;
     3065 +                dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type,
     3066 +                    cp->dn_flags & DT_NF_USERLAND);
3024 3067                  break;
3025 3068  
3026 3069          case DT_TOK_SIZEOF:
3027 3070                  if (cp->dn_flags & DT_NF_BITFIELD) {
3028 3071                          xyerror(D_SIZEOF_BITFIELD,
3029 3072                              "cannot apply sizeof to a bit-field\n");
3030 3073                  }
3031 3074  
3032 3075                  if (dt_node_sizeof(cp) == 0) {
3033 3076                          xyerror(D_SIZEOF_TYPE, "cannot apply sizeof to an "
3034 3077                              "operand of unknown size\n");
3035 3078                  }
3036 3079  
3037 3080                  dt_node_type_assign(dnp, dtp->dt_ddefs->dm_ctfp,
3038      -                    ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"));
     3081 +                    ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"),
     3082 +                    B_FALSE);
3039 3083                  break;
3040 3084  
3041 3085          case DT_TOK_STRINGOF:
3042 3086                  if (!dt_node_is_scalar(cp) && !dt_node_is_pointer(cp) &&
3043 3087                      !dt_node_is_strcompat(cp)) {
3044 3088                          xyerror(D_STRINGOF_TYPE,
3045 3089                              "cannot apply stringof to a value of type %s\n",
3046 3090                              dt_node_type_name(cp, n, sizeof (n)));
3047 3091                  }
3048      -                dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp));
     3092 +                dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp),
     3093 +                    cp->dn_flags & DT_NF_USERLAND);
3049 3094                  break;
3050 3095  
3051 3096          case DT_TOK_PREINC:
3052 3097          case DT_TOK_POSTINC:
3053 3098          case DT_TOK_PREDEC:
3054 3099          case DT_TOK_POSTDEC:
3055 3100                  if (dt_node_is_scalar(cp) == 0) {
3056 3101                          xyerror(D_OP_SCALAR, "operator %s requires operand of "
3057 3102                              "scalar type\n", opstr(dnp->dn_op));
3058 3103                  }
↓ open down ↓ 172 lines elided ↑ open up ↑
3231 3276          case DT_TOK_LXOR:
3232 3277          case DT_TOK_LOR:
3233 3278                  lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3234 3279                  rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3235 3280  
3236 3281                  if (!dt_node_is_scalar(lp) || !dt_node_is_scalar(rp)) {
3237 3282                          xyerror(D_OP_SCALAR, "operator %s requires operands "
3238 3283                              "of scalar type\n", opstr(op));
3239 3284                  }
3240 3285  
3241      -                dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     3286 +                dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp),
     3287 +                    B_FALSE);
3242 3288                  dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3243 3289                  break;
3244 3290  
3245 3291          case DT_TOK_LT:
3246 3292          case DT_TOK_LE:
3247 3293          case DT_TOK_GT:
3248 3294          case DT_TOK_GE:
3249 3295          case DT_TOK_EQU:
3250 3296          case DT_TOK_NEQ:
3251 3297                  /*
↓ open down ↓ 23 lines elided ↑ open up ↑
3275 3321                                      dt_idkind_name(idp->di_kind));
3276 3322                          }
3277 3323  
3278 3324                          free(rp->dn_string);
3279 3325                          rp->dn_string = NULL;
3280 3326                          rp->dn_kind = DT_NODE_INT;
3281 3327                          rp->dn_flags |= DT_NF_COOKED;
3282 3328                          rp->dn_op = DT_TOK_INT;
3283 3329                          rp->dn_value = (intmax_t)val;
3284 3330  
3285      -                        dt_node_type_assign(rp, lp->dn_ctfp, lp->dn_type);
     3331 +                        dt_node_type_assign(rp, lp->dn_ctfp, lp->dn_type,
     3332 +                            B_FALSE);
3286 3333                          dt_node_attr_assign(rp, _dtrace_symattr);
3287 3334                  }
3288 3335  
3289 3336                  rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3290 3337  
3291 3338                  /*
3292 3339                   * The rules for type checking for the relational operators are
3293 3340                   * described in the ANSI-C spec (see K&R[A7.9-10]).  We perform
3294 3341                   * the various tests in order from least to most expensive.  We
3295 3342                   * also allow derived strings to be compared as a first-class
↓ open down ↓ 11 lines elided ↑ open up ↑
3307 3354                  else if (dt_node_is_strcompat(lp) && dt_node_is_strcompat(rp) &&
3308 3355                      (dt_node_is_string(lp) || dt_node_is_string(rp)))
3309 3356                          /*EMPTY*/;
3310 3357                  else if (dt_node_is_ptrcompat(lp, rp, NULL, NULL) == 0) {
3311 3358                          xyerror(D_OP_INCOMPAT, "operands have "
3312 3359                              "incompatible types: \"%s\" %s \"%s\"\n",
3313 3360                              dt_node_type_name(lp, n1, sizeof (n1)), opstr(op),
3314 3361                              dt_node_type_name(rp, n2, sizeof (n2)));
3315 3362                  }
3316 3363  
3317      -                dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
     3364 +                dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp),
     3365 +                    B_FALSE);
3318 3366                  dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3319 3367                  break;
3320 3368  
3321 3369          case DT_TOK_ADD:
3322 3370          case DT_TOK_SUB: {
3323 3371                  /*
3324 3372                   * The rules for type checking for the additive operators are
3325 3373                   * described in the ANSI-C spec (see K&R[A7.7]).  Pointers and
3326 3374                   * integers may be manipulated according to specific rules.  In
3327 3375                   * these cases D permits strings to be treated as pointers.
↓ open down ↓ 27 lines elided ↑ open up ↑
3355 3403                          ctfp = dtp->dt_ddefs->dm_ctfp;
3356 3404                          type = ctf_lookup_by_name(ctfp, "ptrdiff_t");
3357 3405                          uref = 0;
3358 3406                  } else {
3359 3407                          xyerror(D_OP_INCOMPAT, "operands have incompatible "
3360 3408                              "types: \"%s\" %s \"%s\"\n",
3361 3409                              dt_node_type_name(lp, n1, sizeof (n1)), opstr(op),
3362 3410                              dt_node_type_name(rp, n2, sizeof (n2)));
3363 3411                  }
3364 3412  
3365      -                dt_node_type_assign(dnp, ctfp, type);
     3413 +                dt_node_type_assign(dnp, ctfp, type, B_FALSE);
3366 3414                  dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3367 3415  
3368 3416                  if (uref)
3369 3417                          dnp->dn_flags |= DT_NF_USERLAND;
3370 3418                  break;
3371 3419          }
3372 3420  
3373 3421          case DT_TOK_OR_EQ:
3374 3422          case DT_TOK_XOR_EQ:
3375 3423          case DT_TOK_AND_EQ:
↓ open down ↓ 120 lines elided ↑ open up ↑
3496 3544                          uref = rp->dn_flags & DT_NF_USERLAND;
3497 3545                  }
3498 3546  
3499 3547                  /*
3500 3548                   * If the left-hand side of an assignment statement is a virgin
3501 3549                   * variable created by this compilation pass, reset the type of
3502 3550                   * this variable to the type of the right-hand side.
3503 3551                   */
3504 3552                  if (lp->dn_kind == DT_NODE_VAR &&
3505 3553                      dt_ident_unref(lp->dn_ident)) {
3506      -                        dt_node_type_assign(lp, ctfp, type);
     3554 +                        dt_node_type_assign(lp, ctfp, type, B_FALSE);
3507 3555                          dt_ident_type_assign(lp->dn_ident, ctfp, type);
3508 3556  
3509 3557                          if (uref) {
3510 3558                                  lp->dn_flags |= DT_NF_USERLAND;
3511 3559                                  lp->dn_ident->di_flags |= DT_IDFLG_USER;
3512 3560                          }
3513 3561                  }
3514 3562  
3515 3563                  if (lp->dn_kind == DT_NODE_VAR)
3516 3564                          lp->dn_ident->di_flags |= DT_IDFLG_MOD;
↓ open down ↓ 193 lines elided ↑ open up ↑
3710 3758  
3711 3759                  if (ctf_member_info(ctfp, type, rp->dn_string, &m) == CTF_ERR) {
3712 3760                          xyerror(D_TYPE_MEMBER,
3713 3761                              "%s is not a member of %s\n", rp->dn_string,
3714 3762                              ctf_type_name(ctfp, type, n1, sizeof (n1)));
3715 3763                  }
3716 3764  
3717 3765                  type = ctf_type_resolve(ctfp, m.ctm_type);
3718 3766                  kind = ctf_type_kind(ctfp, type);
3719 3767  
3720      -                dt_node_type_assign(dnp, ctfp, m.ctm_type);
     3768 +                dt_node_type_assign(dnp, ctfp, m.ctm_type, B_FALSE);
3721 3769                  dt_node_attr_assign(dnp, lp->dn_attr);
3722 3770  
3723 3771                  if (op == DT_TOK_PTR && (kind != CTF_K_ARRAY ||
3724 3772                      dt_node_is_string(dnp)))
3725 3773                          dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3726 3774  
3727 3775                  if (op == DT_TOK_DOT && (lp->dn_flags & DT_NF_LVALUE) &&
3728 3776                      (kind != CTF_K_ARRAY || dt_node_is_string(dnp)))
3729 3777                          dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3730 3778  
↓ open down ↓ 105 lines elided ↑ open up ↑
3836 3884                  dxp = dt_xlator_lookup(dtp, rp, lp, DT_XLATE_FUZZY);
3837 3885  
3838 3886                  if (dxp == NULL) {
3839 3887                          xyerror(D_XLATE_NONE,
3840 3888                              "cannot translate from \"%s\" to \"%s\"\n",
3841 3889                              dt_node_type_name(rp, n1, sizeof (n1)),
3842 3890                              dt_node_type_name(lp, n2, sizeof (n2)));
3843 3891                  }
3844 3892  
3845 3893                  dnp->dn_ident = dt_xlator_ident(dxp, lp->dn_ctfp, lp->dn_type);
3846      -                dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
     3894 +                dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp),
     3895 +                    B_FALSE);
3847 3896                  dt_node_attr_assign(dnp,
3848 3897                      dt_attr_min(rp->dn_attr, dnp->dn_ident->di_attr));
3849 3898                  break;
3850 3899          }
3851 3900  
3852 3901          case DT_TOK_LPAR: {
3853 3902                  ctf_id_t ltype, rtype;
3854 3903                  uint_t lkind, rkind;
3855 3904  
3856 3905                  assert(lp->dn_kind == DT_NODE_TYPE);
↓ open down ↓ 144 lines elided ↑ open up ↑
4001 4050          } else if (dt_node_is_ptrcompat(lp, rp, &ctfp, &type) == 0) {
4002 4051                  xyerror(D_OP_INCOMPAT,
4003 4052                      "operator ?: operands must have compatible types\n");
4004 4053          }
4005 4054  
4006 4055          if (dt_node_is_actfunc(lp) || dt_node_is_actfunc(rp)) {
4007 4056                  xyerror(D_OP_ACT, "action cannot be "
4008 4057                      "used in a conditional context\n");
4009 4058          }
4010 4059  
4011      -        dt_node_type_assign(dnp, ctfp, type);
     4060 +        dt_node_type_assign(dnp, ctfp, type, B_FALSE);
4012 4061          dt_node_attr_assign(dnp, dt_attr_min(dnp->dn_expr->dn_attr,
4013 4062              dt_attr_min(lp->dn_attr, rp->dn_attr)));
4014 4063  
4015 4064          return (dnp);
4016 4065  }
4017 4066  
4018 4067  static dt_node_t *
4019 4068  dt_cook_statement(dt_node_t *dnp, uint_t idflags)
4020 4069  {
4021 4070          dnp->dn_expr = dt_node_cook(dnp->dn_expr, idflags);
↓ open down ↓ 12 lines elided ↑ open up ↑
4034 4083  static dt_node_t *
4035 4084  dt_cook_aggregation(dt_node_t *dnp, uint_t idflags)
4036 4085  {
4037 4086          dtrace_hdl_t *dtp = yypcb->pcb_hdl;
4038 4087  
4039 4088          if (dnp->dn_aggfun != NULL) {
4040 4089                  dnp->dn_aggfun = dt_node_cook(dnp->dn_aggfun, DT_IDFLG_REF);
4041 4090                  dt_node_attr_assign(dnp, dt_ident_cook(dnp,
4042 4091                      dnp->dn_ident, &dnp->dn_aggtup));
4043 4092          } else {
4044      -                dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
     4093 +                dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp),
     4094 +                    B_FALSE);
4045 4095                  dt_node_attr_assign(dnp, dnp->dn_ident->di_attr);
4046 4096          }
4047 4097  
4048 4098          return (dnp);
4049 4099  }
4050 4100  
4051 4101  /*
4052 4102   * Since D permits new variable identifiers to be instantiated in any program
4053 4103   * expression, we may need to cook a clause's predicate either before or after
4054 4104   * the action list depending on the program code in question.  Consider:
↓ open down ↓ 181 lines elided ↑ open up ↑
4236 4286          for (mnp = dnp->dn_members; mnp != NULL; mnp = mnp->dn_list) {
4237 4287                  if (ctf_member_info(dxp->dx_dst_ctfp, dxp->dx_dst_type,
4238 4288                      mnp->dn_membname, &ctm) == CTF_ERR) {
4239 4289                          xyerror(D_XLATE_MEMB,
4240 4290                              "translator member %s is not a member of %s\n",
4241 4291                              mnp->dn_membname, ctf_type_name(dxp->dx_dst_ctfp,
4242 4292                              dxp->dx_dst_type, n1, sizeof (n1)));
4243 4293                  }
4244 4294  
4245 4295                  (void) dt_node_cook(mnp, DT_IDFLG_REF);
4246      -                dt_node_type_assign(mnp, dxp->dx_dst_ctfp, ctm.ctm_type);
     4296 +                dt_node_type_assign(mnp, dxp->dx_dst_ctfp, ctm.ctm_type,
     4297 +                    B_FALSE);
4247 4298                  attr = dt_attr_min(attr, mnp->dn_attr);
4248 4299  
4249 4300                  if (dt_node_is_argcompat(mnp, mnp->dn_membexpr) == 0) {
4250 4301                          xyerror(D_XLATE_INCOMPAT,
4251 4302                              "translator member %s definition uses "
4252 4303                              "incompatible types: \"%s\" = \"%s\"\n",
4253 4304                              mnp->dn_membname,
4254 4305                              dt_node_type_name(mnp, n1, sizeof (n1)),
4255 4306                              dt_node_type_name(mnp->dn_membexpr,
4256 4307                              n2, sizeof (n2)));
4257 4308                  }
4258 4309          }
4259 4310  
4260 4311          dt_idstack_pop(&yypcb->pcb_globals, dxp->dx_locals);
4261 4312  
4262 4313          dxp->dx_souid.di_attr = attr;
4263 4314          dxp->dx_ptrid.di_attr = attr;
4264 4315  
4265      -        dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
     4316 +        dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE);
4266 4317          dt_node_attr_assign(dnp, _dtrace_defattr);
4267 4318  
4268 4319          return (dnp);
4269 4320  }
4270 4321  
4271 4322  static void
4272 4323  dt_node_provider_cmp_argv(dt_provider_t *pvp, dt_node_t *pnp, const char *kind,
4273 4324      uint_t old_argc, dt_node_t *old_argv, uint_t new_argc, dt_node_t *new_argv)
4274 4325  {
4275 4326          dt_probe_t *prp = pnp->dn_ident->di_data;
↓ open down ↓ 272 lines elided ↑ open up ↑
4548 4599          if (dnp->dn_ctfp == DT_STR_CTFP(dtp) &&
4549 4600              dnp->dn_type == DT_STR_TYPE(dtp)) {
4550 4601                  tp->dtdt_kind = DIF_TYPE_STRING;
4551 4602                  tp->dtdt_ckind = CTF_K_UNKNOWN;
4552 4603          } else {
4553 4604                  tp->dtdt_kind = DIF_TYPE_CTF;
4554 4605                  tp->dtdt_ckind = ctf_type_kind(dnp->dn_ctfp,
4555 4606                      ctf_type_resolve(dnp->dn_ctfp, dnp->dn_type));
4556 4607          }
4557 4608  
4558      -        tp->dtdt_flags = (dnp->dn_flags & DT_NF_REF) ? DIF_TF_BYREF : 0;
     4609 +        tp->dtdt_flags = (dnp->dn_flags & DT_NF_REF) ?
     4610 +            (dnp->dn_flags & DT_NF_USERLAND) ? DIF_TF_BYUREF :
     4611 +            DIF_TF_BYREF : 0;
4559 4612          tp->dtdt_pad = 0;
4560 4613          tp->dtdt_size = ctf_type_size(dnp->dn_ctfp, dnp->dn_type);
4561 4614  }
4562 4615  
4563 4616  void
4564 4617  dt_node_printr(dt_node_t *dnp, FILE *fp, int depth)
4565 4618  {
4566 4619          char n[DT_TYPE_NAMELEN], buf[BUFSIZ], a[8];
4567 4620          const dtrace_syminfo_t *dts;
4568 4621          const dt_idnode_t *inp;
↓ open down ↓ 358 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX