fixed optimzation for Atom
[platform/upstream/binutils.git] / gdb / varobj.c
index 7e8b364..80b7c9a 100644 (file)
@@ -16,7 +16,6 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "exceptions.h"
 #include "value.h"
 #include "expression.h"
 #include "frame.h"
@@ -24,9 +23,6 @@
 #include "gdbcmd.h"
 #include "block.h"
 #include "valprint.h"
-
-#include "gdb_assert.h"
-#include <string.h>
 #include "gdb_regex.h"
 
 #include "varobj.h"
@@ -212,13 +208,9 @@ static char *my_value_of_variable (struct varobj *var,
 
 static int is_root_p (struct varobj *var);
 
-#if HAVE_PYTHON
-
 static struct varobj *varobj_add_child (struct varobj *var,
                                        struct varobj_item *item);
 
-#endif /* HAVE_PYTHON */
-
 /* Private data */
 
 /* Mappings of varobj_display_formats enums to gdb's format codes.  */
@@ -303,7 +295,7 @@ varobj_create (char *objname,
     {
       struct frame_info *fi;
       struct frame_id old_id = null_frame_id;
-      struct block *block;
+      const struct block *block;
       const char *p;
       struct value *value = NULL;
       volatile struct gdb_exception except;
@@ -701,8 +693,6 @@ varobj_restrict_range (VEC (varobj_p) *children, int *from, int *to)
     }
 }
 
-#if HAVE_PYTHON
-
 /* A helper for update_dynamic_varobj_children that installs a new
    child when needed.  */
 
@@ -747,6 +737,8 @@ install_dynamic_child (struct varobj *var,
     }
 }
 
+#if HAVE_PYTHON
+
 static int
 dynamic_varobj_has_child_method (struct varobj *var)
 {
@@ -762,6 +754,7 @@ dynamic_varobj_has_child_method (struct varobj *var)
   do_cleanups (back_to);
   return result;
 }
+#endif
 
 /* A factory for creating dynamic varobj's iterators.  Returns an
    iterator object suitable for iterating over VAR's children.  */
@@ -769,8 +762,10 @@ dynamic_varobj_has_child_method (struct varobj *var)
 static struct varobj_iter *
 varobj_get_iterator (struct varobj *var)
 {
+#if HAVE_PYTHON
   if (var->dynamic->pretty_printer)
     return py_varobj_get_iterator (var, var->dynamic->pretty_printer);
+#endif
 
   gdb_assert_not_reached (_("\
 requested an iterator from a non-dynamic varobj"));
@@ -788,7 +783,6 @@ varobj_clear_saved_item (struct varobj_dynamic *var)
       var->saved_item = NULL;
     }
 }
-#endif
 
 static int
 update_dynamic_varobj_children (struct varobj *var,
@@ -801,7 +795,6 @@ update_dynamic_varobj_children (struct varobj *var,
                                int from,
                                int to)
 {
-#if HAVE_PYTHON
   int i;
 
   *cchanged = 0;
@@ -891,9 +884,6 @@ update_dynamic_varobj_children (struct varobj *var,
   var->num_children = VEC_length (varobj_p, var->children);
 
   return 1;
-#else
-  gdb_assert_not_reached ("should never be called if Python is not enabled");
-#endif
 }
 
 int
@@ -901,7 +891,7 @@ varobj_get_num_children (struct varobj *var)
 {
   if (var->num_children == -1)
     {
-      if (var->dynamic->pretty_printer != NULL)
+      if (varobj_is_dynamic_p (var))
        {
          int dummy;
 
@@ -928,7 +918,7 @@ varobj_list_children (struct varobj *var, int *from, int *to)
 
   var->dynamic->children_requested = 1;
 
-  if (var->dynamic->pretty_printer != NULL)
+  if (varobj_is_dynamic_p (var))
     {
       /* This, in theory, can result in the number of children changing without
         frontend noticing.  But well, calling -var-list-children on the same
@@ -970,8 +960,6 @@ varobj_list_children (struct varobj *var, int *from, int *to)
   return var->children;
 }
 
-#if HAVE_PYTHON
-
 static struct varobj *
 varobj_add_child (struct varobj *var, struct varobj_item *item)
 {
@@ -983,8 +971,6 @@ varobj_add_child (struct varobj *var, struct varobj_item *item)
   return v;
 }
 
-#endif /* HAVE_PYTHON */
-
 /* Obtain the type of an object Variable as a string similar to the one gdb
    prints on the console.  */
 
@@ -1014,18 +1000,18 @@ varobj_get_gdb_type (struct varobj *var)
 static int
 is_path_expr_parent (struct varobj *var)
 {
-  struct type *type;
-
-  /* "Fake" children are not path_expr parents.  */
-  if (CPLUS_FAKE_CHILD (var))
-    return 0;
+  gdb_assert (var->root->lang_ops->is_path_expr_parent != NULL);
+  return var->root->lang_ops->is_path_expr_parent (var);
+}
 
-  type = varobj_get_value_type (var);
+/* Is VAR a path expression parent, i.e., can it be used to construct
+   a valid path expression?  By default we assume any VAR can be a path
+   parent.  */
 
-  /* Anonymous unions and structs are also not path_expr parents.  */
-  return !((TYPE_CODE (type) == TYPE_CODE_STRUCT
-           || TYPE_CODE (type) == TYPE_CODE_UNION)
-          && TYPE_NAME (type) == NULL);
+int
+varobj_default_is_path_expr_parent (struct varobj *var)
+{
+  return 1;
 }
 
 /* Return the path expression parent for VAR.  */
@@ -1076,8 +1062,10 @@ varobj_get_attributes (struct varobj *var)
   return attributes;
 }
 
+/* Return true if VAR is a dynamic varobj.  */
+
 int
-varobj_pretty_printed_p (struct varobj *var)
+varobj_is_dynamic_p (struct varobj *var)
 {
   return var->dynamic->pretty_printer != NULL;
 }
@@ -1732,10 +1720,9 @@ varobj_update (struct varobj **varp, int explicit)
            }
        }
 
-      /* We probably should not get children of a varobj that has a
-        pretty-printer, but for which -var-list-children was never
-        invoked.  */
-      if (v->dynamic->pretty_printer != NULL)
+      /* We probably should not get children of a dynamic varobj, but
+        for which -var-list-children was never invoked.  */
+      if (varobj_is_dynamic_p (v))
        {
          VEC (varobj_p) *changed = 0, *type_changed = 0, *unchanged = 0;
          VEC (varobj_p) *new = 0;
@@ -2738,24 +2725,6 @@ all_root_varobjs (void (*func) (struct varobj *var, void *data), void *data)
       (*func) (var_root->rootvar, data);
     }
 }
-\f
-extern void _initialize_varobj (void);
-void
-_initialize_varobj (void)
-{
-  int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
-
-  varobj_table = xmalloc (sizeof_table);
-  memset (varobj_table, 0, sizeof_table);
-
-  add_setshow_zuinteger_cmd ("varobj", class_maintenance,
-                            &varobjdebug,
-                            _("Set varobj debugging."),
-                            _("Show varobj debugging."),
-                            _("When non-zero, varobj debugging is enabled."),
-                            NULL, show_varobjdebug,
-                            &setdebuglist, &showdebuglist);
-}
 
 /* Invalidate varobj VAR if it is tied to locals and re-create it if it is
    defined on globals.  It is a helper for varobj_invalidate.
@@ -2798,3 +2767,21 @@ varobj_invalidate (void)
 {
   all_root_varobjs (varobj_invalidate_iter, NULL);
 }
+\f
+extern void _initialize_varobj (void);
+void
+_initialize_varobj (void)
+{
+  int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE;
+
+  varobj_table = xmalloc (sizeof_table);
+  memset (varobj_table, 0, sizeof_table);
+
+  add_setshow_zuinteger_cmd ("varobj", class_maintenance,
+                            &varobjdebug,
+                            _("Set varobj debugging."),
+                            _("Show varobj debugging."),
+                            _("When non-zero, varobj debugging is enabled."),
+                            NULL, show_varobjdebug,
+                            &setdebuglist, &showdebuglist);
+}