Implement -list-thread-groups --available
[deliverable/binutils-gdb.git] / gdb / remote.c
index 6af826783737be3082f01df9522bcf9bd6fa2b13..c8a46eedc46e74d7fa11ae2b0f660ac659d69db1 100644 (file)
@@ -105,11 +105,11 @@ static void remote_close (int quitting);
 
 static void remote_store_registers (struct regcache *regcache, int regno);
 
-static void remote_mourn (void);
+static void remote_mourn (struct target_ops *ops);
 
 static void extended_remote_restart (void);
 
-static void extended_remote_mourn (void);
+static void extended_remote_mourn (struct target_ops *);
 
 static void remote_mourn_1 (struct target_ops *);
 
@@ -133,7 +133,7 @@ static void remote_async (void (*callback) (enum inferior_event_type event_type,
 
 static int remote_async_mask (int new_mask);
 
-static void remote_detach (char *args, int from_tty);
+static void remote_detach (struct target_ops *ops, char *args, int from_tty);
 
 static void remote_interrupt (int signo);
 
@@ -232,6 +232,10 @@ static int peek_stop_reply (ptid_t ptid);
 static void remote_async_inferior_event_handler (gdb_client_data);
 static void remote_async_get_pending_events_handler (gdb_client_data);
 
+static void remote_terminal_ours (void);
+
+static int remote_read_description_p (struct target_ops *target);
+
 /* The non-stop remote protocol provisions for one pending stop reply.
    This is where we keep it until it is acknowledged.  */
 
@@ -988,6 +992,7 @@ enum {
   PACKET_qXfer_memory_map,
   PACKET_qXfer_spu_read,
   PACKET_qXfer_spu_write,
+  PACKET_qXfer_osdata,
   PACKET_qGetTLSAddr,
   PACKET_qSupported,
   PACKET_QPassSignals,
@@ -1125,13 +1130,6 @@ static ptid_t continue_thread;
 static void
 notice_new_inferiors (ptid_t currthread)
 {
-  /* When connecting to a target remote, or to a target
-     extended-remote which already was debugging an inferior, we may
-     not know about it yet.  Add it before adding its child thread, so
-     notifications are emitted in a sensible order.  */
-  if (!in_inferior_list (ptid_get_pid (currthread)))
-    add_inferior (ptid_get_pid (currthread));
-
   /* If this is a new thread, add it to GDB's thread list.
      If we leave it up to WFI to do this, bad things will happen.  */
 
@@ -1167,6 +1165,13 @@ notice_new_inferiors (ptid_t currthread)
          return;
        }
 
+      /* When connecting to a target remote, or to a target
+        extended-remote which already was debugging an inferior, we
+        may not know about it yet.  Add it before adding its child
+        thread, so notifications are emitted in a sensible order.  */
+      if (!in_inferior_list (ptid_get_pid (currthread)))
+       add_inferior (ptid_get_pid (currthread));
+
       /* This is really a new thread.  Add it.  */
       add_thread (currthread);
     }
@@ -2287,18 +2292,15 @@ extended_remote_restart (void)
 static void
 remote_close (int quitting)
 {
-  if (remote_desc)
-    {
-      /* Unregister the file descriptor from the event loop.  */
-      if (target_is_async_p ())
-       target_async (NULL, 0);
-      serial_close (remote_desc);
-      remote_desc = NULL;
-    }
+  if (remote_desc == NULL)
+    return; /* already closed */
 
-  /* Make sure we don't leave the async SIGINT signal handler
-     installed.  */
-  signal (SIGINT, handle_sigint);
+  /* Make sure we leave stdin registered in the event loop, and we
+     don't leave the async SIGINT signal handler installed.  */
+  remote_terminal_ours ();
+
+  serial_close (remote_desc);
+  remote_desc = NULL;
 
   /* We don't have a connection to the remote stub anymore.  Get rid
      of all the inferiors and their threads we were controlling.  */
@@ -2554,6 +2556,11 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
      this before anything involving memory or registers.  */
   target_find_description ();
 
+  /* On OSs where the list of libraries is global to all
+     processes, we fetch them early.  */
+  if (gdbarch_has_global_solist (target_gdbarch))
+    solib_add (NULL, args->from_tty, args->target, auto_solib_add);
+
   if (non_stop)
     {
       if (!rs->non_stop_aware)
@@ -2639,6 +2646,17 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
 
       get_offsets ();          /* Get text, data & bss offsets.  */
 
+      /* If we could not find a description using qXfer, and we know
+        how to do it some other way, try again.  This is not
+        supported for non-stop; it could be, but it is tricky if
+        there are no stopped threads when we connect.  */
+      if (remote_read_description_p (args->target)
+         && gdbarch_target_desc (target_gdbarch) == NULL)
+       {
+         target_clear_description ();
+         target_find_description ();
+       }
+
       /* Use the previously fetched status.  */
       gdb_assert (wait_status != NULL);
       strcpy (rs->buf, wait_status);
@@ -2717,6 +2735,12 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
       if (exec_bfd)    /* No use without an exec file.  */
        remote_check_symbols (symfile_objfile);
     }
+
+  /* If code is shared between processes, then breakpoints are global
+     too; Insert them now.  */
+  if (gdbarch_has_global_solist (target_gdbarch)
+      && breakpoints_always_inserted_mode ())
+    insert_breakpoints ();
 }
 
 /* Open a connection to a remote debugger.
@@ -2935,6 +2959,8 @@ static struct protocol_feature remote_protocol_features[] = {
     PACKET_qXfer_spu_read },
   { "qXfer:spu:write", PACKET_DISABLE, remote_supported_packet,
     PACKET_qXfer_spu_write },
+  { "qXfer:osdata:read", PACKET_DISABLE, remote_supported_packet,
+    PACKET_qXfer_osdata },
   { "QPassSignals", PACKET_DISABLE, remote_supported_packet,
     PACKET_QPassSignals },
   { "QStartNoAckMode", PACKET_DISABLE, remote_supported_packet,
@@ -3153,8 +3179,9 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended
     }
   push_target (target);                /* Switch to using remote target now.  */
 
-  /* Assume that the target is running, unless we learn otherwise.  */
-  target_mark_running (target);
+  /* Assume that the target is not running, until we learn otherwise.  */
+  if (extended_p)
+    target_mark_exited (target);
 
   /* Register extra event sources in the event loop.  */
   remote_async_inferior_event_token
@@ -3296,13 +3323,13 @@ remote_detach_1 (char *args, int from_tty, int extended)
 }
 
 static void
-remote_detach (char *args, int from_tty)
+remote_detach (struct target_ops *ops, char *args, int from_tty)
 {
   remote_detach_1 (args, from_tty, 0);
 }
 
 static void
-extended_remote_detach (char *args, int from_tty)
+extended_remote_detach (struct target_ops *ops, char *args, int from_tty)
 {
   remote_detach_1 (args, from_tty, 1);
 }
@@ -3425,9 +3452,9 @@ extended_remote_attach_1 (struct target_ops *target, char *args, int from_tty)
 }
 
 static void
