FreeBSD: Fix 'Couldn't get registers: Device busy' error (PR gdb/23077)
[deliverable/binutils-gdb.git] / gdb / remote.c
index 01b236fcd30276646fed920ce35e20bcf1e93678..49013848d5553dd1da0b014d3ef8001bfb65ca89 100644 (file)
@@ -36,7 +36,7 @@
 #include "remote-notif.h"
 #include "regcache.h"
 #include "value.h"
-#include "observer.h"
+#include "observable.h"
 #include "solib.h"
 #include "cli/cli-decode.h"
 #include "cli/cli-setshow.h"
@@ -3151,13 +3151,13 @@ remote_get_threads_with_qxfer (struct target_ops *ops,
 #if defined(HAVE_LIBEXPAT)
   if (packet_support (PACKET_qXfer_threads) == PACKET_ENABLE)
     {
-      gdb::unique_xmalloc_ptr<char> xml
+      gdb::optional<gdb::char_vector> xml
        = target_read_stralloc (ops, TARGET_OBJECT_THREADS, NULL);
 
-      if (xml != NULL && *xml != '\0')
+      if (xml && (*xml)[0] != '\0')
        {
          gdb_xml_parse_quick (_("threads"), "threads.dtd",
-                              threads_elements, xml.get (), context);
+                              threads_elements, xml->data (), context);
        }
 
       return 1;
@@ -3381,7 +3381,7 @@ remote_threads_extra_info (struct target_ops *self, struct thread_info *tp)
 }
 \f
 
-static int
+static bool
 remote_static_tracepoint_marker_at (struct target_ops *self, CORE_ADDR addr,
                                    struct static_tracepoint_marker *marker)
 {
@@ -3401,21 +3401,20 @@ remote_static_tracepoint_marker_at (struct target_ops *self, CORE_ADDR addr,
   if (*p++ == 'm')
     {
       parse_static_tracepoint_marker_definition (p, NULL, marker);
-      return 1;
+      return true;
     }
 
-  return 0;
+  return false;
 }
 
-static VEC(static_tracepoint_marker_p) *
+static std::vector<static_tracepoint_marker>
 remote_static_tracepoint_markers_by_strid (struct target_ops *self,
                                           const char *strid)
 {
   struct remote_state *rs = get_remote_state ();
-  VEC(static_tracepoint_marker_p) *markers = NULL;
-  struct static_tracepoint_marker *marker = NULL;
-  struct cleanup *old_chain;
+  std::vector<static_tracepoint_marker> markers;
   const char *p;
+  static_tracepoint_marker marker;
 
   /* Ask for a first packet of static tracepoint marker
      definition.  */
@@ -3425,28 +3424,14 @@ remote_static_tracepoint_markers_by_strid (struct target_ops *self,
   if (*p == 'E')
     error (_("Remote failure reply: %s"), p);
 
-  old_chain = make_cleanup (free_current_marker, &marker);
-
   while (*p++ == 'm')
     {
-      if (marker == NULL)
-       marker = XCNEW (struct static_tracepoint_marker);
-
       do
        {
-         parse_static_tracepoint_marker_definition (p, &p, marker);
+         parse_static_tracepoint_marker_definition (p, &p, &marker);
 
-         if (strid == NULL || strcmp (strid, marker->str_id) == 0)
-           {
-             VEC_safe_push (static_tracepoint_marker_p,
-                            markers, marker);
-             marker = NULL;
-           }
-         else
-           {
-             release_static_tracepoint_marker (marker);
-             memset (marker, 0, sizeof (*marker));
-           }
+         if (strid == NULL || marker.str_id == strid)
+           markers.push_back (std::move (marker));
        }
       while (*p++ == ',');     /* comma-separated list */
       /* Ask for another packet of static tracepoint definition.  */
@@ -3455,7 +3440,6 @@ remote_static_tracepoint_markers_by_strid (struct target_ops *self,
       p = rs->buf;
     }
 
-  do_cleanups (old_chain);
   return markers;
 }
 
@@ -3824,9 +3808,9 @@ print_one_stopped_thread (struct thread_info *thread)
       enum gdb_signal sig = ws->value.sig;
 
       if (signal_print_state (sig))
-       observer_notify_signal_received (sig);
+       gdb::observers::signal_received.notify (sig);
     }
-  observer_notify_normal_stop (NULL, 1);
+  gdb::observers::normal_stop.notify (NULL, 1);
 }
 
 /* Process all initial stop replies the remote side sent in response
@@ -4913,7 +4897,7 @@ remote_serial_quit_handler (void)
       /* All-stop protocol, and blocked waiting for stop reply.  Send
         an interrupt request.  */
       else if (!target_terminal::is_ours () && rs->waiting_for_stop_reply)
-       target_interrupt (inferior_ptid);
+       target_interrupt ();
       else
        rs->got_ctrlc_during_io = 1;
     }
