2005-02-07 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / value.c
index 3ff911ccba6b86441d4d7baff0aee01baa9427a6..1a8796e332cd985d8e5ceed9e4e0f71544d2d451 100644 (file)
@@ -83,7 +83,7 @@ allocate_value (struct type *type)
   struct value *val;
   struct type *atype = check_typedef (type);
 
-  val = (struct value *) xmalloc (sizeof (struct value) + TYPE_LENGTH (atype));
+  val = (struct value *) xzalloc (sizeof (struct value) + TYPE_LENGTH (atype));
   val->next = all_values;
   all_values = val;
   val->type = type;
@@ -96,9 +96,9 @@ allocate_value (struct type *type)
   val->bitsize = 0;
   VALUE_REGNUM (val) = -1;
   val->lazy = 0;
-  VALUE_OPTIMIZED_OUT (val) = 0;
-  VALUE_EMBEDDED_OFFSET (val) = 0;
-  VALUE_POINTED_TO_OFFSET (val) = 0;
+  val->optimized_out = 0;
+  val->embedded_offset = 0;
+  val->pointed_to_offset = 0;
   val->modifiable = 1;
   return val;
 }
@@ -179,6 +179,91 @@ value_lazy (struct value *value)
   return value->lazy;
 }
 
+void
+set_value_lazy (struct value *value, int val)
+{
+  value->lazy = val;
+}
+
+const bfd_byte *
+value_contents (struct value *value)
+{
+  return value_contents_writeable (value);
+}
+
+bfd_byte *
+value_contents_writeable (struct value *value)
+{
+  if (value->lazy)
+    value_fetch_lazy (value);
+  return value->aligner.contents;
+}
+
+int
+value_optimized_out (struct value *value)
+{
+  return value->optimized_out;
+}
+
+void
+set_value_optimized_out (struct value *value, int val)
+{
+  value->optimized_out = val;
+}
+
+int
+value_embedded_offset (struct value *value)
+{
+  return value->embedded_offset;
+}
+
+void
+set_value_embedded_offset (struct value *value, int val)
+{
+  value->embedded_offset = val;
+}
+
+int
+value_pointed_to_offset (struct value *value)
+{
+  return value->pointed_to_offset;
+}
+
+void
+set_value_pointed_to_offset (struct value *value, int val)
+{
+  value->pointed_to_offset = val;
+}
+
+enum lval_type *
+deprecated_value_lval_hack (struct value *value)
+{
+  return &value->lval;
+}
+
+CORE_ADDR *
+deprecated_value_address_hack (struct value *value)
+{
+  return &value->location.address;
+}
+
+struct internalvar **
+deprecated_value_internalvar_hack (struct value *value)
+{
+  return &value->location.internalvar;
+}
+
+struct frame_id *
+deprecated_value_frame_id_hack (struct value *value)
+{
+  return &value->frame_id;
+}
+
+short *
+deprecated_value_regnum_hack (struct value *value)
+{
+  return &value->regnum;
+}
 \f
 /* Return a mark in the value chain.  All values allocated after the
    mark is obtained (except for those released) are subject to being freed
@@ -283,9 +368,9 @@ value_copy (struct value *arg)
   VALUE_FRAME_ID (val) = VALUE_FRAME_ID (arg);
   VALUE_REGNUM (val) = VALUE_REGNUM (arg);
   val->lazy = arg->lazy;
-  VALUE_OPTIMIZED_OUT (val) = VALUE_OPTIMIZED_OUT (arg);
-  VALUE_EMBEDDED_OFFSET (val) = VALUE_EMBEDDED_OFFSET (arg);
-  VALUE_POINTED_TO_OFFSET (val) = VALUE_POINTED_TO_OFFSET (arg);
+  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))
     {
@@ -493,13 +578,13 @@ void
 set_internalvar_component (struct internalvar *var, int offset, int bitpos,
                           int bitsize, struct value *newval)
 {
-  char *addr = VALUE_CONTENTS (var->value) + offset;
+  bfd_byte *addr = value_contents_writeable (var->value) + offset;
 
   if (bitsize)
     modify_field (addr, value_as_long (newval),
                  bitpos, bitsize);
   else
-    memcpy (addr, VALUE_CONTENTS (newval), TYPE_LENGTH (value_type (newval)));
+    memcpy (addr, value_contents (newval), TYPE_LENGTH (value_type (newval)));
 }
 
 void
@@ -586,7 +671,7 @@ value_as_long (struct value *val)
      in disassemble_command).  It also dereferences references, which
      I suspect is the most logical thing to do.  */
   val = coerce_array (val);
