boolean/auto-boolean commands, make "o" ambiguous
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 9f6d34f1fe22a461a17e5c8d9592ebdb4fe59295..4cf9fcfa2189c5ecbe373a02fc2c37bedc4e400f 100644 (file)
@@ -1,6 +1,6 @@
 /* DWARF 2 debugging format support for GDB.
 
-   Copyright (C) 1994-2018 Free Software Foundation, Inc.
+   Copyright (C) 1994-2019 Free Software Foundation, Inc.
 
    Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
    Inc.  with support from Florida State University (under contract
@@ -30,6 +30,7 @@
 
 #include "defs.h"
 #include "dwarf2read.h"
+#include "dwarf-index-cache.h"
 #include "dwarf-index-common.h"
 #include "bfd.h"
 #include "elf-bfd.h"
@@ -45,7 +46,6 @@
 #include "macrotab.h"
 #include "language.h"
 #include "complaints.h"
-#include "bcache.h"
 #include "dwarf2expr.h"
 #include "dwarf2loc.h"
 #include "cp-support.h"
@@ -58,7 +58,7 @@
 #include "psympriv.h"
 #include <sys/stat.h>
 #include "completer.h"
-#include "vec.h"
+#include "common/vec.h"
 #include "c-lang.h"
 #include "go-lang.h"
 #include "valprint.h"
@@ -68,7 +68,7 @@
 #include "gdb_bfd.h"
 #include "f-lang.h"
 #include "source.h"
-#include "filestuff.h"
+#include "common/filestuff.h"
 #include "build-id.h"
 #include "namespace.h"
 #include "common/gdb_unlinker.h"
@@ -84,7 +84,7 @@
 #include <algorithm>
 #include <unordered_set>
 #include <unordered_map>
-#include "selftest.h"
+#include "common/selftest.h"
 #include <cmath>
 #include <set>
 #include <forward_list>
@@ -108,7 +108,7 @@ static int check_physname = 0;
 /* When non-zero, do not reject deprecated .gdb_index sections.  */
 static int use_deprecated_index_sections = 0;
 
-static const struct objfile_data *dwarf2_objfile_data_key;
+static const struct objfile_key<dwarf2_per_objfile> dwarf2_objfile_data_key;
 
 /* The "aclass" indices for various kinds of computed DWARF symbols.  */
 
@@ -212,7 +212,7 @@ struct mapped_index final : public mapped_index_base
   bool symbol_name_slot_invalid (offset_type idx) const override
   {
     const auto &bucket = this->symbol_table[idx];
-    return bucket.name == 0 && bucket.vec;
+    return bucket.name == 0 && bucket.vec == 0;
   }
 
   /* Convenience method to get at the name of the symbol at IDX in the
@@ -281,18 +281,7 @@ struct mapped_debug_names final : public mapped_index_base
 dwarf2_per_objfile *
 get_dwarf2_per_objfile (struct objfile *objfile)
 {
-  return ((struct dwarf2_per_objfile *)
-         objfile_data (objfile, dwarf2_objfile_data_key));
-}
-
-/* Set the dwarf2_per_objfile associated to OBJFILE.  */
-
-void
-set_dwarf2_per_objfile (struct objfile *objfile,
-                       struct dwarf2_per_objfile *dwarf2_per_objfile)
-{
-  gdb_assert (get_dwarf2_per_objfile (objfile) == NULL);
-  set_objfile_data (objfile, dwarf2_objfile_data_key, dwarf2_per_objfile);
+  return dwarf2_objfile_data_key.get (objfile);
 }
 
 /* Default names of the debugging sections.  */
@@ -420,6 +409,22 @@ struct dwarf2_cu
 
   DISABLE_COPY_AND_ASSIGN (dwarf2_cu);
 
+  /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
+     Create the set of symtabs used by this TU, or if this TU is sharing
+     symtabs with another TU and the symtabs have already been created
+     then restore those symtabs in the line header.
+     We don't need the pc/line-number mapping for type units.  */
+  void setup_type_unit_groups (struct die_info *die);
+
+  /* Start a symtab for DWARF.  NAME, COMP_DIR, LOW_PC are passed to the
+     buildsym_compunit constructor.  */
+  struct compunit_symtab *start_symtab (const char *name,
+                                       const char *comp_dir,
+                                       CORE_ADDR low_pc);
+
+  /* Reset the builder.  */
+  void reset_builder () { m_builder.reset (); }
+
   /* The header of the compilation unit.  */
   struct comp_unit_head header {};
 
@@ -435,6 +440,12 @@ struct dwarf2_cu
 
   const char *producer = nullptr;
 
+private:
+  /* The symtab builder for this CU.  This is only non-NULL when full
+     symbols are being read.  */
+  std::unique_ptr<buildsym_compunit> m_builder;
+
+public:
   /* The generic symbol table building routines have separate lists for
      file scope symbols and all all other scopes (local scopes).  So
      we need to select the right one to pass to add_symbol_to_list().
@@ -531,30 +542,50 @@ struct dwarf2_cu
   std::vector<struct type *> rust_unions;
 
   /* Mark used when releasing cached dies.  */
-  unsigned int mark : 1;
+  bool mark : 1;
 
   /* This CU references .debug_loc.  See the symtab->locations_valid field.
      This test is imperfect as there may exist optimized debug code not using
      any location list and still facing inlining issues if handled as
      unoptimized code.  For a future better test see GCC PR other/32998.  */
-  unsigned int has_loclist : 1;
+  bool has_loclist : 1;
 
-  /* These cache the results for producer_is_* fields.  CHECKED_PRODUCER is set
+  /* These cache the results for producer_is_* fields.  CHECKED_PRODUCER is true
      if all the producer_is_* fields are valid.  This information is cached
      because profiling CU expansion showed excessive time spent in
      producer_is_gxx_lt_4_6.  */
-  unsigned int checked_producer : 1;
-  unsigned int producer_is_gxx_lt_4_6 : 1;
-  unsigned int producer_is_gcc_lt_4_3 : 1;
-  unsigned int producer_is_icc_lt_14 : 1;
-
-  /* When set, the file that we're processing is known to have
+  bool checked_producer : 1;
+  bool producer_is_gxx_lt_4_6 : 1;
+  bool producer_is_gcc_lt_4_3 : 1;
+  bool producer_is_icc : 1;
+  bool producer_is_icc_lt_14 : 1;
+  bool producer_is_codewarrior : 1;
+
+  /* When true, the file that we're processing is known to have
      debugging info for C++ namespaces.  GCC 3.3.x did not produce
      this information, but later versions do.  */
 
-  unsigned int processing_has_namespace_info : 1;
+  bool processing_has_namespace_info : 1;
 
   struct partial_die_info *find_partial_die (sect_offset sect_off);
+
+  /* If this CU was inherited by another CU (via specification,
+     abstract_origin, etc), this is the ancestor CU.  */
+  dwarf2_cu *ancestor;
+
+  /* Get the buildsym_compunit for this CU.  */
+  buildsym_compunit *get_builder ()
+  {
+    /* If this CU has a builder associated with it, use that.  */
+    if (m_builder != nullptr)
+      return m_builder.get ();
+
+    /* Otherwise, search ancestors for a valid builder.  */
+    if (ancestor != nullptr)
+      return ancestor->get_builder ();
+
+    return nullptr;
+  }
 };
 
 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
@@ -864,6 +895,10 @@ struct dwz_file
 
   /* The dwz's BFD.  */
   gdb_bfd_ref_ptr dwz_bfd;
+
+  /* If we loaded the index from an external file, this contains the
+     resources associated to the open file, memory mapping, etc.  */
+  std::unique_ptr<index_cache_resource> index_cache_res;
 };
 
 /* Struct used to pass misc. parameters to read_die_and_children, et
@@ -990,14 +1025,6 @@ struct line_header
     return &file_names[vec_index];
   }
 
-  /* Const version of the above.  */
-  const file_entry *file_name_at (unsigned int index) const
-  {
-    if (index >= file_names.size ())
-      return NULL;
-    return &file_names[index];
-  }
-
   /* Offset of line number information in .debug_line section.  */
   sect_offset sect_off {};
 
@@ -1480,8 +1507,25 @@ static unsigned int peek_abbrev_code (bfd *, const gdb_byte *);
 static struct partial_die_info *load_partial_dies
   (const struct die_reader_specs *, const gdb_byte *, int);
 
