gdb/
[deliverable/binutils-gdb.git] / gdb / valops.c
index aad9871f7139ae11eb1869612d6b28572a3212ec..c0bc2a53eedb6dfb624f3456d66327a6eab90196 100644 (file)
@@ -2,7 +2,7 @@
 
    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.
+   2008, 2009 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "dictionary.h"
 #include "cp-support.h"
 #include "dfp.h"
+#include "user-regs.h"
 
 #include <errno.h>
 #include "gdb_string.h"
 #include "gdb_assert.h"
 #include "cp-support.h"
 #include "observer.h"
+#include "objfiles.h"
+#include "symtab.h"
 
 extern int overload_debug;
 /* Local functions.  */
@@ -121,10 +124,12 @@ Overload resolution in evaluating C++ functions is %s.\n"),
                    value);
 }
 
-/* Find the address of function name NAME in the inferior.  */
+/* Find the address of function name NAME in the inferior.  If OBJF_P
+   is non-NULL, *OBJF_P will be set to the OBJFILE where the function
+   is defined.  */
 
 struct value *
-find_function_in_inferior (const char *name)
+find_function_in_inferior (const char *name, struct objfile **objf_p)
 {
   struct symbol *sym;
   sym = lookup_symbol (name, 0, VAR_DOMAIN, 0);
@@ -135,6 +140,10 @@ find_function_in_inferior (const char *name)
          error (_("\"%s\" exists in this program but is not a function."),
                 name);
        }
+
+      if (objf_p)
+       *objf_p = SYMBOL_SYMTAB (sym)->objfile;
+
       return value_of_variable (sym, NULL);
     }
   else
@@ -143,12 +152,19 @@ find_function_in_inferior (const char *name)
        lookup_minimal_symbol (name, NULL, NULL);
       if (msymbol != NULL)
        {
+         struct objfile *objfile = msymbol_objfile (msymbol);
+         struct gdbarch *gdbarch = get_objfile_arch (objfile);
+
          struct type *type;
          CORE_ADDR maddr;
-         type = lookup_pointer_type (builtin_type_char);
+         type = lookup_pointer_type (builtin_type (gdbarch)->builtin_char);
          type = lookup_function_type (type);
          type = lookup_pointer_type (type);
          maddr = SYMBOL_VALUE_ADDRESS (msymbol);
+
+         if (objf_p)
+           *objf_p = objfile;
+
          return value_from_pointer (type, maddr);
        }
       else
@@ -168,11 +184,12 @@ find_function_in_inferior (const char *name)
 struct value *
 value_allocate_space_in_inferior (int len)
 {
+  struct objfile *objf;
+  struct value *val = find_function_in_inferior ("malloc", &objf);
+  struct gdbarch *gdbarch = get_objfile_arch (objf);
   struct value *blocklen;
-  struct value *val = 
-    find_function_in_inferior (gdbarch_name_of_malloc (current_gdbarch));
 
-  blocklen = value_from_longest (builtin_type_int, (LONGEST) len);
+  blocklen = value_from_longest (builtin_type (gdbarch)->builtin_int, len);
   val = call_function_by_hand (val, 1, &blocklen);
   if (value_logical_not (val))
     {
@@ -192,7 +209,8 @@ allocate_space_in_inferior (int 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.  */
+   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)
@@ -236,14 +254,13 @@ value_cast_structs (struct type *type, struct value *v2)
       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));
+         CORE_ADDR addr2 = value_address (v2);
+         addr2 -= value_address (v) + value_embedded_offset (v);
          return value_at (type, addr2);
        }
     }
