From cb2d7f800a9fc276b96fd0927fa6d8ec9f5a31c8 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Fri, 29 May 2020 00:05:08 +0200 Subject: Implemented port-specific wrappers and logic for gdb stub --- libpcsxcore/debug.c | 4 +-- libpcsxcore/psxinterpreter.c | 64 +++++++++++++++++++++++++++++++++++++++++++- libpcsxcore/socket.c | 3 ++- libpcsxcore/socket.h | 2 +- 4 files changed, 68 insertions(+), 5 deletions(-) (limited to 'libpcsxcore') diff --git a/libpcsxcore/debug.c b/libpcsxcore/debug.c index 463df73b..ecc9edc7 100644 --- a/libpcsxcore/debug.c +++ b/libpcsxcore/debug.c @@ -397,7 +397,7 @@ void DebugVSync() { if (client_socket < 1) { - client_socket = GetClient(server_socket); + client_socket = GetClient(server_socket, 0); if (client_socket > 0) { @@ -478,7 +478,7 @@ void ProcessDebug() { if (client_socket < 1) { - client_socket = GetClient(server_socket); + client_socket = GetClient(server_socket, 0); if (client_socket > 0) { diff --git a/libpcsxcore/psxinterpreter.c b/libpcsxcore/psxinterpreter.c index a2bc0e1d..941fda4b 100644 --- a/libpcsxcore/psxinterpreter.c +++ b/libpcsxcore/psxinterpreter.c @@ -1198,6 +1198,68 @@ static void intClear(u32 Addr, u32 Size) { static void intShutdown() { } +static void process_gdb(void) { + static int shutdown; + static u32 tgt_addr; + static int step, must_continue; + struct msg msg; + + if (shutdown) + return; + + if (step || (must_continue && tgt_addr && tgt_addr == psxRegs.pc)) { + msg.type = MSG_TYPE_HIT; +#if DEBUG == 1 + printf("hit address 0x%08X\n", psxRegs.pc); +#endif + gdbstub_sys_send(&msg); + must_continue = 0; + step = 0; + } + + if (!must_continue) { + gdbstub_sys_recv(&msg); + + switch (msg.type) { + case MSG_TYPE_CONTINUE: + must_continue = 1; + break; + + case MSG_TYPE_STEP: + step = 1; + break; + + case MSG_TYPE_REMOVE_BREAKPOINT: { + struct msg out; + + tgt_addr = 0; + out.type = MSG_TYPE_ACK; + + gdbstub_sys_send(&out); + } + break; + + case MSG_TYPE_BREAKPOINT: { + struct msg out; + + tgt_addr = msg.data.breakpoint.addr; + out.type = MSG_TYPE_ACK; + + gdbstub_sys_send(&out); + } + break; + + case MSG_TYPE_SHUTDOWN: + shutdown = 1; + break; + + default: + fprintf(stderr, "unknown msg.type %d\n", msg.type); + break; + } + } +} + // interpreter execution static inline void execI() { u32 *code = Read_ICache(psxRegs.pc, FALSE); @@ -1205,7 +1267,7 @@ static inline void execI() { debugI(); - if (Config.GdbServer) dbg_sys_process(); + if (Config.GdbServer) process_gdb(); else if (Config.Debug) ProcessDebug(); psxRegs.pc += 4; diff --git a/libpcsxcore/socket.c b/libpcsxcore/socket.c index 51aefdf7..eec4c96a 100644 --- a/libpcsxcore/socket.c +++ b/libpcsxcore/socket.c @@ -88,7 +88,7 @@ void StopServer(int s_socket) { #endif } -int GetClient(int s_socket) { +int GetClient(int s_socket, int blocking) { int new_socket = accept(s_socket, NULL, NULL); #ifdef _WIN32 @@ -100,6 +100,7 @@ int GetClient(int s_socket) { #endif #ifndef _WIN32 + if (!blocking) { int flags; flags = fcntl(new_socket, F_GETFL, 0); diff --git a/libpcsxcore/socket.h b/libpcsxcore/socket.h index 531a6485..852c76a4 100644 --- a/libpcsxcore/socket.h +++ b/libpcsxcore/socket.h @@ -35,7 +35,7 @@ enum read_socket_err int StartServer(unsigned short port); void StopServer(int s_socket); -int GetClient(int s_socket); +int GetClient(int s_socket, int blocking); void CloseClient(int client_socket); int HasClient(int client_socket); -- cgit v1.2.3