[PATCH v4 03/11] gdb, remote: fix async handler assertion on reconnect to non-stop target

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

When reconnecting to a non-stop remote target during
process_initial_stop_replies (), the code attempts to mark an async event
handler before async mode is enabled.  This causes an assertion failure
in remote_state::mark_async_event_handler (), which requires the serial
connection to be in async mode (is_async_p () == true).

Fix by changing the condition in queued_stop_reply () from
target_can_async_p () to target_is_async_p (), matching the pattern used
in push_stop_reply ().  When async mode is later enabled, the event
handler will be marked then.

Scenario:
    - Connect to non-stop remote target.
    - Thread receives signal (e.g., SIGUSR1) and stops.
    - Disconnect and reconnect.
    - Assertion fails because mark_async_event_handler () requires
      is_async_p ().

Reproducible when running gdb.threads/reconnect-signal.exp, on
native-gdbserver or native-extended-gdbserver with target-non-stop
enabled.

export GDBFLAGS="-iex \"maint set target-non-stop on\""
make check TESTS="gdb.threads/reconnect-signal.exp" \
    RUNTESTFLAGS="--target_board=native-gdbserver GDBFLAGS='$GDBFLAGS'"
---
 gdb/remote.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index 7022e58abab..c5c2814aa55 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -8325,7 +8325,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

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.