-extended_remote_attach (char *args, int from_tty)
+extended_remote_attach (struct target_ops *ops, char *args, int from_tty)
 {
-  extended_remote_attach_1 (&extended_remote_ops, args, from_tty);
+  extended_remote_attach_1 (ops, args, from_tty);
 }
 
 /* Convert hex digit A to a number.  */
@@ -5837,6 +5864,28 @@ remote_send (char **buf,
     error (_("Remote failure reply: %s"), *buf);
 }
 
+/* Return a pointer to an xmalloc'ed string representing an escaped
+   version of BUF, of len N.  E.g. \n is converted to \\n, \t to \\t,
+   etc.  The caller is responsible for releasing the returned
+   memory.  */
+
+static char *
+escape_buffer (const char *buf, int n)
+{
+  struct cleanup *old_chain;
+  struct ui_file *stb;
+  char *str;
+  long length;
+
+  stb = mem_fileopen ();
+  old_chain = make_cleanup_ui_file_delete (stb);
+
+  fputstrn_unfiltered (buf, n, 0, stb);
+  str = ui_file_xstrdup (stb, &length);
+  do_cleanups (old_chain);
+  return str;
+}
+
 /* Display a null-terminated packet on stdout, for debugging, using C
    string notation.  */
 
@@ -5909,11 +5958,15 @@ putpkt_binary (char *buf, int cnt)
 
       if (remote_debug)
        {
+         struct cleanup *old_chain;
+         char *str;
+
          *p = '\0';
-         fprintf_unfiltered (gdb_stdlog, "Sending packet: ");
-         fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog);
-         fprintf_unfiltered (gdb_stdlog, "...");
+         str = escape_buffer (buf2, p - buf2);
+         old_chain = make_cleanup (xfree, str);
+         fprintf_unfiltered (gdb_stdlog, "Sending packet: %s...", str);
          gdb_flush (gdb_stdlog);
