gdb: remove uses of iterate_over_inferiors in mi/mi-main.c
Replace with range-based loops. gdb/ChangeLog: * mi/mi-main.c (run_one_inferior): Change return type to void, replace `void *` parameter with proper parameters. (mi_cmd_exec_run): Use range-based loop to iterate over inferiors. (print_one_inferior): Change return type to void, replace `void *` parameter with proper parameters. (mi_cmd_list_thread_groups): Use range-based loop to iterate over inferiors. (get_other_inferior): Remove. (mi_cmd_remove_inferior): Use range-based loop to iterate over inferiors.
This commit is contained in:
parent
788eca4949
commit
a9ac81b1a7
@ -1,3 +1,16 @@
|
||||
2020-01-17 Simon Marchi <simon.marchi@efficios.com>
|
||||
|
||||
* mi/mi-main.c (run_one_inferior): Change return type to void, replace
|
||||
`void *` parameter with proper parameters.
|
||||
(mi_cmd_exec_run): Use range-based loop to iterate over inferiors.
|
||||
(print_one_inferior): Change return type to void, replace `void *`
|
||||
parameter with proper parameters.
|
||||
(mi_cmd_list_thread_groups): Use range-based loop to iterate over
|
||||
inferiors.
|
||||
(get_other_inferior): Remove.
|
||||
(mi_cmd_remove_inferior): Use range-based loop to iterate over
|
||||
inferiors.
|
||||
|
||||
2020-01-17 Simon Marchi <simon.marchi@efficios.com>
|
||||
|
||||
* mi/mi-interp.c (report_initial_inferior): Remove.
|
||||
|
@ -390,17 +390,14 @@ mi_cmd_exec_interrupt (const char *command, char **argv, int argc)
|
||||
}
|
||||
}
|
||||
|
||||
/* Callback for iterate_over_inferiors which starts the execution
|
||||
of the given inferior.
|
||||
/* Start the execution of the given inferior.
|
||||
|
||||
ARG is a pointer to an integer whose value, if non-zero, indicates
|
||||
that the program should be stopped when reaching the main subprogram
|
||||
(similar to what the CLI "start" command does). */
|
||||
START_P indicates whether the program should be stopped when reaching the
|
||||
main subprogram (similar to what the CLI "start" command does). */
|
||||
|
||||
static int
|
||||
run_one_inferior (struct inferior *inf, void *arg)
|
||||
static void
|
||||
run_one_inferior (inferior *inf, bool start_p)
|
||||
{
|
||||
int start_p = *(int *) arg;
|
||||
const char *run_cmd = start_p ? "start" : "run";
|
||||
struct target_ops *run_target = find_run_target ();
|
||||
int async_p = mi_async && run_target->can_async_p ();
|
||||
@ -417,7 +414,6 @@ run_one_inferior (struct inferior *inf, void *arg)
|
||||
switch_to_inferior_no_thread (inf);
|
||||
mi_execute_cli_command (run_cmd, async_p,
|
||||
async_p ? "&" : NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
@ -462,7 +458,8 @@ mi_cmd_exec_run (const char *command, char **argv, int argc)
|
||||
{
|
||||
scoped_restore_current_pspace_and_thread restore_pspace_thread;
|
||||
|
||||
iterate_over_inferiors (run_one_inferior, &start_p);
|
||||
for (inferior *inf : all_inferiors ())
|
||||
run_one_inferior (inf, start_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -633,16 +630,13 @@ struct print_one_inferior_data
|
||||
const std::set<int> *inferiors;
|
||||
};
|
||||
|
||||
static int
|
||||
print_one_inferior (struct inferior *inferior, void *xdata)
|
||||
static void
|
||||
print_one_inferior (struct inferior *inferior, bool recurse,
|
||||
const std::set<int> &ids)
|
||||
{
|
||||
struct print_one_inferior_data *top_data
|
||||
= (struct print_one_inferior_data *) xdata;
|
||||
struct ui_out *uiout = current_uiout;
|
||||
|
||||
if (top_data->inferiors->empty ()
|
||||
|| (top_data->inferiors->find (inferior->pid)
|
||||
!= top_data->inferiors->end ()))
|
||||
if (ids.empty () || (ids.find (inferior->pid) != ids.end ()))
|
||||
{
|
||||
struct collect_cores_data data;
|
||||
ui_out_emit_tuple tuple_emitter (uiout, NULL);
|
||||
@ -675,11 +669,9 @@ print_one_inferior (struct inferior *inferior, void *xdata)
|
||||
uiout->field_signed (NULL, b);
|
||||
}
|
||||
|
||||
if (top_data->recurse)
|
||||
if (recurse)
|
||||
print_thread_info (uiout, NULL, inferior->pid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Output a field named 'cores' with a list as the value. The
|
||||
@ -853,18 +845,14 @@ mi_cmd_list_thread_groups (const char *command, char **argv, int argc)
|
||||
}
|
||||
else
|
||||
{
|
||||
struct print_one_inferior_data data;
|
||||
|
||||
data.recurse = recurse;
|
||||
data.inferiors = &ids;
|
||||
|
||||
/* Local thread groups. Either no explicit ids -- and we
|
||||
print everything, or several explicit ids. In both cases,
|
||||
we print more than one group, and have to use 'groups'
|
||||
as the top-level element. */
|
||||
ui_out_emit_list list_emitter (uiout, "groups");
|
||||
update_thread_list ();
|
||||
iterate_over_inferiors (print_one_inferior, &data);
|
||||
for (inferior *inf : all_inferiors ())
|
||||
print_one_inferior (inf, recurse, ids);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1719,23 +1707,11 @@ mi_cmd_add_inferior (const char *command, char **argv, int argc)
|
||||
current_uiout->field_fmt ("inferior", "i%d", inf->num);
|
||||
}
|
||||
|
||||
/* Callback used to find the first inferior other than the current
|
||||
one. */
|
||||
|
||||
static int
|
||||
get_other_inferior (struct inferior *inf, void *arg)
|
||||
{
|
||||
if (inf == current_inferior ())
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
mi_cmd_remove_inferior (const char *command, char **argv, int argc)
|
||||
{
|
||||
int id;
|
||||
struct inferior *inf;
|
||||
struct inferior *inf_to_remove;
|
||||
|
||||
if (argc != 1)
|
||||
error (_("-remove-inferior should be passed a single argument"));
|
||||
@ -1743,18 +1719,23 @@ mi_cmd_remove_inferior (const char *command, char **argv, int argc)
|
||||
if (sscanf (argv[0], "i%d", &id) != 1)
|
||||
error (_("the thread group id is syntactically invalid"));
|
||||
|
||||
inf = find_inferior_id (id);
|
||||
if (!inf)
|
||||
inf_to_remove = find_inferior_id (id);
|
||||
if (inf_to_remove == NULL)
|
||||
error (_("the specified thread group does not exist"));
|
||||
|
||||
if (inf->pid != 0)
|
||||
if (inf_to_remove->pid != 0)
|
||||
error (_("cannot remove an active inferior"));
|
||||
|
||||
if (inf == current_inferior ())
|
||||
if (inf_to_remove == current_inferior ())
|
||||
{
|
||||
struct thread_info *tp = 0;
|
||||
struct inferior *new_inferior
|
||||
= iterate_over_inferiors (get_other_inferior, NULL);
|
||||
struct inferior *new_inferior = NULL;
|
||||
|
||||
for (inferior *inf : all_inferiors ())
|
||||
{
|
||||
if (inf != inf_to_remove)
|
||||
new_inferior = inf;
|
||||
}
|
||||
|
||||
if (new_inferior == NULL)
|
||||
error (_("Cannot remove last inferior"));
|
||||
@ -1769,7 +1750,7 @@ mi_cmd_remove_inferior (const char *command, char **argv, int argc)
|
||||
set_current_program_space (new_inferior->pspace);
|
||||
}
|
||||
|
||||
delete_inferior (inf);
|
||||
delete_inferior (inf_to_remove);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user