-static struct partial_die_info *find_partial_die (sect_offset, int,
-                                                 struct dwarf2_cu *);
+/* A pair of partial_die_info and compilation unit.  */
+struct cu_partial_die_info
+{
+  /* The compilation unit of the partial_die_info.  */
+  struct dwarf2_cu *cu;
+  /* A partial_die_info.  */
+  struct partial_die_info *pdi;
+
+  cu_partial_die_info (struct dwarf2_cu *cu, struct partial_die_info *pdi)
+    : cu (cu),
+      pdi (pdi)
+  { /* Nothhing.  */ }
+
+private:
+  cu_partial_die_info () = delete;
+};
+
+static const struct cu_partial_die_info find_partial_die (sect_offset, int,
+                                                         struct dwarf2_cu *);
 
 static const gdb_byte *read_attribute (const struct die_reader_specs *,
                                       struct attribute *, struct attr_abbrev *,
@@ -1493,6 +1537,9 @@ static int read_1_signed_byte (bfd *, const gdb_byte *);
 
 static unsigned int read_2_bytes (bfd *, const gdb_byte *);
 
+/* Read the next three bytes (little-endian order) as an unsigned integer.  */
+static unsigned int read_3_bytes (bfd *, const gdb_byte *);
+
 static unsigned int read_4_bytes (bfd *, const gdb_byte *);
 
 static ULONGEST read_8_bytes (bfd *, const gdb_byte *);
@@ -1570,11 +1617,8 @@ static void dwarf_decode_lines (struct line_header *, const char *,
                                struct dwarf2_cu *, struct partial_symtab *,
                                CORE_ADDR, int decode_mapping);
 
-static void dwarf2_start_subfile (const char *, const char *);
-
-static struct compunit_symtab *dwarf2_start_symtab (struct dwarf2_cu *,
-                                                   const char *, const char *,
-                                                   CORE_ADDR);
+static void dwarf2_start_subfile (struct dwarf2_cu *, const char *,
+                                 const char *);
 
 static struct symbol *new_symbol (struct die_info *, struct type *,
                                  struct dwarf2_cu *, struct symbol * = NULL);
@@ -1683,7 +1727,7 @@ static void read_namespace (struct die_info *die, struct dwarf2_cu *);
 
 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
 
-static struct using_direct **using_directives (enum language);
+static struct using_direct **using_directives (struct dwarf2_cu *cu);
 
 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
 
@@ -2091,7 +2135,8 @@ attr_value_as_address (struct attribute *attr)
 {
   CORE_ADDR addr;
 
-  if (attr->form != DW_FORM_addr && attr->form != DW_FORM_GNU_addr_index)
+  if (attr->form != DW_FORM_addr && attr->form != DW_FORM_addrx
+      && attr->form != DW_FORM_GNU_addr_index)
     {
       /* Aside from a few clearly defined exceptions, attributes that
         contain an address must always be in DW_FORM_addr form.
@@ -2212,13 +2257,9 @@ dwarf2_has_info (struct objfile *objfile,
     = get_dwarf2_per_objfile (objfile);
 
   if (dwarf2_per_objfile == NULL)
-    {
-      /* Initialize per-objfile state.  */
-      dwarf2_per_objfile
-       = new (&objfile->objfile_obstack) struct dwarf2_per_objfile (objfile,
-                                                                    names);
-      set_dwarf2_per_objfile (objfile, dwarf2_per_objfile);
-    }
+    dwarf2_per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile,
+                                                         names);
+
   return (!dwarf2_per_objfile->info.is_virtual
          && dwarf2_per_objfile->info.s.section != NULL
          && !dwarf2_per_objfile->abbrev.is_virtual
@@ -2550,9 +2591,7 @@ dwarf2_get_section_info (struct objfile *objfile,
                          asection **sectp, const gdb_byte **bufp,
                          bfd_size_type *sizep)
 {
-  struct dwarf2_per_objfile *data
-    = (struct dwarf2_per_objfile *) objfile_data (objfile,
-                                                 dwarf2_objfile_data_key);
+  struct dwarf2_per_objfile *data = dwarf2_objfile_data_key.get (objfile);
   struct dwarf2_section_info *info;
 
   /* We may see an objfile without any DWARF, in which case we just
@@ -2678,7 +2717,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
   if (dwz_bfd != NULL)
     {
       if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid))
-       dwz_bfd.release ();
+       dwz_bfd.reset (nullptr);
     }
 
   if (dwz_bfd == NULL)
@@ -3172,14 +3211,14 @@ create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
          continue;
        }
 
-      lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr);
-      hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr);
+      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->get_cu (cu_index));
     }
 
-  objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
-                                                   &objfile->objfile_obstack);
+  objfile->partial_symtabs->psymtabs_addrmap
+    = addrmap_create_fixed (mutable_map, objfile->partial_symtabs->obstack ());
 }
 
 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
@@ -3331,14 +3370,16 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
              continue;
            }
          ULONGEST end = start + length;
-         start = gdbarch_adjust_dwarf2_addr (gdbarch, start + baseaddr);
-         end = gdbarch_adjust_dwarf2_addr (gdbarch, end + baseaddr);
+         start = (gdbarch_adjust_dwarf2_addr (gdbarch, start + baseaddr)
+                  - baseaddr);
+         end = (gdbarch_adjust_dwarf2_addr (gdbarch, end + baseaddr)
+                - baseaddr);
          addrmap_set_empty (mutable_map, start, end - 1, per_cu);
        }
     }
 
-  objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
-                                                   &objfile->objfile_obstack);
+  objfile->partial_symtabs->psymtabs_addrmap
+    = addrmap_create_fixed (mutable_map, objfile->partial_symtabs->obstack ());
 }
 
 /* Find a slot in the mapped index INDEX for the object named NAME.
@@ -3403,8 +3444,8 @@ find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
     }
 }
 
-/* A helper function that reads the .gdb_index from SECTION and fills
-   in MAP.  FILENAME is the name of the file containing the section;
+/* A helper function that reads the .gdb_index from BUFFER and fills
+   in MAP.  FILENAME is the name of the file containing the data;
    it is used for error reporting.  DEPRECATED_OK is true if it is
    ok to use deprecated sections.
 
@@ -3412,37 +3453,23 @@ find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
    out parameters that are filled in with information about the CU and
    TU lists in the section.
 
-   Returns 1 if all went well, 0 otherwise.  */
+   Returns true if all went well, false otherwise.  */
 
 static bool
-read_gdb_index_from_section (struct objfile *objfile,
-                            const char *filename,
-                            bool deprecated_ok,
-                            struct dwarf2_section_info *section,
-                            struct mapped_index *map,
-                            const gdb_byte **cu_list,
-                            offset_type *cu_list_elements,
-                            const gdb_byte **types_list,
-                            offset_type *types_list_elements)
-{
-  const gdb_byte *addr;
-  offset_type version;
-  offset_type *metadata;
-  int i;
+read_gdb_index_from_buffer (struct objfile *objfile,
+                           const char *filename,
+                           bool deprecated_ok,
+                           gdb::array_view<const gdb_byte> buffer,
+                           struct mapped_index *map,
+                           const gdb_byte **cu_list,
+                           offset_type *cu_list_elements,
+                           const gdb_byte **types_list,
+                           offset_type *types_list_elements)
+{
+  const gdb_byte *addr = &buffer[0];
 
-  if (dwarf2_section_empty_p (section))
-    return 0;
-
-  /* Older elfutils strip versions could keep the section in the main
-     executable while splitting it for the separate debug info file.  */
-  if ((get_section_flags (section) & SEC_HAS_CONTENTS) == 0)
-    return 0;
-
-  dwarf2_read_section (objfile, section);
-
-  addr = section->buffer;
   /* Version check.  */
-  version = MAYBE_SWAP (*(offset_type *) addr);
+  offset_type version = MAYBE_SWAP (*(offset_type *) addr);
   /* Versions earlier than 3 emitted every copy of a psymbol.  This
      causes the index to behave very poorly for certain requests.  Version 3
      contained incomplete addrmap.  So, it seems better to just ignore such
@@ -3495,9 +3522,9 @@ to use the section anyway."),
 
   map->version = version;
 
-  metadata = (offset_type *) (addr + sizeof (offset_type));
+  offset_type *metadata = (offset_type *) (addr + sizeof (offset_type));
 
-  i = 0;
+  int i = 0;
   *cu_list = addr + MAYBE_SWAP (metadata[i]);
   *cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
                       / 8);
@@ -3528,23 +3555,41 @@ to use the section anyway."),
   return 1;
 }
 
+/* Callback types for dwarf2_read_gdb_index.  */
+
+typedef gdb::function_view
+    <gdb::array_view<const gdb_byte>(objfile *, dwarf2_per_objfile *)>
+    get_gdb_index_contents_ftype;
+typedef gdb::function_view
+    <gdb::array_view<const gdb_byte>(objfile *, dwz_file *)>
+    get_gdb_index_contents_dwz_ftype;
+
 /* Read .gdb_index.  If everything went ok, initialize the "quick"
    elements of all the CUs and return 1.  Otherwise, return 0.  */
 
 static int
-dwarf2_read_gdb_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
+dwarf2_read_gdb_index
+  (struct dwarf2_per_objfile *dwarf2_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;
 
+  gdb::array_view<const gdb_byte> main_index_contents
+    = get_gdb_index_contents (objfile, dwarf2_per_objfile);
+
+  if (main_index_contents.empty ())
+    return 0;
+
   std::unique_ptr<struct mapped_index> map (new struct mapped_index);
-  if (!read_gdb_index_from_section (objfile, objfile_name (objfile),
-                                   use_deprecated_index_sections,
-                                   &dwarf2_per_objfile->gdb_index, map.get (),
-                                   &cu_list, &cu_list_elements,
-                                   &types_list, &types_list_elements))
+  if (!read_gdb_index_from_buffer (objfile, objfile_name (objfile),
+                                  use_deprecated_index_sections,
+                                  main_index_contents, map.get (), &cu_list,
+                                  &cu_list_elements, &types_list,
+                                  &types_list_elements))
     return 0;
 
   /* Don't use the index if it's empty.  */
@@ -3560,12 +3605,18 @@ dwarf2_read_gdb_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
       const gdb_byte *dwz_types_ignore;
       offset_type dwz_types_elements_ignore;
 
-      if (!read_gdb_index_from_section (objfile,
-                                       bfd_get_filename (dwz->dwz_bfd), 1,
-                                       &dwz->gdb_index, &dwz_map,
-                                       &dwz_list, &dwz_list_elements,
-                                       &dwz_types_ignore,
-                                       &dwz_types_elements_ignore))
+      gdb::array_view<const gdb_byte> dwz_index_content
+       = get_gdb_index_contents_dwz (objfile, dwz);
+
+      if (dwz_index_content.empty ())
+       return 0;
+
+      if (!read_gdb_index_from_buffer (objfile,
+                                      bfd_get_filename (dwz->dwz_bfd), 1,
+                                      dwz_index_content, &dwz_map,
+                                      &dwz_list, &dwz_list_elements,
+                                      &dwz_types_ignore,
+                                      &dwz_types_elements_ignore))
        {
          warning (_("could not read '.gdb_index' section from %s; skipping"),
                   bfd_get_filename (dwz->dwz_bfd));
@@ -4027,7 +4078,7 @@ dw2_lookup_symbol (struct objfile *objfile, int block_index,
       struct symbol *sym, *with_opaque = NULL;
       struct compunit_symtab *stab = dw2_instantiate_symtab (per_cu, false);
       const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
-      struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
+      const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
 
       sym = block_find_symbol (block, name, domain,
                               block_find_non_opaque_type_preferred,
@@ -4093,14 +4144,6 @@ dw2_dump (struct objfile *objfile)
   printf_filtered ("\n");
 }
 
-static void
-dw2_relocate (struct objfile *objfile,
-             const struct section_offsets *new_offsets,
-             const struct section_offsets *delta)
-{
-  /* There's nothing to relocate here.  */
-}
-
 static void
 dw2_expand_symtabs_for_function (struct objfile *objfile,
                                 const char *func_name)
@@ -4180,7 +4223,7 @@ static void
 dw2_map_matching_symbols (struct objfile *objfile,
                          const char * name, domain_enum domain,
                          int global,
-                         int (*callback) (struct block *,
+                         int (*callback) (const struct block *,
                                           struct symbol *, void *),
                          void *data, symbol_name_match_type match,
                          symbol_compare_ftype *ordered_compare)
@@ -5229,11 +5272,13 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
   struct dwarf2_per_cu_data *data;
   struct compunit_symtab *result;
 
-  if (!objfile->psymtabs_addrmap)
+  if (!objfile->partial_symtabs->psymtabs_addrmap)
     return NULL;
 
-  data = (struct dwarf2_per_cu_data *) addrmap_find (objfile->psymtabs_addrmap,
-                                                    pc);
+  CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets,
+                                SECT_OFF_TEXT (objfile));
+  data = (struct dwarf2_per_cu_data *) addrmap_find
+    (objfile->partial_symtabs->psymtabs_addrmap, pc - baseaddr);
   if (!data)
     return NULL;
 
@@ -5331,7 +5376,6 @@ const struct quick_symbol_functions dwarf2_gdb_index_functions =
   dw2_lookup_symbol,
   dw2_print_stats,
   dw2_dump,
-  dw2_relocate,
   dw2_expand_symtabs_for_function,
   dw2_expand_all_symtabs,
   dw2_expand_symtabs_with_fullname,
@@ -5482,7 +5526,6 @@ read_debug_names_from_section (struct objfile *objfile,
   const gdb_byte *abbrev_table_start = addr;
   for (;;)
     {
-      unsigned int bytes_read;
       const ULONGEST index_num = read_unsigned_leb128 (abfd, addr, &bytes_read);
       addr += bytes_read;
       if (index_num == 0)
@@ -6036,7 +6079,7 @@ dw2_debug_names_lookup_symbol (struct objfile *objfile, int block_index_int,
       struct symbol *sym, *with_opaque = NULL;
       struct compunit_symtab *stab = dw2_instantiate_symtab (per_cu, false);
       const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
-      struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
+      const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
 
       sym = block_find_symbol (block, name, domain,
                               block_find_non_opaque_type_preferred,
@@ -6144,7 +6187,6 @@ const struct quick_symbol_functions dwarf2_debug_names_functions =
   dw2_debug_names_lookup_symbol,
   dw2_print_stats,
   dw2_debug_names_dump,
-  dw2_relocate,
   dw2_debug_names_expand_symtabs_for_function,
   dw2_expand_all_symtabs,
   dw2_expand_symtabs_with_fullname,
@@ -6155,6 +6197,60 @@ const struct quick_symbol_functions dwarf2_debug_names_functions =
   dw2_map_symbol_filenames
 };
 
+/* Get the content of the .gdb_index section of OBJ.  SECTION_OWNER should point
+   to either a dwarf2_per_objfile or dwz_file object.  */
+
+template <typename T>
+static gdb::array_view<const gdb_byte>
+get_gdb_index_contents_from_section (objfile *obj, T *section_owner)
+{
+  dwarf2_section_info *section = &section_owner->gdb_index;
+
+  if (dwarf2_section_empty_p (section))
+    return {};
+
+  /* Older elfutils strip versions could keep the section in the main
+     executable while splitting it for the separate debug info file.  */
+  if ((get_section_flags (section) & SEC_HAS_CONTENTS) == 0)
+    return {};
+
+  dwarf2_read_section (obj, section);
+
+  /* dwarf2_section_info::size is a bfd_size_type, while
+     gdb::array_view works with size_t.  On 32-bit hosts, with
+     --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
+     is 32-bit.  So we need an explicit narrowing conversion here.
+     This is fine, because it's impossible to allocate or mmap an
+     array/buffer larger than what size_t can represent.  */
+  return gdb::make_array_view (section->buffer, section->size);
+}
+
+/* Lookup the index cache for the contents of the index associated to
+   DWARF2_OBJ.  */
+
+static gdb::array_view<const gdb_byte>
+get_gdb_index_contents_from_cache (objfile *obj, dwarf2_per_objfile *dwarf2_obj)
+{
+  const bfd_build_id *build_id = build_id_bfd_get (obj->obfd);
+  if (build_id == nullptr)
+    return {};
+
+  return global_index_cache.lookup_gdb_index (build_id,
+                                             &dwarf2_obj->index_cache_res);
+}
+
+/* Same as the above, but for DWZ.  */
+
+static gdb::array_view<const gdb_byte>
+get_gdb_index_contents_from_cache_dwz (objfile *obj, dwz_file *dwz)
+{
+  const bfd_build_id *build_id = build_id_bfd_get (dwz->dwz_bfd.get ());
+  if (build_id == nullptr)
+    return {};
+
+  return global_index_cache.lookup_gdb_index (build_id, &dwz->index_cache_res);
+}
+
 /* See symfile.h.  */
 
 bool
@@ -6198,12 +6294,25 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
       return true;
     }
 
-  if (dwarf2_read_gdb_index (dwarf2_per_objfile))
+  if (dwarf2_read_gdb_index (dwarf2_per_objfile,
+                            get_gdb_index_contents_from_section<struct dwarf2_per_objfile>,
+                            get_gdb_index_contents_from_section<dwz_file>))
+    {
+      *index_kind = dw_index_kind::GDB_INDEX;
+      return true;
+    }
+
+  /* ... otherwise, try to find the index in the index cache.  */
+  if (dwarf2_read_gdb_index (dwarf2_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;
       return true;
     }
 
+  global_index_cache.miss ();
   return false;
 }
 
@@ -6217,11 +6326,9 @@ dwarf2_build_psymtabs (struct objfile *objfile)
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = get_dwarf2_per_objfile (objfile);
 
-  if (objfile->global_psymbols.capacity () == 0
-      && objfile->static_psymbols.capacity () == 0)
-    init_psymbol_list (objfile, 1024);
+  init_psymbol_list (objfile, 1024);
 
-  TRY
+  try
     {
       /* This isn't really ideal: all the data we allocate on the
         objfile's obstack is still uselessly kept around.  However,
@@ -6229,12 +6336,14 @@ dwarf2_build_psymtabs (struct objfile *objfile)
       psymtab_discarder psymtabs (objfile);
       dwarf2_build_psymtabs_hard (dwarf2_per_objfile);
       psymtabs.keep ();
+
+      /* (maybe) store an index in the cache.  */
+      global_index_cache.store (dwarf2_per_objfile);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const gdb_exception_error &except)
     {
       exception_print (gdb_stderr, except);
     }
-  END_CATCH
 }
 
 /* Return the total length of the CU described by HEADER.  */
@@ -6308,6 +6417,10 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
   cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
   info_ptr += bytes_read;
   cu_header->version = read_2_bytes (abfd, info_ptr);
+  if (cu_header->version < 2 || cu_header->version > 5)
+    error (_("Dwarf Error: wrong version in compilation unit header "
+          "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
+          cu_header->version, filename);
   info_ptr += 2;
   if (cu_header->version < 5)
     switch (section_kind)
@@ -6410,11 +6523,6 @@ error_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
 {
   const char *filename = get_section_file_name (section);
 
-  if (header->version < 2 || header->version > 5)
-    error (_("Dwarf Error: wrong version in compilation unit header "
-          "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header->version,
-          filename);
-
   if (to_underlying (header->abbrev_sect_off)
       >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
     error (_("Dwarf Error: bad offset (%s) in compilation unit header "
@@ -6503,21 +6611,11 @@ dwarf2_create_include_psymtab (const char *name, struct partial_symtab *pst,
       subpst->dirname = pst->dirname;
     }
 
-  subpst->textlow = 0;
-  subpst->texthigh = 0;
-
-  subpst->dependencies
-    = XOBNEW (&objfile->objfile_obstack, struct partial_symtab *);
+  subpst->dependencies = objfile->partial_symtabs->allocate_dependencies (1);
   subpst->dependencies[0] = pst;
   subpst->number_of_dependencies = 1;
 
-  subpst->globals_offset = 0;
-  subpst->n_global_syms = 0;
-  subpst->statics_offset = 0;
-  subpst->n_static_syms = 0;
-  subpst->compunit_symtab = NULL;
   subpst->read_symtab = pst->read_symtab;
-  subpst->readin = 0;
 
   /* No private part is necessary for include psymtabs.  This property
      can be used to differentiate between such include psymtabs and
@@ -6543,8 +6641,12 @@ dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
   if (lh == NULL)
     return;  /* No linetable, so no includes.  */
 
-  /* NOTE: pst->dirname is DW_AT_comp_dir (if present).  */
-  dwarf_decode_lines (lh.get (), pst->dirname, cu, pst, pst->textlow, 1);
+  /* NOTE: pst->dirname is DW_AT_comp_dir (if present).  Also note
+     that we pass in the raw text_low here; that is ok because we're
+     only decoding the line table to make include partial symtabs, and
+     so the addresses aren't really used.  */
+  dwarf_decode_lines (lh.get (), pst->dirname, cu, pst,
+                     pst->raw_text_low (), 1);
 }
 
 static hashval_t
@@ -7123,7 +7225,8 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
       comp_dir = dwarf2_attr (stub_comp_unit_die, DW_AT_comp_dir, cu);
 
       /* There should be a DW_AT_addr_base attribute here (if needed).
-        We need the value before we can process DW_FORM_GNU_addr_index.  */
+        We need the value before we can process DW_FORM_GNU_addr_index
+         or DW_FORM_addrx.  */
       cu->addr_base = 0;
       attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_addr_base, cu);
       if (attr)
@@ -7758,19 +7861,17 @@ create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
     {
       unsigned int line_offset = to_underlying (line_offset_struct);
       struct partial_symtab *pst;
-      char *name;
+      std::string name;
 
       /* Give the symtab a useful name for debug purposes.  */
       if ((line_offset & NO_STMT_LIST_TYPE_UNIT_PSYMTAB) != 0)
-       name = xstrprintf ("<type_units_%d>",
-                          (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
+       name = string_printf ("<type_units_%d>",
+                             (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
       else
-       name = xstrprintf ("<type_units_at_0x%x>", line_offset);
+       name = string_printf ("<type_units_at_0x%x>", line_offset);
 
-      pst = create_partial_symtab (per_cu, name);
+      pst = create_partial_symtab (per_cu, name.c_str ());
       pst->anonymous = 1;
-
-      xfree (name);
     }
 
   tu_group->hash.dwo_unit = cu->dwo_unit;
@@ -7852,9 +7953,7 @@ create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name)
   struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
   struct partial_symtab *pst;
 
-  pst = start_psymtab_common (objfile, name, 0,
-                             objfile->global_psymbols,
-                             objfile->static_psymbols);
+  pst = start_psymtab_common (objfile, name, 0);
 
   pst->psymtabs_addrmap_supported = 1;
 
@@ -7909,8 +8008,6 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 
   prepare_one_comp_unit (cu, comp_unit_die, info->pretend_language);
 
-  cu->list_in_scope = &file_symbols;
-
   /* Allocate a new partial symbol table structure.  */
   filename = dwarf2_string_attr (comp_unit_die, DW_AT_name, cu);
   if (filename == NULL)
@@ -7930,14 +8027,18 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
   cu_bounds_kind = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
                                         &best_highpc, cu, pst);
   if (cu_bounds_kind == PC_BOUNDS_HIGH_LOW && best_lowpc < best_highpc)
-    /* Store the contiguous range if it is not empty; it can be empty for
-       CUs with no code.  */
-    addrmap_set_empty (objfile->psymtabs_addrmap,
-                      gdbarch_adjust_dwarf2_addr (gdbarch,
-                                                  best_lowpc + baseaddr),
-                      gdbarch_adjust_dwarf2_addr (gdbarch,
-                                                  best_highpc + baseaddr) - 1,
-                      pst);
+    {
+      CORE_ADDR low
+       = (gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr)
+          - baseaddr);
+      CORE_ADDR high
+       = (gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr)
+          - baseaddr - 1);
+      /* Store the contiguous range if it is not empty; it can be
+        empty for CUs with no code.  */
+      addrmap_set_empty (objfile->partial_symtabs->psymtabs_addrmap,
+                        low, high, pst);
+    }
 
   /* Check if comp unit has_children.
      If so, read the rest of the partial symbols from this comp unit.
@@ -7968,8 +8069,12 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
          best_highpc = highpc;
        }
     }
-  pst->textlow = gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr);
-  pst->texthigh = gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr);
+  pst->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch,
+                                                best_lowpc + baseaddr)
+                    - baseaddr);
+  pst->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch,
+                                                 best_highpc + baseaddr)
+                     - baseaddr);
 
   end_psymtab_common (objfile, pst);
 
@@ -7982,8 +8087,8 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
       /* Fill in 'dependencies' here; we fill in 'users' in a
         post-pass.  */
       pst->number_of_dependencies = len;
-      pst->dependencies =
-       XOBNEWVEC (&objfile->objfile_obstack, struct partial_symtab *, len);
+      pst->dependencies
+       = objfile->partial_symtabs->allocate_dependencies (len);
       for (i = 0;
           VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
                        i, iter);
@@ -7998,18 +8103,14 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
   dwarf2_build_include_psymtabs (cu, comp_unit_die, pst);
 
   if (dwarf_read_debug)
-    {
-      struct gdbarch *gdbarch = get_objfile_arch (objfile);
-
-      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->textlow),
-                         paddress (gdbarch, pst->texthigh),
-                         pst->n_global_syms, pst->n_static_syms);
-    }
+    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);
 }
 
 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
@@ -8078,7 +8179,6 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
   VEC_safe_push (sig_type_ptr, tu_group->tus, sig_type);
 
   prepare_one_comp_unit (cu, type_unit_die, language_minimal);
-  cu->list_in_scope = &file_symbols;
   pst = create_partial_symtab (per_cu, "");
   pst->anonymous = 1;
 
@@ -8241,8 +8341,7 @@ build_type_psymtab_dependencies (void **slot, void *info)
   gdb_assert (IS_TYPE_UNIT_GROUP (per_cu));
 
   pst->number_of_dependencies = len;
-  pst->dependencies =
-    XOBNEWVEC (&objfile->objfile_obstack, struct partial_symtab *, len);
+  pst->dependencies = objfile->partial_symtabs->allocate_dependencies (len);
   for (i = 0;
        VEC_iterate (sig_type_ptr, tu_group->tus, i, iter);
        ++i)
@@ -8394,7 +8493,7 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
   auto_obstack temp_obstack;
 
   scoped_restore save_psymtabs_addrmap
-    = make_scoped_restore (&objfile->psymtabs_addrmap,
+    = make_scoped_restore (&objfile->partial_symtabs->psymtabs_addrmap,
                           addrmap_create_mutable (&temp_obstack));
 
   for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
@@ -8415,8 +8514,9 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   set_partial_user (dwarf2_per_objfile);
 
-  objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
-                                                   &objfile->objfile_obstack);
+  objfile->partial_symtabs->psymtabs_addrmap
+    = addrmap_create_fixed (objfile->partial_symtabs->psymtabs_addrmap,
+                           objfile->partial_symtabs->obstack ());
   /* At this point we want to keep the address map.  */
   save_psymtabs_addrmap.release ();
 
@@ -8677,8 +8777,12 @@ partial_die_parent_scope (struct partial_die_info *pdi,
 
   real_pdi = pdi;
   while (real_pdi->has_specification)
-    real_pdi = find_partial_die (real_pdi->spec_offset,
-                                real_pdi->spec_is_dwz, cu);
+    {
+      auto res = find_partial_die (real_pdi->spec_offset,
+                                  real_pdi->spec_is_dwz, cu);
+      real_pdi = res.pdi;
+      cu = res.cu;
+    }
 
   parent = real_pdi->die_parent;
   if (parent == NULL)
@@ -8727,8 +8831,9 @@ partial_die_parent_scope (struct partial_die_info *pdi,
       /* FIXME drow/2004-04-01: What should we be doing with
         function-local names?  For partial symbols, we should probably be
         ignoring them.  */
-      complaint (_("unhandled containing DIE tag %d for DIE at %s"),
-                parent->tag, sect_offset_str (pdi->sect_off));
+      complaint (_("unhandled containing DIE tag %s for DIE at %s"),
+                dwarf_tag_name (parent->tag),
+                sect_offset_str (pdi->sect_off));
       parent->scope = grandparent_scope;
     }
 
@@ -8801,7 +8906,8 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     {
     case DW_TAG_inlined_subroutine:
     case DW_TAG_subprogram:
-      addr = gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr);
+      addr = (gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr)
+             - baseaddr);
       if (pdi->is_external || cu->language == language_ada)
        {
           /* brobecker/2007-12-26: Normally, only "external" DIEs are part
@@ -8811,15 +8917,18 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          add_psymbol_to_list (actual_name, strlen (actual_name),
                               built_actual_name != NULL,
                               VAR_DOMAIN, LOC_BLOCK,
-                              &objfile->global_psymbols,
-                              addr, cu->language, objfile);
+                              SECT_OFF_TEXT (objfile),
+                              psymbol_placement::GLOBAL,
+                              addr,
+                              cu->language, objfile);
        }
       else
        {
          add_psymbol_to_list (actual_name, strlen (actual_name),
                               built_actual_name != NULL,
                               VAR_DOMAIN, LOC_BLOCK,
-                              &objfile->static_psymbols,
+                              SECT_OFF_TEXT (objfile),
+                              psymbol_placement::STATIC,
                               addr, cu->language, objfile);
        }
 
@@ -8827,17 +8936,12 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
        set_objfile_main_name (objfile, actual_name, cu->language);
       break;
     case DW_TAG_constant:
-      {
-       std::vector<partial_symbol *> *list;
-
-       if (pdi->is_external)
-         list = &objfile->global_psymbols;
-       else
-         list = &objfile->static_psymbols;
-       add_psymbol_to_list (actual_name, strlen (actual_name),
-                            built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
-                            list, 0, cu->language, objfile);
-      }
+      add_psymbol_to_list (actual_name, strlen (actual_name),
+                          built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
+                          -1, (pdi->is_external
+                               ? psymbol_placement::GLOBAL
+                               : psymbol_placement::STATIC),
+                          0, cu->language, objfile);
       break;
     case DW_TAG_variable:
       if (pdi->d.locdesc)
@@ -8871,9 +8975,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
            add_psymbol_to_list (actual_name, strlen (actual_name),
                                 built_actual_name != NULL,
                                 VAR_DOMAIN, LOC_STATIC,
-                                &objfile->global_psymbols,
-                                addr + baseaddr,
-                                cu->language, objfile);
+                                SECT_OFF_TEXT (objfile),
+                                psymbol_placement::GLOBAL,
+                                addr, cu->language, objfile);
        }
       else
        {
@@ -8890,8 +8994,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
          add_psymbol_to_list (actual_name, strlen (actual_name),
                               built_actual_name != NULL,
                               VAR_DOMAIN, LOC_STATIC,
-                              &objfile->static_psymbols,
-                              has_loc ? addr + baseaddr : (CORE_ADDR) 0,
+                              SECT_OFF_TEXT (objfile),
+                              psymbol_placement::STATIC,
+                              has_loc ? addr : 0,
                               cu->language, objfile);
        }
       break;
@@ -8900,24 +9005,28 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     case DW_TAG_subrange_type:
       add_psymbol_to_list (actual_name, strlen (actual_name),
                           built_actual_name != NULL,
-                          VAR_DOMAIN, LOC_TYPEDEF,
-                          &objfile->static_psymbols,
+                          VAR_DOMAIN, LOC_TYPEDEF, -1,
+                          psymbol_placement::STATIC,
                           0, cu->language, objfile);
       break;
     case DW_TAG_imported_declaration:
     case DW_TAG_namespace:
       add_psymbol_to_list (actual_name, strlen (actual_name),
                           built_actual_name != NULL,
-                          VAR_DOMAIN, LOC_TYPEDEF,
-                          &objfile->global_psymbols,
+                          VAR_DOMAIN, LOC_TYPEDEF, -1,
+                          psymbol_placement::GLOBAL,
                           0, cu->language, objfile);
       break;
     case DW_TAG_module:
-      add_psymbol_to_list (actual_name, strlen (actual_name),
-                          built_actual_name != NULL,
-                          MODULE_DOMAIN, LOC_TYPEDEF,
-                          &objfile->global_psymbols,
-                          0, cu->language, objfile);
+      /* 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.  */
+      if (actual_name != nullptr)
+       add_psymbol_to_list (actual_name, strlen (actual_name),
+                            built_actual_name != NULL,
+                            MODULE_DOMAIN, LOC_TYPEDEF, -1,
+                            psymbol_placement::GLOBAL,
+                            0, cu->language, objfile);
       break;
     case DW_TAG_class_type:
     case DW_TAG_interface_type:
@@ -8939,20 +9048,20 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
         static vs. global.  */
       add_psymbol_to_list (actual_name, strlen (actual_name),
                           built_actual_name != NULL,
-                          STRUCT_DOMAIN, LOC_TYPEDEF,
+                          STRUCT_DOMAIN, LOC_TYPEDEF, -1,
                           cu->language == language_cplus
-                          ? &objfile->global_psymbols
-                          : &objfile->static_psymbols,
+                          ? psymbol_placement::GLOBAL
+                          : psymbol_placement::STATIC,
                           0, cu->language, objfile);
 
       break;
     case DW_TAG_enumerator:
       add_psymbol_to_list (actual_name, strlen (actual_name),
                           built_actual_name != NULL,
-                          VAR_DOMAIN, LOC_CONST,
+                          VAR_DOMAIN, LOC_CONST, -1,
                           cu->language == language_cplus
-                          ? &objfile->global_psymbols
-                          : &objfile->static_psymbols,
+                          ? psymbol_placement::GLOBAL
+                          : psymbol_placement::STATIC,
                           0, cu->language, objfile);
       break;
     default:
@@ -9027,16 +9136,21 @@ add_partial_subprogram (struct partial_die_info *pdi,
              struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
              struct gdbarch *gdbarch = get_objfile_arch (objfile);
              CORE_ADDR baseaddr;
-             CORE_ADDR highpc;
-             CORE_ADDR lowpc;
+             CORE_ADDR this_highpc;
+             CORE_ADDR this_lowpc;
 
              baseaddr = ANOFFSET (objfile->section_offsets,
                                   SECT_OFF_TEXT (objfile));
-             lowpc = gdbarch_adjust_dwarf2_addr (gdbarch,
-                                                 pdi->lowpc + baseaddr);
-             highpc = gdbarch_adjust_dwarf2_addr (gdbarch,
-                                                  pdi->highpc + baseaddr);
-             addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1,
+             this_lowpc
+               = (gdbarch_adjust_dwarf2_addr (gdbarch,
+                                              pdi->lowpc + baseaddr)
+                  - baseaddr);
+             this_highpc
+               = (gdbarch_adjust_dwarf2_addr (gdbarch,
+                                              pdi->highpc + baseaddr)
+                  - baseaddr);
+             addrmap_set_empty (objfile->partial_symtabs->psymtabs_addrmap,
+                                this_lowpc, this_highpc - 1,
                                 cu->per_cu->v.psymtab);
            }
         }
@@ -9258,6 +9372,8 @@ skip_one_die (const struct die_reader_specs *reader, const gdb_byte *info_ptr,
        case DW_FORM_block4:
          info_ptr += 4 + read_4_bytes (abfd, info_ptr);
          break;
+       case DW_FORM_addrx:
+       case DW_FORM_strx:
        case DW_FORM_sdata:
        case DW_FORM_udata:
        case DW_FORM_ref_udata:
@@ -9719,7 +9835,9 @@ fixup_go_packaging (struct dwarf2_cu *cu)
   struct pending *list;
   int i;
 
-  for (list = global_symbols; list != NULL; list = list->next)
+  for (list = *cu->get_builder ()->get_global_symbols ();
+       list != NULL;
+       list = list->next)
     {
       for (i = 0; i < list->nsyms; ++i)
        {
@@ -9772,7 +9890,7 @@ fixup_go_packaging (struct dwarf2_cu *cu)
       SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
       SYMBOL_TYPE (sym) = type;
 
-      add_symbol_to_list (sym, &global_symbols);
+      add_symbol_to_list (sym, cu->get_builder ()->get_global_symbols ());
 
       xfree (package_name);
     }
@@ -10105,7 +10223,7 @@ get_compunit_symtab (struct dwarf2_per_cu_data *per_cu)
    included by PER_CU.  */
 
 static void
-recursively_compute_inclusions (VEC (compunit_symtab_ptr) **result,
+recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
                                htab_t all_children, htab_t all_type_symtabs,
                                struct dwarf2_per_cu_data *per_cu,
                                struct compunit_symtab *immediate_parent)
@@ -10135,14 +10253,14 @@ recursively_compute_inclusions (VEC (compunit_symtab_ptr) **result,
          if (*slot == NULL)
            {
              *slot = cust;
-             VEC_safe_push (compunit_symtab_ptr, *result, cust);
+             result->push_back (cust);
              if (cust->user == NULL)
                cust->user = immediate_parent;
            }
        }
       else
        {
-         VEC_safe_push (compunit_symtab_ptr, *result, cust);
+         result->push_back (cust);
          if (cust->user == NULL)
            cust->user = immediate_parent;
        }
@@ -10169,8 +10287,7 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
     {
       int ix, len;
       struct dwarf2_per_cu_data *per_cu_iter;
-      struct compunit_symtab *compunit_symtab_iter;
-      VEC (compunit_symtab_ptr) *result_symtabs = NULL;
+      std::vector<compunit_symtab *> result_symtabs;
       htab_t all_children, all_type_symtabs;
       struct compunit_symtab *cust = get_compunit_symtab (per_cu);
 
@@ -10194,18 +10311,14 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
        }
 
       /* Now we have a transitive closure of all the included symtabs.  */
-      len = VEC_length (compunit_symtab_ptr, result_symtabs);
+      len = result_symtabs.size ();
       cust->includes
        = XOBNEWVEC (&per_cu->dwarf2_per_objfile->objfile->objfile_obstack,
                     struct compunit_symtab *, len + 1);
-      for (ix = 0;
-          VEC_iterate (compunit_symtab_ptr, result_symtabs, ix,
-                       compunit_symtab_iter);
-          ++ix)
-       cust->includes[ix] = compunit_symtab_iter;
+      memcpy (cust->includes, result_symtabs.data (),
+             len * sizeof (compunit_symtab *));
       cust->includes[len] = NULL;
 
-      VEC_free (compunit_symtab_ptr, result_symtabs);
       htab_delete (all_children);
       htab_delete (all_type_symtabs);
     }
@@ -10245,14 +10358,9 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
 
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
-  buildsym_init ();
-  scoped_free_pendings free_pending;
-
   /* Clear the list here in case something was left over.  */
   cu->method_list.clear ();
 
-  cu->list_in_scope = &file_symbols;
-
   cu->language = pretend_language;
   cu->language_defn = language_def (cu->language);
 
@@ -10277,7 +10385,7 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
   get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
 
   addr = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
-  static_block = end_symtab_get_static_block (addr, 0, 1);
+  static_block = cu->get_builder ()->end_symtab_get_static_block (addr, 0, 1);
 
   /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
      Also, DW_AT_ranges may record ranges not belonging to any child DIEs
@@ -10286,8 +10394,9 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
      this comp unit.  */
   dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu);
 
-  cust = end_symtab_from_static_block (static_block,
-                                      SECT_OFF_TEXT (objfile), 0);
+  cust = cu->get_builder ()->end_symtab_from_static_block (static_block,
+                                                   SECT_OFF_TEXT (objfile),
+                                                   0);
 
   if (cust != NULL)
     {
@@ -10332,6 +10441,9 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
 
   /* Push it for inclusion processing later.  */
   dwarf2_per_objfile->just_read_cus.push_back (per_cu);
+
+  /* Not needed any more.  */
+  cu->reset_builder ();
 }
 
 /* Generate full symbol information for type unit PER_CU, whose DIEs have
@@ -10350,14 +10462,9 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
   gdb_assert (per_cu->is_debug_types);
   sig_type = (struct signatured_type *) per_cu;
 
-  buildsym_init ();
-  scoped_free_pendings free_pending;
-
   /* Clear the list here in case something was left over.  */
   cu->method_list.clear ();
 
-  cu->list_in_scope = &file_symbols;
-
   cu->language = pretend_language;
   cu->language_defn = language_def (cu->language);
 
@@ -10382,7 +10489,8 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
      this TU's symbols to the existing symtab.  */
   if (sig_type->type_unit_group->compunit_symtab == NULL)
     {
-      cust = end_expandable_symtab (0, SECT_OFF_TEXT (objfile));
+      buildsym_compunit *builder = cu->get_builder ();
+      cust = builder->end_expandable_symtab (0, SECT_OFF_TEXT (objfile));
       sig_type->type_unit_group->compunit_symtab = cust;
 
       if (cust != NULL)
@@ -10398,7 +10506,7 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
     }
   else
     {
-      augment_type_symtab ();
+      cu->get_builder ()->augment_type_symtab ();
       cust = sig_type->type_unit_group->compunit_symtab;
     }
 
@@ -10410,6 +10518,9 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
       pst->compunit_symtab = cust;
       pst->readin = 1;
     }
+
+  /* Not needed any more.  */
+  cu->reset_builder ();
 }
 
 /* Process an imported unit DIE.  */
@@ -10544,21 +10655,21 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_common_inclusion:
       break;
     case DW_TAG_namespace:
-      cu->processing_has_namespace_info = 1;
+      cu->processing_has_namespace_info = true;
       read_namespace (die, cu);
       break;
     case DW_TAG_module:
-      cu->processing_has_namespace_info = 1;
+      cu->processing_has_namespace_info = true;
       read_module (die, cu);
       break;
     case DW_TAG_imported_declaration:
-      cu->processing_has_namespace_info = 1;
+      cu->processing_has_namespace_info = true;
       if (read_namespace_alias (die, cu))
        break;
       /* The declaration is not a global namespace alias.  */
       /* Fall through.  */
     case DW_TAG_imported_module:
-      cu->processing_has_namespace_info = 1;
+      cu->processing_has_namespace_info = true;
       if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
                                 || cu->language != language_fortran))
        complaint (_("Tag '%s' has unexpected children"),
@@ -11093,7 +11204,7 @@ read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu)
 }
 
 /* Return the using directives repository (global or local?) to use in the
-   current context for LANGUAGE.
+   current context for CU.
 
    For Ada, imported declarations can materialize renamings, which *may* be
    global.  However it is impossible (for now?) in DWARF to distinguish
@@ -11102,12 +11213,13 @@ read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu)
    global only in Ada.  */
 
 static struct using_direct **
-using_directives (enum language language)
+using_directives (struct dwarf2_cu *cu)
 {
-  if (language == language_ada && context_stack_depth == 0)
-    return &global_using_directives;
+  if (cu->language == language_ada
+      && cu->get_builder ()->outermost_context_p ())
+    return cu->get_builder ()->get_global_using_directives ();
   else
-    return &local_using_directives;
+    return cu->get_builder ()->get_local_using_directives ();
 }
 
 /* Read the import statement specified by the given die and record it.  */
@@ -11243,7 +11355,7 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
        process_die (child_die, cu);
       }
 
-  add_using_directive (using_directives (cu->language),
+  add_using_directive (using_directives (cu),
                       import_prefix,
                       canonical_name,
                       import_alias,
@@ -11257,7 +11369,7 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
    types, but gives them a size of zero.  Starting with version 14,
    ICC is compatible with GCC.  */
 
-static int
+static bool
 producer_is_icc_lt_14 (struct dwarf2_cu *cu)
 {
   if (!cu->checked_producer)
@@ -11266,11 +11378,24 @@ producer_is_icc_lt_14 (struct dwarf2_cu *cu)
   return cu->producer_is_icc_lt_14;
 }
 
+/* ICC generates a DW_AT_type for C void functions.  This was observed on
+   ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
+   which says that void functions should not have a DW_AT_type.  */
+
+static bool
+producer_is_icc (struct dwarf2_cu *cu)
+{
+  if (!cu->checked_producer)
+    check_producer (cu);
+
+  return cu->producer_is_icc;
+}
+
 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
    directory paths.  GCC SVN r127613 (new option -fdebug-prefix-map) fixed
    this, it was first present in GCC release 4.3.0.  */
 
-static int
+static bool
 producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu)
 {
   if (!cu->checked_producer)
@@ -11432,6 +11557,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
   struct die_info *child_die;
   CORE_ADDR baseaddr;
 
+  prepare_one_comp_unit (cu, die, cu->language);
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
   get_scope_pc_bounds (die, &lowpc, &highpc, cu);
@@ -11444,8 +11570,6 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
 
   file_and_directory fnd = find_file_and_directory (die, cu);
 
-  prepare_one_comp_unit (cu, die, cu->language);
-
   /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
      standardised yet.  As a workaround for the language detection we fall
      back to the DW_AT_producer string.  */
@@ -11456,7 +11580,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
   if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL)
     set_cu_language (DW_LANG_Go, cu);
 
-  dwarf2_start_symtab (cu, fnd.name, fnd.comp_dir, lowpc);
+  cu->start_symtab (fnd.name, fnd.comp_dir, lowpc);
 
   /* Decode line number information if present.  We do this before
      processing child DIEs, so that the line header table is available
@@ -11500,16 +11624,9 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
     }
 }
 
-/* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
-   Create the set of symtabs used by this TU, or if this TU is sharing
-   symtabs with another TU and the symtabs have already been created
-   then restore those symtabs in the line header.
-   We don't need the pc/line-number mapping for type units.  */
-
-static void
-setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
+void
+dwarf2_cu::setup_type_unit_groups (struct die_info *die)
 {
-  struct dwarf2_per_cu_data *per_cu = cu->per_cu;
   struct type_unit_group *tu_group;
   int first_time;
   struct attribute *attr;
@@ -11519,12 +11636,12 @@ setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
   gdb_assert (per_cu->is_debug_types);
   sig_type = (struct signatured_type *) per_cu;
 
-  attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
+  attr = dwarf2_attr (die, DW_AT_stmt_list, this);
 
   /* If we're using .gdb_index (includes -readnow) then
      per_cu->type_unit_group may not have been set up yet.  */
   if (sig_type->type_unit_group == NULL)
-    sig_type->type_unit_group = get_type_unit_group (cu, attr);
+    sig_type->type_unit_group = get_type_unit_group (this, attr);
   tu_group = sig_type->type_unit_group;
 
   /* If we've already processed this stmt_list there's no real need to
@@ -11539,64 +11656,77 @@ setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
   if (attr != NULL)
     {
       sect_offset line_offset = (sect_offset) DW_UNSND (attr);
-      lh = dwarf_decode_line_header (line_offset, cu);
+      lh = dwarf_decode_line_header (line_offset, this);
     }
   if (lh == NULL)
     {
       if (first_time)
-       dwarf2_start_symtab (cu, "", NULL, 0);
+       start_symtab ("", NULL, 0);
       else
        {
          gdb_assert (tu_group->symtabs == NULL);
-         restart_symtab (tu_group->compunit_symtab, "", 0);
+         gdb_assert (m_builder == nullptr);
+         struct compunit_symtab *cust = tu_group->compunit_symtab;
+         m_builder.reset (new struct buildsym_compunit
+                          (COMPUNIT_OBJFILE (cust), "",
+                           COMPUNIT_DIRNAME (cust),
+                           compunit_language (cust),
+                           0, cust));
        }
       return;
     }
 
-  cu->line_header = lh.release ();
-  cu->line_header_die_owner = die;
+  line_header = lh.release ();
+  line_header_die_owner = die;
 
   if (first_time)
     {
-      struct compunit_symtab *cust = dwarf2_start_symtab (cu, "", NULL, 0);
+      struct compunit_symtab *cust = start_symtab ("", NULL, 0);
 
       /* Note: We don't assign tu_group->compunit_symtab yet because we're
         still initializing it, and our caller (a few levels up)
         process_full_type_unit still needs to know if this is the first
         time.  */
 
-      tu_group->num_symtabs = cu->line_header->file_names.size ();
+      tu_group->num_symtabs = line_header->file_names.size ();
       tu_group->symtabs = XNEWVEC (struct symtab *,
-                                  cu->line_header->file_names.size ());
+                                  line_header->file_names.size ());
 
-      for (i = 0; i < cu->line_header->file_names.size (); ++i)
+      for (i = 0; i < line_header->file_names.size (); ++i)
        {
-         file_entry &fe = cu->line_header->file_names[i];
+         file_entry &fe = line_header->file_names[i];
 
-         dwarf2_start_subfile (fe.name, fe.include_dir (cu->line_header));
-
-         if (current_subfile->symtab == NULL)
+         dwarf2_start_subfile (this, fe.name,
+                               fe.include_dir (line_header));
+         buildsym_compunit *b = get_builder ();
+         if (b->get_current_subfile ()->symtab == NULL)
            {
              /* NOTE: start_subfile will recognize when it's been
                 passed a file it has already seen.  So we can't
                 assume there's a simple mapping from
                 cu->line_header->file_names to subfiles, plus
                 cu->line_header->file_names may contain dups.  */
-             current_subfile->symtab
-               = allocate_symtab (cust, current_subfile->name);
+             b->get_current_subfile ()->symtab
+               = allocate_symtab (cust, b->get_current_subfile ()->name);
            }
 
-         fe.symtab = current_subfile->symtab;
+         fe.symtab = b->get_current_subfile ()->symtab;
          tu_group->symtabs[i] = fe.symtab;
        }
     }
   else
     {
-      restart_symtab (tu_group->compunit_symtab, "", 0);
+      gdb_assert (m_builder == nullptr);
+      struct compunit_symtab *cust = tu_group->compunit_symtab;
+      m_builder.reset (new struct buildsym_compunit
+                      (COMPUNIT_OBJFILE (cust), "",
+                       COMPUNIT_DIRNAME (cust),
+                       compunit_language (cust),
+                       0, cust));
 
-      for (i = 0; i < cu->line_header->file_names.size (); ++i)
+      for (i = 0; i < line_header->file_names.size (); ++i)
        {
-         file_entry &fe = cu->line_header->file_names[i];
+         file_entry &fe = line_header->file_names[i];
 
          fe.symtab = tu_group->symtabs[i];
        }
@@ -11624,7 +11754,7 @@ read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
   /* Initialize (or reinitialize) the machinery for building symtabs.
      We do this before processing child DIEs, so that the line header table
      is available for DW_AT_decl_file.  */
-  setup_type_unit_groups (die, cu);
+  cu->setup_type_unit_groups (die);
 
   if (die->child != NULL)
     {
@@ -12082,6 +12212,7 @@ create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
     {
       const gdb_byte *ids_ptr = htab->unit_table + sizeof (uint32_t) * nr_slots;
       int *ids = htab->section_pool.v2.section_ids;
+      size_t sizeof_ids = sizeof (htab->section_pool.v2.section_ids);
       /* Reverse map for error checking.  */
       int ids_seen[DW_SECT_MAX + 1];
       int i;
@@ -12098,8 +12229,8 @@ create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
                   " in section table [in module %s]"),
                 dwp_file->name);
        }
-      memset (ids, 255, (DW_SECT_MAX + 1) * sizeof (int32_t));
-      memset (ids_seen, 255, (DW_SECT_MAX + 1) * sizeof (int32_t));
+      memset (ids, 255, sizeof_ids);
+      memset (ids_seen, 255, sizeof (ids_seen));
       for (i = 0; i < nr_columns; ++i)
        {
          int id = read_4_bytes (dbfd, ids_ptr + i * sizeof (uint32_t));
@@ -13105,8 +13236,7 @@ open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
   std::unique_ptr<struct dwp_file> dwp_file
     (new struct dwp_file (name, std::move (dbfd)));
 
-  /* +1: section 0 is unused */
-  dwp_file->num_sections = bfd_count_sections (dwp_file->dbfd) + 1;
+  dwp_file->num_sections = elf_numsections (dwp_file->dbfd);
   dwp_file->elf_sections =
     OBSTACK_CALLOC (&objfile->objfile_obstack,
                    dwp_file->num_sections, asection *);
@@ -13616,10 +13746,14 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
        }
     }
 
-  newobj = push_context (0, lowpc);
+  newobj = cu->get_builder ()->push_context (0, lowpc);
   newobj->name = new_symbol (die, read_type_die (die, cu), cu,
                             (struct symbol *) templ_func);
 
+  if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu))
+    set_objfile_main_name (objfile, SYMBOL_LINKAGE_NAME (newobj->name),
+                          cu->language);
+
   /* If there is a location expression for DW_AT_frame_base, record
      it.  */
   attr = dwarf2_attr (die, DW_AT_frame_base, cu);
