• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Révision064eee739c55428d8d297408e8e79abfe55935f7 (tree)
l'heure2005-03-29 03:46:22
AuteurMark Mitchell <mark@code...>
CommiterMark Mitchell

Message de Log

* gdb/configure.ac: Link with -lws2_32 on mingw.
* gdb/configure: Regenerated.
* gdb/defs.h (WINAPI): Define, conditionally.
* gdb/ser-base.c (winsock2.h): Include it.
(fd_event): Use read_prim.
(ser_base_wait_for): Moved here from ser-unix.c.
(do_ser_base_readchar): Likewise.
(generic_readchar): Likewise.
(ser_base_readchar): Likewise.
* gdb/ser-base.h (generic_readchar): Declare.
(ser_base_readchar): Likewise.
* gdb/ser-pipe.c (_initialize_ser_pipe): Adjust for name changes.
* gdb/ser-tcp.c (winsock2.h): Include it.
(ETIMEDOUT): Define on Windows.
(closesocket): Define on UNIX.
(ioctlsocket): Likewise.
(net_open): Adjust for differences in socket functions between
Windows and UNIX.
(_initialize_ser_tcp): Adjust for name changes.
(net_read_prim): New function.
(net_write_prim): Likewise.
* gdb/ser-unix.c (generic_readchar): Remove.
(ser_unix_wait_for): Likewise.
(do_unix_readchar): Likewise.
(ser_unix_readchar): Likewise.
(_initialize_ser_hardwire): Adjust for name changes.
(ser_unix_read_prim): New function.
(ser_unix_write_prim): New function.
* gdb/ser-unix.h (ser_unix_readchar): Remove.
(ser_unix_read_prim): Declare.
(ser_unix_write_prim): Declare.
* gdb/serial.h (struct serial_ops): Add read_prim and write_prim.
* gdb/utils.c (winerror.h): Include it.
(safe_strerror): Handle winsock errors.

Change Summary

Modification

