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


 846         tdp->t_type = ENUM;
 847 
 848         (void) die_unsigned(dw, die, DW_AT_byte_size, &uval, DW_ATTR_REQ);
 849         tdp->t_size = uval;
 850 
 851         if ((mem = die_child(dw, die)) != NULL) {
 852                 elist_t **elastp = &tdp->t_emem;
 853 
 854                 do {
 855                         elist_t *el;
 856 
 857                         if (die_tag(dw, mem) != DW_TAG_enumerator) {
 858                                 /* Nested type declaration */
 859                                 die_create_one(dw, mem);
 860                                 continue;
 861                         }
 862 
 863                         el = xcalloc(sizeof (elist_t));
 864                         el->el_name = die_name(dw, mem);
 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,





 869                             &uval, 0)) {
 870                                 el->el_number = uval;



 871                         } else {
 872                                 terminate("die %llu: enum %llu: member without "
 873                                     "value\n", off, die_off(dw, mem));
 874                         }
 875 
 876                         debug(3, "die %llu: enum %llu: created %s = %d\n", off,
 877                             die_off(dw, mem), el->el_name, el->el_number);
 878 
 879                         *elastp = el;
 880                         elastp = &el->el_next;
 881 
 882                 } while ((mem = die_sibling(dw, mem)) != NULL);
 883 
 884                 hash_add(dw->dw_enumhash, tdp);
 885 
 886                 tdp->t_flags |= TDESC_F_RESOLVED;
 887 
 888                 if (tdp->t_name != NULL) {
 889                         iidesc_t *ii = xcalloc(sizeof (iidesc_t));
 890                         ii->ii_type = II_SOU;


1626                         if (die_tag(dw, arg) != DW_TAG_formal_parameter)
1627                                 continue;
1628 
1629                         ii->ii_args[i++] = die_lookup_pass1(dw, arg,
1630                             DW_AT_type);
1631                 }
1632         }
1633 
1634         iidesc_add(dw->dw_td->td_iihash, ii);
1635 }
1636 
1637 /*ARGSUSED3*/
1638 static void
1639 die_variable_create(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp)
1640 {
1641         iidesc_t *ii;
1642         char *name;
1643 
1644         debug(3, "die %llu: creating object definition\n", off);
1645 
1646         if (die_isdecl(dw, die) || (name = die_name(dw, die)) == NULL)
1647                 return; /* skip prototypes and nameless objects */

1648 

























1649         ii = xcalloc(sizeof (iidesc_t));
1650         ii->ii_type = die_isglobal(dw, die) ? II_GVAR : II_SVAR;
1651         ii->ii_name = name;
1652         ii->ii_dtype = die_lookup_pass1(dw, die, DW_AT_type);
1653         if (ii->ii_type == II_SVAR)
1654                 ii->ii_owner = xstrdup(dw->dw_cuname);
1655 
1656         iidesc_add(dw->dw_td->td_iihash, ii);
1657 }
1658 
1659 /*ARGSUSED2*/
1660 static int
1661 die_fwd_resolve(tdesc_t *fwd, tdesc_t **fwdp, void *private)
1662 {
1663         if (fwd->t_flags & TDESC_F_RESOLVED)
1664                 return (1);
1665 
1666         if (fwd->t_tdesc != NULL) {
1667                 debug(3, "tdp %u: unforwarded %s\n", fwd->t_id,
1668                     tdesc_name(fwd));




 846         tdp->t_type = ENUM;
 847 
 848         (void) die_unsigned(dw, die, DW_AT_byte_size, &uval, DW_ATTR_REQ);
 849         tdp->t_size = uval;
 850 
 851         if ((mem = die_child(dw, die)) != NULL) {
 852                 elist_t **elastp = &tdp->t_emem;
 853 
 854                 do {
 855                         elist_t *el;
 856 
 857                         if (die_tag(dw, mem) != DW_TAG_enumerator) {
 858                                 /* Nested type declaration */
 859                                 die_create_one(dw, mem);
 860                                 continue;
 861                         }
 862 
 863                         el = xcalloc(sizeof (elist_t));
 864                         el->el_name = die_name(dw, mem);
 865 
 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,
 874                             &uval, 0)) {
 875                                 el->el_number = uval;
 876                         } else if (die_signed(dw, mem, DW_AT_const_value,
 877                             &sval, 0)) {
 878                                 el->el_number = sval;
 879                         } else {
 880                                 terminate("die %llu: enum %llu: member without "
 881                                     "value\n", off, die_off(dw, mem));
 882                         }
 883 
 884                         debug(3, "die %llu: enum %llu: created %s = %d\n", off,
 885                             die_off(dw, mem), el->el_name, el->el_number);
 886 
 887                         *elastp = el;
 888                         elastp = &el->el_next;
 889 
 890                 } while ((mem = die_sibling(dw, mem)) != NULL);
 891 
 892                 hash_add(dw->dw_enumhash, tdp);
 893 
 894                 tdp->t_flags |= TDESC_F_RESOLVED;
 895 
 896                 if (tdp->t_name != NULL) {
 897                         iidesc_t *ii = xcalloc(sizeof (iidesc_t));
 898                         ii->ii_type = II_SOU;


1634                         if (die_tag(dw, arg) != DW_TAG_formal_parameter)
1635                                 continue;
1636 
1637                         ii->ii_args[i++] = die_lookup_pass1(dw, arg,
1638                             DW_AT_type);
1639                 }
1640         }
1641 
1642         iidesc_add(dw->dw_td->td_iihash, ii);
1643 }
1644 
1645 /*ARGSUSED3*/
1646 static void
1647 die_variable_create(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp)
1648 {
1649         iidesc_t *ii;
1650         char *name;
1651 
1652         debug(3, "die %llu: creating object definition\n", off);
1653 
1654         /* Skip "Non-Defining Declarations" */
1655         if (die_isdecl(dw, die))
1656                 return;
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 
1683         ii = xcalloc(sizeof (iidesc_t));
1684         ii->ii_type = die_isglobal(dw, die) ? II_GVAR : II_SVAR;
1685         ii->ii_name = name;
1686         ii->ii_dtype = die_lookup_pass1(dw, die, DW_AT_type);
1687         if (ii->ii_type == II_SVAR)
1688                 ii->ii_owner = xstrdup(dw->dw_cuname);
1689 
1690         iidesc_add(dw->dw_td->td_iihash, ii);
1691 }
1692 
1693 /*ARGSUSED2*/
1694 static int
1695 die_fwd_resolve(tdesc_t *fwd, tdesc_t **fwdp, void *private)
1696 {
1697         if (fwd->t_flags & TDESC_F_RESOLVED)
1698                 return (1);
1699 
1700         if (fwd->t_tdesc != NULL) {
1701                 debug(3, "tdp %u: unforwarded %s\n", fwd->t_id,
1702                     tdesc_name(fwd));