From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH v3 36/50] Turn value_copy into a method
Date: Sun, 12 Feb 2023 20:15:52 -0700 [thread overview]
Message-ID: <20230209-submit-value-fixups-2023-v3-36-45e91a20c742@tromey.com> (raw)
In-Reply-To: <20230209-submit-value-fixups-2023-v3-0-45e91a20c742@tromey.com>
This turns value_copy into a method of value. Much of this was
written by script.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
---
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 = 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 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 != 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 2923d9fc0d1..aac32cc0917 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 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;
}
-/* 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. */
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;
val = value::allocate_lazy (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_in_history = arg->m_in_history;
- val->m_initialized = arg->m_initialized;
- val->m_unavailable = arg->m_unavailable;
- val->m_optimized_out = arg->m_optimized_out;
- val->m_parent = arg->m_parent;
- val->m_limited_length = arg->m_limited_length;
+ 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_in_history = m_in_history;
+ val->m_initialized = m_initialized;
+ val->m_unavailable = m_unavailable;
+ val->m_optimized_out = m_optimized_out;
+ val->m_parent = m_parent;
+ val->m_limited_length = m_limited_length;
if (!val->lazy ()
&& !(value_entirely_optimized_out (val)
@@ -1554,9 +1553,9 @@ value_copy (const value *arg)
if (length == 0)
length = val->enclosing_type ()->length ();
- gdb_assert (arg->m_contents != nullptr);
+ gdb_assert (m_contents != nullptr);
const auto &arg_view
- = gdb::make_array_view (arg->m_contents.get (), length);
+ = gdb::make_array_view (m_contents.get (), length);
val->allocate_contents (false);
gdb::array_view<gdb_byte> val_contents
@@ -1586,7 +1585,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));
@@ -1762,7 +1761,7 @@ access_value_history (int num)
absnum--;
- return value_copy (value_history[absnum].get ());
+ return value_history[absnum].get ()->copy ();
}
/* See value.h. */
@@ -2088,7 +2087,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;
@@ -2223,7 +2222,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
@@ -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 = 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 f38241f1a5b..6b0250c0e51 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -165,6 +165,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
+ the same memory address, but it's a different block of
+ storage. */
+ struct value *copy () const;
+
~value ();
DISABLE_COPY_AND_ASSIGN (value);
@@ -1447,8 +1452,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);
--
2.39.1
next prev parent reply other threads:[~2023-02-13 3:53 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-13 3:15 [PATCH v3 00/50] Use methods for struct value Tom Tromey
2023-02-13 3:15 ` [PATCH v3 01/50] Automatic date update in version.in Tom Tromey
2023-02-13 3:24 ` Tom Tromey
2023-02-13 3:15 ` [PATCH v3 02/50] Rename all fields of struct value Tom Tromey
2023-02-13 3:15 ` [PATCH v3 03/50] Move ~value body out-of-line Tom Tromey
2023-02-13 3:15 ` [PATCH v3 04/50] Move struct value to value.h Tom Tromey
2023-02-13 3:15 ` [PATCH v3 05/50] Turn value_type into method Tom Tromey
2023-02-13 3:15 ` [PATCH v3 06/50] Turn deprecated_set_value_type into a method Tom Tromey
2023-02-13 3:15 ` [PATCH v3 07/50] Turn value_arch into method Tom Tromey
2023-02-13 3:15 ` [PATCH v3 08/50] Turn value_bitsize " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 09/50] Turn value_bitpos " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 10/50] Turn value_parent " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 11/50] Turn value_offset " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 12/50] Turn deprecated_value_modifiable " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 13/50] Turn value_enclosing_type " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 14/50] Turn some value offset functions " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 15/50] Turn value_lazy and set_value_lazy functions into methods Tom Tromey
2023-02-13 3:15 ` [PATCH v3 16/50] Turn value_stack and set_value_stack " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 17/50] Turn value_computed_closure and value_computed_funcs " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 18/50] Convert value_lval_const and deprecated_lval_hack to methods Tom Tromey
2023-02-13 3:15 ` [PATCH v3 19/50] Turn value_initialized and set_value_initialized functions into methods Tom Tromey
2023-02-13 3:15 ` [PATCH v3 20/50] Turn value_address and set_value_address " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 21/50] Turn more deprecated_* " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 22/50] Turn allocate_value_lazy into a static "constructor" Tom Tromey
2023-02-13 3:15 ` [PATCH v3 23/50] Turn allocate_value " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 24/50] Turn allocate_computed_value into " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 25/50] Turn allocate_optimized_out_value " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 26/50] Turn value_zero " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 27/50] Turn some value_contents functions into methods Tom Tromey
2023-02-13 3:15 ` [PATCH v3 28/50] Turn value_fetch_lazy into a method Tom Tromey
2023-02-13 17:35 ` Simon Marchi
2023-02-13 3:15 ` [PATCH v3 29/50] Turn allocate_value_contents " Tom Tromey
2023-02-13 17:37 ` Simon Marchi
2023-02-13 3:15 ` [PATCH v3 30/50] Turn value_contents_eq " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 31/50] Turn value_bits_synthetic_pointer " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 32/50] Move value_ref_policy methods out-of-line Tom Tromey
2023-02-13 3:15 ` [PATCH v3 33/50] Turn value_incref and value_decref into methods Tom Tromey
2023-02-13 3:15 ` [PATCH v3 34/50] Turn remaining value_contents functions " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 35/50] Fully qualify calls to copy in value.c Tom Tromey
2023-02-13 3:15 ` Tom Tromey [this message]
2023-02-13 3:15 ` [PATCH v3 37/50] Turn many optimized-out value functions into methods Tom Tromey
2023-02-13 3:15 ` [PATCH v3 38/50] Turn value_non_lval and value_force_lval " Tom Tromey
2023-02-13 3:15 ` [PATCH v3 39/50] Turn set_value_component_location into method Tom Tromey
2023-02-13 3:15 ` [PATCH v3 40/50] Change some code to use value methods Tom Tromey
2023-02-13 3:15 ` [PATCH v3 41/50] Turn some xmethod functions into methods Tom Tromey
2023-02-13 3:15 ` [PATCH v3 42/50] Turn preserve_one_value into method Tom Tromey
2023-02-13 3:15 ` [PATCH v3 43/50] Turn various value copying-related functions into methods Tom Tromey
2023-02-13 3:16 ` [PATCH v3 44/50] Add value::set_modifiable Tom Tromey
2023-02-13 3:16 ` [PATCH v3 45/50] Turn record_latest_value into a method Tom Tromey
2023-02-13 17:38 ` Simon Marchi
2023-02-13 3:16 ` [PATCH v3 46/50] Make struct value data members private Tom Tromey
2023-02-13 3:16 ` [PATCH v3 47/50] Make ~value private Tom Tromey
2023-02-13 3:16 ` [PATCH v3 48/50] Introduce set_lval method on value Tom Tromey
2023-02-13 3:16 ` [PATCH v3 49/50] Remove deprecated_lval_hack Tom Tromey
2023-02-13 22:26 ` [PATCH v3 00/50] Use methods for struct value Tom Tromey
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=20230209-submit-value-fixups-2023-v3-36-45e91a20c742@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).