gdb: remove COMPUNIT_LOCATIONS_VALID macro, add getter/setter
[binutils-gdb.git] / gdb / dwarf2 / read.c
index 3c81ac6b7b51be892882536128741f5d25ae4dfd..a14ac22f2882182f181364cc129b7ae79712a8e5 100644 (file)
@@ -1,6 +1,6 @@
 /* DWARF 2 debugging format support for GDB.
 
-   Copyright (C) 1994-2021 Free Software Foundation, Inc.
+   Copyright (C) 1994-2022 Free Software Foundation, Inc.
 
    Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
    Inc.  with support from Florida State University (under contract
@@ -920,8 +920,8 @@ struct partial_die_info : public allocate_on_obstack
       /* If HAS_PC_INFO, the PC range associated with this DIE.  */
       struct
       {
-       CORE_ADDR lowpc = 0;
-       CORE_ADDR highpc = 0;
+       CORE_ADDR lowpc;
+       CORE_ADDR highpc;
       };
       /* If HAS_RANGE_INFO, the ranges offset associated with this DIE.  */
       ULONGEST ranges_offset;
@@ -974,6 +974,10 @@ struct partial_die_info : public allocate_on_obstack
       is_dwz = 0;
       spec_is_dwz = 0;
       canonical_name = 0;
+      /* Don't set these using NSDMI (Non-static data member initialisation),
+        because g++-4.8 will error out.  */
+      lowpc = 0;
+      highpc = 0;
     }
   };
 
@@ -1202,7 +1206,6 @@ static struct die_info *die_specification (struct die_info *die,
 static line_header_up dwarf_decode_line_header (sect_offset sect_off,
                                                struct dwarf2_cu *cu);
 
-struct file_and_directory;
 static void dwarf_decode_lines (struct line_header *,
                                const file_and_directory &,
                                struct dwarf2_cu *, dwarf2_psymtab *,
@@ -1446,7 +1449,7 @@ static int partial_die_eq (const void *item_lhs, const void *item_rhs);
 
 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
   (sect_offset sect_off, unsigned int offset_in_dwz,
-   dwarf2_per_objfile *per_objfile);
+   dwarf2_per_bfd *per_bfd);
 
 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
                                   struct die_info *comp_unit_die,
@@ -1534,23 +1537,8 @@ dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data *data)
     delete data;
 }
 
-/* The return type of find_file_and_directory.  Note, the enclosed
-   string pointers are only valid while this object is valid.  */
-
-struct file_and_directory
-{
-  /* The filename.  This is never NULL.  */
-  const char *name;
-
-  /* The compilation directory.  NULL if not known.  If we needed to
-     compute a new string, it will be stored in the per-BFD string
-     bcache; otherwise, points directly to the DW_AT_comp_dir string
-     attribute owned by the obstack that owns the DIE.  */
-  const char *comp_dir;
-};
-
-static file_and_directory find_file_and_directory (struct die_info *die,
-                                                  struct dwarf2_cu *cu);
+static file_and_directory &find_file_and_directory
+     (struct die_info *die, struct dwarf2_cu *cu);
 
 static const char *compute_include_file_name
      (const struct line_header *lh,
@@ -3017,10 +3005,10 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
       lh = dwarf_decode_line_header (line_offset, cu);
     }
 
-  file_and_directory fnd = find_file_and_directory (comp_unit_die, cu);
+  file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu);
 
   int offset = 0;
-  if (strcmp (fnd.name, "<unknown>") != 0)
+  if (!fnd.is_unknown ())
     ++offset;
   else if (lh == nullptr)
     return;
@@ -3049,12 +3037,12 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
     }
 
   qfn->num_file_names = offset + include_names.size ();
-  qfn->comp_dir = fnd.comp_dir;
+  qfn->comp_dir = fnd.intern_comp_dir (per_objfile->objfile);
   qfn->file_names =
     XOBNEWVEC (&per_objfile->per_bfd->obstack, const char *,
               qfn->num_file_names);
   if (offset != 0)
-    qfn->file_names[0] = xstrdup (fnd.name);
+    qfn->file_names[0] = xstrdup (fnd.get_name ());
 
   if (!include_names.empty ())
     memcpy (&qfn->file_names[offset], include_names.data (),
@@ -3125,7 +3113,7 @@ dwarf2_base_index_functions::find_last_source_symtab (struct objfile *objfile)
   if (cust == NULL)
     return NULL;
 
-  return compunit_primary_filetab (cust);
+  return cust->primary_filetab ();
 }
 
 /* See read.h.  */
@@ -4463,8 +4451,8 @@ recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust,
 {
   int i;
 
-  if (COMPUNIT_BLOCKVECTOR (cust) != NULL
-      && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust), pc))
+  if (cust->blockvector () != nullptr
+      && blockvector_contains_pc (cust->blockvector (), pc))
     return cust;
 
   if (cust->includes == NULL)
@@ -5783,7 +5771,10 @@ struct dwarf2_include_psymtab : public partial_symtab
 
   compunit_symtab *get_compunit_symtab (struct objfile *objfile) const override
   {
-    return nullptr;
+    compunit_symtab *cust = includer ()->get_compunit_symtab (objfile);
+    while (cust != nullptr && cust->user != nullptr)
+      cust = cust->user;
+    return cust;
   }
 
 private:
@@ -6995,18 +6986,18 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
   prepare_one_comp_unit (cu, comp_unit_die, pretend_language);
 
   /* Allocate a new partial symbol table structure.  */
-  gdb::unique_xmalloc_ptr<char> debug_filename;
   static const char artificial[] = "<artificial>";
-  file_and_directory fnd = find_file_and_directory (comp_unit_die, cu);
-  if (strcmp (fnd.name, artificial) == 0)
+  file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu);
+  if (strcmp (fnd.get_name (), artificial) == 0)
     {
-      debug_filename.reset (concat (artificial, "@",
-                                   sect_offset_str (per_cu->sect_off),
-                                   (char *) NULL));
-      fnd.name = debug_filename.get ();
+      gdb::unique_xmalloc_ptr<char> debug_filename
+       (concat (artificial, "@",
+                sect_offset_str (per_cu->sect_off),
+                (char *) NULL));
+      fnd.set_name (std::move (debug_filename));
     }
 
