* gdbint.texinfo (Host Definition): Remove description of
[deliverable/binutils-gdb.git] / gdb / varobj.c
index fe3f940ae2a583393b3d3daed2fa55e15586bcaa..c3a159bcbfc9eb1d761b0fdb5a443aae41be68b7 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the GDB variable objects API.
-   Copyright 1999, 2000 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2001 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
@@ -20,7 +20,6 @@
 #include "value.h"
 #include "expression.h"
 #include "frame.h"
-#include "valprint.h"
 #include "language.h"
 #include "wrapper.h"
 #include "gdbcmd.h"
@@ -391,11 +390,6 @@ static int rootcount = 0;  /* number of root varobjs in the list */
 /* Pointer to the varobj hash table (built at run time) */
 static struct vlist **varobj_table;
 
-#if defined(FREEIF)
-#undef FREEIF
-#endif
-#define FREEIF(x) if (x != NULL) free((char *) (x))
-
 /* Is the variable X one of our "fake" children? */
 #define CPLUS_FAKE_CHILD(x) \
 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
@@ -411,7 +405,8 @@ varobj_create (char *objname,
               enum varobj_type type)
 {
   struct varobj *var;
-  struct frame_info *fi, *old_fi;
+  struct frame_info *fi;
+  struct frame_info *old_fi = NULL;
   struct block *block;
   struct cleanup *old_chain;
 
@@ -787,7 +782,7 @@ varobj_set_value (struct varobj *var, char *expression)
       if (!gdb_evaluate_expression (exp, &value))
        {
          /* We cannot proceed without a valid expression. */
-         FREEIF (exp);
+         xfree (exp);
          return 0;
        }
 
@@ -818,7 +813,8 @@ varobj_set_value (struct varobj *var, char *expression)
        }
 
       VALUE_ADDRESS (temp) += offset;
-      val = value_assign (temp, value);
+      if (!gdb_value_assign (temp, value, &val))
+       return 0;
       VALUE_ADDRESS (val) -= offset;
       value_free (var->value);
       release_value (val);
@@ -870,10 +866,14 @@ varobj_list (struct varobj ***varlist)
     -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... 
+
+   NOTE: This function may delete the caller's varobj. If it
+   returns -2, then it has done this and VARP will be modified
+   to point to the new varobj. */
 
 int
