all repos — mgba @ 64e8d3fb832a69689ac3753af7b9f6c0a05e648a

mGBA Game Boy Advance Emulator

Fix GBDStub build on Windows
Jeffrey Pfau jeffrey@endrift.com
Wed, 23 Apr 2014 21:42:08 -0700
commit

64e8d3fb832a69689ac3753af7b9f6c0a05e648a

parent

16608a408cd3f9df010aeef11fb7240e86f1faec

3 files changed, 25 insertions(+), 16 deletions(-)

jump to
M CMakeLists.txtCMakeLists.txt

@@ -21,6 +21,7 @@ include_directories(${CMAKE_SOURCE_DIR}/src)

if(WIN32) add_definitions(-D_WIN32_WINNT=0x0600) + set(OS_LIB "${OS_LIB};Ws2_32") file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c) source_group("Windows-specific code" FILES ${OS_SRC}) else()
M src/debugger/gdb-stub.csrc/debugger/gdb-stub.c

@@ -3,6 +3,10 @@

#include <errno.h> #include <signal.h> +#ifndef SIGTRAP +#define SIGTRAP 5 /* Win32 Signals do not include SIGTRAP */ +#endif + enum GDBError { GDB_NO_ERROR = 0x00, GDB_BAD_ARGUMENTS = 0x06,

@@ -18,7 +22,7 @@ static void _sendMessage(struct GDBStub* stub);

static void _gdbStubDeinit(struct ARMDebugger* debugger) { struct GDBStub* stub = (struct GDBStub*) debugger; - if (stub->socket >= 0) { + if (!SOCKET_FAILED(stub->socket)) { GDBStubShutdown(stub); } }

@@ -45,7 +49,7 @@

static void _gdbStubPoll(struct ARMDebugger* debugger) { struct GDBStub* stub = (struct GDBStub*) debugger; while (stub->d.state == DEBUGGER_PAUSED) { - if (stub->connection >= 0) { + if (!SOCKET_FAILED(stub->connection)) { if (!SocketSetBlocking(stub->connection, 1)) { GDBStubHangup(stub); return;

@@ -161,7 +165,7 @@ }

static void _continue(struct GDBStub* stub, const char* message) { stub->d.state = DEBUGGER_RUNNING; - if (stub->connection >= 0) { + if (!SOCKET_FAILED(stub->connection)) { if (!SocketSetBlocking(stub->connection, 0)) { GDBStubHangup(stub); return;

@@ -421,8 +425,8 @@ }

void GDBStubCreate(struct GDBStub* stub) { ARMDebuggerCreate(&stub->d); - stub->socket = -1; - stub->connection = -1; + stub->socket = INVALID_SOCKET; + stub->connection = INVALID_SOCKET; stub->d.init = 0; stub->d.deinit = _gdbStubDeinit; stub->d.paused = _gdbStubPoll;

@@ -431,12 +435,12 @@ stub->d.log = 0;

} int GDBStubListen(struct GDBStub* stub, int port, uint32_t bindAddress) { - if (stub->socket >= 0) { + if (!SOCKET_FAILED(stub->socket)) { GDBStubShutdown(stub); } // TODO: support IPv6 stub->socket = SocketOpenTCP(port, bindAddress); - if (stub->socket < 0) { + if (SOCKET_FAILED(stub->socket)) { if (stub->d.log) { stub->d.log(&stub->d, DEBUGGER_LOG_ERROR, "Couldn't open socket"); }

@@ -462,7 +466,7 @@ return 0;

} void GDBStubHangup(struct GDBStub* stub) { - if (stub->connection >= 0) { + if (!SOCKET_FAILED(stub->connection)) { SocketClose(stub->connection); stub->connection = -1; }

@@ -473,19 +477,19 @@ }

void GDBStubShutdown(struct GDBStub* stub) { GDBStubHangup(stub); - if (stub->socket >= 0) { + if (!SOCKET_FAILED(stub->socket)) { SocketClose(stub->socket); stub->socket = -1; } } void GDBStubUpdate(struct GDBStub* stub) { - if (stub->socket == -1) { + if (stub->socket == INVALID_SOCKET) { return; } - if (stub->connection == -1) { + if (stub->connection == INVALID_SOCKET) { stub->connection = SocketAccept(stub->socket, 0, 0); - if (stub->connection >= 0) { + if (!SOCKET_FAILED(stub->connection)) { if (!SocketSetBlocking(stub->connection, 0)) { goto connectionLost; }
M src/util/socket.hsrc/util/socket.h

@@ -5,7 +5,9 @@ #include "common.h"

#ifdef _WIN32 #include <winsock2.h> +#include <ws2tcpip.h> +#define SOCKET_FAILED(s) (s) == INVALID_SOCKET typedef SOCKET Socket; #else #include <fcntl.h>

@@ -13,6 +15,8 @@ #include <netinet/in.h>

#include <netinet/tcp.h> #include <sys/socket.h> +#define INVALID_SOCKET (-1) +#define SOCKET_FAILED(s) (s) < 0 typedef int Socket; #endif

@@ -33,7 +37,7 @@ }

static inline Socket SocketOpenTCP(int port, uint32_t bindAddress) { Socket sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sock < 0) { + if (SOCKET_FAILED(sock)) { return sock; }

@@ -54,7 +58,7 @@ }

static inline Socket SocketConnectTCP(int port, uint32_t destinationAddress) { Socket sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sock < 0) { + if (SOCKET_FAILED(sock)) { return sock; }

@@ -87,8 +91,8 @@ }

static inline int SocketSetBlocking(Socket socket, int blocking) { #ifdef _WIN32 - blocking = !blocking; - return ioctlsocket(socket, FIONBIO, &blocking) == NO_ERROR; + u_long unblocking = !blocking; + return ioctlsocket(socket, FIONBIO, &unblocking) == NO_ERROR; #else int flags = fcntl(socket, F_GETFL); if (flags == -1) {