diff mbox

[29/38] Add some methods to dwarf2_per_cu_data

Message ID 20200123005710.7978-30-tom@tromey.com
State New
Headers show

Commit Message

Tom Tromey Jan. 23, 2020, 12:57 a.m. UTC
This changes a few helper functions to be methods on
dwarf2_per_cu_data.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/loc.c (dwarf2_find_location_expression)
	(dwarf_evaluate_loc_desc::get_tls_address)
	(dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value)
	(rw_pieced_value, dwarf2_evaluate_loc_desc_full)
	(dwarf2_locexpr_baton_eval, dwarf2_evaluate_property)
	(dwarf2_compile_property_to_c)
	(dwarf2_loc_desc_get_symbol_read_needs)
	(dwarf2_compile_expr_to_ax, locexpr_describe_location)
	(locexpr_tracepoint_var_ref, locexpr_generate_c_location)
	(loclist_describe_location, loclist_tracepoint_var_ref)
	(loclist_generate_c_location): Update.
	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update.
	* dwarf2/loc.h (dwarf2_per_cu_objfile, dwarf2_per_cu_addr_size)
	(dwarf2_per_cu_ref_addr_size, dwarf2_per_cu_offset_size)
	(dwarf2_per_cu_text_offset, dwarf2_version): Don't declare.
	* dwarf2/read.c (dwarf2_per_cu_data::objfile)
	(dwarf2_per_cu_data::addr_size)
	(dwarf2_per_cu_data::ref_addr_size)
	(dwarf2_per_cu_data::text_offset)
	(dwarf2_per_cu_data::addr_type): Now methods.
	(per_cu_header_read_in): Make per_cu "const".
	(dwarf2_version): Remove.
	(dwarf2_per_cu_data::int_type): Now a method.
	(dwarf2_per_cu_data::_addr_sized_int_type): Likewise.
	(set_die_type, read_array_type, read_subrange_index_type)
	(read_tag_string_type, read_subrange_type): Update.
	* dwarf2/read.h (struct dwarf2_per_cu_data) <addr_size,
	offset_size, ref_addr_size, text_offset, addr_type, version,
	objfile, int_type, addr_sized_int_type>: Declare methods.

Change-Id: I07a42fa26e00795352389fa7a0cc1c12997d26f7
---
 gdb/ChangeLog               |  32 ++++++++++
 gdb/compile/compile-loc2c.c |   3 +-
 gdb/dwarf2/loc.c            |  73 +++++++++++------------
 gdb/dwarf2/loc.h            |  23 --------
 gdb/dwarf2/read.c           | 115 +++++++++++++-----------------------
 gdb/dwarf2/read.h           |  43 ++++++++++++++
 6 files changed, 155 insertions(+), 134 deletions(-)
diff mbox

Patch

diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index 636c929b022..06a044de048 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -21,6 +21,7 @@ 
 #include "dwarf2.h"
 #include "dwarf2/expr.h"
 #include "dwarf2/loc.h"
+#include "dwarf2/read.h"
 #include "ui-file.h"
 #include "utils.h"
 #include "compile-internal.h"
@@ -718,7 +719,7 @@  do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 	     index, not an address.  We don't support things like
 	     branching between the address and the TLS op.  */
 	  if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
-	    uoffset += dwarf2_per_cu_text_offset (per_cu);
+	    uoffset += per_cu->text_offset ();
 	  push (indent, stream, uoffset);
 	  break;
 
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index e337a02d473..ad13e8920ff 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -312,13 +312,13 @@  const gdb_byte *
 dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 				 size_t *locexpr_length, CORE_ADDR pc)
 {
-  struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
+  struct objfile *objfile = baton->per_cu->objfile ();
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu);
+  unsigned int addr_size = baton->per_cu->addr_size ();
   int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
   /* Adjust base_address for relocatable objects.  */
-  CORE_ADDR base_offset = dwarf2_per_cu_text_offset (baton->per_cu);
+  CORE_ADDR base_offset = baton->per_cu->text_offset ();
   CORE_ADDR base_address = baton->base_address + base_offset;
   const gdb_byte *loc_ptr, *buf_end;
 
