* corelow.c, exec.c, inftarg.c, m3-nat.c, op50-rom.c, procfs.c,
[deliverable/binutils-gdb.git] / gdb / values.c
index 0ea9c4ad95e04200508c4f8ac410dd61d44fac10..aa4a4f2090a7cc4563f3786bc2e1864b56d47f5e 100644 (file)
@@ -1,5 +1,6 @@
 /* Low level packing and unpacking of values for GDB, the GNU Debugger.
-   Copyright 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
+   Copyright 1986, 1987, 1989, 1991, 1993, 1994
+   Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -189,6 +190,24 @@ release_value (val)
     }
 }
 
+/* Release all values up to mark  */
+value_ptr
+value_release_to_mark (mark)
+     value_ptr mark;
+{
+  value_ptr val, next;
+
+  for (val = next = all_values; next; next = VALUE_NEXT (next))
+    if (VALUE_NEXT (next) == mark)
+      {
+       all_values = VALUE_NEXT (next);
+       VALUE_NEXT (next) = 0;
+       return val;
+      }
+  all_values = 0;
+  return val;
+}
+
 /* Return a copy of the value ARG.
    It contains the same contents, for same memory address,
    but it's a different block of storage.  */
@@ -241,6 +260,18 @@ record_latest_value (val)
       if (i) return -1;                /* Indicate value not saved in history */
     }
 
+  /* We don't want this value to have anything to do with the inferior anymore.
+     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))
+    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
+     but the current contents of that location.  c'est la vie...  */
+  val->modifiable = 0;
+  release_value (val);
+
   /* Here we treat value_history_count as origin-zero
      and applying to the value being stored now.  */
 
@@ -257,18 +288,6 @@ record_latest_value (val)
 
   value_history_chain->values[i] = val;
 
-  /* We don't want this value to have anything to do with the inferior anymore.
-     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))
-    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
-     but the current contents of that location.  c'est la vie...  */
-  val->modifiable = 0;
-  release_value (val);
-
   /* Now we regard value_history_count as origin-one
      and applying to the value just stored.  */
 
@@ -656,11 +675,13 @@ unpack_double (type, valaddr, invp)
   *invp = 0;                   /* Assume valid.   */
   if (code == TYPE_CODE_FLT)
     {
+#ifdef INVALID_FLOAT
       if (INVALID_FLOAT (valaddr, len))
        {
          *invp = 1;
          return 1.234567891011121314;
        }
+#endif
       return extract_floating (valaddr, len);
     }
   else if (nosign)
@@ -862,16 +883,23 @@ value_virtual_fn_field (arg1p, f, j, type, offset)
      a virtual function.  */
   entry = value_subscript (vtbl, vi);
 
-  /* Move the `this' pointer according to the virtual function table. */ 
-  VALUE_OFFSET (arg1) += value_as_long (value_field (entry, 0))/* + offset*/;
-
-  if (! VALUE_LAZY (arg1))
+  if (TYPE_CODE (VALUE_TYPE (entry)) == TYPE_CODE_STRUCT)
     {
-      VALUE_LAZY (arg1) = 1;
-      value_fetch_lazy (arg1);
-    }
+      /* Move the `this' pointer according to the virtual function table. */
+      VALUE_OFFSET (arg1) += value_as_long (value_field (entry, 0));
+      
+      if (! VALUE_LAZY (arg1))
+       {
+         VALUE_LAZY (arg1) = 1;
+         value_fetch_lazy (arg1);
+       }
 
-  vfn = value_field (entry, 2);
+      vfn = value_field (entry, 2);
+    }
+  else if (TYPE_CODE (VALUE_TYPE (entry)) == TYPE_CODE_PTR)
+    vfn = entry;
+  else
+    error ("I'm confused:  virtual function table has bad type");
   /* Reinstantiate the function pointer with the correct type.  */
   VALUE_TYPE (vfn) = lookup_pointer_type (TYPE_FN_FIELD_TYPE (f, j));
 
@@ -913,7 +941,8 @@ value_headof (in_arg, btype, dtype)
   /* Check that VTBL looks like it points to a virtual function table.  */
   msymbol = lookup_minimal_symbol_by_pc (VALUE_ADDRESS (vtbl));
   if (msymbol == NULL
-      || !VTBL_PREFIX_P (demangled_name = SYMBOL_NAME (msymbol)))
+      || (demangled_name = SYMBOL_NAME (msymbol)) == NULL
+      || !VTBL_PREFIX_P (demangled_name))
     {
       /* If we expected to find a vtable, but did not, let the user
         know that we aren't happy, but don't throw an error.
@@ -932,6 +961,9 @@ value_headof (in_arg, btype, dtype)
     {
       entry = value_subscript (vtbl, value_from_longest (builtin_type_int, 
                                                      (LONGEST) i));
+      /* This won't work if we're using thunks. */
+      if (TYPE_CODE (VALUE_TYPE (entry)) != TYPE_CODE_STRUCT)
+       break;
       offset = longest_to_int (value_as_long (value_field (entry, 0)));
       /* If we use '<=' we can handle single inheritance
        * where all offsets are zero - just use the first entry found. */
@@ -1217,11 +1249,10 @@ unpack_field_as_long (type, valaddr, fieldno)
 
   /* Extract bits.  See comment above. */
 
-#if BITS_BIG_ENDIAN
-  lsbcount = (sizeof val * 8 - bitpos % 8 - bitsize);
-#else
-  lsbcount = (bitpos % 8);
-#endif
+  if (BITS_BIG_ENDIAN)
+    lsbcount = (sizeof val * 8 - bitpos % 8 - bitsize);
+  else
+    lsbcount = (bitpos % 8);
   val >>= lsbcount;
 
   /* If the field does not entirely fill a LONGEST, then zero the sign bits.
@@ -1268,9 +1299,8 @@ modify_field (addr, fieldval, bitpos, bitsize)
   oword = extract_signed_integer (addr, sizeof oword);
 
   /* Shifting for bit field depends on endianness of the target machine.  */
-#if BITS_BIG_ENDIAN
-  bitpos = sizeof (oword) * 8 - bitpos - bitsize;
-#endif
+  if (BITS_BIG_ENDIAN)
+    bitpos = sizeof (oword) * 8 - bitpos - bitsize;
 
   /* Mask out old value, while avoiding shifts >= size of oword */
   if (bitsize < 8 * sizeof (oword))
@@ -1436,8 +1466,6 @@ set_return_value (val)
      value_ptr val;
 {
   register enum type_code code = TYPE_CODE (VALUE_TYPE (val));
-  double dbuf;
-  LONGEST lbuf;
 
   if (code == TYPE_CODE_ERROR)
     error ("Function return type unknown.");
@@ -1446,19 +1474,7 @@ set_return_value (val)
       || code == TYPE_CODE_UNION)      /* FIXME, implement struct return.  */
     error ("GDB does not support specifying a struct or union return value.");
 
-  /* FIXME, this is bogus.  We don't know what the return conventions
-     are, or how values should be promoted.... */
-  if (code == TYPE_CODE_FLT)
-    {
-      dbuf = value_as_double (val);
-
-      STORE_RETURN_VALUE (VALUE_TYPE (val), (char *)&dbuf);
-    }
-  else
-    {
-      lbuf = value_as_long (val);
-      STORE_RETURN_VALUE (VALUE_TYPE (val), (char *)&lbuf);
-    }
+  STORE_RETURN_VALUE (VALUE_TYPE (val), VALUE_CONTENTS (val));
 }
 \f
 void
This page took 0.024853 seconds and 4 git commands to generate.