[PATCH] winsock include fixes

Ozkan Sezer
2010-03-26T10:54:17Z

[-- Attachment #1: Type: text/plain, Size: 997 bytes --]

Hi: Here is a patch fixing the winsock include problem
which appeared after the recent winsock header work in
mingw-w64-headers. Problem is this: GDB does windows.h
and winsock2.h includes in its own headers and then it
includes them in its sources in an arbitrary order. If
winsock2.h or a header including winsock2.h (such as
gdb_select.h) is included after windows.h or a header
including windows.h (such as serial.h), then conflicting
definitions occur and they result in error, because windows.h
already includes winsock.h and including winsock2.h after
that is an error. The patch fixes that in a quick and
dirty way mostly by tweaking the include order. Tested
by compiling gdb for x86_64-w64-mingw32, i686-w64-mingw32
and x86_64-pc-linux-gnu. Please consider for applying.

--
Ozkan

PS:
A possibly better solution is defining WIN32_LEAN_AND_MEAN
before including windows.h and then manually including
the necessary additional headers in the sources, but that
may require some more work.

[-- Attachment #2: winsock_includes.patch --]
[-- Type: application/octet-stream, Size: 3749 bytes --]

Index: gdb/inflow.c
===================================================================
RCS file: /cvs/src/src/gdb/inflow.c,v
retrieving revision 1.58
diff -u -p -r1.58 inflow.c
--- gdb/inflow.c 24 Feb 2010 07:51:44 -0000 1.58
+++ gdb/inflow.c 26 Mar 2010 10:48:03 -0000
@@ -19,6 +19,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */

#include "defs.h"
+#include "gdb_select.h"
#include "frame.h"
#include "inferior.h"
#include "command.h"
@@ -31,7 +32,6 @@
#include "gdb_string.h"
#include <signal.h>
#include <fcntl.h>
-#include "gdb_select.h"

#include "inflow.h"

Index: gdb/mingw-hdep.c
===================================================================
RCS file: /cvs/src/src/gdb/mingw-hdep.c,v
retrieving revision 1.11
diff -u -p -r1.11 mingw-hdep.c
--- gdb/mingw-hdep.c 1 Jan 2010 07:31:37 -0000 1.11
+++ gdb/mingw-hdep.c 26 Mar 2010 10:48:03 -0000
@@ -18,11 +18,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */

#include "defs.h"
+#include "gdb_select.h"
#include "serial.h"
#include "event-loop.h"

#include "gdb_assert.h"
-#include "gdb_select.h"
#include "gdb_string.h"
#include "readline/readline.h"

Index: gdb/ser-base.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-base.c,v
retrieving revision 1.15
diff -u -p -r1.15 ser-base.c
--- gdb/ser-base.c 1 Jan 2010 07:31:41 -0000 1.15
+++ gdb/ser-base.c 26 Mar 2010 10:48:03 -0000
@@ -19,6 +19,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */

#include "defs.h"
+#ifdef USE_WIN32API
+#include <winsock2.h>
+#endif
#include "serial.h"
#include "ser-base.h"
#include "event-loop.h"
@@ -26,9 +29,6 @@
#include "gdb_select.h"
#include "gdb_string.h"
#include <sys/time.h>
-#ifdef USE_WIN32API
-#include <winsock2.h>
-#endif

static timer_handler_func push_event;
Index: gdb/ser-mingw.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-mingw.c,v
retrieving revision 1.20
diff -u -p -r1.20 ser-mingw.c
--- gdb/ser-mingw.c 1 Jan 2010 07:31:41 -0000 1.20
+++ gdb/ser-mingw.c 26 Mar 2010 10:48:03 -0000
@@ -18,6 +18,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */

#include "defs.h"
+#ifdef USE_WIN32API
+#include <winsock2.h>
+#endif
#include "serial.h"
#include "ser-base.h"
#include "ser-tcp.h"
Index: gdb/ser-tcp.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-tcp.c,v
retrieving revision 1.33
diff -u -p -r1.33 ser-tcp.c
--- gdb/ser-tcp.c 1 Jan 2010 07:31:41 -0000 1.33
+++ gdb/ser-tcp.c 26 Mar 2010 10:48:03 -0000
@@ -19,6 +19,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */

#include "defs.h"
+#ifdef USE_WIN32API
+#include <winsock2.h>
+#endif
#include "serial.h"
#include "ser-base.h"
#include "ser-tcp.h"
@@ -38,7 +41,6 @@
#include <sys/time.h>

#ifdef USE_WIN32API
-#include <winsock2.h>
#define ETIMEDOUT WSAETIMEDOUT
#define close(fd) closesocket (fd)
#define ioctl ioctlsocket
Index: gdb/ser-unix.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-unix.c,v
retrieving revision 1.34
diff -u -p -r1.34 ser-unix.c
--- gdb/ser-unix.c 1 Jan 2010 07:31:41 -0000 1.34
+++ gdb/ser-unix.c 26 Mar 2010 10:48:03 -0000
@@ -19,6 +19,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */

#include "defs.h"
+#include "gdb_select.h"
#include "serial.h"
#include "ser-base.h"
#include "ser-unix.h"
@@ -29,7 +30,6 @@
#include <sys/socket.h>
#include <sys/time.h>

-#include "gdb_select.h"
#include "gdb_string.h"
#include "gdbcmd.h"