[08/23] Introduce switch_to_inferior_no_thread
Commit Message
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. The
function is made extern because many more uses will be added in follow
up commits.
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.
---
gdb/inferior.c | 21 +++++++++++++--------
gdb/inferior.h | 4 ++++
2 files changed, 17 insertions(+), 8 deletions(-)
Comments
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
Pedro> Several places want to switch context to an inferior and its pspace,
Pedro> while at the same time switch to "no thread selected". This commit
Pedro> adds a function that does that, and uses it in a few places. The
Pedro> function is made extern because many more uses will be added in follow
Pedro> up commits.
mi-main.c:run_one_inferior could also be converted.
This isn't directly related to this patch, but I wonder why
set_current_inferior doesn't set the current program space as well. It
seems possibly dangerous to have these globals that can get out of sync.
Tom
On 9/9/19 7:42 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Pedro> Several places want to switch context to an inferior and its pspace,
> Pedro> while at the same time switch to "no thread selected". This commit
> Pedro> adds a function that does that, and uses it in a few places. The
> Pedro> function is made extern because many more uses will be added in follow
> Pedro> up commits.
>
> mi-main.c:run_one_inferior could also be converted.
Indeed, I did that.
Thanks,
Pedro Alves
@@ -584,6 +584,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)
{
@@ -614,9 +624,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);
@@ -746,11 +754,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);
}
@@ -329,6 +329,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