@@ -13636,7 +13770,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       attr_to_dynamic_prop (attr, die, cu, newobj->static_link);
     }
 
-  cu->list_in_scope = &local_symbols;
+  cu->list_in_scope = cu->get_builder ()->get_local_symbols ();
 
   if (die->child != NULL)
     {
@@ -13684,10 +13818,10 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
        }
     }
 
-  newobj = pop_context ();
+  struct context_stack cstk = cu->get_builder ()->pop_context ();
   /* Make a block for the local symbols within.  */
-  block = finish_block (newobj->name, &local_symbols, newobj->old_blocks,
-                       newobj->static_link, lowpc, highpc);
+  block = cu->get_builder ()->finish_block (cstk.name, cstk.old_blocks,
+                                    cstk.static_link, lowpc, highpc);
 
   /* For C++, set the block's scope.  */
   if ((cu->language == language_cplus
@@ -13701,7 +13835,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   /* If we have address ranges, record them.  */
   dwarf2_record_block_ranges (die, block, baseaddr, cu);
 
-  gdbarch_make_symbol_special (gdbarch, newobj->name, objfile);
+  gdbarch_make_symbol_special (gdbarch, cstk.name, objfile);
 
   /* Attach template arguments to function.  */
   if (!template_args.empty ())
@@ -13715,19 +13849,26 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       memcpy (templ_func->template_arguments,
              template_args.data (),
              (templ_func->n_template_arguments * sizeof (struct symbol *)));
+
+      /* Make sure that the symtab is set on the new symbols.  Even
+        though they don't appear in this symtab directly, other parts
+        of gdb assume that symbols do, and this is reasonably
+        true.  */
+      for (symbol *sym : template_args)
+       symbol_set_symtab (sym, symbol_symtab (templ_func));
     }
 
   /* In C++, we can have functions nested inside functions (e.g., when
      a function declares a class that has methods).  This means that
      when we finish processing a function scope, we may need to go
      back to building a containing block's symbol lists.  */
-  local_symbols = newobj->locals;
-  local_using_directives = newobj->local_using_directives;
+  *cu->get_builder ()->get_local_symbols () = cstk.locals;
+  cu->get_builder ()->set_local_using_directives (cstk.local_using_directives);
 
   /* If we've finished processing a top-level function, subsequent
      symbols go in the file symbol list.  */
-  if (outermost_context_p ())
-    cu->list_in_scope = &file_symbols;
+  if (cu->get_builder ()->outermost_context_p ())
+    cu->list_in_scope = cu->get_builder ()->get_file_symbols ();
 }
 
 /* Process all the DIES contained within a lexical block scope.  Start
@@ -13738,7 +13879,6 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  struct context_stack *newobj;
   CORE_ADDR lowpc, highpc;
   struct die_info *child_die;
   CORE_ADDR baseaddr;
@@ -13767,7 +13907,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
   lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
   highpc = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
 
-  push_context (0, lowpc);
+  cu->get_builder ()->push_context (0, lowpc);
   if (die->child != NULL)
     {
       child_die = die->child;
@@ -13778,13 +13918,14 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
        }
     }
   inherit_abstract_dies (die, cu);
-  newobj = pop_context ();
+  struct context_stack cstk = cu->get_builder ()->pop_context ();
 
-  if (local_symbols != NULL || local_using_directives != NULL)
+  if (*cu->get_builder ()->get_local_symbols () != NULL
+      || (*cu->get_builder ()->get_local_using_directives ()) != NULL)
     {
       struct block *block
-        = finish_block (0, &local_symbols, newobj->old_blocks, NULL,
-                       newobj->start_addr, highpc);
+        = 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
@@ -13798,8 +13939,8 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
          to do.  */
       dwarf2_record_block_ranges (die, block, baseaddr, cu);
     }
