[PATCH v4 02/11] gdb, remote: fix 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, threads may retain stale
internal state from the previous connection (e.g., THREAD_INT_RUNNING).
This causes an assertion failure in
thread_info::set_pending_waitstatus(), which requires the thread to be
in THREAD_INT_STOPPED or THREAD_INT_RESUMED_PENDING_STATUS state.

Fix by setting thread's states before calling set_pending_waitstatus ()
in process_initial_stop_replies ().

Scenario:
    - Connect to non-stop remote target with running threads.
    - Disconnect (threads remain in THREAD_INT_RUNNING state).
    - Reconnect to same target.
    - process_initial_stop_replies() processes stop events.
    - Assertion fails when trying to set pending waitstatus on thread still
      marked as THREAD_INT_RUNNING.

Reproducible when running gdb.server/reconnect-ctrl-c.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.server/reconnect-ctrl-c.exp" \
    RUNTESTFLAGS="--target_board=native-gdbserver GDBFLAGS='$GDBFLAGS'"
---
 gdb/remote.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index 194c4cbd9bb..7022e58abab 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5177,12 +5177,13 @@ remote_target::process_initial_stop_replies (int from_tty)
 	  ws.set_stopped (sig);
 	}
 
+      set_internal_state (this, event_ptid, THREAD_INT_STOPPED);
+      set_state (this, event_ptid, THREAD_STOPPED);
+
       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 ();
     }
 
-- 
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.