Revert call to bfd_cache_close().
[deliverable/binutils-gdb.git] / gdb / varobj.c
index 5cc6e88d1679ecdf89999cb25b6f4d9ea5ad9c91..40bc209de3ef0eb14a664c44738d7e3d24f460d2 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;
 
@@ -781,12 +776,13 @@ varobj_set_value (struct varobj *var, char *expression)
       value_ptr temp;
 
       input_radix = 10;                /* ALWAYS reset to decimal temporarily */
-      /* FIXME: Callee may longjump */
-      exp = parse_exp_1 (&s, 0, 0);
+      if (!gdb_parse_exp_1 (&s, 0, 0, &exp))
+       /* We cannot proceed without a well-formed expression. */
+       return 0;
       if (!gdb_evaluate_expression (exp, &value))
        {
          /* We cannot proceed without a valid expression. */
-         FREEIF (exp);
+         xfree (exp);
          return 0;
        }
 
@@ -817,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);
@@ -881,7 +878,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;
@@ -916,21 +913,24 @@ varobj_update (struct varobj *var, struct varobj ***changelist)
   /* Initialize a stack for temporary results */
   vpush (&result, NULL);
 
-  if (type_changed || !my_value_equal (var->value, new, &error2))
+  /* If this is a "use_selected_frame" varobj, and its type has changed,
+     them note that it's changed. */
+  if (type_changed)
     {
-      /* Note that it's changed   There a couple of exceptions here,
-         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++;
+    }
+  /* 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))
+    {
+      vpush (&result, var);
+      changed++;
+      /* error2 replaces var->error since this new value
+         WILL replace the old one. */
+      var->error = error2;
     }
-  /* error2 replaces var->error since this new value
-     WILL replace the old one. */
-  var->error = error2;
 
   /* We must always keep around the new value for this root
      variable expression, or we lose the updated children! */
@@ -1059,7 +1059,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 */
@@ -1071,7 +1071,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;
     }
 
@@ -1176,7 +1176,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)
@@ -1211,9 +1211,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;
 
@@ -1349,12 +1347,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
@@ -1503,7 +1501,7 @@ vpop (struct vstack **pstack)
   s = *pstack;
   v = s->var;
   *pstack = (*pstack)->next;
-  free (s);
+  xfree (s);
 
   return v;
 }
@@ -1533,7 +1531,7 @@ cppop (struct cpstack **pstack)
   s = *pstack;
   v = s->name;
   *pstack = (*pstack)->next;
-  free (s);
+  xfree (s);
 
   return v;
 }
@@ -1722,6 +1720,7 @@ type_changeable (struct varobj *var)
     {
       case TYPE_CODE_STRUCT:
       case TYPE_CODE_UNION:
+      case TYPE_CODE_ARRAY:
        r = 0;
        break;
 
@@ -2150,9 +2149,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.025972 seconds and 4 git commands to generate.