From patchwork Wed Jan 15 19:12:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 37397 Received: (qmail 86513 invoked by alias); 15 Jan 2020 19:18:05 -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 86501 invoked by uid 89); 15 Jan 2020 19:18:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.1 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= 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:18:02 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id A72A323CD53 for ; Wed, 15 Jan 2020 14:12:30 -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 c2hb6cEPe7sg; Wed, 15 Jan 2020 14:12:30 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id A154023CEC8; Wed, 15 Jan 2020 14:12:28 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com A154023CEC8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1579115548; bh=QvYNVRi0K8neWMpRzbFXvQ82NmIIcpzSa+sap8ZYPXg=; h=From:To:Date:Message-Id:MIME-Version; b=HXOp31BBOogAwgo/B9YpKfRwZYhbOfUtbKrkdTST10E2DFGFOADlrp2mfhNF4otqp lcdFgLHpDOnKJK+UiWmlzh3hZYZTjI5QnRv2OsH4i7SVo9PajBazJ+D2Ij44vFJyR7 rcEA5IaJVISbjo6A3+PEX5Apviq1Ti74dV7r8Ln3nbNoDxft8UaeXfmRaN/tfWS07r O7VQHHq5rGWZmgK+nCFChNT5ybGuwW/RX10cU9bHRj+n9REY+Be8GDzZRI/ArkxeZ5 dSF1Tw07fGuzKPJ1zX5cbSP8qOwL2y8W2JjvtD+Y723N+CgmsyQ8BmtBqS3yowRG51 KBUnDD/q+/tlQ== 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 3ezfSiviHcWL; 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 6867923CDDA; Wed, 15 Jan 2020 14:12:28 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 3/4] gdb: remove uses of iterate_over_inferiors in mi/mi-main.c Date: Wed, 15 Jan 2020 14:12:21 -0500 Message-Id: <20200115191222.28208-4-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 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 *inferiors; }; -static int -print_one_inferior (struct inferior *inferior, void *xdata) +static void +print_one_inferior (struct inferior *inferior, bool recurse, + const std::set &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); }