gdb/dwarf: replace some "compile unit" terminology with "unit"

Message ID 20250416040908.697929-1-simon.marchi@polymtl.ca
State New
Headers
Series gdb/dwarf: replace some "compile unit" terminology with "unit" |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Simon Marchi April 16, 2025, 4:09 a.m. UTC
  From: Simon Marchi <simon.marchi@efficios.com>

In DWARF 5 (and even previous versions, with type units), compile units
are just one type of units.  In many places, we still use "compile
units" when in reality it would be better to talk about "units" (unless
we specifically want to talk about compile units).

Rename comp-unit-head.{c.h} to unit-head.{c,h}, and do a big pass of
renames in it to remove the specific mentions of compile units, where in
fact we want to talk about units in general.

Change-Id: Ia06c90ccb25756c366f269a12620f2f7c8378adb
---
 gdb/Makefile.in                              |   2 +-
 gdb/dwarf2/cooked-indexer.c                  |   2 +-
 gdb/dwarf2/cu.h                              |   4 +-
 gdb/dwarf2/line-header.c                     |  13 +-
 gdb/dwarf2/line-header.h                     |   2 +-
 gdb/dwarf2/read.c                            | 122 +++++++++---------
 gdb/dwarf2/read.h                            |  16 +--
 gdb/dwarf2/{comp-unit-head.c => unit-head.c} | 126 +++++++++----------
 gdb/dwarf2/{comp-unit-head.h => unit-head.h} |  69 +++++-----
 gdb/testsuite/gdb.dwarf2/dw2-error.exp       |   2 +-
 10 files changed, 172 insertions(+), 186 deletions(-)
 rename gdb/dwarf2/{comp-unit-head.c => unit-head.c} (57%)
 rename gdb/dwarf2/{comp-unit-head.h => unit-head.h} (64%)


base-commit: 280160a7d036a73e1dbd012da1f77651921a25a4
  

Patch

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 9275f8dd1a24..e28b9e485fc7 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1095,7 +1095,6 @@  COMMON_SFILES = \
 	dwarf2/ada-imported.c \
 	dwarf2/aranges.c \
 	dwarf2/attribute.c \
-	dwarf2/comp-unit-head.c \
 	dwarf2/cooked-index.c \
 	dwarf2/cooked-index-entry.c \
 	dwarf2/cooked-index-shard.c \
@@ -1120,6 +1119,7 @@  COMMON_SFILES = \
 	dwarf2/read-gdb-index.c \
 	dwarf2/section.c \
 	dwarf2/stringify.c \
+	dwarf2/unit-head.c \
 	extract-store-integer.c \
 	eval.c \
 	event-top.c \
diff --git a/gdb/dwarf2/cooked-indexer.c b/gdb/dwarf2/cooked-indexer.c
index 1f3a2357958f..22aecfdc55ed 100644
--- a/gdb/dwarf2/cooked-indexer.c
+++ b/gdb/dwarf2/cooked-indexer.c
@@ -89,7 +89,7 @@  cooked_indexer::ensure_cu_exists (cutu_reader *reader,
   /* Lookups for type unit references are always in the CU, and
      cross-CU references will crash.  */
   if (reader->cu ()->per_cu->is_dwz == is_dwz
-      && reader->cu ()->header.offset_in_cu_p (sect_off))
+      && reader->cu ()->header.offset_in_unit_p (sect_off))
     return reader;
 
   dwarf2_per_objfile *per_objfile = reader->cu ()->per_objfile;
diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h
index 5683291fbcfe..1f6efc9935f8 100644
--- a/gdb/dwarf2/cu.h
+++ b/gdb/dwarf2/cu.h
@@ -21,7 +21,7 @@ 
 #define GDB_DWARF2_CU_H
 
 #include "buildsym.h"
-#include "dwarf2/comp-unit-head.h"
+#include "dwarf2/unit-head.h"
 #include <optional>
 #include "language.h"
 #include "gdbsupport/unordered_set.h"
@@ -100,7 +100,7 @@  struct dwarf2_cu
   { m_dependencies.emplace (ref_per_cu); }
 
   /* The header of the compilation unit.  */
-  struct comp_unit_head header;
+  struct unit_head header;
 
   /* Base address of this compilation unit.  */
   std::optional<unrelocated_addr> base_address;
diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c
index de162b70b1b9..465230693373 100644
--- a/gdb/dwarf2/line-header.c
+++ b/gdb/dwarf2/line-header.c
@@ -17,7 +17,7 @@ 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "dwarf2/comp-unit-head.h"
+#include "dwarf2/unit-head.h"
 #include "dwarf2/leb.h"
 #include "dwarf2/line-header.h"
 #include "dwarf2/read.h"
