* cp-abi.h (cplus_method_ptr_size): Add TO_TYPE parameter.
[deliverable/binutils-gdb.git] / gdb / valops.c
index 0a5ae14b6a6c145fdea4a89814ed7fe21e040d4e..1ab88ba57ad1c15547444b0377a4bfd621f74583 100644 (file)
@@ -1,14 +1,14 @@
 /* Perform non-arithmetic operations on values, for GDB.
 
-   Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
-   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-   2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+   2008 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -17,9 +17,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "symtab.h"
@@ -38,6 +36,8 @@
 #include "infcall.h"
 #include "dictionary.h"
 #include "cp-support.h"
+#include "dfp.h"
+#include "user-regs.h"
 
 #include <errno.h>
 #include "gdb_string.h"
@@ -81,8 +81,6 @@ static enum
 oload_classification classify_oload_match (struct badness_vector *,
                                           int, int);
 
-static int check_field_in (struct type *, const char *);
-
 static struct value *value_struct_elt_for_reference (struct type *,
                                                     int, struct type *,
                                                     char *,
@@ -130,7 +128,7 @@ struct value *
 find_function_in_inferior (const char *name)
 {
   struct symbol *sym;
-  sym = lookup_symbol (name, 0, VAR_DOMAIN, 0, NULL);
+  sym = lookup_symbol (name, 0, VAR_DOMAIN, 0);
   if (sym != NULL)
     {
       if (SYMBOL_CLASS (sym) != LOC_BLOCK)
@@ -193,6 +191,64 @@ allocate_space_in_inferior (int len)
   return value_as_long (value_allocate_space_in_inferior (len));
 }
 
+/* Cast struct value VAL to type TYPE and return as a value.
+   Both type and val must be of TYPE_CODE_STRUCT or TYPE_CODE_UNION
+   for this to work.  Typedef to one of the codes is permitted.
+   Returns NULL if the cast is neither an upcast nor a downcast.  */
+
+static struct value *
+value_cast_structs (struct type *type, struct value *v2)
+{
+  struct type *t1;
+  struct type *t2;
+  struct value *v;
+
+  gdb_assert (type != NULL && v2 != NULL);
+
+  t1 = check_typedef (type);
+  t2 = check_typedef (value_type (v2));
+
+  /* Check preconditions.  */
+  gdb_assert ((TYPE_CODE (t1) == TYPE_CODE_STRUCT
+              || TYPE_CODE (t1) == TYPE_CODE_UNION)
+             && !!"Precondition is that type is of STRUCT or UNION kind.");
+  gdb_assert ((TYPE_CODE (t2) == TYPE_CODE_STRUCT
+              || TYPE_CODE (t2) == TYPE_CODE_UNION)
+             && !!"Precondition is that value is of STRUCT or UNION kind");
+
+  /* Upcasting: look in the type of the source to see if it contains the
+     type of the target as a superclass.  If so, we'll need to
+     offset the pointer rather than just change its type.  */
+  if (TYPE_NAME (t1) != NULL)
+    {
+      v = search_struct_field (type_name_no_tag (t1),
+                              v2, 0, t2, 1);
+      if (v)
+       return v;
+    }
+
+  /* Downcasting: look in the type of the target to see if it contains the
+     type of the source as a superclass.  If so, we'll need to
+     offset the pointer rather than just change its type.
+     FIXME: This fails silently with virtual inheritance.  */
+  if (TYPE_NAME (t2) != NULL)
+    {
+      v = search_struct_field (type_name_no_tag (t2),
+                              value_zero (t1, not_lval), 0, t1, 1);
+      if (v)
+       {
+         /* Downcasting is possible (t1 is superclass of v2).  */
+         CORE_ADDR addr2 = VALUE_ADDRESS (v2);
+         addr2 -= (VALUE_ADDRESS (v)
+                   + value_offset (v)
+                   + value_embedded_offset (v));
+         return value_at (type, addr2);
+       }
+    }
+
+  return NULL;
+}
+
 /* Cast one pointer or reference type to another.  Both TYPE and
    the type of ARG2 should be pointer types, or else both should be
    reference types.  Returns the new pointer or reference.  */
