]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/varobj.c
2.41 Release sources
[thirdparty/binutils-gdb.git] / gdb / varobj.c
index 1d545382f5e68b99aa3aa51ab3b8a606c2e5e129..81b8e61f30466a7e565c13a16bbb52dbe391a118 100644 (file)
@@ -364,18 +364,18 @@ varobj_create (const char *objname,
          select_frame (fi);     
        }
 
-      /* We definitely need to catch errors here.
-        If evaluate_expression succeeds we got the value we wanted.
-        But if it fails, we still go on with a call to evaluate_type().  */
+      /* We definitely need to catch errors here.  If evaluation of
+        the expression succeeds, we got the value we wanted.  But if
+        it fails, we still go on with a call to evaluate_type().  */
       try
        {
-         value = evaluate_expression (var->root->exp.get ());
+         value = var->root->exp->evaluate ();
        }
       catch (const gdb_exception_error &except)
        {
          /* Error getting the value.  Try to at least get the
             right type.  */
-         struct value *type_only_value = evaluate_type (var->root->exp.get ());
+         struct value *type_only_value = var->root->exp->evaluate_type ();
 
          var->type = type_only_value->type ();
        }
@@ -652,21 +652,6 @@ install_dynamic_child (struct varobj *var,
     }
 }
 
-#if HAVE_PYTHON
-
-static bool
-dynamic_varobj_has_child_method (const struct varobj *var)
-{
-  PyObject *printer = var->dynamic->pretty_printer;
-
-  if (!gdb_python_initialized)
-    return false;
-
-  gdbpy_enter_varobj enter_py (var);
-  return PyObject_HasAttr (printer, gdbpy_children_cst);
-}
-#endif
-
 /* A factory for creating dynamic varobj's iterators.  Returns an
    iterator object suitable for iterating over VAR's children.  */
 
@@ -985,16 +970,16 @@ varobj_set_value (struct varobj *var, const char *expression)
      We need to first construct a legal expression for this -- ugh!  */
   /* Does this cover all the bases?  */
   struct value *value = NULL; /* Initialize to keep gcc happy.  */
-  int saved_input_radix = input_radix;
   const char *s = expression;
 
   gdb_assert (varobj_editable_p (var));
 
-  input_radix = 10;            /* ALWAYS reset to decimal temporarily.  */
+  /* ALWAYS reset to decimal temporarily.  */
+  auto save_input_radix = make_scoped_restore (&input_radix, 10);
   expression_up exp = parse_exp_1 (&s, 0, 0, 0);
   try
     {
-      value = evaluate_expression (exp.get ());
+      value = exp->evaluate ();
     }
 
   catch (const gdb_exception_error &except)
@@ -1037,7 +1022,6 @@ varobj_set_value (struct varobj *var, const char *expression)
      'updated' flag.  There's no need to optimize that, because return value
      of -var-update should be considered an approximation.  */
   var->updated = install_new_value (var, val, false /* Compare values.  */);
-  input_radix = saved_input_radix;
   return true;
 }
 
@@ -2011,7 +1995,7 @@ value_of_root_1 (struct varobj **var_handle)
         expression fails we want to just return NULL.  */
       try
        {
-         new_val = evaluate_expression (var->root->exp.get ());
+         new_val = var->root->exp->evaluate ();
        }
       catch (const gdb_exception_error &except)
        {
@@ -2178,11 +2162,6 @@ varobj_value_get_print_value (struct value *value,
 
       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 "{...}";
-
          if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
            {
              struct value *replacement;
@@ -2193,7 +2172,7 @@ varobj_value_get_print_value (struct value *value,
                                                                &opts);
 
              /* If we have string like output ...  */
-             if (output != NULL)
+             if (output != nullptr && output != Py_None)
                {
                  /* If this is a lazy string, extract it.  For lazy
                     strings we always print as a string, so set
@@ -2245,6 +2224,13 @@ varobj_value_get_print_value (struct value *value,
              if (replacement)
                value = replacement;
            }
+         else
+           {
+             /* No to_string method, so if there is a 'children'
+                method, return the default.  */
+             if (PyObject_HasAttr (value_formatter, gdbpy_children_cst))
+               return "{...}";
+           }
        }
     }
 #endif
@@ -2405,7 +2391,7 @@ varobj_invalidate_if_uses_objfile (struct objfile *objfile)
            {
              /* The varobj is tied to a block which is going away.  There is
                 no way to reconstruct something later, so invalidate the
-                varobj completly and drop the reference to the block which is
+                varobj completely and drop the reference to the block which is
                 being freed.  */
              var->root->is_valid = false;
              var->root->valid_block = nullptr;
@@ -2428,7 +2414,7 @@ varobj_invalidate_if_uses_objfile (struct objfile *objfile)
 
       /* var->value->type and var->type might also reference the objfile.
         This is taken care of in value.c:preserve_values which deals with
-        making sure that objfile-owend types are replaced with
+        making sure that objfile-owned types are replaced with
         gdbarch-owned equivalents.  */
     });
 }