public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH v3 37/50] Turn many optimized-out value functions into methods
Date: Sun, 12 Feb 2023 20:15:53 -0700	[thread overview]
Message-ID: <20230209-submit-value-fixups-2023-v3-37-45e91a20c742@tromey.com> (raw)
In-Reply-To: <20230209-submit-value-fixups-2023-v3-0-45e91a20c742@tromey.com>

This turns many functions that are related to optimized-out or
availability-checking to be methods of value.  The static function
value_entirely_covered_by_range_vector is also converted to be a
private method.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
---
 gdb/aarch64-tdep.c                |   6 +-
 gdb/ada-lang.c                    |   2 +-
 gdb/ada-valprint.c                |   2 +-
 gdb/alpha-tdep.c                  |   4 +-
 gdb/amd64-tdep.c                  |  12 ++--
 gdb/c-valprint.c                  |   8 +--
 gdb/compile/compile-object-load.c |   4 +-
 gdb/cp-valprint.c                 |   2 +-
 gdb/d-valprint.c                  |   5 +-
 gdb/dwarf2/expr.c                 |  18 ++---
 gdb/dwarf2/loc.c                  |   8 +--
 gdb/f-valprint.c                  |  16 ++---
 gdb/findvar.c                     |   6 +-
 gdb/frame.c                       |  22 +++---
 gdb/gnu-v2-abi.c                  |   4 +-
 gdb/guile/scm-pretty-print.c      |   2 +-
 gdb/guile/scm-value.c             |   2 +-
 gdb/i386-tdep.c                   |  34 +++++-----
 gdb/i387-tdep.c                   |   2 +-
 gdb/infcmd.c                      |   4 +-
 gdb/infrun.c                      |   2 +-
 gdb/mi/mi-cmd-stack.c             |   7 +-
 gdb/mi/mi-main.c                  |   2 +-
 gdb/mips-tdep.c                   |   4 +-
 gdb/p-valprint.c                  |   2 +-
 gdb/printcmd.c                    |   4 +-
 gdb/python/py-prettyprint.c       |   2 +-
 gdb/python/py-value.c             |   2 +-
 gdb/regcache.c                    |   6 +-
 gdb/riscv-tdep.c                  |   4 +-
 gdb/s390-tdep.c                   |   6 +-
 gdb/stack.c                       |  10 +--
 gdb/valarith.c                    |   4 +-
 gdb/valops.c                      |   6 +-
 gdb/valprint.c                    |  25 ++++---
 gdb/value.c                       | 136 +++++++++++++++-----------------------
 gdb/value.h                       | 124 +++++++++++++++++-----------------
 37 files changed, 237 insertions(+), 272 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 0aaa746760e..a4f71f246c6 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -2766,8 +2766,8 @@ aarch64_pseudo_read_value_1 (struct gdbarch *gdbarch,
   gdb_static_assert (AARCH64_V0_REGNUM == AARCH64_SVE_Z0_REGNUM);
 
   if (regcache->raw_read (v_regnum, reg_buf) != REG_VALID)
-    mark_value_bytes_unavailable (result_value, 0,
-				  result_value->type ()->length ());
+    result_value->mark_bytes_unavailable (0,
+					  result_value->type ()->length ());
   else
     memcpy (result_value->contents_raw ().data (), reg_buf, regsize);
 
@@ -2801,7 +2801,7 @@ aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache,
 
       /* Read the bottom 4 bytes of X.  */
       if (regcache->raw_read_part (x_regnum, offset, 4, data) != REG_VALID)
-	mark_value_bytes_unavailable (result_value, 0, 4);
+	result_value->mark_bytes_unavailable (0, 4);
       else
 	memcpy (result_value->contents_raw ().data (), data, 4);
 
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e2aa4041263..1b0dc2291d0 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -555,7 +555,7 @@ coerce_unspec_val_to_type (struct value *val, struct type *type)
     {
       struct value *result;
 
-      if (value_optimized_out (val))
+      if (val->optimized_out ())
 	result = value::allocate_optimized_out (type);
       else if (val->lazy ()
 	       /* Be careful not to make a lazy not_lval value.  */
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 16e865c5de6..02ae46bce9e 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -918,7 +918,7 @@ ada_value_print_array (struct value *val, struct ui_file *stream, int recurse,
   gdb_printf (stream, "(");
   print_optional_low_bound (stream, type, options);
 
-  if (value_entirely_optimized_out (val))
+  if (val->entirely_optimized_out ())
     val_print_optimized_out (val, stream);
   else if (TYPE_FIELD_BITSIZE (type, 0) > 0)
     {
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
index 0d51ff73b3d..9fb973597fc 100644
--- a/gdb/alpha-tdep.c
+++ b/gdb/alpha-tdep.c
@@ -241,8 +241,8 @@ alpha_register_to_value (frame_info_ptr frame, int regnum,
   struct value *value = get_frame_register_value (frame, regnum);
 
   gdb_assert (value != NULL);
-  *optimizedp = value_optimized_out (value);
-  *unavailablep = !value_entirely_available (value);
+  *optimizedp = value->optimized_out ();
+  *unavailablep = !value->entirely_available ();
 
   if (*optimizedp || *unavailablep)
     {
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 9c4a90287bc..38440639565 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -375,8 +375,8 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
 	  if (status == REG_VALID)
 	    memcpy (buf, raw_buf + 1, 1);
 	  else
-	    mark_value_bytes_unavailable (result_value, 0,
-					  result_value->type ()->length ());
+	    result_value->mark_bytes_unavailable (0,
+						  result_value->type ()->length ());
 	}
       else
 	{
@@ -385,8 +385,8 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
 	  if (status == REG_VALID)
 	    memcpy (buf, raw_buf, 1);
 	  else
-	    mark_value_bytes_unavailable (result_value, 0,
-					  result_value->type ()->length ());
+	    result_value->mark_bytes_unavailable (0,
+						  result_value->type ()->length ());
 	}
     }
   else if (i386_dword_regnum_p (gdbarch, regnum))
@@ -398,8 +398,8 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
       if (status == REG_VALID)
 	memcpy (buf, raw_buf, 4);
       else
-	mark_value_bytes_unavailable (result_value, 0,
-				      result_value->type ()->length ());
+	result_value->mark_bytes_unavailable (0,
+					      result_value->type ()->length ());
     }
   else
     i386_pseudo_register_read_into_value (gdbarch, regcache, regnum,
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 55ba02996f3..34a9d0f6075 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -257,9 +257,9 @@ c_value_print_array (struct value *val,
 	 long as the entire array is valid.  */
       if (c_textual_element_type (unresolved_elttype,
 				  options->format)
-	  && value_bytes_available (val, 0, type->length ())
-	  && !value_bits_any_optimized_out (val, 0,
-					    TARGET_CHAR_BIT * type->length ()))
+	  && val->bytes_available (0, type->length ())
+	  && !val->bits_any_optimized_out (0,
+					   TARGET_CHAR_BIT * type->length ()))
 	{
 	  int force_ellipses = 0;
 
@@ -520,7 +520,7 @@ c_value_print (struct value *val, struct ui_file *stream,
 	  /* Pointer to class, check real type of object.  */
 	  gdb_printf (stream, "(");
 
-	  if (value_entirely_available (val))
+	  if (val->entirely_available ())
 	    {
 	      real_type = value_rtti_indirect_type (val, &full, &top,
 						    &using_enc);
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index af4f6e2c2ef..12939b19e09 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -578,9 +578,9 @@ store_regs (struct type *regs_type, CORE_ADDR regs_base)
       regnum = compile_register_name_demangle (gdbarch, reg_name);
 
       regval = value_from_register (reg_type, regnum, get_current_frame ());
-      if (value_optimized_out (regval))
+      if (regval->optimized_out ())
 	error (_("Register \"%s\" is optimized out."), reg_name);
-      if (!value_entirely_available (regval))
+      if (!regval->entirely_available ())
 	error (_("Register \"%s\" is not available."), reg_name);
 
       inferior_addr = regs_base + reg_offset;
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 687be9d4bd6..37147749619 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -550,7 +550,7 @@ cp_print_static_field (struct type *type,
 {
   struct value_print_options opts;
 
-  if (value_entirely_optimized_out (val))
+  if (val->entirely_optimized_out ())
     {
       val_print_optimized_out (val, stream);
       return;
diff --git a/gdb/d-valprint.c b/gdb/d-valprint.c
index b5e981874c1..38fb2a07c1f 100644
--- a/gdb/d-valprint.c
+++ b/gdb/d-valprint.c
@@ -38,9 +38,8 @@ dynamic_array_type (struct type *type,
       && type->field (0).type ()->code () == TYPE_CODE_INT
       && strcmp (type->field (0).name (), "length") == 0
       && strcmp (type->field (1).name (), "ptr") == 0
-      && !value_bits_any_optimized_out (val,
-					TARGET_CHAR_BIT * embedded_offset,
-					TARGET_CHAR_BIT * type->length ()))
+      && !val->bits_any_optimized_out (TARGET_CHAR_BIT * embedded_offset,
+				       TARGET_CHAR_BIT * type->length ()))
     {
       CORE_ADDR addr;
       struct type *elttype;
diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index a1119e16c23..45bdb007420 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -233,12 +233,12 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
 		      {
 			if (check_optimized)
 			  return true;
-			mark_value_bits_optimized_out (v, offset,
-						       this_size_bits);
+			v->mark_bits_optimized_out (offset,
+						    this_size_bits);
 		      }
 		    if (unavail && !check_optimized)
-		      mark_value_bits_unavailable (v, offset,
-						   this_size_bits);
+		      v->mark_bits_unavailable (offset,
+						this_size_bits);
 		    break;
 		  }
 
@@ -358,7 +358,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
 
 	    if (from != nullptr)
 	      {
-		mark_value_bits_optimized_out (v, offset, this_size_bits);
+		v->mark_bits_optimized_out (offset, this_size_bits);
 		break;
 	      }
 
@@ -390,7 +390,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
 
 	    if (from != nullptr)
 	      {
-		mark_value_bits_optimized_out (v, offset, this_size_bits);
+		v->mark_bits_optimized_out (offset, this_size_bits);
 		break;
 	      }
 
@@ -413,7 +413,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
 	case DWARF_VALUE_IMPLICIT_POINTER:
 	    if (from != nullptr)
 	      {
-		mark_value_bits_optimized_out (v, offset, this_size_bits);
+		v->mark_bits_optimized_out (offset, this_size_bits);
 		break;
 	      }
 
@@ -424,7 +424,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
 	case DWARF_VALUE_OPTIMIZED_OUT:
 	  if (check_optimized)
 	    return true;
-	  mark_value_bits_optimized_out (v, offset, this_size_bits);
+	  v->mark_bits_optimized_out (offset, this_size_bits);
 	  break;
 
 	default:
@@ -960,7 +960,7 @@ dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type,
 
 	    retval = value_from_register (subobj_type, gdb_regnum,
 					  this->m_frame);
-	    if (value_optimized_out (retval))
+	    if (retval->optimized_out ())
 	      {
 		/* This means the register has undefined value / was
 		   not saved.  As we're computing the location of some
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index f9706a0bc05..616db13488b 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -1515,8 +1515,8 @@ dwarf2_evaluate_loc_desc_full (struct type *type, frame_info_ptr frame,
 	{
 	  free_values.free_to_mark ();
 	  retval = value::allocate (subobj_type);
-	  mark_value_bytes_unavailable (retval, 0,
-					subobj_type->length ());
+	  retval->mark_bytes_unavailable (0,
+					  subobj_type->length ());
 	  return retval;
 	}
       else if (ex.error == NO_ENTRY_VALUE_ERROR)
@@ -1609,7 +1609,7 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
 	throw;
     }
 
-  if (value_optimized_out (result))
+  if (result->optimized_out ())
     return 0;
 
   if (VALUE_LVAL (result) == lval_memory)
@@ -1709,7 +1709,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
 	    val = dwarf2_evaluate_loc_desc (baton->property_type, frame, data,
 					    size, baton->loclist.per_cu,
 					    baton->loclist.per_objfile);
-	    if (!value_optimized_out (val))
+	    if (!val->optimized_out ())
 	      {
 		*value = value_as_address (val);
 		return true;
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 824a303fdc4..e96892947af 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -269,11 +269,11 @@ class fortran_array_printer_impl : public fortran_array_walker_base_impl
 	struct value *e_val = value_from_component (m_val, elt_type, elt_off);
 	struct value *e_prev = value_from_component (m_val, elt_type,
 						     elt_off_prev);
-	repeated = ((value_entirely_available (e_prev)
-		     && value_entirely_available (e_val)
+	repeated = ((e_prev->entirely_available ()
+		     && e_val->entirely_available ()
 		     && e_prev->contents_eq (e_val))
-		    || (value_entirely_unavailable (e_prev)
-			&& value_entirely_unavailable (e_val)));
+		    || (e_prev->entirely_unavailable ()
+			&& e_val->entirely_unavailable ()));
       }
 
     if (repeated)
@@ -376,11 +376,11 @@ class fortran_array_printer_impl : public fortran_array_walker_base_impl
 	struct value *e_val1 = value_from_component (val, type, offset1);
 	struct value *e_val2 = value_from_component (val, type, offset2);
 
-	return ((value_entirely_available (e_val1)
-		 && value_entirely_available (e_val2)
+	return ((e_val1->entirely_available ()
+		 && e_val2->entirely_available ()
 		 && e_val1->contents_eq (e_val2))
-		|| (value_entirely_unavailable (e_val1)
-		    && value_entirely_unavailable (e_val2)));
+		|| (e_val1->entirely_unavailable ()
+		    && e_val2->entirely_unavailable ()));
       }
   }
 
diff --git a/gdb/findvar.c b/gdb/findvar.c
index b4852b2cfb3..2a2c3eb2ab4 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -906,9 +906,9 @@ value_from_register (struct type *type, int regnum, frame_info_ptr frame)
       if (!ok)
 	{
 	  if (optim)
-	    mark_value_bytes_optimized_out (v, 0, type->length ());
+	    v->mark_bytes_optimized_out (0, type->length ());
 	  if (unavail)
-	    mark_value_bytes_unavailable (v, 0, type->length ());
+	    v->mark_bytes_unavailable (0, type->length ());
 	}
     }
   else
@@ -971,7 +971,7 @@ address_from_register (int regnum, frame_info_ptr frame)
   value = gdbarch_value_from_register (gdbarch, type, regnum, null_frame_id);
   read_frame_register_value (value, frame);
 
-  if (value_optimized_out (value))
+  if (value->optimized_out ())
     {
       /* This function is used while computing a location expression.
 	 Complain about the value being optimized out, rather than
diff --git a/gdb/frame.c b/gdb/frame.c
index 628b18d6708..bf9b055878a 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1189,8 +1189,8 @@ frame_register_unwind (frame_info_ptr next_frame, int regnum,
 
   gdb_assert (value != NULL);
 
-  *optimizedp = value_optimized_out (value);
-  *unavailablep = !value_entirely_available (value);
+  *optimizedp = value->optimized_out ();
+  *unavailablep = !value->entirely_available ();
   *lvalp = VALUE_LVAL (value);
   *addrp = value->address ();
   if (*lvalp == lval_register)
@@ -1289,7 +1289,7 @@ frame_unwind_register_value (frame_info_ptr next_frame, int regnum)
       string_file debug_file;
 
       gdb_printf (&debug_file, "  ->");
-      if (value_optimized_out (value))
+      if (value->optimized_out ())
 	{
 	  gdb_printf (&debug_file, " ");
 	  val_print_not_saved (&debug_file);
@@ -1342,12 +1342,12 @@ frame_unwind_register_signed (frame_info_ptr next_frame, int regnum)
 
   gdb_assert (value != NULL);
 
-  if (value_optimized_out (value))
+  if (value->optimized_out ())
     {
       throw_error (OPTIMIZED_OUT_ERROR,
 		   _("Register %d was not saved"), regnum);
     }
-  if (!value_entirely_available (value))
+  if (!value->entirely_available ())
     {
       throw_error (NOT_AVAILABLE_ERROR,
 		   _("Register %d is not available"), regnum);
@@ -1375,12 +1375,12 @@ frame_unwind_register_unsigned (frame_info_ptr next_frame, int regnum)
 
   gdb_assert (value != NULL);
 
-  if (value_optimized_out (value))
+  if (value->optimized_out ())
     {
       throw_error (OPTIMIZED_OUT_ERROR,
 		   _("Register %d was not saved"), regnum);
     }
-  if (!value_entirely_available (value))
+  if (!value->entirely_available ())
     {
       throw_error (NOT_AVAILABLE_ERROR,
 		   _("Register %d is not available"), regnum);
@@ -1405,8 +1405,8 @@ read_frame_register_unsigned (frame_info_ptr frame, int regnum,
 {
   struct value *regval = get_frame_register_value (frame, regnum);
 
-  if (!value_optimized_out (regval)
-      && value_entirely_available (regval))
+  if (!regval->optimized_out ()
+      && regval->entirely_available ())
     {
       struct gdbarch *gdbarch = get_frame_arch (frame);
       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
@@ -1537,8 +1537,8 @@ get_frame_register_bytes (frame_info_ptr frame, int regnum,
 	    = frame_unwind_register_value (frame_info_ptr (frame->next),
 					   regnum);
 	  gdb_assert (value != NULL);
-	  *optimizedp = value_optimized_out (value);
-	  *unavailablep = !value_entirely_available (value);
+	  *optimizedp = value->optimized_out ();
+	  *unavailablep = !value->entirely_available ();
 
 	  if (*optimizedp || *unavailablep)
 	    {
diff --git a/gdb/gnu-v2-abi.c b/gdb/gnu-v2-abi.c
index 4636ad55109..e8202667e24 100644
--- a/gdb/gnu-v2-abi.c
+++ b/gdb/gnu-v2-abi.c
@@ -366,8 +366,8 @@ gnuv2_baseclass_offset (struct type *type, int index,
 	      field_offset = type->field (i).loc_bitpos () / 8;
 	      field_length = field_type->length ();
 
-	      if (!value_bytes_available (val, embedded_offset + field_offset,
-					  field_length))
+	      if (!val->bytes_available (embedded_offset + field_offset,
+					 field_length))
 		throw_error (NOT_AVAILABLE_ERROR,
 			     _("Virtual baseclass pointer is not available"));
 
diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c
index ca44133cd7f..e172a14dbb3 100644
--- a/gdb/guile/scm-pretty-print.c
+++ b/gdb/guile/scm-pretty-print.c
@@ -969,7 +969,7 @@ gdbscm_apply_val_pretty_printer (const struct extension_language_defn *extlang,
     value->fetch_lazy ();
 
   /* No pretty-printer support for unavailable values.  */
-  if (!value_bytes_available (value, 0, type->length ()))
+  if (!value->bytes_available (0, type->length ()))
     return EXT_LANG_RC_NOP;
 
   if (!gdb_scheme_initialized)
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index df76f8a49d1..3e18bd1fdc3 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -390,7 +390,7 @@ gdbscm_value_optimized_out_p (SCM self)
 
   return gdbscm_wrap ([=]
     {
-      return scm_from_bool (value_optimized_out (v_smob->value));
+      return scm_from_bool (v_smob->value->optimized_out ());
     });
 }
 
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index ed61ee1a9b3..c8c7a1e6e45 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3388,8 +3388,8 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
       /* Extract (always little endian).  */
       status = regcache->raw_read (fpnum, raw_buf);
       if (status != REG_VALID)
-	mark_value_bytes_unavailable (result_value, 0,
-				      result_value->type ()->length ());
+	result_value->mark_bytes_unavailable (0,
+					      result_value->type ()->length ());
       else
 	memcpy (buf, raw_buf, register_size (gdbarch, regnum));
     }
@@ -3404,7 +3404,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 	  status = regcache->raw_read (I387_BND0R_REGNUM (tdep) + regnum,
 				       raw_buf);
 	  if (status != REG_VALID)
-	    mark_value_bytes_unavailable (result_value, 0, 16);
+	    result_value->mark_bytes_unavailable (0, 16);
 	  else
 	    {
 	      enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
@@ -3426,7 +3426,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 	  /* Extract (always little endian).  */
 	  status = regcache->raw_read (tdep->k0_regnum + regnum, raw_buf);
 	  if (status != REG_VALID)
-	    mark_value_bytes_unavailable (result_value, 0, 8);
+	    result_value->mark_bytes_unavailable (0, 8);
 	  else
 	    memcpy (buf, raw_buf, 8);
 	}
@@ -3440,7 +3440,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 	      status = regcache->raw_read (I387_XMM0_REGNUM (tdep) + regnum,
 					   raw_buf);
 	      if (status != REG_VALID)
-		mark_value_bytes_unavailable (result_value, 0, 16);
+		result_value->mark_bytes_unavailable (0, 16);
 	      else
 		memcpy (buf, raw_buf, 16);
 
@@ -3448,7 +3448,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 	      status = regcache->raw_read (tdep->ymm0h_regnum + regnum,
 					   raw_buf);
 	      if (status != REG_VALID)
-		mark_value_bytes_unavailable (result_value, 16, 16);
+		result_value->mark_bytes_unavailable (16, 16);
 	      else
 		memcpy (buf + 16, raw_buf, 16);
 	    }
@@ -3459,7 +3459,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 					   - num_lower_zmm_regs,
 					   raw_buf);
 	      if (status != REG_VALID)
-		mark_value_bytes_unavailable (result_value, 0, 16);
+		result_value->mark_bytes_unavailable (0, 16);
 	      else
 		memcpy (buf, raw_buf, 16);
 
@@ -3468,7 +3468,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 					   - num_lower_zmm_regs,
 					   raw_buf);
 	      if (status != REG_VALID)
-		mark_value_bytes_unavailable (result_value, 16, 16);
+		result_value->mark_bytes_unavailable (16, 16);
 	      else
 		memcpy (buf + 16, raw_buf, 16);
 	    }
@@ -3477,7 +3477,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 	  status = regcache->raw_read (tdep->zmm0h_regnum + regnum,
 				       raw_buf);
 	  if (status != REG_VALID)
-	    mark_value_bytes_unavailable (result_value, 32, 32);
+	    result_value->mark_bytes_unavailable (32, 32);
 	  else
 	    memcpy (buf + 32, raw_buf, 32);
 	}
@@ -3489,14 +3489,14 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 	  status = regcache->raw_read (I387_XMM0_REGNUM (tdep) + regnum,
 				       raw_buf);
 	  if (status != REG_VALID)
-	    mark_value_bytes_unavailable (result_value, 0, 16);
+	    result_value->mark_bytes_unavailable (0, 16);
 	  else
 	    memcpy (buf, raw_buf, 16);
 	  /* Read upper 128bits.  */
 	  status = regcache->raw_read (tdep->ymm0h_regnum + regnum,
 				       raw_buf);
 	  if (status != REG_VALID)
-	    mark_value_bytes_unavailable (result_value, 16, 32);
+	    result_value->mark_bytes_unavailable (16, 32);
 	  else
 	    memcpy (buf + 16, raw_buf, 16);
 	}
@@ -3507,14 +3507,14 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 	  status = regcache->raw_read (I387_XMM16_REGNUM (tdep) + regnum,
 				       raw_buf);
 	  if (status != REG_VALID)
-	    mark_value_bytes_unavailable (result_value, 0, 16);
+	    result_value->mark_bytes_unavailable (0, 16);
 	  else
 	    memcpy (buf, raw_buf, 16);
 	  /* Read upper 128bits.  */
 	  status = regcache->raw_read (tdep->ymm16h_regnum + regnum,
 				       raw_buf);
 	  if (status != REG_VALID)
-	    mark_value_bytes_unavailable (result_value, 16, 16);
+	    result_value->mark_bytes_unavailable (16, 16);
 	  else
 	    memcpy (buf + 16, raw_buf, 16);
 	}
@@ -3525,8 +3525,8 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 	  /* Extract (always little endian).  */
 	  status = regcache->raw_read (gpnum, raw_buf);
 	  if (status != REG_VALID)
-	    mark_value_bytes_unavailable (result_value, 0,
-					  result_value->type ()->length ());
+	    result_value->mark_bytes_unavailable (0,
+						  result_value->type ()->length ());
 	  else
 	    memcpy (buf, raw_buf, 2);
 	}
@@ -3538,8 +3538,8 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 	     upper registers.  */
 	  status = regcache->raw_read (gpnum % 4, raw_buf);
 	  if (status != REG_VALID)
-	    mark_value_bytes_unavailable (result_value, 0,
-					  result_value->type ()->length ());
+	    result_value->mark_bytes_unavailable (0,
+						  result_value->type ()->length ());
 	  else if (gpnum >= 4)
 	    memcpy (buf, raw_buf + 1, 1);
 	  else
diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
index e1cbab580eb..df0a6058adc 100644
--- a/gdb/i387-tdep.c
+++ b/gdb/i387-tdep.c
@@ -282,7 +282,7 @@ i387_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 	  regnum = (fpreg + 8 - top) % 8 + I387_ST0_REGNUM (tdep);
 	  regval = get_frame_register_value (frame, regnum);
 
-	  if (value_entirely_available (regval))
+	  if (regval->entirely_available ())
 	    {
 	      const gdb_byte *raw = regval->contents ().data ();
 
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 50378b111c0..3943a562590 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2172,8 +2172,8 @@ default_print_one_register_info (struct ui_file *file,
   format_stream.puts (name);
   pad_to_column (format_stream, value_column_1);
 
-  print_raw_format = (value_entirely_available (val)
-		      && !value_optimized_out (val));
+  print_raw_format = (val->entirely_available ()
+		      && !val->optimized_out ());
 
   /* If virtual format is floating, print it that way, and in raw
      hex.  */
diff --git a/gdb/infrun.c b/gdb/infrun.c
index c5718580162..e5d2b97f1dd 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7989,7 +7989,7 @@ insert_exception_resume_breakpoint (struct thread_info *tp,
 					b, VAR_DOMAIN);
       value = read_var_value (vsym.symbol, vsym.block, frame);
       /* If the value was optimized out, revert to the old behavior.  */
-      if (! value_optimized_out (value))
+      if (! value->optimized_out ())
 	{
 	  handler = value_as_address (value);
 
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index abe0d34f042..1554f9550e6 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -501,14 +501,13 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
 		  && (arg->val || arg->error)));
 
   if (skip_unavailable && arg->val != NULL
-      && (value_entirely_unavailable (arg->val)
+      && (arg->val->entirely_unavailable ()
 	  /* A scalar object that does not have all bits available is
 	     also considered unavailable, because all bits contribute
 	     to its representation.  */
 	  || (val_print_scalar_type_p (arg->val->type ())
-	      && !value_bytes_available (arg->val,
-					 arg->val->embedded_offset (),
-					 arg->val->type ()->length ()))))
+	      && !arg->val->bytes_available (arg->val->embedded_offset (),
+					     arg->val->type ()->length ()))))
     return;
 
   gdb::optional<ui_out_emit_tuple> tuple_emitter;
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index f2e680cb0d3..84a95a24684 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1096,7 +1096,7 @@ output_register (frame_info_ptr frame, int regnum, int format,
   struct value *val = value_of_register (regnum, frame);
   struct value_print_options opts;
 
-  if (skip_unavailable && !value_entirely_available (val))
+  if (skip_unavailable && !val->entirely_available ())
     return;
 
   ui_out_emit_tuple tuple_emitter (uiout, NULL);
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 19e0fdcf81e..b88a2f67ded 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -6585,8 +6585,8 @@ print_gp_register_row (struct ui_file *file, frame_info_ptr frame,
 
       /* OK: get the data in raw format.  */
       value = get_frame_register_value (frame, regnum);
-      if (value_optimized_out (value)
-	|| !value_entirely_available (value))
+      if (value->optimized_out ()
+	  || !value->entirely_available ())
 	{
 	  gdb_printf (file, "%*s ",
 		      (int) mips_abi_regsize (gdbarch) * 2,
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 10d41523851..f13f0ef6625 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -818,7 +818,7 @@ pascal_object_print_static_field (struct value *val,
   struct type *type = val->type ();
   struct value_print_options opts;
 
-  if (value_entirely_optimized_out (val))
+  if (val->entirely_optimized_out ())
     {
       val_print_optimized_out (val, stream);
       return;
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 8619e38aea4..0b3c2e00b4c 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1280,8 +1280,8 @@ should_validate_memtags (struct value *value)
 
   /* OK, we have an address value.  Check we have a complete value we
      can extract.  */
-  if (value_optimized_out (value)
-      || !value_entirely_available (value))
+  if (value->optimized_out ()
+      || !value->entirely_available ())
     return false;
 
   /* We do.  Check whether it includes any tags.  */
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index dd72e230157..dbacb3f3fe2 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -582,7 +582,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
     value->fetch_lazy ();
 
   /* No pretty-printer support for unavailable values.  */
-  if (!value_bytes_available (value, 0, type->length ()))
+  if (!value->bytes_available (0, type->length ()))
     return EXT_LANG_RC_NOP;
 
   if (!gdb_python_initialized)
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index f339845c272..6c33e3529c8 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1197,7 +1197,7 @@ valpy_get_is_optimized_out (PyObject *self, void *closure)
 
   try
     {
-      opt = value_optimized_out (value);
+      opt = value->optimized_out ();
     }
   catch (const gdb_exception &except)
     {
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 90989595acc..09dd6a4b79e 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -715,7 +715,7 @@ readable_regcache::cooked_read (int regnum, gdb_byte *buf)
 
       computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch,
 						     this, regnum);
-      if (value_entirely_available (computed))
+      if (computed->entirely_available ())
 	memcpy (buf, computed->contents_raw ().data (),
 		m_descr->sizeof_register[regnum]);
       else
@@ -752,8 +752,8 @@ readable_regcache::cooked_read_value (int regnum)
 	 API is preferred.  */
       if (cooked_read (regnum,
 		       result->contents_raw ().data ()) == REG_UNAVAILABLE)
-	mark_value_bytes_unavailable (result, 0,
-				      result->type ()->length ());
+	result->mark_bytes_unavailable (0,
+					result->type ()->length ());
 
       return result;
     }
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 78c23ee86fc..388ce8c2519 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -1126,8 +1126,8 @@ riscv_print_one_register_info (struct gdbarch *gdbarch,
       return;
     }
 
-  print_raw_format = (value_entirely_available (val)
-		      && !value_optimized_out (val));
+  print_raw_format = (val->entirely_available ()
+		      && !val->optimized_out ());
 
   if (regtype->code () == TYPE_CODE_FLT
       || (regtype->code () == TYPE_CODE_UNION
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 7d2cdf2a873..cab1757c5ab 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -2199,7 +2199,7 @@ s390_unwind_pseudo_register (frame_info_ptr this_frame, int regnum)
       struct value *val;
 
       val = frame_unwind_register_value (this_frame, S390_PSWA_REGNUM);
-      if (!value_optimized_out (val))
+      if (!val->optimized_out ())
 	{
 	  LONGEST pswa = value_as_long (val);
 
@@ -2216,7 +2216,7 @@ s390_unwind_pseudo_register (frame_info_ptr this_frame, int regnum)
       struct value *val;
 
       val = frame_unwind_register_value (this_frame, S390_PSWM_REGNUM);
-      if (!value_optimized_out (val))
+      if (!val->optimized_out ())
 	{
 	  LONGEST pswm = value_as_long (val);
 
@@ -2235,7 +2235,7 @@ s390_unwind_pseudo_register (frame_info_ptr this_frame, int regnum)
       struct value *val;
 
       val = frame_unwind_register_value (this_frame, S390_R0_REGNUM + reg);
-      if (!value_optimized_out (val))
+      if (!val->optimized_out ())
 	return value_cast (type, val);
     }
 
diff --git a/gdb/stack.c b/gdb/stack.c
index 576947c5dac..934220e7c33 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -550,7 +550,7 @@ read_frame_arg (const frame_print_options &fp_opts,
       && SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry != NULL
       && fp_opts.print_entry_values != print_entry_values_no
       && (fp_opts.print_entry_values != print_entry_values_if_needed
-	  || !val || value_optimized_out (val)))
+	  || !val || val->optimized_out ()))
     {
       try
 	{
@@ -568,7 +568,7 @@ read_frame_arg (const frame_print_options &fp_opts,
 	    }
 	}
 
-      if (entryval != NULL && value_optimized_out (entryval))
+      if (entryval != NULL && entryval->optimized_out ())
 	entryval = NULL;
 
       if (fp_opts.print_entry_values == print_entry_values_compact
@@ -672,7 +672,7 @@ read_frame_arg (const frame_print_options &fp_opts,
       if (fp_opts.print_entry_values == print_entry_values_only
 	  || fp_opts.print_entry_values == print_entry_values_both
 	  || (fp_opts.print_entry_values == print_entry_values_preferred
-	      && (!val || value_optimized_out (val))))
+	      && (!val || val->optimized_out ())))
 	{
 	  entryval = value::allocate_optimized_out (sym->type ());
 	  entryval_error = NULL;
@@ -681,7 +681,7 @@ read_frame_arg (const frame_print_options &fp_opts,
   if ((fp_opts.print_entry_values == print_entry_values_compact
        || fp_opts.print_entry_values == print_entry_values_if_needed
        || fp_opts.print_entry_values == print_entry_values_preferred)
-      && (!val || value_optimized_out (val)) && entryval != NULL)
+      && (!val || val->optimized_out ()) && entryval != NULL)
     {
       val = NULL;
       val_error = NULL;
@@ -1708,7 +1708,7 @@ info_frame_command_core (frame_info_ptr fi, bool selected_frame_p)
 	struct value *value = frame_unwind_register_value (fi, sp_regnum);
 	gdb_assert (value != NULL);
 
-	if (!value_optimized_out (value) && value_entirely_available (value))
+	if (!value->optimized_out () && value->entirely_available ())
 	  {
 	    if (VALUE_LVAL (value) == not_lval)
 	      {
diff --git a/gdb/valarith.c b/gdb/valarith.c
index e92b6672229..854d061aecc 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -188,10 +188,10 @@ value_subscript (struct value *array, LONGEST index)
       struct type *elt_type = check_typedef (tarray->target_type ());
       LONGEST elt_size = type_length_units (elt_type);
       if (!array->lazy ()
-	  && !value_bytes_available (array, elt_size * index, elt_size))
+	  && !array->bytes_available (elt_size * index, elt_size))
 	{
 	  struct value *val = value::allocate (elt_type);
-	  mark_value_bytes_unavailable (val, 0, elt_size);
+	  val->mark_bytes_unavailable (0, elt_size);
 	  VALUE_LVAL (val) = lval_memory;
 	  val->set_address (array->address () + elt_size * index);
 	  return val;
diff --git a/gdb/valops.c b/gdb/valops.c
index aac32cc0917..b088a5d99ae 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1066,9 +1066,9 @@ read_value_memory (struct value *val, LONGEST bit_offset,
       if (status == TARGET_XFER_OK)
 	/* nothing */;
       else if (status == TARGET_XFER_UNAVAILABLE)
-	mark_value_bits_unavailable (val, (xfered_total * HOST_CHAR_BIT
-					   + bit_offset),
-				     xfered_partial * HOST_CHAR_BIT);
+	val->mark_bits_unavailable ((xfered_total * HOST_CHAR_BIT
+				     + bit_offset),
+				    xfered_partial * HOST_CHAR_BIT);
       else if (status == TARGET_XFER_EOF)
 	memory_error (TARGET_XFER_E_IO, memaddr + xfered_total);
       else
diff --git a/gdb/valprint.c b/gdb/valprint.c
index ba62d3af41c..46d0aee1417 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -373,9 +373,8 @@ valprint_check_validity (struct ui_file *stream,
       && type->code () != TYPE_CODE_STRUCT
       && type->code () != TYPE_CODE_ARRAY)
     {
-      if (value_bits_any_optimized_out (val,
-					TARGET_CHAR_BIT * embedded_offset,
-					TARGET_CHAR_BIT * type->length ()))
+      if (val->bits_any_optimized_out (TARGET_CHAR_BIT * embedded_offset,
+				       TARGET_CHAR_BIT * type->length ()))
 	{
 	  val_print_optimized_out (val, stream);
 	  return 0;
@@ -403,7 +402,7 @@ valprint_check_validity (struct ui_file *stream,
 	  return is_ref;
 	}
 
-      if (!value_bytes_available (val, embedded_offset, type->length ()))
+      if (!val->bytes_available (embedded_offset, type->length ()))
 	{
 	  val_print_unavailable (stream);
 	  return 0;
@@ -1131,7 +1130,7 @@ value_check_printable (struct value *val, struct ui_file *stream,
       return 0;
     }
 
-  if (value_entirely_optimized_out (val))
+  if (val->entirely_optimized_out ())
     {
       if (options->summary && !val_print_scalar_type_p (val->type ()))
 	gdb_printf (stream, "...");
@@ -1140,7 +1139,7 @@ value_check_printable (struct value *val, struct ui_file *stream,
       return 0;
     }
 
-  if (value_entirely_unavailable (val))
+  if (val->entirely_unavailable ())
     {
       if (options->summary && !val_print_scalar_type_p (val->type ()))
 	gdb_printf (stream, "...");
@@ -1304,10 +1303,10 @@ value_print_scalar_formatted (struct value *val,
 
   /* A scalar object that does not have all bits available can't be
      printed, because all bits contribute to its representation.  */
-  if (value_bits_any_optimized_out (val, 0,
-				    TARGET_CHAR_BIT * type->length ()))
+  if (val->bits_any_optimized_out (0,
+				   TARGET_CHAR_BIT * type->length ()))
     val_print_optimized_out (val, stream);
-  else if (!value_bytes_available (val, 0, type->length ()))
+  else if (!val->bytes_available (0, type->length ()))
     val_print_unavailable (stream);
   else
     print_scalar_formatted (valaddr, type, options, size, stream);
@@ -2017,8 +2016,8 @@ value_print_array_elements (struct value *val, struct ui_file *stream,
 	 UINT_MAX (unlimited).  */
       if (options->repeat_count_threshold < UINT_MAX)
 	{
-	  bool unavailable = value_entirely_unavailable (element);
-	  bool available = value_entirely_available (element);
+	  bool unavailable = element->entirely_unavailable ();
+	  bool available = element->entirely_available ();
 
 	  while (rep1 < len)
 	    {
@@ -2027,10 +2026,10 @@ value_print_array_elements (struct value *val, struct ui_file *stream,
 						rep1 * bit_stride,
 						bit_stride);
 	      bool repeated = ((available
-				&& value_entirely_available (rep_elt)
+				&& rep_elt->entirely_available ()
 				&& element->contents_eq (rep_elt))
 			       || (unavailable
-				   && value_entirely_unavailable (rep_elt)));
+				   && rep_elt->entirely_unavailable ()));
 	      if (!repeated)
 		break;
 	      ++reps;
diff --git a/gdb/value.c b/gdb/value.c
index b8a032ed30d..beda62d630f 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -169,23 +169,21 @@ value::arch () const
 }
 
 int
-value_bits_available (const struct value *value,
-		      LONGEST offset, ULONGEST length)
+value::bits_available (LONGEST offset, ULONGEST length) const
 {
-  gdb_assert (!value->m_lazy);
+  gdb_assert (!m_lazy);
 
   /* Don't pretend we have anything available there in the history beyond
      the boundaries of the value recorded.  It's not like inferior memory
      where there is actual stuff underneath.  */
-  ULONGEST val_len = TARGET_CHAR_BIT * value->enclosing_type ()->length ();
-  return !((value->m_in_history
+  ULONGEST val_len = TARGET_CHAR_BIT * enclosing_type ()->length ();
+  return !((m_in_history
 	    && (offset < 0 || offset + length > val_len))
-	   || ranges_contain (value->m_unavailable, offset, length));
+	   || ranges_contain (m_unavailable, offset, length));
 }
 
 int
-value_bytes_available (const struct value *value,
-		       LONGEST offset, ULONGEST length)
+value::bytes_available (LONGEST offset, ULONGEST length) const
 {
   ULONGEST sign = (1ULL << (sizeof (ULONGEST) * 8 - 1)) / TARGET_CHAR_BIT;
   ULONGEST mask = (sign << 1) - 1;
@@ -195,70 +193,52 @@ value_bytes_available (const struct value *value,
       || (length > 0 && (~offset & (offset + length - 1) & sign) != 0))
     error (_("Integer overflow in data location calculation"));
 
-  return value_bits_available (value,
-			       offset * TARGET_CHAR_BIT,
-			       length * TARGET_CHAR_BIT);
+  return bits_available (offset * TARGET_CHAR_BIT, length * TARGET_CHAR_BIT);
 }
 
 int
-value_bits_any_optimized_out (const struct value *value, int bit_offset, int bit_length)
+value::bits_any_optimized_out (int bit_offset, int bit_length) const
 {
-  gdb_assert (!value->m_lazy);
+  gdb_assert (!m_lazy);
 
-  return ranges_contain (value->m_optimized_out, bit_offset, bit_length);
+  return ranges_contain (m_optimized_out, bit_offset, bit_length);
 }
 
 int
-value_entirely_available (struct value *value)
+value::entirely_available ()
 {
   /* We can only tell whether the whole value is available when we try
      to read it.  */
-  if (value->m_lazy)
-    value->fetch_lazy ();
+  if (m_lazy)
+    fetch_lazy ();
 
-  if (value->m_unavailable.empty ())
+  if (m_unavailable.empty ())
     return 1;
   return 0;
 }
 
-/* Returns true if VALUE is entirely covered by RANGES.  If the value
-   is lazy, it'll be read now.  Note that RANGE is a pointer to
-   pointer because reading the value might change *RANGE.  */
+/* See value.h.  */
 
-static int
-value_entirely_covered_by_range_vector (struct value *value,
-					const std::vector<range> &ranges)
+int
+value::entirely_covered_by_range_vector (const std::vector<range> &ranges)
 {
   /* We can only tell whether the whole value is optimized out /
      unavailable when we try to read it.  */
-  if (value->m_lazy)
-    value->fetch_lazy ();
+  if (m_lazy)
+    fetch_lazy ();
 
   if (ranges.size () == 1)
     {
       const struct range &t = ranges[0];
 
       if (t.offset == 0
-	  && t.length == (TARGET_CHAR_BIT
-			  * value->enclosing_type ()->length ()))
+	  && t.length == TARGET_CHAR_BIT * enclosing_type ()->length ())
 	return 1;
     }
 
   return 0;
 }
 
-int
-value_entirely_unavailable (struct value *value)
-{
-  return value_entirely_covered_by_range_vector (value, value->m_unavailable);
-}
-
-int
-value_entirely_optimized_out (struct value *value)
-{
-  return value_entirely_covered_by_range_vector (value, value->m_optimized_out);
-}
-
 /* Insert into the vector pointed to by VECTORP the bit range starting of
    OFFSET bits, and extending for the next LENGTH bits.  */
 
@@ -429,19 +409,16 @@ insert_into_bit_range_vector (std::vector<range> *vectorp,
 }
 
 void
-mark_value_bits_unavailable (struct value *value,
-			     LONGEST offset, ULONGEST length)
+value::mark_bits_unavailable (LONGEST offset, ULONGEST length)
 {
-  insert_into_bit_range_vector (&value->m_unavailable, offset, length);
+  insert_into_bit_range_vector (&m_unavailable, offset, length);
 }
 
 void
-mark_value_bytes_unavailable (struct value *value,
-			      LONGEST offset, ULONGEST length)
+value::mark_bytes_unavailable (LONGEST offset, ULONGEST length)
 {
-  mark_value_bits_unavailable (value,
-			       offset * TARGET_CHAR_BIT,
-			       length * TARGET_CHAR_BIT);
+  mark_bits_unavailable (offset * TARGET_CHAR_BIT,
+			 length * TARGET_CHAR_BIT);
 }
 
 /* Find the first range in RANGES that overlaps the range defined by
@@ -1012,7 +989,7 @@ value::allocate_optimized_out (struct type *type)
 {
   struct value *retval = value::allocate_lazy (type);
 
-  mark_value_bytes_optimized_out (retval, 0, type->length ());
+  retval->mark_bytes_optimized_out (0, type->length ());
   retval->set_lazy (0);
   return retval;
 }
@@ -1061,7 +1038,7 @@ value_actual_type (struct value *value, int resolve_simple_types,
       if (result->is_pointer_or_reference ()
 	  && (check_typedef (result->target_type ())->code ()
 	      == TYPE_CODE_STRUCT)
-	  && !value_optimized_out (value))
+	  && !value->optimized_out ())
 	{
 	  struct type *real_type;
 
@@ -1204,10 +1181,9 @@ value_contents_copy_raw (struct value *dst, LONGEST dst_offset,
   /* The overwritten DST range gets unavailability ORed in, not
      replaced.  Make sure to remember to implement replacing if it
      turns out actually necessary.  */
-  gdb_assert (value_bytes_available (dst, dst_offset, length));
-  gdb_assert (!value_bits_any_optimized_out (dst,
-					     TARGET_CHAR_BIT * dst_offset,
-					     TARGET_CHAR_BIT * length));
+  gdb_assert (dst->bytes_available (dst_offset, length));
+  gdb_assert (!dst->bits_any_optimized_out (TARGET_CHAR_BIT * dst_offset,
+					    TARGET_CHAR_BIT * length));
 
   /* Copy the data.  */
   gdb::array_view<gdb_byte> dst_contents
@@ -1247,9 +1223,9 @@ value_contents_copy_raw_bitwise (struct value *dst, LONGEST dst_bit_offset,
      turns out actually necessary.  */
   LONGEST dst_offset = dst_bit_offset / TARGET_CHAR_BIT;
   LONGEST length = bit_length / TARGET_CHAR_BIT;
-  gdb_assert (value_bytes_available (dst, dst_offset, length));
-  gdb_assert (!value_bits_any_optimized_out (dst, dst_bit_offset,
-					     bit_length));
+  gdb_assert (dst->bytes_available (dst_offset, length));
+  gdb_assert (!dst->bits_any_optimized_out (dst_bit_offset,
+					    bit_length));
 
   /* Copy the data.  */
   gdb::array_view<gdb_byte> dst_contents = dst->contents_all_raw ();
@@ -1303,26 +1279,26 @@ value::contents_writeable ()
 }
 
 int
-value_optimized_out (struct value *value)
+value::optimized_out ()
 {
-  if (value->m_lazy)
+  if (m_lazy)
     {
       /* See if we can compute the result without fetching the
 	 value.  */
-      if (VALUE_LVAL (value) == lval_memory)
+      if (VALUE_LVAL (this) == lval_memory)
 	return false;
-      else if (VALUE_LVAL (value) == lval_computed)
+      else if (VALUE_LVAL (this) == lval_computed)
 	{
-	  const struct lval_funcs *funcs = value->m_location.computed.funcs;
+	  const struct lval_funcs *funcs = m_location.computed.funcs;
 
 	  if (funcs->is_optimized_out != nullptr)
-	    return funcs->is_optimized_out (value);
+	    return funcs->is_optimized_out (this);
 	}
 
       /* Fall back to fetching.  */
       try
 	{
-	  value->fetch_lazy ();
+	  fetch_lazy ();
 	}
       catch (const gdb_exception_error &ex)
 	{
@@ -1341,27 +1317,25 @@ value_optimized_out (struct value *value)
 	}
     }
 
-  return !value->m_optimized_out.empty ();
+  return !m_optimized_out.empty ();
 }
 
 /* Mark contents of VALUE as optimized out, starting at OFFSET bytes, and
    the following LENGTH bytes.  */
 
 void
-mark_value_bytes_optimized_out (struct value *value, int offset, int length)
+value::mark_bytes_optimized_out (int offset, int length)
 {
-  mark_value_bits_optimized_out (value,
-				 offset * TARGET_CHAR_BIT,
-				 length * TARGET_CHAR_BIT);
+  mark_bits_optimized_out (offset * TARGET_CHAR_BIT,
+			   length * TARGET_CHAR_BIT);
 }
 
 /* See value.h.  */
 
 void
-mark_value_bits_optimized_out (struct value *value,
-			       LONGEST offset, LONGEST length)
+value::mark_bits_optimized_out (LONGEST offset, LONGEST length)
 {
-  insert_into_bit_range_vector (&value->m_optimized_out, offset, length);
+  insert_into_bit_range_vector (&m_optimized_out, offset, length);
 }
 
 int
@@ -1546,8 +1520,8 @@ value::copy () const
   val->m_limited_length = m_limited_length;
 
   if (!val->lazy ()
-      && !(value_entirely_optimized_out (val)
-	   || value_entirely_unavailable (val)))
+      && !(val->entirely_optimized_out ()
+	   || val->entirely_unavailable ()))
     {
       ULONGEST length = val->m_limited_length;
       if (length == 0)
@@ -1721,8 +1695,8 @@ record_latest_value (struct value *val)
 
   ULONGEST limit = val->m_limited_length;
   if (limit != 0)
-    mark_value_bytes_unavailable (val, limit,
-				  enclosing_type->length () - limit);
+    val->mark_bytes_unavailable (limit,
+				 enclosing_type->length () - limit);
 
   /* Mark the value as recorded in the history for the availability check.  */
   val->m_in_history = true;
@@ -3159,8 +3133,8 @@ unpack_value_field_as_long (struct type *type, const gdb_byte *valaddr,
   gdb_assert (val != NULL);
 
   bit_offset = embedded_offset * TARGET_CHAR_BIT + bitpos;
-  if (value_bits_any_optimized_out (val, bit_offset, bitsize)
-      || !value_bits_available (val, bit_offset, bitsize))
+  if (val->bits_any_optimized_out (bit_offset, bitsize)
+      || !val->bits_available (bit_offset, bitsize))
     return 0;
 
   *result = unpack_bits_as_long (field_type, valaddr + embedded_offset,
@@ -3905,7 +3879,7 @@ value::fetch_lazy_register ()
 		  user_reg_map_regnum_to_name (gdbarch, regnum));
 
       gdb_printf (&debug_file, "->");
-      if (value_optimized_out (new_val))
+      if (new_val->optimized_out ())
 	{
 	  gdb_printf (&debug_file, " ");
 	  val_print_optimized_out (new_val, &debug_file);
@@ -4174,8 +4148,8 @@ test_value_copy ()
   value_ref_ptr val = release_value (value::allocate_optimized_out (type));
   value_ref_ptr copy = release_value (val.get ()->copy ());
 
-  SELF_CHECK (value_entirely_optimized_out (val.get ()));
-  SELF_CHECK (value_entirely_optimized_out (copy.get ()));
+  SELF_CHECK (val.get ()->entirely_optimized_out ());
+  SELF_CHECK (copy.get ()->entirely_optimized_out ());
 }
 
 } /* namespace selftests */
diff --git a/gdb/value.h b/gdb/value.h
index 6b0250c0e51..4ecaeb7c607 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -262,7 +262,6 @@ struct value
   void set_lazy (int val)
   { m_lazy = val; }
 
-
   /* If a value represents a C++ object, then the `type' field gives the
      object's compile-time type.  If the object actually belongs to some
      class derived from `type', perhaps with other base classes and
@@ -479,6 +478,60 @@ struct value
      drops to 0, it will be freed.  */
   void decref ();
 
+  /* Given a value, determine whether the contents bytes starting at
+     OFFSET and extending for LENGTH bytes are available.  This returns
+     nonzero if all bytes in the given range are available, zero if any
+     byte is unavailable.  */
+  int bytes_available (LONGEST offset, ULONGEST length) const;
+
+  /* Given a value, determine whether the contents bits starting at
+     OFFSET and extending for LENGTH bits are available.  This returns
+     nonzero if all bits in the given range are available, zero if any
+     bit is unavailable.  */
+  int bits_available (LONGEST offset, ULONGEST length) const;
+
+  /* Like bytes_available, but return false if any byte in the
+     whole object is unavailable.  */
+  int entirely_available ();
+
+  /* Like entirely_available, but return false if any byte in the
+     whole object is available.  */
+  int entirely_unavailable ()
+  { return entirely_covered_by_range_vector (m_unavailable); }
+
+  /* Mark this value's content bytes starting at OFFSET and extending
+     for LENGTH bytes as unavailable.  */
+  void mark_bytes_unavailable (LONGEST offset, ULONGEST length);
+
+  /* Mark this value's content bits starting at OFFSET and extending
+     for LENGTH bits as unavailable.  */
+  void mark_bits_unavailable (LONGEST offset, ULONGEST length);
+
+  /* If nonzero, this is the value of a variable which does not actually
+     exist in the program, at least partially.  If the value is lazy,
+     this may fetch it now.  */
+  int optimized_out ();
+
+  /* Given a value, return true if any of the contents bits starting at
+     OFFSET and extending for LENGTH bits is optimized out, false
+     otherwise.  */
+  int bits_any_optimized_out (int bit_offset, int bit_length) const;
+
+  /* Like optimized_out, but return true iff the whole value is
+     optimized out.  */
+  int entirely_optimized_out ()
+  {
+    return entirely_covered_by_range_vector (m_optimized_out);
+  }
+
+  /* Mark this value's content bytes starting at OFFSET and extending
+     for LENGTH bytes as optimized out.  */
+  void mark_bytes_optimized_out (int offset, int length);
+
+  /* Mark this value's content bits starting at OFFSET and extending
+     for LENGTH bits as optimized out.  */
+  void mark_bits_optimized_out (LONGEST offset, LONGEST length);
+
 
   /* Type of value; either not an lval, or one of the various
      different possible kinds of lval.  */
@@ -697,6 +750,11 @@ struct value
 
   void require_not_optimized_out () const;
   void require_available () const;
+
+  /* Returns true if this value is entirely covered by RANGES.  If the
+     value is lazy, it'll be read now.  Note that RANGE is a pointer
+     to pointer because reading the value might change *RANGE.  */
+  int entirely_covered_by_range_vector (const std::vector<range> &ranges);
 };
 
 inline void
@@ -793,34 +851,6 @@ struct lval_funcs
 
 extern void error_value_optimized_out (void);
 
-/* If nonzero, this is the value of a variable which does not actually
-   exist in the program, at least partially.  If the value is lazy,
-   this may fetch it now.  */
-extern int value_optimized_out (struct value *value);
-
-/* Given a value, return true if any of the contents bits starting at
-   OFFSET and extending for LENGTH bits is optimized out, false
-   otherwise.  */
-
-extern int value_bits_any_optimized_out (const struct value *value,
-					 int bit_offset, int bit_length);
-
-/* Like value_optimized_out, but return true iff the whole value is
-   optimized out.  */
-extern int value_entirely_optimized_out (struct value *value);
-
-/* Mark VALUE's content bytes starting at OFFSET and extending for
-   LENGTH bytes as optimized out.  */
-
-extern void mark_value_bytes_optimized_out (struct value *value,
-					    int offset, int length);
-
-/* Mark VALUE's content bits starting at OFFSET and extending for
-   LENGTH bits as optimized out.  */
-
-extern void mark_value_bits_optimized_out (struct value *value,
-					   LONGEST offset, LONGEST length);
-
 /* Set COMPONENT's location as appropriate for a component of WHOLE
    --- regardless of what kind of lvalue WHOLE is.  */
 extern void set_value_component_location (struct value *component,
@@ -877,42 +907,6 @@ extern struct value *coerce_ref (struct value *value);
 
 extern struct value *coerce_array (struct value *value);
 
-/* Given a value, determine whether the contents bytes starting at
-   OFFSET and extending for LENGTH bytes are available.  This returns
-   nonzero if all bytes in the given range are available, zero if any
-   byte is unavailable.  */
-
-extern int value_bytes_available (const struct value *value,
-				  LONGEST offset, ULONGEST length);
-
-/* Given a value, determine whether the contents bits starting at
-   OFFSET and extending for LENGTH bits are available.  This returns
-   nonzero if all bits in the given range are available, zero if any
-   bit is unavailable.  */
-
-extern int value_bits_available (const struct value *value,
-				 LONGEST offset, ULONGEST length);
-
-/* Like value_bytes_available, but return false if any byte in the
-   whole object is unavailable.  */
-extern int value_entirely_available (struct value *value);
-
-/* Like value_entirely_available, but return false if any byte in the
-   whole object is available.  */
-extern int value_entirely_unavailable (struct value *value);
-
-/* Mark VALUE's content bytes starting at OFFSET and extending for
-   LENGTH bytes as unavailable.  */
-
-extern void mark_value_bytes_unavailable (struct value *value,
-					  LONGEST offset, ULONGEST length);
-
-/* Mark VALUE's content bits starting at OFFSET and extending for
-   LENGTH bits as unavailable.  */
-
-extern void mark_value_bits_unavailable (struct value *value,
-					 LONGEST offset, ULONGEST length);
-
 /* Read LENGTH addressable memory units starting at MEMADDR into BUFFER,
    which is (or will be copied to) VAL's contents buffer offset by
    BIT_OFFSET bits.  Marks value contents ranges as unavailable if

-- 
2.39.1


  parent reply	other threads:[~2023-02-13  3:53 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-13  3:15 [PATCH v3 00/50] Use methods for struct value Tom Tromey
2023-02-13  3:15 ` [PATCH v3 01/50] Automatic date update in version.in Tom Tromey
2023-02-13  3:24   ` Tom Tromey
2023-02-13  3:15 ` [PATCH v3 02/50] Rename all fields of struct value Tom Tromey
2023-02-13  3:15 ` [PATCH v3 03/50] Move ~value body out-of-line Tom Tromey
2023-02-13  3:15 ` [PATCH v3 04/50] Move struct value to value.h Tom Tromey
2023-02-13  3:15 ` [PATCH v3 05/50] Turn value_type into method Tom Tromey
2023-02-13  3:15 ` [PATCH v3 06/50] Turn deprecated_set_value_type into a method Tom Tromey
2023-02-13  3:15 ` [PATCH v3 07/50] Turn value_arch into method Tom Tromey
2023-02-13  3:15 ` [PATCH v3 08/50] Turn value_bitsize " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 09/50] Turn value_bitpos " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 10/50] Turn value_parent " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 11/50] Turn value_offset " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 12/50] Turn deprecated_value_modifiable " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 13/50] Turn value_enclosing_type " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 14/50] Turn some value offset functions " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 15/50] Turn value_lazy and set_value_lazy functions into methods Tom Tromey
2023-02-13  3:15 ` [PATCH v3 16/50] Turn value_stack and set_value_stack " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 17/50] Turn value_computed_closure and value_computed_funcs " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 18/50] Convert value_lval_const and deprecated_lval_hack to methods Tom Tromey
2023-02-13  3:15 ` [PATCH v3 19/50] Turn value_initialized and set_value_initialized functions into methods Tom Tromey
2023-02-13  3:15 ` [PATCH v3 20/50] Turn value_address and set_value_address " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 21/50] Turn more deprecated_* " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 22/50] Turn allocate_value_lazy into a static "constructor" Tom Tromey
2023-02-13  3:15 ` [PATCH v3 23/50] Turn allocate_value " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 24/50] Turn allocate_computed_value into " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 25/50] Turn allocate_optimized_out_value " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 26/50] Turn value_zero " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 27/50] Turn some value_contents functions into methods Tom Tromey
2023-02-13  3:15 ` [PATCH v3 28/50] Turn value_fetch_lazy into a method Tom Tromey
2023-02-13 17:35   ` Simon Marchi
2023-02-13  3:15 ` [PATCH v3 29/50] Turn allocate_value_contents " Tom Tromey
2023-02-13 17:37   ` Simon Marchi
2023-02-13  3:15 ` [PATCH v3 30/50] Turn value_contents_eq " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 31/50] Turn value_bits_synthetic_pointer " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 32/50] Move value_ref_policy methods out-of-line Tom Tromey
2023-02-13  3:15 ` [PATCH v3 33/50] Turn value_incref and value_decref into methods Tom Tromey
2023-02-13  3:15 ` [PATCH v3 34/50] Turn remaining value_contents functions " Tom Tromey
2023-02-13  3:15 ` [PATCH v3 35/50] Fully qualify calls to copy in value.c Tom Tromey
2023-02-13  3:15 ` [PATCH v3 36/50] Turn value_copy into a method Tom Tromey
2023-02-13  3:15 ` Tom Tromey [this message]
2023-02-13  3:15 ` [PATCH v3 38/50] Turn value_non_lval and value_force_lval into methods Tom Tromey
2023-02-13  3:15 ` [PATCH v3 39/50] Turn set_value_component_location into method Tom Tromey
2023-02-13  3:15 ` [PATCH v3 40/50] Change some code to use value methods Tom Tromey
2023-02-13  3:15 ` [PATCH v3 41/50] Turn some xmethod functions into methods Tom Tromey
2023-02-13  3:15 ` [PATCH v3 42/50] Turn preserve_one_value into method Tom Tromey
2023-02-13  3:15 ` [PATCH v3 43/50] Turn various value copying-related functions into methods Tom Tromey
2023-02-13  3:16 ` [PATCH v3 44/50] Add value::set_modifiable Tom Tromey
2023-02-13  3:16 ` [PATCH v3 45/50] Turn record_latest_value into a method Tom Tromey
2023-02-13 17:38   ` Simon Marchi
2023-02-13  3:16 ` [PATCH v3 46/50] Make struct value data members private Tom Tromey
2023-02-13  3:16 ` [PATCH v3 47/50] Make ~value private Tom Tromey
2023-02-13  3:16 ` [PATCH v3 48/50] Introduce set_lval method on value Tom Tromey
2023-02-13  3:16 ` [PATCH v3 49/50] Remove deprecated_lval_hack Tom Tromey
2023-02-13 22:26 ` [PATCH v3 00/50] Use methods for struct value Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230209-submit-value-fixups-2023-v3-37-45e91a20c742@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).