Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yunlian Jiang <yunlian@google.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] gdbserver: support Unix domain sockets
Date: Thu, 10 Mar 2016 00:05:00 -0000	[thread overview]
Message-ID: <CAMsPy2shyuZECJ7Msx6ADk=SoyJHa6T5Ea0V2iKc7LJB9ntNVQ@mail.gmail.com> (raw)

This patch enables gdbserver to use Unix domain sockets if
the TCP sockets is not allowed to use. Wit this patch, user can
use "gdbserver +debug-socket --attach 123" to use Unix domain
sockets.


diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index e751473..b00960d 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -62,6 +62,10 @@
 #include <winsock2.h>
 #endif

+#ifndef USE_WIN32API
+#include <sys/un.h>
+#endif
+
 #if __QNX__
 #include <sys/iomgr.h>
 #endif /* __QNX__ */
@@ -288,6 +292,49 @@ remote_open (char *name)
 {
   char *port_str;

+  /* Enable gdbserver to use Unix domain sockets if applications aren't
+     allowed to bind to localhost TCP sockets.
+     Typical usage is "gdbserver +debug-socket --attach 123" */
+  if (name[0] == '+')
+    {
+#ifdef USE_WIN32API
+      error ("Only <host>:<port> is supported on this platform.");
+#else
+      struct sockaddr_un sockaddr;
+      socklen_t sockaddrlen;
+
+      listen_desc = socket (AF_UNIX, SOCK_STREAM, 0);
+      if (listen_desc == -1)
+        perror_with_name ("Can't create Unix domain socket");
+
+      /* Skip the initial '+'. */
+      name++;
+
+      memset (&sockaddr, 0, sizeof sockaddr);
+      sockaddr.sun_family = AF_UNIX;
+      snprintf(sockaddr.sun_path, sizeof (sockaddr.sun_path), "%s", name);
+      sockaddrlen = sizeof (sockaddr.sun_family) +
+          strlen (sockaddr.sun_path) + 1;
+
+      unlink (sockaddr.sun_path);
+
+      if (bind (listen_desc, (struct sockaddr *) &sockaddr, sockaddrlen)
+          || listen (listen_desc, 1))
+        perror_with_name ("Can't bind Unix domain socket");
+
+      fprintf (stderr, "Listening on Unix domain socket '%s'\n",
+               sockaddr.sun_path);
+      fflush (stderr);
+
+      /* Register the event loop handler.  */
+      add_file_handler (listen_desc, handle_accept_event, NULL);
+
+      transport_is_reliable = 1;
+#endif
+
+      return;
+    }
+
   port_str = strchr (name, ':');
 #ifdef USE_WIN32API
   if (port_str == NULL)


             reply	other threads:[~2016-03-10  0:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-10  0:05 Yunlian Jiang [this message]
2016-03-10 17:35 ` Pedro Alves
2016-03-14 15:02   ` Pedro Alves

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='CAMsPy2shyuZECJ7Msx6ADk=SoyJHa6T5Ea0V2iKc7LJB9ntNVQ@mail.gmail.com' \
    --to=yunlian@google.com \
    --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