Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Gabriel Corona <gabriel.corona@enst-bretagne.fr>
To: gdb-patches@sourceware.org
Cc: Gabriel Corona <gabriel.corona@enst-bretagne.fr>
Subject: [PATCH v2 2/2] Make gdbserver connect to SOCK_STREAM sockets
Date: Mon, 04 May 2015 21:54:00 -0000	[thread overview]
Message-ID: <1430776463-23214-2-git-send-email-gabriel.corona@enst-bretagne.fr> (raw)
In-Reply-To: <1430776463-23214-1-git-send-email-gabriel.corona@enst-bretagne.fr>

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 | 40 ++++++++++++++++++++++++++++++++++++++--
 gdb/gdbserver/server.c       |  1 +
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index f15f1ce..ef4d8d6 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
@@ -340,6 +343,31 @@ open_shell_command (char *command)
 }
 #endif
 
+#ifndef USE_WIN32API
+static int
+socket_open (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.  */
 
@@ -382,10 +410,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


  reply	other threads:[~2015-05-04 21:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-04 21:54 [PATCH v2 1/2] Use a shell command as a socket for gdbserver Gabriel Corona
2015-05-04 21:54 ` Gabriel Corona [this message]
2015-05-05  3:01   ` [PATCH v2 2/2] Make gdbserver connect to SOCK_STREAM sockets Mike Frysinger
2015-05-05  2:58 ` [PATCH v2 1/2] Use a shell command as a socket for gdbserver Mike Frysinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430776463-23214-2-git-send-email-gabriel.corona@enst-bretagne.fr \
    --to=gabriel.corona@enst-bretagne.fr \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox