]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/dwarf2/read.c
gdb: add type::name / type::set_name
[thirdparty/binutils-gdb.git] / gdb / dwarf2 / read.c
index d71bf9173838b245b25a856dc3e78422af685a6b..2c81a4eed65bf87e52d8dffadbc2737093c1d291 100644 (file)
@@ -5022,6 +5022,26 @@ create_cus_from_debug_names_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
                                  dwarf2_section_info &section,
                                  bool is_dwz)
 {
+  if (!map.augmentation_is_gdb)
+    {
+    for (uint32_t i = 0; i < map.cu_count; ++i)
+      {
+       sect_offset sect_off
+         = (sect_offset) (extract_unsigned_integer
+                          (map.cu_table_reordered + i * map.offset_size,
+                           map.offset_size,
+                           map.dwarf5_byte_order));
+       /* We don't know the length of the CU, because the CU list in a
+          .debug_names index can be incomplete, so we can't use the start of
+          the next CU as end of this CU.  We create the CUs here with length 0,
+          and in cutu_reader::cutu_reader we'll fill in the actual length.  */
+       dwarf2_per_cu_data *per_cu
+         = create_cu_from_index_list (dwarf2_per_objfile, &section, is_dwz,
+                                      sect_off, 0);
+       dwarf2_per_objfile->all_comp_units.push_back (per_cu);
+      }
+    }
+
   sect_offset sect_off_prev;
   for (uint32_t i = 0; i <= map.cu_count; ++i)
     {
@@ -5352,6 +5372,18 @@ dw2_debug_names_iterator::next ()
          ull = read_unsigned_leb128 (abfd, m_addr, &bytes_read);
          m_addr += bytes_read;
          break;
+       case DW_FORM_ref4:
+         ull = read_4_bytes (abfd, m_addr);
+         m_addr += 4;
+         break;
+       case DW_FORM_ref8:
+         ull = read_8_bytes (abfd, m_addr);
+         m_addr += 8;
+         break;
+       case DW_FORM_ref_sig8:
+         ull = read_8_bytes (abfd, m_addr);
+         m_addr += 8;
+         break;
        default:
          complaint (_("Unsupported .debug_names form %s [in module %s]"),
                     dwarf_form_name (attr.form),
@@ -5384,6 +5416,12 @@ dw2_debug_names_iterator::next ()
            }
          per_cu = &dwarf2_per_objfile->get_tu (ull)->per_cu;
          break;
+       case DW_IDX_die_offset:
+         /* In a per-CU index (as opposed to a per-module index), index
+            entries without CU attribute implicitly refer to the single CU.  */
+         if (per_cu == NULL)
+           per_cu = dwarf2_per_objfile->get_cu (0);
+         break;
        case DW_IDX_GNU_internal:
          if (!m_map.augmentation_is_gdb)
            break;
@@ -6928,7 +6966,10 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
                                                    rcuh_kind::COMPILE);
 
          gdb_assert (this_cu->sect_off == cu->header.sect_off);
-         gdb_assert (this_cu->length == cu->header.get_length ());
+         if (this_cu->length == 0)
+           this_cu->length = cu->header.get_length ();
+         else
+           gdb_assert (this_cu->length == cu->header.get_length ());
          this_cu->dwarf_version = cu->header.version;
        }
     }
@@ -8378,7 +8419,14 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     {
       if (built_actual_name != nullptr)
        actual_name = objfile->intern (actual_name);
-      psymbol.ginfo.set_linkage_name (actual_name);
+      if (pdi->linkage_name == nullptr || cu->language == language_ada)
+       psymbol.ginfo.set_linkage_name (actual_name);
+      else
+       {
+         psymbol.ginfo.set_demangled_name (actual_name,
+                                           &objfile->objfile_obstack);
+         psymbol.ginfo.set_linkage_name (pdi->linkage_name);
+       }
       add_psymbol_to_list (psymbol, *where, objfile);
     }
 }
@@ -9124,7 +9172,7 @@ fixup_go_packaging (struct dwarf2_cu *cu)
                                     saved_package_name);
       struct symbol *sym;
 
