This changes varobj to use value_ref_ptr, allowing the removal of some
manual reference count management.
gdb/ChangeLog
2018-04-06 Tom Tromey <tom@tromey.com>
* varobj.h (struct varobj) <value>: Now a value_ref_ptr.
* varobj.c (varobj_set_display_format, varobj_set_value)
(install_default_visualizer, construct_visualizer)
(install_new_value, ~varobj, varobj_get_value_type)
(my_value_of_variable, varobj_editable_p): Update.
* c-varobj.c (c_describe_child, c_value_of_variable)
(cplus_number_of_children, cplus_describe_child): Update.
* ada-varobj.c (ada_number_of_children, ada_name_of_child)
(ada_path_expr_of_child, ada_value_of_child, ada_type_of_child)
(ada_value_of_variable, ada_value_is_changeable_p): Update.
+2018-04-06 Tom Tromey <tom@tromey.com>
+
+ * varobj.h (struct varobj) <value>: Now a value_ref_ptr.
+ * varobj.c (varobj_set_display_format, varobj_set_value)
+ (install_default_visualizer, construct_visualizer)
+ (install_new_value, ~varobj, varobj_get_value_type)
+ (my_value_of_variable, varobj_editable_p): Update.
+ * c-varobj.c (c_describe_child, c_value_of_variable)
+ (cplus_number_of_children, cplus_describe_child): Update.
+ * ada-varobj.c (ada_number_of_children, ada_name_of_child)
+ (ada_path_expr_of_child, ada_value_of_child, ada_type_of_child)
+ (ada_value_of_variable, ada_value_is_changeable_p): Update.
+
2018-04-06 Tom Tromey <tom@tromey.com>
* printcmd.c (last_examine_address): Change type to
2018-04-06 Tom Tromey <tom@tromey.com>
* printcmd.c (last_examine_address): Change type to
static int
ada_number_of_children (const struct varobj *var)
{
static int
ada_number_of_children (const struct varobj *var)
{
- return ada_varobj_get_number_of_children (var->value, var->type);
+ return ada_varobj_get_number_of_children (var->value.get (), var->type);
static std::string
ada_name_of_child (const struct varobj *parent, int index)
{
static std::string
ada_name_of_child (const struct varobj *parent, int index)
{
- return ada_varobj_get_name_of_child (parent->value, parent->type,
+ return ada_varobj_get_name_of_child (parent->value.get (), parent->type,
parent->name.c_str (), index);
}
parent->name.c_str (), index);
}
const struct varobj *parent = child->parent;
const char *parent_path_expr = varobj_get_path_expr (parent);
const struct varobj *parent = child->parent;
const char *parent_path_expr = varobj_get_path_expr (parent);
- return ada_varobj_get_path_expr_of_child (parent->value,
+ return ada_varobj_get_path_expr_of_child (parent->value.get (),
parent->type,
parent->name.c_str (),
parent_path_expr,
parent->type,
parent->name.c_str (),
parent_path_expr,
static struct value *
ada_value_of_child (const struct varobj *parent, int index)
{
static struct value *
ada_value_of_child (const struct varobj *parent, int index)
{
- return ada_varobj_get_value_of_child (parent->value, parent->type,
+ return ada_varobj_get_value_of_child (parent->value.get (), parent->type,
parent->name.c_str (), index);
}
static struct type *
ada_type_of_child (const struct varobj *parent, int index)
{
parent->name.c_str (), index);
}
static struct type *
ada_type_of_child (const struct varobj *parent, int index)
{
- return ada_varobj_get_type_of_child (parent->value, parent->type,
+ return ada_varobj_get_type_of_child (parent->value.get (), parent->type,
varobj_formatted_print_options (&opts, format);
varobj_formatted_print_options (&opts, format);
- return ada_varobj_get_value_of_variable (var->value, var->type, &opts);
+ return ada_varobj_get_value_of_variable (var->value.get (), var->type,
+ &opts);
}
/* Implement the "value_is_changeable_p" routine for Ada. */
}
/* Implement the "value_is_changeable_p" routine for Ada. */
static bool
ada_value_is_changeable_p (const struct varobj *var)
{
static bool
ada_value_is_changeable_p (const struct varobj *var)
{
- struct type *type = var->value ? value_type (var->value) : var->type;
+ struct type *type = (var->value != nullptr
+ ? value_type (var->value.get ()) : var->type);
if (ada_is_array_descriptor_type (type)
&& TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
if (ada_is_array_descriptor_type (type)
&& TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
std::string *cname, struct value **cvalue,
struct type **ctype, std::string *cfull_expression)
{
std::string *cname, struct value **cvalue,
struct type **ctype, std::string *cfull_expression)
{
- struct value *value = parent->value;
+ struct value *value = parent->value.get ();
struct type *type = varobj_get_value_type (parent);
std::string parent_expression;
int was_ptr;
struct type *type = varobj_get_value_type (parent);
std::string parent_expression;
int was_ptr;
- if (var->not_fetched && value_lazy (var->value))
+ if (var->not_fetched && value_lazy (var->value.get ()))
/* Frozen variable and no value yet. We don't
implicitly fetch the value. MI response will
use empty string for the value, which is OK. */
return std::string ();
gdb_assert (varobj_value_is_changeable_p (var));
/* Frozen variable and no value yet. We don't
implicitly fetch the value. MI response will
use empty string for the value, which is OK. */
return std::string ();
gdb_assert (varobj_value_is_changeable_p (var));
- gdb_assert (!value_lazy (var->value));
+ gdb_assert (!value_lazy (var->value.get ()));
/* If the specified format is the current one,
we can reuse print_value. */
if (format == var->format)
return var->print_value;
else
/* If the specified format is the current one,
we can reuse print_value. */
if (format == var->format)
return var->print_value;
else
- return varobj_value_get_print_value (var->value, format, var);
+ return varobj_value_get_print_value (var->value.get (), format,
+ var);
/* It is necessary to access a real type (via RTTI). */
if (opts.objectprint)
{
/* It is necessary to access a real type (via RTTI). */
if (opts.objectprint)
{
+ value = var->value.get ();
lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
}
lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
}
{
const struct varobj *parent = var->parent;
{
const struct varobj *parent = var->parent;
+ value = parent->value.get ();
lookup_actual_type = (TYPE_IS_REFERENCE (parent->type)
|| TYPE_CODE (parent->type) == TYPE_CODE_PTR);
}
lookup_actual_type = (TYPE_IS_REFERENCE (parent->type)
|| TYPE_CODE (parent->type) == TYPE_CODE_PTR);
}
if (opts.objectprint)
lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
if (opts.objectprint)
lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
+ value = var->value.get ();
type = varobj_get_value_type (var);
if (cfull_expression)
parent_expression
type = varobj_get_value_type (var);
if (cfull_expression)
parent_expression
}
if (varobj_value_is_changeable_p (var)
}
if (varobj_value_is_changeable_p (var)
- && var->value && !value_lazy (var->value))
+ && var->value != nullptr && !value_lazy (var->value.get ()))
- var->print_value = varobj_value_get_print_value (var->value,
+ var->print_value = varobj_value_get_print_value (var->value.get (),
gdb_assert (varobj_value_is_changeable_p (var));
/* The value of a changeable variable object must not be lazy. */
gdb_assert (varobj_value_is_changeable_p (var));
/* The value of a changeable variable object must not be lazy. */
- gdb_assert (!value_lazy (var->value));
+ gdb_assert (!value_lazy (var->value.get ()));
/* Need to coerce the input. We want to check if the
value of the variable object will be different
/* Need to coerce the input. We want to check if the
value of the variable object will be different
rather value_contents, will take care of this. */
TRY
{
rather value_contents, will take care of this. */
TRY
{
- val = value_assign (var->value, value);
+ val = value_assign (var->value.get (), value);
}
CATCH (except, RETURN_MASK_ERROR)
}
CATCH (except, RETURN_MASK_ERROR)
{
PyObject *pretty_printer = NULL;
{
PyObject *pretty_printer = NULL;
+ if (var->value != nullptr)
- pretty_printer = gdbpy_get_varobj_pretty_printer (var->value);
+ pretty_printer = gdbpy_get_varobj_pretty_printer (var->value.get ());
if (! pretty_printer)
{
gdbpy_print_stack ();
if (! pretty_printer)
{
gdbpy_print_stack ();
pretty_printer = NULL;
else
{
pretty_printer = NULL;
else
{
- pretty_printer = instantiate_pretty_printer (constructor, var->value);
+ pretty_printer = instantiate_pretty_printer (constructor,
+ var->value.get ());
if (! pretty_printer)
{
gdbpy_print_stack ();
if (! pretty_printer)
{
gdbpy_print_stack ();
/* Get a reference now, before possibly passing it to any Python
code that might release it. */
/* Get a reference now, before possibly passing it to any Python
code that might release it. */
+ value_ref_ptr value_holder;
+ value_holder.reset (value_incref (value));
/* Below, we'll be comparing string rendering of old and new
values. Don't get string rendering if the value is
/* Below, we'll be comparing string rendering of old and new
values. Don't get string rendering if the value is
{
/* Try to compare the values. That requires that both
values are non-lazy. */
{
/* Try to compare the values. That requires that both
values are non-lazy. */
- if (var->not_fetched && value_lazy (var->value))
+ if (var->not_fetched && value_lazy (var->value.get ()))
{
/* This is a frozen varobj and the value was never read.
Presumably, UI shows some "never read" indicator.
{
/* This is a frozen varobj and the value was never read.
Presumably, UI shows some "never read" indicator.
- gdb_assert (!value_lazy (var->value));
+ gdb_assert (!value_lazy (var->value.get ()));
gdb_assert (!value_lazy (value));
gdb_assert (!var->print_value.empty () && !print_value.empty ());
gdb_assert (!value_lazy (value));
gdb_assert (!var->print_value.empty () && !print_value.empty ());
}
/* We must always keep the new value, since children depend on it. */
}
/* We must always keep the new value, since children depend on it. */
- if (var->value != NULL && var->value != value)
- value_decref (var->value);
- var->value = value;
+ var->value = value_holder;
if (value && value_lazy (value) && intentionally_not_fetched)
var->not_fetched = true;
else
if (value && value_lazy (value) && intentionally_not_fetched)
var->not_fetched = true;
else
to see if the variable changed. */
if (var->dynamic->pretty_printer != NULL)
{
to see if the variable changed. */
if (var->dynamic->pretty_printer != NULL)
{
- print_value = varobj_value_get_print_value (var->value, var->format,
- var);
+ print_value = varobj_value_get_print_value (var->value.get (),
+ var->format, var);
if ((var->print_value.empty () && !print_value.empty ())
|| (!var->print_value.empty () && print_value.empty ())
|| (!var->print_value.empty () && !print_value.empty ()
if ((var->print_value.empty () && !print_value.empty ())
|| (!var->print_value.empty () && print_value.empty ())
|| (!var->print_value.empty () && !print_value.empty ()
}
var->print_value = print_value;
}
var->print_value = print_value;
- gdb_assert (!var->value || value_type (var->value));
+ gdb_assert (var->value == nullptr || value_type (var->value.get ()));
varobj_iter_delete (var->dynamic->child_iter);
varobj_clear_saved_item (var->dynamic);
varobj_iter_delete (var->dynamic->child_iter);
varobj_clear_saved_item (var->dynamic);
- value_decref (var->value);
if (is_root_p (var))
delete var->root;
if (is_root_p (var))
delete var->root;
- if (var->value)
- type = value_type (var->value);
+ if (var->value != nullptr)
+ type = value_type (var->value.get ());
if (var->root->is_valid)
{
if (var->dynamic->pretty_printer != NULL)
if (var->root->is_valid)
{
if (var->dynamic->pretty_printer != NULL)
- return varobj_value_get_print_value (var->value, var->format, var);
+ return varobj_value_get_print_value (var->value.get (), var->format,
+ var);
return (*var->root->lang_ops->value_of_variable) (var, format);
}
else
return (*var->root->lang_ops->value_of_variable) (var, format);
}
else
- if (!(var->root->is_valid && var->value && VALUE_LVAL (var->value)))
+ if (!(var->root->is_valid && var->value != nullptr
+ && VALUE_LVAL (var->value.get ())))
return false;
type = varobj_get_value_type (var);
return false;
type = varobj_get_value_type (var);
#include "symtab.h"
#include "gdbtypes.h"
#include "vec.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "vec.h"
/* Enumeration for the format types */
enum varobj_display_formats
/* Enumeration for the format types */
enum varobj_display_formats
indicates there was an error getting this value.
Invariant: if varobj_value_is_changeable_p (this) is non-zero,
the value is either NULL, or not lazy. */
indicates there was an error getting this value.
Invariant: if varobj_value_is_changeable_p (this) is non-zero,
the value is either NULL, or not lazy. */
- struct value *value = NULL;
/* The number of (immediate) children this variable has. */
int num_children = -1;
/* The number of (immediate) children this variable has. */
int num_children = -1;