2005-02-03 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / value.c
index 3835a8a3aa5f4451620905afafea68bfee8a5754..a871df31283c83c520c50117b98cacb5e14b5699 100644 (file)
@@ -1,8 +1,8 @@
 /* Low level packing and unpacking of values for GDB, the GNU Debugger.
 
    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
-   1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003 Free Software
-   Foundation, Inc.
+   1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005 Free
+   Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -83,11 +83,11 @@ 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;
-  VALUE_ENCLOSING_TYPE (val) = type;
+  val->enclosing_type = type;
   VALUE_LVAL (val) = not_lval;
   VALUE_ADDRESS (val) = 0;
   VALUE_FRAME_ID (val) = null_frame_id;
@@ -95,7 +95,7 @@ allocate_value (struct type *type)
   val->bitpos = 0;
   val->bitsize = 0;
   VALUE_REGNUM (val) = -1;
-  VALUE_LAZY (val) = 0;
+  val->lazy = 0;
   VALUE_OPTIMIZED_OUT (val) = 0;
   VALUE_EMBEDDED_OFFSET (val) = 0;
   VALUE_POINTED_TO_OFFSET (val) = 0;
@@ -147,6 +147,39 @@ value_bitsize (struct value *value)
   return value->bitsize;
 }
 
+bfd_byte *
+value_contents_raw (struct value *value)
+{
+  return value->aligner.contents + value->embedded_offset;
+}
+
+bfd_byte *
+value_contents_all_raw (struct value *value)
+{
+  return value->aligner.contents;
+}
+
+struct type *
+value_enclosing_type (struct value *value)
+{
+  return value->enclosing_type;
+}
+
+const bfd_byte *
+value_contents_all (struct value *value)
+{
+  if (value->lazy)
+    value_fetch_lazy (value);
+  return value->aligner.contents;
+}
+
+int
+value_lazy (struct value *value)
+{
+  return value->lazy;
+}
+
+\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
    if a subsequent value_free_to_mark is passed the mark.  */
@@ -239,7 +272,7 @@ value_release_to_mark (struct value *mark)
 struct value *
 value_copy (struct value *arg)
 {
-  struct type *encl_type = VALUE_ENCLOSING_TYPE (arg);
+  struct type *encl_type = value_enclosing_type (arg);
   struct value *val = allocate_value (encl_type);
   val->type = arg->type;
   VALUE_LVAL (val) = VALUE_LVAL (arg);
@@ -249,15 +282,15 @@ value_copy (struct value *arg)
   val->bitsize = arg->bitsize;
   VALUE_FRAME_ID (val) = VALUE_FRAME_ID (arg);
   VALUE_REGNUM (val) = VALUE_REGNUM (arg);
-  VALUE_LAZY (val) = VALUE_LAZY (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->modifiable = arg->modifiable;
-  if (!VALUE_LAZY (val))
+  if (!value_lazy (val))
     {
-      memcpy (VALUE_CONTENTS_ALL_RAW (val), VALUE_CONTENTS_ALL_RAW (arg),
-             TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg)));
+      memcpy (value_contents_all_raw (val), value_contents_all_raw (arg),
+             TYPE_LENGTH (value_enclosing_type (arg)));
 
     }
   return val;
@@ -279,7 +312,7 @@ record_latest_value (struct value *val)
      In particular, "set $1 = 50" should not affect the variable from which
      the value was taken, and fast watchpoints should be able to assume that
      a value on the value history never changes.  */
-  if (VALUE_LAZY (val))
+  if (value_lazy (val))
     value_fetch_lazy (val);
   /* We preserve VALUE_LVAL so that the user can find out where it was fetched
      from.  This is a bit dubious, because then *&$1 does not just return $1
@@ -449,7 +482,7 @@ value_of_internalvar (struct internalvar *var)
   struct value *val;
 
   val = value_copy (var->value);
-  if (VALUE_LAZY (val))
+  if (value_lazy (val))
     value_fetch_lazy (val);
   VALUE_LVAL (val) = lval_internalvar;
   VALUE_INTERNALVAR (val) = var;
@@ -480,7 +513,7 @@ set_internalvar (struct internalvar *var, struct value *val)
   /* Force the value to be fetched from the target now, to avoid problems
      later when this internalvar is referenced and the target is gone or
      has changed.  */