-      sym = allocate_symbol (objfile);
+      sym = new (&objfile->objfile_obstack) symbol;
       sym->set_language (language_go, &objfile->objfile_obstack);
       sym->compute_and_set_names (saved_package_name, false, objfile->per_bfd);
       /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
@@ -9211,7 +9259,7 @@ alloc_rust_variant (struct obstack *obstack, struct type *type,
   prop.kind = PROP_VARIANT_PARTS;
   prop.data.variant_parts = prop_value;
 
-  add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop, type);
+  type->add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop);
 }
 
 /* Some versions of rustc emitted enums in an unusual way.
@@ -9237,7 +9285,7 @@ alloc_rust_variant (struct obstack *obstack, struct type *type,
 static void
 quirk_rust_enum (struct type *type, struct objfile *objfile)
 {
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
+  gdb_assert (type->code () == TYPE_CODE_UNION);
 
   /* We don't need to deal with empty enums.  */
   if (TYPE_NFIELDS (type) == 0)
@@ -9277,7 +9325,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 
       /* Smash this type to be a structure type.  We have to do this
         because the type has already been recorded.  */
-      TYPE_CODE (type) = TYPE_CODE_STRUCT;
+      type->set_code (TYPE_CODE_STRUCT);
       TYPE_NFIELDS (type) = 3;
       /* Save the field we care about.  */
       struct field saved_field = TYPE_FIELD (type, 0);
@@ -9295,9 +9343,9 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       TYPE_FIELD (type, 1) = saved_field;
       TYPE_FIELD_NAME (type, 1)
        = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (type, 1)));
-      TYPE_NAME (TYPE_FIELD_TYPE (type, 1))
-       rust_fully_qualify (&objfile->objfile_obstack, TYPE_NAME (type),
-                             TYPE_FIELD_NAME (type, 1));
+      TYPE_FIELD_TYPE (type, 1)->set_name
+       (rust_fully_qualify (&objfile->objfile_obstack, TYPE_NAME (type),
+                            TYPE_FIELD_NAME (type, 1)));
 
       const char *dataless_name
        = rust_fully_qualify (&objfile->objfile_obstack, TYPE_NAME (type),
@@ -9320,15 +9368,15 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
     {
       /* Smash this type to be a structure type.  We have to do this
         because the type has already been recorded.  */
-      TYPE_CODE (type) = TYPE_CODE_STRUCT;
+      type->set_code (TYPE_CODE_STRUCT);
 
       struct type *field_type = TYPE_FIELD_TYPE (type, 0);
       const char *variant_name
        = rust_last_path_segment (TYPE_NAME (field_type));
       TYPE_FIELD_NAME (type, 0) = variant_name;
-      TYPE_NAME (field_type)
-       rust_fully_qualify (&objfile->objfile_obstack,
-                             TYPE_NAME (type), variant_name);
+      field_type->set_name
+       (rust_fully_qualify (&objfile->objfile_obstack,
+                            TYPE_NAME (type), variant_name));
     }
   else
     {
@@ -9337,7 +9385,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
        {
          disr_type = TYPE_FIELD_TYPE (type, i);
 
-         if (TYPE_CODE (disr_type) != TYPE_CODE_STRUCT)
+         if (disr_type->code () != TYPE_CODE_STRUCT)
            {
              /* All fields of a true enum will be structs.  */
              return;
@@ -9367,7 +9415,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 
       /* Smash this type to be a structure type.  We have to do this
         because the type has already been recorded.  */
-      TYPE_CODE (type) = TYPE_CODE_STRUCT;
+      type->set_code (TYPE_CODE_STRUCT);
 
       /* Make space for the discriminant field.  */
       struct field *disr_field = &TYPE_FIELD (disr_type, 0);
@@ -9429,9 +9477,9 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
              ++TYPE_FIELDS (sub_type);
            }
          TYPE_FIELD_NAME (type, i) = variant_name;
-         TYPE_NAME (sub_type)
-           rust_fully_qualify (&objfile->objfile_obstack,
-                                 TYPE_NAME (type), variant_name);
+         sub_type->set_name
+           (rust_fully_qualify (&objfile->objfile_obstack,
+                                TYPE_NAME (type), variant_name));
        }
 
       /* Indicate that this is a variant type.  */
@@ -10251,7 +10299,7 @@ dwarf2_compute_name (const char *name,
                     the two cases.  */
                  if (TYPE_NFIELDS (type) > 0
                      && TYPE_FIELD_ARTIFICIAL (type, 0)
-                     && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
+                     && TYPE_FIELD_TYPE (type, 0)->code () == TYPE_CODE_PTR
                      && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
                                                                        0))))
                    buf.puts (" const");
