From b6b70c4147e5961e7202c8277477918f122d4b12 Mon Sep 17 00:00:00 2001 From: GalaxyShard Date: Tue, 29 Oct 2024 01:37:05 -0400 Subject: [PATCH] cli option to toggle gdb breakOnStart --- src/frontend/qt_sdl/CLI.cpp | 26 ++++++++++++++++++++++++++ src/frontend/qt_sdl/CLI.h | 4 ++++ src/frontend/qt_sdl/EmuInstance.cpp | 17 ++++++++++++++--- src/frontend/qt_sdl/EmuInstance.h | 6 ++++++ src/frontend/qt_sdl/Window.cpp | 2 +- src/frontend/qt_sdl/main.cpp | 14 ++++++++++---- src/frontend/qt_sdl/main.h | 2 +- 7 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/frontend/qt_sdl/CLI.cpp b/src/frontend/qt_sdl/CLI.cpp index 5e352cae..8f2faf5e 100644 --- a/src/frontend/qt_sdl/CLI.cpp +++ b/src/frontend/qt_sdl/CLI.cpp @@ -44,6 +44,13 @@ CommandLineOptions* ManageArgs(QApplication& melon) parser.addOption(QCommandLineOption({"b", "boot"}, "Whether to boot firmware on startup. Defaults to \"auto\" (boot if NDS rom given)", "auto/always/never", "auto")); parser.addOption(QCommandLineOption({"f", "fullscreen"}, "Start melonDS in fullscreen mode")); +#ifdef GDBSTUB_ENABLED + parser.addOption(QCommandLineOption("break-arm9", "Yield ARM9 execution to the GDB stub immediately on startup")); + parser.addOption(QCommandLineOption("break-arm7", "Yield ARM7 execution to the GDB stub immediately on startup")); + parser.addOption(QCommandLineOption("no-break-arm9", "Do not wait for GDB on ARM9 startup, even if the option to do so is enabled")); + parser.addOption(QCommandLineOption("no-break-arm7", "Do not wait for GDB on ARM9 startup, even if the option to do so is enabled")); +#endif + #ifdef ARCHIVE_SUPPORT_ENABLED parser.addOption(QCommandLineOption({"a", "archive-file"}, "Specify file to load inside an archive given (NDS)", "rom")); parser.addOption(QCommandLineOption({"A", "archive-file-gba"}, "Specify file to load inside an archive given (GBA)", "rom")); @@ -55,6 +62,25 @@ CommandLineOptions* ManageArgs(QApplication& melon) options->fullscreen = parser.isSet("fullscreen"); +#ifdef GDBSTUB_ENABLED + if (parser.isSet("break-arm9")) + { + options->arm9BreakOnStartup = true; + } + if (parser.isSet("no-break-arm9")) + { + options->arm9BreakOnStartup = false; + } + if (parser.isSet("break-arm7")) + { + options->arm7BreakOnStartup = true; + } + if (parser.isSet("no-break-arm7")) + { + options->arm7BreakOnStartup = false; + } +#endif + QStringList posargs = parser.positionalArguments(); switch (posargs.size()) { diff --git a/src/frontend/qt_sdl/CLI.h b/src/frontend/qt_sdl/CLI.h index beb120bf..a76866e7 100644 --- a/src/frontend/qt_sdl/CLI.h +++ b/src/frontend/qt_sdl/CLI.h @@ -34,6 +34,10 @@ struct CommandLineOptions std::optional gbaRomArchivePath; bool fullscreen; bool boot; +#ifdef GDBSTUB_ENABLED + std::optional arm9BreakOnStartup; + std::optional arm7BreakOnStartup; +#endif }; extern CommandLineOptions* ManageArgs(QApplication& melon); diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index 90116692..93423a96 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -65,7 +65,12 @@ const string kWifiSettingsPath = "wfcsettings.bin"; extern Net net; -EmuInstance::EmuInstance(int inst) : deleting(false), +EmuInstance::EmuInstance(int inst, std::optional arm9BreakOnStart, std::optional arm7BreakOnStart) : +#ifdef GDBSTUB_ENABLED + overrideArm9BreakOnStart(arm9BreakOnStart), + overrideArm7BreakOnStart(arm7BreakOnStart), +#endif + deleting(false), instanceID(inst), globalCfg(Config::GetGlobalTable()), localCfg(Config::GetLocalTable(inst)) @@ -149,6 +154,12 @@ EmuInstance::EmuInstance(int inst) : deleting(false), } } +EmuInstance::EmuInstance(int inst) : + EmuInstance(inst, std::nullopt, std::nullopt) +{ + +} + EmuInstance::~EmuInstance() { deleting = true; @@ -1287,8 +1298,8 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB GDBArgs _gdbargs { static_cast(gdbopt.GetInt("ARM7.Port")), static_cast(gdbopt.GetInt("ARM9.Port")), - gdbopt.GetBool("ARM7.BreakOnStartup"), - gdbopt.GetBool("ARM9.BreakOnStartup"), + overrideArm7BreakOnStart.value_or(gdbopt.GetBool("ARM7.BreakOnStartup")), + overrideArm9BreakOnStart.value_or(gdbopt.GetBool("ARM9.BreakOnStartup")), }; auto gdbargs = gdbopt.GetBool("Enabled") ? std::make_optional(_gdbargs) : std::nullopt; #else diff --git a/src/frontend/qt_sdl/EmuInstance.h b/src/frontend/qt_sdl/EmuInstance.h index 658247f0..52851201 100644 --- a/src/frontend/qt_sdl/EmuInstance.h +++ b/src/frontend/qt_sdl/EmuInstance.h @@ -79,6 +79,7 @@ class EmuInstance { public: EmuInstance(int inst); + EmuInstance(int inst, std::optional arm9BreakOnStart, std::optional arm7BreakOnStart); ~EmuInstance(); int getInstanceID() { return instanceID; } @@ -260,6 +261,11 @@ private: std::string baseGBAROMName; std::string baseGBAAssetName; +#ifdef GDBSTUB_ENABLED + std::optional overrideArm9BreakOnStart = std::nullopt; + std::optional overrideArm7BreakOnStart = std::nullopt; +#endif + // HACK public: std::unique_ptr ndsSave; diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 0af72ef6..5b2aee3f 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -1688,7 +1688,7 @@ void MainWindow::onOpenTitleManager() void MainWindow::onMPNewInstance() { - createEmuInstance(); + createEmuInstance(std::nullopt, std::nullopt); } void MainWindow::onLANStartHost() diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index d940340a..12f8696c 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -118,7 +118,7 @@ void NetInit() } -bool createEmuInstance() +bool createEmuInstance(std::optional arm9BreakOnStartup, std::optional arm7BreakOnStartup) { int id = -1; for (int i = 0; i < kMaxEmuInstances; i++) @@ -133,7 +133,11 @@ bool createEmuInstance() if (id == -1) return false; +#ifdef GDBSTUB_ENABLED + auto inst = new EmuInstance(id, arm9BreakOnStartup, arm7BreakOnStartup); +#else auto inst = new EmuInstance(id); +#endif emuInstances[id] = inst; return true; @@ -348,9 +352,11 @@ int main(int argc, char** argv) setMPInterface(MPInterface_Local); NetInit(); - - createEmuInstance(); - +#ifdef GDBSTUB_ENABLED + createEmuInstance(options->arm9BreakOnStartup, options->arm7BreakOnStartup); +#else + createEmuInstance(std::nullopt, std::nullopt); +#endif { MainWindow* win = emuInstances[0]->getMainWindow(); bool memberSyntaxUsed = false; diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index e0d38963..a0301d73 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -54,7 +54,7 @@ extern QString emuDirectory; extern QElapsedTimer sysTimer; -bool createEmuInstance(); +bool createEmuInstance(std::optional arm9BreakOnStartup, std::optional arm7BreakOnStartup); void deleteEmuInstance(int id); void deleteAllEmuInstances(int first = 0); int numEmuInstances();