Initialise target descrption after skipping extra traps for --wrapper
[deliverable/binutils-gdb.git] / gdb / gdbserver / server.c
index 83529ffcd4cad36bb289ea041bc3cc9906a43359..29187704c1972e021b1fceb77d01ee5b659c2ae1 100644 (file)
@@ -57,6 +57,8 @@ static int exit_requested;
 int run_once;
 
 int multi_process;
+int report_fork_events;
+int report_vfork_events;
 int non_stop;
 int swbreak_feature;
 int hwbreak_feature;
@@ -255,22 +257,22 @@ start_inferior (char **argv)
 
       last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
 
-      if (last_status.kind != TARGET_WAITKIND_STOPPED)
-       return signal_pid;
-
-      do
+      if (last_status.kind == TARGET_WAITKIND_STOPPED)
        {
-         (*the_target->resume) (&resume_info, 1);
+         do
+           {
+             (*the_target->resume) (&resume_info, 1);
 
-         last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
-         if (last_status.kind != TARGET_WAITKIND_STOPPED)
-           return signal_pid;
+             last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
+             if (last_status.kind != TARGET_WAITKIND_STOPPED)
+               break;
 
-         current_thread->last_resume_kind = resume_stop;
-         current_thread->last_status = last_status;
+             current_thread->last_resume_kind = resume_stop;
+             current_thread->last_status = last_status;
+           }
+         while (last_status.value.sig != GDB_SIGNAL_TRAP);
        }
-      while (last_status.value.sig != GDB_SIGNAL_TRAP);
-
+      target_arch_setup ();
       return signal_pid;
     }
 
@@ -278,12 +280,16 @@ start_inferior (char **argv)
      (assuming success).  */
   last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
 
+  target_arch_setup ();
+
   if (last_status.kind != TARGET_WAITKIND_EXITED
       && last_status.kind != TARGET_WAITKIND_SIGNALLED)
     {
       current_thread->last_resume_kind = resume_stop;
       current_thread->last_status = last_status;
     }
+  else
+    mourn_inferior (find_process_pid (ptid_get_pid (last_ptid)));
 
   return signal_pid;
 }
@@ -383,8 +389,8 @@ write_qxfer_response (char *buf, const void *data, int len, int is_more)
   else
     buf[0] = 'l';
 
-  return remote_escape_output (data, len, (unsigned char *) buf + 1, &out_len,
-                              PBUFSIZ - 2) + 1;
+  return remote_escape_output (data, len, 1, (unsigned char *) buf + 1,
+                              &out_len, PBUFSIZ - 2) + 1;
 }
 
 /* Handle btrace enabling in BTS format.  */
@@ -404,6 +410,23 @@ handle_btrace_enable_bts (struct thread_info *thread)
   return NULL;
 }
 
+/* Handle btrace enabling in Intel(R) Processor Trace format.  */
+
+static const char *
+handle_btrace_enable_pt (struct thread_info *thread)
+{
+  if (thread->btrace != NULL)
+    return "E.Btrace already enabled.";
+
+  current_btrace_conf.format = BTRACE_FORMAT_PT;
+  thread->btrace = target_enable_btrace (thread->entry.id,
+                                        &current_btrace_conf);
+  if (thread->btrace == NULL)
+    return "E.Could not enable btrace.";
+
+  return NULL;
+}
+
 /* Handle btrace disabling.  */
 
 static const char *
@@ -429,7 +452,7 @@ handle_btrace_general_set (char *own_buf)
   const char *err;
   char *op;
 
-  if (strncmp ("Qbtrace:", own_buf, strlen ("Qbtrace:")) != 0)
+  if (!startswith (own_buf, "Qbtrace:"))
     return 0;
 
   op = own_buf + strlen ("Qbtrace:");
@@ -452,10 +475,12 @@ handle_btrace_general_set (char *own_buf)
 
   if (strcmp (op, "bts") == 0)
     err = handle_btrace_enable_bts (thread);
+  else if (strcmp (op, "pt") == 0)
+    err = handle_btrace_enable_pt (thread);
   else if (strcmp (op, "off") == 0)
     err = handle_btrace_disable (thread);
   else
