aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-12-11 09:33:36 -0700
committerTom Tromey <tom@tromey.com>2020-12-11 09:33:37 -0700
commit76deb5d9181416cb7ea68764db13e7059d48a46c (patch)
tree63eee44cdb7a5fc5202f657b6c5b8b06dc2e113c /gdb
parent2c1413a98c897be397366d16f58bf54859863090 (diff)
downloadgdb-76deb5d9181416cb7ea68764db13e7059d48a46c.zip
gdb-76deb5d9181416cb7ea68764db13e7059d48a46c.tar.gz
gdb-76deb5d9181416cb7ea68764db13e7059d48a46c.tar.bz2
Change varobj.c:rootlist to a std::list
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-12-11 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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/varobj.c67
2 files changed, 18 insertions, 56 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0fd9591..360ddde 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
2020-12-11 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.
+
+2020-12-11 Tom Tromey <tom@tromey.com>
+
* varobj.c (VAROBJ_TABLE_SIZE): Remove.
(varobj_table): Now htab_t.
(varobj_get_handle, install_variable, uninstall_variable):
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 758753f..7124e25 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);
}
}