From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id E72CE3858C2C; Mon, 13 Feb 2023 22:30:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E72CE3858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676327416; bh=CMs8KTP++H7uhPL9H601fN/04f9fG5tUfRvNxwSmT3A=; h=From:To:Subject:Date:From; b=ZQp7hmjiBOdNIfFWUnOsDp1kVSU12n2vtI5DDVbTacuGkcO+p4irZpXsnHsPTMZW+ bGdrMMgeIkmoosCdTV8s3ixRtxIter739ElJCGdY5tmuapMKHmWXi5jC5jO3dnKz+u 7x4t64ODNRpQBXCUYfG4CaED6YcZcAJwlP8W3BbA= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Turn value_copy into a method X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: e18312bb596fcc9b4df1d018038690df28a68b46 X-Git-Newrev: cda0334434412d888443e9a98386255f2e0c2eab Message-Id: <20230213223016.E72CE3858C2C@sourceware.org> Date: Mon, 13 Feb 2023 22:30:16 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dcda033443441= 2d888443e9a98386255f2e0c2eab commit cda0334434412d888443e9a98386255f2e0c2eab Author: Tom Tromey Date: Tue Jan 31 14:43:22 2023 -0700 Turn value_copy into a method =20 This turns value_copy into a method of value. Much of this was written by script. =20 Approved-By: Simon Marchi Diff: --- 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 | 57 ++++++++++++++++++++++-------------------= ---- gdb/value.h | 7 ++++-- 10 files changed, 51 insertions(+), 49 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 =3D lookup_pointer_type (data_type); =20 if (type->code () =3D=3D 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) =20 if (arrType =3D=3D 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); =20 - val =3D value_copy (toval); + val =3D 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 () !=3D TYPE_CODE_ARRAY) error (_("too many subscripts (%d expected)"), k); arr =3D value_cast (lookup_pointer_type (type->target_type ()), - value_copy (arr)); + arr->copy ()); get_discrete_bounds (type->index_type (), &lwb, &upb); arr =3D value_ptradd (arr, pos_atr (ind[k]) - lwb); type =3D 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_f= ile *stream, int recurse, type =3D ada_check_typedef (resolve_dynamic_type (type, view, address)); if (type !=3D saved_type) { - val =3D value_copy (val); + val =3D val->copy (); val->deprecated_set_type (type); } =20 diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 752b28778bc..4653dbfbd74 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4416,7 +4416,7 @@ bpstat::bpstat (const bpstat &other) print_it (other.print_it) { if (other.old_val !=3D NULL) - old_val =3D release_value (value_copy (other.old_val.get ())); + old_val =3D release_value (other.old_val.get ()->copy ()); } =20 /* Return a copy of a bpstat. Like "bs1 =3D 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, fra= me_info_ptr frame, value_ref_ptr value_holder =3D value_ref_ptr::new_reference (retval); free_values.free_to_mark (); =20 - return value_copy (retval); + return retval->copy (); } =20 /* 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 =3D NULL; } else - value =3D value_copy (vlscm_scm_to_value (obj)); + value =3D 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 =3D value_copy (value); + value =3D 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 =3D value_copy (((value_object *) obj)->value); + value =3D ((value_object *) obj)->value->copy (); else if (gdbpy_is_lazy_string (obj)) { PyObject *result; =20 result =3D PyObject_CallMethodObjArgs (obj, gdbpy_value_cst, NULL); - value =3D value_copy (((value_object *) result)->value); + value =3D ((value_object *) result)->value->copy (); } else PyErr_Format (PyExc_TypeError, diff --git a/gdb/valops.c b/gdb/valops.c index 2923d9fc0d1..aac32cc0917 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -325,7 +325,7 @@ value_cast_pointers (struct type *type, struct value *a= rg2, } =20 /* No superclass found, just change the pointer type. */ - arg2 =3D value_copy (arg2); + arg2 =3D 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 () !=3D type) { - arg2 =3D value_copy (arg2); + arg2 =3D arg2->copy (); arg2->deprecated_set_type (type); } return arg2; @@ -647,7 +647,7 @@ value_cast (struct type *type, struct value *arg2) if (code1 =3D=3D TYPE_CODE_PTR && code2 =3D=3D TYPE_CODE_PTR) return value_cast_pointers (to_type, arg2, 0); =20 - arg2 =3D value_copy (arg2); + arg2 =3D 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 *from= val) /* 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 =3D value_copy (toval); + val =3D toval->copy (); val->set_lazy (0); copy (fromval->contents (), val->contents_raw ()); =20 @@ -1572,7 +1572,7 @@ value_addr (struct value *arg1) struct type *enclosing_type_ptr =3D lookup_pointer_type (enclosing_type->target_type ()); =20 - arg2 =3D value_copy (arg1); + arg2 =3D arg1->copy (); arg2->deprecated_set_type (type_ptr); arg2->set_enclosing_type (enclosing_type_ptr); =20 @@ -2107,7 +2107,7 @@ struct_field_searcher::search (struct value *arg1, LO= NGEST offset, } else { - v2 =3D value_copy (arg1); + v2 =3D 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 =3D value_copy (argp); + argp =3D argp->copy (); argp->set_enclosing_type (real_type); return argp; } diff --git a/gdb/value.c b/gdb/value.c index 804444221ba..b8a032ed30d 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1517,34 +1517,33 @@ value_release_to_mark (const struct value *mark) return result; } =20 -/* Return a copy of the value ARG. It contains the same contents, - for the same memory address, but it's a different block of storage. */ +/* See value.h. */ =20 struct value * -value_copy (const value *arg) +value::copy () const { - struct type *encl_type =3D arg->enclosing_type (); + struct type *encl_type =3D enclosing_type (); struct value *val; =20 val =3D value::allocate_lazy (encl_type); - val->m_type =3D arg->m_type; - VALUE_LVAL (val) =3D arg->m_lval; - val->m_location =3D arg->m_location; - val->m_offset =3D arg->m_offset; - val->m_bitpos =3D arg->m_bitpos; - val->m_bitsize =3D arg->m_bitsize; - val->m_lazy =3D arg->m_lazy; - val->m_embedded_offset =3D arg->embedded_offset (); - val->m_pointed_to_offset =3D arg->m_pointed_to_offset; - val->m_modifiable =3D arg->m_modifiable; - val->m_stack =3D arg->m_stack; - val->m_is_zero =3D arg->m_is_zero; - val->m_in_history =3D arg->m_in_history; - val->m_initialized =3D arg->m_initialized; - val->m_unavailable =3D arg->m_unavailable; - val->m_optimized_out =3D arg->m_optimized_out; - val->m_parent =3D arg->m_parent; - val->m_limited_length =3D arg->m_limited_length; + val->m_type =3D m_type; + VALUE_LVAL (val) =3D m_lval; + val->m_location =3D m_location; + val->m_offset =3D m_offset; + val->m_bitpos =3D m_bitpos; + val->m_bitsize =3D m_bitsize; + val->m_lazy =3D m_lazy; + val->m_embedded_offset =3D embedded_offset (); + val->m_pointed_to_offset =3D m_pointed_to_offset; + val->m_modifiable =3D m_modifiable; + val->m_stack =3D m_stack; + val->m_is_zero =3D m_is_zero; + val->m_in_history =3D m_in_history; + val->m_initialized =3D m_initialized; + val->m_unavailable =3D m_unavailable; + val->m_optimized_out =3D m_optimized_out; + val->m_parent =3D m_parent; + val->m_limited_length =3D m_limited_length; =20 if (!val->lazy () && !(value_entirely_optimized_out (val) @@ -1554,9 +1553,9 @@ value_copy (const value *arg) if (length =3D=3D 0) length =3D val->enclosing_type ()->length (); =20 - gdb_assert (arg->m_contents !=3D nullptr); + gdb_assert (m_contents !=3D nullptr); const auto &arg_view - =3D gdb::make_array_view (arg->m_contents.get (), length); + =3D gdb::make_array_view (m_contents.get (), length); =20 val->allocate_contents (false); gdb::array_view val_contents @@ -1586,7 +1585,7 @@ make_cv_value (int cnst, int voltl, struct value *v) { struct type *val_type =3D v->type (); struct type *m_enclosing_type =3D v->enclosing_type (); - struct value *cv_val =3D value_copy (v); + struct value *cv_val =3D v->copy (); =20 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)); @@ -1762,7 +1761,7 @@ access_value_history (int num) =20 absnum--; =20 - return value_copy (value_history[absnum].get ()); + return value_history[absnum].get ()->copy (); } =20 /* See value.h. */ @@ -2088,7 +2087,7 @@ value_of_internalvar (struct gdbarch *gdbarch, struct= internalvar *var) break; =20 case INTERNALVAR_VALUE: - val =3D value_copy (var->u.value); + val =3D var->u.value->copy (); if (val->lazy ()) val->fetch_lazy (); break; @@ -2223,7 +2222,7 @@ set_internalvar (struct internalvar *var, struct valu= e *val) =20 default: new_kind =3D INTERNALVAR_VALUE; - struct value *copy =3D value_copy (val); + struct value *copy =3D val->copy (); copy->m_modifiable =3D 1; =20 /* Force the value to be fetched from the target now, to avoid probl= ems @@ -4173,7 +4172,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 =3D release_value (value::allocate_optimized_out (type= )); - value_ref_ptr copy =3D release_value (value_copy (val.get ())); + value_ref_ptr copy =3D release_value (val.get ()->copy ()); =20 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 f38241f1a5b..6b0250c0e51 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -165,6 +165,11 @@ public: /* Create a value of type TYPE that is zero, and return it. */ static struct value *zero (struct type *type, enum lval_type lv); =20 + /* Return a copy of the value. It contains the same contents, for + the same memory address, but it's a different block of + storage. */ + struct value *copy () const; + ~value (); =20 DISABLE_COPY_AND_ASSIGN (value); @@ -1447,8 +1452,6 @@ extern void preserve_values (struct objfile *); =20 /* From values.c */ =20 -extern struct value *value_copy (const value *); - extern struct value *value_non_lval (struct value *); =20 extern void value_force_lval (struct value *, CORE_ADDR);