[v2,2/2] Make gdbserver connect to SOCK_STREAM sockets
Commit Message
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(-)
Comments
On 04 May 2015 23:54, Gabriel Corona wrote:
> +static int
> +socket_open (char *name)
const
> + int sock;
> + struct sockaddr_un addr;
> +
> + if (strlen (name) >= sizeof (addr.sun_path))
> + return -1;
> + sock = socket (AF_UNIX, SOCK_STREAM, 0);
prefer a blank line before the socket()
> + 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;
> +}
blank line above this last return statement
-mike
@@ -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;
@@ -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"