Feature: Move command-line debugger argument handling

This commit is contained in:
Vicki Pfau 2023-11-24 21:57:35 -08:00
parent b7284542bc
commit 319bdbd106
3 changed files with 37 additions and 29 deletions

View File

@ -59,6 +59,7 @@ void version(const char* arg0);
bool mArgumentsParse(struct mArguments* args, int argc, char* const* argv, struct mSubParser* subparsers, int nSubparsers);
void mArgumentsApply(const struct mArguments* args, struct mSubParser* subparsers, int nSubparsers, struct mCoreConfig* config);
bool mArgumentsApplyDebugger(const struct mArguments*, struct mCore*, struct mDebugger*);
void mArgumentsDeinit(struct mArguments* args);
void mSubParserGraphicsInit(struct mSubParser* parser, struct mGraphicsOpts* opts);

View File

@ -9,6 +9,13 @@
#include <mgba/core/version.h>
#include <mgba-util/string.h>
#ifdef USE_GDB_STUB
#include <mgba/internal/debugger/gdb-stub.h>
#endif
#ifdef USE_EDITLINE
#include <mgba/internal/debugger/cli-el-backend.h>
#endif
#include <fcntl.h>
#ifdef _MSC_VER
#include <mgba-util/platform/windows/getopt.h>
@ -206,6 +213,34 @@ void mArgumentsApply(const struct mArguments* args, struct mSubParser* subparser
}
}
bool mArgumentsApplyDebugger(const struct mArguments* args, struct mCore* core, struct mDebugger* debugger) {
bool hasDebugger = false;
#ifdef USE_EDITLINE
if (args->debugCli) {
struct mDebuggerModule* module = mDebuggerCreateModule(DEBUGGER_CLI, core);
if (module) {
struct CLIDebugger* cliDebugger = (struct CLIDebugger*) module;
CLIDebuggerAttachBackend(cliDebugger, CLIDebuggerEditLineBackendCreate());
mDebuggerAttachModule(debugger, module);
hasDebugger = true;
}
}
#endif
#ifdef USE_GDB_STUB
if (args->debugGdb) {
struct mDebuggerModule* module = mDebuggerCreateModule(DEBUGGER_GDB, core);
if (module) {
mDebuggerAttachModule(debugger, module);
hasDebugger = true;
}
}
#endif
return hasDebugger;
}
void mArgumentsDeinit(struct mArguments* args) {
free(args->fname);
args->fname = 0;

View File

@ -7,12 +7,6 @@
#include <mgba/internal/debugger/cli-debugger.h>
#ifdef USE_GDB_STUB
#include <mgba/internal/debugger/gdb-stub.h>
#endif
#ifdef USE_EDITLINE
#include <mgba/internal/debugger/cli-el-backend.h>
#endif
#ifdef ENABLE_SCRIPTING
#include <mgba/core/scripting.h>
@ -244,30 +238,8 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
#ifdef USE_DEBUGGERS
struct mDebugger debugger;
bool hasDebugger = false;
mDebuggerInit(&debugger);
#ifdef USE_EDITLINE
if (args->debugCli) {
struct mDebuggerModule* module = mDebuggerCreateModule(DEBUGGER_CLI, renderer->core);
if (module) {
struct CLIDebugger* cliDebugger = (struct CLIDebugger*) module;
CLIDebuggerAttachBackend(cliDebugger, CLIDebuggerEditLineBackendCreate());
mDebuggerAttachModule(&debugger, module);
hasDebugger = true;
}
}
#endif
#ifdef USE_GDB_STUB
if (args->debugGdb) {
struct mDebuggerModule* module = mDebuggerCreateModule(DEBUGGER_GDB, renderer->core);
if (module) {
mDebuggerAttachModule(&debugger, module);
hasDebugger = true;
}
}
#endif
bool hasDebugger = mArgumentsApplyDebugger(args, renderer->core, &debugger);
if (hasDebugger) {
mDebuggerAttach(&debugger, renderer->core);