From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 3/4] gdb: remove uses of iterate_over_inferiors in mi/mi-main.c
Date: Wed, 15 Jan 2020 19:50:00 -0000 [thread overview]
Message-ID: <20200115191222.28208-4-simon.marchi@efficios.com> (raw)
In-Reply-To: <20200115191222.28208-1-simon.marchi@efficios.com>
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.
---
gdb/mi/mi-main.c | 73 ++++++++++++++++++------------------------------
1 file changed, 27 insertions(+), 46 deletions(-)
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 014feaf64937..d0a3b2887440 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -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);
}
\f
--
2.25.0
next prev parent reply other threads:[~2020-01-15 19:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-15 19:12 [PATCH 0/4] Remove some uses of iterate_over_inferiors Simon Marchi
2020-01-15 19:12 ` [PATCH 4/4] gdb: remove uses of iterate_over_inferiors in top.c Simon Marchi
2020-01-15 19:12 ` [PATCH 2/4] gdb: remove use of iterate_over_inferiors in mi/mi-interp.c Simon Marchi
2020-01-16 11:29 ` Aktemur, Tankut Baris
2020-01-16 15:31 ` Simon Marchi
2020-01-17 7:52 ` Aktemur, Tankut Baris
2020-01-17 15:14 ` Simon Marchi
2020-01-15 19:18 ` [PATCH 1/4] gdb: remove use of iterate_over_inferiors in py-inferior.c Simon Marchi
2020-01-15 19:50 ` Simon Marchi [this message]
2020-01-16 16:23 ` [PATCH 0/4] Remove some uses of iterate_over_inferiors Tom Tromey
2020-01-16 22:46 ` Simon Marchi
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=20200115191222.28208-4-simon.marchi@efficios.com \
--to=simon.marchi@efficios.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