This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFA]: value_change_enclosing_type
- To: gdb-patches at sources dot redhat dot com
- Subject: [RFA]: value_change_enclosing_type
- From: Daniel Berlin <dan at cgsoftware dot com>
- Date: 07 May 2001 14:04:17 -0400
Accidently includes the value_static_field change, since I couldn't
get diff to not include it, and i haven't committed it just yet.
Sorry about that.
This change fixes a particularly annoying problem. If we changed the
enclosing type to a larger type, we never allocated more space, and
thus, were using random memory.
2001-05-07 Daniel Berlin <dan@cgsoftware.com>
Changes by Jim Ingham:
* values.c (value_change_enclosing_type): New function. If the
new enclosing type is larger than the old one, we need to allocate
more space.
* value.h: Add value_change_enclosing_type prototype.
* valops.c (value_cast): Use it.
(value_assign): Use it.
(value_addr): Use it.
(value_ind): Use it.
(value_full_object): Use it.
Index: values.c
===================================================================
RCS file: /cvs/src/src/gdb/values.c,v
retrieving revision 1.15
diff -c -3 -p -w -B -b -r1.15 values.c
*** values.c 2001/04/27 00:19:09 1.15
--- values.c 2001/05/07 17:53:14
*************** value_static_field (struct type *type, i
*** 762,775 ****
--- 762,825 ----
}
else
{
+ /* Anything static that isn't a constant, has an address */
+ if (SYMBOL_CLASS (sym) != LOC_CONST)
+ {
addr = SYMBOL_VALUE_ADDRESS (sym);
sect = SYMBOL_BFD_SECTION (sym);
}
+ /* However, static const's do not, the value is already known. */
+ else
+ {
+ return value_from_longest (TYPE_FIELD_TYPE (type, fieldno), SYMBOL_VALUE (sym));
+ }
+ }
SET_FIELD_PHYSADDR (TYPE_FIELD (type, fieldno), addr);
}
return value_at (TYPE_FIELD_TYPE (type, fieldno), addr, sect);
}
+ /* Change the enclosing type of a value object VAL to NEW_ENCL_TYPE.
+ You have to be careful here, since the size of the data area for the value
+ is set by the length of the enclosing type. So if NEW_ENCL_TYPE is bigger
+ than the old enclosing type, you have to allocate more space for the data.
+ The return value is a pointer to the new version of this value structure. */
+
+ value_ptr
+ value_change_enclosing_type (value_ptr val, struct type *new_encl_type)
+ {
+ if (TYPE_LENGTH (new_encl_type) <= TYPE_LENGTH (VALUE_ENCLOSING_TYPE (val)))
+ {
+ VALUE_ENCLOSING_TYPE (val) = new_encl_type;
+ return val;
+ }
+ else
+ {
+ value_ptr new_val;
+ register value_ptr prev;
+
+ new_val = (value_ptr) xrealloc (val, sizeof (struct value) + TYPE_LENGTH (new_encl_type));
+
+ /* We have to make sure this ends up in the same place in the value
+ chain as the original copy, so it's clean-up behavior is the same.
+ If the value has been released, this is a waste of time, but there
+ is no way to tell that in advance, so... */
+
+ if (val != all_values)
+ {
+ for (prev = all_values; prev != NULL; prev = prev->next)
+ {
+ if (prev->next == val)
+ {
+ prev->next = new_val;
+ break;
+ }
+ }
+ }
+
+ return new_val;
+ }
+ }
/* Given a value ARG1 (offset by OFFSET bytes)
of a struct or union type ARG_TYPE,
extract and return the value of one of its (non-static) fields.
Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.18
diff -c -3 -p -w -B -b -r1.18 value.h
*** value.h 2001/04/27 00:19:09 1.18
--- value.h 2001/05/07 17:53:14
*************** extern value_ptr allocate_value (struct
*** 307,312 ****
--- 307,314 ----
extern value_ptr allocate_repeat_value (struct type *type, int count);
+ extern value_ptr value_change_enclosing_type (value_ptr val, struct type *new_type);
+
extern value_ptr value_mark (void);
extern void value_free_to_mark (value_ptr mark);
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.35
diff -c -3 -p -w -B -b -r1.35 valops.c
*** valops.c 2001/04/27 00:19:09 1.35
--- valops.c 2001/05/07 17:53:15
*************** value_cast (struct type *type, register
*** 365,371 ****
/* No superclass found, just fall through to change ptr type. */
}
VALUE_TYPE (arg2) = type;
! VALUE_ENCLOSING_TYPE (arg2) = type; /* pai: chk_val */
VALUE_POINTED_TO_OFFSET (arg2) = 0; /* pai: chk_val */
return arg2;
}
--- 366,372 ----
/* No superclass found, just fall through to change ptr type. */
}
VALUE_TYPE (arg2) = type;
! arg2 = value_change_enclosing_type (arg2, type);
VALUE_POINTED_TO_OFFSET (arg2) = 0; /* pai: chk_val */
return arg2;
}
*************** value_assign (register value_ptr toval,
*** 609,615 ****
case lval_internalvar:
set_internalvar (VALUE_INTERNALVAR (toval), fromval);
val = value_copy (VALUE_INTERNALVAR (toval)->value);
! VALUE_ENCLOSING_TYPE (val) = VALUE_ENCLOSING_TYPE (fromval);
VALUE_EMBEDDED_OFFSET (val) = VALUE_EMBEDDED_OFFSET (fromval);
VALUE_POINTED_TO_OFFSET (val) = VALUE_POINTED_TO_OFFSET (fromval);
return val;
--- 610,616 ----
case lval_internalvar:
set_internalvar (VALUE_INTERNALVAR (toval), fromval);
val = value_copy (VALUE_INTERNALVAR (toval)->value);
! val = value_change_enclosing_type (val, VALUE_ENCLOSING_TYPE (fromval));
VALUE_EMBEDDED_OFFSET (val) = VALUE_EMBEDDED_OFFSET (fromval);
VALUE_POINTED_TO_OFFSET (val) = VALUE_POINTED_TO_OFFSET (fromval);
return val;
*************** value_assign (register value_ptr toval,
*** 823,829 ****
memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS (fromval),
TYPE_LENGTH (type));
VALUE_TYPE (val) = type;
! VALUE_ENCLOSING_TYPE (val) = VALUE_ENCLOSING_TYPE (fromval);
VALUE_EMBEDDED_OFFSET (val) = VALUE_EMBEDDED_OFFSET (fromval);
VALUE_POINTED_TO_OFFSET (val) = VALUE_POINTED_TO_OFFSET (fromval);
--- 824,830 ----
memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS (fromval),
TYPE_LENGTH (type));
VALUE_TYPE (val) = type;
! val = value_change_enclosing_type (val, VALUE_ENCLOSING_TYPE (fromval));
VALUE_EMBEDDED_OFFSET (val) = VALUE_EMBEDDED_OFFSET (fromval);
VALUE_POINTED_TO_OFFSET (val) = VALUE_POINTED_TO_OFFSET (fromval);
*************** value_addr (value_ptr arg1)
*** 965,971 ****
/* This may be a pointer to a base subobject; so remember the
full derived object's type ... */
! VALUE_ENCLOSING_TYPE (arg2) = lookup_pointer_type (VALUE_ENCLOSING_TYPE (arg1));
/* ... and also the relative position of the subobject in the full object */
VALUE_POINTED_TO_OFFSET (arg2) = VALUE_EMBEDDED_OFFSET (arg1);
VALUE_BFD_SECTION (arg2) = VALUE_BFD_SECTION (arg1);
--- 966,972 ----
/* This may be a pointer to a base subobject; so remember the
full derived object's type ... */
! arg2 = value_change_enclosing_type (arg2, lookup_pointer_type (VALUE_ENCLOSING_TYPE (arg1)));
/* ... and also the relative position of the subobject in the full object */
VALUE_POINTED_TO_OFFSET (arg2) = VALUE_EMBEDDED_OFFSET (arg1);
VALUE_BFD_SECTION (arg2) = VALUE_BFD_SECTION (arg1);
*************** value_ind (value_ptr arg1)
*** 1009,1015 ****
/* Re-adjust type */
VALUE_TYPE (arg2) = TYPE_TARGET_TYPE (base_type);
/* Add embedding info */
! VALUE_ENCLOSING_TYPE (arg2) = enc_type;
VALUE_EMBEDDED_OFFSET (arg2) = VALUE_POINTED_TO_OFFSET (arg1);
/* We may be pointing to an object of some derived type */
--- 1010,1016 ----
/* Re-adjust type */
VALUE_TYPE (arg2) = TYPE_TARGET_TYPE (base_type);
/* Add embedding info */
! arg2 = value_change_enclosing_type (arg2, enc_type);
VALUE_EMBEDDED_OFFSET (arg2) = VALUE_POINTED_TO_OFFSET (arg1);
/* We may be pointing to an object of some derived type */
*************** value_full_object (value_ptr argp, struc
*** 3165,3171 ****
type is wrong, set it *//* pai: FIXME -- sounds iffy */
if (full)
{
! VALUE_ENCLOSING_TYPE (argp) = real_type;
return argp;
}
--- 3047,3053 ----
type is wrong, set it *//* pai: FIXME -- sounds iffy */
if (full)
{
! argp = value_change_enclosing_type (argp, real_type);
return argp;
}
--
"When I go, I'm flying Air Bizarre. It's a good airline. You
buy a one way round trip ticket. You leave any Monday, and they
bring you back the previous Friday... That way you still have
the weekend.
"-Steven Wright