This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 2/4] gdb: remove use of iterate_over_inferiors in mi/mi-interp.c
- From: Simon Marchi <simon dot marchi at efficios dot com>
- To: gdb-patches at sourceware dot org
- Cc: Simon Marchi <simon dot marchi at efficios dot com>
- Date: Wed, 15 Jan 2020 14:12:20 -0500
- Subject: [PATCH 2/4] gdb: remove use of iterate_over_inferiors in mi/mi-interp.c
- Dkim-filter: OpenDKIM Filter v2.10.3 mail.efficios.com 79D3923CDDB
- References: <20200115191222.28208-1-simon.marchi@efficios.com>
Replace it with a range-based for. I figured that in the hypothetical case
where there are multiple inferiors, we only need to configure the terminal and
flush the output once, so I have moved these out of the loop.
gdb/ChangeLog:
* mi/mi-interp.c (report_initial_inferior): Remove.
(mi_interp::init): Use range-based for to iterate over inferiors.
---
gdb/mi/mi-interp.c | 40 ++++++++++++++++------------------------
1 file changed, 16 insertions(+), 24 deletions(-)
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 2ac4c119961c..6f4f56849611 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -91,8 +91,6 @@ static void mi_memory_changed (struct inferior *inf, CORE_ADDR memaddr,
ssize_t len, const bfd_byte *myaddr);
static void mi_on_sync_execution_done (void);
-static int report_initial_inferior (struct inferior *inf, void *closure);
-
/* Display the MI prompt. */
static void
@@ -140,8 +138,22 @@ mi_interp::init (bool top_level)
/* The initial inferior is created before this function is
called, so we need to report it explicitly. Use iteration in
case future version of GDB creates more than one inferior
- up-front. */
- iterate_over_inferiors (report_initial_inferior, mi);
+ up-front.
+
+ This function is called from mi_interpreter_init, and since
+ mi_inferior_added assumes that inferior is fully initialized
+ and top_level_interpreter_data is set, we cannot call
+ it here. */
+
+ target_terminal::scoped_restore_terminal_state term_state;
+ target_terminal::ours_for_output ();
+
+ for (inferior *inf : all_inferiors ())
+ fprintf_unfiltered (mi->event_channel,
+ "thread-group-added,id=\"i%d\"",
+ inf->num);
+
+ gdb_flush (mi->event_channel);
}
}
@@ -1253,26 +1265,6 @@ mi_user_selected_context_changed (user_selected_what selection)
}
}
-static int
-report_initial_inferior (struct inferior *inf, void *closure)
-{
- /* This function is called from mi_interpreter_init, and since
- mi_inferior_added assumes that inferior is fully initialized
- and top_level_interpreter_data is set, we cannot call
- it here. */
- struct mi_interp *mi = (struct mi_interp *) closure;
-
- target_terminal::scoped_restore_terminal_state term_state;
- target_terminal::ours_for_output ();
-
- fprintf_unfiltered (mi->event_channel,
- "thread-group-added,id=\"i%d\"",
- inf->num);
- gdb_flush (mi->event_channel);
-
- return 0;
-}
-
ui_out *
mi_interp::interp_ui_out ()
{
--
2.25.0