Use std::string in dwarf2read.c
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 9d9dd6db709d78013db992f366e73adfecac8470..40af0b975ba85d22058cd0c25002e2573494bb02 100644 (file)
@@ -1,6 +1,6 @@
 /* DWARF 2 debugging format support for GDB.
 
-   Copyright (C) 1994-2019 Free Software Foundation, Inc.
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
    Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
    Inc.  with support from Florida State University (under contract
@@ -41,7 +41,6 @@
 #include "buildsym.h"
 #include "demangle.h"
 #include "gdb-demangle.h"
-#include "expression.h"
 #include "filenames.h" /* for DOSish file names */
 #include "macrotab.h"
 #include "language.h"
 #include "addrmap.h"
 #include "typeprint.h"
 #include "psympriv.h"
-#include <sys/stat.h>
-#include "completer.h"
-#include "gdbsupport/vec.h"
 #include "c-lang.h"
 #include "go-lang.h"
 #include "valprint.h"
 #include "gdbcore.h" /* for gnutarget */
 #include "gdb/gdb-index.h"
-#include <ctype.h>
 #include "gdb_bfd.h"
 #include "f-lang.h"
 #include "source.h"
-#include "gdbsupport/filestuff.h"
 #include "build-id.h"
 #include "namespace.h"
-#include "gdbsupport/gdb_unlinker.h"
 #include "gdbsupport/function-view.h"
 #include "gdbsupport/gdb_optional.h"
 #include "gdbsupport/underlying.h"
-#include "gdbsupport/byte-vector.h"
 #include "gdbsupport/hash_enum.h"
 #include "filename-seen-cache.h"
 #include "producer.h"
 #include <fcntl.h>
-#include <sys/types.h>
 #include <algorithm>
-#include <unordered_set>
 #include <unordered_map>
 #include "gdbsupport/selftest.h"
-#include <cmath>
-#include <set>
-#include <forward_list>
 #include "rust-lang.h"
 #include "gdbsupport/pathstuff.h"
 
@@ -922,13 +909,13 @@ typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader,
                                      int has_children,
                                      void *data);
 
-/* A 1-based directory index.  This is a strong typedef to prevent
-   accidentally using a directory index as a 0-based index into an
-   array/vector.  */
-enum class dir_index : unsigned int {};
+/* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
+   later.  */
+typedef int dir_index;
 
-/* Likewise, a 1-based file name index.  */
-enum class file_name_index : unsigned int {};
+/* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
+   and later.  */
+typedef int file_name_index;
 
 struct file_entry
 {
@@ -980,32 +967,47 @@ struct line_header
   void add_file_name (const char *name, dir_index d_index,
                      unsigned int mod_time, unsigned int length);
 
-  /* Return the include dir at INDEX (1-based).  Returns NULL if INDEX
-     is out of bounds.  */
+  /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
+     Returns NULL if INDEX is out of bounds.  */
   const char *include_dir_at (dir_index index) const
   {
-    /* Convert directory index number (1-based) to vector index
-       (0-based).  */
-    size_t vec_index = to_underlying (index) - 1;
-
-    if (vec_index >= include_dirs.size ())
+    int vec_index;
+    if (version >= 5)
+      vec_index = index;
+    else
+      vec_index = index - 1;
+    if (vec_index < 0 || vec_index >= m_include_dirs.size ())
       return NULL;
-    return include_dirs[vec_index];
+    return m_include_dirs[vec_index];
   }
 
-  /* Return the file name at INDEX (1-based).  Returns NULL if INDEX
-     is out of bounds.  */
-  file_entry *file_name_at (file_name_index index)
+  bool is_valid_file_index (int file_index)
   {
-    /* Convert file name index number (1-based) to vector index
-       (0-based).  */
-    size_t vec_index = to_underlying (index) - 1;
+    if (version >= 5)
+      return 0 <= file_index && file_index < file_names_size ();
+    return 1 <= file_index && file_index <= file_names_size ();
+  }
 
-    if (vec_index >= file_names.size ())
+  /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
+     Returns NULL if INDEX is out of bounds.  */
+  file_entry *file_name_at (file_name_index index)
+  {
+    int vec_index;
+    if (version >= 5)
+      vec_index = index;
+    else
+      vec_index = index - 1;
+    if (vec_index < 0 || vec_index >= m_file_names.size ())
       return NULL;
-    return &file_names[vec_index];
+    return &m_file_names[vec_index];
   }
 
+  /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
+     this method should only be used to iterate through all file entries in an
+     index-agnostic manner.  */
+  std::vector<file_entry> &file_names ()
+  { return m_file_names; }
+
   /* Offset of line number information in .debug_line section.  */
   sect_offset sect_off {};
 
@@ -1028,16 +1030,23 @@ struct line_header
      element is standard_opcode_lengths[opcode_base - 1].  */
   std::unique_ptr<unsigned char[]> standard_opcode_lengths;
 
-  /* The include_directories table.  Note these are observing
-     pointers.  The memory is owned by debug_line_buffer.  */
-  std::vector<const char *> include_dirs;
-
-  /* The file_names table.  */
-  std::vector<file_entry> file_names;
+  int file_names_size ()
+  { return m_file_names.size(); }
 
   /* The start and end of the statement program following this
      header.  These point into dwarf2_per_objfile->line_buffer.  */
   const gdb_byte *statement_program_start {}, *statement_program_end {};
+
+ private:
+  /* The include_directories table.  Note these are observing
+     pointers.  The memory is owned by debug_line_buffer.  */
+  std::vector<const char *> m_include_dirs;
+
+  /* The file_names table. This is private because the meaning of indexes
+     differs among DWARF versions (The first valid index is 1 in DWARF 4 and
+     before, and is 0 in DWARF 5 and later).  So the client should use
+     file_name_at method for access.  */
+  std::vector<file_entry> m_file_names;
 };
 
 typedef std::unique_ptr<line_header> line_header_up;
@@ -1330,15 +1339,6 @@ struct dwarf_block
     const gdb_byte *data;
   };
 
-#ifndef ATTR_ALLOC_CHUNK
-#define ATTR_ALLOC_CHUNK 4
-#endif
-
-/* Allocate fields for structs, unions and enums in this size.  */
-#ifndef DW_FIELD_ALLOC_CHUNK
-#define DW_FIELD_ALLOC_CHUNK 4
-#endif
-
 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
    but this would require a corresponding change in unpack_field_as_long
    and friends.  */
@@ -1388,7 +1388,7 @@ struct field_info
     /* Number of fields (including baseclasses).  */
     int nfields = 0;
 
-    /* Set if the accesibility of one of the fields is not public.  */
+    /* Set if the accessibility of one of the fields is not public.  */
     int non_public_fields = 0;
 
     /* Member function fieldlist array, contains name of possibly overloaded
@@ -1499,7 +1499,7 @@ struct cu_partial_die_info
   cu_partial_die_info (struct dwarf2_cu *cu, struct partial_die_info *pdi)
     : cu (cu),
       pdi (pdi)
-  { /* Nothhing.  */ }
+  { /* Nothing.  */ }
 
 private:
   cu_partial_die_info () = delete;
@@ -1901,6 +1901,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
@@ -2164,10 +2167,10 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
     htab_delete (line_header_hash);
 
   for (dwarf2_per_cu_data *per_cu : all_comp_units)
