Handle bit offset and bit size in base types
[deliverable/binutils-gdb.git] / gdb / dwarf2 / read.c
index 865f9e2118ba26075479eafb1f8bfe24a327c924..977bdb856893b7794d4c32b1b97aef5a157aa9df 100644 (file)
@@ -2120,10 +2120,8 @@ dwarf2_get_section_info (struct objfile *objfile,
 /* A helper function to find the sections for a .dwz file.  */
 
 static void
-locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
+locate_dwz_sections (bfd *abfd, asection *sectp, dwz_file *dwz_file)
 {
-  struct dwz_file *dwz_file = (struct dwz_file *) arg;
-
   /* Note that we only support the standard ELF names, because .dwz
      is ELF-only (at the time of writing).  */
   if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev))
@@ -2246,8 +2244,8 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd)
   std::unique_ptr<struct dwz_file> result
     (new struct dwz_file (std::move (dwz_bfd)));
 
-  bfd_map_over_sections (result->dwz_bfd.get (), locate_dwz_sections,
-                        result.get ());
+  for (asection *sec : gdb_bfd_sections (result->dwz_bfd))
+    locate_dwz_sections (result->dwz_bfd.get (), sec, result.get ());
 
   gdb_bfd_record_inclusion (per_bfd->obfd, result->dwz_bfd.get ());
   per_bfd->dwz_file = std::move (result);
@@ -9499,7 +9497,7 @@ alloc_rust_variant (struct obstack *obstack, struct type *type,
   part->is_unsigned
     = (discriminant_index == -1
        ? false
-       : TYPE_UNSIGNED (type->field (discriminant_index).type ()));
+       : type->field (discriminant_index).type ()->is_unsigned ());
   part->variants = gdb::array_view<variant> (variants, n_variants);
 
   void *storage = obstack_alloc (obstack, sizeof (gdb::array_view<variant_part>));
@@ -9857,23 +9855,24 @@ compute_compunit_symtab_includes (dwarf2_per_cu_data *per_cu,
     {
       int len;
       std::vector<compunit_symtab *> result_symtabs;
-      htab_t all_children, all_type_symtabs;
       compunit_symtab *cust = per_objfile->get_symtab (per_cu);
 
       /* If we don't have a symtab, we can just skip this case.  */
       if (cust == NULL)
        return;
 
-      all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
-                                       NULL, xcalloc, xfree);
-      all_type_symtabs = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
-                                           NULL, xcalloc, xfree);
+      htab_up all_children (htab_create_alloc (1, htab_hash_pointer,
+                                              htab_eq_pointer,
+                                              NULL, xcalloc, xfree));
+      htab_up all_type_symtabs (htab_create_alloc (1, htab_hash_pointer,
+                                                  htab_eq_pointer,
+                                                  NULL, xcalloc, xfree));
 
       for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
        {
-         recursively_compute_inclusions (&result_symtabs, all_children,
-                                         all_type_symtabs, ptr, per_objfile,
-                                         cust);
+         recursively_compute_inclusions (&result_symtabs, all_children.get (),
+                                         all_type_symtabs.get (), ptr,
+                                         per_objfile, cust);
        }
 
       /* Now we have a transitive closure of all the included symtabs.  */
@@ -9884,9 +9883,6 @@ compute_compunit_symtab_includes (dwarf2_per_cu_data *per_cu,
       memcpy (cust->includes, result_symtabs.data (),
              len * sizeof (compunit_symtab *));
       cust->includes[len] = NULL;
-
-      htab_delete (all_children);
-      htab_delete (all_type_symtabs);
     }
 }
 
@@ -10502,7 +10498,7 @@ dwarf2_compute_name (const char *name,
                                           &cu->comp_unit_obstack, cu,
                                           &value, &bytes, &baton);
 
-                 if (TYPE_NOSIGN (type))
+                 if (type->has_no_signedness ())
                    /* GDB prints characters as NUMBER 'CHAR'.  If that's
                       changed, this can use value_print instead.  */
                    c_printchar (value, type, &buf);
