GNU Binutils with patches for OS216
Révision | 064eee739c55428d8d297408e8e79abfe55935f7 (tree) |
---|---|
l'heure | 2005-03-29 03:46:22 |
Auteur | Mark Mitchell <mark@code...> |
Commiter | Mark Mitchell |
* 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.
@@ -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 | + | |
1 | 38 | 2005-03-28 Mark Mitchell <mark@codesourcery.com> |
2 | 39 | |
3 | 40 | Backport from mainline: |
@@ -15593,6 +15593,109 @@ fi | ||
15593 | 15593 | done |
15594 | 15594 | |
15595 | 15595 | |
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 | + | |
15596 | 15699 | for ac_func in sbrk |
15597 | 15700 | do |
15598 | 15701 | 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 | ||
20034 | 20137 | esac |
20035 | 20138 | fi |
20036 | 20139 | |
20140 | +# The ser-tcp.c module requires sockets. | |
20141 | +case ${host} in | |
20142 | + *mingw32*) | |
20143 | + WIN32LIBS="$WIN32LIBS -lws2_32" | |
20144 | + ;; | |
20145 | +esac | |
20146 | + | |
20037 | 20147 | |
20038 | 20148 | LIBGUI="../libgui/src/libgui.a" |
20039 | 20149 | GUI_CFLAGS_X="-I${srcdir}/../libgui/src" |
@@ -451,6 +451,7 @@ AC_CHECK_FUNCS(canonicalize_file_name realpath) | ||
451 | 451 | AC_CHECK_FUNCS(getuid getgid) |
452 | 452 | AC_CHECK_FUNCS(poll) |
453 | 453 | AC_CHECK_FUNCS(pread64) |
454 | +AC_CHECK_FUNCS(recv send) | |
454 | 455 | AC_CHECK_FUNCS(sbrk) |
455 | 456 | AC_CHECK_FUNCS(setpgid setpgrp) |
456 | 457 | AC_CHECK_FUNCS(sigaction sigprocmask sigsetmask) |
@@ -1187,6 +1188,13 @@ if test x$gdb_cv_os_cygwin = xyes; then | ||
1187 | 1188 | ;; |
1188 | 1189 | esac |
1189 | 1190 | fi |
1191 | + | |
1192 | +# The ser-tcp.c module requires sockets. | |
1193 | +case ${host} in | |
1194 | + *mingw32*) | |
1195 | + WIN32LIBS="$WIN32LIBS -lws2_32" | |
1196 | + ;; | |
1197 | +esac | |
1190 | 1198 | AC_SUBST(WIN32LIBS) |
1191 | 1199 | |
1192 | 1200 | LIBGUI="../libgui/src/libgui.a" |
@@ -1153,6 +1153,10 @@ extern int use_windows; | ||
1153 | 1153 | #define SLASH_STRING "/" |
1154 | 1154 | #endif |
1155 | 1155 | |
1156 | +#if defined(__WIN32__) && !defined(__CYGWIN__) | |
1157 | +#define WINAPI | |
1158 | +#endif | |
1159 | + | |
1156 | 1160 | /* Provide default definitions of PIDGET, TIDGET, and MERGEPID. |
1157 | 1161 | The name ``TIDGET'' is a historical accident. Many uses of TIDGET |
1158 | 1162 | in the code actually refer to a lightweight process id, i.e, |
@@ -144,7 +144,7 @@ _initialize_ser_pipe (void) | ||
144 | 144 | ops->next = 0; |
145 | 145 | ops->open = pipe_open; |
146 | 146 | ops->close = pipe_close; |
147 | - ops->readchar = ser_unix_readchar; | |
147 | + ops->readchar = ser_base_readchar; | |
148 | 148 | ops->write = ser_base_write; |
149 | 149 | ops->flush_output = ser_base_flush_output; |
150 | 150 | ops->flush_input = ser_base_flush_input; |
@@ -158,5 +158,7 @@ _initialize_ser_pipe (void) | ||
158 | 158 | ops->setstopbits = ser_base_setstopbits; |
159 | 159 | ops->drain_output = ser_base_drain_output; |
160 | 160 | ops->async = ser_base_async; |
161 | + ops->read_prim = ser_unix_read_prim; | |
162 | + ops->write_prim = ser_unix_write_prim; | |
161 | 163 | serial_add_interface (ops); |
162 | 164 | } |
@@ -34,11 +34,19 @@ | ||
34 | 34 | #endif |
35 | 35 | |
36 | 36 | #include <sys/time.h> |
37 | + | |
38 | +#ifdef WINAPI | |
39 | +#include <winsock2.h> | |
40 | +#define ETIMEDOUT WSAETIMEDOUT | |
41 | +#else | |
37 | 42 | #include <netinet/in.h> |
38 | 43 | #include <arpa/inet.h> |
39 | 44 | #include <netdb.h> |
40 | 45 | #include <sys/socket.h> |
41 | 46 | #include <netinet/tcp.h> |
47 | +#define closesocket close | |
48 | +#define ioctlsocket ioctl | |
49 | +#endif | |
42 | 50 | |
43 | 51 | #include <signal.h> |
44 | 52 | #include "gdb_string.h" |
@@ -62,6 +70,11 @@ net_open (struct serial *scb, const char *name) | ||
62 | 70 | int use_udp; |
63 | 71 | struct hostent *hostent; |
64 | 72 | struct sockaddr_in sockaddr; |
73 | +#ifdef WINAPI | |
74 | + u_long ioarg; | |
75 | +#else | |
76 | + int ioarg; | |
77 | +#endif | |
65 | 78 | |
66 | 79 | use_udp = 0; |
67 | 80 | if (strncmp (name, "udp:", 4) == 0) |
@@ -108,14 +121,25 @@ net_open (struct serial *scb, const char *name) | ||
108 | 121 | sizeof (struct in_addr)); |
109 | 122 | |
110 | 123 | /* set socket nonblocking */ |
111 | - tmp = 1; | |
112 | - ioctl (scb->fd, FIONBIO, &tmp); | |
124 | + ioarg = 1; | |
125 | + ioctlsocket (scb->fd, FIONBIO, &ioarg); | |
113 | 126 | |
114 | 127 | /* Use Non-blocking connect. connect() will return 0 if connected already. */ |
115 | 128 | n = connect (scb->fd, (struct sockaddr *) &sockaddr, sizeof (sockaddr)); |
116 | 129 | |
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 | + ) | |
118 | 139 | { |
140 | +#ifdef WINAPI | |
141 | + errno = WSAGetLastError(); | |
142 | +#endif | |
119 | 143 | net_close (scb); |
120 | 144 | return -1; |
121 | 145 | } |
@@ -165,7 +189,11 @@ net_open (struct serial *scb, const char *name) | ||
165 | 189 | { |
166 | 190 | int res, err, len; |
167 | 191 | 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); | |
169 | 197 | if (res < 0 || err) |
170 | 198 | { |
171 | 199 | if (err) |
@@ -176,8 +204,8 @@ net_open (struct serial *scb, const char *name) | ||
176 | 204 | } |
177 | 205 | |
178 | 206 | /* turn off nonblocking */ |
179 | - tmp = 0; | |
180 | - ioctl (scb->fd, FIONBIO, &tmp); | |
207 | + ioarg = 0; | |
208 | + ioctlsocket (scb->fd, FIONBIO, &ioarg); | |
181 | 209 | |
182 | 210 | if (use_udp == 0) |
183 | 211 | { |
@@ -202,20 +230,47 @@ net_close (struct serial *scb) | ||
202 | 230 | if (scb->fd < 0) |
203 | 231 | return; |
204 | 232 | |
205 | - close (scb->fd); | |
233 | + closesocket (scb->fd); | |
206 | 234 | scb->fd = -1; |
207 | 235 | } |
208 | 236 | |
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 | + | |
209 | 257 | void |
210 | 258 | _initialize_ser_tcp (void) |
211 | 259 | { |
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); | |
213 | 268 | memset (ops, 0, sizeof (struct serial_ops)); |
214 | 269 | ops->name = "tcp"; |
215 | 270 | ops->next = 0; |
216 | 271 | ops->open = net_open; |
217 | 272 | ops->close = net_close; |
218 | - ops->readchar = ser_unix_readchar; | |
273 | + ops->readchar = ser_base_readchar; | |
219 | 274 | ops->write = ser_base_write; |
220 | 275 | ops->flush_output = ser_base_flush_output; |
221 | 276 | ops->flush_input = ser_base_flush_input; |
@@ -229,5 +284,7 @@ _initialize_ser_tcp (void) | ||
229 | 284 | ops->setstopbits = ser_base_setstopbits; |
230 | 285 | ops->drain_output = ser_base_drain_output; |
231 | 286 | ops->async = ser_base_async; |
287 | + ops->read_prim = net_read_prim; | |
288 | + ops->write_prim = net_write_prim; | |
232 | 289 | serial_add_interface (ops); |
233 | 290 | } |
@@ -70,9 +70,6 @@ static void hardwire_raw (struct serial *scb); | ||
70 | 70 | static int wait_for (struct serial *scb, int timeout); |
71 | 71 | static int hardwire_readchar (struct serial *scb, int timeout); |
72 | 72 | 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)); | |
76 | 73 | static int rate_to_code (int rate); |
77 | 74 | static int hardwire_setbaudrate (struct serial *scb, int rate); |
78 | 75 | static void hardwire_close (struct serial *scb); |
@@ -422,7 +419,7 @@ hardwire_raw (struct serial *scb) | ||
422 | 419 | */ |
423 | 420 | |
424 | 421 | /* 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 | |
426 | 423 | flushed. . */ |
427 | 424 | |
428 | 425 | /* 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) | ||
542 | 539 | dropped dead, or SERIAL_ERROR for any other error (see errno in that case). */ |
543 | 540 | |
544 | 541 | /* 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 | |
546 | 543 | flushed. */ |
547 | 544 | |
548 | 545 | /* 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*() | |
550 | 547 | 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 | |
552 | 549 | that. */ |
553 | 550 | |
554 | 551 | static int |
@@ -863,191 +860,7 @@ hardwire_close (struct serial *scb) | ||
863 | 860 | close (scb->fd); |
864 | 861 | scb->fd = -1; |
865 | 862 | } |
866 | - | |
867 | 863 | |
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 | -} | |
1051 | 864 | |
1052 | 865 | void |
1053 | 866 | _initialize_ser_hardwire (void) |
@@ -1058,7 +871,7 @@ _initialize_ser_hardwire (void) | ||
1058 | 871 | ops->next = 0; |
1059 | 872 | ops->open = hardwire_open; |
1060 | 873 | 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 | |
1062 | 875 | the old TERMIOS/SGTTY/... timer code has been flushed. cagney |
1063 | 876 | 1999-09-16. */ |
1064 | 877 | ops->readchar = hardwire_readchar; |
@@ -1075,5 +888,29 @@ _initialize_ser_hardwire (void) | ||
1075 | 888 | ops->setstopbits = hardwire_setstopbits; |
1076 | 889 | ops->drain_output = hardwire_drain_output; |
1077 | 890 | ops->async = ser_base_async; |
891 | + ops->read_prim = ser_unix_read_prim; | |
892 | + ops->write_prim = ser_unix_write_prim; | |
1078 | 893 | serial_add_interface (ops); |
1079 | 894 | } |
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 | +} |
@@ -22,6 +22,8 @@ | ||
22 | 22 | #ifndef SER_UNIX_H |
23 | 23 | #define SER_UNIX_H |
24 | 24 | |
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); | |
26 | 28 | |
27 | 29 | #endif |
@@ -232,6 +232,12 @@ struct serial_ops | ||
232 | 232 | the specified function when ever there is something |
233 | 233 | interesting. */ |
234 | 234 | 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); | |
235 | 241 | }; |
236 | 242 | |
237 | 243 | /* Add a new serial interface to the interface list */ |
@@ -58,6 +58,10 @@ | ||
58 | 58 | |
59 | 59 | #include <sys/param.h> /* For MAXPATHLEN */ |
60 | 60 | |
61 | +#ifdef WINAPI | |
62 | +#include <winerror.h> | |
63 | +#endif | |
64 | + | |
61 | 65 | #include "gdb_curses.h" |
62 | 66 | |
63 | 67 | #include "readline/readline.h" |
@@ -846,14 +850,28 @@ char * | ||
846 | 850 | safe_strerror (int errnum) |
847 | 851 | { |
848 | 852 | char *msg; |
853 | + static char buf[32]; | |
849 | 854 | |
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) | |
852 | 860 | { |
853 | - static char buf[32]; | |
854 | - xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum); | |
861 | + xsnprintf (buf, sizeof buf, "(winsock error %d)", errnum); | |
855 | 862 | msg = buf; |
856 | 863 | } |
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 | + } | |
857 | 875 | return (msg); |
858 | 876 | } |
859 | 877 |