Protoization.
[deliverable/binutils-gdb.git] / gdb / varobj.c
index f0740c69672966121b7f50ff0a5d69e5731020dc..5cc6e88d1679ecdf89999cb25b6f4d9ea5ad9c91 100644 (file)
@@ -56,6 +56,10 @@ struct varobj_root
     /* The frame for this expression */
     CORE_ADDR frame;
 
     /* The frame for this expression */
     CORE_ADDR frame;
 
+    /* If 1, "update" always recomputes the frame & valid block
+       using the currently selected frame. */
+    int use_selected_frame;
+
     /* Language info for this variable and its children */
     struct language_specific *lang;
 
     /* Language info for this variable and its children */
     struct language_specific *lang;
 
@@ -151,126 +155,128 @@ struct vlist
 
 /* Helper functions for the above subcommands. */
 
 
 /* Helper functions for the above subcommands. */
 
-static int delete_variable PARAMS ((struct cpstack **, struct varobj *, int));
+static int delete_variable (struct cpstack **, struct varobj *, int);
 
 
-static void delete_variable_1 PARAMS ((struct cpstack **, int *,
-                                      struct varobj *, int, int));
+static void delete_variable_1 (struct cpstack **, int *,
+                              struct varobj *, int, int);
 
 
-static int install_variable PARAMS ((struct varobj *));
+static int install_variable (struct varobj *);
 
 
-static void uninstall_variable PARAMS ((struct varobj *));
+static void uninstall_variable (struct varobj *);
 
 
-static struct varobj *child_exists PARAMS ((struct varobj *, char *));
+static struct varobj *child_exists (struct varobj *, char *);
 
 
-static struct varobj *create_child PARAMS ((struct varobj *, int, char *));
+static struct varobj *create_child (struct varobj *, int, char *);
 
 
-static void save_child_in_parent PARAMS ((struct varobj *, struct varobj *));
+static void save_child_in_parent (struct varobj *, struct varobj *);
 
 
-static void remove_child_from_parent PARAMS ((struct varobj *, struct varobj *));
+static void remove_child_from_parent (struct varobj *, struct varobj *);
 
 /* Utility routines */
 
 
 /* Utility routines */
 
-static struct varobj *new_variable PARAMS ((void));
+static struct varobj *new_variable (void);
+
+static struct varobj *new_root_variable (void);
 
 
-static struct varobj *new_root_variable PARAMS ((void));
+static void free_variable (struct varobj *var);
 
 
-static void free_variable PARAMS ((struct varobj * var));
+static struct cleanup *make_cleanup_free_variable (struct varobj *var);
 
 
-static struct type *get_type PARAMS ((struct varobj * var));
+static struct type *get_type (struct varobj *var);
 
 
-static struct type *get_type_deref PARAMS ((struct varobj * var));
+static struct type *get_type_deref (struct varobj *var);
 
 
-static struct type *get_target_type PARAMS ((struct type *));
+static struct type *get_target_type (struct type *);
 
 
-static enum varobj_display_formats variable_default_display PARAMS ((struct varobj *));
+static enum varobj_display_formats variable_default_display (struct varobj *);
 
 
-static int my_value_equal PARAMS ((value_ptr, value_ptr, int *));
+static int my_value_equal (value_ptr, value_ptr, int *);
 
 
-static void vpush PARAMS ((struct vstack ** pstack, struct varobj * var));
+static void vpush (struct vstack **pstack, struct varobj *var);
 
 
-static struct varobj *vpop PARAMS ((struct vstack ** pstack));
+static struct varobj *vpop (struct vstack **pstack);
 
 
-static void cppush PARAMS ((struct cpstack ** pstack, char *name));
+static void cppush (struct cpstack **pstack, char *name);
 
 
-static char *cppop PARAMS ((struct cpstack ** pstack));
+static char *cppop (struct cpstack **pstack);
 
 /* Language-specific routines. */
 
 
 /* Language-specific routines. */
 
-static enum varobj_languages variable_language PARAMS ((struct varobj * var));
+static enum varobj_languages variable_language (struct varobj *var);
 
 
-static int number_of_children PARAMS ((struct varobj *));
+static int number_of_children (struct varobj *);
 
 
-static char *name_of_variable PARAMS ((struct varobj *));
+static char *name_of_variable (struct varobj *);
 
 
-static char *name_of_child PARAMS ((struct varobj *, int));
+static char *name_of_child (struct varobj *, int);
 
 
-static value_ptr value_of_root PARAMS ((struct varobj * var));
+static value_ptr value_of_root (struct varobj **var_handle, int *);
 
 
-static value_ptr value_of_child PARAMS ((struct varobj * parent, int index));
+static value_ptr value_of_child (struct varobj *parent, int index);
 
 
-static struct type *type_of_child PARAMS ((struct varobj * var));
+static struct type *type_of_child (struct varobj *var);
 
 
-static int variable_editable PARAMS ((struct varobj * var));
+static int variable_editable (struct varobj *var);
 
 
-static char *my_value_of_variable PARAMS ((struct varobj * var));
+static char *my_value_of_variable (struct varobj *var);
 
 
-static int type_changeable PARAMS ((struct varobj * var));
+static int type_changeable (struct varobj *var);
 
 /* C implementation */
 
 
 /* C implementation */
 