-  local_symbols = newobj->locals;
-  local_using_directives = newobj->local_using_directives;
+  *cu->get_builder ()->get_local_symbols () = cstk.locals;
+  cu->get_builder ()->set_local_using_directives (cstk.local_using_directives);
 }
 
 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab.  */
@@ -14161,7 +14302,22 @@ read_variable (struct die_info *die, struct dwarf2_cu *cu)
        }
     }
 
-  new_symbol (die, NULL, cu, storage);
+  struct symbol *res = new_symbol (die, NULL, cu, storage);
+  struct attribute *abstract_origin
+    = dwarf2_attr (die, DW_AT_abstract_origin, cu);
+  struct attribute *loc = dwarf2_attr (die, DW_AT_location, cu);
+  if (res == NULL && loc && abstract_origin)
+    {
+      /* We have a variable without a name, but with a location and an abstract
+        origin.  This may be a concrete instance of an abstract variable
+        referenced from an DW_OP_GNU_variable_value, so save it to find it back
+        later.  */
+      struct dwarf2_cu *origin_cu = cu;
+      struct die_info *origin_die
+       = follow_die_ref (die, abstract_origin, &origin_cu);
+      dwarf2_per_objfile *dpo = cu->per_cu->dwarf2_per_objfile;
+      dpo->abstract_to_concrete[origin_die].push_back (die);
+    }
 }
 
 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
