Print this page
12259 CTF shouldn't assume enum size

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libctf/common/ctf_dwarf.c
          +++ new/usr/src/lib/libctf/common/ctf_dwarf.c
↓ open down ↓ 20 lines elided ↑ open up ↑
  21   21  /*
  22   22   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  /*
  26   26   * Copyright 2012 Jason King.  All rights reserved.
  27   27   * Use is subject to license terms.
  28   28   */
  29   29  
  30   30  /*
  31      - * Copyright 2019, Joyent, Inc.
       31 + * Copyright 2020 Joyent, Inc.
  32   32   */
  33   33  
  34   34  /*
  35   35   * CTF DWARF conversion theory.
  36   36   *
  37   37   * DWARF data contains a series of compilation units. Each compilation unit
  38   38   * generally refers to an object file or what once was, in the case of linked
  39   39   * binaries and shared objects. Each compilation unit has a series of what DWARF
  40   40   * calls a DIE (Debugging Information Entry). The set of entries that we care
  41   41   * about have type information stored in a series of attributes. Each DIE also
↓ open down ↓ 1164 lines elided ↑ open up ↑
1206 1206  
1207 1207          return (0);
1208 1208  }
1209 1209  
1210 1210  static int
1211 1211  ctf_dwarf_fixup_sou(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t base, boolean_t add)
1212 1212  {
1213 1213          int ret, kind;
1214 1214          Dwarf_Die child, memb;
1215 1215          Dwarf_Unsigned size;
1216      -        ulong_t nsz;
1217 1216  
1218 1217          kind = ctf_type_kind(cup->cu_ctfp, base);
1219 1218          VERIFY(kind != CTF_ERR);
1220 1219          VERIFY(kind == CTF_K_STRUCT || kind == CTF_K_UNION);
1221 1220  
1222 1221          /*
1223 1222           * Members are in children. However, gcc also allows empty ones.
1224 1223           */
1225 1224          if ((ret = ctf_dwarf_child(cup, die, &child)) != 0)
1226 1225                  return (ret);
↓ open down ↓ 72 lines elided ↑ open up ↑
1299 1298          /*
1300 1299           * If we're not adding members, then we don't know the final size of the
1301 1300           * structure, so end here.
1302 1301           */
1303 1302          if (add == B_FALSE)
1304 1303                  return (0);
1305 1304  
1306 1305          /* Finally set the size of the structure to the actual byte size */
1307 1306          if ((ret = ctf_dwarf_unsigned(cup, die, DW_AT_byte_size, &size)) != 0)
1308 1307                  return (ret);
1309      -        nsz = size;
1310      -        if ((ctf_set_size(cup->cu_ctfp, base, nsz)) == CTF_ERR) {
     1308 +        if ((ctf_set_size(cup->cu_ctfp, base, size)) == CTF_ERR) {
1311 1309                  int e = ctf_errno(cup->cu_ctfp);
1312 1310                  (void) snprintf(cup->cu_errbuf, cup->cu_errlen,
1313 1311                      "failed to set type size for %d to 0x%x: %s", base,
1314 1312                      (uint32_t)size, ctf_errmsg(e));
1315 1313                  return (ECTF_CONVBKERR);
1316 1314          }
1317 1315  
1318 1316          return (0);
1319 1317  }
1320 1318  
↓ open down ↓ 286 lines elided ↑ open up ↑
1607 1605          if ((*idp = ctf_add_reftype(cup->cu_ctfp, isroot, name, id, kind)) ==
1608 1606              CTF_ERR) {
1609 1607                  ctf_free(name, namelen);
1610 1608                  return (ctf_errno(cup->cu_ctfp));
1611 1609          }
1612 1610  
1613 1611          ctf_free(name, namelen);
1614 1612          return (ctf_dwmap_add(cup, *idp, die, B_FALSE));
1615 1613  }
1616 1614  
     1615 +/*
     1616 + * Get the size of the type of a particular die. Note that this is a simple
     1617 + * version that doesn't attempt to traverse further than expecting a single
     1618 + * sized type reference (so no qualifiers etc.). Nor does it attempt to do as
     1619 + * much as ctf_type_size() - which we cannot use here as that doesn't look up
     1620 + * dynamic types, and we don't yet want to do a ctf_update().
     1621 + */
1617 1622  static int
1618      -ctf_dwarf_create_enum(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t *idp, int isroot)
     1623 +ctf_dwarf_get_type_size(ctf_cu_t *cup, Dwarf_Die die, size_t *sizep)
1619 1624  {
     1625 +        const ctf_type_t *t;
     1626 +        Dwarf_Die tdie;
     1627 +        ctf_id_t tid;
1620 1628          int ret;
1621      -        ctf_id_t id;
     1629 +
     1630 +        if ((ret = ctf_dwarf_refdie(cup, die, DW_AT_type, &tdie)) != 0)
     1631 +                return (ret);
     1632 +
     1633 +        if ((ret = ctf_dwarf_convert_type(cup, tdie, &tid,
     1634 +            CTF_ADD_NONROOT)) != 0)
     1635 +                return (ret);
     1636 +
     1637 +        if ((t = ctf_dyn_lookup_by_id(cup->cu_ctfp, tid)) == NULL)
     1638 +                return (ENOENT);
     1639 +
     1640 +        *sizep = ctf_get_ctt_size(cup->cu_ctfp, t, NULL, NULL);
     1641 +        return (0);
     1642 +}
     1643 +
     1644 +static int
     1645 +ctf_dwarf_create_enum(ctf_cu_t *cup, Dwarf_Die die, ctf_id_t *idp, int isroot)
     1646 +{
     1647 +        size_t size = 0;
1622 1648          Dwarf_Die child;
     1649 +        ctf_id_t id;
1623 1650          char *name;
     1651 +        int ret;
1624 1652  
1625 1653          if ((ret = ctf_dwarf_string(cup, die, DW_AT_name, &name)) != 0 &&
1626 1654              ret != ENOENT)
1627 1655                  return (ret);
1628 1656          if (ret == ENOENT)
1629 1657                  name = NULL;
1630      -        id = ctf_add_enum(cup->cu_ctfp, isroot, name);
     1658 +
     1659 +        (void) ctf_dwarf_get_type_size(cup, die, &size);
     1660 +
     1661 +        id = ctf_add_enum(cup->cu_ctfp, isroot, name, size);
1631 1662          ctf_dprintf("added enum %s (%d)\n", name, id);
1632 1663          if (name != NULL)
1633 1664                  ctf_free(name, strlen(name) + 1);
1634 1665          if (id == CTF_ERR)
1635 1666                  return (ctf_errno(cup->cu_ctfp));
1636 1667          *idp = id;
1637 1668          if ((ret = ctf_dwmap_add(cup, id, die, B_FALSE)) != 0)
1638 1669                  return (ret);
1639 1670  
1640 1671          if ((ret = ctf_dwarf_child(cup, die, &child)) != 0) {
↓ open down ↓ 1543 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX