summaryrefslogtreecommitdiff
path: root/libpcsxcore
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2020-05-23 18:06:48 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2020-05-23 19:03:11 +0200
commit850010a96b6cbc3eae03edd891e50325e017b678 (patch)
tree391100fb00f0bf3fe7aae8c9a574c72d8ce9b17b /libpcsxcore
parent470da05658a97a51bd2ad2db7834bcc13dd995fd (diff)
Replaced in-house gdb stub by MIT-licensed implementation
Imported from a fork of https://github.com/mborgerson/gdbstub
Diffstat (limited to 'libpcsxcore')
-rw-r--r--libpcsxcore/CMakeLists.txt3
-rw-r--r--libpcsxcore/debug.c2
-rw-r--r--libpcsxcore/gdb_server.c128
-rw-r--r--libpcsxcore/gdb_server.h10
-rw-r--r--libpcsxcore/psxcommon.h1
-rw-r--r--libpcsxcore/psxcounters.c3
-rw-r--r--libpcsxcore/psxinterpreter.c3
-rw-r--r--libpcsxcore/socket.c4
-rw-r--r--libpcsxcore/socket.h2
9 files changed, 8 insertions, 148 deletions
diff --git a/libpcsxcore/CMakeLists.txt b/libpcsxcore/CMakeLists.txt
index 04633ce1..0be1e4ac 100644
--- a/libpcsxcore/CMakeLists.txt
+++ b/libpcsxcore/CMakeLists.txt
@@ -98,7 +98,6 @@ set(SRCS psxbios.c
pgxp_gte.c
pgxp_mem.c
pgxp_value.c
- gdb_server.c
)
set(LIBS "-lm")
@@ -117,4 +116,4 @@ endif()
set(SRCS ${SRCS} ${DYNAREC_SRC})
add_library(pcsxcore STATIC ${SRCS})
-target_link_libraries(pcsxcore dynstr ${FFMPEG_LIBRARIES} ${LibArchive_LIBRARIES} ${LIBS})
+target_link_libraries(pcsxcore dynstr gdbstub ${FFMPEG_LIBRARIES} ${LibArchive_LIBRARIES} ${LIBS})
diff --git a/libpcsxcore/debug.c b/libpcsxcore/debug.c
index 972343d4..463df73b 100644
--- a/libpcsxcore/debug.c
+++ b/libpcsxcore/debug.c
@@ -474,7 +474,7 @@ void ProcessDebug() {
MarkMap(_Rd_, MAP_EXEC_JAL);
}
}
- while (paused || GdbServerRunning()) {
+ while (paused) {
if (client_socket < 1)
{
diff --git a/libpcsxcore/gdb_server.c b/libpcsxcore/gdb_server.c
deleted file mode 100644
index 7f7ea2ca..00000000
--- a/libpcsxcore/gdb_server.c
+++ /dev/null
@@ -1,128 +0,0 @@
-#include "socket.h"
-#include "psxcommon.h"
-#include "misc.h"
-#include "system.h"
-#include "dynstr.h"
-#include <stdio.h>
-#include <string.h>
-#include <stddef.h>
-
-static int server_socket, client_socket;
-static int debugger_active, resetting, reset, paused, ack_expected;
-
-enum { PACKET_SIZE = 256 };
-
-void GdbStartServer(void)
-{
- enum { PORT = 3333 };
-
- if (server_socket > 0) {
- GdbStopServer();
- }
-
- server_socket = StartServer(PORT);
-
- if (server_socket > 0) {
- printf("GDB server started on port %hu\n", PORT);
- debugger_active = 1;
- }
- else
- {
- fprintf(stderr, "Could not start GDB server\n");
- }
-}
-
-int GdbServerRunning(void)
-{
- return server_socket > 0;
-}
-
-void GdbStopServer(void)
-{
-}
-
-static void ack(struct dynstr *const reply)
-{
- dynstr_append(reply, "OK");
-}
-
-static void nack(struct dynstr *const reply, const int err)
-{
- dynstr_append(reply, "E %02X", err);
-}
-
-static void HandlePacket(char *const packet, const size_t len)
-{
- struct dynstr reply;
- const char *c = packet;
-
- dynstr_init(&reply);
-
- if (strstr(packet, "qSupported")) {
- dynstr_append(&reply, "PacketSize=%x;swbreak+;hwbreak+", PACKET_SIZE - 1);
- }
- else {
- fprintf(stderr, "Unexpected packet \"%s\"\n", packet);
- return;
- }
-
- printf("gdb <- \"%s\"\n", reply.str);
- WriteSocket(client_socket, reply.str, reply.len);
- dynstr_free(&reply);
-}
-
-static void ProcessCommands(void)
-{
- if (HasClient(client_socket)) {
- char packet[PACKET_SIZE];
- size_t len = sizeof packet;
- const enum read_socket_err err = ReadSocket(client_socket, packet, &len);
-
- switch (err)
- {
- case READ_SOCKET_OK:
- if (len && len < sizeof packet) {
- /* gdb apparently does not send null-terminated strings. */
- packet[len] = '\0';
- printf("gdb -> \"%s\"\n", packet);
- HandlePacket(packet, len);
- }
- break;
-
- case READ_SOCKET_ERR_INVALID_ARG:
- /* Fall through. */
- case READ_SOCKET_ERR_RECV:
- /* Fall through. */
- case READ_SOCKET_SHUTDOWN:
- /* Fall through. */
- default:
- return;
- }
- }
-}
-
-void GdbServerProcessDebug(void)
-{
- ProcessCommands();
-}
-
-void GdbServerVSync(void)
-{
- if (!debugger_active || resetting)
- return;
-
- if (reset) {
- resetting = 1;
- SysReset();
- if (reset == 2)
- LoadCdrom();
- reset = resetting = 0;
- return;
- }
-
- if (client_socket < 1) {
- client_socket = GetClient(server_socket);
- }
-
- ProcessCommands();
-}
diff --git a/libpcsxcore/gdb_server.h b/libpcsxcore/gdb_server.h
deleted file mode 100644
index d0e925a6..00000000
--- a/libpcsxcore/gdb_server.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef GDB_SERVER_H
-#define GDB_SERVER_H
-
-void GdbStartServer(void);
-void GdbStopServer(void);
-void GdbServerProcessDebug(void);
-void GdbServerVSync(void);
-int GdbServerRunning(void);
-
-#endif /* GDB_SERVER_H */
diff --git a/libpcsxcore/psxcommon.h b/libpcsxcore/psxcommon.h
index babdff96..c6deaa9f 100644
--- a/libpcsxcore/psxcommon.h
+++ b/libpcsxcore/psxcommon.h
@@ -70,7 +70,6 @@ typedef uint8_t boolean;
// Local includes
#include "system.h"
#include "debug.h"
-#include "gdb_server.h"
#if defined (__linux__) || defined (__MACOSX__)
#define strnicmp strncasecmp
diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c
index 46f9947e..9203d62d 100644
--- a/libpcsxcore/psxcounters.c
+++ b/libpcsxcore/psxcounters.c
@@ -323,8 +323,7 @@ void psxRcntUpdate()
}
}
- DebugVSync();
- GdbServerVSync();
+ if (Config.Debug) DebugVSync();
}
/******************************************************************************/
diff --git a/libpcsxcore/psxinterpreter.c b/libpcsxcore/psxinterpreter.c
index 685c9abf..a2bc0e1d 100644
--- a/libpcsxcore/psxinterpreter.c
+++ b/libpcsxcore/psxinterpreter.c
@@ -28,6 +28,7 @@
#include "pgxp_debug.h"
#include "pgxp_cpu.h"
#include "pgxp_gte.h"
+#include "../gdbstub/gdbstub_sys.h"
static int branch = 0;
static int branch2 = 0;
@@ -1204,7 +1205,7 @@ static inline void execI() {
debugI();
- if (Config.GdbServer) GdbServerProcessDebug();
+ if (Config.GdbServer) dbg_sys_process();
else if (Config.Debug) ProcessDebug();
psxRegs.pc += 4;
diff --git a/libpcsxcore/socket.c b/libpcsxcore/socket.c
index 1faffd3d..51aefdf7 100644
--- a/libpcsxcore/socket.c
+++ b/libpcsxcore/socket.c
@@ -252,8 +252,8 @@ int RawReadSocket(int client_socket, char *buffer, size_t len) {
#endif
}
-void WriteSocket(int client_socket, const char *buffer, size_t len) {
- if (!client_socket)
+void WriteSocket(int client_socket, const void *buffer, size_t len) {
+ if (client_socket <= 0)
return;
if (send(client_socket, buffer, len, 0) == -1) {
diff --git a/libpcsxcore/socket.h b/libpcsxcore/socket.h
index 10d3c2fe..531a6485 100644
--- a/libpcsxcore/socket.h
+++ b/libpcsxcore/socket.h
@@ -42,7 +42,7 @@ int HasClient(int client_socket);
enum read_socket_err ReadSocket(int client_socket, char *buffer, size_t *len);
int RawReadSocket(int client_socket, char *buffer, size_t len);
-void WriteSocket(int client_socket, const char *buffer, size_t len);
+void WriteSocket(int client_socket, const void *buffer, size_t len);
void SetsBlock(int s_socket);
void SetsNonblock(int s_socket);