gdbserver: set ptrace flags after creating inferiors
[deliverable/binutils-gdb.git] / gdb / gdbserver / server.c
index 0762f6aba4450fe7d9f74dd77a3cd19acedab2c1..6d151ee35d39f4654db6a86f9edf4b6a30786aaf 100644 (file)
@@ -61,6 +61,10 @@ int report_fork_events;
 int report_vfork_events;
 int report_exec_events;
 int report_thread_events;
+
+/* Whether to report TARGET_WAITKING_NO_RESUMED events.  */
+static int report_no_resumed;
+
 int non_stop;
 int swbreak_feature;
 int hwbreak_feature;
@@ -278,7 +282,7 @@ start_inferior (char **argv)
            }
          while (last_status.value.sig != GDB_SIGNAL_TRAP);
        }
-      target_arch_setup ();
+      target_post_create_inferior ();
       return signal_pid;
     }
 
@@ -286,7 +290,7 @@ start_inferior (char **argv)
      (assuming success).  */
   last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
 
-  target_arch_setup ();
+  target_post_create_inferior ();
 
   if (last_status.kind != TARGET_WAITKIND_EXITED
       && last_status.kind != TARGET_WAITKIND_SIGNALLED)
@@ -2187,6 +2191,12 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
                vCont_supported = 1;
              else if (strcmp (p, "QThreadEvents+") == 0)
                ;
+             else if (strcmp (p, "no-resumed+") == 0)
+               {
+                 /* GDB supports and wants TARGET_WAITKIND_NO_RESUMED
+                    events.  */
+                 report_no_resumed = 1;
+               }
              else
                {
                  /* Move the unknown features all together.  */
@@ -2309,6 +2319,8 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 
       strcat (own_buf, ";QThreadEvents+");
 
+      strcat (own_buf, ";no-resumed+");
+
       /* Reinitialize components as needed for the new connection.  */
       hostio_handle_new_gdb_connection ();
       target_handle_new_gdb_connection ();
@@ -2716,10 +2728,11 @@ resume (struct thread_resume *actions, size_t num_actions)
     {
       last_ptid = mywait (minus_one_ptid, &last_status, 0, 1);
 
-      if (last_status.kind == TARGET_WAITKIND_NO_RESUMED)
+      if (last_status.kind == TARGET_WAITKIND_NO_RESUMED
+         && !report_no_resumed)
        {
-         /* No proper RSP support for this yet.  At least return
-            error.  */
+         /* The client does not support this stop reply.  At least
+            return error.  */
          sprintf (own_buf, "E.No unwaited-for children left.");
          disable_async_io ();
          return;
@@ -3678,11 +3691,21 @@ captured_main (int argc, char *argv[])
          start_event_loop ();
 
          /* If an exit was requested (using the "monitor exit"
-            command), terminate now.  The only other way to get
-            here is for getpkt to fail; close the connection
-            and reopen it at the top of the loop.  */
+            command), terminate now.  */
+         if (exit_requested)
+           throw_quit ("Quit");
+
+         /* The only other way to get here is for getpkt to fail:
 
-         if (exit_requested || run_once)
+             - If --once was specified, we're done.
+
+             - If not in extended-remote mode, and we're no longer
+               debugging anything, simply exit: GDB has disconnected
+               after processing the last process exit.
+
+             - Otherwise, close the connection and reopen it at the
+               top of the loop.  */
+         if (run_once || (!extended_protocol && !target_running ()))
            throw_quit ("Quit");
 
          fprintf (stderr,
@@ -3847,13 +3870,6 @@ process_serial_event (void)
   int packet_len;
   int new_packet_len = -1;
 
-  /* Used to decide when gdbserver should exit in
-     multi-mode/remote.  */
-  static int have_ran = 0;
-
-  if (!have_ran)
-    have_ran = target_running ();
-
   disable_async_io ();
 
   response_needed = 0;
@@ -4292,21 +4308,6 @@ process_serial_event (void)
 
   response_needed = 0;
 
-  if (!extended_protocol && have_ran && !target_running ())
-    {
-      /* In non-stop, defer exiting until GDB had a chance to query
-        the whole vStopped list (until it gets an OK).  */
-      if (QUEUE_is_empty (notif_event_p, notif_stop.queue))
-       {
-         /* Be transparent when GDB is connected through stdio -- no
-            need to spam GDB's console.  */
-         if (!remote_connection_is_stdio ())
-           fprintf (stderr, "GDBserver exiting\n");
-         remote_close ();
-         exit (0);
-       }
-    }
-
   if (exit_requested)
     return -1;
 
@@ -4332,6 +4333,19 @@ handle_serial_event (int err, gdb_client_data client_data)
   return 0;
 }
 
+/* Push a stop notification on the notification queue.  */
+
+static void
+push_stop_notification (ptid_t ptid, struct target_waitstatus *status)
+{
+  struct vstop_notif *vstop_notif = XNEW (struct vstop_notif);
+
+  vstop_notif->status = *status;
+  vstop_notif->ptid = ptid;
+  /* Push Stop notification.  */
+  notif_push (&notif_stop, (struct notif_event *) vstop_notif);
+}
+
 /* Event-loop callback for target events.  */
 
 int
@@ -4345,7 +4359,8 @@ handle_target_event (int err, gdb_client_data client_data)
 
   if (last_status.kind == TARGET_WAITKIND_NO_RESUMED)
     {
-      /* No RSP support for this yet.  */
+      if (gdb_connected () && report_no_resumed)
+       push_stop_notification (null_ptid, &last_status);
     }
   else if (last_status.kind != TARGET_WAITKIND_IGNORE)
     {
@@ -4405,15 +4420,7 @@ handle_target_event (int err, gdb_client_data client_data)
            }
        }
       else
-       {
-         struct vstop_notif *vstop_notif = XNEW (struct vstop_notif);
-
-         vstop_notif->status = last_status;
-         vstop_notif->ptid = last_ptid;
-         /* Push Stop notification.  */
-         notif_push (&notif_stop,
-                     (struct notif_event *) vstop_notif);
-       }
+       push_stop_notification (last_ptid, &last_status);
     }
 
   /* Be sure to not change the selected thread behind GDB's back.
This page took 0.027807 seconds and 4 git commands to generate.