Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1CslXC-0008Ge-No for qemu-devel@nongnu.org; Sun, 23 Jan 2005 12:28:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1CslWv-0008B6-Gu for qemu-devel@nongnu.org; Sun, 23 Jan 2005 12:28:10 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CslWt-00082L-Fl for qemu-devel@nongnu.org; Sun, 23 Jan 2005 12:28:03 -0500 Received: from [195.250.128.75] (helo=smtp2.vol.cz) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1Csl31-00045L-43 for qemu-devel@nongnu.org; Sun, 23 Jan 2005 11:57:11 -0500 Received: from [10.0.0.2] (prg-v-6-220.static.adsl.vol.cz [62.177.70.220]) by smtp2.vol.cz (8.12.9p2/8.12.9) with ESMTP id j0NGv88T054589 for ; Sun, 23 Jan 2005 17:57:08 +0100 (CET) (envelope-from xnavara@volny.cz) Message-ID: <41F3D766.1040302@volny.cz> Date: Sun, 23 Jan 2005 17:57:10 +0100 From: Filip Navara MIME-Version: 1.0 Subject: [Qemu-devel] [PATCH] Win32 support for the GDB stub (take 3) Content-Type: multipart/mixed; boundary="------------020901090005020900080605" Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------020901090005020900080605 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sorry for flooding the list. This version has correctly fixed the Win32 error checks... :-( Changelog: 2005-01-23 Filip Navara * Support for the GDB stub on Win32. --------------020901090005020900080605 Content-Type: text/plain; name="gdbstub.c.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="gdbstub.c.patch" Index: gdbstub.c =================================================================== RCS file: /cvsroot/qemu/qemu/gdbstub.c,v retrieving revision 1.23 diff -u -r1.23 gdbstub.c --- gdbstub.c 17 Jan 2005 22:03:16 -0000 1.23 +++ gdbstub.c 23 Jan 2005 10:30:39 -0000 @@ -19,11 +19,21 @@ */ #include "vl.h" +#ifdef _WIN32 +#include +#define SIGTRAP 24 +typedef int socklen_t; +#else #include #include #include +#endif #include +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif + //#define DEBUG_GDB enum RSState { @@ -49,9 +59,13 @@ int ret; for(;;) { - ret = read(s->fd, &ch, 1); + ret = recv(s->fd, &ch, 1, MSG_NOSIGNAL); if (ret < 0) { +#ifdef _WIN32 + if (WSAGetLastError() != WSAEINTR) +#else if (errno != EINTR && errno != EAGAIN) +#endif return -1; } else if (ret == 0) { return -1; @@ -67,9 +81,13 @@ int ret; while (len > 0) { - ret = write(s->fd, buf, len); + ret = send(s->fd, buf, len, MSG_NOSIGNAL); if (ret < 0) { +#ifdef _WIN32 + if (WSAGetLastError() != WSAEINTR) +#else if (errno != EINTR && errno != EAGAIN) +#endif return; } else { buf += ret; @@ -551,7 +569,7 @@ { GDBState *s = opaque; int i; - if (size == 0) { + if (size <= 0) { /* end of connection */ qemu_del_vm_stop_handler(gdb_vm_stopped, s); qemu_del_fd_read_handler(s->fd); @@ -569,6 +587,9 @@ struct sockaddr_in sockaddr; socklen_t len; int val, fd; +#ifdef _WIN32 + u_long nbio = 1; +#endif for(;;) { len = sizeof(sockaddr); @@ -583,7 +604,11 @@ /* set short latency */ val = 1; +#ifdef _WIN32 + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char*)&val, sizeof(val)); +#else setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); +#endif s = qemu_mallocz(sizeof(GDBState)); if (!s) { @@ -592,7 +617,11 @@ } s->fd = fd; +#ifdef _WIN32 + ioctlsocket(fd, FIONBIO, &nbio); +#else fcntl(fd, F_SETFL, O_NONBLOCK); +#endif /* stop the VM */ vm_stop(EXCP_INTERRUPT); @@ -607,6 +636,9 @@ { struct sockaddr_in sockaddr; int fd, val, ret; +#ifdef _WIN32 + u_long nbio = 1; +#endif fd = socket(PF_INET, SOCK_STREAM, 0); if (fd < 0) { @@ -616,7 +648,11 @@ /* allow fast reuse */ val = 1; +#ifdef _WIN32 + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&val, sizeof(val)); +#else setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); +#endif sockaddr.sin_family = AF_INET; sockaddr.sin_port = htons(port); @@ -631,12 +667,21 @@ perror("listen"); return -1; } +#ifdef _WIN32 + ioctlsocket(fd, FIONBIO, &nbio); +#else fcntl(fd, F_SETFL, O_NONBLOCK); +#endif return fd; } int gdbserver_start(int port) { +#ifdef _WIN32 + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) + return -1; +#endif gdbserver_fd = gdbserver_open(port); if (gdbserver_fd < 0) return -1; --------------020901090005020900080605--