+         do_cleanups (old_chain);
        }
       if (serial_write (remote_desc, buf2, p - buf2))
        perror_with_name (_("putpkt: write failed"));
@@ -5987,9 +6040,15 @@ putpkt_binary (char *buf, int cnt)
                  {
                    if (remote_debug)
                      {
-                       fprintf_unfiltered (gdb_stdlog, "  Notification received: ");
-                       fputstrn_unfiltered (rs->buf, val, 0, gdb_stdlog);
-                       fprintf_unfiltered (gdb_stdlog, "\n");
+                       struct cleanup *old_chain;
+                       char *str;
+
+                       str = escape_buffer (rs->buf, val);
+                       old_chain = make_cleanup (xfree, str);
+                       fprintf_unfiltered (gdb_stdlog,
+                                           "  Notification received: %s\n",
+                                           str);
+                       do_cleanups (old_chain);
                      }
                    handle_notification (rs->buf, val);
                    /* We're in sync now, rewait for the ack.  */
@@ -6153,11 +6212,16 @@ read_frame (char **buf_p,
 
            if (remote_debug)
              {
-               fprintf_filtered (gdb_stdlog,
-                             "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
-                                 pktcsum, csum);
-               fputstrn_filtered (buf, bc, 0, gdb_stdlog);
-               fputs_filtered ("\n", gdb_stdlog);
+               struct cleanup *old_chain;
+               char *str;
+
+               str = escape_buffer (buf, bc);
+               old_chain = make_cleanup (xfree, str);
+               fprintf_unfiltered (gdb_stdlog,
+                                   "\
+Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
+                                   pktcsum, csum, str);
+               do_cleanups (old_chain);
              }
            /* Number of characters in buffer ignoring trailing
                NULL.  */
@@ -6330,9 +6394,13 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
        {
          if (remote_debug)
            {
-             fprintf_unfiltered (gdb_stdlog, "Packet received: ");
-             fputstrn_unfiltered (*buf, val, 0, gdb_stdlog);
-             fprintf_unfiltered (gdb_stdlog, "\n");
+            struct cleanup *old_chain;
+            char *str;
+
+            str = escape_buffer (*buf, val);
+            old_chain = make_cleanup (xfree, str);
+            fprintf_unfiltered (gdb_stdlog, "Packet received: %s\n", str);
+            do_cleanups (old_chain);
            }
 
          /* Skip the ack char if we're in no-ack mode.  */
@@ -6349,9 +6417,15 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
 
          if (remote_debug)
            {
-             fprintf_unfiltered (gdb_stdlog, "  Notification received: ");
-             fputstrn_unfiltered (*buf, val, 0, gdb_stdlog);
-             fprintf_unfiltered (gdb_stdlog, "\n");
+             struct cleanup *old_chain;
+             char *str;
+
+             str = escape_buffer (*buf, val);
+             old_chain = make_cleanup (xfree, str);
+             fprintf_unfiltered (gdb_stdlog,
+                                 "  Notification received: %s\n",
+                                 str);
+             do_cleanups (old_chain);
            }
 
          handle_notification (*buf, val);
@@ -6442,9 +6516,9 @@ extended_remote_kill (void)
 }
 
 static void
-remote_mourn (void)
+remote_mourn (struct target_ops *ops)
 {
-  remote_mourn_1 (&remote_ops);
+  remote_mourn_1 (ops);
 }
 
 /* Worker function for remote_mourn.  */
@@ -6527,9 +6601,9 @@ extended_remote_mourn_1 (struct target_ops *target)
 }
 
 static void
-extended_remote_mourn (void)
+extended_remote_mourn (struct target_ops *ops)
 {
-  extended_remote_mourn_1 (&extended_remote_ops);
+  extended_remote_mourn_1 (ops);
 }
 
 static int
@@ -6645,7 +6719,8 @@ extended_remote_create_inferior_1 (char *exec_file, char *args,
 }
 
 static void
-extended_remote_create_inferior (char *exec_file, char *args,
+extended_remote_create_inferior (struct target_ops *ops, 
+                                char *exec_file, char *args,
                                 char **env, int from_tty)
 {
   extended_remote_create_inferior_1 (exec_file, args, env, from_tty);
@@ -7283,6 +7358,13 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
       return remote_read_qxfer (ops, "memory-map", annex, readbuf, offset, len,
                                &remote_protocol_packets[PACKET_qXfer_memory_map]);
 
+    case TARGET_OBJECT_OSDATA:
+      /* Should only get here if we're connected.  */
+      gdb_assert (remote_desc);
+      return remote_read_qxfer
+       (ops, "osdata", annex, readbuf, offset, len,
+        &remote_protocol_packets[PACKET_qXfer_osdata]);
+
     default:
       return -1;
     }
@@ -7794,12 +7876,32 @@ register_remote_g_packet_guess (struct gdbarch *gdbarch, int bytes,
   VEC_safe_push (remote_g_packet_guess_s, data->guesses, &new_guess);
 }
 
+/* Return 1 if remote_read_description would do anything on this target
+   and architecture, 0 otherwise.  */
+
+static int
+remote_read_description_p (struct target_ops *target)
+{
+  struct remote_g_packet_data *data
+    = gdbarch_data (target_gdbarch, remote_g_packet_data_handle);
+
+  if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
+    return 1;
+
+  return 0;
+}
+
 static const struct target_desc *
 remote_read_description (struct target_ops *target)
 {
   struct remote_g_packet_data *data
     = gdbarch_data (target_gdbarch, remote_g_packet_data_handle);
 
+  /* Do not try this during initial connection, when we do not know
+     whether there is a running but stopped thread.  */
+  if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid))
+    return NULL;
+
   if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
     {
       struct remote_g_packet_guess *guess;
@@ -8212,12 +8314,6 @@ remote_hostio_error (int errnum)
     error (_("Remote I/O error: %s"), safe_strerror (host_error));
 }
 
-static void
-fclose_cleanup (void *file)
-{
-  fclose (file);
-}
-
 static void
 remote_hostio_close_cleanup (void *opaque)
 {
@@ -8335,7 +8431,7 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty)
   file = fopen (local_file, "rb");
   if (file == NULL)
     perror_with_name (local_file);
-  back_to = make_cleanup (fclose_cleanup, file);
+  back_to = make_cleanup_fclose (file);
 
   fd = remote_hostio_open (remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT
                                         | FILEIO_O_TRUNC),
@@ -8425,7 +8521,7 @@ remote_file_get (const char *remote_file, const char *local_file, int from_tty)
   file = fopen (local_file, "wb");
   if (file == NULL)
     perror_with_name (local_file);
-  back_to = make_cleanup (fclose_cleanup, file);
+  back_to = make_cleanup_fclose (file);
 
   /* Send up to this many bytes at once.  They won't all fit in the
      remote packet limit, so we'll transfer slightly fewer.  */
@@ -8561,6 +8657,15 @@ remote_supports_multi_process (void)
   return remote_multi_process_p (rs);
 }
 
+static int
+extended_remote_can_run (void)
+{
+  if (remote_desc != NULL)
+    return 1;
+
+  return 0;
+}
+
 static void
 init_remote_ops (void)
 {
@@ -8646,6 +8751,7 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
   extended_remote_ops.to_detach = extended_remote_detach;
   extended_remote_ops.to_attach = extended_remote_attach;
   extended_remote_ops.to_kill = extended_remote_kill;
+  extended_remote_ops.to_can_run = extended_remote_can_run;
 }
 
 static int
@@ -8955,6 +9061,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
   add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_spu_write],
                          "qXfer:spu:write", "write-spu-object", 0);
 
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_osdata],
+                        "qXfer:osdata:read", "osdata", 0);
+
   add_packet_config_cmd (&remote_protocol_packets[PACKET_qGetTLSAddr],
                         "qGetTLSAddr", "get-thread-local-storage-address",
                         0);
This page took 0.035053 seconds and 4 git commands to generate.