Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Tom Tromey <tom@tromey.com>
Cc: Pedro Alves <palves@redhat.com>,  gdb-patches@sourceware.org
Subject: Re: [RFA 6/8] Use value_freer in dwarf2_evaluate_loc_desc_full
Date: Fri, 23 Dec 2016 19:59:00 -0000	[thread overview]
Message-ID: <87poki5se8.fsf@tromey.com> (raw)
In-Reply-To: <87wpeq5uvy.fsf@tromey.com> (Tom Tromey's message of "Fri, 23 Dec	2016 12:05:05 -0700")

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> It looks good to me.  I've made this change and I'll send the new
Tom> patches soon.

Here's the new patch to add scoped_value_mark.

Tom

commit 6f8663e26b0498790d3314f0649c5c9c923a48a0
Author: Tom Tromey <tom@tromey.com>
Date:   Mon Nov 21 18:02:11 2016 -0700

    Add scoped_value_mark
    
    This adds a scoped_value_mark class, that records the value mark in
    the constructor and then calls value_free_to_mark in the destructor.
    It then updates various spots in gdb to use this class, rather than a
    cleanup.
    
    It would be better overall to replace "struct value *" with a
    shared_ptr, maybe eliminating the need for this class (watchpoints
    would perhaps need some new mechanism as well).  However, that's
    difficult to do.
    
    2016-12-13  Tom Tromey  <tom@tromey.com>
    
    	* python/py-value.c (valpy_dereference, valpy_referenced_value)
    	(valpy_reference_value, valpy_const_value, valpy_get_address)
    	(valpy_get_dynamic_type, valpy_lazy_string, valpy_do_cast)
    	(valpy_getitem, valpy_call, valpy_binop_throw, valpy_negative)
    	(valpy_absolute, valpy_richcompare_throw): Use scoped_value_mark.
    	* dwarf2loc.c (dwarf2_loc_desc_get_symbol_read_needs): Use
    	scoped_value_mark.
    	* dwarf2-frame.c (execute_stack_op): Use scoped_value_mark.
    	* value.h (scoped_value_mark): New class.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8d3c5b1..01ef9d6 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,17 @@
 2016-12-13  Tom Tromey  <tom@tromey.com>
 
+	* python/py-value.c (valpy_dereference, valpy_referenced_value)
+	(valpy_reference_value, valpy_const_value, valpy_get_address)
+	(valpy_get_dynamic_type, valpy_lazy_string, valpy_do_cast)
+	(valpy_getitem, valpy_call, valpy_binop_throw, valpy_negative)
+	(valpy_absolute, valpy_richcompare_throw): Use scoped_value_mark.
+	* dwarf2loc.c (dwarf2_loc_desc_get_symbol_read_needs): Use
+	scoped_value_mark.
+	* dwarf2-frame.c (execute_stack_op): Use scoped_value_mark.
+	* value.h (scoped_value_mark): New class.
+
+2016-12-13  Tom Tromey  <tom@tromey.com>
+
 	* dwarf2read.c (dwarf2_build_psymtabs): Use psymtab_discarder.
 	* psympriv.h (make_cleanup_discard_psymtabs): Don't declare.
 	* psymtab.c (discard_psymtabs_upto): Remove.
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index beab304..93647ab 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -403,10 +403,9 @@ execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size,
 		  CORE_ADDR initial, int initial_in_stack_memory)
 {
   CORE_ADDR result;
-  struct cleanup *old_chain;
 
   dwarf_expr_executor ctx;
-  old_chain = make_cleanup_value_free_to_mark (value_mark ());
+  scoped_value_mark free_values;
 
   ctx.this_frame = this_frame;
   ctx.gdbarch = get_frame_arch (this_frame);
@@ -430,8 +429,6 @@ execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size,
 Not implemented: computing unwound register using explicit value operator"));
     }
 
