Print this page
9312 ctf: be less clever about skipping 'extern' variables declarations
9864 DWARF->CTF enum conversion needs to be careful of sign

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/ctf/cvt/dwarf.c
          +++ new/usr/src/tools/ctf/cvt/dwarf.c
↓ open down ↓ 855 lines elided ↑ open up ↑
 856  856  
 857  857                          if (die_tag(dw, mem) != DW_TAG_enumerator) {
 858  858                                  /* Nested type declaration */
 859  859                                  die_create_one(dw, mem);
 860  860                                  continue;
 861  861                          }
 862  862  
 863  863                          el = xcalloc(sizeof (elist_t));
 864  864                          el->el_name = die_name(dw, mem);
 865  865  
 866      -                        if (die_signed(dw, mem, DW_AT_const_value, &sval, 0)) {
 867      -                                el->el_number = sval;
 868      -                        } else if (die_unsigned(dw, mem, DW_AT_const_value,
      866 +                        /*
      867 +                         * We have to be careful here: newer GCCs generate DWARF
      868 +                         * where an unsigned value will happily pass
      869 +                         * die_signed().  Since negative values will fail
      870 +                         * die_unsigned(), we try that first to make sure we get
      871 +                         * the right value.
      872 +                         */
      873 +                        if (die_unsigned(dw, mem, DW_AT_const_value,
 869  874                              &uval, 0)) {
 870  875                                  el->el_number = uval;
      876 +                        } else if (die_signed(dw, mem, DW_AT_const_value,
      877 +                            &sval, 0)) {
      878 +                                el->el_number = sval;
 871  879                          } else {
 872  880                                  terminate("die %llu: enum %llu: member without "
 873  881                                      "value\n", off, die_off(dw, mem));
 874  882                          }
 875  883  
 876  884                          debug(3, "die %llu: enum %llu: created %s = %d\n", off,
 877  885                              die_off(dw, mem), el->el_name, el->el_number);
 878  886  
 879  887                          *elastp = el;
 880  888                          elastp = &el->el_next;
↓ open down ↓ 755 lines elided ↑ open up ↑
1636 1644  
1637 1645  /*ARGSUSED3*/
1638 1646  static void
1639 1647  die_variable_create(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp)
1640 1648  {
1641 1649          iidesc_t *ii;
1642 1650          char *name;
1643 1651  
1644 1652          debug(3, "die %llu: creating object definition\n", off);
1645 1653  
1646      -        if (die_isdecl(dw, die) || (name = die_name(dw, die)) == NULL)
1647      -                return; /* skip prototypes and nameless objects */
     1654 +        /* Skip "Non-Defining Declarations" */
     1655 +        if (die_isdecl(dw, die))
     1656 +                return;
1648 1657  
     1658 +        /*
     1659 +         * If we find a DIE of "Declarations Completing Non-Defining
     1660 +         * Declarations", we will use the referenced type's DIE.  This isn't
     1661 +         * quite correct, e.g. DW_AT_decl_line will be the forward declaration
     1662 +         * not this site.  It's sufficient for what we need, however: in
     1663 +         * particular, we should find DW_AT_external as needed there.
     1664 +         */
     1665 +        if (die_attr(dw, die, DW_AT_specification, 0) != NULL) {
     1666 +                Dwarf_Die sdie;
     1667 +                Dwarf_Off soff;
     1668 +
     1669 +                soff = die_attr_ref(dw, die, DW_AT_specification);
     1670 +
     1671 +                if (dwarf_offdie(dw->dw_dw, soff,
     1672 +                    &sdie, &dw->dw_err) != DW_DLV_OK) {
     1673 +                        terminate("dwarf_offdie(%llu) failed: %s\n",
     1674 +                            soff, dwarf_errmsg(dw->dw_err));
     1675 +                }
     1676 +
     1677 +                die = sdie;
     1678 +        }
     1679 +
     1680 +        if ((name = die_name(dw, die)) == NULL)
     1681 +                return;
     1682 +
1649 1683          ii = xcalloc(sizeof (iidesc_t));
1650 1684          ii->ii_type = die_isglobal(dw, die) ? II_GVAR : II_SVAR;
1651 1685          ii->ii_name = name;
1652 1686          ii->ii_dtype = die_lookup_pass1(dw, die, DW_AT_type);
1653 1687          if (ii->ii_type == II_SVAR)
1654 1688                  ii->ii_owner = xstrdup(dw->dw_cuname);
1655 1689  
1656 1690          iidesc_add(dw->dw_td->td_iihash, ii);
1657 1691  }
1658 1692  
↓ open down ↓ 335 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX