Make sure terminal settings are restored before exiting
[deliverable/binutils-gdb.git] / gdb / ada-varobj.c
index 52c76875296b002e0f0d7cb721475da2d64f0479..83d07073a298da8dc45b53a29bfe631281169102 100644 (file)
@@ -1,6 +1,6 @@
 /* varobj support for Ada.
 
-   Copyright (C) 2012-2013 Free Software Foundation, Inc.
+   Copyright (C) 2012-2015 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -18,7 +18,6 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "ada-varobj.h"
 #include "ada-lang.h"
 #include "varobj.h"
 #include "language.h"
@@ -49,6 +48,9 @@
    it allows the code to use the type without having to worry about
    it being set or not.  It makes the code clearer.  */
 
+static int ada_varobj_get_number_of_children (struct value *parent_value,
+                                             struct type *parent_type);
+
 /* A convenience function that decodes the VALUE_PTR/TYPE_PTR couple:
    If there is a value (*VALUE_PTR not NULL), then perform the decoding
    using it, and compute the associated type from the resulting value.
@@ -217,6 +219,15 @@ ada_varobj_adjust_for_child_access (struct value **value,
       && !ada_is_array_descriptor_type (TYPE_TARGET_TYPE (*type))
       && !ada_is_constrained_packed_array_type (TYPE_TARGET_TYPE (*type)))
     ada_varobj_ind (*value, *type, value, type);
+
+  /* If this is a tagged type, we need to transform it a bit in order
+     to be able to fetch its full view.  As always with tagged types,
+     we can only do that if we have a value.  */
+  if (*value != NULL && ada_is_tagged_type (*type, 1))
+    {
+      *value = ada_tag_value_at_base_address (*value);
+      *type = value_type (*value);
+    }
 }
 
 /* Assuming that the (PARENT_VALUE, PARENT_TYPE) pair is an array
@@ -229,6 +240,18 @@ ada_varobj_get_array_number_of_children (struct value *parent_value,
 {
   LONGEST lo, hi;
 
+  if (parent_value == NULL
+      && is_dynamic_type (TYPE_INDEX_TYPE (parent_type)))
+    {
+      /* This happens when listing the children of an object
+        which does not exist in memory (Eg: when requesting
+        the children of a null pointer, which is allowed by
+        varobj).  The array index type being dynamic, we cannot
+        determine how many elements this array has.  Just assume
+        it has none.  */
+      return 0;
+    }
+
   if (!get_array_bounds (parent_type, &lo, &hi))
     {
       /* Could not get the array bounds.  Pretend this is an empty array.  */
@@ -324,7 +347,7 @@ ada_varobj_get_ptr_number_of_children (struct value *parent_value,
 /* Return the number of children for the (PARENT_VALUE, PARENT_TYPE)
    pair.  */
 
-int
+static int
 ada_varobj_get_number_of_children (struct value *parent_value,
                                   struct type *parent_type)
 {
@@ -568,18 +591,12 @@ ada_varobj_describe_simple_array_child (struct value *parent_value,
                                        struct type **child_type,
                                        char **child_path_expr)
 {
-  struct type *index_desc_type;
   struct type *index_type;
   int real_index;
 
   gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_ARRAY);
 
-  index_desc_type = ada_find_parallel_type (parent_type, "___XA");
-  ada_fixup_array_indexes_type (index_desc_type);
-  if (index_desc_type)
-    index_type = TYPE_FIELD_TYPE (index_desc_type, 0);
-  else
-    index_type = TYPE_INDEX_TYPE (parent_type);
+  index_type = TYPE_INDEX_TYPE (parent_type);
   real_index = child_index + ada_discrete_type_low_bound (index_type);
 
   if (child_name)
@@ -722,7 +739,7 @@ ada_varobj_describe_child (struct value *parent_value,
 
    The result should be deallocated after use with xfree.  */
 
-char *
+static char *
 ada_varobj_get_name_of_child (struct value *parent_value,
                              struct type *parent_type,
                              const char *parent_name, int child_index)
@@ -742,7 +759,7 @@ ada_varobj_get_name_of_child (struct value *parent_value,
 
    The result must be deallocated after use with xfree.  */
 
-char *
+static char *
 ada_varobj_get_path_expr_of_child (struct value *parent_value,
                                   struct type *parent_type,
                                   const char *parent_name,
@@ -761,7 +778,7 @@ ada_varobj_get_path_expr_of_child (struct value *parent_value,
 /* Return the value of child number CHILD_INDEX of the (PARENT_VALUE,
    PARENT_TYPE) pair.  PARENT_NAME is the name of the parent.  */
 
-struct value *
+static struct value *
 ada_varobj_get_value_of_child (struct value *parent_value,
                               struct type *parent_type,
                               const char *parent_name, int child_index)
@@ -778,7 +795,7 @@ ada_varobj_get_value_of_child (struct value *parent_value,
 /* Return the type of child number CHILD_INDEX of the (PARENT_VALUE,
    PARENT_TYPE) pair.  */
 
-struct type *
+static struct type *
 ada_varobj_get_type_of_child (struct value *parent_value,
                              struct type *parent_type,
                              int child_index)
@@ -857,7 +874,7 @@ ada_varobj_get_value_of_array_variable (struct value *value,
 /* Return a string representation of the (VALUE, TYPE) pair, using
    the given print options OPTS as our formatting options.  */
 
-char *
+static char *
 ada_varobj_get_value_of_variable (struct value *value,
                                  struct type *type,
                                  struct value_print_options *opts)
@@ -889,28 +906,28 @@ ada_varobj_get_value_of_variable (struct value *value,
 /* Ada specific callbacks for VAROBJs.  */
 
 static int
-ada_number_of_children (struct varobj *var)
+ada_number_of_children (const struct varobj *var)
 {
   return ada_varobj_get_number_of_children (var->value, var->type);
 }
 
 static char *
-ada_name_of_variable (struct varobj *parent)
+ada_name_of_variable (const struct varobj *parent)
 {
   return c_varobj_ops.name_of_variable (parent);
 }
 
 static char *
-ada_name_of_child (struct varobj *parent, int index)
+ada_name_of_child (const struct varobj *parent, int index)
 {
   return ada_varobj_get_name_of_child (parent->value, parent->type,
                                       parent->name, index);
 }
 
 static char*
-ada_path_expr_of_child (struct varobj *child)
+ada_path_expr_of_child (const struct varobj *child)
 {
-  struct varobj *parent = child->parent;
+  const struct varobj *parent = child->parent;
   const char *parent_path_expr = varobj_get_path_expr (parent);
 
   return ada_varobj_get_path_expr_of_child (parent->value,
@@ -921,21 +938,22 @@ ada_path_expr_of_child (struct varobj *child)
 }
 
 static struct value *
-ada_value_of_child (struct varobj *parent, int index)
+ada_value_of_child (const struct varobj *parent, int index)
 {
   return ada_varobj_get_value_of_child (parent->value, parent->type,
                                        parent->name, index);
 }
 
 static struct type *
-ada_type_of_child (struct varobj *parent, int index)
+ada_type_of_child (const struct varobj *parent, int index)
 {
   return ada_varobj_get_type_of_child (parent->value, parent->type,
                                       index);
 }
 
 static char *
-ada_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+ada_value_of_variable (const struct varobj *var,
+                      enum varobj_display_formats format)
 {
   struct value_print_options opts;
 
@@ -947,7 +965,7 @@ ada_value_of_variable (struct varobj *var, enum varobj_display_formats format)
 /* Implement the "value_is_changeable_p" routine for Ada.  */
 
 static int
-ada_value_is_changeable_p (struct varobj *var)
+ada_value_is_changeable_p (const struct varobj *var)
 {
   struct type *type = var->value ? value_type (var->value) : var->type;
 
@@ -973,7 +991,7 @@ ada_value_is_changeable_p (struct varobj *var)
 /* Implement the "value_has_mutated" routine for Ada.  */
 
 static int
-ada_value_has_mutated (struct varobj *var, struct value *new_val,
+ada_value_has_mutated (const struct varobj *var, struct value *new_val,
                       struct type *new_type)
 {
   int i;
@@ -1021,5 +1039,6 @@ const struct lang_varobj_ops ada_varobj_ops =
   ada_type_of_child,
   ada_value_of_variable,
   ada_value_is_changeable_p,
-  ada_value_has_mutated
+  ada_value_has_mutated,
+  varobj_default_is_path_expr_parent
 };
This page took 0.026219 seconds and 4 git commands to generate.