public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/6] Use bool in value
@ 2023-02-14 20:23 Tom Tromey
  2023-02-14 20:23 ` [PATCH 1/6] Change value::m_modifiable to bool Tom Tromey
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Tom Tromey @ 2023-02-14 20:23 UTC (permalink / raw)
  To: gdb-patches

There are a few spots in struct value that should use 'bool'.  This
short series fixes these up.

Regression tested on x86-64 Fedora 36.

---
Tom Tromey (6):
      Change value::m_modifiable to bool
      Change value::m_lazy to bool
      Change value::m_initialized to bool
      Change value::m_stack to bool
      Have value::bits_synthetic_pointer return bool
      Return bool from more value methods

 gdb/breakpoint.c    |  3 +--
 gdb/dwarf2/expr.c   | 12 ++++-----
 gdb/dwarf2/expr.h   |  6 ++---
 gdb/dwarf2/loc.c    |  2 +-
 gdb/frame-unwind.c  |  2 +-
 gdb/gnu-v2-abi.c    |  2 +-
 gdb/opencl-lang.c   | 10 ++++----
 gdb/ppc-linux-nat.c |  2 +-
 gdb/valops.c        |  4 +--
 gdb/valprint.c      |  2 +-
 gdb/value.c         | 48 +++++++++++++++++------------------
 gdb/value.h         | 72 ++++++++++++++++++++++++++---------------------------
 12 files changed, 82 insertions(+), 83 deletions(-)
---
base-commit: 5bed9dc992a0136d403a7addb29a2ed822fd4fd2
change-id: 20230214-submit-more-value-stuff-dea23b091773

Best regards,
-- 
Tom Tromey <tom@tromey.com>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/6] Change value::m_modifiable to bool
  2023-02-14 20:23 [PATCH 0/6] Use bool in value Tom Tromey
@ 2023-02-14 20:23 ` Tom Tromey
  2023-02-21 14:36   ` Alexandra Petlanova Hajkova
  2023-02-14 20:23 ` [PATCH 2/6] Change value::m_lazy " Tom Tromey
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Tom Tromey @ 2023-02-14 20:23 UTC (permalink / raw)
  To: gdb-patches

This changes value::m_modifiable to be a bool and updates the various
uses.
---
 gdb/breakpoint.c    | 3 +--
 gdb/ppc-linux-nat.c | 2 +-
 gdb/value.c         | 6 +++---
 gdb/value.h         | 8 ++++----
 4 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 3b9aebc5605..b1922fc1e98 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -10450,8 +10450,7 @@ can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals)
 		}
 	    }
 	}