-  if (VALUE_LAZY (newval))
+  if (value_lazy (newval))
     value_fetch_lazy (newval);
 
   /* Begin code which must not call error().  If var->value points to
@@ -864,9 +897,9 @@ value_static_field (struct type *type, int fieldno)
 struct value *
 value_change_enclosing_type (struct value *val, struct type *new_encl_type)
 {
-  if (TYPE_LENGTH (new_encl_type) <= TYPE_LENGTH (VALUE_ENCLOSING_TYPE (val))) 
+  if (TYPE_LENGTH (new_encl_type) <= TYPE_LENGTH (value_enclosing_type (val))) 
     {
-      VALUE_ENCLOSING_TYPE (val) = new_encl_type;
+      val->enclosing_type = new_encl_type;
       return val;
     }
   else
@@ -876,7 +909,7 @@ value_change_enclosing_type (struct value *val, struct type *new_encl_type)
       
       new_val = (struct value *) xrealloc (val, sizeof (struct value) + TYPE_LENGTH (new_encl_type));
 
-      VALUE_ENCLOSING_TYPE (new_val) = new_encl_type;
+      new_val->enclosing_type = 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. 
@@ -933,13 +966,13 @@ value_primitive_field (struct value *arg1, int offset,
       /* This field is actually a base subobject, so preserve the
          entire object's contents for later references to virtual
          bases, etc.  */
-      v = allocate_value (VALUE_ENCLOSING_TYPE (arg1));
+      v = allocate_value (value_enclosing_type (arg1));
       v->type = type;
-      if (VALUE_LAZY (arg1))
+      if (value_lazy (arg1))
        VALUE_LAZY (v) = 1;
       else
-       memcpy (VALUE_CONTENTS_ALL_RAW (v), VALUE_CONTENTS_ALL_RAW (arg1),
-               TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg1)));
+       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 +
@@ -951,11 +984,11 @@ value_primitive_field (struct value *arg1, int offset,
       /* Plain old data member */
       offset += TYPE_FIELD_BITPOS (arg_type, fieldno) / 8;
       v = allocate_value (type);
-      if (VALUE_LAZY (arg1))
+      if (value_lazy (arg1))
        VALUE_LAZY (v) = 1;
       else
-       memcpy (VALUE_CONTENTS_RAW (v),
-               VALUE_CONTENTS_RAW (arg1) + offset,
+       memcpy (value_contents_raw (v),
+               value_contents_raw (arg1) + offset,
                TYPE_LENGTH (type));
       v->offset = (value_offset (arg1) + offset
                   + VALUE_EMBEDDED_OFFSET (arg1));
@@ -1154,12 +1187,12 @@ retry:
     case TYPE_CODE_ENUM:
     case TYPE_CODE_BOOL:
     case TYPE_CODE_RANGE:
-      store_signed_integer (VALUE_CONTENTS_RAW (val), len, num);
+      store_signed_integer (value_contents_raw (val), len, num);
       break;
 
     case TYPE_CODE_REF:
     case TYPE_CODE_PTR:
-      store_typed_address (VALUE_CONTENTS_RAW (val), type, (CORE_ADDR) num);
+      store_typed_address (value_contents_raw (val), type, (CORE_ADDR) num);
       break;
 
     default:
@@ -1175,7 +1208,7 @@ struct value *
 value_from_pointer (struct type *type, CORE_ADDR addr)
 {
   struct value *val = allocate_value (type);
-  store_typed_address (VALUE_CONTENTS_RAW (val), type, addr);
+  store_typed_address (value_contents_raw (val), type, addr);
   return val;
 }
 
@@ -1204,7 +1237,7 @@ value_from_string (char *ptr)
                                  string_char_type,
                                  rangetype);
   val = allocate_value (stringtype);
-  memcpy (VALUE_CONTENTS_RAW (val), ptr, len);
+  memcpy (value_contents_raw (val), ptr, len);
   return val;
 }
 
@@ -1218,7 +1251,7 @@ value_from_double (struct type *type, DOUBLEST num)
 
   if (code == TYPE_CODE_FLT)
     {
-      store_typed_floating (VALUE_CONTENTS_RAW (val), base_type, num);
+      store_typed_floating (value_contents_raw (val), base_type, num);
     }
   else
     error ("Unexpected type encountered for floating constant.");
This page took 0.02813 seconds and 4 git commands to generate.