Be more careful when rewriting thick pointer array type
[deliverable/binutils-gdb.git] / gdb / dwarf2 / read.c
index 25f05fb99302c2622d8a940eb889c731db536bb0..4edd8d4d9d6858226f09d30624413239b42a487c 100644 (file)
    This is in contrast to the low level DIE reading of dwarf_die_debug.  */
 static unsigned int dwarf_read_debug = 0;
 
+/* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1.  */
+
+#define dwarf_read_debug_printf(fmt, ...) \
+  debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
+                             ##__VA_ARGS__)
+
+/* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2.  */
+
+#define dwarf_read_debug_printf_v(fmt, ...) \
+  debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
+                             ##__VA_ARGS__)
+
 /* When non-zero, dump DIEs after they are read in.  */
 static unsigned int dwarf_die_debug = 0;
 
@@ -132,6 +144,12 @@ static int dwarf2_loclist_block_index;
 /* Size of .debug_loclists section header for 64-bit DWARF format.  */
 #define LOCLIST_HEADER_SIZE64 20
 
+/* Size of .debug_rnglists section header for 32-bit DWARF format.  */
+#define RNGLIST_HEADER_SIZE32 12
+
+/* Size of .debug_rnglists section header for 64-bit DWARF format.  */
+#define RNGLIST_HEADER_SIZE64 20
+
 /* An index into a (C++) symbol name component in a symbol name as
    recorded in the mapped_index's symbol table.  For each C++ symbol
    in the symbol table, we record one entry for the start of each
@@ -340,6 +358,7 @@ static const struct dwop_section_names
   struct dwarf2_section_names loclists_dwo;
   struct dwarf2_section_names macinfo_dwo;
   struct dwarf2_section_names macro_dwo;
+  struct dwarf2_section_names rnglists_dwo;
   struct dwarf2_section_names str_dwo;
   struct dwarf2_section_names str_offsets_dwo;
   struct dwarf2_section_names types_dwo;
@@ -355,6 +374,7 @@ dwop_section_names =
   { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
   { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
   { ".debug_macro.dwo", ".zdebug_macro.dwo" },
+  { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
   { ".debug_str.dwo", ".zdebug_str.dwo" },
   { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
   { ".debug_types.dwo", ".zdebug_types.dwo" },
@@ -364,9 +384,9 @@ dwop_section_names =
 
 /* local data types */
 
-/* The location list section (.debug_loclists) begins with a header,
-   which contains the following information.  */
-struct loclist_header
+/* The location list and range list sections (.debug_loclists & .debug_rnglists)
+   begin with a header,  which contains the following information.  */
+struct loclists_rnglists_header
 {
   /* A 4-byte or 12-byte length containing the length of the
      set of entries for this compilation unit, not including the
@@ -483,7 +503,7 @@ public:
   struct dwarf2_per_cu_data *per_cu;
 
   /* The dwarf2_per_objfile that owns this.  */
-  struct dwarf2_per_objfile *per_objfile;
+  dwarf2_per_objfile *per_objfile;
 
   /* How many compilation units ago was this CU last referenced?  */
   int last_used = 0;
@@ -650,6 +670,7 @@ struct dwo_sections
   struct dwarf2_section_info loclists;
   struct dwarf2_section_info macinfo;
   struct dwarf2_section_info macro;
+  struct dwarf2_section_info rnglists;
   struct dwarf2_section_info str;
   struct dwarf2_section_info str_offsets;
   /* In the case of a virtual DWO file, these two are unused.  */
@@ -719,7 +740,7 @@ struct dwo_file
   gdb_bfd_ref_ptr dbfd;
 
   /* The sections that make up this DWO file.
-     Remember that for virtual DWO files in DWP V2, these are virtual
+     Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
      sections (for lack of a better name).  */
   struct dwo_sections sections {};
 
@@ -738,25 +759,27 @@ struct dwo_file
 
 struct dwp_sections
 {
-  /* These are used by both DWP version 1 and 2.  */
+  /* These are used by all DWP versions (1, 2 and 5).  */
   struct dwarf2_section_info str;
   struct dwarf2_section_info cu_index;
   struct dwarf2_section_info tu_index;
 
-  /* These are only used by DWP version 2 files.
+  /* These are only used by DWP version 2 and version 5 files.
      In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
      sections are referenced by section number, and are not recorded here.
-     In DWP version 2 there is at most one copy of all these sections, each
-     section being (effectively) comprised of the concatenation of all of the
-     individual sections that exist in the version 1 format.
+     In DWP version 2 or 5 there is at most one copy of all these sections,
+     each section being (effectively) comprised of the concatenation of all of
+     the individual sections that exist in the version 1 format.
      To keep the code simple we treat each of these concatenated pieces as a
      section itself (a virtual section?).  */
   struct dwarf2_section_info abbrev;
   struct dwarf2_section_info info;
   struct dwarf2_section_info line;
   struct dwarf2_section_info loc;
+  struct dwarf2_section_info loclists;
   struct dwarf2_section_info macinfo;
   struct dwarf2_section_info macro;
+  struct dwarf2_section_info rnglists;
   struct dwarf2_section_info str_offsets;
   struct dwarf2_section_info types;
 };
@@ -777,12 +800,12 @@ struct virtual_v1_dwo_sections
   struct dwarf2_section_info info_or_types;
 };
 
-/* Similar to virtual_v1_dwo_sections, but for DWP version 2.
+/* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
    In version 2, the sections of the DWO files are concatenated together
    and stored in one section of that name.  Thus each ELF section contains
    several "virtual" sections.  */
 
-struct virtual_v2_dwo_sections
+struct virtual_v2_or_v5_dwo_sections
 {
   bfd_size_type abbrev_offset;
   bfd_size_type abbrev_size;
@@ -793,12 +816,18 @@ struct virtual_v2_dwo_sections
   bfd_size_type loc_offset;
   bfd_size_type loc_size;
 
+  bfd_size_type loclists_offset;
+  bfd_size_type loclists_size;
+
   bfd_size_type macinfo_offset;
   bfd_size_type macinfo_size;
 
   bfd_size_type macro_offset;
   bfd_size_type macro_size;
 
+  bfd_size_type rnglists_offset;
+  bfd_size_type rnglists_size;
+
   bfd_size_type str_offsets_offset;
   bfd_size_type str_offsets_size;
 
@@ -836,6 +865,22 @@ struct dwp_hash_table
       const gdb_byte *offsets;
       const gdb_byte *sizes;
     } v2;
+    struct
+    {
+      /* This is indexed by column number and gives the id of the section
+        in that column.  */
+#define MAX_NR_V5_DWO_SECTIONS \
+  (1 /* .debug_info */ \
+   + 1 /* .debug_abbrev */ \
+   + 1 /* .debug_line */ \
+   + 1 /* .debug_loclists */ \
+   + 1 /* .debug_str_offsets */ \
+   + 1 /* .debug_macro */ \
+   + 1 /* .debug_rnglists */)
+      int section_ids[MAX_NR_V5_DWO_SECTIONS];
+      const gdb_byte *offsets;
+      const gdb_byte *sizes;
+    } v5;
   } section_pool;
 };
 
@@ -1157,40 +1202,40 @@ struct fnfieldlist
    pass lists of data member fields and lists of member function fields
    in an instance of a field_info structure, as defined below.  */
 struct field_info
-  {
-    /* List of data member and baseclasses fields.  */
-    std::vector<struct nextfield> fields;
-    std::vector<struct nextfield> baseclasses;
+{
+  /* List of data member and baseclasses fields.  */
+  std::vector<struct nextfield> fields;
+  std::vector<struct nextfield> baseclasses;
 
-    /* Set if the accessibility of one of the fields is not public.  */
-    int non_public_fields = 0;
+  /* Set if the accessibility of one of the fields is not public.  */
+  bool non_public_fields = false;
 
-    /* Member function fieldlist array, contains name of possibly overloaded
-       member function, number of overloaded member functions and a pointer
-       to the head of the member function field chain.  */
-    std::vector<struct fnfieldlist> fnfieldlists;
+  /* Member function fieldlist array, contains name of possibly overloaded
+     member function, number of overloaded member functions and a pointer
+     to the head of the member function field chain.  */
+  std::vector<struct fnfieldlist> fnfieldlists;
 
-    /* typedefs defined inside this class.  TYPEDEF_FIELD_LIST contains head of
-       a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements.  */
-    std::vector<struct decl_field> typedef_field_list;
+  /* typedefs defined inside this class.  TYPEDEF_FIELD_LIST contains head of
+     a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements.  */
+  std::vector<struct decl_field> typedef_field_list;
 
-    /* Nested types defined by this class and the number of elements in this
-       list.  */
-    std::vector<struct decl_field> nested_types_list;
+  /* Nested types defined by this class and the number of elements in this
+     list.  */
+  std::vector<struct decl_field> nested_types_list;
 
-    /* If non-null, this is the variant part we are currently
-       reading.  */
-    variant_part_builder *current_variant_part = nullptr;
-    /* This holds all the top-level variant parts attached to the type
-       we're reading.  */
-    std::vector<variant_part_builder> variant_parts;
+  /* If non-null, this is the variant part we are currently
+     reading.  */
+  variant_part_builder *current_variant_part = nullptr;
+  /* This holds all the top-level variant parts attached to the type
+     we're reading.  */
+  std::vector<variant_part_builder> variant_parts;
 
-    /* Return the total number of fields (including baseclasses).  */
-    int nfields () const
-    {
-      return fields.size () + baseclasses.size ();
-    }
-  };
+  /* Return the total number of fields (including baseclasses).  */
+  int nfields () const
+  {
+    return fields.size () + baseclasses.size ();
+  }
+};
 
 /* Loaded secondary compilation units are kept in memory until they
    have not been referenced for the processing of this many
@@ -1220,8 +1265,7 @@ static void build_type_psymtabs_reader (const struct die_reader_specs *reader,
                                        const gdb_byte *info_ptr,
                                        struct die_info *type_unit_die);
 
-static void dwarf2_build_psymtabs_hard
-  (struct dwarf2_per_objfile *dwarf2_per_objfile);
+static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile);
 
 static void scan_partial_symbols (struct partial_die_info *,
                                  CORE_ADDR *, CORE_ADDR *,
@@ -1272,23 +1316,22 @@ static const struct cu_partial_die_info find_partial_die (sect_offset, int,
 
 static const gdb_byte *read_attribute (const struct die_reader_specs *,
                                       struct attribute *, struct attr_abbrev *,
-                                      const gdb_byte *, bool *need_reprocess);
+                                      const gdb_byte *);
 
 static void read_attribute_reprocess (const struct die_reader_specs *reader,
-                                     struct attribute *attr);
+                                     struct attribute *attr, dwarf_tag tag);
 
 static CORE_ADDR read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index);
 
-static sect_offset read_abbrev_offset
-  (struct dwarf2_per_objfile *dwarf2_per_objfile,
-   struct dwarf2_section_info *, sect_offset);
+static sect_offset read_abbrev_offset (dwarf2_per_objfile *per_objfile,
+                                      dwarf2_section_info *, sect_offset);
 
 static const char *read_indirect_string
-  (struct dwarf2_per_objfile *dwarf2_per_objfile, bfd *, const gdb_byte *,
+  (dwarf2_per_objfile *per_objfile, bfd *, const gdb_byte *,
    const struct comp_unit_head *, unsigned int *);
 
 static const char *read_indirect_string_at_offset
-  (struct dwarf2_per_objfile *dwarf2_per_objfile, LONGEST str_offset);
+  (dwarf2_per_objfile *per_objfile, LONGEST str_offset);
 
 static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *,
                                              const gdb_byte *,
@@ -1306,12 +1349,12 @@ static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
                                      struct dwarf2_cu *);
 
 static const char *dwarf2_string_attr (struct die_info *die, unsigned int name,
-                                       struct dwarf2_cu *cu);
+                                      struct dwarf2_cu *cu);
 
 static const char *dwarf2_dwo_name (struct die_info *die, struct dwarf2_cu *cu);
 
 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
-                               struct dwarf2_cu *cu);
+                              struct dwarf2_cu *cu);
 
 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
 
@@ -1342,6 +1385,9 @@ static void dwarf2_const_value_attr (const struct attribute *attr,
                                     const gdb_byte **bytes,
                                     struct dwarf2_locexpr_baton **baton);
 
+static struct type *read_subrange_index_type (struct die_info *die,
+                                             struct dwarf2_cu *cu);
+
 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
 
 static int need_gnat_info (struct dwarf2_cu *);
@@ -1380,12 +1426,13 @@ static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
 
 static void read_variable (struct die_info *die, struct dwarf2_cu *cu);
 
-static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
-                              struct dwarf2_cu *, dwarf2_psymtab *);
-
 /* Return the .debug_loclists section to use for cu.  */
 static struct dwarf2_section_info *cu_debug_loc_section (struct dwarf2_cu *cu);
 
+/* Return the .debug_rnglists section to use for cu.  */
+static struct dwarf2_section_info *cu_debug_rnglists_section
+  (struct dwarf2_cu *cu, dwarf_tag tag);
+
 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
    values.  Keep the items ordered with increasing constraints compliance.  */
 enum pc_bounds_kind
@@ -1414,7 +1461,7 @@ static void get_scope_pc_bounds (struct die_info *,
                                 struct dwarf2_cu *);
 
 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
-                                        CORE_ADDR, struct dwarf2_cu *);
+                                       CORE_ADDR, struct dwarf2_cu *);
 
 static void dwarf2_add_field (struct field_info *, struct die_info *,
                              struct dwarf2_cu *);
@@ -1559,21 +1606,22 @@ static int partial_die_eq (const void *item_lhs, const void *item_rhs);
 
 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
   (sect_offset sect_off, unsigned int offset_in_dwz,
-   struct dwarf2_per_objfile *dwarf2_per_objfile);
+   dwarf2_per_objfile *per_objfile);
 
 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
                                   struct die_info *comp_unit_die,
                                   enum language pretend_language);
 
 static struct type *set_die_type (struct die_info *, struct type *,
-                                 struct dwarf2_cu *);
+                                 struct dwarf2_cu *, bool = false);
 
-static void create_all_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile);
+static void create_all_comp_units (dwarf2_per_objfile *per_objfile);
 
-static int create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile);
+static int create_all_type_units (dwarf2_per_objfile *per_objfile);
 
 static void load_full_comp_unit (dwarf2_per_cu_data *per_cu,
                                 dwarf2_per_objfile *per_objfile,
+                                dwarf2_cu *existing_cu,
                                 bool skip_partial,
                                 enum language pretend_language);
 
@@ -1598,7 +1646,7 @@ static void queue_comp_unit (dwarf2_per_cu_data *per_cu,
                             dwarf2_per_objfile *per_objfile,
                             enum language pretend_language);
 
-static void process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile);
+static void process_queue (dwarf2_per_objfile *per_objfile);
 
 /* 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
@@ -1666,12 +1714,10 @@ static htab_up allocate_signatured_type_table ();
 static htab_up allocate_dwo_unit_table ();
 
 static struct dwo_unit *lookup_dwo_unit_in_dwp
-  (struct dwarf2_per_objfile *dwarf2_per_objfile,
-   struct dwp_file *dwp_file, const char *comp_dir,
-   ULONGEST signature, int is_debug_types);
+  (dwarf2_per_objfile *per_objfile, struct dwp_file *dwp_file,
+   const char *comp_dir, ULONGEST signature, int is_debug_types);
 
-static struct dwp_file *get_dwp_file
-  (struct dwarf2_per_objfile *dwarf2_per_objfile);
+static struct dwp_file *get_dwp_file (dwarf2_per_objfile *per_objfile);
 
 static struct dwo_unit *lookup_dwo_comp_unit
   (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
@@ -1686,7 +1732,7 @@ static void queue_and_load_all_dwo_tus (dwarf2_cu *cu);
 
 typedef std::unique_ptr<struct dwo_file> dwo_file_up;
 
-static void process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile);
+static void process_cu_includes (dwarf2_per_objfile *per_objfile);
 
 static void check_producer (struct dwarf2_cu *cu);
 
@@ -1861,21 +1907,20 @@ dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data *per_cu,
 
 int
 dwarf2_has_info (struct objfile *objfile,
-                 const struct dwarf2_debug_sections *names,
+                const struct dwarf2_debug_sections *names,
                 bool can_copy)
 {
   if (objfile->flags & OBJF_READNEVER)
     return 0;
 
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  if (dwarf2_per_objfile == NULL)
+  if (per_objfile == NULL)
     {
       dwarf2_per_bfd *per_bfd;
 
       /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
-         doesn't require relocations and if there aren't partial symbols
+        doesn't require relocations and if there aren't partial symbols
         from some other reader.  */
       if (!objfile_has_partial_symbols (objfile)
          && !gdb_bfd_requires_relocations (objfile->obfd))
@@ -1897,13 +1942,13 @@ dwarf2_has_info (struct objfile *objfile,
          dwarf2_per_bfd_objfile_data_key.set (objfile, per_bfd);
        }
 
-      dwarf2_per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile, per_bfd);
+      per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile, per_bfd);
     }
 
-  return (!dwarf2_per_objfile->per_bfd->info.is_virtual
-         && dwarf2_per_objfile->per_bfd->info.s.section != NULL
-         && !dwarf2_per_objfile->per_bfd->abbrev.is_virtual
-         && dwarf2_per_objfile->per_bfd->abbrev.s.section != NULL);
+  return (!per_objfile->per_bfd->info.is_virtual
+         && per_objfile->per_bfd->info.s.section != NULL
+         && !per_objfile->per_bfd->abbrev.is_virtual
+         && per_objfile->per_bfd->abbrev.s.section != NULL);
 }
 
 /* When loading sections, we look either for uncompressed section or for
@@ -1911,7 +1956,7 @@ dwarf2_has_info (struct objfile *objfile,
 
 static int
 section_is_p (const char *section_name,
-              const struct dwarf2_section_names *names)
+             const struct dwarf2_section_names *names)
 {
   if (names->normal != NULL
       && strcmp (section_name, names->normal) == 0)
@@ -2053,16 +2098,16 @@ dwarf2_per_bfd::locate_sections (bfd *abfd, asection *sectp,
 
 void
 dwarf2_get_section_info (struct objfile *objfile,
-                         enum dwarf2_section_enum sect,
-                         asection **sectp, const gdb_byte **bufp,
-                         bfd_size_type *sizep)
+                        enum dwarf2_section_enum sect,
+                        asection **sectp, const gdb_byte **bufp,
+                        bfd_size_type *sizep)
 {
-  struct dwarf2_per_objfile *data = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   struct dwarf2_section_info *info;
 
   /* We may see an objfile without any DWARF, in which case we just
      return nothing.  */
-  if (data == NULL)
+  if (per_objfile == NULL)
     {
       *sectp = NULL;
       *bufp = NULL;
@@ -2072,10 +2117,10 @@ dwarf2_get_section_info (struct objfile *objfile,
   switch (sect)
     {
     case DWARF2_DEBUG_FRAME:
-      info = &data->per_bfd->frame;
+      info = &per_objfile->per_bfd->frame;
       break;
     case DWARF2_EH_FRAME:
-      info = &data->per_bfd->eh_frame;
+      info = &per_objfile->per_bfd->eh_frame;
       break;
     default:
       gdb_assert_not_reached ("unexpected section");
@@ -2091,10 +2136,8 @@ dwarf2_get_section_info (struct objfile *objfile,
 /* A helper function to find the sections for a .dwz file.  */
 
 static void
-locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
+locate_dwz_sections (bfd *abfd, asection *sectp, dwz_file *dwz_file)
 {
-  struct dwz_file *dwz_file = (struct dwz_file *) arg;
-
   /* Note that we only support the standard ELF names, because .dwz
      is ELF-only (at the time of writing).  */
   if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev))
@@ -2134,12 +2177,100 @@ locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
     }
 }
 
+/* Attempt to find a .dwz file (whose full path is represented by
+   FILENAME) in all of the specified debug file directories provided.
+
+   Return the equivalent gdb_bfd_ref_ptr of the .dwz file found, or
+   nullptr if it could not find anything.  */
+
+static gdb_bfd_ref_ptr
+dwz_search_other_debugdirs (std::string &filename, bfd_byte *buildid,
+                           size_t buildid_len)
+{
+  /* Let's assume that the path represented by FILENAME has the
+     "/.dwz/" subpath in it.  This is what (most) GNU/Linux
+     distributions do, anyway.  */
+  size_t dwz_pos = filename.find ("/.dwz/");
+
+  if (dwz_pos == std::string::npos)
+    return nullptr;
+
+  /* This is an obvious assertion, but it's here more to educate
+     future readers of this code that FILENAME at DWZ_POS *must*
+     contain a directory separator.  */
+  gdb_assert (IS_DIR_SEPARATOR (filename[dwz_pos]));
+
+  gdb_bfd_ref_ptr dwz_bfd;
+  std::vector<gdb::unique_xmalloc_ptr<char>> debugdir_vec
+    = dirnames_to_char_ptr_vec (debug_file_directory);
+
+  for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
+    {
+      /* The idea is to iterate over the
+        debug file directories provided by the user and
+        replace the hard-coded path in the "filename" by each
+        debug-file-directory.
+
+        For example, suppose that filename is:
+
+          /usr/lib/debug/.dwz/foo.dwz
+
+        And suppose that we have "$HOME/bar" as the
+        debug-file-directory.  We would then adjust filename
+        to look like:
+
+          $HOME/bar/.dwz/foo.dwz
+
+        which would hopefully allow us to find the alt debug
+        file.  */
+      std::string ddir = debugdir.get ();
+
+      if (ddir.empty ())
+       continue;
+
+      /* Make sure the current debug-file-directory ends with a
+        directory separator.  This is needed because, if FILENAME
+        contains something like "/usr/lib/abcde/.dwz/foo.dwz" and
+        DDIR is "/usr/lib/abc", then could wrongfully skip it
+        below.  */
+      if (!IS_DIR_SEPARATOR (ddir.back ()))
+       ddir += SLASH_STRING;
+
+      /* Check whether the beginning of FILENAME is DDIR.  If it is,
+        then we are dealing with a file which we already attempted to
+        open before, so we just skip it and continue processing the
+        remaining debug file directories.  */
+      if (filename.size () > ddir.size ()
+         && filename.compare (0, ddir.size (), ddir) == 0)
+       continue;
+
+      /* Replace FILENAME's default debug-file-directory with
+        DDIR.  */
+      std::string new_filename = ddir + &filename[dwz_pos + 1];
+
+      dwz_bfd = gdb_bfd_open (new_filename.c_str (), gnutarget);
+
+      if (dwz_bfd == nullptr)
+       continue;
+
+      if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid))
+       {
+         dwz_bfd.reset (nullptr);
+         continue;
+       }
+
+      /* Found it.  */
+      break;
+    }
+
+  return dwz_bfd;
+}
+
 /* See dwarf2read.h.  */
 
 struct dwz_file *
 dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd)
 {
-  const char *filename;
   bfd_size_type buildid_len_arg;
   size_t buildid_len;
   bfd_byte *buildid;
@@ -2163,21 +2294,19 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd)
 
   buildid_len = (size_t) buildid_len_arg;
 
-  filename = data.get ();
+  std::string filename = data.get ();
 
-  std::string abs_storage;
-  if (!IS_ABSOLUTE_PATH (filename))
+  if (!IS_ABSOLUTE_PATH (filename.c_str ()))
     {
       gdb::unique_xmalloc_ptr<char> abs
        = gdb_realpath (bfd_get_filename (per_bfd->obfd));
 
-      abs_storage = ldirname (abs.get ()) + SLASH_STRING + filename;
-      filename = abs_storage.c_str ();
+      filename = ldirname (abs.get ()) + SLASH_STRING + filename;
     }
 
   /* First try the file name given in the section.  If that doesn't
      work, try to use the build-id instead.  */
-  gdb_bfd_ref_ptr dwz_bfd (gdb_bfd_open (filename, gnutarget));
+  gdb_bfd_ref_ptr dwz_bfd (gdb_bfd_open (filename.c_str (), gnutarget));
   if (dwz_bfd != NULL)
     {
       if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid))
@@ -2187,6 +2316,13 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd)
   if (dwz_bfd == NULL)
     dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid);
 
+  if (dwz_bfd == nullptr)
+    {
+      /* If the user has provided us with different
+        debug file directories, we can try them in order.  */
+      dwz_bfd = dwz_search_other_debugdirs (filename, buildid, buildid_len);
+    }
+
   if (dwz_bfd == nullptr)
     {
       gdb::unique_xmalloc_ptr<char> alt_filename;
@@ -2217,8 +2353,8 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd)
   std::unique_ptr<struct dwz_file> result
     (new struct dwz_file (std::move (dwz_bfd)));
 
-  bfd_map_over_sections (result->dwz_bfd.get (), locate_dwz_sections,
-                        result.get ());
+  for (asection *sec : gdb_bfd_sections (result->dwz_bfd))
+    locate_dwz_sections (result->dwz_bfd.get (), sec, result.get ());
 
   gdb_bfd_record_inclusion (per_bfd->obfd, result->dwz_bfd.get ());
   per_bfd->dwz_file = std::move (result);
@@ -2358,7 +2494,8 @@ load_cu (dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile,
   if (per_cu->is_debug_types)
     load_full_type_unit (per_cu, per_objfile);
   else
-    load_full_comp_unit (per_cu, per_objfile, skip_partial, language_minimal);
+    load_full_comp_unit (per_cu, per_objfile, per_objfile->get_cu (per_cu),
+                        skip_partial, language_minimal);
 
   dwarf2_cu *cu = per_objfile->get_cu (per_cu);
   if (cu == nullptr)
@@ -2369,12 +2506,11 @@ load_cu (dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile,
   return cu;
 }
 
-/* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE.  */
+/* Read in the symbols for PER_CU in the context of PER_OBJFILE.  */
 
 static void
 dw2_do_instantiate_symtab (dwarf2_per_cu_data *per_cu,
-                          dwarf2_per_objfile *dwarf2_per_objfile,
-                          bool skip_partial)
+                          dwarf2_per_objfile *per_objfile, bool skip_partial)
 {
   /* Skip type_unit_groups, reading the type units they contain
      is handled elsewhere.  */
@@ -2384,12 +2520,12 @@ dw2_do_instantiate_symtab (dwarf2_per_cu_data *per_cu,
   /* The destructor of dwarf2_queue_guard frees any entries left on
      the queue.  After this point we're guaranteed to leave this function
      with the dwarf queue empty.  */
-  dwarf2_queue_guard q_guard (dwarf2_per_objfile);
+  dwarf2_queue_guard q_guard (per_objfile);
 
-  if (!dwarf2_per_objfile->symtab_set_p (per_cu))
+  if (!per_objfile->symtab_set_p (per_cu))
     {
-      queue_comp_unit (per_cu, dwarf2_per_objfile, language_minimal);
-      dwarf2_cu *cu = load_cu (per_cu, dwarf2_per_objfile, skip_partial);
+      queue_comp_unit (per_cu, per_objfile, language_minimal);
+      dwarf2_cu *cu = load_cu (per_cu, per_objfile, skip_partial);
 
       /* If we just loaded a CU from a DWO, and we're working with an index
         that may badly handle TUs, load all the TUs in that DWO as well.
@@ -2397,18 +2533,18 @@ dw2_do_instantiate_symtab (dwarf2_per_cu_data *per_cu,
       if (!per_cu->is_debug_types
          && cu != NULL
          && cu->dwo_unit != NULL
-         && dwarf2_per_objfile->per_bfd->index_table != NULL
-         && dwarf2_per_objfile->per_bfd->index_table->version <= 7
+         && per_objfile->per_bfd->index_table != NULL
+         && per_objfile->per_bfd->index_table->version <= 7
          /* DWP files aren't supported yet.  */
-         && get_dwp_file (dwarf2_per_objfile) == NULL)
+         && get_dwp_file (per_objfile) == NULL)
        queue_and_load_all_dwo_tus (cu);
     }
 
-  process_queue (dwarf2_per_objfile);
+  process_queue (per_objfile);
 
   /* Age the cache, releasing compilation units that have not
      been used recently.  */
-  dwarf2_per_objfile->age_comp_units ();
+  per_objfile->age_comp_units ();
 }
 
 /* Ensure that the symbols for PER_CU have been read in.  DWARF2_PER_OBJFILE is
@@ -2418,20 +2554,20 @@ dw2_do_instantiate_symtab (dwarf2_per_cu_data *per_cu,
 
 static struct compunit_symtab *
 dw2_instantiate_symtab (dwarf2_per_cu_data *per_cu,
-                       dwarf2_per_objfile *dwarf2_per_objfile,
+                       dwarf2_per_objfile *per_objfile,
                        bool skip_partial)
 {
-  gdb_assert (dwarf2_per_objfile->per_bfd->using_index);
+  gdb_assert (per_objfile->per_bfd->using_index);
 
-  if (!dwarf2_per_objfile->symtab_set_p (per_cu))
+  if (!per_objfile->symtab_set_p (per_cu))
     {
-      free_cached_comp_units freer (dwarf2_per_objfile);
+      free_cached_comp_units freer (per_objfile);
       scoped_restore decrementer = increment_reading_symtab ();
-      dw2_do_instantiate_symtab (per_cu, dwarf2_per_objfile, skip_partial);
-      process_cu_includes (dwarf2_per_objfile);
+      dw2_do_instantiate_symtab (per_cu, per_objfile, skip_partial);
+      process_cu_includes (per_objfile);
     }
 
-  return dwarf2_per_objfile->get_symtab (per_cu);
+  return per_objfile->get_symtab (per_cu);
 }
 
 /* See declaration.  */
@@ -2608,18 +2744,18 @@ create_signatured_type_table_from_index
 
 static void
 create_signatured_type_table_from_debug_names
-  (struct dwarf2_per_objfile *dwarf2_per_objfile,
+  (dwarf2_per_objfile *per_objfile,
    const mapped_debug_names &map,
    struct dwarf2_section_info *section,
    struct dwarf2_section_info *abbrev_section)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
 
   section->read (objfile);
   abbrev_section->read (objfile);
 
-  gdb_assert (dwarf2_per_objfile->per_bfd->all_type_units.empty ());
-  dwarf2_per_objfile->per_bfd->all_type_units.reserve (map.tu_count);
+  gdb_assert (per_objfile->per_bfd->all_type_units.empty ());
+  per_objfile->per_bfd->all_type_units.reserve (map.tu_count);
 
   htab_up sig_types_hash = allocate_signatured_type_table ();
 
@@ -2635,38 +2771,38 @@ create_signatured_type_table_from_debug_names
                          map.dwarf5_byte_order));
 
       comp_unit_head cu_header;
-      read_and_check_comp_unit_head (dwarf2_per_objfile, &cu_header, section,
+      read_and_check_comp_unit_head (per_objfile, &cu_header, section,
                                     abbrev_section,
                                     section->buffer + to_underlying (sect_off),
                                     rcuh_kind::TYPE);
 
-      sig_type = dwarf2_per_objfile->per_bfd->allocate_signatured_type ();
+      sig_type = per_objfile->per_bfd->allocate_signatured_type ();
       sig_type->signature = cu_header.signature;
       sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu;
       sig_type->per_cu.is_debug_types = 1;
       sig_type->per_cu.section = section;
       sig_type->per_cu.sect_off = sect_off;
       sig_type->per_cu.v.quick
-       = OBSTACK_ZALLOC (&dwarf2_per_objfile->per_bfd->obstack,
+       = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack,
                          struct dwarf2_per_cu_quick_data);
 
       slot = htab_find_slot (sig_types_hash.get (), sig_type, INSERT);
       *slot = sig_type;
 
-      dwarf2_per_objfile->per_bfd->all_type_units.push_back (sig_type);
+      per_objfile->per_bfd->all_type_units.push_back (sig_type);
     }
 
-  dwarf2_per_objfile->per_bfd->signatured_types = std::move (sig_types_hash);
+  per_objfile->per_bfd->signatured_types = std::move (sig_types_hash);
 }
 
 /* Read the address map data from the mapped index, and use it to
    populate the objfile's psymtabs_addrmap.  */
 
 static void
-create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
+create_addrmap_from_index (dwarf2_per_objfile *per_objfile,
                           struct mapped_index *index)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
   const gdb_byte *iter, *end;
   struct addrmap *mutable_map;
@@ -2698,7 +2834,7 @@ create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
          continue;
        }
 
-      if (cu_index >= dwarf2_per_objfile->per_bfd->all_comp_units.size ())
+      if (cu_index >= per_objfile->per_bfd->all_comp_units.size ())
        {
          complaint (_(".gdb_index address table has invalid CU number %u"),
                     (unsigned) cu_index);
@@ -2708,7 +2844,7 @@ create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
       lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr) - baseaddr;
       hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr) - baseaddr;
       addrmap_set_empty (mutable_map, lo, hi - 1,
-                        dwarf2_per_objfile->per_bfd->get_cu (cu_index));
+                        per_objfile->per_bfd->get_cu (cu_index));
     }
 
   objfile->partial_symtabs->psymtabs_addrmap
@@ -2719,10 +2855,10 @@ create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
    populate the objfile's psymtabs_addrmap.  */
 
 static void
-create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
+create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
                             struct dwarf2_section_info *section)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
   bfd *abfd = objfile->obfd;
   struct gdbarch *gdbarch = objfile->arch ();
   const CORE_ADDR baseaddr = objfile->text_section_offset ();
@@ -2734,7 +2870,7 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
                     dwarf2_per_cu_data *,
                     gdb::hash_enum<sect_offset>>
     debug_info_offset_to_per_cu;
-  for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
     {
       const auto insertpair
        = debug_info_offset_to_per_cu.emplace (per_cu->sect_off, per_cu);
@@ -2768,7 +2904,7 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
       if (addr + entry_length > section->buffer + section->size)
        {
          warning (_("Section .debug_aranges in %s entry at offset %s "
-                    "length %s exceeds section length %s, "
+                    "length %s exceeds section length %s, "
                     "ignoring .debug_aranges."),
                   objfile_name (objfile),
                   plongest (entry_addr - section->buffer),
@@ -2829,11 +2965,11 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
        }
 
       /* Must pad to an alignment boundary that is twice the address
-         size.  It is undocumented by the DWARF standard but GCC does
-         use it.  */
+        size.  It is undocumented by the DWARF standard but GCC does
+        use it.  */
       for (size_t padding = ((-(addr - section->buffer))
                             & (2 * address_size - 1));
-           padding > 0; padding--)
+          padding > 0; padding--)
        if (*addr++ != 0)
          {
            warning (_("Section .debug_aranges in %s entry at offset %s "
@@ -2862,7 +2998,7 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
          addr += address_size;
          if (start == 0 && length == 0)
            break;
-         if (start == 0 && !dwarf2_per_objfile->per_bfd->has_section_at_zero)
+         if (start == 0 && !per_objfile->per_bfd->has_section_at_zero)
            {
              /* Symbol was eliminated due to a COMDAT group.  */
              continue;
@@ -2914,7 +3050,7 @@ find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
      indices for case insensitive languages are built in lowercase, therefore
      simulate our NAME being searched is also lowercased.  */
   hash = mapped_index_string_hash ((index->version == 4
-                                    && case_sensitivity == case_sensitive_off
+                                   && case_sensitivity == case_sensitive_off
                                    ? 5 : index->version),
                                   name);
 
@@ -3066,17 +3202,18 @@ typedef gdb::function_view
 
 static int
 dwarf2_read_gdb_index
-  (struct dwarf2_per_objfile *dwarf2_per_objfile,
+  (dwarf2_per_objfile *per_objfile,
    get_gdb_index_contents_ftype get_gdb_index_contents,
    get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz)
 {
   const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
   offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
   struct dwz_file *dwz;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
 
   gdb::array_view<const gdb_byte> main_index_contents
-    = get_gdb_index_contents (objfile, dwarf2_per_objfile->per_bfd);
+    = get_gdb_index_contents (objfile, per_bfd);
 
   if (main_index_contents.empty ())
     return 0;
@@ -3095,7 +3232,7 @@ dwarf2_read_gdb_index
 
   /* If there is a .dwz file, read it so we can get its CU list as
      well.  */
-  dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
+  dwz = dwarf2_get_dwz_file (per_bfd);
   if (dwz != NULL)
     {
       struct mapped_index dwz_map;
@@ -3120,29 +3257,33 @@ dwarf2_read_gdb_index
        }
     }
 
-  create_cus_from_index (dwarf2_per_objfile->per_bfd, cu_list, cu_list_elements,
-                        dwz_list, dwz_list_elements);
+  create_cus_from_index (per_bfd, cu_list, cu_list_elements, dwz_list,
+                        dwz_list_elements);
 
   if (types_list_elements)
     {
       /* We can only handle a single .debug_types when we have an
         index.  */
-      if (dwarf2_per_objfile->per_bfd->types.size () != 1)
+      if (per_bfd->types.size () != 1)
        return 0;
 
-      dwarf2_section_info *section = &dwarf2_per_objfile->per_bfd->types[0];
+      dwarf2_section_info *section = &per_bfd->types[0];
 
-      create_signatured_type_table_from_index (dwarf2_per_objfile->per_bfd,
-                                              section, types_list,
+      create_signatured_type_table_from_index (per_bfd, section, types_list,
                                               types_list_elements);
     }
 
-  create_addrmap_from_index (dwarf2_per_objfile, map.get ());
+  create_addrmap_from_index (per_objfile, map.get ());
 
-  dwarf2_per_objfile->per_bfd->index_table = std::move (map);
-  dwarf2_per_objfile->per_bfd->using_index = 1;
-  dwarf2_per_objfile->per_bfd->quick_file_names_table =
-    create_quick_file_names_table (dwarf2_per_objfile->per_bfd->all_comp_units.size ());
+  per_bfd->index_table = std::move (map);
+  per_bfd->using_index = 1;
+  per_bfd->quick_file_names_table =
+    create_quick_file_names_table (per_bfd->all_comp_units.size ());
+
+  /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
+     objfiles using the same BFD.  */
+  gdb_assert (per_bfd->partial_symtabs == nullptr);
+  per_bfd->partial_symtabs = objfile->partial_symtabs;
 
   return 1;
 }
@@ -3156,7 +3297,7 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
 {
   struct dwarf2_cu *cu = reader->cu;
   struct dwarf2_per_cu_data *this_cu = cu->per_cu;
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct dwarf2_per_cu_data *lh_cu;
   struct attribute *attr;
   void **slot;
@@ -3179,17 +3320,17 @@ 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 != nullptr)
+  if (attr != nullptr && attr->form_is_unsigned ())
     {
       struct quick_file_names find_entry;
 
-      line_offset = (sect_offset) DW_UNSND (attr);
+      line_offset = (sect_offset) attr->as_unsigned ();
 
       /* We may have already read in this line header (TU line header sharing).
         If we have we're done.  */
       find_entry.hash.dwo_unit = cu->dwo_unit;
       find_entry.hash.line_sect_off = line_offset;
-      slot = htab_find_slot (dwarf2_per_objfile->per_bfd->quick_file_names_table.get (),
+      slot = htab_find_slot (per_objfile->per_bfd->quick_file_names_table.get (),
                             &find_entry, INSERT);
       if (*slot != NULL)
        {
@@ -3205,7 +3346,7 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
       return;
     }
 
-  qfn = XOBNEW (&dwarf2_per_objfile->per_bfd->obstack, struct quick_file_names);
+  qfn = XOBNEW (&per_objfile->per_bfd->obstack, struct quick_file_names);
   qfn->hash.dwo_unit = cu->dwo_unit;
   qfn->hash.line_sect_off = line_offset;
   gdb_assert (slot != NULL);
@@ -3219,7 +3360,7 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
 
   qfn->num_file_names = offset + lh->file_names_size ();
   qfn->file_names =
-    XOBNEWVEC (&dwarf2_per_objfile->per_bfd->obstack, const char *,
+    XOBNEWVEC (&per_objfile->per_bfd->obstack, const char *,
               qfn->num_file_names);
   if (offset != 0)
     qfn->file_names[0] = xstrdup (fnd.name);
@@ -3262,11 +3403,11 @@ dw2_get_file_names (dwarf2_per_cu_data *this_cu,
    real path for a given file name from the line table.  */
 
 static const char *
-dw2_get_real_path (struct dwarf2_per_objfile *dwarf2_per_objfile,
+dw2_get_real_path (dwarf2_per_objfile *per_objfile,
                   struct quick_file_names *qfn, int index)
 {
   if (qfn->real_names == NULL)
-    qfn->real_names = OBSTACK_CALLOC (&dwarf2_per_objfile->per_bfd->obstack,
+    qfn->real_names = OBSTACK_CALLOC (&per_objfile->per_bfd->obstack,
                                      qfn->num_file_names, const char *);
 
   if (qfn->real_names[index] == NULL)
@@ -3278,11 +3419,9 @@ dw2_get_real_path (struct dwarf2_per_objfile *dwarf2_per_objfile,
 static struct symtab *
 dw2_find_last_source_symtab (struct objfile *objfile)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
-  dwarf2_per_cu_data *dwarf_cu = dwarf2_per_objfile->per_bfd->all_comp_units.back ();
-  compunit_symtab *cust
-    = dw2_instantiate_symtab (dwarf_cu, dwarf2_per_objfile, false);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_cu_data *dwarf_cu = per_objfile->per_bfd->all_comp_units.back ();
+  compunit_symtab *cust = dw2_instantiate_symtab (dwarf_cu, per_objfile, false);
 
   if (cust == NULL)
     return NULL;
@@ -3314,10 +3453,9 @@ dw2_free_cached_file_names (void **slot, void *info)
 static void
 dw2_forget_cached_source_info (struct objfile *objfile)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  htab_traverse_noresize (dwarf2_per_objfile->per_bfd->quick_file_names_table.get (),
+  htab_traverse_noresize (per_objfile->per_bfd->quick_file_names_table.get (),
                          dw2_free_cached_file_names, NULL);
 }
 
@@ -3353,20 +3491,18 @@ dw2_map_symtabs_matching_filename
    gdb::function_view<bool (symtab *)> callback)
 {
   const char *name_basename = lbasename (name);
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
   /* The rule is CUs specify all the files, including those used by
      any TU, so there's no need to scan TUs here.  */
 
-  for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
     {
       /* We only need to look at symtabs not already expanded.  */
-      if (dwarf2_per_objfile->symtab_set_p (per_cu))
+      if (per_objfile->symtab_set_p (per_cu))
        continue;
 
-      quick_file_names *file_data
-       = dw2_get_file_names (per_cu, dwarf2_per_objfile);
+      quick_file_names *file_data = dw2_get_file_names (per_cu, per_objfile);
       if (file_data == NULL)
        continue;
 
@@ -3389,8 +3525,7 @@ dw2_map_symtabs_matching_filename
              && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
            continue;
 
-         this_real_name = dw2_get_real_path (dwarf2_per_objfile,
-                                             file_data, j);
+         this_real_name = dw2_get_real_path (per_objfile, file_data, j);
          if (compare_filenames_for_search (this_real_name, name))
            {
              if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
@@ -3423,7 +3558,7 @@ dw2_map_symtabs_matching_filename
 struct dw2_symtab_iterator
 {
   /* The dwarf2_per_objfile owning the CUs we are iterating on.  */
-  struct dwarf2_per_objfile *dwarf2_per_objfile;
+  dwarf2_per_objfile *per_objfile;
   /* If set, only look for symbols that match that block.  Valid values are
      GLOBAL_BLOCK and STATIC_BLOCK.  */
   gdb::optional<block_enum> block_index;
@@ -3443,31 +3578,64 @@ struct dw2_symtab_iterator
   int global_seen;
 };
 
-/* Initialize the index symtab iterator ITER.  */
+/* Initialize the index symtab iterator ITER, common part.  */
 
 static void
-dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
-                     struct dwarf2_per_objfile *dwarf2_per_objfile,
-                     gdb::optional<block_enum> block_index,
-                     domain_enum domain,
-                     const char *name)
+dw2_symtab_iter_init_common (struct dw2_symtab_iterator *iter,
+                            dwarf2_per_objfile *per_objfile,
+                            gdb::optional<block_enum> block_index,
+                            domain_enum domain)
 {
-  iter->dwarf2_per_objfile = dwarf2_per_objfile;
+  iter->per_objfile = per_objfile;
   iter->block_index = block_index;
   iter->domain = domain;
   iter->next = 0;
   iter->global_seen = 0;
+  iter->vec = NULL;
+  iter->length = 0;
+}
 
-  mapped_index *index = dwarf2_per_objfile->per_bfd->index_table.get ();
+/* Initialize the index symtab iterator ITER, const char *NAME variant.  */
+
+static void
+dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
+                     dwarf2_per_objfile *per_objfile,
+                     gdb::optional<block_enum> block_index,
+                     domain_enum domain,
+                     const char *name)
+{
+  dw2_symtab_iter_init_common (iter, per_objfile, block_index, domain);
 
+  mapped_index *index = per_objfile->per_bfd->index_table.get ();
   /* index is NULL if OBJF_READNOW.  */
-  if (index != NULL && find_slot_in_mapped_hash (index, name, &iter->vec))
+  if (index == NULL)
+    return;
+
+  if (find_slot_in_mapped_hash (index, name, &iter->vec))
     iter->length = MAYBE_SWAP (*iter->vec);
-  else
-    {
-      iter->vec = NULL;
-      iter->length = 0;
-    }
+}
+
+/* Initialize the index symtab iterator ITER, offset_type NAMEI variant.  */
+
+static void
+dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
+                     dwarf2_per_objfile *per_objfile,
+                     gdb::optional<block_enum> block_index,
+                     domain_enum domain, offset_type namei)
+{
+  dw2_symtab_iter_init_common (iter, per_objfile, block_index, domain);
+
+  mapped_index *index = per_objfile->per_bfd->index_table.get ();
+  /* index is NULL if OBJF_READNOW.  */
+  if (index == NULL)
+    return;
+
+  gdb_assert (!index->symbol_name_slot_invalid (namei));
+  const auto &bucket = index->symbol_table[namei];
+
+  iter->vec = (offset_type *) (index->constant_pool
+                              + MAYBE_SWAP (bucket.vec));
+  iter->length = MAYBE_SWAP (*iter->vec);
 }
 
 /* Return the next matching CU or NULL if there are no more.  */
@@ -3475,7 +3643,7 @@ dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
 static struct dwarf2_per_cu_data *
 dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = iter->dwarf2_per_objfile;
+  dwarf2_per_objfile *per_objfile = iter->per_objfile;
 
   for ( ; iter->next < iter->length; ++iter->next)
     {
@@ -3489,23 +3657,22 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
         and indices >= 7 may elide them for certain symbols
         (gold does this).  */
       int attrs_valid =
-       (dwarf2_per_objfile->per_bfd->index_table->version >= 7
+       (per_objfile->per_bfd->index_table->version >= 7
         && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
 
       /* Don't crash on bad data.  */
-      if (cu_index >= (dwarf2_per_objfile->per_bfd->all_comp_units.size ()
-                      + dwarf2_per_objfile->per_bfd->all_type_units.size ()))
+      if (cu_index >= (per_objfile->per_bfd->all_comp_units.size ()
+                      + per_objfile->per_bfd->all_type_units.size ()))
        {
          complaint (_(".gdb_index entry has bad CU index"
-                      " [in module %s]"),
-                    objfile_name (dwarf2_per_objfile->objfile));
+                      " [in module %s]"), objfile_name (per_objfile->objfile));
          continue;
        }
 
-      dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->per_bfd->get_cutu (cu_index);
+      dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cutu (cu_index);
 
       /* Skip if already read in.  */
-      if (dwarf2_per_objfile->symtab_set_p (per_cu))
+      if (per_objfile->symtab_set_p (per_cu))
        continue;
 
       /* Check static vs global.  */
@@ -3573,21 +3740,20 @@ dw2_lookup_symbol (struct objfile *objfile, block_enum block_index,
                   const char *name, domain_enum domain)
 {
   struct compunit_symtab *stab_best = NULL;
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
 
   struct dw2_symtab_iterator iter;
   struct dwarf2_per_cu_data *per_cu;
 
-  dw2_symtab_iter_init (&iter, dwarf2_per_objfile, block_index, domain, name);
+  dw2_symtab_iter_init (&iter, per_objfile, block_index, domain, name);
 
   while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
     {
       struct symbol *sym, *with_opaque = NULL;
       struct compunit_symtab *stab
-       = dw2_instantiate_symtab (per_cu, dwarf2_per_objfile, false);
+       = dw2_instantiate_symtab (per_cu, per_objfile, false);
       const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
       const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
 
@@ -3615,17 +3781,16 @@ dw2_lookup_symbol (struct objfile *objfile, block_enum block_index,
 static void
 dw2_print_stats (struct objfile *objfile)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
-  int total = (dwarf2_per_objfile->per_bfd->all_comp_units.size ()
-              + dwarf2_per_objfile->per_bfd->all_type_units.size ());
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
+  int total = (per_objfile->per_bfd->all_comp_units.size ()
+              + per_objfile->per_bfd->all_type_units.size ());
   int count = 0;
 
   for (int i = 0; i < total; ++i)
     {
-      dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->per_bfd->get_cutu (i);
+      dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cutu (i);
 
-      if (!dwarf2_per_objfile->symtab_set_p (per_cu))
+      if (!per_objfile->symtab_set_p (per_cu))
        ++count;
     }
   printf_filtered (_("  Number of read CUs: %d\n"), total - count);
@@ -3640,15 +3805,14 @@ dw2_print_stats (struct objfile *objfile)
 static void
 dw2_dump (struct objfile *objfile)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  gdb_assert (dwarf2_per_objfile->per_bfd->using_index);
+  gdb_assert (per_objfile->per_bfd->using_index);
   printf_filtered (".gdb_index:");
-  if (dwarf2_per_objfile->per_bfd->index_table != NULL)
+  if (per_objfile->per_bfd->index_table != NULL)
     {
       printf_filtered (" version %d\n",
-                      dwarf2_per_objfile->per_bfd->index_table->version);
+                      per_objfile->per_bfd->index_table->version);
     }
   else
     printf_filtered (" faked for \"readnow\"\n");
@@ -3659,37 +3823,35 @@ static void
 dw2_expand_symtabs_for_function (struct objfile *objfile,
                                 const char *func_name)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
   struct dw2_symtab_iterator iter;
   struct dwarf2_per_cu_data *per_cu;
 
-  dw2_symtab_iter_init (&iter, dwarf2_per_objfile, {}, VAR_DOMAIN, func_name);
+  dw2_symtab_iter_init (&iter, per_objfile, {}, VAR_DOMAIN, func_name);
 
   while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
-    dw2_instantiate_symtab (per_cu, dwarf2_per_objfile, false);
+    dw2_instantiate_symtab (per_cu, per_objfile, false);
 
 }
 
 static void
 dw2_expand_all_symtabs (struct objfile *objfile)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
-  int total_units = (dwarf2_per_objfile->per_bfd->all_comp_units.size ()
-                    + dwarf2_per_objfile->per_bfd->all_type_units.size ());
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
+  int total_units = (per_objfile->per_bfd->all_comp_units.size ()
+                    + per_objfile->per_bfd->all_type_units.size ());
 
   for (int i = 0; i < total_units; ++i)
     {
-      dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->per_bfd->get_cutu (i);
+      dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cutu (i);
 
       /* We don't want to directly expand a partial CU, because if we
         read it with the wrong language, then assertion failures can
         be triggered later on.  See PR symtab/23010.  So, tell
         dw2_instantiate_symtab to skip partial CUs -- any important
         partial CU will be read via DW_TAG_imported_unit anyway.  */
-      dw2_instantiate_symtab (per_cu, dwarf2_per_objfile, true);
+      dw2_instantiate_symtab (per_cu, per_objfile, true);
     }
 }
 
@@ -3697,22 +3859,20 @@ static void
 dw2_expand_symtabs_with_fullname (struct objfile *objfile,
                                  const char *fullname)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
   /* We don't need to consider type units here.
      This is only called for examining code, e.g. expand_line_sal.
      There can be an order of magnitude (or more) more type units
      than comp units, and we avoid them if we can.  */
 
-  for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
     {
       /* We only need to look at symtabs not already expanded.  */
-      if (dwarf2_per_objfile->symtab_set_p (per_cu))
+      if (per_objfile->symtab_set_p (per_cu))
        continue;
 
-      quick_file_names *file_data
-       = dw2_get_file_names (per_cu, dwarf2_per_objfile);
+      quick_file_names *file_data = dw2_get_file_names (per_cu, per_objfile);
       if (file_data == NULL)
        continue;
 
@@ -3722,7 +3882,7 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile,
 
          if (filename_cmp (this_fullname, fullname) == 0)
            {
-             dw2_instantiate_symtab (per_cu, dwarf2_per_objfile, false);
+             dw2_instantiate_symtab (per_cu, per_objfile, false);
              break;
            }
        }
@@ -3754,17 +3914,13 @@ dw2_map_matching_symbols
    symbol_compare_ftype *ordered_compare)
 {
   /* Used for Ada.  */
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
   const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
 
-  if (dwarf2_per_objfile->per_bfd->index_table != nullptr)
+  if (per_objfile->per_bfd->index_table != nullptr)
     {
-      /* Ada currently doesn't support .gdb_index (see PR24713).  We can get
-        here though if the current language is Ada for a non-Ada objfile
-        using GNU index.  */
-      mapped_index &index = *dwarf2_per_objfile->per_bfd->index_table;
+      mapped_index &index = *per_objfile->per_bfd->index_table;
 
       const char *match_name = name.ada ().lookup_name ().c_str ();
       auto matcher = [&] (const char *symname)
@@ -3780,13 +3936,13 @@ dw2_map_matching_symbols
        struct dw2_symtab_iterator iter;
        struct dwarf2_per_cu_data *per_cu;
 
-       dw2_symtab_iter_init (&iter, dwarf2_per_objfile, block_kind, domain,
-                             match_name);
+       dw2_symtab_iter_init (&iter, per_objfile, block_kind, domain,
+                             namei);
        while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
-         dw2_expand_symtabs_matching_one (per_cu, dwarf2_per_objfile, nullptr,
+         dw2_expand_symtabs_matching_one (per_cu, per_objfile, nullptr,
                                           nullptr);
        return true;
-      }, dwarf2_per_objfile);
+      }, per_objfile);
     }
   else
     {
@@ -4083,10 +4239,10 @@ dw2_expand_symtabs_matching_symbol
 
       const language_defn *lang = language_def (lang_e);
       symbol_name_matcher_ftype *name_matcher
-       = get_symbol_name_matcher (lang, lookup_name_without_params);
+       = lang->get_symbol_name_matcher (lookup_name_without_params);
 
       name_and_matcher key {
-         name_matcher,
+        name_matcher,
         lookup_name_without_params.language_lookup_name (lang_e)
       };
 
@@ -4602,14 +4758,14 @@ dw2_expand_symtabs_matching_one
 
 static void
 dw2_expand_marked_cus
-  (dwarf2_per_objfile *dwarf2_per_objfile, offset_type idx,
+  (dwarf2_per_objfile *per_objfile, offset_type idx,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
    search_domain kind)
 {
   offset_type *vec, vec_len, vec_idx;
   bool global_seen = false;
-  mapped_index &index = *dwarf2_per_objfile->per_bfd->index_table;
+  mapped_index &index = *per_objfile->per_bfd->index_table;
 
   vec = (offset_type *) (index.constant_pool
                         + MAYBE_SWAP (index.symbol_table[idx].vec));
@@ -4668,17 +4824,16 @@ dw2_expand_marked_cus
        }
 
       /* Don't crash on bad data.  */
-      if (cu_index >= (dwarf2_per_objfile->per_bfd->all_comp_units.size ()
-                      + dwarf2_per_objfile->per_bfd->all_type_units.size ()))
+      if (cu_index >= (per_objfile->per_bfd->all_comp_units.size ()
+                      + per_objfile->per_bfd->all_type_units.size ()))
        {
          complaint (_(".gdb_index entry has bad CU index"
-                      " [in module %s]"),
-                      objfile_name (dwarf2_per_objfile->objfile));
+                      " [in module %s]"), objfile_name (per_objfile->objfile));
          continue;
        }
 
-      dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->per_bfd->get_cutu (cu_index);
-      dw2_expand_symtabs_matching_one (per_cu, dwarf2_per_objfile, file_matcher,
+      dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cutu (cu_index);
+      dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
                                       expansion_notify);
     }
 }
@@ -4689,7 +4844,7 @@ dw2_expand_marked_cus
 
 static void
 dw_expand_symtabs_matching_file_matcher
-  (struct dwarf2_per_objfile *dwarf2_per_objfile,
+  (dwarf2_per_objfile *per_objfile,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher)
 {
   if (file_matcher == NULL)
@@ -4705,18 +4860,17 @@ dw_expand_symtabs_matching_file_matcher
   /* The rule is CUs specify all the files, including those used by
      any TU, so there's no need to scan TUs here.  */
 
-  for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
     {
       QUIT;
 
       per_cu->v.quick->mark = 0;
 
       /* We only need to look at symtabs not already expanded.  */
-      if (dwarf2_per_objfile->symtab_set_p (per_cu))
+      if (per_objfile->symtab_set_p (per_cu))
        continue;
 
-      quick_file_names *file_data
-       = dw2_get_file_names (per_cu, dwarf2_per_objfile);
+      quick_file_names *file_data = dw2_get_file_names (per_cu, per_objfile);
       if (file_data == NULL)
        continue;
 
@@ -4745,8 +4899,7 @@ dw_expand_symtabs_matching_file_matcher
                                true))
            continue;
 
-         this_real_name = dw2_get_real_path (dwarf2_per_objfile,
-                                             file_data, j);
+         this_real_name = dw2_get_real_path (per_objfile, file_data, j);
          if (file_matcher (this_real_name, false))
            {
              per_cu->v.quick->mark = 1;
@@ -4771,37 +4924,36 @@ dw2_expand_symtabs_matching
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
    enum search_domain kind)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
   /* index_table is NULL if OBJF_READNOW.  */
-  if (!dwarf2_per_objfile->per_bfd->index_table)
+  if (!per_objfile->per_bfd->index_table)
     return;
 
-  dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile, file_matcher);
+  dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
 
   if (symbol_matcher == NULL && lookup_name == NULL)
     {
-      for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+      for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
        {
          QUIT;
 
-         dw2_expand_symtabs_matching_one (per_cu, dwarf2_per_objfile,
+         dw2_expand_symtabs_matching_one (per_cu, per_objfile,
                                           file_matcher, expansion_notify);
        }
       return;
     }
 
-  mapped_index &index = *dwarf2_per_objfile->per_bfd->index_table;
+  mapped_index &index = *per_objfile->per_bfd->index_table;
 
   dw2_expand_symtabs_matching_symbol (index, *lookup_name,
                                      symbol_matcher,
                                      kind, [&] (offset_type idx)
     {
-      dw2_expand_marked_cus (dwarf2_per_objfile, idx, file_matcher,
-                            expansion_notify, kind);
+      dw2_expand_marked_cus (per_objfile, idx, file_matcher, expansion_notify,
+                            kind);
       return true;
-    }, dwarf2_per_objfile);
+    }, per_objfile);
 }
 
 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
@@ -4867,12 +5019,11 @@ static void
 dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
                          void *data, int need_fullname)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  if (!dwarf2_per_objfile->per_bfd->filenames_cache)
+  if (!per_objfile->per_bfd->filenames_cache)
     {
-      dwarf2_per_objfile->per_bfd->filenames_cache.emplace ();
+      per_objfile->per_bfd->filenames_cache.emplace ();
 
       htab_up visited (htab_create_alloc (10,
                                          htab_hash_pointer, htab_eq_pointer,
@@ -4882,9 +5033,9 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
         by any TU, so there's no need to scan TUs here.  We can
         ignore file names coming from already-expanded CUs.  */
 
-      for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+      for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
        {
-         if (dwarf2_per_objfile->symtab_set_p (per_cu))
+         if (per_objfile->symtab_set_p (per_cu))
            {
              void **slot = htab_find_slot (visited.get (),
                                            per_cu->v.quick->file_names,
@@ -4894,14 +5045,14 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
            }
        }
 
-      for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+      for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
        {
          /* We only need to look at symtabs not already expanded.  */
-         if (dwarf2_per_objfile->symtab_set_p (per_cu))
+         if (per_objfile->symtab_set_p (per_cu))
            continue;
 
          quick_file_names *file_data
-           = dw2_get_file_names (per_cu, dwarf2_per_objfile);
+           = dw2_get_file_names (per_cu, per_objfile);
          if (file_data == NULL)
            continue;
 
@@ -4916,12 +5067,12 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
          for (int j = 0; j < file_data->num_file_names; ++j)
            {
              const char *filename = file_data->file_names[j];
-             dwarf2_per_objfile->per_bfd->filenames_cache->seen (filename);
+             per_objfile->per_bfd->filenames_cache->seen (filename);
            }
        }
     }
 
-  dwarf2_per_objfile->per_bfd->filenames_cache->traverse ([&] (const char *filename)
+  per_objfile->per_bfd->filenames_cache->traverse ([&] (const char *filename)
     {
       gdb::unique_xmalloc_ptr<char> this_real_name;
 
@@ -5226,15 +5377,15 @@ create_cus_from_debug_names (dwarf2_per_bfd *per_bfd,
    elements of all the CUs and return true.  Otherwise, return false.  */
 
 static bool
-dwarf2_read_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile)
+dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
 {
   std::unique_ptr<mapped_debug_names> map (new mapped_debug_names);
   mapped_debug_names dwz_map;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
 
   if (!read_debug_names_from_section (objfile, objfile_name (objfile),
-                                     &dwarf2_per_objfile->per_bfd->debug_names,
-                                     *map))
+                                     &per_objfile->per_bfd->debug_names, *map))
     return false;
 
   /* Don't use the index if it's empty.  */
@@ -5243,7 +5394,7 @@ dwarf2_read_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   /* If there is a .dwz file, read it so we can get its CU list as
      well.  */
-  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
+  dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
   if (dwz != NULL)
     {
       if (!read_debug_names_from_section (objfile,
@@ -5256,28 +5407,32 @@ dwarf2_read_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile)
        }
     }
 
-  create_cus_from_debug_names (dwarf2_per_objfile->per_bfd, *map, dwz_map);
+  create_cus_from_debug_names (per_bfd, *map, dwz_map);
 
   if (map->tu_count != 0)
     {
       /* We can only handle a single .debug_types when we have an
         index.  */
-      if (dwarf2_per_objfile->per_bfd->types.size () != 1)
+      if (per_bfd->types.size () != 1)
        return false;
 
-      dwarf2_section_info *section = &dwarf2_per_objfile->per_bfd->types[0];
+      dwarf2_section_info *section = &per_bfd->types[0];
 
       create_signatured_type_table_from_debug_names
-       (dwarf2_per_objfile, *map, section, &dwarf2_per_objfile->per_bfd->abbrev);
+       (per_objfile, *map, section, &per_bfd->abbrev);
     }
 
-  create_addrmap_from_aranges (dwarf2_per_objfile,
-                              &dwarf2_per_objfile->per_bfd->debug_aranges);
+  create_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges);
+
+  per_bfd->debug_names_table = std::move (map);
+  per_bfd->using_index = 1;
+  per_bfd->quick_file_names_table =
+    create_quick_file_names_table (per_objfile->per_bfd->all_comp_units.size ());
 
-  dwarf2_per_objfile->per_bfd->debug_names_table = std::move (map);
-  dwarf2_per_objfile->per_bfd->using_index = 1;
-  dwarf2_per_objfile->per_bfd->quick_file_names_table =
-    create_quick_file_names_table (dwarf2_per_objfile->per_bfd->all_comp_units.size ());
+  /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
+     objfiles using the same BFD.  */
+  gdb_assert (per_bfd->partial_symtabs == nullptr);
+  per_bfd->partial_symtabs = objfile->partial_symtabs;
 
   return true;
 }
@@ -5318,9 +5473,11 @@ public:
 
 private:
   static const gdb_byte *find_vec_in_debug_names (const mapped_debug_names &map,
-                                                 const char *name, dwarf2_per_objfile *per_objfile);
+                                                 const char *name,
+                                                 dwarf2_per_objfile *per_objfile);
   static const gdb_byte *find_vec_in_debug_names (const mapped_debug_names &map,
-                                                 uint32_t namei, dwarf2_per_objfile *per_objfile);
+                                                 uint32_t namei,
+                                                 dwarf2_per_objfile *per_objfile);
 
   /* The internalized form of .debug_names.  */
   const mapped_debug_names &m_map;
@@ -5342,15 +5499,14 @@ private:
 
 const char *
 mapped_debug_names::namei_to_name
-  (uint32_t namei, dwarf2_per_objfile *dwarf2_per_objfile) const
+  (uint32_t namei, dwarf2_per_objfile *per_objfile) const
 {
   const ULONGEST namei_string_offs
     = extract_unsigned_integer ((name_table_string_offs_reordered
                                 + namei * offset_size),
                                offset_size,
                                dwarf5_byte_order);
-  return read_indirect_string_at_offset (dwarf2_per_objfile,
-                                        namei_string_offs);
+  return read_indirect_string_at_offset (per_objfile, namei_string_offs);
 }
 
 /* Find a slot in .debug_names for the object named NAME.  If NAME is
@@ -5359,7 +5515,8 @@ mapped_debug_names::namei_to_name
 
 const gdb_byte *
 dw2_debug_names_iterator::find_vec_in_debug_names
-  (const mapped_debug_names &map, const char *name, dwarf2_per_objfile *per_objfile)
+  (const mapped_debug_names &map, const char *name,
+   dwarf2_per_objfile *per_objfile)
 {
   int (*cmp) (const char *, const char *);
 
@@ -5686,10 +5843,9 @@ static struct compunit_symtab *
 dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
                               const char *name, domain_enum domain)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  const auto &mapp = dwarf2_per_objfile->per_bfd->debug_names_table;
+  const auto &mapp = per_objfile->per_bfd->debug_names_table;
   if (!mapp)
     {
       /* index is NULL if OBJF_READNOW.  */
@@ -5697,8 +5853,7 @@ dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
     }
   const auto &map = *mapp;
 
-  dw2_debug_names_iterator iter (map, block_index, domain, name,
-                                dwarf2_per_objfile);
+  dw2_debug_names_iterator iter (map, block_index, domain, name, per_objfile);
 
   struct compunit_symtab *stab_best = NULL;
   struct dwarf2_per_cu_data *per_cu;
@@ -5706,7 +5861,7 @@ dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
     {
       struct symbol *sym, *with_opaque = NULL;
       compunit_symtab *stab
-       = dw2_instantiate_symtab (per_cu, dwarf2_per_objfile, false);
+       = dw2_instantiate_symtab (per_cu, per_objfile, false);
       const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
       const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
 
@@ -5738,12 +5893,11 @@ dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
 static void
 dw2_debug_names_dump (struct objfile *objfile)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  gdb_assert (dwarf2_per_objfile->per_bfd->using_index);
+  gdb_assert (per_objfile->per_bfd->using_index);
   printf_filtered (".debug_names:");
-  if (dwarf2_per_objfile->per_bfd->debug_names_table)
+  if (per_objfile->per_bfd->debug_names_table)
     printf_filtered (" exists\n");
   else
     printf_filtered (" faked for \"readnow\"\n");
@@ -5754,20 +5908,19 @@ static void
 dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile,
                                             const char *func_name)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  /* dwarf2_per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW.  */
-  if (dwarf2_per_objfile->per_bfd->debug_names_table)
+  /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW.  */
+  if (per_objfile->per_bfd->debug_names_table)
     {
-      const mapped_debug_names &map = *dwarf2_per_objfile->per_bfd->debug_names_table;
+      const mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
 
       dw2_debug_names_iterator iter (map, {}, VAR_DOMAIN, func_name,
-                                    dwarf2_per_objfile);
+                                    per_objfile);
 
       struct dwarf2_per_cu_data *per_cu;
       while ((per_cu = iter.next ()) != NULL)
-       dw2_instantiate_symtab (per_cu, dwarf2_per_objfile, false);
+       dw2_instantiate_symtab (per_cu, per_objfile, false);
     }
 }
 
@@ -5779,14 +5932,13 @@ dw2_debug_names_map_matching_symbols
    gdb::function_view<symbol_found_callback_ftype> callback,
    symbol_compare_ftype *ordered_compare)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
   /* debug_names_table is NULL if OBJF_READNOW.  */
-  if (!dwarf2_per_objfile->per_bfd->debug_names_table)
+  if (!per_objfile->per_bfd->debug_names_table)
     return;
 
-  mapped_debug_names &map = *dwarf2_per_objfile->per_bfd->debug_names_table;
+  mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
   const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
 
   const char *match_name = name.ada ().lookup_name ().c_str ();
@@ -5803,22 +5955,22 @@ dw2_debug_names_map_matching_symbols
       /* The name was matched, now expand corresponding CUs that were
         marked.  */
       dw2_debug_names_iterator iter (map, block_kind, domain, namei,
-                                    dwarf2_per_objfile);
+                                    per_objfile);
 
       struct dwarf2_per_cu_data *per_cu;
       while ((per_cu = iter.next ()) != NULL)
-       dw2_expand_symtabs_matching_one (per_cu, dwarf2_per_objfile, nullptr,
+       dw2_expand_symtabs_matching_one (per_cu, per_objfile, nullptr,
                                         nullptr);
       return true;
-    }, dwarf2_per_objfile);
+    }, per_objfile);
 
   /* It's a shame we couldn't do this inside the
      dw2_expand_symtabs_matching_symbol callback, but that skips CUs
      that have already been expanded.  Instead, this loop matches what
      the psymtab code does.  */
-  for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
     {
-      compunit_symtab *symtab = dwarf2_per_objfile->get_symtab (per_cu);
+      compunit_symtab *symtab = per_objfile->get_symtab (per_cu);
       if (symtab != nullptr)
        {
          const struct block *block
@@ -5839,28 +5991,27 @@ dw2_debug_names_expand_symtabs_matching
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
    enum search_domain kind)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
   /* debug_names_table is NULL if OBJF_READNOW.  */
-  if (!dwarf2_per_objfile->per_bfd->debug_names_table)
+  if (!per_objfile->per_bfd->debug_names_table)
     return;
 
-  dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile, file_matcher);
+  dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
 
   if (symbol_matcher == NULL && lookup_name == NULL)
     {
-      for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+      for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
        {
          QUIT;
 
-         dw2_expand_symtabs_matching_one (per_cu, dwarf2_per_objfile,
-                                          file_matcher, expansion_notify);
+         dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
+                                          expansion_notify);
        }
       return;
     }
 
-  mapped_debug_names &map = *dwarf2_per_objfile->per_bfd->debug_names_table;
+  mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
 
   dw2_expand_symtabs_matching_symbol (map, *lookup_name,
                                      symbol_matcher,
@@ -5868,14 +6019,14 @@ dw2_debug_names_expand_symtabs_matching
     {
       /* The name was matched, now expand corresponding CUs that were
         marked.  */
-      dw2_debug_names_iterator iter (map, kind, namei, dwarf2_per_objfile);
+      dw2_debug_names_iterator iter (map, kind, namei, per_objfile);
 
       struct dwarf2_per_cu_data *per_cu;
       while ((per_cu = iter.next ()) != NULL)
-       dw2_expand_symtabs_matching_one (per_cu, dwarf2_per_objfile,
-                                        file_matcher, expansion_notify);
+       dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
+                                        expansion_notify);
       return true;
-    }, dwarf2_per_objfile);
+    }, per_objfile);
 }
 
 const struct quick_symbol_functions dwarf2_debug_names_functions =
@@ -5957,9 +6108,8 @@ get_gdb_index_contents_from_cache_dwz (objfile *obj, dwz_file *dwz)
 bool
 dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
-  dwarf2_per_bfd *per_bfd = dwarf2_per_objfile->per_bfd;
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
 
   /* If we're about to read full symbols, don't bother with the
      indices.  In this case we also don't care if some other debug
@@ -5972,16 +6122,16 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
       if (per_bfd->using_index)
        {
          *index_kind = dw_index_kind::GDB_INDEX;
-         dwarf2_per_objfile->resize_symtabs ();
+         per_objfile->resize_symtabs ();
          return true;
        }
 
       per_bfd->using_index = 1;
-      create_all_comp_units (dwarf2_per_objfile);
-      create_all_type_units (dwarf2_per_objfile);
+      create_all_comp_units (per_objfile);
+      create_all_type_units (per_objfile);
       per_bfd->quick_file_names_table
        = create_quick_file_names_table (per_bfd->all_comp_units.size ());
-      dwarf2_per_objfile->resize_symtabs ();
+      per_objfile->resize_symtabs ();
 
       for (int i = 0; i < (per_bfd->all_comp_units.size ()
                           + per_bfd->all_type_units.size ()); ++i)
@@ -6004,7 +6154,8 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
   if (per_bfd->debug_names_table != nullptr)
     {
       *index_kind = dw_index_kind::DEBUG_NAMES;
-      dwarf2_per_objfile->resize_symtabs ();
+      per_objfile->objfile->partial_symtabs = per_bfd->partial_symtabs;
+      per_objfile->resize_symtabs ();
       return true;
     }
 
@@ -6013,34 +6164,43 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
   if (per_bfd->index_table != nullptr)
     {
       *index_kind = dw_index_kind::GDB_INDEX;
-      dwarf2_per_objfile->resize_symtabs ();
+      per_objfile->objfile->partial_symtabs = per_bfd->partial_symtabs;
+      per_objfile->resize_symtabs ();
       return true;
     }
 
-  if (dwarf2_read_debug_names (dwarf2_per_objfile))
+  /* There might already be partial symtabs built for this BFD.  This happens
+     when loading the same binary twice with the index-cache enabled.  If so,
+     don't try to read an index.  The objfile / per_objfile initialization will
+     be completed in dwarf2_build_psymtabs, in the standard partial symtabs
+     code path.  */
+  if (per_bfd->partial_symtabs != nullptr)
+    return false;
+
+  if (dwarf2_read_debug_names (per_objfile))
     {
       *index_kind = dw_index_kind::DEBUG_NAMES;
-      dwarf2_per_objfile->resize_symtabs ();
+      per_objfile->resize_symtabs ();
       return true;
     }
 
-  if (dwarf2_read_gdb_index (dwarf2_per_objfile,
+  if (dwarf2_read_gdb_index (per_objfile,
                             get_gdb_index_contents_from_section<struct dwarf2_per_bfd>,
                             get_gdb_index_contents_from_section<dwz_file>))
     {
       *index_kind = dw_index_kind::GDB_INDEX;
-      dwarf2_per_objfile->resize_symtabs ();
+      per_objfile->resize_symtabs ();
       return true;
     }
 
   /* ... otherwise, try to find the index in the index cache.  */
-  if (dwarf2_read_gdb_index (dwarf2_per_objfile,
+  if (dwarf2_read_gdb_index (per_objfile,
                             get_gdb_index_contents_from_cache,
                             get_gdb_index_contents_from_cache_dwz))
     {
       global_index_cache.hit ();
       *index_kind = dw_index_kind::GDB_INDEX;
-      dwarf2_per_objfile->resize_symtabs ();
+      per_objfile->resize_symtabs ();
       return true;
     }
 
@@ -6055,34 +6215,31 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
 void
 dwarf2_build_psymtabs (struct objfile *objfile)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
-  dwarf2_per_bfd *per_bfd = dwarf2_per_objfile->per_bfd;
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
 
   if (per_bfd->partial_symtabs != nullptr)
     {
       /* Partial symbols were already read, so now we can simply
         attach them.  */
       objfile->partial_symtabs = per_bfd->partial_symtabs;
-      dwarf2_per_objfile->resize_symtabs ();
+      per_objfile->resize_symtabs ();
       return;
     }
 
-  init_psymbol_list (objfile, 1024);
-
   try
     {
       /* This isn't really ideal: all the data we allocate on the
         objfile's obstack is still uselessly kept around.  However,
         freeing it seems unsafe.  */
       psymtab_discarder psymtabs (objfile);
-      dwarf2_build_psymtabs_hard (dwarf2_per_objfile);
+      dwarf2_build_psymtabs_hard (per_objfile);
       psymtabs.keep ();
 
-      dwarf2_per_objfile->resize_symtabs ();
+      per_objfile->resize_symtabs ();
 
       /* (maybe) store an index in the cache.  */
-      global_index_cache.store (dwarf2_per_objfile);
+      global_index_cache.store (per_objfile);
     }
   catch (const gdb_exception_error &except)
     {
@@ -6111,12 +6268,12 @@ dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
 
   attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
   if (attr != nullptr)
-    cu->base_address = attr->value_as_address ();
+    cu->base_address = attr->as_address ();
   else
     {
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
       if (attr != nullptr)
-       cu->base_address = attr->value_as_address ();
+       cu->base_address = attr->as_address ();
     }
 }
 
@@ -6140,7 +6297,7 @@ get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu)
 /* Fetch the abbreviation table offset from a comp or type unit header.  */
 
 static sect_offset
-read_abbrev_offset (struct dwarf2_per_objfile *dwarf2_per_objfile,
+read_abbrev_offset (dwarf2_per_objfile *per_objfile,
                    struct dwarf2_section_info *section,
                    sect_offset sect_off)
 {
@@ -6149,7 +6306,7 @@ read_abbrev_offset (struct dwarf2_per_objfile *dwarf2_per_objfile,
   unsigned int initial_length_size, offset_size;
   uint16_t version;
 
-  section->read (dwarf2_per_objfile->objfile);
+  section->read (per_objfile->objfile);
   info_ptr = section->buffer + to_underlying (sect_off);
   read_initial_length (abfd, info_ptr, &initial_length_size);
   offset_size = initial_length_size == 4 ? 4 : 8;
@@ -6223,7 +6380,7 @@ private:
 
 static void
 dwarf2_create_include_psymtab (const char *name, dwarf2_psymtab *pst,
-                               struct objfile *objfile)
+                              struct objfile *objfile)
 {
   dwarf2_include_psymtab *subpst = new dwarf2_include_psymtab (name, objfile);
 
@@ -6248,8 +6405,8 @@ dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
   struct attribute *attr;
 
   attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
-  if (attr != nullptr)
-    lh = dwarf_decode_line_header ((sect_offset) DW_UNSND (attr), cu);
+  if (attr != nullptr && attr->form_is_unsigned ())
+    lh = dwarf_decode_line_header ((sect_offset) attr->as_unsigned (), cu);
   if (lh == NULL)
     return;  /* No linetable, so no includes.  */
 
@@ -6310,24 +6467,23 @@ add_signatured_type_cu_to_table (void **slot, void *datum)
    therefore DW_UT_type.  */
 
 static void
-create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
+create_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
                              struct dwo_file *dwo_file,
                              dwarf2_section_info *section, htab_up &types_htab,
                              rcuh_kind section_kind)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct dwarf2_section_info *abbrev_section;
   bfd *abfd;
   const gdb_byte *info_ptr, *end_ptr;
 
   abbrev_section = (dwo_file != NULL
                    ? &dwo_file->sections.abbrev
-                   : &dwarf2_per_objfile->per_bfd->abbrev);
+                   : &per_objfile->per_bfd->abbrev);
 
-  if (dwarf_read_debug)
-    fprintf_unfiltered (gdb_stdlog, "Reading %s for %s:\n",
-                       section->get_name (),
-                       abbrev_section->get_file_name ());
+  dwarf_read_debug_printf ("Reading %s for %s:",
+                          section->get_name (),
+                          abbrev_section->get_file_name ());
 
   section->read (objfile);
   info_ptr = section->buffer;
@@ -6361,7 +6517,7 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
       /* We need to read the type's signature in order to build the hash
         table, but we don't need anything else just yet.  */
 
-      ptr = read_and_check_comp_unit_head (dwarf2_per_objfile, &header, section,
+      ptr = read_and_check_comp_unit_head (per_objfile, &header, section,
                                           abbrev_section, ptr, section_kind);
 
       length = header.get_length ();
@@ -6369,7 +6525,8 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
       /* Skip dummy type units.  */
       if (ptr >= info_ptr + length
          || peek_abbrev_code (abfd, ptr) == 0
-         || header.unit_type != DW_UT_type)
+         || (header.unit_type != DW_UT_type
+             && header.unit_type != DW_UT_split_type))
        {
          info_ptr += length;
          continue;
@@ -6386,8 +6543,7 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
       if (dwo_file)
        {
          sig_type = NULL;
-         dwo_tu = OBSTACK_ZALLOC (&dwarf2_per_objfile->per_bfd->obstack,
-                                  struct dwo_unit);
+         dwo_tu = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, dwo_unit);
          dwo_tu->dwo_file = dwo_file;
          dwo_tu->signature = header.signature;
          dwo_tu->type_offset_in_tu = header.type_cu_offset_in_tu;
@@ -6400,7 +6556,7 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
          /* N.B.: type_offset is not usable if this type uses a DWO file.
             The real type_offset is in the DWO file.  */
          dwo_tu = NULL;
-         sig_type = dwarf2_per_objfile->per_bfd->allocate_signatured_type ();
+         sig_type = per_objfile->per_bfd->allocate_signatured_type ();
          sig_type->signature = header.signature;
          sig_type->type_offset_in_tu = header.type_cu_offset_in_tu;
          sig_type->per_cu.is_debug_types = 1;
@@ -6439,10 +6595,9 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
        }
       *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type;
 
-      if (dwarf_read_debug > 1)
-       fprintf_unfiltered (gdb_stdlog, "  offset %s, signature %s\n",
-                           sect_offset_str (sect_off),
-                           hex_string (header.signature));
+      dwarf_read_debug_printf_v ("  offset %s, signature %s",
+                                sect_offset_str (sect_off),
+                                hex_string (header.signature));
 
       info_ptr += length;
     }
@@ -6458,14 +6613,14 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
    Note: This function processes DWO files only, not DWP files.  */
 
 static void
-create_debug_types_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
+create_debug_types_hash_table (dwarf2_per_objfile *per_objfile,
                               struct dwo_file *dwo_file,
                               gdb::array_view<dwarf2_section_info> type_sections,
                               htab_up &types_htab)
 {
   for (dwarf2_section_info &section : type_sections)
-    create_debug_type_hash_table (dwarf2_per_objfile, dwo_file, &section,
-                                 types_htab, rcuh_kind::TYPE);
+    create_debug_type_hash_table (per_objfile, dwo_file, &section, types_htab,
+                                 rcuh_kind::TYPE);
 }
 
 /* Create the hash table of all entries in the .debug_types section,
@@ -6474,30 +6629,29 @@ create_debug_types_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
    otherwise non-zero. */
 
 static int
-create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
+create_all_type_units (dwarf2_per_objfile *per_objfile)
 {
   htab_up types_htab;
 
-  create_debug_type_hash_table (dwarf2_per_objfile, NULL,
-                               &dwarf2_per_objfile->per_bfd->info, types_htab,
-                               rcuh_kind::COMPILE);
-  create_debug_types_hash_table (dwarf2_per_objfile, NULL,
-                                dwarf2_per_objfile->per_bfd->types, types_htab);
+  create_debug_type_hash_table (per_objfile, NULL, &per_objfile->per_bfd->info,
+                               types_htab, rcuh_kind::COMPILE);
+  create_debug_types_hash_table (per_objfile, NULL, per_objfile->per_bfd->types,
+                                types_htab);
   if (types_htab == NULL)
     {
-      dwarf2_per_objfile->per_bfd->signatured_types = NULL;
+      per_objfile->per_bfd->signatured_types = NULL;
       return 0;
     }
 
-  dwarf2_per_objfile->per_bfd->signatured_types = std::move (types_htab);
+  per_objfile->per_bfd->signatured_types = std::move (types_htab);
 
-  gdb_assert (dwarf2_per_objfile->per_bfd->all_type_units.empty ());
-  dwarf2_per_objfile->per_bfd->all_type_units.reserve
-    (htab_elements (dwarf2_per_objfile->per_bfd->signatured_types.get ()));
+  gdb_assert (per_objfile->per_bfd->all_type_units.empty ());
+  per_objfile->per_bfd->all_type_units.reserve
+    (htab_elements (per_objfile->per_bfd->signatured_types.get ()));
 
-  htab_traverse_noresize (dwarf2_per_objfile->per_bfd->signatured_types.get (),
+  htab_traverse_noresize (per_objfile->per_bfd->signatured_types.get (),
                          add_signatured_type_cu_to_table,
-                         &dwarf2_per_objfile->per_bfd->all_type_units);
+                         &per_objfile->per_bfd->all_type_units);
 
   return 1;
 }
@@ -6507,30 +6661,29 @@ create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
    Otherwise we find one.  */
 
 static struct signatured_type *
-add_type_unit (struct dwarf2_per_objfile *dwarf2_per_objfile, ULONGEST sig,
-              void **slot)
+add_type_unit (dwarf2_per_objfile *per_objfile, ULONGEST sig, void **slot)
 {
-  if (dwarf2_per_objfile->per_bfd->all_type_units.size ()
-      == dwarf2_per_objfile->per_bfd->all_type_units.capacity ())
-    ++dwarf2_per_objfile->per_bfd->tu_stats.nr_all_type_units_reallocs;
+  if (per_objfile->per_bfd->all_type_units.size ()
+      == per_objfile->per_bfd->all_type_units.capacity ())
+    ++per_objfile->per_bfd->tu_stats.nr_all_type_units_reallocs;
 
-  signatured_type *sig_type = dwarf2_per_objfile->per_bfd->allocate_signatured_type ();
+  signatured_type *sig_type = per_objfile->per_bfd->allocate_signatured_type ();
 
-  dwarf2_per_objfile->resize_symtabs ();
+  per_objfile->resize_symtabs ();
 
-  dwarf2_per_objfile->per_bfd->all_type_units.push_back (sig_type);
+  per_objfile->per_bfd->all_type_units.push_back (sig_type);
   sig_type->signature = sig;
   sig_type->per_cu.is_debug_types = 1;
-  if (dwarf2_per_objfile->per_bfd->using_index)
+  if (per_objfile->per_bfd->using_index)
     {
       sig_type->per_cu.v.quick =
-       OBSTACK_ZALLOC (&dwarf2_per_objfile->per_bfd->obstack,
+       OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack,
                        struct dwarf2_per_cu_quick_data);
     }
 
   if (slot == NULL)
     {
-      slot = htab_find_slot (dwarf2_per_objfile->per_bfd->signatured_types.get (),
+      slot = htab_find_slot (per_objfile->per_bfd->signatured_types.get (),
                             sig_type, INSERT);
     }
   gdb_assert (*slot == NULL);
@@ -6543,19 +6696,19 @@ add_type_unit (struct dwarf2_per_objfile *dwarf2_per_objfile, ULONGEST sig,
    Fill in SIG_ENTRY with DWO_ENTRY.  */
 
 static void
-fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile *dwarf2_per_objfile,
+fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile *per_objfile,
                                  struct signatured_type *sig_entry,
                                  struct dwo_unit *dwo_entry)
 {
-  dwarf2_per_bfd *per_bfd = dwarf2_per_objfile->per_bfd;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
 
   /* Make sure we're not clobbering something we don't expect to.  */
   gdb_assert (! sig_entry->per_cu.queued);
-  gdb_assert (dwarf2_per_objfile->get_cu (&sig_entry->per_cu) == NULL);
+  gdb_assert (per_objfile->get_cu (&sig_entry->per_cu) == NULL);
   if (per_bfd->using_index)
     {
       gdb_assert (sig_entry->per_cu.v.quick != NULL);
-      gdb_assert (!dwarf2_per_objfile->symtab_set_p (&sig_entry->per_cu));
+      gdb_assert (!per_objfile->symtab_set_p (&sig_entry->per_cu));
     }
   else
       gdb_assert (sig_entry->per_cu.v.psymtab == NULL);
@@ -6588,18 +6741,18 @@ fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile *dwarf2_per_objfile,
 static struct signatured_type *
 lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct dwo_file *dwo_file;
   struct dwo_unit find_dwo_entry, *dwo_entry;
   struct signatured_type find_sig_entry, *sig_entry;
   void **slot;
 
-  gdb_assert (cu->dwo_unit && dwarf2_per_objfile->per_bfd->using_index);
+  gdb_assert (cu->dwo_unit && per_objfile->per_bfd->using_index);
 
   /* If TU skeletons have been removed then we may not have read in any
      TUs yet.  */
-  if (dwarf2_per_objfile->per_bfd->signatured_types == NULL)
-    dwarf2_per_objfile->per_bfd->signatured_types = allocate_signatured_type_table ();
+  if (per_objfile->per_bfd->signatured_types == NULL)
+    per_objfile->per_bfd->signatured_types = allocate_signatured_type_table ();
 
   /* We only ever need to read in one copy of a signatured type.
      Use the global signatured_types array to do our own comdat-folding
@@ -6608,7 +6761,7 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
      .gdb_index with this TU.  */
 
   find_sig_entry.signature = sig;
-  slot = htab_find_slot (dwarf2_per_objfile->per_bfd->signatured_types.get (),
+  slot = htab_find_slot (per_objfile->per_bfd->signatured_types.get (),
                         &find_sig_entry, INSERT);
   sig_entry = (struct signatured_type *) *slot;
 
@@ -6639,9 +6792,9 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
 
   /* If the global table doesn't have an entry for this TU, add one.  */
   if (sig_entry == NULL)
-    sig_entry = add_type_unit (dwarf2_per_objfile, sig, slot);
+    sig_entry = add_type_unit (per_objfile, sig, slot);
 
-  fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile, sig_entry, dwo_entry);
+  fill_in_sig_entry_from_dwo_entry (per_objfile, sig_entry, dwo_entry);
   sig_entry->per_cu.tu_read = 1;
   return sig_entry;
 }
@@ -6654,22 +6807,22 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
 static struct signatured_type *
 lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct dwp_file *dwp_file = get_dwp_file (dwarf2_per_objfile);
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct dwp_file *dwp_file = get_dwp_file (per_objfile);
   struct dwo_unit *dwo_entry;
   struct signatured_type find_sig_entry, *sig_entry;
   void **slot;
 
-  gdb_assert (cu->dwo_unit && dwarf2_per_objfile->per_bfd->using_index);
+  gdb_assert (cu->dwo_unit && per_objfile->per_bfd->using_index);
   gdb_assert (dwp_file != NULL);
 
   /* If TU skeletons have been removed then we may not have read in any
      TUs yet.  */
-  if (dwarf2_per_objfile->per_bfd->signatured_types == NULL)
-    dwarf2_per_objfile->per_bfd->signatured_types = allocate_signatured_type_table ();
+  if (per_objfile->per_bfd->signatured_types == NULL)
+    per_objfile->per_bfd->signatured_types = allocate_signatured_type_table ();
 
   find_sig_entry.signature = sig;
-  slot = htab_find_slot (dwarf2_per_objfile->per_bfd->signatured_types.get (),
+  slot = htab_find_slot (per_objfile->per_bfd->signatured_types.get (),
                         &find_sig_entry, INSERT);
   sig_entry = (struct signatured_type *) *slot;
 
@@ -6681,13 +6834,13 @@ lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
 
   if (dwp_file->tus == NULL)
     return NULL;
-  dwo_entry = lookup_dwo_unit_in_dwp (dwarf2_per_objfile, dwp_file, NULL,
-                                     sig, 1 /* is_debug_types */);
+  dwo_entry = lookup_dwo_unit_in_dwp (per_objfile, dwp_file, NULL, sig,
+                                     1 /* is_debug_types */);
   if (dwo_entry == NULL)
     return NULL;
 
-  sig_entry = add_type_unit (dwarf2_per_objfile, sig, slot);
-  fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile, sig_entry, dwo_entry);
+  sig_entry = add_type_unit (per_objfile, sig, slot);
+  fill_in_sig_entry_from_dwo_entry (per_objfile, sig_entry, dwo_entry);
 
   return sig_entry;
 }
@@ -6699,14 +6852,13 @@ lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
 static struct signatured_type *
 lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
 
-  if (cu->dwo_unit
-      && dwarf2_per_objfile->per_bfd->using_index)
+  if (cu->dwo_unit && per_objfile->per_bfd->using_index)
     {
       /* We're in a DWO/DWP file, and we're using .gdb_index.
         These cases require special processing.  */
-      if (get_dwp_file (dwarf2_per_objfile) == NULL)
+      if (get_dwp_file (per_objfile) == NULL)
        return lookup_dwo_signatured_type (cu, sig);
       else
        return lookup_dwp_signatured_type (cu, sig);
@@ -6715,11 +6867,11 @@ lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
     {
       struct signatured_type find_entry, *entry;
 
-      if (dwarf2_per_objfile->per_bfd->signatured_types == NULL)
+      if (per_objfile->per_bfd->signatured_types == NULL)
        return NULL;
       find_entry.signature = sig;
       entry = ((struct signatured_type *)
-              htab_find (dwarf2_per_objfile->per_bfd->signatured_types.get (),
+              htab_find (per_objfile->per_bfd->signatured_types.get (),
                          &find_entry));
       return entry;
     }
@@ -6775,9 +6927,9 @@ read_cutu_die_from_dwo (dwarf2_cu *cu,
                        struct die_info **result_comp_unit_die,
                        abbrev_table_up *result_dwo_abbrev_table)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
   dwarf2_per_cu_data *per_cu = cu->per_cu;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
   bfd *abfd;
   const gdb_byte *begin_info_ptr, *info_ptr;
   struct attribute *comp_dir, *stmt_list, *low_pc, *high_pc, *ranges;
@@ -6823,11 +6975,10 @@ read_cutu_die_from_dwo (dwarf2_cu *cu,
   else if (stub_comp_dir != NULL)
     {
       /* Reconstruct the comp_dir attribute to simplify the code below.  */
-      comp_dir = XOBNEW (&cu->comp_unit_obstack, struct attribute);
+      comp_dir = OBSTACK_ZALLOC (&cu->comp_unit_obstack, struct attribute);
       comp_dir->name = DW_AT_comp_dir;
       comp_dir->form = DW_FORM_string;
-      DW_STRING_IS_CANONICAL (comp_dir) = 0;
-      DW_STRING (comp_dir) = stub_comp_dir;
+      comp_dir->set_string_noncanonical (stub_comp_dir);
     }
 
   /* Set up for reading the DWO CU/TU.  */
@@ -6843,9 +6994,8 @@ read_cutu_die_from_dwo (dwarf2_cu *cu,
     {
       signatured_type *sig_type = (struct signatured_type *) per_cu;
 
-      info_ptr = read_and_check_comp_unit_head (dwarf2_per_objfile,
-                                               &cu->header, section,
-                                               dwo_abbrev_section,
+      info_ptr = read_and_check_comp_unit_head (per_objfile, &cu->header,
+                                               section, dwo_abbrev_section,
                                                info_ptr, rcuh_kind::TYPE);
       /* This is not an assert because it can be caused by bad debug info.  */
       if (sig_type->signature != cu->header.signature)
@@ -6870,9 +7020,8 @@ read_cutu_die_from_dwo (dwarf2_cu *cu,
     }
   else
     {
-      info_ptr = read_and_check_comp_unit_head (dwarf2_per_objfile,
-                                               &cu->header, section,
-                                               dwo_abbrev_section,
+      info_ptr = read_and_check_comp_unit_head (per_objfile, &cu->header,
+                                               section, dwo_abbrev_section,
                                                info_ptr, rcuh_kind::COMPILE);
       gdb_assert (dwo_unit->sect_off == cu->header.sect_off);
       /* For DWOs coming from DWP files, we don't know the CU length
@@ -6880,9 +7029,9 @@ read_cutu_die_from_dwo (dwarf2_cu *cu,
       dwo_unit->length = cu->header.get_length ();
     }
 
+  dwo_abbrev_section->read (objfile);
   *result_dwo_abbrev_table
-    = abbrev_table::read (objfile, dwo_abbrev_section,
-                         cu->header.abbrev_sect_off);
+    = abbrev_table::read (dwo_abbrev_section, cu->header.abbrev_sect_off);
   init_cu_die_reader (result_reader, cu, section, dwo_unit->dwo_file,
                      result_dwo_abbrev_table->get ());
 
@@ -6942,9 +7091,9 @@ lookup_dwo_id (struct dwarf2_cu *cu, struct die_info* comp_unit_die)
     return cu->header.signature;
   struct attribute *attr;
   attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
-  if (attr == nullptr)
+  if (attr == nullptr || !attr->form_is_unsigned ())
     return gdb::optional<ULONGEST> ();
-  return DW_UNSND (attr);
+  return attr->as_unsigned ();
 }
 
 /* Subroutine of cutu_reader to simplify it.
@@ -7010,7 +7159,7 @@ cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu,
   else
     {
       /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
-         in per_objfile yet.  */
+        in per_objfile yet.  */
       gdb_assert (per_objfile->get_cu (this_cu) == nullptr);
       m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile));
       cu = m_new_cu.get ();
@@ -7043,14 +7192,14 @@ cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu,
    allocated.  */
 
 cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
-                         dwarf2_per_objfile *dwarf2_per_objfile,
+                         dwarf2_per_objfile *per_objfile,
                          struct abbrev_table *abbrev_table,
                          dwarf2_cu *existing_cu,
                          bool skip_partial)
   : die_reader_specs {},
     m_this_cu (this_cu)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct dwarf2_section_info *section = this_cu->section;
   bfd *abfd = section->get_bfd_owner ();
   const gdb_byte *begin_info_ptr;
@@ -7073,7 +7222,7 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
       /* Narrow down the scope of possibilities to have to understand.  */
       gdb_assert (this_cu->is_debug_types);
       gdb_assert (abbrev_table == NULL);
-      init_tu_and_read_dwo_dies (this_cu, dwarf2_per_objfile, existing_cu);
+      init_tu_and_read_dwo_dies (this_cu, per_objfile, existing_cu);
       return;
     }
 
@@ -7101,9 +7250,9 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
   else
     {
       /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
-         in per_objfile yet.  */
-      gdb_assert (dwarf2_per_objfile->get_cu (this_cu) == nullptr);
-      m_new_cu.reset (new dwarf2_cu (this_cu, dwarf2_per_objfile));
+        in per_objfile yet.  */
+      gdb_assert (per_objfile->get_cu (this_cu) == nullptr);
+      m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile));
       cu = m_new_cu.get ();
     }
 
@@ -7117,10 +7266,9 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
     {
       if (this_cu->is_debug_types)
        {
-         info_ptr = read_and_check_comp_unit_head (dwarf2_per_objfile,
-                                                   &cu->header, section,
-                                                   abbrev_section, info_ptr,
-                                                   rcuh_kind::TYPE);
+         info_ptr = read_and_check_comp_unit_head (per_objfile, &cu->header,
+                                                   section, abbrev_section,
+                                                   info_ptr, rcuh_kind::TYPE);
 
          /* Since per_cu is the first member of struct signatured_type,
             we can go from a pointer to one to a pointer to the other.  */
@@ -7142,9 +7290,8 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
        }
       else
        {
-         info_ptr = read_and_check_comp_unit_head (dwarf2_per_objfile,
-                                                   &cu->header, section,
-                                                   abbrev_section,
+         info_ptr = read_and_check_comp_unit_head (per_objfile, &cu->header,
+                                                   section, abbrev_section,
                                                    info_ptr,
                                                    rcuh_kind::COMPILE);
 
@@ -7172,9 +7319,9 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
     gdb_assert (cu->header.abbrev_sect_off == abbrev_table->sect_off);
   else
     {
+      abbrev_section->read (objfile);
       m_abbrev_table_holder
-       = abbrev_table::read (objfile, abbrev_section,
-                             cu->header.abbrev_sect_off);
+       = abbrev_table::read (abbrev_section, cu->header.abbrev_sect_off);
       abbrev_table = m_abbrev_table_holder.get ();
     }
 
@@ -7243,7 +7390,7 @@ cutu_reader::keep ()
   if (m_new_cu != NULL)
     {
       /* Save this dwarf2_cu in the per_objfile.  The per_objfile owns it
-         now.  */
+        now.  */
       dwarf2_per_objfile *per_objfile = m_new_cu->per_objfile;
       per_objfile->set_cu (m_this_cu, m_new_cu.release ());
     }
@@ -7266,13 +7413,13 @@ cutu_reader::keep ()
    str_offsets_base and addr_base from the parent.  */
 
 cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
-                         dwarf2_per_objfile *dwarf2_per_objfile,
+                         dwarf2_per_objfile *per_objfile,
                          struct dwarf2_cu *parent_cu,
                          struct dwo_file *dwo_file)
   : die_reader_specs {},
     m_this_cu (this_cu)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct dwarf2_section_info *section = this_cu->section;
   bfd *abfd = section->get_bfd_owner ();
   struct dwarf2_section_info *abbrev_section;
@@ -7283,7 +7430,7 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
                        this_cu->is_debug_types ? "type" : "comp",
                        sect_offset_str (this_cu->sect_off));
 
-  gdb_assert (dwarf2_per_objfile->get_cu (this_cu) == nullptr);
+  gdb_assert (per_objfile->get_cu (this_cu) == nullptr);
 
   abbrev_section = (dwo_file != NULL
                    ? &dwo_file->sections.abbrev
@@ -7292,12 +7439,11 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
   /* This is cheap if the section is already read in.  */
   section->read (objfile);
 
-  m_new_cu.reset (new dwarf2_cu (this_cu, dwarf2_per_objfile));
+  m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile));
 
   begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off);
-  info_ptr = read_and_check_comp_unit_head (dwarf2_per_objfile,
-                                           &m_new_cu->header, section,
-                                           abbrev_section, info_ptr,
+  info_ptr = read_and_check_comp_unit_head (per_objfile, &m_new_cu->header,
+                                           section, abbrev_section, info_ptr,
                                            (this_cu->is_debug_types
                                             ? rcuh_kind::TYPE
                                             : rcuh_kind::COMPILE));
@@ -7317,9 +7463,9 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
       return;
     }
 
+  abbrev_section->read (objfile);
   m_abbrev_table_holder
-    = abbrev_table::read (objfile, abbrev_section,
-                         m_new_cu->header.abbrev_sect_off);
+    = abbrev_table::read (abbrev_section, m_new_cu->header.abbrev_sect_off);
 
   init_cu_die_reader (this, m_new_cu.get (), section, dwo_file,
                      m_abbrev_table_holder.get ());
@@ -7376,13 +7522,12 @@ allocate_type_unit_groups_table ()
 static struct type_unit_group *
 create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  dwarf2_per_bfd *per_bfd = dwarf2_per_objfile->per_bfd;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
   struct dwarf2_per_cu_data *per_cu;
   struct type_unit_group *tu_group;
 
-  tu_group = OBSTACK_ZALLOC (&dwarf2_per_objfile->per_bfd->obstack,
-                            struct type_unit_group);
+  tu_group = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, type_unit_group);
   per_cu = &tu_group->per_cu;
   per_cu->per_bfd = per_bfd;
 
@@ -7404,7 +7549,7 @@ create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
       else
        name = string_printf ("<type_units_at_0x%x>", line_offset);
 
-      pst = create_partial_symtab (per_cu, dwarf2_per_objfile, name.c_str ());
+      pst = create_partial_symtab (per_cu, per_objfile, name.c_str ());
       pst->anonymous = true;
     }
 
@@ -7420,21 +7565,21 @@ create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
 static struct type_unit_group *
 get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct tu_stats *tu_stats = &dwarf2_per_objfile->per_bfd->tu_stats;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct tu_stats *tu_stats = &per_objfile->per_bfd->tu_stats;
   struct type_unit_group *tu_group;
   void **slot;
   unsigned int line_offset;
   struct type_unit_group type_unit_group_for_lookup;
 
-  if (dwarf2_per_objfile->per_bfd->type_unit_groups == NULL)
-    dwarf2_per_objfile->per_bfd->type_unit_groups = allocate_type_unit_groups_table ();
+  if (per_objfile->per_bfd->type_unit_groups == NULL)
+    per_objfile->per_bfd->type_unit_groups = allocate_type_unit_groups_table ();
 
   /* Do we need to create a new group, or can we use an existing one?  */
 
-  if (stmt_list)
+  if (stmt_list != nullptr && stmt_list->form_is_unsigned ())
     {
-      line_offset = DW_UNSND (stmt_list);
+      line_offset = stmt_list->as_unsigned ();
       ++tu_stats->nr_symtab_sharers;
     }
   else
@@ -7452,7 +7597,7 @@ get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list)
 
   type_unit_group_for_lookup.hash.dwo_unit = cu->dwo_unit;
   type_unit_group_for_lookup.hash.line_sect_off = (sect_offset) line_offset;
-  slot = htab_find_slot (dwarf2_per_objfile->per_bfd->type_unit_groups.get (),
+  slot = htab_find_slot (per_objfile->per_bfd->type_unit_groups.get (),
                         &type_unit_group_for_lookup, INSERT);
   if (*slot != NULL)
     {
@@ -7595,7 +7740,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
                                                  best_highpc + baseaddr)
                      - baseaddr);
 
-  end_psymtab_common (objfile, pst);
+  pst->end ();
 
   if (!cu->per_cu->imported_symtabs_empty ())
     {
@@ -7620,15 +7765,14 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
      and build a psymtab for each of them.  */
   dwarf2_build_include_psymtabs (cu, comp_unit_die, pst);
 
-  if (dwarf_read_debug)
-    fprintf_unfiltered (gdb_stdlog,
-                       "Psymtab for %s unit @%s: %s - %s"
-                       ", %d global, %d static syms\n",
-                       per_cu->is_debug_types ? "type" : "comp",
-                       sect_offset_str (per_cu->sect_off),
-                       paddress (gdbarch, pst->text_low (objfile)),
-                       paddress (gdbarch, pst->text_high (objfile)),
-                       pst->n_global_syms, pst->n_static_syms);
+  dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
+                          ", %d global, %d static syms",
+                          per_cu->is_debug_types ? "type" : "comp",
+                          sect_offset_str (per_cu->sect_off),
+                          paddress (gdbarch, pst->text_low (objfile)),
+                          paddress (gdbarch, pst->text_high (objfile)),
+                          (int) pst->global_psymbols.size (),
+                          (int) pst->static_psymbols.size ());
 }
 
 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
@@ -7687,8 +7831,7 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
                            const gdb_byte *info_ptr,
                            struct die_info *type_unit_die)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = reader->cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = reader->cu->per_objfile;
   struct dwarf2_cu *cu = reader->cu;
   struct dwarf2_per_cu_data *per_cu = cu->per_cu;
   struct signatured_type *sig_type;
@@ -7712,7 +7855,7 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
   tu_group->tus->push_back (sig_type);
 
   prepare_one_comp_unit (cu, type_unit_die, language_minimal);
-  pst = create_partial_symtab (per_cu, dwarf2_per_objfile, "");
+  pst = create_partial_symtab (per_cu, per_objfile, "");
   pst->anonymous = true;
 
   first_die = load_partial_dies (reader, info_ptr, 1);
@@ -7721,7 +7864,7 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
   highpc = (CORE_ADDR) 0;
   scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu);
 
-  end_psymtab_common (objfile, pst);
+  pst->end ();
 }
 
 /* Struct used to sort TUs by their abbreviation table offset.  */
@@ -7764,16 +7907,16 @@ sort_tu_by_abbrev_offset (const struct tu_abbrev_offset &a,
    dwarf2_per_objfile->per_bfd->type_unit_groups.  */
 
 static void
-build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
+build_type_psymtabs_1 (dwarf2_per_objfile *per_objfile)
 {
-  struct tu_stats *tu_stats = &dwarf2_per_objfile->per_bfd->tu_stats;
+  struct tu_stats *tu_stats = &per_objfile->per_bfd->tu_stats;
   abbrev_table_up abbrev_table;
   sect_offset abbrev_offset;
 
   /* It's up to the caller to not call us multiple times.  */
-  gdb_assert (dwarf2_per_objfile->per_bfd->type_unit_groups == NULL);
+  gdb_assert (per_objfile->per_bfd->type_unit_groups == NULL);
 
-  if (dwarf2_per_objfile->per_bfd->all_type_units.empty ())
+  if (per_objfile->per_bfd->all_type_units.empty ())
     return;
 
   /* TUs typically share abbrev tables, and there can be way more TUs than
@@ -7795,18 +7938,16 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
          [IWBN if DWO skeletons had DW_AT_stmt_list]
        call FUNC  */
 
-  if (dwarf_read_debug)
-    fprintf_unfiltered (gdb_stdlog, "Building type unit groups ...\n");
+  dwarf_read_debug_printf ("Building type unit groups ...");
 
   /* Sort in a separate table to maintain the order of all_type_units
      for .gdb_index: TU indices directly index all_type_units.  */
   std::vector<tu_abbrev_offset> sorted_by_abbrev;
-  sorted_by_abbrev.reserve (dwarf2_per_objfile->per_bfd->all_type_units.size ());
+  sorted_by_abbrev.reserve (per_objfile->per_bfd->all_type_units.size ());
 
-  for (signatured_type *sig_type : dwarf2_per_objfile->per_bfd->all_type_units)
+  for (signatured_type *sig_type : per_objfile->per_bfd->all_type_units)
     sorted_by_abbrev.emplace_back
-      (sig_type, read_abbrev_offset (dwarf2_per_objfile,
-                                    sig_type->per_cu.section,
+      (sig_type, read_abbrev_offset (per_objfile, sig_type->per_cu.section,
                                     sig_type->per_cu.sect_off));
 
   std::sort (sorted_by_abbrev.begin (), sorted_by_abbrev.end (),
@@ -7821,14 +7962,13 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
          || tu.abbrev_offset != abbrev_offset)
        {
          abbrev_offset = tu.abbrev_offset;
+         per_objfile->per_bfd->abbrev.read (per_objfile->objfile);
          abbrev_table =
-           abbrev_table::read (dwarf2_per_objfile->objfile,
-                               &dwarf2_per_objfile->per_bfd->abbrev,
-                               abbrev_offset);
+           abbrev_table::read (&per_objfile->per_bfd->abbrev, abbrev_offset);
          ++tu_stats->nr_uniq_abbrev_tables;
        }
 
-      cutu_reader reader (&tu.sig_type->per_cu, dwarf2_per_objfile,
+      cutu_reader reader (&tu.sig_type->per_cu, per_objfile,
                          abbrev_table.get (), nullptr, false);
       if (!reader.dummy_p)
        build_type_psymtabs_reader (&reader, reader.info_ptr,
@@ -7839,23 +7979,23 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
 /* Print collected type unit statistics.  */
 
 static void
-print_tu_stats (struct dwarf2_per_objfile *dwarf2_per_objfile)
+print_tu_stats (dwarf2_per_objfile *per_objfile)
 {
-  struct tu_stats *tu_stats = &dwarf2_per_objfile->per_bfd->tu_stats;
+  struct tu_stats *tu_stats = &per_objfile->per_bfd->tu_stats;
 
-  fprintf_unfiltered (gdb_stdlog, "Type unit statistics:\n");
-  fprintf_unfiltered (gdb_stdlog, "  %zu TUs\n",
-                     dwarf2_per_objfile->per_bfd->all_type_units.size ());
-  fprintf_unfiltered (gdb_stdlog, "  %d uniq abbrev tables\n",
-                     tu_stats->nr_uniq_abbrev_tables);
-  fprintf_unfiltered (gdb_stdlog, "  %d symtabs from stmt_list entries\n",
-                     tu_stats->nr_symtabs);
-  fprintf_unfiltered (gdb_stdlog, "  %d symtab sharers\n",
-                     tu_stats->nr_symtab_sharers);
-  fprintf_unfiltered (gdb_stdlog, "  %d type units without a stmt_list\n",
-                     tu_stats->nr_stmt_less_type_units);
-  fprintf_unfiltered (gdb_stdlog, "  %d all_type_units reallocs\n",
-                     tu_stats->nr_all_type_units_reallocs);
+  dwarf_read_debug_printf ("Type unit statistics:");
+  dwarf_read_debug_printf ("  %zu TUs",
+                          per_objfile->per_bfd->all_type_units.size ());
+  dwarf_read_debug_printf ("  %d uniq abbrev tables",
+                          tu_stats->nr_uniq_abbrev_tables);
+  dwarf_read_debug_printf ("  %d symtabs from stmt_list entries",
+                          tu_stats->nr_symtabs);
+  dwarf_read_debug_printf ("  %d symtab sharers",
+                          tu_stats->nr_symtab_sharers);
+  dwarf_read_debug_printf ("  %d type units without a stmt_list",
+                          tu_stats->nr_stmt_less_type_units);
+  dwarf_read_debug_printf ("  %d all_type_units reallocs",
+                          tu_stats->nr_all_type_units_reallocs);
 }
 
 /* Traversal function for build_type_psymtabs.  */
@@ -7863,9 +8003,8 @@ print_tu_stats (struct dwarf2_per_objfile *dwarf2_per_objfile)
 static int
 build_type_psymtab_dependencies (void **slot, void *info)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = (struct dwarf2_per_objfile *) info;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) info;
+  struct objfile *objfile = per_objfile->objfile;
   struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
   struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
   dwarf2_psymtab *pst = per_cu->v.psymtab;
@@ -7895,12 +8034,12 @@ build_type_psymtab_dependencies (void **slot, void *info)
    Build partial symbol tables for the .debug_types comp-units.  */
 
 static void
-build_type_psymtabs (struct dwarf2_per_objfile *dwarf2_per_objfile)
+build_type_psymtabs (dwarf2_per_objfile *per_objfile)
 {
-  if (! create_all_type_units (dwarf2_per_objfile))
+  if (! create_all_type_units (per_objfile))
     return;
 
-  build_type_psymtabs_1 (dwarf2_per_objfile);
+  build_type_psymtabs_1 (per_objfile);
 }
 
 /* Traversal function for process_skeletonless_type_unit.
@@ -7910,17 +8049,16 @@ static int
 process_skeletonless_type_unit (void **slot, void *info)
 {
   struct dwo_unit *dwo_unit = (struct dwo_unit *) *slot;
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = (struct dwarf2_per_objfile *) info;
+  dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) info;
   struct signatured_type find_entry, *entry;
 
   /* If this TU doesn't exist in the global table, add it and read it in.  */
 
-  if (dwarf2_per_objfile->per_bfd->signatured_types == NULL)
-    dwarf2_per_objfile->per_bfd->signatured_types = allocate_signatured_type_table ();
+  if (per_objfile->per_bfd->signatured_types == NULL)
+    per_objfile->per_bfd->signatured_types = allocate_signatured_type_table ();
 
   find_entry.signature = dwo_unit->signature;
-  slot = htab_find_slot (dwarf2_per_objfile->per_bfd->signatured_types.get (),
+  slot = htab_find_slot (per_objfile->per_bfd->signatured_types.get (),
                         &find_entry, INSERT);
   /* If we've already seen this type there's nothing to do.  What's happening
      is we're doing our own version of comdat-folding here.  */
@@ -7929,13 +8067,12 @@ process_skeletonless_type_unit (void **slot, void *info)
 
   /* This does the job that create_all_type_units would have done for
      this TU.  */
-  entry = add_type_unit (dwarf2_per_objfile, dwo_unit->signature, slot);
-  fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile, entry, dwo_unit);
+  entry = add_type_unit (per_objfile, dwo_unit->signature, slot);
+  fill_in_sig_entry_from_dwo_entry (per_objfile, entry, dwo_unit);
   *slot = entry;
 
   /* This does the job that build_type_psymtabs_1 would have done.  */
-  cutu_reader reader (&entry->per_cu, dwarf2_per_objfile, nullptr, nullptr,
-                     false);
+  cutu_reader reader (&entry->per_cu, per_objfile, nullptr, nullptr, false);
   if (!reader.dummy_p)
     build_type_psymtabs_reader (&reader, reader.info_ptr,
                                reader.comp_unit_die);
@@ -7962,24 +8099,24 @@ process_dwo_file_for_skeletonless_type_units (void **slot, void *info)
    Note: This can't be done until we know what all the DWO files are.  */
 
 static void
-process_skeletonless_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
+process_skeletonless_type_units (dwarf2_per_objfile *per_objfile)
 {
   /* Skeletonless TUs in DWP files without .gdb_index is not supported yet.  */
-  if (get_dwp_file (dwarf2_per_objfile) == NULL
-      && dwarf2_per_objfile->per_bfd->dwo_files != NULL)
+  if (get_dwp_file (per_objfile) == NULL
+      && per_objfile->per_bfd->dwo_files != NULL)
     {
-      htab_traverse_noresize (dwarf2_per_objfile->per_bfd->dwo_files.get (),
+      htab_traverse_noresize (per_objfile->per_bfd->dwo_files.get (),
                              process_dwo_file_for_skeletonless_type_units,
-                             dwarf2_per_objfile);
+                             per_objfile);
     }
 }
 
 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE.  */
 
 static void
-set_partial_user (struct dwarf2_per_objfile *dwarf2_per_objfile)
+set_partial_user (dwarf2_per_objfile *per_objfile)
 {
-  for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
     {
       dwarf2_psymtab *pst = per_cu->v.psymtab;
 
@@ -7999,29 +8136,26 @@ set_partial_user (struct dwarf2_per_objfile *dwarf2_per_objfile)
    .debug_info and .debug_abbrev sections.  */
 
 static void
-dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
+dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
 
-  if (dwarf_read_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog, "Building psymtabs of objfile %s ...\n",
-                         objfile_name (objfile));
-    }
+  dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
+                          objfile_name (objfile));
 
   scoped_restore restore_reading_psyms
-    = make_scoped_restore (&dwarf2_per_objfile->per_bfd->reading_partial_symbols,
+    = make_scoped_restore (&per_objfile->per_bfd->reading_partial_symbols,
                           true);
 
-  dwarf2_per_objfile->per_bfd->info.read (objfile);
+  per_objfile->per_bfd->info.read (objfile);
 
   /* Any cached compilation units will be linked by the per-objfile
      read_in_chain.  Make sure to free them when we're done.  */
-  free_cached_comp_units freer (dwarf2_per_objfile);
+  free_cached_comp_units freer (per_objfile);
 
-  build_type_psymtabs (dwarf2_per_objfile);
+  build_type_psymtabs (per_objfile);
 
-  create_all_comp_units (dwarf2_per_objfile);
+  create_all_comp_units (per_objfile);
 
   /* Create a temporary address map on a temporary obstack.  We later
      copy this to the final obstack.  */
@@ -8031,29 +8165,29 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
     = make_scoped_restore (&objfile->partial_symtabs->psymtabs_addrmap,
                           addrmap_create_mutable (&temp_obstack));
 
-  for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
     {
       if (per_cu->v.psymtab != NULL)
        /* In case a forward DW_TAG_imported_unit has read the CU already.  */
        continue;
-      process_psymtab_comp_unit (per_cu, dwarf2_per_objfile, false,
+      process_psymtab_comp_unit (per_cu, per_objfile, false,
                                 language_minimal);
     }
 
   /* This has to wait until we read the CUs, we need the list of DWOs.  */
-  process_skeletonless_type_units (dwarf2_per_objfile);
+  process_skeletonless_type_units (per_objfile);
 
   /* Now that all TUs have been processed we can fill in the dependencies.  */
-  if (dwarf2_per_objfile->per_bfd->type_unit_groups != NULL)
+  if (per_objfile->per_bfd->type_unit_groups != NULL)
     {
-      htab_traverse_noresize (dwarf2_per_objfile->per_bfd->type_unit_groups.get (),
-                             build_type_psymtab_dependencies, dwarf2_per_objfile);
+      htab_traverse_noresize (per_objfile->per_bfd->type_unit_groups.get (),
+                             build_type_psymtab_dependencies, per_objfile);
     }
 
-  if (dwarf_read_debug)
-    print_tu_stats (dwarf2_per_objfile);
+  if (dwarf_read_debug > 0)
+    print_tu_stats (per_objfile);
 
-  set_partial_user (dwarf2_per_objfile);
+  set_partial_user (per_objfile);
 
   objfile->partial_symtabs->psymtabs_addrmap
     = addrmap_create_fixed (objfile->partial_symtabs->psymtabs_addrmap,
@@ -8061,9 +8195,8 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
   /* At this point we want to keep the address map.  */
   save_psymtabs_addrmap.release ();
 
-  if (dwarf_read_debug)
-    fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n",
-                       objfile_name (objfile));
+  dwarf_read_debug_printf ("Done building psymtabs of %s",
+                          objfile_name (objfile));
 }
 
 /* Load the partial DIEs for a secondary CU into memory.
@@ -8092,18 +8225,17 @@ load_partial_comp_unit (dwarf2_per_cu_data *this_cu,
 }
 
 static void
-read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
+read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
                              struct dwarf2_section_info *section,
                              struct dwarf2_section_info *abbrev_section,
                              unsigned int is_dwz)
 {
   const gdb_byte *info_ptr;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
 
-  if (dwarf_read_debug)
-    fprintf_unfiltered (gdb_stdlog, "Reading %s for %s\n",
-                       section->get_name (),
-                       section->get_file_name ());
+  dwarf_read_debug_printf ("Reading %s for %s",
+                          section->get_name (),
+                          section->get_file_name ());
 
   section->read (objfile);
 
@@ -8116,16 +8248,16 @@ read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
       sect_offset sect_off = (sect_offset) (info_ptr - section->buffer);
 
       comp_unit_head cu_header;
-      read_and_check_comp_unit_head (dwarf2_per_objfile, &cu_header, section,
+      read_and_check_comp_unit_head (per_objfile, &cu_header, section,
                                     abbrev_section, info_ptr,
                                     rcuh_kind::COMPILE);
 
       /* Save the compilation unit for later lookup.  */
       if (cu_header.unit_type != DW_UT_type)
-       this_cu = dwarf2_per_objfile->per_bfd->allocate_per_cu ();
+       this_cu = per_objfile->per_bfd->allocate_per_cu ();
       else
        {
-         auto sig_type = dwarf2_per_objfile->per_bfd->allocate_signatured_type ();
+         auto sig_type = per_objfile->per_bfd->allocate_signatured_type ();
          sig_type->signature = cu_header.signature;
          sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu;
          this_cu = &sig_type->per_cu;
@@ -8136,7 +8268,7 @@ read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
       this_cu->is_dwz = is_dwz;
       this_cu->section = section;
 
-      dwarf2_per_objfile->per_bfd->all_comp_units.push_back (this_cu);
+      per_objfile->per_bfd->all_comp_units.push_back (this_cu);
 
       info_ptr = info_ptr + this_cu->length;
     }
@@ -8146,16 +8278,15 @@ read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
    This is only done for -readnow and building partial symtabs.  */
 
 static void
-create_all_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
+create_all_comp_units (dwarf2_per_objfile *per_objfile)
 {
-  gdb_assert (dwarf2_per_objfile->per_bfd->all_comp_units.empty ());
-  read_comp_units_from_section (dwarf2_per_objfile, &dwarf2_per_objfile->per_bfd->info,
-                               &dwarf2_per_objfile->per_bfd->abbrev, 0);
+  gdb_assert (per_objfile->per_bfd->all_comp_units.empty ());
+  read_comp_units_from_section (per_objfile, &per_objfile->per_bfd->info,
+                               &per_objfile->per_bfd->abbrev, 0);
 
-  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
+  dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
   if (dwz != NULL)
-    read_comp_units_from_section (dwarf2_per_objfile, &dwz->info, &dwz->abbrev,
-                                 1);
+    read_comp_units_from_section (per_objfile, &dwz->info, &dwz->abbrev, 1);
 }
 
 /* Process all loaded DIEs for compilation unit CU, starting at
@@ -8195,6 +8326,9 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
            case DW_TAG_subprogram:
            case DW_TAG_inlined_subroutine:
              add_partial_subprogram (pdi, lowpc, highpc, set_addrmap, cu);
+             if (cu->language == language_cplus)
+               scan_partial_symbols (pdi->die_child, lowpc, highpc,
+                                     set_addrmap, cu);
              break;
            case DW_TAG_constant:
            case DW_TAG_variable:
@@ -8223,9 +8357,9 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
                add_partial_enumeration (pdi, cu);
              break;
            case DW_TAG_base_type:
-            case DW_TAG_subrange_type:
+           case DW_TAG_subrange_type:
              /* File scope base type definitions are added to the partial
-                symbol table.  */
+                symbol table.  */
              add_partial_symbol (pdi, cu);
              break;
            case DW_TAG_namespace:
@@ -8420,8 +8554,8 @@ partial_die_full_name (struct partial_die_info *pdi,
 static void
 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR addr = 0;
   const char *actual_name = NULL;
@@ -8458,10 +8592,10 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
              && 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.  */
+         /* 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.  */
          where = psymbol_placement::GLOBAL;
        }
       else
@@ -8488,7 +8622,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 
       if (pdi->d.locdesc
          && addr == 0
-         && !dwarf2_per_objfile->per_bfd->has_section_at_zero)
+         && !per_objfile->per_bfd->has_section_at_zero)
        {
          /* A global or static variable may also have been stripped
             out by the linker if unused, in which case its address
@@ -8536,6 +8670,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          where = psymbol_placement::STATIC;
        }
       break;
+    case DW_TAG_array_type:
     case DW_TAG_typedef:
     case DW_TAG_base_type:
     case DW_TAG_subrange_type:
@@ -8551,8 +8686,8 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
       break;
     case DW_TAG_module:
       /* With Fortran 77 there might be a "BLOCK DATA" module
-         available without any name.  If so, we skip the module as it
-         doesn't bring any value.  */
+        available without any name.  If so, we skip the module as it
+        doesn't bring any value.  */
       if (actual_name != nullptr)
        {
          psymbol.domain = MODULE_DOMAIN;
@@ -8566,10 +8701,10 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     case DW_TAG_union_type:
     case DW_TAG_enumeration_type:
       /* Skip external references.  The DWARF standard says in the section
-         about "Structure, Union, and Class Type Entries": "An incomplete
-         structure, union or class type is represented by a structure,
-         union or class entry that does not have a byte size attribute
-         and that has a DW_AT_declaration attribute."  */
+        about "Structure, Union, and Class Type Entries": "An incomplete
+        structure, union or class type is represented by a structure,
+        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)
        return;
 
@@ -8604,7 +8739,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
                                            &objfile->objfile_obstack);
          psymbol.ginfo.set_linkage_name (pdi->linkage_name);
        }
-      add_psymbol_to_list (psymbol, *where, objfile);
+      cu->per_cu->v.psymtab->add_psymbol (psymbol, *where, objfile);
     }
 }
 
@@ -8663,11 +8798,11 @@ add_partial_subprogram (struct partial_die_info *pdi,
   if (pdi->tag == DW_TAG_subprogram || pdi->tag == DW_TAG_inlined_subroutine)
     {
       if (pdi->has_pc_info)
-        {
-          if (pdi->lowpc < *lowpc)
-            *lowpc = pdi->lowpc;
-          if (pdi->highpc > *highpc)
-            *highpc = pdi->highpc;
+       {
+         if (pdi->lowpc < *lowpc)
+           *lowpc = pdi->lowpc;
+         if (pdi->highpc > *highpc)
+           *highpc = pdi->highpc;
          if (set_addrmap)
            {
              struct objfile *objfile = cu->per_objfile->objfile;
@@ -8689,17 +8824,17 @@ add_partial_subprogram (struct partial_die_info *pdi,
                                 this_lowpc, this_highpc - 1,
                                 cu->per_cu->v.psymtab);
            }
-        }
+       }
 
       if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined))
        {
-          if (!pdi->is_declaration)
+         if (!pdi->is_declaration)
            /* Ignore subprogram DIEs that do not have a name, they are
               illegal.  Do not emit a complaint at this point, we will
               do so when we convert this psymtab into a symtab.  */
            if (pdi->name (cu))
              add_partial_symbol (pdi, cu);
-        }
+       }
     }
 
   if (! pdi->has_children)
@@ -8825,9 +8960,7 @@ skip_one_die (const struct die_reader_specs *reader, const gdb_byte *info_ptr,
       /* The only abbrev we care about is DW_AT_sibling.  */
       if (abbrev->attrs[i].name == DW_AT_sibling)
        {
-         bool ignored;
-         read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr,
-                         &ignored);
+         read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
          if (attr.form == DW_FORM_ref_addr)
            complaint (_("ignoring absolute DW_AT_sibling"));
          else
@@ -8977,10 +9110,9 @@ locate_pdi_sibling (const struct die_reader_specs *reader,
 void
 dwarf2_psymtab::read_symtab (struct objfile *objfile)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  gdb_assert (!dwarf2_per_objfile->symtab_set_p (per_cu_data));
+  gdb_assert (!per_objfile->symtab_set_p (per_cu_data));
 
   /* If this psymtab is constructed from a debug-only objfile, the
      has_section_at_zero flag will not necessarily be correct.  We
@@ -8988,16 +9120,16 @@ dwarf2_psymtab::read_symtab (struct objfile *objfile)
      associated with the (presumably stripped) associated objfile.  */
   if (objfile->separate_debug_objfile_backlink)
     {
-      struct dwarf2_per_objfile *dpo_backlink
+      dwarf2_per_objfile *per_objfile_backlink
        = get_dwarf2_per_objfile (objfile->separate_debug_objfile_backlink);
 
-      dwarf2_per_objfile->per_bfd->has_section_at_zero
-       = dpo_backlink->per_bfd->has_section_at_zero;
+      per_objfile->per_bfd->has_section_at_zero
+       = per_objfile_backlink->per_bfd->has_section_at_zero;
     }
 
   expand_psymtab (objfile);
 
-  process_cu_includes (dwarf2_per_objfile);
+  process_cu_includes (per_objfile);
 }
 \f
 /* Reading in full CUs.  */
@@ -9067,25 +9199,21 @@ maybe_queue_comp_unit (struct dwarf2_cu *dependent_cu,
 /* Process the queue.  */
 
 static void
-process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
+process_queue (dwarf2_per_objfile *per_objfile)
 {
-  if (dwarf_read_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog,
-                         "Expanding one or more symtabs of objfile %s ...\n",
-                         objfile_name (dwarf2_per_objfile->objfile));
-    }
+  dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
+                          objfile_name (per_objfile->objfile));
 
   /* The queue starts out with one item, but following a DIE reference
      may load a new CU, adding it to the end of the queue.  */
-  while (!dwarf2_per_objfile->per_bfd->queue.empty ())
+  while (!per_objfile->per_bfd->queue.empty ())
     {
-      dwarf2_queue_item &item = dwarf2_per_objfile->per_bfd->queue.front ();
+      dwarf2_queue_item &item = per_objfile->per_bfd->queue.front ();
       dwarf2_per_cu_data *per_cu = item.per_cu;
 
-      if (!dwarf2_per_objfile->symtab_set_p (per_cu))
+      if (!per_objfile->symtab_set_p (per_cu))
        {
-         dwarf2_cu *cu = dwarf2_per_objfile->get_cu (per_cu);
+         dwarf2_cu *cu = per_objfile->get_cu (per_cu);
 
          /* Skip dummy CUs.  */
          if (cu != nullptr)
@@ -9113,7 +9241,7 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
                }
 
              if (dwarf_read_debug >= debug_print_threshold)
-               fprintf_unfiltered (gdb_stdlog, "Expanding symtab of %s\n", buf);
+               dwarf_read_debug_printf ("Expanding symtab of %s", buf);
 
              if (per_cu->is_debug_types)
                process_full_type_unit (cu, item.pretend_language);
@@ -9121,19 +9249,16 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
                process_full_comp_unit (cu, item.pretend_language);
 
              if (dwarf_read_debug >= debug_print_threshold)
-               fprintf_unfiltered (gdb_stdlog, "Done expanding %s\n", buf);
+               dwarf_read_debug_printf ("Done expanding %s", buf);
            }
        }
 
       per_cu->queued = 0;
-      dwarf2_per_objfile->per_bfd->queue.pop ();
+      per_objfile->per_bfd->queue.pop ();
     }
 
-  if (dwarf_read_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog, "Done expanding symtabs of %s.\n",
-                         objfile_name (dwarf2_per_objfile->objfile));
-    }
+  dwarf_read_debug_printf ("Done expanding symtabs of %s.",
+                          objfile_name (per_objfile->objfile));
 }
 
 /* Read in full symbols for PST, and anything it depends on.  */
@@ -9192,17 +9317,22 @@ die_eq (const void *item_lhs, const void *item_rhs)
   return die_lhs->sect_off == die_rhs->sect_off;
 }
 
-/* Load the DIEs associated with PER_CU into memory.  */
+/* Load the DIEs associated with PER_CU into memory.
+
+   In some cases, the caller, while reading partial symbols, will need to load
+   the full symbols for the CU for some reason.  It will already have a
+   dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
+   rather than creating a new one.  */
 
 static void
 load_full_comp_unit (dwarf2_per_cu_data *this_cu,
                     dwarf2_per_objfile *per_objfile,
+                    dwarf2_cu *existing_cu,
                     bool skip_partial,
                     enum language pretend_language)
 {
   gdb_assert (! this_cu->is_debug_types);
 
-  dwarf2_cu *existing_cu = per_objfile->get_cu (this_cu);
   cutu_reader reader (this_cu, per_objfile, NULL, existing_cu, skip_partial);
   if (reader.dummy_p)
     return;
@@ -9403,7 +9533,8 @@ rust_fully_qualify (struct obstack *obstack, const char *p1, const char *p2)
 /* A helper that allocates a variant part to attach to a Rust enum
    type.  OBSTACK is where the results should be allocated.  TYPE is
    the type we're processing.  DISCRIMINANT_INDEX is the index of the
-   discriminant.  It must be the index of one of the fields of TYPE.
+   discriminant.  It must be the index of one of the fields of TYPE,
+   or -1 to mean there is no discriminant (univariant enum).
    DEFAULT_INDEX is the index of the default field; or -1 if there is
    no default.  RANGES is indexed by "effective" field number (the
    field index, but omitting the discriminant and default fields) and
@@ -9416,15 +9547,17 @@ alloc_rust_variant (struct obstack *obstack, struct type *type,
                    int discriminant_index, int default_index,
                    gdb::array_view<discriminant_range> ranges)
 {
-  /* When DISCRIMINANT_INDEX == -1, we have a univariant enum.  Those
-     must be handled by the caller.  */
-  gdb_assert (discriminant_index >= 0
-             && discriminant_index < type->num_fields ());
+  /* When DISCRIMINANT_INDEX == -1, we have a univariant enum.  */
+  gdb_assert (discriminant_index == -1
+             || (discriminant_index >= 0
+                 && discriminant_index < type->num_fields ()));
   gdb_assert (default_index == -1
              || (default_index >= 0 && default_index < type->num_fields ()));
 
   /* We have one variant for each non-discriminant field.  */
-  int n_variants = type->num_fields () - 1;
+  int n_variants = type->num_fields ();
+  if (discriminant_index != -1)
+    --n_variants;
 
   variant *variants = new (obstack) variant[n_variants];
   int var_idx = 0;
@@ -9453,8 +9586,12 @@ alloc_rust_variant (struct obstack *obstack, struct type *type,
 
   variant_part *part = new (obstack) variant_part;
   part->discriminant_index = discriminant_index;
-  part->is_unsigned = TYPE_UNSIGNED (TYPE_FIELD_TYPE (type,
-                                                     discriminant_index));
+  /* If there is no discriminant, then whether it is signed is of no
+     consequence.  */
+  part->is_unsigned
+    = (discriminant_index == -1
+       ? false
+       : type->field (discriminant_index).type ()->is_unsigned ());
   part->variants = gdb::array_view<variant> (variants, n_variants);
 
   void *storage = obstack_alloc (obstack, sizeof (gdb::array_view<variant_part>));
@@ -9462,8 +9599,7 @@ alloc_rust_variant (struct obstack *obstack, struct type *type,
     = new (storage) gdb::array_view<variant_part> (part, 1);
 
   struct dynamic_prop prop;
-  prop.kind = PROP_VARIANT_PARTS;
-  prop.data.variant_parts = prop_value;
+  prop.set_variant_parts (prop_value);
 
   type->add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop);
 }
@@ -9506,7 +9642,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       /* Decode the field name to find the offset of the
         discriminant.  */
       ULONGEST bit_offset = 0;
-      struct type *field_type = TYPE_FIELD_TYPE (type, 0);
+      struct type *field_type = type->field (0).type ();
       while (name[0] >= '0' && name[0] <= '9')
        {
          char *tail;
@@ -9526,7 +9662,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
          ++name;
 
          bit_offset += TYPE_FIELD_BITPOS (field_type, index);
-         field_type = TYPE_FIELD_TYPE (field_type, index);
+         field_type = field_type->field (index).type ();
        }
 
       /* Smash this type to be a structure type.  We have to do this
@@ -9539,7 +9675,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
        ((struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field)));
 
       /* Put the discriminant at index 0.  */
-      TYPE_FIELD_TYPE (type, 0) = field_type;
+      type->field (0).set_type (field_type);
       TYPE_FIELD_ARTIFICIAL (type, 0) = 1;
       TYPE_FIELD_NAME (type, 0) = "<<discriminant>>";
       SET_FIELD_BITPOS (type->field (0), bit_offset);
@@ -9548,8 +9684,8 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
         field at index 1 and the data-less field at index 2.  */
       type->field (1) = saved_field;
       TYPE_FIELD_NAME (type, 1)
-       = rust_last_path_segment (TYPE_FIELD_TYPE (type, 1)->name ());
-      TYPE_FIELD_TYPE (type, 1)->set_name
+       = rust_last_path_segment (type->field (1).type ()->name ());
+      type->field (1).type ()->set_name
        (rust_fully_qualify (&objfile->objfile_obstack, type->name (),
                             TYPE_FIELD_NAME (type, 1)));
 
@@ -9558,7 +9694,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
                              name);
       struct type *dataless_type = init_type (objfile, TYPE_CODE_VOID, 0,
                                              dataless_name);
-      TYPE_FIELD_TYPE (type, 2) = dataless_type;
+      type->field (2).set_type (dataless_type);
       /* NAME points into the original discriminant name, which
         already has the correct lifetime.  */
       TYPE_FIELD_NAME (type, 2) = name;
@@ -9576,20 +9712,22 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
         because the type has already been recorded.  */
       type->set_code (TYPE_CODE_STRUCT);
 
-      struct type *field_type = TYPE_FIELD_TYPE (type, 0);
+      struct type *field_type = type->field (0).type ();
       const char *variant_name
        = rust_last_path_segment (field_type->name ());
       TYPE_FIELD_NAME (type, 0) = variant_name;
       field_type->set_name
        (rust_fully_qualify (&objfile->objfile_obstack,
                             type->name (), variant_name));
+
+      alloc_rust_variant (&objfile->objfile_obstack, type, -1, 0, {});
     }
   else
     {
       struct type *disr_type = nullptr;
       for (int i = 0; i < type->num_fields (); ++i)
        {
-         disr_type = TYPE_FIELD_TYPE (type, i);
+         disr_type = type->field (i).type ();
 
          if (disr_type->code () != TYPE_CODE_STRUCT)
            {
@@ -9640,7 +9778,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 
       /* We need a way to find the correct discriminant given a
         variant name.  For convenience we build a map here.  */
-      struct type *enum_type = FIELD_TYPE (*disr_field);
+      struct type *enum_type = disr_field->type ();
       std::unordered_map<std::string, ULONGEST> discriminant_map;
       for (int i = 0; i < enum_type->num_fields (); ++i)
        {
@@ -9666,17 +9804,21 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
             That name can be used to look up the correct
             discriminant.  */
          const char *variant_name
-           = rust_last_path_segment (TYPE_FIELD_TYPE (type, i)->name ());
+           = rust_last_path_segment (type->field (i).type ()->name ());
 
          auto iter = discriminant_map.find (variant_name);
          if (iter != discriminant_map.end ())
            {
-             ranges[i].low = iter->second;
-             ranges[i].high = iter->second;
+             ranges[i - 1].low = iter->second;
+             ranges[i - 1].high = iter->second;
            }
 
+         /* In Rust, each element should have the size of the
+            enclosing enum.  */
+         TYPE_LENGTH (type->field (i).type ()) = TYPE_LENGTH (type);
+
          /* Remove the discriminant field, if it exists.  */
-         struct type *sub_type = TYPE_FIELD_TYPE (type, i);
+         struct type *sub_type = type->field (i).type ();
          if (sub_type->num_fields () > 0)
            {
              sub_type->set_num_fields (sub_type->num_fields () - 1);
@@ -9689,7 +9831,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
        }
 
       /* Indicate that this is a variant type.  */
-      alloc_rust_variant (&objfile->objfile_obstack, type, 0, 1,
+      alloc_rust_variant (&objfile->objfile_obstack, type, 0, -1,
                          gdb::array_view<discriminant_range> (ranges,
                                                               n_fields - 1));
     }
@@ -9807,23 +9949,24 @@ compute_compunit_symtab_includes (dwarf2_per_cu_data *per_cu,
     {
       int len;
       std::vector<compunit_symtab *> result_symtabs;
-      htab_t all_children, all_type_symtabs;
       compunit_symtab *cust = per_objfile->get_symtab (per_cu);
 
       /* If we don't have a symtab, we can just skip this case.  */
       if (cust == NULL)
        return;
 
-      all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
-                                       NULL, xcalloc, xfree);
-      all_type_symtabs = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
-                                           NULL, xcalloc, xfree);
+      htab_up all_children (htab_create_alloc (1, htab_hash_pointer,
+                                              htab_eq_pointer,
+                                              NULL, xcalloc, xfree));
+      htab_up all_type_symtabs (htab_create_alloc (1, htab_hash_pointer,
+                                                  htab_eq_pointer,
+                                                  NULL, xcalloc, xfree));
 
       for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
        {
-         recursively_compute_inclusions (&result_symtabs, all_children,
-                                         all_type_symtabs, ptr, per_objfile,
-                                         cust);
+         recursively_compute_inclusions (&result_symtabs, all_children.get (),
+                                         all_type_symtabs.get (), ptr,
+                                         per_objfile, cust);
        }
 
       /* Now we have a transitive closure of all the included symtabs.  */
@@ -9834,9 +9977,6 @@ compute_compunit_symtab_includes (dwarf2_per_cu_data *per_cu,
       memcpy (cust->includes, result_symtabs.data (),
              len * sizeof (compunit_symtab *));
       cust->includes[len] = NULL;
-
-      htab_delete (all_children);
-      htab_delete (all_type_symtabs);
     }
 }
 
@@ -9844,15 +9984,15 @@ compute_compunit_symtab_includes (dwarf2_per_cu_data *per_cu,
    read.  */
 
 static void
-process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile)
+process_cu_includes (dwarf2_per_objfile *per_objfile)
 {
-  for (dwarf2_per_cu_data *iter : dwarf2_per_objfile->per_bfd->just_read_cus)
+  for (dwarf2_per_cu_data *iter : per_objfile->per_bfd->just_read_cus)
     {
       if (! iter->is_debug_types)
-       compute_compunit_symtab_includes (iter, dwarf2_per_objfile);
+       compute_compunit_symtab_includes (iter, per_objfile);
     }
 
-  dwarf2_per_objfile->per_bfd->just_read_cus.clear ();
+  per_objfile->per_bfd->just_read_cus.clear ();
 }
 
 /* Generate full symbol information for CU, whose DIEs have
@@ -9861,8 +10001,8 @@ process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile)
 static void
 process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
 {
-  dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR lowpc, highpc;
   struct compunit_symtab *cust;
@@ -9878,6 +10018,8 @@ process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
   cu->language = pretend_language;
   cu->language_defn = language_def (cu->language);
 
+  dwarf2_find_base_address (cu->dies, cu);
+
   /* Do line number decoding in read_file_scope () */
   process_die (cu->dies, cu);
 
@@ -9944,10 +10086,10 @@ process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
       cust->call_site_htab = cu->call_site_htab;
     }
 
-  dwarf2_per_objfile->set_symtab (cu->per_cu, cust);
+  per_objfile->set_symtab (cu->per_cu, cust);
 
   /* Push it for inclusion processing later.  */
-  dwarf2_per_objfile->per_bfd->just_read_cus.push_back (cu->per_cu);
+  per_objfile->per_bfd->just_read_cus.push_back (cu->per_cu);
 
   /* Not needed any more.  */
   cu->reset_builder ();
@@ -9960,8 +10102,8 @@ static void
 process_full_type_unit (dwarf2_cu *cu,
                        enum language pretend_language)
 {
-  dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct compunit_symtab *cust;
   struct signatured_type *sig_type;
 
@@ -9994,7 +10136,7 @@ process_full_type_unit (dwarf2_cu *cu,
      of it with end_expandable_symtab.  Otherwise, complete the addition of
      this TU's symbols to the existing symtab.  */
   type_unit_group_unshareable *tug_unshare =
-    dwarf2_per_objfile->get_type_unit_group_unshareable (sig_type->type_unit_group);
+    per_objfile->get_type_unit_group_unshareable (sig_type->type_unit_group);
   if (tug_unshare->compunit_symtab == NULL)
     {
       buildsym_compunit *builder = cu->get_builder ();
@@ -10018,7 +10160,7 @@ process_full_type_unit (dwarf2_cu *cu,
       cust = tug_unshare->compunit_symtab;
     }
 
-  dwarf2_per_objfile->set_symtab (cu->per_cu, cust);
+  per_objfile->set_symtab (cu->per_cu, cust);
 
   /* Not needed any more.  */
   cu->reset_builder ();
@@ -10058,7 +10200,8 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
 
       /* If necessary, add it to the queue and load its DIEs.  */
       if (maybe_queue_comp_unit (cu, per_cu, per_objfile, cu->language))
-       load_full_comp_unit (per_cu, per_objfile, false, cu->language);
+       load_full_comp_unit (per_cu, per_objfile, per_objfile->get_cu (per_cu),
+                            false, cu->language);
 
       cu->per_cu->imported_symtabs_push (per_cu);
     }
@@ -10148,7 +10291,6 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
        read them on-demand through read_type_die.  */
     case DW_TAG_subroutine_type:
     case DW_TAG_set_type:
-    case DW_TAG_array_type:
     case DW_TAG_pointer_type:
     case DW_TAG_ptr_to_member_type:
     case DW_TAG_reference_type:
@@ -10156,11 +10298,18 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_string_type:
       break;
 
+    case DW_TAG_array_type:
+      /* We only need to handle this case for Ada -- in other
+        languages, it's normal for the compiler to emit a typedef
+        instead.  */
+      if (cu->language != language_ada)
+       break;
+      /* FALLTHROUGH */
     case DW_TAG_base_type:
     case DW_TAG_subrange_type:
     case DW_TAG_typedef:
       /* Add a typedef symbol for the type definition, if it has a
-         DW_AT_name.  */
+        DW_AT_name.  */
       new_symbol (die, read_type_die (die, cu), cu);
       break;
     case DW_TAG_common_block:
@@ -10452,7 +10601,7 @@ dwarf2_compute_name (const char *name,
                                           &cu->comp_unit_obstack, cu,
                                           &value, &bytes, &baton);
 
-                 if (TYPE_NOSIGN (type))
+                 if (type->has_no_signedness ())
                    /* GDB prints characters as NUMBER 'CHAR'.  If that's
                       changed, this can use value_print instead.  */
                    c_printchar (value, type, &buf);
@@ -10517,9 +10666,8 @@ dwarf2_compute_name (const char *name,
                     the two cases.  */
                  if (type->num_fields () > 0
                      && TYPE_FIELD_ARTIFICIAL (type, 0)
-                     && TYPE_FIELD_TYPE (type, 0)->code () == TYPE_CODE_PTR
-                     && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
-                                                                       0))))
+                     && type->field (0).type ()->code () == TYPE_CODE_PTR
+                     && TYPE_CONST (TYPE_TARGET_TYPE (type->field (0).type ())))
                    buf.puts (" const");
                }
            }
@@ -10586,16 +10734,10 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
   if (mangled != NULL)
     {
 
-      if (language_def (cu->language)->la_store_sym_names_in_linkage_form_p)
+      if (language_def (cu->language)->store_sym_names_in_linkage_form_p ())
        {
          /* Do nothing (do not demangle the symbol name).  */
        }
-      else if (cu->language == language_go)
-       {
-         /* This is a lie, but we already lie to the caller new_symbol.
-            new_symbol assumes we return the mangled name.
-            This just undoes that lie until things are cleaned up.  */
-       }
       else
        {
          /* Use DMGL_RET_DROP for C++ template functions to suppress
@@ -10765,36 +10907,36 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
     {
       /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
 
-        The import in the following code:
-        namespace A
-          {
-            typedef int B;
-          }
-
-        int main ()
-          {
-            using A::B;
-            B b;
-            return b;
-          }
-
-        ...
-         <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
-            <52>   DW_AT_decl_file   : 1
-            <53>   DW_AT_decl_line   : 6
-            <54>   DW_AT_import      : <0x75>
-         <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
-            <59>   DW_AT_name        : B
-            <5b>   DW_AT_decl_file   : 1
-            <5c>   DW_AT_decl_line   : 2
-            <5d>   DW_AT_type        : <0x6e>
-        ...
-         <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
-            <76>   DW_AT_byte_size   : 4
-            <77>   DW_AT_encoding    : 5        (signed)
-
-        imports the wrong die ( 0x75 instead of 0x58 ).
-        This case will be ignored until the gcc bug is fixed.  */
+       The import in the following code:
+       namespace A
+         {
+           typedef int B;
+         }
+
+       int main ()
+         {
+           using A::B;
+           B b;
+           return b;
+         }
+
+       ...
+        <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
+           <52>   DW_AT_decl_file   : 1
+           <53>   DW_AT_decl_line   : 6
+           <54>   DW_AT_import      : <0x75>
+        <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
+           <59>   DW_AT_name        : B
+           <5b>   DW_AT_decl_file   : 1
+           <5c>   DW_AT_decl_line   : 2
+           <5d>   DW_AT_type        : <0x6e>
+       ...
+        <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
+           <76>   DW_AT_byte_size   : 4
+           <77>   DW_AT_encoding    : 5        (signed)
+
+       imports the wrong die ( 0x75 instead of 0x58 ).
+       This case will be ignored until the gcc bug is fixed.  */
       return;
     }
 
@@ -10958,7 +11100,7 @@ static void
 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
                        const char *comp_dir, CORE_ADDR lowpc) /* ARI: editCase function */
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct attribute *attr;
   struct line_header line_header_local;
   hashval_t line_header_local_hash;
@@ -10968,10 +11110,10 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
   gdb_assert (! cu->per_cu->is_debug_types);
 
   attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
-  if (attr == NULL)
+  if (attr == NULL || !attr->form_is_unsigned ())
     return;
 
-  sect_offset line_offset = (sect_offset) DW_UNSND (attr);
+  sect_offset line_offset = (sect_offset) attr->as_unsigned ();
 
   /* The line header hash table is only created if needed (it exists to
      prevent redundant reading of the line table for partial_units).
@@ -10979,10 +11121,10 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
      compile_unit, then use the line header hash table if it's already
      created, but don't create one just yet.  */
 
-  if (dwarf2_per_objfile->line_header_hash == NULL
+  if (per_objfile->line_header_hash == NULL
       && die->tag == DW_TAG_partial_unit)
     {
-      dwarf2_per_objfile->line_header_hash
+      per_objfile->line_header_hash
        .reset (htab_create_alloc (127, line_header_hash_voidp,
                                   line_header_eq_voidp,
                                   free_line_header_voidp,
@@ -10992,9 +11134,9 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
   line_header_local.sect_off = line_offset;
   line_header_local.offset_in_dwz = cu->per_cu->is_dwz;
   line_header_local_hash = line_header_hash (&line_header_local);
-  if (dwarf2_per_objfile->line_header_hash != NULL)
+  if (per_objfile->line_header_hash != NULL)
     {
-      slot = htab_find_slot_with_hash (dwarf2_per_objfile->line_header_hash.get (),
+      slot = htab_find_slot_with_hash (per_objfile->line_header_hash.get (),
                                       &line_header_local,
                                       line_header_local_hash, NO_INSERT);
 
@@ -11018,11 +11160,11 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
   cu->line_header = lh.release ();
   cu->line_header_die_owner = die;
 
-  if (dwarf2_per_objfile->line_header_hash == NULL)
+  if (per_objfile->line_header_hash == NULL)
     slot = NULL;
   else
     {
-      slot = htab_find_slot_with_hash (dwarf2_per_objfile->line_header_hash.get (),
+      slot = htab_find_slot_with_hash (per_objfile->line_header_hash.get (),
                                       &line_header_local,
                                       line_header_local_hash, INSERT);
       gdb_assert (slot != NULL);
@@ -11037,7 +11179,7 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
   else
     {
       /* We cannot free any current entry in (*slot) as that struct line_header
-         may be already used by multiple CUs.  Create only temporary decoded
+        may be already used by multiple CUs.  Create only temporary decoded
         line_header for this CU - it may happen at most once for each line
         number information unit.  And if we're not using line_header_hash
         then this is what we want as well.  */
@@ -11054,8 +11196,8 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
 static void
 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR lowpc = ((CORE_ADDR) -1);
   CORE_ADDR highpc = ((CORE_ADDR) 0);
@@ -11111,19 +11253,19 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_macros, cu);
   if (attr == NULL)
     attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
-  if (attr && cu->line_header)
+  if (attr != nullptr && attr->form_is_unsigned () && cu->line_header)
     {
       if (dwarf2_attr (die, DW_AT_macro_info, cu))
        complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
 
-      dwarf_decode_macros (cu, DW_UNSND (attr), 1);
+      dwarf_decode_macros (cu, attr->as_unsigned (), 1);
     }
   else
     {
       attr = dwarf2_attr (die, DW_AT_macro_info, cu);
-      if (attr && cu->line_header)
+      if (attr != nullptr && attr->form_is_unsigned () && cu->line_header)
        {
-         unsigned int macro_offset = DW_UNSND (attr);
+         unsigned int macro_offset = attr->as_unsigned ();
 
          dwarf_decode_macros (cu, macro_offset, 0);
        }
@@ -11161,9 +11303,9 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
   /* We have to handle the case of both a missing DW_AT_stmt_list or bad
      debug info.  */
   line_header_up lh;
-  if (attr != NULL)
+  if (attr != NULL && attr->form_is_unsigned ())
     {
-      sect_offset line_offset = (sect_offset) DW_UNSND (attr);
+      sect_offset line_offset = (sect_offset) attr->as_unsigned ();
       lh = dwarf_decode_line_header (line_offset, this);
     }
   if (lh == NULL)
@@ -11333,19 +11475,19 @@ allocate_dwo_file_hash_table ()
 /* Lookup DWO file DWO_NAME.  */
 
 static void **
-lookup_dwo_file_slot (struct dwarf2_per_objfile *dwarf2_per_objfile,
+lookup_dwo_file_slot (dwarf2_per_objfile *per_objfile,
                      const char *dwo_name,
                      const char *comp_dir)
 {
   struct dwo_file find_entry;
   void **slot;
 
-  if (dwarf2_per_objfile->per_bfd->dwo_files == NULL)
-    dwarf2_per_objfile->per_bfd->dwo_files = allocate_dwo_file_hash_table ();
+  if (per_objfile->per_bfd->dwo_files == NULL)
+    per_objfile->per_bfd->dwo_files = allocate_dwo_file_hash_table ();
 
   find_entry.dwo_name = dwo_name;
   find_entry.comp_dir = comp_dir;
-  slot = htab_find_slot (dwarf2_per_objfile->per_bfd->dwo_files.get (), &find_entry,
+  slot = htab_find_slot (per_objfile->per_bfd->dwo_files.get (), &find_entry,
                         INSERT);
 
   return slot;
@@ -11415,22 +11557,21 @@ create_dwo_cu_reader (const struct die_reader_specs *reader,
   dwo_unit->sect_off = sect_off;
   dwo_unit->length = cu->per_cu->length;
 
-  if (dwarf_read_debug)
-    fprintf_unfiltered (gdb_stdlog, "  offset %s, dwo_id %s\n",
-                       sect_offset_str (sect_off),
-                       hex_string (dwo_unit->signature));
+  dwarf_read_debug_printf ("  offset %s, dwo_id %s",
+                          sect_offset_str (sect_off),
+                          hex_string (dwo_unit->signature));
 }
 
 /* Create the dwo_units for the CUs in a DWO_FILE.
    Note: This function processes DWO files only, not DWP files.  */
 
 static void
-create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
+create_cus_hash_table (dwarf2_per_objfile *per_objfile,
                       dwarf2_cu *cu, struct dwo_file &dwo_file,
                       dwarf2_section_info &section, htab_up &cus_htab)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
-  dwarf2_per_bfd *per_bfd = dwarf2_per_objfile->per_bfd;
+  struct objfile *objfile = per_objfile->objfile;
+  dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
   const gdb_byte *info_ptr, *end_ptr;
 
   section.read (objfile);
@@ -11439,12 +11580,9 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (info_ptr == NULL)
     return;
 
-  if (dwarf_read_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog, "Reading %s for %s:\n",
-                         section.get_name (),
-                         section.get_file_name ());
-    }
+  dwarf_read_debug_printf ("Reading %s for %s:",
+                          section.get_name (),
+                          section.get_file_name ());
 
   end_ptr = info_ptr + section.size;
   while (info_ptr < end_ptr)
@@ -11461,7 +11599,7 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
       per_cu.sect_off = sect_offset (info_ptr - section.buffer);
       per_cu.section = &section;
 
-      cutu_reader reader (&per_cu, dwarf2_per_objfile, cu, &dwo_file);
+      cutu_reader reader (&per_cu, per_objfile, cu, &dwo_file);
       if (!reader.dummy_p)
        create_dwo_cu_reader (&reader, reader.info_ptr, reader.comp_unit_die,
                              &dwo_file, &read_unit);
@@ -11495,6 +11633,11 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
 /* DWP file .debug_{cu,tu}_index section format:
    [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
+   [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
+
+   DWP Versions 1 & 2 are older, pre-standard format versions.  The first
+   officially standard DWP format was published with DWARF v5 and is called
+   Version 5.  There are no versions 3 or 4.
 
    DWP Version 1:
 
@@ -11539,9 +11682,9 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
    ---
 
-   DWP Version 2:
+   DWP Versions 2 and 5:
 
-   DWP Version 2 combines all the .debug_info, etc. sections into one,
+   DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
    and the entries in the index tables are now offsets into these sections.
    CU offsets begin at 0.  TU offsets begin at the size of the .debug_info
    section.
@@ -11550,8 +11693,8 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
     Header
     Hash Table of Signatures   dwp_hash_table.hash_table
     Parallel Table of Indices  dwp_hash_table.unit_table
-    Table of Section Offsets   dwp_hash_table.v2.{section_ids,offsets}
-    Table of Section Sizes     dwp_hash_table.v2.sizes
+    Table of Section Offsets   dwp_hash_table.{v2|v5}.{section_ids,offsets}
+    Table of Section Sizes     dwp_hash_table.{v2|v5}.sizes
 
    The index section header consists of:
 
@@ -11574,7 +11717,7 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
    Each row in the array is indexed starting from 0.  The first row provides
    a key to the remaining rows: each column in this row provides an identifier
    for a debug section, and the offsets in the same column of subsequent rows
-   refer to that section.  The section identifiers are:
+   refer to that section.  The section identifiers for Version 2 are:
 
     DW_SECT_INFO         1  .debug_info.dwo
     DW_SECT_TYPES        2  .debug_types.dwo
@@ -11585,6 +11728,17 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
     DW_SECT_MACINFO      7  .debug_macinfo.dwo
     DW_SECT_MACRO        8  .debug_macro.dwo
 
+   The section identifiers for Version 5 are:
+
+    DW_SECT_INFO_V5         1  .debug_info.dwo
+    DW_SECT_RESERVED_V5     2  --
+    DW_SECT_ABBREV_V5       3  .debug_abbrev.dwo
+    DW_SECT_LINE_V5         4  .debug_line.dwo
+    DW_SECT_LOCLISTS_V5     5  .debug_loclists.dwo
+    DW_SECT_STR_OFFSETS_V5  6  .debug_str_offsets.dwo
+    DW_SECT_MACRO_V5        7  .debug_macro.dwo
+    DW_SECT_RNGLISTS_V5     8  .debug_rnglists.dwo
+
    The offsets provided by the CU and TU index sections are the base offsets
    for the contributions made by each CU or TU to the corresponding section
    in the package file.  Each CU and TU header contains an abbrev_offset
@@ -11631,10 +11785,10 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
    Note: This function processes DWP files only, not DWO files.  */
 
 static struct dwp_hash_table *
-create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
+create_dwp_hash_table (dwarf2_per_objfile *per_objfile,
                       struct dwp_file *dwp_file, int is_debug_types)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
   bfd *dbfd = dwp_file->dbfd.get ();
   const gdb_byte *index_ptr, *index_end;
   struct dwarf2_section_info *index;
@@ -11653,9 +11807,12 @@ create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
   index_ptr = index->buffer;
   index_end = index_ptr + index->size;
 
+  /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
+     For now it's safe to just read 4 bytes (particularly as it's difficult to
+     tell if you're dealing with Version 5 before you've read the version).   */
   version = read_4_bytes (dbfd, index_ptr);
   index_ptr += 4;
-  if (version == 2)
+  if (version == 2 || version == 5)
     nr_columns = read_4_bytes (dbfd, index_ptr);
   else
     nr_columns = 0;
@@ -11665,7 +11822,7 @@ create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
   nr_slots = read_4_bytes (dbfd, index_ptr);
   index_ptr += 4;
 
-  if (version != 1 && version != 2)
+  if (version != 1 && version != 2 && version != 5)
     {
       error (_("Dwarf Error: unsupported DWP file version (%s)"
               " [in module %s]"),
@@ -11678,7 +11835,7 @@ create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
             pulongest (nr_slots), dwp_file->name);
     }
 
-  htab = OBSTACK_ZALLOC (&dwarf2_per_objfile->per_bfd->obstack, struct dwp_hash_table);
+  htab = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwp_hash_table);
   htab->version = version;
   htab->nr_columns = nr_columns;
   htab->nr_units = nr_units;
@@ -11688,11 +11845,13 @@ create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   /* Exit early if the table is empty.  */
   if (nr_slots == 0 || nr_units == 0
-      || (version == 2 && nr_columns == 0))
+      || (version == 2 && nr_columns == 0)
+      || (version == 5 && nr_columns == 0))
     {
       /* All must be zero.  */
       if (nr_slots != 0 || nr_units != 0
-         || (version == 2 && nr_columns != 0))
+         || (version == 2 && nr_columns != 0)
+         || (version == 5 && nr_columns != 0))
        {
          complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
                       " all zero [in modules %s]"),
@@ -11708,7 +11867,7 @@ create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
       /* It's harder to decide whether the section is too small in v1.
         V1 is deprecated anyway so we punt.  */
     }
-  else
+  else if (version == 2)
     {
       const gdb_byte *ids_ptr = htab->unit_table + sizeof (uint32_t) * nr_slots;
       int *ids = htab->section_pool.v2.section_ids;
@@ -11779,15 +11938,83 @@ create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
                 dwp_file->name);
        }
     }
+  else /* version == 5  */
+    {
+      const gdb_byte *ids_ptr = htab->unit_table + sizeof (uint32_t) * nr_slots;
+      int *ids = htab->section_pool.v5.section_ids;
+      size_t sizeof_ids = sizeof (htab->section_pool.v5.section_ids);
+      /* Reverse map for error checking.  */
+      int ids_seen[DW_SECT_MAX_V5 + 1];
 
-  return htab;
-}
-
-/* Update SECTIONS with the data from SECTP.
+      if (nr_columns < 2)
+       {
+         error (_("Dwarf Error: bad DWP hash table, too few columns"
+                  " in section table [in module %s]"),
+                dwp_file->name);
+       }
+      if (nr_columns > MAX_NR_V5_DWO_SECTIONS)
+       {
+         error (_("Dwarf Error: bad DWP hash table, too many columns"
+                  " in section table [in module %s]"),
+                dwp_file->name);
+       }
+      memset (ids, 255, sizeof_ids);
+      memset (ids_seen, 255, sizeof (ids_seen));
+      for (int i = 0; i < nr_columns; ++i)
+       {
+         int id = read_4_bytes (dbfd, ids_ptr + i * sizeof (uint32_t));
+
+         if (id < DW_SECT_MIN || id > DW_SECT_MAX_V5)
+           {
+             error (_("Dwarf Error: bad DWP hash table, bad section id %d"
+                      " in section table [in module %s]"),
+                    id, dwp_file->name);
+           }
+         if (ids_seen[id] != -1)
+           {
+             error (_("Dwarf Error: bad DWP hash table, duplicate section"
+                      " id %d in section table [in module %s]"),
+                    id, dwp_file->name);
+           }
+         ids_seen[id] = i;
+         ids[i] = id;
+       }
+      /* Must have seen an info section.  */
+      if (ids_seen[DW_SECT_INFO_V5] == -1)
+       {
+         error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
+                  " DWO info/types section [in module %s]"),
+                dwp_file->name);
+       }
+      /* Must have an abbrev section.  */
+      if (ids_seen[DW_SECT_ABBREV_V5] == -1)
+       {
+         error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
+                  " section [in module %s]"),
+                dwp_file->name);
+       }
+      htab->section_pool.v5.offsets = ids_ptr + sizeof (uint32_t) * nr_columns;
+      htab->section_pool.v5.sizes
+       = htab->section_pool.v5.offsets + (sizeof (uint32_t)
+                                        * nr_units * nr_columns);
+      if ((htab->section_pool.v5.sizes + (sizeof (uint32_t)
+                                         * nr_units * nr_columns))
+         > index_end)
+       {
+         error (_("Dwarf Error: DWP index section is corrupt (too small)"
+                  " [in module %s]"),
+                dwp_file->name);
+       }
+    }
+
+  return htab;
+}
+
+/* Update SECTIONS with the data from SECTP.
 
-   This function is like the other "locate" section routines that are
-   passed to bfd_map_over_sections, but in this context the sections to
-   read comes from the DWP V1 hash table, not the full ELF section table.
+   This function is like the other "locate" section routines, but in
+   this context the sections to read comes from the DWP V1 hash table,
+   not the full ELF section table.
 
    The result is non-zero for success, or zero if an error was found.  */
 
@@ -11869,7 +12096,7 @@ locate_v1_virtual_dwo_sections (asection *sectp,
    This is for DWP version 1 files.  */
 
 static struct dwo_unit *
-create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile,
+create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile *per_objfile,
                           struct dwp_file *dwp_file,
                           uint32_t unit_index,
                           const char *comp_dir,
@@ -11887,13 +12114,9 @@ create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   gdb_assert (dwp_file->version == 1);
 
-  if (dwarf_read_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog, "Reading %s %s/%s in DWP V1 file: %s\n",
-                         kind,
-                         pulongest (unit_index), hex_string (signature),
-                         dwp_file->name);
-    }
+  dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
+                          kind, pulongest (unit_index), hex_string (signature),
+                          dwp_file->name);
 
   /* Fetch the sections of this DWO unit.
      Put a limit on the number of sections we look for so that bad data
@@ -11967,19 +12190,16 @@ create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile,
                   sections.loc.get_id (),
                   sections.str_offsets.get_id ());
   /* Can we use an existing virtual DWO file?  */
-  dwo_file_slot = lookup_dwo_file_slot (dwarf2_per_objfile,
-                                       virtual_dwo_name.c_str (),
+  dwo_file_slot = lookup_dwo_file_slot (per_objfile, virtual_dwo_name.c_str (),
                                        comp_dir);
   /* Create one if necessary.  */
   if (*dwo_file_slot == NULL)
     {
-      if (dwarf_read_debug)
-       {
-         fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n",
-                             virtual_dwo_name.c_str ());
-       }
+      dwarf_read_debug_printf ("Creating virtual DWO: %s",
+                              virtual_dwo_name.c_str ());
+
       dwo_file = new struct dwo_file;
-      dwo_file->dwo_name = dwarf2_per_objfile->objfile->intern (virtual_dwo_name);
+      dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name);
       dwo_file->comp_dir = comp_dir;
       dwo_file->sections.abbrev = sections.abbrev;
       dwo_file->sections.line = sections.line;
@@ -12000,34 +12220,32 @@ create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile,
     }
   else
     {
-      if (dwarf_read_debug)
-       {
-         fprintf_unfiltered (gdb_stdlog, "Using existing virtual DWO: %s\n",
-                             virtual_dwo_name.c_str ());
-       }
+      dwarf_read_debug_printf ("Using existing virtual DWO: %s",
+                              virtual_dwo_name.c_str ());
+
       dwo_file = (struct dwo_file *) *dwo_file_slot;
     }
 
-  dwo_unit = OBSTACK_ZALLOC (&dwarf2_per_objfile->per_bfd->obstack, struct dwo_unit);
+  dwo_unit = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwo_unit);
   dwo_unit->dwo_file = dwo_file;
   dwo_unit->signature = signature;
   dwo_unit->section =
-    XOBNEW (&dwarf2_per_objfile->per_bfd->obstack, struct dwarf2_section_info);
+    XOBNEW (&per_objfile->per_bfd->obstack, struct dwarf2_section_info);
   *dwo_unit->section = sections.info_or_types;
   /* dwo_unit->{offset,length,type_offset_in_tu} are set later.  */
 
   return dwo_unit;
 }
 
-/* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
-   Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
-   piece within that section used by a TU/CU, return a virtual section
-   of just that piece.  */
+/* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
+   simplify them.  Given a pointer to the containing section SECTION, and
+   OFFSET,SIZE of the piece within that section used by a TU/CU, return a
+   virtual section of just that piece.  */
 
 static struct dwarf2_section_info
-create_dwp_v2_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
-                      struct dwarf2_section_info *section,
-                      bfd_size_type offset, bfd_size_type size)
+create_dwp_v2_or_v5_section (dwarf2_per_objfile *per_objfile,
+                            struct dwarf2_section_info *section,
+                            bfd_size_type offset, bfd_size_type size)
 {
   struct dwarf2_section_info result;
   asection *sectp;
@@ -12050,10 +12268,10 @@ create_dwp_v2_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (sectp == NULL
       || offset + size > bfd_section_size (sectp))
     {
-      error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
+      error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
               " in section %s [in module %s]"),
             sectp ? bfd_section_name (sectp) : "<unknown>",
-            objfile_name (dwarf2_per_objfile->objfile));
+            objfile_name (per_objfile->objfile));
     }
 
   result.virtual_offset = offset;
@@ -12067,7 +12285,7 @@ create_dwp_v2_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
    This is for DWP version 2 files.  */
 
 static struct dwo_unit *
-create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile *dwarf2_per_objfile,
+create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile *per_objfile,
                           struct dwp_file *dwp_file,
                           uint32_t unit_index,
                           const char *comp_dir,
@@ -12079,19 +12297,15 @@ create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile *dwarf2_per_objfile,
   const char *kind = is_debug_types ? "TU" : "CU";
   struct dwo_file *dwo_file;
   struct dwo_unit *dwo_unit;
-  struct virtual_v2_dwo_sections sections;
+  struct virtual_v2_or_v5_dwo_sections sections;
   void **dwo_file_slot;
   int i;
 
   gdb_assert (dwp_file->version == 2);
 
-  if (dwarf_read_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog, "Reading %s %s/%s in DWP V2 file: %s\n",
-                         kind,
-                         pulongest (unit_index), hex_string (signature),
-                         dwp_file->name);
-    }
+  dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
+                          kind, pulongest (unit_index), hex_string (signature),
+                          dwp_file->name);
 
   /* Fetch the section offsets of this DWO unit.  */
 
@@ -12161,40 +12375,41 @@ create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile *dwarf2_per_objfile,
                   (long) (sections.str_offsets_size
                           ? sections.str_offsets_offset : 0));
   /* Can we use an existing virtual DWO file?  */
-  dwo_file_slot = lookup_dwo_file_slot (dwarf2_per_objfile,
-                                       virtual_dwo_name.c_str (),
+  dwo_file_slot = lookup_dwo_file_slot (per_objfile, virtual_dwo_name.c_str (),
                                        comp_dir);
   /* Create one if necessary.  */
   if (*dwo_file_slot == NULL)
     {
-      if (dwarf_read_debug)
-       {
-         fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n",
-                             virtual_dwo_name.c_str ());
-       }
+      dwarf_read_debug_printf ("Creating virtual DWO: %s",
+                              virtual_dwo_name.c_str ());
+
       dwo_file = new struct dwo_file;
-      dwo_file->dwo_name = dwarf2_per_objfile->objfile->intern (virtual_dwo_name);
+      dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name);
       dwo_file->comp_dir = comp_dir;
       dwo_file->sections.abbrev =
-       create_dwp_v2_section (dwarf2_per_objfile, &dwp_file->sections.abbrev,
-                              sections.abbrev_offset, sections.abbrev_size);
+       create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.abbrev,
+                                    sections.abbrev_offset,
+                                    sections.abbrev_size);
       dwo_file->sections.line =
-       create_dwp_v2_section (dwarf2_per_objfile, &dwp_file->sections.line,
-                              sections.line_offset, sections.line_size);
+       create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.line,
+                                    sections.line_offset,
+                                    sections.line_size);
       dwo_file->sections.loc =
-       create_dwp_v2_section (dwarf2_per_objfile, &dwp_file->sections.loc,
-                              sections.loc_offset, sections.loc_size);
+       create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.loc,
+                                    sections.loc_offset, sections.loc_size);
       dwo_file->sections.macinfo =
-       create_dwp_v2_section (dwarf2_per_objfile, &dwp_file->sections.macinfo,
-                              sections.macinfo_offset, sections.macinfo_size);
+       create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.macinfo,
+                                    sections.macinfo_offset,
+                                    sections.macinfo_size);
       dwo_file->sections.macro =
-       create_dwp_v2_section (dwarf2_per_objfile, &dwp_file->sections.macro,
-                              sections.macro_offset, sections.macro_size);
+       create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.macro,
+                                    sections.macro_offset,
+                                    sections.macro_size);
       dwo_file->sections.str_offsets =
-       create_dwp_v2_section (dwarf2_per_objfile,
-                              &dwp_file->sections.str_offsets,
-                              sections.str_offsets_offset,
-                              sections.str_offsets_size);
+       create_dwp_v2_or_v5_section (per_objfile,
+                                    &dwp_file->sections.str_offsets,
+                                    sections.str_offsets_offset,
+                                    sections.str_offsets_size);
       /* The "str" section is global to the entire DWP file.  */
       dwo_file->sections.str = dwp_file->sections.str;
       /* The info or types section is assigned below to dwo_unit,
@@ -12208,23 +12423,196 @@ create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile *dwarf2_per_objfile,
     }
   else
     {
-      if (dwarf_read_debug)
+      dwarf_read_debug_printf ("Using existing virtual DWO: %s",
+                              virtual_dwo_name.c_str ());
+
+      dwo_file = (struct dwo_file *) *dwo_file_slot;
+    }
+
+  dwo_unit = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwo_unit);
+  dwo_unit->dwo_file = dwo_file;
+  dwo_unit->signature = signature;
+  dwo_unit->section =
+    XOBNEW (&per_objfile->per_bfd->obstack, struct dwarf2_section_info);
+  *dwo_unit->section = create_dwp_v2_or_v5_section
+                        (per_objfile,
+                         is_debug_types
+                         ? &dwp_file->sections.types
+                         : &dwp_file->sections.info,
+                         sections.info_or_types_offset,
+                         sections.info_or_types_size);
+  /* dwo_unit->{offset,length,type_offset_in_tu} are set later.  */
+
+  return dwo_unit;
+}
+
+/* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
+   UNIT_INDEX is the index of the DWO unit in the DWP hash table.
+   COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
+   This is for DWP version 5 files.  */
+
+static struct dwo_unit *
+create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile *per_objfile,
+                          struct dwp_file *dwp_file,
+                          uint32_t unit_index,
+                          const char *comp_dir,
+                          ULONGEST signature, int is_debug_types)
+{
+  const struct dwp_hash_table *dwp_htab
+    = is_debug_types ? dwp_file->tus : dwp_file->cus;
+  bfd *dbfd = dwp_file->dbfd.get ();
+  const char *kind = is_debug_types ? "TU" : "CU";
+  struct dwo_file *dwo_file;
+  struct dwo_unit *dwo_unit;
+  struct virtual_v2_or_v5_dwo_sections sections {};
+  void **dwo_file_slot;
+
+  gdb_assert (dwp_file->version == 5);
+
+  dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
+                          kind, pulongest (unit_index), hex_string (signature),
+                          dwp_file->name);
+
+  /* Fetch the section offsets of this DWO unit.  */
+
+  /*  memset (&sections, 0, sizeof (sections)); */
+
+  for (int i = 0; i < dwp_htab->nr_columns; ++i)
+    {
+      uint32_t offset = read_4_bytes (dbfd,
+                                     dwp_htab->section_pool.v5.offsets
+                                     + (((unit_index - 1)
+                                         * dwp_htab->nr_columns
+                                         + i)
+                                        * sizeof (uint32_t)));
+      uint32_t size = read_4_bytes (dbfd,
+                                   dwp_htab->section_pool.v5.sizes
+                                   + (((unit_index - 1) * dwp_htab->nr_columns
+                                       + i)
+                                      * sizeof (uint32_t)));
+
+      switch (dwp_htab->section_pool.v5.section_ids[i])
        {
-         fprintf_unfiltered (gdb_stdlog, "Using existing virtual DWO: %s\n",
-                             virtual_dwo_name.c_str ());
+         case DW_SECT_ABBREV_V5:
+           sections.abbrev_offset = offset;
+           sections.abbrev_size = size;
+           break;
+         case DW_SECT_INFO_V5:
+           sections.info_or_types_offset = offset;
+           sections.info_or_types_size = size;
+           break;
+         case DW_SECT_LINE_V5:
+           sections.line_offset = offset;
+           sections.line_size = size;
+           break;
+         case DW_SECT_LOCLISTS_V5:
+           sections.loclists_offset = offset;
+           sections.loclists_size = size;
+           break;
+         case DW_SECT_MACRO_V5:
+           sections.macro_offset = offset;
+           sections.macro_size = size;
+           break;
+         case DW_SECT_RNGLISTS_V5:
+           sections.rnglists_offset = offset;
+           sections.rnglists_size = size;
+           break;
+         case DW_SECT_STR_OFFSETS_V5:
+           sections.str_offsets_offset = offset;
+           sections.str_offsets_size = size;
+           break;
+         case DW_SECT_RESERVED_V5:
+         default:
+           break;
        }
+    }
+
+  /* It's easier for the rest of the code if we fake a struct dwo_file and
+     have dwo_unit "live" in that.  At least for now.
+
+     The DWP file can be made up of a random collection of CUs and TUs.
+     However, for each CU + set of TUs that came from the same original DWO
+     file, we can combine them back into a virtual DWO file to save space
+     (fewer struct dwo_file objects to allocate).  Remember that for really
+     large apps there can be on the order of 8K CUs and 200K TUs, or more.  */
+
+  std::string virtual_dwo_name =
+    string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
+                (long) (sections.abbrev_size ? sections.abbrev_offset : 0),
+                (long) (sections.line_size ? sections.line_offset : 0),
+                (long) (sections.loclists_size ? sections.loclists_offset : 0),
+                (long) (sections.str_offsets_size
+                           ? sections.str_offsets_offset : 0),
+                (long) (sections.macro_size ? sections.macro_offset : 0),
+                (long) (sections.rnglists_size ? sections.rnglists_offset: 0));
+  /* Can we use an existing virtual DWO file?  */
+  dwo_file_slot = lookup_dwo_file_slot (per_objfile,
+                                       virtual_dwo_name.c_str (),
+                                       comp_dir);
+  /* Create one if necessary.  */
+  if (*dwo_file_slot == NULL)
+    {
+      dwarf_read_debug_printf ("Creating virtual DWO: %s",
+                              virtual_dwo_name.c_str ());
+
+      dwo_file = new struct dwo_file;
+      dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name);
+      dwo_file->comp_dir = comp_dir;
+      dwo_file->sections.abbrev =
+       create_dwp_v2_or_v5_section (per_objfile,
+                                    &dwp_file->sections.abbrev,
+                                    sections.abbrev_offset,
+                                    sections.abbrev_size);
+      dwo_file->sections.line =
+       create_dwp_v2_or_v5_section (per_objfile,
+                                    &dwp_file->sections.line,
+                                    sections.line_offset, sections.line_size);
+      dwo_file->sections.macro =
+       create_dwp_v2_or_v5_section (per_objfile,
+                                    &dwp_file->sections.macro,
+                                    sections.macro_offset,
+                                    sections.macro_size);
+      dwo_file->sections.loclists =
+       create_dwp_v2_or_v5_section (per_objfile,
+                                    &dwp_file->sections.loclists,
+                                    sections.loclists_offset,
+                                    sections.loclists_size);
+      dwo_file->sections.rnglists =
+       create_dwp_v2_or_v5_section (per_objfile,
+                                    &dwp_file->sections.rnglists,
+                                    sections.rnglists_offset,
+                                    sections.rnglists_size);
+      dwo_file->sections.str_offsets =
+       create_dwp_v2_or_v5_section (per_objfile,
+                                    &dwp_file->sections.str_offsets,
+                                    sections.str_offsets_offset,
+                                    sections.str_offsets_size);
+      /* The "str" section is global to the entire DWP file.  */
+      dwo_file->sections.str = dwp_file->sections.str;
+      /* The info or types section is assigned below to dwo_unit,
+        there's no need to record it in dwo_file.
+        Also, we can't simply record type sections in dwo_file because
+        we record a pointer into the vector in dwo_unit.  As we collect more
+        types we'll grow the vector and eventually have to reallocate space
+        for it, invalidating all copies of pointers into the previous
+        contents.  */
+      *dwo_file_slot = dwo_file;
+    }
+  else
+    {
+      dwarf_read_debug_printf ("Using existing virtual DWO: %s",
+                              virtual_dwo_name.c_str ());
+
       dwo_file = (struct dwo_file *) *dwo_file_slot;
     }
 
-  dwo_unit = OBSTACK_ZALLOC (&dwarf2_per_objfile->per_bfd->obstack, struct dwo_unit);
+  dwo_unit = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwo_unit);
   dwo_unit->dwo_file = dwo_file;
   dwo_unit->signature = signature;
-  dwo_unit->section =
-    XOBNEW (&dwarf2_per_objfile->per_bfd->obstack, struct dwarf2_section_info);
-  *dwo_unit->section = create_dwp_v2_section (dwarf2_per_objfile,
-                                             is_debug_types
-                                             ? &dwp_file->sections.types
-                                             : &dwp_file->sections.info,
+  dwo_unit->section
+    = XOBNEW (&per_objfile->per_bfd->obstack, struct dwarf2_section_info);
+  *dwo_unit->section = create_dwp_v2_or_v5_section (per_objfile,
+                                             &dwp_file->sections.info,
                                              sections.info_or_types_offset,
                                              sections.info_or_types_size);
   /* dwo_unit->{offset,length,type_offset_in_tu} are set later.  */
@@ -12236,7 +12624,7 @@ create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile *dwarf2_per_objfile,
    Returns NULL if the signature isn't found.  */
 
 static struct dwo_unit *
-lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile *dwarf2_per_objfile,
+lookup_dwo_unit_in_dwp (dwarf2_per_objfile *per_objfile,
                        struct dwp_file *dwp_file, const char *comp_dir,
                        ULONGEST signature, int is_debug_types)
 {
@@ -12275,17 +12663,21 @@ lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
          if (dwp_file->version == 1)
            {
-             *slot = create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile,
-                                                dwp_file, unit_index,
-                                                comp_dir, signature,
-                                                is_debug_types);
+             *slot = create_dwo_unit_in_dwp_v1 (per_objfile, dwp_file,
+                                                unit_index, comp_dir,
+                                                signature, is_debug_types);
            }
-         else
+         else if (dwp_file->version == 2)
+           {
+             *slot = create_dwo_unit_in_dwp_v2 (per_objfile, dwp_file,
+                                                unit_index, comp_dir,
+                                                signature, is_debug_types);
+           }
+         else /* version == 5  */
            {
-             *slot = create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile,
-                                                dwp_file, unit_index,
-                                                comp_dir, signature,
-                                                is_debug_types);
+             *slot = create_dwo_unit_in_dwp_v5 (per_objfile, dwp_file,
+                                                unit_index, comp_dir,
+                                                signature, is_debug_types);
            }
          return (struct dwo_unit *) *slot;
        }
@@ -12312,7 +12704,7 @@ lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile *dwarf2_per_objfile,
    NOTE: This function is derived from symfile_bfd_open.  */
 
 static gdb_bfd_ref_ptr
-try_open_dwop_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
+try_open_dwop_file (dwarf2_per_objfile *per_objfile,
                    const char *file_name, int is_dwp, int search_cwd)
 {
   int desc;
@@ -12361,7 +12753,7 @@ try_open_dwop_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
      This is important because things like demangled_names_hash lives in the
      objfile's per_bfd space and may have references to things like symbol
      names that live in the DWO/DWP file's per_bfd space.  PR 16426.  */
-  gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, sym_bfd.get ());
+  gdb_bfd_record_inclusion (per_objfile->objfile->obfd, sym_bfd.get ());
 
   return sym_bfd;
 }
@@ -12374,11 +12766,11 @@ try_open_dwop_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
    same as symfile_bfd_open.  */
 
 static gdb_bfd_ref_ptr
-open_dwo_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
+open_dwo_file (dwarf2_per_objfile *per_objfile,
               const char *file_name, const char *comp_dir)
 {
   if (IS_ABSOLUTE_PATH (file_name))
-    return try_open_dwop_file (dwarf2_per_objfile, file_name,
+    return try_open_dwop_file (per_objfile, file_name,
                               0 /*is_dwp*/, 0 /*search_cwd*/);
 
   /* Before trying the search path, try DWO_NAME in COMP_DIR.  */
@@ -12390,8 +12782,7 @@ open_dwo_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
       /* 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.get (),
+      gdb_bfd_ref_ptr abfd (try_open_dwop_file (per_objfile, path_to_try.get (),
                                                0 /*is_dwp*/,
                                                1 /*search_cwd*/));
       if (abfd != NULL)
@@ -12404,7 +12795,7 @@ open_dwo_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (*debug_file_directory == '\0')
     return NULL;
 
-  return try_open_dwop_file (dwarf2_per_objfile, file_name,
+  return try_open_dwop_file (per_objfile, file_name,
                             0 /*is_dwp*/, 1 /*search_cwd*/);
 }
 
@@ -12412,9 +12803,9 @@ open_dwo_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
    size of each of the DWO debugging sections we are interested in.  */
 
 static void
-dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr)
+dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp,
+                           dwo_sections *dwo_sections)
 {
-  struct dwo_sections *dwo_sections = (struct dwo_sections *) dwo_sections_ptr;
   const struct dwop_section_names *names = &dwop_section_names;
 
   if (section_is_p (sectp->name, &names->abbrev_dwo))
@@ -12452,6 +12843,11 @@ dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr)
       dwo_sections->macro.s.section = sectp;
       dwo_sections->macro.size = bfd_section_size (sectp);
     }
+  else if (section_is_p (sectp->name, &names->rnglists_dwo))
+    {
+      dwo_sections->rnglists.s.section = sectp;
+      dwo_sections->rnglists.size = bfd_section_size (sectp);
+    }
   else if (section_is_p (sectp->name, &names->str_dwo))
     {
       dwo_sections->str.s.section = sectp;
@@ -12481,13 +12877,13 @@ static struct dwo_file *
 open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
                        const char *comp_dir)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
 
-  gdb_bfd_ref_ptr dbfd = open_dwo_file (dwarf2_per_objfile, dwo_name, comp_dir);
+  gdb_bfd_ref_ptr dbfd = open_dwo_file (per_objfile, dwo_name, comp_dir);
   if (dbfd == NULL)
     {
-      if (dwarf_read_debug)
-       fprintf_unfiltered (gdb_stdlog, "DWO file not found: %s\n", dwo_name);
+      dwarf_read_debug_printf ("DWO file not found: %s", dwo_name);
+
       return NULL;
     }
 
@@ -12496,17 +12892,26 @@ open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
   dwo_file->comp_dir = comp_dir;
   dwo_file->dbfd = std::move (dbfd);
 
-  bfd_map_over_sections (dwo_file->dbfd.get (), dwarf2_locate_dwo_sections,
-                        &dwo_file->sections);
+  for (asection *sec : gdb_bfd_sections (dwo_file->dbfd))
+    dwarf2_locate_dwo_sections (dwo_file->dbfd.get (), sec,
+                               &dwo_file->sections);
 
-  create_cus_hash_table (dwarf2_per_objfile, cu, *dwo_file,
-                        dwo_file->sections.info, dwo_file->cus);
+  create_cus_hash_table (per_objfile, cu, *dwo_file, dwo_file->sections.info,
+                        dwo_file->cus);
 
-  create_debug_types_hash_table (dwarf2_per_objfile, dwo_file.get (),
-                                dwo_file->sections.types, dwo_file->tus);
+  if (cu->per_cu->dwarf_version < 5)
+    {
+      create_debug_types_hash_table (per_objfile, dwo_file.get (),
+                                    dwo_file->sections.types, dwo_file->tus);
+    }
+  else
+    {
+      create_debug_type_hash_table (per_objfile, dwo_file.get (),
+                                   &dwo_file->sections.info, dwo_file->tus,
+                                   rcuh_kind::TYPE);
+    }
 
-  if (dwarf_read_debug)
-    fprintf_unfiltered (gdb_stdlog, "DWO file found: %s\n", dwo_name);
+  dwarf_read_debug_printf ("DWO file found: %s", dwo_name);
 
   return dwo_file.release ();
 }
@@ -12517,9 +12922,8 @@ open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
 
 static void
 dwarf2_locate_common_dwp_sections (bfd *abfd, asection *sectp,
-                                  void *dwp_file_ptr)
+                                  dwp_file *dwp_file)
 {
-  struct dwp_file *dwp_file = (struct dwp_file *) dwp_file_ptr;
   const struct dwop_section_names *names = &dwop_section_names;
   unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
 
@@ -12549,7 +12953,7 @@ dwarf2_locate_common_dwp_sections (bfd *abfd, asection *sectp,
 /* This function is mapped across the sections and remembers the offset and
    size of each of the DWP version 2 debugging sections that we are interested
    in.  This is split into a separate function because we don't know if we
-   have version 1 or 2 until we parse the cu_index/tu_index sections.  */
+   have version 1 or 2 or 5 until we parse the cu_index/tu_index sections.  */
 
 static void
 dwarf2_locate_v2_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_ptr)
@@ -12606,6 +13010,61 @@ dwarf2_locate_v2_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_ptr)
     }
 }
 
+/* This function is mapped across the sections and remembers the offset and
+   size of each of the DWP version 5 debugging sections that we are interested
+   in.  This is split into a separate function because we don't know if we
+   have version 1 or 2 or 5 until we parse the cu_index/tu_index sections.  */
+
+static void
+dwarf2_locate_v5_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_ptr)
+{
+  struct dwp_file *dwp_file = (struct dwp_file *) dwp_file_ptr;
+  const struct dwop_section_names *names = &dwop_section_names;
+  unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
+
+  /* Record the ELF section number for later lookup: this is what the
+     .debug_cu_index,.debug_tu_index tables use in DWP V1.  */
+  gdb_assert (elf_section_nr < dwp_file->num_sections);
+  dwp_file->elf_sections[elf_section_nr] = sectp;
+
+  /* Look for specific sections that we need.  */
+  if (section_is_p (sectp->name, &names->abbrev_dwo))
+    {
+      dwp_file->sections.abbrev.s.section = sectp;
+      dwp_file->sections.abbrev.size = bfd_section_size (sectp);
+    }
+  else if (section_is_p (sectp->name, &names->info_dwo))
+    {
+      dwp_file->sections.info.s.section = sectp;
+      dwp_file->sections.info.size = bfd_section_size (sectp);
+    }
+  else if (section_is_p (sectp->name, &names->line_dwo))
+   {
+     dwp_file->sections.line.s.section = sectp;
+     dwp_file->sections.line.size = bfd_section_size (sectp);
+    }
+  else if (section_is_p (sectp->name, &names->loclists_dwo))
+    {
+      dwp_file->sections.loclists.s.section = sectp;
+      dwp_file->sections.loclists.size = bfd_section_size (sectp);
+    }
+  else if (section_is_p (sectp->name, &names->macro_dwo))
+    {
+      dwp_file->sections.macro.s.section = sectp;
+      dwp_file->sections.macro.size = bfd_section_size (sectp);
+    }
+  else if (section_is_p (sectp->name, &names->rnglists_dwo))
+    {
+      dwp_file->sections.rnglists.s.section = sectp;
+      dwp_file->sections.rnglists.size = bfd_section_size (sectp);
+    }
+  else if (section_is_p (sectp->name, &names->str_offsets_dwo))
+    {
+      dwp_file->sections.str_offsets.s.section = sectp;
+      dwp_file->sections.str_offsets.size = bfd_section_size (sectp);
+    }
+}
+
 /* Hash function for dwp_file loaded CUs/TUs.  */
 
 static hashval_t
@@ -12646,10 +13105,9 @@ allocate_dwp_loaded_cutus_table ()
    same as symfile_bfd_open.  */
 
 static gdb_bfd_ref_ptr
-open_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
-              const char *file_name)
+open_dwp_file (dwarf2_per_objfile *per_objfile, const char *file_name)
 {
-  gdb_bfd_ref_ptr abfd (try_open_dwop_file (dwarf2_per_objfile, file_name,
+  gdb_bfd_ref_ptr abfd (try_open_dwop_file (per_objfile, file_name,
                                            1 /*is_dwp*/,
                                            1 /*search_cwd*/));
   if (abfd != NULL)
@@ -12668,8 +13126,8 @@ open_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
       /* Don't implicitly search the current directory here.
         If the user wants to search "." to handle this case,
         it must be added to debug-file-directory.  */
-      return try_open_dwop_file (dwarf2_per_objfile,
-                                lbasename (file_name), 1 /*is_dwp*/,
+      return try_open_dwop_file (per_objfile, lbasename (file_name),
+                                1 /*is_dwp*/,
                                 0 /*search_cwd*/);
     }
 
@@ -12681,9 +13139,9 @@ open_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile,
    The result is NULL if it can't be found.  */
 
 static std::unique_ptr<struct dwp_file>
-open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
+open_and_init_dwp_file (dwarf2_per_objfile *per_objfile)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
 
   /* Try to find first .dwp for the binary file before any symbolic links
      resolving.  */
@@ -12703,20 +13161,20 @@ open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   dwp_name += ".dwp";
 
-  gdb_bfd_ref_ptr dbfd (open_dwp_file (dwarf2_per_objfile, dwp_name.c_str ()));
+  gdb_bfd_ref_ptr dbfd (open_dwp_file (per_objfile, dwp_name.c_str ()));
   if (dbfd == NULL
       && strcmp (objfile->original_name, objfile_name (objfile)) != 0)
     {
       /* Try to find .dwp for the binary file after gdb_realpath resolving.  */
       dwp_name = objfile_name (objfile);
       dwp_name += ".dwp";
-      dbfd = open_dwp_file (dwarf2_per_objfile, dwp_name.c_str ());
+      dbfd = open_dwp_file (per_objfile, dwp_name.c_str ());
     }
 
   if (dbfd == NULL)
     {
-      if (dwarf_read_debug)
-       fprintf_unfiltered (gdb_stdlog, "DWP file not found: %s\n", dwp_name.c_str ());
+      dwarf_read_debug_printf ("DWP file not found: %s", dwp_name.c_str ());
+
       return std::unique_ptr<dwp_file> ();
     }
 
@@ -12726,18 +13184,16 @@ open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   dwp_file->num_sections = elf_numsections (dwp_file->dbfd);
   dwp_file->elf_sections =
-    OBSTACK_CALLOC (&dwarf2_per_objfile->per_bfd->obstack,
+    OBSTACK_CALLOC (&per_objfile->per_bfd->obstack,
                    dwp_file->num_sections, asection *);
 
-  bfd_map_over_sections (dwp_file->dbfd.get (),
-                        dwarf2_locate_common_dwp_sections,
-                        dwp_file.get ());
+  for (asection *sec : gdb_bfd_sections (dwp_file->dbfd))
+    dwarf2_locate_common_dwp_sections (dwp_file->dbfd.get (), sec,
+                                      dwp_file.get ());
 
-  dwp_file->cus = create_dwp_hash_table (dwarf2_per_objfile, dwp_file.get (),
-                                        0);
+  dwp_file->cus = create_dwp_hash_table (per_objfile, dwp_file.get (), 0);
 
-  dwp_file->tus = create_dwp_hash_table (dwarf2_per_objfile, dwp_file.get (),
-                                        1);
+  dwp_file->tus = create_dwp_hash_table (per_objfile, dwp_file.get (), 1);
 
   /* The DWP file version is stored in the hash table.  Oh well.  */
   if (dwp_file->cus && dwp_file->tus
@@ -12759,22 +13215,23 @@ open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
   else
     dwp_file->version = 2;
 
-  if (dwp_file->version == 2)
-    bfd_map_over_sections (dwp_file->dbfd.get (),
-                          dwarf2_locate_v2_dwp_sections,
-                          dwp_file.get ());
+  for (asection *sec : gdb_bfd_sections (dwp_file->dbfd))
+    {
+      if (dwp_file->version == 2)
+       dwarf2_locate_v2_dwp_sections (dwp_file->dbfd.get (), sec,
+                                      dwp_file.get ());
+      else
+       dwarf2_locate_v5_dwp_sections (dwp_file->dbfd.get (), sec,
+                                      dwp_file.get ());
+    }
 
   dwp_file->loaded_cus = allocate_dwp_loaded_cutus_table ();
   dwp_file->loaded_tus = allocate_dwp_loaded_cutus_table ();
 
-  if (dwarf_read_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog, "DWP file found: %s\n", dwp_file->name);
-      fprintf_unfiltered (gdb_stdlog,
-                         "    %s CUs, %s TUs\n",
-                         pulongest (dwp_file->cus ? dwp_file->cus->nr_units : 0),
-                         pulongest (dwp_file->tus ? dwp_file->tus->nr_units : 0));
-    }
+  dwarf_read_debug_printf ("DWP file found: %s", dwp_file->name);
+  dwarf_read_debug_printf ("    %s CUs, %s TUs",
+                          pulongest (dwp_file->cus ? dwp_file->cus->nr_units : 0),
+                          pulongest (dwp_file->tus ? dwp_file->tus->nr_units : 0));
 
   return dwp_file;
 }
@@ -12782,15 +13239,14 @@ open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
 /* Wrapper around open_and_init_dwp_file, only open it once.  */
 
 static struct dwp_file *
-get_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
+get_dwp_file (dwarf2_per_objfile *per_objfile)
 {
-  if (! dwarf2_per_objfile->per_bfd->dwp_checked)
+  if (!per_objfile->per_bfd->dwp_checked)
     {
-      dwarf2_per_objfile->per_bfd->dwp_file
-       = open_and_init_dwp_file (dwarf2_per_objfile);
-      dwarf2_per_objfile->per_bfd->dwp_checked = 1;
+      per_objfile->per_bfd->dwp_file = open_and_init_dwp_file (per_objfile);
+      per_objfile->per_bfd->dwp_checked = 1;
     }
-  return dwarf2_per_objfile->per_bfd->dwp_file.get ();
+  return per_objfile->per_bfd->dwp_file.get ();
 }
 
 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
@@ -12813,8 +13269,8 @@ static struct dwo_unit *
 lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
                 ULONGEST signature, int is_debug_types)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   const char *kind = is_debug_types ? "TU" : "CU";
   void **dwo_file_slot;
   struct dwo_file *dwo_file;
@@ -12825,7 +13281,7 @@ lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
      look for the original DWO file.  It makes gdb behave differently
      depending on whether one is debugging in the build tree.  */
 
-  dwp_file = get_dwp_file (dwarf2_per_objfile);
+  dwp_file = get_dwp_file (per_objfile);
   if (dwp_file != NULL)
     {
       const struct dwp_hash_table *dwp_htab =
@@ -12834,18 +13290,15 @@ lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
       if (dwp_htab != NULL)
        {
          struct dwo_unit *dwo_cutu =
-           lookup_dwo_unit_in_dwp (dwarf2_per_objfile, dwp_file, comp_dir,
-                                   signature, is_debug_types);
+           lookup_dwo_unit_in_dwp (per_objfile, dwp_file, comp_dir, signature,
+                                   is_debug_types);
 
          if (dwo_cutu != NULL)
            {
-             if (dwarf_read_debug)
-               {
-                 fprintf_unfiltered (gdb_stdlog,
-                                     "Virtual DWO %s %s found: @%s\n",
-                                     kind, hex_string (signature),
-                                     host_address_to_string (dwo_cutu));
-               }
+             dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
+                                      kind, hex_string (signature),
+                                      host_address_to_string (dwo_cutu));
+
              return dwo_cutu;
            }
        }
@@ -12854,8 +13307,7 @@ lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
     {
       /* No DWP file, look for the DWO file.  */
 
-      dwo_file_slot = lookup_dwo_file_slot (dwarf2_per_objfile,
-                                           dwo_name, comp_dir);
+      dwo_file_slot = lookup_dwo_file_slot (per_objfile, dwo_name, comp_dir);
       if (*dwo_file_slot == NULL)
        {
          /* Read in the file and build a table of the CUs/TUs it contains.  */
@@ -12890,12 +13342,10 @@ lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
 
          if (dwo_cutu != NULL)
            {
-             if (dwarf_read_debug)
-               {
-                 fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) found: @%s\n",
-                                     kind, dwo_name, hex_string (signature),
-                                     host_address_to_string (dwo_cutu));
-               }
+             dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
+                                      kind, dwo_name, hex_string (signature),
+                                      host_address_to_string (dwo_cutu));
+
              return dwo_cutu;
            }
        }
@@ -12905,11 +13355,8 @@ lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
      someone deleted the DWO/DWP file, or the search path isn't set up
      correctly to find the file.  */
 
-  if (dwarf_read_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) not found\n",
-                         kind, dwo_name, hex_string (signature));
-    }
+  dwarf_read_debug_printf ("DWO %s %s(%s) not found",
+                          kind, dwo_name, hex_string (signature));
 
   /* This is a warning and not a complaint because it can be caused by
      pilot error (e.g., user accidentally deleting the DWO).  */
@@ -13060,7 +13507,7 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
         present in the abstract instance but not referenced in the concrete
         one.  */
       if (child_die->tag == DW_TAG_call_site
-          || child_die->tag == DW_TAG_GNU_call_site)
+         || child_die->tag == DW_TAG_GNU_call_site)
        continue;
 
       /* For each CHILD_DIE, find the corresponding child of
@@ -13183,7 +13630,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       <= PC_BOUNDS_INVALID)
     {
       attr = dwarf2_attr (die, DW_AT_external, cu);
-      if (!attr || !DW_UNSND (attr))
+      if (attr == nullptr || !attr->as_boolean ())
        complaint (_("cannot get low and high bounds "
                     "for subprogram DIE at %s"),
                   sect_offset_str (die->sect_off));
@@ -13305,7 +13752,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 
       templ_func->n_template_arguments = template_args.size ();
       templ_func->template_arguments
-        = XOBNEWVEC (&objfile->objfile_obstack, struct symbol *,
+       = XOBNEWVEC (&objfile->objfile_obstack, struct symbol *,
                     templ_func->n_template_arguments);
       memcpy (templ_func->template_arguments,
              template_args.data (),
@@ -13394,19 +13841,19 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
       || (*cu->get_builder ()->get_local_using_directives ()) != NULL)
     {
       struct block *block
-        = cu->get_builder ()->finish_block (0, cstk.old_blocks, NULL,
+       = cu->get_builder ()->finish_block (0, cstk.old_blocks, NULL,
                                     cstk.start_addr, highpc);
 
       /* Note that recording ranges after traversing children, as we
-         do here, means that recording a parent's ranges entails
-         walking across all its children's ranges as they appear in
-         the address map, which is quadratic behavior.
-
-         It would be nicer to record the parent's ranges before
-         traversing its children, simply overriding whatever you find
-         there.  But since we don't even decide whether to create a
-         block until after we've traversed its children, that's hard
-         to do.  */
+        do here, means that recording a parent's ranges entails
+        walking across all its children's ranges as they appear in
+        the address map, which is quadratic behavior.
+
+        It would be nicer to record the parent's ranges before
+        traversing its children, simply overriding whatever you find
+        there.  But since we don't even decide whether to create a
+        block until after we've traversed its children, that's hard
+        to do.  */
       dwarf2_record_block_ranges (die, block, baseaddr, cu);
     }
   *cu->get_builder ()->get_local_symbols () = cstk.locals;
@@ -13444,7 +13891,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
                 sect_offset_str (die->sect_off), objfile_name (objfile));
       return;
     }
-  pc = attr->value_as_address () + baseaddr;
+  pc = attr->as_address () + baseaddr;
   pc = gdbarch_adjust_dwarf2_addr (gdbarch, pc);
 
   if (cu->call_site_htab == NULL)
@@ -13469,7 +13916,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
        child_die = child_die->sibling)
     {
       if (child_die->tag != DW_TAG_call_site_parameter
-          && child_die->tag != DW_TAG_GNU_call_site_parameter)
+         && child_die->tag != DW_TAG_GNU_call_site_parameter)
        {
          complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
                       "DW_TAG_call_site child DIE %s [in module %s]"),
@@ -13504,8 +13951,8 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
       /* DW_AT_call_all_calls is a superset
         of DW_AT_call_all_tail_calls.  */
       if (func_die
-          && !dwarf2_flag_true_p (func_die, DW_AT_call_all_calls, cu)
-          && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
+         && !dwarf2_flag_true_p (func_die, DW_AT_call_all_calls, cu)
+         && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
          && !dwarf2_flag_true_p (func_die, DW_AT_call_all_tail_calls, cu)
          && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
        {
@@ -13550,15 +13997,16 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
       attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
     }
   SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
-  if (!attr || (attr->form_is_block () && DW_BLOCK (attr)->size == 0))
+  if (!attr || (attr->form_is_block () && attr->as_block ()->size == 0))
     /* Keep NULL DWARF_BLOCK.  */;
   else if (attr->form_is_block ())
     {
       struct dwarf2_locexpr_baton *dlbaton;
+      struct dwarf_block *block = attr->as_block ();
 
       dlbaton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
-      dlbaton->data = DW_BLOCK (attr)->data;
-      dlbaton->size = DW_BLOCK (attr)->size;
+      dlbaton->data = block->data;
+      dlbaton->size = block->size;
       dlbaton->per_objfile = per_objfile;
       dlbaton->per_cu = cu->per_cu;
 
@@ -13581,7 +14029,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
            target_physname = dwarf2_physname (NULL, target_die, target_cu);
          if (target_physname == NULL)
            complaint (_("DW_AT_call_target target DIE has invalid "
-                        "physname, for referencing DIE %s [in module %s]"),
+                        "physname, for referencing DIE %s [in module %s]"),
                       sect_offset_str (die->sect_off), objfile_name (objfile));
          else
            SET_FIELD_PHYSNAME (call_site->target, target_physname);
@@ -13594,7 +14042,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
          if (dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)
              <= PC_BOUNDS_INVALID)
            complaint (_("DW_AT_call_target target DIE has invalid "
-                        "low pc, for referencing DIE %s [in module %s]"),
+                        "low pc, for referencing DIE %s [in module %s]"),
                       sect_offset_str (die->sect_off), objfile_name (objfile));
          else
            {
@@ -13619,7 +14067,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
       struct attribute *loc, *origin;
 
       if (child_die->tag != DW_TAG_call_site_parameter
-          && child_die->tag != DW_TAG_GNU_call_site_parameter)
+         && child_die->tag != DW_TAG_GNU_call_site_parameter)
        {
          /* Already printed the complaint above.  */
          continue;
@@ -13668,12 +14116,14 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
        }
       else
        {
+         struct dwarf_block *block = loc->as_block ();
+
          parameter->u.dwarf_reg = dwarf_block_to_dwarf_reg
-           (DW_BLOCK (loc)->data, &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size]);
+           (block->data, &block->data[block->size]);
          if (parameter->u.dwarf_reg != -1)
            parameter->kind = CALL_SITE_PARAMETER_DWARF_REG;
-         else if (dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (loc)->data,
-                                   &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size],
+         else if (dwarf_block_to_sp_offset (gdbarch, block->data,
+                                   &block->data[block->size],
                                             &parameter->u.fb_offset))
            parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET;
          else
@@ -13699,8 +14149,10 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
                     objfile_name (objfile));
          continue;
        }
-      parameter->value = DW_BLOCK (attr)->data;
-      parameter->value_size = DW_BLOCK (attr)->size;
+
+      struct dwarf_block *block = attr->as_block ();
+      parameter->value = block->data;
+      parameter->value_size = block->size;
 
       /* Parameters are not pre-cleared by memset above.  */
       parameter->data_value = NULL;
@@ -13719,8 +14171,9 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
                       objfile_name (objfile));
          else
            {
-             parameter->data_value = DW_BLOCK (attr)->data;
-             parameter->data_value_size = DW_BLOCK (attr)->size;
+             block = attr->as_block ();
+             parameter->data_value = block->data;
+             parameter->data_value_size = block->size;
            }
        }
     }
@@ -13801,27 +14254,30 @@ read_variable (struct die_info *die, struct dwarf2_cu *cu)
 template <typename Callback>
 static bool
 dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
-                        Callback &&callback)
+                        dwarf_tag tag, Callback &&callback)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   bfd *obfd = objfile->obfd;
   /* Base address selection entry.  */
   gdb::optional<CORE_ADDR> base;
   const gdb_byte *buffer;
   CORE_ADDR baseaddr;
   bool overflow = false;
+  ULONGEST addr_index;
+  struct dwarf2_section_info *rnglists_section;
 
   base = cu->base_address;
+  rnglists_section = cu_debug_rnglists_section (cu, tag);
+  rnglists_section->read (objfile);
 
-  dwarf2_per_objfile->per_bfd->rnglists.read (objfile);
-  if (offset >= dwarf2_per_objfile->per_bfd->rnglists.size)
+  if (offset >= rnglists_section->size)
     {
       complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
                 offset);
       return false;
     }
-  buffer = dwarf2_per_objfile->per_bfd->rnglists.buffer + offset;
+  buffer = rnglists_section->buffer + offset;
 
   baseaddr = objfile->text_section_offset ();
 
@@ -13829,8 +14285,8 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
     {
       /* Initialize it due to a false compiler warning.  */
       CORE_ADDR range_beginning = 0, range_end = 0;
-      const gdb_byte *buf_end = (dwarf2_per_objfile->per_bfd->rnglists.buffer
-                                + dwarf2_per_objfile->per_bfd->rnglists.size);
+      const gdb_byte *buf_end = (rnglists_section->buffer
+                                + rnglists_section->size);
       unsigned int bytes_read;
 
       if (buffer == buf_end)
@@ -13852,6 +14308,11 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
          base = cu->header.read_address (obfd, buffer, &bytes_read);
          buffer += bytes_read;
          break;
+       case DW_RLE_base_addressx:
+         addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
+         buffer += bytes_read;
+         base = read_addr_index (cu, addr_index);
+         break;
        case DW_RLE_start_length:
          if (buffer + cu->header.addr_size > buf_end)
            {
@@ -13870,6 +14331,19 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
              break;
            }
          break;
+       case DW_RLE_startx_length:
+         addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
+         buffer += bytes_read;
+         range_beginning = read_addr_index (cu, addr_index);
+         if (buffer > buf_end)
+           {
+             overflow = true;
+             break;
+           }
+         range_end = (range_beginning
+                      + read_unsigned_leb128 (obfd, buffer, &bytes_read));
+         buffer += bytes_read;
+         break;
        case DW_RLE_offset_pair:
          range_beginning = read_unsigned_leb128 (obfd, buffer, &bytes_read);
          buffer += bytes_read;
@@ -13898,6 +14372,19 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
          range_end = cu->header.read_address (obfd, buffer, &bytes_read);
          buffer += bytes_read;
          break;
+       case DW_RLE_startx_endx:
+         addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
+         buffer += bytes_read;
+         range_beginning = read_addr_index (cu, addr_index);
+         if (buffer > buf_end)
+           {
+             overflow = true;
+             break;
+           }
+         addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
+         buffer += bytes_read;
+         range_end = read_addr_index (cu, addr_index);
+         break;
        default:
          complaint (_("Invalid .debug_rnglists data (no base address)"));
          return false;
@@ -13907,14 +14394,6 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
       if (rlet == DW_RLE_base_address)
        continue;
 
-      if (!base.has_value ())
-       {
-         /* We have no valid base address for the ranges
-            data.  */
-         complaint (_("Invalid .debug_rnglists data (no base address)"));
-         return false;
-       }
-
       if (range_beginning > range_end)
        {
          /* Inverted range entries are invalid.  */
@@ -13926,13 +14405,25 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
       if (range_beginning == range_end)
        continue;
 
-      range_beginning += *base;
-      range_end += *base;
+      /* Only DW_RLE_offset_pair needs the base address added.  */
+      if (rlet == DW_RLE_offset_pair)
+       {
+         if (!base.has_value ())
+           {
+             /* We have no valid base address for the DW_RLE_offset_pair.  */
+             complaint (_("Invalid .debug_rnglists data (no base address for "
+                          "DW_RLE_offset_pair)"));
+             return false;
+           }
+
+         range_beginning += *base;
+         range_end += *base;
+       }
 
       /* A not-uncommon case of bad debug info.
         Don't pollute the addrmap with bad data.  */
       if (range_beginning + baseaddr == 0
-         && !dwarf2_per_objfile->per_bfd->has_section_at_zero)
+         && !per_objfile->per_bfd->has_section_at_zero)
        {
          complaint (_(".debug_rnglists entry has start address of zero"
                       " [in module %s]"), objfile_name (objfile));
@@ -13960,7 +14451,7 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
 
 template <typename Callback>
 static int
-dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
+dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag,
                       Callback &&callback)
 {
   dwarf2_per_objfile *per_objfile = cu->per_objfile;
@@ -13976,7 +14467,7 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
   CORE_ADDR baseaddr;
 
   if (cu_header->version >= 5)
-    return dwarf2_rnglists_process (offset, cu, callback);
+    return dwarf2_rnglists_process (offset, cu, tag, callback);
 
   base = cu->base_address;
 
@@ -14062,7 +14553,7 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
 static int
 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
                    CORE_ADDR *high_return, struct dwarf2_cu *cu,
-                   dwarf2_psymtab *ranges_pst)
+                   dwarf2_psymtab *ranges_pst, dwarf_tag tag)
 {
   struct objfile *objfile = cu->per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
@@ -14072,7 +14563,7 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
   CORE_ADDR high = 0;
   int retval;
 
-  retval = dwarf2_ranges_process (offset, cu,
+  retval = dwarf2_ranges_process (offset, cu, tag,
     [&] (CORE_ADDR range_beginning, CORE_ADDR range_end)
     {
       if (ranges_pst != NULL)
@@ -14132,7 +14623,7 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
                      CORE_ADDR *highpc, struct dwarf2_cu *cu,
                      dwarf2_psymtab *pst)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct attribute *attr;
   struct attribute *attr_high;
   CORE_ADDR low = 0;
@@ -14144,9 +14635,9 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
     {
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
       if (attr != nullptr)
-        {
-         low = attr->value_as_address ();
-         high = attr_high->value_as_address ();
+       {
+         low = attr->as_address ();
+         high = attr_high->as_address ();
          if (cu->header.version >= 4 && attr_high->form_is_constant ())
            high += low;
        }
@@ -14160,20 +14651,27 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
   else
     {
       attr = dwarf2_attr (die, DW_AT_ranges, cu);
-      if (attr != NULL)
+      if (attr != nullptr && attr->form_is_unsigned ())
        {
          /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
             We take advantage of the fact that DW_AT_ranges does not appear
-            in DW_TAG_compile_unit of DWO files.  */
-         int need_ranges_base = die->tag != DW_TAG_compile_unit;
-         unsigned int ranges_offset = (DW_UNSND (attr)
+            in DW_TAG_compile_unit of DWO files.
+
+            Attributes of the form DW_FORM_rnglistx have already had their
+            value changed by read_rnglist_index and already include
+            DW_AT_rnglists_base, so don't need to add the ranges base,
+            either.  */
+         int need_ranges_base = (die->tag != DW_TAG_compile_unit
+                                 && attr->form != DW_FORM_rnglistx);
+         unsigned int ranges_offset = (attr->as_unsigned ()
                                        + (need_ranges_base
                                           ? cu->ranges_base
                                           : 0));
 
          /* Value of the DW_AT_ranges attribute is the offset in the
             .debug_ranges section.  */
-         if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu, pst))
+         if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu, pst,
+                                  die->tag))
            return PC_BOUNDS_INVALID;
          /* Found discontinuous range of addresses.  */
          ret = PC_BOUNDS_RANGES;
@@ -14194,7 +14692,7 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
      labels are not in the output, so the relocs get a value of 0.
      If this is a discarded function, mark the pc bounds as invalid,
      so that GDB will ignore it.  */
-  if (low == 0 && !dwarf2_per_objfile->per_bfd->has_section_at_zero)
+  if (low == 0 && !per_objfile->per_bfd->has_section_at_zero)
     return PC_BOUNDS_INVALID;
 
   *lowpc = low;
@@ -14210,8 +14708,8 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
 
 static void
 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
-                                 CORE_ADDR *lowpc, CORE_ADDR *highpc,
-                                 struct dwarf2_cu *cu)
+                                CORE_ADDR *lowpc, CORE_ADDR *highpc,
+                                struct dwarf2_cu *cu)
 {
   CORE_ADDR low, high;
   struct die_info *child = die->child;
@@ -14234,8 +14732,8 @@ dwarf2_get_subprogram_pc_bounds (struct die_info *die,
   while (child && child->tag)
     {
       if (child->tag == DW_TAG_subprogram
-          || child->tag == DW_TAG_lexical_block)
-        dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
+         || child->tag == DW_TAG_lexical_block)
+       dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
       child = child->sibling;
     }
 }
@@ -14267,7 +14765,7 @@ get_scope_pc_bounds (struct die_info *die,
        {
          switch (child->tag) {
          case DW_TAG_subprogram:
-            dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
+           dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
            break;
          case DW_TAG_namespace:
          case DW_TAG_module:
@@ -14305,7 +14803,7 @@ get_scope_pc_bounds (struct die_info *die,
 
 static void
 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
-                            CORE_ADDR baseaddr, struct dwarf2_cu *cu)
+                           CORE_ADDR baseaddr, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
@@ -14317,9 +14815,9 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
     {
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
       if (attr != nullptr)
-        {
-          CORE_ADDR low = attr->value_as_address ();
-         CORE_ADDR high = attr_high->value_as_address ();
+       {
+         CORE_ADDR low = attr->as_address ();
+         CORE_ADDR high = attr_high->as_address ();
 
          if (cu->header.version >= 4 && attr_high->form_is_constant ())
            high += low;
@@ -14327,24 +14825,30 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
          low = gdbarch_adjust_dwarf2_addr (gdbarch, low + baseaddr);
          high = gdbarch_adjust_dwarf2_addr (gdbarch, high + baseaddr);
          cu->get_builder ()->record_block_range (block, low, high - 1);
-        }
+       }
     }
 
   attr = dwarf2_attr (die, DW_AT_ranges, cu);
-  if (attr != nullptr)
+  if (attr != nullptr && attr->form_is_unsigned ())
     {
       /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
         We take advantage of the fact that DW_AT_ranges does not appear
-        in DW_TAG_compile_unit of DWO files.  */
-      int need_ranges_base = die->tag != DW_TAG_compile_unit;
+        in DW_TAG_compile_unit of DWO files.
+
+        Attributes of the form DW_FORM_rnglistx have already had their
+        value changed by read_rnglist_index and already include
+        DW_AT_rnglists_base, so don't need to add the ranges base,
+        either.  */
+      int need_ranges_base = (die->tag != DW_TAG_compile_unit
+                             && attr->form != DW_FORM_rnglistx);
 
       /* The value of the DW_AT_ranges attribute is the offset of the
-         address range list in the .debug_ranges section.  */
-      unsigned long offset = (DW_UNSND (attr)
+        address range list in the .debug_ranges section.  */
+      unsigned long offset = (attr->as_unsigned ()
                              + (need_ranges_base ? cu->ranges_base : 0));
 
       std::vector<blockrange> blockvec;
-      dwarf2_ranges_process (offset, cu,
+      dwarf2_ranges_process (offset, cu, die->tag,
        [&] (CORE_ADDR start, CORE_ADDR end)
        {
          start += baseaddr;
@@ -14425,12 +14929,25 @@ producer_is_codewarrior (struct dwarf2_cu *cu)
   return cu->producer_is_codewarrior;
 }
 
-/* Return the default accessibility type if it is not overridden by
-   DW_AT_accessibility.  */
+/* Return the accessibility of DIE, as given by DW_AT_accessibility.
+   If that attribute is not available, return the appropriate
+   default.  */
 
 static enum dwarf_access_attribute
-dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
+dwarf2_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
 {
+  attribute *attr = dwarf2_attr (die, DW_AT_accessibility, cu);
+  if (attr != nullptr)
+    {
+      LONGEST value = attr->constant_value (-1);
+      if (value == DW_ACCESS_public
+         || value == DW_ACCESS_protected
+         || value == DW_ACCESS_private)
+       return (dwarf_access_attribute) value;
+      complaint (_("Unhandled DW_AT_accessibility value (%s)"),
+                plongest (value));
+    }
+
   if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
     {
       /* The default DWARF 2 accessibility for members is public, the default
@@ -14479,7 +14996,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
       else if (attr->form_is_section_offset ())
        dwarf2_complex_location_expr_complaint ();
       else if (attr->form_is_block ())
-       *offset = decode_locdesc (DW_BLOCK (attr), cu);
+       *offset = decode_locdesc (attr->as_block (), cu);
       else
        dwarf2_complex_location_expr_complaint ();
 
@@ -14510,7 +15027,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
       else if (attr->form_is_block ())
        {
          bool handled;
-         CORE_ADDR offset = decode_locdesc (DW_BLOCK (attr), cu, &handled);
+         CORE_ADDR offset = decode_locdesc (attr->as_block (), cu, &handled);
          if (handled)
            SET_FIELD_BITPOS (*field, offset * bits_per_byte);
          else
@@ -14520,8 +15037,8 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
              struct dwarf2_locexpr_baton *dlbaton
                = XOBNEW (&objfile->objfile_obstack,
                          struct dwarf2_locexpr_baton);
-             dlbaton->data = DW_BLOCK (attr)->data;
-             dlbaton->size = DW_BLOCK (attr)->size;
+             dlbaton->data = attr->as_block ()->data;
+             dlbaton->size = attr->as_block ()->size;
              /* When using this baton, we want to compute the address
                 of the field, not the value.  This is why
                 is_reference is set to false here.  */
@@ -14563,17 +15080,13 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
 
   new_field->offset = die->sect_off;
 
-  attr = dwarf2_attr (die, DW_AT_accessibility, cu);
-  if (attr != nullptr)
-    new_field->accessibility = DW_UNSND (attr);
-  else
-    new_field->accessibility = dwarf2_default_access_attribute (die, cu);
+  new_field->accessibility = dwarf2_access_attribute (die, cu);
   if (new_field->accessibility != DW_ACCESS_public)
-    fip->non_public_fields = 1;
+    fip->non_public_fields = true;
 
   attr = dwarf2_attr (die, DW_AT_virtuality, cu);
   if (attr != nullptr)
-    new_field->virtuality = DW_UNSND (attr);
+    new_field->virtuality = attr->as_virtuality ();
   else
     new_field->virtuality = DW_VIRTUALITY_none;
 
@@ -14584,7 +15097,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       /* Data member other than a C++ static data member.  */
 
       /* Get type of field.  */
-      fp->type = die_type (die, cu);
+      fp->set_type (die_type (die, cu));
 
       SET_FIELD_BITPOS (*fp, 0);
 
@@ -14592,7 +15105,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       attr = dwarf2_attr (die, DW_AT_bit_size, cu);
       if (attr != nullptr)
        {
-         FIELD_BITSIZE (*fp) = DW_UNSND (attr);
+         FIELD_BITSIZE (*fp) = attr->constant_value (0);
        }
       else
        {
@@ -14602,35 +15115,36 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       /* Get bit offset of field.  */
       handle_data_member_location (die, cu, fp);
       attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
-      if (attr != nullptr)
+      if (attr != nullptr && attr->form_is_constant ())
        {
          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
-                anonymous object to the MSB of the field.  We don't
-                have to do anything special since we don't need to
-                know the size of the anonymous object.  */
-             SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr));
+                additional bit offset from the MSB of the containing
+                anonymous object to the MSB of the field.  We don't
+                have to do anything special since we don't need to
+                know the size of the anonymous object.  */
+             SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp)
+                                     + attr->constant_value (0)));
            }
          else
            {
              /* For little endian bits, compute the bit offset to the
-                MSB of the anonymous object, subtract off the number of
-                bits from the MSB of the field to the MSB of the
-                object, and then subtract off the number of bits of
-                the field itself.  The result is the bit offset of
-                the LSB of the field.  */
+                MSB of the anonymous object, subtract off the number of
+                bits from the MSB of the field to the MSB of the
+                object, and then subtract off the number of bits of
+                the field itself.  The result is the bit offset of
+                the LSB of the field.  */
              int anonymous_size;
-             int bit_offset = DW_UNSND (attr);
+             int bit_offset = attr->constant_value (0);
 
              attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-             if (attr != nullptr)
+             if (attr != nullptr && attr->form_is_constant ())
                {
                  /* The size of the anonymous object containing
                     the bit field is explicit, so use the
                     indicated size (in bytes).  */
-                 anonymous_size = DW_UNSND (attr);
+                 anonymous_size = attr->constant_value (0);
                }
              else
                {
@@ -14638,7 +15152,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
                     the bit field must be inferred from the type
                     attribute of the data member containing the
                     bit field.  */
-                 anonymous_size = TYPE_LENGTH (fp->type);
+                 anonymous_size = TYPE_LENGTH (fp->type ());
                }
              SET_FIELD_BITPOS (*fp,
                                (FIELD_BITPOS (*fp)
@@ -14661,12 +15175,12 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       fp->name = fieldname;
 
       /* Change accessibility for artificial fields (e.g. virtual table
-         pointer or virtual base class pointer) to private.  */
+        pointer or virtual base class pointer) to private.  */
       if (dwarf2_attr (die, DW_AT_artificial, cu))
        {
          FIELD_ARTIFICIAL (*fp) = 1;
          new_field->accessibility = DW_ACCESS_private;
-         fip->non_public_fields = 1;
+         fip->non_public_fields = true;
        }
     }
   else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
@@ -14704,7 +15218,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       /* The name is already allocated along with this objfile, so we don't
         need to duplicate it for the type.  */
       SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
-      FIELD_TYPE (*fp) = die_type (die, cu);
+      fp->set_type (die_type (die, cu));
       FIELD_NAME (*fp) = fieldname;
     }
   else if (die->tag == DW_TAG_inheritance)
@@ -14712,8 +15226,8 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       /* C++ base class field.  */
       handle_data_member_location (die, cu, fp);
       FIELD_BITSIZE (*fp) = 0;
-      FIELD_TYPE (*fp) = die_type (die, cu);
-      FIELD_NAME (*fp) = fp->type->name ();
+      fp->set_type (die_type (die, cu));
+      FIELD_NAME (*fp) = fp->type ()->name ();
     }
   else
     gdb_assert_not_reached ("missing case in dwarf2_add_field");
@@ -14754,12 +15268,7 @@ dwarf2_add_type_defn (struct field_info *fip, struct die_info *die,
   fp.type = read_type_die (die, cu);
 
   /* Save accessibility.  */
-  enum dwarf_access_attribute accessibility;
-  struct attribute *attr = dwarf2_attr (die, DW_AT_accessibility, cu);
-  if (attr != NULL)
-    accessibility = (enum dwarf_access_attribute) DW_UNSND (attr);
-  else
-    accessibility = dwarf2_default_access_attribute (die, cu);
+  dwarf_access_attribute accessibility = dwarf2_access_attribute (die, cu);
   switch (accessibility)
     {
     case DW_ACCESS_public:
@@ -14771,8 +15280,6 @@ dwarf2_add_type_defn (struct field_info *fip, struct die_info *die,
     case DW_ACCESS_protected:
       fp.is_protected = 1;
       break;
-    default:
-      complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility);
     }
 
   if (die->tag == DW_TAG_typedef)
@@ -14912,8 +15419,7 @@ create_one_variant_part (variant_part &result,
     {
       result.discriminant_index = iter->second;
       result.is_unsigned
-       = TYPE_UNSIGNED (FIELD_TYPE
-                        (fi->fields[result.discriminant_index].field));
+       = fi->fields[result.discriminant_index].field.type ()->is_unsigned ();
     }
 
   size_t n = builder.variants.size ();
@@ -14969,10 +15475,9 @@ add_variant_property (struct field_info *fip, struct type *type,
                            fip->variant_parts);
 
   struct dynamic_prop prop;
-  prop.kind = PROP_VARIANT_PARTS;
-  prop.data.variant_parts
-    = ((gdb::array_view<variant_part> *)
-       obstack_copy (&objfile->objfile_obstack, &parts, sizeof (parts)));
+  prop.set_variant_parts ((gdb::array_view<variant_part> *)
+                         obstack_copy (&objfile->objfile_obstack, &parts,
+                                       sizeof (parts)));
 
   type->add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop);
 }
@@ -15099,25 +15604,6 @@ 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
@@ -15131,7 +15617,6 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   struct fn_field *fnp;
   const char *fieldname;
   struct type *this_type;
-  enum dwarf_access_attribute accessibility;
 
   if (cu->language == language_ada)
     error (_("unexpected member function in Ada type"));
@@ -15187,14 +15672,14 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
                            TYPE_TARGET_TYPE (this_type),
                            this_type->fields (),
                            this_type->num_fields (),
-                           TYPE_VARARGS (this_type));
+                           this_type->has_varargs ());
 
       /* Handle static member functions.
-         Dwarf2 has no clean way to discern C++ static and non-static
-         member functions.  G++ helps GDB by marking the first
-         parameter for non-static member functions (which is the this
-         pointer) as artificial.  We obtain this information from
-         read_subroutine_type via TYPE_FIELD_ARTIFICIAL.  */
+        Dwarf2 has no clean way to discern C++ static and non-static
+        member functions.  G++ helps GDB by marking the first
+        parameter for non-static member functions (which is the this
+        pointer) as artificial.  We obtain this information from
+        read_subroutine_type via TYPE_FIELD_ARTIFICIAL.  */
       if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
        fnp->voffset = VOFFSET_STATIC;
     }
@@ -15210,11 +15695,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
      is_volatile is irrelevant, as it is needed by gdb_mangle_name only.  */
 
   /* Get accessibility.  */
-  attr = dwarf2_attr (die, DW_AT_accessibility, cu);
-  if (attr != nullptr)
-    accessibility = (enum dwarf_access_attribute) DW_UNSND (attr);
-  else
-    accessibility = dwarf2_default_access_attribute (die, cu);
+  dwarf_access_attribute accessibility = dwarf2_access_attribute (die, cu);
   switch (accessibility)
     {
     case DW_ACCESS_private:
@@ -15227,17 +15708,17 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 
   /* Check for artificial methods.  */
   attr = dwarf2_attr (die, DW_AT_artificial, cu);
-  if (attr && DW_UNSND (attr) != 0)
+  if (attr && attr->as_boolean ())
     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);
+  if (attr != nullptr)
+    fnp->defaulted = attr->defaulted ();
 
   /* Check for deleted methods.  */
   attr = dwarf2_attr (die, DW_AT_deleted, cu);
-  if (attr != nullptr && DW_UNSND (attr) != 0)
+  if (attr != nullptr && attr->as_boolean ())
     fnp->is_deleted = 1;
 
   fnp->is_constructor = dwarf2_is_constructor (die, cu);
@@ -15251,19 +15732,21 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
   if (attr != nullptr)
     {
-      if (attr->form_is_block () && DW_BLOCK (attr)->size > 0)
-        {
-         if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
+      if (attr->form_is_block () && attr->as_block ()->size > 0)
+       {
+         struct dwarf_block *block = attr->as_block ();
+
+         if (block->data[0] == DW_OP_constu)
            {
              /* Old-style GCC.  */
-             fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
+             fnp->voffset = decode_locdesc (block, cu) + 2;
            }
-         else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
-                  || (DW_BLOCK (attr)->size > 1
-                      && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
-                      && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
+         else if (block->data[0] == DW_OP_deref
+                  || (block->size > 1
+                      && block->data[0] == DW_OP_deref_size
+                      && block->data[1] == cu->header.addr_size))
            {
-             fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
+             fnp->voffset = decode_locdesc (block, cu);
              if ((fnp->voffset % cu->header.addr_size) != 0)
                dwarf2_complex_location_expr_complaint ();
              else
@@ -15288,24 +15771,24 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
              else
                {
                  fnp->fcontext
-                   = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
+                   = TYPE_TARGET_TYPE (this_type->field (0).type ());
                }
            }
        }
       else if (attr->form_is_section_offset ())
-        {
+       {
          dwarf2_complex_location_expr_complaint ();
-        }
+       }
       else
-        {
+       {
          dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
                                                 fieldname);
-        }
+       }
     }
   else
     {
       attr = dwarf2_attr (die, DW_AT_virtuality, cu);
-      if (attr && DW_UNSND (attr))
+      if (attr != nullptr && attr->as_virtuality () != DW_VIRTUALITY_none)
        {
          /* GCC does this, as of 2008-08-25; PR debug/37237.  */
          complaint (_("Member function \"%s\" (offset %s) is virtual "
@@ -15386,7 +15869,7 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
     return;
 
   /* Find the type of the method.  */
-  pfn_type = TYPE_FIELD_TYPE (type, 0);
+  pfn_type = type->field (0).type ();
   if (pfn_type == NULL
       || pfn_type->code () != TYPE_CODE_PTR
       || TYPE_TARGET_TYPE (pfn_type)->code () != TYPE_CODE_FUNC)
@@ -15395,18 +15878,105 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
   /* Look for the "this" argument.  */
   pfn_type = TYPE_TARGET_TYPE (pfn_type);
   if (pfn_type->num_fields () == 0
-      /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
-      || TYPE_FIELD_TYPE (pfn_type, 0)->code () != TYPE_CODE_PTR)
+      /* || pfn_type->field (0).type () == NULL */
+      || pfn_type->field (0).type ()->code () != TYPE_CODE_PTR)
     return;
 
-  self_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
+  self_type = TYPE_TARGET_TYPE (pfn_type->field (0).type ());
   new_type = alloc_type (objfile);
   smash_to_method_type (new_type, self_type, TYPE_TARGET_TYPE (pfn_type),
                        pfn_type->fields (), pfn_type->num_fields (),
-                       TYPE_VARARGS (pfn_type));
+                       pfn_type->has_varargs ());
   smash_to_methodptr_type (type, new_type);
 }
 
+/* Helper for quirk_ada_thick_pointer.  If TYPE is an array type that
+   requires rewriting, then copy it and return the updated copy.
+   Otherwise return nullptr.  */
+
+static struct type *
+rewrite_array_type (struct type *type)
+{
+  if (type->code () != TYPE_CODE_ARRAY)
+    return nullptr;
+
+  struct type *index_type = type->index_type ();
+  range_bounds *current_bounds = index_type->bounds ();
+
+  /* Handle multi-dimensional arrays.  */
+  struct type *new_target = rewrite_array_type (TYPE_TARGET_TYPE (type));
+  if (new_target == nullptr)
+    {
+      /* Maybe we don't need to rewrite this array.  */
+      if (current_bounds->low.kind () == PROP_CONST
+         && current_bounds->high.kind () == PROP_CONST)
+       return nullptr;
+    }
+
+  /* Either the target type was rewritten, or the bounds have to be
+     updated.  Either way we want to copy the type and update
+     everything.  */
+  struct type *copy = copy_type (type);
+  int nfields = copy->num_fields ();
+  field *new_fields
+    = ((struct field *) TYPE_ZALLOC (copy,
+                                    nfields * sizeof (struct field)));
+  memcpy (new_fields, copy->fields (), nfields * sizeof (struct field));
+  copy->set_fields (new_fields);
+  if (new_target != nullptr)
+    TYPE_TARGET_TYPE (copy) = new_target;
+
+  struct type *index_copy = copy_type (index_type);
+  range_bounds *bounds
+    = (struct range_bounds *) TYPE_ZALLOC (index_copy,
+                                          sizeof (range_bounds));
+  *bounds = *current_bounds;
+  bounds->low.set_const_val (1);
+  bounds->high.set_const_val (0);
+  index_copy->set_bounds (bounds);
+  copy->set_index_type (index_copy);
+
+  return copy;
+}
+
+/* While some versions of GCC will generate complicated DWARF for an
+   array (see quirk_ada_thick_pointer), more recent versions were
+   modified to emit an explicit thick pointer structure.  However, in
+   this case, the array still has DWARF expressions for its ranges,
+   and these must be ignored.  */
+
+static void
+quirk_ada_thick_pointer_struct (struct die_info *die, struct dwarf2_cu *cu,
+                               struct type *type)
+{
+  gdb_assert (cu->language == language_ada);
+
+  /* Check for a structure with two children.  */
+  if (type->code () != TYPE_CODE_STRUCT || type->num_fields () != 2)
+    return;
+
+  /* Check for P_ARRAY and P_BOUNDS members.  */
+  if (TYPE_FIELD_NAME (type, 0) == NULL
+      || strcmp (TYPE_FIELD_NAME (type, 0), "P_ARRAY") != 0
+      || TYPE_FIELD_NAME (type, 1) == NULL
+      || strcmp (TYPE_FIELD_NAME (type, 1), "P_BOUNDS") != 0)
+    return;
+
+  /* Make sure we're looking at a pointer to an array.  */
+  if (type->field (0).type ()->code () != TYPE_CODE_PTR)
+    return;
+
+  /* The Ada code already knows how to handle these types, so all that
+     we need to do is turn the bounds into static bounds.  However, we
+     don't want to rewrite existing array or index types in-place,
+     because those may be referenced in other contexts where this
+     rewriting is undesirable.  */
+  struct type *new_ary_type
+    = rewrite_array_type (TYPE_TARGET_TYPE (type->field (0).type ()));
+  if (new_ary_type != nullptr)
+    type->field (0).set_type (lookup_pointer_type (new_ary_type));
+}
+
 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
    appropriate error checking and issuing complaints if there is a
    problem.  */
@@ -15428,22 +15998,16 @@ get_alignment (struct dwarf2_cu *cu, struct die_info *die)
       return 0;
     }
 
-  ULONGEST align;
-  if (attr->form == DW_FORM_sdata)
+  LONGEST val = attr->constant_value (0);
+  if (val < 0)
     {
-      LONGEST val = DW_SND (attr);
-      if (val < 0)
-       {
-         complaint (_("DW_AT_alignment value must not be negative"
-                      " - DIE at %s [in module %s]"),
-                    sect_offset_str (die->sect_off),
-                    objfile_name (cu->per_objfile->objfile));
-         return 0;
-       }
-      align = val;
+      complaint (_("DW_AT_alignment value must not be negative"
+                  " - DIE at %s [in module %s]"),
+                sect_offset_str (die->sect_off),
+                objfile_name (cu->per_objfile->objfile));
+      return 0;
     }
-  else
-    align = DW_UNSND (attr);
+  ULONGEST align = val;
 
   if (align == 0)
     {
@@ -15606,24 +16170,24 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
      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)))
+      && is_valid_DW_AT_calling_convention_for_type (attr->constant_value (0)))
     {
       ALLOCATE_CPLUS_STRUCT_TYPE (type);
       TYPE_CPLUS_CALLING_CONVENTION (type)
-       = (enum dwarf_calling_convention) (DW_UNSND (attr));
+       = (enum dwarf_calling_convention) (attr->constant_value (0));
     }
 
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr != nullptr)
     {
       if (attr->form_is_constant ())
-        TYPE_LENGTH (type) = DW_UNSND (attr);
+       TYPE_LENGTH (type) = attr->constant_value (0);
       else
        {
          struct dynamic_prop prop;
          if (attr_to_dynamic_prop (attr, die, cu, &prop, cu->addr_type ()))
            type->add_dyn_prop (DYN_PROP_BYTE_SIZE, prop);
-          TYPE_LENGTH (type) = 0;
+         TYPE_LENGTH (type) = 0;
        }
     }
   else
@@ -15637,18 +16201,18 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       /* ICC<14 does not output the required DW_AT_declaration on
         incomplete types, but gives them a size of zero.  */
-      TYPE_STUB (type) = 1;
+      type->set_is_stub (true);
     }
   else
-    TYPE_STUB_SUPPORTED (type) = 1;
+    type->set_stub_is_supported (true);
 
   if (die_is_declaration (die, cu))
-    TYPE_STUB (type) = 1;
+    type->set_is_stub (true);
   else if (attr == NULL && die->child == NULL
           && producer_is_realview (cu->producer))
     /* RealView does not output the required DW_AT_declaration
        on incomplete types.  */
-    TYPE_STUB (type) = 1;
+    type->set_is_stub (true);
 
   /* We need to add the type field to the die immediately so we don't
      infinitely recurse when dealing with pointers to the structure
@@ -15766,16 +16330,16 @@ handle_variant (struct die_info *die, struct type *type,
   /* In a variant we want to get the discriminant and also add a
      field for our sole member child.  */
   struct attribute *discr = dwarf2_attr (die, DW_AT_discr_value, cu);
-  if (discr == nullptr)
+  if (discr == nullptr || !discr->form_is_constant ())
     {
       discr = dwarf2_attr (die, DW_AT_discr_list, cu);
-      if (discr == nullptr || DW_BLOCK (discr)->size == 0)
+      if (discr == nullptr || discr->as_block ()->size == 0)
        variant.default_branch = true;
       else
-       variant.discr_list_data = DW_BLOCK (discr);
+       variant.discr_list_data = discr->as_block ();
     }
   else
-    variant.discriminant_value = DW_UNSND (discr);
+    variant.discriminant_value = discr->constant_value (0);
 
   for (die_info *variant_child = die->child;
        variant_child != NULL;
@@ -15910,7 +16474,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
                    {
                      const char *fieldname = TYPE_FIELD_NAME (t, i);
 
-                      if (is_vtable_name (fieldname, cu))
+                     if (is_vtable_name (fieldname, cu))
                        {
                          set_type_vptr_fieldno (type, i);
                          break;
@@ -15932,8 +16496,8 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
                   && startswith (cu->producer, "IBM(R) XL C/C++ Advanced Edition"))
            {
              /* The IBM XLC compiler does not provide direct indication
-                of the containing type, but the vtable pointer is
-                always named __vfp.  */
+                of the containing type, but the vtable pointer is
+                always named __vfp.  */
 
              int i;
 
@@ -15988,6 +16552,8 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
   quirk_gcc_member_function_pointer (type, objfile);
   if (cu->language == language_rust && die->tag == DW_TAG_union_type)
     cu->rust_unions.push_back (type);
+  else if (cu->language == language_ada)
+    quirk_ada_thick_pointer_struct (die, cu, type);
 
   /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
      snapshots) has been known to create a die giving a declaration
@@ -16124,7 +16690,8 @@ update_enumeration_type_from_children (struct die_info *die,
     }
 
   if (unsigned_enum)
-    TYPE_UNSIGNED (type) = 1;
+    type->set_is_unsigned (true);
+
   if (flag_enum)
     TYPE_FLAG_ENUM (type) = 1;
 }
@@ -16171,7 +16738,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr != nullptr)
     {
-      TYPE_LENGTH (type) = DW_UNSND (attr);
+      TYPE_LENGTH (type) = attr->constant_value (0);
     }
   else
     {
@@ -16186,7 +16753,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
      Types.  When another package uses such a type, an incomplete DIE
      may be generated by the compiler.  */
   if (die_is_declaration (die, cu))
-    TYPE_STUB (type) = 1;
+    type->set_is_stub (true);
 
   /* If this type has an underlying type that is not a stub, then we
      may use its attributes.  We always use the "unsigned" attribute
@@ -16195,13 +16762,16 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
      can tell us the reality.  However, we defer to a local size
      attribute if one exists, because this lets the compiler override
      the underlying type if needed.  */
-  if (TYPE_TARGET_TYPE (type) != NULL && !TYPE_STUB (TYPE_TARGET_TYPE (type)))
+  if (TYPE_TARGET_TYPE (type) != NULL && !TYPE_TARGET_TYPE (type)->is_stub ())
     {
       struct type *underlying_type = TYPE_TARGET_TYPE (type);
       underlying_type = check_typedef (underlying_type);
-      TYPE_UNSIGNED (type) = TYPE_UNSIGNED (underlying_type);
+
+      type->set_is_unsigned (underlying_type->is_unsigned ());
+
       if (TYPE_LENGTH (type) == 0)
        TYPE_LENGTH (type) = TYPE_LENGTH (underlying_type);
+
       if (TYPE_RAW_ALIGN (type) == 0
          && TYPE_RAW_ALIGN (underlying_type) != 0)
        set_type_align (type, TYPE_RAW_ALIGN (underlying_type));
@@ -16280,6 +16850,263 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
   new_symbol (die, this_type, cu);
 }
 
+/* Helper function for quirk_ada_thick_pointer that examines a bounds
+   expression for an index type and finds the corresponding field
+   offset in the hidden "P_BOUNDS" structure.  Returns true on success
+   and updates *FIELD, false if it fails to recognize an
+   expression.  */
+
+static bool
+recognize_bound_expression (struct die_info *die, enum dwarf_attribute name,
+                           int *bounds_offset, struct field *field,
+                           struct dwarf2_cu *cu)
+{
+  struct attribute *attr = dwarf2_attr (die, name, cu);
+  if (attr == nullptr || !attr->form_is_block ())
+    return false;
+
+  const struct dwarf_block *block = attr->as_block ();
+  const gdb_byte *start = block->data;
+  const gdb_byte *end = block->data + block->size;
+
+  /* The expression to recognize generally looks like:
+
+     (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
+     DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
+
+     However, the second "plus_uconst" may be missing:
+
+     (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
+     DW_OP_deref_size: 4)
+
+     This happens when the field is at the start of the structure.
+
+     Also, the final deref may not be sized:
+
+     (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
+     DW_OP_deref)
+
+     This happens when the size of the index type happens to be the
+     same as the architecture's word size.  This can occur with or
+     without the second plus_uconst.  */
+
+  if (end - start < 2)
+    return false;
+  if (*start++ != DW_OP_push_object_address)
+    return false;
+  if (*start++ != DW_OP_plus_uconst)
+    return false;
+
+  uint64_t this_bound_off;
+  start = gdb_read_uleb128 (start, end, &this_bound_off);
+  if (start == nullptr || (int) this_bound_off != this_bound_off)
+    return false;
+  /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
+     is consistent among all bounds.  */
+  if (*bounds_offset == -1)
+    *bounds_offset = this_bound_off;
+  else if (*bounds_offset != this_bound_off)
+    return false;
+
+  if (start == end || *start++ != DW_OP_deref)
+    return false;
+
+  int offset = 0;
+  if (start ==end)
+    return false;
+  else if (*start == DW_OP_deref_size || *start == DW_OP_deref)
+    {
+      /* This means an offset of 0.  */
+    }
+  else if (*start++ != DW_OP_plus_uconst)
+    return false;
+  else
+    {
+      /* The size is the parameter to DW_OP_plus_uconst.  */
+      uint64_t val;
+      start = gdb_read_uleb128 (start, end, &val);
+      if (start == nullptr)
+       return false;
+      if ((int) val != val)
+       return false;
+      offset = val;
+    }
+
+  if (start == end)
+    return false;
+
+  uint64_t size;
+  if (*start == DW_OP_deref_size)
+    {
+      start = gdb_read_uleb128 (start + 1, end, &size);
+      if (start == nullptr)
+       return false;
+    }
+  else if (*start == DW_OP_deref)
+    {
+      size = cu->header.addr_size;
+      ++start;
+    }
+  else
+    return false;
+
+  SET_FIELD_BITPOS (*field, 8 * offset);
+  if (size != TYPE_LENGTH (field->type ()))
+    FIELD_BITSIZE (*field) = 8 * size;
+
+  return true;
+}
+
+/* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
+   some kinds of Ada arrays:
+
+   <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
+      <11dc>   DW_AT_name        : (indirect string, offset: 0x1bb8): string
+      <11e0>   DW_AT_data_location: 2 byte block: 97 6
+         (DW_OP_push_object_address; DW_OP_deref)
+      <11e3>   DW_AT_type        : <0x1173>
+      <11e7>   DW_AT_sibling     : <0x1201>
+   <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
+      <11ec>   DW_AT_type        : <0x1206>
+      <11f0>   DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
+         (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
+          DW_OP_deref_size: 4)
+      <11f7>   DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
+         (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
+          DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
+
+   This actually represents a "thick pointer", which is a structure
+   with two elements: one that is a pointer to the array data, and one
+   that is a pointer to another structure; this second structure holds
+   the array bounds.
+
+   This returns a new type on success, or nullptr if this didn't
+   recognize the type.  */
+
+static struct type *
+quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
+                        struct type *type)
+{
+  struct attribute *attr = dwarf2_attr (die, DW_AT_data_location, cu);
+  /* So far we've only seen this with block form.  */
+  if (attr == nullptr || !attr->form_is_block ())
+    return nullptr;
+
+  /* Note that this will fail if the structure layout is changed by
+     the compiler.  However, we have no good way to recognize some
+     other layout, because we don't know what expression the compiler
+     might choose to emit should this happen.  */
+  struct dwarf_block *blk = attr->as_block ();
+  if (blk->size != 2
+      || blk->data[0] != DW_OP_push_object_address
+      || blk->data[1] != DW_OP_deref)
+    return nullptr;
+
+  int bounds_offset = -1;
+  int max_align = -1;
+  std::vector<struct field> range_fields;
+  for (struct die_info *child_die = die->child;
+       child_die;
+       child_die = child_die->sibling)
+    {
+      if (child_die->tag == DW_TAG_subrange_type)
+       {
+         struct type *underlying = read_subrange_index_type (child_die, cu);
+
+         int this_align = type_align (underlying);
+         if (this_align > max_align)
+           max_align = this_align;
+
+         range_fields.emplace_back ();
+         range_fields.emplace_back ();
+
+         struct field &lower = range_fields[range_fields.size () - 2];
+         struct field &upper = range_fields[range_fields.size () - 1];
+
+         lower.set_type (underlying);
+         FIELD_ARTIFICIAL (lower) = 1;
+
+         upper.set_type (underlying);
+         FIELD_ARTIFICIAL (upper) = 1;
+
+         if (!recognize_bound_expression (child_die, DW_AT_lower_bound,
+                                          &bounds_offset, &lower, cu)
+             || !recognize_bound_expression (child_die, DW_AT_upper_bound,
+                                             &bounds_offset, &upper, cu))
+           return nullptr;
+       }
+    }
+
+  /* This shouldn't really happen, but double-check that we found
+     where the bounds are stored.  */
+  if (bounds_offset == -1)
+    return nullptr;
+
+  struct objfile *objfile = cu->per_objfile->objfile;
+  for (int i = 0; i < range_fields.size (); i += 2)
+    {
+      char name[20];
+
+      /* Set the name of each field in the bounds.  */
+      xsnprintf (name, sizeof (name), "LB%d", i / 2);
+      FIELD_NAME (range_fields[i]) = objfile->intern (name);
+      xsnprintf (name, sizeof (name), "UB%d", i / 2);
+      FIELD_NAME (range_fields[i + 1]) = objfile->intern (name);
+    }
+
+  struct type *bounds = alloc_type (objfile);
+  bounds->set_code (TYPE_CODE_STRUCT);
+
+  bounds->set_num_fields (range_fields.size ());
+  bounds->set_fields
+    ((struct field *) TYPE_ALLOC (bounds, (bounds->num_fields ()
+                                          * sizeof (struct field))));
+  memcpy (bounds->fields (), range_fields.data (),
+         bounds->num_fields () * sizeof (struct field));
+
+  int last_fieldno = range_fields.size () - 1;
+  int bounds_size = (TYPE_FIELD_BITPOS (bounds, last_fieldno) / 8
+                    + TYPE_LENGTH (bounds->field (last_fieldno).type ()));
+  TYPE_LENGTH (bounds) = align_up (bounds_size, max_align);
+
+  /* Rewrite the existing array type in place.  Specifically, we
+     remove any dynamic properties we might have read, and we replace
+     the index types.  */
+  struct type *iter = type;
+  for (int i = 0; i < range_fields.size (); i += 2)
+    {
+      gdb_assert (iter->code () == TYPE_CODE_ARRAY);
+      iter->main_type->dyn_prop_list = nullptr;
+      iter->set_index_type
+       (create_static_range_type (NULL, bounds->field (i).type (), 1, 0));
+      iter = TYPE_TARGET_TYPE (iter);
+    }
+
+  struct type *result = alloc_type (objfile);
+  result->set_code (TYPE_CODE_STRUCT);
+
+  result->set_num_fields (2);
+  result->set_fields
+    ((struct field *) TYPE_ZALLOC (result, (result->num_fields ()
+                                           * sizeof (struct field))));
+
+  /* The names are chosen to coincide with what the compiler does with
+     -fgnat-encodings=all, which the Ada code in gdb already
+     understands.  */
+  TYPE_FIELD_NAME (result, 0) = "P_ARRAY";
+  result->field (0).set_type (lookup_pointer_type (type));
+
+  TYPE_FIELD_NAME (result, 1) = "P_BOUNDS";
+  result->field (1).set_type (lookup_pointer_type (bounds));
+  SET_FIELD_BITPOS (result->field (1), 8 * bounds_offset);
+
+  result->set_name (type->name ());
+  TYPE_LENGTH (result) = (TYPE_LENGTH (result->field (0).type ())
+                         + TYPE_LENGTH (result->field (1).type ()));
+
+  return result;
+}
+
 /* Extract all information from a DW_TAG_array_type DIE and put it in
    the DIE's type field.  For now, this only handles one dimensional
    arrays.  */
@@ -16328,7 +17155,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
 
   attr = dwarf2_attr (die, DW_AT_bit_stride, cu);
   if (attr != NULL)
-    bit_stride = DW_UNSND (attr);
+    bit_stride = attr->constant_value (0);
 
   /* Irix 6.2 native cc creates array types without children for
      arrays with unspecified length.  */
@@ -16349,12 +17176,12 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
        {
          struct type *child_type = read_type_die (child_die, cu);
 
-          if (child_type != NULL)
-            {
+         if (child_type != NULL)
+           {
              /* The range type was succesfully read.  Save it for the
-                 array type creation.  */
+                array type creation.  */
              range_types.push_back (child_type);
-            }
+           }
        }
       child_die = child_die->sibling;
     }
@@ -16369,15 +17196,23 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
       int i = 0;
 
       while (i < range_types.size ())
-       type = create_array_type_with_stride (NULL, type, range_types[i++],
-                                             byte_stride_prop, bit_stride);
+       {
+         type = create_array_type_with_stride (NULL, type, range_types[i++],
+                                               byte_stride_prop, bit_stride);
+         bit_stride = 0;
+         byte_stride_prop = nullptr;
+       }
     }
   else
     {
       size_t ndim = range_types.size ();
       while (ndim-- > 0)
-       type = create_array_type_with_stride (NULL, type, range_types[ndim],
-                                             byte_stride_prop, bit_stride);
+       {
+         type = create_array_type_with_stride (NULL, type, range_types[ndim],
+                                               byte_stride_prop, bit_stride);
+         bit_stride = 0;
+         byte_stride_prop = nullptr;
+       }
     }
 
   /* Understand Dwarf2 support for vector types (like they occur on
@@ -16394,10 +17229,10 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
      implementation may choose to implement triple vectors using this
      attribute.  */
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-  if (attr != nullptr)
+  if (attr != nullptr && attr->form_is_unsigned ())
     {
-      if (DW_UNSND (attr) >= TYPE_LENGTH (type))
-       TYPE_LENGTH (type) = DW_UNSND (attr);
+      if (attr->as_unsigned () >= TYPE_LENGTH (type))
+       TYPE_LENGTH (type) = attr->as_unsigned ();
       else
        complaint (_("DW_AT_byte_size for array type smaller "
                     "than the total size of elements"));
@@ -16409,8 +17244,16 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
 
   maybe_set_alignment (cu, die, type);
 
+  struct type *replacement_type = nullptr;
+  if (cu->language == language_ada)
+    {
+      replacement_type = quirk_ada_thick_pointer (die, cu, type);
+      if (replacement_type != nullptr)
+       type = replacement_type;
+    }
+
   /* Install the type in the die.  */
-  set_die_type (die, type, cu);
+  set_die_type (die, type, cu, replacement_type != nullptr);
 
   /* set_die_type should be already done.  */
   set_descriptive_type (type, die, cu);
@@ -16426,7 +17269,11 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_ordering, cu);
 
   if (attr != nullptr)
-    return (enum dwarf_array_dim_ordering) DW_SND (attr);
+    {
+      LONGEST val = attr->constant_value (-1);
+      if (val == DW_ORD_row_major || val == DW_ORD_col_major)
+       return (enum dwarf_array_dim_ordering) val;
+    }
 
   /* GNU F77 is a special case, as at 08/2004 array type info is the
      opposite order to the dwarf2 specification, but data is still
@@ -16441,7 +17288,7 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
       return DW_ORD_row_major;
     }
 
-  switch (cu->language_defn->la_array_ordering)
+  switch (cu->language_defn->array_ordering ())
     {
     case array_column_major:
       return DW_ORD_col_major;
@@ -16470,8 +17317,8 @@ 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 != nullptr)
-    TYPE_LENGTH (set_type) = DW_UNSND (attr);
+  if (attr != nullptr && attr->form_is_unsigned ())
+    TYPE_LENGTH (set_type) = attr->as_unsigned ();
 
   maybe_set_alignment (cu, die, set_type);
 
@@ -16520,7 +17367,7 @@ mark_common_block_symbol_computed (struct symbol *sym,
       baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
     }
   else
-    baton->size += DW_BLOCK (member_loc)->size;
+    baton->size += member_loc->as_block ()->size;
 
   ptr = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, baton->size);
   baton->data = ptr;
@@ -16540,8 +17387,9 @@ mark_common_block_symbol_computed (struct symbol *sym,
     {
       /* We have to copy the data here, because DW_OP_call4 will only
         use a DW_AT_location attribute.  */
-      memcpy (ptr, DW_BLOCK (member_loc)->data, DW_BLOCK (member_loc)->size);
-      ptr += DW_BLOCK (member_loc)->size;
+      struct dwarf_block *block = member_loc->as_block ();
+      memcpy (ptr, block->data, block->size);
+      ptr += block->size;
     }
 
   *ptr++ = DW_OP_plus;
@@ -16567,20 +17415,20 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
     {
       /* Support the .debug_loc offsets.  */
       if (attr->form_is_block ())
-        {
+       {
          /* Ok.  */
-        }
+       }
       else if (attr->form_is_section_offset ())
-        {
+       {
          dwarf2_complex_location_expr_complaint ();
          attr = NULL;
-        }
+       }
       else
-        {
+       {
          dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
                                                 "common block member");
          attr = NULL;
-        }
+       }
     }
 
   if (die->child != NULL)
@@ -16826,13 +17674,13 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
 
   attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr_byte_size)
-    byte_size = DW_UNSND (attr_byte_size);
+    byte_size = attr_byte_size->constant_value (cu_header->addr_size);
   else
     byte_size = cu_header->addr_size;
 
   attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
   if (attr_address_class)
-    addr_class = DW_UNSND (attr_address_class);
+    addr_class = attr_address_class->constant_value (DW_ADDR_none);
   else
     addr_class = DW_ADDR_none;
 
@@ -16848,10 +17696,9 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       if (gdbarch_address_class_type_flags_p (gdbarch))
        {
-         int type_flags;
-
-         type_flags = gdbarch_address_class_type_flags
-                        (gdbarch, byte_size, addr_class);
+         type_instance_flags type_flags
+           = gdbarch_address_class_type_flags (gdbarch, byte_size,
+                                               addr_class);
          gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
                      == 0);
          type = make_type_with_address_space (type, type_flags);
@@ -16904,7 +17751,7 @@ read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
 
       smash_to_method_type (new_type, domain, TYPE_TARGET_TYPE (to_type),
                            to_type->fields (), to_type->num_fields (),
-                           TYPE_VARARGS (to_type));
+                           to_type->has_varargs ());
       type = lookup_methodptr_type (new_type);
     }
   else
@@ -16918,7 +17765,7 @@ read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
 
 static struct type *
 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu,
-                          enum type_code refcode)
+                         enum type_code refcode)
 {
   struct comp_unit_head *cu_header = &cu->header;
   struct type *type, *target_type;
@@ -16937,7 +17784,7 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu,
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr != nullptr)
     {
-      TYPE_LENGTH (type) = DW_UNSND (attr);
+      TYPE_LENGTH (type) = attr->constant_value (cu_header->addr_size);
     }
   else
     {
@@ -17148,8 +17995,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       struct dynamic_prop low_bound;
 
-      low_bound.kind = PROP_CONST;
-      low_bound.data.const_val = 1;
+      low_bound.set_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);
@@ -17167,7 +18013,7 @@ prototyped_function_p (struct die_info *die, struct dwarf2_cu *cu)
   struct attribute *attr;
 
   attr = dwarf2_attr (die, DW_AT_prototyped, cu);
-  if (attr && (DW_UNSND (attr) != 0))
+  if (attr && attr->as_boolean ())
     return 1;
 
   /* The DWARF standard implies that the DW_AT_prototyped attribute
@@ -17218,16 +18064,16 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
   ftype = lookup_function_type (type);
 
   if (prototyped_function_p (die, cu))
-    TYPE_PROTOTYPED (ftype) = 1;
+    ftype->set_is_prototyped (true);
 
   /* Store the calling convention in the type if it's available in
      the subroutine die.  Otherwise set the calling convention to
      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_subroutine (DW_UNSND (attr)))
+      && is_valid_DW_AT_calling_convention_for_subroutine (attr->constant_value (0)))
     TYPE_CALLING_CONVENTION (ftype)
-      = (enum dwarf_calling_convention) (DW_UNSND (attr));
+      = (enum dwarf_calling_convention) attr->constant_value (0);
   else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
     TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
   else
@@ -17236,7 +18082,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
   /* Record whether the function returns normally to its caller or not
      if the DWARF producer set that information.  */
   attr = dwarf2_attr (die, DW_AT_noreturn, cu);
-  if (attr && (DW_UNSND (attr) != 0))
+  if (attr && attr->as_boolean ())
     TYPE_NO_RETURN (ftype) = 1;
 
   /* We need to add the subroutine type to the die immediately so
@@ -17251,8 +18097,8 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
       int nparams, iparams;
 
       /* Count the number of parameters.
-         FIXME: GDB currently ignores vararg functions, but knows about
-         vararg member functions.  */
+        FIXME: GDB currently ignores vararg functions, but knows about
+        vararg member functions.  */
       nparams = 0;
       child_die = die->child;
       while (child_die && child_die->tag)
@@ -17260,7 +18106,8 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
          if (child_die->tag == DW_TAG_formal_parameter)
            nparams++;
          else if (child_die->tag == DW_TAG_unspecified_parameters)
-           TYPE_VARARGS (ftype) = 1;
+           ftype->set_has_varargs (true);
+
          child_die = child_die->sibling;
        }
 
@@ -17272,7 +18119,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
       /* TYPE_FIELD_TYPE must never be NULL.  Pre-fill the array to ensure it
         even if we error out during the parameters reading below.  */
       for (iparams = 0; iparams < nparams; iparams++)
-       TYPE_FIELD_TYPE (ftype, iparams) = void_type;
+       ftype->field (iparams).set_type (void_type);
 
       iparams = 0;
       child_die = die->child;
@@ -17293,7 +18140,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
                 4.5 does not yet generate.  */
              attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
              if (attr != nullptr)
-               TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
+               TYPE_FIELD_ARTIFICIAL (ftype, iparams) = attr->as_boolean ();
              else
                TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
              arg_type = die_type (child_die, cu);
@@ -17329,7 +18176,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
                                             arg_type, 0);
                }
 
-             TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
+             ftype->field (iparams).set_type (arg_type);
              iparams++;
            }
          child_die = child_die->sibling;
@@ -17348,7 +18195,7 @@ read_typedef (struct die_info *die, struct dwarf2_cu *cu)
 
   name = dwarf2_full_name (NULL, die, cu);
   this_type = init_type (objfile, TYPE_CODE_TYPEDEF, 0, name);
-  TYPE_TARGET_STUB (this_type) = 1;
+  this_type->set_target_is_stub (true);
   set_die_type (die, this_type, cu);
   target_type = die_type (die, cu);
   if (target_type != this_type)
@@ -17362,17 +18209,182 @@ read_typedef (struct die_info *die, struct dwarf2_cu *cu)
                 sect_offset_str (die->sect_off), objfile_name (objfile));
       TYPE_TARGET_TYPE (this_type) = NULL;
     }
-  if (name == NULL)
+  if (name == NULL)
+    {
+      /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
+        anonymous typedefs, which is, strictly speaking, invalid DWARF.
+        Handle these by just returning the target type, rather than
+        constructing an anonymous typedef type and trying to handle this
+        elsewhere.  */
+      set_die_type (die, target_type, cu);
+      return target_type;
+    }
+  return this_type;
+}
+
+/* Assuming DIE is a rational DW_TAG_constant, read the DIE's
+   numerator and denominator into NUMERATOR and DENOMINATOR (resp).
+
+   If the numerator and/or numerator attribute is missing,
+   a complaint is filed, and NUMERATOR and DENOMINATOR are left
+   untouched.  */
+
+static void
+get_dwarf2_rational_constant (struct die_info *die, struct dwarf2_cu *cu,
+                             gdb_mpz *numerator, gdb_mpz *denominator)
+{
+  struct attribute *num_attr, *denom_attr;
+
+  num_attr = dwarf2_attr (die, DW_AT_GNU_numerator, cu);
+  if (num_attr == nullptr)
+    complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
+              dwarf_tag_name (die->tag), sect_offset_str (die->sect_off));
+
+  denom_attr = dwarf2_attr (die, DW_AT_GNU_denominator, cu);
+  if (denom_attr == nullptr)
+    complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
+              dwarf_tag_name (die->tag), sect_offset_str (die->sect_off));
+
+  if (num_attr == nullptr || denom_attr == nullptr)
+    return;
+
+  if (num_attr->form_is_block ())
+    {
+      dwarf_block *blk = num_attr->as_block ();
+      mpz_import (numerator->val, blk->size,
+                 bfd_big_endian (cu->per_objfile->objfile->obfd) ? 1 : -1,
+                 1, 0, 0, blk->data);
+    }
+  else
+    *numerator = gdb_mpz (num_attr->constant_value (1));
+
+  if (denom_attr->form_is_block ())
+    {
+      dwarf_block *blk = denom_attr->as_block ();
+      mpz_import (denominator->val, blk->size,
+                 bfd_big_endian (cu->per_objfile->objfile->obfd) ? 1 : -1,
+                 1, 0, 0, blk->data);
+    }
+  else
+    *denominator = gdb_mpz (denom_attr->constant_value (1));
+}
+
+/* Same as get_dwarf2_rational_constant, but extracting an unsigned
+   rational constant, rather than a signed one.
+
+   If the rational constant has a negative value, a complaint
+   is filed, and NUMERATOR and DENOMINATOR are left untouched.  */
+
+static void
+get_dwarf2_unsigned_rational_constant (struct die_info *die,
+                                      struct dwarf2_cu *cu,
+                                      gdb_mpz *numerator,
+                                      gdb_mpz *denominator)
+{
+  gdb_mpz num (1);
+  gdb_mpz denom (1);
+
+  get_dwarf2_rational_constant (die, cu, &num, &denom);
+  if (mpz_sgn (num.val) == -1 && mpz_sgn (denom.val) == -1)
+    {
+      mpz_neg (num.val, num.val);
+      mpz_neg (denom.val, denom.val);
+    }
+  else if (mpz_sgn (num.val) == -1)
+    {
+      complaint (_("unexpected negative value for DW_AT_GNU_numerator"
+                  " in DIE at %s"),
+                sect_offset_str (die->sect_off));
+      return;
+    }
+  else if (mpz_sgn (denom.val) == -1)
+    {
+      complaint (_("unexpected negative value for DW_AT_GNU_denominator"
+                  " in DIE at %s"),
+                sect_offset_str (die->sect_off));
+      return;
+    }
+
+  *numerator = std::move (num);
+  *denominator = std::move (denom);
+}
+
+/* Assuming DIE corresponds to a fixed point type, finish the creation
+   of the corresponding TYPE by setting its type-specific data.
+   CU is the DIE's CU.  */
+
+static void
+finish_fixed_point_type (struct type *type, struct die_info *die,
+                        struct dwarf2_cu *cu)
+{
+  struct attribute *attr;
+
+  gdb_assert (type->code () == TYPE_CODE_FIXED_POINT
+             && TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FIXED_POINT);
+
+  attr = dwarf2_attr (die, DW_AT_binary_scale, cu);
+  if (!attr)
+    attr = dwarf2_attr (die, DW_AT_decimal_scale, cu);
+  if (!attr)
+    attr = dwarf2_attr (die, DW_AT_small, cu);
+
+  /* Numerator and denominator of our fixed-point type's scaling factor.
+     The default is a scaling factor of 1, which we use as a fallback
+     when we are not able to decode it (problem with the debugging info,
+     unsupported forms, bug in GDB, etc...).  Using that as the default
+     allows us to at least print the unscaled value, which might still
+     be useful to a user.  */
+  gdb_mpz scale_num (1);
+  gdb_mpz scale_denom (1);
+
+  if (attr == nullptr)
+    {
+      /* Scaling factor not found.  Assume a scaling factor of 1,
+        and hope for the best.  At least the user will be able to see
+        the encoded value.  */
+      complaint (_("no scale found for fixed-point type (DIE at %s)"),
+                sect_offset_str (die->sect_off));
+    }
+  else if (attr->name == DW_AT_binary_scale)
+    {
+      LONGEST scale_exp = attr->constant_value (0);
+      gdb_mpz *num_or_denom = scale_exp > 0 ? &scale_num : &scale_denom;
+
+      mpz_mul_2exp (num_or_denom->val, num_or_denom->val, std::abs (scale_exp));
+    }
+  else if (attr->name == DW_AT_decimal_scale)
+    {
+      LONGEST scale_exp = attr->constant_value (0);
+      gdb_mpz *num_or_denom = scale_exp > 0 ? &scale_num : &scale_denom;
+
+      mpz_ui_pow_ui (num_or_denom->val, 10, std::abs (scale_exp));
+    }
+  else if (attr->name == DW_AT_small)
     {
-      /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
-        anonymous typedefs, which is, strictly speaking, invalid DWARF.
-        Handle these by just returning the target type, rather than
-        constructing an anonymous typedef type and trying to handle this
-        elsewhere.  */
-      set_die_type (die, target_type, cu);
-      return target_type;
+      struct die_info *scale_die;
+      struct dwarf2_cu *scale_cu = cu;
+
+      scale_die = follow_die_ref (die, attr, &scale_cu);
+      if (scale_die->tag == DW_TAG_constant)
+       get_dwarf2_unsigned_rational_constant (scale_die, scale_cu,
+                                              &scale_num, &scale_denom);
+      else
+       complaint (_("%s DIE not supported as target of DW_AT_small attribute"
+                    " (DIE at %s)"),
+                  dwarf_tag_name (die->tag), sect_offset_str (die->sect_off));
     }
-  return this_type;
+  else
+    {
+      complaint (_("unsupported scale attribute %s for fixed-point type"
+                  " (DIE at %s)"),
+                dwarf_attr_name (attr->name),
+                sect_offset_str (die->sect_off));
+    }
+
+  gdb_mpq &scaling_factor = type->fixed_point_info ().scaling_factor;
+  mpz_set (mpq_numref (scaling_factor.val), scale_num.val);
+  mpz_set (mpq_denref (scaling_factor.val), scale_denom.val);
+  mpq_canonicalize (scaling_factor.val);
 }
 
 /* Allocate a floating-point type of size BITS and name NAME.  Pass NAME_HINT
@@ -17416,6 +18428,32 @@ dwarf2_init_integer_type (struct dwarf2_cu *cu, struct objfile *objfile,
   return type;
 }
 
+/* Return true if DIE has a DW_AT_small attribute whose value is
+   a constant rational, where both the numerator and denominator
+   are equal to zero.
+
+   CU is the DIE's Compilation Unit.  */
+
+static bool
+has_zero_over_zero_small_attribute (struct die_info *die,
+                                   struct dwarf2_cu *cu)
+{
+  struct attribute *attr = dwarf2_attr (die, DW_AT_small, cu);
+  if (attr == nullptr)
+    return false;
+
+  struct dwarf2_cu *scale_cu = cu;
+  struct die_info *scale_die
+    = follow_die_ref (die, attr, &scale_cu);
+
+  if (scale_die->tag != DW_TAG_constant)
+    return false;
+
+  gdb_mpz num (1), denom (1);
+  get_dwarf2_rational_constant (scale_die, cu, &num, &denom);
+  return mpz_sgn (num.val) == 0 && mpz_sgn (denom.val) == 0;
+}
+
 /* Initialise and return a floating point type of size BITS suitable for
    use as a component of a complex number.  The NAME_HINT is passed through
    when initialising the floating point type and is the name of the complex
@@ -17495,11 +18533,11 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
   gdbarch *arch;
 
   attr = dwarf2_attr (die, DW_AT_encoding, cu);
-  if (attr != nullptr)
-    encoding = DW_UNSND (attr);
+  if (attr != nullptr && attr->form_is_constant ())
+    encoding = attr->constant_value (0);
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr != nullptr)
-    bits = DW_UNSND (attr) * TARGET_CHAR_BIT;
+    bits = attr->constant_value (0) * TARGET_CHAR_BIT;
   name = dwarf2_name (die, cu);
   if (!name)
     complaint (_("DW_AT_name missing from DW_TAG_base_type"));
@@ -17508,9 +18546,9 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
   enum bfd_endian byte_order = gdbarch_byte_order (arch);
 
   attr = dwarf2_attr (die, DW_AT_endianity, cu);
-  if (attr)
+  if (attr != nullptr && attr->form_is_constant ())
     {
-      int endianity = DW_UNSND (attr);
+      int endianity = attr->constant_value (0);
 
       switch (endianity)
        {
@@ -17526,6 +18564,31 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        }
     }
 
+  if ((encoding == DW_ATE_signed_fixed || encoding == DW_ATE_unsigned_fixed)
+      && cu->language == language_ada
+      && has_zero_over_zero_small_attribute (die, cu))
+    {
+      /* brobecker/2018-02-24: This is a fixed point type for which
+        the scaling factor is represented as fraction whose value
+        does not make sense (zero divided by zero), so we should
+        normally never see these.  However, there is a small category
+        of fixed point types for which GNAT is unable to provide
+        the scaling factor via the standard DWARF mechanisms, and
+        for which the info is provided via the GNAT encodings instead.
+        This is likely what this DIE is about.
+
+        Ideally, GNAT should be declaring this type the same way
+        it declares other fixed point types when using the legacy
+        GNAT encoding, which is to use a simple signed or unsigned
+        base type.  A report to the GNAT team has been created to
+        look into it.  In the meantime, pretend this type is a simple
+        signed or unsigned integral, rather than a fixed point type,
+        to avoid any confusion later on as to how to process this type.  */
+      encoding = (encoding == DW_ATE_signed_fixed
+                 ? DW_ATE_signed
+                 : DW_ATE_unsigned);
+    }
+
   switch (encoding)
     {
       case DW_ATE_address:
@@ -17602,6 +18665,14 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
          return set_die_type (die, type, cu);
        }
        break;
+      case DW_ATE_signed_fixed:
+       type = init_fixed_point_type (objfile, bits, 0, name);
+       finish_fixed_point_type (type, die, cu);
+       break;
+      case DW_ATE_unsigned_fixed:
+       type = init_fixed_point_type (objfile, bits, 1, name);
+       finish_fixed_point_type (type, die, cu);
+       break;
 
       default:
        complaint (_("unsupported DW_AT_encoding: '%s'"),
@@ -17611,11 +18682,32 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
     }
 
   if (name && strcmp (name, "char") == 0)
-    TYPE_NOSIGN (type) = 1;
+    type->set_has_no_signedness (true);
 
   maybe_set_alignment (cu, die, type);
 
-  TYPE_ENDIANITY_NOT_DEFAULT (type) = gdbarch_byte_order (arch) != byte_order;
+  type->set_endianity_is_not_default (gdbarch_byte_order (arch) != byte_order);
+
+  if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_INT)
+    {
+      attr = dwarf2_attr (die, DW_AT_bit_size, cu);
+      if (attr != nullptr && attr->as_unsigned () <= 8 * TYPE_LENGTH (type))
+       {
+         unsigned real_bit_size = attr->as_unsigned ();
+         attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
+         /* Only use the attributes if they make sense together.  */
+         if (attr == nullptr
+             || (attr->as_unsigned () + real_bit_size
+                 <= 8 * TYPE_LENGTH (type)))
+           {
+             TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size
+               = real_bit_size;
+             if (attr != nullptr)
+               TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset
+                 = attr->as_unsigned ();
+           }
+       }
+    }
 
   return set_die_type (die, type, cu);
 }
@@ -17645,8 +18737,10 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
       baton->property_type = default_type;
       baton->locexpr.per_cu = cu->per_cu;
       baton->locexpr.per_objfile = per_objfile;
-      baton->locexpr.size = DW_BLOCK (attr)->size;
-      baton->locexpr.data = DW_BLOCK (attr)->data;
+
+      struct dwarf_block *block = attr->as_block ();
+      baton->locexpr.size = block->size;
+      baton->locexpr.data = block->data;
       switch (attr->name)
        {
        case DW_AT_string_length:
@@ -17656,9 +18750,9 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
          baton->locexpr.is_reference = false;
          break;
        }
-      prop->data.baton = baton;
-      prop->kind = PROP_LOCEXPR;
-      gdb_assert (prop->data.baton != NULL);
+
+      prop->set_locexpr (baton);
+      gdb_assert (prop->baton () != NULL);
     }
   else if (attr->form_is_ref ())
     {
@@ -17682,9 +18776,8 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
                baton = XOBNEW (obstack, struct dwarf2_property_baton);
                baton->property_type = die_type (target_die, target_cu);
                fill_in_loclist_baton (cu, &baton->loclist, target_attr);
-               prop->data.baton = baton;
-               prop->kind = PROP_LOCLIST;
-               gdb_assert (prop->data.baton != NULL);
+               prop->set_loclist (baton);
+               gdb_assert (prop->baton () != NULL);
              }
            else if (target_attr->form_is_block ())
              {
@@ -17692,12 +18785,12 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
                baton->property_type = die_type (target_die, target_cu);
                baton->locexpr.per_cu = cu->per_cu;
                baton->locexpr.per_objfile = per_objfile;
-               baton->locexpr.size = DW_BLOCK (target_attr)->size;
-               baton->locexpr.data = DW_BLOCK (target_attr)->data;
+               struct dwarf_block *block = target_attr->as_block ();
+               baton->locexpr.size = block->size;
+               baton->locexpr.data = block->data;
                baton->locexpr.is_reference = true;
-               prop->data.baton = baton;
-               prop->kind = PROP_LOCEXPR;
-               gdb_assert (prop->data.baton != NULL);
+               prop->set_locexpr (baton);
+               gdb_assert (prop->baton () != NULL);
              }
            else
              {
@@ -17719,17 +18812,13 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
                                                      target_cu);
              baton->offset_info.offset = offset;
              baton->offset_info.type = die_type (target_die, target_cu);
-             prop->data.baton = baton;
-             prop->kind = PROP_ADDR_OFFSET;
+             prop->set_addr_offset (baton);
              break;
            }
        }
     }
   else if (attr->form_is_constant ())
-    {
-      prop->data.const_val = attr->constant_value (0);
-      prop->kind = PROP_CONST;
-    }
+    prop->set_const_val (attr->constant_value (0));
   else
     {
       dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr->form),
@@ -17829,9 +18918,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   if (range_type)
     return range_type;
 
-  low.kind = PROP_CONST;
-  high.kind = PROP_CONST;
-  high.data.const_val = 0;
+  high.set_const_val (0);
 
   /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
      omitting DW_AT_lower_bound.  */
@@ -17839,27 +18926,27 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
     {
     case language_c:
     case language_cplus:
-      low.data.const_val = 0;
+      low.set_const_val (0);
       low_default_is_valid = 1;
       break;
     case language_fortran:
-      low.data.const_val = 1;
+      low.set_const_val (1);
       low_default_is_valid = 1;
       break;
     case language_d:
     case language_objc:
     case language_rust:
-      low.data.const_val = 0;
+      low.set_const_val (0);
       low_default_is_valid = (cu->header.version >= 4);
       break;
     case language_ada:
     case language_m2:
     case language_pascal:
-      low.data.const_val = 1;
+      low.set_const_val (1);
       low_default_is_valid = (cu->header.version >= 4);
       break;
     default:
-      low.data.const_val = 0;
+      low.set_const_val (0);
       low_default_is_valid = 0;
       break;
     }
@@ -17881,8 +18968,8 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
       if (attr_to_dynamic_prop (attr, die, cu, &high, base_type))
        {
          /* If bounds are constant do the final calculation here.  */
-         if (low.kind == PROP_CONST && high.kind == PROP_CONST)
-           high.data.const_val = low.data.const_val + high.data.const_val - 1;
+         if (low.kind () == PROP_CONST && high.kind () == PROP_CONST)
+           high.set_const_val (low.const_val () + high.const_val () - 1);
          else
            high_bound_is_count = 1;
        }
@@ -17915,12 +19002,12 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
      the base type is signed.  */
   negative_mask =
     -((ULONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
-  if (low.kind == PROP_CONST
-      && !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask))
-    low.data.const_val |= negative_mask;
-  if (high.kind == PROP_CONST
-      && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
-    high.data.const_val |= negative_mask;
+  if (low.kind () == PROP_CONST
+      && !base_type->is_unsigned () && (low.const_val () & negative_mask))
+    low.set_const_val (low.const_val () | negative_mask);
+  if (high.kind () == PROP_CONST
+      && !base_type->is_unsigned () && (high.const_val () & negative_mask))
+    high.set_const_val (high.const_val () | negative_mask);
 
   /* Check for bit and byte strides.  */
   struct dynamic_prop byte_stride_prop;
@@ -17968,11 +19055,11 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
     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;
+    range_type->bounds ()->flag_upper_bound_is_count = 1;
 
   /* Ada expects an empty array on no boundary attributes.  */
   if (attr == NULL && cu->language != language_ada)
-    TYPE_HIGH_BOUND_KIND (range_type) = PROP_UNDEFINED;
+    range_type->bounds ()->high.set_undefined ();
 
   name = dwarf2_name (die, cu);
   if (name)
@@ -17980,7 +19067,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr != nullptr)
-    TYPE_LENGTH (range_type) = DW_UNSND (attr);
+    TYPE_LENGTH (range_type) = attr->constant_value (0);
 
   maybe_set_alignment (cu, die, range_type);
 
@@ -18005,7 +19092,7 @@ read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
      such a type, we treat it as a stub, and try to resolve it later on,
      when needed.  */
   if (cu->language == language_ada)
-    TYPE_STUB (type) = 1;
+    type->set_is_stub (true);
 
   return set_die_type (die, type, cu);
 }
@@ -18153,30 +19240,39 @@ read_full_die_1 (const struct die_reader_specs *reader,
      attributes.  */
   die->num_attrs = abbrev->num_attrs;
 
-  std::vector<int> indexes_that_need_reprocess;
+  bool any_need_reprocess = false;
   for (i = 0; i < abbrev->num_attrs; ++i)
     {
-      bool need_reprocess;
-      info_ptr =
-        read_attribute (reader, &die->attrs[i], &abbrev->attrs[i],
-                       info_ptr, &need_reprocess);
-      if (need_reprocess)
-        indexes_that_need_reprocess.push_back (i);
+      info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i],
+                                info_ptr);
+      if (die->attrs[i].requires_reprocessing_p ())
+       any_need_reprocess = true;
     }
 
   struct attribute *attr = die->attr (DW_AT_str_offsets_base);
-  if (attr != nullptr)
-    cu->str_offsets_base = DW_UNSND (attr);
+  if (attr != nullptr && attr->form_is_unsigned ())
+    cu->str_offsets_base = attr->as_unsigned ();
 
   attr = die->attr (DW_AT_loclists_base);
   if (attr != nullptr)
-    cu->loclist_base = DW_UNSND (attr);
+    cu->loclist_base = attr->as_unsigned ();
 
   auto maybe_addr_base = die->addr_base ();
   if (maybe_addr_base.has_value ())
     cu->addr_base = *maybe_addr_base;
-  for (int index : indexes_that_need_reprocess)
-    read_attribute_reprocess (reader, &die->attrs[index]);
+
+  attr = die->attr (DW_AT_rnglists_base);
+  if (attr != nullptr)
+    cu->ranges_base = attr->as_unsigned ();
+
+  if (any_need_reprocess)
+    {
+      for (i = 0; i < abbrev->num_attrs; ++i)
+       {
+         if (die->attrs[i].requires_reprocessing_p ())
+           read_attribute_reprocess (reader, &die->attrs[i], die->tag);
+       }
+    }
   *diep = die;
   return info_ptr;
 }
@@ -18211,20 +19307,27 @@ read_full_die (const struct die_reader_specs *reader,
    symbol for.  */
 
 static int
-is_type_tag_for_partial (int tag)
+is_type_tag_for_partial (int tag, enum language lang)
 {
   switch (tag)
     {
 #if 0
     /* Some types that would be reasonable to generate partial symbols for,
-       that we don't at present.  */
-    case DW_TAG_array_type:
+       that we don't at present.  Note that normally this does not
+       matter, mainly because C compilers don't give names to these
+       types, but instead emit DW_TAG_typedef.  */
     case DW_TAG_file_type:
     case DW_TAG_ptr_to_member_type:
     case DW_TAG_set_type:
     case DW_TAG_string_type:
     case DW_TAG_subroutine_type:
 #endif
+
+      /* GNAT may emit an array with a name, but no typedef, so we
+        need to make a symbol in this case.  */
+    case DW_TAG_array_type:
+      return lang == language_ada;
+
     case DW_TAG_base_type:
     case DW_TAG_class_type:
     case DW_TAG_interface_type:
@@ -18306,7 +19409,8 @@ load_partial_dies (const struct die_reader_specs *reader,
       if (!load_all
          && cu->language == language_cplus
          && parent_die != NULL
-         && parent_die->tag == DW_TAG_subprogram)
+         && parent_die->tag == DW_TAG_subprogram
+         && abbrev->tag != DW_TAG_inlined_subroutine)
        {
          info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
          continue;
@@ -18317,7 +19421,7 @@ load_partial_dies (const struct die_reader_specs *reader,
         later variables referencing them via DW_AT_specification (for
         static members).  */
       if (!load_all
-         && !is_type_tag_for_partial (abbrev->tag)
+         && !is_type_tag_for_partial (abbrev->tag, cu->language)
          && abbrev->tag != DW_TAG_constant
          && abbrev->tag != DW_TAG_enumerator
          && abbrev->tag != DW_TAG_subprogram
@@ -18361,6 +19465,7 @@ load_partial_dies (const struct die_reader_specs *reader,
          && pdi.is_declaration == 0
          && ((pdi.tag == DW_TAG_typedef && !pdi.has_children)
              || pdi.tag == DW_TAG_base_type
+             || pdi.tag == DW_TAG_array_type
              || pdi.tag == DW_TAG_subrange_type))
        {
          if (building_psymtab && pdi.raw_name != NULL)
@@ -18528,7 +19633,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
                        const struct abbrev_info &abbrev, const gdb_byte *info_ptr)
 {
   struct dwarf2_cu *cu = reader->cu;
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
   unsigned int i;
   int has_low_pc_attr = 0;
   int has_high_pc_attr = 0;
@@ -18537,16 +19642,14 @@ partial_die_info::read (const struct die_reader_specs *reader,
   for (i = 0; i < abbrev.num_attrs; ++i)
     {
       attribute attr;
-      bool need_reprocess;
-      info_ptr = read_attribute (reader, &attr, &abbrev.attrs[i],
-                                info_ptr, &need_reprocess);
+      info_ptr = read_attribute (reader, &attr, &abbrev.attrs[i], info_ptr);
       /* String and address offsets that need to do the reprocessing have
-         already been read at this point, so there is no need to wait until
+        already been read at this point, so there is no need to wait until
         the loop terminates to do the reprocessing.  */
-      if (need_reprocess)
-       read_attribute_reprocess (reader, &attr);
+      if (attr.requires_reprocessing_p ())
+       read_attribute_reprocess (reader, &attr, tag);
       /* Store the data if it is of an attribute we want to keep in a
-         partial symbol table.  */
+        partial symbol table.  */
       switch (attr.name)
        {
        case DW_AT_name:
@@ -18562,11 +19665,11 @@ partial_die_info::read (const struct die_reader_specs *reader,
              /* These tags always have simple identifiers already; no need
                 to canonicalize them.  */
              canonical_name = 1;
-             raw_name = DW_STRING (&attr);
+             raw_name = attr.as_string ();
              break;
            default:
              canonical_name = 0;
-             raw_name = DW_STRING (&attr);
+             raw_name = attr.as_string ();
              break;
            }
          break;
@@ -18575,44 +19678,39 @@ partial_die_info::read (const struct die_reader_specs *reader,
          /* Note that both forms of linkage name might appear.  We
             assume they will be the same, and we only store the last
             one we see.  */
-         linkage_name = attr.value_as_string ();
-         /* rustc emits invalid values for DW_AT_linkage_name.  Ignore these.
-            See https://github.com/rust-lang/rust/issues/32925.  */
-         if (cu->language == language_rust && linkage_name != NULL
-             && strchr (linkage_name, '{') != NULL)
-           linkage_name = NULL;
+         linkage_name = attr.as_string ();
          break;
        case DW_AT_low_pc:
          has_low_pc_attr = 1;
-         lowpc = attr.value_as_address ();
+         lowpc = attr.as_address ();
          break;
        case DW_AT_high_pc:
          has_high_pc_attr = 1;
-         highpc = attr.value_as_address ();
+         highpc = attr.as_address ();
          if (cu->header.version >= 4 && attr.form_is_constant ())
                high_pc_relative = 1;
          break;
        case DW_AT_location:
-          /* Support the .debug_loc offsets.  */
-          if (attr.form_is_block ())
-            {
-              d.locdesc = DW_BLOCK (&attr);
-            }
-          else if (attr.form_is_section_offset ())
-            {
+         /* Support the .debug_loc offsets.  */
+         if (attr.form_is_block ())
+           {
+             d.locdesc = attr.as_block ();
+           }
+         else if (attr.form_is_section_offset ())
+           {
              dwarf2_complex_location_expr_complaint ();
-            }
-          else
-            {
+           }
+         else
+           {
              dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
                                                     "partial symbol information");
-            }
+           }
          break;
        case DW_AT_external:
-         is_external = DW_UNSND (&attr);
+         is_external = attr.as_boolean ();
          break;
        case DW_AT_declaration:
-         is_declaration = DW_UNSND (&attr);
+         is_declaration = attr.as_boolean ();
          break;
        case DW_AT_type:
          has_type = 1;
@@ -18644,12 +19742,12 @@ partial_die_info::read (const struct die_reader_specs *reader,
                sibling = sibling_ptr;
            }
          break;
-        case DW_AT_byte_size:
-          has_byte_size = 1;
-          break;
-        case DW_AT_const_value:
-          has_const_value = 1;
-          break;
+       case DW_AT_byte_size:
+         has_byte_size = 1;
+         break;
+       case DW_AT_const_value:
+         has_const_value = 1;
+         break;
        case DW_AT_calling_convention:
          /* DWARF doesn't provide a way to identify a program's source-level
             entry point.  DW_AT_calling_convention attributes are only meant
@@ -18665,14 +19763,17 @@ partial_die_info::read (const struct die_reader_specs *reader,
             Although DWARF now specifies a way to provide this
             information, we support this practice for backward
             compatibility.  */
-         if (DW_UNSND (&attr) == DW_CC_program
+         if (attr.constant_value (0) == DW_CC_program
              && cu->language == language_fortran)
            main_subprogram = 1;
          break;
        case DW_AT_inline:
-         if (DW_UNSND (&attr) == DW_INL_inlined
-             || DW_UNSND (&attr) == DW_INL_declared_inlined)
-           may_be_inlined = 1;
+         {
+           LONGEST value = attr.constant_value (-1);
+           if (value == DW_INL_inlined
+               || value == DW_INL_declared_inlined)
+             may_be_inlined = 1;
+         }
          break;
 
        case DW_AT_import:
@@ -18685,16 +19786,25 @@ partial_die_info::read (const struct die_reader_specs *reader,
          break;
 
        case DW_AT_main_subprogram:
-         main_subprogram = DW_UNSND (&attr);
+         main_subprogram = attr.as_boolean ();
          break;
 
        case DW_AT_ranges:
          {
+           /* DW_AT_rnglists_base does not apply to DIEs from the DWO
+              skeleton.  We take advantage of the fact the DW_AT_ranges
+              does not appear in DW_TAG_compile_unit of DWO files.
+
+              Attributes of the form DW_FORM_rnglistx have already had
+              their value changed by read_rnglist_index and already
+              include DW_AT_rnglists_base, so don't need to add the ranges
+              base, either.  */
+           int need_ranges_base = (tag != DW_TAG_compile_unit
+                                   && attr.form != DW_FORM_rnglistx);
            /* It would be nice to reuse dwarf2_get_pc_bounds here,
               but that requires a full DIE, so instead we just
               reimplement it.  */
-           int need_ranges_base = tag != DW_TAG_compile_unit;
-           unsigned int ranges_offset = (DW_UNSND (&attr)
+           unsigned int ranges_offset = (attr.constant_value (0)
                                          + (need_ranges_base
                                             ? cu->ranges_base
                                             : 0));
@@ -18702,7 +19812,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
            /* Value of the DW_AT_ranges attribute is the offset in the
               .debug_ranges section.  */
            if (dwarf2_ranges_read (ranges_offset, &lowpc, &highpc, cu,
-                                   nullptr))
+                                   nullptr, tag))
              has_pc_info = 1;
          }
          break;
@@ -18733,9 +19843,9 @@ partial_die_info::read (const struct die_reader_specs *reader,
         labels are not in the output, so the relocs get a value of 0.
         If this is a discarded function, mark the pc bounds as invalid,
         so that GDB will ignore it.  */
-      if (lowpc == 0 && !dwarf2_per_objfile->per_bfd->has_section_at_zero)
+      if (lowpc == 0 && !per_objfile->per_bfd->has_section_at_zero)
        {
-         struct objfile *objfile = dwarf2_per_objfile->objfile;
+         struct objfile *objfile = per_objfile->objfile;
          struct gdbarch *gdbarch = objfile->arch ();
 
          complaint (_("DW_AT_low_pc %s is zero "
@@ -18747,7 +19857,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
       /* dwarf2_get_pc_bounds has also the strict low < high requirement.  */
       else if (lowpc >= highpc)
        {
-         struct objfile *objfile = dwarf2_per_objfile->objfile;
+         struct objfile *objfile = per_objfile->objfile;
          struct gdbarch *gdbarch = objfile->arch ();
 
          complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
@@ -18787,8 +19897,8 @@ dwarf2_cu::find_partial_die (sect_offset sect_off)
 static const struct cu_partial_die_info
 find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct partial_die_info *pd = NULL;
 
   if (offset_in_dwz == cu->per_cu->is_dwz
@@ -18812,13 +19922,13 @@ find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
        }
       dwarf2_per_cu_data *per_cu
        = dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz,
-                                           dwarf2_per_objfile);
+                                           per_objfile);
 
-      cu = dwarf2_per_objfile->get_cu (per_cu);
+      cu = per_objfile->get_cu (per_cu);
       if (cu == NULL || cu->partial_dies == NULL)
-       load_partial_comp_unit (per_cu, dwarf2_per_objfile, nullptr);
+       load_partial_comp_unit (per_cu, per_objfile, nullptr);
 
-      cu = dwarf2_per_objfile->get_cu (per_cu);
+      cu = per_objfile->get_cu (per_cu);
 
       cu->last_used = 0;
       pd = cu->find_partial_die (sect_off);
@@ -18837,15 +19947,13 @@ find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
         DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
         and clobber THIS_CU->cu->partial_dies with the hash table for the new
         set.  */
-      load_partial_comp_unit (cu->per_cu, dwarf2_per_objfile, cu);
+      load_partial_comp_unit (cu->per_cu, per_objfile, cu);
 
       pd = cu->find_partial_die (sect_off);
     }
 
   if (pd == NULL)
-    internal_error (__FILE__, __LINE__,
-                   _("could not find partial DIE %s "
-                     "in cache [from module %s]\n"),
+    error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
                    sect_offset_str (sect_off), bfd_get_filename (objfile->obfd));
   return { cu, pd };
 }
@@ -18891,8 +19999,8 @@ guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
          && child_pdi->linkage_name != NULL)
        {
          gdb::unique_xmalloc_ptr<char> actual_class_name
-           (language_class_name_from_physname (cu->language_defn,
-                                               child_pdi->linkage_name));
+           (cu->language_defn->class_name_from_physname
+            (child_pdi->linkage_name));
          if (actual_class_name != NULL)
            {
              struct objfile *objfile = cu->per_objfile->objfile;
@@ -19026,11 +20134,11 @@ partial_die_info::fixup (struct dwarf2_cu *cu)
   fixup_called = 1;
 }
 
-/* Read the .debug_loclists header contents from the given SECTION in the
-   HEADER.  */
+/* Read the .debug_loclists or .debug_rnglists header (they are the same format)
+   contents from the given SECTION in the HEADER.  */
 static void
-read_loclist_header (struct loclist_header *header,
-                     struct dwarf2_section_info *section)
+read_loclists_rnglists_header (struct loclists_rnglists_header *header,
+                              struct dwarf2_section_info *section)
 {
   unsigned int bytes_read;
   bfd *abfd = section->get_bfd_owner ();
@@ -19073,8 +20181,8 @@ lookup_loclist_base (struct dwarf2_cu *cu)
 static CORE_ADDR
 read_loclist_index (struct dwarf2_cu *cu, ULONGEST loclist_index)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   bfd *abfd = objfile->obfd;
   ULONGEST loclist_base = lookup_loclist_base (cu);
   struct dwarf2_section_info *section = cu_debug_loc_section (cu);
@@ -19082,18 +20190,18 @@ read_loclist_index (struct dwarf2_cu *cu, ULONGEST loclist_index)
   section->read (objfile);
   if (section->buffer == NULL)
     complaint (_("DW_FORM_loclistx used without .debug_loclists "
-               "section [in module %s]"), objfile_name (objfile));
-  struct loclist_header header;
-  read_loclist_header (&header, section);
+               "section [in module %s]"), objfile_name (objfile));
+  struct loclists_rnglists_header header;
+  read_loclists_rnglists_header (&header, section);
   if (loclist_index >= header.offset_entry_count)
     complaint (_("DW_FORM_loclistx pointing outside of "
-               ".debug_loclists offset array [in module %s]"),
-               objfile_name (objfile));
+               ".debug_loclists offset array [in module %s]"),
+               objfile_name (objfile));
   if (loclist_base + loclist_index * cu->header.offset_size
        >= section->size)
     complaint (_("DW_FORM_loclistx pointing outside of "
-               ".debug_loclists section [in module %s]"),
-               objfile_name (objfile));
+               ".debug_loclists section [in module %s]"),
+               objfile_name (objfile));
   const gdb_byte *info_ptr
     = section->buffer + loclist_base + loclist_index * cu->header.offset_size;
 
@@ -19103,24 +20211,83 @@ read_loclist_index (struct dwarf2_cu *cu, ULONGEST loclist_index)
     return bfd_get_64 (abfd, info_ptr) + loclist_base;
 }
 
+/* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
+   array of offsets in the .debug_rnglists section.  */
+static CORE_ADDR
+read_rnglist_index (struct dwarf2_cu *cu, ULONGEST rnglist_index,
+                   dwarf_tag tag)
+{
+  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  bfd *abfd = objfile->obfd;
+  ULONGEST rnglist_header_size =
+    (cu->header.initial_length_size == 4 ? RNGLIST_HEADER_SIZE32
+     : RNGLIST_HEADER_SIZE64);
+  ULONGEST rnglist_base =
+      (cu->dwo_unit != nullptr) ? rnglist_header_size : cu->ranges_base;
+  ULONGEST start_offset =
+    rnglist_base + rnglist_index * cu->header.offset_size;
+
+  /* Get rnglists section.  */
+  struct dwarf2_section_info *section = cu_debug_rnglists_section (cu, tag);
+
+  /* Read the rnglists section content.  */
+  section->read (objfile);
+  if (section->buffer == nullptr)
+    error (_("DW_FORM_rnglistx used without .debug_rnglists section "
+            "[in module %s]"),
+          objfile_name (objfile));
+
+  /* Verify the rnglist index is valid.  */
+  struct loclists_rnglists_header header;
+  read_loclists_rnglists_header (&header, section);
+  if (rnglist_index >= header.offset_entry_count)
+    error (_("DW_FORM_rnglistx index pointing outside of "
+            ".debug_rnglists offset array [in module %s]"),
+          objfile_name (objfile));
+
+  /* Validate that the offset is within the section's range.  */
+  if (start_offset >= section->size)
+    error (_("DW_FORM_rnglistx pointing outside of "
+            ".debug_rnglists section [in module %s]"),
+          objfile_name (objfile));
+
+  /* Validate that reading won't go beyond the end of the section.  */
+  if (start_offset + cu->header.offset_size > rnglist_base + section->size)
+    error (_("Reading DW_FORM_rnglistx index beyond end of"
+            ".debug_rnglists section [in module %s]"),
+          objfile_name (objfile));
+
+  const gdb_byte *info_ptr = section->buffer + start_offset;
+
+  if (cu->header.offset_size == 4)
+    return read_4_bytes (abfd, info_ptr) + rnglist_base;
+  else
+    return read_8_bytes (abfd, info_ptr) + rnglist_base;
+}
+
 /* Process the attributes that had to be skipped in the first round. These
    attributes are the ones that need str_offsets_base or addr_base attributes.
    They could not have been processed in the first round, because at the time
    the values of str_offsets_base or addr_base may not have been known.  */
 static void
 read_attribute_reprocess (const struct die_reader_specs *reader,
-                         struct attribute *attr)
+                         struct attribute *attr, dwarf_tag tag)
 {
   struct dwarf2_cu *cu = reader->cu;
   switch (attr->form)
     {
       case DW_FORM_addrx:
       case DW_FORM_GNU_addr_index:
-        DW_ADDR (attr) = read_addr_index (cu, DW_UNSND (attr));
-        break;
+       attr->set_address (read_addr_index (cu,
+                                           attr->as_unsigned_reprocess ()));
+       break;
       case DW_FORM_loclistx:
-        DW_UNSND (attr) = read_loclist_index (cu, DW_UNSND (attr));
+       attr->set_address (read_loclist_index (cu, attr->as_unsigned ()));
         break;
+      case DW_FORM_rnglistx:
+       attr->set_address (read_rnglist_index (cu, attr->as_unsigned (), tag));
+       break;
       case DW_FORM_strx:
       case DW_FORM_strx1:
       case DW_FORM_strx2:
@@ -19128,17 +20295,14 @@ read_attribute_reprocess (const struct die_reader_specs *reader,
       case DW_FORM_strx4:
       case DW_FORM_GNU_str_index:
        {
-         unsigned int str_index = DW_UNSND (attr);
+         unsigned int str_index = attr->as_unsigned_reprocess ();
+         gdb_assert (!attr->canonical_string_p ());
          if (reader->dwo_file != NULL)
-           {
-             DW_STRING (attr) = read_dwo_str_index (reader, str_index);
-             DW_STRING_IS_CANONICAL (attr) = 0;
-           }
+           attr->set_string_noncanonical (read_dwo_str_index (reader,
+                                                              str_index));
          else
-           {
-             DW_STRING (attr) = read_stub_str_index (cu, str_index);
-             DW_STRING_IS_CANONICAL (attr) = 0;
-           }
+           attr->set_string_noncanonical (read_stub_str_index (cu,
+                                                               str_index));
          break;
        }
       default:
@@ -19151,39 +20315,39 @@ read_attribute_reprocess (const struct die_reader_specs *reader,
 static const gdb_byte *
 read_attribute_value (const struct die_reader_specs *reader,
                      struct attribute *attr, unsigned form,
-                     LONGEST implicit_const, const gdb_byte *info_ptr,
-                     bool *need_reprocess)
+                     LONGEST implicit_const, const gdb_byte *info_ptr)
 {
   struct dwarf2_cu *cu = reader->cu;
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   bfd *abfd = reader->abfd;
   struct comp_unit_head *cu_header = &cu->header;
   unsigned int bytes_read;
   struct dwarf_block *blk;
-  *need_reprocess = false;
 
   attr->form = (enum dwarf_form) form;
   switch (form)
     {
     case DW_FORM_ref_addr:
       if (cu->header.version == 2)
-       DW_UNSND (attr) = cu->header.read_address (abfd, info_ptr,
-                                                  &bytes_read);
+       attr->set_unsigned (cu->header.read_address (abfd, info_ptr,
+                                                    &bytes_read));
       else
-       DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr,
-                                                 &bytes_read);
+       attr->set_unsigned (cu->header.read_offset (abfd, info_ptr,
+                                                   &bytes_read));
       info_ptr += bytes_read;
       break;
     case DW_FORM_GNU_ref_alt:
-      DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr, &bytes_read);
+      attr->set_unsigned (cu->header.read_offset (abfd, info_ptr,
+                                                 &bytes_read));
       info_ptr += bytes_read;
       break;
     case DW_FORM_addr:
       {
        struct gdbarch *gdbarch = objfile->arch ();
-       DW_ADDR (attr) = cu->header.read_address (abfd, info_ptr, &bytes_read);
-       DW_ADDR (attr) = gdbarch_adjust_dwarf2_addr (gdbarch, DW_ADDR (attr));
+       CORE_ADDR addr = cu->header.read_address (abfd, info_ptr, &bytes_read);
+       addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr);
+       attr->set_address (addr);
        info_ptr += bytes_read;
       }
       break;
@@ -19193,7 +20357,7 @@ read_attribute_value (const struct die_reader_specs *reader,
       info_ptr += 2;
       blk->data = read_n_bytes (abfd, info_ptr, blk->size);
       info_ptr += blk->size;
-      DW_BLOCK (attr) = blk;
+      attr->set_block (blk);
       break;
     case DW_FORM_block4:
       blk = dwarf_alloc_block (cu);
@@ -19201,18 +20365,18 @@ read_attribute_value (const struct die_reader_specs *reader,
       info_ptr += 4;
       blk->data = read_n_bytes (abfd, info_ptr, blk->size);
       info_ptr += blk->size;
-      DW_BLOCK (attr) = blk;
+      attr->set_block (blk);
       break;
     case DW_FORM_data2:
-      DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
+      attr->set_unsigned (read_2_bytes (abfd, info_ptr));
       info_ptr += 2;
       break;
     case DW_FORM_data4:
-      DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
+      attr->set_unsigned (read_4_bytes (abfd, info_ptr));
       info_ptr += 4;
       break;
     case DW_FORM_data8:
-      DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
+      attr->set_unsigned (read_8_bytes (abfd, info_ptr));
       info_ptr += 8;
       break;
     case DW_FORM_data16:
@@ -19220,31 +20384,32 @@ read_attribute_value (const struct die_reader_specs *reader,
       blk->size = 16;
       blk->data = read_n_bytes (abfd, info_ptr, 16);
       info_ptr += 16;
-      DW_BLOCK (attr) = blk;
+      attr->set_block (blk);
       break;
     case DW_FORM_sec_offset:
-      DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr, &bytes_read);
+      attr->set_unsigned (cu->header.read_offset (abfd, info_ptr,
+                                                 &bytes_read));
       info_ptr += bytes_read;
       break;
     case DW_FORM_loclistx:
       {
-        *need_reprocess = true;
-        DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
-        info_ptr += bytes_read;
+       attr->set_unsigned_reprocess (read_unsigned_leb128 (abfd, info_ptr,
+                                                           &bytes_read));
+       info_ptr += bytes_read;
       }
       break;
     case DW_FORM_string:
-      DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
-      DW_STRING_IS_CANONICAL (attr) = 0;
+      attr->set_string_noncanonical (read_direct_string (abfd, info_ptr,
+                                                        &bytes_read));
       info_ptr += bytes_read;
       break;
     case DW_FORM_strp:
       if (!cu->per_cu->is_dwz)
        {
-         DW_STRING (attr) = read_indirect_string (dwarf2_per_objfile,
-                                                  abfd, info_ptr, cu_header,
-                                                  &bytes_read);
-         DW_STRING_IS_CANONICAL (attr) = 0;
+         attr->set_string_noncanonical
+           (read_indirect_string (per_objfile,
+                                  abfd, info_ptr, cu_header,
+                                  &bytes_read));
          info_ptr += bytes_read;
          break;
        }
@@ -19252,22 +20417,21 @@ read_attribute_value (const struct die_reader_specs *reader,
     case DW_FORM_line_strp:
       if (!cu->per_cu->is_dwz)
        {
-         DW_STRING (attr)
-           = dwarf2_per_objfile->read_line_string (info_ptr, cu_header,
-                                                   &bytes_read);
-         DW_STRING_IS_CANONICAL (attr) = 0;
+         attr->set_string_noncanonical
+           (per_objfile->read_line_string (info_ptr, cu_header,
+                                           &bytes_read));
          info_ptr += bytes_read;
          break;
        }
       /* FALLTHROUGH */
     case DW_FORM_GNU_strp_alt:
       {
-       dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
+       dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
        LONGEST str_offset = cu_header->read_offset (abfd, info_ptr,
                                                     &bytes_read);
 
-       DW_STRING (attr) = dwz->read_string (objfile, str_offset);
-       DW_STRING_IS_CANONICAL (attr) = 0;
+       attr->set_string_noncanonical
+         (dwz->read_string (objfile, str_offset));
        info_ptr += bytes_read;
       }
       break;
@@ -19278,7 +20442,7 @@ read_attribute_value (const struct die_reader_specs *reader,
       info_ptr += bytes_read;
       blk->data = read_n_bytes (abfd, info_ptr, blk->size);
       info_ptr += blk->size;
-      DW_BLOCK (attr) = blk;
+      attr->set_block (blk);
       break;
     case DW_FORM_block1:
       blk = dwarf_alloc_block (cu);
@@ -19286,55 +20450,59 @@ read_attribute_value (const struct die_reader_specs *reader,
       info_ptr += 1;
       blk->data = read_n_bytes (abfd, info_ptr, blk->size);
       info_ptr += blk->size;
-      DW_BLOCK (attr) = blk;
+      attr->set_block (blk);
       break;
     case DW_FORM_data1:
-      DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
-      info_ptr += 1;
-      break;
     case DW_FORM_flag:
-      DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
+      attr->set_unsigned (read_1_byte (abfd, info_ptr));
       info_ptr += 1;
       break;
     case DW_FORM_flag_present:
-      DW_UNSND (attr) = 1;
+      attr->set_unsigned (1);
       break;
     case DW_FORM_sdata:
-      DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
+      attr->set_signed (read_signed_leb128 (abfd, info_ptr, &bytes_read));
       info_ptr += bytes_read;
       break;
-    case DW_FORM_udata:
     case DW_FORM_rnglistx:
-      DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+      {
+       attr->set_unsigned_reprocess (read_unsigned_leb128 (abfd, info_ptr,
+                                                           &bytes_read));
+       info_ptr += bytes_read;
+      }
+      break;
+    case DW_FORM_udata:
+      attr->set_unsigned (read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
       info_ptr += bytes_read;
       break;
     case DW_FORM_ref1:
-      DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
-                        + read_1_byte (abfd, info_ptr));
+      attr->set_unsigned ((to_underlying (cu->header.sect_off)
+                          + read_1_byte (abfd, info_ptr)));
       info_ptr += 1;
       break;
     case DW_FORM_ref2:
-      DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
-                        + read_2_bytes (abfd, info_ptr));
+      attr->set_unsigned ((to_underlying (cu->header.sect_off)
+                          + read_2_bytes (abfd, info_ptr)));
       info_ptr += 2;
       break;
     case DW_FORM_ref4:
-      DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
-                        + read_4_bytes (abfd, info_ptr));
+      attr->set_unsigned ((to_underlying (cu->header.sect_off)
+                          + read_4_bytes (abfd, info_ptr)));
       info_ptr += 4;
       break;
     case DW_FORM_ref8:
-      DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
-                        + read_8_bytes (abfd, info_ptr));
+      attr->set_unsigned ((to_underlying (cu->header.sect_off)
+                          + read_8_bytes (abfd, info_ptr)));
       info_ptr += 8;
       break;
     case DW_FORM_ref_sig8:
-      DW_SIGNATURE (attr) = read_8_bytes (abfd, info_ptr);
+      attr->set_signature (read_8_bytes (abfd, info_ptr));
       info_ptr += 8;
       break;
     case DW_FORM_ref_udata:
-      DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
-                        + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
+      attr->set_unsigned ((to_underlying (cu->header.sect_off)
+                          + read_unsigned_leb128 (abfd, info_ptr,
+                                                  &bytes_read)));
       info_ptr += bytes_read;
       break;
     case DW_FORM_indirect:
@@ -19346,15 +20514,15 @@ read_attribute_value (const struct die_reader_specs *reader,
          info_ptr += bytes_read;
        }
       info_ptr = read_attribute_value (reader, attr, form, implicit_const,
-                                      info_ptr, need_reprocess);
+                                      info_ptr);
       break;
     case DW_FORM_implicit_const:
-      DW_SND (attr) = implicit_const;
+      attr->set_signed (implicit_const);
       break;
     case DW_FORM_addrx:
     case DW_FORM_GNU_addr_index:
-      *need_reprocess = true;
-      DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+      attr->set_unsigned_reprocess (read_unsigned_leb128 (abfd, info_ptr,
+                                                         &bytes_read));
       info_ptr += bytes_read;
       break;
     case DW_FORM_strx:
@@ -19390,9 +20558,8 @@ read_attribute_value (const struct die_reader_specs *reader,
            str_index = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
            info_ptr += bytes_read;
          }
-       *need_reprocess = true;
-        DW_UNSND (attr) = str_index;
-       }
+       attr->set_unsigned_reprocess (str_index);
+      }
       break;
     default:
       error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
@@ -19412,12 +20579,12 @@ read_attribute_value (const struct die_reader_specs *reader,
      treat them as zero by default.  */
   if (attr->name == DW_AT_byte_size
       && form == DW_FORM_data4
-      && DW_UNSND (attr) >= 0xffffffff)
+      && attr->as_unsigned () >= 0xffffffff)
     {
       complaint
-        (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
-         hex_string (DW_UNSND (attr)));
-      DW_UNSND (attr) = 0;
+       (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
+        hex_string (attr->as_unsigned ()));
+      attr->set_unsigned (0);
     }
 
   return info_ptr;
@@ -19428,22 +20595,23 @@ read_attribute_value (const struct die_reader_specs *reader,
 static const gdb_byte *
 read_attribute (const struct die_reader_specs *reader,
                struct attribute *attr, struct attr_abbrev *abbrev,
-               const gdb_byte *info_ptr, bool *need_reprocess)
+               const gdb_byte *info_ptr)
 {
   attr->name = abbrev->name;
+  attr->string_is_canonical = 0;
+  attr->requires_reprocessing = 0;
   return read_attribute_value (reader, attr, abbrev->form,
-                              abbrev->implicit_const, info_ptr,
-                              need_reprocess);
+                              abbrev->implicit_const, info_ptr);
 }
 
 /* Return pointer to string at .debug_str offset STR_OFFSET.  */
 
 static const char *
-read_indirect_string_at_offset (struct dwarf2_per_objfile *dwarf2_per_objfile,
+read_indirect_string_at_offset (dwarf2_per_objfile *per_objfile,
                                LONGEST str_offset)
 {
-  return dwarf2_per_objfile->per_bfd->str.read_string
-    (dwarf2_per_objfile->objfile, str_offset, "DW_FORM_strp");
+  return per_objfile->per_bfd->str.read_string (per_objfile->objfile,
+                                               str_offset, "DW_FORM_strp");
 }
 
 /* Return pointer to string at .debug_str offset as read from BUF.
@@ -19451,14 +20619,14 @@ read_indirect_string_at_offset (struct dwarf2_per_objfile *dwarf2_per_objfile,
    Return *BYTES_READ_PTR count of bytes read from BUF.  */
 
 static const char *
-read_indirect_string (struct dwarf2_per_objfile *dwarf2_per_objfile, bfd *abfd,
+read_indirect_string (dwarf2_per_objfile *per_objfile, bfd *abfd,
                      const gdb_byte *buf,
                      const struct comp_unit_head *cu_header,
                      unsigned int *bytes_read_ptr)
 {
   LONGEST str_offset = cu_header->read_offset (abfd, buf, bytes_read_ptr);
 
-  return read_indirect_string_at_offset (dwarf2_per_objfile, str_offset);
+  return read_indirect_string_at_offset (per_objfile, str_offset);
 }
 
 /* See read.h.  */
@@ -19479,26 +20647,25 @@ dwarf2_per_objfile::read_line_string (const gdb_byte *buf,
    ADDR_SIZE is the size of addresses from the CU header.  */
 
 static CORE_ADDR
-read_addr_index_1 (struct dwarf2_per_objfile *dwarf2_per_objfile,
-                  unsigned int addr_index, gdb::optional<ULONGEST> addr_base,
-                  int addr_size)
+read_addr_index_1 (dwarf2_per_objfile *per_objfile, unsigned int addr_index,
+                  gdb::optional<ULONGEST> addr_base, int addr_size)
 {
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
   bfd *abfd = objfile->obfd;
   const gdb_byte *info_ptr;
   ULONGEST addr_base_or_zero = addr_base.has_value () ? *addr_base : 0;
 
-  dwarf2_per_objfile->per_bfd->addr.read (objfile);
-  if (dwarf2_per_objfile->per_bfd->addr.buffer == NULL)
+  per_objfile->per_bfd->addr.read (objfile);
+  if (per_objfile->per_bfd->addr.buffer == NULL)
     error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
           objfile_name (objfile));
   if (addr_base_or_zero + addr_index * addr_size
-      >= dwarf2_per_objfile->per_bfd->addr.size)
+      >= per_objfile->per_bfd->addr.size)
     error (_("DW_FORM_addr_index pointing outside of "
             ".debug_addr section [in module %s]"),
           objfile_name (objfile));
-  info_ptr = (dwarf2_per_objfile->per_bfd->addr.buffer
-             + addr_base_or_zero + addr_index * addr_size);
+  info_ptr = (per_objfile->per_bfd->addr.buffer + addr_base_or_zero
+             + addr_index * addr_size);
   if (addr_size == 4)
     return bfd_get_32 (abfd, info_ptr);
   else
@@ -19530,10 +20697,10 @@ read_addr_index_from_leb128 (struct dwarf2_cu *cu, const gdb_byte *info_ptr,
 
 CORE_ADDR
 dwarf2_read_addr_index (dwarf2_per_cu_data *per_cu,
-                       dwarf2_per_objfile *dwarf2_per_objfile,
+                       dwarf2_per_objfile *per_objfile,
                        unsigned int addr_index)
 {
-  struct dwarf2_cu *cu = dwarf2_per_objfile->get_cu (per_cu);
+  struct dwarf2_cu *cu = per_objfile->get_cu (per_cu);
   gdb::optional<ULONGEST> addr_base;
   int addr_size;
 
@@ -19560,13 +20727,12 @@ dwarf2_read_addr_index (dwarf2_per_cu_data *per_cu,
     }
   else
     {
-      cutu_reader reader (per_cu, dwarf2_per_objfile, nullptr, nullptr, false);
+      cutu_reader reader (per_cu, per_objfile, nullptr, nullptr, false);
       addr_base = reader.cu->addr_base;
       addr_size = reader.cu->header.addr_size;
     }
 
-  return read_addr_index_1 (dwarf2_per_objfile, addr_index, addr_base,
-                           addr_size);
+  return read_addr_index_1 (per_objfile, addr_index, addr_base, addr_size);
 }
 
 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
@@ -19579,8 +20745,8 @@ read_str_index (struct dwarf2_cu *cu,
                struct dwarf2_section_info *str_offsets_section,
                ULONGEST str_offsets_base, ULONGEST str_index)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   const char *objf_name = objfile_name (objfile);
   bfd *abfd = objfile->obfd;
   const gdb_byte *info_ptr;
@@ -19593,12 +20759,12 @@ read_str_index (struct dwarf2_cu *cu,
     error (_("%s used without %s section"
             " in CU at offset %s [in module %s]"),
           form_name, str_section->get_name (),
-           sect_offset_str (cu->header.sect_off), objf_name);
+          sect_offset_str (cu->header.sect_off), objf_name);
   if (str_offsets_section->buffer == NULL)
     error (_("%s used without %s section"
             " in CU at offset %s [in module %s]"),
           form_name, str_section->get_name (),
-           sect_offset_str (cu->header.sect_off), objf_name);
+          sect_offset_str (cu->header.sect_off), objf_name);
   info_ptr = (str_offsets_section->buffer
              + str_offsets_base
              + str_index * cu->header.offset_size);
@@ -19765,9 +20931,9 @@ dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *c
 
   if (attr != NULL)
     {
-      str = attr->value_as_string ();
+      str = attr->as_string ();
       if (str == nullptr)
-        complaint (_("string type expected for attribute %s for "
+       complaint (_("string type expected for attribute %s for "
                     "DIE at %s in module %s"),
                   dwarf_attr_name (name), sect_offset_str (die->sect_off),
                   objfile_name (cu->per_objfile->objfile));
@@ -19796,7 +20962,7 @@ dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
 {
   struct attribute *attr = dwarf2_attr (die, name, cu);
 
-  return (attr && DW_UNSND (attr));
+  return attr != nullptr && attr->as_boolean ();
 }
 
 static int
@@ -19850,7 +21016,7 @@ static struct dwarf2_section_info *
 get_debug_line_section (struct dwarf2_cu *cu)
 {
   struct dwarf2_section_info *section;
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
 
   /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
      DWO file.  */
@@ -19858,12 +21024,12 @@ get_debug_line_section (struct dwarf2_cu *cu)
     section = &cu->dwo_unit->dwo_file->sections.line;
   else if (cu->per_cu->is_dwz)
     {
-      dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
+      dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
 
       section = &dwz->line;
     }
   else
-    section = &dwarf2_per_objfile->per_bfd->line;
+    section = &per_objfile->per_bfd->line;
 
   return section;
 }
@@ -19882,10 +21048,10 @@ static line_header_up
 dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
 {
   struct dwarf2_section_info *section;
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
 
   section = get_debug_line_section (cu);
-  section->read (dwarf2_per_objfile->objfile);
+  section->read (per_objfile->objfile);
   if (section->buffer == NULL)
     {
       if (cu->dwo_unit && cu->per_cu->is_debug_types)
@@ -19896,8 +21062,7 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
     }
 
   return dwarf_decode_line_header (sect_off, cu->per_cu->is_dwz,
-                                  dwarf2_per_objfile, section,
-                                  &cu->header);
+                                  per_objfile, section, &cu->header);
 }
 
 /* Subroutine of dwarf_decode_lines to simplify it.
@@ -19996,7 +21161,7 @@ public:
      we're processing the end of a sequence.  */
   void record_line (bool end_sequence);
 
-  /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
+  /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
      nop-out rest of the lines in this sequence.  */
   void check_line_address (struct dwarf2_cu *cu,
                           const gdb_byte *line_ptr,
@@ -20104,6 +21269,15 @@ private:
   /* The last file a line number was recorded for.  */
   struct subfile *m_last_subfile = NULL;
 
+  /* The address of the last line entry.  */
+  CORE_ADDR m_last_address;
+
+  /* Set to true when a previous line at the same address (using
+     m_last_address) had m_is_stmt true.  This is reset to false when a
+     line entry at a new address (m_address different to m_last_address) is
+     processed.  */
+  bool m_stmt_at_address = false;
+
   /* When true, record the lines we decode.  */
   bool m_currently_recording_lines = false;
 
@@ -20297,14 +21471,35 @@ lnp_state_machine::record_line (bool end_sequence)
       fe->included_p = 1;
       if (m_record_lines_p)
        {
-         if (m_last_subfile != m_cu->get_builder ()->get_current_subfile ()
-             || end_sequence)
+         /* When we switch files we insert an end maker in the first file,
+            switch to the second file and add a new line entry.  The
+            problem is that the end marker inserted in the first file will
+            discard any previous line entries at the same address.  If the
+            line entries in the first file are marked as is-stmt, while
+            the new line in the second file is non-stmt, then this means
+            the end marker will discard is-stmt lines so we can have a
+            non-stmt line.  This means that there are less addresses at
+            which the user can insert a breakpoint.
+
+            To improve this we track the last address in m_last_address,
+            and whether we have seen an is-stmt at this address.  Then
+            when switching files, if we have seen a stmt at the current
+            address, and we are switching to create a non-stmt line, then
+            discard the new line.  */
+         bool file_changed
+           = m_last_subfile != m_cu->get_builder ()->get_current_subfile ();
+         bool ignore_this_line
+          = ((file_changed && !end_sequence && m_last_address == m_address
+              && !m_is_stmt && m_stmt_at_address)
+             || (!end_sequence && m_line == 0));
+
+         if ((file_changed && !ignore_this_line) || end_sequence)
            {
              dwarf_finish_line (m_gdbarch, m_last_subfile, m_address,
                                 m_currently_recording_lines ? m_cu : nullptr);
            }
 
-         if (!end_sequence)
+         if (!end_sequence && !ignore_this_line)
            {
              bool is_stmt = producer_is_codewarrior (m_cu) || m_is_stmt;
 
@@ -20323,6 +21518,15 @@ lnp_state_machine::record_line (bool end_sequence)
            }
        }
     }
+
+  /* Track whether we have seen any m_is_stmt true at m_address in case we
+     have multiple line table entries all at m_address.  */
+  if (m_last_address != m_address)
+    {
+      m_stmt_at_address = false;
+      m_last_address = m_address;
+    }
+  m_stmt_at_address |= m_is_stmt;
 }
 
 lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch,
@@ -20342,6 +21546,9 @@ lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch,
   m_address = gdbarch_adjust_dwarf2_line (arch, 0, 0);
   m_is_stmt = lh->default_is_stmt;
   m_discriminator = 0;
+
+  m_last_address = m_address;
+  m_stmt_at_address = false;
 }
 
 void
@@ -20349,12 +21556,13 @@ lnp_state_machine::check_line_address (struct dwarf2_cu *cu,
                                       const gdb_byte *line_ptr,
                                       CORE_ADDR unrelocated_lowpc, CORE_ADDR address)
 {
-  /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
-     the pc range of the CU.  However, we restrict the test to only ADDRESS
-     values of zero to preserve GDB's previous behaviour which is to handle
-     the specific case of a function being GC'd by the linker.  */
+  /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
+     -1.  If ADDRESS is 0, ignoring the opcode will err if the text section is
+     located at 0x0.  In this case, additionally check that if
+     ADDRESS < UNRELOCATED_LOWPC.  */
 
-  if (address == 0 && address < unrelocated_lowpc)
+  if ((address == 0 && address < unrelocated_lowpc)
+      || address == (CORE_ADDR) -1)
     {
       /* This line table is for a function which has been
         GCd by the linker.  Ignore it.  PR gdb/12528 */
@@ -20435,6 +21643,13 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
              extended_end = line_ptr + extended_len;
              extended_op = read_1_byte (abfd, line_ptr);
              line_ptr += 1;
+             if (DW_LNE_lo_user <= extended_op
+                 && extended_op <= DW_LNE_hi_user)
+               {
+                 /* Vendor extension, ignore.  */
+                 line_ptr = extended_end;
+                 break;
+               }
              switch (extended_op)
                {
                case DW_LNE_end_sequence:
@@ -20453,25 +21668,25 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
                  }
                  break;
                case DW_LNE_define_file:
-                  {
-                    const char *cur_file;
+                 {
+                   const char *cur_file;
                    unsigned int mod_time, length;
                    dir_index dindex;
 
-                    cur_file = read_direct_string (abfd, line_ptr,
+                   cur_file = read_direct_string (abfd, line_ptr,
                                                   &bytes_read);
-                    line_ptr += bytes_read;
-                    dindex = (dir_index)
-                      read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
-                    line_ptr += bytes_read;
-                    mod_time =
-                      read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
-                    line_ptr += bytes_read;
-                    length =
-                      read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
-                    line_ptr += bytes_read;
-                    lh->add_file_name (cur_file, dindex, mod_time, length);
-                  }
+                   line_ptr += bytes_read;
+                   dindex = (dir_index)
+                     read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+                   line_ptr += bytes_read;
+                   mod_time =
+                     read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+                   line_ptr += bytes_read;
+                   length =
+                     read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+                   line_ptr += bytes_read;
+                   lh->add_file_name (cur_file, dindex, mod_time, length);
+                 }
                  break;
                case DW_LNE_set_discriminator:
                  {
@@ -20622,17 +21837,17 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
   if (decode_for_pst_p)
     {
       /* Now that we're done scanning the Line Header Program, we can
-         create the psymtab of each included file.  */
+        create the psymtab of each included file.  */
       for (auto &file_entry : lh->file_names ())
-        if (file_entry.included_p == 1)
-          {
+       if (file_entry.included_p == 1)
+         {
            gdb::unique_xmalloc_ptr<char> name_holder;
            const char *include_name =
              psymtab_include_file_name (lh, file_entry, pst,
                                         comp_dir, &name_holder);
            if (include_name != NULL)
-              dwarf2_create_include_psymtab (include_name, pst, objfile);
-          }
+             dwarf2_create_include_psymtab (include_name, pst, objfile);
+         }
     }
   else
     {
@@ -20743,7 +21958,7 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
 
   /* A DW_AT_location attribute with no contents indicates that a
      variable has been optimized away.  */
-  if (attr->form_is_block () && DW_BLOCK (attr)->size == 0)
+  if (attr->form_is_block () && attr->as_block ()->size == 0)
     {
       SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
       return;
@@ -20754,32 +21969,36 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
      specified.  If this is just a DW_OP_addr, DW_OP_addrx, or
      DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC.  */
 
-  if (attr->form_is_block ()
-      && ((DW_BLOCK (attr)->data[0] == DW_OP_addr
-          && DW_BLOCK (attr)->size == 1 + cu_header->addr_size)
-         || ((DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index
-               || DW_BLOCK (attr)->data[0] == DW_OP_addrx)
-             && (DW_BLOCK (attr)->size
-                 == 1 + leb128_size (&DW_BLOCK (attr)->data[1])))))
-    {
-      unsigned int dummy;
-
-      if (DW_BLOCK (attr)->data[0] == DW_OP_addr)
-       SET_SYMBOL_VALUE_ADDRESS
-         (sym, cu->header.read_address (objfile->obfd,
-                                        DW_BLOCK (attr)->data + 1,
-                                        &dummy));
-      else
-       SET_SYMBOL_VALUE_ADDRESS
-         (sym, read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1,
+  if (attr->form_is_block ())
+    {
+      struct dwarf_block *block = attr->as_block ();
+
+      if ((block->data[0] == DW_OP_addr
+          && block->size == 1 + cu_header->addr_size)
+         || ((block->data[0] == DW_OP_GNU_addr_index
+              || block->data[0] == DW_OP_addrx)
+             && (block->size
+                 == 1 + leb128_size (&block->data[1]))))
+       {
+         unsigned int dummy;
+
+         if (block->data[0] == DW_OP_addr)
+           SET_SYMBOL_VALUE_ADDRESS
+             (sym, cu->header.read_address (objfile->obfd,
+                                            block->data + 1,
                                             &dummy));
-      SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
-      fixup_symbol_section (sym, objfile);
-      SET_SYMBOL_VALUE_ADDRESS
-       (sym,
-        SYMBOL_VALUE_ADDRESS (sym)
-        + objfile->section_offsets[SYMBOL_SECTION (sym)]);
-      return;
+         else
+           SET_SYMBOL_VALUE_ADDRESS
+             (sym, read_addr_index_from_leb128 (cu, block->data + 1,
+                                                &dummy));
+         SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
+         fixup_symbol_section (sym, objfile);
+         SET_SYMBOL_VALUE_ADDRESS
+           (sym,
+            SYMBOL_VALUE_ADDRESS (sym)
+            + objfile->section_offsets[SYMBOL_SECTION (sym)]);
+         return;
+       }
     }
 
   /* NOTE drow/2002-01-30: It might be worthwhile to have a static
@@ -20807,8 +22026,8 @@ static struct symbol *
 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
            struct symbol *space)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
   struct symbol *sym = NULL;
   const char *name;
@@ -20851,7 +22070,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
        }
 
       /* Default assumptions.
-         Use the passed type or decode it from the die.  */
+        Use the passed type or decode it from the die.  */
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
       if (type != NULL)
@@ -20862,16 +22081,15 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
                          inlined_func ? DW_AT_call_line : DW_AT_decl_line,
                          cu);
       if (attr != nullptr)
-       {
-         SYMBOL_LINE (sym) = DW_UNSND (attr);
-       }
+       SYMBOL_LINE (sym) = attr->constant_value (0);
 
       attr = dwarf2_attr (die,
                          inlined_func ? DW_AT_call_file : DW_AT_decl_file,
                          cu);
-      if (attr != nullptr)
+      if (attr != nullptr && attr->form_is_unsigned ())
        {
-         file_name_index file_index = (file_name_index) DW_UNSND (attr);
+         file_name_index file_index
+           = (file_name_index) attr->as_unsigned ();
          struct file_entry *fe;
 
          if (cu->line_header != NULL)
@@ -20893,13 +22111,15 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
            {
              CORE_ADDR addr;
 
-             addr = attr->value_as_address ();
+             addr = attr->as_address ();
              addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr);
              SET_SYMBOL_VALUE_ADDRESS (sym, addr);
+             SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
            }
+         else
+           SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
          SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
          SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
-         SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
          add_symbol_to_list (sym, cu->list_in_scope);
          break;
        case DW_TAG_subprogram:
@@ -20907,16 +22127,16 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
             finish_block.  */
          SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
          attr2 = dwarf2_attr (die, DW_AT_external, cu);
-         if ((attr2 && (DW_UNSND (attr2) != 0))
+         if ((attr2 != nullptr && attr2->as_boolean ())
              || cu->language == language_ada
              || cu->language == language_fortran)
            {
-              /* Subprograms marked external are stored as a global symbol.
-                 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.  */
+             /* Subprograms marked external are stored as a global symbol.
+                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
@@ -20959,7 +22179,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
              attr2 = dwarf2_attr (die, DW_AT_external, cu);
              if (!suppress_add)
                {
-                 if (attr2 && (DW_UNSND (attr2) != 0))
+                 if (attr2 != nullptr && attr2->as_boolean ())
                    list_to_add = cu->get_builder ()->get_global_symbols ();
                  else
                    list_to_add = cu->list_in_scope;
@@ -20980,18 +22200,18 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 
              if (SYMBOL_CLASS (sym) == LOC_STATIC
                  && SYMBOL_VALUE_ADDRESS (sym) == 0
-                 && !dwarf2_per_objfile->per_bfd->has_section_at_zero)
+                 && !per_objfile->per_bfd->has_section_at_zero)
                {
                  /* When a static variable is eliminated by the linker,
                     the corresponding debug information is not stripped
                     out, but the variable address is set to null;
                     do not add such variables into symbol table.  */
                }
-             else if (attr2 && (DW_UNSND (attr2) != 0))
+             else if (attr2 != nullptr && attr2->as_boolean ())
                {
                  if (SYMBOL_CLASS (sym) == LOC_STATIC
                      && (objfile->flags & OBJF_MAINLINE) == 0
-                     && dwarf2_per_objfile->per_bfd->can_copy)
+                     && per_objfile->per_bfd->can_copy)
                    {
                      /* A global static variable might be subject to
                         copy relocation.  We first check for a local
@@ -21019,11 +22239,11 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
          else
            {
              /* We do not know the address of this symbol.
-                If it is an external symbol and we have type information
-                for it, enter the symbol as a LOC_UNRESOLVED symbol.
-                The address of the variable will then be determined from
-                the minimal symbol table whenever the variable is
-                referenced.  */
+                If it is an external symbol and we have type information
+                for it, enter the symbol as a LOC_UNRESOLVED symbol.
+                The address of the variable will then be determined from
+                the minimal symbol table whenever the variable is
+                referenced.  */
              attr2 = dwarf2_attr (die, DW_AT_external, cu);
 
              /* Fortran explicitly imports any global symbols to the local
@@ -21036,7 +22256,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
                  if (!suppress_add)
                    list_to_add = cu->list_in_scope;
                }
-             else if (attr2 && (DW_UNSND (attr2) != 0)
+             else if (attr2 != nullptr && attr2->as_boolean ()
                       && dwarf2_attr (die, DW_AT_type, cu) != NULL)
                {
                  /* A variable with DW_AT_external is never static, but it
@@ -21139,8 +22359,9 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
          SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
          list_to_add = cu->list_in_scope;
          break;
+       case DW_TAG_array_type:
        case DW_TAG_base_type:
-        case DW_TAG_subrange_type:
+       case DW_TAG_subrange_type:
          SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
          SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
          list_to_add = cu->list_in_scope;
@@ -21221,7 +22442,7 @@ dwarf2_const_value_data (const struct attribute *attr, struct obstack *obstack,
   struct objfile *objfile = cu->per_objfile->objfile;
   enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
                                BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
-  LONGEST l = DW_UNSND (attr);
+  LONGEST l = attr->constant_value (0);
 
   if (bits < sizeof (*value) * 8)
     {
@@ -21290,7 +22511,7 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
 
        data[0] = DW_OP_addr;
        store_unsigned_integer (&data[1], cu_header->addr_size,
-                               byte_order, DW_ADDR (attr));
+                               byte_order, attr->as_address ());
        data[cu_header->addr_size + 1] = DW_OP_stack_value;
       }
       break;
@@ -21299,9 +22520,9 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
     case DW_FORM_strx:
     case DW_FORM_GNU_str_index:
     case DW_FORM_GNU_strp_alt:
-      /* DW_STRING is already allocated on the objfile obstack, point
+      /* The string is already allocated on the objfile obstack, point
         directly to it.  */
-      *bytes = (const gdb_byte *) DW_STRING (attr);
+      *bytes = (const gdb_byte *) attr->as_string ();
       break;
     case DW_FORM_block1:
     case DW_FORM_block2:
@@ -21309,7 +22530,7 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
     case DW_FORM_block:
     case DW_FORM_exprloc:
     case DW_FORM_data16:
-      blk = DW_BLOCK (attr);
+      blk = attr->as_block ();
       if (TYPE_LENGTH (type) != blk->size)
        dwarf2_const_value_length_mismatch_complaint (name, blk->size,
                                                      TYPE_LENGTH (type));
@@ -21336,11 +22557,11 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
 
     case DW_FORM_sdata:
     case DW_FORM_implicit_const:
-      *value = DW_SND (attr);
+      *value = attr->as_signed ();
       break;
 
     case DW_FORM_udata:
-      *value = DW_UNSND (attr);
+      *value = attr->as_unsigned ();
       break;
 
     default:
@@ -21469,8 +22690,8 @@ die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
 static struct type *
 build_error_marker_type (struct dwarf2_cu *cu, struct die_info *die)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   char *saved;
 
   std::string message
@@ -21492,8 +22713,8 @@ static struct type *
 lookup_die_type (struct die_info *die, const struct attribute *attr,
                 struct dwarf2_cu *cu)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct type *this_type;
 
   gdb_assert (attr->name == DW_AT_type
@@ -21507,20 +22728,18 @@ lookup_die_type (struct die_info *die, const struct attribute *attr,
       struct dwarf2_per_cu_data *per_cu;
       sect_offset sect_off = attr->get_ref_die_offset ();
 
-      per_cu = dwarf2_find_containing_comp_unit (sect_off, 1,
-                                                dwarf2_per_objfile);
-      this_type = get_die_type_at_offset (sect_off, per_cu, dwarf2_per_objfile);
+      per_cu = dwarf2_find_containing_comp_unit (sect_off, 1, per_objfile);
+      this_type = get_die_type_at_offset (sect_off, per_cu, per_objfile);
     }
   else if (attr->form_is_ref ())
     {
       sect_offset sect_off = attr->get_ref_die_offset ();
 
-      this_type = get_die_type_at_offset (sect_off, cu->per_cu,
-                                         dwarf2_per_objfile);
+      this_type = get_die_type_at_offset (sect_off, cu->per_cu, per_objfile);
     }
   else if (attr->form == DW_FORM_ref_sig8)
     {
-      ULONGEST signature = DW_SIGNATURE (attr);
+      ULONGEST signature = attr->as_signature ();
 
       return get_signatured_type (die, signature, cu);
     }
@@ -21697,8 +22916,7 @@ guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
          if (linkage_name != NULL)
            {
              gdb::unique_xmalloc_ptr<char> actual_name
-               (language_class_name_from_physname (cu->language_defn,
-                                                   linkage_name));
+               (cu->language_defn->class_name_from_physname (linkage_name));
              const char *name = NULL;
 
              if (actual_name != NULL)
@@ -21748,21 +22966,22 @@ anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
     return NULL;
 
   attr = dw2_linkage_name_attr (die, cu);
-  if (attr == NULL || DW_STRING (attr) == NULL)
+  const char *attr_name = attr->as_string ();
+  if (attr == NULL || attr_name == NULL)
     return NULL;
 
   /* dwarf2_name had to be already called.  */
-  gdb_assert (DW_STRING_IS_CANONICAL (attr));
+  gdb_assert (attr->canonical_string_p ());
 
   /* Strip the base name, keep any leading namespaces/classes.  */
-  base = strrchr (DW_STRING (attr), ':');
-  if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
+  base = strrchr (attr_name, ':');
+  if (base == NULL || base == attr_name || base[-1] != ':')
     return "";
 
   struct objfile *objfile = cu->per_objfile->objfile;
   return obstack_strndup (&objfile->per_bfd->storage_obstack,
-                         DW_STRING (attr),
-                         &base[-1] - DW_STRING (attr));
+                         attr_name,
+                         &base[-1] - attr_name);
 }
 
 /* Return the name of the namespace/class that DIE is defined within,
@@ -21783,7 +23002,7 @@ anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
 static const char *
 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct die_info *parent, *spec_die;
   struct dwarf2_cu *spec_cu;
   struct type *parent_type;
@@ -21843,13 +23062,13 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
         template class <class Enum> Class{};
         Class<enum E> class_e;
 
-         1: DW_TAG_class_type (Class)
-           2: DW_TAG_enumeration_type (E)
-             3: DW_TAG_enumerator (enum1:0)
-             3: DW_TAG_enumerator (enum2:1)
-             ...
-           2: DW_TAG_template_type_param
-              DW_AT_type  DW_FORM_ref_udata (E)
+        1: DW_TAG_class_type (Class)
+          2: DW_TAG_enumeration_type (E)
+            3: DW_TAG_enumerator (enum1:0)
+            3: DW_TAG_enumerator (enum2:1)
+            ...
+          2: DW_TAG_template_type_param
+             DW_AT_type  DW_FORM_ref_udata (E)
 
         Besides being broken debug info, it can put GDB into an
         infinite loop.  Consider:
@@ -21901,7 +23120,7 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
       case DW_TAG_partial_unit:
        /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace.  Cope.  */
        if (cu->language == language_cplus
-           && !dwarf2_per_objfile->per_bfd->types.empty ()
+           && !per_objfile->per_bfd->types.empty ()
            && die->child != NULL
            && (die->tag == DW_TAG_class_type
                || die->tag == DW_TAG_structure_type
@@ -21946,7 +23165,7 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
 
 static char *
 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
-                 int physname, struct dwarf2_cu *cu)
+                int physname, struct dwarf2_cu *cu)
 {
   const char *lead = "";
   const char *sep;
@@ -22029,7 +23248,8 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
   struct objfile *objfile = cu->per_objfile->objfile;
 
   attr = dwarf2_attr (die, DW_AT_name, cu);
-  if ((!attr || !DW_STRING (attr))
+  const char *attr_name = attr == nullptr ? nullptr : attr->as_string ();
+  if (attr_name == nullptr
       && die->tag != DW_TAG_namespace
       && die->tag != DW_TAG_class_type
       && die->tag != DW_TAG_interface_type
@@ -22047,11 +23267,11 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_enumerator:
       /* These tags always have simple identifiers already; no need
         to canonicalize them.  */
-      return DW_STRING (attr);
+      return attr_name;
 
     case DW_TAG_namespace:
-      if (attr != NULL && DW_STRING (attr) != NULL)
-       return DW_STRING (attr);
+      if (attr_name != nullptr)
+       return attr_name;
       return CP_ANONYMOUS_NAMESPACE_STR;
 
     case DW_TAG_class_type:
@@ -22062,39 +23282,41 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
         structures or unions.  These were of the form "._%d" in GCC 4.1,
         or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
         and GCC 4.4.  We work around this problem by ignoring these.  */
-      if (attr && DW_STRING (attr)
-         && (startswith (DW_STRING (attr), "._")
-             || startswith (DW_STRING (attr), "<anonymous")))
+      if (attr_name != nullptr
+         && (startswith (attr_name, "._")
+             || startswith (attr_name, "<anonymous")))
        return NULL;
 
       /* GCC might emit a nameless typedef that has a linkage name.  See
         http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510.  */
-      if (!attr || DW_STRING (attr) == NULL)
+      if (!attr || attr_name == NULL)
        {
          attr = dw2_linkage_name_attr (die, cu);
-         if (attr == NULL || DW_STRING (attr) == NULL)
+         attr_name = attr == nullptr ? nullptr : attr->as_string ();
+         if (attr == NULL || attr_name == NULL)
            return NULL;
 
-         /* Avoid demangling DW_STRING (attr) the second time on a second
+         /* Avoid demangling attr_name the second time on a second
             call for the same DIE.  */
-         if (!DW_STRING_IS_CANONICAL (attr))
+         if (!attr->canonical_string_p ())
            {
              gdb::unique_xmalloc_ptr<char> demangled
-               (gdb_demangle (DW_STRING (attr), DMGL_TYPES));
+               (gdb_demangle (attr_name, DMGL_TYPES));
              if (demangled == nullptr)
                return nullptr;
 
-             DW_STRING (attr) = objfile->intern (demangled.get ());
-             DW_STRING_IS_CANONICAL (attr) = 1;
+             attr->set_string_canonical (objfile->intern (demangled.get ()));
+             attr_name = attr->as_string ();
            }
 
-         /* Strip any leading namespaces/classes, keep only the base name.
-            DW_AT_name for named DIEs does not contain the prefixes.  */
-         const char *base = strrchr (DW_STRING (attr), ':');
-         if (base && base > DW_STRING (attr) && base[-1] == ':')
+         /* Strip any leading namespaces/classes, keep only the
+            base name.  DW_AT_name for named DIEs does not
+            contain the prefixes.  */
+         const char *base = strrchr (attr_name, ':');
+         if (base && base > attr_name && base[-1] == ':')
            return &base[1];
          else
-           return DW_STRING (attr);
+           return attr_name;
        }
       break;
 
@@ -22102,13 +23324,10 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
       break;
     }
 
-  if (!DW_STRING_IS_CANONICAL (attr))
-    {
-      DW_STRING (attr) = dwarf2_canonicalize_name (DW_STRING (attr), cu,
-                                                  objfile);
-      DW_STRING_IS_CANONICAL (attr) = 1;
-    }
-  return DW_STRING (attr);
+  if (!attr->canonical_string_p ())
+    attr->set_string_canonical (dwarf2_canonicalize_name (attr_name, cu,
+                                                         objfile));
+  return attr->as_string ();
 }
 
 /* Return the die that this die in an extension of, or NULL if there
@@ -22164,29 +23383,29 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
        case DW_FORM_addrx:
        case DW_FORM_GNU_addr_index:
          fprintf_unfiltered (f, "address: ");
-         fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
+         fputs_filtered (hex_string (die->attrs[i].as_address ()), f);
          break;
        case DW_FORM_block2:
        case DW_FORM_block4:
        case DW_FORM_block:
        case DW_FORM_block1:
          fprintf_unfiltered (f, "block: size %s",
-                             pulongest (DW_BLOCK (&die->attrs[i])->size));
+                             pulongest (die->attrs[i].as_block ()->size));
          break;
        case DW_FORM_exprloc:
          fprintf_unfiltered (f, "expression: size %s",
-                             pulongest (DW_BLOCK (&die->attrs[i])->size));
+                             pulongest (die->attrs[i].as_block ()->size));
          break;
        case DW_FORM_data16:
          fprintf_unfiltered (f, "constant of 16 bytes");
          break;
        case DW_FORM_ref_addr:
          fprintf_unfiltered (f, "ref address: ");
-         fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
+         fputs_filtered (hex_string (die->attrs[i].as_unsigned ()), f);
          break;
        case DW_FORM_GNU_ref_alt:
          fprintf_unfiltered (f, "alt ref address: ");
-         fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
+         fputs_filtered (hex_string (die->attrs[i].as_unsigned ()), f);
          break;
        case DW_FORM_ref1:
        case DW_FORM_ref2:
@@ -22194,24 +23413,23 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
        case DW_FORM_ref8:
        case DW_FORM_ref_udata:
          fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
-                             (long) (DW_UNSND (&die->attrs[i])));
+                             (long) (die->attrs[i].as_unsigned ()));
          break;
        case DW_FORM_data1:
        case DW_FORM_data2:
        case DW_FORM_data4:
        case DW_FORM_data8:
        case DW_FORM_udata:
-       case DW_FORM_sdata:
          fprintf_unfiltered (f, "constant: %s",
-                             pulongest (DW_UNSND (&die->attrs[i])));
+                             pulongest (die->attrs[i].as_unsigned ()));
          break;
        case DW_FORM_sec_offset:
          fprintf_unfiltered (f, "section offset: %s",
-                             pulongest (DW_UNSND (&die->attrs[i])));
+                             pulongest (die->attrs[i].as_unsigned ()));
          break;
        case DW_FORM_ref_sig8:
          fprintf_unfiltered (f, "signature: %s",
-                             hex_string (DW_SIGNATURE (&die->attrs[i])));
+                             hex_string (die->attrs[i].as_signature ()));
          break;
        case DW_FORM_string:
        case DW_FORM_strp:
@@ -22220,12 +23438,12 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
        case DW_FORM_GNU_str_index:
        case DW_FORM_GNU_strp_alt:
          fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
-                  DW_STRING (&die->attrs[i])
-                  ? DW_STRING (&die->attrs[i]) : "",
-                  DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
+                             die->attrs[i].as_string ()
+                             ? die->attrs[i].as_string () : "",
+                             die->attrs[i].canonical_string_p () ? "is" : "not");
          break;
        case DW_FORM_flag:
-         if (DW_UNSND (&die->attrs[i]))
+         if (die->attrs[i].as_boolean ())
            fprintf_unfiltered (f, "flag: TRUE");
          else
            fprintf_unfiltered (f, "flag: FALSE");
@@ -22239,9 +23457,10 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
          fprintf_unfiltered (f,
                              "unexpected attribute form: DW_FORM_indirect");
          break;
+       case DW_FORM_sdata:
        case DW_FORM_implicit_const:
          fprintf_unfiltered (f, "constant: %s",
-                             plongest (DW_SND (&die->attrs[i])));
+                             plongest (die->attrs[i].as_signed ()));
          break;
        default:
          fprintf_unfiltered (f, "unsupported attribute form: %d.",
@@ -22348,7 +23567,7 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
 {
   struct die_info temp_die;
   struct dwarf2_cu *target_cu, *cu = *ref_cu;
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
 
   gdb_assert (cu->per_cu != NULL);
 
@@ -22368,19 +23587,20 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
       struct dwarf2_per_cu_data *per_cu;
 
       per_cu = dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz,
-                                                dwarf2_per_objfile);
+                                                per_objfile);
 
       /* If necessary, add it to the queue and load its DIEs.  */
-      if (maybe_queue_comp_unit (cu, per_cu, dwarf2_per_objfile, cu->language))
-       load_full_comp_unit (per_cu, dwarf2_per_objfile, false, cu->language);
+      if (maybe_queue_comp_unit (cu, per_cu, per_objfile, cu->language))
+       load_full_comp_unit (per_cu, per_objfile, per_objfile->get_cu (per_cu),
+                            false, cu->language);
 
-      target_cu = dwarf2_per_objfile->get_cu (per_cu);
+      target_cu = per_objfile->get_cu (per_cu);
     }
   else if (cu->dies == NULL)
     {
       /* We're loading full DIEs during partial symbol reading.  */
-      gdb_assert (dwarf2_per_objfile->per_bfd->reading_partial_symbols);
-      load_full_comp_unit (cu->per_cu, dwarf2_per_objfile, false,
+      gdb_assert (per_objfile->per_bfd->reading_partial_symbols);
+      load_full_comp_unit (cu->per_cu, per_objfile, cu, false,
                           language_minimal);
     }
 
@@ -22425,18 +23645,18 @@ follow_die_ref (struct die_info *src_die, const struct attribute *attr,
 struct dwarf2_locexpr_baton
 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
                               dwarf2_per_cu_data *per_cu,
-                              dwarf2_per_objfile *dwarf2_per_objfile,
-                              CORE_ADDR (*get_frame_pc) (void *baton),
-                              void *baton, bool resolve_abstract_p)
+                              dwarf2_per_objfile *per_objfile,
+                              gdb::function_view<CORE_ADDR ()> get_frame_pc,
+                              bool resolve_abstract_p)
 {
   struct die_info *die;
   struct attribute *attr;
   struct dwarf2_locexpr_baton retval;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
 
-  dwarf2_cu *cu = dwarf2_per_objfile->get_cu (per_cu);
+  dwarf2_cu *cu = per_objfile->get_cu (per_cu);
   if (cu == nullptr)
-    cu = load_cu (per_cu, dwarf2_per_objfile, false);
+    cu = load_cu (per_cu, per_objfile, false);
 
   if (cu == nullptr)
     {
@@ -22453,15 +23673,15 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
 
   attr = dwarf2_attr (die, DW_AT_location, cu);
   if (!attr && resolve_abstract_p
-      && (dwarf2_per_objfile->per_bfd->abstract_to_concrete.find (die->sect_off)
-         != dwarf2_per_objfile->per_bfd->abstract_to_concrete.end ()))
+      && (per_objfile->per_bfd->abstract_to_concrete.find (die->sect_off)
+         != per_objfile->per_bfd->abstract_to_concrete.end ()))
     {
-      CORE_ADDR pc = (*get_frame_pc) (baton);
+      CORE_ADDR pc = get_frame_pc ();
       CORE_ADDR baseaddr = objfile->text_section_offset ();
       struct gdbarch *gdbarch = objfile->arch ();
 
       for (const auto &cand_off
-            : dwarf2_per_objfile->per_bfd->abstract_to_concrete[die->sect_off])
+            : per_objfile->per_bfd->abstract_to_concrete[die->sect_off])
        {
          struct dwarf2_cu *cand_cu = cu;
          struct die_info *cand
@@ -22497,7 +23717,7 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
   else if (attr->form_is_section_offset ())
     {
       struct dwarf2_loclist_baton loclist_baton;
-      CORE_ADDR pc = (*get_frame_pc) (baton);
+      CORE_ADDR pc = get_frame_pc ();
       size_t size;
 
       fill_in_loclist_baton (cu, &loclist_baton, attr);
@@ -22513,13 +23733,14 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
                 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
               sect_offset_str (sect_off), objfile_name (objfile));
 
-      retval.data = DW_BLOCK (attr)->data;
-      retval.size = DW_BLOCK (attr)->size;
+      struct dwarf_block *block = attr->as_block ();
+      retval.data = block->data;
+      retval.size = block->size;
     }
-  retval.per_objfile = dwarf2_per_objfile;
+  retval.per_objfile = per_objfile;
   retval.per_cu = cu->per_cu;
 
-  dwarf2_per_objfile->age_comp_units ();
+  per_objfile->age_comp_units ();
 
   return retval;
 }
@@ -22530,13 +23751,12 @@ struct dwarf2_locexpr_baton
 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu,
                             dwarf2_per_cu_data *per_cu,
                             dwarf2_per_objfile *per_objfile,
-                            CORE_ADDR (*get_frame_pc) (void *baton),
-                            void *baton)
+                            gdb::function_view<CORE_ADDR ()> get_frame_pc)
 {
   sect_offset sect_off = per_cu->sect_off + to_underlying (offset_in_cu);
 
   return dwarf2_fetch_die_loc_sect_off (sect_off, per_cu, per_objfile,
-                                       get_frame_pc, baton);
+                                       get_frame_pc);
 }
 
 /* Write a constant of a given type as target-ordered bytes into
@@ -22609,7 +23829,7 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
 
        *len = cu->header.addr_size;
        tem = (gdb_byte *) obstack_alloc (obstack, *len);
-       store_unsigned_integer (tem, *len, byte_order, DW_ADDR (attr));
+       store_unsigned_integer (tem, *len, byte_order, attr->as_address ());
        result = tem;
       }
       break;
@@ -22618,10 +23838,13 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
     case DW_FORM_strx:
     case DW_FORM_GNU_str_index:
     case DW_FORM_GNU_strp_alt:
-      /* DW_STRING is already allocated on the objfile obstack, point
+      /* The string is already allocated on the objfile obstack, point
         directly to it.  */
-      result = (const gdb_byte *) DW_STRING (attr);
-      *len = strlen (DW_STRING (attr));
+      {
+       const char *attr_name = attr->as_string ();
+       result = (const gdb_byte *) attr_name;
+       *len = strlen (attr_name);
+      }
       break;
     case DW_FORM_block1:
     case DW_FORM_block2:
@@ -22629,8 +23852,11 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
     case DW_FORM_block:
     case DW_FORM_exprloc:
     case DW_FORM_data16:
-      result = DW_BLOCK (attr)->data;
-      *len = DW_BLOCK (attr)->size;
+      {
+       struct dwarf_block *block = attr->as_block ();
+       result = block->data;
+       *len = block->size;
+      }
       break;
 
       /* The DW_AT_const_value attributes are supposed to carry the
@@ -22671,13 +23897,13 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
     case DW_FORM_implicit_const:
       type = die_type (die, cu);
       result = write_constant_as_bytes (obstack, byte_order,
-                                       type, DW_SND (attr), len);
+                                       type, attr->as_signed (), len);
       break;
 
     case DW_FORM_udata:
       type = die_type (die, cu);
       result = write_constant_as_bytes (obstack, byte_order,
-                                       type, DW_UNSND (attr), len);
+                                       type, attr->as_unsigned (), len);
       break;
 
     default:
@@ -22735,7 +23961,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
   struct die_info temp_die;
   struct dwarf2_cu *sig_cu, *cu = *ref_cu;
   struct die_info *die;
-  dwarf2_per_objfile *dwarf2_per_objfile = (*ref_cu)->per_objfile;
+  dwarf2_per_objfile *per_objfile = (*ref_cu)->per_objfile;
 
 
   /* While it might be nice to assert sig_type->type == NULL here,
@@ -22744,11 +23970,11 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
 
   /* If necessary, add it to the queue and load its DIEs.  */
 
-  if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, dwarf2_per_objfile,
+  if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, per_objfile,
                             language_minimal))
-    read_signatured_type (sig_type, dwarf2_per_objfile);
+    read_signatured_type (sig_type, per_objfile);
 
-  sig_cu = dwarf2_per_objfile->get_cu (&sig_type->per_cu);
+  sig_cu = per_objfile->get_cu (&sig_type->per_cu);
   gdb_assert (sig_cu != NULL);
   gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
   temp_die.sect_off = sig_type->type_offset_in_section;
@@ -22758,8 +23984,8 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
     {
       /* For .gdb_index version 7 keep track of included TUs.
         http://sourceware.org/bugzilla/show_bug.cgi?id=15021.  */
-      if (dwarf2_per_objfile->per_bfd->index_table != NULL
-         && dwarf2_per_objfile->per_bfd->index_table->version <= 7)
+      if (per_objfile->per_bfd->index_table != NULL
+         && per_objfile->per_bfd->index_table->version <= 7)
        {
          (*ref_cu)->per_cu->imported_symtabs_push (sig_cu->per_cu);
        }
@@ -22784,7 +24010,7 @@ static struct die_info *
 follow_die_sig (struct die_info *src_die, const struct attribute *attr,
                struct dwarf2_cu **ref_cu)
 {
-  ULONGEST signature = DW_SIGNATURE (attr);
+  ULONGEST signature = attr->as_signature ();
   struct signatured_type *sig_type;
   struct die_info *die;
 
@@ -22796,8 +24022,8 @@ follow_die_sig (struct die_info *src_die, const struct attribute *attr,
   if (sig_type == NULL)
     {
       error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
-               " from DIE at %s [in module %s]"),
-             hex_string (signature), sect_offset_str (src_die->sect_off),
+              " from DIE at %s [in module %s]"),
+            hex_string (signature), sect_offset_str (src_die->sect_off),
             objfile_name ((*ref_cu)->per_objfile->objfile));
     }
 
@@ -22821,7 +24047,7 @@ static struct type *
 get_signatured_type (struct die_info *die, ULONGEST signature,
                     struct dwarf2_cu *cu)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct signatured_type *sig_type;
   struct dwarf2_cu *type_cu;
   struct die_info *type_die;
@@ -22835,12 +24061,12 @@ get_signatured_type (struct die_info *die, ULONGEST signature,
       complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
                   " from DIE at %s [in module %s]"),
                 hex_string (signature), sect_offset_str (die->sect_off),
-                objfile_name (dwarf2_per_objfile->objfile));
+                objfile_name (per_objfile->objfile));
       return build_error_marker_type (cu, die);
     }
 
   /* If we already know the type we're done.  */
-  type = dwarf2_per_objfile->get_type_for_signatured_type (sig_type);
+  type = per_objfile->get_type_for_signatured_type (sig_type);
   if (type != nullptr)
     return type;
 
@@ -22857,7 +24083,7 @@ get_signatured_type (struct die_info *die, ULONGEST signature,
          complaint (_("Dwarf Error: Cannot build signatured type %s"
                       " referenced from DIE at %s [in module %s]"),
                     hex_string (signature), sect_offset_str (die->sect_off),
-                    objfile_name (dwarf2_per_objfile->objfile));
+                    objfile_name (per_objfile->objfile));
          type = build_error_marker_type (cu, die);
        }
     }
@@ -22866,11 +24092,11 @@ get_signatured_type (struct die_info *die, ULONGEST signature,
       complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
                   " from DIE at %s [in module %s]"),
                 hex_string (signature), sect_offset_str (die->sect_off),
-                objfile_name (dwarf2_per_objfile->objfile));
+                objfile_name (per_objfile->objfile));
       type = build_error_marker_type (cu, die);
     }
 
-  dwarf2_per_objfile->set_type_for_signatured_type (sig_type, type);
+  per_objfile->set_type_for_signatured_type (sig_type, type);
 
   return type;
 }
@@ -22892,16 +24118,16 @@ get_DW_AT_signature_type (struct die_info *die, const struct attribute *attr,
     }
   else if (attr->form == DW_FORM_ref_sig8)
     {
-      return get_signatured_type (die, DW_SIGNATURE (attr), cu);
+      return get_signatured_type (die, attr->as_signature (), cu);
     }
   else
     {
-      struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+      dwarf2_per_objfile *per_objfile = cu->per_objfile;
 
       complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
                   " at %s [in module %s]"),
                 dwarf_form_name (attr->form), sect_offset_str (die->sect_off),
-                objfile_name (dwarf2_per_objfile->objfile));
+                objfile_name (per_objfile->objfile));
       return build_error_marker_type (cu, die);
     }
 }
@@ -23189,7 +24415,7 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu, bool *computed)
            }
          break;
 
-        case DW_OP_GNU_push_tls_address:
+       case DW_OP_GNU_push_tls_address:
        case DW_OP_form_tls_address:
          /* The top of the stack has the offset from the beginning
             of the thread control block at which the variable is located.  */
@@ -23207,7 +24433,7 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu, bool *computed)
                return 0;
            }
          stack[stacki]++;
-          break;
+         break;
 
        case DW_OP_GNU_uninit:
          if (computed != nullptr)
@@ -23239,7 +24465,7 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu, bool *computed)
        }
 
       /* Enforce maximum stack depth of SIZE-1 to avoid writing
-         outside of the allocated space.  Also enforce minimum>0.  */
+        outside of the allocated space.  Also enforce minimum>0.  */
       if (stacki >= ARRAY_SIZE (stack) - 1)
        {
          if (computed == nullptr)
@@ -23293,8 +24519,8 @@ static void
 dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
                     int section_is_gnu)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   const struct line_header *lh = cu->line_header;
   unsigned int offset_size = cu->header.offset_size;
   struct dwarf2_section_info *section;
@@ -23317,12 +24543,12 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
     {
       if (section_is_gnu)
        {
-         section = &dwarf2_per_objfile->per_bfd->macro;
+         section = &per_objfile->per_bfd->macro;
          section_name = ".debug_macro";
        }
       else
        {
-         section = &dwarf2_per_objfile->per_bfd->macinfo;
+         section = &per_objfile->per_bfd->macinfo;
          section_name = ".debug_macinfo";
        }
     }
@@ -23336,8 +24562,27 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
 
   buildsym_compunit *builder = cu->get_builder ();
 
-  dwarf_decode_macros (dwarf2_per_objfile, builder, section, lh,
-                      offset_size, offset, section_is_gnu);
+  struct dwarf2_section_info *str_offsets_section;
+  struct dwarf2_section_info *str_section;
+  ULONGEST str_offsets_base;
+
+  if (cu->dwo_unit != nullptr)
+    {
+      str_offsets_section = &cu->dwo_unit->dwo_file
+                              ->sections.str_offsets;
+      str_section = &cu->dwo_unit->dwo_file->sections.str;
+      str_offsets_base = cu->header.addr_size;
+    }
+  else
+    {
+      str_offsets_section = &per_objfile->per_bfd->str_offsets;
+      str_section = &per_objfile->per_bfd->str;
+      str_offsets_base = *cu->str_offsets_base;
+    }
+
+  dwarf_decode_macros (per_objfile, builder, section, lh,
+                      offset_size, offset, str_section, str_offsets_section,
+                      str_offsets_base, section_is_gnu);
 }
 
 /* Return the .debug_loc section to use for CU.
@@ -23346,7 +24591,7 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
 static struct dwarf2_section_info *
 cu_debug_loc_section (struct dwarf2_cu *cu)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
 
   if (cu->dwo_unit)
     {
@@ -23354,8 +24599,36 @@ cu_debug_loc_section (struct dwarf2_cu *cu)
 
       return cu->header.version >= 5 ? &sections->loclists : &sections->loc;
     }
-  return (cu->header.version >= 5 ? &dwarf2_per_objfile->per_bfd->loclists
-                                 : &dwarf2_per_objfile->per_bfd->loc);
+  return (cu->header.version >= 5 ? &per_objfile->per_bfd->loclists
+                                 : &per_objfile->per_bfd->loc);
+}
+
+/* Return the .debug_rnglists section to use for CU.  */
+static struct dwarf2_section_info *
+cu_debug_rnglists_section (struct dwarf2_cu *cu, dwarf_tag tag)
+{
+  if (cu->header.version < 5)
+    error (_(".debug_rnglists section cannot be used in DWARF %d"),
+          cu->header.version);
+  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+
+  /* Make sure we read the .debug_rnglists section from the file that
+     contains the DW_AT_ranges attribute we are reading.  Normally that
+     would be the .dwo file, if there is one.  However for DW_TAG_compile_unit
+     or DW_TAG_skeleton unit, we always want to read from objfile/linked
+     program.  */
+  if (cu->dwo_unit != nullptr
+      && tag != DW_TAG_compile_unit
+      && tag != DW_TAG_skeleton_unit)
+    {
+      struct dwo_sections *sections = &cu->dwo_unit->dwo_file->sections;
+
+      if (sections->rnglists.size > 0)
+       return &sections->rnglists;
+      else
+       error (_(".debug_rnglists section is missing from .dwo file."));
+    }
+  return &dwarf2_per_objfile->per_bfd->rnglists;
 }
 
 /* A helper function that fills in a dwarf2_loclist_baton.  */
@@ -23365,18 +24638,18 @@ fill_in_loclist_baton (struct dwarf2_cu *cu,
                       struct dwarf2_loclist_baton *baton,
                       const struct attribute *attr)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct dwarf2_section_info *section = cu_debug_loc_section (cu);
 
-  section->read (dwarf2_per_objfile->objfile);
+  section->read (per_objfile->objfile);
 
-  baton->per_objfile = dwarf2_per_objfile;
+  baton->per_objfile = per_objfile;
   baton->per_cu = cu->per_cu;
   gdb_assert (baton->per_cu);
   /* We don't know how long the location list is, but make sure we
      don't run off the edge of the section.  */
-  baton->size = section->size - DW_UNSND (attr);
-  baton->data = section->buffer + DW_UNSND (attr);
+  baton->size = section->size - attr->as_unsigned ();
+  baton->data = section->buffer + attr->as_unsigned ();
   if (cu->base_address.has_value ())
     baton->base_address = *cu->base_address;
   else
@@ -23388,15 +24661,15 @@ static void
 dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
                             struct dwarf2_cu *cu, int is_block)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct dwarf2_section_info *section = cu_debug_loc_section (cu);
 
   if (attr->form_is_section_offset ()
       /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
         the section.  If so, fall through to the complaint in the
         other branch.  */
-      && DW_UNSND (attr) < section->get_size (objfile))
+      && attr->as_unsigned () < section->get_size (objfile))
     {
       struct dwarf2_loclist_baton *baton;
 
@@ -23418,7 +24691,7 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
       struct dwarf2_locexpr_baton *baton;
 
       baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
-      baton->per_objfile = dwarf2_per_objfile;
+      baton->per_objfile = per_objfile;
       baton->per_cu = cu->per_cu;
       gdb_assert (baton->per_cu);
 
@@ -23429,8 +24702,9 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
             info_buffer for SYM's objfile; right now we never release
             that buffer, but when we do clean up properly this may
             need to change.  */
-         baton->size = DW_BLOCK (attr)->size;
-         baton->data = DW_BLOCK (attr)->data;
+         struct dwarf_block *block = attr->as_block ();
+         baton->size = block->size;
+         baton->data = block->data;
        }
       else
        {
@@ -23507,7 +24781,7 @@ dwarf2_cu::addr_type () const
   if (TYPE_LENGTH (addr_type) == addr_size)
     return addr_type;
 
-  addr_type = addr_sized_int_type (TYPE_UNSIGNED (addr_type));
+  addr_type = addr_sized_int_type (addr_type->is_unsigned ());
   return addr_type;
 }
 
@@ -23550,13 +24824,11 @@ dwarf2_find_containing_comp_unit
 static struct dwarf2_per_cu_data *
 dwarf2_find_containing_comp_unit (sect_offset sect_off,
                                  unsigned int offset_in_dwz,
-                                 struct dwarf2_per_objfile *dwarf2_per_objfile)
+                                 dwarf2_per_objfile *per_objfile)
 {
-  int low
-    = dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz,
-                                       dwarf2_per_objfile->per_bfd->all_comp_units);
-  struct dwarf2_per_cu_data *this_cu
-    = dwarf2_per_objfile->per_bfd->all_comp_units[low];
+  int low = dwarf2_find_containing_comp_unit
+    (sect_off, offset_in_dwz, per_objfile->per_bfd->all_comp_units);
+  dwarf2_per_cu_data *this_cu = per_objfile->per_bfd->all_comp_units[low];
 
   if (this_cu->is_dwz != offset_in_dwz || this_cu->sect_off > sect_off)
     {
@@ -23564,15 +24836,15 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
        error (_("Dwarf Error: could not find partial DIE containing "
               "offset %s [in module %s]"),
               sect_offset_str (sect_off),
-              bfd_get_filename (dwarf2_per_objfile->objfile->obfd));
+              bfd_get_filename (per_objfile->objfile->obfd));
 
-      gdb_assert (dwarf2_per_objfile->per_bfd->all_comp_units[low-1]->sect_off
+      gdb_assert (per_objfile->per_bfd->all_comp_units[low-1]->sect_off
                  <= sect_off);
-      return dwarf2_per_objfile->per_bfd->all_comp_units[low-1];
+      return per_objfile->per_bfd->all_comp_units[low-1];
     }
   else
     {
-      if (low == dwarf2_per_objfile->per_bfd->all_comp_units.size () - 1
+      if (low == per_objfile->per_bfd->all_comp_units.size () - 1
          && sect_off >= this_cu->sect_off + this_cu->length)
        error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off));
       gdb_assert (sect_off < this_cu->sect_off + this_cu->length);
@@ -23660,7 +24932,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 != nullptr)
-    set_cu_language (DW_UNSND (attr), cu);
+    set_cu_language (attr->constant_value (0), cu);
   else
     {
       cu->language = pretend_language;
@@ -23811,11 +25083,12 @@ per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
      * Make the type as complete as possible before fetching more types.  */
 
 static struct type *
-set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
+set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
+             bool skip_data_location)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct dwarf2_per_cu_offset_and_type **slot, ofs;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct attribute *attr;
   struct dynamic_prop prop;
 
@@ -23832,46 +25105,38 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
       && type->code () != TYPE_CODE_METHODPTR
       && type->code () != TYPE_CODE_MEMBERPTR
       && type->code () != TYPE_CODE_METHOD
+      && type->code () != TYPE_CODE_FIXED_POINT
       && !HAVE_GNAT_AUX_INFO (type))
     INIT_GNAT_SPECIFIC (type);
 
   /* Read DW_AT_allocated and set in type.  */
   attr = dwarf2_attr (die, DW_AT_allocated, cu);
-  if (attr != NULL && attr->form_is_block ())
+  if (attr != NULL)
     {
       struct type *prop_type = cu->addr_sized_int_type (false);
       if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
-        type->add_dyn_prop (DYN_PROP_ALLOCATED, prop);
-    }
-  else if (attr != NULL)
-    {
-      complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
-                (attr != NULL ? dwarf_form_name (attr->form) : "n/a"),
-                sect_offset_str (die->sect_off));
+       type->add_dyn_prop (DYN_PROP_ALLOCATED, prop);
     }
 
   /* Read DW_AT_associated and set in type.  */
   attr = dwarf2_attr (die, DW_AT_associated, cu);
-  if (attr != NULL && attr->form_is_block ())
+  if (attr != NULL)
     {
       struct type *prop_type = cu->addr_sized_int_type (false);
       if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
-        type->add_dyn_prop (DYN_PROP_ASSOCIATED, prop);
-    }
-  else if (attr != NULL)
-    {
-      complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
-                (attr != NULL ? dwarf_form_name (attr->form) : "n/a"),
-                sect_offset_str (die->sect_off));
+       type->add_dyn_prop (DYN_PROP_ASSOCIATED, prop);
     }
 
   /* Read DW_AT_data_location and set in type.  */
-  attr = dwarf2_attr (die, DW_AT_data_location, cu);
-  if (attr_to_dynamic_prop (attr, die, cu, &prop, cu->addr_type ()))
-    type->add_dyn_prop (DYN_PROP_DATA_LOCATION, prop);
+  if (!skip_data_location)
+    {
+      attr = dwarf2_attr (die, DW_AT_data_location, cu);
+      if (attr_to_dynamic_prop (attr, die, cu, &prop, cu->addr_type ()))
+       type->add_dyn_prop (DYN_PROP_DATA_LOCATION, prop);
+    }
 
-  if (dwarf2_per_objfile->die_type_hash == NULL)
-    dwarf2_per_objfile->die_type_hash
+  if (per_objfile->die_type_hash == NULL)
+    per_objfile->die_type_hash
       = htab_up (htab_create_alloc (127,
                                    per_cu_offset_and_type_hash,
                                    per_cu_offset_and_type_eq,
@@ -23881,7 +25146,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   ofs.sect_off = die->sect_off;
   ofs.type = type;
   slot = (struct dwarf2_per_cu_offset_and_type **)
-    htab_find_slot (dwarf2_per_objfile->die_type_hash.get (), &ofs, INSERT);
+    htab_find_slot (per_objfile->die_type_hash.get (), &ofs, INSERT);
   if (*slot)
     complaint (_("A problem internal to GDB: DIE %s has type already set"),
               sect_offset_str (die->sect_off));
@@ -23897,17 +25162,17 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
 static struct type *
 get_die_type_at_offset (sect_offset sect_off,
                        dwarf2_per_cu_data *per_cu,
-                       dwarf2_per_objfile *dwarf2_per_objfile)
+                       dwarf2_per_objfile *per_objfile)
 {
   struct dwarf2_per_cu_offset_and_type *slot, ofs;
 
-  if (dwarf2_per_objfile->die_type_hash == NULL)
+  if (per_objfile->die_type_hash == NULL)
     return NULL;
 
   ofs.per_cu = per_cu;
   ofs.sect_off = sect_off;
   slot = ((struct dwarf2_per_cu_offset_and_type *)
-         htab_find (dwarf2_per_objfile->die_type_hash.get (), &ofs));
+         htab_find (per_objfile->die_type_hash.get (), &ofs));
   if (slot)
     return slot->type;
   else
This page took 0.213994 seconds and 4 git commands to generate.