From patchwork Wed Jan 15 19:12:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 37395 Received: (qmail 79119 invoked by alias); 15 Jan 2020 19:12:42 -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 79025 invoked by uid 89); 15 Jan 2020 19:12:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=quit X-HELO: mail.efficios.com Received: from mail.efficios.com (HELO mail.efficios.com) (167.114.26.124) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Jan 2020 19:12:30 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 4A9DF23CD52 for ; Wed, 15 Jan 2020 14:12:29 -0500 (EST) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id sNGzPdEm-XFr; Wed, 15 Jan 2020 14:12:29 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id C536023D183; Wed, 15 Jan 2020 14:12:28 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com C536023D183 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1579115548; bh=NNCxrGYLHaWOrtZa4RHIm1xu3LnnJHVd/NO/T/FsDJ0=; h=From:To:Date:Message-Id:MIME-Version; b=C19c0RhK4R8EdBCG6pMsgH5TLUPUxZ5lgktSczlwFhNbUwXSvJ/PMWBVYULRuI/Cc MevbiuIuvSWB1KiT9HC91FXX5a8N+Qshiz1TDauQElnaEMSOsx/k5qdQppcq6+V+JK QSeTmo+kpSY9dZPP7mVc0BZAjVAigPj2Qdoa0G++OczEPQz5BtvoGjRw4QbyoZFWSq Nje8IhO4tJXjDj2oHRixhgSHSXK/QRu1O+UsufRO5xZEP5majMuODUfgKK2QRZTY0S TJiBAWuFJ3WUEb61cMFPM52klMGNs96z5bSBBhQg7fwlYa7ZOWlCf+rxfjz5fc/83a oxrTFW13dSOKg== Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id jYmPvbIp-K9b; Wed, 15 Jan 2020 14:12:28 -0500 (EST) Received: from smarchi-efficios.internal.efficios.com (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by mail.efficios.com (Postfix) with ESMTPSA id 7DE9F23CEC7; Wed, 15 Jan 2020 14:12:28 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 4/4] gdb: remove uses of iterate_over_inferiors in top.c Date: Wed, 15 Jan 2020 14:12:22 -0500 Message-Id: <20200115191222.28208-5-simon.marchi@efficios.com> In-Reply-To: <20200115191222.28208-1-simon.marchi@efficios.com> References: <20200115191222.28208-1-simon.marchi@efficios.com> MIME-Version: 1.0 Replace with range-based for loops. gdb/ChangeLog: * top.c (struct qt_args): Remove. (kill_or_detach): Change return type to void, replace `void *` parameter with a proper one. (print_inferior_quit_action): Likewise. (quit_confirm): Use range-based for loop to iterate over inferiors. (quit_force): Likewise. --- gdb/top.c | 51 +++++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/gdb/top.c b/gdb/top.c index a266bfa59256..f702af9acd34 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1607,21 +1607,14 @@ 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. */ +/* Kills or detaches the given 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 (inferior *inf, int from_tty) { - struct qt_args *qt = (struct qt_args *) args; - if (inf->pid == 0) - return 0; + return; thread_info *thread = any_thread_of_inferior (inf); if (thread != NULL) @@ -1632,37 +1625,30 @@ kill_or_detach (struct inferior *inf, void *args) if (target_has_execution) { if (inf->attach_flag) - target_detach (inf, qt->from_tty); + 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. */ +/* Prints info about what GDB will do to inferior INF on a "quit". OUT is + where to collect the output. */ -static int -print_inferior_quit_action (struct inferior *inf, void *arg) +static void +print_inferior_quit_action (inferior *inf, ui_file *out) { - struct ui_file *stb = (struct ui_file *) arg; - if (inf->pid == 0) - return 0; + return; if (inf->attach_flag) - fprintf_filtered (stb, + fprintf_filtered (out, _("\tInferior %d [%s] will be detached.\n"), inf->num, target_pid_to_str (ptid_t (inf->pid)).c_str ()); else - fprintf_filtered (stb, + fprintf_filtered (out, _("\tInferior %d [%s] will be killed.\n"), inf->num, target_pid_to_str (ptid_t (inf->pid)).c_str ()); - - return 0; } /* If necessary, make the user confirm that we should quit. Return @@ -1679,7 +1665,10 @@ quit_confirm (void) string_file stb; stb.puts (_("A debugging session is active.\n\n")); - iterate_over_inferiors (print_inferior_quit_action, &stb); + + for (inferior *inf : all_inferiors ()) + print_inferior_quit_action (inf, &stb); + stb.puts (_("\nQuit anyway? ")); return query ("%s", stb.c_str ()); @@ -1712,7 +1701,6 @@ void quit_force (int *exit_arg, int from_tty) { int exit_code = 0; - struct qt_args qt; undo_terminal_modifications_before_exit (); @@ -1723,15 +1711,14 @@ 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); + for (inferior *inf : all_inferiors ()) + kill_or_detach (inf, from_tty); } catch (const gdb_exception &ex) {