Add parameter to allow enabling/disabling selftests via configure
[deliverable/binutils-gdb.git] / gdb / gdbserver / server.c
index 3c58c6eb10d66c91aae7fe5c2e080e87a1895e34..4ec3548d64444ac11e5417f4d7b40acb6dcfe27d 100644 (file)
@@ -441,8 +441,8 @@ handle_btrace_general_set (char *own_buf)
 
   op = own_buf + strlen ("Qbtrace:");
 
-  if (ptid_equal (cs.general_thread, null_ptid)
-      || ptid_equal (cs.general_thread, minus_one_ptid))
+  if (cs.general_thread == null_ptid
+      || cs.general_thread == minus_one_ptid)
     {
       strcpy (own_buf, "E.Must select a single thread.");
       return -1;
@@ -491,8 +491,8 @@ handle_btrace_conf_general_set (char *own_buf)
 
   op = own_buf + strlen ("Qbtrace-conf:");
 
-  if (ptid_equal (cs.general_thread, null_ptid)
-      || ptid_equal (cs.general_thread, minus_one_ptid))
+  if (cs.general_thread == null_ptid
+      || cs.general_thread == minus_one_ptid)
     {
       strcpy (own_buf, "E.Must select a single thread.");
       return -1;
@@ -1195,34 +1195,37 @@ static void
 handle_detach (char *own_buf)
 {
   client_state &cs = get_client_state ();
-  require_running_or_return (own_buf);
 
-  int pid;
+  process_info *process;
 
   if (cs.multi_process)
     {
       /* skip 'D;' */
-      pid = strtol (&own_buf[2], NULL, 16);
+      int pid = strtol (&own_buf[2], NULL, 16);
+
+      process = find_process_pid (pid);
     }
   else
-    pid = current_ptid.pid ();
-
-  if ((tracing && disconnected_tracing) || any_persistent_commands ())
     {
-      struct process_info *process = find_process_pid (pid);
+      process = (current_thread != nullptr
+                ? get_thread_process (current_thread)
+                : nullptr);
+    }
 
-      if (process == NULL)
-       {
-         write_enn (own_buf);
-         return;
-       }
+  if (process == NULL)
+    {
+      write_enn (own_buf);
+      return;
+    }
 
+  if ((tracing && disconnected_tracing) || any_persistent_commands (process))
+    {
       if (tracing && disconnected_tracing)
        fprintf (stderr,
                 "Disconnected tracing in effect, "
                 "leaving gdbserver attached to the process\n");
 
-      if (any_persistent_commands ())
+      if (any_persistent_commands (process))
        fprintf (stderr,
                 "Persistent commands are present, "
                 "leaving gdbserver attached to the process\n");
@@ -1250,13 +1253,13 @@ handle_detach (char *own_buf)
       return;
     }
 
-  fprintf (stderr, "Detaching from process %d\n", pid);
+  fprintf (stderr, "Detaching from process %d\n", process->pid);
   stop_tracing ();
-  if (detach_inferior (pid) != 0)
+  if (detach_inferior (process) != 0)
     write_enn (own_buf);
   else
     {
-      discard_queued_stop_replies (ptid_t (pid));
+      discard_queued_stop_replies (ptid_t (process->pid));
       write_ok (own_buf);
 
       if (extended_protocol || target_running ())
@@ -1266,7 +1269,7 @@ handle_detach (char *own_buf)
             and instead treat this like a normal program exit.  */
          cs.last_status.kind = TARGET_WAITKIND_EXITED;
          cs.last_status.value.integer = 0;
-         cs.last_ptid = ptid_t (pid);
+         cs.last_ptid = ptid_t (process->pid);
 
          current_thread = NULL;
        }
@@ -1278,7 +1281,7 @@ handle_detach (char *own_buf)
          /* If we are attached, then we can exit.  Otherwise, we
             need to hang around doing nothing, until the child is
             gone.  */
-         join_inferior (pid);
+         join_inferior (process);
          exit (0);
        }
     }
@@ -1829,8 +1832,8 @@ handle_qxfer_btrace (const char *annex,
   if (writebuf != NULL)
     return -2;
 
-  if (ptid_equal (cs.general_thread, null_ptid)
-      || ptid_equal (cs.general_thread, minus_one_ptid))
+  if (cs.general_thread == null_ptid
+      || cs.general_thread == minus_one_ptid)
     {
       strcpy (cs.own_buf, "E.Must select a single thread.");
       return -3;
@@ -1913,8 +1916,8 @@ handle_qxfer_btrace_conf (const char *annex,
   if (annex[0] != '\0')
     return -1;
 
-  if (ptid_equal (cs.general_thread, null_ptid)
-      || ptid_equal (cs.general_thread, minus_one_ptid))
+  if (cs.general_thread == null_ptid
+      || cs.general_thread == minus_one_ptid)
     {
       strcpy (cs.own_buf, "E.Must select a single thread.");
       return -3;
@@ -2696,8 +2699,8 @@ visit_actioned_threads (thread_info *thread,
     {
       const struct thread_resume *action = &actions[i];
 
-      if (ptid_equal (action->thread, minus_one_ptid)
-         || ptid_equal (action->thread, thread->id)
+      if (action->thread == minus_one_ptid
+         || action->thread == thread->id
          || ((action->thread.pid ()
               == thread->id.pid ())
              && action->thread.lwp () == -1))
@@ -3077,7 +3080,10 @@ handle_v_kill (char *own_buf)
     pid = strtol (p, NULL, 16);
   else
     pid = signal_pid;
-  if (pid != 0 && kill_inferior (pid) == 0)
+
+  process_info *proc = find_process_pid (pid);
+
+  if (proc != nullptr && kill_inferior (proc) == 0)
     {
       cs.last_status.kind = TARGET_WAITKIND_SIGNALLED;
       cs.last_status.value.sig = GDB_SIGNAL_KILL;
@@ -3199,8 +3205,8 @@ myresume (char *own_buf, int step, int sig)
   int n = 0;
   int valid_cont_thread;
 
-  valid_cont_thread = (!ptid_equal (cs.cont_thread, null_ptid)
-                        && !ptid_equal (cs.cont_thread, minus_one_ptid));
+  valid_cont_thread = (cs.cont_thread != null_ptid
+                        && cs.cont_thread != minus_one_ptid);
 
   if (step || sig || valid_cont_thread)
     {
@@ -3361,9 +3367,9 @@ handle_status (char *own_buf)
       /* If the last event thread is not found for some reason, look
         for some other thread that might have an event to report.  */
       if (thread == NULL)
-       thread = find_thread ([] (thread_info *thread)
+       thread = find_thread ([] (thread_info *thr_arg)
          {
-           return thread->status_pending_p;
+           return thr_arg->status_pending_p;
          });
 
       /* If we're still out of luck, simply pick the first thread in
@@ -3478,10 +3484,8 @@ gdbserver_show_disableable (FILE *stream)
 static void
 kill_inferior_callback (process_info *process)
 {
-  int pid = process->pid;
-
-  kill_inferior (pid);
-  discard_queued_stop_replies (ptid_t (pid));
+  kill_inferior (process);
+  discard_queued_stop_replies (ptid_t (process->pid));
 }
 
 /* Call this when exiting gdbserver with possible inferiors that need
@@ -3523,9 +3527,9 @@ detach_or_kill_for_exit (void)
     int pid = process->pid;
 
     if (process->attached)
-      detach_inferior (pid);
+      detach_inferior (process);
     else
-      kill_inferior (pid);
+      kill_inferior (process);
 
     discard_queued_stop_replies (ptid_t (pid));
   });
@@ -3786,7 +3790,7 @@ captured_main (int argc, char *argv[])
 #if GDB_SELF_TEST
       selftests::run_tests (selftest_filter);
 #else
-      printf (_("Selftests are not available in a non-development build.\n"));
+      printf (_("Selftests have been disabled for this build.\n"));
 #endif
       throw_quit ("Quit");
     }
@@ -4024,7 +4028,6 @@ process_serial_event (void)
   client_state &cs = get_client_state ();
   int signal;
   unsigned int len;
-  int res;
   CORE_ADDR mem_addr;
   unsigned char sig;
   int packet_len;
@@ -4095,7 +4098,7 @@ process_serial_event (void)
 
          if (cs.own_buf[1] == 'g')
            {
-             if (ptid_equal (thread_id, null_ptid))
+             if (thread_id == null_ptid)
                {
                  /* GDB is telling us to choose any thread.  Check if
                     the currently selected thread is still valid. If
@@ -4168,13 +4171,15 @@ process_serial_event (void)
        }
       break;
     case 'm':
-      require_running_or_break (cs.own_buf);
-      decode_m_packet (&cs.own_buf[1], &mem_addr, &len);
-      res = gdb_read_memory (mem_addr, mem_buf, len);
-      if (res < 0)
-       write_enn (cs.own_buf);
-      else
-       bin2hex (mem_buf, cs.own_buf, res);
+      {
+       require_running_or_break (cs.own_buf);
+       decode_m_packet (&cs.own_buf[1], &mem_addr, &len);
+       int res = gdb_read_memory (mem_addr, mem_buf, len);
+       if (res < 0)
+         write_enn (cs.own_buf);
+       else
+         bin2hex (mem_buf, cs.own_buf, res);
+      }
       break;
     case 'M':
       require_running_or_break (cs.own_buf);
This page took 0.028042 seconds and 4 git commands to generate.