This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] attach + target always in non-stop mode: stop all threads
- From: Pedro Alves <palves at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 30 Nov 2015 19:55:34 -0000
- Subject: [binutils-gdb] attach + target always in non-stop mode: stop all threads
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=066f6b6edcb63b363cc9a95c3727b996d1895549
commit 066f6b6edcb63b363cc9a95c3727b996d1895549
Author: Pedro Alves <palves@redhat.com>
Date: Mon Nov 30 16:05:14 2015 +0000
attach + target always in non-stop mode: stop all threads
When running with "maint set target-non-stop on", and in all-stop
mode, nothing is stopping all threads after attaching. vAttach in
non-stop can leave all threads running and GDB has to explicitly pause
them.
This is not visible with the native target, as in that case, attach
always stops all threads (the core re-resumes them in case of
"attach&").
In addition, it's not defined which thread manages to report the
initial attach stop, so always pick the lowest one (otherwise
multi-attach.exp regresses).
gdb/ChangeLog:
2015-11-30 Pedro Alves <palves@redhat.com>
* infcmd.c (attach_post_wait): If the target is always in non-stop
mode, and the UI is in all-stop mode, stop all threads and pick
the one with lowest number as current.
Diff:
---
gdb/ChangeLog | 6 ++++++
gdb/infcmd.c | 25 ++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6833076..3e10e2b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2015-11-30 Pedro Alves <palves@redhat.com>
+ * infcmd.c (attach_post_wait): If the target is always in non-stop
+ mode, and the UI is in all-stop mode, stop all threads and pick
+ the one with lowest number as current.
+
+2015-11-30 Pedro Alves <palves@redhat.com>
+
* gdbthread.h (switch_to_thread_no_regs): Declare.
* infcmd.c (setup_inferior): New function, factored out from ...
(attach_command_post_wait): ... this. Rename to ...
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 9aae860..ea689f5 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2697,8 +2697,31 @@ attach_post_wait (char *args, int from_tty, enum attach_post_wait_mode mode)
selected thread is stopped, others may still be executing.
Be sure to explicitly stop all threads of the process. This
should have no effect on already stopped threads. */
- if (target_is_non_stop_p ())
+ if (non_stop)
target_stop (pid_to_ptid (inferior->pid));
+ else if (target_is_non_stop_p ())
+ {
+ struct thread_info *thread;
+ struct thread_info *lowest = inferior_thread ();
+ int pid = current_inferior ()->pid;
+
+ stop_all_threads ();
+
+ /* It's not defined which thread will report the attach
+ stop. For consistency, always select the thread with
+ lowest GDB number, which should be the main thread, if it
+ still exists. */
+ ALL_NON_EXITED_THREADS (thread)
+ {
+ if (ptid_get_pid (thread->ptid) == pid)
+ {
+ if (thread->num < lowest->num)
+ lowest = thread;
+ }
+ }
+
+ switch_to_thread (lowest->ptid);
+ }
/* Tell the user/frontend where we're stopped. */
normal_stop ();