-      else if (v->lval () != not_lval
-	       && v->deprecated_modifiable () == 0)
+      else if (v->lval () != not_lval && !v->deprecated_modifiable ())
 	return 0;	/* These are values from the history (e.g., $1).  */
       else if (v->lval () == lval_register)
 	return 0;	/* Cannot watch a register with a HW watchpoint.  */
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index 32c0177228a..494e9bf6119 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -2455,7 +2455,7 @@ ppc_linux_nat_target::num_memory_accesses (const std::vector<value_ref_ptr>
       struct value *v = iter.get ();
 
       /* Constants and values from the history are fine.  */
-      if (v->lval () == not_lval || v->deprecated_modifiable () == 0)
+      if (v->lval () == not_lval || !v->deprecated_modifiable ())
 	continue;
       else if (v->lval () == lval_memory)
 	{
diff --git a/gdb/value.c b/gdb/value.c
index 7873aeb9558..b027b63ee48 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1676,7 +1676,7 @@ value::record_latest ()
   /* We preserve VALUE_LVAL so that the user can find out where it was fetched
      from.  This is a bit dubious, because then *&$1 does not just return $1
      but the current contents of that location.  c'est la vie...  */
-  set_modifiable (0);
+  set_modifiable (false);
 
   value_history.push_back (release_value (this));
 
@@ -2169,7 +2169,7 @@ set_internalvar (struct internalvar *var, struct value *val)
     default:
       new_kind = INTERNALVAR_VALUE;
       struct value *copy = val->copy ();
-      copy->set_modifiable (1);
+      copy->set_modifiable (true);
 
       /* Force the value to be fetched from the target now, to avoid problems
 	 later when this internalvar is referenced and the target is gone or
@@ -2492,7 +2492,7 @@ value::from_xmethod (xmethod_worker_up &&worker)
   v = value::allocate (builtin_type (target_gdbarch ())->xmethod);
   v->m_lval = lval_xcallable;
   v->m_location.xm_worker = worker.release ();
-  v->m_modifiable = 0;
+  v->m_modifiable = false;
 
   return v;
 }
diff --git a/gdb/value.h b/gdb/value.h
index 8b45f7fdee8..92247185cd0 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -132,7 +132,7 @@ struct value
 
   /* Values can only be created via "static constructors".  */
   explicit value (struct type *type_)
-    : m_modifiable (1),
+    : m_modifiable (true),
       m_lazy (1),
       m_initialized (1),
       m_stack (0),
@@ -228,11 +228,11 @@ struct value
   /* The comment from "struct value" reads: ``Is it modifiable?  Only
      relevant if lval != not_lval.''.  Shouldn't the value instead be
      not_lval and be done with it?  */
-  int deprecated_modifiable () const
+  bool deprecated_modifiable () const
   { return m_modifiable; }
 
   /* Set or clear the modifiable flag.  */
-  void set_modifiable (int val)
+  void set_modifiable (bool val)
   { m_modifiable = val; }
 
   LONGEST pointed_to_offset () const
@@ -619,7 +619,7 @@ struct value
   enum lval_type m_lval = not_lval;
 
   /* Is it modifiable?  Only relevant if lval != not_lval.  */
-  unsigned int m_modifiable : 1;
+  bool m_modifiable : 1;
 
   /* If zero, contents of this value are in the contents field.  If
      nonzero, contents are in inferior.  If the lval field is lval_memory,

-- 
2.39.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 2/6] Change value::m_lazy to bool
  2023-02-14 20:23 [PATCH 0/6] Use bool in value Tom Tromey
  2023-02-14 20:23 ` [PATCH 1/6] Change value::m_modifiable to bool Tom Tromey
@ 2023-02-14 20:23 ` Tom Tromey
  2023-02-15 11:53   ` Bruno Larsen
  2023-02-14 20:23 ` [PATCH 3/6] Change value::m_initialized " Tom Tromey
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Tom Tromey @ 2023-02-14 20:23 UTC (permalink / raw)
  To: gdb-patches

This changes value::m_lazy to be a bool and updates the various uses.
---
 gdb/dwarf2/loc.c |  2 +-
 gdb/gnu-v2-abi.c |  2 +-
 gdb/valops.c     |  2 +-
 gdb/value.c      |  6 +++---
 gdb/value.h      | 16 ++++++++--------
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 27c4b7ce31a..0ab54abea9a 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -1366,7 +1366,7 @@ value_of_dwarf_reg_entry (struct type *type, frame_info_ptr frame,
   memcpy (val->contents_raw ().data (),
 	  outer_val->contents_raw ().data (),
 	  checked_type->length ());
-  val->set_lazy (0);
+  val->set_lazy (false);
 
   return val;
 }
diff --git a/gdb/gnu-v2-abi.c b/gdb/gnu-v2-abi.c
index fa46d474914..6afa1795ebd 100644
--- a/gdb/gnu-v2-abi.c
+++ b/gdb/gnu-v2-abi.c
@@ -163,7 +163,7 @@ gnuv2_virtual_fn_field (struct value **arg1p, struct fn_field * f, int j,
 
       if (!arg1->lazy ())
 	{
-	  arg1->set_lazy (1);
+	  arg1->set_lazy (true);
 	  arg1->fetch_lazy ();
 	}
 
diff --git a/gdb/valops.c b/gdb/valops.c
index 3901053c7d5..90f7b8c5532 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1343,7 +1343,7 @@ value_assign (struct value *toval, struct value *fromval)
      information, but its contents are updated from FROMVAL.  This
      implies the returned value is not lazy, even if TOVAL was.  */
   val = toval->copy ();
-  val->set_lazy (0);
+  val->set_lazy (false);
   copy (fromval->contents (), val->contents_raw ());
 
   /* We copy over the enclosing type and pointed-to offset from FROMVAL
diff --git a/gdb/value.c b/gdb/value.c
index b027b63ee48..855354f542f 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -990,7 +990,7 @@ value::allocate_optimized_out (struct type *type)
   struct value *retval = value::allocate_lazy (type);
 
   retval->mark_bytes_optimized_out (0, type->length ());
-  retval->set_lazy (0);
+  retval->set_lazy (false);
   return retval;
 }
 
@@ -3809,7 +3809,7 @@ value::fetch_lazy_register ()
 
   /* Copy the contents and the unavailability/optimized-out
      meta-data from NEW_VAL to VAL.  */
-  set_lazy (0);
+  set_lazy (false);
   new_val->contents_copy (this, embedded_offset (),
 			  new_val->embedded_offset (),
 			  type_length_units (type));
@@ -3893,7 +3893,7 @@ value::fetch_lazy ()
   else
     internal_error (_("Unexpected lazy value type."));
 
-  set_lazy (0);
+  set_lazy (false);
 }
 
 /* Implementation of the convenience function $_isvoid.  */
diff --git a/gdb/value.h b/gdb/value.h
index 92247185cd0..233f42d32a0 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -133,7 +133,7 @@ struct value
   /* Values can only be created via "static constructors".  */
   explicit value (struct type *type_)
     : m_modifiable (true),
-      m_lazy (1),
+      m_lazy (true),
       m_initialized (1),
       m_stack (0),
       m_is_zero (false),
@@ -247,8 +247,8 @@ struct value
   void set_embedded_offset (LONGEST val)
   { m_embedded_offset = val; }
 
-  /* If zero, contents of this value are in the contents field.  If
-     nonzero, contents are in inferior.  If the lval field is lval_memory,
+  /* If false, contents of this value are in the contents field.  If
+     true, contents are in inferior.  If the lval field is lval_memory,
      the contents are in inferior memory at location.address plus offset.
      The lval field may also be lval_register.
 
@@ -262,10 +262,10 @@ struct value
      element.  If you ever change the way lazy flag is set and reset, be
      sure to consider this use as well!  */
 
-  int lazy () const
+  bool lazy () const
   { return m_lazy; }
 
-  void set_lazy (int val)
+  void set_lazy (bool val)
   { m_lazy = val; }
 
   /* If a value represents a C++ object, then the `type' field gives the
@@ -621,8 +621,8 @@ struct value
   /* Is it modifiable?  Only relevant if lval != not_lval.  */
   bool m_modifiable : 1;
 
-  /* If zero, contents of this value are in the contents field.  If
-     nonzero, contents are in inferior.  If the lval field is lval_memory,
+  /* If false, contents of this value are in the contents field.  If
+     true, contents are in inferior.  If the lval field is lval_memory,
      the contents are in inferior memory at location.address plus offset.
      The lval field may also be lval_register.
 
@@ -635,7 +635,7 @@ struct value
      or array when the user wants to watch a single struct member or
      array element.  If you ever change the way lazy flag is set and
      reset, be sure to consider this use as well!  */
-  unsigned int m_lazy : 1;
+  bool m_lazy : 1;
 
   /* If value is a variable, is it initialized or not.  */
   unsigned int m_initialized : 1;

-- 
2.39.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 3/6] Change value::m_initialized to bool
  2023-02-14 20:23 [PATCH 0/6] Use bool in value Tom Tromey
  2023-02-14 20:23 ` [PATCH 1/6] Change value::m_modifiable to bool Tom Tromey
  2023-02-14 20:23 ` [PATCH 2/6] Change value::m_lazy " Tom Tromey
