From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/4] Don't use iterate_over_inferiors in top.c
Date: Thu, 19 Sep 2019 21:28:00 -0000 [thread overview]
Message-ID: <20190919212825.7586-3-tom@tromey.com> (raw)
In-Reply-To: <20190919212825.7586-1-tom@tromey.com>
This changes top.c to use iterators rather than
iterate_over_inferiors.
gdb/ChangeLog
2019-09-19 Tom Tromey <tom@tromey.com>
* top.c (struct qt_args): Remove.
(kill_or_detach): Change type.
(quit_force): Update.
(print_inferior_quit_actions): Rename from
print_inferior_quit_action. Change type.
(quit_confirm): Update.
---
gdb/ChangeLog | 9 ++++++
gdb/top.c | 90 +++++++++++++++++++++++----------------------------
2 files changed, 49 insertions(+), 50 deletions(-)
diff --git a/gdb/top.c b/gdb/top.c
index 49e6daae949..276780f7219 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1548,62 +1548,55 @@ set_prompt (const char *s)
}
\f
-struct qt_args
-{
- int from_tty;
-};
-
-/* Callback for iterate_over_inferiors. Kills or detaches the given
- inferior, depending on how we originally gained control of it. */
+/* Kill or detach each inferior, depending on how we originally gained
+ control of it. */
-static int
-kill_or_detach (struct inferior *inf, void *args)
+static void
+kill_or_detach (int from_tty)
{
- struct qt_args *qt = (struct qt_args *) args;
-
- if (inf->pid == 0)
- return 0;
-
- thread_info *thread = any_thread_of_inferior (inf);
- if (thread != NULL)
+ for (inferior *inf : all_inferiors_safe ())
{
- switch_to_thread (thread);
+ if (inf->pid == 0)
+ continue;
- /* Leave core files alone. */
- if (target_has_execution)
+ thread_info *thread = any_thread_of_inferior (inf);
+ if (thread != NULL)
{
- if (inf->attach_flag)
- target_detach (inf, qt->from_tty);
- else
- target_kill ();
+ switch_to_thread (thread);
+
+ /* Leave core files alone. */
+ if (target_has_execution)
+ {
+ if (inf->attach_flag)
+ target_detach (inf, from_tty);
+ else
+ target_kill ();
+ }
}
}
-
- return 0;
}
-/* Callback for iterate_over_inferiors. Prints info about what GDB
- will do to each inferior on a "quit". ARG points to a struct
- ui_out where output is to be collected. */
+/* Print info about what GDB will do to each inferior on a "quit". */
-static int
-print_inferior_quit_action (struct inferior *inf, void *arg)
+static void
+print_inferior_quit_actions (struct ui_file *stb)
{
- struct ui_file *stb = (struct ui_file *) arg;
-
- if (inf->pid == 0)
- return 0;
-
- if (inf->attach_flag)
- fprintf_filtered (stb,
- _("\tInferior %d [%s] will be detached.\n"), inf->num,
- target_pid_to_str (ptid_t (inf->pid)).c_str ());
- else
- fprintf_filtered (stb,
- _("\tInferior %d [%s] will be killed.\n"), inf->num,
- target_pid_to_str (ptid_t (inf->pid)).c_str ());
-
- return 0;
+ for (inferior *inf : all_inferiors_safe ())
+ {
+ if (inf->pid == 0)
+ continue;
+
+ if (inf->attach_flag)
+ fprintf_filtered (stb,
+ _("\tInferior %d [%s] will be detached.\n"),
+ inf->num,
+ target_pid_to_str (ptid_t (inf->pid)).c_str ());
+ else
+ fprintf_filtered (stb,
+ _("\tInferior %d [%s] will be killed.\n"),
+ inf->num,
+ target_pid_to_str (ptid_t (inf->pid)).c_str ());
+ }
}
/* If necessary, make the user confirm that we should quit. Return
@@ -1620,7 +1613,7 @@ quit_confirm (void)
string_file stb;
stb.puts (_("A debugging session is active.\n\n"));
- iterate_over_inferiors (print_inferior_quit_action, &stb);
+ print_inferior_quit_actions (&stb);
stb.puts (_("\nQuit anyway? "));
return query ("%s", stb.c_str ());
@@ -1653,7 +1646,6 @@ void
quit_force (int *exit_arg, int from_tty)
{
int exit_code = 0;
- struct qt_args qt;
undo_terminal_modifications_before_exit ();
@@ -1664,15 +1656,13 @@ quit_force (int *exit_arg, int from_tty)
else if (return_child_result)
exit_code = return_child_result_value;
- qt.from_tty = from_tty;
-
/* We want to handle any quit errors and exit regardless. */
/* Get out of tfind mode, and kill or detach all inferiors. */
try
{
disconnect_tracing ();
- iterate_over_inferiors (kill_or_detach, &qt);
+ kill_or_detach (from_tty);
}
catch (const gdb_exception &ex)
{
--
2.17.2
next prev parent reply other threads:[~2019-09-19 21:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-19 21:28 [PATCH 0/4] Remove some uses of iterate_over_inferiors Tom Tromey
2019-09-19 21:28 ` [PATCH 4/4] Remove a use of iterate_over_threads from mi-main.c Tom Tromey
2019-09-19 21:28 ` Tom Tromey [this message]
2019-09-19 21:28 ` [PATCH 3/4] Don't use iterate_over_inferiors in target.c Tom Tromey
2019-09-19 21:28 ` [PATCH 1/4] Use foreach in gdbpy_inferiors Tom Tromey
2019-09-20 2:16 ` [PATCH 0/4] Remove some uses of iterate_over_inferiors Simon Marchi
2019-09-20 14:02 ` Tom Tromey
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=20190919212825.7586-3-tom@tromey.com \
--to=tom@tromey.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