value: Make accessor methods' parameters const-correct

Message ID 1459974933-616-1-git-send-email-martin.galvan@tallertechnologies.com
State New, archived
Headers

Commit Message

Martin Galvan April 6, 2016, 8:35 p.m. UTC
  I did a quick pass over value.c and value.h and made some of the accessor methods'
parameters const-correct. Besides the obvious benefits, this is required if we
want to use them on values that are already declared as const (such as the parameters
to lval_funcs). I also const-ified some of the pass-by-value parameters; while
they're not as important it's still nice to have them like that.

There's probably a lot more stuff that can be made const, here and elsewhere.

I have write access and copyright assignment. Ok to commit?

gdb/ChangeLog
2016-04-06  Martin Galvan  <martin.galvan@tallertechnologies.com>

	* value.c (value_next): Make parameters const-correct.
	(set_value_offset): Likewise.
	(set_value_bitsize): Likewise.
	(value_parent): Likewise.
	(value_enclosing_type): Likewise.
	(value_actual_type): Likewise.
	(ranges_copy_adjusted): Likewise.
	(value_ranges_copy_adjusted): Likewise.
	(value_lazy): Likewise.
	(set_value_lazy): Likewise.
	(value_stack): Likewise.
	(set_value_stack): Likewise.
	(mark_value_bytes_optimized_out): Likewise.
	(value_embedded_offset): Likewise.
	(set_value_embedded_offset): Likewise.
	(value_pointed_to_offset): Likewise.
	(set_value_pointed_to_offset): Likewise.
	(value_raw_address): Likewise.
	(set_value_address): Likewise.
	(deprecated_value_modifiable): Likewise.
	(value_free_to_mark): Likewise.
	(value_release_to_mark): Likewise.
	(make_cv_value): Likewise.
	(value_force_lval): Likewise.
	(access_value_history): Likewise.
	(show_values): Likewise.
	(set_internalvar_component): Likewise.
	(set_internalvar_integer): Likewise.
	(internalvar_name): Likewise.
	(result_type_of_xmethod): Likewise.
	(call_xmethod): Likewise.
	(value_static_field): Likewise.
	(value_primitive_field): Likewise.
	(value_field): Likewise.
	(value_fn_field): Likewise.
	(unpack_bits_as_long): Likewise.
	(unpack_value_field_as_long): Likewise.
	(unpack_field_as_long): Likewise.
	(unpack_value_bitfield): Likewise.
	(value_field_bitfield): Likewise.
	(modify_field): Likewise.
	(pack_long): Likewise.
	(pack_unsigned_long): Likewise.
	(value_from_longest): Likewise.
	(value_from_ulongest): Likewise.
	(value_from_pointer): Likewise.
	(value_from_contents_and_address_unresolved): Likewise.
	(value_from_double): Likewise.
	(readjust_indirect_value_type): Likewise.
	(set_value_initialized): Likewise.
	(value_initialized): Likewise.
	(isvoid_internal_fn): Likewise.
	(set_value_bitpos): Likewise.
	* value.h (value_next): Likewise.
	(value_parent): Likewise.
	(deprecated_value_modifiable): Likewise.
	(value_enclosing_type): Likewise.
	(value_pointed_to_offset): Likewise.
	(value_embedded_offset): Likewise.
	(value_lazy): Likewise.
	(value_stack): Likewise.
	(value_initialized): Likewise.
	(value_raw_address): Likewise.
	(readjust_indirect_value_type): Likewise.
	(value_free_to_mark): Likewise.
	(value_release_to_mark): Likewise.
	(internalvar_name): Likewise.

---
 gdb/value.c | 129 +++++++++++++++++++++++++++++++-----------------------------
 gdb/value.h |  34 ++++++++--------
 2 files changed, 84 insertions(+), 79 deletions(-)
  

Comments

