switch inferior/thread before calling target methods
authorPedro Alves <palves@redhat.com>
Fri, 10 Jan 2020 20:05:48 +0000 (20:05 +0000)
committerPedro Alves <palves@redhat.com>
Fri, 10 Jan 2020 20:05:48 +0000 (20:05 +0000)
commitf3f8ece4b1c77c925d1f1566df0bf632790a4d24
tree6ded291c77a7b5e3d235093c573275247425e4e3
parentdb2d40f7d0b8477ca5ad9e305b8137a085434c97
switch inferior/thread before calling target methods

Once each inferior has its own target stack, we'll need to make sure
that the right inferior is selected before we call into target
methods.

It kind of sounds worse than it is in practice.  Not that many places
need to be concerned.

In thread.c, we add a new switch_to_thread_if_alive function that
centralizes the switching before calls to target_thread_alive.  Other
cases are handled with explicit switching.

gdb/ChangeLog:
2020-01-10  Pedro Alves  <palves@redhat.com>

* gdbthread.h (scoped_restore_current_thread)
<dont_restore, restore, m_dont_restore>: Declare.
* thread.c (thread_alive): Add assertion.  Return bool.
(switch_to_thread_if_alive): New.
(prune_threads): Switch inferior/thread.
(print_thread_info_1): Switch thread before calling target methods.
(scoped_restore_current_thread::restore): New, factored out from
...
(scoped_restore_current_thread::~scoped_restore_current_thread):
... this.
(scoped_restore_current_thread::scoped_restore_current_thread):
Add assertion.
(thread_apply_all_command, thread_select): Use
switch_to_thread_if_alive.
* infrun.c (proceed, restart_threads, handle_signal_stop)
(switch_back_to_stepped_thread): Switch current thread before
calling target methods.
gdb/ChangeLog
gdb/infrun.c
gdb/thread.c