@@ -336,7 +336,7 @@  dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 	kind = decode_debug_loc_dwo_addresses (baton->per_cu,
 					       loc_ptr, buf_end, &new_ptr,
 					       &low, &high, byte_order);
-      else if (dwarf2_version (baton->per_cu) < 5)
+      else if (baton->per_cu->version () < 5)
 	kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr,
 					   &low, &high,
 					   byte_order, addr_size,
@@ -382,7 +382,7 @@  dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 	  high += base_address;
 	}
 
-      if (dwarf2_version (baton->per_cu) < 5)
+      if (baton->per_cu->version () < 5)
 	{
 	  length = extract_unsigned_integer (loc_ptr, 2, byte_order);
 	  loc_ptr += 2;
@@ -643,7 +643,7 @@  class dwarf_evaluate_loc_desc : public dwarf_expr_context
      current thread's thread-local storage with offset OFFSET.  */
   CORE_ADDR get_tls_address (CORE_ADDR offset) override
   {
-    struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
+    struct objfile *objfile = per_cu->objfile ();
 
     return target_translate_tls_address (objfile, offset);
   }
@@ -730,12 +730,11 @@  class dwarf_evaluate_loc_desc : public dwarf_expr_context
 							(CORE_ADDR) 0);
 
     scoped_restore save_arch = make_scoped_restore (&this->gdbarch);
-    this->gdbarch
-      = get_objfile_arch (dwarf2_per_cu_objfile (per_cu));
+    this->gdbarch = get_objfile_arch (per_cu->objfile ());
     scoped_restore save_addr_size = make_scoped_restore (&this->addr_size);
-    this->addr_size = dwarf2_per_cu_addr_size (per_cu);
+    this->addr_size = per_cu->addr_size ();
     scoped_restore save_offset = make_scoped_restore (&this->offset);
-    this->offset = dwarf2_per_cu_text_offset (per_cu);
+    this->offset = per_cu->text_offset ();
 
     this->eval (data_src, size);
   }
@@ -1819,7 +1818,7 @@  rw_pieced_value (struct value *v, struct value *from)
 		break;
 	      }
 
-	    struct objfile *objfile = dwarf2_per_cu_objfile (c->per_cu);
+	    struct objfile *objfile = c->per_cu->objfile ();
 	    struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
 	    ULONGEST stack_value_size_bits
 	      = 8 * TYPE_LENGTH (value_type (p->v.value));