-  return unpack_long (value_type (val), VALUE_CONTENTS (val));
+  return unpack_long (value_type (val), value_contents (val));
 }
 
 DOUBLEST
@@ -595,7 +680,7 @@ value_as_double (struct value *val)
   DOUBLEST foo;
   int inv;
 
-  foo = unpack_double (value_type (val), VALUE_CONTENTS (val), &inv);
+  foo = unpack_double (value_type (val), value_contents (val), &inv);
   if (inv)
     error ("Invalid floating value found in program.");
   return foo;
@@ -699,9 +784,9 @@ value_as_address (struct value *val)
       && TYPE_CODE (value_type (val)) != TYPE_CODE_REF
       && gdbarch_integer_to_address_p (current_gdbarch))
     return gdbarch_integer_to_address (current_gdbarch, value_type (val),
-                                      VALUE_CONTENTS (val));
+                                      value_contents (val));
 
-  return unpack_long (value_type (val), VALUE_CONTENTS (val));
+  return unpack_long (value_type (val), value_contents (val));
 #endif
 }
 \f
@@ -953,7 +1038,7 @@ value_primitive_field (struct value *arg1, int offset,
     {
       v = value_from_longest (type,
                              unpack_field_as_long (arg_type,
-                                                   VALUE_CONTENTS (arg1)
+                                                   value_contents (arg1)
                                                    + offset,
                                                    fieldno));
       v->bitpos = TYPE_FIELD_BITPOS (arg_type, fieldno) % 8;
@@ -969,15 +1054,13 @@ value_primitive_field (struct value *arg1, int offset,
       v = allocate_value (value_enclosing_type (arg1));
       v->type = type;
       if (value_lazy (arg1))
-       VALUE_LAZY (v) = 1;
+       set_value_lazy (v, 1);
       else
        memcpy (value_contents_all_raw (v), value_contents_all_raw (arg1),
                TYPE_LENGTH (value_enclosing_type (arg1)));
       v->offset = value_offset (arg1);
-      VALUE_EMBEDDED_OFFSET (v)
-       = offset +
-       VALUE_EMBEDDED_OFFSET (arg1) +
-       TYPE_FIELD_BITPOS (arg_type, fieldno) / 8;
+      v->embedded_offset = (offset + value_embedded_offset (arg1)
+                           + TYPE_FIELD_BITPOS (arg_type, fieldno) / 8);
     }
   else
     {
@@ -985,13 +1068,13 @@ value_primitive_field (struct value *arg1, int offset,
       offset += TYPE_FIELD_BITPOS (arg_type, fieldno) / 8;
       v = allocate_value (type);
       if (value_lazy (arg1))
-       VALUE_LAZY (v) = 1;
+       set_value_lazy (v, 1);
       else
        memcpy (value_contents_raw (v),
                value_contents_raw (arg1) + offset,
                TYPE_LENGTH (type));
       v->offset = (value_offset (arg1) + offset
-                  + VALUE_EMBEDDED_OFFSET (arg1));
+                  + value_embedded_offset (arg1));
     }
   VALUE_LVAL (v) = VALUE_LVAL (arg1);
   if (VALUE_LVAL (arg1) == lval_internalvar)
@@ -1266,7 +1349,7 @@ coerce_ref (struct value *arg)
   if (TYPE_CODE (value_type_arg_tmp) == TYPE_CODE_REF)
     arg = value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp),
                         unpack_pointer (value_type (arg),              
-                                        VALUE_CONTENTS (arg)));
+                                        value_contents (arg)));
   return arg;
 }
 
This page took 0.02633 seconds and 4 git commands to generate.