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(BINARY_NAME gbac CACHE INTERNAL "Name of output binaries")
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra --std=gnu99") set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra --std=gnu99")
set(CMAKE_C_FLAGS_RELEASE "-O3 -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_SDL ON CACHE BOOL "Build SDL frontend")
set(BUILD_PERF ON CACHE BOOL "Build performance profiling tool") set(BUILD_PERF ON CACHE BOOL "Build performance profiling tool")
file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c) file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)
@ -29,15 +29,15 @@ else()
source_group("POSIX-specific code" FILES ${OS_SRC}) source_group("POSIX-specific code" FILES ${OS_SRC})
endif() endif()
if(USE_DEBUGGER) set(DEBUGGER_SRC "${CMAKE_SOURCE_DIR}/src/debugger/debugger.c;${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c")
file(GLOB DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/*.c)
source_group("ARM debugger" FILES ${DEBUGGER_SRC}) if(USE_CLI_DEBUGGER)
set(DEBUGGER_SRC "${DEBUGGER_SRC};${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c")
set(DEBUGGER_LIB "edit") set(DEBUGGER_LIB "edit")
add_definitions(-DUSE_DEBUGGER)
else() else()
set(DEBUGGER_SRC "")
set(DEBUGGER_LIB "") set(DEBUGGER_LIB "")
endif() 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}) 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}) target_link_libraries(${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB})

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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