@@ -2176,7 +2175,7 @@  dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 			       LONGEST subobj_byte_offset)
 {
   struct value *retval;
-  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
+  struct objfile *objfile = per_cu->objfile ();
 
   if (subobj_type == NULL)
     {
@@ -2197,9 +2196,9 @@  dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
   scoped_value_mark free_values;
 
   ctx.gdbarch = get_objfile_arch (objfile);
-  ctx.addr_size = dwarf2_per_cu_addr_size (per_cu);
-  ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
-  ctx.offset = dwarf2_per_cu_text_offset (per_cu);
+  ctx.addr_size = per_cu->addr_size ();
+  ctx.ref_addr_size = per_cu->ref_addr_size ();
+  ctx.offset = per_cu->text_offset ();
 
   try
     {
@@ -2411,12 +2410,12 @@  dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
   ctx.per_cu = dlbaton->per_cu;
   ctx.obj_address = addr;
 
-  objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
+  objfile = dlbaton->per_cu->objfile ();
 
   ctx.gdbarch = get_objfile_arch (objfile);
-  ctx.addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
-  ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (dlbaton->per_cu);
-  ctx.offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
+  ctx.addr_size = dlbaton->per_cu->addr_size ();
+  ctx.ref_addr_size = dlbaton->per_cu->ref_addr_size ();
+  ctx.offset = dlbaton->per_cu->text_offset ();
 
   try
     {
@@ -2504,7 +2503,7 @@  dwarf2_evaluate_property (const struct dynamic_prop *prop,
 		       CORE_ADDR on 64bit machine has 8 bytes but address
 		       size of an 32bit application is bytes.  */
 		    const int addr_size
-		      = (dwarf2_per_cu_addr_size (baton->locexpr.per_cu)
+		      = (baton->locexpr.per_cu->addr_size ()
 			 * TARGET_CHAR_BIT);
 		    const CORE_ADDR neg_mask
 		      = (~((CORE_ADDR) 0) <<  (addr_size - 1));
@@ -2610,7 +2609,7 @@  dwarf2_compile_property_to_c (string_file *stream,
 
   compile_dwarf_bounds_to_c (stream, result_name, prop, sym, pc,
 			     gdbarch, registers_used,
-			     dwarf2_per_cu_addr_size (per_cu),
+			     per_cu->addr_size (),
 			     data, data + size, per_cu);
 }
 
@@ -2732,7 +2731,7 @@  dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size,
 				       struct dwarf2_per_cu_data *per_cu)
 {
   int in_reg;
-  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
+  struct objfile *objfile = per_cu->objfile ();
 
   scoped_value_mark free_values;
 
@@ -2741,9 +2740,9 @@  dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size,
   ctx.needs = SYMBOL_NEEDS_NONE;
   ctx.per_cu = per_cu;
   ctx.gdbarch = get_objfile_arch (objfile);
-  ctx.addr_size = dwarf2_per_cu_addr_size (per_cu);
-  ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
-  ctx.offset = dwarf2_per_cu_text_offset (per_cu);
+  ctx.addr_size = per_cu->addr_size ();
+  ctx.ref_addr_size = per_cu->ref_addr_size ();
+  ctx.offset = per_cu->text_offset ();
 
   ctx.eval (data, size);
 
@@ -2984,7 +2983,7 @@  dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	     index, not an address.  We don't support things like
 	     branching between the address and the TLS op.  */
 	  if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
-	    uoffset += dwarf2_per_cu_text_offset (per_cu);
+	    uoffset += per_cu->text_offset ();
 	  ax_const_l (expr, uoffset);
 	  break;
 
@@ -4292,9 +4291,9 @@  locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr,
 {
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
-  struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
-  int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
+  struct objfile *objfile = dlbaton->per_cu->objfile ();
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
+  int offset_size = dlbaton->per_cu->offset_size ();
 
   locexpr_describe_location_1 (symbol, addr, stream,
 			       dlbaton->data, dlbaton->size,
@@ -4311,7 +4310,7 @@  locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
 {
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
 
   if (dlbaton->size == 0)
     value->optimized_out = 1;
@@ -4330,7 +4329,7 @@  locexpr_generate_c_location (struct symbol *sym, string_file *stream,
 {
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (sym);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
 
   if (dlbaton->size == 0)
     error (_("symbol \"%s\" is optimized out"), sym->natural_name ());
@@ -4429,14 +4428,14 @@  loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
   struct dwarf2_loclist_baton *dlbaton
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
   const gdb_byte *loc_ptr, *buf_end;
-  struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
+  struct objfile *objfile = dlbaton->per_cu->objfile ();
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
-  int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
+  int offset_size = dlbaton->per_cu->offset_size ();
   int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
   /* Adjust base_address for relocatable objects.  */
-  CORE_ADDR base_offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
+  CORE_ADDR base_offset = dlbaton->per_cu->text_offset ();
   CORE_ADDR base_address = dlbaton->base_address + base_offset;
   int done = 0;
 
@@ -4520,7 +4519,7 @@  loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
   const gdb_byte *data;
   size_t size;
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
 
   data = dwarf2_find_location_expression (dlbaton, &size, ax->scope);
   if (size == 0)
@@ -4540,7 +4539,7 @@  loclist_generate_c_location (struct symbol *sym, string_file *stream,
 {
   struct dwarf2_loclist_baton *dlbaton
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (sym);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
   const gdb_byte *data;
   size_t size;
 
diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h
index a49a9903b11..2cc7e066a33 100644
--- a/gdb/dwarf2/loc.h
+++ b/gdb/dwarf2/loc.h
@@ -35,29 +35,6 @@  struct axs_value;
 /* `set debug entry-values' setting.  */
 extern unsigned int entry_values_debug;
 
-/* Return the OBJFILE associated with the compilation unit CU.  If CU
-   came from a separate debuginfo file, then the master objfile is
-   returned.  */
-struct objfile *dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *cu);
-
-/* Return the address size given in the compilation unit header for CU.  */
-int dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *cu);
-
-/* Return the DW_FORM_ref_addr size given in the compilation unit header for
-   CU.  */
-int dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *cu);
-
-/* Return the offset size given in the compilation unit header for CU.  */
-int dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *cu);
-
-/* Return the text offset of the CU.  The returned offset comes from
-   this CU's objfile.  If this objfile came from a separate debuginfo
-   file, then the offset may be different from the corresponding
-   offset in the parent objfile.  */
-CORE_ADDR dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *cu);
-
-short dwarf2_version (struct dwarf2_per_cu_data *per_cu);
-
 /* Find a particular location expression from a location list.  */
 const gdb_byte *dwarf2_find_location_expression
   (struct dwarf2_loclist_baton *baton,
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 6a9a1a95012..f0d39ddb7f8 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1644,13 +1644,6 @@  static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
 
 static void process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile);
 
-static struct type *dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data *per_cu);
-static struct type *dwarf2_per_cu_addr_sized_int_type
-	(struct dwarf2_per_cu_data *per_cu, bool unsigned_p);
-static struct type *dwarf2_per_cu_int_type
-	(struct dwarf2_per_cu_data *per_cu, int size_in_bytes,
-	 bool unsigned_p);
-
 /* Class, the destructor of which frees all allocated queue entries.  This
    will only have work to do if an error was thrown while processing the
    dwarf.  If no error was thrown then the queue entries should have all
@@ -13214,7 +13207,7 @@  read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       newobj->static_link
 	= XOBNEW (&objfile->objfile_obstack, struct dynamic_prop);
       attr_to_dynamic_prop (attr, die, cu, newobj->static_link,
-			    dwarf2_per_cu_addr_type (cu->per_cu));
+			    cu->per_cu->addr_type ());
     }
 
   cu->list_in_scope = cu->get_builder ()->get_local_symbols ();
@@ -16051,8 +16044,7 @@  read_array_type (struct die_info *die, struct dwarf2_cu *cu)
   if (attr != NULL)
     {
       int stride_ok;
-      struct type *prop_type
-	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+      struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
 
       byte_stride_prop
 	= (struct dynamic_prop *) alloca (sizeof (struct dynamic_prop));
@@ -16854,13 +16846,13 @@  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 = dwarf2_get_attr_constant_value (len, 0);
-	  prop_type = dwarf2_per_cu_int_type (cu->per_cu, sz, true);
+	  prop_type = cu->per_cu->int_type (sz, true);
 	}
       else
 	{
 	  /* If the size is not specified then we assume it is the size of
 	     an address on this target.  */
-	  prop_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, true);
+	  prop_type = cu->per_cu->addr_sized_int_type (true);
 	}
 
       /* Convert the attribute into a dynamic property.  */
@@ -17462,14 +17454,12 @@  attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
   return 1;
 }
 
-/* Find an integer type SIZE_IN_BYTES bytes in size and return it.
-   UNSIGNED_P controls if the integer is unsigned or not.  */
+/* See read.h.  */
 
-static struct type *
-dwarf2_per_cu_int_type (struct dwarf2_per_cu_data *per_cu,
-			int size_in_bytes, bool unsigned_p)
+struct type *
+dwarf2_per_cu_data::int_type (int size_in_bytes, bool unsigned_p) const
 {
-  struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct type *int_type;
 
   /* Helper macro to examine the various builtin types.  */
@@ -17491,16 +17481,13 @@  dwarf2_per_cu_int_type (struct dwarf2_per_cu_data *per_cu,
   gdb_assert_not_reached ("unable to find suitable integer type");
 }
 
-/* Find an integer type the same size as the address size given in the
-   compilation unit header for PER_CU.  UNSIGNED_P controls if the integer
-   is unsigned or not.  */
+/* See read.h.  */
 
-static struct type *
-dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data *per_cu,
-				   bool unsigned_p)
+struct type *
+dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p) const
 {
-  int addr_size = dwarf2_per_cu_addr_size (per_cu);
-  return dwarf2_per_cu_int_type (per_cu, addr_size, unsigned_p);
+  int addr_size = this->addr_size ();
+  return int_type (addr_size, unsigned_p);
 }
 
 /* Read the DW_AT_type attribute for a sub-range.  If this attribute is not
@@ -17525,7 +17512,7 @@  read_subrange_index_type (struct die_info *die, struct dwarf2_cu *cu)
      FIXME: muller/2010-05-28: Possible references to object for low bound,
      high bound or count are not yet handled by this code.  */
   if (TYPE_CODE (index_type) == TYPE_CODE_VOID)
-    index_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+    index_type = cu->per_cu->addr_sized_int_type (false);
 
   return index_type;
 }
@@ -17655,8 +17642,7 @@  read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   attribute *attr_byte_stride = dwarf2_attr (die, DW_AT_byte_stride, cu);
   if (attr_byte_stride != nullptr)
     {
-      struct type *prop_type
-	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+      struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
       attr_to_dynamic_prop (attr_byte_stride, die, cu, &byte_stride_prop,
 			    prop_type);
     }
@@ -17676,8 +17662,7 @@  read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 	}
       else
 	{
-	  struct type *prop_type
-	    = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+	  struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
 	  attr_to_dynamic_prop (attr_bit_stride, die, cu, &bit_stride_prop,
 				prop_type);
 	}
@@ -24566,14 +24551,12 @@  dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
     }
 }
 
