gdb/riscv: expect h/w watchpoints to trigger before the memory is written
[deliverable/binutils-gdb.git] / gdb / valops.c
index 93374576841056a6b5951716437260847c5a9d91..c45caefbf1e039d7581a20bb6de589c9bf0ef200 100644 (file)
@@ -102,13 +102,6 @@ static void find_method_list (struct value **, const char *,
                              std::vector<xmethod_worker_up> *,
                              struct type **, LONGEST *);
 
-#if 0
-/* Flag for whether we want to abandon failed expression evals by
-   default.  */
-
-static int auto_abandon = 0;
-#endif
-
 int overload_resolution = 0;
 static void
 show_overload_resolution (struct ui_file *file, int from_tty,
@@ -1588,7 +1581,6 @@ value_ind (struct value *arg1)
     }
 
   error (_("Attempt to take contents of a non-pointer value."));
-  return 0;                    /* For lint -- never reached.  */
 }
 \f
 /* Create a value for an array by allocating space in GDB, copying the
@@ -2683,20 +2675,20 @@ find_overload_match (struct value **args, int nargs,
               && TYPE_CODE (check_typedef (SYMBOL_TYPE (fsym)))
              == TYPE_CODE_FUNC)
             {
-             char *temp;
+             char *temp_func;
 
-             temp = cp_func_name (qualified_name);
+             temp_func = cp_func_name (qualified_name);
 
              /* If cp_func_name did not remove anything, the name of the
                 symbol did not include scope or argument types - it was
                 probably a C-style function.  */
-             if (temp)
+             if (temp_func)
                {
-                 make_cleanup (xfree, temp);
-                 if (strcmp (temp, qualified_name) == 0)
+                 make_cleanup (xfree, temp_func);
+                 if (strcmp (temp_func, qualified_name) == 0)
                    func_name = NULL;
                  else
-                   func_name = temp;
+                   func_name = temp_func;
                }
             }
         }
@@ -3329,6 +3321,49 @@ compare_parameters (struct type *t1, struct type *t2, int skip_artificial)
   return 0;
 }
 
+/* C++: Given an aggregate type VT, and a class type CLS, search
+   recursively for CLS using value V; If found, store the offset
+   which is either fetched from the virtual base pointer if CLS
+   is virtual or accumulated offset of its parent classes if
+   CLS is non-virtual in *BOFFS, set ISVIRT to indicate if CLS
+   is virtual, and return true.  If not found, return false.  */
+
+static bool
+get_baseclass_offset (struct type *vt, struct type *cls,
+                     struct value *v, int *boffs, bool *isvirt)
+{
+  for (int i = 0; i < TYPE_N_BASECLASSES (vt); i++)
+    {
+      struct type *t = TYPE_FIELD_TYPE (vt, i);
+      if (types_equal (t, cls))
+        {
+          if (BASETYPE_VIA_VIRTUAL (vt, i))
+            {
+             const gdb_byte *adr = value_contents_for_printing (v);
+             *boffs = baseclass_offset (vt, i, adr, value_offset (v),
+                                        value_as_long (v), v);
+             *isvirt = true;
+            }
+          else
+           *isvirt = false;
+          return true;
+        }
+
+      if (get_baseclass_offset (check_typedef (t), cls, v, boffs, isvirt))
+        {
+         if (*isvirt == false) /* Add non-virtual base offset.  */
+           {
+             const gdb_byte *adr = value_contents_for_printing (v);
+             *boffs += baseclass_offset (vt, i, adr, value_offset (v),
+                                         value_as_long (v), v);
+           }
+         return true;
+       }
+    }
+
+  return false;
+}
+
 /* C++: Given an aggregate type CURTYPE, and a member name NAME,
    return the address of this member as a "pointer to member" type.
    If INTYPE is non-null, then it will be the type of the member we
@@ -3343,9 +3378,9 @@ value_struct_elt_for_reference (struct type *domain, int offset,
                                int want_address,
                                enum noside noside)
 {
-  struct type *t = curtype;
+  struct type *t = check_typedef (curtype);
   int i;
-  struct value *v, *result;
+  struct value *result;
 
   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
       && TYPE_CODE (t) != TYPE_CODE_UNION)
@@ -3360,7 +3395,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
        {
          if (field_is_static (&TYPE_FIELD (t, i)))
            {
-             v = value_static_field (t, i);
+             struct value *v = value_static_field (t, i);
              if (want_address)
                v = value_addr (v);
              return v;
@@ -3379,10 +3414,10 @@ value_struct_elt_for_reference (struct type *domain, int offset,
              /* Try to evaluate NAME as a qualified name with implicit
                 this pointer.  In this case, attempt to return the
                 equivalent to `this->*(&TYPE::NAME)'.  */
-             v = value_of_this_silent (current_language);
+             struct value *v = value_of_this_silent (current_language);
              if (v != NULL)
                {
-                 struct value *ptr;
+                 struct value *ptr, *this_v = v;
                  long mem_offset;
                  struct type *type, *tmp;
 
@@ -3393,6 +3428,24 @@ value_struct_elt_for_reference (struct type *domain, int offset,
                  tmp = lookup_pointer_type (TYPE_SELF_TYPE (type));
                  v = value_cast_pointers (tmp, v, 1);
                  mem_offset = value_as_long (ptr);
+                 if (domain != curtype)
+                   {
+                     /* Find class offset of type CURTYPE from either its
+                        parent type DOMAIN or the type of implied this.  */
+                     int boff = 0;
+                     bool isvirt = false;
+                     if (get_baseclass_offset (domain, curtype, v, &boff,
+                                               &isvirt))
+                       mem_offset += boff;
+                     else
+                       {
+                         struct type *p = check_typedef (value_type (this_v));
+                         p = check_typedef (TYPE_TARGET_TYPE (p));
+                         if (get_baseclass_offset (p, curtype, this_v,
+                                                   &boff, &isvirt))
+                           mem_offset += boff;
+                       }
+                   }
                  tmp = lookup_pointer_type (TYPE_TARGET_TYPE (type));
                  result = value_from_pointer (tmp,
                                               value_as_long (v) + mem_offset);
@@ -3527,7 +3580,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
              if (s == NULL)
                return NULL;
 
-             v = read_var_value (s, 0, 0);
+             struct value *v = read_var_value (s, 0, 0);
              if (!want_address)
                result = v;
              else
This page took 0.02756 seconds and 4 git commands to generate.