Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GdbServer: Fixes crash on gdb detach #3319

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since OpenListenSocket is running at the start of the GDB server thread, is there potential for a race condition for short-lived FEX processes here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not currently since gdbserver always forces processes to wait for gdb attach currently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it? I see GDBServer::GDBServer() ending in a call to StartThread, so the caller can immediately close it after. Is there external logic that does this waiting?

Copy link
Member Author

@Sonicadvance1 Sonicadvance1 Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, thanks for clarifying!

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
Loading