Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Remove deprecated_set_value_type (part 1)
@ 2008-01-21  4:53 Rob Quill
  2008-01-29 20:07 ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Rob Quill @ 2008-01-21  4:53 UTC (permalink / raw)
  To: gdb-patches, Daniel Jacobowitz

On 16/12/2007, Daniel Jacobowitz <drow@false.org> wrote:
> On Tue, Nov 13, 2007 at 07:23:18PM +0000, Rob Quill wrote:
> > Is it a correct solution to add a function something like
> > copy_val_except_type, which copies all the fields from a value struct
> > except the type? So an new value is created of the right type, then
> > cop_val_except_type is called, which would replace the other fields.
>
> Sorry for losing this message.  That may be right, but only for some
> of the calls.  The trick is to consider not just what the effect of
> the current calls is, but what this means in terms of the abstraction
> of a "struct value".  Does it make sense to change the type of a value
> without changing anything else about it?  In a few cases yes, but
> not usually.
>
> I picked one call to deprecated_set_value_type; the one in
> c-valprint.c.
>
>               /* Copy value, change to pointer, so we don't get an
>                * error about a non-pointer type in value_rtti_target_type
>                */
>               struct value *temparg;
>               temparg=value_copy(val);
>               deprecated_set_value_type (temparg, lookup_pointer_type (TYPE_TARGET_TYPE(type)));
>               val=temparg;
>
> There's a better way to do this: value_addr of a reference becomes
> a pointer to the same object.  Of course, I see that the body of
> value_addr does it the same way as this code, using the
> deprecated method.  So this call should use value_addr and the
> implementation of value_addr probably needs a new method that
> doesn't exist yet.  I suggest "value_copy_and_change_type".
>
> To pick another example, printcmd.c uses it to do unchecked
> conversions from integers to bit patterns of floating point numbers -
> much to my surprise!  I had no idea this was there until I read the
> code.  Assuming we want to keep that behavior, the right way
> is not to smash the type of some existing value; instead, use
> value_zero (not_lval) to create a new value, and copy the
> bit pattern into it.
>

Hi all,

The attached patch goes part way to removing
deprecated_set_value_type. It adds a new function
value_copy_and_change_type which copies a copies a value but changes
hte type of the new value.

There are also some replacements which create new values of a certain
type and copy data between the old and new values, as necessary.

The remaining uses of deprecated_set_value_type seem to be in more
difficult to understand places, such as in the language specific files
like jv-lang and ada-lang where they seem to be used for coercing
arrays.

So far I have not dealt with these cases as I am unsure why they are
need to change the type. However, as I see it, unless we are to have a
set of separate very similar functions such as
coerce_array_and_change_type() etc, then it seems that the possible
solutions are either copy the value and change the type or make a new
value of the same type and copy some other attributes of the type. Is
this the right idea or have I missed the point?

If this it right then for the remaining uses I intend to figure out
which of the above methods is the best (right) way.

Rob

2008-01-21   Rob Quill <rob.quill@gmail.com>

         Removes some uses of deprecated_set_value_type
         * ada-lang.c (ada_coerce_to_simple_array_type): Create a new
zero value of the correct type instead of changing type.
         (ada_value_assign): Call copy_value_and_change_type instead.
         * c-valprint.c (c_value_print): Call copy_value_and_change_type.
         * printcmd.c (printf_command): Create a zero value of the
correct type and copy the contents of the old value into it.
         * valops.c (value_cast_pointers, value_cast, value_assign,
value_addr): Call value_value_copy_and_change_type instead of copying
the value and then changing the type.
         * value.c (value_copy_and_change_type): Define.
         * value.h (value_copy_and_change_type): Declare.