@@ -10311,7 +10359,8 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
   if (!die_needs_namespace (die, cu))
     return dwarf2_compute_name (name, die, cu, 1);
 
-  mangled = dw2_linkage_name (die, cu);
+  if (cu->language != language_rust)
+    mangled = dw2_linkage_name (die, cu);
 
   /* DW_AT_linkage_name is missing in some cases - depend on what GDB
      has computed.  */
@@ -10434,7 +10483,7 @@ read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu)
          sect_offset sect_off = attr->get_ref_die_offset ();
 
          type = get_die_type_at_offset (sect_off, cu->per_cu);
-         if (type != NULL && TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
+         if (type != NULL && type->code () == TYPE_CODE_NAMESPACE)
            {
              /* This declaration is a global namespace alias.  Add
                 a symbol for it whose type is the aliased namespace.  */
@@ -10913,6 +10962,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
                            COMPUNIT_DIRNAME (cust),
                            compunit_language (cust),
                            0, cust));
+         list_in_scope = get_builder ()->get_file_symbols ();
        }
       return;
     }
@@ -10964,6 +11014,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
                        COMPUNIT_DIRNAME (cust),
                        compunit_language (cust),
                        0, cust));
+      list_in_scope = get_builder ()->get_file_symbols ();
 
       auto &file_names = line_header->file_names ();
       for (i = 0; i < file_names.size (); ++i)
@@ -12932,7 +12983,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       if (child_die->tag == DW_TAG_template_type_param
          || child_die->tag == DW_TAG_template_value_param)
        {
-         templ_func = allocate_template_symbol (objfile);
+         templ_func = new (&objfile->objfile_obstack) template_symbol;
          templ_func->subclass = SYMBOL_TEMPLATE;
          break;
        }
@@ -13092,7 +13143,16 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
       for (child_die = die->child;
           child_die != NULL && child_die->tag;
           child_die = child_die->sibling)
-       process_die (child_die, cu);
+       {
+         /* We might already be processing this DIE.  This can happen
+            in an unusual circumstance -- where a subroutine A
+            appears lexically in another subroutine B, but A actually
+            inlines B.  The recursion is broken here, rather than in
+            inherit_abstract_dies, because it seems better to simply
+            drop concrete children here.  */
+         if (!child_die->in_process)
+           process_die (child_die, cu);
+       }
       return;
     case PC_BOUNDS_INVALID:
       return;
@@ -13248,7 +13308,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
            func_type = get_die_type (func_die, cu);
          if (func_type != NULL)
            {
-             gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
+             gdb_assert (func_type->code () == TYPE_CODE_FUNC);
 
              /* Enlist this call site to the function.  */
              call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type);
@@ -13486,8 +13546,7 @@ read_variable (struct die_info *die, struct dwarf2_cu *cu)
        {
          struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
 
-         storage = new (&objfile->objfile_obstack) rust_vtable_symbol ();
-         initialize_objfile_symbol (storage);
+         storage = new (&objfile->objfile_obstack) rust_vtable_symbol;
          storage->concrete_type = containing_type;
          storage->subclass = SYMBOL_RUST_VTABLE;
        }
