GNU Binutils with patches for OS216
修订版 | 6866f55720b7f4bf54b32fc2b89be08453a67b2d (tree) |
---|---|
时间 | 2019-09-07 07:39:08 |
作者 | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
Fix reconnecting to a gdbserver already debugging multiple processes, II
Another bug exposed by gdb.server/extended-remote-restart.exp in the
multi-target work is that remote_target::start_remote can leave
inferior_ptid and current_inferior() out of sync:
This is caused by writing to inferior_ptid directly instead of using
switch_to_thread. Also, "inferior_list->thread_list->ptid" assumes
that we want the first thread of the first inferior, but that inferior
may not have threads, or with multi-target, that target may be
connected to some other target.
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* remote.c (remote_target::start_remote): Don't set inferior_ptid
directly. Instead find the first thread in the thread list and
use switch_to_thread.
@@ -4709,8 +4709,8 @@ remote_target::start_remote (int from_tty, int extended_p) | ||
4709 | 4709 | says should be current. If we're reconnecting to a |
4710 | 4710 | multi-threaded program, this will ideally be the thread |
4711 | 4711 | that last reported an event before GDB disconnected. */ |
4712 | - inferior_ptid = get_current_thread (wait_status); | |
4713 | - if (inferior_ptid == null_ptid) | |
4712 | + ptid_t curr_thread = get_current_thread (wait_status); | |
4713 | + if (curr_thread == null_ptid) | |
4714 | 4714 | { |
4715 | 4715 | /* Odd... The target was able to list threads, but not |
4716 | 4716 | tell us which thread was current (no "thread" |
@@ -4722,8 +4722,14 @@ remote_target::start_remote (int from_tty, int extended_p) | ||
4722 | 4722 | "warning: couldn't determine remote " |
4723 | 4723 | "current thread; picking first in list.\n"); |
4724 | 4724 | |
4725 | - inferior_ptid = inferior_list->thread_list->ptid; | |
4725 | + for (thread_info *tp : all_non_exited_threads ()) | |
4726 | + { | |
4727 | + switch_to_thread (tp); | |
4728 | + break; | |
4729 | + } | |
4726 | 4730 | } |
4731 | + else | |
4732 | + switch_to_thread (find_thread_ptid (curr_thread)); | |
4727 | 4733 | } |
4728 | 4734 | |
4729 | 4735 | /* init_wait_for_inferior should be called before get_offsets in order |