GdbServer: Fixes crash on gdb detach

GdbServer object was getting deleted before the socket thread was
shutdown which was causing a crash on detach.

Now on destructor it will wait for the thread to thread to exit.
This commit is contained in:
Ryan Houdek 2023-12-08 06:03:58 -08:00
parent 7524029a06
commit 499a40ecb5
2 changed files with 15 additions and 3 deletions

View File

@ -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)
@ -1432,8 +1436,7 @@ void GdbServer::GdbServerLoop() {
}
}
close(ListenSocket);
unlink(GdbUnixSocketPath.c_str());
CloseListenSocket();
}
static void* ThreadHandler(void *Arg) {
FEXCore::Threads::SetThreadName("FEX:gdbserver");
@ -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{};

View File

@ -39,6 +39,7 @@ private:
void Break(int signal);
void OpenListenSocket();
void CloseListenSocket();
enum class WaitForConnectionResult {
CONNECTION,
ERROR,