[PATCH v4 06/11] gdb, remote: fix ptid matching for process-wide stop events

Mohamed Bouhaouel <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
From: "Rohr, Stephan" <[email protected]>

If an inferior call results in a process event for a non-stop remote
target, GDB does not properly handle the event but is hanging.

Because GDB is evaluating a breakpoint condition, the corresponding
inferior call is evaluated w.r.t. the ptid of the current thread.
gdbserver sends a process exit event; the event is not matched by the
thread PTID and GDB hangs.

Fix this by matching a process event in 'stop_reply_queue' if there is
no matching thread event.  This ensures a thread event is prioritized
if both a thread event and a process event are queued and preserves the
current behavior.

Reproducible when running gdb.base/exit-in-condition.exp, on
native-extended-gdbserver with target-non-stop enabled.

export GDBFLAGS="-iex \"maint set target-non-stop on\""
make check TESTS="gdb.base/exit-in-condition.exp" \
    RUNTESTFLAGS="--target_board=native-extended-gdbserver GDBFLAGS='$GDBFLAGS'"
---
 gdb/remote.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/gdb/remote.c b/gdb/remote.c
index b27b1a1b6c0..b1bc1283b9a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -8303,6 +8303,20 @@ remote_target::remote_notif_remove_queued_reply (ptid_t ptid)
 			    {
 			      return event->ptid.matches (ptid);
 			    });
+
+  /* Match process events if PTID is a thread and there is no matching event
+     queued.  Prioritize thread events to preserve the existing behavior.  */
+  if (iter == rs->stop_reply_queue.end ()
+      && ptid != minus_one_ptid
+      && !ptid.is_pid ())
+    iter = std::find_if (rs->stop_reply_queue.begin (),
+			 rs->stop_reply_queue.end (),
+			 [=] (const stop_reply_up &event)
+			 {
+			   return (event->ptid.is_pid ()
+			     && event->ptid.pid () == ptid.pid ());
+			 });
+
   stop_reply_up result;
   if (iter != rs->stop_reply_queue.end ())
     {
-- 
2.43.0

Intel Deutschland GmbH

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.