Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb/remote: fix assertions when attaching in non-stop mode
@ 2026-06-11  5:36 Martin KOCH
  2026-06-17  3:44 ` Simon Marchi
  0 siblings, 1 reply; 4+ messages in thread
From: Martin KOCH @ 2026-06-11  5:36 UTC (permalink / raw)
  To: gdb-patches; +Cc: Martin KOCH

When connecting to a remote target in non-stop mode against a
multi-threaded inferior stopped at raise(SIGSTOP), three internal-error
assertions can fire in sequence:

  remote.c:546: mark_async_event_handler: Assertion 'this->is_async_p ()' failed.
  thread.c:429: set_pending_waitstatus: Assertion 'this->internal_state () ==
                THREAD_INT_STOPPED || ...' failed.
  thread.c:426: set_pending_waitstatus: Assertion '!this->has_pending_waitstatus ()' failed.

The first one is what PR 30630 reports and is fixed with the PR proposed
by Mikhail Terekhov, but with the fix the two other assertions surface:

 * thread.c:429: addressed by reordering set_internal_state / set_state
   to run before set_pending_waitstatus.
 * thread.c:426: addressed by clearing any existing pending wait
   status before installing the new one, when gdbserver delivers
   multiple events for the same thread.

[1] https://sourceware.org/pipermail/gdb-patches/2023-October/202937.html

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30630
Signed-off-by: Martin KOCH <Martin.KOCH@bachmann.info>
---
 gdb/remote.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index 2961664cf33..4148301bc6f 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5237,13 +5237,17 @@ remote_target::process_initial_stop_replies (int from_tty)
 	  ws.set_stopped (sig);
 	}
 
-      if (ws.kind () != TARGET_WAITKIND_STOPPED
-	  || ws.sig () != GDB_SIGNAL_0)
-	evthread->set_pending_waitstatus (ws);
-
       set_internal_state (this, event_ptid, THREAD_INT_STOPPED);
       set_state (this, event_ptid, THREAD_STOPPED);
       get_remote_thread_info (evthread)->set_not_resumed ();
+
+      if (ws.kind () != TARGET_WAITKIND_STOPPED
+	  || ws.sig () != GDB_SIGNAL_0)
+	{
+	  if (evthread->has_pending_waitstatus ())
+	    evthread->clear_pending_waitstatus ();
+	  evthread->set_pending_waitstatus (ws);
+	}
     }
 
   /* "Notice" the new inferiors before anything related to
@@ -8384,7 +8388,7 @@ remote_target::queued_stop_reply (ptid_t ptid)
   remote_state *rs = get_remote_state ();
   stop_reply_up r = remote_notif_remove_queued_reply (ptid);
 
-  if (!rs->stop_reply_queue.empty () && target_can_async_p ())
+  if (!rs->stop_reply_queue.empty () && target_is_async_p ())
     {
       /* There's still at least an event left.  */
       rs->mark_async_event_handler ();
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-08 18:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-11  5:36 [PATCH] gdb/remote: fix assertions when attaching in non-stop mode Martin KOCH
2026-06-17  3:44 ` Simon Marchi
2026-06-19  9:25   ` [PATCH v2] " Martin KOCH
2026-07-08 18:57     ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox