GB Debugger: Expose platform info in CLI

This commit is contained in:
Vicki Pfau 2019-03-04 18:30:36 -08:00
parent d6ac0dc6f5
commit b3687bfbe9
8 changed files with 93 additions and 36 deletions

View File

@ -4,6 +4,7 @@ Features:
- 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

View File

@ -747,6 +747,7 @@ if(M_CORE_GB)
${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}

View File

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

View File

@ -20,6 +20,7 @@ struct LR35902Segment {
const char* name;
};
struct CLIDebuggerSystem;
struct LR35902Debugger {
struct mDebuggerPlatform d;
struct LR35902Core* cpu;
@ -31,6 +32,8 @@ struct LR35902Debugger {
ssize_t nextId;
const struct LR35902Segment* segments;
void (*printStatus)(struct CLIDebuggerSystem*);
};
struct mDebuggerPlatform* LR35902DebuggerPlatformCreate(void);

View File

@ -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>
@ -37,20 +38,6 @@ static const struct mCoreChannelInfo _GBAudioChannels[] = {
{ 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[] = {
{ -1, "mem", "All", "All", 0, 0x10000, 0x10000, mCORE_MEMORY_VIRTUAL },
{ GB_REGION_CART_BANK0, "cart0", "ROM Bank", "Game Pak (32kiB)", GB_BASE_CART_BANK0, GB_SIZE_CART_BANK0 * 2, 0x800000, mCORE_MEMORY_READ | mCORE_MEMORY_MAPPED, 511 },
@ -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;

View File

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

View File

@ -87,6 +87,7 @@ static void _printStatus(struct CLIDebuggerSystem* debugger) {
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 @@ static void _printStatus(struct CLIDebuggerSystem* debugger) {
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));
}

View File

@ -75,21 +75,22 @@ static bool LR35902DebuggerGetRegister(struct mDebuggerPlatform*, const char* na
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) {