@@ -5126,7 +5110,7 @@ remote_detach_pid (int pid)
    one.  */
 
 static void
-remote_detach_1 (int from_tty)
+remote_detach_1 (int from_tty, inferior *inf)
 {
   int pid = ptid_get_pid (inferior_ptid);
   struct remote_state *rs = get_remote_state ();
@@ -5162,15 +5146,15 @@ remote_detach_1 (int from_tty)
 }
 
 static void
-remote_detach (struct target_ops *ops, int from_tty)
+remote_detach (struct target_ops *ops, inferior *inf, int from_tty)
 {
-  remote_detach_1 (from_tty);
+  remote_detach_1 (from_tty, inf);
 }
 
 static void
-extended_remote_detach (struct target_ops *ops, int from_tty)
+extended_remote_detach (struct target_ops *ops, inferior *inf, int from_tty)
 {
-  remote_detach_1 (from_tty);
+  remote_detach_1 (from_tty, inf);
 }
 
 /* Target follow-fork function for remote targets.  On entry, and
@@ -5206,7 +5190,6 @@ remote_follow_fork (struct target_ops *ops, int follow_child,
          child_pid = ptid_get_pid (child_ptid);
 
          remote_detach_pid (child_pid);
-         detach_inferior (child_pid);
        }
     }
   return 0;
@@ -5333,7 +5316,10 @@ extended_remote_attach (struct target_ops *target, const char *args,
       inferior_ptid = remote_current_thread (inferior_ptid);
 
       /* Add the main thread to the thread list.  */
-      add_thread_silent (inferior_ptid);
+      thread_info *thr = add_thread_silent (inferior_ptid);
+      /* Don't consider the thread stopped until we've processed the
+        saved stop reply.  */
+      set_executing (thr->ptid, true);
     }
 
   /* Next, if the target can specify a description, read it.  We do
@@ -6165,7 +6151,7 @@ remote_stop (struct target_ops *self, ptid_t ptid)
 /* Implement the to_interrupt function for the remote targets.  */
 
 static void
-remote_interrupt (struct target_ops *self, ptid_t ptid)
+remote_interrupt (struct target_ops *self)
 {
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
@@ -6194,7 +6180,7 @@ remote_pass_ctrlc (struct target_ops *self)
   else if (rs->ctrlc_pending_p)
     interrupt_query ();
   else
-    target_interrupt (inferior_ptid);
+    target_interrupt ();
 }
 
 /* Ask the user what to do when an interrupt is received.  */
@@ -8721,11 +8707,9 @@ putpkt_binary (const char *buf, int cnt)
 
          fprintf_unfiltered (gdb_stdlog, "Sending packet: %s", str.c_str ());
 
-         if (str.length () > REMOTE_DEBUG_MAX_CHAR)
-           {
-             fprintf_unfiltered (gdb_stdlog, "[%zu bytes omitted]",
-                                 str.length () - REMOTE_DEBUG_MAX_CHAR);
-           }
+         if (len > REMOTE_DEBUG_MAX_CHAR)
+           fprintf_unfiltered (gdb_stdlog, "[%d bytes omitted]",
+                               len - REMOTE_DEBUG_MAX_CHAR);
 
          fprintf_unfiltered (gdb_stdlog, "...");
 
@@ -9158,11 +9142,9 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
              fprintf_unfiltered (gdb_stdlog, "Packet received: %s",
                                  str.c_str ());
 
-             if (str.length () >  REMOTE_DEBUG_MAX_CHAR)
-               {
-                 fprintf_unfiltered (gdb_stdlog, "[%zu bytes omitted]",
-                                     str.length () - REMOTE_DEBUG_MAX_CHAR);
-               }
+             if (val > REMOTE_DEBUG_MAX_CHAR)
+               fprintf_unfiltered (gdb_stdlog, "[%d bytes omitted]",
+                                   val - REMOTE_DEBUG_MAX_CHAR);
 
              fprintf_unfiltered (gdb_stdlog, "\n");
            }