-static int c_number_of_children PARAMS ((struct varobj * var));
+static int c_number_of_children (struct varobj *var);
 
 
-static char *c_name_of_variable PARAMS ((struct varobj * parent));
+static char *c_name_of_variable (struct varobj *parent);
 
 
-static char *c_name_of_child PARAMS ((struct varobj * parent, int index));
+static char *c_name_of_child (struct varobj *parent, int index);
 
 
-static value_ptr c_value_of_root PARAMS ((struct varobj * var));
+static value_ptr c_value_of_root (struct varobj **var_handle);
 
 
-static value_ptr c_value_of_child PARAMS ((struct varobj * parent, int index));
+static value_ptr c_value_of_child (struct varobj *parent, int index);
 
 
-static struct type *c_type_of_child PARAMS ((struct varobj * parent, int index));
+static struct type *c_type_of_child (struct varobj *parent, int index);
 
 
-static int c_variable_editable PARAMS ((struct varobj * var));
+static int c_variable_editable (struct varobj *var);
 
 
-static char *c_value_of_variable PARAMS ((struct varobj * var));
+static char *c_value_of_variable (struct varobj *var);
 
 /* C++ implementation */
 
 
 /* C++ implementation */
 
-static int cplus_number_of_children PARAMS ((struct varobj * var));
+static int cplus_number_of_children (struct varobj *var);
 
 
-static void cplus_class_num_children PARAMS ((struct type * type, int children[3]));
+static void cplus_class_num_children (struct type *type, int children[3]);
 
 
-static char *cplus_name_of_variable PARAMS ((struct varobj * parent));
+static char *cplus_name_of_variable (struct varobj *parent);
 
 
-static char *cplus_name_of_child PARAMS ((struct varobj * parent, int index));
+static char *cplus_name_of_child (struct varobj *parent, int index);
 
 
-static value_ptr cplus_value_of_root PARAMS ((struct varobj * var));
+static value_ptr cplus_value_of_root (struct varobj **var_handle);
 
 
-static value_ptr cplus_value_of_child PARAMS ((struct varobj * parent, int index));
+static value_ptr cplus_value_of_child (struct varobj *parent, int index);
 
 
-static struct type *cplus_type_of_child PARAMS ((struct varobj * parent, int index));
+static struct type *cplus_type_of_child (struct varobj *parent, int index);
 
 
-static int cplus_variable_editable PARAMS ((struct varobj * var));
+static int cplus_variable_editable (struct varobj *var);
 
 
-static char *cplus_value_of_variable PARAMS ((struct varobj * var));
+static char *cplus_value_of_variable (struct varobj *var);
 
 /* Java implementation */
 
 
 /* Java implementation */
 
-static int java_number_of_children PARAMS ((struct varobj * var));
+static int java_number_of_children (struct varobj *var);
 
 
-static char *java_name_of_variable PARAMS ((struct varobj * parent));
+static char *java_name_of_variable (struct varobj *parent);
 
 
-static char *java_name_of_child PARAMS ((struct varobj * parent, int index));
+static char *java_name_of_child (struct varobj *parent, int index);
 
 
-static value_ptr java_value_of_root PARAMS ((struct varobj * var));
+static value_ptr java_value_of_root (struct varobj **var_handle);
 
 
-static value_ptr java_value_of_child PARAMS ((struct varobj * parent, int index));
+static value_ptr java_value_of_child (struct varobj *parent, int index);
 
 
-static struct type *java_type_of_child PARAMS ((struct varobj * parent, int index));
+static struct type *java_type_of_child (struct varobj *parent, int index);
 
 
-static int java_variable_editable PARAMS ((struct varobj * var));
+static int java_variable_editable (struct varobj *var);
 
 
-static char *java_value_of_variable PARAMS ((struct varobj * var));
+static char *java_value_of_variable (struct varobj *var);
 
 /* The language specific vector */
 
 
 /* The language specific vector */
 
@@ -281,28 +287,28 @@ struct language_specific
     enum varobj_languages language;
 
     /* The number of children of PARENT. */
     enum varobj_languages language;
 
     /* The number of children of PARENT. */
-    int (*number_of_children) PARAMS ((struct varobj * parent));
+    int (*number_of_children) (struct varobj * parent);
 
     /* The name (expression) of a root varobj. */
 
     /* The name (expression) of a root varobj. */
-    char *(*name_of_variable) PARAMS ((struct varobj * parent));
+    char *(*name_of_variable) (struct varobj * parent);
 
     /* The name of the INDEX'th child of PARENT. */
 
     /* The name of the INDEX'th child of PARENT. */
-    char *(*name_of_child) PARAMS ((struct varobj * parent, int index));
+    char *(*name_of_child) (struct varobj * parent, int index);
 
     /* The value_ptr of the root variable ROOT. */
 
     /* The value_ptr of the root variable ROOT. */
-      value_ptr (*value_of_root) PARAMS ((struct varobj * root));
+      value_ptr (*value_of_root) (struct varobj ** root_handle);
 
     /* The value_ptr of the INDEX'th child of PARENT. */
 
     /* The value_ptr of the INDEX'th child of PARENT. */
-      value_ptr (*value_of_child) PARAMS ((struct varobj * parent, int index));
+      value_ptr (*value_of_child) (struct varobj * parent, int index);
 
     /* The type of the INDEX'th child of PARENT. */
 
     /* The type of the INDEX'th child of PARENT. */
-    struct type *(*type_of_child) PARAMS ((struct varobj * parent, int index));
+    struct type *(*type_of_child) (struct varobj * parent, int index);
 
     /* Is VAR editable? */
 
     /* Is VAR editable? */
-    int (*variable_editable) PARAMS ((struct varobj * var));
+    int (*variable_editable) (struct varobj * var);
 
     /* The current value of VAR. */
 
     /* The current value of VAR. */
-    char *(*value_of_variable) PARAMS ((struct varobj * var));
+    char *(*value_of_variable) (struct varobj * var);
   };
 
 /* Array of known source language routines. */
   };
 
 /* Array of known source language routines. */