@@ -10635,16 +10631,10 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
   if (mangled != NULL)
     {
 
-      if (language_def (cu->language)->la_store_sym_names_in_linkage_form_p)
+      if (language_def (cu->language)->store_sym_names_in_linkage_form_p ())
        {
          /* Do nothing (do not demangle the symbol name).  */
        }
-      else if (cu->language == language_go)
-       {
-         /* This is a lie, but we already lie to the caller new_symbol.
-            new_symbol assumes we return the mangled name.
-            This just undoes that lie until things are cleaned up.  */
-       }
       else
        {
          /* Use DMGL_RET_DROP for C++ template functions to suppress
@@ -11923,9 +11913,9 @@ create_dwp_hash_table (dwarf2_per_objfile *per_objfile,
 
 /* Update SECTIONS with the data from SECTP.
 
-   This function is like the other "locate" section routines that are
-   passed to bfd_map_over_sections, but in this context the sections to
-   read comes from the DWP V1 hash table, not the full ELF section table.
+   This function is like the other "locate" section routines, but in
+   this context the sections to read comes from the DWP V1 hash table,
+   not the full ELF section table.
 
    The result is non-zero for success, or zero if an error was found.  */
 
@@ -12738,9 +12728,9 @@ open_dwo_file (dwarf2_per_objfile *per_objfile,
    size of each of the DWO debugging sections we are interested in.  */
 
 static void
-dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr)
+dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp,
+                           dwo_sections *dwo_sections)
 {
-  struct dwo_sections *dwo_sections = (struct dwo_sections *) dwo_sections_ptr;
   const struct dwop_section_names *names = &dwop_section_names;
 
   if (section_is_p (sectp->name, &names->abbrev_dwo))
@@ -12827,8 +12817,9 @@ open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
   dwo_file->comp_dir = comp_dir;
   dwo_file->dbfd = std::move (dbfd);
 
-  bfd_map_over_sections (dwo_file->dbfd.get (), dwarf2_locate_dwo_sections,
-                        &dwo_file->sections);
+  for (asection *sec : gdb_bfd_sections (dwo_file->dbfd))
+    dwarf2_locate_dwo_sections (dwo_file->dbfd.get (), sec,
+                               &dwo_file->sections);
 
   create_cus_hash_table (per_objfile, cu, *dwo_file, dwo_file->sections.info,
                         dwo_file->cus);
@@ -12857,9 +12848,8 @@ open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
 
 static void
 dwarf2_locate_common_dwp_sections (bfd *abfd, asection *sectp,
-                                  void *dwp_file_ptr)
+                                  dwp_file *dwp_file)
 {
-  struct dwp_file *dwp_file = (struct dwp_file *) dwp_file_ptr;
   const struct dwop_section_names *names = &dwop_section_names;
   unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
 
@@ -13123,9 +13113,9 @@ open_and_init_dwp_file (dwarf2_per_objfile *per_objfile)
     OBSTACK_CALLOC (&per_objfile->per_bfd->obstack,
                    dwp_file->num_sections, asection *);
 
-  bfd_map_over_sections (dwp_file->dbfd.get (),
-                        dwarf2_locate_common_dwp_sections,
-                        dwp_file.get ());
+  for (asection *sec : gdb_bfd_sections (dwp_file->dbfd))
+    dwarf2_locate_common_dwp_sections (dwp_file->dbfd.get (), sec,
+                                      dwp_file.get ());
 
   dwp_file->cus = create_dwp_hash_table (per_objfile, dwp_file.get (), 0);
 
@@ -13151,15 +13141,15 @@ open_and_init_dwp_file (dwarf2_per_objfile *per_objfile)
   else
     dwp_file->version = 2;
 
-  if (dwp_file->version == 2)
-    bfd_map_over_sections (dwp_file->dbfd.get (),
-                          dwarf2_locate_v2_dwp_sections,
-                          dwp_file.get ());
-  else if (dwp_file->version == 5)
-    bfd_map_over_sections (dwp_file->dbfd.get (),
-                          dwarf2_locate_v5_dwp_sections,
-                          dwp_file.get ());
-
+  for (asection *sec : gdb_bfd_sections (dwp_file->dbfd))
+    {
+      if (dwp_file->version == 2)
+       dwarf2_locate_v2_dwp_sections (dwp_file->dbfd.get (), sec,
+                                      dwp_file.get ());
+      else
+       dwarf2_locate_v5_dwp_sections (dwp_file->dbfd.get (), sec,
+                                      dwp_file.get ());
+    }
 
   dwp_file->loaded_cus = allocate_dwp_loaded_cutus_table ();
   dwp_file->loaded_tus = allocate_dwp_loaded_cutus_table ();
@@ -15358,7 +15348,7 @@ create_one_variant_part (variant_part &result,
     {
       result.discriminant_index = iter->second;
       result.is_unsigned
-       = TYPE_UNSIGNED (fi->fields[result.discriminant_index].field.type ());
+       = fi->fields[result.discriminant_index].field.type ()->is_unsigned ();
     }
 
   size_t n = builder.variants.size ();
@@ -15631,7 +15621,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
                            TYPE_TARGET_TYPE (this_type),
                            this_type->fields (),
                            this_type->num_fields (),
-                           TYPE_VARARGS (this_type));
+                           this_type->has_varargs ());
 
       /* Handle static member functions.
          Dwarf2 has no clean way to discern C++ static and non-static
@@ -15847,7 +15837,7 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
   new_type = alloc_type (objfile);
   smash_to_method_type (new_type, self_type, TYPE_TARGET_TYPE (pfn_type),
                        pfn_type->fields (), pfn_type->num_fields (),
-                       TYPE_VARARGS (pfn_type));
+                       pfn_type->has_varargs ());
   smash_to_methodptr_type (type, new_type);
 }
 
@@ -16081,18 +16071,18 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       /* ICC<14 does not output the required DW_AT_declaration on
         incomplete types, but gives them a size of zero.  */
-      TYPE_STUB (type) = 1;
+      type->set_is_stub (true);
     }
   else
