Always enable the debugger framework

This commit is contained in:
Jeffrey Pfau 2014-02-01 01:14:41 -08:00
parent a214481b76
commit 6616ca9111
8 changed files with 17 additions and 52 deletions

View File

@ -3,7 +3,7 @@ project(GBAc)
set(BINARY_NAME gbac CACHE INTERNAL "Name of output binaries")
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra --std=gnu99")
set(CMAKE_C_FLAGS_RELEASE "-O3 -Wall -Wextra --std=gnu99")
set(USE_DEBUGGER ON CACHE BOOL "Whether or not to enable the ARM debugger")
set(USE_CLI_DEBUGGER ON CACHE BOOL "Whether or not to enable the CLI-mode ARM debugger")
set(BUILD_SDL ON CACHE BOOL "Build SDL frontend")
set(BUILD_PERF ON CACHE BOOL "Build performance profiling tool")
file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)
@ -29,15 +29,15 @@ else()
source_group("POSIX-specific code" FILES ${OS_SRC})
endif()
if(USE_DEBUGGER)
file(GLOB DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/*.c)
source_group("ARM debugger" FILES ${DEBUGGER_SRC})
set(DEBUGGER_SRC "${CMAKE_SOURCE_DIR}/src/debugger/debugger.c;${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c")
if(USE_CLI_DEBUGGER)
set(DEBUGGER_SRC "${DEBUGGER_SRC};${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c")
set(DEBUGGER_LIB "edit")
add_definitions(-DUSE_DEBUGGER)
else()
set(DEBUGGER_SRC "")
set(DEBUGGER_LIB "")
endif()
source_group("ARM debugger" FILES ${DEBUGGER_SRC})
add_library(${BINARY_NAME} SHARED ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${OS_SRC})
target_link_libraries(${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB})

View File

@ -1,9 +1,7 @@
#ifndef DEBUGGER_H
#define DEBUGGER_H
#ifdef USE_DEBUGGER
#include "arm.h"
#endif
enum DebuggerState {
DEBUGGER_PAUSED,
@ -12,8 +10,6 @@ enum DebuggerState {
DEBUGGER_SHUTDOWN
};
#ifdef USE_DEBUGGER
struct DebugBreakpoint {
struct DebugBreakpoint* next;
int32_t address;
@ -54,12 +50,4 @@ void ARMDebuggerEnter(struct ARMDebugger*, enum DebuggerEntryReason);
void ARMDebuggerSetBreakpoint(struct ARMDebugger* debugger, uint32_t address);
void ARMDebuggerSetWatchpoint(struct ARMDebugger* debugger, uint32_t address);
#else
struct ARMDebugger {
enum DebuggerState state;
};
#endif
#endif

View File

@ -1,7 +1,7 @@
#include "gba-thread.h"
#include "arm.h"
#include "cli-debugger.h"
#include "debugger.h"
#include "gba.h"
#include "gba-serialize.h"
@ -44,10 +44,6 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
InitOnceExecuteOnce(&_contextOnce, _createTLS, NULL, 0);
#endif
#ifdef USE_DEBUGGER
struct CLIDebugger debugger;
CLIDebuggerCreate(&debugger);
#endif
struct GBA gba;
struct GBAThread* threadContext = context;
char* savedata = 0;
@ -98,16 +94,9 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
}
}
#ifdef USE_DEBUGGER
if (threadContext->useDebugger) {
threadContext->debugger = &debugger.d;
GBAAttachDebugger(&gba, &debugger.d);
} else {
threadContext->debugger = 0;
if (threadContext->debugger) {
GBAAttachDebugger(&gba, threadContext->debugger);
}
#else
threadContext->debugger = 0;
#endif
gba.keySource = &threadContext->activeKeys;
@ -118,20 +107,16 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
_changeState(threadContext, THREAD_RUNNING, 1);
while (threadContext->state < THREAD_EXITING) {
#ifdef USE_DEBUGGER
if (threadContext->useDebugger) {
ARMDebuggerRun(&debugger.d);
if (debugger.d.state == DEBUGGER_SHUTDOWN) {
if (threadContext->debugger) {
ARMDebuggerRun(threadContext->debugger);
if (threadContext->debugger->state == DEBUGGER_SHUTDOWN) {
_changeState(threadContext, THREAD_EXITING, 0);
}
} else {
#endif
while (threadContext->state == THREAD_RUNNING) {
ARMRun(&gba.cpu);
}
#ifdef USE_DEBUGGER
}
#endif
MutexLock(&threadContext->stateMutex);
while (threadContext->state == THREAD_PAUSED) {
ConditionWait(&threadContext->stateCond, &threadContext->stateMutex);

View File

@ -32,12 +32,11 @@ struct GBASync {
struct GBAThread {
// Output
enum ThreadState state;
int useDebugger;
struct GBA* gba;
struct ARMDebugger* debugger;
// Input
struct GBAVideoRenderer* renderer;
struct ARMDebugger* debugger;
int fd;
int biosFd;
const char* fname;

View File

@ -341,12 +341,10 @@ static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {
return nextEvent;
}
#ifdef USE_DEBUGGER
void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger) {
ARMDebuggerInit(debugger, &gba->cpu);
gba->debugger = debugger;
}
#endif
void GBALoadROM(struct GBA* gba, int fd, const char* fname) {
struct stat info;
@ -539,23 +537,19 @@ void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...) {
void GBAHitStub(struct ARMBoard* board, uint32_t opcode) {
struct GBABoard* gbaBoard = (struct GBABoard*) board;
enum GBALogLevel level = GBA_LOG_FATAL;
#ifdef USE_DEBUGGER
if (gbaBoard->p->debugger) {
level = GBA_LOG_STUB;
ARMDebuggerEnter(gbaBoard->p->debugger, DEBUGGER_ENTER_ILLEGAL_OP);
}
#endif
GBALog(gbaBoard->p, level, "Stub opcode: %08x", opcode);
}
void GBAIllegal(struct ARMBoard* board, uint32_t opcode) {
struct GBABoard* gbaBoard = (struct GBABoard*) board;
GBALog(gbaBoard->p, GBA_LOG_WARN, "Illegal opcode: %08x", opcode);
#ifdef USE_DEBUGGER
if (gbaBoard->p->debugger) {
ARMDebuggerEnter(gbaBoard->p->debugger, DEBUGGER_ENTER_ILLEGAL_OP);
}
#endif
}
void _checkOverrides(struct GBA* gba, uint32_t id) {

View File

@ -36,7 +36,6 @@ int main(int argc, char** argv) {
.fd = fd,
.fname = fname,
.biosFd = -1,
.useDebugger = 0,
.renderer = &renderer.d,
.frameskip = 0,
.sync.videoFrameWait = 0,

View File

@ -1,4 +1,4 @@
#include "debugger.h"
#include "cli-debugger.h"
#include "gba-thread.h"
#include "gba.h"
#include "sdl-audio.h"
@ -68,11 +68,13 @@ int main(int argc, char** argv) {
return 1;
}
struct CLIDebugger debugger;
CLIDebuggerCreate(&debugger);
struct GBAThread context = {
.fd = fd,
.biosFd = -1,
.fname = fname,
.useDebugger = 1,
.debugger = &debugger.d,
.renderer = &renderer.d.d,
.frameskip = 0,
.sync.videoFrameWait = 0,

View File

@ -59,13 +59,11 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke
case SDLK_RIGHT:
key = GBA_KEY_RIGHT;
break;
#ifdef USE_DEBUGGER
case SDLK_F11:
if (event->type == SDL_KEYDOWN && context->debugger) {
ARMDebuggerEnter(context->debugger, DEBUGGER_ENTER_MANUAL);
}
break;
#endif
case SDLK_TAB:
context->sync.audioWait = event->type != SDL_KEYDOWN;
return;