@@ -401,7 +407,8 @@ static struct vlist **varobj_table;
 
 struct varobj *
 varobj_create (char *objname,
 
 struct varobj *
 varobj_create (char *objname,
-              char *expression, CORE_ADDR frame)
+              char *expression, CORE_ADDR frame,
+              enum varobj_type type)
 {
   struct varobj *var;
   struct frame_info *fi, *old_fi;
 {
   struct varobj *var;
   struct frame_info *fi, *old_fi;
@@ -410,7 +417,7 @@ varobj_create (char *objname,
 
   /* Fill out a varobj structure for the (root) variable being constructed. */
   var = new_root_variable ();
 
   /* Fill out a varobj structure for the (root) variable being constructed. */
   var = new_root_variable ();
-  old_chain = make_cleanup ((make_cleanup_func) free_variable, var);
+  old_chain = make_cleanup_free_variable (var);
 
   if (expression != NULL)
     {
 
   if (expression != NULL)
     {
@@ -421,19 +428,28 @@ varobj_create (char *objname,
          of the variable's data as possible */
 
       /* Allow creator to specify context of variable */
          of the variable's data as possible */
 
       /* Allow creator to specify context of variable */
-      if (frame == (CORE_ADDR) -1)
+      if ((type == USE_CURRENT_FRAME)
+         || (type == USE_SELECTED_FRAME))
        fi = selected_frame;
       else
        fi = find_frame_addr_in_frame_chain (frame);
 
        fi = selected_frame;
       else
        fi = find_frame_addr_in_frame_chain (frame);
 
+      /* frame = -2 means always use selected frame */
+      if (type == USE_SELECTED_FRAME)
+       var->root->use_selected_frame = 1;
+
       block = NULL;
       if (fi != NULL)
        block = get_frame_block (fi);
 
       p = expression;
       innermost_block = NULL;
       block = NULL;
       if (fi != NULL)
        block = get_frame_block (fi);
 
       p = expression;
       innermost_block = NULL;
-      /* Callee may longjump */
-      var->root->exp = parse_exp_1 (&p, block, 0);
+      /* Wrap the call to parse expression, so we can 
+         return a sensible error. */
+      if (!gdb_parse_exp_1 (&p, block, 0, &var->root->exp))
+       {
+         return NULL;
+       }
 
       /* Don't allow variables to be created for types. */
       if (var->root->exp->elts[0].opcode == OP_TYPE)
 
       /* Don't allow variables to be created for types. */
       if (var->root->exp->elts[0].opcode == OP_TYPE)
@@ -486,7 +502,10 @@ varobj_create (char *objname,
        select_frame (old_fi, -1);
     }
 
        select_frame (old_fi, -1);
     }
 
-  if (var != NULL)
+  /* If the variable object name is null, that means this
+     is a temporary variable, so don't install it. */
+
+  if ((var != NULL) && (objname != NULL))
     {
       var->obj_name = savestring (objname, strlen (objname));
 
     {
       var->obj_name = savestring (objname, strlen (objname));
 
@@ -845,6 +864,10 @@ varobj_list (struct varobj ***varlist)
    expression to see if it's changed.  Then go all the way
    through its children, reconstructing them and noting if they've
    changed.
    expression to see if it's changed.  Then go all the way
    through its children, reconstructing them and noting if they've
    changed.
+   Return value:
+    -1 if there was an error updating the varobj
+    -2 if the type changed
+    Otherwise it is the number of children + parent changed
 
    Only root variables can be updated... */
 
 
    Only root variables can be updated... */
 
@@ -852,6 +875,7 @@ int
 varobj_update (struct varobj *var, struct varobj ***changelist)
 {
   int changed = 0;
 varobj_update (struct varobj *var, struct varobj ***changelist)
 {
   int changed = 0;
+  int type_changed;
   int i;
   int vleft;
   int error2;
   int i;
   int vleft;
   int error2;
@@ -878,19 +902,27 @@ varobj_update (struct varobj *var, struct varobj ***changelist)
 
   /* Update the root variable. value_of_root can return NULL
      if the variable is no longer around, i.e. we stepped out of
 
   /* Update the root variable. value_of_root can return NULL
      if the variable is no longer around, i.e. we stepped out of
-     the frame in which a local existed. */
-  new = value_of_root (var);
+     the frame in which a local existed. We are letting the 
+     value_of_root variable dispose of the varobj if the type
+     has changed. */
+  type_changed = 1;
+  new = value_of_root (&var, &type_changed);
   if (new == NULL)
   if (new == NULL)
-    return -1;
+    {
+      var->error = 1;
+      return -1;
+    }
 
   /* Initialize a stack for temporary results */
   vpush (&result, NULL);
 
 
   /* Initialize a stack for temporary results */
   vpush (&result, NULL);
 
-  if (!my_value_equal (var->value, new, &error2))
+  if (type_changed || !my_value_equal (var->value, new, &error2))
     {
       /* Note that it's changed   There a couple of exceptions here,
     {
       /* Note that it's changed   There a couple of exceptions here,
-         though. We don't want some types to be reported as "changed". */
-      if (type_changeable (var))
+         though. We don't want some types to be reported as 
+        "changed". The exception to this is if this is a 
+        "use_selected_frame" varobj, and its type has changed. */
+      if (type_changed || type_changeable (var))
        {
          vpush (&result, var);
          changed++;
        {
          vpush (&result, var);
          changed++;
@@ -984,7 +1016,10 @@ varobj_update (struct varobj *var, struct varobj ***changelist)
   /* Restore selected frame */
   select_frame (old_fi, -1);
 
   /* Restore selected frame */
   select_frame (old_fi, -1);
 
-  return changed;
+  if (type_changed)
+    return -2;
+  else
+    return changed;
 }
 \f
 
 }
 \f
 
@@ -995,10 +1030,8 @@ varobj_update (struct varobj *var, struct varobj ***changelist)
  */
 
 static int
  */
 
 static int
-delete_variable (resultp, var, only_children_p)
-     struct cpstack **resultp;
-     struct varobj *var;
-     int only_children_p;
+delete_variable (struct cpstack **resultp, struct varobj *var,
+                int only_children_p)
 {
   int delcount = 0;
 
 {
   int delcount = 0;
 
@@ -1013,13 +1046,8 @@ delete_variable (resultp, var, only_children_p)
    and the parent is not removed we dump core.  It must be always
    initially called with remove_from_parent_p set */
 static void
    and the parent is not removed we dump core.  It must be always
    initially called with remove_from_parent_p set */
 static void
-delete_variable_1 (resultp, delcountp, var,
-                  only_children_p, remove_from_parent_p)
-     struct cpstack **resultp;
-     int *delcountp;
-     struct varobj *var;
-     int only_children_p;
-     int remove_from_parent_p;
+delete_variable_1 (struct cpstack **resultp, int *delcountp, struct varobj *var,
+                  int only_children_p, int remove_from_parent_p)
 {
   struct varobj_child *vc;
   struct varobj_child *next;
 {
   struct varobj_child *vc;
   struct varobj_child *next;
@@ -1039,9 +1067,9 @@ delete_variable_1 (resultp, delcountp, var,
     return;
 
   /* Otherwise, add it to the list of deleted ones and proceed to do so */
     return;
 
   /* Otherwise, add it to the list of deleted ones and proceed to do so */
-  if (var->obj_name == NULL)
-    warning ("Assertion failed: NULL var->obj_name unexpectdly found");
-  else
+  /* If the name is null, this is a temporary variable, that has not
+     yet been installed, don't report it, it belongs to the caller... */
+  if (var->obj_name != NULL)
     {
       cppush (resultp, strdup (var->obj_name));
       *delcountp = *delcountp + 1;
     {
       cppush (resultp, strdup (var->obj_name));
       *delcountp = *delcountp + 1;
@@ -1057,8 +1085,9 @@ delete_variable_1 (resultp, delcountp, var,
     {
       remove_child_from_parent (var->parent, var);
     }
     {
       remove_child_from_parent (var->parent, var);
     }
-
-  uninstall_variable (var);
+  
+  if (var->obj_name != NULL)
+    uninstall_variable (var);
 
   /* Free memory associated with this variable */
   free_variable (var);
 
   /* Free memory associated with this variable */
   free_variable (var);
@@ -1066,8 +1095,7 @@ delete_variable_1 (resultp, delcountp, var,
 
 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
 static int
 
 /* Install the given variable VAR with the object name VAR->OBJ_NAME. */
 static int
-install_variable (var)
-     struct varobj *var;
+install_variable (struct varobj *var)
 {
   struct vlist *cv;
   struct vlist *newvl;
 {
   struct vlist *cv;
   struct vlist *newvl;
@@ -1110,8 +1138,7 @@ install_variable (var)
 
 /* Unistall the object VAR. */
 static void
 
 /* Unistall the object VAR. */
 static void
-uninstall_variable (var)
-     struct varobj *var;
+uninstall_variable (struct varobj *var)
 {
   struct vlist *cv;
   struct vlist *prev;
 {
   struct vlist *cv;
   struct vlist *prev;
@@ -1201,10 +1228,7 @@ child_exists (var, name)
 
 /* Create and install a child of the parent of the given name */
 static struct varobj *
 
 /* Create and install a child of the parent of the given name */
 static struct varobj *
-create_child (parent, index, name)
-     struct varobj *parent;
-     int index;
-     char *name;
+create_child (struct varobj *parent, int index, char *name)
 {
   struct varobj *child;
   char *childs_name;
 {
   struct varobj *child;
   char *childs_name;
@@ -1237,9 +1261,7 @@ create_child (parent, index, name)
 /* FIXME: This should be a generic add to list */
 /* Save CHILD in the PARENT's data. */
 static void
 /* FIXME: This should be a generic add to list */
 /* Save CHILD in the PARENT's data. */
 static void
-save_child_in_parent (parent, child)
-     struct varobj *parent;
-     struct varobj *child;
+save_child_in_parent (struct varobj *parent, struct varobj *child)
 {
   struct varobj_child *vc;
 
 {
   struct varobj_child *vc;
 
@@ -1255,9 +1277,7 @@ save_child_in_parent (parent, child)
 /* FIXME: This should be a generic remove from list */
 /* Remove the CHILD from the PARENT's list of children. */
 static void
 /* FIXME: This should be a generic remove from list */
 /* Remove the CHILD from the PARENT's list of children. */
 static void
-remove_child_from_parent (parent, child)
-     struct varobj *parent;
-     struct varobj *child;
+remove_child_from_parent (struct varobj *parent, struct varobj *child)
 {
   struct varobj_child *vc, *prev;
 
 {
   struct varobj_child *vc, *prev;
 
@@ -1315,6 +1335,7 @@ new_root_variable (void)
   var->root->exp = NULL;
   var->root->valid_block = NULL;
   var->root->frame = (CORE_ADDR) -1;
   var->root->exp = NULL;
   var->root->valid_block = NULL;
   var->root->frame = (CORE_ADDR) -1;
+  var->root->use_selected_frame = 0;
   var->root->rootvar = NULL;
 
   return var;
   var->root->rootvar = NULL;
 
   return var;
@@ -1322,8 +1343,7 @@ new_root_variable (void)
 
 /* Free any allocated memory associated with VAR. */
 static void
 
 /* Free any allocated memory associated with VAR. */
 static void
-free_variable (var)
-     struct varobj *var;
+free_variable (struct varobj *var)
 {
   /* Free the expression if this is a root variable. */
   if (var->root->rootvar == var)
 {
   /* Free the expression if this is a root variable. */
   if (var->root->rootvar == var)
@@ -1337,12 +1357,23 @@ free_variable (var)
   FREEIF (var);
 }
 
   FREEIF (var);
 }
 
+static void
+do_free_variable_cleanup (void *var)
+{
+  free_variable (var);
+}
+
+static struct cleanup *
+make_cleanup_free_variable (struct varobj *var)
+{
+  return make_cleanup (do_free_variable_cleanup, var);
+}
+
 /* This returns the type of the variable. This skips past typedefs
    and returns the real type of the variable. It also dereferences
    pointers and references. */
 static struct type *
 /* This returns the type of the variable. This skips past typedefs
    and returns the real type of the variable. It also dereferences
    pointers and references. */
 static struct type *
-get_type (var)
-     struct varobj *var;
+get_type (struct varobj *var)
 {
   struct type *type;
   type = var->type;
 {
   struct type *type;
   type = var->type;
@@ -1355,8 +1386,7 @@ get_type (var)
 
 /* This returns the type of the variable, dereferencing pointers, too. */
 static struct type *
 
 /* This returns the type of the variable, dereferencing pointers, too. */
 static struct type *
-get_type_deref (var)
-     struct varobj *var;
+get_type_deref (struct varobj *var)
 {
   struct type *type;
 
 {
   struct type *type;
 
@@ -1372,8 +1402,7 @@ get_type_deref (var)
 /* This returns the target type (or NULL) of TYPE, also skipping
    past typedefs, just like get_type (). */
 static struct type *
 /* This returns the target type (or NULL) of TYPE, also skipping
    past typedefs, just like get_type (). */
 static struct type *
-get_target_type (type)
-     struct type *type;
+get_target_type (struct type *type)
 {
   if (type != NULL)
     {
 {
   if (type != NULL)
     {
@@ -1388,8 +1417,7 @@ get_target_type (type)
 /* What is the default display for this variable? We assume that
    everything is "natural". Any exceptions? */
 static enum varobj_display_formats
 /* What is the default display for this variable? We assume that
    everything is "natural". Any exceptions? */
 static enum varobj_display_formats
-variable_default_display (var)
-     struct varobj *var;
+variable_default_display (struct varobj *var)
 {
   return FORMAT_NATURAL;
 }
 {
   return FORMAT_NATURAL;
 }
@@ -1398,10 +1426,7 @@ variable_default_display (var)
    one is "safe" -- it NEVER longjmps. It determines if the VAR's
    value is the same as VAL2. */
 static int
    one is "safe" -- it NEVER longjmps. It determines if the VAR's
    value is the same as VAL2. */
 static int
-my_value_equal (val1, val2, error2)
-     value_ptr val1;
-     value_ptr val2;
-     int *error2;
+my_value_equal (value_ptr val1, value_ptr val2, int *error2)
 {
   int r, err1, err2;
 
 {
   int r, err1, err2;
 
@@ -1455,9 +1480,7 @@ my_value_equal (val1, val2, error2)
 
 /* FIXME: The following should be generic for any pointer */
 static void
 
 /* FIXME: The following should be generic for any pointer */
 static void
-vpush (pstack, var)
-     struct vstack **pstack;
-     struct varobj *var;
+vpush (struct vstack **pstack, struct varobj *var)
 {
   struct vstack *s;
 
 {
   struct vstack *s;
 
@@ -1469,8 +1492,7 @@ vpush (pstack, var)
 
 /* FIXME: The following should be generic for any pointer */
 static struct varobj *
 
 /* FIXME: The following should be generic for any pointer */
 static struct varobj *
-vpop (pstack)
-     struct vstack **pstack;
+vpop (struct vstack **pstack)
 {
   struct vstack *s;
   struct varobj *v;
 {
   struct vstack *s;
   struct varobj *v;
@@ -1488,9 +1510,7 @@ vpop (pstack)
 
 /* FIXME: The following should be generic for any pointer */
 static void
 
 /* FIXME: The following should be generic for any pointer */
 static void
-cppush (pstack, name)
-     struct cpstack **pstack;
-     char *name;
+cppush (struct cpstack **pstack, char *name)
 {
   struct cpstack *s;
 
 {
   struct cpstack *s;
 
@@ -1502,8 +1522,7 @@ cppush (pstack, name)
 
 /* FIXME: The following should be generic for any pointer */
 static char *
 
 /* FIXME: The following should be generic for any pointer */
 static char *
-cppop (pstack)
-     struct cpstack **pstack;
+cppop (struct cpstack **pstack)
 {
   struct cpstack *s;
   char *v;
 {
   struct cpstack *s;
   char *v;
@@ -1527,8 +1546,7 @@ cppop (pstack)
 
 /* Get the language of variable VAR. */
 static enum varobj_languages
 
 /* Get the language of variable VAR. */
 static enum varobj_languages
-variable_language (var)
-     struct varobj *var;
+variable_language (struct varobj *var)
 {
   enum varobj_languages lang;
 
 {
   enum varobj_languages lang;
 
@@ -1555,42 +1573,96 @@ variable_language (var)
    is the number of children that the user will see in the variable
    display. */
 static int
    is the number of children that the user will see in the variable
    display. */
 static int
-number_of_children (var)
-     struct varobj *var;
+number_of_children (struct varobj *var)
 {
   return (*var->root->lang->number_of_children) (var);;
 }
 
 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
 static char *
 {
   return (*var->root->lang->number_of_children) (var);;
 }
 
 /* What is the expression for the root varobj VAR? Returns a malloc'd string. */
 static char *
-name_of_variable (var)
-     struct varobj *var;
+name_of_variable (struct varobj *var)
 {
   return (*var->root->lang->name_of_variable) (var);
 }
 
 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
 static char *
 {
   return (*var->root->lang->name_of_variable) (var);
 }
 
 /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */
 static char *
-name_of_child (var, index)
-     struct varobj *var;
-     int index;
+name_of_child (struct varobj *var, int index)
 {
   return (*var->root->lang->name_of_child) (var, index);
 }
 
 {
   return (*var->root->lang->name_of_child) (var, index);
 }
 
-/* What is the value_ptr of the root variable VAR? */
+/* What is the value_ptr of the root variable VAR? 
+   TYPE_CHANGED controls what to do if the type of a
+   use_selected_frame = 1 variable changes.  On input,
+   TYPE_CHANGED = 1 means discard the old varobj, and replace
+   it with this one.  TYPE_CHANGED = 0 means leave it around.
+   NB: In both cases, var_handle will point to the new varobj,
+   so if you use TYPE_CHANGED = 0, you will have to stash the
+   old varobj pointer away somewhere before calling this.
+   On return, TYPE_CHANGED will be 1 if the type has changed, and 
+   0 otherwise. */
 static value_ptr
 static value_ptr
-value_of_root (var)
-     struct varobj *var;
+value_of_root (struct varobj **var_handle, int *type_changed)
 {
 {
-  return (*var->root->lang->value_of_root) (var);
+  struct varobj *var;
+
+  if (var_handle == NULL)
+    return NULL;
+
+  var = *var_handle;
+
+  /* This should really be an exception, since this should
+     only get called with a root variable. */
+
+  if (var->root->rootvar != var)
+    return NULL;
+
+  if (var->root->use_selected_frame)
+    {
+      struct varobj *tmp_var;
+      char *old_type, *new_type;
+      old_type = varobj_get_type (var);
+      tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0,
+                              USE_SELECTED_FRAME);
+      if (tmp_var == NULL)
+       {
+         return NULL;
+       }
+      new_type = varobj_get_type (tmp_var);
+      if (strcmp(old_type, new_type) == 0)
+       {
+         varobj_delete (tmp_var, NULL, 0);
+         *type_changed = 0;
+       }
+      else
+       {
+         if (*type_changed)
+           {
+             tmp_var->obj_name = 
+               savestring (var->obj_name, strlen (var->obj_name));
+             uninstall_variable (var);
+           }
+         else
+           {
+             tmp_var->obj_name = varobj_gen_name ();  
+           }
+         install_variable (tmp_var);
+         *var_handle = tmp_var;
+         *type_changed = 1;
+       }
+    }
+  else
+    {
+      *type_changed = 0;
+    }
+
+  return (*var->root->lang->value_of_root) (var_handle);
 }
 
 /* What is the value_ptr for the INDEX'th child of PARENT? */
 static value_ptr
 }
 
 /* What is the value_ptr for the INDEX'th child of PARENT? */
 static value_ptr
-value_of_child (parent, index)
-     struct varobj *parent;
-     int index;
+value_of_child (struct varobj *parent, int index)
 {
   value_ptr value;
 
 {
   value_ptr value;
 
@@ -1605,8 +1677,7 @@ value_of_child (parent, index)
 
 /* What is the type of VAR? */
 static struct type *
 
 /* What is the type of VAR? */
 static struct type *
-type_of_child (var)
-     struct varobj *var;
+type_of_child (struct varobj *var)
 {
 
   /* If the child had no evaluation errors, var->value
 {
 
   /* If the child had no evaluation errors, var->value
@@ -1621,16 +1692,14 @@ type_of_child (var)
 /* Is this variable editable? Use the variable's type to make
    this determination. */
 static int
 /* Is this variable editable? Use the variable's type to make
    this determination. */
 static int
-variable_editable (var)
-     struct varobj *var;
+variable_editable (struct varobj *var)
 {
   return (*var->root->lang->variable_editable) (var);
 }
 
 /* GDB already has a command called "value_of_variable". Sigh. */
 static char *
 {
   return (*var->root->lang->variable_editable) (var);
 }
 
 /* GDB already has a command called "value_of_variable". Sigh. */
 static char *
-my_value_of_variable (var)
-     struct varobj *var;
+my_value_of_variable (struct varobj *var)
 {
   return (*var->root->lang->value_of_variable) (var);
 }
 {
   return (*var->root->lang->value_of_variable) (var);
 }
@@ -1639,8 +1708,7 @@ my_value_of_variable (var)
    some variable's values never change. For example,
    struct and unions never change values. */
 static int
    some variable's values never change. For example,
    struct and unions never change values. */
 static int
-type_changeable (var)
-     struct varobj *var;
+type_changeable (struct varobj *var)
 {
   int r;
   struct type *type;
 {
   int r;
   struct type *type;
@@ -1666,8 +1734,7 @@ type_changeable (var)
 
 /* C */
 static int
 
 /* C */
 static int
-c_number_of_children (var)
-     struct varobj *var;
+c_number_of_children (struct varobj *var)
 {
   struct type *type;
   struct type *target;
 {
   struct type *type;
   struct type *target;
@@ -1727,16 +1794,13 @@ c_number_of_children (var)
 }
 
 static char *
 }
 
 static char *
-c_name_of_variable (parent)
-     struct varobj *parent;
+c_name_of_variable (struct varobj *parent)
 {
   return savestring (parent->name, strlen (parent->name));
 }
 
 static char *
 {
   return savestring (parent->name, strlen (parent->name));
 }
 
 static char *
-c_name_of_child (parent, index)
-     struct varobj *parent;
-     int index;
+c_name_of_child (struct varobj *parent, int index)
 {
   struct type *type;
   struct type *target;
 {
   struct type *type;
   struct type *target;
@@ -1790,38 +1854,50 @@ c_name_of_child (parent, index)
 }
 
 static value_ptr
 }
 
 static value_ptr
-c_value_of_root (var)
-     struct varobj *var;
+c_value_of_root (struct varobj **var_handle)
 {
   value_ptr new_val;
 {
   value_ptr new_val;
+  struct varobj *var = *var_handle;
   struct frame_info *fi;
   int within_scope;
 
   struct frame_info *fi;
   int within_scope;
 
+  /*  Only root variables can be updated... */
+  if (var->root->rootvar != var)
+    /* Not a root var */
+    return NULL;
+
+  
   /* Determine whether the variable is still around. */
   if (var->root->valid_block == NULL)
     within_scope = 1;
   else
     {
       reinit_frame_cache ();
   /* Determine whether the variable is still around. */
   if (var->root->valid_block == NULL)
     within_scope = 1;
   else
     {
       reinit_frame_cache ();
+      
+      
       fi = find_frame_addr_in_frame_chain (var->root->frame);
       fi = find_frame_addr_in_frame_chain (var->root->frame);
+      
       within_scope = fi != NULL;
       /* FIXME: select_frame could fail */
       if (within_scope)
        select_frame (fi, -1);
     }
       within_scope = fi != NULL;
       /* FIXME: select_frame could fail */
       if (within_scope)
        select_frame (fi, -1);
     }
-
+  
   if (within_scope)
     {
   if (within_scope)
     {
-      /* We need to catch errors here, because if evaluate expression fails
-         we just want to make val->error = 1 and go on */
+      /* We need to catch errors here, because if evaluate
+        expression fails we just want to make val->error = 1 and
+        go on */
       if (gdb_evaluate_expression (var->root->exp, &new_val))
        {
          if (VALUE_LAZY (new_val))
            {
       if (gdb_evaluate_expression (var->root->exp, &new_val))
        {
          if (VALUE_LAZY (new_val))
            {
-             /* We need to catch errors because if value_fetch_lazy fails we
-                still want to continue (after making val->error = 1) */
-             /* FIXME: Shouldn't be using VALUE_CONTENTS?  The comment on
-                value_fetch_lazy() says it is only called from the macro... */
+             /* We need to catch errors because if
+                value_fetch_lazy fails we still want to continue
+                (after making val->error = 1) */
+             /* FIXME: Shouldn't be using VALUE_CONTENTS?  The
+                comment on value_fetch_lazy() says it is only
+                called from the macro... */
              if (!gdb_value_fetch_lazy (new_val))
                var->error = 1;
              else
              if (!gdb_value_fetch_lazy (new_val))
                var->error = 1;
              else
@@ -1830,7 +1906,7 @@ c_value_of_root (var)
        }
       else
        var->error = 1;
        }
       else
        var->error = 1;
-
+      
       release_value (new_val);
       return new_val;
     }
       release_value (new_val);
       return new_val;
     }
@@ -1839,11 +1915,9 @@ c_value_of_root (var)
 }
 
 static value_ptr
 }
 
 static value_ptr
-c_value_of_child (parent, index)
-     struct varobj *parent;
-     int index;
+c_value_of_child (struct varobj *parent, int index)
 {
 {
-  value_ptr value, temp;
+  value_ptr value, temp, indval;
   struct type *type, *target;
   char *name;
 
   struct type *type, *target;
   char *name;
 
@@ -1858,9 +1932,15 @@ c_value_of_child (parent, index)
       switch (TYPE_CODE (type))
        {
        case TYPE_CODE_ARRAY:
       switch (TYPE_CODE (type))
        {
        case TYPE_CODE_ARRAY:
+#if 0
+          /* This breaks if the array lives in a (vector) register. */
          value = value_slice (temp, index, 1);
          temp = value_coerce_array (value);
          gdb_value_ind (temp, &value);
          value = value_slice (temp, index, 1);
          temp = value_coerce_array (value);
          gdb_value_ind (temp, &value);
+#else
+         indval = value_from_longest (builtin_type_int, (LONGEST) index);
+         gdb_value_subscript (temp, indval, &value);
+#endif
          break;
 
        case TYPE_CODE_STRUCT:
          break;
 
        case TYPE_CODE_STRUCT:
@@ -1894,9 +1974,7 @@ c_value_of_child (parent, index)
 }
 
 static struct type *
 }
 
 static struct type *
-c_type_of_child (parent, index)
-     struct varobj *parent;
-     int index;
+c_type_of_child (struct varobj *parent, int index)
 {
   struct type *type;
   char *name = name_of_child (parent, index);
 {
   struct type *type;
   char *name = name_of_child (parent, index);
@@ -1938,8 +2016,7 @@ c_type_of_child (parent, index)
 }
 
 static int
 }
 
 static int
-c_variable_editable (var)
-     struct varobj *var;
+c_variable_editable (struct varobj *var)
 {
   switch (TYPE_CODE (get_type (var)))
     {
 {
   switch (TYPE_CODE (get_type (var)))
     {
@@ -1959,8 +2036,7 @@ c_variable_editable (var)
 }
 
 static char *
 }
 
 static char *
-c_value_of_variable (var)
-     struct varobj *var;
+c_value_of_variable (struct varobj *var)
 {
   struct type *type;
   value_ptr val;
 {
   struct type *type;
   value_ptr val;
@@ -2016,8 +2092,7 @@ c_value_of_variable (var)
 /* C++ */
 
 static int
 /* C++ */
 
 static int
-cplus_number_of_children (var)
-     struct varobj *var;
+cplus_number_of_children (struct varobj *var)
 {
   struct type *type;
   int children, dont_know;
 {
   struct type *type;
   int children, dont_know;
@@ -2102,16 +2177,13 @@ cplus_class_num_children (type, children)
 }
 
 static char *
 }
 
 static char *
-cplus_name_of_variable (parent)
-     struct varobj *parent;
+cplus_name_of_variable (struct varobj *parent)
 {
   return c_name_of_variable (parent);
 }
 
 static char *
 {
   return c_name_of_variable (parent);
 }
 
 static char *
-cplus_name_of_child (parent, index)
-     struct varobj *parent;
-     int index;
+cplus_name_of_child (struct varobj *parent, int index)
 {
   char *name;
   struct type *type;
 {
   char *name;
   struct type *type;
@@ -2194,16 +2266,13 @@ cplus_name_of_child (parent, index)
 }
 
 static value_ptr
 }
 
 static value_ptr
-cplus_value_of_root (var)
-     struct varobj *var;
+cplus_value_of_root (struct varobj **var_handle)
 {
 {
-  return c_value_of_root (var);
+  return c_value_of_root (var_handle);
 }
 
 static value_ptr
 }
 
 static value_ptr
-cplus_value_of_child (parent, index)
-     struct varobj *parent;
-     int index;
+cplus_value_of_child (struct varobj *parent, int index)
 {
   struct type *type;
   value_ptr value;
 {
   struct type *type;
   value_ptr value;
@@ -2258,9 +2327,7 @@ cplus_value_of_child (parent, index)
 }
 
 static struct type *
 }
 
 static struct type *
-cplus_type_of_child (parent, index)
-     struct varobj *parent;
-     int index;
+cplus_type_of_child (struct varobj *parent, int index)
 {
   struct type *type, *t;
 
 {
   struct type *type, *t;
 
@@ -2293,8 +2360,7 @@ cplus_type_of_child (parent, index)
 }
 
 static int
 }
 
 static int
-cplus_variable_editable (var)
-     struct varobj *var;
+cplus_variable_editable (struct varobj *var)
 {
   if (CPLUS_FAKE_CHILD (var))
     return 0;
 {
   if (CPLUS_FAKE_CHILD (var))
     return 0;
@@ -2303,8 +2369,7 @@ cplus_variable_editable (var)
 }
 
 static char *
 }
 
 static char *
-cplus_value_of_variable (var)
-     struct varobj *var;
+cplus_value_of_variable (struct varobj *var)
 {
 
   /* If we have one of our special types, don't print out
 {
 
   /* If we have one of our special types, don't print out
@@ -2318,15 +2383,13 @@ cplus_value_of_variable (var)
 /* Java */
 
 static int
 /* Java */
 
 static int
-java_number_of_children (var)
-     struct varobj *var;
+java_number_of_children (struct varobj *var)
 {
   return cplus_number_of_children (var);
 }
 
 static char *
 {
   return cplus_number_of_children (var);
 }
 
 static char *
-java_name_of_variable (parent)
-     struct varobj *parent;
+java_name_of_variable (struct varobj *parent)
 {
   char *p, *name;
 
 {
   char *p, *name;
 
@@ -2346,9 +2409,7 @@ java_name_of_variable (parent)
 }
 
 static char *
 }
 
 static char *
-java_name_of_child (parent, index)
-     struct varobj *parent;
-     int index;
+java_name_of_child (struct varobj *parent, int index)
 {
   char *name, *p;
 
 {
   char *name, *p;
 
@@ -2367,38 +2428,31 @@ java_name_of_child (parent, index)
 }
 
 static value_ptr
 }
 
 static value_ptr
-java_value_of_root (var)
-     struct varobj *var;
+java_value_of_root (struct varobj **var_handle)
 {
 {
-  return cplus_value_of_root (var);
+  return cplus_value_of_root (var_handle);
 }
 
 static value_ptr
 }
 
 static value_ptr
-java_value_of_child (parent, index)
-     struct varobj *parent;
-     int index;
+java_value_of_child (struct varobj *parent, int index)
 {
   return cplus_value_of_child (parent, index);
 }
 
 static struct type *
 {
   return cplus_value_of_child (parent, index);
 }
 
 static struct type *
-java_type_of_child (parent, index)
-     struct varobj *parent;
-     int index;
+java_type_of_child (struct varobj *parent, int index)
 {
   return cplus_type_of_child (parent, index);
 }
 
 static int
 {
   return cplus_type_of_child (parent, index);
 }
 
 static int
-java_variable_editable (var)
-     struct varobj *var;
+java_variable_editable (struct varobj *var)
 {
   return cplus_variable_editable (var);
 }
 
 static char *
 {
   return cplus_variable_editable (var);
 }
 
 static char *
-java_value_of_variable (var)
-     struct varobj *var;
+java_value_of_variable (struct varobj *var)
 {
   return cplus_value_of_variable (var);
 }
 {
   return cplus_value_of_variable (var);
 }
This page took 0.042228 seconds and 4 git commands to generate.