[06/47] Turn value_arch into method

Message ID 20230209-submit-value-fixups-2023-v1-6-55dc2794dbb9@tromey.com
State New
Headers
Series Use methods for struct value |

Commit Message

Tom Tromey Feb. 9, 2023, 9:38 p.m. UTC
  This changes value_arch to be a method of value.  Much of this patch
was written by script.
---
 gdb/valops.c |  2 +-
 gdb/value.c  | 12 ++++++------
 gdb/value.h  |  7 +++----
 3 files changed, 10 insertions(+), 11 deletions(-)
  

Comments

Simon Marchi Feb. 10, 2023, 2:08 a.m. UTC | #1
> diff --git a/gdb/value.h b/gdb/value.h
> index cb92b872bc6..31ec0b5c202 100644
> --- a/gdb/value.h
> +++ b/gdb/value.h
> @@ -169,6 +169,9 @@ struct value
>    void deprecated_set_type (struct type *type)
>    { m_type = type; }
>  
> +  /* Return the gdbarch associated with the value. */
> +  struct gdbarch *get_arch () const;

We typically don't use the "get_" prefix for getters.  Is there a reason
to use it here?

Simon
  
Tom Tromey Feb. 10, 2023, 4:36 p.m. UTC | #2
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

>> diff --git a/gdb/value.h b/gdb/value.h
>> index cb92b872bc6..31ec0b5c202 100644
>> --- a/gdb/value.h
>> +++ b/gdb/value.h
>> @@ -169,6 +169,9 @@ struct value
>> void deprecated_set_type (struct type *type)
>> { m_type = type; }
>> 
>> +  /* Return the gdbarch associated with the value. */
>> +  struct gdbarch *get_arch () const;

Simon> We typically don't use the "get_" prefix for getters.  Is there a reason
Simon> to use it here?

I think I was just copying the function name.

I updated this.  It required a few changes in later patches -- I renamed
some local 'arch' variables to avoid confusion -- but nothing too big.

Tom
  

Patch

diff --git a/gdb/valops.c b/gdb/valops.c
index 1cac2496183..2d1db3cef83 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1045,7 +1045,7 @@  read_value_memory (struct value *val, LONGEST bit_offset,
 		   gdb_byte *buffer, size_t length)
 {
   ULONGEST xfered_total = 0;
-  struct gdbarch *arch = get_value_arch (val);
+  struct gdbarch *arch = val->get_arch ();
   int unit_size = gdbarch_addressable_memory_unit_size (arch);
   enum target_object object;
 
diff --git a/gdb/value.c b/gdb/value.c
index bde8f3da4d2..96db14c99cc 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -163,9 +163,9 @@  value::~value ()
 /* See value.h.  */
 
 struct gdbarch *
-get_value_arch (const struct value *value)
+value::get_arch () const
 {
-  return value->type ()->arch ();
+  return type ()->arch ();
 }
 
 int
@@ -944,7 +944,7 @@  set_value_parent (struct value *value, struct value *parent)
 gdb::array_view<gdb_byte>
 value_contents_raw (struct value *value)
 {
-  struct gdbarch *arch = get_value_arch (value);
+  struct gdbarch *arch = value->get_arch ();
   int unit_size = gdbarch_addressable_memory_unit_size (arch);
 
   allocate_value_contents (value);
@@ -1121,7 +1121,7 @@  value_contents_copy_raw (struct value *dst, LONGEST dst_offset,
 			 struct value *src, LONGEST src_offset, LONGEST length)
 {
   LONGEST src_bit_offset, dst_bit_offset, bit_length;
-  struct gdbarch *arch = get_value_arch (src);
+  struct gdbarch *arch = src->get_arch ();
   int unit_size = gdbarch_addressable_memory_unit_size (arch);
 
   /* A lazy DST would make that this copy operation useless, since as
@@ -2160,7 +2160,7 @@  set_internalvar_component (struct internalvar *var,
     {
     case INTERNALVAR_VALUE:
       addr = value_contents_writeable (var->u.value).data ();
-      arch = get_value_arch (var->u.value);
+      arch = var->u.value->get_arch ();
       unit_size = gdbarch_addressable_memory_unit_size (arch);
 
       if (bitsize)
@@ -2884,7 +2884,7 @@  value_primitive_field (struct value *arg1, LONGEST offset,
 {
   struct value *v;
   struct type *type;
-  struct gdbarch *arch = get_value_arch (arg1);
+  struct gdbarch *arch = arg1->get_arch ();
   int unit_size = gdbarch_addressable_memory_unit_size (arch);
 
   arg_type = check_typedef (arg_type);
diff --git a/gdb/value.h b/gdb/value.h
index cb92b872bc6..31ec0b5c202 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -169,6 +169,9 @@  struct value
   void deprecated_set_type (struct type *type)
   { m_type = type; }
 
+  /* Return the gdbarch associated with the value. */
+  struct gdbarch *get_arch () const;
+
 
   /* Type of value; either not an lval, or one of the various
      different possible kinds of lval.  */
@@ -336,10 +339,6 @@  struct value
   std::vector<range> m_optimized_out;
 };
 
-/* Return the gdbarch associated with the value. */
-
-extern struct gdbarch *get_value_arch (const struct value *value);
-
 /* Only used for bitfields; number of bits contained in them.  */
 
 extern LONGEST value_bitsize (const struct value *);