[PATCH v2 32/47] gdbserver: wait for stopped threads in queue_stop_reply_callback

Tankut Baris Aktemur
2024-12-13T16:28:17Z

From: Markus Metzger <markus.t.metzger@intel.com>

In queue_stop_reply_callback, we check whether a thread is stopped in the
target and then assume that the thread's status is already filled in.

This would require targets to modify the thread's status rather than the
server setting it in response to a target wait call, which kind of breaks
the abstraction.

Call wait for a stopped thread and update the wait status before asserting
that it isn't TARGET_WAITKIND_IGNORE.
---
gdbserver/server.cc | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index abaa6509041eb6b1c60ca4e99b2fdc1402d202da..b144d2b165564f1681e1082e230fdbbeac8d3bf6 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -3896,6 +3896,13 @@ queue_stop_reply_callback (thread_info *thread)
{
if (target_thread_stopped (thread))
{
+ /* Wait for THREAD if we have not done that, already. */
+ client_state cs;
+ cs.last_ptid = mywait (thread->id, &cs.last_status,
+ TARGET_WNOHANG, 1);
+ if (cs.last_ptid == thread->id)
+ thread->last_status = cs.last_status;
+
threads_debug_printf
("Reporting thread %s as already stopped with %s",
target_pid_to_str (thread->id).c_str (),