-    VEC_free (dwarf2_per_cu_ptr, per_cu->imported_symtabs);
+    per_cu->imported_symtabs_free ();
 
   for (signatured_type *sig_type : all_type_units)
-    VEC_free (dwarf2_per_cu_ptr, sig_type->per_cu.imported_symtabs);
+    sig_type->per_cu.imported_symtabs_free ();
 
   /* Everything else should be on the objfile obstack.  */
 }
@@ -2351,6 +2354,15 @@ dwarf2_per_objfile::locate_sections (bfd *abfd, asection *sectp,
   if ((aflag & SEC_HAS_CONTENTS) == 0)
     {
     }
+  else if (elf_section_data (sectp)->this_hdr.sh_size
+          > bfd_get_file_size (abfd))
+    {
+      bfd_size_type size = elf_section_data (sectp)->this_hdr.sh_size;
+      warning (_("Discarding section %s which has a section size (%s"
+                ") larger than the file size [in module %s]"),
+              bfd_section_name (sectp), phex_nz (size, sizeof (size)),
+              bfd_get_filename (abfd));
+    }
   else if (section_is_p (sectp->name, &names.info))
     {
       this->info.s.section = sectp;
@@ -3644,7 +3656,6 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct dwarf2_per_cu_data *lh_cu;
   struct attribute *attr;
-  int i;
   void **slot;
   struct quick_file_names *qfn;
 
@@ -3665,7 +3676,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;
 
@@ -3703,12 +3714,12 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
   if (strcmp (fnd.name, "<unknown>") != 0)
     ++offset;
 
-  qfn->num_file_names = offset + lh->file_names.size ();
+  qfn->num_file_names = offset + lh->file_names_size ();
   qfn->file_names =
     XOBNEWVEC (&objfile->objfile_obstack, const char *, qfn->num_file_names);
   if (offset != 0)
     qfn->file_names[0] = xstrdup (fnd.name);
-  for (i = 0; i < lh->file_names.size (); ++i)
+  for (int i = 0; i < lh->file_names_size (); ++i)
     qfn->file_names[i + offset] = file_full_name (i + 1, lh.get (), fnd.comp_dir);
   qfn->real_names = NULL;
 
@@ -4025,6 +4036,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;
            }
@@ -5047,6 +5062,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;
            }
@@ -5953,6 +5972,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;
     }
@@ -5989,6 +6017,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;
     }
@@ -6031,10 +6067,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.  */
@@ -6377,7 +6413,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;
@@ -6385,7 +6421,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;
@@ -6649,7 +6685,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.  */
@@ -7234,14 +7270,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)
@@ -8092,24 +8128,23 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 
   end_psymtab_common (objfile, pst);
 
-  if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs))
+  if (!cu->per_cu->imported_symtabs_empty ())
     {
       int i;
-      int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs);
-      struct dwarf2_per_cu_data *iter;
+      int len = cu->per_cu->imported_symtabs_size ();
 
       /* Fill in 'dependencies' here; we fill in 'users' in a
         post-pass.  */
       pst->number_of_dependencies = len;
       pst->dependencies
        = objfile->partial_symtabs->allocate_dependencies (len);
-      for (i = 0;
-          VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
-                       i, iter);
-          ++i)
-       pst->dependencies[i] = iter->v.psymtab;
+      for (i = 0; i < len; ++i)
+       {
+         pst->dependencies[i]
+           = cu->per_cu->imported_symtabs->at (i)->v.psymtab;
+       }
 
-      VEC_free (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs);
+      cu->per_cu->imported_symtabs_free ();
     }
 
   /* Get the list of files included in the current compilation unit,
@@ -8717,7 +8752,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:
              {
@@ -8739,8 +8775,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
                if (per_cu->v.psymtab == NULL)
                  process_psymtab_comp_unit (per_cu, 1, cu->language);
 
-               VEC_safe_push (dwarf2_per_cu_ptr,
-                              cu->per_cu->imported_symtabs, per_cu);
+               cu->per_cu->imported_symtabs_push (per_cu);
              }
              break;
            case DW_TAG_imported_declaration:
@@ -8823,6 +8858,7 @@ partial_die_parent_scope (struct partial_die_info *pdi,
       return NULL;
     }
 
+  /* Nested subroutines in Fortran get a prefix.  */
   if (pdi->tag == DW_TAG_enumerator)
     /* Enumerators should not get the name of the enumeration as a prefix.  */
     parent->scope = grandparent_scope;
