From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106069 invoked by alias); 13 Oct 2018 17:58:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 106022 invoked by uid 89); 13 Oct 2018 17:58:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy=hint, prefixes X-HELO: jocasta.intra Received: from de.cellform.com (HELO jocasta.intra) (88.217.224.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 13 Oct 2018 17:58:07 +0000 Received: from jocasta.intra (localhost [127.0.0.1]) by jocasta.intra (8.15.2/8.15.2/Debian-8) with ESMTPS id w9DHw4HD002737 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 13 Oct 2018 19:58:05 +0200 Received: (from john@localhost) by jocasta.intra (8.15.2/8.15.2/Submit) id w9DHw4in002733; Sat, 13 Oct 2018 19:58:04 +0200 From: John Darrington To: gdb-patches@sourceware.org Cc: John Darrington 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 Message-Id: <20181013175801.2670-4-john@darrington.wattle.id.au> In-Reply-To: <20181013175801.2670-1-john@darrington.wattle.id.au> References: <20181013175801.2670-1-john@darrington.wattle.id.au> X-SW-Source: 2018-10/txt/msg00306.txt.bz2 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 #include +#include +#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