Pedro Alves April 6, 2016, 11:36 p.m. UTC | #1
On 04/06/2016 09:35 PM, Martin Galvan wrote:
> I did a quick pass over value.c and value.h and made some of the accessor methods'
> parameters const-correct. Besides the obvious benefits, this is required if we
> want to use them on values that are already declared as const (such as the parameters
> to lval_funcs). I also const-ified some of the pass-by-value parameters; while
> they're not as important it's still nice to have them like that.

Thanks for doing this.

Const on pointer parameters is certainly useful.  But since you asked
me [ :-) ], I'm on the "const on value params is mostly useless
clutter" camp.  It's something you don't see many style guides requiring,
and it's something gdb hasn't been doing either.

So personally I'd prefer a patch without those bits.

> 
> There's probably a lot more stuff that can be made const, here and elsewhere.
> 
> I have write access and copyright assignment. Ok to commit?
Thanks,
Pedro Alves
  
Martin Galvan April 7, 2016, 1:31 p.m. UTC | #2
On Wed, Apr 6, 2016 at 8:36 PM, Pedro Alves <palves@redhat.com> wrote:
> Const on pointer parameters is certainly useful.  But since you asked
> me [ :-) ], I'm on the "const on value params is mostly useless
> clutter" camp.  It's something you don't see many style guides requiring,
> and it's something gdb hasn't been doing either.
>
> So personally I'd prefer a patch without those bits.

No problem, I'll remove them. Can I commit the patch after I do it, or
should I send in a v2 first?
  
Pedro Alves April 7, 2016, 1:33 p.m. UTC | #3
On 04/07/2016 02:31 PM, Martin Galvan wrote:

> No problem, I'll remove them. Can I commit the patch after I do it, or
> should I send in a v2 first?

Please send a v2.

Thanks,
Pedro Alves
  
Simon Marchi April 7, 2016, 1:38 p.m. UTC | #4
On 16-04-06 07:36 PM, Pedro Alves wrote:
> On 04/06/2016 09:35 PM, Martin Galvan wrote:
>> I did a quick pass over value.c and value.h and made some of the accessor methods'
>> parameters const-correct. Besides the obvious benefits, this is required if we
>> want to use them on values that are already declared as const (such as the parameters
>> to lval_funcs). I also const-ified some of the pass-by-value parameters; while
>> they're not as important it's still nice to have them like that.
> 
> Thanks for doing this.
> 
> Const on pointer parameters is certainly useful.  But since you asked
> me [ :-) ], I'm on the "const on value params is mostly useless
> clutter" camp.  It's something you don't see many style guides requiring,
> and it's something gdb hasn't been doing either.
> 
> So personally I'd prefer a patch without those bits.
> 
>>
>> There's probably a lot more stuff that can be made const, here and elsewhere.
>>
>> I have write access and copyright assignment. Ok to commit?
> Thanks,
> Pedro Alves
> 

I agree with Pedro.

The main value of const I think is to give the assurance to the callers that the function
won't change anything that is passed by reference, preventing side-effects.  For arguments
passed by value, we already know that.  One could argue that it could prevent assigning to
it by mistake.  But I'd say that that risk is very low, especially in short/obvious functions
like this.  If the function was longer and more complicated, then maybe it could help the
reader understand that this argument/variable never changes value.

If that became the standard coding style everywhere in the code, it would make things quite heavy.

And to be pedantic, if you want to make all arguments const you should also do this :)

-set_value_bitpos (struct value *value, int bit)
+set_value_bitpos (struct value *const value, const int bit)

Simon
  
Martin Galvan April 7, 2016, 1:49 p.m. UTC | #5
On Thu, Apr 7, 2016 at 10:38 AM, Simon Marchi <simon.marchi@ericsson.com> wrote:
> And to be pedantic, if you want to make all arguments const you should also do this :)
>
> -set_value_bitpos (struct value *value, int bit)
> +set_value_bitpos (struct value *const value, const int bit)

Yeah, I thought of that but it'd been too much. Thanks for the
feedback guys, I'll be sending v2 in a moment.