@ 2023-02-14 20:23 ` Tom Tromey
  2023-02-21 15:10   ` Alexandra Petlanova Hajkova
  2023-02-14 20:23 ` [PATCH 4/6] Change value::m_stack " Tom Tromey
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Tom Tromey @ 2023-02-14 20:23 UTC (permalink / raw)
  To: gdb-patches

This changes value::m_initialized to be a bool and updates the various
uses.
---
 gdb/dwarf2/expr.c |  4 ++--
 gdb/dwarf2/expr.h |  6 +++---
 gdb/value.h       | 10 +++++-----
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index 60d9bf5f1f9..760c5c4b0d0 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -1496,7 +1496,7 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
   type *address_type = this->address_type ();
 
   this->m_location = DWARF_VALUE_MEMORY;
-  this->m_initialized = 1;  /* Default is initialized.  */
+  this->m_initialized = true;  /* Default is initialized.  */
 
   if (this->m_recursion_depth > this->m_max_recursion_depth)
     error (_("DWARF-2 expression error: Loop detected (%d)."),
@@ -2192,7 +2192,7 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
 	    error (_("DWARF-2 expression error: DW_OP_GNU_uninit must always "
 		   "be the very last op."));
 
-	  this->m_initialized = 0;
+	  this->m_initialized = false;
 	  goto no_push;
 
 	case DW_OP_call2:
diff --git a/gdb/dwarf2/expr.h b/gdb/dwarf2/expr.h
index 44fc645116a..7a64316160e 100644
--- a/gdb/dwarf2/expr.h
+++ b/gdb/dwarf2/expr.h
@@ -164,9 +164,9 @@ struct dwarf_expr_context
   ULONGEST m_len = 0;
   const gdb_byte *m_data = nullptr;
 
-  /* Initialization status of variable: Non-zero if variable has been
-     initialized; zero otherwise.  */
-  int m_initialized = 0;
+  /* Initialization status of variable: True if variable has been
+     initialized; false otherwise.  */
+  bool m_initialized = false;
 
   /* A vector of pieces.
 
diff --git a/gdb/value.h b/gdb/value.h
index 233f42d32a0..41327ebe3b8 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -134,7 +134,7 @@ struct value
   explicit value (struct type *type_)
     : m_modifiable (true),
       m_lazy (true),
-      m_initialized (1),
+      m_initialized (true),
       m_stack (0),
       m_is_zero (false),
       m_in_history (false),
@@ -338,11 +338,11 @@ struct value
 
   /* Set or return field indicating whether a variable is initialized or
      not, based on debugging information supplied by the compiler.
-     1 = initialized; 0 = uninitialized.  */
-  int initialized () const
+     true = initialized; false = uninitialized.  */
+  bool initialized () const
   { return m_initialized; }
 
-  void set_initialized (int value)
+  void set_initialized (bool value)
   { m_initialized = value; }
 
   /* If lval == lval_memory, return the address in the inferior.  If
@@ -638,7 +638,7 @@ struct value
   bool m_lazy : 1;
 
   /* If value is a variable, is it initialized or not.  */
-  unsigned int m_initialized : 1;
+  bool m_initialized : 1;
 
   /* If value is from the stack.  If this is set, read_stack will be
      used instead of read_memory to enable extra caching.  */

-- 
2.39.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 4/6] Change value::m_stack to bool
  2023-02-14 20:23 [PATCH 0/6] Use bool in value Tom Tromey
                   ` (2 preceding siblings ...)
  2023-02-14 20:23 ` [PATCH 3/6] Change value::m_initialized " Tom Tromey
@ 2023-02-14 20:23 ` Tom Tromey
  2023-02-21 15:30   ` Alexandra Petlanova Hajkova
  2023-02-14 20:23 ` [PATCH 5/6] Have value::bits_synthetic_pointer return bool Tom Tromey
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Tom Tromey @ 2023-02-14 20:23 UTC (permalink / raw)
  To: gdb-patches