@@ -8832,7 +8868,10 @@ partial_die_parent_scope (struct partial_die_info *pdi,
       || parent->tag == DW_TAG_class_type
       || parent->tag == DW_TAG_interface_type
       || parent->tag == DW_TAG_union_type
-      || parent->tag == DW_TAG_enumeration_type)
+      || parent->tag == DW_TAG_enumeration_type
+      || (cu->language == language_fortran
+         && parent->tag == DW_TAG_subprogram
+         && pdi->tag == DW_TAG_subprogram))
     {
       if (grandparent_scope == NULL)
        parent->scope = parent->name;
@@ -8859,7 +8898,7 @@ partial_die_parent_scope (struct partial_die_info *pdi,
 /* Return the fully scoped name associated with PDI, from compilation unit
    CU.  The result will be allocated with malloc.  */
 
-static char *
+static gdb::unique_xmalloc_ptr<char>
 partial_die_full_name (struct partial_die_info *pdi,
                       struct dwarf2_cu *cu)
 {
@@ -8885,7 +8924,7 @@ partial_die_full_name (struct partial_die_info *pdi,
          attr.u.unsnd = to_underlying (pdi->sect_off);
          die = follow_die_ref (NULL, &attr, &ref_cu);
 
-         return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
+         return make_unique_xstrdup (dwarf2_full_name (NULL, die, ref_cu));
        }
     }
 
@@ -8893,7 +8932,8 @@ partial_die_full_name (struct partial_die_info *pdi,
   if (parent_scope == NULL)
     return NULL;
   else
-    return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
+    return gdb::unique_xmalloc_ptr<char> (typename_concat (NULL, parent_scope,
+                                                          pdi->name, 0, cu));
 }
 
 static void
@@ -8906,13 +8946,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
   CORE_ADDR addr = 0;
   const char *actual_name = NULL;
   CORE_ADDR baseaddr;
-  char *built_actual_name;
 
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
-  built_actual_name = partial_die_full_name (pdi, cu);
+  gdb::unique_xmalloc_ptr<char> built_actual_name
+    = partial_die_full_name (pdi, cu);
   if (built_actual_name != NULL)
-    actual_name = built_actual_name;
+    actual_name = built_actual_name.get ();
 
   if (actual_name == NULL)
     actual_name = pdi->name;
@@ -8923,13 +8963,17 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     case DW_TAG_subprogram:
       addr = (gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr)
              - baseaddr);
-      if (pdi->is_external || cu->language == language_ada)
-       {
-          /* brobecker/2007-12-26: Normally, only "external" DIEs are part
-             of the global scope.  But in Ada, we want to be able to access
-             nested procedures globally.  So all Ada subprograms are stored
-             in the global scope.  */
-         add_psymbol_to_list (actual_name, strlen (actual_name),
+      if (pdi->is_external
+         || cu->language == language_ada
+         || (cu->language == language_fortran
+             && pdi->die_parent != NULL
+             && pdi->die_parent->tag == DW_TAG_subprogram))
+       {
+          /* Normally, only "external" DIEs are part of the global scope.
+             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,
                               built_actual_name != NULL,
                               VAR_DOMAIN, LOC_BLOCK,
                               SECT_OFF_TEXT (objfile),
@@ -8939,7 +8983,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),
@@ -8951,7 +8995,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
@@ -8987,7 +9031,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),
@@ -9001,12 +9045,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          /* Static Variable.  Skip symbols whose value we cannot know (those
             without location descriptors or constant values).  */
          if (!has_loc && !pdi->has_const_value)
-           {
-             xfree (built_actual_name);
-             return;
-           }
+           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),
@@ -9018,7 +9059,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,
@@ -9026,7 +9067,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,
@@ -9037,7 +9078,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,
@@ -9054,14 +9095,11 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          union or class entry that does not have a byte size attribute
          and that has a DW_AT_declaration attribute."  */
       if (!pdi->has_byte_size && pdi->is_declaration)
-       {
-         xfree (built_actual_name);
-         return;
-       }
+       return;
 
       /* 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
@@ -9071,7 +9109,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
@@ -9082,8 +9120,6 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     default:
       break;
     }
-
-  xfree (built_actual_name);
 }
 
 /* Read a partial die corresponding to a namespace; also, add a symbol
@@ -9184,7 +9220,7 @@ add_partial_subprogram (struct partial_die_info *pdi,
   if (! pdi->has_children)
     return;
 
-  if (cu->language == language_ada)
+  if (cu->language == language_ada || cu->language == language_fortran)
     {
       pdi = pdi->die_child;
       while (pdi != NULL)
@@ -9852,7 +9888,7 @@ compute_delayed_physnames (struct dwarf2_cu *cu)
 static void
 fixup_go_packaging (struct dwarf2_cu *cu)
 {
-  char *package_name = NULL;
+  gdb::unique_xmalloc_ptr<char> package_name;
   struct pending *list;
   int i;
 
@@ -9864,27 +9900,27 @@ fixup_go_packaging (struct dwarf2_cu *cu)
        {
          struct symbol *sym = list->symbol[i];
 
-         if (SYMBOL_LANGUAGE (sym) == language_go
+         if (sym->language () == language_go
              && SYMBOL_CLASS (sym) == LOC_BLOCK)
            {
-             char *this_package_name = go_symbol_package_name (sym);
+             gdb::unique_xmalloc_ptr<char> this_package_name
+               (go_symbol_package_name (sym));
 
              if (this_package_name == NULL)
                continue;
              if (package_name == NULL)
-               package_name = this_package_name;
+               package_name = std::move (this_package_name);
              else
                {
                  struct objfile *objfile
                    = cu->per_cu->dwarf2_per_objfile->objfile;
-                 if (strcmp (package_name, this_package_name) != 0)
+                 if (strcmp (package_name.get (), this_package_name.get ()) != 0)
                    complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
                               (symbol_symtab (sym) != NULL
                                ? symtab_to_filename_for_display
                                    (symbol_symtab (sym))
                                : objfile_name (objfile)),
-                              this_package_name, package_name);
-                 xfree (this_package_name);
+                              this_package_name.get (), package_name.get ());
                }
            }
        }
@@ -9894,15 +9930,14 @@ fixup_go_packaging (struct dwarf2_cu *cu)
     {
       struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
       const char *saved_package_name
-       = obstack_strdup (&objfile->per_bfd->storage_obstack, package_name);
+       = obstack_strdup (&objfile->per_bfd->storage_obstack, package_name.get ());
       struct type *type = init_type (objfile, TYPE_CODE_MODULE, 0,
                                     saved_package_name);
       struct symbol *sym;
 
       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);
+      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,
         e.g., "main" finds the "main" module and not C's main().  */
       SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
@@ -9910,8 +9945,6 @@ fixup_go_packaging (struct dwarf2_cu *cu)
       SYMBOL_TYPE (sym) = type;
 
       add_symbol_to_list (sym, cu->get_builder ()->get_global_symbols ());
-
-      xfree (package_name);
     }
 }
 
@@ -10068,10 +10101,10 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       SET_FIELD_BITPOS (TYPE_FIELD (type, 0), 0);
       TYPE_FIELD_NAME (type, 0) = "<<variants>>";
     }
-  else if (TYPE_NFIELDS (type) == 1)
+  /* A union with a single anonymous field is probably an old-style
+     univariant enum.  */
+  else if (TYPE_NFIELDS (type) == 1 && streq (TYPE_FIELD_NAME (type, 0), ""))
     {
-      /* We assume that a union with a single field is a univariant
-        enum.  */
       /* 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;
@@ -10248,9 +10281,7 @@ recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
                                struct compunit_symtab *immediate_parent)
 {
   void **slot;
-  int ix;
   struct compunit_symtab *cust;
-  struct dwarf2_per_cu_data *iter;
 
   slot = htab_find_slot (all_children, per_cu, INSERT);
   if (*slot != NULL)
@@ -10285,13 +10316,12 @@ recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
        }
     }
 
-  for (ix = 0;
-       VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter);
-       ++ix)
-    {
-      recursively_compute_inclusions (result, all_children,
-                                     all_type_symtabs, iter, cust);
-    }
+  if (!per_cu->imported_symtabs_empty ())
+    for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
+      {
+       recursively_compute_inclusions (result, all_children,
+                                       all_type_symtabs, ptr, cust);
+      }
 }
 
 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
@@ -10302,10 +10332,9 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
 {
   gdb_assert (! per_cu->is_debug_types);
 
-  if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs))
+  if (!per_cu->imported_symtabs_empty ())
     {
-      int ix, len;
-      struct dwarf2_per_cu_data *per_cu_iter;
+      int len;
       std::vector<compunit_symtab *> result_symtabs;
       htab_t all_children, all_type_symtabs;
       struct compunit_symtab *cust = get_compunit_symtab (per_cu);
@@ -10319,14 +10348,10 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
       all_type_symtabs = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
                                            NULL, xcalloc, xfree);
 
-      for (ix = 0;
-          VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs,
-                       ix, per_cu_iter);
-          ++ix)
+      for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
        {
          recursively_compute_inclusions (&result_symtabs, all_children,
-                                         all_type_symtabs, per_cu_iter,
-                                         cust);
+                                         all_type_symtabs, ptr, cust);
        }
 
       /* Now we have a transitive closure of all the included symtabs.  */
@@ -10570,8 +10595,7 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
       if (maybe_queue_comp_unit (cu, per_cu, cu->language))
        load_full_comp_unit (per_cu, false, cu->language);
 
-      VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
-                    per_cu);
+      cu->per_cu->imported_symtabs_push (per_cu);
     }
 }
 
@@ -10626,6 +10650,12 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
       read_type_unit_scope (die, cu);
       break;
     case DW_TAG_subprogram:
+      /* Nested subprograms in Fortran get a prefix.  */
+      if (cu->language == language_fortran
+         && die->parent != NULL
+         && die->parent->tag == DW_TAG_subprogram)
+       cu->processing_has_namespace_info = true;
+      /* Fall through.  */
     case DW_TAG_inlined_subroutine:
       read_func_scope (die, cu);
       break;
