Skip to content

Commit

Permalink
Merge pull request #3319 from Sonicadvance1/fix_gdbserver_crash
Browse files Browse the repository at this point in the history
GdbServer: Fixes crash on gdb detach
  • Loading branch information
Sonicadvance1 authored Dec 11, 2023
2 parents 7524029 + 499a40e commit a1cf14f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Source/Tools/FEXLoader/LinuxSyscalls/GdbServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ void GdbServer::WaitForThreadWakeup() {
}

GdbServer::~GdbServer() {
CloseListenSocket();
CoreShuttingDown = true;
close(ListenSocket);

if (gdbServerThread->joinable()) {
gdbServerThread->join(nullptr);
}
}

GdbServer::GdbServer(FEXCore::Context::Context *ctx, FEX::HLE::SignalDelegator *SignalDelegation, FEXCore::HLE::SyscallHandler *const SyscallHandler)
Expand Down Expand Up @@ -1432,8 +1436,7 @@ void GdbServer::GdbServerLoop() {
}
}

close(ListenSocket);
unlink(GdbUnixSocketPath.c_str());
CloseListenSocket();
}
static void* ThreadHandler(void *Arg) {
FEXCore::Threads::SetThreadName("FEX:gdbserver");
Expand Down Expand Up @@ -1493,6 +1496,14 @@ void GdbServer::OpenListenSocket() {
LogMan::Msg::IFmt("[GdbServer] gdb-multiarch -ex \"target extended-remote {}\"", GdbUnixSocketPath);
}

void GdbServer::CloseListenSocket() {
if (ListenSocket != -1) {
close(ListenSocket);
ListenSocket = -1;
}
unlink(GdbUnixSocketPath.c_str());
}

fextl::unique_ptr<std::iostream> GdbServer::OpenSocket() {
// Block until a connection arrives
struct sockaddr_storage their_addr{};
Expand Down
1 change: 1 addition & 0 deletions Source/Tools/FEXLoader/LinuxSyscalls/GdbServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class GdbServer {
void Break(int signal);

void OpenListenSocket();
void CloseListenSocket();
enum class WaitForConnectionResult {
CONNECTION,
ERROR,
Expand Down

0 comments on commit a1cf14f

Please sign in to comment.