From 5b80b8e4c748e1b3128f645763f141c993827acf Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 26 Oct 2016 23:28:25 -0700 Subject: [PATCH] Debugger: Make building with debugging aspects optional --- CHANGES | 1 + CMakeLists.txt | 46 +++++++++++++++++++----------- src/core/core.h | 2 ++ src/core/thread.c | 5 +++- src/gb/core.c | 6 +++- src/gb/{ => extra}/cli.c | 0 src/gb/{ => extra}/cli.h | 0 src/gb/gb.c | 4 +++ src/gba/core.c | 4 +++ src/gba/gba.c | 9 +++++- src/gba/{extra => }/sharkport.c | 0 src/gba/{extra => }/sharkport.h | 0 src/platform/qt/CMakeLists.txt | 12 +++++--- src/platform/qt/GameController.cpp | 2 +- src/platform/qt/Window.cpp | 6 ++++ src/platform/qt/Window.h | 4 +++ src/platform/sdl/main.c | 2 ++ src/platform/sdl/sdl-events.c | 2 ++ 18 files changed, 81 insertions(+), 24 deletions(-) rename src/gb/{ => extra}/cli.c (100%) rename src/gb/{ => extra}/cli.h (100%) rename src/gba/{extra => }/sharkport.c (100%) rename src/gba/{extra => }/sharkport.h (100%) diff --git a/CHANGES b/CHANGES index b118de5ca..8c00531c0 100644 --- a/CHANGES +++ b/CHANGES @@ -32,6 +32,7 @@ Misc: - VFS: Allow truncating memory chunk VFiles - Debugger: Modularize CLI debugger - Core: Clean up some thread state checks + - Debugger: Make building with debugging aspects optional 0.5.1: (2016-10-05) Bugfixes: diff --git a/CMakeLists.txt b/CMakeLists.txt index e9f62f030..6bf41d4ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ if(NOT MSVC) else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS /wd4003 /wd4244 /wd4146") endif() +set(USE_DEBUGGERS ON CACHE BOOL "Whether or not to enable the debugging infrastructure") set(USE_EDITLINE ON CACHE BOOL "Whether or not to enable the CLI-mode debugger") set(USE_GDB_STUB ON CACHE BOOL "Whether or not to enable the GDB stub ARM debugger") set(USE_FFMPEG ON CACHE BOOL "Whether or not to enable FFmpeg support") @@ -44,7 +45,6 @@ file(GLOB GB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/*.c) file(GLOB GB_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/test/*.c) file(GLOB GBA_CHEATS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/cheats/*.c) file(GLOB GBA_RR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/rr/*.c) -file(GLOB GBA_EXTRA_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/extra/*.c) file(GLOB CORE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/core/*.c) file(GLOB CORE_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/core/test/*.c) file(GLOB UTIL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/*.[cSs]) @@ -60,7 +60,7 @@ set(VFS_SRC) source_group("ARM core" FILES ${ARM_SRC}) source_group("LR35902 core" FILES ${LR35902_SRC}) source_group("GBA board" FILES ${GBA_SRC} ${GBA_RENDERER_SRC} ${SIO_SRC}) -source_group("GBA extra" FILES ${GBA_CHEATS_SRC} ${GBA_EXTRA_SRC} ${GBA_RR_SRC}) +source_group("GBA extra" FILES ${GBA_CHEATS_SRC} ${GBA_RR_SRC}) source_group("GB board" FILES ${GB_SRC}) source_group("Utilities" FILES ${UTIL_SRC}) include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src) @@ -235,7 +235,16 @@ if(PSP2 OR WII) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format") endif() -if(DEFINED 3DS OR DEFINED PSP2 OR DEFINED WII OR NOT M_CORE_GBA) +if(DEFINED 3DS OR DEFINED PSP2 OR DEFINED WII) + set(USE_DEBUGGERS OFF) +endif() + +if(NOT M_CORE_GBA) + set(USE_GDB_STUB OFF) +endif() + +if(NOT USE_DEBUGGERS) + set(USE_EDITLINE OFF) set(USE_GDB_STUB OFF) endif() @@ -530,22 +539,17 @@ if(USE_EPOXY) set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libepoxy0") endif() - -set(FEATURE_DEFINES) -foreach(FEATURE IN LISTS FEATURES) - list(APPEND FEATURE_DEFINES "USE_${FEATURE}") -endforeach() - set(TEST_SRC ${CORE_TEST_SRC}) if(M_CORE_GB) add_definitions(-DM_CORE_GB) list(APPEND CORE_SRC ${LR35902_SRC} - ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/debugger.c ${GB_SRC} ${GB_RENDERER_SRC}) - list(APPEND CLI_SRC - ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/cli-debugger.c) + list(APPEND DEBUGGER_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/cli-debugger.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/debugger.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/extra/cli.c) list(APPEND TEST_SRC ${LR35902_TEST_SRC} ${GB_TEST_SRC}) @@ -555,13 +559,13 @@ if(M_CORE_GBA) add_definitions(-DM_CORE_GBA) list(APPEND CORE_SRC ${ARM_SRC} - ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/debugger.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/memory-debugger.c ${GBA_SRC} ${GBA_CHEATS_SRC} ${GBA_RENDERER_SRC}) - list(APPEND CLI_SRC + list(APPEND DEBUGGER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/cli-debugger.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/debugger.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/memory-debugger.c ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/extra/cli.c) list(APPEND TEST_SRC ${ARM_TEST_SRC} @@ -571,6 +575,16 @@ if(M_CORE_GBA) endif() endif() +if(USE_DEBUGGERS) + list(APPEND FEATURE_SRC ${DEBUGGER_SRC}) + list(APPEND FEATURES DEBUGGERS) +endif() + +set(FEATURE_DEFINES) +foreach(FEATURE IN LISTS FEATURES) + list(APPEND FEATURE_DEFINES "USE_${FEATURE}") +endforeach() + source_group("Virtual files" FILES ${CORE_VFS_SRC} ${VFS_SRC}) source_group("Extra features" FILES ${FEATURE_SRC}) source_group("Third-party code" FILES ${THIRD_PARTY_SRC}) @@ -592,7 +606,6 @@ endif() list(APPEND CORE_SRC ${UTIL_SRC} ${CORE_VFS_SRC} - ${DEBUGGER_SRC} ${OS_SRC} ${THIRD_PARTY_SRC}) list(APPEND TEST_SRC ${UTIL_TEST_SRC}) @@ -802,6 +815,7 @@ if(NOT QUIET) message(STATUS " Game Boy Advance: ${M_CORE_GBA}") message(STATUS " Game Boy: ${M_CORE_GB}") message(STATUS "Features:") + message(STATUS " Debuggers: ${USE_DEBUGGERS}") message(STATUS " CLI debugger: ${USE_EDITLINE}") message(STATUS " GDB stub: ${USE_GDB_STUB}") message(STATUS " Video recording: ${USE_FFMPEG}") diff --git a/src/core/core.h b/src/core/core.h index d781f38cf..2f4f9153b 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -118,11 +118,13 @@ struct mCore { void (*rawWrite16)(struct mCore*, uint32_t address, int segment, uint16_t); void (*rawWrite32)(struct mCore*, uint32_t address, int segment, uint32_t); +#ifdef USE_DEBUGGERS bool (*supportsDebuggerType)(struct mCore*, enum mDebuggerType); struct mDebuggerPlatform* (*debuggerPlatform)(struct mCore*); struct CLIDebuggerSystem* (*cliDebuggerSystem)(struct mCore*); void (*attachDebugger)(struct mCore*, struct mDebugger*); void (*detachDebugger)(struct mCore*); +#endif struct mCheatDevice* (*cheatDevice)(struct mCore*); diff --git a/src/core/thread.c b/src/core/thread.c index 89ff1d2e8..4c7eb90eb 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -162,13 +162,16 @@ static THREAD_ENTRY _mCoreThreadRun(void* context) { } while (threadContext->state < THREAD_EXITING) { +#ifdef USE_DEBUGGERS struct mDebugger* debugger = core->debugger; if (debugger) { mDebuggerRun(debugger); if (debugger->state == DEBUGGER_SHUTDOWN) { _changeState(threadContext, THREAD_EXITING, false); } - } else { + } else +#endif + { while (threadContext->state <= THREAD_MAX_RUNNING) { core->runLoop(core); } diff --git a/src/gb/core.c b/src/gb/core.c index cfab4b3b3..fabe88f8c 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -7,7 +7,7 @@ #include "core/core.h" #include "gb/cheats.h" -#include "gb/cli.h" +#include "gb/extra/cli.h" #include "gb/gb.h" #include "gb/mbc.h" #include "gb/overrides.h" @@ -427,6 +427,7 @@ static void _GBCoreRawWrite32(struct mCore* core, uint32_t address, int segment, GBPatch8(cpu, address + 3, value >> 24, NULL, segment); } +#ifdef USE_DEBUGGERS static bool _GBCoreSupportsDebuggerType(struct mCore* core, enum mDebuggerType type) { UNUSED(core); switch (type) { @@ -467,6 +468,7 @@ static void _GBCoreDetachDebugger(struct mCore* core) { cpu->components[CPU_COMPONENT_DEBUGGER] = NULL; core->debugger = NULL; } +#endif static struct mCheatDevice* _GBCoreCheatDevice(struct mCore* core) { struct GBCore* gbcore = (struct GBCore*) core; @@ -570,11 +572,13 @@ struct mCore* GBCoreCreate(void) { core->rawWrite8 = _GBCoreRawWrite8; core->rawWrite16 = _GBCoreRawWrite16; core->rawWrite32 = _GBCoreRawWrite32; +#ifdef USE_DEBUGGERS core->supportsDebuggerType = _GBCoreSupportsDebuggerType; core->debuggerPlatform = _GBCoreDebuggerPlatform; core->cliDebuggerSystem = _GBCoreCliDebuggerSystem; core->attachDebugger = _GBCoreAttachDebugger; core->detachDebugger = _GBCoreDetachDebugger; +#endif core->cheatDevice = _GBCoreCheatDevice; core->savedataClone = _GBCoreSavedataClone; core->savedataRestore = _GBCoreSavedataRestore; diff --git a/src/gb/cli.c b/src/gb/extra/cli.c similarity index 100% rename from src/gb/cli.c rename to src/gb/extra/cli.c diff --git a/src/gb/cli.h b/src/gb/extra/cli.h similarity index 100% rename from src/gb/cli.h rename to src/gb/extra/cli.h diff --git a/src/gb/gb.c b/src/gb/gb.c index 5ac0028f2..2535b7264 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -600,6 +600,7 @@ void GBStop(struct LR35902Core* cpu) { gb->memory.io[REG_KEY1] = 0; gb->memory.io[REG_KEY1] |= gb->doubleSpeed << 7; } else if (cpu->bus) { +#ifdef USE_DEBUGGERS if (cpu->components && cpu->components[CPU_COMPONENT_DEBUGGER]) { struct mDebuggerEntryInfo info = { .address = cpu->pc - 1, @@ -607,6 +608,7 @@ void GBStop(struct LR35902Core* cpu) { }; mDebuggerEnter((struct mDebugger*) cpu->components[CPU_COMPONENT_DEBUGGER], DEBUGGER_ENTER_ILLEGAL_OP, &info); } +#endif // Hang forever gb->memory.ime = 0; cpu->pc -= 2; @@ -617,6 +619,7 @@ void GBStop(struct LR35902Core* cpu) { void GBIllegal(struct LR35902Core* cpu) { struct GB* gb = (struct GB*) cpu->master; mLOG(GB, GAME_ERROR, "Hit illegal opcode at address %04X:%02X\n", cpu->pc, cpu->bus); +#ifdef USE_DEBUGGERS if (cpu->components && cpu->components[CPU_COMPONENT_DEBUGGER]) { struct mDebuggerEntryInfo info = { .address = cpu->pc, @@ -624,6 +627,7 @@ void GBIllegal(struct LR35902Core* cpu) { }; mDebuggerEnter((struct mDebugger*) cpu->components[CPU_COMPONENT_DEBUGGER], DEBUGGER_ENTER_ILLEGAL_OP, &info); } +#endif // Hang forever gb->memory.ime = 0; --cpu->pc; diff --git a/src/gba/core.c b/src/gba/core.c index c838fab69..a3f5b4441 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -439,6 +439,7 @@ static void _GBACoreRawWrite32(struct mCore* core, uint32_t address, int segment GBAPatch32(cpu, address, value, NULL); } +#ifdef USE_DEBUGGERS static bool _GBACoreSupportsDebuggerType(struct mCore* core, enum mDebuggerType type) { UNUSED(core); switch (type) { @@ -477,6 +478,7 @@ static void _GBACoreDetachDebugger(struct mCore* core) { GBADetachDebugger(core->board); core->debugger = NULL; } +#endif static struct mCheatDevice* _GBACoreCheatDevice(struct mCore* core) { struct GBACore* gbacore = (struct GBACore*) core; @@ -587,11 +589,13 @@ struct mCore* GBACoreCreate(void) { core->rawWrite8 = _GBACoreRawWrite8; core->rawWrite16 = _GBACoreRawWrite16; core->rawWrite32 = _GBACoreRawWrite32; +#ifdef USE_DEBUGGERS core->supportsDebuggerType = _GBACoreSupportsDebuggerType; core->debuggerPlatform = _GBACoreDebuggerPlatform; core->cliDebuggerSystem = _GBACoreCliDebuggerSystem; core->attachDebugger = _GBACoreAttachDebugger; core->detachDebugger = _GBACoreDetachDebugger; +#endif core->cheatDevice = _GBACoreCheatDevice; core->savedataClone = _GBACoreSavedataClone; core->savedataRestore = _GBACoreSavedataRestore; diff --git a/src/gba/gba.c b/src/gba/gba.c index 3f5e82c04..a6d2bbe99 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -791,6 +791,7 @@ void GBAGetGameTitle(const struct GBA* gba, char* out) { void GBAHitStub(struct ARMCore* cpu, uint32_t opcode) { struct GBA* gba = (struct GBA*) cpu->master; +#ifdef USE_DEBUGGERS if (gba->debugger) { struct mDebuggerEntryInfo info = { .address = _ARMPCAddress(cpu), @@ -798,6 +799,7 @@ void GBAHitStub(struct ARMCore* cpu, uint32_t opcode) { }; mDebuggerEnter(gba->debugger->d.p, DEBUGGER_ENTER_ILLEGAL_OP, &info); } +#endif // TODO: More sensible category? mLOG(GBA, ERROR, "Stub opcode: %08x", opcode); } @@ -808,13 +810,16 @@ void GBAIllegal(struct ARMCore* cpu, uint32_t opcode) { // TODO: More sensible category? mLOG(GBA, WARN, "Illegal opcode: %08x", opcode); } +#ifdef USE_DEBUGGERS if (gba->debugger) { struct mDebuggerEntryInfo info = { .address = _ARMPCAddress(cpu), .opcode = opcode }; mDebuggerEnter(gba->debugger->d.p, DEBUGGER_ENTER_ILLEGAL_OP, &info); - } else { + } else +#endif + { ARMRaiseUndefined(cpu); } } @@ -825,6 +830,7 @@ void GBABreakpoint(struct ARMCore* cpu, int immediate) { return; } switch (immediate) { +#ifdef USE_DEBUGGERS case CPU_COMPONENT_DEBUGGER: if (gba->debugger) { struct mDebuggerEntryInfo info = { @@ -834,6 +840,7 @@ void GBABreakpoint(struct ARMCore* cpu, int immediate) { mDebuggerEnter(gba->debugger->d.p, DEBUGGER_ENTER_BREAKPOINT, &info); } break; +#endif case CPU_COMPONENT_CHEAT_DEVICE: if (gba->cpu->components[CPU_COMPONENT_CHEAT_DEVICE]) { struct mCheatDevice* device = (struct mCheatDevice*) gba->cpu->components[CPU_COMPONENT_CHEAT_DEVICE]; diff --git a/src/gba/extra/sharkport.c b/src/gba/sharkport.c similarity index 100% rename from src/gba/extra/sharkport.c rename to src/gba/sharkport.c diff --git a/src/gba/extra/sharkport.h b/src/gba/sharkport.h similarity index 100% rename from src/gba/extra/sharkport.h rename to src/gba/sharkport.h diff --git a/src/platform/qt/CMakeLists.txt b/src/platform/qt/CMakeLists.txt index fe062276f..f5485f089 100644 --- a/src/platform/qt/CMakeLists.txt +++ b/src/platform/qt/CMakeLists.txt @@ -75,9 +75,6 @@ set(SOURCE_FILES CheatsModel.cpp CheatsView.cpp ConfigController.cpp - DebuggerController.cpp - DebuggerREPL.cpp - DebuggerREPLController.cpp Display.cpp DisplayGL.cpp DisplayQt.cpp @@ -181,8 +178,15 @@ if(NOT AUDIO_SRC) return() endif() +if(USE_DEBUGGERS) + list(APPEND SOURCE_FILES + DebuggerController.cpp + DebuggerREPL.cpp + DebuggerREPLController.cpp) +endif() + if(USE_GDB_STUB) - list(APPEND PLATFORM_SRC GDBController.cpp GDBWindow.cpp) + list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp) endif() qt5_add_resources(RESOURCES resources.qrc) diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 0c62ed04d..2ef954cc6 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -26,8 +26,8 @@ extern "C" { #include "gba/bios.h" #include "gba/core.h" #include "gba/gba.h" -#include "gba/extra/sharkport.h" #include "gba/renderers/tile-cache.h" +#include "gba/sharkport.h" #endif #ifdef M_CORE_GB #include "gb/gb.h" diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 9dca63a4e..b8a387601 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -72,7 +72,9 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent) #ifdef USE_GDB_STUB , m_gdbController(nullptr) #endif +#ifdef USE_DEBUGGERS , m_repl(nullptr) +#endif , m_mruMenu(nullptr) , m_shortcutController(new ShortcutController(this)) , m_fullscreenOnStart(false) @@ -516,6 +518,7 @@ void Window::gdbOpen() { } #endif +#ifdef USE_DEBUGGERS void Window::replOpen() { if (!m_repl) { m_repl = new DebuggerREPLController(m_controller, this); @@ -523,6 +526,7 @@ void Window::replOpen() { DebuggerREPL* window = new DebuggerREPL(m_repl); openView(window); } +#endif void Window::keyPressEvent(QKeyEvent* event) { if (event->isAutoRepeat()) { @@ -1348,9 +1352,11 @@ void Window::setupMenu(QMenuBar* menubar) { toolsMenu->addSeparator(); +#ifdef USE_DEBUGGERS QAction* replWindow = new QAction(tr("Open debugger REPL..."), toolsMenu); connect(replWindow, SIGNAL(triggered()), this, SLOT(replOpen())); addControlledAction(toolsMenu, replWindow, "debuggerWindow"); +#endif #ifdef USE_GDB_STUB QAction* gdbWindow = new QAction(tr("Start &GDB server..."), toolsMenu); diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index 0436e08ca..9e20efc41 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -81,7 +81,9 @@ public slots: void openSettingsWindow(); void openAboutScreen(); +#ifdef USE_DEBUGGERS void replOpen(); +#endif #ifdef USE_FFMPEG void openVideoWindow(); @@ -159,7 +161,9 @@ private: QMap m_frameSizes; LogController m_log; LogView* m_logView; +#ifdef USE_DEBUGGERS DebuggerREPLController* m_repl; +#endif LoadSaveState* m_stateWindow; WindowBackground* m_screenWidget; QPixmap m_logo; diff --git a/src/platform/sdl/main.c b/src/platform/sdl/main.c index 20495b5b6..c6621ecf5 100644 --- a/src/platform/sdl/main.c +++ b/src/platform/sdl/main.c @@ -168,6 +168,7 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) { return 1; } mCoreAutoloadSave(renderer->core); +#ifdef USE_DEBUGGERS struct mDebugger* debugger = mDebuggerCreate(args->debuggerType, renderer->core); if (debugger) { #ifdef USE_EDITLINE @@ -179,6 +180,7 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) { mDebuggerAttach(debugger, renderer->core); mDebuggerEnter(debugger, DEBUGGER_ENTER_MANUAL, NULL); } +#endif if (args->patch) { struct VFile* patch = VFileOpen(args->patch, O_RDONLY); diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 78db5134f..3da4c2a78 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -398,11 +398,13 @@ static void _mSDLHandleKeypress(struct mCoreThread* context, struct mSDLPlayer* } if (event->type == SDL_KEYDOWN) { switch (event->keysym.sym) { +#ifdef USE_DEBUGGERS case SDLK_F11: if (context->core->debugger) { mDebuggerEnter(context->core->debugger, DEBUGGER_ENTER_MANUAL, NULL); } return; +#endif #ifdef USE_PNG case SDLK_F12: mCoreTakeScreenshot(context->core);