-/* Return the OBJFILE associated with the compilation unit CU.  If CU
-   came from a separate debuginfo file, then the master objfile is
-   returned.  */
+/* See read.h.  */
 
 struct objfile *
-dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
+dwarf2_per_cu_data::objfile () const
 {
-  struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
 
   /* Return the master objfile, so that we can report and look up the
      correct file containing this variable.  */
@@ -24589,7 +24572,7 @@  dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
 
 static const struct comp_unit_head *
 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
-		       struct dwarf2_per_cu_data *per_cu)
+		       const struct dwarf2_per_cu_data *per_cu)
 {
   const gdb_byte *info_ptr;
 
@@ -24605,41 +24588,41 @@  per_cu_header_read_in (struct comp_unit_head *cu_headerp,
   return cu_headerp;
 }
 
-/* Return the address size given in the compilation unit header for CU.  */
+/* See read.h.  */
 
 int
-dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
+dwarf2_per_cu_data::addr_size () const
 {
   struct comp_unit_head cu_header_local;
   const struct comp_unit_head *cu_headerp;
 
-  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
+  cu_headerp = per_cu_header_read_in (&cu_header_local, this);
 
   return cu_headerp->addr_size;
 }
 
-/* Return the offset size given in the compilation unit header for CU.  */
+/* See read.h.  */
 
 int
-dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
+dwarf2_per_cu_data::offset_size () const
 {
   struct comp_unit_head cu_header_local;
   const struct comp_unit_head *cu_headerp;
 
-  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
+  cu_headerp = per_cu_header_read_in (&cu_header_local, this);
 
   return cu_headerp->offset_size;
 }
 
-/* See its dwarf2loc.h declaration.  */
+/* See read.h.  */
 
 int
-dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
+dwarf2_per_cu_data::ref_addr_size () const
 {
   struct comp_unit_head cu_header_local;
   const struct comp_unit_head *cu_headerp;
 
-  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
+  cu_headerp = per_cu_header_read_in (&cu_header_local, this);
 
   if (cu_headerp->version == 2)
     return cu_headerp->addr_size;
@@ -24647,45 +24630,33 @@  dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
     return cu_headerp->offset_size;
 }
 
-/* Return the text offset of the CU.  The returned offset comes from
-   this CU's objfile.  If this objfile came from a separate debuginfo
-   file, then the offset may be different from the corresponding
-   offset in the parent objfile.  */
+/* See read.h.  */
 
 CORE_ADDR
-dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
+dwarf2_per_cu_data::text_offset () const
 {
-  struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
 
   return objfile->section_offsets[SECT_OFF_TEXT (objfile)];
 }
 
-/* Return a type that is a generic pointer type, the size of which matches
-   the address size given in the compilation unit header for PER_CU.  */
-static struct type *
-dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data *per_cu)
+/* See read.h.  */
+
+struct type *
+dwarf2_per_cu_data::addr_type () const
 {
-  struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct type *void_type = objfile_type (objfile)->builtin_void;
   struct type *addr_type = lookup_pointer_type (void_type);
-  int addr_size = dwarf2_per_cu_addr_size (per_cu);
+  int addr_size = this->addr_size ();
 
   if (TYPE_LENGTH (addr_type) == addr_size)
     return addr_type;
 
-  addr_type
-    = dwarf2_per_cu_addr_sized_int_type (per_cu, TYPE_UNSIGNED (addr_type));
+  addr_type = addr_sized_int_type (TYPE_UNSIGNED (addr_type));
   return addr_type;
 }
 
