gdb: resume ongoing step after handling fork or vfork
[deliverable/binutils-gdb.git] / gdbserver / remote-utils.cc
index 1c211e2572096eae4df94a37e22f54672f87f981..3ee5aff97b1c7c210bf3811cba7a0f613ea83556 100644 (file)
@@ -1,5 +1,5 @@
 /* Remote utility routines for the remote server for GDB.
-   Copyright (C) 1986-2020 Free Software Foundation, Inc.
+   Copyright (C) 1986-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include <ws2tcpip.h>
 #endif
 
-#if __QNX__
-#include <sys/iomgr.h>
-#endif /* __QNX__ */
-
 #ifndef HAVE_SOCKLEN_T
 typedef int socklen_t;
 #endif
 
 #ifndef IN_PROCESS_AGENT
 
-#if USE_WIN32API
-# define INVALID_DESCRIPTOR INVALID_SOCKET
-#else
-# define INVALID_DESCRIPTOR -1
-#endif
-
 /* Extra value for readchar_callback.  */
 enum {
   /* The callback is currently not scheduled.  */
@@ -108,10 +98,14 @@ struct sym_cache
 
 static int remote_is_stdio = 0;
 
-static gdb_fildes_t remote_desc = INVALID_DESCRIPTOR;
-static gdb_fildes_t listen_desc = INVALID_DESCRIPTOR;
+static int remote_desc = -1;
+static int listen_desc = -1;
 
 #ifdef USE_WIN32API
+/* gnulib wraps these as macros, undo them.  */
+# undef read
+# undef write
+
 # define read(fd, buf, len) recv (fd, (char *) buf, len, 0)
 # define write(fd, buf, len) send (fd, (char *) buf, len, 0)
 #endif
@@ -119,7 +113,7 @@ static gdb_fildes_t listen_desc = INVALID_DESCRIPTOR;
 int
 gdb_connected (void)
 {
-  return remote_desc != INVALID_DESCRIPTOR;
+  return remote_desc != -1;
 }
 
 /* Return true if the remote connection is over stdio.  */
@@ -144,7 +138,7 @@ enable_async_notification (int fd)
 #endif
 }
 
-static int
+static void
 handle_accept_event (int err, gdb_client_data client_data)
 {
   struct sockaddr_storage sockaddr;
@@ -204,7 +198,7 @@ handle_accept_event (int err, gdb_client_data client_data)
   enable_async_notification (remote_desc);
 
   /* Register the event loop handler.  */
-  add_file_handler (remote_desc, handle_serial_event, NULL);
+  add_file_handler (remote_desc, handle_serial_event, NULL, "remote-net");
 
   /* We have a new GDB connection now.  If we were disconnected
      tracing, there's a window where the target could report a stop
@@ -213,8 +207,6 @@ handle_accept_event (int err, gdb_client_data client_data)
      until GDB as selected all-stop/non-stop, and has queried the
      threads' status ('?').  */
   target_async (0);
-
-  return 0;
 }
 
 /* Prepare for a later connection to a remote debugger.
@@ -343,7 +335,7 @@ remote_open (const char *name)
       enable_async_notification (remote_desc);
 
       /* Register the event loop handler.  */
-      add_file_handler (remote_desc, handle_serial_event, NULL);
+      add_file_handler (remote_desc, handle_serial_event, NULL, "remote-stdio");
     }
 #ifndef USE_WIN32API
   else if (port_str == NULL)
@@ -384,7 +376,8 @@ remote_open (const char *name)
       enable_async_notification (remote_desc);
 
       /* Register the event loop handler.  */
-      add_file_handler (remote_desc, handle_serial_event, NULL);
+      add_file_handler (remote_desc, handle_serial_event, NULL,
+                       "remote-device");
     }
 #endif /* USE_WIN32API */
   else
@@ -410,7 +403,8 @@ remote_open (const char *name)
       fflush (stderr);
 
       /* Register the event loop handler.  */
-      add_file_handler (listen_desc, handle_accept_event, NULL);
+      add_file_handler (listen_desc, handle_accept_event, NULL,
+                       "remote-listen");
     }
 }
 
@@ -427,7 +421,7 @@ remote_close (void)
   if (! remote_connection_is_stdio ())
     close (remote_desc);
 #endif
-  remote_desc = INVALID_DESCRIPTOR;
+  remote_desc = -1;
 
   reset_readchar ();
 }
@@ -790,7 +784,7 @@ check_remote_input_interrupt_request (void)
   /* This function may be called before establishing communications,
      therefore we need to validate the remote descriptor.  */
 
-  if (remote_desc == INVALID_DESCRIPTOR)
+  if (remote_desc == -1)
     return;
 
   input_interrupt (0);
@@ -812,28 +806,6 @@ block_unblock_async_io (int block)
 #endif
 }
 