@@ -14505,7 +14564,8 @@ dwarf2_add_type_defn (struct field_info *fip, struct die_info *die,
 
 /* A convenience typedef that's used when finding the discriminant
    field for a variant part.  */
-typedef std::unordered_map<sect_offset, int> offset_map_type;
+typedef std::unordered_map<sect_offset, int, gdb::hash_enum<sect_offset>>
+  offset_map_type;
 
 /* Compute the discriminant range for a given variant.  OBSTACK is
    where the results will be stored.  VARIANT is the variant to
@@ -14695,7 +14755,7 @@ add_variant_property (struct field_info *fip, struct type *type,
     = ((gdb::array_view<variant_part> *)
        obstack_copy (&objfile->objfile_obstack, &parts, sizeof (parts)));
 
-  add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop, type);
+  type->add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop);
 }
 
 /* Create the vector of fields, and attach it to the type.  */
@@ -14898,7 +14958,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 
   fnp->type = alloc_type (objfile);
   this_type = read_type_die (die, cu);
-  if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
+  if (this_type && this_type->code () == TYPE_CODE_FUNC)
     {
       int nparams = TYPE_NFIELDS (this_type);
 
@@ -15096,7 +15156,7 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
   struct type *pfn_type, *self_type, *new_type;
 
   /* Check for a structure with no name and two children.  */
-  if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
+  if (type->code () != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
     return;
 
   /* Check for __pfn and __delta members.  */
@@ -15109,15 +15169,15 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
   /* Find the type of the method.  */
   pfn_type = TYPE_FIELD_TYPE (type, 0);
   if (pfn_type == NULL
-      || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
-      || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
+      || pfn_type->code () != TYPE_CODE_PTR
+      || TYPE_TARGET_TYPE (pfn_type)->code () != TYPE_CODE_FUNC)
     return;
 
   /* Look for the "this" argument.  */
   pfn_type = TYPE_TARGET_TYPE (pfn_type);
   if (TYPE_NFIELDS (pfn_type) == 0
       /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
-      || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
+      || TYPE_FIELD_TYPE (pfn_type, 0)->code () != TYPE_CODE_PTR)
     return;
 
   self_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
@@ -15296,27 +15356,27 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
          if (get_die_type (die, cu) != NULL)
            return get_die_type (die, cu);
 
-         TYPE_NAME (type) = full_name;
+         type->set_name (full_name);
        }
       else
        {
          /* The name is already allocated along with this objfile, so
             we don't need to duplicate it for the type.  */
-         TYPE_NAME (type) = name;
+         type->set_name (name);
        }
     }
 
   if (die->tag == DW_TAG_structure_type)
     {
-      TYPE_CODE (type) = TYPE_CODE_STRUCT;
+      type->set_code (TYPE_CODE_STRUCT);
     }
   else if (die->tag == DW_TAG_union_type)
     {
-      TYPE_CODE (type) = TYPE_CODE_UNION;
+      type->set_code (TYPE_CODE_UNION);
     }
   else
     {
-      TYPE_CODE (type) = TYPE_CODE_STRUCT;
+      type->set_code (TYPE_CODE_STRUCT);
     }
 
   if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
@@ -15344,7 +15404,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
          struct dynamic_prop prop;
          if (attr_to_dynamic_prop (attr, die, cu, &prop,
                                    cu->per_cu->addr_type ()))
-           add_dyn_prop (DYN_PROP_BYTE_SIZE, prop, type);
+           type->add_dyn_prop (DYN_PROP_BYTE_SIZE, prop);
           TYPE_LENGTH (type) = 0;
        }
     }
@@ -15740,7 +15800,8 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
      these DIEs are identified by the fact that they have no byte_size
      attribute, and a declaration attribute.  */
   if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
-      || !die_is_declaration (die, cu))
+      || !die_is_declaration (die, cu)
+      || dwarf2_attr (die, DW_AT_signature, cu) != NULL)
     {
       struct symbol *sym = new_symbol (die, type, cu);
 
@@ -15778,8 +15839,9 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
     }
 }
 