-/* Return DWARF version number of PER_CU.  */
-
-short
-dwarf2_version (struct dwarf2_per_cu_data *per_cu)
-{
-  return per_cu->dwarf_version;
-}
-
 /* Locate the .debug_info compilation unit from CU's objfile which contains
    the DIE at OFFSET.  Raises an error on failure.  */
 
@@ -24944,8 +24915,7 @@  set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_allocated, cu);
   if (attr != NULL && attr->form_is_block ())
     {
-      struct type *prop_type
-	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+      struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
       if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
         add_dyn_prop (DYN_PROP_ALLOCATED, prop, type);
     }
@@ -24960,8 +24930,7 @@  set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_associated, cu);
   if (attr != NULL && attr->form_is_block ())
     {
-      struct type *prop_type
-	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+      struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
       if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
         add_dyn_prop (DYN_PROP_ASSOCIATED, prop, type);
     }
@@ -24975,7 +24944,7 @@  set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   /* Read DW_AT_data_location and set in type.  */
   attr = dwarf2_attr (die, DW_AT_data_location, cu);
   if (attr_to_dynamic_prop (attr, die, cu, &prop,
-			    dwarf2_per_cu_addr_type (cu->per_cu)))
+			    cu->per_cu->addr_type ()))
     add_dyn_prop (DYN_PROP_DATA_LOCATION, prop, type);
 
   if (dwarf2_per_objfile->die_type_hash == NULL)
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 646a53fadd2..4aa9c4b9029 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -373,6 +373,49 @@  struct dwarf2_per_cu_data
     delete imported_symtabs;
     imported_symtabs = nullptr;
   }