-  return v2;
+
+  return NULL;
 }
 
 /* Cast one pointer or reference type to another.  Both TYPE and
@@ -342,8 +359,7 @@ value_cast (struct type *type, struct value *arg2)
     {
       struct type *element_type = TYPE_TARGET_TYPE (type);
       unsigned element_length = TYPE_LENGTH (check_typedef (element_type));
-      if (element_length > 0
-       && TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED)
+      if (element_length > 0 && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
        {
          struct type *range_type = TYPE_INDEX_TYPE (type);
          int val_length = TYPE_LENGTH (type2);
@@ -396,7 +412,12 @@ value_cast (struct type *type, struct value *arg2)
   if ((code1 == TYPE_CODE_STRUCT || code1 == TYPE_CODE_UNION)
       && (code2 == TYPE_CODE_STRUCT || code2 == TYPE_CODE_UNION)
       && TYPE_NAME (type) != 0)
-    return value_cast_structs (type, arg2);
+    {
+      struct value *v = value_cast_structs (type, arg2);
+      if (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)
@@ -465,7 +486,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
@@ -487,8 +508,7 @@ value_cast (struct type *type, struct value *arg2)
       return arg2;
     }
   else if (VALUE_LVAL (arg2) == lval_memory)
-    return value_at_lazy (type, 
-                         VALUE_ADDRESS (arg2) + value_offset (arg2));
+    return value_at_lazy (type, value_address (arg2));
   else if (code1 == TYPE_CODE_VOID)
     {
       return value_zero (builtin_type_void, not_lval);
@@ -517,15 +537,12 @@ struct value *
 value_one (struct type *type, enum lval_type lv)
 {
   struct type *type1 = check_typedef (type);
-  struct value *val = NULL; /* avoid -Wall warning */
+  struct value *val;
 
   if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT)
     {
-      struct value *int_one = value_from_longest (builtin_type_int, 1);
-      struct value *val;
       gdb_byte v[16];
-
-      decimal_from_integral (int_one, v, TYPE_LENGTH (builtin_type_int));
+      decimal_from_string (v, TYPE_LENGTH (type), "1");
       val = value_from_decfloat (type, v);
     }
   else if (TYPE_CODE (type1) == TYPE_CODE_FLT)
@@ -570,7 +587,7 @@ value_at (struct type *type, CORE_ADDR addr)
   read_memory (addr, value_contents_all_raw (val), TYPE_LENGTH (type));
 
   VALUE_LVAL (val) = lval_memory;
-  VALUE_ADDRESS (val) = addr;
+  set_value_address (val, addr);
 
   return val;
 }
@@ -585,11 +602,10 @@ value_at_lazy (struct type *type, CORE_ADDR addr)
   if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
     error (_("Attempt to dereference a generic pointer."));
 
-  val = allocate_value (type);
+  val = allocate_value_lazy (type);
 
   VALUE_LVAL (val) = lval_memory;
-  VALUE_ADDRESS (val) = addr;
-  set_value_lazy (val, 1);
+  set_value_address (val, addr);
 
   return val;
 }
@@ -611,12 +627,13 @@ value_at_lazy (struct type *type, CORE_ADDR addr)
 int
 value_fetch_lazy (struct value *val)
 {
+  gdb_assert (value_lazy (val));
+  allocate_value_contents (val);
   if (VALUE_LVAL (val) == lval_memory)
     {
-      CORE_ADDR addr = VALUE_ADDRESS (val) + value_offset (val);
-      int length = TYPE_LENGTH (value_enclosing_type (val));
+      CORE_ADDR addr = value_address (val);
+      int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
 
-      struct type *type = value_type (val);
       if (length)
        read_memory (addr, value_contents_all_raw (val), length);
     }
@@ -663,13 +680,15 @@ value_fetch_lazy (struct value *val)
 
       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,
-                             frame_map_regnum_to_name (frame, regnum));
+                             user_reg_map_regnum_to_name (gdbarch, regnum));
 
          fprintf_unfiltered (gdb_stdlog, "->");
          if (value_optimized_out (new_val))
@@ -684,15 +703,13 @@ value_fetch_lazy (struct value *val)
                                    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)));
+                                   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 (get_frame_arch (frame), regnum);
-                  i++)
+             for (i = 0; i < register_size (gdbarch, regnum); i++)
                fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
              fprintf_unfiltered (gdb_stdlog, "]");
            }