@@ -10830,7 +10860,7 @@ dwarf2_compute_name (const char *name,
   /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
      but otherwise compute it by typename_concat inside GDB.
      FIXME: Actually this is not really true, or at least not always true.
-     It's all very confusing.  SYMBOL_SET_NAMES doesn't try to demangle
+     It's all very confusing.  compute_and_set_names doesn't try to demangle
      Fortran names because there is no mangling standard.  So new_symbol
      will set the demangled name to the result of dwarf2_full_name, and it is
      the demangled name that GDB uses if it exists.  */
@@ -10864,11 +10894,10 @@ dwarf2_compute_name (const char *name,
          prefix = determine_prefix (die, cu);
          if (*prefix != '\0')
            {
-             char *prefixed_name = typename_concat (NULL, prefix, name,
-                                                    physname, cu);
+             gdb::unique_xmalloc_ptr<char> prefixed_name
+               (typename_concat (NULL, prefix, name, physname, cu));
 
-             buf.puts (prefixed_name);
-             xfree (prefixed_name);
+             buf.puts (prefixed_name.get ());
            }
          else
            buf.puts (name);
@@ -11703,14 +11732,14 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
         process_full_type_unit still needs to know if this is the first
         time.  */
 
-      tu_group->num_symtabs = line_header->file_names.size ();
+      tu_group->num_symtabs = line_header->file_names_size ();
       tu_group->symtabs = XNEWVEC (struct symtab *,
-                                  line_header->file_names.size ());
+                                  line_header->file_names_size ());
 
-      for (i = 0; i < line_header->file_names.size (); ++i)
+      auto &file_names = line_header->file_names ();
+      for (i = 0; i < file_names.size (); ++i)
        {
-         file_entry &fe = line_header->file_names[i];
-
+         file_entry &fe = file_names[i];
          dwarf2_start_subfile (this, fe.name,
                                fe.include_dir (line_header));
          buildsym_compunit *b = get_builder ();
@@ -11739,10 +11768,10 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
                        compunit_language (cust),
                        0, cust));
 
-      for (i = 0; i < line_header->file_names.size (); ++i)
+      auto &file_names = line_header->file_names ();
+      for (i = 0; i < file_names.size (); ++i)
        {
-         file_entry &fe = line_header->file_names[i];
-
+         file_entry &fe = file_names[i];
          fe.symtab = tu_group->symtabs[i];
        }
     }
@@ -12910,16 +12939,15 @@ open_dwo_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   if (comp_dir != NULL)
     {
-      char *path_to_try = concat (comp_dir, SLASH_STRING,
-                                 file_name, (char *) NULL);
+      gdb::unique_xmalloc_ptr<char> path_to_try
+       (concat (comp_dir, SLASH_STRING, file_name, (char *) NULL));
 
       /* NOTE: If comp_dir is a relative path, this will also try the
         search path, which seems useful.  */
       gdb_bfd_ref_ptr abfd (try_open_dwop_file (dwarf2_per_objfile,
-                                               path_to_try,
+                                               path_to_try.get (),
                                                0 /*is_dwp*/,
                                                1 /*search_cwd*/));
-      xfree (path_to_try);
       if (abfd != NULL)
        return abfd;
     }
@@ -13497,7 +13525,7 @@ queue_and_load_dwo_tu (void **slot, void *info)
         while processing PER_CU.  */
       if (maybe_queue_comp_unit (NULL, sig_cu, per_cu->cu->language))
        load_full_type_unit (sig_cu);
-      VEC_safe_push (dwarf2_per_cu_ptr, per_cu->imported_symtabs, sig_cu);
+      per_cu->imported_symtabs_push (sig_cu);
     }
 
   return 1;
@@ -13652,6 +13680,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
@@ -13731,19 +13762,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);
@@ -14219,7 +14250,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 "
@@ -14275,8 +14306,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;
@@ -14661,7 +14691,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);
@@ -14834,7 +14864,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);
@@ -14849,7 +14879,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
@@ -14943,7 +14973,7 @@ producer_is_codewarrior (struct dwarf2_cu *cu)
   return cu->producer_is_codewarrior;
 }
 
-/* Return the default accessibility type if it is not overriden by
+/* Return the default accessibility type if it is not overridden by
    DW_AT_accessibility.  */
 
 static enum dwarf_access_attribute
@@ -15034,7 +15064,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);
@@ -15042,7 +15072,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;
@@ -15062,7 +15092,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);
        }
@@ -15075,9 +15105,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
@@ -15098,7 +15128,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
@@ -15205,13 +15235,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;
        }
     }
@@ -15417,6 +15452,25 @@ dwarf2_is_constructor (struct die_info *die, struct dwarf2_cu *cu)
          && (type_name[len] == '\0' || type_name[len] == '<'));
 }
 
+/* Check if the given VALUE is a recognized enum
+   dwarf_defaulted_attribute constant according to DWARF5 spec,
+   Table 7.24.  */
+
+static bool
+is_valid_DW_AT_defaulted (ULONGEST value)
+{
+  switch (value)
+    {
+    case DW_DEFAULTED_no:
+    case DW_DEFAULTED_in_class:
+    case DW_DEFAULTED_out_of_class:
+      return true;
+    }
+
+  complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value));
+  return false;
+}
+
 /* Add a member function to the proper fieldlist.  */
 
 static void
@@ -15510,7 +15564,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);
@@ -15529,6 +15583,16 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   if (attr && DW_UNSND (attr) != 0)
     fnp->is_artificial = 1;
 
+  /* Check for defaulted methods.  */
+  attr = dwarf2_attr (die, DW_AT_defaulted, cu);
+  if (attr != nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr)))
+    fnp->defaulted = (enum dwarf_defaulted_attribute) DW_UNSND (attr);
+
+  /* Check for deleted methods.  */
+  attr = dwarf2_attr (die, DW_AT_deleted, cu);
+  if (attr != nullptr && DW_UNSND (attr) != 0)
+    fnp->is_deleted = 1;
+
   fnp->is_constructor = dwarf2_is_constructor (die, cu);
 
   /* Get index in virtual function table if it is a virtual member
@@ -15538,7 +15602,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)
         {
@@ -15768,6 +15832,52 @@ maybe_set_alignment (struct dwarf2_cu *cu, struct die_info *die,
               objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
 }
 
+/* Check if the given VALUE is a valid enum dwarf_calling_convention
+   constant for a type, according to DWARF5 spec, Table 5.5.  */
+
+static bool
+is_valid_DW_AT_calling_convention_for_type (ULONGEST value)
+{
+  switch (value)
+    {
+    case DW_CC_normal:
+    case DW_CC_pass_by_reference:
+    case DW_CC_pass_by_value:
+      return true;
+
+    default:
+      complaint (_("unrecognized DW_AT_calling_convention value "
+                  "(%s) for a type"), pulongest (value));
+      return false;
+    }
+}
+
+/* Check if the given VALUE is a valid enum dwarf_calling_convention
+   constant for a subroutine, according to DWARF5 spec, Table 3.3, and
+   also according to GNU-specific values (see include/dwarf2.h).  */
+
+static bool
+is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value)
+{
+  switch (value)
+    {
+    case DW_CC_normal:
+    case DW_CC_program:
+    case DW_CC_nocall:
+      return true;
+
+    case DW_CC_GNU_renesas_sh:
+    case DW_CC_GNU_borland_fastcall_i386:
+    case DW_CC_GDB_IBM_OpenCL:
+      return true;
+
+    default:
+      complaint (_("unrecognized DW_AT_calling_convention value "
+                  "(%s) for a subroutine"), pulongest (value));
+      return false;
+    }
+}
+
 /* Called when we find the DIE that starts a structure or union scope
    (definition) to create a type for the structure or union.  Fill in
    the type's name and general properties; the members will not be
@@ -15792,7 +15902,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);
 
@@ -15849,8 +15959,20 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
   if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
     TYPE_DECLARED_CLASS (type) = 1;
 
+  /* Store the calling convention in the type if it's available in
+     the die.  Otherwise the calling convention remains set to
+     the default value DW_CC_normal.  */
+  attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
+  if (attr != nullptr
+      && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr)))
+    {
+      ALLOCATE_CPLUS_STRUCT_TYPE (type);
+      TYPE_CPLUS_CALLING_CONVENTION (type)
+       = (enum dwarf_calling_convention) (DW_UNSND (attr));
+    }
+
   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);
