Change all_root_varobjs to take a function_view

This changes all_root_varobjs to take a function_view.  This
simplifies some of the callers, in particular we can remove a data
type that only existed to be passed through.

gdb/ChangeLog
2020-12-11  Tom Tromey  <tom@tromey.com>

	* varobj.h (all_root_varobjs): Take a function_view.
	* varobj.c (all_root_varobjs): Take a function_view.
	(varobj_invalidate_iter): Remove unused parameter.
	(varobj_invalidate): Update.
	* mi/mi-cmd-var.c (struct mi_cmd_var_update): Remove.
	(mi_cmd_var_update_iter): Change parameters.
This commit is contained in:
Tom Tromey 2020-12-11 09:33:36 -07:00
parent 76deb5d918
commit d8f168ddd0
4 changed files with 24 additions and 26 deletions

View file

@ -1,3 +1,12 @@
2020-12-11 Tom Tromey <tom@tromey.com>
* varobj.h (all_root_varobjs): Take a function_view.
* varobj.c (all_root_varobjs): Take a function_view.
(varobj_invalidate_iter): Remove unused parameter.
(varobj_invalidate): Update.
* mi/mi-cmd-var.c (struct mi_cmd_var_update): Remove.
(mi_cmd_var_update_iter): Change parameters.
2020-12-11 Tom Tromey <tom@tromey.com> 2020-12-11 Tom Tromey <tom@tromey.com>
* varobj.c (struct varobj_root) <next>: Remove. * varobj.c (struct varobj_root) <next>: Remove.

View file

@ -585,20 +585,12 @@ mi_cmd_var_assign (const char *command, char **argv, int argc)
uiout->field_string ("value", val.c_str ()); uiout->field_string ("value", val.c_str ());
} }
/* Type used for parameters passing to mi_cmd_var_update_iter. */
struct mi_cmd_var_update
{
int only_floating;
enum print_values print_values;
};
/* Helper for mi_cmd_var_update - update each VAR. */ /* Helper for mi_cmd_var_update - update each VAR. */
static void static void
mi_cmd_var_update_iter (struct varobj *var, void *data_pointer) mi_cmd_var_update_iter (struct varobj *var, bool only_floating,
enum print_values print_values)
{ {
struct mi_cmd_var_update *data = (struct mi_cmd_var_update *) data_pointer;
bool thread_stopped; bool thread_stopped;
int thread_id = varobj_get_thread_id (var); int thread_id = varobj_get_thread_id (var);
@ -617,8 +609,8 @@ mi_cmd_var_update_iter (struct varobj *var, void *data_pointer)
} }
if (thread_stopped if (thread_stopped
&& (!data->only_floating || varobj_floating_p (var))) && (!only_floating || varobj_floating_p (var)))
varobj_update_one (var, data->print_values, false /* implicit */); varobj_update_one (var, print_values, false /* implicit */);
} }
void void
@ -656,16 +648,14 @@ mi_cmd_var_update (const char *command, char **argv, int argc)
if ((*name == '*' || *name == '@') && (*(name + 1) == '\0')) if ((*name == '*' || *name == '@') && (*(name + 1) == '\0'))
{ {
struct mi_cmd_var_update data;
data.only_floating = (*name == '@');
data.print_values = print_values;
/* varobj_update_one automatically updates all the children of /* varobj_update_one automatically updates all the children of
VAROBJ. Therefore update each VAROBJ only once by iterating VAROBJ. Therefore update each VAROBJ only once by iterating
only the root VAROBJs. */ only the root VAROBJs. */
all_root_varobjs (mi_cmd_var_update_iter, &data); all_root_varobjs ([=] (varobj *var)
{
mi_cmd_var_update_iter (var, *name == '0', print_values);
});
} }
else else
{ {

View file

@ -2357,11 +2357,11 @@ varobj_default_value_is_changeable_p (const struct varobj *var)
return r; return r;
} }
/* Iterate all the existing _root_ VAROBJs and call the FUNC callback for them /* Iterate all the existing _root_ VAROBJs and call the FUNC callback
with an arbitrary caller supplied DATA pointer. */ for each one. */
void void
all_root_varobjs (void (*func) (struct varobj *var, void *data), void *data) all_root_varobjs (gdb::function_view<void (struct varobj *var)> func)
{ {
/* Iterate "safely" - handle if the callee deletes its passed VAROBJ. */ /* Iterate "safely" - handle if the callee deletes its passed VAROBJ. */
auto iter = rootlist.begin (); auto iter = rootlist.begin ();
@ -2369,7 +2369,7 @@ all_root_varobjs (void (*func) (struct varobj *var, void *data), void *data)
while (iter != end) while (iter != end)
{ {
auto self = iter++; auto self = iter++;
(*func) ((*self)->rootvar, data); func ((*self)->rootvar);
} }
} }
@ -2381,7 +2381,7 @@ all_root_varobjs (void (*func) (struct varobj *var, void *data), void *data)
varobj must be either re-evaluated, or marked as invalid here. */ varobj must be either re-evaluated, or marked as invalid here. */
static void static void
varobj_invalidate_iter (struct varobj *var, void *unused) varobj_invalidate_iter (struct varobj *var)
{ {
/* global and floating var must be re-evaluated. */ /* global and floating var must be re-evaluated. */
if (var->root->floating || var->root->valid_block == NULL) if (var->root->floating || var->root->valid_block == NULL)
@ -2412,7 +2412,7 @@ varobj_invalidate_iter (struct varobj *var, void *unused)
void void
varobj_invalidate (void) varobj_invalidate (void)
{ {
all_root_varobjs (varobj_invalidate_iter, NULL); all_root_varobjs (varobj_invalidate_iter);
} }
/* A hash function for a varobj. */ /* A hash function for a varobj. */

View file

@ -309,8 +309,7 @@ extern std::string varobj_get_value (struct varobj *var);
extern bool varobj_set_value (struct varobj *var, const char *expression); extern bool varobj_set_value (struct varobj *var, const char *expression);
extern void all_root_varobjs (void (*func) (struct varobj *var, void *data), extern void all_root_varobjs (gdb::function_view<void (struct varobj *var)>);
void *data);
extern std::vector<varobj_update_result> extern std::vector<varobj_update_result>
varobj_update (struct varobj **varp, bool is_explicit); varobj_update (struct varobj **varp, bool is_explicit);