From 9eb1356e381f3412f53ffe5bc68ce854330600fb Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 9 Mar 2015 11:27:05 +0000 Subject: [PATCH] Revert union gdb_sockaddr_u This reverts 366c75fc. We don't actually need to access the object through "struct sockaddr *", so we don't need the union: https://sourceware.org/ml/gdb-patches/2015-03/msg00213.html gdb/ChangeLog: 2015-03-09 Pedro Alves Revert: 2015-03-07 Pedro Alves * common/gdb_socket.h: New file. * ser-tcp.c: Include gdb_socket.h. Don't include netinet/in.h nor sys/socket.h. (net_open): Use union gdb_sockaddr_u. gdb/gdbserver/ChangeLog: 2015-03-09 Pedro Alves Revert: 2015-03-07 Pedro Alves * gdbreplay.c: No longer include , , or here. Instead include "gdb_socket.h". (remote_open): Use union gdb_sockaddr_u. * remote-utils.c: No longer include , or here. Instead include "gdb_socket.h". (handle_accept_event, remote_prepare): Use union gdb_sockaddr_u. * tracepoint.c: Include "gdb_socket.h" instead of or . (init_named_socket, gdb_agent_helper_thread): Use union gdb_sockaddr_u. --- gdb/ChangeLog | 9 ++++++++ gdb/common/gdb_socket.h | 43 ------------------------------------ gdb/gdbserver/ChangeLog | 15 +++++++++++++ gdb/gdbserver/gdbreplay.c | 24 +++++++++++++------- gdb/gdbserver/remote-utils.c | 29 +++++++++++++++--------- gdb/gdbserver/tracepoint.c | 19 ++++++++-------- gdb/ser-tcp.c | 14 ++++++------ 7 files changed, 76 insertions(+), 77 deletions(-) delete mode 100644 gdb/common/gdb_socket.h diff --git a/gdb/ChangeLog b/gdb/ChangeLog index eee5badd29..a5d9d42586 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2015-03-09 Pedro Alves + + Revert: + 2015-03-07 Pedro Alves + * common/gdb_socket.h: New file. + * ser-tcp.c: Include gdb_socket.h. Don't include netinet/in.h nor + sys/socket.h. + (net_open): Use union gdb_sockaddr_u. + 2015-03-07 Pedro Alves * configure.ac (build_warnings): Move -Wmissing-prototypes diff --git a/gdb/common/gdb_socket.h b/gdb/common/gdb_socket.h deleted file mode 100644 index a670f7479a..0000000000 --- a/gdb/common/gdb_socket.h +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright (C) 2015 Free Software Foundation, Inc. - - This file is part of GDB. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#ifndef GDB_SOCKET_H -#define GDB_SOCKET_H - -#if USE_WIN32API -#include -#else -#include -#include -#if HAVE_SYS_UN_H -#include -#endif -#endif - -/* Use this union instead of casts between struct sockaddr <-> struct - sockaddr_foo to avoid strict aliasing violations. */ - -union gdb_sockaddr_u -{ - struct sockaddr sa; - struct sockaddr_in sa_in; -#if HAVE_SYS_UN_H - struct sockaddr_un sa_un; -#endif -}; - -#endif /* GDB_SOCKET_H */ diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index b27090ee9a..e26f123118 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,18 @@ +2015-03-09 Pedro Alves + + Revert: + 2015-03-07 Pedro Alves + * gdbreplay.c: No longer include , , + or here. Instead include "gdb_socket.h". + (remote_open): Use union gdb_sockaddr_u. + * remote-utils.c: No longer include , + or here. Instead include "gdb_socket.h". + (handle_accept_event, remote_prepare): Use union gdb_sockaddr_u. + * tracepoint.c: Include "gdb_socket.h" instead of + or . + (init_named_socket, gdb_agent_helper_thread): Use union + gdb_sockaddr_u. + 2015-03-07 Pedro Alves * configure.ac (build_warnings): Move diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c index bfd6f1918a..a02a824072 100644 --- a/gdb/gdbserver/gdbreplay.c +++ b/gdb/gdbserver/gdbreplay.c @@ -36,16 +36,24 @@ #include #include #include +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif #if HAVE_NETDB_H #include #endif #if HAVE_NETINET_TCP_H #include #endif -#include "gdb_socket.h" #include +#if USE_WIN32API +#include +#endif #ifndef HAVE_SOCKLEN_T typedef int socklen_t; @@ -180,7 +188,7 @@ remote_open (char *name) #endif char *port_str; int port; - union gdb_sockaddr_u sockaddr; + struct sockaddr_in sockaddr; socklen_t tmp; int tmp_desc; @@ -207,16 +215,16 @@ remote_open (char *name) setsockopt (tmp_desc, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof (tmp)); - sockaddr.sa_in.sin_family = PF_INET; - sockaddr.sa_in.sin_port = htons (port); - sockaddr.sa_in.sin_addr.s_addr = INADDR_ANY; + sockaddr.sin_family = PF_INET; + sockaddr.sin_port = htons (port); + sockaddr.sin_addr.s_addr = INADDR_ANY; - if (bind (tmp_desc, &sockaddr.sa, sizeof (sockaddr.sa_in)) + if (bind (tmp_desc, (struct sockaddr *) &sockaddr, sizeof (sockaddr)) || listen (tmp_desc, 1)) perror_with_name ("Can't bind address"); - tmp = sizeof (sockaddr.sa_in); - remote_desc = accept (tmp_desc, &sockaddr.sa, &tmp); + tmp = sizeof (sockaddr); + remote_desc = accept (tmp_desc, (struct sockaddr *) &sockaddr, &tmp); if (remote_desc == -1) perror_with_name ("Accept failed"); diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index 69f87bd27f..1de86beecf 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -30,6 +30,12 @@ #if HAVE_SYS_FILE_H #include #endif +#if HAVE_NETINET_IN_H +#include +#endif +#if HAVE_SYS_SOCKET_H +#include +#endif #if HAVE_NETDB_H #include #endif @@ -51,7 +57,10 @@ #include #endif #include -#include "gdb_socket.h" + +#if USE_WIN32API +#include +#endif #if __QNX__ #include @@ -144,14 +153,14 @@ enable_async_notification (int fd) static int handle_accept_event (int err, gdb_client_data client_data) { - union gdb_sockaddr_u sockaddr; + struct sockaddr_in sockaddr; socklen_t tmp; if (debug_threads) debug_printf ("handling possible accept event\n"); - tmp = sizeof (sockaddr.sa_in); - remote_desc = accept (listen_desc, &sockaddr.sa, &tmp); + tmp = sizeof (sockaddr); + remote_desc = accept (listen_desc, (struct sockaddr *) &sockaddr, &tmp); if (remote_desc == -1) perror_with_name ("Accept failed"); @@ -186,7 +195,7 @@ handle_accept_event (int err, gdb_client_data client_data) /* Convert IP address to string. */ fprintf (stderr, "Remote debugging from host %s\n", - inet_ntoa (sockaddr.sa_in.sin_addr)); + inet_ntoa (sockaddr.sin_addr)); enable_async_notification (remote_desc); @@ -215,7 +224,7 @@ remote_prepare (char *name) static int winsock_initialized; #endif int port; - union gdb_sockaddr_u sockaddr; + struct sockaddr_in sockaddr; socklen_t tmp; char *port_end; @@ -260,11 +269,11 @@ remote_prepare (char *name) setsockopt (listen_desc, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof (tmp)); - sockaddr.sa_in.sin_family = PF_INET; - sockaddr.sa_in.sin_port = htons (port); - sockaddr.sa_in.sin_addr.s_addr = INADDR_ANY; + sockaddr.sin_family = PF_INET; + sockaddr.sin_port = htons (port); + sockaddr.sin_addr.s_addr = INADDR_ANY; - if (bind (listen_desc, &sockaddr.sa, sizeof (sockaddr.sa_in)) + if (bind (listen_desc, (struct sockaddr *) &sockaddr, sizeof (sockaddr)) || listen (listen_desc, 1)) perror_with_name ("Can't bind address"); diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c index 6c34ad4494..27fcf03247 100644 --- a/gdb/gdbserver/tracepoint.c +++ b/gdb/gdbserver/tracepoint.c @@ -6817,7 +6817,8 @@ run_inferior_command (char *cmd, int len) #else /* !IN_PROCESS_AGENT */ -#include "gdb_socket.h" +#include +#include #ifndef UNIX_PATH_MAX #define UNIX_PATH_MAX sizeof(((struct sockaddr_un *) NULL)->sun_path) @@ -6836,7 +6837,7 @@ static int init_named_socket (const char *name) { int result, fd; - union gdb_sockaddr_u addr; + struct sockaddr_un addr; result = fd = socket (PF_UNIX, SOCK_STREAM, 0); if (result == -1) @@ -6845,10 +6846,10 @@ init_named_socket (const char *name) return -1; } - addr.sa_un.sun_family = AF_UNIX; + addr.sun_family = AF_UNIX; - strncpy (addr.sa_un.sun_path, name, UNIX_PATH_MAX); - addr.sa_un.sun_path[UNIX_PATH_MAX - 1] = '\0'; + strncpy (addr.sun_path, name, UNIX_PATH_MAX); + addr.sun_path[UNIX_PATH_MAX - 1] = '\0'; result = access (name, F_OK); if (result == 0) @@ -6864,7 +6865,7 @@ init_named_socket (const char *name) warning ("socket %s already exists; overwriting", name); } - result = bind (fd, &addr.sa, sizeof (addr.sa_un)); + result = bind (fd, (struct sockaddr *) &addr, sizeof (addr)); if (result == -1) { warning ("bind failed: %s", strerror (errno)); @@ -7163,17 +7164,17 @@ gdb_agent_helper_thread (void *arg) while (1) { socklen_t tmp; - union gdb_sockaddr_u sockaddr; + struct sockaddr_un sockaddr; int fd; char buf[1]; int ret; int stop_loop = 0; - tmp = sizeof (sockaddr.sa_un); + tmp = sizeof (sockaddr); do { - fd = accept (listen_fd, &sockaddr.sa, &tmp); + fd = accept (listen_fd, &sockaddr, &tmp); } /* It seems an ERESTARTSYS can escape out of accept. */ while (fd == -512 || (fd == -1 && errno == EINTR)); diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c index 648f1fb1d3..9c3dcf4ee4 100644 --- a/gdb/ser-tcp.c +++ b/gdb/ser-tcp.c @@ -37,8 +37,6 @@ #include -#include "gdb_socket.h" - #ifdef USE_WIN32API #include #ifndef ETIMEDOUT @@ -47,8 +45,10 @@ #define close(fd) closesocket (fd) #define ioctl ioctlsocket #else +#include #include #include +#include #include #endif @@ -159,7 +159,7 @@ net_open (struct serial *scb, const char *name) int n, port, tmp; int use_udp; struct hostent *hostent; - union gdb_sockaddr_u sockaddr; + struct sockaddr_in sockaddr; #ifdef USE_WIN32API u_long ioarg; #else @@ -199,9 +199,9 @@ net_open (struct serial *scb, const char *name) return -1; } - sockaddr.sa_in.sin_family = PF_INET; - sockaddr.sa_in.sin_port = htons (port); - memcpy (&sockaddr.sa_in.sin_addr.s_addr, hostent->h_addr, + sockaddr.sin_family = PF_INET; + sockaddr.sin_port = htons (port); + memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr, sizeof (struct in_addr)); retry: @@ -220,7 +220,7 @@ net_open (struct serial *scb, const char *name) /* Use Non-blocking connect. connect() will return 0 if connected already. */ - n = connect (scb->fd, &sockaddr.sa, sizeof (sockaddr.sa_in)); + n = connect (scb->fd, (struct sockaddr *) &sockaddr, sizeof (sockaddr)); if (n < 0) { -- 2.34.1