-varobj_update (struct varobj *var, struct varobj ***changelist)
+varobj_update (struct varobj **varp, struct varobj ***changelist)
 {
   int changed = 0;
   int type_changed;
@@ -882,7 +882,7 @@ varobj_update (struct varobj *var, struct varobj ***changelist)
   int error2;
   struct varobj *v;
   struct varobj **cv;
-  struct varobj **templist;
+  struct varobj **templist = NULL;
   value_ptr new;
   struct vstack *stack = NULL;
   struct vstack *result = NULL;
@@ -893,7 +893,7 @@ varobj_update (struct varobj *var, struct varobj ***changelist)
     return -1;
 
   /*  Only root variables can be updated... */
-  if (var->root->rootvar != var)
+  if ((*varp)->root->rootvar != *varp)
     /* Not a root var */
     return -1;
 
@@ -907,10 +907,10 @@ varobj_update (struct varobj *var, struct varobj ***changelist)
      value_of_root variable dispose of the varobj if the type
      has changed. */
   type_changed = 1;
-  new = value_of_root (&var, &type_changed);
+  new = value_of_root (varp, &type_changed);
   if (new == NULL)
     {
-      var->error = 1;
+      (*varp)->error = 1;
       return -1;
     }
 
@@ -921,34 +921,34 @@ varobj_update (struct varobj *var, struct varobj ***changelist)
      them note that it's changed. */
   if (type_changed)
     {
-      vpush (&result, var);
+      vpush (&result, *varp);
       changed++;
     }
   /* If values are not equal, note that it's changed.
      There a couple of exceptions here, though.
      We don't want some types to be reported as "changed". */
-  else if (type_changeable (var) && !my_value_equal (var->value, new, &error2))
+  else if (type_changeable (*varp) && !my_value_equal ((*varp)->value, new, &error2))
     {
-      vpush (&result, var);
+      vpush (&result, *varp);
       changed++;
       /* error2 replaces var->error since this new value
          WILL replace the old one. */
-      var->error = error2;
+      (*varp)->error = error2;
     }
 
   /* We must always keep around the new value for this root
      variable expression, or we lose the updated children! */
-  value_free (var->value);
-  var->value = new;
+  value_free ((*varp)->value);
+  (*varp)->value = new;
 
   /* Initialize a stack */
   vpush (&stack, NULL);
 
   /* Push the root's children */
-  if (var->children != NULL)
+  if ((*varp)->children != NULL)
     {
       struct varobj_child *c;
-      for (c = var->children; c != NULL; c = c->next)
+      for (c = (*varp)->children; c != NULL; c = c->next)
        vpush (&stack, c->child);
     }
 
@@ -1063,7 +1063,7 @@ delete_variable_1 (struct cpstack **resultp, int *delcountp, struct varobj *var,
        vc->child->parent = NULL;
       delete_variable_1 (resultp, delcountp, vc->child, 0, only_children_p);
       next = vc->next;
-      free (vc);
+      xfree (vc);
     }
 
   /* if we were called to delete only the children we are done here */
@@ -1075,7 +1075,7 @@ delete_variable_1 (struct cpstack **resultp, int *delcountp, struct varobj *var,
      yet been installed, don't report it, it belongs to the caller... */
   if (var->obj_name != NULL)
     {
-      cppush (resultp, strdup (var->obj_name));
+      cppush (resultp, xstrdup (var->obj_name));
       *delcountp = *delcountp + 1;
     }
 
@@ -1180,7 +1180,7 @@ uninstall_variable (struct varobj *var)
   else
     prev->next = cv->next;
 
-  free (cv);
+  xfree (cv);
 
   /* If root, remove varobj from root list */
   if (var->root->rootvar == var)
@@ -1215,9 +1215,7 @@ uninstall_variable (struct varobj *var)
 /* Does a child with the name NAME exist in VAR? If so, return its data.
    If not, return NULL. */
 static struct varobj *
-child_exists (var, name)
-     struct varobj *var;       /* Parent */
-     char *name;               /* name of child */
+child_exists (struct varobj *var, char *name)
 {
   struct varobj_child *vc;
 
@@ -1353,12 +1351,12 @@ free_variable (struct varobj *var)
   if (var->root->rootvar == var)
     {
       free_current_contents ((char **) &var->root->exp);
-      FREEIF (var->root);
+      xfree (var->root);
     }
 
-  FREEIF (var->name);
-  FREEIF (var->obj_name);
-  FREEIF (var);
+  xfree (var->name);
+  xfree (var->obj_name);
+  xfree (var);
 }
 
 static void
@@ -1507,7 +1505,7 @@ vpop (struct vstack **pstack)
   s = *pstack;
   v = s->var;
   *pstack = (*pstack)->next;
-  free (s);
+  xfree (s);
 
   return v;
 }
@@ -1537,7 +1535,7 @@ cppop (struct cpstack **pstack)
   s = *pstack;
   v = s->name;
   *pstack = (*pstack)->next;
-  free (s);
+  xfree (s);
 
   return v;
 }
@@ -1645,7 +1643,7 @@ value_of_root (struct varobj **var_handle, int *type_changed)
            {
              tmp_var->obj_name = 
                savestring (var->obj_name, strlen (var->obj_name));
-             uninstall_variable (var);
+             varobj_delete (var, NULL, 0);
            }
          else
            {
@@ -1653,6 +1651,7 @@ value_of_root (struct varobj **var_handle, int *type_changed)
            }
          install_variable (tmp_var);
          *var_handle = tmp_var;
+         var = *var_handle;
          *type_changed = 1;
        }
     }
@@ -1767,7 +1766,13 @@ c_number_of_children (struct varobj *var)
     case TYPE_CODE_PTR:
       /* This is where things get compilcated. All pointers have one child.
          Except, of course, for struct and union ptr, which we automagically
-         dereference for the user and function ptrs, which have no children. */
+         dereference for the user and function ptrs, which have no children.
+         We also don't dereference void* as we don't know what to show.
+         We can show char* so we allow it to be dereferenced.  If you decide
+         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" */
+
       switch (TYPE_CODE (target))
        {
        case TYPE_CODE_STRUCT:
@@ -1776,17 +1781,12 @@ c_number_of_children (struct varobj *var)
          break;
 
        case TYPE_CODE_FUNC:
+       case TYPE_CODE_VOID:
          children = 0;
          break;
 
        default:
-         /* Don't dereference char* or void*. */
-         if (TYPE_NAME (target) != NULL
-             && (STREQ (TYPE_NAME (target), "char")
-                 || STREQ (TYPE_NAME (target), "void")))
-           children = 0;
-         else
-           children = 1;
+         children = 1;
        }
       break;
 
@@ -2155,9 +2155,7 @@ cplus_number_of_children (struct varobj *var)
    That means we need to descend into all baseclasses and find out
    how many are there, too. */
 static void
-cplus_class_num_children (type, children)
-     struct type *type;
-     int children[3];
+cplus_class_num_children (struct type *type, int children[3])
 {
   int i;
 
This page took 0.03126 seconds and 4 git commands to generate.