PR ld/12549
[binutils-gdb.git] / gdb / varobj.c
index 308649972108ad8a954abf511d3b7737c8b66ba3..9255dc4dced09a85098f8f1ac6f293ce8f84820c 100644 (file)
@@ -1,6 +1,6 @@
 /* Implementation of the GDB variable objects API.
 
-   Copyright (C) 1999-2012 Free Software Foundation, Inc.
+   Copyright (C) 1999-2013 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
@@ -49,7 +49,7 @@ typedef int PyObject;
 
 /* Non-zero if we want to see trace of varobj level stuff.  */
 
-int varobjdebug = 0;
+unsigned int varobjdebug = 0;
 static void
 show_varobjdebug (struct ui_file *file, int from_tty,
                  struct cmd_list_element *c, const char *value)
@@ -84,7 +84,7 @@ struct varobj_root
   struct expression *exp;
 
   /* Block for which this expression is valid.  */
-  struct block *valid_block;
+  const struct block *valid_block;
 
   /* The frame for this expression.  This field is set iff valid_block is
      not NULL.  */
@@ -624,6 +624,7 @@ varobj_create (char *objname,
       enum varobj_languages lang;
       struct value *value = NULL;
       volatile struct gdb_exception except;
+      CORE_ADDR pc;
 
       /* Parse and evaluate the expression, filling in as much of the
          variable's data as possible.  */
@@ -650,9 +651,13 @@ varobj_create (char *objname,
       if (type == USE_SELECTED_FRAME)
        var->root->floating = 1;
 
+      pc = 0;
       block = NULL;
       if (fi != NULL)
-       block = get_frame_block (fi, 0);
+       {
+         block = get_frame_block (fi, 0);
+         pc = get_frame_pc (fi);
+       }
 
       p = expression;
       innermost_block = NULL;
@@ -660,7 +665,7 @@ varobj_create (char *objname,
          return a sensible error.  */
       TRY_CATCH (except, RETURN_MASK_ERROR)
        {
-         var->root->exp = parse_exp_1 (&p, block, 0);
+         var->root->exp = parse_exp_1 (&p, pc, block, 0);
        }
 
       if (except.reason < 0)
@@ -670,7 +675,9 @@ varobj_create (char *objname,
        }
 
       /* Don't allow variables to be created for types.  */
-      if (var->root->exp->elts[0].opcode == OP_TYPE)
+      if (var->root->exp->elts[0].opcode == OP_TYPE
+         || var->root->exp->elts[0].opcode == OP_TYPEOF
+         || var->root->exp->elts[0].opcode == OP_DECLTYPE)
        {
          do_cleanups (old_chain);
          fprintf_unfiltered (gdb_stderr, "Attempt to use a type name"
@@ -1107,9 +1114,6 @@ update_dynamic_varobj_children (struct varobj *var,
 
       make_cleanup_py_decref (children);
 
-      if (!PyIter_Check (children))
-       error (_("Returned value is not iterable"));
-
       Py_XDECREF (var->child_iter);
       var->child_iter = PyObject_GetIter (children);
       if (!var->child_iter)
@@ -1471,7 +1475,7 @@ varobj_set_value (struct varobj *var, char *expression)
   gdb_assert (varobj_editable_p (var));
 
   input_radix = 10;            /* ALWAYS reset to decimal temporarily.  */
-  exp = parse_exp_1 (&s, 0, 0);
+  exp = parse_exp_1 (&s, 0, 0, 0);
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
       value = evaluate_expression (exp);
@@ -1965,7 +1969,6 @@ varobj_value_has_mutated (struct varobj *var, struct value *new_value,
 VEC(varobj_update_result) *
 varobj_update (struct varobj **varp, int explicit)
 {
-  int changed = 0;
   int type_changed = 0;
   int i;
   struct value *new;
@@ -2906,12 +2909,10 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
                       string_print.  Otherwise just return the extracted
                       string as a value.  */
 
-                   PyObject *py_str
-                     = python_string_to_target_python_string (output);
+                   char *s = python_string_to_target_string (output);
 
-                   if (py_str)
+                   if (s)
                      {
-                       char *s = PyString_AsString (py_str);
                        char *hint;
 
                        hint = gdbpy_get_display_hint (value_formatter);
@@ -2922,10 +2923,10 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
                            xfree (hint);
                          }
 
-                       len = PyString_Size (py_str);
+                       len = strlen (s);
                        thevalue = xmemdup (s, len + 1, len + 1);
                        type = builtin_type (gdbarch)->builtin_char;
-                       Py_DECREF (py_str);
+                       xfree (s);
 
                        if (!string_print)
                          {
@@ -4169,28 +4170,27 @@ _initialize_varobj (void)
   varobj_table = xmalloc (sizeof_table);
   memset (varobj_table, 0, sizeof_table);
 
-  add_setshow_zinteger_cmd ("debugvarobj", class_maintenance,
-                           &varobjdebug,
-                           _("Set varobj debugging."),
-                           _("Show varobj debugging."),
-                           _("When non-zero, varobj debugging is enabled."),
-                           NULL, show_varobjdebug,
-                           &setlist, &showlist);
+  add_setshow_zuinteger_cmd ("debugvarobj", class_maintenance,
+                            &varobjdebug,
+                            _("Set varobj debugging."),
+                            _("Show varobj debugging."),
+                            _("When non-zero, varobj debugging is enabled."),
+                            NULL, show_varobjdebug,
+                            &setlist, &showlist);
 }
 
 /* Invalidate varobj VAR if it is tied to locals and re-create it if it is
-   defined on globals.  It is a helper for varobj_invalidate.  */
+   defined on globals.  It is a helper for varobj_invalidate.
+
+   This function is called after changing the symbol file, in this case the
+   pointers to "struct type" stored by the varobj are no longer valid.  All
+   varobj must be either re-evaluated, or marked as invalid here.  */
 
 static void
 varobj_invalidate_iter (struct varobj *var, void *unused)
 {
-  /* Floating varobjs are reparsed on each stop, so we don't care if the
-     presently parsed expression refers to something that's gone.  */
-  if (var->root->floating)
-    return;
-
-  /* global var must be re-evaluated.  */     
-  if (var->root->valid_block == NULL)
+  /* global and floating var must be re-evaluated.  */
+  if (var->root->floating || var->root->valid_block == NULL)
     {
       struct varobj *tmp_var;