From 5418bb066fbc8667ac68e2b3af33e18f483f33da Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 27 Mar 2022 02:33:32 -0700 Subject: [PATCH] Debugger: Add callback for updating while the runloop is suspended; use for GDB --- CHANGES | 1 + include/mgba/debugger/debugger.h | 1 + src/core/thread.c | 10 +++++++++- src/debugger/cli-debugger.c | 1 + src/debugger/gdb-stub.c | 7 +++++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index a107ee4a1..30aa4e0d9 100644 --- a/CHANGES +++ b/CHANGES @@ -47,6 +47,7 @@ Other fixes: Misc: - Core: Suspend runloop when a core crashes - Debugger: Save and restore CLI history + - Debugger: GDB now works while the game is paused - GB Video: Add default SGB border - GBA: Automatically skip BIOS if ROM has invalid logo - GBA: Refine multiboot detection (fixes mgba.io/i/2192) diff --git a/include/mgba/debugger/debugger.h b/include/mgba/debugger/debugger.h index 2adfa117c..f3fa0ab85 100644 --- a/include/mgba/debugger/debugger.h +++ b/include/mgba/debugger/debugger.h @@ -140,6 +140,7 @@ struct mDebugger { void (*deinit)(struct mDebugger*); void (*paused)(struct mDebugger*); + void (*update)(struct mDebugger*); void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*); void (*custom)(struct mDebugger*); }; diff --git a/src/core/thread.c b/src/core/thread.c index 1a9378a77..7f87e9e75 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -250,7 +250,15 @@ static THREAD_ENTRY _mCoreThreadRun(void* context) { } while (impl->state >= mTHREAD_MIN_WAITING && impl->state <= mTHREAD_MAX_WAITING) { - ConditionWait(&impl->stateCond, &impl->stateMutex); +#ifdef USE_DEBUGGERS + if (debugger && debugger->update && debugger->state != DEBUGGER_SHUTDOWN) { + debugger->update(debugger); + ConditionWaitTimed(&impl->stateCond, &impl->stateMutex, 10); + } else +#endif + { + ConditionWait(&impl->stateCond, &impl->stateMutex); + } if (impl->sync.audioWait) { MutexUnlock(&impl->stateMutex); diff --git a/src/debugger/cli-debugger.c b/src/debugger/cli-debugger.c index 3bac2c8ab..d757f19c2 100644 --- a/src/debugger/cli-debugger.c +++ b/src/debugger/cli-debugger.c @@ -1124,6 +1124,7 @@ void CLIDebuggerCreate(struct CLIDebugger* debugger) { debugger->d.deinit = _cliDebuggerDeinit; debugger->d.custom = _cliDebuggerCustom; debugger->d.paused = _commandLine; + debugger->d.update = NULL; debugger->d.entered = _reportEntry; debugger->d.type = DEBUGGER_CLI; diff --git a/src/debugger/gdb-stub.c b/src/debugger/gdb-stub.c index 5526aa0b2..5d625e403 100644 --- a/src/debugger/gdb-stub.c +++ b/src/debugger/gdb-stub.c @@ -135,6 +135,12 @@ static void _gdbStubWait(struct mDebugger* debugger) { GDBStubUpdate(stub); } +static void _gdbStubUpdate(struct mDebugger* debugger) { + struct GDBStub* stub = (struct GDBStub*) debugger; + stub->shouldBlock = false; + GDBStubUpdate(stub); +} + static void _ack(struct GDBStub* stub) { char ack = '+'; SocketSend(stub->connection, &ack, 1); @@ -758,6 +764,7 @@ void GDBStubCreate(struct GDBStub* stub) { stub->d.init = 0; stub->d.deinit = _gdbStubDeinit; stub->d.paused = _gdbStubWait; + stub->d.update = _gdbStubUpdate; stub->d.entered = _gdbStubEntered; stub->d.custom = _gdbStubPoll; stub->d.type = DEBUGGER_GDB;