This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Cleanup varobj children handling
- From: Vladimir Prus <ghost at cs dot msu dot su>
- To: gdb-patches at sources dot redhat dot com
- Date: Fri, 8 Dec 2006 23:00:06 +0300
- Subject: Cleanup varobj children handling
This patch changes varobj.c to use VEC for hodling children, thereby making three
functions unnecessary. No regressions in MI tests. OK?
- Volodya
gdb/
* varobj.c: Include "vec.h".
(varobj_p): New typedef, declare vector of those.
(struct varobj): Use vector for the 'children' member.
(child_exists): Remove.
(save_child_in_parent): Remove.
(remove_child_from_parent): Remove.
(varobj_list_children): Adjust to work work vector.
(varobj_update): Likewise.
(delete_variable_1): Likewise.
* Makefile.in (varobj.o): Update dependencies.
testsuite/
* gdb.mi/mi-var-child.exp: Adjust to the change in order
of varobjs reported by -var-update.
* gdb.mi/mi2-var-child.exp: Likewise.
--- gdb/testsuite/gdb.mi/mi2-var-child.exp (/patches/gdb/path_1/gdb_mainline) (revision 2561)
+++ gdb/testsuite/gdb.mi/mi2-var-child.exp (/patches/gdb/path_2_children/gdb_mainline) (revision 2561)
@@ -831,7 +831,7 @@ mi_execute_to "exec-step 7" "end-steppin
# Test: c_variable-5.8
# Desc: check that long_array[3-9] changed
mi_gdb_test "-var-update *" \
- "\\^done,changelist=\\\[\{name=\"struct_declarations.long_array.3\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.4\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.5\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.6\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.7\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.8\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.9\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
+ "\\^done,changelist=\\\[\{name=\"struct_declarations.long_array.9\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.8\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.7\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.6\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.5\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.4\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.3\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
"update all vars struct_declarations.long_array.3-9 changed"
--- gdb/testsuite/gdb.mi/mi-var-child.exp (/patches/gdb/path_1/gdb_mainline) (revision 2561)
+++ gdb/testsuite/gdb.mi/mi-var-child.exp (/patches/gdb/path_2_children/gdb_mainline) (revision 2561)
@@ -835,7 +835,7 @@ mi_execute_to "exec-step 7" "end-steppin
# Test: c_variable-5.8
# Desc: check that long_array[3-9] changed
mi_gdb_test "-var-update *" \
- "\\^done,changelist=\\\[\{name=\"struct_declarations.long_array.3\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.4\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.5\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.6\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.7\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.8\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.9\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
+ "\\^done,changelist=\\\[\{name=\"struct_declarations.long_array.9\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.8\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.7\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.6\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.5\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.4\",in_scope=\"true\",type_changed=\"false\"\},\{name=\"struct_declarations.long_array.3\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
"update all vars struct_declarations.long_array.3-9 changed"
--- gdb/varobj.c (/patches/gdb/path_1/gdb_mainline) (revision 2561)
+++ gdb/varobj.c (/patches/gdb/path_2_children/gdb_mainline) (revision 2561)
@@ -31,6 +31,8 @@
#include "gdb_string.h"
#include "varobj.h"
+#include "vec.h"
+
/* Non-zero if we want to see trace of varobj level stuff. */
@@ -79,6 +81,10 @@ struct varobj_root
struct varobj_root *next;
};
+typedef struct varobj *varobj_p;
+
+DEF_VEC_P (varobj_p);
+
/* Every variable in the system has a structure of this type defined
for it. This structure holds all information necessary to manipulate
a particular object variable. Members which must be freed are noted. */
@@ -115,8 +121,8 @@ struct varobj
/* If this object is a child, this points to its immediate parent. */
struct varobj *parent;
- /* A list of this object's children */
- struct varobj_child *children;
+ /* Children of this object. */
+ VEC (varobj_p) *children;
/* Description of the root variable. Points to root variable for children. */
struct varobj_root *root;
@@ -128,6 +134,7 @@ struct varobj
int updated;
};
+
/* Every variable keeps a linked list of its children, described
by the following structure. */
/* FIXME: Deprecated. All should use vlist instead */
@@ -178,14 +185,8 @@ static int install_variable (struct varo
static void uninstall_variable (struct varobj *);
-static struct varobj *child_exists (struct varobj *, char *);
-
static struct varobj *create_child (struct varobj *, int, char *);
-static void save_child_in_parent (struct varobj *, struct varobj *);
-
-static void remove_child_from_parent (struct varobj *, struct varobj *);
-
/* Utility routines */
static struct varobj *new_variable (void);
@@ -714,7 +715,14 @@ varobj_list_children (struct varobj *var
*childlist = NULL;
if (var->num_children == -1)
- var->num_children = number_of_children (var);
+ {
+ var->num_children = number_of_children (var);
+ }
+
+ /* If we're called when the list of children is not yet initialized,
+ allocated enough elements in it. */
+ while (VEC_length (varobj_p, var->children) < var->num_children)
+ VEC_safe_push (varobj_p, var->children, NULL);
/* List of children */
*childlist = xmalloc ((var->num_children + 1) * sizeof (struct varobj *));
@@ -724,13 +732,18 @@ varobj_list_children (struct varobj *var
/* Mark as the end in case we bail out */
*((*childlist) + i) = NULL;
- /* check if child exists, if not create */
- name = name_of_child (var, i);
- child = child_exists (var, name);
- if (child == NULL)
- child = create_child (var, i, name);
+ varobj_p *existing = VEC_address (varobj_p, var->children) + i;
+
+ if (*existing == NULL)
+ {
+ /* Either it's the first call to varobj_list_children for
+ this variable object, and the child was never created,
+ or it was explicitly deleted by the client. */
+ name = name_of_child (var, i);
+ *existing = create_child (var, i, name);
+ }
- *((*childlist) + i) = child;
+ *((*childlist) + i) = *existing;
}
/* End of list is marked by a NULL pointer */
@@ -1080,11 +1093,9 @@ varobj_update (struct varobj **varp, str
vpush (&stack, NULL);
/* Push the root's children */
- if ((*varp)->children != NULL)
- {
- struct varobj_child *c;
- for (c = (*varp)->children; c != NULL; c = c->next)
- vpush (&stack, c->child);
+ for (i = 0; i < VEC_length (varobj_p, (*varp)->children); ++i)
+ {
+ vpush (&stack, VEC_index (varobj_p, (*varp)->children, i));
}
/* Walk through the children, reconstructing them all. */
@@ -1092,11 +1103,9 @@ varobj_update (struct varobj **varp, str
while (v != NULL)
{
/* Push any children */
- if (v->children != NULL)
- {
- struct varobj_child *c;
- for (c = v->children; c != NULL; c = c->next)
- vpush (&stack, c->child);
+ for (i = 0; i < VEC_length (varobj_p, v->children); ++i)
+ {
+ vpush (&stack, VEC_index (varobj_p, v->children, i));
}
/* Update this variable */
@@ -1186,16 +1195,17 @@ delete_variable_1 (struct cpstack **resu
{
struct varobj_child *vc;
struct varobj_child *next;
+ int i;
/* Delete any children of this variable, too. */
- for (vc = var->children; vc != NULL; vc = next)
- {
+ for (i = 0; i < VEC_length (varobj_p, var->children); ++i)
+ {
+ varobj_p child = VEC_index (varobj_p, var->children, i);
if (!remove_from_parent_p)
- vc->child->parent = NULL;
- delete_variable_1 (resultp, delcountp, vc->child, 0, only_children_p);
- next = vc->next;
- xfree (vc);
+ child->parent = NULL;
+ delete_variable_1 (resultp, delcountp, child, 0, only_children_p);
}
+ VEC_free (varobj_p, var->children);
/* if we were called to delete only the children we are done here */
if (only_children_p)
@@ -1217,7 +1227,7 @@ delete_variable_1 (struct cpstack **resu
discarding the list afterwards */
if ((remove_from_parent_p) && (var->parent != NULL))
{
- remove_child_from_parent (var->parent, var);
+ VEC_replace (varobj_p, var->parent->children, var->index, NULL);
}
if (var->obj_name != NULL)
@@ -1346,22 +1356,6 @@ uninstall_variable (struct varobj *var)
}
-/* Does a child with the name NAME exist in VAR? If so, return its data.
- If not, return NULL. */
-static struct varobj *
-child_exists (struct varobj *var, char *name)
-{
- struct varobj_child *vc;
-
- for (vc = var->children; vc != NULL; vc = vc->next)
- {
- if (strcmp (vc->child->name, name) == 0)
- return vc->child;
- }
-
- return NULL;
-}
-
/* Create and install a child of the parent of the given name */
static struct varobj *
create_child (struct varobj *parent, int index, char *name)
@@ -1382,9 +1376,6 @@ create_child (struct varobj *parent, int
child->obj_name = childs_name;
install_variable (child);
- /* Save a pointer to this child in the parent */
- save_child_in_parent (parent, child);
-
/* Compute the type of the child. Must do this before
calling install_new_value. */
if (value != NULL)
@@ -1402,46 +1393,6 @@ create_child (struct varobj *parent, int
return child;
}
-
-/* FIXME: This should be a generic add to list */
-/* Save CHILD in the PARENT's data. */
-static void
-save_child_in_parent (struct varobj *parent, struct varobj *child)
-{
- struct varobj_child *vc;
-
- /* Insert the child at the top */
- vc = parent->children;
- parent->children =
- (struct varobj_child *) xmalloc (sizeof (struct varobj_child));
-
- parent->children->next = vc;
- parent->children->child = child;
-}
-
-/* FIXME: This should be a generic remove from list */
-/* Remove the CHILD from the PARENT's list of children. */
-static void
-remove_child_from_parent (struct varobj *parent, struct varobj *child)
-{
- struct varobj_child *vc, *prev;
-
- /* Find the child in the parent's list */
- prev = NULL;
- for (vc = parent->children; vc != NULL;)
- {
- if (vc->child == child)
- break;
- prev = vc;
- vc = vc->next;
- }
-
- if (prev == NULL)
- parent->children = vc->next;
- else
- prev->next = vc->next;
-
-}
/*
--- gdb/Makefile.in (/patches/gdb/path_1/gdb_mainline) (revision 2561)
+++ gdb/Makefile.in (/patches/gdb/path_2_children/gdb_mainline) (revision 2561)
@@ -2844,7 +2844,7 @@ value.o: value.c $(defs_h) $(gdb_string_
$(gdb_assert_h) $(regcache_h) $(block_h)
varobj.o: varobj.c $(defs_h) $(exceptions_h) $(value_h) $(expression_h) \
$(frame_h) $(language_h) $(wrapper_h) $(gdbcmd_h) $(gdb_assert_h) \
- $(gdb_string_h) $(varobj_h)
+ $(gdb_string_h) $(varobj_h) $(vec_h)
vaxbsd-nat.o: vaxbsd-nat.c $(defs_h) $(inferior_h) $(regcache_h) $(target_h) \
$(vax_tdep_h) $(inf_ptrace_h) $(bsd_kvm_h)
vax-nat.o: vax-nat.c $(defs_h) $(inferior_h) $(gdb_assert_h) $(vax_tdep_h) \
Property changes on:
___________________________________________________________________
Name: csl:base
+/all/patches/gdb/path_1/gdb_mainline
Name: svk:merge
+d48a11ec-ee1c-0410-b3f5-c20844f99675:/patches/gdb/path_expression/gdb_mainline:2560