Btw, while I was looking through value.c I saw many functions whose
names are 'deprecated', or 'hack', yet they're still being used. If
you guys want I can look into removing/replacing them after I'm done
with the synthetic reference fixes.
  
Tom Tromey April 7, 2016, 2:43 p.m. UTC | #6
>>>>> "Martin" == Martin Galvan <martin.galvan@tallertechnologies.com> writes:

Martin> Btw, while I was looking through value.c I saw many functions whose
Martin> names are 'deprecated', or 'hack', yet they're still being used. If
Martin> you guys want I can look into removing/replacing them after I'm done
Martin> with the synthetic reference fixes.

See

https://github.com/tromey/gdb/commits/cleanups/value-deprecation-removals

Not sure how much of that is still relevant, but you're welcome to
whatever you think is worth taking.

Tom
  

Patch

diff --git a/gdb/value.c b/gdb/value.c
index 8268b08..38478c6 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1093,7 +1093,7 @@  allocate_optimized_out_value (struct type *type)
 /* Accessor methods.  */
 
 struct value *
-value_next (struct value *value)
+value_next (const struct value *value)
 {
   return value->next;
 }
@@ -1115,7 +1115,7 @@  value_offset (const struct value *value)
   return value->offset;
 }
 void
-set_value_offset (struct value *value, int offset)
+set_value_offset (struct value *value, const int offset)
 {
   value->offset = offset;
 }
@@ -1125,8 +1125,9 @@  value_bitpos (const struct value *value)
 {
   return value->bitpos;
 }
+
 void
-set_value_bitpos (struct value *value, int bit)
+set_value_bitpos (struct value *value, const int bit)
 {
   value->bitpos = bit;
 }
@@ -1137,13 +1138,13 @@  value_bitsize (const struct value *value)
   return value->bitsize;
 }
 void
-set_value_bitsize (struct value *value, int bit)
+set_value_bitsize (struct value *value, const int bit)
 {
   value->bitsize = bit;
 }
 
 struct value *
-value_parent (struct value *value)
+value_parent (const struct value *value)
 {
   return value->parent;
 }
@@ -1179,7 +1180,7 @@  value_contents_all_raw (struct value *value)
 }
 
 struct type *
-value_enclosing_type (struct value *value)
+value_enclosing_type (const struct value *value)
 {
   return value->enclosing_type;
 }
@@ -1187,7 +1188,7 @@  value_enclosing_type (struct value *value)
 /* Look at value.h for description.  */
 
 struct type *
