public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Use scoped_value_mark in more places
@ 2022-10-14 17:38 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-10-14 17:38 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=65558ca5df91470521fda6b0bfdfbbdbd37ce4d3

commit 65558ca5df91470521fda6b0bfdfbbdbd37ce4d3
Author: Tom Tromey <tromey@adacore.com>
Date:   Mon Oct 3 13:51:58 2022 -0600

    Use scoped_value_mark in more places
    
    I looked at all the spots using value_mark, and converted all the
    straightforward ones to use scoped_value_mark instead.
    
    Regression tested on x86-64 Fedora 34.

Diff:
---
 gdb/ada-lang.c       | 12 ++++--------
 gdb/ada-valprint.c   |  5 ++---
 gdb/breakpoint.c     | 24 +++++++++---------------
 gdb/cli/cli-script.c | 32 ++++++++++++++++----------------
 gdb/gnu-nat.c        |  4 +---
 gdb/opencl-lang.c    |  5 ++---
 gdb/regcache.c       |  6 ++----
 gdb/valarith.c       |  3 +--
 8 files changed, 37 insertions(+), 54 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 0e3f0daa416..1f26394208a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -7858,7 +7858,6 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 				     CORE_ADDR address, struct value *dval0,
 				     int keep_dynamic_fields)
 {
-  struct value *mark = value_mark ();
   struct value *dval;
   struct type *rtype;
   int nfields, bit_len;
@@ -7867,6 +7866,8 @@ ada_template_to_fixed_record_type_1 (struct type *type,
   int fld_bit_len;
   int f;
 
+  scoped_value_mark mark;
+
   /* Compute the number of fields in this record type that are going
      to be processed: unless keep_dynamic_fields, this includes only
      fields whose position and length are static will be processed.  */
@@ -8068,7 +8069,6 @@ ada_template_to_fixed_record_type_1 (struct type *type,
   else
     rtype->set_length (align_up (rtype->length (), type->length ()));
 
-  value_free_to_mark (mark);
   return rtype;
 }
 
@@ -8169,7 +8169,6 @@ static struct type *
 to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
 				   CORE_ADDR address, struct value *dval0)
 {
-  struct value *mark = value_mark ();
   struct value *dval;
   struct type *rtype;
   struct type *branch_type;
@@ -8179,6 +8178,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
   if (variant_field == -1)
     return type;
 
+  scoped_value_mark mark;
   if (dval0 == NULL)
     {
       dval = value_from_contents_and_address (type, valaddr, address);
@@ -8228,7 +8228,6 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
   rtype->set_length (rtype->length ()
 		     - type->field (variant_field).type ()->length ());
 
-  value_free_to_mark (mark);
   return rtype;
 }
 
@@ -12311,11 +12310,8 @@ should_stop_exception (const struct bp_location *bl)
   stop = true;
   try
     {
-      struct value *mark;
-
-      mark = value_mark ();
+      scoped_value_mark mark;
       stop = value_true (evaluate_expression (ada_loc->excep_cond_expr.get ()));
-      value_free_to_mark (mark);
     }
   catch (const gdb_exception &ex)
     {
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 59f0be480d4..40c26145224 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -127,9 +127,10 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
   unsigned len;
   struct type *elttype, *index_type;
   unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
-  struct value *mark = value_mark ();
   LONGEST low = 0;
 
+  scoped_value_mark mark;
+
   elttype = type->target_type ();
   index_type = type->index_type ();
 
@@ -251,8 +252,6 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
     {
       gdb_printf (stream, "...");
     }
-
-  value_free_to_mark (mark);
 }
 
 /* Print the character C on STREAM as part of the contents of a literal
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e9aee6315fa..f6591d43871 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -4837,11 +4837,8 @@ bpstat_print (bpstat *bs, target_waitkind kind)
 static bool
 breakpoint_cond_eval (expression *exp)
 {
-  struct value *mark = value_mark ();
-  bool res = value_true (evaluate_expression (exp));
-
-  value_free_to_mark (mark);
-  return res;
+  scoped_value_mark mark;
+  return value_true (evaluate_expression (exp));
 }
 
 /* Allocate a new bpstat.  Link it to the FIFO list by BS_LINK_POINTER.  */
@@ -5363,12 +5360,11 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
       int within_current_scope = 1;
       struct watchpoint * w;
 
-      /* We use value_mark and value_free_to_mark because it could
-	 be a long time before we return to the command level and
-	 call free_all_values.  We can't call free_all_values
-	 because we might be in the middle of evaluating a
-	 function call.  */
-      struct value *mark = value_mark ();
+      /* We use scoped_value_mark because it could be a long time
+	 before we return to the command level and call
+	 free_all_values.  We can't call free_all_values because we
+	 might be in the middle of evaluating a function call.  */
+      scoped_value_mark mark;
 
       if (is_watchpoint (b))
 	w = (struct watchpoint *) b;
@@ -5427,7 +5423,6 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
 	     watchpoint, unconditionally report it.  */
 	}
       /* FIXME-someday, should give breakpoint #.  */
-      value_free_to_mark (mark);
     }
 
   if (cond != nullptr && !condition_result)
@@ -9979,17 +9974,16 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
 	      /* We've found a "mask" token, which means the user wants to
 		 create a hardware watchpoint that is going to have the mask
 		 facility.  */
