aboutsummaryrefslogtreecommitdiff
path: root/gdb/inferior.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2023-04-03 14:52:05 -0400
committerSimon Marchi <simon.marchi@efficios.com>2023-04-17 13:47:13 -0400
commit348da4565b5c901e9320c3e2d7f5b62793b48a38 (patch)
tree494850c0621b85dd9ef473e0ecfb65e2c6bb7ea1 /gdb/inferior.c
parent2b214d3e3b51b9a6544ffbcf0a1554376c3ce9c5 (diff)
downloadgdb-348da4565b5c901e9320c3e2d7f5b62793b48a38.zip
gdb-348da4565b5c901e9320c3e2d7f5b62793b48a38.tar.gz
gdb-348da4565b5c901e9320c3e2d7f5b62793b48a38.tar.bz2
gdb: add maybe_switch_inferior function
Add the maybe_switch_inferior function, which ensures that the given inferior is the current one. Return an instantiated scoped_restore_current_thread object only we actually needed to switch inferior. Returning a scoped_restore_current_thread requires it to be move-constructible, so give it a move constructor. Change-Id: I1231037102ed6166f2530399e8257ad937fb0569 Reviewed-By: Pedro Alves <pedro@palves.net>
Diffstat (limited to 'gdb/inferior.c')
-rw-r--r--gdb/inferior.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 6eb9f3f..9e37029 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -684,6 +684,21 @@ switch_to_inferior_no_thread (inferior *inf)
set_current_program_space (inf->pspace);
}
+/* See regcache.h. */
+
+gdb::optional<scoped_restore_current_thread>
+maybe_switch_inferior (inferior *inf)
+{
+ gdb::optional<scoped_restore_current_thread> maybe_restore_thread;
+ if (inf != current_inferior ())
+ {
+ maybe_restore_thread.emplace ();
+ switch_to_inferior_no_thread (inf);
+ }
+
+ return maybe_restore_thread;
+}
+
static void
inferior_command (const char *args, int from_tty)
{