Compile-time flag for disabling debugger
Jeffrey Pfau jeffrey@endrift.com
Sat, 12 Oct 2013 00:13:11 -0700
4 files changed,
43 insertions(+),
2 deletions(-)
M
CMakeLists.txt
→
CMakeLists.txt
@@ -3,11 +3,11 @@ project(GBAc)
set(BINARY_NAME gbac CACHE INTERNAL "Name of output binaries") set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra -Wno-error=type-limits --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") file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c) file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c) file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.c) file(GLOB RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/video-software.c) -file(GLOB DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/*.c) include_directories(${CMAKE_SOURCE_DIR}/src/arm) include_directories(${CMAKE_SOURCE_DIR}/src/gba) include_directories(${CMAKE_SOURCE_DIR}/src/debugger)@@ -18,6 +18,15 @@ find_package(SDL 1.2 REQUIRED)
file(GLOB SDL_SRC ${CMAKE_SOURCE_DIR}/src/sdl/sdl-*.c) include_directories(${CMAKE_SOURCE_DIR}/src/sdl) +if(USE_DEBUGGER) + file(GLOB DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/*.c) + set(DEBUGGER_LIB "edit") + add_definitions(-DUSE_DEBUGGER) +else() + set(DEBUGGER_SRC "") + set(DEBUGGER_LIB "") +endif() + if(BUILD_RASPI AND BUILD_EGL) set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/egl-main.c) set(OPENGL_LIBRARY "-lEGL -lGLESv2 -lbcm_host")@@ -33,4 +42,4 @@ endif()
include_directories(${SDL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}) add_executable(${BINARY_NAME} ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${SDL_SRC} ${MAIN_SRC}) -target_link_libraries(${BINARY_NAME} m pthread edit ${SDL_LIBRARY} ${OPENGL_LIBRARY}) +target_link_libraries(${BINARY_NAME} m pthread ${DEBUGGER_LIB} ${SDL_LIBRARY} ${OPENGL_LIBRARY})
M
src/debugger/debugger.h
→
src/debugger/debugger.h
@@ -1,15 +1,19 @@
#ifndef DEBUGGER_H #define DEBUGGER_H +#ifdef USE_DEBUGGER #include <histedit.h> #include "arm.h" +#endif enum DebuggerState { DEBUGGER_PAUSED, DEBUGGER_RUNNING, DEBUGGER_EXITING }; + +#ifdef USE_DEBUGGER struct DebugBreakpoint { struct DebugBreakpoint* next;@@ -39,5 +43,13 @@ void ARMDebuggerInit(struct ARMDebugger*, struct ARMCore*);
void ARMDebuggerDeinit(struct ARMDebugger*); void ARMDebuggerRun(struct ARMDebugger*); void ARMDebuggerEnter(struct ARMDebugger*); + +#else + +struct ARMDebugger { + enum DebuggerState state; +}; + +#endif #endif
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -17,7 +17,9 @@ static void* _GBAThreadRun(void* context) {
static pthread_once_t once = PTHREAD_ONCE_INIT; pthread_once(&once, _createTLS); +#ifdef USE_DEBUGGER struct ARMDebugger debugger; +#endif struct GBA gba; struct GBAThread* threadContext = context; char* savedata = 0;@@ -57,12 +59,18 @@ }
GBALoadROM(&gba, threadContext->fd, threadContext->fname); gba.savefile = savedata; } + +#ifdef USE_DEBUGGER if (threadContext->useDebugger) { threadContext->debugger = &debugger; GBAAttachDebugger(&gba, &debugger); } else { threadContext->debugger = 0; } +#else + threadContext->debugger = 0; +#endif + gba.keySource = &threadContext->activeKeys; if (threadContext->startCallback) {@@ -74,14 +82,18 @@ pthread_mutex_lock(&threadContext->startMutex);
pthread_cond_broadcast(&threadContext->startCond); pthread_mutex_unlock(&threadContext->startMutex); +#ifdef USE_DEBUGGER if (threadContext->useDebugger) { ARMDebuggerRun(&debugger); threadContext->started = 0; } else { +#endif while (threadContext->started) { ARMRun(&gba.cpu); } +#ifdef USE_DEBUGGER } +#endif if (threadContext->cleanCallback) { threadContext->cleanCallback(threadContext);
M
src/gba/gba.c
→
src/gba/gba.c
@@ -36,6 +36,7 @@
void GBAInit(struct GBA* gba) { gba->errno = GBA_NO_ERROR; gba->errstr = 0; + gba->debugger = 0; ARMInit(&gba->cpu);@@ -266,10 +267,12 @@ }
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;@@ -434,11 +437,16 @@
void GBAHitStub(struct ARMBoard* board, uint32_t opcode) { struct GBABoard* gbaBoard = (struct GBABoard*) board; GBALog(gbaBoard->p, GBA_LOG_STUB, "Stub opcode: %08x", opcode); +#ifdef USE_DEBUGGER if (!gbaBoard->p->debugger) { abort(); } else { ARMDebuggerEnter(gbaBoard->p->debugger); } +#else + abort(); +#endif + } void _checkOverrides(struct GBA* gba, uint32_t id) {