all repos — mgba @ 7c356ffd07a7fdd456748452df14bbfd4576bd40

mGBA Game Boy Advance Emulator

Move debugger creation off the stack
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Apr 2014 04:19:03 -0700
commit

7c356ffd07a7fdd456748452df14bbfd4576bd40

parent

89ccb41b03c9e4e95d4a8f66fa0a6bc57666e8b5

3 files changed, 45 insertions(+), 27 deletions(-)

jump to
M src/platform/commandline.csrc/platform/commandline.c

@@ -1,5 +1,13 @@

#include "commandline.h" +#ifdef USE_CLI_DEBUGGER +#include "debugger/cli-debugger.h" +#endif + +#ifdef USE_GDB_STUB +#include "debugger/gdb-stub.h" +#endif + #include <fcntl.h> #include <getopt.h>

@@ -49,6 +57,40 @@ opts->fname = _defaultFilename;

} opts->fd = open(opts->fname, O_RDONLY); return 1; +} + +struct ARMDebugger* createDebugger(struct StartupOptions* opts) { + union DebugUnion { + struct ARMDebugger d; +#ifdef USE_CLI_DEBUGGER + struct CLIDebugger cli; +#endif +#ifdef USE_GDB_STUB + struct GDBStub gdb; +#endif + }; + + union DebugUnion* debugger = malloc(sizeof(union DebugUnion)); + + switch (opts->debuggerType) { +#ifdef USE_CLI_DEBUGGER + case DEBUGGER_CLI: + CLIDebuggerCreate(&debugger->cli); + break; +#endif +#ifdef USE_GDB_STUB + case DEBUGGER_GDB: + GDBStubCreate(&debugger->gdb); + break; +#endif + case DEBUGGER_NONE: + case DEBUGGER_MAX: + free(debugger); + return 0; + break; + } + + return &debugger->d; } void usage(const char* arg0) {
M src/platform/commandline.hsrc/platform/commandline.h

@@ -31,6 +31,7 @@ int debugAtStart;

}; int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv); +struct ARMDebugger* createDebugger(struct StartupOptions* opts); void usage(const char* arg0); #endif
M src/platform/sdl/gl-main.csrc/platform/sdl/gl-main.c

@@ -77,18 +77,7 @@ if (!_GBASDLInit(&renderer)) {

return 1; } - union { - struct ARMDebugger d; -#ifdef USE_CLI_DEBUGGER - struct CLIDebugger cli; -#endif -#ifdef USE_GDB_STUB - struct GDBStub gdb; -#endif - } debugger; - struct GBAThread context = { - .debugger = &debugger.d, .renderer = &renderer.d.d, .startCallback = _GBASDLStart, .cleanCallback = _GBASDLClean,

@@ -97,22 +86,7 @@ .sync.audioWait = 1,

.userData = &renderer }; - switch (opts.debuggerType) { -#ifdef USE_CLI_DEBUGGER - case DEBUGGER_CLI: - CLIDebuggerCreate(&debugger.cli); - break; -#endif -#ifdef USE_GDB_STUB - case DEBUGGER_GDB: - GDBStubCreate(&debugger.gdb); - break; -#endif - case DEBUGGER_NONE: - case DEBUGGER_MAX: - context.debugger = 0; - break; - } + context.debugger = createDebugger(&opts); GBAMapOptionsToContext(&opts, &context);

@@ -125,6 +99,7 @@ close(opts.fd);

if (opts.biosFd >= 0) { close(opts.biosFd); } + free(context.debugger); _GBASDLDeinit(&renderer);