--- a/ChangeLog.csl
+++ b/ChangeLog.csl
@@ -1,3 +1,40 @@
1+2005-03-25 Mark Mitchell <mark@codesourcery.com>
2+
3+ * gdb/configure.ac: Link with -lws2_32 on mingw.
4+ * gdb/configure: Regenerated.
5+ * gdb/defs.h (WINAPI): Define, conditionally.
6+ * gdb/ser-base.c (winsock2.h): Include it.
7+ (fd_event): Use read_prim.
8+ (ser_base_wait_for): Moved here from ser-unix.c.
9+ (do_ser_base_readchar): Likewise.
10+ (generic_readchar): Likewise.
11+ (ser_base_readchar): Likewise.
12+ * gdb/ser-base.h (generic_readchar): Declare.
13+ (ser_base_readchar): Likewise.
14+ * gdb/ser-pipe.c (_initialize_ser_pipe): Adjust for name changes.
15+ * gdb/ser-tcp.c (winsock2.h): Include it.
16+ (ETIMEDOUT): Define on Windows.
17+ (closesocket): Define on UNIX.
18+ (ioctlsocket): Likewise.
19+ (net_open): Adjust for differences in socket functions between
20+ Windows and UNIX.
21+ (_initialize_ser_tcp): Adjust for name changes.
22+ (net_read_prim): New function.
23+ (net_write_prim): Likewise.
24+ * gdb/ser-unix.c (generic_readchar): Remove.
25+ (ser_unix_wait_for): Likewise.
26+ (do_unix_readchar): Likewise.
27+ (ser_unix_readchar): Likewise.
28+ (_initialize_ser_hardwire): Adjust for name changes.
29+ (ser_unix_read_prim): New function.
30+ (ser_unix_write_prim): New function.
31+ * gdb/ser-unix.h (ser_unix_readchar): Remove.
32+ (ser_unix_read_prim): Declare.
33+ (ser_unix_write_prim): Declare.
34+ * gdb/serial.h (struct serial_ops): Add read_prim and write_prim.
35+ * gdb/utils.c (winerror.h): Include it.
36+ (safe_strerror): Handle winsock errors.
37+
138 2005-03-28 Mark Mitchell <mark@codesourcery.com>
239
340 Backport from mainline:
--- a/gdb/configure
+++ b/gdb/configure
@@ -15593,6 +15593,109 @@ fi
1559315593 done
1559415594
1559515595
15596+
15597+for ac_func in recv send
15598+do
15599+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
15600+echo "$as_me:$LINENO: checking for $ac_func" >&5
15601+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
15602+if eval "test \"\${$as_ac_var+set}\" = set"; then
15603+ echo $ECHO_N "(cached) $ECHO_C" >&6
15604+else
15605+ cat >conftest.$ac_ext <<_ACEOF
15606+/* confdefs.h. */
15607+_ACEOF
15608+cat confdefs.h >>conftest.$ac_ext
15609+cat >>conftest.$ac_ext <<_ACEOF
15610+/* end confdefs.h. */
15611+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
15612+ For example, HP-UX 11i <limits.h> declares gettimeofday. */
15613+#define $ac_func innocuous_$ac_func
15614+
15615+/* System header to define __stub macros and hopefully few prototypes,
15616+ which can conflict with char $ac_func (); below.
15617+ Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
15618+ <limits.h> exists even on freestanding compilers. */
15619+
15620+#ifdef __STDC__
15621+# include <limits.h>
15622+#else
15623+# include <assert.h>
15624+#endif
15625+
15626+#undef $ac_func
15627+
15628+/* Override any gcc2 internal prototype to avoid an error. */
15629+#ifdef __cplusplus
15630+extern "C"
15631+{
15632+#endif
15633+/* We use char because int might match the return type of a gcc2
15634+ builtin and then its argument prototype would still apply. */
15635+char $ac_func ();
15636+/* The GNU C library defines this for functions which it implements
15637+ to always fail with ENOSYS. Some functions are actually named
15638+ something starting with __ and the normal name is an alias. */
15639+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
15640+choke me
15641+#else
15642+char (*f) () = $ac_func;
15643+#endif
15644+#ifdef __cplusplus
15645+}
15646+#endif
15647+
15648+int
15649+main ()
15650+{
15651+return f != $ac_func;
15652+ ;
15653+ return 0;
15654+}
15655+_ACEOF
15656+rm -f conftest.$ac_objext conftest$ac_exeext
15657+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
15658+ (eval $ac_link) 2>conftest.er1
15659+ ac_status=$?
15660+ grep -v '^ *+' conftest.er1 >conftest.err
15661+ rm -f conftest.er1
15662+ cat conftest.err >&5
15663+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
15664+ (exit $ac_status); } &&
15665+ { ac_try='test -z "$ac_c_werror_flag"
15666+ || test ! -s conftest.err'
15667+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
15668+ (eval $ac_try) 2>&5
15669+ ac_status=$?
15670+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
15671+ (exit $ac_status); }; } &&
15672+ { ac_try='test -s conftest$ac_exeext'
15673+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
15674+ (eval $ac_try) 2>&5
15675+ ac_status=$?
15676+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
15677+ (exit $ac_status); }; }; then
15678+ eval "$as_ac_var=yes"
15679+else
15680+ echo "$as_me: failed program was:" >&5
15681+sed 's/^/| /' conftest.$ac_ext >&5
15682+
15683+eval "$as_ac_var=no"
15684+fi
15685+rm -f conftest.err conftest.$ac_objext \
15686+ conftest$ac_exeext conftest.$ac_ext
15687+fi
15688+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
15689+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
15690+if test `eval echo '${'$as_ac_var'}'` = yes; then
15691+ cat >>confdefs.h <<_ACEOF
15692+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
15693+_ACEOF
15694+
15695+fi
15696+done
15697+
15698+
1559615699 for ac_func in sbrk
1559715700 do
1559815701 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
@@ -20034,6 +20137,13 @@ if test x$gdb_cv_os_cygwin = xyes; then
2003420137 esac
2003520138 fi
2003620139
20140+# The ser-tcp.c module requires sockets.
20141+case ${host} in
20142+ *mingw32*)
20143+ WIN32LIBS="$WIN32LIBS -lws2_32"
20144+ ;;
20145+esac
20146+
2003720147
2003820148 LIBGUI="../libgui/src/libgui.a"
2003920149 GUI_CFLAGS_X="-I${srcdir}/../libgui/src"
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -451,6 +451,7 @@ AC_CHECK_FUNCS(canonicalize_file_name realpath)
451451 AC_CHECK_FUNCS(getuid getgid)
452452 AC_CHECK_FUNCS(poll)
453453 AC_CHECK_FUNCS(pread64)
454+AC_CHECK_FUNCS(recv send)
454455 AC_CHECK_FUNCS(sbrk)
455456 AC_CHECK_FUNCS(setpgid setpgrp)
456457 AC_CHECK_FUNCS(sigaction sigprocmask sigsetmask)
@@ -1187,6 +1188,13 @@ if test x$gdb_cv_os_cygwin = xyes; then
11871188 ;;
11881189 esac
11891190 fi
1191+
1192+# The ser-tcp.c module requires sockets.
1193+case ${host} in
1194+ *mingw32*)
1195+ WIN32LIBS="$WIN32LIBS -lws2_32"
1196+ ;;
1197+esac
11901198 AC_SUBST(WIN32LIBS)
11911199
11921200 LIBGUI="../libgui/src/libgui.a"
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -1153,6 +1153,10 @@ extern int use_windows;
11531153 #define SLASH_STRING "/"
11541154 #endif
11551155
1156+#if defined(__WIN32__) && !defined(__CYGWIN__)
1157+#define WINAPI
1158+#endif
1159+
11561160 /* Provide default definitions of PIDGET, TIDGET, and MERGEPID.
11571161 The name ``TIDGET'' is a historical accident. Many uses of TIDGET
11581162 in the code actually refer to a lightweight process id, i.e,
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -144,7 +144,7 @@ _initialize_ser_pipe (void)
144144 ops->next = 0;
145145 ops->open = pipe_open;
146146 ops->close = pipe_close;
147- ops->readchar = ser_unix_readchar;
147+ ops->readchar = ser_base_readchar;
148148 ops->write = ser_base_write;
149149 ops->flush_output = ser_base_flush_output;
150150 ops->flush_input = ser_base_flush_input;
@@ -158,5 +158,7 @@ _initialize_ser_pipe (void)
158158 ops->setstopbits = ser_base_setstopbits;
159159 ops->drain_output = ser_base_drain_output;
160160 ops->async = ser_base_async;
161+ ops->read_prim = ser_unix_read_prim;
162+ ops->write_prim = ser_unix_write_prim;
161163 serial_add_interface (ops);
162164 }
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -34,11 +34,19 @@
3434 #endif
3535
3636 #include <sys/time.h>
37+
38+#ifdef WINAPI
39+#include <winsock2.h>
40+#define ETIMEDOUT WSAETIMEDOUT
41+#else
3742 #include <netinet/in.h>
3843 #include <arpa/inet.h>
3944 #include <netdb.h>
4045 #include <sys/socket.h>
4146 #include <netinet/tcp.h>
47+#define closesocket close
48+#define ioctlsocket ioctl
49+#endif
4250
4351 #include <signal.h>
4452 #include "gdb_string.h"
@@ -62,6 +70,11 @@ net_open (struct serial *scb, const char *name)
6270 int use_udp;
6371 struct hostent *hostent;
6472 struct sockaddr_in sockaddr;
73+#ifdef WINAPI
74+ u_long ioarg;
75+#else
76+ int ioarg;
77+#endif
6578
6679 use_udp = 0;
6780 if (strncmp (name, "udp:", 4) == 0)
@@ -108,14 +121,25 @@ net_open (struct serial *scb, const char *name)
108121 sizeof (struct in_addr));
109122
110123 /* set socket nonblocking */
111- tmp = 1;
112- ioctl (scb->fd, FIONBIO, &tmp);
124+ ioarg = 1;
125+ ioctlsocket (scb->fd, FIONBIO, &ioarg);
113126
114127 /* Use Non-blocking connect. connect() will return 0 if connected already. */
115128 n = connect (scb->fd, (struct sockaddr *) &sockaddr, sizeof (sockaddr));
116129
117- if (n < 0 && errno != EINPROGRESS)
130+ if (n < 0
131+#ifdef WINAPI
132+ /* Under Windows, calling "connect" with a non-blocking socket
133+ results in WSAEWOULDBLOCK, not WSAEINPROGRESS. */
134+ && WSAGetLastError() != WSAEWOULDBLOCK
135+#else
136+ && errno != EINPROGRESS
137+#endif
138+ )
118139 {
140+#ifdef WINAPI
141+ errno = WSAGetLastError();
142+#endif
119143 net_close (scb);
120144 return -1;
121145 }
@@ -165,7 +189,11 @@ net_open (struct serial *scb, const char *name)
165189 {
166190 int res, err, len;
167191 len = sizeof(err);
168- res = getsockopt (scb->fd, SOL_SOCKET, SO_ERROR, &err, &len);
192+ /* On Windows, the fourth parameter to getsockopt is a "char *";
193+ on UNIX systems it is generally "void *". The cast to "void *"
194+ is OK everywhere, since in C "void *" can be implicitly
195+ converted to any pointer type. */
196+ res = getsockopt (scb->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len);
169197 if (res < 0 || err)
170198 {
171199 if (err)
@@ -176,8 +204,8 @@ net_open (struct serial *scb, const char *name)
176204 }
177205
178206 /* turn off nonblocking */
179- tmp = 0;
180- ioctl (scb->fd, FIONBIO, &tmp);
207+ ioarg = 0;
208+ ioctlsocket (scb->fd, FIONBIO, &ioarg);
181209
182210 if (use_udp == 0)
183211 {
@@ -202,20 +230,47 @@ net_close (struct serial *scb)
202230 if (scb->fd < 0)
203231 return;
204232
205- close (scb->fd);
233+ closesocket (scb->fd);
206234 scb->fd = -1;
207235 }
208236
237+static int
238+net_read_prim (struct serial *scb, size_t count)
239+{
240+#ifdef HAVE_RECV
241+ return recv (scb->fd, scb->buf, count, 0);
242+#else
243+ return ser_unix_read_prim (scb, count);
244+#endif
245+}
246+
247+static int
248+net_write_prim (struct serial *scb, const char *str, int len)
249+{
250+#ifdef HAVE_SEND
251+ return send (scb->fd, str, len, 0);
252+#else
253+ return ser_unix_write_prim (scb, str, len);
254+#endif
255+}
256+
209257 void
210258 _initialize_ser_tcp (void)
211259 {
212- struct serial_ops *ops = XMALLOC (struct serial_ops);
260+ struct serial_ops *ops;
261+#ifdef WINAPI
262+ WSADATA wsa_data;
263+ if (WSAStartup (MAKEWORD (1, 0), &wsa_data) != 0)
264+ /* WinSock is unavailable. */
265+ return;
266+#endif
267+ ops = XMALLOC (struct serial_ops);
213268 memset (ops, 0, sizeof (struct serial_ops));
214269 ops->name = "tcp";
215270 ops->next = 0;
216271 ops->open = net_open;
217272 ops->close = net_close;
218- ops->readchar = ser_unix_readchar;
273+ ops->readchar = ser_base_readchar;
219274 ops->write = ser_base_write;
220275 ops->flush_output = ser_base_flush_output;
221276 ops->flush_input = ser_base_flush_input;
@@ -229,5 +284,7 @@ _initialize_ser_tcp (void)
229284 ops->setstopbits = ser_base_setstopbits;
230285 ops->drain_output = ser_base_drain_output;
231286 ops->async = ser_base_async;
287+ ops->read_prim = net_read_prim;
288+ ops->write_prim = net_write_prim;
232289 serial_add_interface (ops);
233290 }
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -70,9 +70,6 @@ static void hardwire_raw (struct serial *scb);
7070 static int wait_for (struct serial *scb, int timeout);
7171 static int hardwire_readchar (struct serial *scb, int timeout);
7272 static int do_hardwire_readchar (struct serial *scb, int timeout);
73-static int generic_readchar (struct serial *scb, int timeout,
74- int (*do_readchar) (struct serial *scb,
75- int timeout));
7673 static int rate_to_code (int rate);
7774 static int hardwire_setbaudrate (struct serial *scb, int rate);
7875 static void hardwire_close (struct serial *scb);
@@ -422,7 +419,7 @@ hardwire_raw (struct serial *scb)
422419 */
423420
424421 /* FIXME: cagney/1999-09-16: Don't replace this with the equivalent
425- ser_unix*() until the old TERMIOS/SGTTY/... timer code has been
422+ ser_base*() until the old TERMIOS/SGTTY/... timer code has been
426423 flushed. . */
427424
428425 /* NOTE: cagney/1999-09-30: Much of the code below is dead. The only
@@ -542,13 +539,13 @@ wait_for (struct serial *scb, int timeout)
542539 dropped dead, or SERIAL_ERROR for any other error (see errno in that case). */
543540
544541 /* FIXME: cagney/1999-09-16: Don't replace this with the equivalent
545- ser_unix*() until the old TERMIOS/SGTTY/... timer code has been
542+ ser_base*() until the old TERMIOS/SGTTY/... timer code has been
546543 flushed. */
547544
548545 /* NOTE: cagney/1999-09-16: This function is not identical to
549- ser_unix_readchar() as part of replacing it with ser_unix*()
546+ ser_base_readchar() as part of replacing it with ser_base*()
550547 merging will be required - this code handles the case where read()
551- times out due to no data while ser_unix_readchar() doesn't expect
548+ times out due to no data while ser_base_readchar() doesn't expect
552549 that. */
553550
554551 static int
@@ -863,191 +860,7 @@ hardwire_close (struct serial *scb)
863860 close (scb->fd);
864861 scb->fd = -1;
865862 }
866-
867863
868-/* Wait for input on scb, with timeout seconds. Returns 0 on success,
869- otherwise SERIAL_TIMEOUT or SERIAL_ERROR. */
870-
871-static int
872-ser_unix_wait_for (struct serial *scb, int timeout)
873-{
874- while (1)
875- {
876- int numfds;
877- struct timeval tv;
878- fd_set readfds, exceptfds;
879-
880- /* NOTE: Some OS's can scramble the READFDS when the select()
881- call fails (ex the kernel with Red Hat 5.2). Initialize all
882- arguments before each call. */
883-
884- tv.tv_sec = timeout;
885- tv.tv_usec = 0;
886-
887- FD_ZERO (&readfds);
888- FD_ZERO (&exceptfds);
889- FD_SET (scb->fd, &readfds);
890- FD_SET (scb->fd, &exceptfds);
891-
892- if (timeout >= 0)
893- numfds = select (scb->fd + 1, &readfds, 0, &exceptfds, &tv);
894- else
895- numfds = select (scb->fd + 1, &readfds, 0, &exceptfds, 0);
896-
897- if (numfds <= 0)
898- {
899- if (numfds == 0)
900- return SERIAL_TIMEOUT;
901- else if (errno == EINTR)
902- continue;
903- else
904- return SERIAL_ERROR; /* Got an error from select or poll */
905- }
906-
907- return 0;
908- }
909-}
910-
911-/* Read a character with user-specified timeout. TIMEOUT is number of seconds
912- to wait, or -1 to wait forever. Use timeout of 0 to effect a poll. Returns
913- char if successful. Returns -2 if timeout expired, EOF if line dropped
914- dead, or -3 for any other error (see errno in that case). */
915-
916-static int
917-do_unix_readchar (struct serial *scb, int timeout)
918-{
919- int status;
920- int delta;
921-
922- /* We have to be able to keep the GUI alive here, so we break the
923- original timeout into steps of 1 second, running the "keep the
924- GUI alive" hook each time through the loop.
925-
926- Also, timeout = 0 means to poll, so we just set the delta to 0,
927- so we will only go through the loop once. */
928-
929- delta = (timeout == 0 ? 0 : 1);
930- while (1)
931- {
932-
933- /* N.B. The UI may destroy our world (for instance by calling
934- remote_stop,) in which case we want to get out of here as
935- quickly as possible. It is not safe to touch scb, since
936- someone else might have freed it. The
937- deprecated_ui_loop_hook signals that we should exit by
938- returning 1. */
939-
940- if (deprecated_ui_loop_hook)
941- {
942- if (deprecated_ui_loop_hook (0))
943- return SERIAL_TIMEOUT;
944- }
945-
946- status = ser_unix_wait_for (scb, delta);
947- if (timeout > 0)
948- timeout -= delta;
949-
950- /* If we got a character or an error back from wait_for, then we can
951- break from the loop before the timeout is completed. */
952-
953- if (status != SERIAL_TIMEOUT)
954- {
955- break;
956- }
957-
958- /* If we have exhausted the original timeout, then generate
959- a SERIAL_TIMEOUT, and pass it out of the loop. */
960-
961- else if (timeout == 0)
962- {
963- status = SERIAL_TIMEOUT;
964- break;
965- }
966- }
967-
968- if (status < 0)
969- return status;
970-
971- while (1)
972- {
973- status = read (scb->fd, scb->buf, BUFSIZ);
974- if (status != -1 || errno != EINTR)
975- break;
976- }
977-
978- if (status <= 0)
979- {
980- if (status == 0)
981- return SERIAL_TIMEOUT; /* 0 chars means timeout [may need to
982- distinguish between EOF & timeouts
983- someday] */
984- else
985- return SERIAL_ERROR; /* Got an error from read */
986- }
987-
988- scb->bufcnt = status;
989- scb->bufcnt--;
990- scb->bufp = scb->buf;
991- return *scb->bufp++;
992-}
993-
994-/* Perform operations common to both old and new readchar. */
995-
996-/* Return the next character from the input FIFO. If the FIFO is
997- empty, call the SERIAL specific routine to try and read in more
998- characters.
999-
1000- Initially data from the input FIFO is returned (fd_event()
1001- pre-reads the input into that FIFO. Once that has been emptied,
1002- further data is obtained by polling the input FD using the device
1003- specific readchar() function. Note: reschedule() is called after
1004- every read. This is because there is no guarentee that the lower
1005- level fd_event() poll_event() code (which also calls reschedule())
1006- will be called. */
1007-
1008-static int
1009-generic_readchar (struct serial *scb, int timeout,
1010- int (do_readchar) (struct serial *scb, int timeout))
1011-{
1012- int ch;
1013- if (scb->bufcnt > 0)
1014- {
1015- ch = *scb->bufp;
1016- scb->bufcnt--;
1017- scb->bufp++;
1018- }
1019- else if (scb->bufcnt < 0)
1020- {
1021- /* Some errors/eof are are sticky. */
1022- ch = scb->bufcnt;
1023- }
1024- else
1025- {
1026- ch = do_readchar (scb, timeout);
1027- if (ch < 0)
1028- {
1029- switch ((enum serial_rc) ch)
1030- {
1031- case SERIAL_EOF:
1032- case SERIAL_ERROR:
1033- /* Make the error/eof stick. */
1034- scb->bufcnt = ch;
1035- break;
1036- case SERIAL_TIMEOUT:
1037- scb->bufcnt = 0;
1038- break;
1039- }
1040- }
1041- }
1042- reschedule (scb);
1043- return ch;
1044-}
1045-
1046-int
1047-ser_unix_readchar (struct serial *scb, int timeout)
1048-{
1049- return generic_readchar (scb, timeout, do_unix_readchar);
1050-}
1051864
1052865 void
1053866 _initialize_ser_hardwire (void)
@@ -1058,7 +871,7 @@ _initialize_ser_hardwire (void)
1058871 ops->next = 0;
1059872 ops->open = hardwire_open;
1060873 ops->close = hardwire_close;
1061- /* FIXME: Don't replace this with the equivalent ser_unix*() until
874+ /* FIXME: Don't replace this with the equivalent ser_base*() until
1062875 the old TERMIOS/SGTTY/... timer code has been flushed. cagney
1063876 1999-09-16. */
1064877 ops->readchar = hardwire_readchar;
@@ -1075,5 +888,29 @@ _initialize_ser_hardwire (void)
1075888 ops->setstopbits = hardwire_setstopbits;
1076889 ops->drain_output = hardwire_drain_output;
1077890 ops->async = ser_base_async;
891+ ops->read_prim = ser_unix_read_prim;
892+ ops->write_prim = ser_unix_write_prim;
1078893 serial_add_interface (ops);
1079894 }
895+
896+int
897+ser_unix_read_prim (struct serial *scb, size_t count)
898+{
899+ int status;
900+
901+ while (1)
902+ {
903+ status = read (scb->fd, scb->buf, count);
904+ if (status != -1 || errno != EINTR)
905+ break;
906+ }
907+ return status;
908+}
909+
910+int
911+ser_unix_write_prim (struct serial *scb, const void *buf, size_t len)
912+{
913+ /* ??? Historically, GDB has not retried calls to "write" that
914+ result in EINTR. */
915+ return write (scb->fd, buf, len);
916+}
--- a/gdb/ser-unix.h
+++ b/gdb/ser-unix.h
@@ -22,6 +22,8 @@
2222 #ifndef SER_UNIX_H
2323 #define SER_UNIX_H
2424
25-extern int ser_unix_readchar (struct serial *scb, int timeout);
25+extern int ser_unix_read_prim (struct serial *scb, size_t count);
26+extern int ser_unix_write_prim (struct serial *scb, const void *buf,
27+ size_t count);
2628
2729 #endif
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -232,6 +232,12 @@ struct serial_ops
232232 the specified function when ever there is something
233233 interesting. */
234234 void (*async) (struct serial *scb, int async_p);
235+ /* Perform a low-level read operation, reading (at most) COUNT
236+ bytes into SCB->BUF. */
237+ int (*read_prim)(struct serial *scb, size_t count);
238+ /* Perform a low-level write operation, writing (at most) COUNT
239+ bytes from BUF. */
240+ int (*write_prim)(struct serial *scb, const void *buf, size_t count);
235241 };
236242
237243 /* Add a new serial interface to the interface list */
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -58,6 +58,10 @@
5858
5959 #include <sys/param.h> /* For MAXPATHLEN */
6060
61+#ifdef WINAPI
62+#include <winerror.h>
63+#endif
64+
6165 #include "gdb_curses.h"
6266
6367 #include "readline/readline.h"
@@ -846,14 +850,28 @@ char *
846850 safe_strerror (int errnum)
847851 {
848852 char *msg;
853+ static char buf[32];
849854
850- msg = strerror (errnum);
851- if (msg == NULL)
855+#ifdef WINAPI
856+ /* The strerror function only works for functions that set errno.
857+ In the case of Windows sockets, we can get error numbers that
858+ strerror cannot handle. */
859+ if (errnum > WSABASEERR)
852860 {
853- static char buf[32];
854- xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
861+ xsnprintf (buf, sizeof buf, "(winsock error %d)", errnum);
855862 msg = buf;
856863 }
864+ else
865+#endif
866+ {
867+ msg = strerror (errnum);
868+
869+ if (msg == NULL)
870+ {
871+ xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
872+ msg = buf;
873+ }
874+ }
857875 return (msg);
858876 }
859877