Call OSFatal when the debug server crashes

This commit is contained in:
Yannik Marchand 2018-09-25 09:04:20 +02:00
parent 015b3228f8
commit 90cf855667
2 changed files with 26 additions and 15 deletions

View File

@ -560,7 +560,7 @@ void Debugger::handleBreakPoint(ExceptionState *state) {
stepper.handleBreakPoint(state); stepper.handleBreakPoint(state);
if (!connected) { if (!connected) {
handleFatalCrash(state); handleFatalCrash(&state->context, state->type);
} }
uint32_t addr = state->context.srr0; uint32_t addr = state->context.srr0;
@ -578,7 +578,7 @@ void Debugger::handleBreakPoint(ExceptionState *state) {
resumeBreakPoint(state); resumeBreakPoint(state);
} }
void Debugger::handleFatalCrash(ExceptionState *state) { void Debugger::handleCrash(ExceptionState *state) {
stepper.adjustAddress(state); stepper.adjustAddress(state);
if (connected) { if (connected) {
OSMessage message; OSMessage message;
@ -593,19 +593,27 @@ void Debugger::handleFatalCrash(ExceptionState *state) {
} }
} }
else { else {
const char *type; handleFatalCrash(&state->context, state->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);
} }
} }
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) { void Debugger::handleException(OSContext *context, ExceptionState::Type type) {
OSThread *thread = OSGetCurrentThread(); OSThread *thread = OSGetCurrentThread();
if (thread == serverThread) {
handleFatalCrash(context, type);
}
ExceptionState *state = exceptions.findOrCreate(thread); ExceptionState *state = exceptions.findOrCreate(thread);
memcpy(&state->context, context, sizeof(OSContext)); memcpy(&state->context, context, sizeof(OSContext));
state->type = type; state->type = type;
@ -616,7 +624,7 @@ void Debugger::handleException(OSContext *context, ExceptionState::Type type) {
handleBreakPoint(state); handleBreakPoint(state);
} }
else { else {
handleFatalCrash(state); handleCrash(state);
} }
} }
@ -913,16 +921,16 @@ void Debugger::start() {
exceptions.init(); exceptions.init();
stepper.init(); stepper.init();
OSThread *thread = new OSThread(); serverThread = new OSThread();
char *stack = new char[0x8000]; char *stack = new char[0x8000];
OSCreateThread( OSCreateThread(
thread, threadEntry, 0, 0, serverThread, threadEntry, 0, 0,
stack + STACK_SIZE, STACK_SIZE, stack + STACK_SIZE, STACK_SIZE,
0, 12 0, 12
); );
OSSetThreadName(thread, "Debug Server"); OSSetThreadName(serverThread, "Debug Server");
OSResumeThread(thread); OSResumeThread(serverThread);
while (!initialized) { while (!initialized) {
OSSleepTicks(OSMillisecondsToTicks(20)); OSSleepTicks(OSMillisecondsToTicks(20));

View File

@ -235,7 +235,8 @@ private:
void threadFunc(); void threadFunc();
void mainLoop(Client *client); void mainLoop(Client *client);
void handleException(OSContext *context, ExceptionState::Type type); 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 handleBreakPoint(ExceptionState *state);
void processBreakPoint(ExceptionState *state); void processBreakPoint(ExceptionState *state);
void resumeBreakPoint(ExceptionState *state); void resumeBreakPoint(ExceptionState *state);
@ -247,6 +248,8 @@ private:
OSMessageQueue eventQueue; OSMessageQueue eventQueue;
OSMessage eventMessages[MESSAGE_COUNT]; OSMessage eventMessages[MESSAGE_COUNT];
OSThread *serverThread;
BreakPointMgr breakpoints; BreakPointMgr breakpoints;
ExceptionMgr exceptions; ExceptionMgr exceptions;
StepMgr stepper; StepMgr stepper;