+
+  /* Return the OBJFILE associated with this compilation unit.  If
+     this compilation unit came from a separate debuginfo file, then
+     the master objfile is returned.  */
+  struct objfile *objfile () const;
+
+  /* Return the address size given in the compilation unit header for
+     this CU.  */
+  int addr_size () const;
+
+  /* Return the offset size given in the compilation unit header for
+     this CU.  */
+  int offset_size () const;
+
+  /* Return the DW_FORM_ref_addr size given in the compilation unit
+     header for this CU.  */
+  int ref_addr_size () const;
+
+  /* Return the text offset of the CU.  The returned offset comes from
+     this CU's objfile.  If this objfile came from a separate
+     debuginfo file, then the offset may be different from the
+     corresponding offset in the parent objfile.  */
+  CORE_ADDR text_offset () const;
+
+  /* Return a type that is a generic pointer type, the size of which
+     matches the address size given in the compilation unit header for
+     this CU.  */
+  struct type *addr_type () const;
+
+  /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
+     UNSIGNED_P controls if the integer is unsigned or not.  */
+  struct type *int_type (int size_in_bytes, bool unsigned_p) const;
+
+  /* Find an integer type the same size as the address size given in
+     the compilation unit header for this CU.  UNSIGNED_P controls if
+     the integer is unsigned or not.  */
+  struct type *addr_sized_int_type (bool unsigned_p) const;
+
+  /* Return DWARF version number of this CU.  */
+  short version () const
+  {
+    return dwarf_version;
+  }
 };
 
 /* Entry in the signatured_types hash table.  */