From patchwork Thu Sep 19 21:28:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 34606 Received: (qmail 69367 invoked by alias); 19 Sep 2019 21:28:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 69206 invoked by uid 89); 19 Sep 2019 21:28:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=sk:disconn, tfind, sk:return_, collected X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.65.13) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Sep 2019 21:28:31 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 10C26400E8027 for ; Thu, 19 Sep 2019 15:22:19 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id B3yWiAJ3JiQerB3yWiPVQp; Thu, 19 Sep 2019 16:28:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=eYu0NiY+ZJCYiM4DNHN9mo915H1ey3P7OyCdvs3btEo=; b=s00neZsKlXX0oO4hlvCocKZaA8 l8x5H6S440YhwWcPS9kxwZpsDYCDRfWABbRp/kYFK1ducYfDG7orZfrgxtjumD6FJGFp25qRTbaAc mzxSKemebBS5fQUdeD4/5V3V8; Received: from 71-218-73-27.hlrn.qwest.net ([71.218.73.27]:35244 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1iB3yW-001n6D-G8; Thu, 19 Sep 2019 16:28:28 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/4] Don't use iterate_over_inferiors in top.c Date: Thu, 19 Sep 2019 15:28:23 -0600 Message-Id: <20190919212825.7586-3-tom@tromey.com> In-Reply-To: <20190919212825.7586-1-tom@tromey.com> References: <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 * 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) } -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) {