From b60f42b281e4b465ff3cd6f964ab10d238ad31bd Mon Sep 17 00:00:00 2001 From: GalaxyShard <76917584+GalaxyShard@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:06:59 +0000 Subject: [PATCH] Fix gdb break on start & gdb ports not closing after restarting/crashing (#2167) --- src/ARM.cpp | 1 + src/debug/GdbStub.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/ARM.cpp b/src/ARM.cpp index 4cf70749..b7b703da 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -110,6 +110,7 @@ const u32 ARM::ConditionTable[16] = ARM::ARM(u32 num, bool jit, std::optional gdb, melonDS::NDS& nds) : #ifdef GDBSTUB_ENABLED GdbStub(this, gdb ? (num ? gdb->PortARM7 : gdb->PortARM9) : 0), + BreakOnStartup(gdb ? (num ? gdb->ARM7BreakOnStartup : gdb->ARM9BreakOnStartup) : false), #endif Num(num), // well uh NDS(nds) diff --git a/src/debug/GdbStub.cpp b/src/debug/GdbStub.cpp index 14a8670a..b055794a 100644 --- a/src/debug/GdbStub.cpp +++ b/src/debug/GdbStub.cpp @@ -101,6 +101,15 @@ bool GdbStub::Init() Log(LogLevel::Error, "[GDB] err: can't create a socket fd\n"); goto err; } + { + // Make sure the port can be reused immediately after melonDS stops and/or restarts + int enable = 1; +#ifdef _WIN32 + setsockopt(SockFd, SOL_SOCKET, SO_REUSEADDR, (const char*)&enable, sizeof(enable)); +#else + setsockopt(SockFd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)); +#endif + } #ifndef __linux__ SocketSetBlocking(SockFd, false); #endif