@@ -704,6 +721,8 @@ value_fetch_lazy (struct value *val)
         watchpoints from trying to watch the saved frame pointer.  */
       value_free_to_mark (mark);
     }
+  else if (VALUE_LVAL (val) == lval_computed)
+    value_computed_funcs (val)->read (val);
   else
     internal_error (__FILE__, __LINE__, "Unexpected lazy value type.");
 
@@ -752,7 +771,7 @@ value_assign (struct value *toval, struct value *fromval)
     {
     case lval_internalvar:
       set_internalvar (VALUE_INTERNALVAR (toval), fromval);
-      val = value_copy (VALUE_INTERNALVAR (toval)->value);
+      val = value_copy (fromval);
       val = value_change_enclosing_type (val, 
                                         value_enclosing_type (fromval));
       set_value_embedded_offset (val, value_embedded_offset (fromval));
@@ -788,16 +807,15 @@ value_assign (struct value *toval, struct value *fromval)
              error (_("Can't handle bitfields which don't fit in a %d bit word."),
                     (int) sizeof (LONGEST) * HOST_CHAR_BIT);
 
-           read_memory (VALUE_ADDRESS (toval) + value_offset (toval),
-                        buffer, changed_len);
+           read_memory (value_address (toval), buffer, changed_len);
            modify_field (buffer, value_as_long (fromval),
                          value_bitpos (toval), value_bitsize (toval));
-           changed_addr = VALUE_ADDRESS (toval) + value_offset (toval);
+           changed_addr = value_address (toval);
            dest_buffer = buffer;
          }
        else
          {
-           changed_addr = VALUE_ADDRESS (toval) + value_offset (toval);
+           changed_addr = value_address (toval);
            changed_len = TYPE_LENGTH (type);
            dest_buffer = value_contents (fromval);
          }
@@ -811,6 +829,7 @@ value_assign (struct value *toval, struct value *fromval)
     case lval_register:
       {
        struct frame_info *frame;
+       struct gdbarch *gdbarch;
        int value_reg;
 
        /* Figure out which frame this is in currently.  */
@@ -819,14 +838,14 @@ value_assign (struct value *toval, struct value *fromval)
 
        if (!frame)
          error (_("Value being assigned to is no longer active."));
-       
-       if (gdbarch_convert_register_p
-           (current_gdbarch, VALUE_REGNUM (toval), type))
+
+       gdbarch = get_frame_arch (frame);
+       if (gdbarch_convert_register_p (gdbarch, VALUE_REGNUM (toval), type))
          {
            /* If TOVAL is a special machine register requiring
               conversion of program values to a special raw
               format.  */
-           gdbarch_value_to_register (current_gdbarch, frame, 
+           gdbarch_value_to_register (gdbarch, frame,
                                       VALUE_REGNUM (toval), type,
                                       value_contents (fromval));
          }
@@ -872,7 +891,15 @@ value_assign (struct value *toval, struct value *fromval)
        observer_notify_target_changed (&current_target);
        break;
       }
-      
+
+    case lval_computed:
+      {
+       struct lval_funcs *funcs = value_computed_funcs (toval);
+
+       funcs->write (toval, fromval);
+      }
+      break;
+
     default:
       error (_("Left operand of assignment is not an lvalue."));
     }
@@ -952,11 +979,11 @@ value_repeat (struct value *arg1, int count)
 
   val = allocate_repeat_value (value_enclosing_type (arg1), count);
 
-  read_memory (VALUE_ADDRESS (arg1) + value_offset (arg1),
+  read_memory (value_address (arg1),
               value_contents_all_raw (val),
               TYPE_LENGTH (value_enclosing_type (val)));
   VALUE_LVAL (val) = lval_memory;
-  VALUE_ADDRESS (val) = VALUE_ADDRESS (arg1) + value_offset (arg1);
+  set_value_address (val, value_address (arg1));
 
   return val;
 }