-    TYPE_STUB_SUPPORTED (type) = 1;
+    type->set_stub_is_supported (true);
 
   if (die_is_declaration (die, cu))
-    TYPE_STUB (type) = 1;
+    type->set_is_stub (true);
   else if (attr == NULL && die->child == NULL
           && producer_is_realview (cu->producer))
     /* RealView does not output the required DW_AT_declaration
        on incomplete types.  */
-    TYPE_STUB (type) = 1;
+    type->set_is_stub (true);
 
   /* We need to add the type field to the die immediately so we don't
      infinitely recurse when dealing with pointers to the structure
@@ -16568,7 +16558,8 @@ update_enumeration_type_from_children (struct die_info *die,
     }
 
   if (unsigned_enum)
-    TYPE_UNSIGNED (type) = 1;
+    type->set_is_unsigned (true);
+
   if (flag_enum)
     TYPE_FLAG_ENUM (type) = 1;
 }
@@ -16630,7 +16621,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
      Types.  When another package uses such a type, an incomplete DIE
      may be generated by the compiler.  */
   if (die_is_declaration (die, cu))
-    TYPE_STUB (type) = 1;
+    type->set_is_stub (true);
 
   /* If this type has an underlying type that is not a stub, then we
      may use its attributes.  We always use the "unsigned" attribute
@@ -16639,13 +16630,16 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
      can tell us the reality.  However, we defer to a local size
      attribute if one exists, because this lets the compiler override
      the underlying type if needed.  */
-  if (TYPE_TARGET_TYPE (type) != NULL && !TYPE_STUB (TYPE_TARGET_TYPE (type)))
+  if (TYPE_TARGET_TYPE (type) != NULL && !TYPE_TARGET_TYPE (type)->is_stub ())
     {
       struct type *underlying_type = TYPE_TARGET_TYPE (type);
       underlying_type = check_typedef (underlying_type);
-      TYPE_UNSIGNED (type) = TYPE_UNSIGNED (underlying_type);
+
+      type->set_is_unsigned (underlying_type->is_unsigned ());
+
       if (TYPE_LENGTH (type) == 0)
        TYPE_LENGTH (type) = TYPE_LENGTH (underlying_type);
+
       if (TYPE_RAW_ALIGN (type) == 0
          && TYPE_RAW_ALIGN (underlying_type) != 0)
        set_type_align (type, TYPE_RAW_ALIGN (underlying_type));
@@ -16885,7 +16879,7 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
       return DW_ORD_row_major;
     }
 
-  switch (cu->language_defn->la_array_ordering)
+  switch (cu->language_defn->array_ordering ())
     {
     case array_column_major:
       return DW_ORD_col_major;
@@ -17292,10 +17286,9 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       if (gdbarch_address_class_type_flags_p (gdbarch))
        {
-         int type_flags;
-
-         type_flags = gdbarch_address_class_type_flags
-                        (gdbarch, byte_size, addr_class);
+         type_instance_flags type_flags
+           = gdbarch_address_class_type_flags (gdbarch, byte_size,
+                                               addr_class);
          gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
                      == 0);
          type = make_type_with_address_space (type, type_flags);
@@ -17348,7 +17341,7 @@ read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
 
       smash_to_method_type (new_type, domain, TYPE_TARGET_TYPE (to_type),
                            to_type->fields (), to_type->num_fields (),
-                           TYPE_VARARGS (to_type));
+                           to_type->has_varargs ());
       type = lookup_methodptr_type (new_type);
     }
   else
@@ -17661,7 +17654,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
   ftype = lookup_function_type (type);
 
   if (prototyped_function_p (die, cu))
-    TYPE_PROTOTYPED (ftype) = 1;
+    ftype->set_is_prototyped (true);
 
   /* Store the calling convention in the type if it's available in
      the subroutine die.  Otherwise set the calling convention to
@@ -17703,7 +17696,8 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
          if (child_die->tag == DW_TAG_formal_parameter)
            nparams++;
          else if (child_die->tag == DW_TAG_unspecified_parameters)
-           TYPE_VARARGS (ftype) = 1;
+           ftype->set_has_varargs (true);
+
          child_die = child_die->sibling;
        }
 
@@ -17791,7 +17785,7 @@ read_typedef (struct die_info *die, struct dwarf2_cu *cu)
 
   name = dwarf2_full_name (NULL, die, cu);
   this_type = init_type (objfile, TYPE_CODE_TYPEDEF, 0, name);
-  TYPE_TARGET_STUB (this_type) = 1;
+  this_type->set_target_is_stub (true);
   set_die_type (die, this_type, cu);
   target_type = die_type (die, cu);
   if (target_type != this_type)
@@ -18054,11 +18048,31 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
     }
 
   if (name && strcmp (name, "char") == 0)
-    TYPE_NOSIGN (type) = 1;
+    type->set_has_no_signedness (true);
 
   maybe_set_alignment (cu, die, type);
 
-  TYPE_ENDIANITY_NOT_DEFAULT (type) = gdbarch_byte_order (arch) != byte_order;
+  type->set_endianity_is_not_default (gdbarch_byte_order (arch) != byte_order);
+
+  if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_INT)
+    {
+      attr = dwarf2_attr (die, DW_AT_bit_size, cu);
+      if (attr != nullptr && DW_UNSND (attr) <= 8 * TYPE_LENGTH (type))
+       {
+         unsigned real_bit_size = DW_UNSND (attr);
+         attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
+         /* Only use the attributes if they make sense together.  */
+         if (attr == nullptr
+             || DW_UNSND (attr) + real_bit_size <= 8 * TYPE_LENGTH (type))
+           {
+             TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size
+               = real_bit_size;
+             if (attr != nullptr)
+               TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset
+                 = DW_UNSND (attr);
+           }
+       }
+    }
 
   return set_die_type (die, type, cu);
 }
@@ -18351,10 +18365,10 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   negative_mask =
     -((ULONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
   if (low.kind () == PROP_CONST
-      && !TYPE_UNSIGNED (base_type) && (low.const_val () & negative_mask))
+      && !base_type->is_unsigned () && (low.const_val () & negative_mask))
     low.set_const_val (low.const_val () | negative_mask);
   if (high.kind () == PROP_CONST
-      && !TYPE_UNSIGNED (base_type) && (high.const_val () & negative_mask))
+      && !base_type->is_unsigned () && (high.const_val () & negative_mask))
     high.set_const_val (high.const_val () | negative_mask);
 
   /* Check for bit and byte strides.  */
@@ -18440,7 +18454,7 @@ read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
      such a type, we treat it as a stub, and try to resolve it later on,
      when needed.  */
   if (cu->language == language_ada)
-    TYPE_STUB (type) = 1;
+    type->set_is_stub (true);
 
   return set_die_type (die, type, cu);
 }
@@ -24083,7 +24097,7 @@ dwarf2_cu::addr_type () const
   if (TYPE_LENGTH (addr_type) == addr_size)
     return addr_type;
 
-  addr_type = addr_sized_int_type (TYPE_UNSIGNED (addr_type));
+  addr_type = addr_sized_int_type (addr_type->is_unsigned ());
   return addr_type;
 }
 
This page took 0.038298 seconds and 4 git commands to generate.