From: Martin KOCH <Martin.KOCH@bachmann.info>
To: <gdb-patches@sourceware.org>
Cc: Martin KOCH <Martin.KOCH@bachmann.info>
Subject: [PATCH] gdb/remote: fix assertions when attaching in non-stop mode
Date: Thu, 11 Jun 2026 07:36:42 +0200 [thread overview]
Message-ID: <20260611053642.3893794-1-Martin.KOCH@bachmann.info> (raw)
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
next reply other threads:[~2026-06-11 5:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 5:36 Martin KOCH [this message]
2026-06-17 3:44 ` Simon Marchi
2026-06-19 9:25 ` [PATCH v2] " Martin KOCH
2026-07-08 18:57 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260611053642.3893794-1-Martin.KOCH@bachmann.info \
--to=martin.koch@bachmann.info \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox