This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/2] Make gdbserver connect to SOCK_STREAM sockets


In GDB:

    (gdb) target remote |socat STDIO UNIX-LISTEN:foo.sock

In gdbserver:

   $ gdbserver foo.sock ./foo

gdb/gdbserver/ChangeLog:

   * remote-utils.c: add support for connecting to a SOCK_STREAM socket
   * remote.c: add documentation about this feature
---
 gdb/gdbserver/remote-utils.c | 42 ++++++++++++++++++++++++++++++++++++++++--
 gdb/gdbserver/server.c       |  1 +
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index adf6d25..e2ba326 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -36,6 +36,9 @@
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
+#if HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
 #if HAVE_NETDB_H
 #include <netdb.h>
 #endif
@@ -344,6 +347,33 @@ open_shell_command (const char *command)
 }
 #endif
 
+#ifndef USE_WIN32API
+static int
+socket_open (const char *name)
+{
+  int sock;
+  struct sockaddr_un addr;
+
+  if (strlen (name) >= sizeof (addr.sun_path))
+    return -1;
+
+  sock = socket (AF_UNIX, SOCK_STREAM, 0);
+  if (sock < 0)
+    return -1;
+
+  addr.sun_family = AF_UNIX;
+  strcpy (addr.sun_path, name);
+  if (connect (sock, (const struct sockaddr *) &addr,
+	       sizeof (struct sockaddr_un)) < 0)
+    {
+      close (sock);
+      return -1;
+    }
+
+  return sock;
+}
+#endif
+
 /* Open a connection to a remote debugger.
    NAME is the filename used for communication.  */
 
@@ -386,10 +416,18 @@ remote_open (char *name)
   else if (port_str == NULL)
     {
       struct stat statbuf;
+      int res;
 
-      if (stat (name, &statbuf) == 0
+      res = stat (name, &statbuf);
+      if (res == 0
 	  && (S_ISCHR (statbuf.st_mode) || S_ISFIFO (statbuf.st_mode)))
-	remote_desc = open (name, O_RDWR);
+	{
+	  remote_desc = open (name, O_RDWR);
+	}
+      else if (res == 0 && S_ISSOCK (statbuf.st_mode))
+	{
+	  remote_desc = socket_open (name);
+	}
       else
 	{
 	  errno = EINVAL;
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 9ed4049..675f9a5 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3037,6 +3037,7 @@ gdbserver_usage (FILE *stream)
 	   "\tgdbserver [OPTIONS] --multi COMM\n"
 	   "\n"
 	   "COMM may be a tty device (for serial debugging),\n"
+	   "an existing pathname stream-oriented socket,\n"
 	   "'|some shell command' to use stdin/stdout of a given shell command,\n"
 	   "HOST:PORT to listen for a TCP connection, or '-' or 'stdio' to use \n"
 	   "stdin/stdout of gdbserver.\n"
-- 
2.1.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]