all repos — mgba @ 5b80b8e4c748e1b3128f645763f141c993827acf

mGBA Game Boy Advance Emulator

Debugger: Make building with debugging aspects optional
Jeffrey Pfau jeffrey@endrift.com
Wed, 26 Oct 2016 23:28:25 -0700
commit

5b80b8e4c748e1b3128f645763f141c993827acf

parent

5f1011d4744195d40685b94f78df0ad0e2158974

M CHANGESCHANGES

@@ -32,6 +32,7 @@ - GB, GBA: Prevent loading null ROMs

- 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:
M CMakeLists.txtCMakeLists.txt

@@ -6,6 +6,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-missing-field-initializers -std=c99")

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 @@ set(OPENGLES2_LIBRARY ${EPOXY_LIBRARIES})

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 @@ list(APPEND CORE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/audio.c)

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 @@ # Binaries

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 @@ message(STATUS "Platforms:")

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}")
M src/core/core.hsrc/core/core.h

@@ -118,11 +118,13 @@ void (*rawWrite8)(struct mCore*, uint32_t address, int segment, uint8_t);

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*);
M src/core/thread.csrc/core/thread.c

@@ -162,13 +162,16 @@ threadContext->resetCallback(threadContext);

} 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); }
M src/gb/core.csrc/gb/core.c

@@ -7,7 +7,7 @@ #include "core.h"

#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 @@ GBPatch8(cpu, address + 2, value >> 16, NULL, 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 @@ }

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 @@ core->rawRead32 = _GBCoreRawRead32;

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;
M src/gb/gb.csrc/gb/gb.c

@@ -600,6 +600,7 @@ gb->doubleSpeed ^= 1;

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 @@ .opcode = 0x1000 | cpu->bus

}; 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 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 @@ .opcode = cpu->bus

}; mDebuggerEnter((struct mDebugger*) cpu->components[CPU_COMPONENT_DEBUGGER], DEBUGGER_ENTER_ILLEGAL_OP, &info); } +#endif // Hang forever gb->memory.ime = 0; --cpu->pc;
M src/gba/core.csrc/gba/core.c

@@ -439,6 +439,7 @@ struct ARMCore* cpu = core->cpu;

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 @@ core->rawRead32 = _GBACoreRawRead32;

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;
M src/gba/gba.csrc/gba/gba.c

@@ -791,6 +791,7 @@ }

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 @@ .opcode = 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 @@ if (!gba->yankedRomSize) {

// 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 @@ if (immediate >= CPU_COMPONENT_MAX) {

return; } switch (immediate) { +#ifdef USE_DEBUGGERS case CPU_COMPONENT_DEBUGGER: if (gba->debugger) { struct mDebuggerEntryInfo info = {

@@ -834,6 +840,7 @@ };

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];
M src/platform/qt/CMakeLists.txtsrc/platform/qt/CMakeLists.txt

@@ -75,9 +75,6 @@ AudioProcessor.cpp

CheatsModel.cpp CheatsView.cpp ConfigController.cpp - DebuggerController.cpp - DebuggerREPL.cpp - DebuggerREPLController.cpp Display.cpp DisplayGL.cpp DisplayQt.cpp

@@ -181,8 +178,15 @@ set(BUILD_QT OFF PARENT_SCOPE)

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)
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -26,8 +26,8 @@ #ifdef M_CORE_GBA

#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"
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -72,7 +72,9 @@ #endif

#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 @@ openView(window);

} #endif +#ifdef USE_DEBUGGERS void Window::replOpen() { if (!m_repl) { m_repl = new DebuggerREPLController(m_controller, this);

@@ -523,6 +526,7 @@ }

DebuggerREPL* window = new DebuggerREPL(m_repl); openView(window); } +#endif void Window::keyPressEvent(QKeyEvent* event) { if (event->isAutoRepeat()) {

@@ -1348,9 +1352,11 @@ "settings");

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);
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -81,7 +81,9 @@

void openSettingsWindow(); void openAboutScreen(); +#ifdef USE_DEBUGGERS void replOpen(); +#endif #ifdef USE_FFMPEG void openVideoWindow();

@@ -159,7 +161,9 @@ #endif

QMap<int, QAction*> m_frameSizes; LogController m_log; LogView* m_logView; +#ifdef USE_DEBUGGERS DebuggerREPLController* m_repl; +#endif LoadSaveState* m_stateWindow; WindowBackground* m_screenWidget; QPixmap m_logo;
M src/platform/sdl/main.csrc/platform/sdl/main.c

@@ -168,6 +168,7 @@ if (!mCoreLoadFile(renderer->core, args->fname)) {

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 @@ #endif

mDebuggerAttach(debugger, renderer->core); mDebuggerEnter(debugger, DEBUGGER_ENTER_MANUAL, NULL); } +#endif if (args->patch) { struct VFile* patch = VFileOpen(args->patch, O_RDONLY);
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -398,11 +398,13 @@ mCoreThreadSetRewinding(context, event->type == SDL_KEYDOWN);

} 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);