This changes value::m_stack to be a bool and updates the various uses.
---
 gdb/dwarf2/expr.c  |  2 +-
 gdb/frame-unwind.c |  2 +-
 gdb/valops.c       |  2 +-
 gdb/value.c        |  2 +-
 gdb/value.h        | 10 +++++-----
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index 760c5c4b0d0..3f040e7b2d3 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -1005,7 +1005,7 @@ dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type,
 	    retval = value_at_lazy (subobj_type,
 				    address + subobj_offset);
 	    if (in_stack_memory)
-	      retval->set_stack (1);
+	      retval->set_stack (true);
 	  }
 	  break;
 
diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
index e5f8dc639e3..a3673dde77a 100644
--- a/gdb/frame-unwind.c
+++ b/gdb/frame-unwind.c
@@ -289,7 +289,7 @@ frame_unwind_got_memory (frame_info_ptr frame, int regnum, CORE_ADDR addr)
   struct gdbarch *gdbarch = frame_unwind_arch (frame);
   struct value *v = value_at_lazy (register_type (gdbarch, regnum), addr);
 
-  v->set_stack (1);
+  v->set_stack (true);
   return v;
 }
 
diff --git a/gdb/valops.c b/gdb/valops.c
index 90f7b8c5532..3a1b14c3d44 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1041,7 +1041,7 @@ value_at_lazy (struct type *type, CORE_ADDR addr)
 
 void
 read_value_memory (struct value *val, LONGEST bit_offset,
-		   int stack, CORE_ADDR memaddr,
+		   bool stack, CORE_ADDR memaddr,
 		   gdb_byte *buffer, size_t length)
 {
   ULONGEST xfered_total = 0;
diff --git a/gdb/value.c b/gdb/value.c
index 855354f542f..6a8c12823c4 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3743,7 +3743,7 @@ value::fetch_lazy_memory ()
   gdb_assert (len >= 0);
 
   if (len > 0)
-    read_value_memory (this, 0, stack (), addr,
+    read_value_memory (this, false, stack (), addr,
 		       contents_all_raw ().data (), len);
 }
 
diff --git a/gdb/value.h b/gdb/value.h
index 41327ebe3b8..4cb6fac4104 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -135,7 +135,7 @@ struct value
     : m_modifiable (true),
       m_lazy (true),
       m_initialized (true),
-      m_stack (0),
+      m_stack (false),
       m_is_zero (false),
       m_in_history (false),
       m_type (type_),
@@ -314,10 +314,10 @@ struct value
 
   void set_enclosing_type (struct type *new_type);
 
-  int stack () const
+  bool stack () const
   { return m_stack; }
 
-  void set_stack (int val)
+  void set_stack (bool val)
   { m_stack = val; }
 
   /* If this value is lval_computed, return its lval_funcs
@@ -642,7 +642,7 @@ struct value
 
   /* If value is from the stack.  If this is set, read_stack will be
      used instead of read_memory to enable extra caching.  */
-  unsigned int m_stack : 1;
+  bool m_stack : 1;
 
   /* True if this is a zero value, created by 'value::zero'; false
      otherwise.  */
@@ -1000,7 +1000,7 @@ extern struct value *coerce_array (struct value *value);
    whether the memory is known to be stack memory.  */
 
 extern void read_value_memory (struct value *val, LONGEST bit_offset,
-			       int stack, CORE_ADDR memaddr,
+			       bool stack, CORE_ADDR memaddr,
 			       gdb_byte *buffer, size_t length);
 
 /* Cast SCALAR_VALUE to the element type of VECTOR_TYPE, then replicate

-- 
2.39.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 5/6] Have value::bits_synthetic_pointer return bool
  2023-02-14 20:23 [PATCH 0/6] Use bool in value Tom Tromey
                   ` (3 preceding siblings ...)
  2023-02-14 20:23 ` [PATCH 4/6] Change value::m_stack " Tom Tromey
@ 2023-02-14 20:23 ` Tom Tromey
  2023-02-14 20:23 ` [PATCH 6/6] Return bool from more value methods Tom Tromey
  2023-02-15 12:22 ` [PATCH 0/6] Use bool in value Bruno Larsen
  6 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2023-02-14 20:23 UTC (permalink / raw)
  To: gdb-patches

This changes value::bits_synthetic_pointer to return bool and fixes up
some fallout from this.
---
 gdb/dwarf2/expr.c |  6 +++---
 gdb/opencl-lang.c | 10 +++++-----
 gdb/valprint.c    |  2 +-
 gdb/value.c       |  4 ++--
 gdb/value.h       |  6 +++---
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index 3f040e7b2d3..b48bab0b410 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -459,7 +459,7 @@ is_optimized_out_pieced_value (value *v)
 /* An implementation of an lval_funcs method to see whether a value is
    a synthetic pointer.  */
 
-static int
+static bool
 check_pieced_synthetic_pointer (const value *value, LONGEST bit_offset,
 				int bit_length)
 {
@@ -490,10 +490,10 @@ check_pieced_synthetic_pointer (const value *value, LONGEST bit_offset,
 	bit_length -= this_size_bits;
 
       if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
-	return 0;
+	return false;
     }
 
-  return 1;
+  return true;
 }
 
 /* An implementation of an lval_funcs method to indirect through a
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 3e4a9c360b2..ae1a6d4446d 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -187,10 +187,10 @@ lval_func_write (struct value *v, struct value *fromval)
     }
 }
 
-/* Return nonzero if bits in V from OFFSET and LENGTH represent a
+/* Return true if bits in V from OFFSET and LENGTH represent a
    synthetic pointer.  */
 
-static int
+static bool
 lval_func_check_synthetic_pointer (const struct value *v,
 				   LONGEST offset, int length)
 {
@@ -208,7 +208,7 @@ lval_func_check_synthetic_pointer (const struct value *v,
     end++;
 
   if (end > c->n)
-    return 0;
+    return false;
 
   for (i = start; i < end; i++)
     {
@@ -217,10 +217,10 @@ lval_func_check_synthetic_pointer (const struct value *v,
 
       if (!c->val->bits_synthetic_pointer (c->indices[i] * elsize + comp_offset,
 					   comp_length))
-	return 0;
+	return false;
     }
 
-  return 1;
+  return true;
 }
 
 static void *
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 8c067693492..357db3815b0 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -566,7 +566,7 @@ generic_val_print_ref (struct type *type,
 {
   struct type *elttype = check_typedef (type->target_type ());
   struct value *deref_val = NULL;
-  const int value_is_synthetic
+  const bool value_is_synthetic
     = original_value->bits_synthetic_pointer (TARGET_CHAR_BIT * embedded_offset,
 					      TARGET_CHAR_BIT * type->length ());
   const int must_coerce_ref = ((options->addressprint && value_is_synthetic)
diff --git a/gdb/value.c b/gdb/value.c
index 6a8c12823c4..9e561e28551 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1315,12 +1315,12 @@ value::mark_bits_optimized_out (LONGEST offset, LONGEST length)
   insert_into_bit_range_vector (&m_optimized_out, offset, length);
 }
 
-int
+bool
 value::bits_synthetic_pointer (LONGEST offset, LONGEST length) const
 {
   if (m_lval != lval_computed
       || !m_location.computed.funcs->check_synthetic_pointer)
-    return 0;
+    return false;
   return m_location.computed.funcs->check_synthetic_pointer (this, offset,
 							     length);
 }
diff --git a/gdb/value.h b/gdb/value.h
index 4cb6fac4104..5536e00332e 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -475,7 +475,7 @@ struct value
   /* Given a value, determine whether the bits starting at OFFSET and
      extending for LENGTH bits are a synthetic pointer.  */
 
-  int bits_synthetic_pointer (LONGEST offset, LONGEST length) const;
+  bool bits_synthetic_pointer (LONGEST offset, LONGEST length) const;
 
   /* Increase this value's reference count.  */
   void incref ()
@@ -924,8 +924,8 @@ struct lval_funcs
 
   /* If non-NULL, this is used to determine whether the indicated bits
      of VALUE are a synthetic pointer.  */
-  int (*check_synthetic_pointer) (const struct value *value,
-				  LONGEST offset, int length);
+  bool (*check_synthetic_pointer) (const struct value *value,
+				   LONGEST offset, int length);
 
   /* Return a duplicate of VALUE's closure, for use in a new value.
      This may simply return the same closure, if VALUE's is

-- 
2.39.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 6/6] Return bool from more value methods
  2023-02-14 20:23 [PATCH 0/6] Use bool in value Tom Tromey
                   ` (4 preceding siblings ...)
  2023-02-14 20:23 ` [PATCH 5/6] Have value::bits_synthetic_pointer return bool Tom Tromey
@ 2023-02-14 20:23 ` Tom Tromey
  2023-02-15 12:22 ` [PATCH 0/6] Use bool in value Bruno Larsen
  6 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2023-02-14 20:23 UTC (permalink / raw)
  To: gdb-patches

There are several more value methods that currently return 'int' but
that should return 'bool'.  This patch updates these.
---
 gdb/value.c | 30 +++++++++++++++---------------
 gdb/value.h | 22 +++++++++++-----------
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/gdb/value.c b/gdb/value.c
index 9e561e28551..1943ef06321 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -69,7 +69,7 @@ struct internal_function
 /* Returns true if the ranges defined by [offset1, offset1+len1) and
    [offset2, offset2+len2) overlap.  */
 
-static int
+static bool
 ranges_overlap (LONGEST offset1, ULONGEST len1,
 		LONGEST offset2, ULONGEST len2)
 {
@@ -83,7 +83,7 @@ ranges_overlap (LONGEST offset1, ULONGEST len1,
 /* Returns true if RANGES contains any range that overlaps [OFFSET,
    OFFSET+LENGTH).  */
 
-static int
+static bool
 ranges_contain (const std::vector<range> &ranges, LONGEST offset,
 		ULONGEST length)
 {
@@ -131,7 +131,7 @@ ranges_contain (const std::vector<range> &ranges, LONGEST offset,
       const struct range &bef = *(i - 1);
 
       if (ranges_overlap (bef.offset, bef.length, offset, length))
-	return 1;
+	return true;
     }
 
   if (i < ranges.end ())
@@ -139,10 +139,10 @@ ranges_contain (const std::vector<range> &ranges, LONGEST offset,
       const struct range &r = *i;
 
       if (ranges_overlap (r.offset, r.length, offset, length))
-	return 1;
+	return true;
     }
 
-  return 0;
+  return false;
 }
 
 static struct cmd_list_element *functionlist;
@@ -168,7 +168,7 @@ value::arch () const
   return type ()->arch ();
 }
 
-int
+bool
 value::bits_available (LONGEST offset, ULONGEST length) const
 {
   gdb_assert (!m_lazy);
@@ -182,7 +182,7 @@ value::bits_available (LONGEST offset, ULONGEST length) const
 	   || ranges_contain (m_unavailable, offset, length));
 }
 
-int
+bool
 value::bytes_available (LONGEST offset, ULONGEST length) const
 {
   ULONGEST sign = (1ULL << (sizeof (ULONGEST) * 8 - 1)) / TARGET_CHAR_BIT;
@@ -196,7 +196,7 @@ value::bytes_available (LONGEST offset, ULONGEST length) const
   return bits_available (offset * TARGET_CHAR_BIT, length * TARGET_CHAR_BIT);
 }
 
-int
+bool
 value::bits_any_optimized_out (int bit_offset, int bit_length) const
 {
   gdb_assert (!m_lazy);
@@ -204,7 +204,7 @@ value::bits_any_optimized_out (int bit_offset, int bit_length) const
   return ranges_contain (m_optimized_out, bit_offset, bit_length);
 }
 
-int
+bool
 value::entirely_available ()
 {
   /* We can only tell whether the whole value is available when we try
@@ -213,13 +213,13 @@ value::entirely_available ()
     fetch_lazy ();
 
   if (m_unavailable.empty ())
-    return 1;
-  return 0;
+    return true;
+  return false;
 }
 
 /* See value.h.  */
 
-int
+bool
 value::entirely_covered_by_range_vector (const std::vector<range> &ranges)
 {
   /* We can only tell whether the whole value is optimized out /
@@ -233,10 +233,10 @@ value::entirely_covered_by_range_vector (const std::vector<range> &ranges)
 
       if (t.offset == 0
 	  && t.length == TARGET_CHAR_BIT * enclosing_type ()->length ())
-	return 1;
+	return true;
     }
 
-  return 0;
+  return false;
 }
 
 /* Insert into the vector pointed to by VECTORP the bit range starting of
@@ -1255,7 +1255,7 @@ value::contents_writeable ()
   return contents_raw ();
 }
 
-int
+bool
 value::optimized_out ()
 {
   if (m_lazy)
diff --git a/gdb/value.h b/gdb/value.h
index 5536e00332e..f2a4907ab81 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -487,23 +487,23 @@ struct 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
+     true if all bytes in the given range are available, false if any
      byte is unavailable.  */
-  int bytes_available (LONGEST offset, ULONGEST length) const;
+  bool 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
+     true if all bits in the given range are available, false if any
      bit is unavailable.  */
-  int bits_available (LONGEST offset, ULONGEST length) const;
+  bool 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 ();
+  bool entirely_available ();
 
   /* Like entirely_available, but return false if any byte in the
      whole object is available.  */
-  int entirely_unavailable ()
+  bool entirely_unavailable ()
   { return entirely_covered_by_range_vector (m_unavailable); }
 
   /* Mark this value's content bytes starting at OFFSET and extending
@@ -514,19 +514,19 @@ struct value
      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
+  /* If true, 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 ();
+  bool 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;
+  bool 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 ()
+  bool entirely_optimized_out ()
   {
     return entirely_covered_by_range_vector (m_optimized_out);
   }
@@ -829,7 +829,7 @@ struct value
   /* 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);
+  bool entirely_covered_by_range_vector (const std::vector<range> &ranges);
 
   /* Copy the ranges metadata from this value that overlaps
      [SRC_BIT_OFFSET, SRC_BIT_OFFSET+BIT_LENGTH) into DST,

-- 
2.39.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/6] Change value::m_lazy to bool
  2023-02-14 20:23 ` [PATCH 2/6] Change value::m_lazy " Tom Tromey
@ 2023-02-15 11:53   ` Bruno Larsen
  2023-02-15 21:52     ` Tom Tromey
  0 siblings, 1 reply; 14+ messages in thread
From: Bruno Larsen @ 2023-02-15 11:53 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 14/02/2023 21:23, Tom Tromey wrote:
> This changes value::m_lazy to be a bool and updates the various uses.

You've missed an occurrence of val->m_lazy = 0 on the function 
value::allocate in gdb/value.c

Other than that, Reviewed-By: Bruno Larsen <blarsen@redhat.com>

-- 
Cheers,
Bruno

> ---
>   gdb/dwarf2/loc.c |  2 +-
>   gdb/gnu-v2-abi.c |  2 +-
>   gdb/valops.c     |  2 +-
>   gdb/value.c      |  6 +++---
>   gdb/value.h      | 16 ++++++++--------
>   5 files changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
> index 27c4b7ce31a..0ab54abea9a 100644
> --- a/gdb/dwarf2/loc.c
> +++ b/gdb/dwarf2/loc.c
> @@ -1366,7 +1366,7 @@ value_of_dwarf_reg_entry (struct type *type, frame_info_ptr frame,
>     memcpy (val->contents_raw ().data (),
>   	  outer_val->contents_raw ().data (),
>   	  checked_type->length ());
> -  val->set_lazy (0);
> +  val->set_lazy (false);
>   
>     return val;
>   }
> diff --git a/gdb/gnu-v2-abi.c b/gdb/gnu-v2-abi.c
> index fa46d474914..6afa1795ebd 100644
> --- a/gdb/gnu-v2-abi.c
> +++ b/gdb/gnu-v2-abi.c
> @@ -163,7 +163,7 @@ gnuv2_virtual_fn_field (struct value **arg1p, struct fn_field * f, int j,
>   
>         if (!arg1->lazy ())
>   	{
> -	  arg1->set_lazy (1);
> +	  arg1->set_lazy (true);
>   	  arg1->fetch_lazy ();
>   	}
>   
> diff --git a/gdb/valops.c b/gdb/valops.c
> index 3901053c7d5..90f7b8c5532 100644
> --- a/gdb/valops.c
> +++ b/gdb/valops.c
> @@ -1343,7 +1343,7 @@ value_assign (struct value *toval, struct value *fromval)
>        information, but its contents are updated from FROMVAL.  This
>        implies the returned value is not lazy, even if TOVAL was.  */
>     val = toval->copy ();
> -  val->set_lazy (0);
> +  val->set_lazy (false);
>     copy (fromval->contents (), val->contents_raw ());
>   
>     /* We copy over the enclosing type and pointed-to offset from FROMVAL
> diff --git a/gdb/value.c b/gdb/value.c
> index b027b63ee48..855354f542f 100644
> --- a/gdb/value.c
> +++ b/gdb/value.c
> @@ -990,7 +990,7 @@ value::allocate_optimized_out (struct type *type)
>     struct value *retval = value::allocate_lazy (type);
>   
>     retval->mark_bytes_optimized_out (0, type->length ());
> -  retval->set_lazy (0);
> +  retval->set_lazy (false);
>     return retval;
>   }
>   
> @@ -3809,7 +3809,7 @@ value::fetch_lazy_register ()
>   
>     /* Copy the contents and the unavailability/optimized-out
>        meta-data from NEW_VAL to VAL.  */
> -  set_lazy (0);
> +  set_lazy (false);
>     new_val->contents_copy (this, embedded_offset (),
>   			  new_val->embedded_offset (),
>   			  type_length_units (type));
> @@ -3893,7 +3893,7 @@ value::fetch_lazy ()
>     else
>       internal_error (_("Unexpected lazy value type."));
>   
> -  set_lazy (0);
> +  set_lazy (false);
>   }
>   
>   /* Implementation of the convenience function $_isvoid.  */
> diff --git a/gdb/value.h b/gdb/value.h
> index 92247185cd0..233f42d32a0 100644
> --- a/gdb/value.h
> +++ b/gdb/value.h
> @@ -133,7 +133,7 @@ struct value
>     /* Values can only be created via "static constructors".  */
>     explicit value (struct type *type_)
>       : m_modifiable (true),
> -      m_lazy (1),
> +      m_lazy (true),
>         m_initialized (1),
>         m_stack (0),
>         m_is_zero (false),
> @@ -247,8 +247,8 @@ struct value
>     void set_embedded_offset (LONGEST val)
>     { m_embedded_offset = val; }
>   
> -  /* If zero, contents of this value are in the contents field.  If
> -     nonzero, contents are in inferior.  If the lval field is lval_memory,
> +  /* If false, contents of this value are in the contents field.  If
> +     true, contents are in inferior.  If the lval field is lval_memory,
>        the contents are in inferior memory at location.address plus offset.
>        The lval field may also be lval_register.
>   
> @@ -262,10 +262,10 @@ struct value
>        element.  If you ever change the way lazy flag is set and reset, be
>        sure to consider this use as well!  */
>   
> -  int lazy () const
> +  bool lazy () const
>     { return m_lazy; }
>   
> -  void set_lazy (int val)
> +  void set_lazy (bool val)
>     { m_lazy = val; }
>   
>     /* If a value represents a C++ object, then the `type' field gives the
> @@ -621,8 +621,8 @@ struct value
>     /* Is it modifiable?  Only relevant if lval != not_lval.  */
>     bool m_modifiable : 1;
>   
> -  /* If zero, contents of this value are in the contents field.  If
> -     nonzero, contents are in inferior.  If the lval field is lval_memory,
> +  /* If false, contents of this value are in the contents field.  If
> +     true, contents are in inferior.  If the lval field is lval_memory,
>        the contents are in inferior memory at location.address plus offset.
>        The lval field may also be lval_register.
>   
> @@ -635,7 +635,7 @@ struct value
>        or array when the user wants to watch a single struct member or
>        array element.  If you ever change the way lazy flag is set and
>        reset, be sure to consider this use as well!  */
> -  unsigned int m_lazy : 1;
> +  bool m_lazy : 1;
>   
>     /* If value is a variable, is it initialized or not.  */
>     unsigned int m_initialized : 1;
>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/6] Use bool in value
  2023-02-14 20:23 [PATCH 0/6] Use bool in value Tom Tromey
                   ` (5 preceding siblings ...)
  2023-02-14 20:23 ` [PATCH 6/6] Return bool from more value methods Tom Tromey
@ 2023-02-15 12:22 ` Bruno Larsen
  2023-02-15 21:54   ` Tom Tromey
  6 siblings, 1 reply; 14+ messages in thread
From: Bruno Larsen @ 2023-02-15 12:22 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 14/02/2023 21:23, Tom Tromey wrote:
> There are a few spots in struct value that should use 'bool'.  This
> short series fixes these up.
>
> Regression tested on x86-64 Fedora 36.
>
> ---
> Tom Tromey (6):
>        Change value::m_modifiable to bool
>        Change value::m_lazy to bool
>        Change value::m_initialized to bool
>        Change value::m_stack to bool
>        Have value::bits_synthetic_pointer return bool
>        Return bool from more value methods
>
>   gdb/breakpoint.c    |  3 +--
>   gdb/dwarf2/expr.c   | 12 ++++-----
>   gdb/dwarf2/expr.h   |  6 ++---
>   gdb/dwarf2/loc.c    |  2 +-
>   gdb/frame-unwind.c  |  2 +-
>   gdb/gnu-v2-abi.c    |  2 +-
>   gdb/opencl-lang.c   | 10 ++++----
>   gdb/ppc-linux-nat.c |  2 +-
>   gdb/valops.c        |  4 +--
>   gdb/valprint.c      |  2 +-
>   gdb/value.c         | 48 +++++++++++++++++------------------
>   gdb/value.h         | 72 ++++++++++++++++++++++++++---------------------------
>   12 files changed, 82 insertions(+), 83 deletions(-)
> ---
> base-commit: 5bed9dc992a0136d403a7addb29a2ed822fd4fd2
> change-id: 20230214-submit-more-value-stuff-dea23b091773
>
> Best regards,

I've double checked the testing and changes, and apart from a comment on 
patch #2 everything looks ready to go. You may apply my tag to the whole 
series:

Reviewed-By: Bruno Larsen <blarsen@redhat.com>

-- 
Cheers,
Bruno


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/6] Change value::m_lazy to bool
  2023-02-15 11:53   ` Bruno Larsen
@ 2023-02-15 21:52     ` Tom Tromey
  0 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2023-02-15 21:52 UTC (permalink / raw)
  To: Bruno Larsen; +Cc: Tom Tromey, gdb-patches

Bruno> You've missed an occurrence of val->m_lazy = 0 on the function
Bruno> value::allocate in gdb/value.c

Thanks, I fixed this.

Tom

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/6] Use bool in value
  2023-02-15 12:22 ` [PATCH 0/6] Use bool in value Bruno Larsen
@ 2023-02-15 21:54   ` Tom Tromey
  0 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2023-02-15 21:54 UTC (permalink / raw)
  To: Bruno Larsen; +Cc: Tom Tromey, gdb-patches

Bruno> I've double checked the testing and changes, and apart from a comment
Bruno> on patch #2 everything looks ready to go. You may apply my tag to the
Bruno> whole series:

Bruno> Reviewed-By: Bruno Larsen <blarsen@redhat.com>

Thanks.  I'm going to check this in.

Tom

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/6] Change value::m_modifiable to bool
  2023-02-14 20:23 ` [PATCH 1/6] Change value::m_modifiable to bool Tom Tromey
@ 2023-02-21 14:36   ` Alexandra Petlanova Hajkova
  0 siblings, 0 replies; 14+ messages in thread
From: Alexandra Petlanova Hajkova @ 2023-02-21 14:36 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 191 bytes --]

On Tue, Feb 14, 2023 at 9:24 PM Tom Tromey <tom@tromey.com> wrote:

> This changes value::m_modifiable to be a bool and updates the various
> uses.
>
>
I think it's good to go in.

Alexandra

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/6] Change value::m_initialized to bool
  2023-02-14 20:23 ` [PATCH 3/6] Change value::m_initialized " Tom Tromey
@ 2023-02-21 15:10   ` Alexandra Petlanova Hajkova
  0 siblings, 0 replies; 14+ messages in thread
