gdb:
[deliverable/binutils-gdb.git] / gdb / value.c
index 1c0bc57792cc446d95bc7c860db2487aadd0608f..381318b987c36cee05ea58ff09c361b962fa424c 100644 (file)
@@ -521,7 +521,7 @@ value_entirely_optimized_out (const struct value *value)
   if (value->lval != lval_computed
       || !value->location.computed.funcs->check_validity)
     return 1;
-  return value->location.computed.funcs->check_all_valid (value);
+  return !value->location.computed.funcs->check_any_valid (value);
 }
 
 int
@@ -722,6 +722,20 @@ free_all_values (void)
   all_values = 0;
 }
 
+/* Frees all the elements in a chain of values.  */
+
+void
+free_value_chain (struct value *v)
+{
+  struct value *next;
+
+  for (; v; v = next)
+    {
+      next = value_next (v);
+      value_free (v);
+    }
+}
+
 /* Remove VAL from the chain all_values
    so it will not be freed automatically.  */
 
@@ -733,6 +747,7 @@ release_value (struct value *val)
   if (all_values == val)
     {
       all_values = val->next;
+      val->next = NULL;
       return;
     }
 
@@ -741,6 +756,7 @@ release_value (struct value *val)
       if (v->next == val)
        {
          v->next = val->next;
+         val->next = NULL;
          break;
        }
     }
@@ -810,6 +826,26 @@ value_copy (struct value *arg)
   return val;
 }
 
+/* Return a version of ARG that is non-lvalue.  */
+
+struct value *
+value_non_lval (struct value *arg)
+{
+  if (VALUE_LVAL (arg) != not_lval)
+    {
+      struct type *enc_type = value_enclosing_type (arg);
+      struct value *val = allocate_value (enc_type);
+
+      memcpy (value_contents_all_raw (val), value_contents_all (arg),
+             TYPE_LENGTH (enc_type));
+      val->type = arg->type;
+      set_value_embedded_offset (val, value_embedded_offset (arg));
+      set_value_pointed_to_offset (val, value_pointed_to_offset (arg));
+      return val;
+    }
+   return arg;
+}
+
 void
 set_value_component_location (struct value *component,
                              const struct value *whole)
@@ -1887,21 +1923,11 @@ value_static_field (struct type *type, int fieldno)
            }
        }
       else
-       {
-         /* SYM should never have a SYMBOL_CLASS which will require
-            read_var_value to use the FRAME parameter.  */
-         if (symbol_read_needs_frame (sym))
-           warning (_("static field's value depends on the current "
-                    "frame - bad debug info?"));
-         retval = read_var_value (sym, NULL);
-       }
-      if (retval && VALUE_LVAL (retval) == lval_memory)
-       SET_FIELD_PHYSADDR (TYPE_FIELD (type, fieldno),
-                           value_address (retval));
+       retval = value_of_variable (sym, NULL);
       break;
     }
     default:
-      gdb_assert (0);
+      gdb_assert_not_reached ("unexpected field location kind");
     }
 
   return retval;
@@ -1967,8 +1993,9 @@ value_primitive_field (struct value *arg1, int offset,
        v->bitpos = bitpos % container_bitsize;
       else
        v->bitpos = bitpos % 8;
-      v->offset = value_embedded_offset (arg1)
-       + (bitpos - v->bitpos) / 8;
+      v->offset = (value_embedded_offset (arg1)
+                  + offset
+                  + (bitpos - v->bitpos) / 8);
       v->parent = arg1;
       value_incref (v->parent);
       if (!value_lazy (arg1))
@@ -2250,6 +2277,43 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num)
 }
 
 
+/* Pack NUM into BUF using a target format of TYPE.  */
+
+void
+pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num)
+{
+  int len;
+  enum bfd_endian byte_order;
+
+  type = check_typedef (type);
+  len = TYPE_LENGTH (type);
+  byte_order = gdbarch_byte_order (get_type_arch (type));
+
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_INT:
+    case TYPE_CODE_CHAR:
+    case TYPE_CODE_ENUM:
+    case TYPE_CODE_FLAGS:
+    case TYPE_CODE_BOOL:
+    case TYPE_CODE_RANGE:
+    case TYPE_CODE_MEMBERPTR:
+      store_unsigned_integer (buf, len, byte_order, num);
+      break;
+
+    case TYPE_CODE_REF:
+    case TYPE_CODE_PTR:
+      store_typed_address (buf, type, (CORE_ADDR) num);
+      break;
+
+    default:
+      error (_("\
+Unexpected type (%d) encountered for unsigned integer constant."),
+            TYPE_CODE (type));
+    }
+}
+
+
 /* Convert C numbers into newly allocated values.  */
 
 struct value *
@@ -2262,6 +2326,19 @@ value_from_longest (struct type *type, LONGEST num)
 }
 
 
+/* Convert C unsigned numbers into newly allocated values.  */
+
+struct value *
+value_from_ulongest (struct type *type, ULONGEST num)
+{
+  struct value *val = allocate_value (type);
+
+  pack_unsigned_long (value_contents_raw (val), type, num);
+
+  return val;
+}
+
+
 /* Create a value representing a pointer of type TYPE to the address
    ADDR.  */
 struct value *
@@ -2343,7 +2420,7 @@ coerce_array (struct value *arg)
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_ARRAY:
-      if (current_language->c_style_arrays)
+      if (!TYPE_VECTOR (type) && current_language->c_style_arrays)
        arg = value_coerce_array (arg);
       break;
     case TYPE_CODE_FUNC:
This page took 0.028706 seconds and 4 git commands to generate.