gdb/remote: Restore support for 'S' stop reply packet
[deliverable/binutils-gdb.git] / gdb / remote.c
index 665e2773e15be3ae69da88bc4d38aae6030731d7..9b73faf9a3459ef28dbc6789e552dc5abf54dae1 100644 (file)
@@ -2411,6 +2411,9 @@ remote_target::remote_add_inferior (bool fake_pid_p, int pid, int attached,
   if (try_open_exec && get_exec_file (0) == NULL)
     exec_file_locate_attach (pid, 0, 1);
 
+  /* Check for exec file mismatch, and let the user solve it.  */
+  validate_exec_file (1);
+
   return inf;
 }
 
@@ -4446,8 +4449,8 @@ remote_target::process_initial_stop_replies (int from_tty)
          || ws.value.sig != GDB_SIGNAL_0)
        evthread->suspend.waitstatus_pending_p = 1;
 
-      set_executing (this, event_ptid, 0);
-      set_running (this, event_ptid, 0);
+      set_executing (this, event_ptid, false);
+      set_running (this, event_ptid, false);
       get_remote_thread_info (evthread)->vcont_resumed = 0;
     }
 
@@ -6842,9 +6845,9 @@ remote_console_output (const char *msg)
 
       tb[0] = c;
       tb[1] = 0;
-      fputs_unfiltered (tb, gdb_stdtarg);
+      gdb_stdtarg->puts (tb);
     }
-  gdb_flush (gdb_stdtarg);
+  gdb_stdtarg->flush ();
 }
 
 struct stop_reply : public notif_event
@@ -7399,18 +7402,14 @@ Packet: '%s'\n"),
                     reported expedited registers.  */
                  if (event->ptid == null_ptid)
                    {
+                     /* If there is no thread-id information then leave
+                        the event->ptid as null_ptid.  Later in
+                        process_stop_reply we will pick a suitable
+                        thread.  */
                      const char *thr = strstr (p1 + 1, ";thread:");
                      if (thr != NULL)
                        event->ptid = read_ptid (thr + strlen (";thread:"),
                                                 NULL);
-                     else
-                       {
-                         /* Either the current thread hasn't changed,
-                            or the inferior is not multi-threaded.
-                            The event must be for the thread we last
-                            set as (or learned as being) current.  */
-                         event->ptid = event->rs->general_thread;
-                       }
                    }
 
                  if (rsa == NULL)
@@ -7665,10 +7664,35 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply,
   *status = stop_reply->ws;
   ptid = stop_reply->ptid;
 
-  /* If no thread/process was reported by the stub, assume the current
-     inferior.  */
+  /* If no thread/process was reported by the stub then use the first
+     non-exited thread in the current target.  */
   if (ptid == null_ptid)
-    ptid = inferior_ptid;
+    {
+      for (thread_info *thr : all_non_exited_threads (this))
+       {
+         if (ptid != null_ptid)
+           {
+             static bool warned = false;
+
+             if (!warned)
+               {
+                 /* If you are seeing this warning then the remote target
+                    has multiple threads and either sent an 'S' stop
+                    packet, or a 'T' stop packet without a thread-id.  In
+                    both of these cases GDB is unable to know which thread
+                    just stopped and is now having to guess.  The correct
+                    action is to fix the remote target to send the correct
+                    packet (a 'T' packet and include a thread-id).  */
+                 warning (_("multi-threaded target stopped without sending "
+                            "a thread-id, using first non-exited thread"));
+                 warned = true;
+               }
+             break;
+           }
+         ptid = thr->ptid;
+       }
+      gdb_assert (ptid != null_ptid);
+    }
 
   if (status->kind != TARGET_WAITKIND_EXITED
       && status->kind != TARGET_WAITKIND_SIGNALLED
@@ -14312,8 +14336,9 @@ set_range_stepping (const char *ignore_args, int from_tty,
     }
 }
 
+void _initialize_remote ();
 void
-_initialize_remote (void)
+_initialize_remote ()
 {
   struct cmd_list_element *cmd;
   const char *cmd_name;
This page took 0.035072 seconds and 4 git commands to generate.