@@ -965,16 +992,18 @@ struct value *
 value_of_variable (struct symbol *var, struct block *b)
 {
   struct value *val;
-  struct frame_info *frame = NULL;
+  struct frame_info *frame;
 
-  if (!b)
-    frame = NULL;              /* Use selected frame.  */
-  else if (symbol_read_needs_frame (var))
+  if (!symbol_read_needs_frame (var))
+    frame = NULL;
+  else if (!b)
+    frame = get_selected_frame (_("No frame selected."));
+  else
     {
       frame = block_innermost_frame (b);
       if (!frame)
        {
-         if (BLOCK_FUNCTION (b)
+         if (BLOCK_FUNCTION (b) && !block_inlined_p (b)
              && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)))
            error (_("No frame is currently executing in block %s."),
                   SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)));
@@ -990,6 +1019,54 @@ value_of_variable (struct symbol *var, struct block *b)
   return val;
 }
 
+struct value *
+address_of_variable (struct symbol *var, struct block *b)
+{
+  struct type *type = SYMBOL_TYPE (var);
+  struct value *val;
+
+  /* Evaluate it first; if the result is a memory address, we're fine.
+     Lazy evaluation pays off here. */
+
+  val = value_of_variable (var, b);
+
+  if ((VALUE_LVAL (val) == lval_memory && value_lazy (val))
+      || TYPE_CODE (type) == TYPE_CODE_FUNC)
+    {
+      CORE_ADDR addr = value_address (val);
+      return value_from_pointer (lookup_pointer_type (type), addr);
+    }
+
+  /* Not a memory address; check what the problem was.  */
+  switch (VALUE_LVAL (val))
+    {
+    case lval_register:
+      {
+       struct frame_info *frame;
+       const char *regname;
+
+       frame = frame_find_by_id (VALUE_FRAME_ID (val));
+       gdb_assert (frame);
+
+       regname = gdbarch_register_name (get_frame_arch (frame),
+                                        VALUE_REGNUM (val));
+       gdb_assert (regname && *regname);
+
+       error (_("Address requested for identifier "
+                "\"%s\" which is in register $%s"),
+              SYMBOL_PRINT_NAME (var), regname);
+       break;
+      }
+
+    default:
+      error (_("Can't take address of \"%s\" which isn't an lvalue."),
+            SYMBOL_PRINT_NAME (var));
+      break;
+    }
+
+  return val;
+}
+
 /* Return one if VAL does not live in target memory, but should in order
    to operate on it.  Otherwise return zero.  */
 
@@ -1072,7 +1149,7 @@ value_coerce_array (struct value *arg1)
     error (_("Attempt to take address of value not located in memory."));
 
   return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