-#ifdef __QNX__
-static void
-nto_comctrl (int enable)
-{
-  struct sigevent event;
-
-  if (enable)
-    {
-      event.sigev_notify = SIGEV_SIGNAL_THREAD;
-      event.sigev_signo = SIGIO;
-      event.sigev_code = 0;
-      event.sigev_value.sival_ptr = NULL;
-      event.sigev_priority = -1;
-      ionotify (remote_desc, _NOTIFY_ACTION_POLLARM, _NOTIFY_COND_INPUT,
-               &event);
-    }
-  else
-    ionotify (remote_desc, _NOTIFY_ACTION_POLL, _NOTIFY_COND_INPUT, NULL);
-}
-#endif /* __QNX__ */
-
-
 /* Current state of asynchronous I/O.  */
 static int async_io_enabled;
 
@@ -847,9 +819,6 @@ enable_async_io (void)
   block_unblock_async_io (0);
 
   async_io_enabled = 1;
-#ifdef __QNX__
-  nto_comctrl (1);
-#endif /* __QNX__ */
 }
 
 /* Disable asynchronous I/O.  */
@@ -862,10 +831,6 @@ disable_async_io (void)
   block_unblock_async_io (1);
 
   async_io_enabled = 0;
-#ifdef __QNX__
-  nto_comctrl (0);
-#endif /* __QNX__ */
-
 }
 
 void
@@ -930,27 +895,21 @@ reset_readchar (void)
   readchar_bufcnt = 0;
   if (readchar_callback != NOT_SCHEDULED)
     {
-      delete_callback_event (readchar_callback);
+      delete_timer (readchar_callback);
       readchar_callback = NOT_SCHEDULED;
     }
 }
 
 /* Process remaining data in readchar_buf.  */
 
-static int
+static void
 process_remaining (void *context)
 {
-  int res;
-
   /* This is a one-shot event.  */
   readchar_callback = NOT_SCHEDULED;
 
   if (readchar_bufcnt > 0)
-    res = handle_serial_event (0, NULL);
-  else
-    res = 0;
-
-  return res;
+    handle_serial_event (0, NULL);
 }
 
 /* If there is still data in the buffer, queue another event to process it,
@@ -960,7 +919,7 @@ static void
 reschedule (void)
 {
   if (readchar_bufcnt > 0 && readchar_callback == NOT_SCHEDULED)
-    readchar_callback = append_callback_event (process_remaining, NULL);
+    readchar_callback = create_timer (0, process_remaining, NULL);
 }
 
 /* Read a packet from the remote machine, with error checking,
@@ -1311,11 +1270,11 @@ prepare_resume_reply (char *buf, ptid_t ptid,
              }
          }
 
-       if (dlls_changed)
+       if (current_process ()->dlls_changed)
          {
            strcpy (buf, "library:;");
            buf += strlen (buf);
-           dlls_changed = 0;
+           current_process ()->dlls_changed = false;
          }
 
        current_thread = saved_thread;
@@ -1349,10 +1308,13 @@ prepare_resume_reply (char *buf, ptid_t ptid,
     }
 }
 
-void
-decode_m_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr)
+/* See remote-utils.h.  */
+
+const char *
+decode_m_packet_params (const char *from, CORE_ADDR *mem_addr_ptr,
+                       unsigned int *len_ptr, const char end_marker)
 {
-  int i = 0, j = 0;
+  int i = 0;
   char ch;
   *mem_addr_ptr = *len_ptr = 0;
 
@@ -1362,39 +1324,32 @@ decode_m_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr)
       *mem_addr_ptr |= fromhex (ch) & 0x0f;
     }
 
-  for (j = 0; j < 4; j++)
+  while ((ch = from[i++]) != end_marker)
     {
-      if ((ch = from[i++]) == 0)
-       break;
       *len_ptr = *len_ptr << 4;
       *len_ptr |= fromhex (ch) & 0x0f;
     }
+
+  return from + i;
 }
 
 void
-decode_M_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr,
-                unsigned char **to_p)
+decode_m_packet (const char *from, CORE_ADDR *mem_addr_ptr,
+                unsigned int *len_ptr)
 {
-  int i = 0;
-  char ch;
-  *mem_addr_ptr = *len_ptr = 0;
-
-  while ((ch = from[i++]) != ',')
-    {
-      *mem_addr_ptr = *mem_addr_ptr << 4;
-      *mem_addr_ptr |= fromhex (ch) & 0x0f;
-    }
+  decode_m_packet_params (from, mem_addr_ptr, len_ptr, '\0');
+}
 
-  while ((ch = from[i++]) != ':')
-    {
-      *len_ptr = *len_ptr << 4;
-      *len_ptr |= fromhex (ch) & 0x0f;
-    }
+void
+decode_M_packet (const char *from, CORE_ADDR *mem_addr_ptr,
+                unsigned int *len_ptr, unsigned char **to_p)
+{
+  from = decode_m_packet_params (from, mem_addr_ptr, len_ptr, ':');
 
   if (*to_p == NULL)
     *to_p = (unsigned char *) xmalloc (*len_ptr);
 
-  hex2bin (&from[i++], *to_p, *len_ptr);
+  hex2bin (from, *to_p, *len_ptr);
 }
 
 int
This page took 0.030199 seconds and 4 git commands to generate.