From: Alexandra Petlanova Hajkova @ 2023-02-21 15:10 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 194 bytes --]

On Tue, Feb 14, 2023 at 9:24 PM Tom Tromey <tom@tromey.com> wrote:

> This changes value::m_initialized to be a bool and updates the various
> uses.
>
> I think it looks good and is good to go.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/6] Change value::m_stack to bool
  2023-02-14 20:23 ` [PATCH 4/6] Change value::m_stack " Tom Tromey
@ 2023-02-21 15:30   ` Alexandra Petlanova Hajkova
  0 siblings, 0 replies; 14+ messages in thread
From: Alexandra Petlanova Hajkova @ 2023-02-21 15:30 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 176 bytes --]

On Tue, Feb 14, 2023 at 9:24 PM Tom Tromey <tom@tromey.com> wrote:

> This changes value::m_stack to be a bool and updates the various uses.
> ---
>
>
I think it's good to go.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-02-21 15:30 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 20:23 [PATCH 0/6] Use bool in value Tom Tromey
2023-02-14 20:23 ` [PATCH 1/6] Change value::m_modifiable to bool Tom Tromey
2023-02-21 14:36   ` Alexandra Petlanova Hajkova
2023-02-14 20:23 ` [PATCH 2/6] Change value::m_lazy " Tom Tromey
2023-02-15 11:53   ` Bruno Larsen
2023-02-15 21:52     ` Tom Tromey
2023-02-14 20:23 ` [PATCH 3/6] Change value::m_initialized " Tom Tromey
2023-02-21 15:10   ` Alexandra Petlanova Hajkova
2023-02-14 20:23 ` [PATCH 4/6] Change value::m_stack " Tom Tromey
2023-02-21 15:30   ` Alexandra Petlanova Hajkova
2023-02-14 20:23 ` [PATCH 5/6] Have value::bits_synthetic_pointer return bool Tom Tromey
2023-02-14 20:23 ` [PATCH 6/6] Return bool from more value methods Tom Tromey
2023-02-15 12:22 ` [PATCH 0/6] Use bool in value Bruno Larsen
2023-02-15 21:54   ` Tom Tromey

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).