Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 3/4] Don't use iterate_over_inferiors in target.c
Date: Thu, 19 Sep 2019 21:28:00 -0000	[thread overview]
Message-ID: <20190919212825.7586-4-tom@tromey.com> (raw)
In-Reply-To: <20190919212825.7586-1-tom@tromey.com>

This changes target.c to use C++ iterators rather than
iterate_over_inferiors.

gdb/ChangeLog
2019-09-19  Tom Tromey  <tom@tromey.com>

	* target.c (dispose_inferiors): Rename from dispose_inferior.
	Change type.
	(target_preopen): Update.
---
 gdb/ChangeLog |  6 ++++++
 gdb/target.c  | 43 ++++++++++++++++++++++---------------------
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/gdb/target.c b/gdb/target.c
index 78bdfeb49a4..c414c022c75 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1951,31 +1951,32 @@ target_pre_inferior (int from_tty)
   agent_capability_invalidate ();
 }
 
-/* Callback for iterate_over_inferiors.  Gets rid of the given
-   inferior.  */
+/* Gets rid of all inferiors.  */
 
-static int
-dispose_inferior (struct inferior *inf, void *args)
+static void
+dispose_inferiors ()
 {
-  /* Not all killed inferiors can, or will ever be, removed from the
-     inferior list.  Killed inferiors clearly don't need to be killed
-     again, so, we're done.  */
-  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);
+      /* Not all killed inferiors can, or will ever be, removed from
+	 the inferior list.  Killed inferiors clearly don't need to be
+	 killed again, so, we're done.  */
+      if (inf->pid == 0)
+	continue;
 
-      /* Core inferiors actually should be detached, not killed.  */
-      if (target_has_execution)
-	target_kill ();
-      else
-	target_detach (inf, 0);
-    }
+      thread_info *thread = any_thread_of_inferior (inf);
+      if (thread != NULL)
+	{
+	  switch_to_thread (thread);
 
-  return 0;
+	  /* Core inferiors actually should be detached, not
+	     killed.  */
+	  if (target_has_execution)
+	    target_kill ();
+	  else
+	    target_detach (inf, 0);
+	}
+    }
 }
 
 /* This is to be called by the open routine before it does
@@ -1991,7 +1992,7 @@ target_preopen (int from_tty)
       if (!from_tty
 	  || !have_live_inferiors ()
 	  || query (_("A program is being debugged already.  Kill it? ")))
-	iterate_over_inferiors (dispose_inferior, NULL);
+	dispose_inferiors ();
       else
 	error (_("Program not killed."));
     }
-- 
2.17.2


  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 ` Tom Tromey [this message]
2019-09-19 21:28 ` [PATCH 1/4] Use foreach in gdbpy_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 ` [PATCH 2/4] Don't use iterate_over_inferiors in top.c 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-4-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