-    err = "E.Bad Qbtrace operation. Use bts or off.";
+    err = "E.Bad Qbtrace operation. Use bts, pt, or off.";
 
   if (err != 0)
     strcpy (own_buf, err);
@@ -473,7 +498,7 @@ handle_btrace_conf_general_set (char *own_buf)
   struct thread_info *thread;
   char *op;
 
-  if (strncmp ("Qbtrace-conf:", own_buf, strlen ("Qbtrace-conf:")) != 0)
+  if (!startswith (own_buf, "Qbtrace-conf:"))
     return 0;
 
   op = own_buf + strlen ("Qbtrace-conf:");
@@ -492,7 +517,7 @@ handle_btrace_conf_general_set (char *own_buf)
       return -1;
     }
 
-  if (strncmp (op, "bts:size=", strlen ("bts:size=")) == 0)
+  if (startswith (op, "bts:size="))
     {
       unsigned long size;
       char *endp = NULL;
@@ -507,6 +532,21 @@ handle_btrace_conf_general_set (char *own_buf)
 
       current_btrace_conf.bts.size = (unsigned int) size;
     }
+  else if (strncmp (op, "pt:size=", strlen ("pt:size=")) == 0)
+    {
+      unsigned long size;
+      char *endp = NULL;
+
+      errno = 0;
+      size = strtoul (op + strlen ("pt:size="), &endp, 16);
+      if (endp == NULL || *endp != 0 || errno != 0 || size > UINT_MAX)
+       {
+         strcpy (own_buf, "E.Bad size value.");
+         return -1;
+       }
+
+      current_btrace_conf.pt.size = (unsigned int) size;
+    }
   else
     {
       strcpy (own_buf, "E.Bad Qbtrace configuration option.");
@@ -522,7 +562,7 @@ handle_btrace_conf_general_set (char *own_buf)
 static void
 handle_general_set (char *own_buf)
 {
-  if (strncmp ("QPassSignals:", own_buf, strlen ("QPassSignals:")) == 0)
+  if (startswith (own_buf, "QPassSignals:"))
     {
       int numsigs = (int) GDB_SIGNAL_LAST, i;
       const char *p = own_buf + strlen ("QPassSignals:");
@@ -547,7 +587,7 @@ handle_general_set (char *own_buf)
       return;
     }
 
-  if (strncmp ("QProgramSignals:", own_buf, strlen ("QProgramSignals:")) == 0)
+  if (startswith (own_buf, "QProgramSignals:"))
     {
       int numsigs = (int) GDB_SIGNAL_LAST, i;
       const char *p = own_buf + strlen ("QProgramSignals:");
@@ -587,11 +627,11 @@ handle_general_set (char *own_buf)
       return;
     }
 
-  if (strncmp (own_buf, "QNonStop:", 9) == 0)
+  if (startswith (own_buf, "QNonStop:"))
     {
       char *mode = own_buf + 9;
       int req = -1;
-      char *req_str;
+      const char *req_str;
 
       if (strcmp (mode, "0") == 0)
        req = 0;
@@ -624,8 +664,7 @@ handle_general_set (char *own_buf)
       return;
     }
 
-  if (strncmp ("QDisableRandomization:", own_buf,
-              strlen ("QDisableRandomization:")) == 0)
+  if (startswith (own_buf, "QDisableRandomization:"))
     {
       char *packet = own_buf + strlen ("QDisableRandomization:");
       ULONGEST setting;
@@ -649,7 +688,7 @@ handle_general_set (char *own_buf)
       && handle_tracepoint_general_set (own_buf))
     return;
 
-  if (strncmp ("QAgent:", own_buf, strlen ("QAgent:")) == 0)
+  if (startswith (own_buf, "QAgent:"))
     {
       char *mode = own_buf + strlen ("QAgent:");
       int req = 0;
@@ -1072,8 +1111,7 @@ handle_monitor_command (char *mon, char *own_buf)
       remote_debug = 0;
       monitor_output ("Protocol debug output disabled.\n");
     }
-  else if (strncmp (mon, "set debug-format ",
-                   sizeof ("set debug-format ") - 1) == 0)
+  else if (startswith (mon, "set debug-format "))
     {
       char *error_msg
        = parse_debug_format_options (mon + sizeof ("set debug-format ") - 1,
@@ -1139,6 +1177,57 @@ handle_qxfer_auxv (const char *annex,
   return (*the_target->read_auxv) (offset, readbuf, len);
 }
 
+/* Handle qXfer:exec-file:read.  */
+
+static int
+handle_qxfer_exec_file (const char *const_annex,
+                       gdb_byte *readbuf, const gdb_byte *writebuf,
+                       ULONGEST offset, LONGEST len)
+{
+  char *file;
+  ULONGEST pid;
+  int total_len;
+
+  if (the_target->pid_to_exec_file == NULL || writebuf != NULL)
+    return -2;
+
+  if (const_annex[0] == '\0')
+    {
+      if (current_thread == NULL)
+       return -1;
+
+      pid = pid_of (current_thread);
+    }
+  else
+    {
+      char *annex = alloca (strlen (const_annex) + 1);
+
+      strcpy (annex, const_annex);
+      annex = unpack_varlen_hex (annex, &pid);
+
+      if (annex[0] != '\0')
+       return -1;
+    }
+
+  if (pid <= 0)
+    return -1;
+
+  file = (*the_target->pid_to_exec_file) (pid);
+  if (file == NULL)
+    return -1;
+
+  total_len = strlen (file);
+
+  if (offset > total_len)
+    return -1;
+
+  if (offset + len > total_len)
+    len = total_len - offset;
+
+  memcpy (readbuf, file + offset, len);
+  return len;
+}
+
 /* Handle qXfer:features:read.  */
 
 static int
@@ -1238,7 +1327,7 @@ handle_qxfer_libraries (const char *annex,
   if (document == NULL)
     return -1;
 
-  strcpy (document, "<library-list>\n");
+  strcpy (document, "<library-list version=\"1.0\">\n");
   p = document + strlen (document);
 
   for_each_inferior_with_data (&all_dlls, emit_dll_description, &p);
@@ -1640,6 +1729,7 @@ static const struct qxfer qxfer_packets[] =
     { "auxv", handle_qxfer_auxv },
     { "btrace", handle_qxfer_btrace },
     { "btrace-conf", handle_qxfer_btrace_conf },
+    { "exec-file", handle_qxfer_exec_file},
     { "fdpic", handle_qxfer_fdpic},
     { "features", handle_qxfer_features },
     { "libraries", handle_qxfer_libraries },
@@ -1661,7 +1751,7 @@ handle_qxfer (char *own_buf, int packet_len, int *new_packet_len_p)
   char *annex;
   char *offset;
 
-  if (strncmp (own_buf, "qXfer:", 6) != 0)
+  if (!startswith (own_buf, "qXfer:"))
     return 0;
 
   /* Grab the object, r/w and annex.  */
@@ -1817,12 +1907,25 @@ crc32 (CORE_ADDR base, int len, unsigned int crc)
 static void
 supported_btrace_packets (char *buf)
 {
+  int btrace_supported = 0;
+
   if (target_supports_btrace (BTRACE_FORMAT_BTS))
     {
       strcat (buf, ";Qbtrace:bts+");
       strcat (buf, ";Qbtrace-conf:bts:size+");
+
+      btrace_supported = 1;
     }
-  else
+
+  if (target_supports_btrace (BTRACE_FORMAT_PT))
+    {
+      strcat (buf, ";Qbtrace:pt+");
+      strcat (buf, ";Qbtrace-conf:pt:size+");
+
+      btrace_supported = 1;
+    }
+
+  if (!btrace_supported)
     return;
 
   strcat (buf, ";Qbtrace:off+");
@@ -1935,7 +2038,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
     }
 
   /* Protocol features query.  */
-  if (strncmp ("qSupported", own_buf, 10) == 0
+  if (startswith (own_buf, "qSupported")
       && (own_buf[10] == ':' || own_buf[10] == '\0'))
     {
       char *p = &own_buf[10];
@@ -1994,6 +2097,18 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
                  if (target_supports_stopped_by_hw_breakpoint ())
                    hwbreak_feature = 1;
                }
+             else if (strcmp (p, "fork-events+") == 0)
+               {
+                 /* GDB supports and wants fork events if possible.  */
+                 if (target_supports_fork_events ())
+                   report_fork_events = 1;
+               }
+             else if (strcmp (p, "vfork-events+") == 0)
+               {
+                 /* GDB supports and wants vfork events if possible.  */
+                 if (target_supports_vfork_events ())
+                   report_vfork_events = 1;
+               }
              else
                target_process_qsupported (p);
 
@@ -2044,6 +2159,12 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (target_supports_multi_process ())
        strcat (own_buf, ";multiprocess+");
 
+      if (target_supports_fork_events ())
+       strcat (own_buf, ";fork-events+");
+
+      if (target_supports_vfork_events ())
+       strcat (own_buf, ";vfork-events+");
+
       if (target_supports_non_stop ())
        strcat (own_buf, ";QNonStop+");
 
@@ -2070,7 +2191,8 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
        }
 
       /* Support target-side breakpoint conditions and commands.  */
-      strcat (own_buf, ";ConditionalBreakpoints+");
+      if (target_supports_conditional_breakpoints ())
+       strcat (own_buf, ";ConditionalBreakpoints+");
       strcat (own_buf, ";BreakpointCommands+");
 
       if (target_supports_agent ())
@@ -2084,12 +2206,19 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (target_supports_stopped_by_hw_breakpoint ())
        strcat (own_buf, ";hwbreak+");
 
+      if (the_target->pid_to_exec_file != NULL)
+       strcat (own_buf, ";qXfer:exec-file:read+");
+
+      /* Reinitialize components as needed for the new connection.  */
+      hostio_handle_new_gdb_connection ();
+      target_handle_new_gdb_connection ();
+
       return;
     }
 
   /* Thread-local storage support.  */
   if (the_target->get_tls_address != NULL
-      && strncmp ("qGetTLSAddr:", own_buf, 12) == 0)
+      && startswith (own_buf, "qGetTLSAddr:"))
     {
       char *p = own_buf + 12;
       CORE_ADDR parts[2], address = 0;
@@ -2154,7 +2283,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 
   /* Windows OS Thread Information Block address support.  */
   if (the_target->get_tib_address != NULL
-      && strncmp ("qGetTIBAddr:", own_buf, 12) == 0)
+      && startswith (own_buf, "qGetTIBAddr:"))
     {
       char *annex;
       int n;
@@ -2176,7 +2305,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
     }
 
   /* Handle "monitor" commands.  */
-  if (strncmp ("qRcmd,", own_buf, 6) == 0)
+  if (startswith (own_buf, "qRcmd,"))
     {
       char *mon = malloc (PBUFSIZ);
       int len = strlen (own_buf + 6);
@@ -2207,8 +2336,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       return;
     }
 
-  if (strncmp ("qSearch:memory:", own_buf,
-              sizeof ("qSearch:memory:") - 1) == 0)
+  if (startswith (own_buf, "qSearch:memory:"))
     {
       require_running (own_buf);
       handle_search_memory (own_buf, packet_len);
@@ -2216,7 +2344,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
     }
 
   if (strcmp (own_buf, "qAttached") == 0
-      || strncmp (own_buf, "qAttached:", sizeof ("qAttached:") - 1) == 0)
+      || startswith (own_buf, "qAttached:"))
     {
       struct process_info *process;
 
@@ -2242,7 +2370,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       return;
     }
 
-  if (strncmp ("qCRC:", own_buf, 5) == 0)
+  if (startswith (own_buf, "qCRC:"))
     {
       /* CRC check (compare-section).  */
       char *comma;
@@ -2672,14 +2800,14 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
 {
   if (!disable_packet_vCont)
     {
-      if (strncmp (own_buf, "vCont;", 6) == 0)
+      if (startswith (own_buf, "vCont;"))
        {
          require_running (own_buf);
          handle_v_cont (own_buf);
          return;
        }
 
-      if (strncmp (own_buf, "vCont?", 6) == 0)
+      if (startswith (own_buf, "vCont?"))
        {
          strcpy (own_buf, "vCont;c;C;s;S;t");
          if (target_supports_range_stepping ())
@@ -2691,11 +2819,11 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
        }
     }
 
-  if (strncmp (own_buf, "vFile:", 6) == 0
+  if (startswith (own_buf, "vFile:")
       && handle_vFile (own_buf, packet_len, new_packet_len))
     return;
 
-  if (strncmp (own_buf, "vAttach;", 8) == 0)
+  if (startswith (own_buf, "vAttach;"))
     {
       if ((!extended_protocol || !multi_process) && target_running ())
        {
@@ -2707,7 +2835,7 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
       return;
     }
 
-  if (strncmp (own_buf, "vRun;", 5) == 0)
+  if (startswith (own_buf, "vRun;"))
     {
       if ((!extended_protocol || !multi_process) && target_running ())
        {
@@ -2719,7 +2847,7 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
       return;
     }
 
-  if (strncmp (own_buf, "vKill;", 6) == 0)
+  if (startswith (own_buf, "vKill;"))
     {
       if (!target_running ())
        {
@@ -2999,10 +3127,32 @@ gdbserver_usage (FILE *stream)
           "\tgdbserver [OPTIONS] --attach COMM PID\n"
           "\tgdbserver [OPTIONS] --multi COMM\n"
           "\n"
-          "COMM may either be a tty device (for serial debugging), or \n"
-          "HOST:PORT to listen for a TCP connection.\n"
+          "COMM may either be a tty device (for serial debugging),\n"
+          "HOST:PORT to listen for a TCP connection, or '-' or 'stdio' to use \n"
+          "stdin/stdout of gdbserver.\n"
+          "PROG is the executable program.  ARGS are arguments passed to inferior.\n"
+          "PID is the process ID to attach to, when --attach is specified.\n"
+          "\n"
+          "Operating modes:\n"
+          "\n"
+          "  --attach              Attach to running process PID.\n"
+          "  --multi               Start server without a specific program, and\n"
+          "                        only quit when explicitly commanded.\n"
+          "  --once                Exit after the first connection has closed.\n"
+          "  --help                Print this message and then exit.\n"
+          "  --version             Display version information and exit.\n"
+          "\n"
+          "Other options:\n"
+          "\n"
+          "  --wrapper WRAPPER --  Run WRAPPER to start new programs.\n"
+          "  --disable-randomization\n"
+          "                        Run PROG with address space randomization disabled.\n"
+          "  --no-disable-randomization\n"
+          "                        Don't disable address space randomization when\n"
+          "                        starting PROG.\n"
+          "\n"
+          "Debug options:\n"
           "\n"
-          "Options:\n"
           "  --debug               Enable general debugging output.\n"
           "  --debug-format=opt1[,opt2,...]\n"
           "                        Specify extra content in debugging output.\n"
@@ -3011,10 +3161,14 @@ gdbserver_usage (FILE *stream)
           "                            none\n"
           "                            timestamp\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"
-          "  --once                Exit after the first connection has "
-                                                                 "closed.\n");
+          "  --disable-packet=opt1[,opt2,...]\n"
+          "                        Disable support for RSP packets or features.\n"
+          "                          Options:\n"
+          "                            vCont, Tthread, qC, qfThreadInfo and \n"
+          "                            threads (disable all threading packets).\n"
+          "\n"
+          "For more information, consult the GDB manual (available as on-line \n"
+          "info or a printed manual).\n");
   if (REPORT_BUGS_TO[0] && stream == stdout)
     fprintf (stream, "Report bugs to \"%s\".\n", REPORT_BUGS_TO);
 }
@@ -3147,19 +3301,19 @@ static int exit_code;
 static void
 detach_or_kill_for_exit_cleanup (void *ignore)
 {
-  volatile struct gdb_exception exception;
 
-  TRY_CATCH (exception, RETURN_MASK_ALL)
+  TRY
     {
       detach_or_kill_for_exit ();
     }
 
-  if (exception.reason < 0)
+  CATCH (exception, RETURN_MASK_ALL)
     {
       fflush (stdout);
       fprintf (stderr, "Detach or kill failed: %s\n", exception.message);
       exit_code = 1;
     }
+  END_CATCH
 }
 
 /* Main function.  This is called by the real "main" function,
@@ -3211,9 +3365,7 @@ captured_main (int argc, char *argv[])
        }
       else if (strcmp (*next_arg, "--debug") == 0)
        debug_threads = 1;
-      else if (strncmp (*next_arg,
-                       "--debug-format=",
-                       sizeof ("--debug-format=") - 1) == 0)
+      else if (startswith (*next_arg, "--debug-format="))
        {
          char *error_msg
            = parse_debug_format_options ((*next_arg)
@@ -3232,9 +3384,7 @@ captured_main (int argc, char *argv[])
          gdbserver_show_disableable (stdout);
          exit (0);
        }
-      else if (strncmp (*next_arg,
-                       "--disable-packet=",
-                       sizeof ("--disable-packet=") - 1) == 0)
+      else if (startswith (*next_arg, "--disable-packet="))
        {
          char *packets, *tok;
 
@@ -3392,10 +3542,11 @@ captured_main (int argc, char *argv[])
 
   while (1)
     {
-      volatile struct gdb_exception exception;
 
       noack_mode = 0;
       multi_process = 0;
+      report_fork_events = 0;
+      report_vfork_events = 0;
       /* Be sure we're out of tfind mode.  */
       current_traceframe = -1;
       cont_thread = null_ptid;
@@ -3404,7 +3555,7 @@ captured_main (int argc, char *argv[])
 
       remote_open (port);
 
-      TRY_CATCH (exception, RETURN_MASK_ERROR)
+      TRY
        {
          /* Wait for events.  This will return when all event sources
             are removed from the event loop.  */
@@ -3457,8 +3608,7 @@ captured_main (int argc, char *argv[])
                }
            }
        }
-
-      if (exception.reason == RETURN_ERROR)
+      CATCH (exception, RETURN_MASK_ERROR)
        {
          if (response_needed)
            {
@@ -3466,6 +3616,7 @@ captured_main (int argc, char *argv[])
              putpkt (own_buf);
            }
        }
+      END_CATCH
     }
 }
 
@@ -3474,25 +3625,26 @@ captured_main (int argc, char *argv[])
 int
 main (int argc, char *argv[])
 {
-  volatile struct gdb_exception exception;
 
-  TRY_CATCH (exception, RETURN_MASK_ALL)
+  TRY
     {
       captured_main (argc, argv);
     }
-
-  /* captured_main should never return.  */
-  gdb_assert (exception.reason < 0);
-
-  if (exception.reason == RETURN_ERROR)
+  CATCH (exception, RETURN_MASK_ALL)
     {
-      fflush (stdout);
-      fprintf (stderr, "%s\n", exception.message);
-      fprintf (stderr, "Exiting\n");
-      exit_code = 1;
+      if (exception.reason == RETURN_ERROR)
+       {
+         fflush (stdout);
+         fprintf (stderr, "%s\n", exception.message);
+         fprintf (stderr, "Exiting\n");
+         exit_code = 1;
+       }
+
+      exit (exit_code);
     }
+  END_CATCH
 
-  exit (exit_code);
+  gdb_assert_not_reached ("captured_main should never return");
 }
 
 /* Skip PACKET until the next semi-colon (or end of string).  */
@@ -3533,7 +3685,7 @@ process_point_options (struct breakpoint *bp, char **packet)
          if (!add_breakpoint_condition (bp, &dataptr))
            skip_to_semicolon (&dataptr);
        }
-      else if (strncmp (dataptr, "cmds:", strlen ("cmds:")) == 0)
+      else if (startswith (dataptr, "cmds:"))
        {
          dataptr += strlen ("cmds:");
          if (debug_threads)
@@ -3962,7 +4114,20 @@ process_serial_event (void)
 
          /* Wait till we are at 1st instruction in prog.  */
          if (program_argv != NULL)
-           start_inferior (program_argv);
+           {
+             start_inferior (program_argv);
+             if (last_status.kind == TARGET_WAITKIND_STOPPED)
+               {
+                 /* Stopped at the first instruction of the target
+                    process.  */
+                 general_thread = last_ptid;
+               }
+             else
+               {
+                 /* Something went wrong.  */
+                 general_thread = null_ptid;
+               }
+           }
          else
            {
              last_status.kind = TARGET_WAITKIND_EXITED;
This page took 0.073543 seconds and 4 git commands to generate.