-value_actual_type (struct value *value, int resolve_simple_types,
+value_actual_type (struct value *value, const int resolve_simple_types,
 		   int *real_type_found)
 {
   struct value_print_options opts;
@@ -1281,9 +1282,9 @@  value_contents_all (struct value *value)
    SRC_BIT_OFFSET+BIT_LENGTH) ranges into *DST_RANGE, adjusted.  */
 
 static void
-ranges_copy_adjusted (VEC (range_s) **dst_range, int dst_bit_offset,
-		      VEC (range_s) *src_range, int src_bit_offset,
-		      int bit_length)
+ranges_copy_adjusted (VEC (range_s) **dst_range, const int dst_bit_offset,
+		      VEC (range_s) *src_range, const int src_bit_offset,
+		      const int bit_length)
 {
   range_s *r;
   int i;
@@ -1306,9 +1307,9 @@  ranges_copy_adjusted (VEC (range_s) **dst_range, int dst_bit_offset,
    SRC_BIT_OFFSET+BIT_LENGTH) into DST, adjusted.  */
 
 static void
-value_ranges_copy_adjusted (struct value *dst, int dst_bit_offset,
-			    const struct value *src, int src_bit_offset,
-			    int bit_length)
+value_ranges_copy_adjusted (struct value *dst, const int dst_bit_offset,
+			    const struct value *src, const int src_bit_offset,
+			    const int bit_length)
 {
   ranges_copy_adjusted (&dst->unavailable, dst_bit_offset,
 			src->unavailable, src_bit_offset,
@@ -1387,25 +1388,25 @@  value_contents_copy (struct value *dst, int dst_offset,
 }
 
 int
-value_lazy (struct value *value)
+value_lazy (const struct value *value)
 {
   return value->lazy;
 }
 
 void
-set_value_lazy (struct value *value, int val)
+set_value_lazy (struct value *value, const int val)
 {
   value->lazy = val;
 }
 
 int
-value_stack (struct value *value)
+value_stack (const struct value *value)
 {
   return value->stack;
 }
 
 void
-set_value_stack (struct value *value, int val)
+set_value_stack (struct value *value, const int val)
 {
   value->stack = val;
 }
@@ -1442,7 +1443,8 @@  value_optimized_out (struct value *value)
    the following LENGTH bytes.  */
 
 void
-mark_value_bytes_optimized_out (struct value *value, int offset, int length)
+mark_value_bytes_optimized_out (struct value *value, const int offset,
+				const int length)
 {
   mark_value_bits_optimized_out (value,
 				 offset * TARGET_CHAR_BIT,
@@ -1470,25 +1472,25 @@  value_bits_synthetic_pointer (const struct value *value,
 }
 
 int
-value_embedded_offset (struct value *value)
+value_embedded_offset (const struct value *value)
 {
   return value->embedded_offset;
 }
 
 void
-set_value_embedded_offset (struct value *value, int val)
+set_value_embedded_offset (struct value *value, const int val)
 {
   value->embedded_offset = val;
 }
 
 int
-value_pointed_to_offset (struct value *value)
+value_pointed_to_offset (const struct value *value)
 {
   return value->pointed_to_offset;
 }
 
 void
-set_value_pointed_to_offset (struct value *value, int val)
+set_value_pointed_to_offset (struct value *value, const int val)
 {
   value->pointed_to_offset = val;
 }
@@ -1535,7 +1537,7 @@  value_address (const struct value *value)
 }
 
 CORE_ADDR
-value_raw_address (struct value *value)
+value_raw_address (const struct value *value)
 {
   if (value->lval == lval_internalvar
       || value->lval == lval_internalvar_component
@@ -1545,7 +1547,7 @@  value_raw_address (struct value *value)
 }
 
 void
-set_value_address (struct value *value, CORE_ADDR addr)
+set_value_address (struct value *value, const CORE_ADDR addr)
 {
   gdb_assert (value->lval != lval_internalvar
 	      && value->lval != lval_internalvar_component
@@ -1572,7 +1574,7 @@  deprecated_value_regnum_hack (struct value *value)
 }
 
 int
-deprecated_value_modifiable (struct value *value)
+deprecated_value_modifiable (const struct value *value)
 {
   return value->modifiable;
 }
@@ -1633,7 +1635,7 @@  value_free (struct value *val)
 /* Free all values allocated since MARK was obtained by value_mark
    (except for those released).  */
 void
-value_free_to_mark (struct value *mark)
+value_free_to_mark (const struct value *mark)
 {
   struct value *val;
   struct value *next;
@@ -1725,7 +1727,7 @@  release_value_or_incref (struct value *val)
 
 /* Release all values up to mark  */
 struct value *
-value_release_to_mark (struct value *mark)
+value_release_to_mark (const struct value *mark)
 {
   struct value *val;
   struct value *next;
@@ -1796,7 +1798,7 @@  value_copy (struct value *arg)
    "volatile".  */
 
 struct value *
-make_cv_value (int cnst, int voltl, struct value *v)
+make_cv_value (const int cnst, const int voltl, struct value *v)
 {
   struct type *val_type = value_type (v);
   struct type *enclosing_type = value_enclosing_type (v);
@@ -1833,7 +1835,7 @@  value_non_lval (struct value *arg)
 /* Write contents of V at ADDR and set its lval type to be LVAL_MEMORY.  */
 
 void
-value_force_lval (struct value *v, CORE_ADDR addr)
+value_force_lval (struct value *v, const CORE_ADDR addr)
 {
   gdb_assert (VALUE_LVAL (v) == not_lval);
 
@@ -1913,7 +1915,7 @@  record_latest_value (struct value *val)
 /* Return a copy of the value in the history with sequence number NUM.  */
 
 struct value *
-access_value_history (int num)
+access_value_history (const int num)
 {
   struct value_history_chunk *chunk;
   int i;
@@ -1948,7 +1950,7 @@  access_value_history (int num)
 }
 
 static void
-show_values (char *num_exp, int from_tty)
+show_values (char *num_exp, const int from_tty)
 {
   int i;
   struct value *val;
@@ -2348,8 +2350,9 @@  get_internalvar_function (struct internalvar *var,
 }
 
 void
-set_internalvar_component (struct internalvar *var, int offset, int bitpos,
-			   int bitsize, struct value *newval)
+set_internalvar_component (struct internalvar *var, const int offset,
+			   const int bitpos, const int bitsize,
+			   struct value *newval)
 {
   gdb_byte *addr;
   struct gdbarch *arch;
@@ -2429,7 +2432,7 @@  set_internalvar (struct internalvar *var, struct value *val)
 }
 
 void
-set_internalvar_integer (struct internalvar *var, LONGEST l)
+set_internalvar_integer (struct internalvar *var, const LONGEST l)
 {
   /* Clean up old contents.  */
   clear_internalvar (var);
@@ -2489,7 +2492,7 @@  clear_internalvar (struct internalvar *var)
 }
 
 char *
-internalvar_name (struct internalvar *var)
+internalvar_name (const struct internalvar *var)
 {
   return var->name;
 }
@@ -2709,7 +2712,8 @@  value_of_xmethod (struct xmethod_worker *worker)
 /* Return the type of the result of TYPE_CODE_XMETHOD value METHOD.  */
 
 struct type *
-result_type_of_xmethod (struct value *method, int argc, struct value **argv)
+result_type_of_xmethod (struct value *method, const int argc,
+			struct value **argv)
 {
   gdb_assert (TYPE_CODE (value_type (method)) == TYPE_CODE_XMETHOD
 	      && method->lval == lval_xcallable && argc > 0);
@@ -2721,7 +2725,7 @@  result_type_of_xmethod (struct value *method, int argc, struct value **argv)
 /* Call the xmethod corresponding to the TYPE_CODE_XMETHOD value METHOD.  */
 
 struct value *
-call_xmethod (struct value *method, int argc, struct value **argv)
+call_xmethod (struct value *method, const int argc, struct value **argv)
 {
   gdb_assert (TYPE_CODE (value_type (method)) == TYPE_CODE_XMETHOD
 	      && method->lval == lval_xcallable && argc > 0);
@@ -3008,7 +3012,7 @@  unpack_pointer (struct type *type, const gdb_byte *valaddr)
    TYPE.  */
 
 struct value *
-value_static_field (struct type *type, int fieldno)
+value_static_field (struct type *type, const int fieldno)
 {
   struct value *retval;
 
@@ -3076,7 +3080,7 @@  set_value_enclosing_type (struct value *val, struct type *new_encl_type)
 
 struct value *
 value_primitive_field (struct value *arg1, int offset,
-		       int fieldno, struct type *arg_type)
+		       const int fieldno, struct type *arg_type)
 {
   struct value *v;
   struct type *type;
@@ -3190,7 +3194,7 @@  value_primitive_field (struct value *arg1, int offset,
    FIELDNO says which field.  */
 
 struct value *
-value_field (struct value *arg1, int fieldno)
+value_field (struct value *arg1, const int fieldno)
 {
   return value_primitive_field (arg1, 0, fieldno, value_type (arg1));
 }
@@ -3204,8 +3208,8 @@  value_field (struct value *arg1, int fieldno)
 
 struct value *
 value_fn_field (struct value **arg1p, struct fn_field *f,
-		int j, struct type *type,
-		int offset)
+		const int j, struct type *type,
+		const int offset)
 {
   struct value *v;
   struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
@@ -3275,7 +3279,7 @@  value_fn_field (struct value **arg1p, struct fn_field *f,
 
 static LONGEST
 unpack_bits_as_long (struct type *field_type, const gdb_byte *valaddr,
-		     int bitpos, int bitsize)
+		     const int bitpos, const int bitsize)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (field_type));
   ULONGEST val;
@@ -3331,7 +3335,7 @@  unpack_bits_as_long (struct type *field_type, const gdb_byte *valaddr,
 
 int
 unpack_value_field_as_long (struct type *type, const gdb_byte *valaddr,
-			    int embedded_offset, int fieldno,
+			    const int embedded_offset, const int fieldno,
 			    const struct value *val, LONGEST *result)
 {
   int bitpos = TYPE_FIELD_BITPOS (type, fieldno);
@@ -3355,7 +3359,8 @@  unpack_value_field_as_long (struct type *type, const gdb_byte *valaddr,
    object at VALADDR.  See unpack_bits_as_long for more details.  */
 
 LONGEST
-unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno)
+unpack_field_as_long (struct type *type, const gdb_byte *valaddr,
+		      const int fieldno)
 {
   int bitpos = TYPE_FIELD_BITPOS (type, fieldno);
   int bitsize = TYPE_FIELD_BITSIZE (type, fieldno);
@@ -3374,8 +3379,8 @@  unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno)
 
 void
 unpack_value_bitfield (struct value *dest_val,
-		       int bitpos, int bitsize,
-		       const gdb_byte *valaddr, int embedded_offset,
+		       const int bitpos, const int bitsize,
+		       const gdb_byte *valaddr, const int embedded_offset,
 		       const struct value *val)
 {
   enum bfd_endian byte_order;
@@ -3411,9 +3416,9 @@  unpack_value_bitfield (struct value *dest_val,
    correspondingly marked unavailable/optimized out.  */
 
 struct value *
-value_field_bitfield (struct type *type, int fieldno,
+value_field_bitfield (struct type *type, const int fieldno,
 		      const gdb_byte *valaddr,
-		      int embedded_offset, const struct value *val)
+		      const int embedded_offset, const struct value *val)
 {
   int bitpos = TYPE_FIELD_BITPOS (type, fieldno);
   int bitsize = TYPE_FIELD_BITSIZE (type, fieldno);
@@ -3434,7 +3439,7 @@  value_field_bitfield (struct type *type, int fieldno,
 
 void
 modify_field (struct type *type, gdb_byte *addr,
-	      LONGEST fieldval, int bitpos, int bitsize)
+	      LONGEST fieldval, int bitpos, const int bitsize)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
   ULONGEST oword;
@@ -3480,7 +3485,7 @@  modify_field (struct type *type, gdb_byte *addr,
 /* Pack NUM into BUF using a target format of TYPE.  */
 
 void
-pack_long (gdb_byte *buf, struct type *type, LONGEST num)
+pack_long (gdb_byte *buf, struct type *type, const LONGEST num)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
   int len;
@@ -3515,7 +3520,7 @@  pack_long (gdb_byte *buf, struct type *type, LONGEST num)
 /* Pack NUM into BUF using a target format of TYPE.  */
 
 static void
-pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num)
+pack_unsigned_long (gdb_byte *buf, struct type *type, const ULONGEST num)
 {
   int len;
   enum bfd_endian byte_order;
@@ -3552,7 +3557,7 @@  pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num)
 /* Convert C numbers into newly allocated values.  */
 
 struct value *
-value_from_longest (struct type *type, LONGEST num)
+value_from_longest (struct type *type, const LONGEST num)
 {
   struct value *val = allocate_value (type);
 
@@ -3564,7 +3569,7 @@  value_from_longest (struct type *type, LONGEST num)
 /* Convert C unsigned numbers into newly allocated values.  */
 
 struct value *
-value_from_ulongest (struct type *type, ULONGEST num)
+value_from_ulongest (struct type *type, const ULONGEST num)
 {
   struct value *val = allocate_value (type);
 
@@ -3578,7 +3583,7 @@  value_from_ulongest (struct type *type, ULONGEST num)
    ADDR.  */
 
 struct value *
-value_from_pointer (struct type *type, CORE_ADDR addr)
+value_from_pointer (struct type *type, const CORE_ADDR addr)
 {
   struct value *val = allocate_value (type);
 
@@ -3598,7 +3603,7 @@  value_from_pointer (struct type *type, CORE_ADDR addr)
 struct value *
 value_from_contents_and_address_unresolved (struct type *type,
 					    const gdb_byte *valaddr,
-					    CORE_ADDR address)
+					    const CORE_ADDR address)
 {
   struct value *v;
 
@@ -3651,7 +3656,7 @@  value_from_contents (struct type *type, const gdb_byte *contents)
 }
 
 struct value *
-value_from_double (struct type *type, DOUBLEST num)
+value_from_double (struct type *type, const DOUBLEST num)
 {
   struct value *val = allocate_value (type);
   struct type *base_type = check_typedef (type);
@@ -3761,8 +3766,8 @@  coerce_ref_if_computed (const struct value *arg)
 
 struct value *
 readjust_indirect_value_type (struct value *value, struct type *enc_type,
-			      struct type *original_type,
-			      struct value *original_value)
+			      const struct type *original_type,
+			      const struct value *original_value)
 {
   /* Re-adjust type.  */
   deprecated_set_value_type (value, TYPE_TARGET_TYPE (original_type));
@@ -3859,7 +3864,7 @@  using_struct_return (struct gdbarch *gdbarch,
 /* Set the initialized field in a value struct.  */
 
 void
-set_value_initialized (struct value *val, int status)
+set_value_initialized (struct value *val, const int status)
 {
   val->initialized = status;
 }
@@ -3867,7 +3872,7 @@  set_value_initialized (struct value *val, int status)
 /* Return the initialized field in a value struct.  */
 
 int
-value_initialized (struct value *val)
+value_initialized (const struct value *val)
 {
   return val->initialized;
 }
@@ -4039,7 +4044,7 @@  value_fetch_lazy (struct value *val)
 static struct value *
 isvoid_internal_fn (struct gdbarch *gdbarch,
 		    const struct language_defn *language,
-		    void *cookie, int argc, struct value **argv)
+		    void *cookie, const int argc, struct value **argv)
 {
   int ret;
 
diff --git a/gdb/value.h b/gdb/value.h
index 2eac5ef..05449d2 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -93,7 +93,7 @@  struct value;
    put into the value history or exposed to Python are taken off this
    list.  */
 
-struct value *value_next (struct value *);
+struct value *value_next (const struct value *);
 
 /* Type of the value.  */
 
@@ -126,7 +126,7 @@  extern void set_value_bitpos (struct value *, int bit);
    single read from the target when displaying multiple
    bitfields.  */
 
-struct value *value_parent (struct value *);
+struct value *value_parent (const struct value *);
 extern void set_value_parent (struct value *value, struct value *parent);
 
 /* Describes offset of a value within lval of a structure in bytes.
@@ -142,7 +142,7 @@  extern void set_value_offset (struct value *, int offset);
    relevant if lval != not_lval.''.  Shouldn't the value instead be
    not_lval and be done with it?  */
 
-extern int deprecated_value_modifiable (struct value *value);
+extern int deprecated_value_modifiable (const struct value *value);
 
 /* If a value represents a C++ object, then the `type' field gives the
    object's compile-time type.  If the object actually belongs to some
@@ -185,7 +185,7 @@  extern int deprecated_value_modifiable (struct value *value);
    `type', and `embedded_offset' is zero, so everything works
    normally.  */
 
-extern struct type *value_enclosing_type (struct value *);
+extern struct type *value_enclosing_type (const struct value *);
 extern void set_value_enclosing_type (struct value *val,
 				      struct type *new_type);
 
@@ -205,9 +205,9 @@  extern struct type *value_actual_type (struct value *value,
 				       int resolve_simple_types,
 				       int *real_type_found);
 
-extern int value_pointed_to_offset (struct value *value);
+extern int value_pointed_to_offset (const struct value *value);
 extern void set_value_pointed_to_offset (struct value *value, int val);
-extern int value_embedded_offset (struct value *value);
+extern int value_embedded_offset (const struct value *value);
 extern void set_value_embedded_offset (struct value *value, int val);
 
 /* For lval_computed values, this structure holds functions used to
@@ -312,10 +312,10 @@  extern void *value_computed_closure (const struct value *value);
    element.  If you ever change the way lazy flag is set and reset, be
    sure to consider this use as well!  */
 
-extern int value_lazy (struct value *);
+extern int value_lazy (const struct value *);
 extern void set_value_lazy (struct value *value, int val);
 
-extern int value_stack (struct value *);
+extern int value_stack (const struct value *);
 extern void set_value_stack (struct value *value, int val);
 
 /* Throw an error complaining that the value has been optimized
@@ -398,7 +398,7 @@  extern void mark_value_bits_optimized_out (struct value *value,
 /* Set or return field indicating whether a variable is initialized or
    not, based on debugging information supplied by the compiler.
    1 = initialized; 0 = uninitialized.  */
-extern int value_initialized (struct value *);
+extern int value_initialized (const struct value *);
 extern void set_value_initialized (struct value *, int);
 
 /* Set COMPONENT's location as appropriate for a component of WHOLE
@@ -425,7 +425,7 @@  extern CORE_ADDR value_address (const struct value *);
 
 /* Like value_address, except the result does not include value's
    offset.  */
-extern CORE_ADDR value_raw_address (struct value *);
+extern CORE_ADDR value_raw_address (const struct value *);
 
 /* Set the address of a value.  */
 extern void set_value_address (struct value *, CORE_ADDR);
@@ -456,10 +456,10 @@  extern struct value *coerce_ref_if_computed (const struct value *arg);
 
    It is a common implementation for coerce_ref and value_ind.  */
 
-extern struct value * readjust_indirect_value_type (struct value *value,
-						    struct type *enc_type,
-						    struct type *original_type,
-						    struct value *original_val);
+extern struct value *readjust_indirect_value_type (struct value *value,
+						   struct type *enc_type,
+						   const struct type *original_type,
+						   const struct value *original_val);
 
 /* Convert a REF to the object referenced.  */
 
@@ -694,7 +694,7 @@  extern struct value *allocate_repeat_value (struct type *type, int count);
 
 extern struct value *value_mark (void);
 
-extern void value_free_to_mark (struct value *mark);
+extern void value_free_to_mark (const struct value *mark);
 
 extern struct value *value_cstring (const char *ptr, ssize_t len,
 				    struct type *char_type);
@@ -1006,7 +1006,7 @@  extern void value_print_array_elements (struct value *val,
 					struct ui_file *stream, int format,
 					enum val_prettyformat pretty);
 
-extern struct value *value_release_to_mark (struct value *mark);
+extern struct value *value_release_to_mark (const struct value *mark);
 
 extern void val_print (struct type *type, const gdb_byte *valaddr,
 		       int embedded_offset, CORE_ADDR address,
@@ -1034,7 +1034,7 @@  extern void print_variable_and_value (const char *name,
 extern void typedef_print (struct type *type, struct symbol *news,
 			   struct ui_file *stream);
 
-extern char *internalvar_name (struct internalvar *var);
+extern char *internalvar_name (const struct internalvar *var);
 
 extern void preserve_values (struct objfile *);