@@ -200,6 +256,7 @@ allocate_space_in_inferior (int len)
 struct value *
 value_cast_pointers (struct type *type, struct value *arg2)
 {
+  struct type *type1 = check_typedef (type);
   struct type *type2 = check_typedef (value_type (arg2));
   struct type *t1 = check_typedef (TYPE_TARGET_TYPE (type));
   struct type *t2 = check_typedef (TYPE_TARGET_TYPE (type2));
@@ -208,47 +265,23 @@ value_cast_pointers (struct type *type, struct value *arg2)
       && TYPE_CODE (t2) == TYPE_CODE_STRUCT
       && !value_logical_not (arg2))
     {
-      struct value *v;
-
-      /* Look in the type of the source to see if it contains the
-        type of the target as a superclass.  If so, we'll need to
-        offset the pointer rather than just change its type.  */
-      if (TYPE_NAME (t1) != NULL)
-       {
-         struct value *v2;
+      struct value *v2;
 
-         if (TYPE_CODE (type2) == TYPE_CODE_REF)
-           v2 = coerce_ref (arg2);
-         else
-           v2 = value_ind (arg2);
-         v = search_struct_field (type_name_no_tag (t1),
-                                  v2, 0, t2, 1);
-         if (v)
-           {
-             v = value_addr (v);
-             deprecated_set_value_type (v, type);
-             return v;
-           }
-       }
-
-      /* Look in the type of the target to see if it contains the
-        type of the source as a superclass.  If so, we'll need to
-        offset the pointer rather than just change its type.
-        FIXME: This fails silently with virtual inheritance.  */
-      if (TYPE_NAME (t2) != NULL)
+      if (TYPE_CODE (type2) == TYPE_CODE_REF)
+       v2 = coerce_ref (arg2);
+      else
+       v2 = value_ind (arg2);
+      gdb_assert (TYPE_CODE (check_typedef (value_type (v2))) == TYPE_CODE_STRUCT
+                 && !!"Why did coercion fail?");
+      v2 = value_cast_structs (t1, v2);
+      /* At this point we have what we can have, un-dereference if needed.  */
+      if (v2)
        {
-         v = search_struct_field (type_name_no_tag (t2),
-                                  value_zero (t1, not_lval), 0, t1, 1);
-         if (v)
-           {
-             CORE_ADDR addr2 = value_as_address (arg2);
-             addr2 -= (VALUE_ADDRESS (v)
-                       + value_offset (v)
-                       + value_embedded_offset (v));
-             return value_from_pointer (type, addr2);
-           }
+         struct value *v = value_addr (v2);
+         deprecated_set_value_type (v, type);
+         return v;
        }
-    }
+   }
 
   /* No superclass found, just change the pointer type.  */
   arg2 = value_copy (arg2);
@@ -276,6 +309,26 @@ value_cast (struct type *type, struct value *arg2)
   if (value_type (arg2) == type)
     return arg2;
 
+  code1 = TYPE_CODE (check_typedef (type));
+
+  /* Check if we are casting struct reference to struct reference.  */
+  if (code1 == TYPE_CODE_REF)
+    {
+      /* We dereference type; then we recurse and finally
+         we generate value of the given reference. Nothing wrong with 
+        that.  */
+      struct type *t1 = check_typedef (type);
+      struct type *dereftype = check_typedef (TYPE_TARGET_TYPE (t1));
+      struct value *val =  value_cast (dereftype, arg2);
+      return value_ref (val); 
+    }
+
+  code2 = TYPE_CODE (check_typedef (value_type (arg2)));
+
+  if (code2 == TYPE_CODE_REF)
+    /* We deref the value and then do the cast.  */
+    return value_cast (type, coerce_ref (arg2)); 
+
   CHECK_TYPEDEF (type);
   code1 = TYPE_CODE (type);
   arg2 = coerce_ref (arg2);
@@ -340,25 +393,36 @@ value_cast (struct type *type, struct value *arg2)
     code2 = TYPE_CODE_INT;
 
   scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT
-           || code2 == TYPE_CODE_ENUM || code2 == TYPE_CODE_RANGE);
+           || code2 == TYPE_CODE_DECFLOAT || code2 == TYPE_CODE_ENUM
+           || code2 == TYPE_CODE_RANGE);
 