@@ -14460,12 +14616,14 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
          CORE_ADDR lowpc;
          CORE_ADDR highpc;
 
-         lowpc = gdbarch_adjust_dwarf2_addr (gdbarch,
-                                             range_beginning + baseaddr);
-         highpc = gdbarch_adjust_dwarf2_addr (gdbarch,
-                                              range_end + baseaddr);
-         addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1,
-                            ranges_pst);
+         lowpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
+                                              range_beginning + baseaddr)
+                  - baseaddr);
+         highpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
+                                               range_end + baseaddr)
+                   - baseaddr);
+         addrmap_set_empty (objfile->partial_symtabs->psymtabs_addrmap,
+                            lowpc, highpc - 1, ranges_pst);
        }
 
       /* FIXME: This is recording everything as a low-high
@@ -14705,7 +14863,7 @@ 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);
-         record_block_range (block, low, high - 1);
+         cu->get_builder ()->record_block_range (block, low, high - 1);
         }
     }
 
@@ -14722,6 +14880,7 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
       unsigned long offset = (DW_UNSND (attr)
                              + (need_ranges_base ? cu->ranges_base : 0));
 
+      std::vector<blockrange> blockvec;
       dwarf2_ranges_process (offset, cu,
        [&] (CORE_ADDR start, CORE_ADDR end)
        {
@@ -14729,8 +14888,11 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
          end += baseaddr;
          start = gdbarch_adjust_dwarf2_addr (gdbarch, start);
          end = gdbarch_adjust_dwarf2_addr (gdbarch, end);
-         record_block_range (block, start, end - 1);
+         cu->get_builder ()->record_block_range (block, start, end - 1);
+         blockvec.emplace_back (start, end);
        });
+
+      BLOCK_RANGES(block) = make_blockranges (objfile, blockvec);
     }
 }
 
@@ -14759,21 +14921,26 @@ check_producer (struct dwarf2_cu *cu)
       cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
     }
   else if (producer_is_icc (cu->producer, &major, &minor))
-    cu->producer_is_icc_lt_14 = major < 14;
+    {
+      cu->producer_is_icc = true;
+      cu->producer_is_icc_lt_14 = major < 14;
+    }
+  else if (startswith (cu->producer, "CodeWarrior S12/L-ISA"))
+    cu->producer_is_codewarrior = true;
   else
     {
       /* For other non-GCC compilers, expect their behavior is DWARF version
         compliant.  */
     }
 
-  cu->checked_producer = 1;
+  cu->checked_producer = true;
 }
 
 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
    to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
    during 4.6.0 experimental.  */
 
-static int
+static bool
 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
 {
   if (!cu->checked_producer)
@@ -14782,6 +14949,19 @@ producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
   return cu->producer_is_gxx_lt_4_6;
 }
 
+
+/* Codewarrior (at least as of version 5.0.40) generates dwarf line information
+   with incorrect is_stmt attributes.  */
+
+static bool
+producer_is_codewarrior (struct dwarf2_cu *cu)
+{
+  if (!cu->checked_producer)
+    check_producer (cu);
+
+  return cu->producer_is_codewarrior;
+}
+
 /* Return the default accessibility type if it is not overriden by
    DW_AT_accessibility.  */
 
@@ -15041,6 +15221,18 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       fp->type = get_die_type (die, cu);
       fp->artificial = 1;
       fp->name = "<<variant>>";
+
+      /* Normally a DW_TAG_variant_part won't have a size, but our
+        representation requires one, so set it to the maximum of the
+        child sizes.  */
+      if (TYPE_LENGTH (fp->type) == 0)
+       {
+         unsigned max = 0;
+         for (int i = 0; i < TYPE_NFIELDS (fp->type); ++i)
+           if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i)) > max)
+             max = TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i));
+         TYPE_LENGTH (fp->type) = max;
+       }
     }
   else
     gdb_assert_not_reached ("missing case in dwarf2_add_field");
@@ -15783,7 +15975,7 @@ handle_struct_member_die (struct die_info *child_die, struct type *type,
         field for our sole member child.  */
       struct attribute *discr = dwarf2_attr (child_die, DW_AT_discr_value, cu);
 
-      for (struct die_info *variant_child = child_die->child;
+      for (die_info *variant_child = child_die->child;
           variant_child != NULL;
           variant_child = sibling_die (variant_child))
        {
@@ -15833,6 +16025,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
      discriminant_info.  */
   bool is_variant_part = TYPE_FLAG_DISCRIMINATED_UNION (type);
   sect_offset discr_offset;
+  bool has_template_parameters = false;
 
   if (is_variant_part)
     {
@@ -15880,6 +16073,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
       /* Attach template arguments to type.  */
       if (!template_args.empty ())
        {
+         has_template_parameters = true;
          ALLOCATE_CPLUS_STRUCT_TYPE (type);
          TYPE_N_TEMPLATE_ARGUMENTS (type) = template_args.size ();
          TYPE_TEMPLATE_ARGUMENTS (type)
@@ -16029,7 +16223,41 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
      attribute, and a declaration attribute.  */
   if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
       || !die_is_declaration (die, cu))
-    new_symbol (die, type, cu);
+    {
+      struct symbol *sym = new_symbol (die, type, cu);
+
+      if (has_template_parameters)
+       {
+         struct symtab *symtab;
+         if (sym != nullptr)
+           symtab = symbol_symtab (sym);
+         else if (cu->line_header != nullptr)
+           {
+             /* Any related symtab will do.  */
+             symtab
+               = cu->line_header->file_name_at (file_name_index (1))->symtab;
+           }
+         else
+           {
+             symtab = nullptr;
+             complaint (_("could not find suitable "
+                          "symtab for template parameter"
+                          " - DIE at %s [in module %s]"),
+                        sect_offset_str (die->sect_off),
+                        objfile_name (objfile));
+           }
+
+         if (symtab != nullptr)
+           {
+             /* Make sure that the symtab is set on the new symbols.
+                Even though they don't appear in this symtab directly,
+                other parts of gdb assume that symbols do, and this is
+                reasonably true.  */
+             for (int i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
+               symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type, i), symtab);
+           }
+       }
+    }
 }
 
 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
@@ -16701,7 +16929,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
          const char *previous_prefix = determine_prefix (die, cu);
 
          std::vector<const char *> excludes;
-         add_using_directive (using_directives (cu->language),
+         add_using_directive (using_directives (cu),
                               previous_prefix, TYPE_NAME (type), NULL,
                               NULL, excludes, 0, &objfile->objfile_obstack);
        }
@@ -16731,9 +16959,6 @@ read_module_type (struct die_info *die, struct dwarf2_cu *cu)
   struct type *type;
 
   module_name = dwarf2_name (die, cu);
-  if (!module_name)
-    complaint (_("DW_TAG_module has no name, offset %s"),
-               sect_offset_str (die->sect_off));
   type = init_type (objfile, TYPE_CODE_MODULE, 0, module_name);
 
   return set_die_type (die, type, cu);
@@ -17314,6 +17539,90 @@ dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
   return type;
 }
 
+/* Allocate an integer type of size BITS and name NAME.  */
+
+static struct type *
+dwarf2_init_integer_type (struct dwarf2_cu *cu, struct objfile *objfile,
+                         int bits, int unsigned_p, const char *name)
+{
+  struct type *type;
+
+  /* Versions of Intel's C Compiler generate an integer type called "void"
+     instead of using DW_TAG_unspecified_type.  This has been seen on
+     at least versions 14, 17, and 18.  */
+  if (bits == 0 && producer_is_icc (cu) && name != nullptr
+      && strcmp (name, "void") == 0)
+    type = objfile_type (objfile)->builtin_void;
+  else
+    type = init_integer_type (objfile, bits, unsigned_p, name);
+
+  return type;
+}
+
+/* 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
+   type.
+
+   As DWARF doesn't currently provide an explicit name for the components
+   of a complex number, but it can be helpful to have these components
+   named, we try to select a suitable name based on the size of the
+   component.  */
+static struct type *
+dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
+                                struct objfile *objfile,
+                                int bits, const char *name_hint)
+{
+  gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct type *tt = nullptr;
+
+  /* Try to find a suitable floating point builtin type of size BITS.
+     We're going to use the name of this type as the name for the complex
+     target type that we are about to create.  */
+  switch (cu->language)
+    {
+    case language_fortran:
+      switch (bits)
+       {
+       case 32:
+         tt = builtin_f_type (gdbarch)->builtin_real;
+         break;
+       case 64:
+         tt = builtin_f_type (gdbarch)->builtin_real_s8;
+         break;
+       case 96:        /* The x86-32 ABI specifies 96-bit long double.  */
+       case 128:
+         tt = builtin_f_type (gdbarch)->builtin_real_s16;
+         break;
+       }
+      break;
+    default:
+      switch (bits)
+       {
+       case 32:
+         tt = builtin_type (gdbarch)->builtin_float;
+         break;
+       case 64:
+         tt = builtin_type (gdbarch)->builtin_double;
+         break;
+       case 96:        /* The x86-32 ABI specifies 96-bit long double.  */
+       case 128:
+         tt = builtin_type (gdbarch)->builtin_long_double;
+         break;
+       }
+      break;
+    }
+
+  /* If the type we found doesn't match the size we were looking for, then
+     pretend we didn't find a type at all, the complex target type we
+     create will then be nameless.  */
+  if (tt != nullptr && TYPE_LENGTH (tt) * TARGET_CHAR_BIT != bits)
+    tt = nullptr;
+
+  const char *name = (tt == nullptr) ? nullptr : TYPE_NAME (tt);
+  return dwarf2_init_float_type (objfile, bits, name, name_hint);
+}
+
 /* Find a representation of a given base type and install
    it in the TYPE field of the die.  */
 
