From 90cf855667746ad46db068e2ba0edb791b9476a1 Mon Sep 17 00:00:00 2001 From: Yannik Marchand Date: Tue, 25 Sep 2018 09:04:20 +0200 Subject: [PATCH] Call OSFatal when the debug server crashes --- src/debugger.cpp | 36 ++++++++++++++++++++++-------------- src/debugger.h | 5 ++++- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/debugger.cpp b/src/debugger.cpp index 6a14220..1519aea 100644 --- a/src/debugger.cpp +++ b/src/debugger.cpp @@ -560,7 +560,7 @@ void Debugger::handleBreakPoint(ExceptionState *state) { stepper.handleBreakPoint(state); if (!connected) { - handleFatalCrash(state); + handleFatalCrash(&state->context, state->type); } uint32_t addr = state->context.srr0; @@ -578,7 +578,7 @@ void Debugger::handleBreakPoint(ExceptionState *state) { resumeBreakPoint(state); } -void Debugger::handleFatalCrash(ExceptionState *state) { +void Debugger::handleCrash(ExceptionState *state) { stepper.adjustAddress(state); if (connected) { OSMessage message; @@ -593,19 +593,27 @@ void Debugger::handleFatalCrash(ExceptionState *state) { } } else { - const char *type; - if (state->type == ExceptionState::DSI) type = "A DSI"; - else if (state->type == ExceptionState::ISI) type = "An ISI"; - else { - type = "A program"; - } - DumpContext(&state->context, type); + handleFatalCrash(&state->context, state->type); } } +void Debugger::handleFatalCrash(OSContext *context, ExceptionState::Type type) { + const char *name; + if (type == ExceptionState::DSI) name = "A DSI"; + else if (type == ExceptionState::ISI) name = "An ISI"; + else { + name = "A program"; + } + DumpContext(context, name); +} + void Debugger::handleException(OSContext *context, ExceptionState::Type type) { OSThread *thread = OSGetCurrentThread(); + if (thread == serverThread) { + handleFatalCrash(context, type); + } + ExceptionState *state = exceptions.findOrCreate(thread); memcpy(&state->context, context, sizeof(OSContext)); state->type = type; @@ -616,7 +624,7 @@ void Debugger::handleException(OSContext *context, ExceptionState::Type type) { handleBreakPoint(state); } else { - handleFatalCrash(state); + handleCrash(state); } } @@ -913,16 +921,16 @@ void Debugger::start() { exceptions.init(); stepper.init(); - OSThread *thread = new OSThread(); + serverThread = new OSThread(); char *stack = new char[0x8000]; OSCreateThread( - thread, threadEntry, 0, 0, + serverThread, threadEntry, 0, 0, stack + STACK_SIZE, STACK_SIZE, 0, 12 ); - OSSetThreadName(thread, "Debug Server"); - OSResumeThread(thread); + OSSetThreadName(serverThread, "Debug Server"); + OSResumeThread(serverThread); while (!initialized) { OSSleepTicks(OSMillisecondsToTicks(20)); diff --git a/src/debugger.h b/src/debugger.h index a725f8c..ca0a4a2 100644 --- a/src/debugger.h +++ b/src/debugger.h @@ -235,7 +235,8 @@ private: void threadFunc(); void mainLoop(Client *client); void handleException(OSContext *context, ExceptionState::Type type); - void handleFatalCrash(ExceptionState *state); + void handleFatalCrash(OSContext *context, ExceptionState::Type type); + void handleCrash(ExceptionState *state); void handleBreakPoint(ExceptionState *state); void processBreakPoint(ExceptionState *state); void resumeBreakPoint(ExceptionState *state); @@ -247,6 +248,8 @@ private: OSMessageQueue eventQueue; OSMessage eventMessages[MESSAGE_COUNT]; + OSThread *serverThread; + BreakPointMgr breakpoints; ExceptionMgr exceptions; StepMgr stepper;