-/* Assuming DIE is an enumeration type, and TYPE is its associated type,
-   update TYPE using some information only available in DIE's children.  */
+/* Assuming DIE is an enumeration type, and TYPE is its associated
+   type, update TYPE using some information only available in DIE's
+   children.  In particular, the fields are computed.  */
 
 static void
 update_enumeration_type_from_children (struct die_info *die,
@@ -15791,6 +15853,7 @@ update_enumeration_type_from_children (struct die_info *die,
   int flag_enum = 1;
 
   auto_obstack obstack;
+  std::vector<struct field> fields;
 
   for (child_die = die->child;
        child_die != NULL && child_die->tag;
@@ -15826,10 +15889,19 @@ update_enumeration_type_from_children (struct die_info *die,
            flag_enum = 0;
        }
 
-      /* If we already know that the enum type is neither unsigned, nor
-        a flag type, no need to look at the rest of the enumerates.  */
-      if (!unsigned_enum && !flag_enum)
-       break;
+      fields.emplace_back ();
+      struct field &field = fields.back ();
+      FIELD_NAME (field) = dwarf2_physname (name, child_die, cu);
+      SET_FIELD_ENUMVAL (field, value);
+    }
+
+  if (!fields.empty ())
+    {
+      TYPE_NFIELDS (type) = fields.size ();
+      TYPE_FIELDS (type) = (struct field *)
+       TYPE_ALLOC (type, sizeof (struct field) * fields.size ());
+      memcpy (TYPE_FIELDS (type), fields.data (),
+             sizeof (struct field) * fields.size ());
     }
 
   if (unsigned_enum)
@@ -15864,10 +15936,10 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
 
   type = alloc_type (objfile);
 
-  TYPE_CODE (type) = TYPE_CODE_ENUM;
+  type->set_code (TYPE_CODE_ENUM);
   name = dwarf2_full_name (NULL, die, cu);
   if (name != NULL)
-    TYPE_NAME (type) = name;
+    type->set_name (name);
 
   attr = dwarf2_attr (die, DW_AT_type, cu);
   if (attr != NULL)
@@ -15897,11 +15969,6 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
   if (die_is_declaration (die, cu))
     TYPE_STUB (type) = 1;
 
-  /* Finish the creation of this type by using the enum's children.
-     We must call this even when the underlying type has been provided
-     so that we can determine if we're looking at a "flag" enum.  */
-  update_enumeration_type_from_children (die, type, cu);
-
   /* If this type has an underlying type that is not a stub, then we
      may use its attributes.  We always use the "unsigned" attribute
      in this situation, because ordinarily we guess whether the type
@@ -15923,7 +15990,15 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
 
   TYPE_DECLARED_CLASS (type) = dwarf2_flag_true_p (die, DW_AT_enum_class, cu);
 
-  return set_die_type (die, type, cu);
+  set_die_type (die, type, cu);
+
+  /* Finish the creation of this type by using the enum's children.
+     Note that, as usual, this must come after set_die_type to avoid
+     infinite recursion when trying to compute the names of the
+     enumerators.  */
+  update_enumeration_type_from_children (die, type, cu);
+
+  return type;
 }
 
 /* Given a pointer to a die which begins an enumeration, process all
@@ -15944,8 +16019,6 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
   if (die->child != NULL)
     {
       struct die_info *child_die;
-      struct symbol *sym;
-      std::vector<struct field> fields;
       const char *name;
 
       child_die = die->child;
@@ -15959,30 +16032,11 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
            {
              name = dwarf2_name (child_die, cu);
              if (name)
-               {
-                 sym = new_symbol (child_die, this_type, cu);
-
-                 fields.emplace_back ();
-                 struct field &field = fields.back ();
-
-                 FIELD_NAME (field) = sym->linkage_name ();
-                 FIELD_TYPE (field) = NULL;
-                 SET_FIELD_ENUMVAL (field, SYMBOL_VALUE (sym));
-                 FIELD_BITSIZE (field) = 0;
-               }
+               new_symbol (child_die, this_type, cu);
            }
 
          child_die = child_die->sibling;
        }
-
-      if (!fields.empty ())
-       {
-         TYPE_NFIELDS (this_type) = fields.size ();
-         TYPE_FIELDS (this_type) = (struct field *)
-           TYPE_ALLOC (this_type, sizeof (struct field) * fields.size ());
-         memcpy (TYPE_FIELDS (this_type), fields.data (),
-                 sizeof (struct field) * fields.size ());
-       }
     }
 
   /* If we are reading an enum from a .debug_types unit, and the enum
@@ -16132,7 +16186,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
 
   name = dwarf2_name (die, cu);
   if (name)
-    TYPE_NAME (type) = name;
+    type->set_name (name);
 
   maybe_set_alignment (cu, die, type);
 
@@ -16624,9 +16678,9 @@ read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
   if (type)
     return type;
 
-  if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
+  if (check_typedef (to_type)->code () == TYPE_CODE_METHOD)
     type = lookup_methodptr_type (to_type);
-  else if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_FUNC)
+  else if (check_typedef (to_type)->code () == TYPE_CODE_FUNC)
     {
       struct type *new_type
        = alloc_type (cu->per_cu->dwarf2_per_objfile->objfile);
@@ -16691,7 +16745,7 @@ add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu,
   base_type = copy_type (base_type);
   inner_array = base_type;
 
-  while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
+  while (TYPE_TARGET_TYPE (inner_array)->code () == TYPE_CODE_ARRAY)
     {
       TYPE_TARGET_TYPE (inner_array) =
        copy_type (TYPE_TARGET_TYPE (inner_array));
@@ -16720,7 +16774,7 @@ read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
 
   /* In case the const qualifier is applied to an array type, the element type
      is so qualified, not the array type (section 6.7.3 of C99).  */
-  if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
+  if (base_type->code () == TYPE_CODE_ARRAY)
     return add_array_cv_type (die, cu, base_type, 1, 0);
 
   cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
@@ -16742,7 +16796,7 @@ read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
   /* In case the volatile qualifier is applied to an array type, the
      element type is so qualified, not the array type (section 6.7.3
      of C99).  */
-  if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
+  if (base_type->code () == TYPE_CODE_ARRAY)
     return add_array_cv_type (die, cu, base_type, 0, 1);
 
   cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
@@ -17268,7 +17322,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
       case DW_ATE_complex_float:
        type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name,
                                                byte_order);
