gdb/
[deliverable/binutils-gdb.git] / gdb / valops.c
index f720ea92db280cd30732aee923dca7d2eb078726..2dc237a7740bea9db154d9cf716f4329cf668f92 100644 (file)
 #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)
@@ -243,7 +261,8 @@ value_cast_structs (struct type *type, struct value *v2)
          return value_at (type, addr2);
        }
     }
-  return v2;
+
+  return NULL;
 }
 
 /* Cast one pointer or reference type to another.  Both TYPE and
@@ -268,7 +287,7 @@ value_cast_pointers (struct type *type, struct value *arg2)
        v2 = coerce_ref (arg2);
       else
        v2 = value_ind (arg2);
-      gdb_assert (TYPE_CODE (value_type (v2)) == TYPE_CODE_STRUCT
+      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.  */
@@ -342,8 +361,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 +414,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 +488,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
@@ -521,11 +544,11 @@ value_one (struct type *type, enum lval_type lv)
 
   if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT)
     {
-      struct value *int_one = value_from_longest (builtin_type_int, 1);
+      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_int));
+      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)
@@ -614,9 +637,8 @@ value_fetch_lazy (struct value *val)
   if (VALUE_LVAL (val) == lval_memory)
     {
       CORE_ADDR addr = VALUE_ADDRESS (val) + value_offset (val);
-      int length = TYPE_LENGTH (value_enclosing_type (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 +685,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))
@@ -690,9 +714,7 @@ value_fetch_lazy (struct value *val)
 
              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, "]");
            }
@@ -1165,14 +1187,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 +1262,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]), 
@@ -1291,7 +1306,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
@@ -1321,7 +1336,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);
@@ -1819,6 +1834,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)
@@ -2614,7 +2633,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,7 +2657,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);
                }
            }
This page took 0.02914 seconds and 4 git commands to generate.