Always enable the debugger framework
Jeffrey Pfau jeffrey@endrift.com
Sat, 01 Feb 2014 01:14:41 -0800
8 files changed,
17 insertions(+),
52 deletions(-)
M
CMakeLists.txt
→
CMakeLists.txt
@@ -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 @@ file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
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})
M
src/debugger/debugger.h
→
src/debugger/debugger.h
@@ -1,9 +1,7 @@
#ifndef DEBUGGER_H #define DEBUGGER_H -#ifdef USE_DEBUGGER #include "arm.h" -#endif enum DebuggerState { DEBUGGER_PAUSED,@@ -11,8 +9,6 @@ DEBUGGER_RUNNING,
DEBUGGER_EXITING, DEBUGGER_SHUTDOWN }; - -#ifdef USE_DEBUGGER struct DebugBreakpoint { struct DebugBreakpoint* next;@@ -53,13 +49,5 @@ void ARMDebuggerRun(struct ARMDebugger*);
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
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -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 @@ #else
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 @@ GBALoadBIOS(&gba, threadContext->biosFd);
} } -#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 @@
_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);
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -32,12 +32,11 @@
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;
M
src/gba/gba.c
→
src/gba/gba.c
@@ -341,12 +341,10 @@ }
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 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) {
M
src/platform/perf-main.c
→
src/platform/perf-main.c
@@ -36,7 +36,6 @@ struct GBAThread context = {
.fd = fd, .fname = fname, .biosFd = -1, - .useDebugger = 0, .renderer = &renderer.d, .frameskip = 0, .sync.videoFrameWait = 0,
M
src/platform/sdl/gl-main.c
→
src/platform/sdl/gl-main.c
@@ -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 @@ if (!_GBASDLInit(&renderer)) {
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,
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -59,13 +59,11 @@ break;
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;