-       if (TYPE_CODE (type) == TYPE_CODE_ERROR)
+       if (type->code () == TYPE_CODE_ERROR)
          {
            if (name == nullptr)
              {
@@ -17523,7 +17577,7 @@ read_subrange_index_type (struct die_info *die, struct dwarf2_cu *cu)
      GCC produces an empty range DIE.
      FIXME: muller/2010-05-28: Possible references to object for low bound,
      high bound or count are not yet handled by this code.  */
-  if (TYPE_CODE (index_type) == TYPE_CODE_VOID)
+  if (index_type->code () == TYPE_CODE_VOID)
     index_type = cu->per_cu->addr_sized_int_type (false);
 
   return index_type;
@@ -17703,7 +17757,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 
   name = dwarf2_name (die, cu);
   if (name)
-    TYPE_NAME (range_type) = name;
+    range_type->set_name (name);
 
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr != nullptr)
@@ -17726,7 +17780,7 @@ read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
 
   type = init_type (cu->per_cu->dwarf2_per_objfile->objfile, TYPE_CODE_VOID,0,
                    NULL);
-  TYPE_NAME (type) = dwarf2_name (die, cu);
+  type->set_name (dwarf2_name (die, cu));
 
   /* In Ada, an unspecified type is typically used when the description
      of the type is deferred to a different unit.  When encountering
@@ -20546,25 +20600,31 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
   name = dwarf2_name (die, cu);
   if (name)
     {
-      const char *linkagename;
       int suppress_add = 0;
 
       if (space)
        sym = space;
       else
-       sym = allocate_symbol (objfile);
+       sym = new (&objfile->objfile_obstack) symbol;
       OBJSTAT (objfile, n_syms++);
 
       /* Cache this symbol's name and the name's demangled form (if any).  */
       sym->set_language (cu->language, &objfile->objfile_obstack);
-      linkagename = dwarf2_physname (name, die, cu);
-      sym->compute_and_set_names (linkagename, false, objfile->per_bfd);
-
       /* 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) == NULL)
-       sym->set_demangled_name (dwarf2_full_name (name, die, cu), NULL);
+      const char *physname
+       = (cu->language == language_fortran
+          ? dwarf2_full_name (name, die, cu)
+          : dwarf2_physname (name, die, cu));
+      const char *linkagename = dw2_linkage_name (die, cu);
+
+      if (linkagename == nullptr || cu->language == language_ada)
+       sym->set_linkage_name (physname);
+      else
+       {
+         sym->set_demangled_name (physname, &objfile->objfile_obstack);
+         sym->set_linkage_name (linkagename);
+       }
 
       /* Default assumptions.
          Use the passed type or decode it from the die.  */
@@ -20656,7 +20716,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
          /* Compilation with minimal debug info may result in
             variables with missing type entries.  Change the
             misleading `void' type to something sensible.  */
-         if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
+         if (SYMBOL_TYPE (sym)->code () == TYPE_CODE_VOID)
            SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_int;
 
          attr = dwarf2_attr (die, DW_AT_const_value, cu);
@@ -20845,7 +20905,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)) = sym->search_name ();
+                     SYMBOL_TYPE (sym)->set_name (sym->search_name ());
                  }
              }
          }