-  if (code1 == TYPE_CODE_STRUCT
-      && code2 == TYPE_CODE_STRUCT
+  if ((code1 == TYPE_CODE_STRUCT || code1 == TYPE_CODE_UNION)
+      && (code2 == TYPE_CODE_STRUCT || code2 == TYPE_CODE_UNION)
       && TYPE_NAME (type) != 0)
     {
-      /* Look in the type of the source to see if it contains the
-         type of the target as a superclass.  If so, we'll need to
-         offset the object in addition to changing its type.  */
-      struct value *v = search_struct_field (type_name_no_tag (type),
-                                            arg2, 0, type2, 1);
+      struct value *v = value_cast_structs (type, arg2);
       if (v)
-       {
-         deprecated_set_value_type (v, type);
-         return v;
-       }
+       return v;
     }
+
   if (code1 == TYPE_CODE_FLT && scalar)
     return value_from_double (type, value_as_double (arg2));
+  else if (code1 == TYPE_CODE_DECFLOAT && scalar)
+    {
+      int dec_len = TYPE_LENGTH (type);
+      gdb_byte dec[16];
+
+      if (code2 == TYPE_CODE_FLT)
+       decimal_from_floating (arg2, dec, dec_len);
+      else if (code2 == TYPE_CODE_DECFLOAT)
+       decimal_convert (value_contents (arg2), TYPE_LENGTH (type2),
+                        dec, dec_len);
+      else
+       /* The only option left is an integral type.  */
+       decimal_from_integral (arg2, dec, dec_len);
+
+      return value_from_decfloat (type, dec);
+    }
   else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM
            || code1 == TYPE_CODE_RANGE)
           && (scalar || code2 == TYPE_CODE_PTR
@@ -409,7 +473,7 @@ value_cast (struct type *type, struct value *arg2)
           && value_as_long (arg2) == 0)
     {
       struct value *result = allocate_value (type);
-      cplus_make_method_ptr (value_contents_writeable (result), 0, 0);
+      cplus_make_method_ptr (type, value_contents_writeable (result), 0, 0);
       return result;
     }
   else if (code1 == TYPE_CODE_MEMBERPTR && code2 == TYPE_CODE_INT
@@ -455,6 +519,40 @@ value_zero (struct type *type, enum lval_type lv)
   return val;
 }
 
+/* Create a value of numeric type TYPE that is one, and return it.  */
+
+struct value *
+value_one (struct type *type, enum lval_type lv)
+{
+  struct type *type1 = check_typedef (type);
+  struct value *val = NULL; /* avoid -Wall warning */
+
+  if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT)
+    {
+      struct value *int_one = value_from_longest (builtin_type_int32, 1);
+      struct value *val;
+      gdb_byte v[16];
+
+      decimal_from_integral (int_one, v, TYPE_LENGTH (builtin_type_int32));
+      val = value_from_decfloat (type, v);
+    }
+  else if (TYPE_CODE (type1) == TYPE_CODE_FLT)
+    {
+      val = value_from_double (type, (DOUBLEST) 1);
+    }
+  else if (is_integral_type (type1))
+    {
+      val = value_from_longest (type, (LONGEST) 1);
+    }
+  else
+    {
+      error (_("Not a numeric type."));
+    }
+
+  VALUE_LVAL (val) = lv;
+  return val;
+}
+
 /* Return a value with type TYPE located at ADDR.
 
    Call value_at only if the data needs to be fetched immediately;
@@ -521,12 +619,100 @@ value_at_lazy (struct type *type, CORE_ADDR addr)
 int
 value_fetch_lazy (struct value *val)
 {
-  CORE_ADDR addr = VALUE_ADDRESS (val) + value_offset (val);
-  int length = TYPE_LENGTH (value_enclosing_type (val));
+  if (VALUE_LVAL (val) == lval_memory)
+    {
+      CORE_ADDR addr = VALUE_ADDRESS (val) + value_offset (val);
+      int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
+
+      if (length)
+       read_memory (addr, value_contents_all_raw (val), length);
+    }
+  else if (VALUE_LVAL (val) == lval_register)
+    {
+      struct frame_info *frame;
+      int regnum;
+      struct type *type = check_typedef (value_type (val));
+      struct value *new_val = val, *mark = value_mark ();
 
-  struct type *type = value_type (val);
-  if (length)
-    read_memory (addr, value_contents_all_raw (val), length);
+      /* Offsets are not supported here; lazy register values must
+        refer to the entire register.  */
+      gdb_assert (value_offset (val) == 0);
+
+      while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val))
+       {
+         frame = frame_find_by_id (VALUE_FRAME_ID (new_val));
+         regnum = VALUE_REGNUM (new_val);
+
+         gdb_assert (frame != NULL);
+
+         /* Convertible register routines are used for multi-register
+            values and for interpretation in different types
+            (e.g. float or int from a double register).  Lazy
+            register values should have the register's natural type,
+            so they do not apply.  */
+         gdb_assert (!gdbarch_convert_register_p (get_frame_arch (frame),
+                                                  regnum, type));
+
+         new_val = get_frame_register_value (frame, regnum);
+       }
+
+      /* If it's still lazy (for instance, a saved register on the
+        stack), fetch it.  */
+      if (value_lazy (new_val))
+       value_fetch_lazy (new_val);
+
+      /* If the register was not saved, mark it unavailable.  */
+      if (value_optimized_out (new_val))
+       set_value_optimized_out (val, 1);
+      else
+       memcpy (value_contents_raw (val), value_contents (new_val),
+               TYPE_LENGTH (type));
+
+      if (frame_debug)
+       {
+         struct gdbarch *gdbarch;
+         frame = frame_find_by_id (VALUE_FRAME_ID (val));
+         regnum = VALUE_REGNUM (val);
+         gdbarch = get_frame_arch (frame);
+
+         fprintf_unfiltered (gdb_stdlog, "\
+{ value_fetch_lazy (frame=%d,regnum=%d(%s),...) ",
+                             frame_relative_level (frame), regnum,
+                             user_reg_map_regnum_to_name (gdbarch, regnum));
+
+         fprintf_unfiltered (gdb_stdlog, "->");
+         if (value_optimized_out (new_val))
+           fprintf_unfiltered (gdb_stdlog, " optimized out");
+         else
+           {
+             int i;
+             const gdb_byte *buf = value_contents (new_val);
+
+             if (VALUE_LVAL (new_val) == lval_register)
+               fprintf_unfiltered (gdb_stdlog, " register=%d",
+                                   VALUE_REGNUM (new_val));
+             else if (VALUE_LVAL (new_val) == lval_memory)
+               fprintf_unfiltered (gdb_stdlog, " address=0x%s",
+                                   paddr_nz (VALUE_ADDRESS (new_val)));
+             else
+               fprintf_unfiltered (gdb_stdlog, " computed");
+
+             fprintf_unfiltered (gdb_stdlog, " bytes=");
+             fprintf_unfiltered (gdb_stdlog, "[");
+             for (i = 0; i < register_size (gdbarch, regnum); i++)
+               fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
+             fprintf_unfiltered (gdb_stdlog, "]");
+           }
+
+         fprintf_unfiltered (gdb_stdlog, " }\n");
+       }
+
+      /* Dispose of the intermediate values.  This prevents
+        watchpoints from trying to watch the saved frame pointer.  */
+      value_free_to_mark (mark);
+    }
+  else
+    internal_error (__FILE__, __LINE__, "Unexpected lazy value type.");
 
   set_value_lazy (val, 0);
   return 0;
@@ -550,9 +736,18 @@ value_assign (struct value *toval, struct value *fromval)
 
   type = value_type (toval);
   if (VALUE_LVAL (toval) != lval_internalvar)
-    fromval = value_cast (type, fromval);
+    {
+      toval = value_coerce_to_target (toval);
+      fromval = value_cast (type, fromval);
+    }
   else
-    fromval = coerce_array (fromval);
+    {
+      /* Coerce arrays and functions to pointers, except for arrays
+        which only live in GDB's storage.  */
+      if (!value_must_coerce_to_target (fromval))
+       fromval = coerce_array (fromval);
+    }
+
   CHECK_TYPEDEF (type);
 
   /* Since modifying a register can trash the frame chain, and
@@ -802,6 +997,50 @@ value_of_variable (struct symbol *var, struct block *b)
   return val;
 }
 
+/* Return one if VAL does not live in target memory, but should in order
+   to operate on it.  Otherwise return zero.  */
+
+int
+value_must_coerce_to_target (struct value *val)
+{
+  struct type *valtype;
+
+  /* The only lval kinds which do not live in target memory.  */
+  if (VALUE_LVAL (val) != not_lval
+      && VALUE_LVAL (val) != lval_internalvar)
+    return 0;
+
+  valtype = check_typedef (value_type (val));
+
+  switch (TYPE_CODE (valtype))
+    {
+    case TYPE_CODE_ARRAY:
+    case TYPE_CODE_STRING:
+      return 1;
+    default:
+      return 0;
+    }
+}
+
+/* Make sure that VAL lives in target memory if it's supposed to.  For instance,
+   strings are constructed as character arrays in GDB's storage, and this
+   function copies them to the target.  */
+
+struct value *
+value_coerce_to_target (struct value *val)
+{
+  LONGEST length;
+  CORE_ADDR addr;
+
+  if (!value_must_coerce_to_target (val))
+    return val;
+
+  length = TYPE_LENGTH (check_typedef (value_type (val)));
+  addr = allocate_space_in_inferior (length);
+  write_memory (addr, value_contents (val), length);
+  return value_at_lazy (value_type (val), addr);
+}
+
 /* Given a value which is an array, return a value which is a pointer
    to its first element, regardless of whether or not the array has a
    nonzero lower bound.
@@ -831,6 +1070,11 @@ value_coerce_array (struct value *arg1)
 {
   struct type *type = check_typedef (value_type (arg1));
 
+  /* If the user tries to do something requiring a pointer with an
+     array that has not yet been pushed to the target, then this would
+     be a good time to do so.  */
+  arg1 = value_coerce_to_target (arg1);
+
   if (VALUE_LVAL (arg1) != lval_memory)
     error (_("Attempt to take address of value not located in memory."));
 
@@ -876,6 +1120,10 @@ value_addr (struct value *arg1)
   if (TYPE_CODE (type) == TYPE_CODE_FUNC)
     return value_coerce_function (arg1);
 
