From patchwork Tue Nov 29 05:05:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 18029 Received: (qmail 15272 invoked by alias); 29 Nov 2016 05:06:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 14804 invoked by uid 89); 29 Nov 2016 05:06:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=virtue, TRY, H*F:U*tom, old_chain X-HELO: gproxy1.mail.unifiedlayer.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO gproxy1.mail.unifiedlayer.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Nov 2016 05:06:00 +0000 Received: from cmgw4 (cmgw5 [10.0.90.85]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 5C5A0175D0F for ; Mon, 28 Nov 2016 22:05:59 -0700 (MST) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id Dh5w1u00P2f2jeq01h5zbi; Mon, 28 Nov 2016 22:05:59 -0700 X-Authority-Analysis: v=2.1 cv=Zpp+dbLG c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=L24OOQBejmoA:10 a=zstS-IiYAAAA:8 a=38WnfMltFKLLAKDrFkoA:9 a=sg073qr_ZhxL2NSW:21 a=UiT_RlJmL8vc6J78:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 71-218-195-233.hlrn.qwest.net ([71.218.195.233]:46172 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1cBac8-0000aB-5O; Mon, 28 Nov 2016 22:05:56 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 5/8] Add value_freer Date: Mon, 28 Nov 2016 22:05:43 -0700 Message-Id: <1480395946-10924-6-git-send-email-tom@tromey.com> In-Reply-To: <1480395946-10924-1-git-send-email-tom@tromey.com> References: <1480395946-10924-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1cBac8-0000aB-5O X-Source-Sender: 71-218-195-233.hlrn.qwest.net (bapiya.Home) [71.218.195.233]:46172 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This adds a value_freer 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-11-28 Tom Tromey * 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 value_freer. * dwarf2loc.c (dwarf2_loc_desc_get_symbol_read_needs): Use value_freer. * dwarf2-frame.c (execute_stack_op): Use value_freer. * value.h (value_freer): New class. --- gdb/ChangeLog | 12 ++++++++++ gdb/dwarf2-frame.c | 5 +---- gdb/dwarf2loc.c | 8 ++----- gdb/python/py-value.c | 62 +++++++++++++++------------------------------------ gdb/value.h | 22 ++++++++++++++++++ 5 files changed, 55 insertions(+), 54 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d00862a..6197bfb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,17 @@ 2016-11-28 Tom Tromey + * 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 value_freer. + * dwarf2loc.c (dwarf2_loc_desc_get_symbol_read_needs): Use + value_freer. + * dwarf2-frame.c (execute_stack_op): Use value_freer. + * value.h (value_freer): New class. + +2016-11-28 Tom Tromey + * 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..6e5e4fd 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 ()); + value_freer 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; } diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 6284e68..0d8a47c 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -2840,16 +2840,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); + value_freer 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); @@ -2870,8 +2868,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..2afa4e6 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 ()); + value_freer 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 ()); + value_freer 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 ()); + value_freer 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 ()); + value_freer 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 ()); + value_freer 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 ()); + value_freer 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 ()); + value_freer 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 ()); + value_freer 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; + value_freer 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); + value_freer 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; + value_freer 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 ()); + value_freer 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 ()); + value_freer 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; + value_freer 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..399bf48 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 value_freer +{ + public: + + value_freer () + : m_value (value_mark ()) + { + } + + ~value_freer () + { + 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,