From 6423d0c1b33285655329276b4e3e31f8d7fcfedd Mon Sep 17 00:00:00 2001 From: TuxSH Date: Wed, 1 May 2019 19:37:46 +0200 Subject: [PATCH] gdb: fix hang when "debug next application" is used more than once --- sysmodules/rosalina/source/gdb/server.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sysmodules/rosalina/source/gdb/server.c b/sysmodules/rosalina/source/gdb/server.c index 9577b11..6b896ac 100644 --- a/sysmodules/rosalina/source/gdb/server.c +++ b/sysmodules/rosalina/source/gdb/server.c @@ -246,9 +246,6 @@ GDBContext *GDB_GetClient(GDBServer *server, u16 port) return NULL; } - if (ctx->localPort == GDB_PORT_BASE + MAX_DEBUG) - TaskRunner_WaitReady(); // Finish grabbing new process debug, if anything... - ctx->flags |= GDB_FLAG_USED; ctx->state = GDB_STATE_CONNECTED; ctx->parent = server; @@ -273,6 +270,20 @@ GDBContext *GDB_GetClient(GDBServer *server, u16 port) } GDB_UnlockAllContexts(server); + if (port == GDB_PORT_BASE + MAX_DEBUG) + { + // this is not sufficient/foolproof and is buggy: TaskRunner_WaitReady(); // Finish grabbing new process debug, if anything... + bool ok = false; + do + { + svcSleepThread(5 * 1000 * 1000LL); + RecursiveLock_Lock(&ctx->lock); + ok = ctx->debug != 0; + RecursiveLock_Unlock(&ctx->lock); + } + while (!ok); + } + return ctx; }