summaryrefslogtreecommitdiffstats
path: root/remote.c
diff options
context:
space:
mode:
authorJiri Gaisler <jiri@gaisler.se>2019-11-14 11:51:10 +0100
committerJiri Gaisler <jiri@gaisler.se>2019-11-14 11:51:10 +0100
commit3475d6203ce56692cab1af0e402de286ac9bf0f8 (patch)
tree68836d196868c421e0df4aca1c3c5829b26af9d6 /remote.c
parentSupport building on MinGW-W64/MSYS2 (diff)
downloadsis-3475d6203ce56692cab1af0e402de286ac9bf0f8.tar.bz2
Cross-platform support for async gdb break (ctrl-c)
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/remote.c b/remote.c
index 5e5f02e..7093516 100644
--- a/remote.c
+++ b/remote.c
@@ -24,12 +24,15 @@
#include <unistd.h>
#include <stdio.h>
#ifdef WIN32
-#include <winsock.h>
+#include <winsock2.h>
#else
+#define WSAPOLLFD struct pollfd
+#define WSAPoll poll
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
+#include <poll.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
@@ -112,12 +115,26 @@ create_socket (int port)
sizeof (opt));
#ifndef WIN32
fcntl (new_socket, F_SETOWN, getpid ());
- fcntl (new_socket, F_SETFL, FASYNC);
#endif
return 1;
}
+/* poll socket periodically to detect gdb break */
+void
+socket_poll ()
+{
+ WSAPOLLFD fdarray = { 0 };
+ int ret;
+
+ fdarray.fd = new_socket;
+ fdarray.events = POLLRDNORM;
+ ret = WSAPoll (&fdarray, 1, 0);
+ if (ret)
+ ctrl_c = 1;
+ event (socket_poll, 0, 10000000);
+}
+
static int
hex (unsigned char ch)
{
@@ -435,14 +452,7 @@ gdb_remote (int port)
sis_gdb_break = 1;
detach = 0;
-#ifndef WIN32
- signal (SIGIO, int_handler);
-#endif
-#ifdef __CYGWIN__
- printf ("Warning: gdb cannot interrupt a running simulator under CYGWIN\n");
- printf
- (" As a workaround, use Ctrl-C in the simulator window instead\n\n");
-#endif
+
printf ("gdb: listening on port %d ", port);
while (cont)
{
@@ -526,8 +536,4 @@ gdb_remote (int port)
}
new_socket = 0;
sis_gdb_break = 0;
-#ifndef WIN32
- signal (SIGIO, SIG_DFL);
-#endif
-
}