@@ -17353,7 +17662,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        type = init_boolean_type (objfile, bits, 1, name);
        break;
       case DW_ATE_complex_float:
-       type = dwarf2_init_float_type (objfile, bits / 2, NULL, name);
+       type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name);
        type = init_complex_type (objfile, name, type);
        break;
       case DW_ATE_decimal_float:
@@ -17363,7 +17672,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        type = dwarf2_init_float_type (objfile, bits, name, name);
        break;
       case DW_ATE_signed:
-       type = init_integer_type (objfile, bits, 0, name);
+       type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
        break;
       case DW_ATE_unsigned:
        if (cu->language == language_fortran
@@ -17371,7 +17680,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
            && startswith (name, "character("))
          type = init_character_type (objfile, bits, 1, name);
        else
-         type = init_integer_type (objfile, bits, 1, name);
+         type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
        break;
       case DW_ATE_signed_char:
        if (cu->language == language_ada || cu->language == language_m2
@@ -17379,7 +17688,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
            || cu->language == language_fortran)
          type = init_character_type (objfile, bits, 0, name);
        else
-         type = init_integer_type (objfile, bits, 0, name);
+         type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
        break;
       case DW_ATE_unsigned_char:
        if (cu->language == language_ada || cu->language == language_m2
@@ -17388,7 +17697,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
            || cu->language == language_rust)
          type = init_character_type (objfile, bits, 1, name);
        else
-         type = init_integer_type (objfile, bits, 1, name);
+         type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
        break;
       case DW_ATE_UTF:
        {
@@ -17402,7 +17711,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
            {
              complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
                         bits);
-             type = init_integer_type (objfile, bits, 1, name);
+             type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
            }
          return set_die_type (die, type, cu);
        }
@@ -17539,7 +17848,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   int low_default_is_valid;
   int high_bound_is_count = 0;
   const char *name;
-  LONGEST negative_mask;
+  ULONGEST negative_mask;
 
   orig_base_type = die_type (die, cu);
   /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
@@ -17597,10 +17906,11 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
               sect_offset_str (die->sect_off),
               objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
 