@@ -16005,7 +16127,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)
@@ -16216,7 +16338,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
            {
              /* Any related symtab will do.  */
              symtab
-               = cu->line_header->file_name_at (file_name_index (1))->symtab;
+               = cu->line_header->file_names ()[0].symtab;
            }
          else
            {
@@ -16316,7 +16438,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);
 
@@ -16341,7 +16463,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);
     }
@@ -16406,8 +16528,7 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
     {
       struct die_info *child_die;
       struct symbol *sym;
-      struct field *fields = NULL;
-      int num_fields = 0;
+      std::vector<struct field> fields;
       const char *name;
 
       child_die = die->child;
@@ -16424,34 +16545,26 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
                {
                  sym = new_symbol (child_die, this_type, cu);
 
-                 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
-                   {
-                     fields = (struct field *)
-                       xrealloc (fields,
-                                 (num_fields + DW_FIELD_ALLOC_CHUNK)
-                                 * sizeof (struct field));
-                   }
-
-                 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
-                 FIELD_TYPE (fields[num_fields]) = NULL;
-                 SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym));
-                 FIELD_BITSIZE (fields[num_fields]) = 0;
+                 fields.emplace_back ();
+                 struct field &field = fields.back ();
 
-                 num_fields++;
+                 FIELD_NAME (field) = sym->linkage_name ();
+                 FIELD_TYPE (field) = NULL;
+                 SET_FIELD_ENUMVAL (field, SYMBOL_VALUE (sym));
+                 FIELD_BITSIZE (field) = 0;
                }
            }
 
          child_die = sibling_die (child_die);
        }
 
-      if (num_fields)
+      if (!fields.empty ())
        {
-         TYPE_NFIELDS (this_type) = num_fields;
+         TYPE_NFIELDS (this_type) = fields.size ();
          TYPE_FIELDS (this_type) = (struct field *)
-           TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
-         memcpy (TYPE_FIELDS (this_type), fields,
-                 sizeof (struct field) * num_fields);
-         xfree (fields);
+           TYPE_ALLOC (this_type, sizeof (struct field) * fields.size ());
+         memcpy (TYPE_FIELDS (this_type), fields.data (),
+                 sizeof (struct field) * fields.size ());
        }
     }
 
@@ -16585,14 +16698,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);
@@ -16623,7 +16736,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
@@ -16668,7 +16781,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);
@@ -16752,7 +16865,7 @@ mark_common_block_symbol_computed (struct symbol *sym,
 /* Create appropriate locally-scoped variables for all the
    DW_TAG_common_block entries.  Also create a struct common_block
    listing all such variables for `info common'.  COMMON_BLOCK_DOMAIN
-   is used to sepate the common blocks name namespace from regular
+   is used to separate the common blocks name namespace from regular
    variable names.  */
 
 static void
@@ -16761,7 +16874,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))
@@ -16834,7 +16947,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);
                    }
@@ -17135,7 +17248,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);
     }
@@ -17268,29 +17381,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)
+    {
+      /* 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)
     {
-      length = DW_UNSND (attr);
+      /* 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);
 
@@ -17310,7 +17484,7 @@ prototyped_function_p (struct die_info *die, struct dwarf2_cu *cu)
     return 1;
 
   /* The DWARF standard implies that the DW_AT_prototyped attribute
-     is only meaninful for C, but the concept also extends to other
+     is only meaningful for C, but the concept also extends to other
      languages that allow unprototyped functions (Eg: Objective C).
      For all other languages, assume that functions are always
      prototyped.  */
@@ -17363,8 +17537,10 @@ 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)
-    TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
+  if (attr != nullptr
+      && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr)))
+    TYPE_CALLING_CONVENTION (ftype)
+      = (enum dwarf_calling_convention) (DW_UNSND (attr));
   else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
     TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
   else
@@ -17429,7 +17605,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;
@@ -17446,7 +17622,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)
@@ -17508,7 +17684,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;
@@ -17516,7 +17692,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);
 
@@ -17555,7 +17731,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;
@@ -17604,7 +17781,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
@@ -17618,21 +17795,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)
@@ -17646,14 +17840,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);
@@ -17685,8 +17880,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)
@@ -17713,6 +17906,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);
 }
 
@@ -17741,7 +17936,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);
@@ -17825,24 +18028,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);
@@ -17856,6 +18057,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.  */
@@ -17946,7 +18159,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 "
@@ -18003,7 +18216,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;
@@ -18017,7 +18275,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);
@@ -18040,7 +18298,7 @@ read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
   TYPE_NAME (type) = dwarf2_name (die, cu);
 
   /* In Ada, an unspecified type is typically used when the description
-     of the type is defered to a different unit.  When encountering
+     of the type is deferred to a different unit.  When encountering
      such a type, we treat it as a stub, and try to resolve it later on,
      when needed.  */
   if (cu->language == language_ada)
@@ -18297,8 +18555,7 @@ abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
   struct abbrev_info *cur_abbrev;
   unsigned int abbrev_number, bytes_read, abbrev_name;
   unsigned int abbrev_form;
-  struct attr_abbrev *cur_attrs;
-  unsigned int allocated_attrs;
+  std::vector<struct attr_abbrev> cur_attrs;
 
   abbrev_table_up abbrev_table (new struct abbrev_table (sect_off));
 
@@ -18307,12 +18564,10 @@ abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
   abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
   abbrev_ptr += bytes_read;
 