-                            (VALUE_ADDRESS (arg1) + value_offset (arg1)));
+                            value_address (arg1));
 }
 
 /* Given a value which is a function, return a value which is a pointer
@@ -1087,7 +1164,7 @@ value_coerce_function (struct value *arg1)
     error (_("Attempt to take address of value not located in memory."));
 
   retval = value_from_pointer (lookup_pointer_type (value_type (arg1)),
-                              (VALUE_ADDRESS (arg1) + value_offset (arg1)));
+                              value_address (arg1));
   return retval;
 }
 
@@ -1122,8 +1199,7 @@ value_addr (struct value *arg1)
 
   /* Get target memory address */
   arg2 = value_from_pointer (lookup_pointer_type (value_type (arg1)),
-                            (VALUE_ADDRESS (arg1)
-                             + value_offset (arg1)
+                            (value_address (arg1)
                              + value_embedded_offset (arg1)));
 
   /* This may be a pointer to a base subobject; so remember the
@@ -1165,14 +1241,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.
@@ -1247,7 +1316,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]), 
@@ -1276,6 +1345,24 @@ value_array (int lowbound, int highbound, struct value **elemvec)
   return val;
 }
 
+struct value *
+value_cstring (char *ptr, int len, struct type *char_type)
+{
+  struct value *val;
+  int lowbound = current_language->string_lower_bound;
+  int highbound = len / TYPE_LENGTH (char_type);
+  struct type *rangetype = create_range_type ((struct type *) NULL,
+                                             builtin_type_int32,
+                                             lowbound, 
+                                             highbound + lowbound - 1);
+  struct type *stringtype
+    = create_array_type ((struct type *) NULL, char_type, rangetype);
+
+  val = allocate_value (stringtype);
+  memcpy (value_contents_raw (val), ptr, len);
+  return val;
+}
+
 /* Create a value for a string constant by allocating space in the
    inferior, copying the data into that space, and returning the
    address with type TYPE_CODE_STRING.  PTR points to the string
@@ -1286,34 +1373,21 @@ value_array (int lowbound, int highbound, struct value **elemvec)
    string may contain embedded null bytes.  */
 
 struct value *
-value_string (char *ptr, int len)
+value_string (char *ptr, int len, struct type *char_type)
 {
   struct value *val;
   int lowbound = current_language->string_lower_bound;
+  int highbound = len / TYPE_LENGTH (char_type);
   struct type *rangetype = create_range_type ((struct type *) NULL,
-                                             builtin_type_int,
+                                             builtin_type_int32,
                                              lowbound, 
-                                             len + lowbound - 1);
+                                             highbound + lowbound - 1);
   struct type *stringtype
-    = create_string_type ((struct type *) NULL, rangetype);
-  CORE_ADDR addr;
-
-  if (current_language->c_style_arrays == 0)
-    {
-      val = allocate_value (stringtype);
-      memcpy (value_contents_raw (val), ptr, len);
-      return val;
-    }
-
-
-  /* Allocate space to store the string in the inferior, and then copy
-     LEN bytes from PTR in gdb to that address in the inferior.  */
+    = create_string_type ((struct type *) NULL, char_type, rangetype);
 
-  addr = allocate_space_in_inferior (len);
-  write_memory (addr, (gdb_byte *) ptr, len);
-
-  val = value_at_lazy (stringtype, addr);
-  return (val);
+  val = allocate_value (stringtype);
+  memcpy (value_contents_raw (val), ptr, len);
+  return val;
 }
 
 struct value *
