This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v2 08/24] Introduce switch_to_inferior_no_thread
- From: Pedro Alves <palves at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 17 Oct 2019 23:50:10 +0100
- Subject: [PATCH v2 08/24] Introduce switch_to_inferior_no_thread
- References: <20191017225026.30496-1-palves@redhat.com>
Several places want to switch context to an inferior and its pspace,
while at the same time switch to "no thread selected". This commit
adds a function that does that, and uses it in a few places.
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* inferior.c (switch_to_inferior_no_thread): New function,
factored out from ...
(inferior_command): ... here.
* inferior.h (switch_to_inferior_no_thread): Declare.
* mi/mi-main.c (run_one_inferior): Use
switch_to_inferior_no_thread.
---
gdb/inferior.c | 21 +++++++++++++--------
gdb/inferior.h | 4 ++++
gdb/mi/mi-main.c | 6 +-----
3 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 310b8f5dd3..619b8caac7 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -585,6 +585,16 @@ kill_inferior_command (const char *args, int from_tty)
bfd_cache_close_all ();
}
+/* See inferior.h. */
+
+void
+switch_to_inferior_no_thread (inferior *inf)
+{
+ set_current_inferior (inf);
+ switch_to_no_thread ();
+ set_current_program_space (inf->pspace);
+}
+
static void
inferior_command (const char *args, int from_tty)
{
@@ -615,9 +625,7 @@ inferior_command (const char *args, int from_tty)
}
else
{
- set_current_inferior (inf);
- switch_to_no_thread ();
- set_current_program_space (inf->pspace);
+ switch_to_inferior_no_thread (inf);
gdb::observers::user_selected_context_changed.notify
(USER_SELECTED_INFERIOR);
@@ -747,11 +755,8 @@ add_inferior_command (const char *args, int from_tty)
if (exec != NULL)
{
/* Switch over temporarily, while reading executable and
- symbols.q. */
- set_current_program_space (inf->pspace);
- set_current_inferior (inf);
- switch_to_no_thread ();
-
+ symbols. */
+ switch_to_inferior_no_thread (inf);
exec_file_attach (exec.get (), from_tty);
symbol_file_add_main (exec.get (), add_flags);
}
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 720d570fa3..2e19b751ca 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -310,6 +310,10 @@ extern inferior *current_inferior ();
extern void set_current_inferior (inferior *);
+/* Switch inferior (and program space) to INF, and switch to no thread
+ selected. */
+extern void switch_to_inferior_no_thread (inferior *inf);
+
/* GDB represents the state of each program execution with an object
called an inferior. An inferior typically corresponds to a process
but is more general and applies also to targets that do not have a
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 9a0b7f97b2..4fa7ffaf90 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -414,11 +414,7 @@ run_one_inferior (struct inferior *inf, void *arg)
switch_to_thread (tp);
}
else
- {
- set_current_inferior (inf);
- switch_to_no_thread ();
- set_current_program_space (inf->pspace);
- }
+ switch_to_inferior_no_thread (inf);
mi_execute_cli_command (run_cmd, async_p,
async_p ? "&" : NULL);
return 0;
--
2.14.5