-  allocated_attrs = ATTR_ALLOC_CHUNK;
-  cur_attrs = XNEWVEC (struct attr_abbrev, allocated_attrs);
-
   /* Loop until we reach an abbrev number of 0.  */
   while (abbrev_number)
     {
+      cur_attrs.clear ();
       cur_abbrev = abbrev_table->alloc_abbrev ();
 
       /* read in abbrev header */
@@ -18347,25 +18602,18 @@ abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
          if (abbrev_name == 0)
            break;
 
-         if (cur_abbrev->num_attrs == allocated_attrs)
-           {
-             allocated_attrs += ATTR_ALLOC_CHUNK;
-             cur_attrs
-               = XRESIZEVEC (struct attr_abbrev, cur_attrs, allocated_attrs);
-           }
-
-         cur_attrs[cur_abbrev->num_attrs].name
-           = (enum dwarf_attribute) abbrev_name;
-         cur_attrs[cur_abbrev->num_attrs].form
-           = (enum dwarf_form) abbrev_form;
-         cur_attrs[cur_abbrev->num_attrs].implicit_const = implicit_const;
+         cur_attrs.emplace_back ();
+         struct attr_abbrev &cur_attr = cur_attrs.back ();
+         cur_attr.name = (enum dwarf_attribute) abbrev_name;
+         cur_attr.form = (enum dwarf_form) abbrev_form;
+         cur_attr.implicit_const = implicit_const;
          ++cur_abbrev->num_attrs;
        }
 
       cur_abbrev->attrs =
        XOBNEWVEC (&abbrev_table->abbrev_obstack, struct attr_abbrev,
                   cur_abbrev->num_attrs);
-      memcpy (cur_abbrev->attrs, cur_attrs,
+      memcpy (cur_abbrev->attrs, cur_attrs.data (),
              cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
 
       abbrev_table->add_abbrev (abbrev_number, cur_abbrev);
@@ -18385,7 +18633,6 @@ abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
        break;
     }
 
-  xfree (cur_attrs);
   return abbrev_table;
 }
 
@@ -18546,7 +18793,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);
@@ -18580,7 +18827,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
@@ -18653,10 +18900,10 @@ load_partial_dies (const struct die_reader_specs *reader,
         inside functions to find template arguments (if the name of the
         function does not already contain the template arguments).
 
-        For Ada, we need to scan the children of subprograms and lexical
-        blocks as well because Ada allows the definition of nested
-        entities that could be interesting for the debugger, such as
-        nested subprograms for instance.  */
+        For Ada and Fortran, we need to scan the children of subprograms
+        and lexical blocks as well because these languages allow the
+        definition of nested entities that could be interesting for the
+        debugger, such as nested subprograms for instance.  */
       if (last_die->has_children
          && (load_all
              || last_die->tag == DW_TAG_namespace
@@ -18671,7 +18918,8 @@ load_partial_dies (const struct die_reader_specs *reader,
                      || last_die->tag == DW_TAG_interface_type
                      || last_die->tag == DW_TAG_structure_type
                      || last_die->tag == DW_TAG_union_type))
-             || (cu->language == language_ada
+             || ((cu->language == language_ada
+                  || cu->language == language_fortran)
                  && (last_die->tag == DW_TAG_subprogram
                      || last_die->tag == DW_TAG_lexical_block))))
        {
@@ -19057,16 +19305,15 @@ guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
       if (child_pdi->tag == DW_TAG_subprogram
          && child_pdi->linkage_name != NULL)
        {
-         char *actual_class_name
-           language_class_name_from_physname (cu->language_defn,
-                                                child_pdi->linkage_name);
+         gdb::unique_xmalloc_ptr<char> actual_class_name
+           (language_class_name_from_physname (cu->language_defn,
+                                               child_pdi->linkage_name));
          if (actual_class_name != NULL)
            {
              struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
              struct_pdi->name
                = obstack_strdup (&objfile->per_bfd->storage_obstack,
-                                 actual_class_name);
-             xfree (actual_class_name);
+                                 actual_class_name.get ());
            }
          break;
        }
@@ -19131,24 +19378,22 @@ partial_die_info::fixup (struct dwarf2_cu *cu)
          || tag == DW_TAG_union_type)
       && linkage_name != NULL)
     {
-      char *demangled;
-
-      demangled = gdb_demangle (linkage_name, DMGL_TYPES);
-      if (demangled)
+      gdb::unique_xmalloc_ptr<char> demangled
+       (gdb_demangle (linkage_name, DMGL_TYPES));
+      if (demangled != nullptr)
        {
          const char *base;
 
          /* Strip any leading namespaces/classes, keep only the base name.
             DW_AT_name for named DIEs does not contain the prefixes.  */
-         base = strrchr (demangled, ':');
-         if (base && base > demangled && base[-1] == ':')
+         base = strrchr (demangled.get (), ':');
+         if (base && base > demangled.get () && base[-1] == ':')
            base++;
          else
-           base = demangled;
+           base = demangled.get ();
 
          struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
          name = obstack_strdup (&objfile->per_bfd->storage_obstack, base);
-         xfree (demangled);
        }
     }
 
@@ -20199,7 +20444,7 @@ dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *c
 }
 
 /* Return the dwo name or NULL if not present. If present, it is in either
-   DW_AT_GNU_dwo_name or DW_AT_dwo_name atrribute.  */
+   DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.  */
 static const char *
 dwarf2_dwo_name (struct die_info *die, struct dwarf2_cu *cu)
 {
@@ -20270,10 +20515,16 @@ void
 line_header::add_include_dir (const char *include_dir)
 {
   if (dwarf_line_debug >= 2)
-    fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
-                       include_dirs.size () + 1, include_dir);
-
-  include_dirs.push_back (include_dir);
+    {
+      size_t new_size;
+      if (version >= 5)
+        new_size = m_include_dirs.size ();
+      else
+        new_size = m_include_dirs.size () + 1;
+      fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
+                         new_size, include_dir);
+    }
+  m_include_dirs.push_back (include_dir);
 }
 
 void
@@ -20283,10 +20534,16 @@ line_header::add_file_name (const char *name,
                            unsigned int length)
 {
   if (dwarf_line_debug >= 2)
-    fprintf_unfiltered (gdb_stdlog, "Adding file %u: %s\n",
-                       (unsigned) file_names.size () + 1, name);
-
-  file_names.emplace_back (name, d_index, mod_time, length);
+    {
+      size_t new_size;
+      if (version >= 5)
+        new_size = file_names_size ();
+      else
+        new_size = file_names_size () + 1;
+      fprintf_unfiltered (gdb_stdlog, "Adding file %zu: %s\n",
+                         new_size, name);
+    }
+  m_file_names.emplace_back (name, d_index, mod_time, length);
 }
 
 /* A convenience function to find the proper .debug_line section for a CU.  */
@@ -20400,6 +20657,11 @@ read_formatted_entries (struct dwarf2_per_objfile *dwarf2_per_objfile,
              buf += 8;
              break;
 
+           case DW_FORM_data16:
+             /*  This is used for MD5, but file_entry does not record MD5s. */
+             buf += 16;
+             break;
+
            case DW_FORM_udata:
              uint.emplace (read_unsigned_leb128 (abfd, buf, &bytes_read));
              buf += bytes_read;
@@ -20500,12 +20762,15 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
     read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
                                            &bytes_read, &offset_size);
   line_ptr += bytes_read;
+
+  const gdb_byte *start_here = line_ptr;
+
   if (line_ptr + lh->total_length > (section->buffer + section->size))
     {
       dwarf2_statement_list_fits_in_line_number_section_complaint ();
       return 0;
     }