-  pst = create_partial_symtab (per_cu, per_objfile, fnd.name);
+  pst = create_partial_symtab (per_cu, per_objfile, fnd.get_name ());
 
   /* This must be done before calling dwarf2_build_include_psymtabs.  */
   pst->dirname = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu);
@@ -7728,7 +7719,8 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
                  }
 
                per_cu = dwarf2_find_containing_comp_unit
-                          (pdi->d.sect_off, pdi->is_dwz, cu->per_objfile);
+                          (pdi->d.sect_off, pdi->is_dwz,
+                           cu->per_objfile->per_bfd);
 
                /* Go read the partial unit, if needed.  */
                if (per_cu->v.psymtab == NULL)
@@ -9046,9 +9038,9 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 
 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
   if (type->num_fields () == 1
-      && startswith (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX))
+      && startswith (type->field (0).name (), RUST_ENUM_PREFIX))
     {
-      const char *name = TYPE_FIELD_NAME (type, 0) + strlen (RUST_ENUM_PREFIX);
+      const char *name = type->field (0).name () + strlen (RUST_ENUM_PREFIX);
 
       /* Decode the field name to find the offset of the
         discriminant.  */
@@ -9061,18 +9053,18 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
          name = tail;
          if (*name != '$'
              || index >= field_type->num_fields ()
-             || (TYPE_FIELD_LOC_KIND (field_type, index)
+             || (field_type->field (index).loc_kind ()
                  != FIELD_LOC_KIND_BITPOS))
            {
              complaint (_("Could not parse Rust enum encoding string \"%s\""
                           "[in module %s]"),
-                        TYPE_FIELD_NAME (type, 0),
+                        type->field (0).name (),
                         objfile_name (objfile));
              return;
            }
          ++name;
 
-         bit_offset += TYPE_FIELD_BITPOS (field_type, index);
+         bit_offset += field_type->field (index).loc_bitpos ();
          field_type = field_type->field (index).type ();
        }
 
@@ -9088,17 +9080,17 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       /* Put the discriminant at index 0.  */
       type->field (0).set_type (field_type);
       TYPE_FIELD_ARTIFICIAL (type, 0) = 1;
-      TYPE_FIELD_NAME (type, 0) = "<<discriminant>>";
-      SET_FIELD_BITPOS (type->field (0), bit_offset);
+      type->field (0).set_name ("<<discriminant>>");
+      type->field (0).set_loc_bitpos (bit_offset);
 
       /* The order of fields doesn't really matter, so put the real
         field at index 1 and the data-less field at index 2.  */
       type->field (1) = saved_field;
-      TYPE_FIELD_NAME (type, 1)
-       = rust_last_path_segment (type->field (1).type ()->name ());
+      type->field (1).set_name
+       (rust_last_path_segment (type->field (1).type ()->name ()));
       type->field (1).type ()->set_name
        (rust_fully_qualify (&objfile->objfile_obstack, type->name (),
-                            TYPE_FIELD_NAME (type, 1)));
+                            type->field (1).name ()));
 
       const char *dataless_name
        = rust_fully_qualify (&objfile->objfile_obstack, type->name (),
@@ -9108,8 +9100,8 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       type->field (2).set_type (dataless_type);
       /* NAME points into the original discriminant name, which
         already has the correct lifetime.  */
-      TYPE_FIELD_NAME (type, 2) = name;
-      SET_FIELD_BITPOS (type->field (2), 0);
+      type->field (2).set_name (name);
+      type->field (2).set_loc_bitpos (0);
 
       /* Indicate that this is a variant type.  */
       static discriminant_range ranges[1] = { { 0, 0 } };
@@ -9117,7 +9109,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
     }
   /* A union with a single anonymous field is probably an old-style
      univariant enum.  */
-  else if (type->num_fields () == 1 && streq (TYPE_FIELD_NAME (type, 0), ""))
+  else if (type->num_fields () == 1 && streq (type->field (0).name (), ""))
     {
       /* Smash this type to be a structure type.  We have to do this
         because the type has already been recorded.  */
@@ -9126,7 +9118,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       struct type *field_type = type->field (0).type ();
       const char *variant_name
        = rust_last_path_segment (field_type->name ());
-      TYPE_FIELD_NAME (type, 0) = variant_name;
+      type->field (0).set_name (variant_name);
       field_type->set_name
        (rust_fully_qualify (&objfile->objfile_obstack,
                             type->name (), variant_name));
@@ -9150,7 +9142,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
              /* Could be data-less variant, so keep going.  */
              disr_type = nullptr;
            }
-         else if (strcmp (TYPE_FIELD_NAME (disr_type, 0),
+         else if (strcmp (disr_type->field (0).name (),
                           "RUST$ENUM$DISR") != 0)
            {
              /* Not a Rust enum.  */
@@ -9185,7 +9177,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       /* Install the discriminant at index 0 in the union.  */
       type->field (0) = *disr_field;
       TYPE_FIELD_ARTIFICIAL (type, 0) = 1;
-      TYPE_FIELD_NAME (type, 0) = "<<discriminant>>";
+      type->field (0).set_name ("<<discriminant>>");
 
       /* We need a way to find the correct discriminant given a
         variant name.  For convenience we build a map here.  */
@@ -9193,11 +9185,11 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       std::unordered_map<std::string, ULONGEST> discriminant_map;
       for (int i = 0; i < enum_type->num_fields (); ++i)
        {
-         if (TYPE_FIELD_LOC_KIND (enum_type, i) == FIELD_LOC_KIND_ENUMVAL)
+         if (enum_type->field (i).loc_kind () == FIELD_LOC_KIND_ENUMVAL)
            {
              const char *name
-               = rust_last_path_segment (TYPE_FIELD_NAME (enum_type, i));
-             discriminant_map[name] = TYPE_FIELD_ENUMVAL (enum_type, i);
+               = rust_last_path_segment (enum_type->field (i).name ());
+             discriminant_map[name] = enum_type->field (i).loc_enumval ();
            }
        }
 
@@ -9235,7 +9227,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
              sub_type->set_num_fields (sub_type->num_fields () - 1);
              sub_type->set_fields (sub_type->fields () + 1);
            }
-         TYPE_FIELD_NAME (type, i) = variant_name;
+         type->field (i).set_name (variant_name);
          sub_type->set_name
            (rust_fully_qualify (&objfile->objfile_obstack,
                                 type->name (), variant_name));
@@ -9485,8 +9477,8 @@ process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
         compilation is from a C file generated by language preprocessors, do
         not set the language if it was already deduced by start_subfile.  */
       if (!(cu->per_cu->lang == language_c
-           && COMPUNIT_FILETABS (cust)->language != language_unknown))
-       COMPUNIT_FILETABS (cust)->language = cu->per_cu->lang;
+           && cust->primary_filetab ()->language != language_unknown))
+       cust->primary_filetab ()->language = cu->per_cu->lang;
 
       /* GCC-4.0 has started to support -fvar-tracking.  GCC-3.x still can
         produce DW_AT_location with location lists but it can be possibly
@@ -9501,12 +9493,12 @@ process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
         options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
         */
       if (cu->has_loclist && gcc_4_minor >= 5)
-       cust->locations_valid = 1;
+       cust->set_locations_valid (true);
 
       if (gcc_4_minor >= 5)
        cust->epilogue_unwind_valid = 1;
 
-      cust->call_site_htab = cu->call_site_htab;
+      cust->set_call_site_htab (cu->call_site_htab);
     }
 
   per_objfile->set_symtab (cu->per_cu, cust);
@@ -9570,8 +9562,8 @@ process_full_type_unit (dwarf2_cu *cu,
             do not set the language if it was already deduced by
             start_subfile.  */
          if (!(cu->per_cu->lang == language_c
-               && COMPUNIT_FILETABS (cust)->language != language_c))
-           COMPUNIT_FILETABS (cust)->language = cu->per_cu->lang;
+               && cust->primary_filetab ()->language != language_c))
+           cust->primary_filetab ()->language = cu->per_cu->lang;
        }
     }
   else
@@ -9608,7 +9600,8 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
       bool is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
       dwarf2_per_objfile *per_objfile = cu->per_objfile;
       dwarf2_per_cu_data *per_cu
-       = dwarf2_find_containing_comp_unit (sect_off, is_dwz, per_objfile);
+       = dwarf2_find_containing_comp_unit (sect_off, is_dwz,
+                                           per_objfile->per_bfd);
 
       /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
         into another compilation unit, at root level.  Regard this as a hint,
