Debugger: Allow attaching multiple debugger modules independently

This commit is contained in:
Vicki Pfau 2022-12-12 01:58:01 -08:00
parent 8efb3fb5df
commit a00f2939ad
7 changed files with 60 additions and 27 deletions

View File

@ -29,6 +29,7 @@ enum mDebuggerType {
};
enum mDebuggerState {
DEBUGGER_CREATED = 0,
DEBUGGER_PAUSED,
DEBUGGER_RUNNING,
DEBUGGER_CALLBACK,

View File

@ -25,8 +25,9 @@ struct mArguments {
struct Table configOverrides;
enum mDebuggerType debuggerType;
bool debugAtStart;
bool debugCli;
bool debugGdb;
bool showHelp;
bool showVersion;
};

View File

@ -95,11 +95,27 @@ void mDebuggerAttach(struct mDebugger* debugger, struct mCore* core) {
void mDebuggerAttachModule(struct mDebugger* debugger, struct mDebuggerModule* module) {
module->p = debugger;
*mDebuggerModuleListAppend(&debugger->modules) = module;
if (debugger->state > DEBUGGER_CREATED && debugger->state < DEBUGGER_SHUTDOWN) {
if (module->init) {
module->init(module);
}
}
}
void mDebuggerDetachModule(struct mDebugger* debugger, struct mDebuggerModule* module) {
// TODO
abort();
size_t i;
for (i = 0; i < mDebuggerModuleListSize(&debugger->modules); ++i) {
if (module != *mDebuggerModuleListGetPointer(&debugger->modules, i)) {
continue;
}
if (debugger->state > DEBUGGER_CREATED && debugger->state < DEBUGGER_SHUTDOWN) {
if (module->deinit) {
module->deinit(module);
}
}
mDebuggerModuleListShift(&debugger->modules, i, 1);
break;
}
}
void mDebuggerRun(struct mDebugger* debugger) {
@ -143,6 +159,9 @@ void mDebuggerRun(struct mDebugger* debugger) {
debugger->state = DEBUGGER_RUNNING;
}
break;
case DEBUGGER_CREATED:
mLOG(DEBUGGER, ERROR, "Attempted to run debugger before initializtion");
return;
case DEBUGGER_SHUTDOWN:
return;
}
@ -258,6 +277,7 @@ static void _mDebuggerInit(void* cpu, struct mCPUComponent* component) {
static void _mDebuggerDeinit(struct mCPUComponent* component) {
struct mDebugger* debugger = (struct mDebugger*) component;
debugger->state = DEBUGGER_SHUTDOWN;
size_t i;
for (i = 0; i < mDebuggerModuleListSize(&debugger->modules); ++i) {
struct mDebuggerModule* module = *mDebuggerModuleListGetPointer(&debugger->modules, i);

View File

@ -137,18 +137,14 @@ bool mArgumentsParse(struct mArguments* args, int argc, char* const* argv, struc
break;
#ifdef USE_EDITLINE
case 'd':
if (args->debuggerType != DEBUGGER_NONE) {
return false;
}
args->debuggerType = DEBUGGER_CLI;
args->debugAtStart = true;
args->debugCli = true;
break;
#endif
#ifdef USE_GDB_STUB
case 'g':
if (args->debuggerType != DEBUGGER_NONE) {
return false;
}
args->debuggerType = DEBUGGER_GDB;
args->debugAtStart = true;
args->debugGdb = true;
break;
#endif
case 'h':

View File

@ -347,7 +347,9 @@ void CoreController::detachDebugger() {
void CoreController::attachDebuggerModule(mDebuggerModule* module, bool interrupt) {
Interrupter interrupter(this);
mDebuggerAttachModule(&m_debugger, module);
if (module) {
mDebuggerAttachModule(&m_debugger, module);
}
attachDebugger(interrupt);
}

View File

@ -206,15 +206,14 @@ void Window::argumentsPassed() {
}
#ifdef USE_GDB_STUB
if (args->debuggerType == DEBUGGER_GDB) {
if (!m_gdbController) {
m_gdbController = new GDBController(this);
if (m_controller) {
m_gdbController->setController(m_controller);
}
m_gdbController->attach();
m_gdbController->listen();
}
if (args->debugGdb) {
gdbOpen();
}
#endif
#ifdef USE_DEBUGGERS
if (args->debugCli) {
consoleOpen();
}
#endif

View File

@ -243,19 +243,33 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
#endif
#ifdef USE_DEBUGGERS
struct mDebuggerModule* module = mDebuggerCreateModule(args->debuggerType, renderer->core);
struct mDebugger debugger;
bool hasDebugger = false;
mDebuggerInit(&debugger);
if (module) {
#ifdef USE_EDITLINE
if (args->debuggerType == DEBUGGER_CLI) {
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
module->isPaused = true;
mDebuggerAttachModule(&debugger, module);
#ifdef USE_GDB_STUB
if (args->debugGdb) {
struct mDebuggerModule* module = mDebuggerCreateModule(DEBUGGER_GDB, renderer->core);
if (module) {
mDebuggerAttachModule(&debugger, module);
hasDebugger = true;
}
}
#endif
if (hasDebugger) {
mDebuggerAttach(&debugger, renderer->core);
mDebuggerEnter(&debugger, DEBUGGER_ENTER_MANUAL, NULL);
#ifdef ENABLE_SCRIPTING
@ -328,7 +342,7 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
#endif
#ifdef USE_DEBUGGERS
if (module) {
if (hasDebugger) {
renderer->core->detachDebugger(renderer->core);
mDebuggerDeinit(&debugger);
}