This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [rfc] Fix value_assign return value (Re: [patch] fix pre-/post- in-/decrement)
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: dan at codesourcery dot com (Daniel Jacobowitz)
- Cc: ken at linux dot vnet dot ibm dot com (Ken Werner), gdb-patches at sourceware dot org, brobecker at adacore dot com (Joel Brobecker), vladimir at codesourcery dot com (Vladimir Prus)
- Date: Wed, 1 Dec 2010 17:51:13 +0100 (CET)
- Subject: Re: [rfc] Fix value_assign return value (Re: [patch] fix pre-/post- in-/decrement)
Dan Jacobowitz wrote:
> On Wed, Oct 06, 2010 at 08:59:18PM +0200, Ulrich Weigand wrote:
> > * valops.c (value_assign): Returned value is never lazy. If a
> > C++ class type is returned, fix incorrect enclosing type / embedded
> > offset. If internal variable is returned, allocate new internalvar
> > value using value_of_internalvar.
> >
> > * NEWS: Document changes in behavior of "print x = 0" and similar
> > expressions.
>
> Looks good to me.
OK, thanks for the review! I've now updated the patch for recent changes
(see below), retested on i386-linux, and checked it in.
Bye,
Ulrich
ChangeLog:
* valops.c (value_assign): Returned value is never lazy. If a
C++ class type is returned, fix incorrect enclosing type / embedded
offset. If internal variable is returned, allocate new internalvar
value using value_of_internalvar.
* NEWS: Document changes in behavior of "print x = 0" and similar
expressions.
Index: gdb/NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.411
diff -u -p -r1.411 NEWS
--- gdb/NEWS 5 Nov 2010 16:55:37 -0000 1.411
+++ gdb/NEWS 25 Nov 2010 16:11:03 -0000
@@ -46,6 +46,12 @@
feature requires proper debuginfo support from the compiler; it
was added to GCC 4.5.
+* GDB now follows GCC's rules on accessing volatile objects when
+ reading or writing target state during expression evaluation.
+ One notable difference to prior behavior is that "print x = 0"
+ no longer generates a read of x; the value of the assignment is
+ now always taken directly from the value being assigned.
+
* GDB now has some support for using labels in the program's source in
linespecs. For instance, you can use "advance label" to continue
execution to a label.
Index: gdb/valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.257
diff -u -p -r1.257 valops.c
--- gdb/valops.c 10 Nov 2010 17:47:23 -0000 1.257
+++ gdb/valops.c 25 Nov 2010 16:11:04 -0000
@@ -1138,11 +1138,8 @@ value_assign (struct value *toval, struc
{
case lval_internalvar:
set_internalvar (VALUE_INTERNALVAR (toval), fromval);
- val = value_copy (fromval);
- set_value_enclosing_type (val, value_enclosing_type (fromval));
- set_value_embedded_offset (val, value_embedded_offset (fromval));
- set_value_pointed_to_offset (val, value_pointed_to_offset (fromval));
- return val;
+ return value_of_internalvar (get_type_arch (type),
+ VALUE_INTERNALVAR (toval));
case lval_internalvar_component:
set_internalvar_component (VALUE_INTERNALVAR (toval),
@@ -1328,13 +1325,23 @@ value_assign (struct value *toval, struc
fromval = value_from_longest (type, fieldval);
}
+ /* 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);
+ set_value_lazy (val, 0);
memcpy (value_contents_raw (val), value_contents (fromval),
TYPE_LENGTH (type));
- deprecated_set_value_type (val, type);
- set_value_enclosing_type (val, value_enclosing_type (fromval));
- set_value_embedded_offset (val, value_embedded_offset (fromval));
- set_value_pointed_to_offset (val, value_pointed_to_offset (fromval));
+
+ /* We copy over the enclosing type and pointed-to offset from FROMVAL
+ in the case of pointer types. For object types, the enclosing type
+ and embedded offset must *not* be copied: the target object refered
+ to by TOVAL retains its original dynamic type after assignment. */
+ if (TYPE_CODE (type) == TYPE_CODE_PTR)
+ {
+ set_value_enclosing_type (val, value_enclosing_type (fromval));
+ set_value_pointed_to_offset (val, value_pointed_to_offset (fromval));
+ }
return val;
}
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com