@@ -10041,7 +10034,7 @@ dwarf2_compute_name (const char *name,
                      else if (bytes != NULL)
                        {
                          v = allocate_value (type);
-                         memcpy (value_contents_writeable (v), bytes,
+                         memcpy (value_contents_writeable (v).data (), bytes,
                                  TYPE_LENGTH (type));
                        }
                      else
@@ -10170,9 +10163,8 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
             to look up their definition from their declaration so
             the only disadvantage remains the minimal symbol variant
             `long name(params)' does not have the proper inferior type.  */
-         demangled.reset (gdb_demangle (mangled,
-                                        (DMGL_PARAMS | DMGL_ANSI
-                                         | DMGL_RET_DROP)));
+         demangled = gdb_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
+                                             | DMGL_RET_DROP));
        }
       if (demangled)
        canon = demangled.get ();
@@ -10482,39 +10474,25 @@ producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu)
   return cu->producer_is_gcc_lt_4_3;
 }
 
-static file_and_directory
+static file_and_directory &
 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu)
 {
-  file_and_directory res;
+  if (cu->per_cu->fnd != nullptr)
+    return *cu->per_cu->fnd;
 
   /* Find the filename.  Do not use dwarf2_name here, since the filename
      is not a source language identifier.  */
-  res.name = dwarf2_string_attr (die, DW_AT_name, cu);
-  res.comp_dir = dwarf2_string_attr (die, DW_AT_comp_dir, cu);
+  file_and_directory res (dwarf2_string_attr (die, DW_AT_name, cu),
+                         dwarf2_string_attr (die, DW_AT_comp_dir, cu));
 
-  if (res.comp_dir == NULL
-      && producer_is_gcc_lt_4_3 (cu) && res.name != NULL
-      && IS_ABSOLUTE_PATH (res.name))
-    {
-      std::string comp_dir_storage = ldirname (res.name);
-      if (!comp_dir_storage.empty ())
-       res.comp_dir
-         = cu->per_objfile->objfile->intern (comp_dir_storage.c_str ());
-    }
-  if (res.comp_dir != NULL)
-    {
-      /* Irix 6.2 native cc prepends <machine>.: to the compilation
-        directory, get rid of it.  */
-      const char *cp = strchr (res.comp_dir, ':');
-
-      if (cp && cp != res.comp_dir && cp[-1] == '.' && cp[1] == '/')
-       res.comp_dir = cp + 1;
-    }
+  if (res.get_comp_dir () == nullptr
+      && producer_is_gcc_lt_4_3 (cu)
+      && res.get_name () != nullptr
+      && IS_ABSOLUTE_PATH (res.get_name ()))
+    res.set_comp_dir (ldirname (res.get_name ()));
 
-  if (res.name == NULL)
-    res.name = "<unknown>";
-
-  return res;
+  cu->per_cu->fnd.reset (new file_and_directory (std::move (res)));
+  return *cu->per_cu->fnd;
 }
 
 /* Handle DW_AT_stmt_list for a compilation unit.
@@ -10642,9 +10620,9 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
     lowpc = highpc;
   lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
 
-  file_and_directory fnd = find_file_and_directory (die, cu);
+  file_and_directory &fnd = find_file_and_directory (die, cu);
 
-  cu->start_symtab (fnd.name, fnd.comp_dir, lowpc);
+  cu->start_symtab (fnd.get_name (), fnd.intern_comp_dir (objfile), lowpc);
 
   gdb_assert (per_objfile->sym_cu == nullptr);
   scoped_restore restore_sym_cu
@@ -10652,8 +10630,13 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
 
   /* Decode line number information if present.  We do this before
      processing child DIEs, so that the line header table is available
-     for DW_AT_decl_file.  */
-  handle_DW_AT_stmt_list (die, cu, fnd, lowpc);
+     for DW_AT_decl_file.  The PC check is here because, if LOWPC and
+     HIGHPC are both 0x0, then there won't be any interesting code in
+     the CU, but a check later on (in
+     lnp_state_machine::check_line_address) will fail to properly
+     exclude an entry that was removed via --gc-sections.  */
+  if (lowpc != highpc)
+    handle_DW_AT_stmt_list (die, cu, fnd, lowpc);
 
   /* Process all dies in compilation unit.  */
   if (die->child != NULL)
@@ -10739,8 +10722,8 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
          gdb_assert (m_builder == nullptr);
          struct compunit_symtab *cust = tug_unshare->compunit_symtab;
          m_builder.reset (new struct buildsym_compunit
-                          (COMPUNIT_OBJFILE (cust), "",
-                           COMPUNIT_DIRNAME (cust),
+                          (cust->objfile (), "",
+                           cust->dirname (),
                            compunit_language (cust),
                            0, cust));
          list_in_scope = get_builder ()->get_file_symbols ();
@@ -10761,7 +10744,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
         time.  */
 
       tug_unshare->symtabs
-       = XOBNEWVEC (&COMPUNIT_OBJFILE (cust)->objfile_obstack,
+       = XOBNEWVEC (&cust->objfile ()->objfile_obstack,
                     struct symtab *, line_header->file_names_size ());
 
       auto &file_names = line_header->file_names ();
@@ -10791,8 +10774,8 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
       gdb_assert (m_builder == nullptr);
       struct compunit_symtab *cust = tug_unshare->compunit_symtab;
       m_builder.reset (new struct buildsym_compunit
-                      (COMPUNIT_OBJFILE (cust), "",
-                       COMPUNIT_DIRNAME (cust),
+                      (cust->objfile (), "",
+                       cust->dirname (),
                        compunit_language (cust),
                        0, cust));
       list_in_scope = get_builder ()->get_file_symbols ();
@@ -12130,10 +12113,10 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
   gdb::unique_xmalloc_ptr<char> search_path_holder;
   if (search_cwd)
     {
-      if (*debug_file_directory != '\0')
+      if (!debug_file_directory.empty ())
        {
          search_path_holder.reset (concat (".", dirname_separator_string,
-                                           debug_file_directory,
+                                           debug_file_directory.c_str (),
                                            (char *) NULL));
          search_path = search_path_holder.get ();
        }
@@ -12141,7 +12124,7 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
        search_path = ".";
     }
   else
-    search_path = debug_file_directory;
+    search_path = debug_file_directory.c_str ();
 
   /* Add the path for the executable binary to the list of search paths.  */
   std::string objfile_dir = ldirname (objfile_name (per_objfile->objfile));
@@ -12212,7 +12195,7 @@ open_dwo_file (dwarf2_per_objfile *per_objfile,
   /* That didn't work, try debug-file-directory, which, despite its name,
      is a list of paths.  */
 
-  if (*debug_file_directory == '\0')
+  if (debug_file_directory.empty ())
     return NULL;
 
   return try_open_dwop_file (per_objfile, file_name,
@@ -12541,7 +12524,7 @@ open_dwp_file (dwarf2_per_objfile *per_objfile, const char *file_name)
      [IWBN if the dwp file name was recorded in the executable, akin to
      .gnu_debuglink, but that doesn't exist yet.]
      Strip the directory from FILE_NAME and search again.  */
-  if (*debug_file_directory != '\0')
+  if (!debug_file_directory.empty ())
     {
       /* Don't implicitly search the current directory here.
         If the user wants to search "." to handle this case,
@@ -13337,7 +13320,6 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
   struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR pc, baseaddr;
   struct attribute *attr;
-  struct call_site *call_site, call_site_local;
   void **slot;
   int nparams;
   struct die_info *child_die;
@@ -13360,12 +13342,14 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
     }
   pc = attr->as_address () + baseaddr;
   pc = gdbarch_adjust_dwarf2_addr (gdbarch, pc);
+  pc -= baseaddr;
 
   if (cu->call_site_htab == NULL)
-    cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
-                                              NULL, &objfile->objfile_obstack,
+    cu->call_site_htab = htab_create_alloc_ex (16, call_site::hash,
+                                              call_site::eq, NULL,
+                                              &objfile->objfile_obstack,
                                               hashtab_obstack_allocate, NULL);
-  call_site_local.pc = pc;
+  struct call_site call_site_local (pc, nullptr, nullptr);
   slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
   if (*slot != NULL)
     {
@@ -13395,14 +13379,16 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
       nparams++;
     }
 
-  call_site
-    = ((struct call_site *)
-       obstack_alloc (&objfile->objfile_obstack,
-                     sizeof (*call_site)
-                     + (sizeof (*call_site->parameter) * (nparams - 1))));
+  struct call_site *call_site
+    = new (XOBNEWVAR (&objfile->objfile_obstack,
+                     struct call_site,
+                     sizeof (*call_site) + sizeof (call_site->parameter[0]) * nparams))
+    struct call_site (pc, cu->per_cu, per_objfile);
   *slot = call_site;
-  memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
-  call_site->pc = pc;
+
+  /* We never call the destructor of call_site, so we must ensure it is
+     trivially destructible.  */
+  gdb_static_assert(std::is_trivially_destructible<struct call_site>::value);
 
   if (dwarf2_flag_true_p (die, DW_AT_call_tail_call, cu)
       || dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
@@ -13463,7 +13449,8 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
       /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin.  */
       attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
     }
-  SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
+
+  call_site->target.set_loc_dwarf_block (nullptr);
   if (!attr || (attr->form_is_block () && attr->as_block ()->size == 0))
     /* Keep NULL DWARF_BLOCK.  */;
   else if (attr->form_is_block ())
@@ -13477,7 +13464,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
       dlbaton->per_objfile = per_objfile;
       dlbaton->per_cu = cu->per_cu;
 
-      SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
+      call_site->target.set_loc_dwarf_block (dlbaton);
     }
   else if (attr->form_is_ref ())
     {
@@ -13499,7 +13486,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
                         "physname, for referencing DIE %s [in module %s]"),
                       sect_offset_str (die->sect_off), objfile_name (objfile));
          else
-           SET_FIELD_PHYSNAME (call_site->target, target_physname);
+           call_site->target.set_loc_physname (target_physname);
        }
       else
        {
@@ -13513,8 +13500,9 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
                       sect_offset_str (die->sect_off), objfile_name (objfile));
          else
            {
-             lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
-             SET_FIELD_PHYSADDR (call_site->target, lowpc);
+             lowpc = (gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr)
+                      - baseaddr);
+             call_site->target.set_loc_physaddr (lowpc);
            }
        }
     }
@@ -13523,9 +13511,6 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
                 "block nor reference, for DIE %s [in module %s]"),
               sect_offset_str (die->sect_off), objfile_name (objfile));
 
-  call_site->per_cu = cu->per_cu;
-  call_site->per_objfile = per_objfile;
-
   for (child_die = die->child;
        child_die && child_die->tag;
        child_die = child_die->sibling)
@@ -14335,6 +14320,7 @@ check_producer (struct dwarf2_cu *cu)
     {
       cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6);
       cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
+      cu->producer_is_gcc_11 = major == 11;
     }
   else if (producer_is_icc (cu->producer, &major, &minor))
     {
@@ -14420,14 +14406,14 @@ dwarf2_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
     }
 }
 
-/* Look for DW_AT_data_member_location.  Set *OFFSET to the byte
-   offset.  If the attribute was not found return 0, otherwise return
-   1.  If it was found but could not properly be handled, set *OFFSET
-   to 0.  */
+/* Look for DW_AT_data_member_location or DW_AT_data_bit_offset.  Set
+   *OFFSET to the byte offset.  If the attribute was not found return
+   0, otherwise return 1.  If it was found but could not properly be
+   handled, set *OFFSET to 0.  */
 
 static int
-handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
-                            LONGEST *offset)
+handle_member_location (struct die_info *die, struct dwarf2_cu *cu,
+                       LONGEST *offset)
 {
   struct attribute *attr;
 
@@ -14451,15 +14437,25 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
 
       return 1;
     }
+  else
+    {
+      attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
+      if (attr != nullptr)
+       {
+         *offset = attr->constant_value (0);
+         return 1;
+       }
+    }
 
   return 0;
 }
 
-/* Look for DW_AT_data_member_location and store the results in FIELD.  */
+/* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
+   store the results in FIELD.  */
 
 static void
-handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
-                            struct field *field)
+handle_member_location (struct die_info *die, struct dwarf2_cu *cu,
+                       struct field *field)
 {
   struct attribute *attr;
 
@@ -14469,7 +14465,20 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
       if (attr->form_is_constant ())
        {
          LONGEST offset = attr->constant_value (0);
-         SET_FIELD_BITPOS (*field, offset * bits_per_byte);
+
+         /* Work around this GCC 11 bug, where it would erroneously use -1
+            data member locations, instead of 0:
+
+              Negative DW_AT_data_member_location
+              https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378
+            */
+         if (offset == -1 && cu->producer_is_gcc_11)
+           {
+             complaint (_("DW_AT_data_member_location value of -1, assuming 0"));
+             offset = 0;
+           }
+
+         field->set_loc_bitpos (offset * bits_per_byte);
        }
       else if (attr->form_is_section_offset ())
        dwarf2_complex_location_expr_complaint ();
@@ -14478,7 +14487,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
          bool handled;
          CORE_ADDR offset = decode_locdesc (attr->as_block (), cu, &handled);
          if (handled)
-           SET_FIELD_BITPOS (*field, offset * bits_per_byte);
+           field->set_loc_bitpos (offset * bits_per_byte);
          else
            {
              dwarf2_per_objfile *per_objfile = cu->per_objfile;
@@ -14495,12 +14504,18 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
              dlbaton->per_objfile = per_objfile;
              dlbaton->per_cu = cu->per_cu;
 
-             SET_FIELD_DWARF_BLOCK (*field, dlbaton);
+             field->set_loc_dwarf_block (dlbaton);
            }
        }
       else
        dwarf2_complex_location_expr_complaint ();
     }
+  else
+    {
+      attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
+      if (attr != nullptr)
+       field->set_loc_bitpos (attr->constant_value (0));
+    }
 }
 
 /* Add an aggregate field to the field list.  */
@@ -14548,7 +14563,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       /* Get type of field.  */
       fp->set_type (die_type (die, cu));
 
-      SET_FIELD_BITPOS (*fp, 0);
+      fp->set_loc_bitpos (0);
 
       /* Get bit size of field (zero if none).  */
       attr = dwarf2_attr (die, DW_AT_bit_size, cu);
@@ -14562,7 +14577,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
        }
 
       /* Get bit offset of field.  */
-      handle_data_member_location (die, cu, fp);
+      handle_member_location (die, cu, fp);
       attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
       if (attr != nullptr && attr->form_is_constant ())
        {
@@ -14573,8 +14588,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
                 anonymous object to the MSB of the field.  We don't
                 have to do anything special since we don't need to
                 know the size of the anonymous object.  */
-             SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp)
-                                     + attr->constant_value (0)));
+             fp->set_loc_bitpos (fp->loc_bitpos () + attr->constant_value (0));
            }
          else
            {
@@ -14603,16 +14617,11 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
                     bit field.  */
                  anonymous_size = TYPE_LENGTH (fp->type ());
                }
-             SET_FIELD_BITPOS (*fp,
-                               (FIELD_BITPOS (*fp)
-                                + anonymous_size * bits_per_byte
-                                - bit_offset - FIELD_BITSIZE (*fp)));
+             fp->set_loc_bitpos (fp->loc_bitpos ()
+                                 + anonymous_size * bits_per_byte
+                                 - bit_offset - FIELD_BITSIZE (*fp));
            }
        }
-      attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
-      if (attr != NULL)
-       SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp)
-                               + attr->constant_value (0)));
 
       /* Get name of field.  */
       fieldname = dwarf2_name (die, cu);
@@ -14621,7 +14630,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
 
       /* The name is already allocated along with this objfile, so we don't
         need to duplicate it for the type.  */
-      fp->name = fieldname;
+      fp->set_name (fieldname);
 
       /* Change accessibility for artificial fields (e.g. virtual table
         pointer or virtual base class pointer) to private.  */
@@ -14666,17 +14675,17 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
 
       /* The name is already allocated along with this objfile, so we don't
         need to duplicate it for the type.  */
-      SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
+      fp->set_loc_physname (physname ? physname : "");
       fp->set_type (die_type (die, cu));
-      FIELD_NAME (*fp) = fieldname;
+      fp->set_name (fieldname);
     }
   else if (die->tag == DW_TAG_inheritance)
     {
       /* C++ base class field.  */
-      handle_data_member_location (die, cu, fp);
+      handle_member_location (die, cu, fp);
       FIELD_BITSIZE (*fp) = 0;
       fp->set_type (die_type (die, cu));
-      FIELD_NAME (*fp) = fp->type ()->name ();
+      fp->set_name (fp->type ()->name ());
     }
   else
     gdb_assert_not_reached ("missing case in dwarf2_add_field");
@@ -14919,7 +14928,7 @@ add_variant_property (struct field_info *fip, struct type *type,
     offset_map[fip->fields[i].offset] = i;
 
   struct objfile *objfile = cu->per_objfile->objfile;
-  gdb::array_view<variant_part> parts
+  gdb::array_view<const variant_part> parts
     = create_variant_parts (&objfile->objfile_obstack, offset_map, fip,
                            fip->variant_parts);
 
@@ -15311,10 +15320,10 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
     return;
 
   /* Check for __pfn and __delta members.  */
-  if (TYPE_FIELD_NAME (type, 0) == NULL
-      || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
-      || TYPE_FIELD_NAME (type, 1) == NULL
-      || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
+  if (type->field (0).name () == NULL
+      || strcmp (type->field (0).name (), "__pfn") != 0
+      || type->field (1).name () == NULL
+      || strcmp (type->field (1).name (), "__delta") != 0)
     return;
 
   /* Find the type of the method.  */
@@ -15405,10 +15414,10 @@ quirk_ada_thick_pointer_struct (struct die_info *die, struct dwarf2_cu *cu,
     return;
 
   /* Check for P_ARRAY and P_BOUNDS members.  */
-  if (TYPE_FIELD_NAME (type, 0) == NULL
-      || strcmp (TYPE_FIELD_NAME (type, 0), "P_ARRAY") != 0
-      || TYPE_FIELD_NAME (type, 1) == NULL
-      || strcmp (TYPE_FIELD_NAME (type, 1), "P_BOUNDS") != 0)
+  if (type->field (0).name () == NULL
+      || strcmp (type->field (0).name (), "P_ARRAY") != 0
+      || type->field (1).name () == NULL
+      || strcmp (type->field (1).name (), "P_BOUNDS") != 0)
     return;
 
   /* Make sure we're looking at a pointer to an array.  */
@@ -15921,7 +15930,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
                       i >= TYPE_N_BASECLASSES (t);
                       --i)
                    {
-                     const char *fieldname = TYPE_FIELD_NAME (t, i);
+                     const char *fieldname = t->field (i).name ();
 
                      if (is_vtable_name (fieldname, cu))
                        {
@@ -15954,7 +15963,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
                   i >= TYPE_N_BASECLASSES (type);
                   --i)
                {
-                 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
+                 if (strcmp (type->field (i).name (), "__vfp") == 0)
                    {
                      set_type_vptr_fieldno (type, i);
                      set_type_vptr_basetype (type, type);
@@ -16125,8 +16134,8 @@ update_enumeration_type_from_children (struct die_info *die,
 
       fields.emplace_back ();
       struct field &field = fields.back ();
-      FIELD_NAME (field) = dwarf2_physname (name, child_die, cu);
-      SET_FIELD_ENUMVAL (field, value);
+      field.set_name (dwarf2_physname (name, child_die, cu));
+      field.set_loc_enumval (value);
     }
 
   if (!fields.empty ())
@@ -16400,7 +16409,7 @@ recognize_bound_expression (struct die_info *die, enum dwarf_attribute name,
   else
     return false;
 
-  SET_FIELD_BITPOS (*field, 8 * offset);
+  field->set_loc_bitpos (8 * offset);
   if (size != TYPE_LENGTH (field->type ()))
     FIELD_BITSIZE (*field) = 8 * size;
 
@@ -16499,9 +16508,9 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
 
       /* Set the name of each field in the bounds.  */
       xsnprintf (name, sizeof (name), "LB%d", i / 2);
-      FIELD_NAME (range_fields[i]) = objfile->intern (name);
+      range_fields[i].set_name (objfile->intern (name));
       xsnprintf (name, sizeof (name), "UB%d", i / 2);
-      FIELD_NAME (range_fields[i + 1]) = objfile->intern (name);
+      range_fields[i + 1].set_name (objfile->intern (name));
     }
 
   struct type *bounds = alloc_type (objfile);
@@ -16515,7 +16524,7 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
          bounds->num_fields () * sizeof (struct field));
 
   int last_fieldno = range_fields.size () - 1;
-  int bounds_size = (TYPE_FIELD_BITPOS (bounds, last_fieldno) / 8
+  int bounds_size = (bounds->field (last_fieldno).loc_bitpos () / 8
                     + TYPE_LENGTH (bounds->field (last_fieldno).type ()));
   TYPE_LENGTH (bounds) = align_up (bounds_size, max_align);
 
@@ -16543,12 +16552,12 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
   /* The names are chosen to coincide with what the compiler does with
      -fgnat-encodings=all, which the Ada code in gdb already
      understands.  */
-  TYPE_FIELD_NAME (result, 0) = "P_ARRAY";
+  result->field (0).set_name ("P_ARRAY");
   result->field (0).set_type (lookup_pointer_type (type));
 
-  TYPE_FIELD_NAME (result, 1) = "P_BOUNDS";
+  result->field (1).set_name ("P_BOUNDS");
   result->field (1).set_type (lookup_pointer_type (bounds));
-  SET_FIELD_BITPOS (result->field (1), 8 * bounds_offset);
+  result->field (1).set_loc_bitpos (8 * bounds_offset);
 
   result->set_name (type->name ());
   TYPE_LENGTH (result) = (TYPE_LENGTH (result->field (0).type ())
@@ -17414,7 +17423,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
          /* Pass 0 as the default as we know this attribute is constant
             and the default value will not be returned.  */
          LONGEST sz = len->constant_value (0);
-         prop_type = cu->per_objfile->int_type (sz, true);
+         prop_type = objfile_int_type (objfile, sz, true);
        }
       else
        {
@@ -18241,16 +18250,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        break;
       case DW_ATE_UTF:
        {
-         if (bits == 16)
-           type = builtin_type (arch)->builtin_char16;
-         else if (bits == 32)
-           type = builtin_type (arch)->builtin_char32;
-         else
-           {
-             complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
-                        bits);
-             type = dwarf2_init_integer_type (cu, objfile, bits, 1, name);
-           }
+         type = init_character_type (objfile, bits, 1, name);
          return set_die_type (die, type, cu);
        }
        break;
@@ -18270,7 +18270,9 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        break;
     }
 
-  if (name && strcmp (name, "char") == 0)
+  if (type->code () == TYPE_CODE_INT
+      && name != nullptr
+      && strcmp (name, "char") == 0)
     type->set_has_no_signedness (true);
 
   maybe_set_alignment (cu, die, type);
@@ -18388,6 +18390,9 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
       if (target_attr == NULL)
        target_attr = dwarf2_attr (target_die, DW_AT_data_member_location,
                                   target_cu);
+      if (target_attr == nullptr)
+       target_attr = dwarf2_attr (target_die, DW_AT_data_bit_offset,
+                                  target_cu);
       if (target_attr == NULL)
        {
          const char *name = var_decl_name (target_die, target_cu);
@@ -18431,11 +18436,11 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
              }
            break;
          case DW_AT_data_member_location:
+         case DW_AT_data_bit_offset:
            {
              LONGEST offset;
 
-             if (!handle_data_member_location (target_die, target_cu,
-                                               &offset))
+             if (!handle_member_location (target_die, target_cu, &offset))
                return 0;
 
              baton = XOBNEW (obstack, struct dwarf2_property_baton);
@@ -18450,42 +18455,34 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
     }
   else if (attr->form_is_constant ())
     prop->set_const_val (attr->constant_value (0));
-  else
+  else if (attr->form_is_section_offset ())
     {
-      dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr->form),
-                                            dwarf2_name (die, cu));
-      return 0;
+      switch (attr->name)
+       {
+       case DW_AT_string_length:
+         baton = XOBNEW (obstack, struct dwarf2_property_baton);
+         baton->property_type = default_type;
+         fill_in_loclist_baton (cu, &baton->loclist, attr);
+         prop->set_loclist (baton);
+         gdb_assert (prop->baton () != NULL);
+         break;
+       default:
+         goto invalid;
+       }
     }
+  else
+    goto invalid;
 
   return 1;
+
+ invalid:
+  dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr->form),
+                                        dwarf2_name (die, cu));
+  return 0;
 }
 
 /* See read.h.  */
 
-struct type *
-dwarf2_per_objfile::int_type (int size_in_bytes, bool unsigned_p) const
-{
-  struct type *int_type;
-
-  /* Helper macro to examine the various builtin types.  */
-#define TRY_TYPE(F)                                                    \
-  int_type = (unsigned_p                                               \
-             ? objfile_type (objfile)->builtin_unsigned_ ## F          \
-             : objfile_type (objfile)->builtin_ ## F);                 \
-  if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes)     \
-    return int_type
-
-  TRY_TYPE (char);
-  TRY_TYPE (short);
-  TRY_TYPE (int);
-  TRY_TYPE (long);
-  TRY_TYPE (long_long);
-
-#undef TRY_TYPE
-
-  gdb_assert_not_reached ("unable to find suitable integer type");
-}
-
 /* Read the DW_AT_type attribute for a sub-range.  If this attribute is not
    present (which is valid) then compute the default type based on the
    compilation units address size.  */
@@ -19532,7 +19529,7 @@ find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
        }
       dwarf2_per_cu_data *per_cu
        = dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz,
-                                           per_objfile);
+                                           per_objfile->per_bfd);
 
       cu = per_objfile->get_cu (per_cu);
       if (cu == NULL || cu->partial_dies == NULL)
@@ -19967,7 +19964,7 @@ read_attribute_reprocess (const struct die_reader_specs *reader,
          break;
        }
       default:
-       gdb_assert_not_reached (_("Unexpected DWARF form."));
+       gdb_assert_not_reached ("Unexpected DWARF form.");
     }
 }
 
@@ -20292,6 +20289,18 @@ read_indirect_string (dwarf2_per_objfile *per_objfile, bfd *abfd,
 
 /* See read.h.  */
 
+const char *
+dwarf2_per_objfile::read_line_string (const gdb_byte *buf,
+                                     unsigned int offset_size)
+{
+  bfd *abfd = objfile->obfd;
+  ULONGEST str_offset = read_offset (abfd, buf, offset_size);
+
+  return per_bfd->line_str.read_string (objfile, str_offset, "DW_FORM_line_strp");
+}
+
+/* See read.h.  */
+
 const char *
 dwarf2_per_objfile::read_line_string (const gdb_byte *buf,
                                      const struct comp_unit_head *cu_header,
@@ -20741,7 +20750,7 @@ compute_include_file_name (const struct line_header *lh, const file_entry &fe,
 
   gdb::unique_xmalloc_ptr<char> hold_compare;
   if (!IS_ABSOLUTE_PATH (include_name)
-      && (dir_name != NULL || cu_info.comp_dir != NULL))
+      && (dir_name != nullptr || cu_info.get_comp_dir () != nullptr))
     {
       /* Avoid creating a duplicate name for CU_INFO.
         We do this by comparing INCLUDE_NAME and CU_INFO.
@@ -20771,19 +20780,20 @@ compute_include_file_name (const struct line_header *lh, const file_entry &fe,
          include_name = name_holder->get ();
          include_name_to_compare = include_name;
        }
-      if (!IS_ABSOLUTE_PATH (include_name) && cu_info.comp_dir != nullptr)
+      if (!IS_ABSOLUTE_PATH (include_name)
+         && cu_info.get_comp_dir () != nullptr)
        {
-         hold_compare.reset (concat (cu_info.comp_dir, SLASH_STRING,
+         hold_compare.reset (concat (cu_info.get_comp_dir (), SLASH_STRING,
                                      include_name, (char *) NULL));
          include_name_to_compare = hold_compare.get ();
        }
     }
 
   gdb::unique_xmalloc_ptr<char> copied_name;
-  const char *cu_filename = cu_info.name;
-  if (!IS_ABSOLUTE_PATH (cu_filename) && cu_info.comp_dir != nullptr)
+  const char *cu_filename = cu_info.get_name ();
+  if (!IS_ABSOLUTE_PATH (cu_filename) && cu_info.get_comp_dir () != nullptr)
     {
-      copied_name.reset (concat (cu_info.comp_dir, SLASH_STRING,
+      copied_name.reset (concat (cu_info.get_comp_dir (), SLASH_STRING,
                                 cu_filename, (char *) NULL));
       cu_filename = copied_name.get ();
     }
@@ -22364,7 +22374,8 @@ lookup_die_type (struct die_info *die, const struct attribute *attr,
       struct dwarf2_per_cu_data *per_cu;
       sect_offset sect_off = attr->get_ref_die_offset ();
 
-      per_cu = dwarf2_find_containing_comp_unit (sect_off, 1, per_objfile);
+      per_cu = dwarf2_find_containing_comp_unit (sect_off, 1,
+                                                per_objfile->per_bfd);
       this_type = get_die_type_at_offset (sect_off, per_cu, per_objfile);
     }
   else if (attr->form_is_ref ())
@@ -22988,31 +22999,28 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
 {
   unsigned int i;
 
-  print_spaces (indent, f);
-  fprintf_unfiltered (f, "Die: %s (abbrev %d, offset %s)\n",
+  fprintf_unfiltered (f, "%*sDie: %s (abbrev %d, offset %s)\n",
+                     indent, "",
                      dwarf_tag_name (die->tag), die->abbrev,
                      sect_offset_str (die->sect_off));
 
   if (die->parent != NULL)
-    {
-      print_spaces (indent, f);
-      fprintf_unfiltered (f, "  parent at offset: %s\n",
-                         sect_offset_str (die->parent->sect_off));
-    }
+    fprintf_unfiltered (f, "%*s  parent at offset: %s\n",
+                       indent, "",
+                       sect_offset_str (die->parent->sect_off));
 
-  print_spaces (indent, f);
-  fprintf_unfiltered (f, "  has children: %s\n",
-          dwarf_bool_name (die->child != NULL));
+  fprintf_unfiltered (f, "%*s  has children: %s\n",
+                     indent, "",
+                     dwarf_bool_name (die->child != NULL));
 
-  print_spaces (indent, f);
-  fprintf_unfiltered (f, "  attributes:\n");
+  fprintf_unfiltered (f, "%*s  attributes:\n", indent, "");
 
   for (i = 0; i < die->num_attrs; ++i)
     {
-      print_spaces (indent, f);
-      fprintf_unfiltered (f, "    %s (%s) ",
-              dwarf_attr_name (die->attrs[i].name),
-              dwarf_form_name (die->attrs[i].form));
+      fprintf_unfiltered (f, "%*s    %s (%s) ",
+                         indent, "",
+                         dwarf_attr_name (die->attrs[i].name),
+                         dwarf_form_name (die->attrs[i].form));
 
       switch (die->attrs[i].form)
        {
@@ -23128,8 +23136,7 @@ dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
 
   if (die->child != NULL)
     {
-      print_spaces (indent, f);
-      fprintf_unfiltered (f, "  Children:");
+      fprintf_unfiltered (f, "%*s  Children:", indent, "");
       if (level + 1 < max_level)
        {
          fprintf_unfiltered (f, "\n");
@@ -23230,7 +23237,7 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
       struct dwarf2_per_cu_data *per_cu;
 
       per_cu = dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz,
-                                                per_objfile);
+                                                per_objfile->per_bfd);
 
       dwarf_read_debug_printf_v ("target CU offset: %s, "
                                 "target CU DIEs loaded: %d",
@@ -24462,12 +24469,11 @@ dwarf2_find_containing_comp_unit
 static struct dwarf2_per_cu_data *
 dwarf2_find_containing_comp_unit (sect_offset sect_off,
                                  unsigned int offset_in_dwz,
-                                 dwarf2_per_objfile *per_objfile)
+                                 dwarf2_per_bfd *per_bfd)
 {
   int low = dwarf2_find_containing_comp_unit
-    (sect_off, offset_in_dwz, per_objfile->per_bfd->all_comp_units);
-  dwarf2_per_cu_data *this_cu
-    = per_objfile->per_bfd->all_comp_units[low].get ();
+    (sect_off, offset_in_dwz, per_bfd->all_comp_units);
+  dwarf2_per_cu_data *this_cu = per_bfd->all_comp_units[low].get ();
 
   if (this_cu->is_dwz != offset_in_dwz || this_cu->sect_off > sect_off)
     {
@@ -24475,15 +24481,15 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
        error (_("Dwarf Error: could not find partial DIE containing "
               "offset %s [in module %s]"),
               sect_offset_str (sect_off),
-              bfd_get_filename (per_objfile->objfile->obfd));
+              bfd_get_filename (per_bfd->obfd));
 
-      gdb_assert (per_objfile->per_bfd->all_comp_units[low-1]->sect_off
+      gdb_assert (per_bfd->all_comp_units[low-1]->sect_off
                  <= sect_off);
-      return per_objfile->per_bfd->all_comp_units[low - 1].get ();
+      return per_bfd->all_comp_units[low - 1].get ();
     }
   else
     {
-      if (low == per_objfile->per_bfd->all_comp_units.size () - 1
+      if (low == per_bfd->all_comp_units.size () - 1
          && sect_off >= this_cu->sect_off + this_cu->length)
        error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off));
       gdb_assert (sect_off < this_cu->sect_off + this_cu->length);
@@ -24879,17 +24885,15 @@ void _initialize_dwarf2_read ();
 void
 _initialize_dwarf2_read ()
 {
-  add_basic_prefix_cmd ("dwarf", class_maintenance, _("\
+  add_setshow_prefix_cmd ("dwarf", class_maintenance,
+                         _("\
 Set DWARF specific variables.\n\
 Configure DWARF variables such as the cache size."),
-                       &set_dwarf_cmdlist,
-                       0/*allow-unknown*/, &maintenance_set_cmdlist);
-
-  add_show_prefix_cmd ("dwarf", class_maintenance, _("\
+                         _("\
 Show DWARF specific variables.\n\
 Show DWARF variables such as the cache size."),
-                      &show_dwarf_cmdlist,
-                      0/*allow-unknown*/, &maintenance_show_cmdlist);
+                         &set_dwarf_cmdlist, &show_dwarf_cmdlist,
+                         &maintenance_set_cmdlist, &maintenance_show_cmdlist);
 
   add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
                            &dwarf_max_cache_age, _("\