@@ -10811,11 +10793,11 @@ static std::vector<mem_region>
 remote_memory_map (struct target_ops *ops)
 {
   std::vector<mem_region> result;
-  gdb::unique_xmalloc_ptr<char> text
+  gdb::optional<gdb::char_vector> text
     = target_read_stralloc (&current_target, TARGET_OBJECT_MEMORY_MAP, NULL);
 
   if (text)
-    result = parse_memory_map (text.get ());
+    result = parse_memory_map (text->data ());
 
   return result;
 }
@@ -11371,8 +11353,7 @@ remote_hostio_send_command (int command_bytes, int which_packet,
   int ret, bytes_read;
   char *attachment_tmp;
 
-  if (!rs->remote_desc
-      || packet_support (which_packet) == PACKET_DISABLE)
+  if (packet_support (which_packet) == PACKET_DISABLE)
     {
       *remote_errno = FILEIO_ENOSYS;
       return -1;
@@ -11714,7 +11695,7 @@ remote_hostio_unlink (struct target_ops *self,
 
 /* Implementation of to_fileio_readlink.  */
 
-static char *
+static gdb::optional<std::string>
 remote_hostio_readlink (struct target_ops *self,
                        struct inferior *inf, const char *filename,
                        int *remote_errno)
@@ -11725,10 +11706,9 @@ remote_hostio_readlink (struct target_ops *self,
   int left = get_remote_packet_size ();
   int len, attachment_len;
   int read_len;
-  char *ret;
 
   if (remote_hostio_set_filesystem (inf, remote_errno) != 0)
-    return NULL;
+    return {};
 
   remote_buffer_add_string (&p, &left, "vFile:readlink:");
 
@@ -11740,16 +11720,15 @@ remote_hostio_readlink (struct target_ops *self,
                                    &attachment_len);
 
   if (len < 0)
-    return NULL;
+    return {};
 
-  ret = (char *) xmalloc (len + 1);
+  std::string ret (len, '\0');
 
   read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
-                                   (gdb_byte *) ret, len);
+                                   (gdb_byte *) &ret[0], len);
   if (read_len != len)
     error (_("Readlink returned %d, but %d bytes."), len, read_len);
 
-  ret[len] = '\0';
   return ret;
 }
 
@@ -12471,18 +12450,18 @@ remote_can_download_tracepoint (struct target_ops *self)
 
 static void
 remote_download_trace_state_variable (struct target_ops *self,
-                                     struct trace_state_variable *tsv)
+                                     const trace_state_variable &tsv)
 {
   struct remote_state *rs = get_remote_state ();
   char *p;
 
   xsnprintf (rs->buf, get_remote_packet_size (), "QTDV:%x:%s:%x:",
-            tsv->number, phex ((ULONGEST) tsv->initial_value, 8),
-            tsv->builtin);
+            tsv.number, phex ((ULONGEST) tsv.initial_value, 8),
+            tsv.builtin);
   p = rs->buf + strlen (rs->buf);
-  if ((p - rs->buf) + strlen (tsv->name) * 2 >= get_remote_packet_size ())
+  if ((p - rs->buf) + tsv.name.length () * 2 >= get_remote_packet_size ())
     error (_("Trace state variable name too long for tsv definition packet"));
-  p += 2 * bin2hex ((gdb_byte *) (tsv->name), p, strlen (tsv->name));
+  p += 2 * bin2hex ((gdb_byte *) (tsv.name.data ()), p, tsv.name.length ());
   *p++ = '\0';
   putpkt (rs->buf);
   remote_get_noisy_reply ();
@@ -12928,11 +12907,11 @@ remote_set_circular_trace_buffer (struct target_ops *self, int val)
 static traceframe_info_up
 remote_traceframe_info (struct target_ops *self)
 {
-  gdb::unique_xmalloc_ptr<char> text
+  gdb::optional<gdb::char_vector> text
     = target_read_stralloc (&current_target, TARGET_OBJECT_TRACEFRAME_INFO,
                            NULL);
-  if (text != NULL)
-    return parse_traceframe_info (text.get ());
+  if (text)
+    return parse_traceframe_info (text->data ());
 
   return NULL;
 }
@@ -13096,37 +13075,6 @@ remote_btrace_reset (void)
   memset (&rs->btrace_config, 0, sizeof (rs->btrace_config));
 }
 
