Skip to content

Commit

Permalink
Fix gdb break on start & gdb ports not closing after restarting/crash…
Browse files Browse the repository at this point in the history
…ing (#2167)
  • Loading branch information
GalaxyShard authored Oct 27, 2024
1 parent 98d969a commit b60f42b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const u32 ARM::ConditionTable[16] =
ARM::ARM(u32 num, bool jit, std::optional<GDBArgs> 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)
Expand Down
9 changes: 9 additions & 0 deletions src/debug/GdbStub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b60f42b

Please sign in to comment.