+  /* If this is an array that has not yet been pushed to the target,
+     then this would be a good time to force it to memory.  */
+  arg1 = value_coerce_to_target (arg1);
+
   if (VALUE_LVAL (arg1) != lval_memory)
     error (_("Attempt to take address of value not located in memory."));
 
@@ -924,14 +1172,7 @@ value_ind (struct value *arg1)
 
   base_type = check_typedef (value_type (arg1));
 
-  /* Allow * on an integer so we can cast it to whatever we want.
-     This returns an int, which seems like the most C-like thing to
-     do.  "long long" variables are rare enough that
-     BUILTIN_TYPE_LONGEST would seem to be a mistake.  */
-  if (TYPE_CODE (base_type) == TYPE_CODE_INT)
-    return value_at_lazy (builtin_type_int,
-                         (CORE_ADDR) value_as_address (arg1));
-  else if (TYPE_CODE (base_type) == TYPE_CODE_PTR)
+  if (TYPE_CODE (base_type) == TYPE_CODE_PTR)
     {
       struct type *enc_type;
       /* We may be pointing to something embedded in a larger object.
@@ -966,7 +1207,7 @@ value_ind (struct value *arg1)
   return 0;                    /* For lint -- never reached.  */
 }
 \f
-/* Create a value for an array by allocating space in the inferior,
+/* Create a value for an array by allocating space in GDB, copying
    copying the data into that space, and then setting up an array
    value.
 
@@ -1006,7 +1247,7 @@ value_array (int lowbound, int highbound, struct value **elemvec)
     }
 
   rangetype = create_range_type ((struct type *) NULL, 
-                                builtin_type_int,
+                                builtin_type_int32,
                                 lowbound, highbound);
   arraytype = create_array_type ((struct type *) NULL,
                                 value_enclosing_type (elemvec[0]), 
@@ -1024,24 +1265,15 @@ value_array (int lowbound, int highbound, struct value **elemvec)
       return val;
     }
 
-  /* Allocate space to store the array in the inferior, and then
-     initialize it by copying in each element.  FIXME: Is it worth it
-     to create a local buffer in which to collect each value and then
-     write all the bytes in one operation?  */
+  /* Allocate space to store the array, and then initialize it by
+     copying in each element.  */
 
-  addr = allocate_space_in_inferior (nelem * typelength);
+  val = allocate_value (arraytype);
   for (idx = 0; idx < nelem; idx++)
