Add support for enabling and disabling tracepoints while a trace
[deliverable/binutils-gdb.git] / gdb / gdbserver / server.c
index 8a19809d7cac2eadcc3743caab204d3542a990e8..fd06c8f9a2a0ec0ea149a0996e41db39e314d5b6 100644 (file)
@@ -40,6 +40,9 @@ static int extended_protocol;
 static int response_needed;
 static int exit_requested;
 
+/* --once: Exit after the first connection has closed.  */
+int run_once;
+
 int multi_process;
 int non_stop;
 
@@ -1537,6 +1540,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
          strcat (own_buf, ";StaticTracepoints+");
          strcat (own_buf, ";qXfer:statictrace:read+");
          strcat (own_buf, ";qXfer:traceframe-info:read+");
+         strcat (own_buf, ";EnableDisableTracepoints+");
        }
 
       return;
@@ -1949,16 +1953,16 @@ handle_v_run (char *own_buf)
 
       if (program_argv == NULL)
        {
-         /* FIXME: new_argv memory leak */
          write_enn (own_buf);
+         freeargv (new_argv);
          return 0;
        }
 
       new_argv[0] = strdup (program_argv[0]);
       if (new_argv[0] == NULL)
        {
-         /* FIXME: new_argv memory leak */
          write_enn (own_buf);
+         freeargv (new_argv);
          return 0;
        }
     }
@@ -2312,7 +2316,9 @@ gdbserver_usage (FILE *stream)
           "  --debug               Enable general debugging output.\n"
           "  --remote-debug        Enable remote protocol debugging output.\n"
           "  --version             Display version information and exit.\n"
-          "  --wrapper WRAPPER --  Run WRAPPER to start new programs.\n");
+          "  --wrapper WRAPPER --  Run WRAPPER to start new programs.\n"
+          "  --once                Exit after the first connection has "
+                                                                 "closed.\n");
   if (REPORT_BUGS_TO[0] && stream == stdout)
     fprintf (stream, "Report bugs to \"%s\".\n", REPORT_BUGS_TO);
 }
@@ -2437,17 +2443,6 @@ detach_or_kill_for_exit (void)
   for_each_inferior (&all_processes, detach_or_kill_inferior_callback);
 }
 
-static void
-join_inferiors_callback (struct inferior_list_entry *entry)
-{
-  struct process_info *process = (struct process_info *) entry;
-
-  /* If we are attached, then we can exit.  Otherwise, we need to hang
-     around doing nothing, until the child is gone.  */
-  if (!process->attached)
-    join_inferior (ptid_get_pid (process->head.id));
-}
-
 int
 main (int argc, char *argv[])
 {
@@ -2536,6 +2531,8 @@ main (int argc, char *argv[])
                }
            }
        }
+      else if (strcmp (*next_arg, "--once") == 0)
+       run_once = 1;
       else
        {
          fprintf (stderr, "Unknown argument: %s\n", *next_arg);
@@ -2648,6 +2645,8 @@ main (int argc, char *argv[])
       exit (1);
     }
 
+  remote_prepare (port);
+
   while (1)
     {
       noack_mode = 0;
@@ -2676,7 +2675,7 @@ main (int argc, char *argv[])
         getpkt to fail; close the connection and reopen it at the
         top of the loop.  */
 
-      if (exit_requested)
+      if (exit_requested || run_once)
        {
          detach_or_kill_for_exit ();
          exit (0);
@@ -2842,8 +2841,7 @@ process_serial_event (void)
              /* If we are attached, then we can exit.  Otherwise, we
                 need to hang around doing nothing, until the child is
                 gone.  */
-             for_each_inferior (&all_processes,
-                                join_inferiors_callback);
+             join_inferior (pid);
              exit (0);
            }
        }
This page took 0.025653 seconds and 4 git commands to generate.