-  attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
+  struct attribute *attr_ub, *attr_count;
+  attr = attr_ub = dwarf2_attr (die, DW_AT_upper_bound, cu);
   if (!attr_to_dynamic_prop (attr, die, cu, &high))
     {
-      attr = dwarf2_attr (die, DW_AT_count, cu);
+      attr = attr_count = dwarf2_attr (die, DW_AT_count, cu);
       if (attr_to_dynamic_prop (attr, die, cu, &high))
        {
          /* If bounds are constant do the final calculation here.  */
@@ -17609,6 +17919,20 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
          else
            high_bound_is_count = 1;
        }
+      else
+       {
+         if (attr_ub != NULL)
+           complaint (_("Unresolved DW_AT_upper_bound "
+                        "- DIE at %s [in module %s]"),
+                      sect_offset_str (die->sect_off),
+                      objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+         if (attr_count != NULL)
+           complaint (_("Unresolved DW_AT_count "
+                        "- DIE at %s [in module %s]"),
+                      sect_offset_str (die->sect_off),
+                      objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+       }
+       
     }
 
   /* Dwarf-2 specifications explicitly allows to create subrange types
@@ -17657,7 +17981,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
      the bounds as signed, and thus sign-extend their values, when
      the base type is signed.  */
   negative_mask =
-    -((LONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
+    -((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;
@@ -18209,8 +18533,8 @@ load_partial_dies (const struct die_reader_specs *reader,
        {
          if (building_psymtab && pdi.name != NULL)
            add_psymbol_to_list (pdi.name, strlen (pdi.name), 0,
-                                VAR_DOMAIN, LOC_TYPEDEF,
-                                &objfile->static_psymbols,
+                                VAR_DOMAIN, LOC_TYPEDEF, -1,
+                                psymbol_placement::STATIC,
                                 0, cu->language, objfile);
          info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr);
          continue;
@@ -18243,10 +18567,10 @@ load_partial_dies (const struct die_reader_specs *reader,
            complaint (_("malformed enumerator DIE ignored"));
          else if (building_psymtab)
            add_psymbol_to_list (pdi.name, strlen (pdi.name), 0,
-                                VAR_DOMAIN, LOC_CONST,
+                                VAR_DOMAIN, LOC_CONST, -1,
                                 cu->language == language_cplus
-                                ? &objfile->global_psymbols
-                                : &objfile->static_psymbols,
+                                ? psymbol_placement::GLOBAL
+                                : psymbol_placement::STATIC,
                                 0, cu->language, objfile);
 
          info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr);
@@ -18520,6 +18844,25 @@ partial_die_info::read (const struct die_reader_specs *reader,
          main_subprogram = DW_UNSND (&attr);
          break;
 
+       case DW_AT_ranges:
+         {
+           /* 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)
+                                         + (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, &lowpc, &highpc, cu,
+                                   nullptr))
+             has_pc_info = 1;
+         }
+         break;
+
        default:
          break;
        }
@@ -18589,7 +18932,7 @@ dwarf2_cu::find_partial_die (sect_offset sect_off)
    outside their CU (they do however referencing other types via
    DW_FORM_ref_sig8).  */
 
-static struct partial_die_info *
+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
@@ -18603,7 +18946,7 @@ find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
     {
       pd = cu->find_partial_die (sect_off);
       if (pd != NULL)
-       return pd;
+       return { cu, pd };
       /* We missed recording what we needed.
         Load all dies and try again.  */
       per_cu = cu->per_cu;
@@ -18651,7 +18994,7 @@ find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
                    _("could not find partial DIE %s "
                      "in cache [from module %s]\n"),
                    sect_offset_str (sect_off), bfd_get_filename (objfile->obfd));
-  return pd;
+  return { per_cu->cu, pd };
 }
 
 /* See if we can figure out if the class lives in a namespace.  We do
@@ -18677,8 +19020,12 @@ guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
 
   real_pdi = struct_pdi;
   while (real_pdi->has_specification)
-    real_pdi = find_partial_die (real_pdi->spec_offset,
-                                real_pdi->spec_is_dwz, cu);
+    {
+      auto res = find_partial_die (real_pdi->spec_offset,
+                                  real_pdi->spec_is_dwz, cu);
+      real_pdi = res.pdi;
+      cu = res.cu;
+    }
 
   if (real_pdi->die_parent != NULL)
     return;
@@ -18724,7 +19071,9 @@ partial_die_info::fixup (struct dwarf2_cu *cu)
     {
       struct partial_die_info *spec_die;
 
-      spec_die = find_partial_die (spec_offset, spec_is_dwz, cu);
+      auto res = find_partial_die (spec_offset, spec_is_dwz, cu);
+      spec_die = res.pdi;
+      cu = res.cu;
 
       spec_die->fixup (cu);
 
@@ -18986,6 +19335,7 @@ read_attribute_value (const struct die_reader_specs *reader,
     case DW_FORM_implicit_const:
       DW_SND (attr) = implicit_const;
       break;
+    case DW_FORM_addrx:
     case DW_FORM_GNU_addr_index:
       if (reader->dwo_file == NULL)
        {
@@ -18998,6 +19348,11 @@ read_attribute_value (const struct die_reader_specs *reader,
       DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read);
       info_ptr += bytes_read;
       break;
+    case DW_FORM_strx:
+    case DW_FORM_strx1:
+    case DW_FORM_strx2:
+    case DW_FORM_strx3:
+    case DW_FORM_strx4:
     case DW_FORM_GNU_str_index:
       if (reader->dwo_file == NULL)
        {
@@ -19008,12 +19363,34 @@ read_attribute_value (const struct die_reader_specs *reader,
                 bfd_get_filename (abfd));
        }
       {
-       ULONGEST str_index =
-         read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
-
+       ULONGEST str_index;
+       if (form == DW_FORM_strx1)
+         {
+           str_index = read_1_byte (abfd, info_ptr);
+           info_ptr += 1;
+         }
+       else if (form == DW_FORM_strx2)
+         {
+           str_index = read_2_bytes (abfd, info_ptr);
+           info_ptr += 2;
+         }
+       else if (form == DW_FORM_strx3)
+         {
+           str_index = read_3_bytes (abfd, info_ptr);
+           info_ptr += 3;
+         }
+       else if (form == DW_FORM_strx4)
+         {
+           str_index = read_4_bytes (abfd, info_ptr);
+           info_ptr += 4;
+         }
+       else
+         {
+           str_index = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+           info_ptr += bytes_read;
+         }
        DW_STRING (attr) = read_str_index (reader, str_index);
        DW_STRING_IS_CANONICAL (attr) = 0;
-       info_ptr += bytes_read;
       }
       break;
     default:
@@ -19083,6 +19460,19 @@ read_2_signed_bytes (bfd *abfd, const gdb_byte *buf)
   return bfd_get_signed_16 (abfd, buf);
 }
 
+static unsigned int
+read_3_bytes (bfd *abfd, const gdb_byte *buf)
+{
+  unsigned int result = 0;
+  for (int i = 0; i < 3; ++i)
+    {
+      unsigned char byte = bfd_get_8 (abfd, buf);
+      buf++;
+      result |= ((unsigned int) byte << (i * 8));
+    }
+  return result;
+}
+
 static unsigned int
 read_4_bytes (bfd *abfd, const gdb_byte *buf)
 {
@@ -19442,7 +19832,7 @@ static LONGEST
 read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
                    unsigned int *bytes_read_ptr)
 {
-  LONGEST result;
+  ULONGEST result;
   int shift, num_read;
   unsigned char byte;
 
@@ -19454,7 +19844,7 @@ read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
       byte = bfd_get_8 (abfd, buf);
       buf++;
       num_read++;
-      result |= ((LONGEST) (byte & 127) << shift);
+      result |= ((ULONGEST) (byte & 127) << shift);
       shift += 7;
       if ((byte & 128) == 0)
        {
@@ -19462,7 +19852,7 @@ read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
        }
     }
   if ((shift < 8 * sizeof (result)) && (byte & 0x40))
-    result |= -(((LONGEST) 1) << shift);
+    result |= -(((ULONGEST) 1) << shift);
   *bytes_read_ptr = num_read;
   return result;
 }
@@ -19593,7 +19983,7 @@ dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu,
                            addr_size);
 }
 
-/* Given a DW_FORM_GNU_str_index, fetch the string.
+/* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
    This is only used by the Fission support.  */
 
 static const char *
@@ -19610,7 +20000,7 @@ read_str_index (const struct die_reader_specs *reader, ULONGEST str_index)
     &reader->dwo_file->sections.str_offsets;
   const gdb_byte *info_ptr;
   ULONGEST str_offset;
-  static const char form_name[] = "DW_FORM_GNU_str_index";
+  static const char form_name[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
 
   dwarf2_read_section (objfile, str_section);
   dwarf2_read_section (objfile, str_offsets_section);
@@ -19776,6 +20166,7 @@ dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *c
     {
       if (attr->form == DW_FORM_strp || attr->form == DW_FORM_line_strp
          || attr->form == DW_FORM_string
+         || attr->form == DW_FORM_strx
          || attr->form == DW_FORM_GNU_str_index
          || attr->form == DW_FORM_GNU_strp_alt)
        str = DW_STRING (attr);
@@ -20154,21 +20545,21 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
       /* Read directory table.  */
       read_formatted_entries (dwarf2_per_objfile, abfd, &line_ptr, lh.get (),
                              &cu->header,
-                             [] (struct line_header *lh, const char *name,
+                             [] (struct line_header *header, const char *name,
                                  dir_index d_index, unsigned int mod_time,
                                  unsigned int length)
        {
-         lh->add_include_dir (name);
+         header->add_include_dir (name);
        });
 
       /* Read file name table.  */
       read_formatted_entries (dwarf2_per_objfile, abfd, &line_ptr, lh.get (),
                              &cu->header,
-                             [] (struct line_header *lh, const char *name,
+                             [] (struct line_header *header, const char *name,
                                  dir_index d_index, unsigned int mod_time,
                                  unsigned int length)
        {
-         lh->add_file_name (name, d_index, mod_time, length);
+         header->add_file_name (name, d_index, mod_time, length);
        });
     }
   else
@@ -20292,7 +20683,8 @@ class lnp_state_machine
 public:
   /* Initialize a machine state for the start of a line number
      program.  */
-  lnp_state_machine (gdbarch *arch, line_header *lh, bool record_lines_p);
+  lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch, line_header *lh,
+                    bool record_lines_p);
 
   file_entry *current_file ()
   {
@@ -20366,7 +20758,7 @@ public:
   /* Handle DW_LNE_end_sequence.  */
   void handle_end_sequence ()
   {
-    m_record_line_callback = ::record_line;
+    m_currently_recording_lines = true;
   }
 
 private:
@@ -20379,6 +20771,8 @@ private:
       m_line_has_non_zero_discriminator = m_discriminator != 0;
   }
 
+  struct dwarf2_cu *m_cu;
+
   gdbarch *m_gdbarch;
 
   /* True if we're recording lines.
@@ -20411,8 +20805,8 @@ private:
   /* The last file a line number was recorded for.  */
   struct subfile *m_last_subfile = NULL;
 
-  /* The function to call to record a line.  */
-  record_line_ftype *m_record_line_callback = NULL;
+  /* When true, record the lines we decode.  */
+  bool m_currently_recording_lines = false;
 
   /* The last line number that was recorded, used to coalesce
      consecutive entries for the same line.  This can happen, for
@@ -20463,9 +20857,9 @@ lnp_state_machine::handle_set_file (file_name_index file)
     {
       const char *dir = fe->include_dir (m_line_header);
 
-      m_last_subfile = current_subfile;
+      m_last_subfile = m_cu->get_builder ()->get_current_subfile ();
       m_line_has_non_zero_discriminator = m_discriminator != 0;
-      dwarf2_start_subfile (fe->name, dir);
+      dwarf2_start_subfile (m_cu, fe->name, dir);
     }
 }
 
@@ -20485,14 +20879,6 @@ lnp_state_machine::handle_const_add_pc ()
                % m_line_header->maximum_ops_per_instruction);
 }
 
-/* Ignore this record_line request.  */
-
-static void
-noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
-{
-  return;
-}
-
 /* Return non-zero if we should add LINE to the line number table.
    LINE is the line to add, LAST_LINE is the last line that was added,
    LAST_SUBFILE is the subfile for LAST_LINE.
@@ -20524,11 +20910,12 @@ noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
    within one sequence, thus this coalescing is ok.  */
 
 static int
-dwarf_record_line_p (unsigned int line, unsigned int last_line,
+dwarf_record_line_p (struct dwarf2_cu *cu,
+                    unsigned int line, unsigned int last_line,
                     int line_has_non_zero_discriminator,
                     struct subfile *last_subfile)
 {
-  if (current_subfile != last_subfile)
+  if (cu->get_builder ()->get_current_subfile () != last_subfile)
     return 1;
   if (line != last_line)
     return 1;
@@ -20540,13 +20927,13 @@ dwarf_record_line_p (unsigned int line, unsigned int last_line,
   return 0;
 }
 
-/* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
-   in the line table of subfile SUBFILE.  */
+/* Use the CU's builder to record line number LINE beginning at
+   address ADDRESS in the line table of subfile SUBFILE.  */
 
 static void
 dwarf_record_line_1 (struct gdbarch *gdbarch, struct subfile *subfile,
                     unsigned int line, CORE_ADDR address,
-                    record_line_ftype p_record_line)
+                    struct dwarf2_cu *cu)
 {
   CORE_ADDR addr = gdbarch_addr_bits_remove (gdbarch, address);
 
@@ -20558,7 +20945,8 @@ dwarf_record_line_1 (struct gdbarch *gdbarch, struct subfile *subfile,
                          paddress (gdbarch, address));
     }
 
-  (*p_record_line) (subfile, line, addr);
+  if (cu != nullptr)
+    cu->get_builder ()->record_line (subfile, line, addr);
 }
 
 /* Subroutine of dwarf_decode_lines_1 to simplify it.
@@ -20568,7 +20956,7 @@ dwarf_record_line_1 (struct gdbarch *gdbarch, struct subfile *subfile,
 
 static void
 dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile,
-                  CORE_ADDR address, record_line_ftype p_record_line)
+                  CORE_ADDR address, struct dwarf2_cu *cu)
 {
   if (subfile == NULL)
     return;
@@ -20581,7 +20969,7 @@ dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile,
                          paddress (gdbarch, address));
     }
 
-  dwarf_record_line_1 (gdbarch, subfile, 0, address, p_record_line);
+  dwarf_record_line_1 (gdbarch, subfile, 0, address, cu);
 }
 
 void
@@ -20607,39 +20995,43 @@ lnp_state_machine::record_line (bool end_sequence)
   else if (m_op_index == 0 || end_sequence)
     {
       fe->included_p = 1;
-      if (m_record_lines_p && m_is_stmt)
+      if (m_record_lines_p && (producer_is_codewarrior (m_cu) || m_is_stmt))
        {
-         if (m_last_subfile != current_subfile || end_sequence)
+         if (m_last_subfile != m_cu->get_builder ()->get_current_subfile ()
+             || end_sequence)
            {
-             dwarf_finish_line (m_gdbarch, m_last_subfile,
-                                m_address, m_record_line_callback);
+             dwarf_finish_line (m_gdbarch, m_last_subfile, m_address,
+                                m_currently_recording_lines ? m_cu : nullptr);
            }
 
          if (!end_sequence)
            {
-             if (dwarf_record_line_p (m_line, m_last_line,
+             if (dwarf_record_line_p (m_cu, m_line, m_last_line,
                                       m_line_has_non_zero_discriminator,
                                       m_last_subfile))
                {
-                 dwarf_record_line_1 (m_gdbarch, current_subfile,
+                 buildsym_compunit *builder = m_cu->get_builder ();
+                 dwarf_record_line_1 (m_gdbarch,
+                                      builder->get_current_subfile (),
                                       m_line, m_address,
-                                      m_record_line_callback);
+                                      m_currently_recording_lines ? m_cu : nullptr);
                }
-             m_last_subfile = current_subfile;
+             m_last_subfile = m_cu->get_builder ()->get_current_subfile ();
              m_last_line = m_line;
            }
        }
     }
 }
 
-lnp_state_machine::lnp_state_machine (gdbarch *arch, line_header *lh,
-                                     bool record_lines_p)
+lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch,
+                                     line_header *lh, bool record_lines_p)
 {
+  m_cu = cu;
   m_gdbarch = arch;
   m_record_lines_p = record_lines_p;
   m_line_header = lh;
 
-  m_record_line_callback = ::record_line;
+  m_currently_recording_lines = true;
 
   /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
      was a line entry for it so that the backend has a chance to adjust it
@@ -20670,9 +21062,9 @@ lnp_state_machine::check_line_address (struct dwarf2_cu *cu,
 
       complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
                 line_offset, objfile_name (objfile));
-      m_record_line_callback = noop_record_line;
-      /* Note: record_line_callback is left as noop_record_line until
-        we see DW_LNE_end_sequence.  */
+      m_currently_recording_lines = false;
+      /* Note: m_currently_recording_lines is left as false until we see
+        DW_LNE_end_sequence.  */
     }
 }
 
@@ -20708,7 +21100,7 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
     {
       /* The DWARF line number program state machine.  Reset the state
         machine at the start of each sequence.  */
-      lnp_state_machine state_machine (gdbarch, lh, record_lines_p);
+      lnp_state_machine state_machine (cu, gdbarch, lh, record_lines_p);
       bool end_sequence = false;
 
       if (record_lines_p)
@@ -20718,7 +21110,7 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
          const file_entry *fe = state_machine.current_file ();
 
          if (fe != NULL)
-           dwarf2_start_subfile (fe->name, fe->include_dir (lh));
+           dwarf2_start_subfile (cu, fe->name, fe->include_dir (lh));
        }
 
       /* Decode the table.  */
@@ -20947,21 +21339,23 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
       /* Make sure a symtab is created for every file, even files
         which contain only variables (i.e. no code with associated
         line numbers).  */
-      struct compunit_symtab *cust = buildsym_compunit_symtab ();
+      buildsym_compunit *builder = cu->get_builder ();
+      struct compunit_symtab *cust = builder->get_compunit_symtab ();
       int i;
 
       for (i = 0; i < lh->file_names.size (); i++)
        {
          file_entry &fe = lh->file_names[i];
 
-         dwarf2_start_subfile (fe.name, fe.include_dir (lh));
+         dwarf2_start_subfile (cu, fe.name, fe.include_dir (lh));
 
-         if (current_subfile->symtab == NULL)
+         if (builder->get_current_subfile ()->symtab == NULL)
            {
-             current_subfile->symtab
-               = allocate_symtab (cust, current_subfile->name);
+             builder->get_current_subfile ()->symtab
+               = allocate_symtab (cust,
+                                  builder->get_current_subfile ()->name);
            }
-         fe.symtab = current_subfile->symtab;
+         fe.symtab = builder->get_current_subfile ()->symtab;
        }
     }
 }
@@ -20990,7 +21384,8 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
    subfile's name.  */
 
 static void
-dwarf2_start_subfile (const char *filename, const char *dirname)
+dwarf2_start_subfile (struct dwarf2_cu *cu, const char *filename,
+                     const char *dirname)
 {
   char *copy = NULL;
 
@@ -21007,32 +21402,33 @@ dwarf2_start_subfile (const char *filename, const char *dirname)
       filename = copy;
     }
 
-  start_subfile (filename);
+  cu->get_builder ()->start_subfile (filename);
 
   if (copy != NULL)
     xfree (copy);
 }
 
-/* Start a symtab for DWARF.
-   NAME, COMP_DIR, LOW_PC are passed to start_symtab.  */
+/* Start a symtab for DWARF.  NAME, COMP_DIR, LOW_PC are passed to the
+   buildsym_compunit constructor.  */
 
-static struct compunit_symtab *
-dwarf2_start_symtab (struct dwarf2_cu *cu,
-                    const char *name, const char *comp_dir, CORE_ADDR low_pc)
+struct compunit_symtab *
+dwarf2_cu::start_symtab (const char *name, const char *comp_dir,
+                        CORE_ADDR low_pc)
 {
-  struct compunit_symtab *cust
-    = start_symtab (cu->per_cu->dwarf2_per_objfile->objfile, name, comp_dir,
-                   low_pc, cu->language);
+  gdb_assert (m_builder == nullptr);
 
-  record_debugformat ("DWARF 2");
-  record_producer (cu->producer);
+  m_builder.reset (new struct buildsym_compunit
+                  (per_cu->dwarf2_per_objfile->objfile,
+                   name, comp_dir, language, low_pc));
 
-  /* We assume that we're processing GCC output.  */
-  processing_gcc_compilation = 2;
+  list_in_scope = get_builder ()->get_file_symbols ();
 
-  cu->processing_has_namespace_info = 0;
+  get_builder ()->record_debugformat ("DWARF 2");
+  get_builder ()->record_producer (producer);
 
-  return cust;
+  processing_has_namespace_info = false;
+
+  return get_builder ()->get_compunit_symtab ();
 }
 
 static void
@@ -21062,13 +21458,14 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
 
   /* Handle one degenerate form of location expression specially, to
      preserve GDB's previous behavior when section offsets are
-     specified.  If this is just a DW_OP_addr or DW_OP_GNU_addr_index
-     then mark this symbol as LOC_STATIC.  */
+     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 (attr)
       && ((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_GNU_addr_index
+               || DW_BLOCK (attr)->data[0] == DW_OP_addrx)
              && (DW_BLOCK (attr)->size
                  == 1 + leb128_size (&DW_BLOCK (attr)->data[1])))))
     {
@@ -21097,7 +21494,7 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
   dwarf2_symbol_mark_computed (attr, sym, cu, 0);
 
   if (SYMBOL_COMPUTED_OPS (sym)->location_has_loclist)
-    cu->has_loclist = 1;
+    cu->has_loclist = true;
 }
 
 /* Given a pointer to a DWARF information entry, figure out if we need
@@ -21218,7 +21615,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
                  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 = &global_symbols;
+             list_to_add = cu->get_builder ()->get_global_symbols ();
            }
          else
            {
@@ -21261,7 +21658,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
              if (!suppress_add)
                {
                  if (attr2 && (DW_UNSND (attr2) != 0))
-                   list_to_add = &global_symbols;
+                   list_to_add = cu->get_builder ()->get_global_symbols ();
                  else
                    list_to_add = cu->list_in_scope;
                }
@@ -21306,8 +21703,11 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 
                  /* A variable with DW_AT_external is never static,
                     but it may be block-scoped.  */
-                 list_to_add = (cu->list_in_scope == &file_symbols
-                                ? &global_symbols : cu->list_in_scope);
+                 list_to_add
+                   = ((cu->list_in_scope
+                       == cu->get_builder ()->get_file_symbols ())
+                      ? cu->get_builder ()->get_global_symbols ()
+                      : cu->list_in_scope);
                }
              else
                list_to_add = cu->list_in_scope;
@@ -21337,8 +21737,11 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
                {
                  /* A variable with DW_AT_external is never static, but it
                     may be block-scoped.  */
-                 list_to_add = (cu->list_in_scope == &file_symbols
-                                ? &global_symbols : cu->list_in_scope);
+                 list_to_add
+                   = ((cu->list_in_scope
+                       == cu->get_builder ()->get_file_symbols ())
+                      ? cu->get_builder ()->get_global_symbols ()
+                      : cu->list_in_scope);
 
                  SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED;
                }
@@ -21352,26 +21755,29 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
            }
          break;
        case DW_TAG_formal_parameter:
-         /* If we are inside a function, mark this as an argument.  If
-            not, we might be looking at an argument to an inlined function
-            when we do not have enough information to show inlined frames;
-            pretend it's a local variable in that case so that the user can
-            still see it.  */
-         if (context_stack_depth > 0
-             && context_stack[context_stack_depth - 1].name != NULL)
-           SYMBOL_IS_ARGUMENT (sym) = 1;
-         attr = dwarf2_attr (die, DW_AT_location, cu);
-         if (attr)
-           {
-             var_decode_location (attr, sym, cu);
-           }
-         attr = dwarf2_attr (die, DW_AT_const_value, cu);
-         if (attr)
-           {
-             dwarf2_const_value (attr, sym, cu);
-           }
+         {
+           /* If we are inside a function, mark this as an argument.  If
+              not, we might be looking at an argument to an inlined function
+              when we do not have enough information to show inlined frames;
+              pretend it's a local variable in that case so that the user can
+              still see it.  */
+           struct context_stack *curr
+             = cu->get_builder ()->get_current_context_stack ();
+           if (curr != nullptr && curr->name != nullptr)
+             SYMBOL_IS_ARGUMENT (sym) = 1;
+           attr = dwarf2_attr (die, DW_AT_location, cu);
+           if (attr)
+             {
+               var_decode_location (attr, sym, cu);
+             }
+           attr = dwarf2_attr (die, DW_AT_const_value, cu);
+           if (attr)
+             {
+               dwarf2_const_value (attr, sym, cu);
+             }
 
-         list_to_add = cu->list_in_scope;
+           list_to_add = cu->list_in_scope;
+         }
          break;
        case DW_TAG_unspecified_parameters:
          /* From varargs functions; gdb doesn't seem to have any
@@ -21401,9 +21807,12 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 
            if (!suppress_add)
              {
-               list_to_add = (cu->list_in_scope == &file_symbols
-                              && cu->language == language_cplus
-                              ? &global_symbols : cu->list_in_scope);
+               buildsym_compunit *builder = cu->get_builder ();
+               list_to_add
+                 = (cu->list_in_scope == builder->get_file_symbols ()
+                    && cu->language == language_cplus
+                    ? builder->get_global_symbols ()
+                    : cu->list_in_scope);
 
                /* The semantics of C++ state that "struct foo {
                   ... }" also defines a typedef for "foo".  */
@@ -21442,20 +21851,22 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
            /* NOTE: carlton/2003-11-10: See comment above in the
               DW_TAG_class_type, etc. block.  */
 
-           list_to_add = (cu->list_in_scope == &file_symbols
-                          && cu->language == language_cplus
-                          ? &global_symbols : cu->list_in_scope);
+           list_to_add
+             = (cu->list_in_scope == cu->get_builder ()->get_file_symbols ()
+                && cu->language == language_cplus
+                ? cu->get_builder ()->get_global_symbols ()
+                : cu->list_in_scope);
          }
          break;
        case DW_TAG_imported_declaration:
        case DW_TAG_namespace:
          SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
-         list_to_add = &global_symbols;
+         list_to_add = cu->get_builder ()->get_global_symbols ();
          break;
        case DW_TAG_module:
          SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
          SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
-         list_to_add = &global_symbols;
+         list_to_add = cu->get_builder ()->get_global_symbols ();
          break;
        case DW_TAG_common_block:
          SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
@@ -21486,7 +21897,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
         namespaces based on the demangled name.  */
       if (!cu->processing_has_namespace_info
          && cu->language == language_cplus)
-       cp_scan_for_anonymous_namespaces (sym, objfile);
+       cp_scan_for_anonymous_namespaces (cu->get_builder (), sym, objfile);
     }
   return (sym);
 }