-    {
-      write_memory (addr + (idx * typelength),
-                   value_contents_all (elemvec[idx]),
-                   typelength);
-    }
-
-  /* Create the array type and set up an array value to be evaluated
-     lazily.  */
-
-  val = value_at_lazy (arraytype, addr);
-  return (val);
+    memcpy (value_contents_writeable (val) + (idx * typelength),
+           value_contents_all (elemvec[idx]),
+           typelength);
+  return val;
 }
 
 /* Create a value for a string constant by allocating space in the
@@ -1059,7 +1291,7 @@ value_string (char *ptr, int len)
   struct value *val;
   int lowbound = current_language->string_lower_bound;
   struct type *rangetype = create_range_type ((struct type *) NULL,
-                                             builtin_type_int,
+                                             builtin_type_int32,
                                              lowbound, 
                                              len + lowbound - 1);
   struct type *stringtype
@@ -1089,7 +1321,7 @@ value_bitstring (char *ptr, int len)
 {
   struct value *val;
   struct type *domain_type = create_range_type (NULL, 
-                                               builtin_type_int,
+                                               builtin_type_int32,
                                                0, len - 1);
   struct type *type = create_set_type ((struct type *) NULL, 
                                       domain_type);
@@ -1321,7 +1553,7 @@ search_struct_field (char *name, struct value *arg1, int offset,
              VALUE_ADDRESS (v2) = VALUE_ADDRESS (arg1);
              VALUE_FRAME_ID (v2) = VALUE_FRAME_ID (arg1);
              set_value_offset (v2, value_offset (arg1) + boffset);
-             if (value_lazy (arg1))
+             if (VALUE_LVAL (arg1) == lval_memory && value_lazy (arg1))
                set_value_lazy (v2, 1);
              else
                memcpy (value_contents_raw (v2),
@@ -1348,100 +1580,6 @@ search_struct_field (char *name, struct value *arg1, int offset,
   return NULL;
 }
 
-
-/* Return the offset (in bytes) of the virtual base of type BASETYPE
- * in an object pointed to by VALADDR (on the host), assumed to be of
- * type TYPE.  OFFSET is number of bytes beyond start of ARG to start
- * looking (in case VALADDR is the contents of an enclosing object).
- *
- * This routine recurses on the primary base of the derived class
- * because the virtual base entries of the primary base appear before
- * the other virtual base entries.
- *
- * If the virtual base is not found, a negative integer is returned.
- * The magnitude of the negative integer is the number of entries in
- * the virtual table to skip over (entries corresponding to various
- * ancestral classes in the chain of primary bases).
- *
- * Important: This assumes the HP / Taligent C++ runtime conventions.
- * Use baseclass_offset() instead to deal with g++ conventions.  */
-
-void
-find_rt_vbase_offset (struct type *type, struct type *basetype,
-                     const gdb_byte *valaddr, int offset, 
-                     int *boffset_p, int *skip_p)
-{
-  int boffset;                 /* Offset of virtual base.  */
-  int index;                   /* Displacement to use in virtual
-                                  table.  */
-  int skip;
-
-  struct value *vp;
-  CORE_ADDR vtbl;              /* The virtual table pointer.  */
-  struct type *pbc;            /* The primary base class.  */
-
-  /* Look for the virtual base recursively in the primary base, first.
-   * This is because the derived class object and its primary base
-   * subobject share the primary virtual table.  */
-
-  boffset = 0;
-  pbc = TYPE_PRIMARY_BASE (type);
-  if (pbc)
-    {
-      find_rt_vbase_offset (pbc, basetype, valaddr,
-                           offset, &boffset, &skip);
-      if (skip < 0)
-       {
-         *boffset_p = boffset;
-         *skip_p = -1;
-         return;
-       }
-    }
-  else
-    skip = 0;
-
-
-  /* Find the index of the virtual base according to HP/Taligent
-     runtime spec.  (Depth-first, left-to-right.)  */
-  index = virtual_base_index_skip_primaries (basetype, type);
-
-  if (index < 0)
-    {
-      *skip_p = skip + virtual_base_list_length_skip_primaries (type);
-      *boffset_p = 0;
-      return;
-    }
-
-  /* pai: FIXME -- 32x64 possible problem.  */
-  /* First word (4 bytes) in object layout is the vtable pointer.  */
-  vtbl = *(CORE_ADDR *) (valaddr + offset);
-
-  /* Before the constructor is invoked, things are usually zero'd
-     out.  */
-  if (vtbl == 0)
-    error (_("Couldn't find virtual table -- object may not be constructed yet."));
-
-
-  /* Find virtual base's offset -- jump over entries for primary base
-   * ancestors, then use the index computed above.  But also adjust by
-   * HP_ACC_VBASE_START for the vtable slots before the start of the
-   * virtual base entries.  Offset is negative -- virtual base entries
-   * appear _before_ the address point of the virtual table.  */
-
-  /* pai: FIXME -- 32x64 problem, if word = 8 bytes, change multiplier
-     & use long type */
-
-  /* epstein : FIXME -- added param for overlay section. May not be
-     correct.  */
-  vp = value_at (builtin_type_int, 
-                vtbl + 4 * (-skip - index - HP_ACC_VBASE_START));
-  boffset = value_as_long (vp);
-  *skip_p = -1;
-  *boffset_p = boffset;
-  return;
-}
-
-
 /* Helper function used by value_struct_elt to recurse through
    baseclasses.  Look for a field NAME in ARG1. Adjust the address of
    ARG1 by OFFSET bytes, and search in it assuming it has (class) type
@@ -1518,47 +1656,30 @@ search_struct_method (char *name, struct value **arg1p,
 
       if (BASETYPE_VIA_VIRTUAL (type, i))
        {
-         if (TYPE_HAS_VTABLE (type))
-           {
-             /* HP aCC compiled type, search for virtual base offset
-                according to HP/Taligent runtime spec.  */
-             int skip;
-             find_rt_vbase_offset (type, TYPE_BASECLASS (type, i),
-                                   value_contents_all (*arg1p),
-                                   offset + value_embedded_offset (*arg1p),
-                                   &base_offset, &skip);
-             if (skip >= 0)
-               error (_("Virtual base class offset not found in vtable"));
-           }
-         else
-           {
-             struct type *baseclass = 
-               check_typedef (TYPE_BASECLASS (type, i));
-             const gdb_byte *base_valaddr;
-
-             /* The virtual base class pointer might have been
-                clobbered by the user program. Make sure that it
-                still points to a valid memory location.  */
+         struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
+         const gdb_byte *base_valaddr;
 
-             if (offset < 0 || offset >= TYPE_LENGTH (type))
-               {
-                 gdb_byte *tmp = alloca (TYPE_LENGTH (baseclass));
-                 if (target_read_memory (VALUE_ADDRESS (*arg1p)
-                                         + value_offset (*arg1p) + offset,
-                                         tmp, TYPE_LENGTH (baseclass)) != 0)
-                   error (_("virtual baseclass botch"));
-                 base_valaddr = tmp;
-               }
-             else
-               base_valaddr = value_contents (*arg1p) + offset;
+         /* The virtual base class pointer might have been
+            clobbered by the user program. Make sure that it
+           still points to a valid memory location.  */
 
-             base_offset =
-               baseclass_offset (type, i, base_valaddr,
-                                 VALUE_ADDRESS (*arg1p)
-                                 + value_offset (*arg1p) + offset);
-             if (base_offset == -1)
+         if (offset < 0 || offset >= TYPE_LENGTH (type))
+           {
+             gdb_byte *tmp = alloca (TYPE_LENGTH (baseclass));
+             if (target_read_memory (VALUE_ADDRESS (*arg1p)
+                                     + value_offset (*arg1p) + offset,
+                                     tmp, TYPE_LENGTH (baseclass)) != 0)
                error (_("virtual baseclass botch"));
+             base_valaddr = tmp;
            }
+         else
+           base_valaddr = value_contents (*arg1p) + offset;
+
+         base_offset = baseclass_offset (type, i, base_valaddr,
+                                         VALUE_ADDRESS (*arg1p)
+                                         + value_offset (*arg1p) + offset);
+         if (base_offset == -1)
+           error (_("virtual baseclass botch"));
        }
       else
        {
@@ -1698,6 +1819,10 @@ value_struct_elt (struct value **argp, struct value **args,
          back.  If it's not callable (i.e., a pointer to function),
          gdb should give an error.  */
       v = search_struct_field (name, *argp, 0, t, 0);
+      /* If we found an ordinary field, then it is not a method call.
+        So, treat it as if it were a static member function.  */
+      if (v && static_memfuncp)
+       *static_memfuncp = 1;
     }
 
   if (!v)
@@ -1758,29 +1883,12 @@ find_method_list (struct value **argp, char *method,
       int base_offset;
       if (BASETYPE_VIA_VIRTUAL (type, i))
        {
-         if (TYPE_HAS_VTABLE (type))
-           {
-             /* HP aCC compiled type, search for virtual base offset
-              * according to HP/Taligent runtime spec.  */
-             int skip;
-             find_rt_vbase_offset (type, TYPE_BASECLASS (type, i),
-                                   value_contents_all (*argp),
-                                   offset + value_embedded_offset (*argp),
-                                   &base_offset, &skip);
-             if (skip >= 0)
-               error (_("Virtual base class offset not found in vtable"));
-           }
-         else
-           {
-             /* probably g++ runtime model */
-             base_offset = value_offset (*argp) + offset;
-             base_offset =
-               baseclass_offset (type, i,
-                                 value_contents (*argp) + base_offset,
-                                 VALUE_ADDRESS (*argp) + base_offset);
-             if (base_offset == -1)
-               error (_("virtual baseclass botch"));
-           }
+         base_offset = value_offset (*argp) + offset;
+         base_offset = baseclass_offset (type, i,
+                                         value_contents (*argp) + base_offset,
+                                         VALUE_ADDRESS (*argp) + base_offset);
+         if (base_offset == -1)
+           error (_("virtual baseclass botch"));
        }
       else /* Non-virtual base, simply use bit position from debug
              info.  */
@@ -1895,6 +2003,7 @@ find_overload_match (struct type **arg_types, int nargs,
   /* Get the list of overloaded methods or functions.  */
   if (method)
     {
+      gdb_assert (obj);
       obj_type_name = TYPE_NAME (value_type (obj));
       /* Hack: evaluate_subexp_standard often passes in a pointer
          value rather than the object itself, so try again.  */
@@ -1996,7 +2105,8 @@ find_overload_match (struct type **arg_types, int nargs,
   if (objp)
     {
       if (TYPE_CODE (value_type (temp)) != TYPE_CODE_PTR
-         && TYPE_CODE (value_type (*objp)) == TYPE_CODE_PTR)
+         && (TYPE_CODE (value_type (*objp)) == TYPE_CODE_PTR
+             || TYPE_CODE (value_type (*objp)) == TYPE_CODE_REF))
        {
          temp = value_addr (temp);
        }
@@ -2320,12 +2430,12 @@ destructor_name_p (const char *name, const struct type *type)
   return 0;
 }
 
-/* Helper function for check_field: Given TYPE, a structure/union,
+/* Given TYPE, a structure/union,
    return 1 if the component named NAME from the ultimate target
    structure/union is defined, otherwise, return 0.  */
 
-static int
-check_field_in (struct type *type, const char *name)
+int
+check_field (struct type *type, const char *name)
 {
   int i;
 
@@ -2354,44 +2464,12 @@ check_field_in (struct type *type, const char *name)
     }
 
   for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
-    if (check_field_in (TYPE_BASECLASS (type, i), name))
+    if (check_field (TYPE_BASECLASS (type, i), name))
       return 1;
 
   return 0;
 }
 
-
-/* C++: Given ARG1, a value of type (pointer to a)* structure/union,
-   return 1 if the component named NAME from the ultimate target
-   structure/union is defined, otherwise, return 0.  */
-
-int
-check_field (struct value *arg1, const char *name)
-{
-  struct type *t;
-
-  arg1 = coerce_array (arg1);
-
-  t = value_type (arg1);
-
-  /* Follow pointers until we get to a non-pointer.  */
-
-  for (;;)
-    {
-      CHECK_TYPEDEF (t);
-      if (TYPE_CODE (t) != TYPE_CODE_PTR 
-         && TYPE_CODE (t) != TYPE_CODE_REF)
-       break;
-      t = TYPE_TARGET_TYPE (t);
-    }
-
-  if (TYPE_CODE (t) != TYPE_CODE_STRUCT
-      && TYPE_CODE (t) != TYPE_CODE_UNION)
-    error (_("Internal error: `this' is not an aggregate"));
-
-  return check_field_in (t, name);
-}
-
 /* C++: Given an aggregate type CURTYPE, and a member name NAME,
    return the appropriate member (or the address of the member, if
    WANT_ADDRESS).  This function is used to resolve user expressions
@@ -2524,7 +2602,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
            {
              struct symbol *s = 
                lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
-                              0, VAR_DOMAIN, 0, NULL);
+                              0, VAR_DOMAIN, 0);
              if (s == NULL)
                return NULL;
 
@@ -2540,7 +2618,8 @@ value_struct_elt_for_reference (struct type *domain, int offset,
                {
                  result = allocate_value
                    (lookup_methodptr_type (TYPE_FN_FIELD_TYPE (f, j)));
-                 cplus_make_method_ptr (value_contents_writeable (result),
+                 cplus_make_method_ptr (value_type (result),
+                                        value_contents_writeable (result),
                                         TYPE_FN_FIELD_VOFFSET (f, j), 1);
                }
              else if (noside == EVAL_AVOID_SIDE_EFFECTS)
@@ -2553,7 +2632,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
            {
              struct symbol *s = 
                lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
-                              0, VAR_DOMAIN, 0, NULL);
+                              0, VAR_DOMAIN, 0);
              if (s == NULL)
                return NULL;
 
@@ -2563,7 +2642,8 @@ value_struct_elt_for_reference (struct type *domain, int offset,
              else
                {
                  result = allocate_value (lookup_methodptr_type (TYPE_FN_FIELD_TYPE (f, j)));
-                 cplus_make_method_ptr (value_contents_writeable (result),
+                 cplus_make_method_ptr (value_type (result),
+                                        value_contents_writeable (result),
                                         VALUE_ADDRESS (v), 0);
                }
            }
@@ -2632,7 +2712,7 @@ value_maybe_namespace_elt (const struct type *curtype,
 
   sym = cp_lookup_symbol_namespace (namespace_name, name, NULL,
                                    get_selected_block (0), 
-                                   VAR_DOMAIN, NULL);
+                                   VAR_DOMAIN);
 
   if (sym == NULL)
     return NULL;
@@ -2797,10 +2877,9 @@ value_of_local (const char *name, int complain)
 struct value *
 value_of_this (int complain)
 {
-  if (current_language->la_language == language_objc)
-    return value_of_local ("self", complain);
-  else
-    return value_of_local ("this", complain);
+  if (!current_language->la_name_of_this)
+    return 0;
+  return value_of_local (current_language->la_name_of_this, complain);
 }
 
 /* Create a slice (sub-string, sub-array) of ARRAY, that is LENGTH
@@ -2854,7 +2933,7 @@ value_slice (struct value *array, int lowbound, int length)
          else if (element > 0)
            {
              int j = i % TARGET_CHAR_BIT;
-             if (BITS_BIG_ENDIAN)
+             if (gdbarch_bits_big_endian (current_gdbarch))
                j = TARGET_CHAR_BIT - 1 - j;
              value_contents_raw (slice)[i / TARGET_CHAR_BIT] |= (1 << j);
            }
@@ -2876,7 +2955,7 @@ value_slice (struct value *array, int lowbound, int length)
       TYPE_CODE (slice_type) = TYPE_CODE (array_type);
 
       slice = allocate_value (slice_type);
-      if (value_lazy (array))
+      if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
        set_value_lazy (slice, 1);
       else
        memcpy (value_contents_writeable (slice),
This page took 0.034849 seconds and 4 git commands to generate.