From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 02/11] Change varobj.c:rootlist to a std::list
Date: Sat, 24 Oct 2020 15:08:47 -0600 [thread overview]
Message-ID: <20201024210856.12021-3-tom@tromey.com> (raw)
In-Reply-To: <20201024210856.12021-1-tom@tromey.com>
This changes varobj.c:rootlist to be a std::list. This lets us remove
some code. std::list is chosen because its iterator invalidation
approach suits the all_root_varobjs API.
I considered replacing all_root_varobjs with "external iteration", but
haven't gotten around to doing so.
gdb/ChangeLog
2020-10-24 Tom Tromey <tom@tromey.com>
* varobj.c (struct varobj_root) <next>: Remove.
(struct vlist): Remove.
(rootlist): Now a std::list.
(install_variable, uninstall_variable, all_root_varobjs): Update.
---
gdb/ChangeLog | 7 ++++++
gdb/varobj.c | 67 +++++++++------------------------------------------
2 files changed, 18 insertions(+), 56 deletions(-)
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 3af1ef22d7e..ea57a79aa41 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -31,6 +31,7 @@
#include "varobj-iter.h"
#include "parser-defs.h"
#include "gdbarch.h"
+#include <algorithm>
#if HAVE_PYTHON
#include "python/python.h"
@@ -100,9 +101,6 @@ struct varobj_root
/* The varobj for this root node. */
struct varobj *rootvar = NULL;
-
- /* Next root variable */
- struct varobj_root *next = NULL;
};
/* Dynamic part of varobj. */
@@ -136,14 +134,6 @@ struct varobj_dynamic
varobj_item *saved_item = NULL;
};
-/* A list of varobjs */
-
-struct vlist
-{
- struct varobj *var;
- struct vlist *next;
-};
-
/* Private function prototypes */
/* Helper functions for the above subcommands. */
@@ -197,8 +187,8 @@ static struct varobj *varobj_add_child (struct varobj *var,
/* Mappings of varobj_display_formats enums to gdb's format codes. */
static int format_code[] = { 0, 't', 'd', 'x', 'o', 'z' };
-/* Header of the list of root variable objects. */
-static struct varobj_root *rootlist;
+/* List of root variable objects. */
+static std::list<struct varobj_root *> rootlist;
/* Pointer to the varobj hash table (built at run time). */
static htab_t varobj_table;
@@ -1790,14 +1780,7 @@ install_variable (struct varobj *var)
/* If root, add varobj to root list. */
if (is_root_p (var))
- {
- /* Add to list of root variables. */
- if (rootlist == NULL)
- var->root->next = NULL;
- else
- var->root->next = rootlist;
- rootlist = var->root;
- }
+ rootlist.push_front (var->root);
return true; /* OK */
}
@@ -1806,9 +1789,6 @@ install_variable (struct varobj *var)
static void
uninstall_variable (struct varobj *var)
{
- struct varobj_root *cr;
- struct varobj_root *prer;
-
hashval_t hash = htab_hash_string (var->obj_name.c_str ());
htab_remove_elt_with_hash (varobj_table, var->obj_name.c_str (), hash);
@@ -1818,32 +1798,9 @@ uninstall_variable (struct varobj *var)
/* If root, remove varobj from root list. */
if (is_root_p (var))
{
- /* Remove from list of root variables. */
- if (rootlist == var->root)
- rootlist = var->root->next;
- else
- {
- prer = NULL;
- cr = rootlist;
- while ((cr != NULL) && (cr->rootvar != var))
- {
- prer = cr;
- cr = cr->next;
- }
- if (cr == NULL)
- {
- warning (_("Assertion failed: Could not find "
- "varobj \"%s\" in root list"),
- var->obj_name.c_str ());
- return;
- }
- if (prer == NULL)
- rootlist = NULL;
- else
- prer->next = cr->next;
- }
+ auto iter = std::find (rootlist.begin (), rootlist.end (), var->root);
+ rootlist.erase (iter);
}
-
}
/* Create and install a child of the parent of the given name.
@@ -2406,15 +2363,13 @@ varobj_default_value_is_changeable_p (const struct varobj *var)
void
all_root_varobjs (void (*func) (struct varobj *var, void *data), void *data)
{
- struct varobj_root *var_root, *var_root_next;
-
/* Iterate "safely" - handle if the callee deletes its passed VAROBJ. */
-
- for (var_root = rootlist; var_root != NULL; var_root = var_root_next)
+ auto iter = rootlist.begin ();
+ auto end = rootlist.end ();
+ while (iter != end)
{
- var_root_next = var_root->next;
-
- (*func) (var_root->rootvar, data);
+ auto self = iter++;
+ (*func) ((*self)->rootvar, data);
}
}
--
2.17.2
next prev parent reply other threads:[~2020-10-24 21:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-24 21:08 [PATCH 00/11] Some varobj C++-ification and cleanup Tom Tromey
2020-10-24 21:08 ` [PATCH 01/11] Use htab_t in varobj Tom Tromey
2020-10-24 21:08 ` Tom Tromey [this message]
2020-10-24 21:08 ` [PATCH 03/11] Change all_root_varobjs to take a function_view Tom Tromey
2020-10-24 21:08 ` [PATCH 04/11] C++-ify varobj iteration Tom Tromey
2020-10-24 21:08 ` [PATCH 05/11] Change varobj_iter::next to return unique_ptr Tom Tromey
2020-10-24 21:08 ` [PATCH 06/11] Change varobj_dynamic::saved_item to unique_ptr Tom Tromey
2020-10-24 21:08 ` [PATCH 07/11] Change varobj_dynamic::child_iter " Tom Tromey
2020-10-24 21:08 ` [PATCH 08/11] Change varobj_item::value to a value_ref_ptr Tom Tromey
2020-10-24 21:08 ` [PATCH 09/11] Remove varobj_clear_saved_item Tom Tromey
2020-10-24 21:08 ` [PATCH 10/11] Use gdbpy_ref in instantiate_pretty_printer Tom Tromey
2020-10-24 21:08 ` [PATCH 11/11] install_variable cannot fail Tom Tromey
2020-12-11 16:46 ` [PATCH 00/11] Some varobj C++-ification and cleanup 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=20201024210856.12021-3-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).