gdb: fix vfork with multiple threads
[deliverable/binutils-gdb.git] / gdb / remote.c
index c09d714087596fcfdcdc07f0c136120d9d98b687..d8c4adc1edd70e876d5112cc75426a388fe5140b 100644 (file)
@@ -957,6 +957,8 @@ public: /* Remote specific methods.  */
 
   void packet_command (const char *args, int from_tty);
 
+  void commit_resumed (ptid_t filter);
+
 private: /* data fields */
 
   /* The remote state.  Don't reference this directly.  Use the
@@ -2494,9 +2496,11 @@ remote_target::remote_add_inferior (bool fake_pid_p, int pid, int attached,
        }
       if (inf == nullptr)
        {
+         gdb_assert(0);
          /* Since all inferiors were already bound to a process, add
             a new inferior.  */
          inf = add_inferior_with_spaces ();
+
        }
       switch_to_inferior_no_thread (inf);
       inf->push_target (this);
@@ -4591,7 +4595,7 @@ remote_target::process_initial_stop_replies (int from_tty)
      the inferiors.  */
   if (!non_stop)
     {
-      stop_all_threads ();
+      stop_all_threads ("remote connect in all-stop");
 
       /* If all threads of an inferior were already stopped, we
         haven't setup the inferior yet.  */
@@ -6665,6 +6669,12 @@ vcont_builder::push_action (ptid_t ptid, bool step, gdb_signal siggnal)
 
 void
 remote_target::commit_resumed ()
+{
+  this->commit_resumed (minus_one_ptid);
+}
+
+void
+remote_target::commit_resumed (ptid_t filter)
 {
   /* If connected in all-stop mode, we'd send the remote resume
      request directly from remote_resume.  Likewise if
@@ -6722,14 +6732,14 @@ remote_target::commit_resumed ()
      (vCont;c).  We can still send process-wide wildcards though.  */
 
   /* Start by assuming a global wildcard (vCont;c) is possible.  */
-  bool may_global_wildcard_vcont = true;
+  bool may_global_wildcard_vcont = filter == minus_one_ptid;
 
   /* And assume every process is individually wildcard-able too.  */
   for (inferior *inf : all_non_exited_inferiors (this))
     {
       remote_inferior *priv = get_remote_inferior (inf);
 
-      priv->may_wildcard_vcont = true;
+      priv->may_wildcard_vcont = filter == minus_one_ptid || (filter.is_pid () && inf->pid == filter.pid ());
     }
 
   /* Check for any pending events (not reported or processed yet) and
@@ -6738,7 +6748,7 @@ remote_target::commit_resumed ()
 
   bool any_pending_vcont_resume = false;
 
-  for (thread_info *tp : all_non_exited_threads (this))
+  for (thread_info *tp : all_non_exited_threads (this, filter))
     {
       remote_thread_info *priv = get_remote_thread_info (tp);
 
@@ -6777,7 +6787,7 @@ remote_target::commit_resumed ()
   struct vcont_builder vcont_builder (this);
 
   /* Threads first.  */
-  for (thread_info *tp : all_non_exited_threads (this))
+  for (thread_info *tp : all_non_exited_threads (this, filter))
     {
       remote_thread_info *remote_thr = get_remote_thread_info (tp);
 
@@ -6907,7 +6917,7 @@ remote_target::remote_stop_ns (ptid_t ptid)
     }
 
   if (needs_commit)
-    commit_resumed ();
+    commit_resumed (ptid);
   else
     for (thread_info *tp : all_non_exited_threads (this, ptid))
       {
@@ -9990,6 +10000,9 @@ remote_target::getpkt_or_notif_sane_1 (gdb::char_vector *buf,
          /* We have tried hard enough, and just can't receive the
             packet/notification.  Give up.  */
          printf_unfiltered (_("Ignoring packet error, continuing...\n"));
+         gdb_assert(0);
+
+
 
          /* Skip the ack char if we're in no-ack mode.  */
          if (!rs->noack_mode)
@@ -10223,10 +10236,16 @@ remote_target::mourn_inferior ()
   discard_pending_stop_replies (current_inferior ());
 
   /* In 'target remote' mode with one inferior, we close the connection.  */
-  if (!rs->extended && number_of_live_inferiors (this) <= 1)
+  if (!rs->extended)
     {
-      remote_unpush_target (this);
-      return;
+      // needed to make the test not hang at exit with native-gdbserver, should be investigated
+      if (number_of_live_inferiors (this) <= 1)
+       {
+         remote_unpush_target (this);
+         return;
+       }
+      else
+       pop_all_targets_at_and_above (process_stratum);
     }
 
   /* In case we got here due to an error, but we're going to stay
@@ -12277,6 +12296,9 @@ remote_target::remote_hostio_open (inferior *inf, const char *filename,
   char *p = rs->buf.data ();
   int left = get_remote_packet_size () - 1;
 
+  REMOTE_SCOPED_DEBUG_ENTER_EXIT;
+  remote_debug_printf ("inf=%d, filename=%s", inf != nullptr ? inf->num : -1, filename);
+
   if (warn_if_slow)
     {
       static int warning_issued = 0;
This page took 0.026592 seconds and 4 git commands to generate.