gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / c-varobj.c
index 16d5077a5a1a678cc6a1ef0239f91cc7d6fd4479..2be447a86609a1a82eeb743fd16b317907bab564 100644 (file)
@@ -1,6 +1,6 @@
 /* varobj support for C and C++.
 
-   Copyright (C) 1999-2016 Free Software Foundation, Inc.
+   Copyright (C) 1999-2020 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -28,13 +28,13 @@ static void cplus_class_num_children (struct type *type, int children[3]);
 #define ANONYMOUS_UNION_NAME _("<anonymous union>")
 
 /* Does CHILD represent a child with no name?  This happens when
-   the child is an anonmous struct or union and it has no field name
+   the child is an anonymous struct or union and it has no field name
    in its parent variable.
 
    This has already been determined by *_describe_child. The easiest
    thing to do is to compare the child's name with ANONYMOUS_*_NAME.  */
 
-int
+bool
 varobj_is_anonymous_child (const struct varobj *child)
 {
   return (child->name == ANONYMOUS_STRUCT_NAME
@@ -78,30 +78,29 @@ adjust_value_for_child_access (struct value **value,
      to us, is already supposed to be
      reference-stripped.  */
 
-  gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
+  gdb_assert (!TYPE_IS_REFERENCE (*type));
 
   /* Pointers to structures are treated just like
      structures when accessing children.  Don't
-     dererences pointers to other types.  */
-  if (TYPE_CODE (*type) == TYPE_CODE_PTR)
+     dereference pointers to other types.  */
+  if ((*type)->code () == TYPE_CODE_PTR)
     {
       struct type *target_type = get_target_type (*type);
-      if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT
-         || TYPE_CODE (target_type) == TYPE_CODE_UNION)
+      if (target_type->code () == TYPE_CODE_STRUCT
+         || target_type->code () == TYPE_CODE_UNION)
        {
          if (value && *value)
            {
 
-             TRY
+             try
                {
                  *value = value_ind (*value);
                }
 
-             CATCH (except, RETURN_MASK_ERROR)
+             catch (const gdb_exception_error &except)
                {
                  *value = NULL;
                }
-             END_CATCH
            }
          *type = target_type;
          if (was_ptr)
@@ -131,22 +130,21 @@ adjust_value_for_child_access (struct value **value,
 /* Is VAR a path expression parent, i.e., can it be used to construct
    a valid path expression?  */
 
-static int
+static bool
 c_is_path_expr_parent (const struct varobj *var)
 {
   struct type *type;
 
   /* "Fake" children are not path_expr parents.  */
   if (CPLUS_FAKE_CHILD (var))
-    return 0;
+    return false;
 
   type = varobj_get_gdb_type (var);
 
   /* Anonymous unions and structs are also not path_expr parents.  */
-  if ((TYPE_CODE (type) == TYPE_CODE_STRUCT
-       || TYPE_CODE (type) == TYPE_CODE_UNION)
-      && TYPE_NAME (type) == NULL
-      && TYPE_TAG_NAME (type) == NULL)
+  if ((type->code () == TYPE_CODE_STRUCT
+       || type->code () == TYPE_CODE_UNION)
+      && type->name () == NULL)
     {
       const struct varobj *parent = var->parent;
 
@@ -161,21 +159,21 @@ c_is_path_expr_parent (const struct varobj *var)
          parent_type = varobj_get_value_type (parent);
          adjust_value_for_child_access (NULL, &parent_type, &was_ptr, 0);
 
-         if (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT
-             || TYPE_CODE (parent_type) == TYPE_CODE_UNION)
+         if (parent_type->code () == TYPE_CODE_STRUCT
+             || parent_type->code () == TYPE_CODE_UNION)
            {
              const char *field_name;
 
-             gdb_assert (var->index < TYPE_NFIELDS (parent_type));
+             gdb_assert (var->index < parent_type->num_fields ());
              field_name = TYPE_FIELD_NAME (parent_type, var->index);
              return !(field_name == NULL || *field_name == '\0');
            }
        }
 
-      return 0;
+      return false;
     }
 
-  return 1;
+  return true;
 }
 
 /* C */
@@ -190,7 +188,7 @@ c_number_of_children (const struct varobj *var)
   adjust_value_for_child_access (NULL, &type, NULL, 0);
   target = get_target_type (type);
 
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_ARRAY:
       if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
@@ -204,7 +202,7 @@ c_number_of_children (const struct varobj *var)
 
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
-      children = TYPE_NFIELDS (type);
+      children = type->num_fields ();
       break;
 
     case TYPE_CODE_PTR:
@@ -216,8 +214,8 @@ c_number_of_children (const struct varobj *var)
          to test for it, please mind that a little magic is necessary to
          properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and 
          TYPE_NAME == "char".  */
-      if (TYPE_CODE (target) == TYPE_CODE_FUNC
-         || TYPE_CODE (target) == TYPE_CODE_VOID)
+      if (target->code () == TYPE_CODE_FUNC
+         || target->code () == TYPE_CODE_VOID)
        children = 0;
       else
        children = 1;
@@ -251,21 +249,20 @@ value_struct_element_index (struct value *value, int type_index)
 
   type = check_typedef (type);
 
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
-             || TYPE_CODE (type) == TYPE_CODE_UNION);
+  gdb_assert (type->code () == TYPE_CODE_STRUCT
+             || type->code () == TYPE_CODE_UNION);
 
-  TRY
+  try
     {
-      if (field_is_static (&TYPE_FIELD (type, type_index)))
+      if (field_is_static (&type->field (type_index)))
        result = value_static_field (type, type_index);
       else
        result = value_primitive_field (value, 0, type_index, type);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const gdb_exception_error &e)
     {
       return NULL;
     }
-  END_CATCH
 
   return result;
 }
@@ -286,7 +283,7 @@ c_describe_child (const struct varobj *parent, int index,
                  std::string *cname, struct value **cvalue,
                  struct type **ctype, std::string *cfull_expression)
 {
-  struct value *value = parent->value;
+  struct value *value = parent->value.get ();
   struct type *type = varobj_get_value_type (parent);
   std::string parent_expression;
   int was_ptr;
@@ -305,7 +302,7 @@ c_describe_child (const struct varobj *parent, int index,
     }
   adjust_value_for_child_access (&value, &type, &was_ptr, 0);
 
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_ARRAY:
       if (cname)
@@ -317,14 +314,13 @@ c_describe_child (const struct varobj *parent, int index,
        {
          int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
 
-         TRY
+         try
            {
              *cvalue = value_subscript (value, real_index);
            }
-         CATCH (except, RETURN_MASK_ERROR)
+         catch (const gdb_exception_error &except)
            {
            }
-         END_CATCH
        }
 
       if (ctype)
@@ -352,7 +348,7 @@ c_describe_child (const struct varobj *parent, int index,
          {
            if (cname)
              {
-               if (TYPE_CODE (TYPE_FIELD_TYPE (type, index))
+               if (TYPE_FIELD_TYPE (type, index)->code ()
                    == TYPE_CODE_STRUCT)
                  *cname = ANONYMOUS_STRUCT_NAME;
                else
@@ -394,16 +390,15 @@ c_describe_child (const struct varobj *parent, int index,
 
       if (cvalue && value)
        {
-         TRY
+         try
            {
              *cvalue = value_ind (value);
            }
 
-         CATCH (except, RETURN_MASK_ERROR)
+         catch (const gdb_exception_error &except)
            {
              *cvalue = NULL;
            }
-         END_CATCH
        }
 
       /* Don't use get_target_type because it calls
@@ -488,10 +483,10 @@ c_value_of_variable (const struct varobj *var,
   struct type *type = get_type (var);
 
   /* Strip top-level references.  */
-  while (TYPE_CODE (type) == TYPE_CODE_REF)
+  while (TYPE_IS_REFERENCE (type))
     type = check_typedef (TYPE_TARGET_TYPE (type));
 
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
@@ -513,21 +508,22 @@ c_value_of_variable (const struct varobj *var,
          }
        else
          {
-           if (var->not_fetched && value_lazy (var->value))
+           if (var->not_fetched && value_lazy (var->value.get ()))
              /* Frozen variable and no value yet.  We don't
                 implicitly fetch the value.  MI response will
                 use empty string for the value, which is OK.  */
              return std::string ();
 
            gdb_assert (varobj_value_is_changeable_p (var));
-           gdb_assert (!value_lazy (var->value));
+           gdb_assert (!value_lazy (var->value.get ()));
            
            /* If the specified format is the current one,
               we can reuse print_value.  */
            if (format == var->format)
              return var->print_value;
            else
-             return varobj_value_get_print_value (var->value, format, var);
+             return varobj_value_get_print_value (var->value.get (), format,
+                                                  var);
          }
       }
     }
@@ -579,14 +575,14 @@ cplus_number_of_children (const struct varobj *var)
       /* It is necessary to access a real type (via RTTI).  */
       if (opts.objectprint)
         {
-          value = var->value;
-          lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
-                               || TYPE_CODE (var->type) == TYPE_CODE_PTR);
+          value = var->value.get ();
+          lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
+                               || var->type->code () == TYPE_CODE_PTR);
         }
       adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
 
-      if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT)
-         || ((TYPE_CODE (type)) == TYPE_CODE_UNION))
+      if (((type->code ()) == TYPE_CODE_STRUCT)
+         || ((type->code ()) == TYPE_CODE_UNION))
        {
          int kids[3];
 
@@ -616,9 +612,9 @@ cplus_number_of_children (const struct varobj *var)
         {
          const struct varobj *parent = var->parent;
 
-         value = parent->value;
-         lookup_actual_type = (TYPE_CODE (parent->type) == TYPE_CODE_REF
-                               || TYPE_CODE (parent->type) == TYPE_CODE_PTR);
+         value = parent->value.get ();
+         lookup_actual_type = (TYPE_IS_REFERENCE (parent->type)
+                               || parent->type->code () == TYPE_CODE_PTR);
         }
       adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
 
@@ -653,7 +649,7 @@ cplus_class_num_children (struct type *type, int children[3])
   children[v_protected] = 0;
 
   vptr_fieldno = get_vptr_fieldno (type, &basetype);
-  for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
+  for (i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
     {
       /* If we have a virtual table pointer, omit it.  Even if virtual
         table pointers are not specifically marked in the debug info,
@@ -722,9 +718,9 @@ cplus_describe_child (const struct varobj *parent, int index,
 
   var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent;
   if (opts.objectprint)
-    lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
-                         || TYPE_CODE (var->type) == TYPE_CODE_PTR);
-  value = var->value;
+    lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
+                         || var->type->code () == TYPE_CODE_PTR);
+  value = var->value.get ();
   type = varobj_get_value_type (var);
   if (cfull_expression)
     parent_expression
@@ -732,8 +728,8 @@ cplus_describe_child (const struct varobj *parent, int index,
 
   adjust_value_for_child_access (&value, &type, &was_ptr, lookup_actual_type);
 
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT
-      || TYPE_CODE (type) == TYPE_CODE_UNION)
+  if (type->code () == TYPE_CODE_STRUCT
+      || type->code () == TYPE_CODE_UNION)
     {
       const char *join = was_ptr ? "->" : ".";
 
@@ -769,16 +765,16 @@ cplus_describe_child (const struct varobj *parent, int index,
          --type_index;
 
          /* If the type is anonymous and the field has no name,
-            set an appopriate name.  */
+            set an appropriate name.  */
          field_name = TYPE_FIELD_NAME (type, type_index);
          if (field_name == NULL || *field_name == '\0')
            {
              if (cname)
                {
-                 if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
+                 if (TYPE_FIELD_TYPE (type, type_index)->code ()
                      == TYPE_CODE_STRUCT)
                    *cname = ANONYMOUS_STRUCT_NAME;
-                 else if (TYPE_CODE (TYPE_FIELD_TYPE (type, type_index))
+                 else if (TYPE_FIELD_TYPE (type, type_index)->code ()
                           == TYPE_CODE_UNION)
                    *cname = ANONYMOUS_UNION_NAME;
                }
@@ -843,7 +839,7 @@ cplus_describe_child (const struct varobj *parent, int index,
        }
       else
        {
-         char *access = NULL;
+         const char *access = NULL;
          int children[3];
 
          cplus_class_num_children (type, children);
This page took 0.031127 seconds and 4 git commands to generate.