-/* Check whether the target supports branch tracing.  */
-
-static int
-remote_supports_btrace (struct target_ops *self, enum btrace_format format)
-{
-  if (packet_support (PACKET_Qbtrace_off) != PACKET_ENABLE)
-    return 0;
-  if (packet_support (PACKET_qXfer_btrace) != PACKET_ENABLE)
-    return 0;
-
-  switch (format)
-    {
-      case BTRACE_FORMAT_NONE:
-       return 0;
-
-      case BTRACE_FORMAT_BTS:
-       return (packet_support (PACKET_Qbtrace_bts) == PACKET_ENABLE);
-
-      case BTRACE_FORMAT_PT:
-       /* The trace is decoded on the host.  Even if our target supports it,
-          we still need to have libipt to decode the trace.  */
-#if defined (HAVE_LIBIPT)
-       return (packet_support (PACKET_Qbtrace_pt) == PACKET_ENABLE);
-#else /* !defined (HAVE_LIBIPT)  */
-       return 0;
-#endif /* !defined (HAVE_LIBIPT)  */
-    }
-
-  internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
-}
-
 /* Synchronize the configuration with the target.  */
 
 static void
@@ -13191,10 +13139,10 @@ btrace_sync_conf (const struct btrace_config *conf)
 static void
 btrace_read_config (struct btrace_config *conf)
 {
-  gdb::unique_xmalloc_ptr<char> xml
+  gdb::optional<gdb::char_vector> xml
     = target_read_stralloc (&current_target, TARGET_OBJECT_BTRACE_CONF, "");
-  if (xml != NULL)
-    parse_xml_btrace_conf (conf, xml.get ());
+  if (xml)
+    parse_xml_btrace_conf (conf, xml->data ());
 }
 
 /* Maybe reopen target btrace.  */
@@ -13225,8 +13173,8 @@ remote_btrace_maybe_reopen (void)
          if (!warned)
            {
              warned = 1;
-             warning (_("GDB does not support Intel Processor Trace. "
-                        "\"record\" will not work in this session."));
+             warning (_("Target is recording using Intel Processor Trace "
+                        "but support was disabled at compile time."));
            }
 
          continue;
@@ -13391,12 +13339,12 @@ remote_read_btrace (struct target_ops *self,
                      (unsigned int) type);
     }
 
-  gdb::unique_xmalloc_ptr<char> xml
+  gdb::optional<gdb::char_vector> xml
     = target_read_stralloc (&current_target, TARGET_OBJECT_BTRACE, annex);
-  if (xml == NULL)
+  if (!xml)
     return BTRACE_ERR_UNKNOWN;
 
-  parse_xml_btrace (btrace, xml.get ());
+  parse_xml_btrace (btrace, xml->data ());
 
   return BTRACE_ERR_NONE;
 }
@@ -13430,7 +13378,7 @@ remote_load (struct target_ops *self, const char *name, int from_tty)
 static char *
 remote_pid_to_exec_file (struct target_ops *self, int pid)
 {
-  static gdb::unique_xmalloc_ptr<char> filename;
+  static gdb::optional<gdb::char_vector> filename;
   struct inferior *inf;
   char *annex = NULL;
 
@@ -13453,7 +13401,7 @@ remote_pid_to_exec_file (struct target_ops *self, int pid)
   filename = target_read_stralloc (&current_target,
                                   TARGET_OBJECT_EXEC_FILE, annex);
 
-  return filename.get ();
+  return filename ? filename->data () : nullptr;
 }
 
 /* Implement the to_can_do_single_step target_ops method.  */
@@ -13650,7 +13598,6 @@ Specify the serial device it is connected to\n\
   remote_ops.to_traceframe_info = remote_traceframe_info;
   remote_ops.to_use_agent = remote_use_agent;
   remote_ops.to_can_use_agent = remote_can_use_agent;
-  remote_ops.to_supports_btrace = remote_supports_btrace;
   remote_ops.to_enable_btrace = remote_enable_btrace;
   remote_ops.to_disable_btrace = remote_disable_btrace;
   remote_ops.to_teardown_btrace = remote_teardown_btrace;
@@ -13964,10 +13911,10 @@ _initialize_remote (void)
   add_target (&extended_remote_ops);
 
   /* Hook into new objfile notification.  */
-  observer_attach_new_objfile (remote_new_objfile);
+  gdb::observers::new_objfile.attach (remote_new_objfile);
   /* We're no longer interested in notification events of an inferior
      when it exits.  */
-  observer_attach_inferior_exit (discard_pending_stop_replies);
+  gdb::observers::inferior_exit.attach (discard_pending_stop_replies);
 
 #if 0
   init_remote_threadtests ();
This page took 0.037684 seconds and 4 git commands to generate.