-	      struct value *mask_value, *mark;
+	      struct value *mask_value;
 
 	      if (use_mask)
 		error(_("You can specify only one mask."));
 
 	      use_mask = just_location = true;
 
-	      mark = value_mark ();
+	      scoped_value_mark mark;
 	      mask_value = parse_to_comma_and_eval (&value_start);
 	      mask = value_as_address (mask_value);
-	      value_free_to_mark (mark);
 	    }
 	  else
 	    /* We didn't recognize what we found.  We should stop here.  */
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 6c67b60e721..22e3efa5643 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -512,8 +512,6 @@ static enum command_control_type
 execute_control_command_1 (struct command_line *cmd, int from_tty)
 {
   struct command_line *current;
-  struct value *val;
-  struct value *val_mark;
   int loop;
   enum command_control_type ret;
 
@@ -567,10 +565,11 @@ execute_control_command_1 (struct command_line *cmd, int from_tty)
 	    QUIT;
 
 	    /* Evaluate the expression.  */
-	    val_mark = value_mark ();
-	    val = evaluate_expression (expr.get ());
-	    cond_result = value_true (val);
-	    value_free_to_mark (val_mark);
+	    {
+	      scoped_value_mark mark;
+	      value *val = evaluate_expression (expr.get ());
+	      cond_result = value_true (val);
+	    }
 
 	    /* If the value is false, then break out of the loop.  */
 	    if (!cond_result)
@@ -621,16 +620,17 @@ execute_control_command_1 (struct command_line *cmd, int from_tty)
 	ret = simple_control;
 
 	/* Evaluate the conditional.  */
-	val_mark = value_mark ();
-	val = evaluate_expression (expr.get ());
-
-	/* Choose which arm to take commands from based on the value
-	   of the conditional expression.  */
-	if (value_true (val))
-	  current = cmd->body_list_0.get ();
-	else if (cmd->body_list_1 != nullptr)
-	  current = cmd->body_list_1.get ();
-	value_free_to_mark (val_mark);
+	{
+	  scoped_value_mark mark;
+	  value *val = evaluate_expression (expr.get ());
+
+	  /* Choose which arm to take commands from based on the value
+	     of the conditional expression.  */
+	  if (value_true (val))
+	    current = cmd->body_list_0.get ();
+	  else if (cmd->body_list_1 != nullptr)
+	    current = cmd->body_list_1.get ();
+	}
 
 	/* Execute commands in the given arm.  */
 	while (current)
diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index 5dd4d148c76..ae049cab3de 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -3062,7 +3062,7 @@ static void
 info_port_rights (const char *args, mach_port_type_t only)
 {
   struct inf *inf = active_inf ();
-  struct value *vmark = value_mark ();
+  scoped_value_mark vmark;
 
   if (args)
     /* Explicit list of port rights.  */
@@ -3088,8 +3088,6 @@ info_port_rights (const char *args, mach_port_type_t only)
       if (err)
 	error (_("%s."), safe_strerror (err));
     }
-
-  value_free_to_mark (vmark);
 }
 
 static void
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index c88b3fe6bbd..e41db3dcbba 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -147,7 +147,8 @@ lval_func_read (struct value *v)
 static void
 lval_func_write (struct value *v, struct value *fromval)
 {
-  struct value *mark = value_mark ();
+  scoped_value_mark mark;
+
   struct lval_closure *c = (struct lval_closure *) value_computed_closure (v);
   struct type *type = check_typedef (value_type (v));
   struct type *eltype = check_typedef (value_type (c->val))->target_type ();
@@ -184,8 +185,6 @@ lval_func_write (struct value *v, struct value *fromval)
 	      elsize);
       value_assign (to_elm_val, from_elm_val);
     }
-
-  value_free_to_mark (mark);
 }
 
 /* Return nonzero if bits in V from OFFSET and LENGTH represent a
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 279bf2258a9..11565909d7d 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -708,10 +708,10 @@ readable_regcache::cooked_read (int regnum, gdb_byte *buf)
     }
   else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
     {
-      struct value *mark, *computed;
+      struct value *computed;
       enum register_status result = REG_VALID;
 
-      mark = value_mark ();
+      scoped_value_mark mark;
 
       computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch,
 						     this, regnum);
@@ -724,8 +724,6 @@ readable_regcache::cooked_read (int regnum, gdb_byte *buf)
 	  result = REG_UNAVAILABLE;
 	}
 
-      value_free_to_mark (mark);
-
       return result;
     }
   else
diff --git a/gdb/valarith.c b/gdb/valarith.c
index c0e937d6c25..7a9e130a576 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -1615,7 +1615,7 @@ vector_binop (struct value *val1, struct value *val2, enum exp_opcode op)
 
   value *val = allocate_value (type1);
   gdb::array_view<gdb_byte> val_contents = value_contents_writeable (val);
-  value *mark = value_mark ();
+  scoped_value_mark mark;
   for (i = 0; i < high_bound1 - low_bound1 + 1; i++)
     {
       value *tmp = value_binop (value_subscript (val1, i),
@@ -1623,7 +1623,6 @@ vector_binop (struct value *val1, struct value *val2, enum exp_opcode op)
       copy (value_contents_all (tmp),
 	    val_contents.slice (i * elsize, elsize));
      }
-  value_free_to_mark (mark);
 
   return val;
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-14 17:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-14 17:38 [binutils-gdb] Use scoped_value_mark in more places 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).