NEWS: Mention new sim --map-info flag.
[deliverable/binutils-gdb.git] / gdb / varobj.c
index b4b2461017e0cf7178f9209d40c04648ca642dc7..e87d399cee204356fbc67e9c6a359bd860328c16 100644 (file)
@@ -512,6 +512,7 @@ find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
         comparing it against our argument.  */
       CORE_ADDR frame_base = get_frame_base_address (frame);
       int addr_bit = gdbarch_addr_bit (get_frame_arch (frame));
+
       if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
        frame_base &= ((CORE_ADDR) 1 << addr_bit) - 1;
 
@@ -527,9 +528,6 @@ varobj_create (char *objname,
               char *expression, CORE_ADDR frame, enum varobj_type type)
 {
   struct varobj *var;
-  struct frame_info *fi;
-  struct frame_info *old_fi = NULL;
-  struct block *block;
   struct cleanup *old_chain;
 
   /* Fill out a varobj structure for the (root) variable being constructed. */
@@ -538,6 +536,9 @@ varobj_create (char *objname,
 
   if (expression != NULL)
     {
+      struct frame_info *fi;
+      struct frame_id old_id = null_frame_id;
+      struct block *block;
       char *p;
       enum varobj_languages lang;
       struct value *value = NULL;
@@ -610,7 +611,7 @@ varobj_create (char *objname,
 
          var->root->frame = get_frame_id (fi);
          var->root->thread_id = pid_to_thread_id (inferior_ptid);
-         old_fi = get_selected_frame (NULL);
+         old_id = get_frame_id (get_selected_frame (NULL));
          select_frame (fi);     
        }
 
@@ -622,6 +623,7 @@ varobj_create (char *objname,
          /* Error getting the value.  Try to at least get the
             right type.  */
          struct value *type_only_value = evaluate_type (var->root->exp);
+
          var->type = value_type (type_only_value);
        }
       else 
@@ -637,8 +639,8 @@ varobj_create (char *objname,
       var->root->rootvar = var;
 
       /* Reset the selected frame */
-      if (old_fi != NULL)
-       select_frame (old_fi);
+      if (frame_id_p (old_id))
+       select_frame (frame_find_by_id (old_id));
     }
 
   /* If the variable object name is null, that means this
@@ -924,6 +926,7 @@ install_dynamic_child (struct varobj *var,
     {
       /* There's no child yet.  */
       struct varobj *child = varobj_add_child (var, name, value);
+
       if (new)
        {
          VEC_safe_push (varobj_p, *new, child);
@@ -933,6 +936,7 @@ install_dynamic_child (struct varobj *var,
   else 
     {
       varobj_p existing = VEC_index (varobj_p, var->children, index);
+
       if (install_new_value (existing, value, 0))
        {
          if (changed)
@@ -1048,6 +1052,8 @@ update_dynamic_varobj_children (struct varobj *var,
            error (_("Invalid item from the child list"));
 
          v = convert_value_from_python (py_v);
+         if (v == NULL)
+           gdbpy_print_stack ();
          install_dynamic_child (var, can_mention ? changed : NULL,
                                 can_mention ? new : NULL,
                                 can_mention ? unchanged : NULL,
@@ -1068,6 +1074,7 @@ update_dynamic_varobj_children (struct varobj *var,
   if (i < VEC_length (varobj_p, var->children))
     {
       int j;
+
       *cchanged = 1;
       for (j = i; j < VEC_length (varobj_p, var->children); ++j)
        varobj_delete (VEC_index (varobj_p, var->children, j), NULL, 0);
@@ -1116,7 +1123,6 @@ varobj_get_num_children (struct varobj *var)
 VEC (varobj_p)*
 varobj_list_children (struct varobj *var, int *from, int *to)
 {
-  struct varobj *child;
   char *name;
   int i, children_changed;
 
@@ -1172,6 +1178,7 @@ varobj_add_child (struct varobj *var, const char *name, struct value *value)
   varobj_p v = create_child_with_value (var, 
                                        VEC_length (varobj_p, var->children), 
                                        name, value);
+
   VEC_safe_push (varobj_p, var->children, v);
   return v;
 }
@@ -1263,8 +1270,6 @@ int
 varobj_set_value (struct varobj *var, char *expression)
 {
   struct value *val;
-  int offset = 0;
-  int error = 0;
 
   /* The argument "expression" contains the variable's new value.
      We need to first construct a legal expression for this -- ugh! */
@@ -1273,7 +1278,6 @@ varobj_set_value (struct varobj *var, char *expression)
   struct value *value;
   int saved_input_radix = input_radix;
   char *s = expression;
-  int i;
 
   gdb_assert (varobj_editable_p (var));
 
@@ -1413,7 +1417,6 @@ install_new_value_visualizer (struct varobj *var)
   if (var->constructor != Py_None && var->value)
     {
       struct cleanup *cleanup;
-      PyObject *pretty_printer = NULL;
 
       cleanup = varobj_ensure_python_env (var);
 
@@ -1491,6 +1494,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
     {
       struct varobj *parent = var->parent;
       int frozen = var->frozen;
+
       for (; !frozen && parent; parent = parent->parent)
        frozen |= parent->frozen;
 
@@ -1593,7 +1597,10 @@ install_new_value (struct varobj *var, struct value *value, int initial)
     {
       xfree (print_value);
       print_value = value_get_print_value (var->value, var->format, var);
-      if (!var->print_value || strcmp (var->print_value, print_value) != 0)
+      if ((var->print_value == NULL && print_value != NULL)
+         || (var->print_value != NULL && print_value == NULL)
+         || (var->print_value != NULL && print_value != NULL
+             && strcmp (var->print_value, print_value) != 0))
        changed = 1;
     }
   if (var->print_value)
@@ -1630,8 +1637,8 @@ void
 varobj_set_visualizer (struct varobj *var, const char *visualizer)
 {
 #if HAVE_PYTHON
-  PyObject *mainmod, *globals, *pretty_printer, *constructor;
-  struct cleanup *back_to, *value;
+  PyObject *mainmod, *globals, *constructor;
+  struct cleanup *back_to;
 
   back_to = varobj_ensure_python_env (var);
 
@@ -1681,14 +1688,9 @@ VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
   int changed = 0;
   int type_changed = 0;
   int i;
-  int vleft;
-  struct varobj *v;
-  struct varobj **cv;
-  struct varobj **templist = NULL;
   struct value *new;
   VEC (varobj_update_result) *stack = NULL;
   VEC (varobj_update_result) *result = NULL;
-  struct frame_info *fi;
 
   /* Frozen means frozen -- we don't check for any change in
      this varobj, including its going out of scope, or
@@ -1701,6 +1703,7 @@ VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
   if (!(*varp)->root->is_valid)
     {
       varobj_update_result r = {0};
+
       r.varobj = *varp;
       r.status = VAROBJ_INVALID;
       VEC_safe_push (varobj_update_result, result, &r);
@@ -1710,6 +1713,7 @@ VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
   if ((*varp)->root->rootvar == *varp)
     {
       varobj_update_result r = {0};
+
       r.varobj = *varp;
       r.status = VAROBJ_IN_SCOPE;
 
@@ -1741,6 +1745,7 @@ VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
   else
     {
       varobj_update_result r = {0};
+
       r.varobj = *varp;
       VEC_safe_push (varobj_update_result, stack, &r);
     }
@@ -1819,6 +1824,7 @@ VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
                {
                  varobj_p tmp = VEC_index (varobj_p, changed, i);
                  varobj_update_result r = {0};
+
                  r.varobj = tmp;
                  r.changed = 1;
                  r.value_installed = 1;
@@ -1827,9 +1833,11 @@ VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
              for (i = VEC_length (varobj_p, unchanged) - 1; i >= 0; --i)
                {
                  varobj_p tmp = VEC_index (varobj_p, unchanged, i);
+
                  if (!tmp->frozen)
                    {
                      varobj_update_result r = {0};
+
                      r.varobj = tmp;
                      r.value_installed = 1;
                      VEC_safe_push (varobj_update_result, stack, &r);
@@ -1854,10 +1862,12 @@ VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit)
       for (i = VEC_length (varobj_p, v->children)-1; i >= 0; --i)
        {
          varobj_p c = VEC_index (varobj_p, v->children, i);
+
          /* Child may be NULL if explicitly deleted by -var-delete.  */
          if (c != NULL && !c->frozen)
            {
              varobj_update_result r = {0};
+
              r.varobj = c;
              VEC_safe_push (varobj_update_result, stack, &r);
            }
@@ -1906,6 +1916,7 @@ delete_variable_1 (struct cpstack **resultp, int *delcountp,
   for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
     {   
       varobj_p child = VEC_index (varobj_p, var->children, i);
+
       if (!child)
        continue;
       if (!remove_from_parent_p)
@@ -2146,6 +2157,7 @@ static struct varobj *
 new_root_variable (void)
 {
   struct varobj *var = new_variable ();
+
   var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));;
   var->root->lang = NULL;
   var->root->exp = NULL;
@@ -2211,8 +2223,8 @@ static struct type *
 get_type (struct varobj *var)
 {
   struct type *type;
-  type = var->type;
 
+  type = var->type;
   if (type != NULL)
     type = check_typedef (type);
 
@@ -2407,6 +2419,7 @@ value_of_root (struct varobj **var_handle, int *type_changed)
             correct in other frames, so update the expression.  */
 
          struct expression *tmp_exp = var->root->exp;
+
          var->root->exp = tmp_var->root->exp;
          tmp_var->root->exp = tmp_exp;
 
@@ -2473,28 +2486,37 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
   long len = 0;
   char *encoding = NULL;
   struct gdbarch *gdbarch = NULL;
+  /* Initialize it just to avoid a GCC false warning.  */
+  CORE_ADDR str_addr = 0;
+  int string_print = 0;
 
   if (value == NULL)
     return NULL;
 
+  stb = mem_fileopen ();
+  old_chain = make_cleanup_ui_file_delete (stb);
+
   gdbarch = get_type_arch (value_type (value));
 #if HAVE_PYTHON
   {
-    struct cleanup *back_to = varobj_ensure_python_env (var);
     PyObject *value_formatter = var->pretty_printer;
 
+    varobj_ensure_python_env (var);
+
     if (value_formatter)
       {
        /* First check to see if we have any children at all.  If so,
           we simply return {...}.  */
        if (dynamic_varobj_has_child_method (var))
-         return xstrdup ("{...}");
+         {
+           do_cleanups (old_chain);
+           return xstrdup ("{...}");
+         }
 
        if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
          {
            char *hint;
            struct value *replacement;
-           int string_print = 0;
            PyObject *output = NULL;
 
            hint = gdbpy_get_display_hint (value_formatter);
@@ -2506,56 +2528,59 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
              }
 
            output = apply_varobj_pretty_printer (value_formatter,
-                                                 &replacement);
+                                                 &replacement,
+                                                 stb);
            if (output)
              {
+               make_cleanup_py_decref (output);
+
                if (gdbpy_is_lazy_string (output))
                  {
-                   thevalue = gdbpy_extract_lazy_string (output, &type,
-                                                         &len, &encoding);
+                   gdbpy_extract_lazy_string (output, &str_addr, &type,
+                                              &len, &encoding);
+                   make_cleanup (free_current_contents, &encoding);
                    string_print = 1;
                  }
                else
                  {
                    PyObject *py_str
                      = python_string_to_target_python_string (output);
+
                    if (py_str)
                      {
                        char *s = PyString_AsString (py_str);
+
                        len = PyString_Size (py_str);
                        thevalue = xmemdup (s, len + 1, len + 1);
                        type = builtin_type (gdbarch)->builtin_char;
                        Py_DECREF (py_str);
+
+                       if (!string_print)
+                         {
+                           do_cleanups (old_chain);
+                           return thevalue;
+                         }
+
+                       make_cleanup (xfree, thevalue);
                      }
+                   else
+                     gdbpy_print_stack ();
                  }
-               Py_DECREF (output);
-             }
-           if (thevalue && !string_print)
-             {
-               do_cleanups (back_to);
-               xfree (encoding);
-               return thevalue;
              }
            if (replacement)
              value = replacement;
          }
       }
-    do_cleanups (back_to);
   }
 #endif
 
-  stb = mem_fileopen ();
-  old_chain = make_cleanup_ui_file_delete (stb);
-
   get_formatted_print_options (&opts, format_code[(int) format]);
   opts.deref_ref = 0;
   opts.raw = 1;
   if (thevalue)
-    {
-      make_cleanup (xfree, thevalue);
-      make_cleanup (xfree, encoding);
-      LA_PRINT_STRING (stb, type, thevalue, len, encoding, 0, &opts);
-    }
+    LA_PRINT_STRING (stb, type, thevalue, len, encoding, 0, &opts);
+  else if (string_print)
+    val_print_string (type, encoding, str_addr, len, stb, &opts);
   else
     common_val_print (value, stb, 0, &opts, current_language);
   thevalue = ui_file_xstrdup (stb, NULL);
@@ -2568,7 +2593,6 @@ int
 varobj_editable_p (struct varobj *var)
 {
   struct type *type;
-  struct value *value;
 
   if (!(var->root->is_valid && var->value && VALUE_LVAL (var->value)))
     return 0;
@@ -2679,7 +2703,8 @@ adjust_value_for_child_access (struct value **value,
        {
          if (value && *value)
            {
-             int success = gdb_value_ind (*value, value);        
+             int success = gdb_value_ind (*value, value);
+
              if (!success)
                *value = NULL;
            }
@@ -2762,8 +2787,8 @@ value_struct_element_index (struct value *value, int type_index)
 {
   struct value *result = NULL;
   volatile struct gdb_exception e;
-
   struct type *type = value_type (value);
+
   type = check_typedef (type);
 
   gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
@@ -2830,6 +2855,7 @@ c_describe_child (struct varobj *parent, int index,
       if (cvalue && value)
        {
          int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
+
          gdb_value_subscript (value, real_index, cvalue);
        }
 
@@ -2863,6 +2889,7 @@ c_describe_child (struct varobj *parent, int index,
       if (cfull_expression)
        {
          char *join = was_ptr ? "->" : ".";
+
          *cfull_expression = xstrprintf ("(%s)%s%s", parent_expression, join,
                                          TYPE_FIELD_NAME (type, index));
        }
@@ -2876,6 +2903,7 @@ c_describe_child (struct varobj *parent, int index,
       if (cvalue && value)
        {
          int success = gdb_value_ind (value, cvalue);
+
          if (!success)
            *cvalue = NULL;
        }
@@ -2905,6 +2933,7 @@ static char *
 c_name_of_child (struct varobj *parent, int index)
 {
   char *name;
+
   c_describe_child (parent, index, &name, NULL, NULL, NULL);
   return name;
 }
@@ -2931,6 +2960,7 @@ check_scope (struct varobj *var)
   if (fi)
     {
       CORE_ADDR pc = get_frame_pc (fi);
+
       if (pc <  BLOCK_START (var->root->valid_block) ||
          pc >= BLOCK_END (var->root->valid_block))
        scope = 0;
@@ -2945,7 +2975,6 @@ c_value_of_root (struct varobj **var_handle)
 {
   struct value *new_val = NULL;
   struct varobj *var = *var_handle;
-  struct frame_info *fi;
   int within_scope = 0;
   struct cleanup *back_to;
                                                                 
@@ -2994,8 +3023,8 @@ static struct value *
 c_value_of_child (struct varobj *parent, int index)
 {
   struct value *value = NULL;
-  c_describe_child (parent, index, NULL, &value, NULL, NULL);
 
+  c_describe_child (parent, index, NULL, &value, NULL, NULL);
   return value;
 }
 
@@ -3003,6 +3032,7 @@ static struct type *
 c_type_of_child (struct varobj *parent, int index)
 {
   struct type *type = NULL;
+
   c_describe_child (parent, index, NULL, NULL, &type, NULL);
   return type;
 }
@@ -3034,6 +3064,7 @@ c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
     case TYPE_CODE_ARRAY:
       {
        char *number;
+
        number = xstrprintf ("[%d]", var->num_children);
        return (number);
       }
@@ -3191,7 +3222,6 @@ cplus_describe_child (struct varobj *parent, int index,
                      char **cname, struct value **cvalue, struct type **ctype,
                      char **cfull_expression)
 {
-  char *name = NULL;
   struct value *value;
   struct type *type;
   int was_ptr;
@@ -3227,6 +3257,7 @@ cplus_describe_child (struct varobj *parent, int index,
       || TYPE_CODE (type) == TYPE_CODE_UNION)
     {
       char *join = was_ptr ? "->" : ".";
+
       if (CPLUS_FAKE_CHILD (parent))
        {
          /* The fields of the class type are ordered as they
@@ -3288,6 +3319,7 @@ cplus_describe_child (struct varobj *parent, int index,
          if (cfull_expression)
            {
              char *ptr = was_ptr ? "*" : "";
+
              /* Cast the parent to the base' type. Note that in gdb,
                 expression like 
                         (Base1)d
@@ -3306,6 +3338,7 @@ cplus_describe_child (struct varobj *parent, int index,
        {
          char *access = NULL;
          int children[3];
+
          cplus_class_num_children (type, children);
 
          /* Everything beyond the baseclasses can
@@ -3361,6 +3394,7 @@ static char *
 cplus_name_of_child (struct varobj *parent, int index)
 {
   char *name = NULL;
+
   cplus_describe_child (parent, index, &name, NULL, NULL, NULL);
   return name;
 }
@@ -3383,6 +3417,7 @@ static struct value *
 cplus_value_of_child (struct varobj *parent, int index)
 {
   struct value *value = NULL;
+
   cplus_describe_child (parent, index, NULL, &value, NULL, NULL);
   return value;
 }
@@ -3391,12 +3426,14 @@ static struct type *
 cplus_type_of_child (struct varobj *parent, int index)
 {
   struct type *type = NULL;
+
   cplus_describe_child (parent, index, NULL, NULL, &type, NULL);
   return type;
 }
 
 static char *
-cplus_value_of_variable (struct varobj *var, enum varobj_display_formats format)
+cplus_value_of_variable (struct varobj *var, 
+                        enum varobj_display_formats format)
 {
 
   /* If we have one of our special types, don't print out
This page took 0.030104 seconds and 4 git commands to generate.