-  do_cleanups (old_chain);
-
   return result;
 }
 \f
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index d19f6a2..f5ab371 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2801,16 +2801,14 @@ dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size,
 				       struct dwarf2_per_cu_data *per_cu)
 {
   int in_reg;
-  struct cleanup *old_chain;
   struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
 
+  scoped_value_mark free_values;
+
   symbol_needs_eval_context ctx;
 
   ctx.needs = SYMBOL_NEEDS_NONE;
   ctx.per_cu = per_cu;
-
-  old_chain = make_cleanup_value_free_to_mark (value_mark ());
-
   ctx.gdbarch = get_objfile_arch (objfile);
   ctx.addr_size = dwarf2_per_cu_addr_size (per_cu);
   ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
@@ -2831,8 +2829,6 @@ dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size,
           in_reg = 1;
     }
 
-  do_cleanups (old_chain);
-
   if (in_reg)
     ctx.needs = SYMBOL_NEEDS_FRAME;
   return ctx.needs;
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index c1f3e16..f7ec202 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -178,11 +178,10 @@ valpy_dereference (PyObject *self, PyObject *args)
   TRY
     {
       struct value *res_val;
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
+      scoped_value_mark free_values;
 
       res_val = value_ind (((value_object *) self)->value);
       result = value_to_value_object (res_val);
-      do_cleanups (cleanup);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -209,7 +208,7 @@ valpy_referenced_value (PyObject *self, PyObject *args)
   TRY
     {
       struct value *self_val, *res_val;
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
+      scoped_value_mark free_values;
 
       self_val = ((value_object *) self)->value;
       switch (TYPE_CODE (check_typedef (value_type (self_val))))
@@ -226,7 +225,6 @@ valpy_referenced_value (PyObject *self, PyObject *args)
         }
 
       result = value_to_value_object (res_val);
-      do_cleanups (cleanup);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -247,12 +245,10 @@ valpy_reference_value (PyObject *self, PyObject *args)
   TRY
     {
       struct value *self_val;
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
+      scoped_value_mark free_values;
 
       self_val = ((value_object *) self)->value;
       result = value_to_value_object (value_ref (self_val));
-
-      do_cleanups (cleanup);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -273,13 +269,11 @@ valpy_const_value (PyObject *self, PyObject *args)
   TRY
     {
       struct value *self_val, *res_val;
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
+      scoped_value_mark free_values;
 
       self_val = ((value_object *) self)->value;
       res_val = make_cv_value (1, 0, self_val);
       result = value_to_value_object (res_val);
-
-      do_cleanups (cleanup);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -301,12 +295,10 @@ valpy_get_address (PyObject *self, void *closure)
       TRY
 	{
 	  struct value *res_val;
-	  struct cleanup *cleanup
-	    = make_cleanup_value_free_to_mark (value_mark ());
+	  scoped_value_mark free_values;
 
 	  res_val = value_addr (val_obj->value);
 	  val_obj->address = value_to_value_object (res_val);
-	  do_cleanups (cleanup);
 	}
       CATCH (except, RETURN_MASK_ALL)
 	{
@@ -354,7 +346,7 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
   TRY
     {
       struct value *val = obj->value;
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
+      scoped_value_mark free_values;
 
       type = value_type (val);
       type = check_typedef (type);
@@ -387,8 +379,6 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
 	  /* Re-use object's static type.  */
 	  type = NULL;
 	}
-
-      do_cleanups (cleanup);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -428,7 +418,7 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
 
   TRY
     {
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
+      scoped_value_mark free_values;
 
       if (TYPE_CODE (value_type (value)) == TYPE_CODE_PTR)
 	value = value_ind (value);
@@ -436,8 +426,6 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
       str_obj = gdbpy_create_lazy_string_object (value_address (value), length,
 						 user_encoding,
 						 value_type (value));
-
-      do_cleanups (cleanup);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -514,7 +502,7 @@ valpy_do_cast (PyObject *self, PyObject *args, enum exp_opcode op)
     {
       struct value *val = ((value_object *) self)->value;
       struct value *res_val;
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
+      scoped_value_mark free_values;
 
       if (op == UNOP_DYNAMIC_CAST)
 	res_val = value_dynamic_cast (type, val);
@@ -527,7 +515,6 @@ valpy_do_cast (PyObject *self, PyObject *args, enum exp_opcode op)
 	}
 
       result = value_to_value_object (res_val);
-      do_cleanups (cleanup);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -737,8 +724,8 @@ valpy_getitem (PyObject *self, PyObject *key)
   TRY
     {
       struct value *tmp = self_value->value;
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
       struct value *res_val = NULL;
+      scoped_value_mark free_values;
 
       if (field)
 	res_val = value_struct_elt (&tmp, NULL, field.get (), NULL,
@@ -783,7 +770,6 @@ valpy_getitem (PyObject *self, PyObject *key)
 
       if (res_val)
 	result = value_to_value_object (res_val);
-      do_cleanups (cleanup);
     }
   CATCH (ex, RETURN_MASK_ALL)
     {
@@ -861,12 +847,11 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
 
   TRY
     {
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (mark);
+      scoped_value_mark free_values;
       struct value *return_value;
 
       return_value = call_function_by_hand (function, args_count, vargs);
       result = value_to_value_object (return_value);
-      do_cleanups (cleanup);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -1014,11 +999,12 @@ valpy_binop_throw (enum valpy_opcode opcode, PyObject *self, PyObject *other)
   PyObject *result = NULL;
 
   struct value *arg1, *arg2;
-  struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
   struct value *res_val = NULL;
   enum exp_opcode op = OP_NULL;
   int handled = 0;
 
+  scoped_value_mark free_values;
+
   /* If the gdb.Value object is the second operand, then it will be
      passed to us as the OTHER argument, and SELF will be an entirely
      different kind of object, altogether.  Because of this, we can't
@@ -1026,17 +1012,11 @@ valpy_binop_throw (enum valpy_opcode opcode, PyObject *self, PyObject *other)
      python as well.  */
   arg1 = convert_value_from_python (self);
   if (arg1 == NULL)
-    {
-      do_cleanups (cleanup);
-      return NULL;
-    }
+    return NULL;
 
   arg2 = convert_value_from_python (other);
   if (arg2 == NULL)
-    {
-      do_cleanups (cleanup);
-      return NULL;
-    }
+    return NULL;
 
   switch (opcode)
     {
@@ -1130,7 +1110,6 @@ valpy_binop_throw (enum valpy_opcode opcode, PyObject *self, PyObject *other)
   if (res_val)
     result = value_to_value_object (res_val);
 
-  do_cleanups (cleanup);
   return result;
 }
 
@@ -1209,12 +1188,11 @@ valpy_negative (PyObject *self)
   TRY
     {
       /* Perhaps overkill, but consistency has some virtue.  */
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
+      scoped_value_mark free_values;
       struct value *val;
 
       val = value_neg (((value_object *) self)->value);
       result = value_to_value_object (val);
-      do_cleanups (cleanup);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -1239,12 +1217,10 @@ valpy_absolute (PyObject *self)
 
   TRY
     {
-      struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
+      scoped_value_mark free_values;
 
       if (value_less (value, value_zero (value_type (value), not_lval)))
 	isabs = 0;
-
-      do_cleanups (cleanup);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -1362,15 +1338,14 @@ valpy_richcompare_throw (PyObject *self, PyObject *other, int op)
   int result;
   struct value *value_other;
   struct value *value_self;
-  struct value *mark = value_mark ();
   struct cleanup *cleanup;
 
+  scoped_value_mark free_values;
+
   value_other = convert_value_from_python (other);
   if (value_other == NULL)
     return -1;
 
-  cleanup = make_cleanup_value_free_to_mark (mark);
-
   value_self = ((value_object *) self)->value;
 
   switch (op)
@@ -1403,7 +1378,6 @@ valpy_richcompare_throw (PyObject *self, PyObject *other, int op)
       break;
     }
 
-  do_cleanups (cleanup);
   return result;
 }
 
diff --git a/gdb/value.h b/gdb/value.h
index f776323..3a0641a 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -714,6 +714,28 @@ extern struct value *value_mark (void);
 
 extern void value_free_to_mark (const struct value *mark);
 
+/* A helper class that uses value_mark at construction time and calls
+   value_free_to_mark in the destructor.  This is used to clear out
+   temporary values created during the lifetime of this object.  */
+class scoped_value_mark
+{
+ public:
+
+  scoped_value_mark ()
+    : m_value (value_mark ())
+  {
+  }
+
+  ~scoped_value_mark ()
+  {
+    value_free_to_mark (m_value);
+  }
+
+ private:
+
+  const struct value *m_value;
+};
+
 extern struct value *value_cstring (const char *ptr, ssize_t len,
 				    struct type *char_type);
 extern struct value *value_string (const char *ptr, ssize_t len,


  reply	other threads:[~2016-12-23 19:59 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29  5:06 [RFA 0/8] C++-ification series #5 Tom Tromey
2016-11-29  5:06 ` [RFA 8/8] Add constructor and destructor to demangle_parse_info Tom Tromey
2016-12-02 15:04   ` Pedro Alves
2016-12-13 13:50     ` Tom Tromey
2016-11-29  5:06 ` [RFA 1/8] Add gdb_ref_ptr.h Tom Tromey
2016-12-02 13:08   ` Pedro Alves
2016-12-02 17:46     ` Tom Tromey
2016-12-02 18:11       ` Pedro Alves
2016-12-02 19:52         ` Tom Tromey
2016-12-02 23:45           ` Pedro Alves
2016-12-03  0:05   ` Pedro Alves
2016-12-13 13:13     ` Tom Tromey
2016-11-29  5:06 ` [RFA 2/8] Use class to manage BFD reference counts Tom Tromey
2016-12-02 13:05   ` Pedro Alves
2016-12-13 13:26     ` Tom Tromey
2016-12-15  4:12       ` Tom Tromey
2016-12-20 18:18         ` Pedro Alves
2016-12-20 17:19       ` [pushed] gdb: Constify solib_find (Re: [RFA 2/8] Use class to manage BFD reference counts) Pedro Alves
2016-12-20 18:05         ` Tom Tromey
2016-11-29  5:06 ` [RFA 6/8] Use value_freer in dwarf2_evaluate_loc_desc_full Tom Tromey
2016-12-02 14:45   ` Pedro Alves
2016-12-13 13:29     ` Tom Tromey
2016-12-20 14:49       ` Pedro Alves
2016-12-23 19:05         ` Tom Tromey
2016-12-23 19:59           ` Tom Tromey [this message]
2017-01-10 17:57             ` Pedro Alves
2016-12-23 19:59           ` Tom Tromey
2017-01-10 17:58             ` Pedro Alves
2016-11-29  5:06 ` [RFA 5/8] Add value_freer Tom Tromey
2016-12-02 14:24   ` Pedro Alves
2016-11-29  5:06 ` [RFA 7/8] Use unique_xmalloc_ptr in execute_gdb_command Tom Tromey
2016-11-29  5:22   ` Tom Tromey
2016-12-15  3:49     ` Tom Tromey
2016-12-20 17:48       ` Pedro Alves
2016-12-20 18:13         ` Tom Tromey
2016-12-23 20:01           ` Tom Tromey
2017-01-10 17:59             ` Pedro Alves
2017-01-10 19:22               ` Tom Tromey
2016-12-20 23:31         ` Tom Tromey
2016-12-20 23:56           ` Pedro Alves
2016-12-22 14:50             ` Tom Tromey
2016-12-22 15:09               ` Pedro Alves
2016-12-22 15:29                 ` Tom Tromey
2016-12-22 15:40                   ` Pedro Alves
2016-12-02 14:49   ` Pedro Alves
2016-12-13 13:30     ` Tom Tromey
2016-11-29  5:06 ` [RFA 4/8] Remove make_cleanup_discard_psymtabs Tom Tromey
2016-12-02 14:21   ` Pedro Alves
2016-11-29  5:06 ` [RFA 3/8] Introduce and use gdb::unlinker Tom Tromey
2016-12-02 13:17   ` Pedro Alves

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=87poki5se8.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.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