diff --git a/gdbstub/gdbstub_sys.c b/gdbstub/gdbstub_sys.c index 00b78f10..ca8dd2db 100644 --- a/gdbstub/gdbstub_sys.c +++ b/gdbstub/gdbstub_sys.c @@ -81,6 +81,11 @@ int dbg_sys_getc(void) size_t len = sizeof packet; const enum read_socket_err err = ReadSocket(client_socket, &packet, &len); +#ifdef _POSIX_VERSION + if (exit_loop) + pthread_exit(NULL); +#endif + switch (err) { case READ_SOCKET_OK: return packet; @@ -130,6 +135,9 @@ static int wait_hit_or_break(struct msg *msg) do { int ret = mq_receive(in_queue, (char *)msg, sizeof *msg, 0); + if (exit_loop) + return 1; + if (ret < 0 && errno == EAGAIN) { /* Breakpoint has not been hit yet, look for incoming messages from gdb. */ char packet; @@ -213,6 +221,9 @@ static int wait_ack(struct msg *msg) int ret; do { + if (exit_loop) + return 1; + ret = mq_receive(in_queue, (char *)msg, sizeof *msg, 0); } while (ret < 0 && errno == EAGAIN); diff --git a/gui/LnxMain.c b/gui/LnxMain.c index 2e087ee3..4af1100d 100644 --- a/gui/LnxMain.c +++ b/gui/LnxMain.c @@ -466,8 +466,6 @@ int main(int argc, char *argv[]) { psxCpu->Execute(); } - if (Config.GdbServer) dbg_stop(); - return 0; } @@ -515,6 +513,7 @@ void SysClose() { ReleasePlugins(); StopDebugger(); + if (Config.GdbServer) dbg_stop(); if (emuLog != NULL) fclose(emuLog); } diff --git a/win32/gui/WndMain.c b/win32/gui/WndMain.c index 6f7d0749..5602f41a 100644 --- a/win32/gui/WndMain.c +++ b/win32/gui/WndMain.c @@ -244,8 +244,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine RunGui(); - if (Config.GdbServer) dbg_stop(); - return 0; } @@ -2018,6 +2016,7 @@ void SysClose() { ReleasePlugins(); StopDebugger(); + if (Config.GdbServer) dbg_stop(); if (Config.PsxOut) CloseConsole();