From patchwork Thu Feb 9 21:38:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 64598 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3BE103846414 for ; Thu, 9 Feb 2023 23:36:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from progateway7-pub.mail.pro1.eigbox.com (gproxy5-pub.mail.unifiedlayer.com [67.222.38.55]) by sourceware.org (Postfix) with ESMTPS id 987063858C5F for ; Thu, 9 Feb 2023 23:36:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 987063858C5F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway7.mail.pro1.eigbox.com (Postfix) with ESMTP id 05A4B10048163 for ; Thu, 9 Feb 2023 23:36:33 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id QGSupjIhb2s14QGSupj1Yc; Thu, 09 Feb 2023 23:36:32 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=R7DGpfdX c=1 sm=1 tr=0 ts=63e58381 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=m04uMKEZRckA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=44RPbHKIDy2rvR-I3r0A:9 a=QEXdDO2ut3YA:10:nop_charset_2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=iAVbZXferV4tF+/LLJpgurpEgkHpxRhwXuXoS9UHSRo=; b=hv0RJyYKZnSLfhiJdVHsoEIVe8 XrsDgMRh/4N9rAFpcVFIitjXJLWbbPOcrAkdb9SypExiUI4fO7E/K+in0XxpSvxuJAIlNp/syQJp0 yyOhezQRokk8XyBQUG8nKJhog; Received: from 75-166-130-93.hlrn.qwest.net ([75.166.130.93]:52822 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pQEcu-001ZcE-Er for gdb-patches@sourceware.org; Thu, 09 Feb 2023 14:38:44 -0700 From: Tom Tromey Date: Thu, 09 Feb 2023 14:38:56 -0700 Subject: [PATCH 35/47] Turn value_copy into a method MIME-Version: 1.0 Message-Id: <20230209-submit-value-fixups-2023-v1-35-55dc2794dbb9@tromey.com> References: <20230209-submit-value-fixups-2023-v1-0-55dc2794dbb9@tromey.com> In-Reply-To: <20230209-submit-value-fixups-2023-v1-0-55dc2794dbb9@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.130.93 X-Source-L: No X-Exim-ID: 1pQEcu-001ZcE-Er X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-130-93.hlrn.qwest.net ([192.168.0.21]) [75.166.130.93]:52822 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This turns value_copy into a method of value. Much of this was written by script. --- gdb/ada-lang.c | 8 +++---- gdb/ada-valprint.c | 2 +- gdb/breakpoint.c | 2 +- gdb/dwarf2/loc.c | 2 +- gdb/guile/scm-math.c | 2 +- gdb/python/py-prettyprint.c | 2 +- gdb/python/py-value.c | 4 ++-- gdb/valops.c | 14 +++++------ gdb/value.c | 58 ++++++++++++++++++++++----------------------- gdb/value.h | 7 ++++-- 10 files changed, 51 insertions(+), 50 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index c11182a5a0f..e2aa4041263 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -1762,7 +1762,7 @@ thin_data_pntr (struct value *val) data_type = lookup_pointer_type (data_type); if (type->code () == TYPE_CODE_PTR) - return value_cast (data_type, value_copy (val)); + return value_cast (data_type, val->copy ()); else return value_from_longest (data_type, val->address ()); } @@ -2190,7 +2190,7 @@ ada_coerce_to_simple_array_ptr (struct value *arr) if (arrType == NULL) return NULL; - return value_cast (arrType, value_copy (desc_data (arr))); + return value_cast (arrType, desc_data (arr)->copy ()); } else if (ada_is_constrained_packed_array_type (arr->type ())) return decode_constrained_packed_array (arr); @@ -2920,7 +2920,7 @@ ada_value_assign (struct value *toval, struct value *fromval) bits, is_big_endian); write_memory_with_notification (to_addr, buffer, len); - val = value_copy (toval); + val = toval->copy (); memcpy (val->contents_raw ().data (), fromval->contents ().data (), type->length ()); @@ -3073,7 +3073,7 @@ ada_value_ptr_subscript (struct value *arr, int arity, struct value **ind) if (type->code () != TYPE_CODE_ARRAY) error (_("too many subscripts (%d expected)"), k); arr = value_cast (lookup_pointer_type (type->target_type ()), - value_copy (arr)); + arr->copy ()); get_discrete_bounds (type->index_type (), &lwb, &upb); arr = value_ptradd (arr, pos_atr (ind[k]) - lwb); type = type->target_type (); diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index a56c8a1de81..16e865c5de6 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -1028,7 +1028,7 @@ ada_value_print_inner (struct value *val, struct ui_file *stream, int recurse, type = ada_check_typedef (resolve_dynamic_type (type, view, address)); if (type != saved_type) { - val = value_copy (val); + val = val->copy (); val->deprecated_set_type (type); } diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index c3524a9c9a1..1ffdb4bf33d 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4408,7 +4408,7 @@ bpstat::bpstat (const bpstat &other) print_it (other.print_it) { if (other.old_val != NULL) - old_val = release_value (value_copy (other.old_val.get ())); + old_val = release_value (other.old_val.get ()->copy ()); } /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index 64a7e035b06..f9706a0bc05 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -1538,7 +1538,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, frame_info_ptr frame, value_ref_ptr value_holder = value_ref_ptr::new_reference (retval); free_values.free_to_mark (); - return value_copy (retval); + return retval->copy (); } /* The exported interface to dwarf2_evaluate_loc_desc_full; it always diff --git a/gdb/guile/scm-math.c b/gdb/guile/scm-math.c index dcbdef5f4b0..5036871c5f1 100644 --- a/gdb/guile/scm-math.c +++ b/gdb/guile/scm-math.c @@ -744,7 +744,7 @@ vlscm_convert_typed_value_from_scheme (const char *func_name, value = NULL; } else - value = value_copy (vlscm_scm_to_value (obj)); + value = vlscm_scm_to_value (obj)->copy (); } else if (gdbscm_is_true (scm_bytevector_p (obj))) { diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index 18d2b7f5ba4..dd72e230157 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -663,7 +663,7 @@ gdbpy_get_varobj_pretty_printer (struct value *value) { try { - value = value_copy (value); + value = value->copy (); } catch (const gdb_exception &except) { diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 26cbac3586c..f339845c272 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1900,13 +1900,13 @@ convert_value_from_python (PyObject *obj) builtin_type_pychar); } else if (PyObject_TypeCheck (obj, &value_object_type)) - value = value_copy (((value_object *) obj)->value); + value = ((value_object *) obj)->value->copy (); else if (gdbpy_is_lazy_string (obj)) { PyObject *result; result = PyObject_CallMethodObjArgs (obj, gdbpy_value_cst, NULL); - value = value_copy (((value_object *) result)->value); + value = ((value_object *) result)->value->copy (); } else PyErr_Format (PyExc_TypeError, diff --git a/gdb/valops.c b/gdb/valops.c index efe75e12da6..93e58d1d168 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -325,7 +325,7 @@ value_cast_pointers (struct type *type, struct value *arg2, } /* No superclass found, just change the pointer type. */ - arg2 = value_copy (arg2); + arg2 = arg2->copy (); arg2->deprecated_set_type (type); arg2->set_enclosing_type (type); arg2->set_pointed_to_offset (0); /* pai: chk_val */ @@ -428,7 +428,7 @@ value_cast (struct type *type, struct value *arg2) value completely. */ if (arg2->type () != type) { - arg2 = value_copy (arg2); + arg2 = arg2->copy (); arg2->deprecated_set_type (type); } return arg2; @@ -647,7 +647,7 @@ value_cast (struct type *type, struct value *arg2) if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR) return value_cast_pointers (to_type, arg2, 0); - arg2 = value_copy (arg2); + arg2 = arg2->copy (); arg2->deprecated_set_type (to_type); arg2->set_enclosing_type (to_type); arg2->set_pointed_to_offset (0); /* pai: chk_val */ @@ -1342,7 +1342,7 @@ value_assign (struct value *toval, struct value *fromval) /* The return value is a copy of TOVAL so it shares its location information, but its contents are updated from FROMVAL. This implies the returned value is not lazy, even if TOVAL was. */ - val = value_copy (toval); + val = toval->copy (); val->set_lazy (0); copy (fromval->contents (), val->contents_raw ()); @@ -1572,7 +1572,7 @@ value_addr (struct value *arg1) struct type *enclosing_type_ptr = lookup_pointer_type (enclosing_type->target_type ()); - arg2 = value_copy (arg1); + arg2 = arg1->copy (); arg2->deprecated_set_type (type_ptr); arg2->set_enclosing_type (enclosing_type_ptr); @@ -2107,7 +2107,7 @@ struct_field_searcher::search (struct value *arg1, LONGEST offset, } else { - v2 = value_copy (arg1); + v2 = arg1->copy (); v2->deprecated_set_type (basetype); v2->set_embedded_offset (boffset); } @@ -3958,7 +3958,7 @@ value_full_object (struct value *argp, /* pai: FIXME -- sounds iffy */ if (full) { - argp = value_copy (argp); + argp = argp->copy (); argp->set_enclosing_type (real_type); return argp; } diff --git a/gdb/value.c b/gdb/value.c index 81199ab4b9a..98078ed44d2 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1389,46 +1389,44 @@ value_release_to_mark (const struct value *mark) return result; } -/* Return a copy of the value ARG. - It contains the same contents, for same memory address, - but it's a different block of storage. */ +/* See value.h. */ struct value * -value_copy (const value *arg) +value::copy () const { - struct type *encl_type = arg->enclosing_type (); + struct type *encl_type = enclosing_type (); struct value *val; - if (arg->lazy ()) + if (lazy ()) val = value::allocate_lazy (encl_type); else val = value::allocate (encl_type); - val->m_type = arg->m_type; - VALUE_LVAL (val) = arg->m_lval; - val->m_location = arg->m_location; - val->m_offset = arg->m_offset; - val->m_bitpos = arg->m_bitpos; - val->m_bitsize = arg->m_bitsize; - val->m_lazy = arg->m_lazy; - val->m_embedded_offset = arg->embedded_offset (); - val->m_pointed_to_offset = arg->m_pointed_to_offset; - val->m_modifiable = arg->m_modifiable; - val->m_stack = arg->m_stack; - val->m_is_zero = arg->m_is_zero; - val->m_initialized = arg->m_initialized; - val->m_unavailable = arg->m_unavailable; - val->m_optimized_out = arg->m_optimized_out; + val->m_type = m_type; + VALUE_LVAL (val) = m_lval; + val->m_location = m_location; + val->m_offset = m_offset; + val->m_bitpos = m_bitpos; + val->m_bitsize = m_bitsize; + val->m_lazy = m_lazy; + val->m_embedded_offset = embedded_offset (); + val->m_pointed_to_offset = m_pointed_to_offset; + val->m_modifiable = m_modifiable; + val->m_stack = m_stack; + val->m_is_zero = m_is_zero; + val->m_initialized = m_initialized; + val->m_unavailable = m_unavailable; + val->m_optimized_out = m_optimized_out; if (!val->lazy () && !value_entirely_optimized_out (val)) { - gdb_assert (arg->m_contents != nullptr); - ULONGEST length = arg->enclosing_type ()->length (); + gdb_assert (m_contents != nullptr); + ULONGEST length = enclosing_type ()->length (); const auto &arg_view - = gdb::make_array_view (arg->m_contents.get (), length); + = gdb::make_array_view (m_contents.get (), length); gdb::copy (arg_view, val->contents_all_raw ()); } - val->m_parent = arg->m_parent; + val->m_parent = m_parent; if (VALUE_LVAL (val) == lval_computed) { const struct lval_funcs *funcs = val->m_location.computed.funcs; @@ -1450,7 +1448,7 @@ make_cv_value (int cnst, int voltl, struct value *v) { struct type *val_type = v->type (); struct type *m_enclosing_type = v->enclosing_type (); - struct value *cv_val = value_copy (v); + struct value *cv_val = v->copy (); cv_val->deprecated_set_type (make_cv_type (cnst, voltl, val_type, NULL)); cv_val->set_enclosing_type (make_cv_type (cnst, voltl, m_enclosing_type, NULL)); @@ -1600,7 +1598,7 @@ access_value_history (int num) absnum--; - return value_copy (value_history[absnum].get ()); + return value_history[absnum].get ()->copy (); } /* See value.h. */ @@ -1926,7 +1924,7 @@ value_of_internalvar (struct gdbarch *gdbarch, struct internalvar *var) break; case INTERNALVAR_VALUE: - val = value_copy (var->u.value); + val = var->u.value->copy (); if (val->lazy ()) val->fetch_lazy (); break; @@ -2061,7 +2059,7 @@ set_internalvar (struct internalvar *var, struct value *val) default: new_kind = INTERNALVAR_VALUE; - struct value *copy = value_copy (val); + struct value *copy = val->copy (); copy->m_modifiable = 1; /* Force the value to be fetched from the target now, to avoid problems @@ -3998,7 +3996,7 @@ test_value_copy () /* Verify that we can copy an entirely optimized out value, that may not have its contents allocated. */ value_ref_ptr val = release_value (value::allocate_optimized_out (type)); - value_ref_ptr copy = release_value (value_copy (val.get ())); + 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 ())); diff --git a/gdb/value.h b/gdb/value.h index 7b034bba1e2..fdecfa99405 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -164,6 +164,11 @@ struct value /* Create a value of type TYPE that is zero, and return it. */ static struct value *zero (struct type *type, enum lval_type lv); + /* Return a copy of the value. + It contains the same contents, for same memory address, + but it's a different block of storage. */ + struct value *copy () const; + ~value (); DISABLE_COPY_AND_ASSIGN (value); @@ -1413,8 +1418,6 @@ extern void preserve_values (struct objfile *); /* From values.c */ -extern struct value *value_copy (const value *); - extern struct value *value_non_lval (struct value *); extern void value_force_lval (struct value *, CORE_ADDR);