Index: gdb/ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.131
diff -u -p -r1.131 ada-lang.c
--- gdb/ada-lang.c	8 Jan 2008 19:28:08 -0000	1.131
+++ gdb/ada-lang.c	21 Jan 2008 00:00:46 -0000
@@ -1737,9 +1737,8 @@ struct type *
 ada_coerce_to_simple_array_type (struct type *type)
 {
   struct value *mark = value_mark ();
-  struct value *dummy = value_from_longest (builtin_type_long, 0);
+  struct value *dummy = value_zero(type, not_lval);
   struct type *result;
-  deprecated_set_value_type (dummy, type);
   result = ada_type_of_array (dummy, 0);
   value_free_to_mark (mark);
   return result;
@@ -2241,10 +2240,9 @@ ada_value_assign (struct value *toval, s
       if (deprecated_memory_changed_hook)
 	deprecated_memory_changed_hook (to_addr, len);

-      val = value_copy (toval);
+      val = value_copy_and_change_type(toval, type);
       memcpy (value_contents_raw (val), value_contents (fromval),
               TYPE_LENGTH (type));
-      deprecated_set_value_type (val, type);

       return val;
     }
Index: gdb/c-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-valprint.c,v
retrieving revision 1.48
diff -u -p -r1.48 c-valprint.c
--- gdb/c-valprint.c	11 Jan 2008 13:34:14 -0000	1.48
+++ gdb/c-valprint.c	21 Jan 2008 00:00:46 -0000
@@ -562,8 +562,8 @@ c_value_print (struct value *val, struct
 	       * error about a non-pointer type in value_rtti_target_type
 	       */
 	      struct value *temparg;
-	      temparg=value_copy(val);
-	      deprecated_set_value_type (temparg, lookup_pointer_type
(TYPE_TARGET_TYPE(type)));
+	      temparg=value_copy_and_change_type(val,
+				  lookup_pointer_type (TYPE_TARGET_TYPE(type)));
 	      val=temparg;
 	    }
 	  /* Pointer to class, check real type of object */
Index: gdb/printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.116
diff -u -p -r1.116 printcmd.c
--- gdb/printcmd.c	11 Jan 2008 13:34:14 -0000	1.116
+++ gdb/printcmd.c	21 Jan 2008 00:00:50 -0000
@@ -2035,9 +2035,19 @@ printf_command (char *arg, int from_tty)
 	  {
 	    struct type *type = value_type (val_args[nargs]);
 	    if (TYPE_LENGTH (type) == sizeof (float))
-	      deprecated_set_value_type (val_args[nargs], builtin_type_float);
+		{
+			struct value *temp = value_zero(builtin_type_float, not_lval);
+			memcpy(value_contents_all_raw(temp),
value_contents_all_raw(val_args[nargs]),
+					TYPE_LENGTH(builtin_type_float));
+			val_args[nargs] = temp;
+		}
 	    if (TYPE_LENGTH (type) == sizeof (double))
-	      deprecated_set_value_type (val_args[nargs], builtin_type_double);
+		{	
+			struct value *temp = value_zero(builtin_type_double, not_lval);
+			memcpy(value_contents_all_raw(temp),
value_contents_all_raw(val_args[nargs]),
+					TYPE_LENGTH(builtin_type_double));
+			val_args[nargs] = temp;
+		}
 	  }
 	nargs++;
 	s = s1;
Index: gdb/valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.181
diff -u -p -r1.181 valops.c
--- gdb/valops.c	7 Jan 2008 22:33:57 -0000	1.181
+++ gdb/valops.c	21 Jan 2008 00:00:55 -0000
@@ -250,8 +250,7 @@ value_cast_pointers (struct type *type,
     }

   /* No superclass found, just change the pointer type.  */
-  arg2 = value_copy (arg2);
-  deprecated_set_value_type (arg2, type);
+  arg2 = value_copy_and_change_type (arg2, type);
   arg2 = value_change_enclosing_type (arg2, type);
   set_value_pointed_to_offset (arg2, 0);	/* pai: chk_val */
   return arg2;
@@ -440,8 +439,7 @@ value_cast (struct type *type, struct va
       if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
 	return value_cast_pointers (type, arg2);

-      arg2 = value_copy (arg2);
-      deprecated_set_value_type (arg2, type);
+      arg2 = value_copy_and_change_type(arg2, type);
       arg2 = value_change_enclosing_type (arg2, type);
       set_value_pointed_to_offset (arg2, 0);	/* pai: chk_val */
       return arg2;
@@ -754,10 +752,9 @@ value_assign (struct value *toval, struc
       fromval = value_from_longest (type, fieldval);
     }

-  val = value_copy (toval);
+  val = value_copy_and_change_type(toval, type);
   memcpy (value_contents_raw (val), value_contents (fromval),
 	  TYPE_LENGTH (type));
-  deprecated_set_value_type (val, type);
   val = value_change_enclosing_type (val,
 				     value_enclosing_type (fromval));
   set_value_embedded_offset (val, value_embedded_offset (fromval));
@@ -884,9 +881,8 @@ value_addr (struct value *arg1)
       /* Copy the value, but change the type from (T&) to (T*).  We
          keep the same location information, which is efficient, and
          allows &(&X) to get the location containing the reference.  */
-      arg2 = value_copy (arg1);
-      deprecated_set_value_type (arg2,
-				 lookup_pointer_type (TYPE_TARGET_TYPE (type)));
+      arg2 = value_copy_and_change_type (arg1,
+			  lookup_pointer_type (TYPE_TARGET_TYPE (type)));
       return arg2;
     }
   if (TYPE_CODE (type) == TYPE_CODE_FUNC)
Index: gdb/value.c
===================================================================
RCS file: /cvs/src/src/gdb/value.c,v
retrieving revision 1.56
diff -u -p -r1.56 value.c
--- gdb/value.c	16 Jan 2008 16:16:44 -0000	1.56
+++ gdb/value.c	21 Jan 2008 00:00:56 -0000
@@ -275,6 +275,33 @@ deprecated_set_value_type (struct value
   value->type = type;
 }

+struct value *
+value_copy_and_change_type (struct value *arg, struct type *type)
+{
+  struct type *encl_type = value_enclosing_type (arg);
+  struct value *val = allocate_value (encl_type);
+  val->type = type;
+  VALUE_LVAL (val) = VALUE_LVAL (arg);
+  val->location = arg->location;
+  val->offset = arg->offset;
+  val->bitpos = arg->bitpos;
+  val->bitsize = arg->bitsize;
+  VALUE_FRAME_ID (val) = VALUE_FRAME_ID (arg);
+  VALUE_REGNUM (val) = VALUE_REGNUM (arg);
+  val->lazy = arg->lazy;
+  val->optimized_out = arg->optimized_out;
+  val->embedded_offset = value_embedded_offset (arg);
+  val->pointed_to_offset = arg->pointed_to_offset;
+  val->modifiable = arg->modifiable;
+  if (!value_lazy (val))
+    {
+      memcpy (value_contents_all_raw (val), value_contents_all_raw (arg),
+	      TYPE_LENGTH (value_enclosing_type (arg)));
+
+    }
+  return val;
+}
+
 int
 value_offset (struct value *value)
 {
Index: gdb/value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.107
diff -u -p -r1.107 value.h
--- gdb/value.h	18 Jan 2008 17:07:40 -0000	1.107
+++ gdb/value.h	21 Jan 2008 00:00:57 -0000
@@ -56,6 +56,13 @@ extern struct type *value_type (struct v
 extern void deprecated_set_value_type (struct value *value,
 				       struct type *type);

+/* This function acts as a partial replacement for deprecated_set_value_type.
+   The function is exactly the same as value_copy() but it also changes
+   the type.  */
+
+ extern struct value *value_copy_and_change_type(struct value *arg,
+					          struct type *type);
+
 /* Only used for bitfields; number of bits contained in them.  */

 extern int value_bitsize (struct value *);


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Remove deprecated_set_value_type (part 1)
  2008-01-21  4:53 Remove deprecated_set_value_type (part 1) Rob Quill
@ 2008-01-29 20:07 ` Daniel Jacobowitz
  2008-01-30 12:06   ` Rob Quill
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2008-01-29 20:07 UTC (permalink / raw)
  To: Rob Quill; +Cc: gdb-patches

On Mon, Jan 21, 2008 at 04:53:05AM +0000, Rob Quill wrote:
> 2008-01-21   Rob Quill <rob.quill@gmail.com>
> 
>          Removes some uses of deprecated_set_value_type
>          * ada-lang.c (ada_coerce_to_simple_array_type): Create a new
> zero value of the correct type instead of changing type.
>          (ada_value_assign): Call copy_value_and_change_type instead.
>          * c-valprint.c (c_value_print): Call copy_value_and_change_type.
>          * printcmd.c (printf_command): Create a zero value of the
> correct type and copy the contents of the old value into it.
>          * valops.c (value_cast_pointers, value_cast, value_assign,
> value_addr): Call value_value_copy_and_change_type instead of copying
> the value and then changing the type.
>          * value.c (value_copy_and_change_type): Define.
>          * value.h (value_copy_and_change_type): Declare.

Formatting: a changelog entry is single tab indented, and each line
should wrap at a sensible margin (somewhere between 72 and 79
columns).

> Index: gdb/ada-lang.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/ada-lang.c,v
> retrieving revision 1.131
> diff -u -p -r1.131 ada-lang.c
> --- gdb/ada-lang.c	8 Jan 2008 19:28:08 -0000	1.131
> +++ gdb/ada-lang.c	21 Jan 2008 00:00:46 -0000
> @@ -1737,9 +1737,8 @@ struct type *
>  ada_coerce_to_simple_array_type (struct type *type)
>  {
>    struct value *mark = value_mark ();
> -  struct value *dummy = value_from_longest (builtin_type_long, 0);
> +  struct value *dummy = value_zero(type, not_lval);
>    struct type *result;
> -  deprecated_set_value_type (dummy, type);
>    result = ada_type_of_array (dummy, 0);
>    value_free_to_mark (mark);
>    return result;

Spaces before open parentheses, please.  This one's certainly correct.

> @@ -2241,10 +2240,9 @@ ada_value_assign (struct value *toval, s
>        if (deprecated_memory_changed_hook)
>  	deprecated_memory_changed_hook (to_addr, len);
> 
> -      val = value_copy (toval);
> +      val = value_copy_and_change_type(toval, type);
>        memcpy (value_contents_raw (val), value_contents (fromval),
>                TYPE_LENGTH (type));
> -      deprecated_set_value_type (val, type);
> 
>        return val;
>      }

I can't tell if this one is right.  I don't understand what it's for
either.  Mind leaving it out for now?

> Index: gdb/c-valprint.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/c-valprint.c,v
> retrieving revision 1.48
> diff -u -p -r1.48 c-valprint.c
> --- gdb/c-valprint.c	11 Jan 2008 13:34:14 -0000	1.48
> +++ gdb/c-valprint.c	21 Jan 2008 00:00:46 -0000
> @@ -562,8 +562,8 @@ c_value_print (struct value *val, struct
>  	       * error about a non-pointer type in value_rtti_target_type
>  	       */
>  	      struct value *temparg;
> -	      temparg=value_copy(val);
> -	      deprecated_set_value_type (temparg, lookup_pointer_type
> (TYPE_TARGET_TYPE(type)));
> +	      temparg=value_copy_and_change_type(val,
> +				  lookup_pointer_type (TYPE_TARGET_TYPE(type)));
>  	      val=temparg;
>  	    }
>  	  /* Pointer to class, check real type of object */

This one should just call value_addr; that's how you convert a
reference into the corresponding pointer.

> Index: gdb/printcmd.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/printcmd.c,v
> retrieving revision 1.116
> diff -u -p -r1.116 printcmd.c
> --- gdb/printcmd.c	11 Jan 2008 13:34:14 -0000	1.116
> +++ gdb/printcmd.c	21 Jan 2008 00:00:50 -0000
> @@ -2035,9 +2035,19 @@ printf_command (char *arg, int from_tty)
>  	  {
>  	    struct type *type = value_type (val_args[nargs]);
>  	    if (TYPE_LENGTH (type) == sizeof (float))
> -	      deprecated_set_value_type (val_args[nargs], builtin_type_float);
> +		{
> +			struct value *temp = value_zero(builtin_type_float, not_lval);
> +			memcpy(value_contents_all_raw(temp),
> value_contents_all_raw(val_args[nargs]),
> +					TYPE_LENGTH(builtin_type_float));
> +			val_args[nargs] = temp;
> +		}
>  	    if (TYPE_LENGTH (type) == sizeof (double))
> -	      deprecated_set_value_type (val_args[nargs], builtin_type_double);
> +		{	
> +			struct value *temp = value_zero(builtin_type_double, not_lval);
> +			memcpy(value_contents_all_raw(temp),
> value_contents_all_raw(val_args[nargs]),
> +					TYPE_LENGTH(builtin_type_double));
> +			val_args[nargs] = temp;
> +		}
>  	  }
>  	nargs++;
>  	s = s1;

Formatting: two spaces for the braces, two more for the body, spaces
before open parentheses.  Also be careful of the right margin.  The
code change looks correct to me.  You can use just
value_contents_writeable for temp (the _all_raw bit is only for cases
where you might have a different dynamic type), and use just
value_contents for the right hand type (value_contents is the data
that goes along with value_type; value_contents_all* might be an
enclosing object).

> @@ -440,8 +439,7 @@ value_cast (struct type *type, struct va
>        if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
>  	return value_cast_pointers (type, arg2);
> 
> -      arg2 = value_copy (arg2);
> -      deprecated_set_value_type (arg2, type);
> +      arg2 = value_copy_and_change_type(arg2, type);
>        arg2 = value_change_enclosing_type (arg2, type);
>        set_value_pointed_to_offset (arg2, 0);	/* pai: chk_val */
>        return arg2;

Space before apren.

> Index: gdb/value.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/value.c,v
> retrieving revision 1.56
> diff -u -p -r1.56 value.c
> --- gdb/value.c	16 Jan 2008 16:16:44 -0000	1.56
> +++ gdb/value.c	21 Jan 2008 00:00:56 -0000
> @@ -275,6 +275,33 @@ deprecated_set_value_type (struct value
>    value->type = type;
>  }
> 
> +struct value *
> +value_copy_and_change_type (struct value *arg, struct type *type)
> +{

You can just use value_copy for most of this, to avoid the
duplication; that's not a problem here, since we're inside value.c.

> +/* This function acts as a partial replacement for deprecated_set_value_type.
> +   The function is exactly the same as value_copy() but it also changes
> +   the type.  */
> +
> + extern struct value *value_copy_and_change_type(struct value *arg,
> +					          struct type *type);

Space before paren.

/* Copy ARG to a new value.  The new value is exactly the same, except
   for its type, which is set to TYPE.  */

Don't want to add new references to deprecated_set_value_type; just
one more thing to delete when it's gone.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Remove deprecated_set_value_type (part 1)
  2008-01-29 20:07 ` Daniel Jacobowitz
@ 2008-01-30 12:06   ` Rob Quill
  2008-01-30 18:06     ` Mark Kettenis
  0 siblings, 1 reply; 8+ messages in thread
From: Rob Quill @ 2008-01-30 12:06 UTC (permalink / raw)
  To: Rob Quill, gdb-patches

On 29/01/2008, Daniel Jacobowitz <drow@false.org> wrote:
> I can't tell if this one is right.  I don't understand what it's for
> either.  Mind leaving it out for now?
>

No problem, I've taken it out now. Thanks for you help with this and
sorry about the formatting mistakes. I've attached the new patch,
which shows no regressions, below.

Rob

2008-01-30   Rob Quill <rob.quill@gmail.com>

	Removes some uses of deprecated_set_value_type
	* ada-lang.c (ada_coerce_to_simple_array_type): Create a new zero
	  value of the correct type instead of changing type.
	(ada_value_assign): Call copy_value_and_change_type instead.
	* c-valprint.c (c_value_print): Call copy_value_and_change_type.
	* printcmd.c (printf_command): Create a zero value of the
	  correct type and copy the contents of the old value into it.
	* valops.c (value_cast_pointers, value_cast, value_assign,
	  value_addr): Call value_value_copy_and_change_type instead
	  of copying the value and then changing the type.
	* value.c (value_copy_and_change_type): Define.
	* value.h (value_copy_and_change_type): Declare.

Index: gdb/ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.131
diff -u -p -r1.131 ada-lang.c
--- gdb/ada-lang.c	8 Jan 2008 19:28:08 -0000	1.131
+++ gdb/ada-lang.c	30 Jan 2008 11:20:33 -0000
@@ -1737,9 +1737,8 @@ struct type *
 ada_coerce_to_simple_array_type (struct type *type)
 {
   struct value *mark = value_mark ();
-  struct value *dummy = value_from_longest (builtin_type_long, 0);
+  struct value *dummy = value_zero (type, not_lval);
   struct type *result;
-  deprecated_set_value_type (dummy, type);
   result = ada_type_of_array (dummy, 0);
   value_free_to_mark (mark);
   return result;
Index: gdb/c-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-valprint.c,v
retrieving revision 1.48
diff -u -p -r1.48 c-valprint.c
--- gdb/c-valprint.c	11 Jan 2008 13:34:14 -0000	1.48
+++ gdb/c-valprint.c	30 Jan 2008 11:20:33 -0000
@@ -562,8 +562,7 @@ c_value_print (struct value *val, struct
 	       * error about a non-pointer type in value_rtti_target_type
 	       */
 	      struct value *temparg;
-	      temparg=value_copy(val);
-	      deprecated_set_value_type (temparg, lookup_pointer_type
(TYPE_TARGET_TYPE(type)));
+	      temparg=value_addr (val);
 	      val=temparg;
 	    }
 	  /* Pointer to class, check real type of object */
Index: gdb/printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.116
diff -u -p -r1.116 printcmd.c
--- gdb/printcmd.c	11 Jan 2008 13:34:14 -0000	1.116
+++ gdb/printcmd.c	30 Jan 2008 11:20:38 -0000
@@ -2035,9 +2035,21 @@ printf_command (char *arg, int from_tty)
 	  {
 	    struct type *type = value_type (val_args[nargs]);
 	    if (TYPE_LENGTH (type) == sizeof (float))
-	      deprecated_set_value_type (val_args[nargs], builtin_type_float);
+	      {
+	        struct value *temp = value_zero (builtin_type_float, not_lval);
+			memcpy (value_contents_writeable (temp),
+					value_contents (val_args[nargs]),
+					TYPE_LENGTH (builtin_type_float));
+			val_args[nargs] = temp;
+	      }
 	    if (TYPE_LENGTH (type) == sizeof (double))
-	      deprecated_set_value_type (val_args[nargs], builtin_type_double);
+	      {	
+	        struct value *temp = value_zero (builtin_type_double, not_lval);
+			memcpy (value_contents_all_raw (temp),
+					value_contents_all_raw (val_args[nargs]),
+					TYPE_LENGTH (builtin_type_double));
+			val_args[nargs] = temp;
+	      }
 	  }
 	nargs++;
 	s = s1;
Index: gdb/valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.181
diff -u -p -r1.181 valops.c
--- gdb/valops.c	7 Jan 2008 22:33:57 -0000	1.181
+++ gdb/valops.c	30 Jan 2008 11:20:41 -0000
@@ -250,8 +250,7 @@ value_cast_pointers (struct type *type,
     }

   /* No superclass found, just change the pointer type.  */
-  arg2 = value_copy (arg2);
-  deprecated_set_value_type (arg2, type);
+  arg2 = value_copy_and_change_type (arg2, type);
   arg2 = value_change_enclosing_type (arg2, type);
   set_value_pointed_to_offset (arg2, 0);	/* pai: chk_val */
   return arg2;
@@ -440,8 +439,7 @@ value_cast (struct type *type, struct va
       if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
 	return value_cast_pointers (type, arg2);

-      arg2 = value_copy (arg2);
-      deprecated_set_value_type (arg2, type);
+      arg2 = value_copy_and_change_type (arg2, type);
       arg2 = value_change_enclosing_type (arg2, type);
       set_value_pointed_to_offset (arg2, 0);	/* pai: chk_val */
       return arg2;
@@ -754,10 +752,9 @@ value_assign (struct value *toval, struc
       fromval = value_from_longest (type, fieldval);
     }

-  val = value_copy (toval);
+  val = value_copy_and_change_type(toval, type);
   memcpy (value_contents_raw (val), value_contents (fromval),
 	  TYPE_LENGTH (type));
-  deprecated_set_value_type (val, type);
   val = value_change_enclosing_type (val,
 				     value_enclosing_type (fromval));
   set_value_embedded_offset (val, value_embedded_offset (fromval));
@@ -884,9 +881,8 @@ value_addr (struct value *arg1)
       /* Copy the value, but change the type from (T&) to (T*).  We
          keep the same location information, which is efficient, and
          allows &(&X) to get the location containing the reference.  */
-      arg2 = value_copy (arg1);
-      deprecated_set_value_type (arg2,
-				 lookup_pointer_type (TYPE_TARGET_TYPE (type)));
+      arg2 = value_copy_and_change_type (arg1,
+			  lookup_pointer_type (TYPE_TARGET_TYPE (type)));
       return arg2;
     }
   if (TYPE_CODE (type) == TYPE_CODE_FUNC)
Index: gdb/value.c
===================================================================
RCS file: /cvs/src/src/gdb/value.c,v
retrieving revision 1.56
diff -u -p -r1.56 value.c
--- gdb/value.c	16 Jan 2008 16:16:44 -0000	1.56
+++ gdb/value.c	30 Jan 2008 11:20:42 -0000
@@ -275,6 +275,15 @@ deprecated_set_value_type (struct value
   value->type = type;
 }

+struct value *
+value_copy_and_change_type (struct value *arg, struct type *type)
+{
+  struct value *val = value_copy (arg);
+  val->type = type;
+
+  return val;
+}
+
 int
 value_offset (struct value *value)
 {
Index: gdb/value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.107
diff -u -p -r1.107 value.h
--- gdb/value.h	18 Jan 2008 17:07:40 -0000	1.107
+++ gdb/value.h	30 Jan 2008 11:20:43 -0000
@@ -56,6 +56,12 @@ extern struct type *value_type (struct v
 extern void deprecated_set_value_type (struct value *value,
 				       struct type *type);

+/* Copy ARG to new value. The new value is exactly the same, except
+   for its type, which is set to TYPE.  */
+
+extern struct value *value_copy_and_change_type(struct value *arg,
+						struct type *type);
+
 /* Only used for bitfields; number of bits contained in them.  */

 extern int value_bitsize (struct value *);


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Remove deprecated_set_value_type (part 1)
  2008-01-30 12:06   ` Rob Quill
@ 2008-01-30 18:06     ` Mark Kettenis
  2008-02-26  2:24       ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Kettenis @ 2008-01-30 18:06 UTC (permalink / raw)
  To: rob.quill; +Cc: rob.quill, gdb-patches

> Date: Wed, 30 Jan 2008 11:38:32 +0000
> From: "Rob Quill" <rob.quill@gmail.com>
> 
> Index: gdb/c-valprint.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/c-valprint.c,v
> retrieving revision 1.48
> diff -u -p -r1.48 c-valprint.c
> --- gdb/c-valprint.c	11 Jan 2008 13:34:14 -0000	1.48
> +++ gdb/c-valprint.c	30 Jan 2008 11:20:33 -0000
> @@ -562,8 +562,7 @@ c_value_print (struct value *val, struct
>  	       * error about a non-pointer type in value_rtti_target_type
>  	       */
>  	      struct value *temparg;
> -	      temparg=value_copy(val);
> -	      deprecated_set_value_type (temparg, lookup_pointer_type
> (TYPE_TARGET_TYPE(type)));
> +	      temparg=value_addr (val);
>  	      val=temparg;
>  	    }

There are some code style problems here too, and although they're not
your fault, it'd be nice to fix them while you're there.  Actually, it
looks to me as if the temparg variable is completely redundant now, so
the above could be simplified to

              val = value_addr (val);


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Remove deprecated_set_value_type (part 1)
  2008-01-30 18:06     ` Mark Kettenis
@ 2008-02-26  2:24       ` Daniel Jacobowitz
  2008-02-26 14:36         ` Rob Quill
  2008-07-27 19:16         ` Rob Quill
  0 siblings, 2 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2008-02-26  2:24 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: rob.quill, gdb-patches

On Wed, Jan 30, 2008 at 07:04:40PM +0100, Mark Kettenis wrote:
> There are some code style problems here too, and although they're not
> your fault, it'd be nice to fix them while you're there.  Actually, it
> looks to me as if the temparg variable is completely redundant now, so
> the above could be simplified to
> 
>               val = value_addr (val);

Mark's right; also, there are still formatting problems with the patch
that I commented on the last time I reviewed it :-(  Rob, let me know if
you'd like me to point them out individually.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Remove deprecated_set_value_type (part 1)
  2008-02-26  2:24       ` Daniel Jacobowitz
@ 2008-02-26 14:36         ` Rob Quill
  2008-07-27 19:16         ` Rob Quill
  1 sibling, 0 replies; 8+ messages in thread
From: Rob Quill @ 2008-02-26 14:36 UTC (permalink / raw)
  To: Mark Kettenis, gdb-patches, Daniel Jacobowitz

On 26/02/2008, Daniel Jacobowitz <drow@false.org> wrote:
> On Wed, Jan 30, 2008 at 07:04:40PM +0100, Mark Kettenis wrote:
>  > There are some code style problems here too, and although they're not
>  > your fault, it'd be nice to fix them while you're there.  Actually, it
>  > looks to me as if the temparg variable is completely redundant now, so
>  > the above could be simplified to
>  >
>  >               val = value_addr (val);
>
>
> Mark's right; also, there are still formatting problems with the patch
>  that I commented on the last time I reviewed it :-(  Rob, let me know if
>  you'd like me to point them out individually.

Thanks. I'll take a look at this at some point reasonably soon, I just
have quite a bit of other stuff to do at the moment.

Rob


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Remove deprecated_set_value_type (part 1)
  2008-02-26  2:24       ` Daniel Jacobowitz
  2008-02-26 14:36         ` Rob Quill
@ 2008-07-27 19:16         ` Rob Quill
  2008-08-09 15:10           ` Rob Quill
  1 sibling, 1 reply; 8+ messages in thread
From: Rob Quill @ 2008-07-27 19:16 UTC (permalink / raw)
  To: Mark Kettenis, rob.quill, gdb-patches, Daniel Jacobowitz

[-- Attachment #1: Type: text/plain, Size: 857 bytes --]

2008/2/26 Daniel Jacobowitz <drow@false.org>:
> On Wed, Jan 30, 2008 at 07:04:40PM +0100, Mark Kettenis wrote:
>> There are some code style problems here too, and although they're not
>> your fault, it'd be nice to fix them while you're there.  Actually, it
>> looks to me as if the temparg variable is completely redundant now, so
>> the above could be simplified to
>>
>>               val = value_addr (val);
>
> Mark's right; also, there are still formatting problems with the patch
> that I commented on the last time I reviewed it :-(  Rob, let me know if
> you'd like me to point them out individually.

Hi all,

This has been a long time coming, but I've finally managed to find
some time to get this finished. Please find attached what I believe
should be the final version of this patch, checked against the current
head with no regressions.

Rob

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: remove_deprecated_set_value_type.patch --]
[-- Type: text/x-diff; name=remove_deprecated_set_value_type.patch, Size: 6817 bytes --]

	Removes some uses of deprecated_set_value_type
	* ada-lang.c (ada_coerce_to_simple_array_type): Create a new zero
	  value of the correct type instead of changing type.
	* c-valprint.c (c_value_print): Call copy_value_and_change_type.
	* printcmd.c (printf_command): Create a zero value of the
	  correct type and copy the contents of the old value into it.
	* valops.c (value_cast_pointers, value_cast, value_assign,
	  value_addr): Call value_value_copy_and_change_type instead
	  of copying the value and then changing the type.
	* value.c (value_copy_and_change_type): Define.
	* value.h (value_copy_and_change_type): Declare.

Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.151
diff -u -p -r1.151 ada-lang.c
--- ada-lang.c	21 Jul 2008 16:47:10 -0000	1.151
+++ ada-lang.c	26 Jul 2008 22:16:29 -0000
@@ -1767,9 +1767,8 @@ struct type *
 ada_coerce_to_simple_array_type (struct type *type)
 {
   struct value *mark = value_mark ();
-  struct value *dummy = value_from_longest (builtin_type_long, 0);
+  struct value *dummy = value_zero (type, not_lval);
   struct type *result;
-  deprecated_set_value_type (dummy, type);
   result = ada_type_of_array (dummy, 0);
   value_free_to_mark (mark);
   return result;
Index: c-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-valprint.c,v
retrieving revision 1.50
diff -u -p -r1.50 c-valprint.c
--- c-valprint.c	19 May 2008 15:50:09 -0000	1.50
+++ c-valprint.c	26 Jul 2008 22:16:29 -0000
@@ -562,10 +562,7 @@ c_value_print (struct value *val, struct
 	      /* Copy value, change to pointer, so we don't get an
 	       * error about a non-pointer type in value_rtti_target_type
 	       */
-	      struct value *temparg;
-	      temparg=value_copy(val);
-	      deprecated_set_value_type (temparg, lookup_pointer_type (TYPE_TARGET_TYPE(type)));
-	      val=temparg;
+	      val=value_addr (val);
 	    }
 	  /* Pointer to class, check real type of object */
 	  fprintf_filtered (stream, "(");
Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.127
diff -u -p -r1.127 printcmd.c
--- printcmd.c	6 Jun 2008 20:58:08 -0000	1.127
+++ printcmd.c	26 Jul 2008 22:16:30 -0000
@@ -2005,9 +2005,21 @@ printf_command (char *arg, int from_tty)
 	  {
 	    struct type *type = value_type (val_args[nargs]);
 	    if (TYPE_LENGTH (type) == sizeof (float))
-	      deprecated_set_value_type (val_args[nargs], builtin_type_float);
+        {
+          struct value *temp = value_zero (builtin_type_float, not_lval);
+          memcpy (value_contents_writeable (temp),
+                          value_contents (val_args[nargs]),
+                          TYPE_LENGTH (builtin_type_float));
+          val_args[nargs] = temp;
+        }
 	    if (TYPE_LENGTH (type) == sizeof (double))
-	      deprecated_set_value_type (val_args[nargs], builtin_type_double);
+        {
+          struct value *temp = value_zero (builtin_type_double, not_lval);
+          memcpy (value_contents_writeable (temp),
+                          value_contents (val_args[nargs]),
+                          TYPE_LENGTH (builtin_type_double));
+          val_args[nargs] = temp;
+        }
 	  }
 	nargs++;
 	s = s1;
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.192
diff -u -p -r1.192 valops.c
--- valops.c	15 Jul 2008 22:13:42 -0000	1.192
+++ valops.c	26 Jul 2008 22:16:32 -0000
@@ -281,8 +281,7 @@ value_cast_pointers (struct type *type, 
    }
 
   /* No superclass found, just change the pointer type.  */
-  arg2 = value_copy (arg2);
-  deprecated_set_value_type (arg2, type);
+  arg2 = value_copy_and_change_type (arg2, type);
   arg2 = value_change_enclosing_type (arg2, type);
   set_value_pointed_to_offset (arg2, 0);	/* pai: chk_val */
   return arg2;
@@ -480,8 +479,7 @@ value_cast (struct type *type, struct va
       if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
 	return value_cast_pointers (type, arg2);
 
-      arg2 = value_copy (arg2);
-      deprecated_set_value_type (arg2, type);
+      arg2 = value_copy_and_change_type (arg2, type);
       arg2 = value_change_enclosing_type (arg2, type);
       set_value_pointed_to_offset (arg2, 0);	/* pai: chk_val */
       return arg2;
@@ -926,10 +924,9 @@ value_assign (struct value *toval, struc
       fromval = value_from_longest (type, fieldval);
     }
 
-  val = value_copy (toval);
+  val = value_copy_and_change_type (toval, type);
   memcpy (value_contents_raw (val), value_contents (fromval),
 	  TYPE_LENGTH (type));
-  deprecated_set_value_type (val, type);
   val = value_change_enclosing_type (val, 
 				     value_enclosing_type (fromval));
   set_value_embedded_offset (val, value_embedded_offset (fromval));
@@ -1106,8 +1103,8 @@ value_addr (struct value *arg1)
          keep the same location information, which is efficient, and
          allows &(&X) to get the location containing the reference.  */
       arg2 = value_copy (arg1);
-      deprecated_set_value_type (arg2, 
-				 lookup_pointer_type (TYPE_TARGET_TYPE (type)));
+      arg2 = value_copy_and_change_type (arg1,
+                         lookup_pointer_type (TYPE_TARGET_TYPE (type)));
       return arg2;
     }
   if (TYPE_CODE (type) == TYPE_CODE_FUNC)
Index: value.c
===================================================================
RCS file: /cvs/src/src/gdb/value.c,v
retrieving revision 1.64
diff -u -p -r1.64 value.c
--- value.c	11 Jun 2008 19:59:09 -0000	1.64
+++ value.c	26 Jul 2008 22:16:33 -0000
@@ -276,6 +276,15 @@ deprecated_set_value_type (struct value 
   value->type = type;
 }
 
+struct value *
+value_copy_and_change_type (struct value *arg, struct type *type)
+{
+  struct value *val = value_copy (arg);
+  val->type = type;
+
+  return val;
+}
+
 int
 value_offset (struct value *value)
 {
Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.115
diff -u -p -r1.115 value.h
--- value.h	6 Jun 2008 20:58:08 -0000	1.115
+++ value.h	26 Jul 2008 22:16:34 -0000
@@ -57,6 +57,12 @@ extern struct type *value_type (struct v
 extern void deprecated_set_value_type (struct value *value,
 				       struct type *type);
 
+/* Copy ARG to new value. The new value is exactly the same, except
+   for its type, which is set to TYPE.  */
+
+extern struct value *value_copy_and_change_type (struct value *arg,
+                                               struct type *type);
+
 /* Only used for bitfields; number of bits contained in them.  */
 
 extern int value_bitsize (struct value *);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Remove deprecated_set_value_type (part 1)
  2008-07-27 19:16         ` Rob Quill
@ 2008-08-09 15:10           ` Rob Quill
  0 siblings, 0 replies; 8+ messages in thread
From: Rob Quill @ 2008-08-09 15:10 UTC (permalink / raw)
  To: Mark Kettenis, rob.quill, gdb-patches, Daniel Jacobowitz

Ping :)

Rob

2008/7/27 Rob Quill <rob.quill@gmail.com>:
> 2008/2/26 Daniel Jacobowitz <drow@false.org>:
>> On Wed, Jan 30, 2008 at 07:04:40PM +0100, Mark Kettenis wrote:
>>> There are some code style problems here too, and although they're not
>>> your fault, it'd be nice to fix them while you're there.  Actually, it
>>> looks to me as if the temparg variable is completely redundant now, so
>>> the above could be simplified to
>>>
>>>               val = value_addr (val);
>>
>> Mark's right; also, there are still formatting problems with the patch
>> that I commented on the last time I reviewed it :-(  Rob, let me know if
>> you'd like me to point them out individually.
>
> Hi all,
>
> This has been a long time coming, but I've finally managed to find
> some time to get this finished. Please find attached what I believe
> should be the final version of this patch, checked against the current
> head with no regressions.
>
> Rob
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-08-09 15:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-21  4:53 Remove deprecated_set_value_type (part 1) Rob Quill
2008-01-29 20:07 ` Daniel Jacobowitz
2008-01-30 12:06   ` Rob Quill
2008-01-30 18:06     ` Mark Kettenis
2008-02-26  2:24       ` Daniel Jacobowitz
2008-02-26 14:36         ` Rob Quill
2008-07-27 19:16         ` Rob Quill
2008-08-09 15:10           ` Rob Quill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox