GB Debugger: Expose platform info in CLI
Vicki Pfau vi@endrift.com
Mon, 04 Mar 2019 18:30:36 -0800
8 files changed,
93 insertions(+),
36 deletions(-)
M
CHANGES
→
CHANGES
@@ -4,6 +4,7 @@ - Improved logging configuration
- One-Player BattleChip/Progress/Beast Link Gate support - Add Game Boy Color palettes for original Game Boy games - Debugger: Add unary operators and memory dereferencing + - GB: Expose platform information to CLI debugger Emulation fixes: - GBA: All IRQs have 7 cycle delay (fixes mgba.io/i/539, mgba.io/i/1208) - GBA: Reset now reloads multiboot ROMs
M
CMakeLists.txt
→
CMakeLists.txt
@@ -747,6 +747,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/cli-debugger.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/debugger.c ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/memory-debugger.c ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/debugger/cli.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/debugger/debugger.c ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/debugger/symbols.c) list(APPEND TEST_SRC ${LR35902_TEST_SRC}
A
include/mgba/internal/gb/debugger/debugger.h
@@ -0,0 +1,20 @@
+/* Copyright (c) 2013-2019 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef GB_DEBUGGER_H +#define GB_DEBUGGER_H + +#include <mgba-util/common.h> + +CXX_GUARD_START + +struct GB; +struct mDebuggerPlatform; + +struct mDebuggerPlatform* GBDebuggerCreate(struct GB* gb); + +CXX_GUARD_END + +#endif
M
include/mgba/internal/lr35902/debugger/debugger.h
→
include/mgba/internal/lr35902/debugger/debugger.h
@@ -20,6 +20,7 @@ uint16_t end;
const char* name; }; +struct CLIDebuggerSystem; struct LR35902Debugger { struct mDebuggerPlatform d; struct LR35902Core* cpu;@@ -31,6 +32,8 @@
ssize_t nextId; const struct LR35902Segment* segments; + + void (*printStatus)(struct CLIDebuggerSystem*); }; struct mDebuggerPlatform* LR35902DebuggerPlatformCreate(void);
M
src/gb/core.c
→
src/gb/core.c
@@ -8,6 +8,7 @@
#include <mgba/core/core.h> #include <mgba/internal/debugger/symbols.h> #include <mgba/internal/gb/cheats.h> +#include <mgba/internal/gb/debugger/debugger.h> #include <mgba/internal/gb/debugger/symbols.h> #include <mgba/internal/gb/extra/cli.h> #include <mgba/internal/gb/io.h>@@ -35,20 +36,6 @@ { 0, "ch1", "Channel 1", "Square/Sweep" },
{ 1, "ch2", "Channel 2", "Square" }, { 2, "ch3", "Channel 3", "PCM" }, { 3, "ch4", "Channel 4", "Noise" }, -}; - -static const struct LR35902Segment _GBSegments[] = { - { .name = "ROM", .start = GB_BASE_CART_BANK1, .end = GB_BASE_VRAM }, - { .name = "RAM", .start = GB_BASE_EXTERNAL_RAM, .end = GB_BASE_WORKING_RAM_BANK0 }, - { 0 } -}; - -static const struct LR35902Segment _GBCSegments[] = { - { .name = "ROM", .start = GB_BASE_CART_BANK1, .end = GB_BASE_VRAM }, - { .name = "RAM", .start = GB_BASE_EXTERNAL_RAM, .end = GB_BASE_WORKING_RAM_BANK0 }, - { .name = "WRAM", .start = GB_BASE_WORKING_RAM_BANK1, .end = 0xE000 }, - { .name = "VRAM", .start = GB_BASE_VRAM, .end = GB_BASE_EXTERNAL_RAM }, - { 0 } }; static const struct mCoreMemoryBlock _GBMemoryBlocks[] = {@@ -692,12 +679,7 @@ static struct mDebuggerPlatform* _GBCoreDebuggerPlatform(struct mCore* core) {
struct GBCore* gbcore = (struct GBCore*) core; struct GB* gb = core->board; if (!gbcore->debuggerPlatform) { - struct LR35902Debugger* platform = (struct LR35902Debugger*) LR35902DebuggerPlatformCreate(); - if (gb->model >= GB_MODEL_CGB) { - platform->segments = _GBCSegments; - } else { - platform->segments = _GBSegments; - } + struct LR35902Debugger* platform = (struct LR35902Debugger*) GBDebuggerCreate(gb); gbcore->debuggerPlatform = &platform->d; } return gbcore->debuggerPlatform;
A
src/gb/debugger/debugger.c
@@ -0,0 +1,46 @@
+/* Copyright (c) 2013-2019 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include <mgba/internal/gb/debugger/debugger.h> + + #include <mgba/core/core.h> + #include <mgba/internal/debugger/cli-debugger.h> + #include <mgba/internal/gb/gb.h> + #include <mgba/internal/gb/io.h> + #include <mgba/internal/gb/memory.h> + #include <mgba/internal/lr35902/debugger/debugger.h> + +static const struct LR35902Segment _GBSegments[] = { + { .name = "ROM", .start = GB_BASE_CART_BANK1, .end = GB_BASE_VRAM }, + { .name = "RAM", .start = GB_BASE_EXTERNAL_RAM, .end = GB_BASE_WORKING_RAM_BANK0 }, + { 0 } +}; + +static const struct LR35902Segment _GBCSegments[] = { + { .name = "ROM", .start = GB_BASE_CART_BANK1, .end = GB_BASE_VRAM }, + { .name = "RAM", .start = GB_BASE_EXTERNAL_RAM, .end = GB_BASE_WORKING_RAM_BANK0 }, + { .name = "WRAM", .start = GB_BASE_WORKING_RAM_BANK1, .end = 0xE000 }, + { .name = "VRAM", .start = GB_BASE_VRAM, .end = GB_BASE_EXTERNAL_RAM }, + { 0 } +}; + +static void _printStatus(struct CLIDebuggerSystem* debugger) { + struct CLIDebuggerBackend* be = debugger->p->backend; + struct GB* gb = debugger->p->d.core->board; + be->printf(be, "IE: %02X IF: %02X IME: %i\n", gb->memory.ie, gb->memory.io[REG_IF], gb->memory.ime); + be->printf(be, "LCDC: %02X STAT: %02X LY: %02X\n", gb->memory.io[REG_LCDC], gb->memory.io[REG_STAT] | 0x80, gb->memory.io[REG_LY]); + be->printf(be, "Next video mode: %i\n", mTimingUntil(&gb->timing, &gb->video.modeEvent) / 4); +} + +struct mDebuggerPlatform* GBDebuggerCreate(struct GB* gb) { + struct LR35902Debugger* platform = (struct LR35902Debugger*) LR35902DebuggerPlatformCreate(); + if (gb->model >= GB_MODEL_CGB) { + platform->segments = _GBCSegments; + } else { + platform->segments = _GBSegments; + } + platform->printStatus = _printStatus; + return &platform->d; +}
M
src/lr35902/debugger/cli-debugger.c
→
src/lr35902/debugger/cli-debugger.c
@@ -87,6 +87,7 @@ be->printf(be, "B: %02X C: %02X (BC: %04X)\n", cpu->b, cpu->c, cpu->bc);
be->printf(be, "D: %02X E: %02X (DE: %04X)\n", cpu->d, cpu->e, cpu->de); be->printf(be, "H: %02X L: %02X (HL: %04X)\n", cpu->h, cpu->l, cpu->hl); be->printf(be, "PC: %04X SP: %04X\n", cpu->pc, cpu->sp); + _printFlags(be, cpu->f); struct LR35902Debugger* platDebugger = (struct LR35902Debugger*) debugger->p->d.platform; size_t i;@@ -96,7 +97,9 @@ }
if (i) { be->printf(be, "\n"); } - _printFlags(be, cpu->f); + if (platDebugger->printStatus) { + platDebugger->printStatus(debugger); + } _printLine(debugger->p, cpu->pc, cpu->memory.currentSegment(cpu, cpu->pc)); }
M
src/lr35902/debugger/debugger.c
→
src/lr35902/debugger/debugger.c
@@ -75,21 +75,22 @@ static bool LR35902DebuggerGetRegister(struct mDebuggerPlatform*, const char* name, int32_t* value);
static bool LR35902DebuggerSetRegister(struct mDebuggerPlatform*, const char* name, int32_t value); struct mDebuggerPlatform* LR35902DebuggerPlatformCreate(void) { - struct mDebuggerPlatform* platform = (struct mDebuggerPlatform*) malloc(sizeof(struct LR35902Debugger)); - platform->entered = LR35902DebuggerEnter; - platform->init = LR35902DebuggerInit; - platform->deinit = LR35902DebuggerDeinit; - platform->setBreakpoint = LR35902DebuggerSetBreakpoint; - platform->listBreakpoints = LR35902DebuggerListBreakpoints; - platform->clearBreakpoint = LR35902DebuggerClearBreakpoint; - platform->setWatchpoint = LR35902DebuggerSetWatchpoint; - platform->listWatchpoints = LR35902DebuggerListWatchpoints; - platform->checkBreakpoints = LR35902DebuggerCheckBreakpoints; - platform->hasBreakpoints = LR35902DebuggerHasBreakpoints; - platform->trace = LR35902DebuggerTrace; - platform->getRegister = LR35902DebuggerGetRegister; - platform->setRegister = LR35902DebuggerSetRegister; - return platform; + struct LR35902Debugger* platform = malloc(sizeof(struct LR35902Debugger)); + platform->d.entered = LR35902DebuggerEnter; + platform->d.init = LR35902DebuggerInit; + platform->d.deinit = LR35902DebuggerDeinit; + platform->d.setBreakpoint = LR35902DebuggerSetBreakpoint; + platform->d.listBreakpoints = LR35902DebuggerListBreakpoints; + platform->d.clearBreakpoint = LR35902DebuggerClearBreakpoint; + platform->d.setWatchpoint = LR35902DebuggerSetWatchpoint; + platform->d.listWatchpoints = LR35902DebuggerListWatchpoints; + platform->d.checkBreakpoints = LR35902DebuggerCheckBreakpoints; + platform->d.hasBreakpoints = LR35902DebuggerHasBreakpoints; + platform->d.trace = LR35902DebuggerTrace; + platform->d.getRegister = LR35902DebuggerGetRegister; + platform->d.setRegister = LR35902DebuggerSetRegister; + platform->printStatus = NULL; + return &platform->d; } void LR35902DebuggerInit(void* cpu, struct mDebuggerPlatform* platform) {