]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/valops.c
Add two methods to tui_data_window
[thirdparty/binutils-gdb.git] / gdb / valops.c
index 25d02123be17424b52120699ab4900444d7c5b08..0f6ff7b0a5722cd678388b1d016763217d690c26 100644 (file)
@@ -1,6 +1,6 @@
 /* Perform non-arithmetic operations on values, for GDB.
 
-   Copyright (C) 1986-2018 Free Software Foundation, Inc.
+   Copyright (C) 1986-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -39,7 +39,7 @@
 #include "observable.h"
 #include "objfiles.h"
 #include "extension.h"
-#include "byte-vector.h"
+#include "gdbsupport/byte-vector.h"
 
 extern unsigned int overload_debug;
 /* Local functions.  */
@@ -402,12 +402,12 @@ value_cast (struct type *type, struct value *arg2)
                       "divide object size in cast"));
          /* FIXME-type-allocation: need a way to free this type when
             we are done with it.  */
-         range_type = create_static_range_type ((struct type *) NULL,
+         range_type = create_static_range_type (NULL,
                                                 TYPE_TARGET_TYPE (range_type),
                                                 low_bound,
                                                 new_length + low_bound - 1);
          deprecated_set_value_type (arg2, 
-                                    create_array_type ((struct type *) NULL,
+                                    create_array_type (NULL,
                                                        element_type, 
                                                        range_type));
          return arg2;
@@ -555,8 +555,9 @@ value_cast (struct type *type, struct value *arg2)
     return value_at_lazy (to_type, value_address (arg2));
   else
     {
+      if (current_language->la_language == language_ada)
+       error (_("Invalid type conversion."));
       error (_("Invalid cast."));
-      return 0;
     }
 }
 
@@ -1342,10 +1343,9 @@ address_of_variable (struct symbol *var, const 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.  */
+/* See value.h.  */
 
-int
+bool
 value_must_coerce_to_target (struct value *val)
 {
   struct type *valtype;
@@ -1354,7 +1354,7 @@ value_must_coerce_to_target (struct value *val)
   if (VALUE_LVAL (val) != not_lval
       && VALUE_LVAL (val) != lval_internalvar
       && VALUE_LVAL (val) != lval_xcallable)
-    return 0;
+    return false;
 
   valtype = check_typedef (value_type (val));
 
@@ -1363,9 +1363,9 @@ value_must_coerce_to_target (struct value *val)
     case TYPE_CODE_ARRAY:
       return TYPE_VECTOR (valtype) ? 0 : 1;
     case TYPE_CODE_STRING:
-      return 1;
+      return true;
     default:
-      return 0;
+      return false;
     }
 }
 
@@ -1980,23 +1980,12 @@ search_struct_method (const char *name, struct value **arg1p,
   int i;
   struct value *v;
   int name_matched = 0;
-  char dem_opname[64];
 
   type = check_typedef (type);
   for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; i--)
     {
       const char *t_field_name = TYPE_FN_FIELDLIST_NAME (type, i);
 
-      /* FIXME!  May need to check for ARM demangling here.  */
-      if (startswith (t_field_name, "__") ||
-         startswith (t_field_name, "op") ||
-         startswith (t_field_name, "type"))
-       {
-         if (cplus_demangle_opname (t_field_name, dem_opname, DMGL_ANSI))
-           t_field_name = dem_opname;
-         else if (cplus_demangle_opname (t_field_name, dem_opname, 0))
-           t_field_name = dem_opname;
-       }
       if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
        {
          int j = TYPE_FN_FIELDLIST_LENGTH (type, i) - 1;
@@ -2516,10 +2505,9 @@ find_overload_match (gdb::array_view<value *> args,
   struct type *basetype = NULL;
   LONGEST boffset;
 
-  struct cleanup *all_cleanups = make_cleanup (null_cleanup, NULL);
-
   const char *obj_type_name = NULL;
   const char *func_name = NULL;
+  gdb::unique_xmalloc_ptr<char> temp_func;
   enum oload_classification match_quality;
   enum oload_classification method_match_quality = INCOMPATIBLE;
   enum oload_classification src_method_match_quality = INCOMPATIBLE;
@@ -2546,7 +2534,6 @@ find_overload_match (gdb::array_view<value *> args,
          if (*valp)
            {
              *staticp = 1;
-             do_cleanups (all_cleanups);
              return 0;
            }
        }
@@ -2666,20 +2653,17 @@ find_overload_match (gdb::array_view<value *> args,
               && TYPE_CODE (check_typedef (SYMBOL_TYPE (fsym)))
              == TYPE_CODE_FUNC)
             {
-             char *temp_func;
-
              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_func)
+             if (temp_func != nullptr)
                {
-                 make_cleanup (xfree, temp_func);
-                 if (strcmp (temp_func, qualified_name) == 0)
+                 if (strcmp (temp_func.get (), qualified_name) == 0)
                    func_name = NULL;
                  else
-                   func_name = temp_func;
+                   func_name = temp_func.get ();
                }
             }
         }
@@ -2695,7 +2679,6 @@ find_overload_match (gdb::array_view<value *> args,
       if (func_name == NULL)
         {
          *symp = fsym;
-         do_cleanups (all_cleanups);
           return 0;
         }
 
@@ -2822,8 +2805,6 @@ find_overload_match (gdb::array_view<value *> args,
       *objp = temp;
     }
 
-  do_cleanups (all_cleanups);
-
   switch (match_quality)
     {
     case INCOMPATIBLE:
@@ -3429,19 +3410,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
   for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
     {
       const char *t_field_name = TYPE_FN_FIELDLIST_NAME (t, i);
-      char dem_opname[64];
 
-      if (startswith (t_field_name, "__") 
-         || startswith (t_field_name, "op") 
-         || startswith (t_field_name, "type"))
-       {
-         if (cplus_demangle_opname (t_field_name, 
-                                    dem_opname, DMGL_ANSI))
-           t_field_name = dem_opname;
-         else if (cplus_demangle_opname (t_field_name, 
-                                         dem_opname, 0))
-           t_field_name = dem_opname;
-       }
       if (t_field_name && strcmp (t_field_name, name) == 0)
        {
          int j;
@@ -3652,11 +3621,11 @@ value_rtti_indirect_type (struct value *v, int *full,
   else if (TYPE_CODE (type) == TYPE_CODE_PTR)
     {
 
-      TRY
+      try
         {
          target = value_ind (v);
         }
-      CATCH (except, RETURN_MASK_ERROR)
+      catch (const gdb_exception_error &except)
        {
          if (except.error == MEMORY_ERROR)
            {
@@ -3665,9 +3634,8 @@ value_rtti_indirect_type (struct value *v, int *full,
                 type.  */
              return NULL;
            }
-         throw_exception (except);
+         throw;
        }
-      END_CATCH
     }
   else
     return NULL;
@@ -3805,14 +3773,13 @@ value_of_this_silent (const struct language_defn *lang)
 {
   struct value *ret = NULL;
 
-  TRY
+  try
     {
       ret = value_of_this (lang);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const gdb_exception_error &except)
     {
     }
-  END_CATCH
 
   return ret;
 }
@@ -3834,6 +3801,11 @@ value_slice (struct value *array, int lowbound, int length)
       && TYPE_CODE (array_type) != TYPE_CODE_STRING)
     error (_("cannot take slice of non-array"));
 
+  if (type_not_allocated (array_type))
+    error (_("array not allocated"));
+  if (type_not_associated (array_type))
+    error (_("array not associated"));
+
   range_type = TYPE_INDEX_TYPE (array_type);
   if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
     error (_("slice from bad array or bitstring"));
@@ -3844,7 +3816,7 @@ value_slice (struct value *array, int lowbound, int length)
 
   /* FIXME-type-allocation: need a way to free this type when we are
      done with it.  */
-  slice_range_type = create_static_range_type ((struct type *) NULL,
+  slice_range_type = create_static_range_type (NULL,
                                               TYPE_TARGET_TYPE (range_type),
                                               lowbound,
                                               lowbound + length - 1);
@@ -3854,7 +3826,7 @@ value_slice (struct value *array, int lowbound, int length)
     LONGEST offset
       = (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
 
-    slice_type = create_array_type ((struct type *) NULL,
+    slice_type = create_array_type (NULL,
                                    element_type,
                                    slice_range_type);
     TYPE_CODE (slice_type) = TYPE_CODE (array_type);