-  lh->statement_program_end = line_ptr + lh->total_length;
+  lh->statement_program_end = start_here + lh->total_length;
   lh->version = read_2_bytes (abfd, line_ptr);
   line_ptr += 2;
   if (lh->version > 5)
@@ -20535,6 +20800,7 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
     }
   lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
   line_ptr += offset_size;
+  lh->statement_program_start = line_ptr + lh->header_length;
   lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
   line_ptr += 1;
   if (lh->version >= 4)
@@ -20619,7 +20885,6 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
        }
       line_ptr += bytes_read;
     }
-  lh->statement_program_start = line_ptr;
 
   if (line_ptr > (section->buffer + section->size))
     complaint (_("line number info header doesn't "
@@ -20629,19 +20894,17 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
 }
 
 /* Subroutine of dwarf_decode_lines to simplify it.
-   Return the file name of the psymtab for included file FILE_INDEX
-   in line header LH of PST.
+   Return the file name of the psymtab for the given file_entry.
    COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
    If space for the result is malloc'd, *NAME_HOLDER will be set.
    Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.  */
 
 static const char *
-psymtab_include_file_name (const struct line_header *lh, int file_index,
+psymtab_include_file_name (const struct line_header *lh, const file_entry &fe,
                           const struct partial_symtab *pst,
                           const char *comp_dir,
                           gdb::unique_xmalloc_ptr<char> *name_holder)
 {
-  const file_entry &fe = lh->file_names[file_index];
   const char *include_name = fe.name;
   const char *include_name_to_compare = include_name;
   const char *pst_filename;
@@ -20816,8 +21079,8 @@ private:
      and initialized according to the DWARF spec.  */
 
   unsigned char m_op_index = 0;
-  /* The line table index (1-based) of the current file.  */
-  file_name_index m_file = (file_name_index) 1;
+  /* The line table index of the current file.  */
+  file_name_index m_file = 1;
   unsigned int m_line = 1;
 
   /* These are initialized in the constructor.  */
@@ -21009,7 +21272,7 @@ lnp_state_machine::record_line (bool end_sequence)
       fprintf_unfiltered (gdb_stdlog,
                          "Processing actual line %u: file %u,"
                          " address %s, is_stmt %u, discrim %u\n",
-                         m_line, to_underlying (m_file),
+                         m_line, m_file,
                          paddress (m_gdbarch, m_address),
                          m_is_stmt, m_discriminator);
     }
@@ -21348,17 +21611,15 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
 
   if (decode_for_pst_p)
     {
-      int file_index;
-
       /* Now that we're done scanning the Line Header Program, we can
          create the psymtab of each included file.  */
-      for (file_index = 0; file_index < lh->file_names.size (); file_index++)
-        if (lh->file_names[file_index].included_p == 1)
+      for (auto &file_entry : lh->file_names ())
+        if (file_entry.included_p == 1)
           {
            gdb::unique_xmalloc_ptr<char> name_holder;
            const char *include_name =
-             psymtab_include_file_name (lh, file_index, pst, comp_dir,
-                                        &name_holder);
+             psymtab_include_file_name (lh, file_entry, pst,
+                                        comp_dir, &name_holder);
            if (include_name != NULL)
               dwarf2_create_include_psymtab (include_name, pst, objfile);
           }
@@ -21370,14 +21631,10 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
         line numbers).  */
       buildsym_compunit *builder = cu->get_builder ();
       struct compunit_symtab *cust = builder->get_compunit_symtab ();
-      int i;
 
-      for (i = 0; i < lh->file_names.size (); i++)
+      for (auto &fe : lh->file_names ())
        {
-         file_entry &fe = lh->file_names[i];
-
          dwarf2_start_subfile (cu, fe.name, fe.include_dir (lh));
-
          if (builder->get_current_subfile ()->symtab == NULL)
            {
              builder->get_current_subfile ()->symtab
@@ -21416,7 +21673,7 @@ static void
 dwarf2_start_subfile (struct dwarf2_cu *cu, const char *filename,
                      const char *dirname)
 {
-  char *copy = NULL;
+  gdb::unique_xmalloc_ptr<char> copy;
 
   /* In order not to lose the line information directory,
      we concatenate it to the filename when it makes sense.
@@ -21427,14 +21684,11 @@ dwarf2_start_subfile (struct dwarf2_cu *cu, const char *filename,
 
   if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
     {
-      copy = concat (dirname, SLASH_STRING, filename, (char *)NULL);
-      filename = copy;
+      copy.reset (concat (dirname, SLASH_STRING, filename, (char *) NULL));
+      filename = copy.get ();
     }
 
   cu->get_builder ()->start_subfile (filename);
-
-  if (copy != NULL)
-    xfree (copy);
 }
 
 /* Start a symtab for DWARF.  NAME, COMP_DIR, LOW_PC are passed to the
@@ -21571,15 +21825,15 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
       OBJSTAT (objfile, n_syms++);
 
       /* Cache this symbol's name and the name's demangled form (if any).  */
-      SYMBOL_SET_LANGUAGE (sym, cu->language, &objfile->objfile_obstack);
+      sym->set_language (cu->language, &objfile->objfile_obstack);
       linkagename = dwarf2_physname (name, die, cu);
-      SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
+      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->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);
 
@@ -21594,7 +21848,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);
        }
@@ -21602,7 +21856,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;
@@ -21622,7 +21876,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;
 
@@ -21641,14 +21895,15 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
          SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
          attr2 = dwarf2_attr (die, DW_AT_external, cu);
          if ((attr2 && (DW_UNSND (attr2) != 0))
-              || cu->language == language_ada)
+             || cu->language == language_ada
+             || cu->language == language_fortran)
            {
               /* Subprograms marked external are stored as a global symbol.
-                 Ada subprograms, whether marked external or not, are always
-                 stored as a global symbol, because we want to be able to
-                 access them globally.  For instance, we want to be able
-                 to break on a nested subprogram without having to
-                 specify the context.  */
+                 Ada and Fortran subprograms, whether marked external or
+                 not, are always stored as a global symbol, because we want
+                 to be able to access them globally.  For instance, we want
+                 to be able to break on a nested subprogram without having
+                 to specify the context.  */
              list_to_add = cu->get_builder ()->get_global_symbols ();
            }
          else
@@ -21685,7 +21940,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);
@@ -21699,7 +21954,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);
@@ -21732,7 +21987,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;
                    }
@@ -21802,12 +22057,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);
              }
@@ -21861,7 +22116,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 ();
                  }
              }
          }
@@ -21879,7 +22134,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);
            }
@@ -22094,7 +22349,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);
 
@@ -22401,7 +22656,7 @@ read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
    This is the full-die version of guess_partial_die_structure_name.
    In this case we know DIE has no useful parent.  */
 
-static char *
+static const char *
 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct die_info *spec_die;