@@ -21551,6 +21962,7 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
   switch (attr->form)
     {
     case DW_FORM_addr:
+    case DW_FORM_addrx:
     case DW_FORM_GNU_addr_index:
       {
        gdb_byte *data;
@@ -21578,6 +21990,7 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
       break;
     case DW_FORM_string:
     case DW_FORM_strp:
+    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
@@ -21753,15 +22166,15 @@ build_error_marker_type (struct dwarf2_cu *cu, struct die_info *die)
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = cu->per_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
-  char *message, *saved;
+  char *saved;
 
-  message = xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
-                       objfile_name (objfile),
-                       sect_offset_str (cu->header.sect_off),
-                       sect_offset_str (die->sect_off));
+  std::string message
+    = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
+                    objfile_name (objfile),
+                    sect_offset_str (cu->header.sect_off),
+                    sect_offset_str (die->sect_off));
   saved = (char *) obstack_copy0 (&objfile->objfile_obstack,
-                                 message, strlen (message));
-  xfree (message);
+                                 message.c_str (), message.length ());
 
   return init_type (objfile, TYPE_CODE_ERROR, 0, saved);
 }
@@ -22422,6 +22835,18 @@ dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
   return follow_die_ref (die, attr, ext_cu);
 }
 
+/* A convenience function that returns an "unknown" DWARF name,
+   including the value of V.  STR is the name of the entity being
+   printed, e.g., "TAG".  */
+
+static const char *
+dwarf_unknown (const char *str, unsigned v)
+{
+  char *cell = get_print_cell ();
+  xsnprintf (cell, PRINT_CELL_SIZE, "DW_%s_<unknown: %u>", str, v);
+  return cell;
+}
+
 /* Convert a DIE tag into its string name.  */
 
 static const char *
@@ -22430,7 +22855,7 @@ dwarf_tag_name (unsigned tag)
   const char *name = get_DW_TAG_name (tag);
 
   if (name == NULL)
-    return "DW_TAG_<unknown>";
+    return dwarf_unknown ("TAG", tag);
 
   return name;
 }
@@ -22453,7 +22878,7 @@ dwarf_attr_name (unsigned attr)
   name = get_DW_AT_name (attr);
 
   if (name == NULL)
-    return "DW_AT_<unknown>";
+    return dwarf_unknown ("AT", attr);
 
   return name;
 }
@@ -22466,7 +22891,7 @@ dwarf_form_name (unsigned form)
   const char *name = get_DW_FORM_name (form);
 
   if (name == NULL)
-    return "DW_FORM_<unknown>";
+    return dwarf_unknown ("FORM", form);
 
   return name;
 }
@@ -22488,7 +22913,7 @@ dwarf_type_encoding_name (unsigned enc)
   const char *name = get_DW_ATE_name (enc);
 
   if (name == NULL)
-    return "DW_ATE_<unknown>";
+    return dwarf_unknown ("ATE", enc);
 
   return name;
 }
@@ -22527,6 +22952,7 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
       switch (die->attrs[i].form)
        {
        case DW_FORM_addr:
+       case DW_FORM_addrx:
        case DW_FORM_GNU_addr_index:
          fprintf_unfiltered (f, "address: ");
          fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
@@ -22581,6 +23007,7 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
        case DW_FORM_string:
        case DW_FORM_strp:
        case DW_FORM_line_strp:
+       case DW_FORM_strx:
        case DW_FORM_GNU_str_index:
        case DW_FORM_GNU_strp_alt:
          fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
@@ -22787,6 +23214,10 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
 
   *ref_cu = target_cu;
   temp_die.sect_off = sect_off;
+
+  if (target_cu != cu)
+    target_cu->ancestor = cu;
+
   return (struct die_info *) htab_find_with_hash (target_cu->die_hash,
                                                  &temp_die,
                                                  to_underlying (sect_off));
@@ -22826,7 +23257,7 @@ struct dwarf2_locexpr_baton
 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
                               struct dwarf2_per_cu_data *per_cu,
                               CORE_ADDR (*get_frame_pc) (void *baton),
-                              void *baton)
+                              void *baton, bool resolve_abstract_p)
 {
   struct dwarf2_cu *cu;
   struct die_info *die;
@@ -22852,6 +23283,30 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
           sect_offset_str (sect_off), objfile_name (objfile));
 
   attr = dwarf2_attr (die, DW_AT_location, cu);
+  if (!attr && resolve_abstract_p
+      && (dwarf2_per_objfile->abstract_to_concrete.find (die)
+         != dwarf2_per_objfile->abstract_to_concrete.end ()))
+    {
+      CORE_ADDR pc = (*get_frame_pc) (baton);
+
+      for (const auto &cand : dwarf2_per_objfile->abstract_to_concrete[die])
+       {
+         if (!cand->parent
+             || cand->parent->tag != DW_TAG_subprogram)
+           continue;
+
+         CORE_ADDR pc_low, pc_high;
+         get_scope_pc_bounds (cand->parent, &pc_low, &pc_high, cu);
+         if (pc_low == ((CORE_ADDR) -1)
+             || !(pc_low <= pc && pc < pc_high))
+           continue;
+
+         die = cand;
+         attr = dwarf2_attr (die, DW_AT_location, cu);
+         break;
+       }
+    }
+
   if (!attr)
     {
       /* DWARF: "If there is no such attribute, then there is no effect.".
@@ -22968,6 +23423,7 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
   switch (attr->form)
     {
     case DW_FORM_addr:
+    case DW_FORM_addrx:
     case DW_FORM_GNU_addr_index:
       {
        gdb_byte *tem;
@@ -22980,6 +23436,7 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
       break;
     case DW_FORM_string:
     case DW_FORM_strp:
+    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
@@ -23097,7 +23554,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
                  struct dwarf2_cu **ref_cu)
 {
   struct die_info temp_die;
-  struct dwarf2_cu *sig_cu;
+  struct dwarf2_cu *sig_cu, *cu = *ref_cu;
   struct die_info *die;
 
   /* While it might be nice to assert sig_type->type == NULL here,
@@ -23131,6 +23588,9 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
        }
 
       *ref_cu = sig_cu;
+      if (sig_cu != cu)
+       sig_cu->ancestor = cu;
+
       return die;
     }
 
@@ -23569,6 +24029,7 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
        case DW_OP_GNU_uninit:
          break;
 
+       case DW_OP_addrx:
        case DW_OP_GNU_addr_index:
        case DW_OP_GNU_const_index:
          stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i],
@@ -23695,7 +24156,8 @@ file_full_name (int file, struct line_header *lh, const char *comp_dir)
 
 
 static struct macro_source_file *
-macro_start_file (int file, int line,
+macro_start_file (struct dwarf2_cu *cu,
+                 int file, int line,
                   struct macro_source_file *current_file,
                   struct line_header *lh)
 {
@@ -23706,7 +24168,7 @@ macro_start_file (int file, int line,
     {
       /* Note: We don't create a macro table for this compilation unit
         at all until we actually get a filename.  */
-      struct macro_table *macro_table = get_macro_table ();
+      struct macro_table *macro_table = cu->get_builder ()->get_macro_table ();
 
       /* If we have no current file, then this must be the start_file
         directive for the compilation unit's main source file.  */
@@ -23938,7 +24400,9 @@ skip_form_bytes (bfd *abfd, const gdb_byte *bytes, const gdb_byte *buffer_end,
       bytes += 4 + read_4_bytes (abfd, bytes);
       break;
 
+    case DW_FORM_addrx:
     case DW_FORM_sdata:
+    case DW_FORM_strx:
     case DW_FORM_udata:
     case DW_FORM_GNU_addr_index:
     case DW_FORM_GNU_str_index:
@@ -24070,7 +24534,7 @@ dwarf_parse_macro_header (const gdb_byte **opcode_definitions,
    including DW_MACRO_import.  */
 
 static void
-dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
+dwarf_decode_macro_bytes (struct dwarf2_cu *cu,
                          bfd *abfd,
                          const gdb_byte *mac_ptr, const gdb_byte *mac_end,
                          struct macro_source_file *current_file,
@@ -24080,6 +24544,8 @@ dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
                          unsigned int offset_size,
                          htab_t include_hash)
 {
+  struct dwarf2_per_objfile *dwarf2_per_objfile
+    = cu->per_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   enum dwarf_macro_record_type macinfo_type;
   int at_commandline;
@@ -24187,7 +24653,21 @@ dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
                         is_define ? _("definition") : _("undefinition"),
                         line == 0 ? _("zero") : _("non-zero"), line, body);
 
-           if (is_define)
+           if (body == NULL)
+             {
+               /* Fedora's rpm-build's "debugedit" binary
+                  corrupted .debug_macro sections.
+
+                  For more info, see
+                  https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
+               complaint (_("debug info gives %s invalid macro %s "
+                            "without body (corrupted?) at line %d "
+                            "on file %s"),
+                          at_commandline ? _("command-line") : _("in-file"),
+                          is_define ? _("definition") : _("undefinition"),
+                          line, current_file->filename);
+             }
+           else if (is_define)
              parse_macro_definition (current_file, line, body);
            else
              {
@@ -24223,7 +24703,8 @@ dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
                at_commandline = 0;
              }
            else
-             current_file = macro_start_file (file, line, current_file, lh);
+             current_file = macro_start_file (cu, file, line, current_file,
+                                              lh);
           }
           break;
 
@@ -24304,8 +24785,7 @@ dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
              {
                *slot = (void *) new_mac_ptr;
 
-               dwarf_decode_macro_bytes (dwarf2_per_objfile,
-                                         include_bfd, new_mac_ptr,
+               dwarf_decode_macro_bytes (cu, include_bfd, new_mac_ptr,
                                          include_mac_end, current_file, lh,
                                          section, section_is_gnu, is_dwz,
                                          offset_size, include_hash);
@@ -24467,7 +24947,7 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
            file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
            mac_ptr += bytes_read;
 
-           current_file = macro_start_file (file, line, current_file, lh);
+           current_file = macro_start_file (cu, file, line, current_file, lh);
          }
          break;
 
@@ -24532,8 +25012,7 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
   mac_ptr = section->buffer + offset;
   slot = htab_find_slot (include_hash.get (), mac_ptr, INSERT);
   *slot = (void *) mac_ptr;
-  dwarf_decode_macro_bytes (dwarf2_per_objfile,
-                           abfd, mac_ptr, mac_end,
+  dwarf_decode_macro_bytes (cu, abfd, mac_ptr, mac_end,
                            current_file, lh, section,
                            section_is_gnu, 0, offset_size,
                            include_hash.get ());
@@ -24842,7 +25321,6 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
 {
   struct dwarf2_per_cu_data *this_cu;
   int low, high;
-  const sect_offset *cu_off;
 
   low = 0;
   high = dwarf2_per_objfile->all_comp_units.size () - 1;
@@ -24852,17 +25330,16 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
       int mid = low + (high - low) / 2;
 
       mid_cu = dwarf2_per_objfile->all_comp_units[mid];
-      cu_off = &mid_cu->sect_off;
       if (mid_cu->is_dwz > offset_in_dwz
-         || (mid_cu->is_dwz == offset_in_dwz && *cu_off >= sect_off))
+         || (mid_cu->is_dwz == offset_in_dwz
+             && mid_cu->sect_off + mid_cu->length >= sect_off))
        high = mid;
       else
        low = mid + 1;
     }
   gdb_assert (low == high);
   this_cu = dwarf2_per_objfile->all_comp_units[low];
-  cu_off = &this_cu->sect_off;
-  if (this_cu->is_dwz != offset_in_dwz || *cu_off > sect_off)
+  if (this_cu->is_dwz != offset_in_dwz || this_cu->sect_off > sect_off)
     {
       if (low == 0 || this_cu->is_dwz != offset_in_dwz)
        error (_("Dwarf Error: could not find partial DIE containing "
@@ -24876,7 +25353,6 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
     }
   else
     {
-      this_cu = dwarf2_per_objfile->all_comp_units[low];
       if (low == dwarf2_per_objfile->all_comp_units.size () - 1
          && sect_off >= this_cu->sect_off + this_cu->length)
        error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off));
@@ -24889,13 +25365,15 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
 
 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data *per_cu_)
   : per_cu (per_cu_),
-    mark (0),
-    has_loclist (0),
-    checked_producer (0),
-    producer_is_gxx_lt_4_6 (0),
-    producer_is_gcc_lt_4_3 (0),
-    producer_is_icc_lt_14 (0),
-    processing_has_namespace_info (0)
+    mark (false),
+    has_loclist (false),
+    checked_producer (false),
+    producer_is_gxx_lt_4_6 (false),
+    producer_is_gcc_lt_4_3 (false),
+    producer_is_icc (false),
+    producer_is_icc_lt_14 (false),
+    producer_is_codewarrior (false),
+    processing_has_namespace_info (false)
 {
   per_cu->cu = this;
 }
@@ -24997,17 +25475,6 @@ free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu)
     }
 }
 
-/* Cleanup function for the dwarf2_per_objfile data.  */
-
-static void
-dwarf2_free_objfile (struct objfile *objfile, void *datum)
-{
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = static_cast<struct dwarf2_per_objfile *> (datum);
-
-  delete dwarf2_per_objfile;
-}
-
 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
    We store these in a hash table separate from the DIEs, and preserve them
    when the DIEs are flushed out of cache.
@@ -25228,7 +25695,7 @@ dwarf2_mark_helper (void **slot, void *data)
 
   if (per_cu->cu->mark)
     return 1;
-  per_cu->cu->mark = 1;
+  per_cu->cu->mark = true;
 
   if (per_cu->cu->dependencies != NULL)
     htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
@@ -25244,7 +25711,7 @@ dwarf2_mark (struct dwarf2_cu *cu)
 {
   if (cu->mark)
     return;
-  cu->mark = 1;
+  cu->mark = true;
   if (cu->dependencies != NULL)
     htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
 }
@@ -25254,7 +25721,7 @@ dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
 {
   while (per_cu)
     {
-      per_cu->cu->mark = 0;
+      per_cu->cu->mark = false;
       per_cu = per_cu->cu->read_in_chain;
     }
 }
@@ -25285,8 +25752,8 @@ partial_die_eq (const void *item_lhs, const void *item_rhs)
   return part_die_lhs->sect_off == part_die_rhs->sect_off;
 }
 
-static struct cmd_list_element *set_dwarf_cmdlist;
-static struct cmd_list_element *show_dwarf_cmdlist;
+struct cmd_list_element *set_dwarf_cmdlist;
+struct cmd_list_element *show_dwarf_cmdlist;
 
 static void
 set_dwarf_cmd (const char *args, int from_tty)
@@ -25325,9 +25792,6 @@ show_check_physname (struct ui_file *file, int from_tty,
 void
 _initialize_dwarf2_read (void)
 {
-  dwarf2_objfile_data_key
-    = register_objfile_data_with_cleanup (nullptr, dwarf2_free_objfile);
-
   add_prefix_cmd ("dwarf", class_maintenance, set_dwarf_cmd, _("\
 Set DWARF specific variables.\n\
 Configure DWARF variables such as the cache size"),
This page took 0.075671 seconds and 4 git commands to generate.