@@ -21725,13 +21785,11 @@ dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu,
 {
   if (name && cu->language == language_cplus)
     {
-      std::string canon_name = cp_canonicalize_string (name);
+      gdb::unique_xmalloc_ptr<char> canon_name
+       = cp_canonicalize_string (name);
 
-      if (!canon_name.empty ())
-       {
-         if (canon_name != name)
-           name = objfile->intern (canon_name);
-       }
+      if (canon_name != nullptr)
+       name = objfile->intern (canon_name.get ());
     }
 
   return name;
@@ -23580,11 +23638,11 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
      But this is not a problem, because the gnat-specific information
      is actually not needed for these types.  */
   if (need_gnat_info (cu)
-      && TYPE_CODE (type) != TYPE_CODE_FUNC
-      && TYPE_CODE (type) != TYPE_CODE_FLT
-      && TYPE_CODE (type) != TYPE_CODE_METHODPTR
-      && TYPE_CODE (type) != TYPE_CODE_MEMBERPTR
-      && TYPE_CODE (type) != TYPE_CODE_METHOD
+      && type->code () != TYPE_CODE_FUNC
+      && type->code () != TYPE_CODE_FLT
+      && type->code () != TYPE_CODE_METHODPTR
+      && type->code () != TYPE_CODE_MEMBERPTR
+      && type->code () != TYPE_CODE_METHOD
       && !HAVE_GNAT_AUX_INFO (type))
     INIT_GNAT_SPECIFIC (type);
 
@@ -23594,7 +23652,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
     {
       struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
       if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
-        add_dyn_prop (DYN_PROP_ALLOCATED, prop, type);
+        type->add_dyn_prop (DYN_PROP_ALLOCATED, prop);
     }
   else if (attr != NULL)
     {
@@ -23609,7 +23667,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
     {
       struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
       if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
-        add_dyn_prop (DYN_PROP_ASSOCIATED, prop, type);
+        type->add_dyn_prop (DYN_PROP_ASSOCIATED, prop);
     }
   else if (attr != NULL)
     {
@@ -23622,7 +23680,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_data_location, cu);
   if (attr_to_dynamic_prop (attr, die, cu, &prop,
                            cu->per_cu->addr_type ()))
-    add_dyn_prop (DYN_PROP_DATA_LOCATION, prop, type);
+    type->add_dyn_prop (DYN_PROP_DATA_LOCATION, prop);
 
   if (dwarf2_per_objfile->die_type_hash == NULL)
     dwarf2_per_objfile->die_type_hash