@@ -1321,7 +1395,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);
@@ -1444,7 +1518,7 @@ search_struct_field (char *name, struct value *arg1, int offset,
        if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
          {
            struct value *v;
-           if (TYPE_FIELD_STATIC (type, i))
+           if (field_is_static (&TYPE_FIELD (type, i)))
              {
                v = value_static_field (type, i);
                if (v == 0)
@@ -1520,12 +1594,11 @@ search_struct_field (char *name, struct value *arg1, int offset,
       if (BASETYPE_VIA_VIRTUAL (type, i))
        {
          int boffset;
-         struct value *v2 = allocate_value (basetype);
+         struct value *v2;
 
          boffset = baseclass_offset (type, i,
                                      value_contents (arg1) + offset,
-                                     VALUE_ADDRESS (arg1)
-                                     + value_offset (arg1) + offset);
+                                     value_address (arg1) + offset);
          if (boffset == -1)
            error (_("virtual baseclass botch"));
 
@@ -1538,27 +1611,29 @@ search_struct_field (char *name, struct value *arg1, int offset,
            {
              CORE_ADDR base_addr;
 
-             base_addr = 
-               VALUE_ADDRESS (arg1) + value_offset (arg1) + boffset;
+             v2  = allocate_value (basetype);
+             base_addr = value_address (arg1) + boffset;
              if (target_read_memory (base_addr, 
                                      value_contents_raw (v2),
                                      TYPE_LENGTH (basetype)) != 0)
                error (_("virtual baseclass botch"));
              VALUE_LVAL (v2) = lval_memory;
-             VALUE_ADDRESS (v2) = base_addr;
+             set_value_address (v2, base_addr);
            }
          else
            {
-             VALUE_LVAL (v2) = VALUE_LVAL (arg1);
-             VALUE_ADDRESS (v2) = VALUE_ADDRESS (arg1);
-             VALUE_FRAME_ID (v2) = VALUE_FRAME_ID (arg1);
-             set_value_offset (v2, value_offset (arg1) + boffset);
              if (VALUE_LVAL (arg1) == lval_memory && value_lazy (arg1))
-               set_value_lazy (v2, 1);
+               v2  = allocate_value_lazy (basetype);
              else
-               memcpy (value_contents_raw (v2),
-                       value_contents_raw (arg1) + boffset,
-                       TYPE_LENGTH (basetype));
+               {
+                 v2  = allocate_value (basetype);
+                 memcpy (value_contents_raw (v2),
+                         value_contents_raw (arg1) + boffset,
+                         TYPE_LENGTH (basetype));
+               }
+             set_value_component_location (v2, arg1);
+             VALUE_FRAME_ID (v2) = VALUE_FRAME_ID (arg1);
+             set_value_offset (v2, value_offset (arg1) + boffset);
            }
 
          if (found_baseclass)
@@ -1666,8 +1741,7 @@ search_struct_method (char *name, struct value **arg1p,
          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,
+             if (target_read_memory (value_address (*arg1p) + offset,
                                      tmp, TYPE_LENGTH (baseclass)) != 0)
                error (_("virtual baseclass botch"));
              base_valaddr = tmp;
@@ -1676,8 +1750,7 @@ search_struct_method (char *name, struct value **arg1p,
            base_valaddr = value_contents (*arg1p) + offset;
 
          base_offset = baseclass_offset (type, i, base_valaddr,
-                                         VALUE_ADDRESS (*arg1p)
-                                         + value_offset (*arg1p) + offset);
+                                         value_address (*arg1p) + offset);
          if (base_offset == -1)
            error (_("virtual baseclass botch"));
        }
@@ -1761,10 +1834,6 @@ value_struct_elt (struct value **argp, struct value **args,
 
       /* C++: If it was not found as a data field, then try to
          return it as a pointer to a method.  */
-
-      if (destructor_name_p (name, t))
-       error (_("Cannot get value of destructor"));
-
       v = search_struct_method (name, argp, args, 0, 
                                static_memfuncp, t);
 
@@ -1780,32 +1849,6 @@ value_struct_elt (struct value **argp, struct value **args,
       return v;
     }
 
-  if (destructor_name_p (name, t))
-    {
-      if (!args[1])
-       {
-         /* Destructors are a special case.  */
-         int m_index, f_index;
-
-         v = NULL;
-         if (get_destructor_fn_field (t, &m_index, &f_index))
-           {
-             v = value_fn_field (NULL, 
-                                 TYPE_FN_FIELDLIST1 (t, m_index),
-                                 f_index, NULL, 0);
-           }
-         if (v == NULL)
-           error (_("could not find destructor function named %s."), 
-                  name);
-         else
-           return v;
-       }
-      else
-       {
-         error (_("destructor should not have any argument"));
-       }
-    }
-  else
     v = search_struct_method (name, argp, args, 0, 
                              static_memfuncp, t);
   
@@ -1819,6 +1862,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)
@@ -1827,7 +1874,7 @@ value_struct_elt (struct value **argp, struct value **args,
 }
 
 /* Search through the methods of an object (and its bases) to find a
-   specified method. Return the pointer to the fn_field list of
+   specified method.  Return the pointer to the fn_field list of
    overloaded instances.
 
    Helper function for value_find_oload_list.
@@ -1882,7 +1929,7 @@ find_method_list (struct value **argp, char *method,
          base_offset = value_offset (*argp) + offset;
          base_offset = baseclass_offset (type, i,
                                          value_contents (*argp) + base_offset,
-                                         VALUE_ADDRESS (*argp) + base_offset);
+                                         value_address (*argp) + base_offset);
          if (base_offset == -1)
            error (_("virtual baseclass botch"));
        }
@@ -2100,9 +2147,11 @@ 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_REF))
+      struct type *temp_type = check_typedef (value_type (temp));
+      struct type *obj_type = check_typedef (value_type (*objp));
+      if (TYPE_CODE (temp_type) != TYPE_CODE_PTR
+         && (TYPE_CODE (obj_type) == TYPE_CODE_PTR
+             || TYPE_CODE (obj_type) == TYPE_CODE_REF))
        {
          temp = value_addr (temp);
        }
@@ -2405,8 +2454,6 @@ classify_oload_match (struct badness_vector *oload_champ_bv,
 int
 destructor_name_p (const char *name, const struct type *type)
 {
-  /* Destructors are a special case.  */
-
   if (name[0] == '~')
     {
       char *dname = type_name_no_tag (type);
@@ -2445,14 +2492,6 @@ check_field (struct type *type, const char *name)
   /* C++: If it was not found as a data field, then try to return it
      as a pointer to a method.  */
 
-  /* Destructors are a special case.  */
-  if (destructor_name_p (name, type))
-    {
-      int m_index, f_index;
-
-      return get_destructor_fn_field (type, &m_index, &f_index);
-    }
-
   for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
     {
       if (strcmp_iw (TYPE_FN_FIELDLIST_NAME (type, i), name) == 0)
@@ -2521,7 +2560,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
 
       if (t_field_name && strcmp (t_field_name, name) == 0)
        {
-         if (TYPE_FIELD_STATIC (t, i))
+         if (field_is_static (&TYPE_FIELD (t, i)))
            {
              v = value_static_field (t, i);
              if (v == NULL)
@@ -2548,12 +2587,6 @@ value_struct_elt_for_reference (struct type *domain, int offset,
   /* C++: If it was not found as a data field, then try to return it
      as a pointer to a method.  */
 
-  /* Destructors are a special case.  */
-  if (destructor_name_p (name, t))
-    {
-      error (_("member pointers to destructors not implemented yet"));
-    }
-
   /* Perform all necessary dereferencing.  */
   while (intype && TYPE_CODE (intype) == TYPE_CODE_PTR)
     intype = TYPE_TARGET_TYPE (intype);
@@ -2614,7 +2647,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)
@@ -2637,8 +2671,9 @@ 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),
-                                        VALUE_ADDRESS (v), 0);
+                 cplus_make_method_ptr (value_type (result),
+                                        value_contents_writeable (result),
+                                        value_address (v), 0);
                }
            }
          return result;
@@ -2797,7 +2832,7 @@ value_full_object (struct value *argp,
   /* Go back by the computed top_offset from the beginning of the
      object, adjusting for the embedded offset of argp if that's what
      value_rtti_type used for its computation.  */
-  new_val = value_at_lazy (real_type, VALUE_ADDRESS (argp) - top +
+  new_val = value_at_lazy (real_type, value_address (argp) - top +
                           (using_enc ? 0 : value_embedded_offset (argp)));
   deprecated_set_value_type (new_val, value_type (argp));
   set_value_embedded_offset (new_val, (using_enc
@@ -2948,20 +2983,17 @@ value_slice (struct value *array, int lowbound, int length)
                                      slice_range_type);
       TYPE_CODE (slice_type) = TYPE_CODE (array_type);
 
-      slice = allocate_value (slice_type);
       if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
-       set_value_lazy (slice, 1);
-      else
-       memcpy (value_contents_writeable (slice),
-               value_contents (array) + offset,
-               TYPE_LENGTH (slice_type));
-
-      if (VALUE_LVAL (array) == lval_internalvar)
-       VALUE_LVAL (slice) = lval_internalvar_component;
+       slice = allocate_value_lazy (slice_type);
       else
-       VALUE_LVAL (slice) = VALUE_LVAL (array);
+       {
+         slice = allocate_value (slice_type);
+         memcpy (value_contents_writeable (slice),
+                 value_contents (array) + offset,
+                 TYPE_LENGTH (slice_type));
+       }
 
-      VALUE_ADDRESS (slice) = VALUE_ADDRESS (array);
+      set_value_component_location (slice, array);
       VALUE_FRAME_ID (slice) = VALUE_FRAME_ID (array);
       set_value_offset (slice, value_offset (array) + offset);
     }
This page took 0.036446 seconds and 4 git commands to generate.