Fix initial thread state of non-threaded remote targets
authorJan Matyas <jmatyas@codasip.com>
Thu, 25 Feb 2021 07:27:09 +0000 (08:27 +0100)
committerSimon Marchi <simon.marchi@polymtl.ca>
Thu, 25 Feb 2021 20:38:54 +0000 (15:38 -0500)
This change fixes the initial state of the main thread of remote
targets which have no concept of threading. Such targets are
treated as single-threaded by gdb, and this single thread needs
to be initially set to the "resumed" state, in the same manner as
threads in thread-aware remote targets (see remote.c,
remote_target::remote_add_thread).

Without this fix, the following assert was triggered on thread-
unaware remote targets:

    remote_target::select_thread_for_ambiguous_stop_reply(const target_waitstatus*): Assertion `first_resumed_thread != nullptr' failed.

The bug can be reproduced using gdbserver

    * by disabling packets 'T' and 'qThreadInfo', or
    * by disabling all thread-related packets.

The test suite has been updated to include these two scenarios, see
gdb.server/stop-reply-no-thread.exp.

Change-Id: I2c39c9de17e8d6922a8c1b9e259eb316a554a43d

gdb/ChangeLog
gdb/remote.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.server/stop-reply-no-thread.exp

index 27b0e0cfec0e8b86ea44641928644332a727c0d7..74e0dee1b0f9c2e5d8e06b8730e05cc180c275dc 100644 (file)
@@ -1,3 +1,13 @@
+2021-02-25  Jan Matyas  <jmatyas@codasip.com>
+
+       PR gdb/26819
+       * remote.c (remote_target::start_remote): Ensure the single
+       thread, automatically added for remote targets without the
+       concept of threading, is initially in set to the "resumed"
+       state.
+       * remote.c (remote_target::add_current_inferior_and_thread):
+       Add return value - return the main thread.
+
 2021-02-25  Jan Vrany  <jan.vrany@labware.com>
 
        * gdb/mi/mi-interp.c (mi_traceframe_changed): Remove trailing \n from output.
index 2c85bdcffbc58db4fcc78cf131f274f655e16225..ae15f416153f91747166201972ef35fc6db744ed 100644 (file)
@@ -741,7 +741,7 @@ public: /* Remote specific methods.  */
   int remote_resume_with_vcont (ptid_t ptid, int step,
                                gdb_signal siggnal);
 
-  void add_current_inferior_and_thread (const char *wait_status);
+  thread_info *add_current_inferior_and_thread (const char *wait_status);
 
   ptid_t wait_ns (ptid_t ptid, struct target_waitstatus *status,
                  target_wait_flags options);
@@ -4409,9 +4409,11 @@ remote_target::get_current_thread (const char *wait_status)
    whose response is a stop reply from which we can also try
    extracting the thread.  If the target doesn't support the explicit
    qC query, we infer the current thread from that stop reply, passed
-   in in WAIT_STATUS, which may be NULL.  */
+   in in WAIT_STATUS, which may be NULL.
 
-void
+   The function returns pointer to the main thread of the inferior. */
+
+thread_info *
 remote_target::add_current_inferior_and_thread (const char *wait_status)
 {
   struct remote_state *rs = get_remote_state ();
@@ -4445,6 +4447,8 @@ remote_target::add_current_inferior_and_thread (const char *wait_status)
      yet.  */
   thread_info *tp = add_thread_silent (this, curr_ptid);
   switch_to_thread_no_regs (tp);
+
+  return tp;
 }
 
 /* Print info about a thread that was found already stopped on
@@ -4800,7 +4804,8 @@ remote_target::start_remote (int from_tty, int extended_p)
          /* Target has no concept of threads at all.  GDB treats
             non-threaded target as single-threaded; add a main
             thread.  */
-         add_current_inferior_and_thread (wait_status);
+         thread_info *tp = add_current_inferior_and_thread (wait_status);
+         get_remote_thread_info (tp)->set_resumed ();
        }
       else
        {
index 46d27a1b52f69aaab7d77ac3a8f0a8ae4abf7c7c..f2c142e6b941524df775f2468809a9b10ffb4d6d 100644 (file)
@@ -1,3 +1,10 @@
+2021-02-25  Jan Matyas  <jmatyas@codasip.com>
+
+       PR gdb/26819
+       * gdb.server/stop-reply-no-thread.exp: Add two test
+       scenarios that cover remote targets which do not have
+       the concept of threads.
+
 2021-02-25  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.fortran/associated.exp: Add missing '-wrap' argument.
index 68bf42ac1a0001175c6f7c128055adca517690d2..823bdf894c095b373e82c60a77ae4a06c395f51e 100644 (file)
@@ -112,3 +112,13 @@ foreach_with_prefix to_disable { "" Tthread T } {
        run_test $to_disable $t_nonstop
     }
 }
+
+# Regression for PR gdb/26819: Cover the case when GDBserver does not report
+# any threads (i.e. the remote target has no concept of threads).
+#
+# Scenario 1: Disable 'T' and 'qfThreadInfo' packets
+# Scenario 2: Disable all threading packets
+foreach_with_prefix to_disable { "T,qfThreadInfo" "threads" } {
+    # Non-stop mode not applicable - off.
+    run_test $to_disable off
+}
This page took 0.052198 seconds and 4 git commands to generate.