Fortran, testsuite: Add testcases for nested structures.
[deliverable/binutils-gdb.git] / gdb / valops.c
index acaf027d9d2fa893bfd7a3d2c6bfbe073f8910db..71fb1b301973670f315df33e0de428847de723db 100644 (file)
@@ -1,6 +1,6 @@
 /* Perform non-arithmetic operations on values, for GDB.
 
-   Copyright (C) 1986-2015 Free Software Foundation, Inc.
+   Copyright (C) 1986-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -961,6 +961,9 @@ read_value_memory (struct value *val, int embedded_offset,
   ULONGEST xfered_total = 0;
   struct gdbarch *arch = get_value_arch (val);
   int unit_size = gdbarch_addressable_memory_unit_size (arch);
+  enum target_object object;
+
+  object = stack ? TARGET_OBJECT_STACK_MEMORY : TARGET_OBJECT_MEMORY;
 
   while (xfered_total < length)
     {
@@ -968,7 +971,7 @@ read_value_memory (struct value *val, int embedded_offset,
       ULONGEST xfered_partial;
 
       status = target_xfer_partial (current_target.beneath,
-                                   TARGET_OBJECT_MEMORY, NULL,
+                                   object, NULL,
                                    buffer + xfered_total * unit_size, NULL,
                                    memaddr + xfered_total,
                                    length - xfered_total,
@@ -1291,27 +1294,12 @@ value_repeat (struct value *arg1, int count)
 struct value *
 value_of_variable (struct symbol *var, const struct block *b)
 {
-  struct frame_info *frame;
+  struct frame_info *frame = NULL;
 
-  if (!symbol_read_needs_frame (var))
-    frame = NULL;
-  else if (!b)
+  if (symbol_read_needs_frame (var))
     frame = get_selected_frame (_("No frame selected."));
-  else
-    {
-      frame = block_innermost_frame (b);
-      if (!frame)
-       {
-         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)));
-         else
-           error (_("No frame is currently executing in specified block"));
-       }
-    }
 
-  return read_var_value (var, frame);
+  return read_var_value (var, b, frame);
 }
 
 struct value *
@@ -1478,11 +1466,20 @@ value_addr (struct value *arg1)
   if (TYPE_CODE (type) == TYPE_CODE_REF)
     {
       /* Copy the value, but change the type from (T&) to (T*).  We
-         keep the same location information, which is efficient, and
-         allows &(&X) to get the location containing the reference.  */
+        keep the same location information, which is efficient, and
+        allows &(&X) to get the location containing the reference.
+        Do the same to its enclosing type for consistency.  */
+      struct type *type_ptr
+        = lookup_pointer_type (TYPE_TARGET_TYPE (type));
+      struct type *enclosing_type
+        = check_typedef (value_enclosing_type (arg1));
+      struct type *enclosing_type_ptr
+        = lookup_pointer_type (TYPE_TARGET_TYPE (enclosing_type));
+
       arg2 = value_copy (arg1);
-      deprecated_set_value_type (arg2, 
-                                lookup_pointer_type (TYPE_TARGET_TYPE (type)));
+      deprecated_set_value_type (arg2, type_ptr);
+      set_value_enclosing_type (arg2, enclosing_type_ptr);
+
       return arg2;
     }
   if (TYPE_CODE (type) == TYPE_CODE_FUNC)
@@ -1641,7 +1638,7 @@ value_array (int lowbound, int highbound, struct value **elemvec)
 }
 
 struct value *
-value_cstring (char *ptr, ssize_t len, struct type *char_type)
+value_cstring (const char *ptr, ssize_t len, struct type *char_type)
 {
   struct value *val;
   int lowbound = current_language->string_lower_bound;
@@ -1664,7 +1661,7 @@ value_cstring (char *ptr, ssize_t len, struct type *char_type)
    string may contain embedded null bytes.  */
 
 struct value *
-value_string (char *ptr, ssize_t len, struct type *char_type)
+value_string (const char *ptr, ssize_t len, struct type *char_type)
 {
   struct value *val;
   int lowbound = current_language->string_lower_bound;
@@ -2062,7 +2059,7 @@ search_struct_method (const char *name, struct value **arg1p,
              struct cleanup *back_to;
              CORE_ADDR address;
 
-             tmp = xmalloc (TYPE_LENGTH (baseclass));
+             tmp = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass));
              back_to = make_cleanup (xfree, tmp);
              address = value_address (*arg1p);
 
@@ -2220,9 +2217,7 @@ value_struct_elt_bitpos (struct value **argp, int bitpos, struct type *ftype,
                         const char *err)
 {
   struct type *t;
-  struct value *v;
   int i;
-  int nbases;
 
   *argp = coerce_array (*argp);
 
@@ -2475,7 +2470,6 @@ find_overload_match (struct value **args, int nargs,
   int method_oload_champ = -1;
   int src_method_oload_champ = -1;
   int ext_method_oload_champ = -1;
-  int src_and_ext_equal = 0;
 
   /* The measure for the current best match.  */
   struct badness_vector *method_badness = NULL;
@@ -2574,7 +2568,6 @@ find_overload_match (struct value **args, int nargs,
          switch (compare_badness (ext_method_badness, src_method_badness))
            {
              case 0: /* Src method and xmethod are equally good.  */
-               src_and_ext_equal = 1;
                /* If src method and xmethod are equally good, then
                   xmethod should be the winner.  Hence, fall through to the
                   case where a xmethod is better than the source
@@ -2915,7 +2908,7 @@ find_oload_champ_namespace_loop (struct value **args, int nargs,
 
   old_cleanups = make_cleanup (xfree, *oload_syms);
   make_cleanup (xfree, *oload_champ_bv);
-  new_namespace = alloca (namespace_len + 1);
+  new_namespace = (char *) alloca (namespace_len + 1);
   strncpy (new_namespace, qualified_name, namespace_len);
   new_namespace[namespace_len] = '\0';
   new_oload_syms = make_symbol_overload_list (func_name,
@@ -2999,7 +2992,6 @@ find_oload_champ (struct value **args, int nargs,
 {
   int ix;
   int fn_count;
-  int xm_worker_vec_n = VEC_length (xmethod_worker_ptr, xm_worker_vec);
   /* A measure of how good an overloaded instance is.  */
   struct badness_vector *bv;
   /* Index of best overloaded function.  */
@@ -3043,8 +3035,7 @@ find_oload_champ (struct value **args, int nargs,
          else
            nparms = TYPE_NFIELDS (SYMBOL_TYPE (oload_syms[ix]));
 
-         parm_types = (struct type **)
-           xmalloc (nparms * (sizeof (struct type *)));
+         parm_types = XNEWVEC (struct type *, nparms);
          for (jj = 0; jj < nparms; jj++)
            parm_types[jj] = (fns_ptr != NULL
                              ? (TYPE_FN_FIELD_ARGS (fns_ptr, ix)[jj].type)
@@ -3463,9 +3454,9 @@ value_struct_elt_for_reference (struct type *domain, int offset,
                return NULL;
 
              if (want_address)
-               return value_addr (read_var_value (s, 0));
+               return value_addr (read_var_value (s, 0, 0));
              else
-               return read_var_value (s, 0);
+               return read_var_value (s, 0, 0);
            }
 
          if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
@@ -3493,7 +3484,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
              if (s == NULL)
                return NULL;
 
-             v = read_var_value (s, 0);
+             v = read_var_value (s, 0, 0);
              if (!want_address)
                result = v;
              else
@@ -3729,7 +3720,7 @@ value_full_object (struct value *argp,
 struct value *
 value_of_this (const struct language_defn *lang)
 {
-  struct symbol *sym;
+  struct block_symbol sym;
   const struct block *b;
   struct frame_info *frame;
 
@@ -3740,12 +3731,12 @@ value_of_this (const struct language_defn *lang)
 
   b = get_frame_block (frame, NULL);
 
-  sym = lookup_language_this (lang, b).symbol;
-  if (sym == NULL)
+  sym = lookup_language_this (lang, b);
+  if (sym.symbol == NULL)
     error (_("current stack frame does not contain a variable named `%s'"),
           lang->la_name_of_this);
 
-  return read_var_value (sym, frame);
+  return read_var_value (sym.symbol, sym.block, frame);
 }
 
 /* Return the value of the local variable, if one exists.  Return NULL
This page took 0.027336 seconds and 4 git commands to generate.