Store objfiles on a std::list
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 4372a47c6d61a2527fde4c6be92e276cc30f4a96..e009b523ccc831ca315f13a5ec4a44f8b8946242 100644 (file)
@@ -1910,6 +1910,9 @@ static void process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile);
 static struct type *dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data *per_cu);
 static struct type *dwarf2_per_cu_addr_sized_int_type
        (struct dwarf2_per_cu_data *per_cu, bool unsigned_p);
+static struct type *dwarf2_per_cu_int_type
+       (struct dwarf2_per_cu_data *per_cu, int size_in_bytes,
+        bool unsigned_p);
 
 /* Class, the destructor of which frees all allocated queue entries.  This
    will only have work to do if an error was thrown while processing the
@@ -3682,7 +3685,7 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
   sect_offset line_offset {};
 
   attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu);
-  if (attr)
+  if (attr != nullptr)
     {
       struct quick_file_names find_entry;
 
@@ -4042,6 +4045,10 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
              if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
                continue;
              break;
+           case MODULE_DOMAIN:
+             if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
+               continue;
+             break;
            default:
              break;
            }
@@ -5064,6 +5071,10 @@ dw2_expand_marked_cus
              if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
                continue;
              break;
+           case MODULES_DOMAIN:
+             if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
+               continue;
+             break;
            default:
              break;
            }
@@ -5970,6 +5981,15 @@ dw2_debug_names_iterator::next ()
          goto again;
        }
       break;
+    case MODULE_DOMAIN:
+      switch (indexval.dwarf_tag)
+       {
+       case DW_TAG_module:
+         break;
+       default:
+         goto again;
+       }
+      break;
     default:
       break;
     }
@@ -6006,6 +6026,14 @@ dw2_debug_names_iterator::next ()
          goto again;
        }
       break;
+    case MODULES_DOMAIN:
+      switch (indexval.dwarf_tag)
+       {
+       case DW_TAG_module:
+         break;
+       default:
+         goto again;
+       }
     default:
       break;
     }
@@ -6048,10 +6076,10 @@ dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
         information (but NAME might contain it).  */
 
       if (sym != NULL
-         && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
+         && strcmp_iw (sym->search_name (), name) == 0)
        return stab;
       if (with_opaque != NULL
-         && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque), name) == 0)
+         && strcmp_iw (with_opaque->search_name (), name) == 0)
        stab_best = stab;
 
       /* Keep looking through other CUs.  */
@@ -6394,7 +6422,7 @@ dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
   cu->base_address = 0;
 
   attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
-  if (attr)
+  if (attr != nullptr)
     {
       cu->base_address = attr_value_as_address (attr);
       cu->base_known = 1;
@@ -6402,7 +6430,7 @@ dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
   else
     {
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
-      if (attr)
+      if (attr != nullptr)
        {
          cu->base_address = attr_value_as_address (attr);
          cu->base_known = 1;
@@ -6666,7 +6694,7 @@ dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
   struct attribute *attr;
 
   attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
-  if (attr)
+  if (attr != nullptr)
     lh = dwarf_decode_line_header ((sect_offset) DW_UNSND (attr), cu);
   if (lh == NULL)
     return;  /* No linetable, so no includes.  */
@@ -7251,14 +7279,14 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
          or DW_FORM_addrx.  */
       cu->addr_base = 0;
       attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_addr_base, cu);
-      if (attr)
+      if (attr != nullptr)
        cu->addr_base = DW_UNSND (attr);
 
       /* There should be a DW_AT_ranges_base attribute here (if needed).
         We need the value before we can process DW_AT_ranges.  */
       cu->ranges_base = 0;
       attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_ranges_base, cu);
-      if (attr)
+      if (attr != nullptr)
        cu->ranges_base = DW_UNSND (attr);
     }
   else if (stub_comp_dir != NULL)
@@ -8733,7 +8761,8 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
              add_partial_namespace (pdi, lowpc, highpc, set_addrmap, cu);
              break;
            case DW_TAG_module:
-             add_partial_module (pdi, lowpc, highpc, set_addrmap, cu);
+             if (!pdi->is_declaration)
+               add_partial_module (pdi, lowpc, highpc, set_addrmap, cu);
              break;
            case DW_TAG_imported_unit:
              {
@@ -8952,7 +8981,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
              But in Ada and Fortran, we want to be able to access nested
              procedures globally.  So all Ada and Fortran subprograms are
              stored in the global scope.  */
-         add_psymbol_to_list (actual_name, strlen (actual_name),
+         add_psymbol_to_list (actual_name,
                               built_actual_name != NULL,
                               VAR_DOMAIN, LOC_BLOCK,
                               SECT_OFF_TEXT (objfile),
@@ -8962,7 +8991,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
        }
       else
        {
-         add_psymbol_to_list (actual_name, strlen (actual_name),
+         add_psymbol_to_list (actual_name,
                               built_actual_name != NULL,
                               VAR_DOMAIN, LOC_BLOCK,
                               SECT_OFF_TEXT (objfile),
@@ -8974,7 +9003,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
        set_objfile_main_name (objfile, actual_name, cu->language);
       break;
     case DW_TAG_constant:
-      add_psymbol_to_list (actual_name, strlen (actual_name),
+      add_psymbol_to_list (actual_name,
                           built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
                           -1, (pdi->is_external
                                ? psymbol_placement::GLOBAL
@@ -9010,7 +9039,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
             table building.  */
 
          if (pdi->d.locdesc || pdi->has_type)
-           add_psymbol_to_list (actual_name, strlen (actual_name),
+           add_psymbol_to_list (actual_name,
                                 built_actual_name != NULL,
                                 VAR_DOMAIN, LOC_STATIC,
                                 SECT_OFF_TEXT (objfile),
@@ -9029,7 +9058,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
              return;
            }
 
-         add_psymbol_to_list (actual_name, strlen (actual_name),
+         add_psymbol_to_list (actual_name,
                               built_actual_name != NULL,
                               VAR_DOMAIN, LOC_STATIC,
                               SECT_OFF_TEXT (objfile),
@@ -9041,7 +9070,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     case DW_TAG_typedef:
     case DW_TAG_base_type:
     case DW_TAG_subrange_type:
-      add_psymbol_to_list (actual_name, strlen (actual_name),
+      add_psymbol_to_list (actual_name,
                           built_actual_name != NULL,
                           VAR_DOMAIN, LOC_TYPEDEF, -1,
                           psymbol_placement::STATIC,
@@ -9049,7 +9078,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
       break;
     case DW_TAG_imported_declaration:
     case DW_TAG_namespace:
-      add_psymbol_to_list (actual_name, strlen (actual_name),
+      add_psymbol_to_list (actual_name,
                           built_actual_name != NULL,
                           VAR_DOMAIN, LOC_TYPEDEF, -1,
                           psymbol_placement::GLOBAL,
@@ -9060,7 +9089,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          available without any name.  If so, we skip the module as it
          doesn't bring any value.  */
       if (actual_name != nullptr)
-       add_psymbol_to_list (actual_name, strlen (actual_name),
+       add_psymbol_to_list (actual_name,
                             built_actual_name != NULL,
                             MODULE_DOMAIN, LOC_TYPEDEF, -1,
                             psymbol_placement::GLOBAL,
@@ -9084,7 +9113,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 
       /* NOTE: carlton/2003-10-07: See comment in new_symbol about
         static vs. global.  */
-      add_psymbol_to_list (actual_name, strlen (actual_name),
+      add_psymbol_to_list (actual_name,
                           built_actual_name != NULL,
                           STRUCT_DOMAIN, LOC_TYPEDEF, -1,
                           cu->language == language_cplus
@@ -9094,7 +9123,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 
       break;
     case DW_TAG_enumerator:
-      add_psymbol_to_list (actual_name, strlen (actual_name),
+      add_psymbol_to_list (actual_name,
                           built_actual_name != NULL,
                           VAR_DOMAIN, LOC_CONST, -1,
                           cu->language == language_cplus
@@ -9924,8 +9953,7 @@ fixup_go_packaging (struct dwarf2_cu *cu)
 
       sym = allocate_symbol (objfile);
       SYMBOL_SET_LANGUAGE (sym, language_go, &objfile->objfile_obstack);
-      SYMBOL_SET_NAMES (sym, saved_package_name,
-                       strlen (saved_package_name), 0, objfile);
+      SYMBOL_SET_NAMES (sym, saved_package_name, false, objfile);
       /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
         e.g., "main" finds the "main" module and not C's main().  */
       SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
@@ -13672,6 +13700,9 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
       origin_child_die = sibling_die (origin_child_die);
     }
   origin_cu->list_in_scope = origin_previous_list_in_scope;
+
+  if (cu != origin_cu)
+    compute_delayed_physnames (origin_cu);
 }
 
 static void
@@ -13751,19 +13782,19 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
                             (struct symbol *) templ_func);
 
   if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu))
-    set_objfile_main_name (objfile, SYMBOL_LINKAGE_NAME (newobj->name),
+    set_objfile_main_name (objfile, newobj->name->linkage_name (),
                           cu->language);
 
   /* If there is a location expression for DW_AT_frame_base, record
      it.  */
   attr = dwarf2_attr (die, DW_AT_frame_base, cu);
-  if (attr)
+  if (attr != nullptr)
     dwarf2_symbol_mark_computed (attr, newobj->name, cu, 1);
 
   /* If there is a location for the static link, record it.  */
   newobj->static_link = NULL;
   attr = dwarf2_attr (die, DW_AT_static_link, cu);
-  if (attr)
+  if (attr != nullptr)
     {
       newobj->static_link
        = XOBNEW (&objfile->objfile_obstack, struct dynamic_prop);
@@ -14239,7 +14270,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
       attr = dwarf2_attr (child_die, DW_AT_call_data_value, cu);
       if (attr == NULL)
        attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
-      if (attr)
+      if (attr != nullptr)
        {
          if (!attr_form_is_block (attr))
            complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
@@ -14295,8 +14326,7 @@ read_variable (struct die_info *die, struct dwarf2_cu *cu)
        {
          struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
 
-         storage = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-                                   struct rust_vtable_symbol);
+         storage = new (&objfile->objfile_obstack) rust_vtable_symbol ();
          initialize_objfile_symbol (storage);
          storage->concrete_type = containing_type;
          storage->subclass = SYMBOL_RUST_VTABLE;
@@ -14681,7 +14711,7 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
   if (attr_high)
     {
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
-      if (attr)
+      if (attr != nullptr)
         {
          low = attr_value_as_address (attr);
          high = attr_value_as_address (attr_high);
@@ -14854,7 +14884,7 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
   if (attr_high)
     {
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
-      if (attr)
+      if (attr != nullptr)
         {
           CORE_ADDR low = attr_value_as_address (attr);
          CORE_ADDR high = attr_value_as_address (attr_high);
@@ -14869,7 +14899,7 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
     }
 
   attr = dwarf2_attr (die, DW_AT_ranges, cu);
-  if (attr)
+  if (attr != nullptr)
     {
       /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
         We take advantage of the fact that DW_AT_ranges does not appear
@@ -15054,7 +15084,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
   fip->nfields++;
 
   attr = dwarf2_attr (die, DW_AT_accessibility, cu);
-  if (attr)
+  if (attr != nullptr)
     new_field->accessibility = DW_UNSND (attr);
   else
     new_field->accessibility = dwarf2_default_access_attribute (die, cu);
@@ -15062,7 +15092,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
     fip->non_public_fields = 1;
 
   attr = dwarf2_attr (die, DW_AT_virtuality, cu);
-  if (attr)
+  if (attr != nullptr)
     new_field->virtuality = DW_UNSND (attr);
   else
     new_field->virtuality = DW_VIRTUALITY_none;
@@ -15082,7 +15112,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
 
       /* Get bit size of field (zero if none).  */
       attr = dwarf2_attr (die, DW_AT_bit_size, cu);
-      if (attr)
+      if (attr != nullptr)
        {
          FIELD_BITSIZE (*fp) = DW_UNSND (attr);
        }
@@ -15095,9 +15125,9 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       if (handle_data_member_location (die, cu, &offset))
        SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
       attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
-      if (attr)
+      if (attr != nullptr)
        {
-         if (gdbarch_bits_big_endian (gdbarch))
+         if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
            {
              /* For big endian bits, the DW_AT_bit_offset gives the
                 additional bit offset from the MSB of the containing
@@ -15118,7 +15148,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
              int bit_offset = DW_UNSND (attr);
 
              attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-             if (attr)
+             if (attr != nullptr)
                {
                  /* The size of the anonymous object containing
                     the bit field is explicit, so use the
@@ -15225,13 +15255,18 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
 
       /* Normally a DW_TAG_variant_part won't have a size, but our
         representation requires one, so set it to the maximum of the
-        child sizes.  */
+        child sizes, being sure to account for the offset at which
+        each child is seen.  */
       if (TYPE_LENGTH (fp->type) == 0)
        {
          unsigned max = 0;
          for (int i = 0; i < TYPE_NFIELDS (fp->type); ++i)
-           if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i)) > max)
-             max = TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i));
+           {
+             unsigned len = ((TYPE_FIELD_BITPOS (fp->type, i) + 7) / 8
+                             + TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i)));
+             if (len > max)
+               max = len;
+           }
          TYPE_LENGTH (fp->type) = max;
        }
     }
@@ -15530,7 +15565,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 
   /* Get accessibility.  */
   attr = dwarf2_attr (die, DW_AT_accessibility, cu);
-  if (attr)
+  if (attr != nullptr)
     accessibility = (enum dwarf_access_attribute) DW_UNSND (attr);
   else
     accessibility = dwarf2_default_access_attribute (die, cu);
@@ -15558,7 +15593,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
      to the object address.  */
 
   attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
-  if (attr)
+  if (attr != nullptr)
     {
       if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
         {
@@ -15812,7 +15847,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
      Don't follow DW_AT_specification though, that will take us back up
      the chain and we want to go down.  */
   attr = dwarf2_attr_no_follow (die, DW_AT_signature);
-  if (attr)
+  if (attr != nullptr)
     {
       type = get_DW_AT_signature_type (die, attr, cu);
 
@@ -15870,7 +15905,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
     TYPE_DECLARED_CLASS (type) = 1;
 
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-  if (attr)
+  if (attr != nullptr)
     {
       if (attr_form_is_constant (attr))
         TYPE_LENGTH (type) = DW_UNSND (attr);
@@ -16025,7 +16060,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
      read the discriminant member, so we can record it later in the
      discriminant_info.  */
   bool is_variant_part = TYPE_FLAG_DISCRIMINATED_UNION (type);
-  sect_offset discr_offset;
+  sect_offset discr_offset {};
   bool has_template_parameters = false;
 
   if (is_variant_part)
@@ -16336,7 +16371,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
      Don't follow DW_AT_specification though, that will take us back up
      the chain and we want to go down.  */
   attr = dwarf2_attr_no_follow (die, DW_AT_signature);
-  if (attr)
+  if (attr != nullptr)
     {
       type = get_DW_AT_signature_type (die, attr, cu);
 
@@ -16361,7 +16396,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
     }
 
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-  if (attr)
+  if (attr != nullptr)
     {
       TYPE_LENGTH (type) = DW_UNSND (attr);
     }
@@ -16452,7 +16487,7 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
                                  * sizeof (struct field));
                    }
 
-                 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
+                 FIELD_NAME (fields[num_fields]) = sym->linkage_name ();
                  FIELD_TYPE (fields[num_fields]) = NULL;
                  SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym));
                  FIELD_BITSIZE (fields[num_fields]) = 0;
@@ -16605,14 +16640,14 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
      array and the vector variant is that vectors are passed by value
      to functions.  */
   attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
-  if (attr)
+  if (attr != nullptr)
     make_vector_type (type);
 
   /* The DIE may have DW_AT_byte_size set.  For example an OpenCL
      implementation may choose to implement triple vectors using this
      attribute.  */
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-  if (attr)
+  if (attr != nullptr)
     {
       if (DW_UNSND (attr) >= TYPE_LENGTH (type))
        TYPE_LENGTH (type) = DW_UNSND (attr);
@@ -16643,7 +16678,7 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
 
   attr = dwarf2_attr (die, DW_AT_ordering, cu);
 
-  if (attr)
+  if (attr != nullptr)
     return (enum dwarf_array_dim_ordering) DW_SND (attr);
 
   /* GNU F77 is a special case, as at 08/2004 array type info is the
@@ -16688,7 +16723,7 @@ read_set_type (struct die_info *die, struct dwarf2_cu *cu)
   set_type = create_set_type (NULL, domain_type);
 
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-  if (attr)
+  if (attr != nullptr)
     TYPE_LENGTH (set_type) = DW_UNSND (attr);
 
   maybe_set_alignment (cu, die, set_type);
@@ -16781,7 +16816,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
   struct attribute *attr;
 
   attr = dwarf2_attr (die, DW_AT_location, cu);
-  if (attr)
+  if (attr != nullptr)
     {
       /* Support the .debug_loc offsets.  */
       if (attr_form_is_block (attr))
@@ -16854,7 +16889,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
                  else if (attr_form_is_constant (member_loc)
                           || attr_form_is_block (member_loc))
                    {
-                     if (attr)
+                     if (attr != nullptr)
                        mark_common_block_symbol_computed (sym, die, attr,
                                                           member_loc, cu);
                    }
@@ -17155,7 +17190,7 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu,
 
   type = lookup_reference_type (target_type, refcode);
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-  if (attr)
+  if (attr != nullptr)
     {
       TYPE_LENGTH (type) = DW_UNSND (attr);
     }
@@ -17288,29 +17323,90 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct type *type, *range_type, *index_type, *char_type;
   struct attribute *attr;
-  unsigned int length;
+  struct dynamic_prop prop;
+  bool length_is_constant = true;
+  LONGEST length;
+
+  /* There are a couple of places where bit sizes might be made use of
+     when parsing a DW_TAG_string_type, however, no producer that we know
+     of make use of these.  Handling bit sizes that are a multiple of the
+     byte size is easy enough, but what about other bit sizes?  Lets deal
+     with that problem when we have to.  Warn about these attributes being
+     unsupported, then parse the type and ignore them like we always
+     have.  */
+  if (dwarf2_attr (die, DW_AT_bit_size, cu) != nullptr
+      || dwarf2_attr (die, DW_AT_string_length_bit_size, cu) != nullptr)
+    {
+      static bool warning_printed = false;
+      if (!warning_printed)
+       {
+         warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
+                    "currently supported on DW_TAG_string_type."));
+         warning_printed = true;
+       }
+    }
 
   attr = dwarf2_attr (die, DW_AT_string_length, cu);
-  if (attr)
+  if (attr != nullptr && !attr_form_is_constant (attr))
+    {
+      /* The string length describes the location at which the length of
+        the string can be found.  The size of the length field can be
+        specified with one of the attributes below.  */
+      struct type *prop_type;
+      struct attribute *len
+       = dwarf2_attr (die, DW_AT_string_length_byte_size, cu);
+      if (len == nullptr)
+       len = dwarf2_attr (die, DW_AT_byte_size, cu);
+      if (len != nullptr && attr_form_is_constant (len))
+       {
+         /* Pass 0 as the default as we know this attribute is constant
+            and the default value will not be returned.  */
+         LONGEST sz = dwarf2_get_attr_constant_value (len, 0);
+         prop_type = dwarf2_per_cu_int_type (cu->per_cu, sz, true);
+       }
+      else
+       {
+         /* If the size is not specified then we assume it is the size of
+            an address on this target.  */
+         prop_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, true);
+       }
+
+      /* Convert the attribute into a dynamic property.  */
+      if (!attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
+       length = 1;
+      else
+       length_is_constant = false;
+    }
+  else if (attr != nullptr)
     {
-      length = DW_UNSND (attr);
+      /* This DW_AT_string_length just contains the length with no
+        indirection.  There's no need to create a dynamic property in this
+        case.  Pass 0 for the default value as we know it will not be
+        returned in this case.  */
+      length = dwarf2_get_attr_constant_value (attr, 0);
+    }
+  else if ((attr = dwarf2_attr (die, DW_AT_byte_size, cu)) != nullptr)
+    {
+      /* We don't currently support non-constant byte sizes for strings.  */
+      length = dwarf2_get_attr_constant_value (attr, 1);
     }
   else
     {
-      /* Check for the DW_AT_byte_size attribute.  */
-      attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-      if (attr)
-        {
-          length = DW_UNSND (attr);
-        }
-      else
-        {
-          length = 1;
-        }
+      /* Use 1 as a fallback length if we have nothing else.  */
+      length = 1;
     }
 
   index_type = objfile_type (objfile)->builtin_int;
-  range_type = create_static_range_type (NULL, index_type, 1, length);
+  if (length_is_constant)
+    range_type = create_static_range_type (NULL, index_type, 1, length);
+  else
+    {
+      struct dynamic_prop low_bound;
+
+      low_bound.kind = PROP_CONST;
+      low_bound.data.const_val = 1;
+      range_type = create_range_type (NULL, index_type, &low_bound, &prop, 0);
+    }
   char_type = language_string_char_type (cu->language_defn, gdbarch);
   type = create_string_type (NULL, char_type, range_type);
 
@@ -17383,7 +17479,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
      the subroutine die.  Otherwise set the calling convention to
      the default value DW_CC_normal.  */
   attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
-  if (attr)
+  if (attr != nullptr)
     TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
   else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
     TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
@@ -17449,7 +17545,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
                 DWARF version 3 added DW_AT_object_pointer, which GCC
                 4.5 does not yet generate.  */
              attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
-             if (attr)
+             if (attr != nullptr)
                TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
              else
                TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
@@ -17466,7 +17562,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
                  const char *name = dwarf2_name (child_die, cu);
 
                  attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
-                 if (attr)
+                 if (attr != nullptr)
                    {
                      /* If the compiler emits this, use it.  */
                      if (follow_die_ref (die, attr, &arg_cu) == child_die)
@@ -17528,7 +17624,7 @@ read_typedef (struct die_info *die, struct dwarf2_cu *cu)
 
 static struct type *
 dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
-                       const char *name_hint)
+                       const char *name_hint, enum bfd_endian byte_order)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   const struct floatformat **format;
@@ -17536,7 +17632,7 @@ dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
 
   format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
   if (format)
-    type = init_float_type (objfile, bits, name, format);
+    type = init_float_type (objfile, bits, name, format, byte_order);
   else
     type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
 
@@ -17575,7 +17671,8 @@ dwarf2_init_integer_type (struct dwarf2_cu *cu, struct objfile *objfile,
 static struct type *
 dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
                                 struct objfile *objfile,
-                                int bits, const char *name_hint)
+                                int bits, const char *name_hint,
+                                enum bfd_endian byte_order)
 {
   gdbarch *gdbarch = get_objfile_arch (objfile);
   struct type *tt = nullptr;
@@ -17624,7 +17721,7 @@ dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
     tt = nullptr;
 
   const char *name = (tt == nullptr) ? nullptr : TYPE_NAME (tt);
-  return dwarf2_init_float_type (objfile, bits, name, name_hint);
+  return dwarf2_init_float_type (objfile, bits, name, name_hint, byte_order);
 }
 
 /* Find a representation of a given base type and install
@@ -17638,21 +17735,38 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
   struct attribute *attr;
   int encoding = 0, bits = 0;
   const char *name;
+  gdbarch *arch;
 
   attr = dwarf2_attr (die, DW_AT_encoding, cu);
-  if (attr)
-    {
-      encoding = DW_UNSND (attr);
-    }
+  if (attr != nullptr)
+    encoding = DW_UNSND (attr);
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-  if (attr)
-    {
-      bits = DW_UNSND (attr) * TARGET_CHAR_BIT;
-    }
+  if (attr != nullptr)
+    bits = DW_UNSND (attr) * TARGET_CHAR_BIT;
   name = dwarf2_name (die, cu);
   if (!name)
+    complaint (_("DW_AT_name missing from DW_TAG_base_type"));
+
+  arch = get_objfile_arch (objfile);
+  enum bfd_endian byte_order = gdbarch_byte_order (arch);
+
+  attr = dwarf2_attr (die, DW_AT_endianity, cu);
+  if (attr)
     {
-      complaint (_("DW_AT_name missing from DW_TAG_base_type"));
+      int endianity = DW_UNSND (attr);
+
+      switch (endianity)
+       {
+       case DW_END_big:
+         byte_order = BFD_ENDIAN_BIG;
+         break;
+       case DW_END_little:
+         byte_order = BFD_ENDIAN_LITTLE;
+         break;
+       default:
+         complaint (_("DW_AT_endianity has unrecognized value %d"), endianity);
+         break;
+       }
     }
 
   switch (encoding)
@@ -17666,14 +17780,15 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        type = init_boolean_type (objfile, bits, 1, name);
        break;
       case DW_ATE_complex_float:
-       type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name);
+       type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name,
+                                               byte_order);
        type = init_complex_type (objfile, name, type);
        break;
       case DW_ATE_decimal_float:
        type = init_decfloat_type (objfile, bits, name);
        break;
       case DW_ATE_float:
-       type = dwarf2_init_float_type (objfile, bits, name, name);
+       type = dwarf2_init_float_type (objfile, bits, name, name, byte_order);
        break;
       case DW_ATE_signed:
        type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
@@ -17705,8 +17820,6 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        break;
       case DW_ATE_UTF:
        {
-         gdbarch *arch = get_objfile_arch (objfile);
-
          if (bits == 16)
            type = builtin_type (arch)->builtin_char16;
          else if (bits == 32)
@@ -17733,6 +17846,8 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
 
   maybe_set_alignment (cu, die, type);
 
+  TYPE_ENDIANITY_NOT_DEFAULT (type) = gdbarch_byte_order (arch) != byte_order;
+
   return set_die_type (die, type, cu);
 }
 
@@ -17761,7 +17876,15 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
       baton->locexpr.per_cu = cu->per_cu;
       baton->locexpr.size = DW_BLOCK (attr)->size;
       baton->locexpr.data = DW_BLOCK (attr)->data;
-      baton->locexpr.is_reference = false;
+      switch (attr->name)
+       {
+       case DW_AT_string_length:
+         baton->locexpr.is_reference = true;
+         break;
+       default:
+         baton->locexpr.is_reference = false;
+         break;
+       }
       prop->data.baton = baton;
       prop->kind = PROP_LOCEXPR;
       gdb_assert (prop->data.baton != NULL);
@@ -17845,24 +17968,22 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
   return 1;
 }
 
-/* Find an integer type the same size as the address size given in the
-   compilation unit header for PER_CU.  UNSIGNED_P controls if the integer
-   is unsigned or not.  */
+/* Find an integer type SIZE_IN_BYTES bytes in size and return it.
+   UNSIGNED_P controls if the integer is unsigned or not.  */
 
 static struct type *
-dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data *per_cu,
-                                  bool unsigned_p)
+dwarf2_per_cu_int_type (struct dwarf2_per_cu_data *per_cu,
+                       int size_in_bytes, bool unsigned_p)
 {
   struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
-  int addr_size = dwarf2_per_cu_addr_size (per_cu);
   struct type *int_type;
 
   /* Helper macro to examine the various builtin types.  */
-#define TRY_TYPE(F)                                            \
-  int_type = (unsigned_p                                       \
-             ? objfile_type (objfile)->builtin_unsigned_ ## F  \
-             : objfile_type (objfile)->builtin_ ## F);         \
-  if (int_type != NULL && TYPE_LENGTH (int_type) == addr_size) \
+#define TRY_TYPE(F)                                                    \
+  int_type = (unsigned_p                                               \
+             ? objfile_type (objfile)->builtin_unsigned_ ## F          \
+             : objfile_type (objfile)->builtin_ ## F);                 \
+  if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes)     \
     return int_type
 
   TRY_TYPE (char);
@@ -17876,6 +17997,18 @@ dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data *per_cu,
   gdb_assert_not_reached ("unable to find suitable integer type");
 }
 
+/* Find an integer type the same size as the address size given in the
+   compilation unit header for PER_CU.  UNSIGNED_P controls if the integer
+   is unsigned or not.  */
+
+static struct type *
+dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data *per_cu,
+                                  bool unsigned_p)
+{
+  int addr_size = dwarf2_per_cu_addr_size (per_cu);
+  return dwarf2_per_cu_int_type (per_cu, addr_size, unsigned_p);
+}
+
 /* Read the DW_AT_type attribute for a sub-range.  If this attribute is not
    present (which is valid) then compute the default type based on the
    compilation units address size.  */
@@ -17966,7 +18099,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
     }
 
   attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
-  if (attr)
+  if (attr != nullptr)
     attr_to_dynamic_prop (attr, die, cu, &low, base_type);
   else if (!low_default_is_valid)
     complaint (_("Missing DW_AT_lower_bound "
@@ -18023,7 +18156,52 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
       && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
     high.data.const_val |= negative_mask;
 
-  range_type = create_range_type (NULL, orig_base_type, &low, &high, bias);
+  /* Check for bit and byte strides.  */
+  struct dynamic_prop byte_stride_prop;
+  attribute *attr_byte_stride = dwarf2_attr (die, DW_AT_byte_stride, cu);
+  if (attr_byte_stride != nullptr)
+    {
+      struct type *prop_type
+       = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+      attr_to_dynamic_prop (attr_byte_stride, die, cu, &byte_stride_prop,
+                           prop_type);
+    }
+
+  struct dynamic_prop bit_stride_prop;
+  attribute *attr_bit_stride = dwarf2_attr (die, DW_AT_bit_stride, cu);
+  if (attr_bit_stride != nullptr)
+    {
+      /* It only makes sense to have either a bit or byte stride.  */
+      if (attr_byte_stride != nullptr)
+       {
+         complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
+                      "- DIE at %s [in module %s]"),
+                    sect_offset_str (die->sect_off),
+                    objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+         attr_bit_stride = nullptr;
+       }
+      else
+       {
+         struct type *prop_type
+           = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+         attr_to_dynamic_prop (attr_bit_stride, die, cu, &bit_stride_prop,
+                               prop_type);
+       }
+    }
+
+  if (attr_byte_stride != nullptr
+      || attr_bit_stride != nullptr)
+    {
+      bool byte_stride_p = (attr_byte_stride != nullptr);
+      struct dynamic_prop *stride
+       = byte_stride_p ? &byte_stride_prop : &bit_stride_prop;
+
+      range_type
+       = create_range_type_with_stride (NULL, orig_base_type, &low,
+                                        &high, bias, stride, byte_stride_p);
+    }
+  else
+    range_type = create_range_type (NULL, orig_base_type, &low, &high, bias);
 
   if (high_bound_is_count)
     TYPE_RANGE_DATA (range_type)->flag_upper_bound_is_count = 1;
@@ -18037,7 +18215,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
     TYPE_NAME (range_type) = name;
 
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-  if (attr)
+  if (attr != nullptr)
     TYPE_LENGTH (range_type) = DW_UNSND (attr);
 
   maybe_set_alignment (cu, die, range_type);
@@ -18566,7 +18744,7 @@ load_partial_dies (const struct die_reader_specs *reader,
              || pdi.tag == DW_TAG_subrange_type))
        {
          if (building_psymtab && pdi.name != NULL)
-           add_psymbol_to_list (pdi.name, strlen (pdi.name), false,
+           add_psymbol_to_list (pdi.name, false,
                                 VAR_DOMAIN, LOC_TYPEDEF, -1,
                                 psymbol_placement::STATIC,
                                 0, cu->language, objfile);
@@ -18600,7 +18778,7 @@ load_partial_dies (const struct die_reader_specs *reader,
          if (pdi.name == NULL)
            complaint (_("malformed enumerator DIE ignored"));
          else if (building_psymtab)
-           add_psymbol_to_list (pdi.name, strlen (pdi.name), false,
+           add_psymbol_to_list (pdi.name, false,
                                 VAR_DOMAIN, LOC_CONST, -1,
                                 cu->language == language_cplus
                                 ? psymbol_placement::GLOBAL
@@ -21606,13 +21784,13 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
       /* Cache this symbol's name and the name's demangled form (if any).  */
       SYMBOL_SET_LANGUAGE (sym, cu->language, &objfile->objfile_obstack);
       linkagename = dwarf2_physname (name, die, cu);
-      SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
+      SYMBOL_SET_NAMES (sym, linkagename, false, objfile);
 
       /* Fortran does not have mangling standard and the mangling does differ
         between gfortran, iFort etc.  */
       if (cu->language == language_fortran
-          && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
-       symbol_set_demangled_name (&(sym->ginfo),
+          && symbol_get_demangled_name (sym) == NULL)
+       symbol_set_demangled_name (sym,
                                   dwarf2_full_name (name, die, cu),
                                   NULL);
 
@@ -21627,7 +21805,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
       attr = dwarf2_attr (die,
                          inlined_func ? DW_AT_call_line : DW_AT_decl_line,
                          cu);
-      if (attr)
+      if (attr != nullptr)
        {
          SYMBOL_LINE (sym) = DW_UNSND (attr);
        }
@@ -21635,7 +21813,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
       attr = dwarf2_attr (die,
                          inlined_func ? DW_AT_call_file : DW_AT_decl_file,
                          cu);
-      if (attr)
+      if (attr != nullptr)
        {
          file_name_index file_index = (file_name_index) DW_UNSND (attr);
          struct file_entry *fe;
@@ -21655,7 +21833,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
        {
        case DW_TAG_label:
          attr = dwarf2_attr (die, DW_AT_low_pc, cu);
-         if (attr)
+         if (attr != nullptr)
            {
              CORE_ADDR addr;
 
@@ -21719,7 +21897,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
              gdb_assert (die_is_declaration (die, cu));
              gdb_assert (attr);
            }
-         if (attr)
+         if (attr != nullptr)
            {
              dwarf2_const_value (attr, sym, cu);
              attr2 = dwarf2_attr (die, DW_AT_external, cu);
@@ -21733,7 +21911,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
              break;
            }
          attr = dwarf2_attr (die, DW_AT_location, cu);
-         if (attr)
+         if (attr != nullptr)
            {
              var_decode_location (attr, sym, cu);
              attr2 = dwarf2_attr (die, DW_AT_external, cu);
@@ -21766,7 +21944,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
                         apply.  */
                      bound_minimal_symbol found
                        = (lookup_minimal_symbol_linkage
-                          (SYMBOL_LINKAGE_NAME (sym), objfile));
+                          (sym->linkage_name (), objfile));
                      if (found.minsym != nullptr)
                        sym->maybe_copied = 1;
                    }
@@ -21836,12 +22014,12 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
            if (curr != nullptr && curr->name != nullptr)
              SYMBOL_IS_ARGUMENT (sym) = 1;
            attr = dwarf2_attr (die, DW_AT_location, cu);
-           if (attr)
+           if (attr != nullptr)
              {
                var_decode_location (attr, sym, cu);
              }
            attr = dwarf2_attr (die, DW_AT_const_value, cu);
-           if (attr)
+           if (attr != nullptr)
              {
                dwarf2_const_value (attr, sym, cu);
              }
@@ -21895,7 +22073,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
                       with this objfile, so we don't need to
                       duplicate it for the type.  */
                    if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
-                     TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
+                     TYPE_NAME (SYMBOL_TYPE (sym)) = sym->search_name ();
                  }
              }
          }
@@ -21913,7 +22091,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
          break;
        case DW_TAG_enumerator:
          attr = dwarf2_attr (die, DW_AT_const_value, cu);
-         if (attr)
+         if (attr != nullptr)
            {
              dwarf2_const_value (attr, sym, cu);
            }
@@ -22128,7 +22306,7 @@ dwarf2_const_value (const struct attribute *attr, struct symbol *sym,
   struct dwarf2_locexpr_baton *baton;
 
   dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
-                          SYMBOL_PRINT_NAME (sym),
+                          sym->print_name (),
                           &objfile->objfile_obstack, cu,
                           &value, &bytes, &baton);
 
@@ -25310,7 +25488,7 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
       else
        {
          dwarf2_invalid_attrib_class_complaint ("location description",
-                                                SYMBOL_NATURAL_NAME (sym));
+                                                sym->natural_name ());
          baton->size = 0;
        }
 
@@ -25525,7 +25703,7 @@ prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
 
   /* Set the language we're debugging.  */
   attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
-  if (attr)
+  if (attr != nullptr)
     set_cu_language (DW_UNSND (attr), cu);
   else
     {
This page took 0.047345 seconds and 4 git commands to generate.