Debugger: Make building with debugging aspects optional

This commit is contained in:
Jeffrey Pfau 2016-10-26 23:28:25 -07:00
parent 5f1011d474
commit 5b80b8e4c7
18 changed files with 81 additions and 24 deletions

View File

@ -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:

View File

@ -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}")

View File

@ -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*);

View File

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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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];

View File

@ -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)

View File

@ -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"

View File

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

View File

@ -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<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;

View File

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

View File

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