@@ -95,7 +95,7 @@  dwarf2_statement_list_fits_in_line_number_section_complaint (void)
 
 static LONGEST
 read_checked_initial_length_and_offset (bfd *abfd, const gdb_byte *buf,
-					const struct comp_unit_head *cu_header,
+					const struct unit_head *cu_header,
 					unsigned int *bytes_read,
 					unsigned int *offset_size)
 {
@@ -253,11 +253,10 @@  read_formatted_entries (dwarf2_per_objfile *per_objfile, bfd *abfd,
 /* See line-header.h.  */
 
 line_header_up
-dwarf_decode_line_header  (sect_offset sect_off, bool is_dwz,
-			   dwarf2_per_objfile *per_objfile,
-			   struct dwarf2_section_info *section,
-			   const struct comp_unit_head *cu_header,
-			   const char *comp_dir)
+dwarf_decode_line_header (sect_offset sect_off, bool is_dwz,
+			  dwarf2_per_objfile *per_objfile,
+			  struct dwarf2_section_info *section,
+			  const unit_head *cu_header, const char *comp_dir)
 {
   const gdb_byte *line_ptr;
   unsigned int bytes_read, offset_size;
diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h
index 36385b6d13ac..e6f9ea9f2d4c 100644
--- a/gdb/dwarf2/line-header.h
+++ b/gdb/dwarf2/line-header.h
@@ -218,7 +218,7 @@  file_entry::include_dir (const line_header *lh) const
 
 extern line_header_up dwarf_decode_line_header
   (sect_offset sect_off, bool is_dwz, dwarf2_per_objfile *per_objfile,
-   struct dwarf2_section_info *section, const struct comp_unit_head *cu_header,
+   struct dwarf2_section_info *section, const struct unit_head *cu_header,
    const char *comp_dir);
 
 #endif /* GDB_DWARF2_LINE_HEADER_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 794c3973cb56..70c9bc1294cc 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -31,7 +31,7 @@ 
 #include "dwarf2/abbrev.h"
 #include "dwarf2/aranges.h"
 #include "dwarf2/attribute.h"
-#include "dwarf2/comp-unit-head.h"
+#include "dwarf2/unit-head.h"
 #include "dwarf2/cooked-index-worker.h"
 #include "dwarf2/cooked-indexer.h"
 #include "dwarf2/cu.h"
@@ -742,9 +742,9 @@  static unrelocated_addr read_addr_index (struct dwarf2_cu *cu,
 static sect_offset read_abbrev_offset (dwarf2_per_objfile *per_objfile,
 				       dwarf2_section_info *, sect_offset);
 
-static const char *read_indirect_string
-  (dwarf2_per_objfile *per_objfile, bfd *, const gdb_byte *,
-   const struct comp_unit_head *, unsigned int *);
+static const char *read_indirect_string (dwarf2_per_objfile *per_objfile, bfd *,
+					 const gdb_byte *, const unit_head *,
+					 unsigned int *);
 
 static unrelocated_addr read_addr_index_from_leb128 (struct dwarf2_cu *,
 						     const gdb_byte *,
@@ -2389,8 +2389,9 @@  read_abbrev_offset (dwarf2_per_objfile *per_objfile,
 
 static void
 create_dwo_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
-				  dwo_file *dwo_file, dwarf2_section_info *section,
-				  rcuh_kind section_kind)
+				  dwo_file *dwo_file,
+				  dwarf2_section_info *section,
+				  ruh_kind section_kind)
 {
   struct objfile *objfile = per_objfile->objfile;
   struct dwarf2_section_info *abbrev_section;
@@ -2420,20 +2421,20 @@  create_dwo_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
   while (info_ptr < end_ptr)
     {
       const gdb_byte *ptr = info_ptr;
-      struct comp_unit_head header;
+      unit_head header;
       unsigned int length;
 
       sect_offset sect_off = (sect_offset) (ptr - section->buffer);
 
       /* Initialize it due to a false compiler warning.  */
       header.signature = -1;
-      header.type_cu_offset_in_tu = (cu_offset) -1;
+      header.type_offset_in_tu = (cu_offset) -1;
 
       /* We need to read the type's signature in order to build the hash
 	 table, but we don't need anything else just yet.  */
 
-      ptr = read_and_check_comp_unit_head (per_objfile, &header, section,
-					   abbrev_section, ptr, section_kind);
+      ptr = read_and_check_unit_head (per_objfile, &header, section,
+				      abbrev_section, ptr, section_kind);
 
       length = header.get_length_with_initial ();
 
@@ -2451,7 +2452,7 @@  create_dwo_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
 	= OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, dwo_unit);
       dwo_tu->dwo_file = dwo_file;
       dwo_tu->signature = header.signature;
-      dwo_tu->type_offset_in_tu = header.type_cu_offset_in_tu;
+      dwo_tu->type_offset_in_tu = header.type_offset_in_tu;
       dwo_tu->section = section;
       dwo_tu->sect_off = sect_off;
       dwo_tu->length = length;
@@ -2485,7 +2486,7 @@  create_dwo_debug_types_hash_table
 {
   for (dwarf2_section_info &section : type_sections)
     create_dwo_debug_type_hash_table (per_objfile, dwo_file, &section,
-				  rcuh_kind::TYPE);
+				      ruh_kind::TYPE);
 }
 
 /* Add an entry for signature SIG to per_bfd->signatured_types.  */
@@ -2790,9 +2791,9 @@  cutu_reader::read_cutu_die_from_dwo (dwarf2_cu *cu, dwo_unit *dwo_unit,
     {
       signatured_type *sig_type = (struct signatured_type *) per_cu;
 
-      m_info_ptr = read_and_check_comp_unit_head (per_objfile, &cu->header,
-						  section, dwo_abbrev_section,
-						  m_info_ptr, rcuh_kind::TYPE);
+      m_info_ptr = read_and_check_unit_head (per_objfile, &cu->header, section,
+					     dwo_abbrev_section, m_info_ptr,
+					     ruh_kind::TYPE);
       /* This is not an assert because it can be caused by bad debug info.  */
       if (sig_type->signature != cu->header.signature)
 	{
@@ -2808,7 +2809,7 @@  cutu_reader::read_cutu_die_from_dwo (dwarf2_cu *cu, dwo_unit *dwo_unit,
       /* For DWOs coming from DWP files, we don't know the CU length
 	 nor the type's offset in the TU until now.  */
       dwo_unit->length = cu->header.get_length_with_initial ();
-      dwo_unit->type_offset_in_tu = cu->header.type_cu_offset_in_tu;
+      dwo_unit->type_offset_in_tu = cu->header.type_offset_in_tu;
 
       /* Establish the type offset that can be used to lookup the type.
 	 For DWO files, we don't know it until now.  */
@@ -2817,10 +2818,9 @@  cutu_reader::read_cutu_die_from_dwo (dwarf2_cu *cu, dwo_unit *dwo_unit,
     }
   else
     {
-      m_info_ptr
-	= read_and_check_comp_unit_head (per_objfile, &cu->header, section,
-					 dwo_abbrev_section, m_info_ptr,
-					 rcuh_kind::COMPILE);
+      m_info_ptr = read_and_check_unit_head (per_objfile, &cu->header, section,
+					     dwo_abbrev_section, m_info_ptr,
+					     ruh_kind::COMPILE);
       gdb_assert (dwo_unit->sect_off == cu->header.sect_off);
       /* For DWOs coming from DWP files, we don't know the CU length
 	 until now.  */
@@ -3037,26 +3037,26 @@  cutu_reader::cutu_reader (dwarf2_per_cu &this_cu,
     }
 
   /* Get the header.  */
-  if (to_underlying (cu->header.first_die_cu_offset) != 0 && !rereading_dwo_cu)
+  if (to_underlying (cu->header.first_die_offset_in_unit) != 0
+      && !rereading_dwo_cu)
     {
       /* We already have the header, there's no need to read it in again.  */
-      m_info_ptr += to_underlying (cu->header.first_die_cu_offset);
+      m_info_ptr += to_underlying (cu->header.first_die_offset_in_unit);
     }
   else
     {
       if (this_cu.is_debug_types)
 	{
-	  m_info_ptr
-	    = read_and_check_comp_unit_head (&per_objfile, &cu->header, section,
-					     abbrev_section, m_info_ptr,
-					     rcuh_kind::TYPE);
+	  m_info_ptr = read_and_check_unit_head (&per_objfile, &cu->header,
+						 section, abbrev_section,
+						 m_info_ptr, ruh_kind::TYPE);
 
 	  /* Since per_cu is the first member of struct signatured_type,
 	     we can go from a pointer to one to a pointer to the other.  */
 	  sig_type = (struct signatured_type *) &this_cu;
 	  gdb_assert (sig_type->signature == cu->header.signature);
 	  gdb_assert (sig_type->type_offset_in_tu
-		      == cu->header.type_cu_offset_in_tu);
+		      == cu->header.type_offset_in_tu);
 	  gdb_assert (this_cu.sect_off == cu->header.sect_off);
 
 	  /* LENGTH has not been set yet for type units if we're
@@ -3069,10 +3069,9 @@  cutu_reader::cutu_reader (dwarf2_per_cu &this_cu,
 	}
       else
 	{
-	  m_info_ptr
-	    = read_and_check_comp_unit_head (&per_objfile, &cu->header, section,
-					     abbrev_section, m_info_ptr,
-					     rcuh_kind::COMPILE);
+	  m_info_ptr = read_and_check_unit_head (&per_objfile, &cu->header,
+						 section, abbrev_section,
+						 m_info_ptr, ruh_kind::COMPILE);
 
 	  gdb_assert (this_cu.sect_off == cu->header.sect_off);
 	  this_cu.set_length (cu->header.get_length_with_initial ());
@@ -3205,11 +3204,11 @@  cutu_reader::cutu_reader (dwarf2_per_cu &this_cu,
   m_info_ptr = section->buffer + to_underlying (this_cu.sect_off);
   const gdb_byte *begin_info_ptr = m_info_ptr;
   m_info_ptr
-    = read_and_check_comp_unit_head (&per_objfile, &m_new_cu->header, section,
-				     abbrev_section, m_info_ptr,
-				     (this_cu.is_debug_types
-				      ? rcuh_kind::TYPE
-				      : rcuh_kind::COMPILE));
+    = read_and_check_unit_head (&per_objfile, &m_new_cu->header, section,
+				abbrev_section, m_info_ptr,
+				(this_cu.is_debug_types
+				 ? ruh_kind::TYPE
+				 : ruh_kind::COMPILE));
 
   m_new_cu->str_offsets_base = parent_cu.str_offsets_base;
   m_new_cu->addr_base = parent_cu.addr_base;
@@ -3688,7 +3687,7 @@  read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
 			      struct dwarf2_section_info *abbrev_section,
 			      unsigned int is_dwz,
 			      signatured_type_set &sig_types,
-			      rcuh_kind section_kind)
+			      ruh_kind section_kind)
 {
   const gdb_byte *info_ptr;
   struct objfile *objfile = per_objfile->objfile;
@@ -3707,10 +3706,9 @@  read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
 
       sect_offset sect_off = (sect_offset) (info_ptr - section->buffer);
 
-      comp_unit_head cu_header;
-      read_and_check_comp_unit_head (per_objfile, &cu_header, section,
-				     abbrev_section, info_ptr,
-				     section_kind);
+      unit_head cu_header;
+      read_and_check_unit_head (per_objfile, &cu_header, section,
+				abbrev_section, info_ptr, section_kind);
 
       unsigned int length = cu_header.get_length_with_initial ();
 
@@ -3723,7 +3721,7 @@  read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
 	  auto sig_type = per_objfile->per_bfd->allocate_signatured_type
 	    (section, sect_off, length, is_dwz, cu_header.signature);
 	  signatured_type *sig_ptr = sig_type.get ();
-	  sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu;
+	  sig_type->type_offset_in_tu = cu_header.type_offset_in_tu;
 	  this_cu.reset (sig_type.release ());
 
 	  auto inserted = sig_types.emplace (sig_ptr).second;
@@ -3765,17 +3763,17 @@  create_all_units (dwarf2_per_objfile *per_objfile)
   for (dwarf2_section_info &section : per_objfile->per_bfd->infos)
     read_comp_units_from_section (per_objfile, &section,
 				  &per_objfile->per_bfd->abbrev, 0, sig_types,
-				  rcuh_kind::COMPILE);
+				  ruh_kind::COMPILE);
   for (dwarf2_section_info &section : per_objfile->per_bfd->types)
     read_comp_units_from_section (per_objfile, &section,
 				  &per_objfile->per_bfd->abbrev, 0, sig_types,
-				  rcuh_kind::TYPE);
+				  ruh_kind::TYPE);
 
   dwz_file *dwz = per_objfile->per_bfd->get_dwz_file ();
   if (dwz != NULL)
     {
       read_comp_units_from_section (per_objfile, &dwz->info, &dwz->abbrev, 1,
-				    sig_types, rcuh_kind::COMPILE);
+				    sig_types, ruh_kind::COMPILE);
 
       if (!dwz->types.empty ())
 	{
@@ -7644,7 +7642,7 @@  open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
   else
     create_dwo_debug_type_hash_table (per_objfile, dwo_file.get (),
 				      &dwo_file->sections.info,
-				      rcuh_kind::COMPILE);
+				      ruh_kind::COMPILE);
 
   dwarf_read_debug_printf ("DWO file found: %s", dwo_name);
 
@@ -8894,7 +8892,7 @@  read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	  parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET;
 
 	  sect_offset sect_off = origin->get_ref_die_offset ();
-	  if (!cu->header.offset_in_cu_p (sect_off))
+	  if (!cu->header.offset_in_unit_p (sect_off))
 	    {
 	      /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
 		 binding can be done only inside one CU.  Such referenced DIE
@@ -9262,7 +9260,7 @@  dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag,
 {
   dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct objfile *objfile = per_objfile->objfile;
-  struct comp_unit_head *cu_header = &cu->header;
+  unit_head *cu_header = &cu->header;
   bfd *obfd = objfile->obfd.get ();
   unsigned int addr_size = cu_header->addr_size;
   CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
@@ -12602,7 +12600,7 @@  static struct type *
 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct gdbarch *gdbarch = cu->per_objfile->objfile->arch ();
-  struct comp_unit_head *cu_header = &cu->header;
+  unit_head *cu_header = &cu->header;
   struct type *type;
   struct attribute *attr_byte_size;
   struct attribute *attr_address_class;
@@ -12716,7 +12714,7 @@  static struct type *
 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu,
 			  enum type_code refcode)
 {
-  struct comp_unit_head *cu_header = &cu->header;
+  unit_head *cu_header = &cu->header;
   struct type *type, *target_type;
   struct attribute *attr;
 
@@ -14883,7 +14881,7 @@  cutu_reader::read_attribute_value (attribute *attr, unsigned form,
 {
   dwarf2_per_objfile *per_objfile = m_cu->per_objfile;
   struct objfile *objfile = per_objfile->objfile;
-  struct comp_unit_head *cu_header = &m_cu->header;
+  unit_head *cu_header = &m_cu->header;
   unsigned int bytes_read;
   struct dwarf_block *blk;
 
@@ -15188,8 +15186,7 @@  read_indirect_string_at_offset (dwarf2_per_objfile *per_objfile,
 
 static const char *
 read_indirect_string (dwarf2_per_objfile *per_objfile, bfd *abfd,
-		      const gdb_byte *buf,
-		      const struct comp_unit_head *cu_header,
+		      const gdb_byte *buf, const unit_head *cu_header,
 		      unsigned int *bytes_read_ptr)
 {
   LONGEST str_offset = cu_header->read_offset (abfd, buf, bytes_read_ptr);
@@ -15213,7 +15210,7 @@  dwarf2_per_objfile::read_line_string (const gdb_byte *buf,
 
 const char *
 dwarf2_per_objfile::read_line_string (const gdb_byte *buf,
-				      const struct comp_unit_head *cu_header,
+				      const unit_head *cu_header,
 				      unsigned int *bytes_read_ptr)
 {
   bfd *abfd = objfile->obfd.get ();
@@ -16545,7 +16542,7 @@  var_decode_location (struct attribute *attr, struct symbol *sym,
 		     struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->per_objfile->objfile;
-  struct comp_unit_head *cu_header = &cu->header;
+  unit_head *cu_header = &cu->header;
 
   /* NOTE drow/2003-01-30: There used to be a comment and some special
      code here to turn a symbol with DW_AT_external and a
@@ -17227,7 +17224,7 @@  dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
 {
   dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct objfile *objfile = per_objfile->objfile;
-  struct comp_unit_head *cu_header = &cu->header;
+  unit_head *cu_header = &cu->header;
   struct dwarf_block *blk;
   enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd.get ()) ?
 				BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
@@ -18202,18 +18199,18 @@  follow_die_offset (sect_offset sect_off, int offset_in_dwz,
 			     "source CU contains target offset: %d",
 			     sect_offset_str (source_cu->per_cu->sect_off),
 			     sect_offset_str (sect_off),
-			     source_cu->header.offset_in_cu_p (sect_off));
+			     source_cu->header.offset_in_unit_p (sect_off));
 
   if (source_cu->per_cu->is_debug_types)
     {
       /* .debug_types CUs cannot reference anything outside their CU.
 	 If they need to, they have to reference a signatured type via
 	 DW_FORM_ref_sig8.  */
-      if (!source_cu->header.offset_in_cu_p (sect_off))
+      if (!source_cu->header.offset_in_unit_p (sect_off))
 	return NULL;
     }
   else if (offset_in_dwz != source_cu->per_cu->is_dwz
-	   || !source_cu->header.offset_in_cu_p (sect_off))
+	   || !source_cu->header.offset_in_unit_p (sect_off))
     {
       dwarf2_per_cu *target_per_cu
 	= dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz,
@@ -19242,7 +19239,7 @@  dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
 
 /* See read.h.  */
 
-const comp_unit_head *
+const unit_head *
 dwarf2_per_cu::get_header () const
 {
   if (!m_header_read_in)
@@ -19250,8 +19247,7 @@  dwarf2_per_cu::get_header () const
       const gdb_byte *info_ptr
 	= this->section->buffer + to_underlying (this->sect_off);
 
-      read_comp_unit_head (&m_header, info_ptr, this->section,
-			   rcuh_kind::COMPILE);
+      read_unit_head (&m_header, info_ptr, this->section, ruh_kind::COMPILE);
 
       m_header_read_in = true;
     }
@@ -19280,7 +19276,7 @@  dwarf2_per_cu::offset_size () const
 int
 dwarf2_per_cu::ref_addr_size () const
 {
-  const comp_unit_head *header = this->get_header ();
+  const unit_head *header = this->get_header ();
 
   if (header->version == 2)
     return header->addr_size;
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 3177b19ede57..5f4aadc3cb3b 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -22,7 +22,7 @@ 
 
 #include <queue>
 #include "dwarf2/abbrev.h"
-#include "dwarf2/comp-unit-head.h"
+#include "dwarf2/unit-head.h"
 #include "dwarf2/file-and-dir.h"
 #include "dwarf2/index-cache.h"
 #include "dwarf2/mapped-index.h"
@@ -233,14 +233,14 @@  struct dwarf2_per_cu
   /* Backlink to the owner of this.  */
   dwarf2_per_bfd *per_bfd;
 
-  /* DWARF header of this CU.  Note that dwarf2_cu reads its own version of the
-     header, which may differ from this one, since it may pass rcuh_kind::TYPE
-     to read_comp_unit_head, whereas for dwarf2_per_cu we always pass
-     rcuh_kind::COMPILE.
+  /* DWARF header of this unit.  Note that dwarf2_cu reads its own version of
+     the header, which may differ from this one, since it may pass
+     rch_kind::TYPE to read_unit_head, whereas for dwarf2_per_cu we always pass
+     ruh_kind::COMPILE.
 
      Don't access this field directly, use the get_header method instead.  It
      should be private, but we can't make it private at the moment.  */
-  mutable comp_unit_head m_header;
+  mutable unit_head m_header;
 
   /* The file and directory for this CU.  This is cached so that we
      don't need to re-examine the DWO in some situations.  This may be
@@ -271,7 +271,7 @@  struct dwarf2_per_cu
   std::vector<dwarf2_per_cu *> imported_symtabs;
 
   /* Get the header of this per_cu, reading it if necessary.  */
-  const comp_unit_head *get_header () const;
+  const unit_head *get_header () const;
 
   /* Return the address size given in the compilation unit header for
      this CU.  */
@@ -815,7 +815,7 @@  struct dwarf2_per_objfile
      BUF is assumed to be in a compilation unit described by CU_HEADER.
      Return *BYTES_READ_PTR count of bytes read from BUF.  */
   const char *read_line_string (const gdb_byte *buf,
-				const struct comp_unit_head *cu_header,
+				const struct unit_head *unit_header,
 				unsigned int *bytes_read_ptr);
 
   /* Return pointer to string at .debug_line_str offset as read from BUF.
diff --git a/gdb/dwarf2/comp-unit-head.c b/gdb/dwarf2/unit-head.c
similarity index 57%
rename from gdb/dwarf2/comp-unit-head.c
rename to gdb/dwarf2/unit-head.c
index 8ec8897b283e..14dc400c167a 100644
--- a/gdb/dwarf2/comp-unit-head.c
+++ b/gdb/dwarf2/unit-head.c
@@ -24,119 +24,118 @@ 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "dwarf2/comp-unit-head.h"
+#include "dwarf2/unit-head.h"
 #include "dwarf2/leb.h"
 #include "dwarf2/read.h"
 #include "dwarf2/section.h"
 #include "dwarf2/stringify.h"
 #include "dwarf2/error.h"
 
-/* See comp-unit-head.h.  */
+/* See unit-head.h.  */
 
 const gdb_byte *
-read_comp_unit_head (struct comp_unit_head *cu_header,
-		     const gdb_byte *info_ptr,
-		     struct dwarf2_section_info *section,
-		     rcuh_kind section_kind)
+read_unit_head (struct unit_head *header, const gdb_byte *info_ptr,
+		struct dwarf2_section_info *section, ruh_kind section_kind)
 {
   int signed_addr;
   unsigned int bytes_read;
   const char *filename = section->get_file_name ();
   bfd *abfd = section->get_bfd_owner ();
 
-  cu_header->set_length (read_initial_length (abfd, info_ptr, &bytes_read));
-  cu_header->initial_length_size = bytes_read;
-  cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
+  header->set_length (read_initial_length (abfd, info_ptr, &bytes_read));
+  header->initial_length_size = bytes_read;
+  header->offset_size = (bytes_read == 4) ? 4 : 8;
   info_ptr += bytes_read;
   unsigned version = read_2_bytes (abfd, info_ptr);
   if (version < 2 || version > 5)
     error (_(DWARF_ERROR_PREFIX
-	     "wrong version in compilation unit header "
+	     "wrong version in unit header "
 	     "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
 	   version, filename);
-  cu_header->version = version;
+  header->version = version;
   info_ptr += 2;
-  if (cu_header->version < 5)
+  if (header->version < 5)
     switch (section_kind)
       {
-      case rcuh_kind::COMPILE:
-	cu_header->unit_type = DW_UT_compile;
+      case ruh_kind::COMPILE:
+	header->unit_type = DW_UT_compile;
 	break;
-      case rcuh_kind::TYPE:
-	cu_header->unit_type = DW_UT_type;
+      case ruh_kind::TYPE:
+	header->unit_type = DW_UT_type;
 	break;
       default:
-	internal_error (_("read_comp_unit_head: invalid section_kind"));
+	internal_error (_("read_unit_head: invalid section_kind"));
       }
   else
     {
-      cu_header->unit_type = static_cast<enum dwarf_unit_type>
-						 (read_1_byte (abfd, info_ptr));
+      header->unit_type
+	= static_cast<enum dwarf_unit_type> (read_1_byte (abfd, info_ptr));
       info_ptr += 1;
-      switch (cu_header->unit_type)
+      switch (header->unit_type)
 	{
 	case DW_UT_compile:
 	case DW_UT_partial:
 	case DW_UT_skeleton:
 	case DW_UT_split_compile:
-	  if (section_kind != rcuh_kind::COMPILE)
+	  if (section_kind != ruh_kind::COMPILE)
 	    error (_(DWARF_ERROR_PREFIX
-		     "wrong unit_type in compilation unit header "
+		     "wrong unit_type in unit header "
 		     "(is %s, should be %s) [in module %s]"),
-		   dwarf_unit_type_name (cu_header->unit_type),
+		   dwarf_unit_type_name (header->unit_type),
 		   dwarf_unit_type_name (DW_UT_type), filename);
 	  break;
 	case DW_UT_type:
 	case DW_UT_split_type:
-	  section_kind = rcuh_kind::TYPE;
+	  section_kind = ruh_kind::TYPE;
 	  break;
 	default:
 	  error (_(DWARF_ERROR_PREFIX
-		   "wrong unit_type in compilation unit header "
+		   "wrong unit_type in unit header "
 		   "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
 		   "[in module %s]"),
-		 cu_header->unit_type, dwarf_unit_type_name (DW_UT_compile),
+		 header->unit_type, dwarf_unit_type_name (DW_UT_compile),
 		 dwarf_unit_type_name (DW_UT_skeleton),
 		 dwarf_unit_type_name (DW_UT_split_compile),
 		 dwarf_unit_type_name (DW_UT_type),
 		 dwarf_unit_type_name (DW_UT_split_type), filename);
 	}
 
-      cu_header->addr_size = read_1_byte (abfd, info_ptr);
+      header->addr_size = read_1_byte (abfd, info_ptr);
       info_ptr += 1;
     }
-  cu_header->abbrev_sect_off
-    = (sect_offset) cu_header->read_offset (abfd, info_ptr, &bytes_read);
+  header->abbrev_sect_off
+    = (sect_offset) header->read_offset (abfd, info_ptr, &bytes_read);
   info_ptr += bytes_read;
-  if (cu_header->version < 5)
+  if (header->version < 5)
     {
-      cu_header->addr_size = read_1_byte (abfd, info_ptr);
+      header->addr_size = read_1_byte (abfd, info_ptr);
       info_ptr += 1;
     }
   signed_addr = bfd_get_sign_extend_vma (abfd);
   if (signed_addr < 0)
-    internal_error (_("read_comp_unit_head: dwarf from non elf file"));
-  cu_header->signed_addr_p = signed_addr;
+    internal_error (_("read_unit_head: dwarf from non elf file"));
+  header->signed_addr_p = signed_addr;
 
-  bool header_has_signature = section_kind == rcuh_kind::TYPE
-    || cu_header->unit_type == DW_UT_skeleton
-    || cu_header->unit_type == DW_UT_split_compile;
+  bool header_has_signature =
+    (section_kind == ruh_kind::TYPE
+     || header->unit_type == DW_UT_skeleton
+     || header->unit_type == DW_UT_split_compile);
 
   if (header_has_signature)
     {
-      cu_header->signature = read_8_bytes (abfd, info_ptr);
+      header->signature = read_8_bytes (abfd, info_ptr);
       info_ptr += 8;
     }
 
-  if (section_kind == rcuh_kind::TYPE)
+  if (section_kind == ruh_kind::TYPE)
     {
       LONGEST type_offset;
-      type_offset = cu_header->read_offset (abfd, info_ptr, &bytes_read);
+      type_offset = header->read_offset (abfd, info_ptr, &bytes_read);
       info_ptr += bytes_read;
-      cu_header->type_cu_offset_in_tu = (cu_offset) type_offset;
-      if (to_underlying (cu_header->type_cu_offset_in_tu) != type_offset)
+      header->type_offset_in_tu = (cu_offset) type_offset;
+      if (to_underlying (header->type_offset_in_tu) != type_offset)
 	error (_(DWARF_ERROR_PREFIX
-		 "Too big type_offset in compilation unit "
+		 "Too big type_offset in unit "
 		 "header (is %s) [in module %s]"),
 	       plongest (type_offset), filename);
     }
@@ -144,64 +143,59 @@  read_comp_unit_head (struct comp_unit_head *cu_header,
   return info_ptr;
 }
 
-/* Subroutine of read_and_check_comp_unit_head and
-   read_and_check_type_unit_head to simplify them.
+/* Subroutine of read_and_check_unit_head to to simplify it.
    Perform various error checking on the header.  */
 
 static void
-error_check_comp_unit_head (dwarf2_per_objfile *per_objfile,
-			    struct comp_unit_head *header,
-			    struct dwarf2_section_info *section,
-			    struct dwarf2_section_info *abbrev_section)
+error_check_unit_head (dwarf2_per_objfile *per_objfile, unit_head *header,
+		       dwarf2_section_info *section,
+		       dwarf2_section_info *abbrev_section)
 {
   const char *filename = section->get_file_name ();
 
   if (to_underlying (header->abbrev_sect_off)
       >= abbrev_section->get_size (per_objfile->objfile))
     error (_(DWARF_ERROR_PREFIX
-	     "bad offset (%s) in compilation unit header "
+	     "bad offset (%s) in unit header "
 	     "(offset %s + 6) [in module %s]"),
 	   sect_offset_str (header->abbrev_sect_off),
-	   sect_offset_str (header->sect_off),
-	   filename);
+	   sect_offset_str (header->sect_off), filename);
 
   /* Cast to ULONGEST to use 64-bit arithmetic when possible to
      avoid potential 32-bit overflow.  */
   if (((ULONGEST) header->sect_off + header->get_length_with_initial ())
       > section->size)
     error (_(DWARF_ERROR_PREFIX
-	     "bad length (0x%x) in compilation unit header "
+	     "bad length (0x%x) in unit header "
 	     "(offset %s + 0) [in module %s]"),
 	   header->get_length_without_initial (), sect_offset_str (header->sect_off),
 	   filename);
 }
 
-/* See comp-unit-head.h.  */
+/* See unit-head.h.  */
 
 const gdb_byte *
-read_and_check_comp_unit_head (dwarf2_per_objfile *per_objfile,
-			       struct comp_unit_head *header,
-			       struct dwarf2_section_info *section,
-			       struct dwarf2_section_info *abbrev_section,
-			       const gdb_byte *info_ptr,
-			       rcuh_kind section_kind)
+read_and_check_unit_head (dwarf2_per_objfile *per_objfile, unit_head *header,
+			  dwarf2_section_info *section,
+			  dwarf2_section_info *abbrev_section,
+			  const gdb_byte *info_ptr, ruh_kind section_kind)
 {
-  const gdb_byte *beg_of_comp_unit = info_ptr;
+  const gdb_byte *beg_of_unit = info_ptr;
 
-  header->sect_off = (sect_offset) (beg_of_comp_unit - section->buffer);
+  header->sect_off = (sect_offset) (beg_of_unit - section->buffer);
 
-  info_ptr = read_comp_unit_head (header, info_ptr, section, section_kind);
+  info_ptr = read_unit_head (header, info_ptr, section, section_kind);
 
-  header->first_die_cu_offset = (cu_offset) (info_ptr - beg_of_comp_unit);
+  header->first_die_offset_in_unit = (cu_offset) (info_ptr - beg_of_unit);
 
-  error_check_comp_unit_head (per_objfile, header, section, abbrev_section);
+  error_check_unit_head (per_objfile, header, section, abbrev_section);
 
   return info_ptr;
 }
 
 unrelocated_addr
-comp_unit_head::read_address (bfd *abfd, const gdb_byte *buf,
-			      unsigned int *bytes_read) const
+unit_head::read_address (bfd *abfd, const gdb_byte *buf,
+			 unsigned int *bytes_read) const
 {
   ULONGEST retval = 0;
 
diff --git a/gdb/dwarf2/comp-unit-head.h b/gdb/dwarf2/unit-head.h
similarity index 64%
rename from gdb/dwarf2/comp-unit-head.h
rename to gdb/dwarf2/unit-head.h
index 513489394d99..c0c5c5fbb581 100644
--- a/gdb/dwarf2/comp-unit-head.h
+++ b/gdb/dwarf2/unit-head.h
@@ -24,18 +24,19 @@ 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#ifndef GDB_DWARF2_COMP_UNIT_HEAD_H
-#define GDB_DWARF2_COMP_UNIT_HEAD_H
+#ifndef GDB_DWARF2_UNIT_HEAD_H
+#define GDB_DWARF2_UNIT_HEAD_H
 
 #include "dwarf2.h"
 #include "dwarf2/leb.h"
 #include "dwarf2/types.h"
 
 struct dwarf2_per_objfile;
+struct dwarf2_section_info;
 
-/* The data in a compilation unit header, after target2host
-   translation, looks like this.  */
-struct comp_unit_head
+/* The data in a unit header, after target2host translation, looks like
+   this.  */
+struct unit_head
 {
 private:
   unsigned int m_length = 0;
@@ -53,16 +54,16 @@  struct comp_unit_head
 
   enum dwarf_unit_type unit_type {};
 
-  /* Offset to first die in this cu from the start of the cu.
-     This will be the first byte following the compilation unit header.  */
-  cu_offset first_die_cu_offset {};
+  /* Offset to first die in this unit from the start of the unit.
+     This will be the first byte following the unit header.  */
+  cu_offset first_die_offset_in_unit {};
 
-  /* Offset to the first byte of this compilation unit header in the
-     .debug_info section, for resolving relative reference dies.  */
+  /* Offset to the first byte of this unit header in the containing section,
+     for resolving relative reference dies.  */
   sect_offset sect_off {};
 
   /* For types, offset in the type's DIE of the type defined by this TU.  */
-  cu_offset type_cu_offset_in_tu {};
+  cu_offset type_offset_in_tu {};
 
   /* 64-bit signature of this unit. For type units, it denotes the signature of
      the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
@@ -75,22 +76,22 @@  struct comp_unit_head
     m_length = length;
   }
 
-  /* Return the total length of the CU described by this header, including the
+  /* Return the total length of the unit described by this header, including the
      initial length field.  */
   unsigned int get_length_with_initial () const
   {
     return m_length + initial_length_size;
   }
 
-  /* Return the total length of the CU described by this header, excluding the
+  /* Return the total length of the unit described by this header, excluding the
      initial length field.  */
   unsigned int get_length_without_initial () const
   {
     return m_length;
   }
 
-  /* Return TRUE if OFF is within this CU.  */
-  bool offset_in_cu_p (sect_offset off) const
+  /* Return TRUE if OFF is within this unit.  */
+  bool offset_in_unit_p (sect_offset off) const
   {
     sect_offset bottom = sect_off;
     sect_offset top = sect_off + get_length_with_initial ();
@@ -98,7 +99,7 @@  struct comp_unit_head
   }
 
   /* Read an offset from the data stream.  The size of the offset is
-     given by cu_header->offset_size.  */
+     given by unit_head::offset_size.  */
   LONGEST read_offset (bfd *abfd, const gdb_byte *buf,
 		       unsigned int *bytes_read) const
   {
@@ -112,28 +113,24 @@  struct comp_unit_head
 				 unsigned int *bytes_read) const;
 };
 
-/* Expected enum dwarf_unit_type for read_comp_unit_head.  */
-enum class rcuh_kind { COMPILE, TYPE };
+/* Expected enum dwarf_unit_type for read_unit_head.  */
+enum class ruh_kind { COMPILE, TYPE };
 
-/* Read in the comp unit header information from the debug_info at info_ptr.
-   Use rcuh_kind::COMPILE as the default type if not known by the caller.
-   NOTE: This leaves members offset, first_die_offset to be filled in
+/* Read in the unit header information from the debug_info at info_ptr.
+   Use ruh_kind::COMPILE as the default type if not known by the caller.
+   NOTE: This leaves members sect_off, first_die_unit_offset to be filled in
    by the caller.  */
-extern const gdb_byte *read_comp_unit_head
-  (struct comp_unit_head *cu_header,
-   const gdb_byte *info_ptr,
-   struct dwarf2_section_info *section,
-   rcuh_kind section_kind);
+extern const gdb_byte *read_unit_head (unit_head *header,
+				       const gdb_byte *info_ptr,
+				       dwarf2_section_info *section,
+				       ruh_kind section_kind);
 
-/* Read in a CU/TU header and perform some basic error checking.
+/* Read in a unit header and perform some basic error checking.
    The contents of the header are stored in HEADER.
    The result is a pointer to the start of the first DIE.  */
-extern const gdb_byte *read_and_check_comp_unit_head
-  (dwarf2_per_objfile *per_objfile,
-   struct comp_unit_head *header,
-   struct dwarf2_section_info *section,
-   struct dwarf2_section_info *abbrev_section,
-   const gdb_byte *info_ptr,
-   rcuh_kind section_kind);
-
-#endif /* GDB_DWARF2_COMP_UNIT_HEAD_H */
+extern const gdb_byte *read_and_check_unit_head
+  (dwarf2_per_objfile *per_objfile, unit_head *header,
+   dwarf2_section_info *section, dwarf2_section_info *abbrev_section,
+   const gdb_byte *info_ptr, ruh_kind section_kind);
+
+#endif /* GDB_DWARF2_UNIT_HEAD_H */
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-error.exp b/gdb/testsuite/gdb.dwarf2/dw2-error.exp
index f1c861715516..0701ec633704 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-error.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-error.exp
@@ -37,7 +37,7 @@  set host_binfile [gdb_remote_download host $binfile]
 
 # First test that reading symbols fails.
 gdb_test "file $host_binfile" \
-    {Reading symbols.*DWARF Error: wrong version in compilation unit header \(is 153, should be 2, 3, 4 or 5\).*} \
+    {Reading symbols.*DWARF Error: wrong version in unit header \(is 153, should be 2, 3, 4 or 5\).*} \
     "file $testfile"
 
 # We can't use proc readnow, because the PR makes it return 0.