From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 04/12] Change varobj to use value_ref_ptr
Date: Thu, 05 Apr 2018 21:16:00 -0000 [thread overview]
Message-ID: <20180405211507.6103-5-tom@tromey.com> (raw)
In-Reply-To: <20180405211507.6103-1-tom@tromey.com>
This changes varobj to use value_ref_ptr, allowing the removal of some
manual reference count management.
ChangeLog
2018-04-05 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.
---
gdb/ChangeLog | 13 +++++++++++++
gdb/ada-varobj.c | 16 +++++++++-------
gdb/c-varobj.c | 15 ++++++++-------
gdb/varobj.c | 43 ++++++++++++++++++++++---------------------
gdb/varobj.h | 3 ++-
5 files changed, 54 insertions(+), 36 deletions(-)
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c
index 1257ee864e..6dafe472c7 100644
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -872,7 +872,7 @@ ada_varobj_get_value_of_variable (struct value *value,
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
@@ -884,7 +884,7 @@ ada_name_of_variable (const struct varobj *parent)
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);
}
@@ -894,7 +894,7 @@ ada_path_expr_of_child (const struct varobj *child)
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,
@@ -904,14 +904,14 @@ ada_path_expr_of_child (const struct varobj *child)
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)
{
- return ada_varobj_get_type_of_child (parent->value, parent->type,
+ return ada_varobj_get_type_of_child (parent->value.get (), parent->type,
index);
}
@@ -923,7 +923,8 @@ ada_value_of_variable (const struct varobj *var,
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. */
@@ -931,7 +932,8 @@ ada_value_of_variable (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)
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index babda29278..03656c0a81 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -286,7 +286,7 @@ c_describe_child (const struct varobj *parent, int index,
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;
@@ -513,21 +513,22 @@ c_value_of_variable (const struct varobj *var,
}
else
{
- 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));
- 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
- return varobj_value_get_print_value (var->value, format, var);
+ return varobj_value_get_print_value (var->value.get (), format,
+ var);
}
}
}
@@ -579,7 +580,7 @@ cplus_number_of_children (const struct varobj *var)
/* It is necessary to access a real type (via RTTI). */
if (opts.objectprint)
{
- value = var->value;
+ value = var->value.get ();
lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
}
@@ -616,7 +617,7 @@ cplus_number_of_children (const struct varobj *var)
{
const struct varobj *parent = var->parent;
- value = parent->value;
+ value = parent->value.get ();
lookup_actual_type = (TYPE_IS_REFERENCE (parent->type)
|| TYPE_CODE (parent->type) == TYPE_CODE_PTR);
}
@@ -724,7 +725,7 @@ cplus_describe_child (const struct varobj *parent, int index,
if (opts.objectprint)
lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
- value = var->value;
+ value = var->value.get ();
type = varobj_get_value_type (var);
if (cfull_expression)
parent_expression
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 58eb531927..2d00964317 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -522,9 +522,9 @@ varobj_set_display_format (struct varobj *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 (),
var->format, var);
}
@@ -1045,7 +1045,7 @@ varobj_set_value (struct varobj *var, const char *expression)
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
@@ -1060,7 +1060,7 @@ varobj_set_value (struct varobj *var, const char *expression)
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)
@@ -1112,9 +1112,9 @@ install_default_visualizer (struct varobj *var)
{
PyObject *pretty_printer = NULL;
- if (var->value)
+ 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 ();
@@ -1149,7 +1149,8 @@ construct_visualizer (struct varobj *var, PyObject *constructor)
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 ();
@@ -1326,8 +1327,9 @@ install_new_value (struct varobj *var, struct value *value, bool initial)
/* Get a reference now, before possibly passing it to any Python
code that might release it. */
+ value_ref_ptr value_holder;
if (value != NULL)
- value_incref (value);
+ 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
@@ -1354,7 +1356,7 @@ install_new_value (struct varobj *var, struct value *value, bool initial)
{
/* 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.
@@ -1372,7 +1374,7 @@ install_new_value (struct varobj *var, struct value *value, bool initial)
}
else
{
- 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 ());
@@ -1392,9 +1394,7 @@ install_new_value (struct varobj *var, struct value *value, bool initial)
}
/* 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
@@ -1407,8 +1407,8 @@ install_new_value (struct varobj *var, struct value *value, bool initial)
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 ()
@@ -1417,7 +1417,7 @@ install_new_value (struct varobj *var, struct value *value, bool initial)
}
var->print_value = print_value;
- gdb_assert (!var->value || value_type (var->value));
+ gdb_assert (var->value == nullptr || value_type (var->value.get ()));
return changed;
}
@@ -1990,7 +1990,6 @@ varobj::~varobj ()
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;
@@ -2014,8 +2013,8 @@ varobj_get_value_type (const struct varobj *var)
{
struct type *type;
- if (var->value)
- type = value_type (var->value);
+ if (var->value != nullptr)
+ type = value_type (var->value.get ());
else
type = var->type;
@@ -2261,7 +2260,8 @@ my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
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
@@ -2397,7 +2397,8 @@ varobj_editable_p (const struct varobj *var)
{
struct type *type;
- 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);
diff --git a/gdb/varobj.h b/gdb/varobj.h
index 6e80d1b89e..3aba0cda67 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -20,6 +20,7 @@
#include "symtab.h"
#include "gdbtypes.h"
#include "vec.h"
+#include "value.h"
/* Enumeration for the format types */
enum varobj_display_formats
@@ -122,7 +123,7 @@ struct varobj
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;
+ value_ref_ptr value;
/* The number of (immediate) children this variable has. */
int num_children = -1;
--
2.13.6
next prev parent reply other threads:[~2018-04-05 21:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-05 21:16 [RFA 00/12] (somewhat) clean up struct value ownership Tom Tromey
2018-04-05 21:16 ` [RFA 08/12] Remove value::next and value::released Tom Tromey
2018-04-06 19:32 ` Pedro Alves
2018-04-06 21:40 ` Tom Tromey
2018-04-05 21:16 ` Tom Tromey [this message]
2018-04-05 21:16 ` [RFA 10/12] Change value::parent to a value_ref_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 06/12] Remove free_all_values Tom Tromey
2018-04-05 21:16 ` [RFA 12/12] Change value::contents to be a unique_xmalloc_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 01/12] Introduce a gdb_ref_ptr specialization for struct value Tom Tromey
2018-04-06 19:29 ` Pedro Alves
2018-04-05 21:16 ` [RFA 05/12] Change value history to use value_ref_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 11/12] Remove range_s VEC Tom Tromey
2018-04-05 21:16 ` [RFA 03/12] Change last_examine_value to value_ref_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 09/12] Use new and delete for values Tom Tromey
2018-04-05 21:16 ` [RFA 02/12] Change breakpoints to use value_ref_ptr Tom Tromey
2018-04-06 19:31 ` Pedro Alves
2018-04-06 21:31 ` Tom Tromey
2018-04-05 21:16 ` [RFA 07/12] Remove free_value_chain Tom Tromey
2018-04-06 19:33 ` [RFA 00/12] (somewhat) clean up struct value ownership Pedro Alves
2018-04-06 21:20 ` Tom Tromey
2018-04-06 21:44 ` Tom Tromey
2018-04-08 21:32 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180405211507.6103-5-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).