Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: John Darrington <john@darrington.wattle.id.au>
To: gdb-patches@sourceware.org
Cc: John Darrington <john@darrington.wattle.id.au>
Subject: [PATCH 4/4] GDB: Remote target can now accept the form unix::/path/to/socket.
Date: Sat, 13 Oct 2018 17:58:00 -0000	[thread overview]
Message-ID: <20181013175801.2670-4-john@darrington.wattle.id.au> (raw)
In-Reply-To: <20181013175801.2670-1-john@darrington.wattle.id.au>

Allow target remote to use the unix::/path/to/socket syntax as well as just
plain /path/to/socket

gdb/

  * ser-uds.c (uds_open): Use parse_connection_spec to deal with the
    comm form unix::/path/to/socket.

  * serial.c (serial_open): Consider the "unix:" prefix when deciding which
    interface to use.
---
 gdb/ser-uds.c | 18 ++++++++++++++++--
 gdb/serial.c  |  5 +++--
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/gdb/ser-uds.c b/gdb/ser-uds.c
index a98469f67b..acace258be 100644
--- a/gdb/ser-uds.c
+++ b/gdb/ser-uds.c
@@ -23,6 +23,8 @@
 
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <netdb.h>
+#include "netstuff.h"
 
 #ifndef UNIX_PATH_MAX
 #define UNIX_PATH_MAX sizeof(((struct sockaddr_un *) NULL)->sun_path)
@@ -33,9 +35,21 @@
 static int
 uds_open (struct serial *scb, const char *name)
 {
+  struct addrinfo hint;
+
+  memset (&hint, 0, sizeof (hint));
+  /* Assume no prefix will be passed, therefore we should use
+     AF_UNSPEC.  */
+  hint.ai_family = AF_UNSPEC;
+  hint.ai_socktype = SOCK_STREAM;
+
+  parsed_connection_spec parsed = parse_connection_spec (name, &hint);
+
+  const char *socket_name = parsed.port_str.empty() ? name : parsed.port_str.c_str ();
+
   struct sockaddr_un addr;
 
-  if (strlen (name) > UNIX_PATH_MAX - 1)
+  if (strlen (socket_name) > UNIX_PATH_MAX - 1)
     {
       warning
         (_("The socket name is too long.  It may be no longer than %s bytes."),
@@ -45,7 +59,7 @@ uds_open (struct serial *scb, const char *name)
 
   memset (&addr, 0, sizeof addr);
   addr.sun_family = AF_UNIX;
-  strncpy (addr.sun_path, name, UNIX_PATH_MAX - 1);
+  strncpy (addr.sun_path, socket_name, UNIX_PATH_MAX - 1);
 
   int sock = socket (AF_UNIX, SOCK_STREAM, 0);
 
diff --git a/gdb/serial.c b/gdb/serial.c
index 7f9362a3bf..f7c3e6e5ee 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -210,7 +210,7 @@ serial_open (const char *name)
   /* Check for a colon, suggesting an IP address/port pair.
      Do this *after* checking for all the interesting prefixes.  We
      don't want to constrain the syntax of what can follow them.  */
-  else if (strchr (name, ':'))
+  else if (!startswith (name, "unix:") && (strchr (name, ':')))
     ops = serial_interface_lookup ("tcp");
   else
     {
@@ -218,7 +218,8 @@ serial_open (const char *name)
       /* Check to see if name is a socket.  If it is, then treat it
          as such.  Otherwise assume that it's a character device.  */
       struct stat sb;
-      if (stat (name, &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFSOCK)
+      if (startswith (name, "unix:") ||
+	  (stat (name, &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFSOCK))
 	ops = serial_interface_lookup ("local");
       else
 #endif
-- 
2.11.0


  parent reply	other threads:[~2018-10-13 17:58 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 17:33 Gdbserver can listen on local domain sockets John Darrington
2018-10-09 17:33 ` [PATCH] GDBSERVER: Listen on a unix domain (instead of TCP) socket if requested John Darrington
2018-10-09 17:56   ` Eli Zaretskii
2018-10-09 18:02   ` Pedro Alves
2018-10-09 18:41     ` John Darrington
2018-10-09 18:53       ` Pedro Alves
2018-10-09 19:00         ` John Darrington
2018-10-09 19:06           ` Pedro Alves
2018-10-13 17:58     ` [PATCH 1/4] " John Darrington
2018-10-13 17:58       ` [PATCH 3/4] GDB: Fix documentation for invoking GDBSERVER John Darrington
2018-10-13 18:10         ` Eli Zaretskii
2018-10-18 20:27         ` Sergio Durigan Junior
2018-10-19  7:05           ` John Darrington
2018-10-19 20:45             ` Sergio Durigan Junior
2018-10-21  7:33               ` John Darrington
2018-10-21 16:47                 ` Sergio Durigan Junior
2018-10-23 18:25               ` John Darrington
2018-10-23 18:58                 ` Sergio Durigan Junior
2018-10-13 17:58       ` [PATCH 2/4] GDB: Document the unix::/path/to/socket of remote connection John Darrington
2018-10-13 18:11         ` Eli Zaretskii
2018-10-15  9:31         ` Simon Tatham
2018-10-18 20:21         ` Sergio Durigan Junior
2018-10-13 17:58       ` John Darrington [this message]
2018-10-13 18:12       ` [PATCH 1/4] GDBSERVER: Listen on a unix domain (instead of TCP) socket if requested Eli Zaretskii
2018-10-18 20:18       ` Sergio Durigan Junior
2018-10-19 18:55         ` John Darrington
2018-10-19 19:43           ` Sergio Durigan Junior
2018-10-28 16:20             ` Simon Marchi
2018-10-28 18:10               ` John Darrington
2018-10-28 18:51                 ` Simon Marchi
2018-10-29  8:24                   ` John Darrington
2018-10-29  9:13                     ` Rainer Orth
2018-10-29  9:38                       ` Rainer Orth
     [not found]                       ` <4da7206f-6e6a-7aad-634e-a4485d99e988@ericsson.com>
     [not found]                         ` <20181029162513.oztznqp74gudrqgm@jocasta.intra>
2018-10-29 16:42                           ` Sergio Durigan Junior
2018-10-29 17:34                             ` John Darrington
2018-10-31 13:54                               ` Simon Marchi
2018-10-29 18:32                             ` Simon Marchi

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=20181013175801.2670-4-john@darrington.wattle.id.au \
    --to=john@darrington.wattle.id.au \
    --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