@@ -22427,33 +22682,32 @@ guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
 
          if (linkage_name != NULL)
            {
-             char *actual_name
-               language_class_name_from_physname (cu->language_defn,
-                                                    linkage_name);
-             char *name = NULL;
+             gdb::unique_xmalloc_ptr<char> actual_name
+               (language_class_name_from_physname (cu->language_defn,
+                                                   linkage_name));
+             const char *name = NULL;
 
              if (actual_name != NULL)
                {
                  const char *die_name = dwarf2_name (die, cu);
 
                  if (die_name != NULL
-                     && strcmp (die_name, actual_name) != 0)
+                     && strcmp (die_name, actual_name.get ()) != 0)
                    {
                      /* Strip off the class name from the full name.
                         We want the prefix.  */
                      int die_name_len = strlen (die_name);
-                     int actual_name_len = strlen (actual_name);
+                     int actual_name_len = strlen (actual_name.get ());
+                     const char *ptr = actual_name.get ();
 
                      /* Test for '::' as a sanity check.  */
                      if (actual_name_len > die_name_len + 2
-                         && actual_name[actual_name_len
-                                        - die_name_len - 1] == ':')
+                         && ptr[actual_name_len - die_name_len - 1] == ':')
                        name = obstack_strndup (
                          &objfile->per_bfd->storage_obstack,
-                         actual_name, actual_name_len - die_name_len - 2);
+                         ptr, actual_name_len - die_name_len - 2);
                    }
                }
-             xfree (actual_name);
              return name;
            }
        }
@@ -22640,11 +22894,21 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
                || die->tag == DW_TAG_structure_type
                || die->tag == DW_TAG_union_type))
          {
-           char *name = guess_full_die_structure_name (die, cu);
+           const char *name = guess_full_die_structure_name (die, cu);
            if (name != NULL)
              return name;
          }
        return "";
+      case DW_TAG_subprogram:
+       /* Nested subroutines in Fortran get a prefix with the name
+          of the parent's subroutine.  */
+       if (cu->language == language_fortran)
+         {
+           if ((die->tag ==  DW_TAG_subprogram)
+               && (dwarf2_name (parent, cu) != NULL))
+             return dwarf2_name (parent, cu);
+         }
+       return determine_prefix (parent, cu);
       case DW_TAG_enumeration_type:
        parent_type = read_type_die (parent, cu);
        if (TYPE_DECLARED_CLASS (parent_type))
@@ -22804,8 +23068,6 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
         http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510.  */
       if (!attr || DW_STRING (attr) == NULL)
        {
-         char *demangled = NULL;
-
          attr = dw2_linkage_name_attr (die, cu);
          if (attr == NULL || DW_STRING (attr) == NULL)
            return NULL;
@@ -22813,18 +23075,17 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
          /* Avoid demangling DW_STRING (attr) the second time on a second
             call for the same DIE.  */
          if (!DW_STRING_IS_CANONICAL (attr))
-           demangled = gdb_demangle (DW_STRING (attr), DMGL_TYPES);
-
-         if (demangled)
            {
+             gdb::unique_xmalloc_ptr<char> demangled
+               (gdb_demangle (DW_STRING (attr), DMGL_TYPES));
+
              const char *base;
 
              /* FIXME: we already did this for the partial symbol... */
              DW_STRING (attr)
                = obstack_strdup (&objfile->per_bfd->storage_obstack,
-                                 demangled);
+                                 demangled.get ());
              DW_STRING_IS_CANONICAL (attr) = 1;
-             xfree (demangled);
 
              /* Strip any leading namespaces/classes, keep only the base name.
                 DW_AT_name for named DIEs does not contain the prefixes.  */
@@ -23652,9 +23913,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
       if (dwarf2_per_objfile->index_table != NULL
          && dwarf2_per_objfile->index_table->version <= 7)
        {
-         VEC_safe_push (dwarf2_per_cu_ptr,
-                        (*ref_cu)->per_cu->imported_symtabs,
-                        sig_cu->per_cu);
+         (*ref_cu)->per_cu->imported_symtabs_push (sig_cu->per_cu);
        }
 
       *ref_cu = sig_cu;
@@ -24173,17 +24432,17 @@ file_file_name (int file, struct line_header *lh)
 {
   /* Is the file number a valid index into the line header's file name
      table?  Remember that file numbers start with one, not zero.  */
-  if (1 <= file && file <= lh->file_names.size ())
+  if (lh->is_valid_file_index (file))
     {
-      const file_entry &fe = lh->file_names[file - 1];
+      const file_entry *fe = lh->file_name_at (file);
 
-      if (!IS_ABSOLUTE_PATH (fe.name))
+      if (!IS_ABSOLUTE_PATH (fe->name))
        {
-         const char *dir = fe.include_dir (lh);
+         const char *dir = fe->include_dir (lh);
          if (dir != NULL)
-           return concat (dir, SLASH_STRING, fe.name, (char *) NULL);
+           return concat (dir, SLASH_STRING, fe->name, (char *) NULL);
        }
-      return xstrdup (fe.name);
+      return xstrdup (fe->name);
     }
   else
     {
@@ -24211,7 +24470,7 @@ file_full_name (int file, struct line_header *lh, const char *comp_dir)
 {
   /* Is the file number a valid index into the line header's file name
      table?  Remember that file numbers start with one, not zero.  */
-  if (1 <= file && file <= lh->file_names.size ())
+  if (lh->is_valid_file_index (file))
     {
       char *relative = file_file_name (file, lh);
 
@@ -24311,7 +24570,7 @@ parse_macro_definition (struct macro_source_file *file, int line,
     {
       /* It's an object-like macro.  */
       int name_len = p - body;
-      char *name = savestring (body, name_len);
+      std::string name (body, name_len);
       const char *replacement;
 
       if (*p == ' ')
@@ -24322,14 +24581,12 @@ parse_macro_definition (struct macro_source_file *file, int line,
           replacement = body + name_len;
         }
 
-      macro_define_object (file, line, name, replacement);
-
-      xfree (name);
+      macro_define_object (file, line, name.c_str (), replacement);
     }
   else if (*p == '(')
     {
       /* It's a function-like macro.  */
-      char *name = savestring (body, p - body);
+      std::string name (body, p - body);
       int argc = 0;
       int argv_size = 1;
       char **argv = XNEWVEC (char *, argv_size);
@@ -24378,14 +24635,14 @@ parse_macro_definition (struct macro_source_file *file, int line,
 
           if (*p == ' ')
             /* Perfectly formed definition, no complaints.  */
-            macro_define_function (file, line, name,
+            macro_define_function (file, line, name.c_str (),
                                    argc, (const char **) argv,
                                    p + 1);
           else if (*p == '\0')
             {
               /* Complain, but do define it.  */
              dwarf2_macro_malformed_definition_complaint (body);
-              macro_define_function (file, line, name,
+              macro_define_function (file, line, name.c_str (),
                                      argc, (const char **) argv,
                                      p);
             }
@@ -24397,7 +24654,6 @@ parse_macro_definition (struct macro_source_file *file, int line,
         /* Just complain.  */
        dwarf2_macro_malformed_definition_complaint (body);
 
-      xfree (name);
       {
         int i;
 
@@ -25268,7 +25524,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;
        }
 
@@ -25483,7 +25739,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
     {
@@ -25613,7 +25869,7 @@ per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
    table if necessary.  For convenience, return TYPE.
 
    The DIEs reading must have careful ordering to:
-    * Not cause infite loops trying to read in DIEs as a prerequisite for
+    * Not cause infinite loops trying to read in DIEs as a prerequisite for
       reading current DIE.
     * Not trying to dereference contents of still incompletely read in types
       while reading in other DIEs.
This page took 0.066648 seconds and 4 git commands to generate.