Debugger: Add CLI functions for writing to memory

This commit is contained in:
Jeffrey Pfau 2014-12-26 01:40:50 -08:00
parent 89c7146878
commit 747fcca3b2
2 changed files with 58 additions and 0 deletions

View File

@ -9,6 +9,7 @@ Features:
- Add option to skip BIOS start screen
- List of recently opened games
- Support for games using the Solar Sensor
- Debugger: Add CLI functions for writing to memory
Bugfixes:
- Qt: Fix issue with set frame sizes being the wrong height
- Qt: Fix emulator crashing when full screen if a game is not running

View File

@ -14,6 +14,7 @@
#endif
static const char* ERROR_MISSING_ARGS = "Arguments missing"; // TODO: share
static const char* ERROR_OVERFLOW = "Arguments overflow";
static struct CLIDebugger* _activeDebugger;
@ -36,6 +37,9 @@ static void _readWord(struct CLIDebugger*, struct CLIDebugVector*);
static void _setBreakpoint(struct CLIDebugger*, struct CLIDebugVector*);
static void _clearBreakpoint(struct CLIDebugger*, struct CLIDebugVector*);
static void _setWatchpoint(struct CLIDebugger*, struct CLIDebugVector*);
static void _writeByte(struct CLIDebugger*, struct CLIDebugVector*);
static void _writeHalfword(struct CLIDebugger*, struct CLIDebugVector*);
static void _writeWord(struct CLIDebugger*, struct CLIDebugVector*);
static void _breakIntoDefault(int signal);
static void _disassembleMode(struct CLIDebugger*, struct CLIDebugVector*, enum ExecutionMode mode);
@ -78,6 +82,9 @@ static struct CLIDebuggerCommandSummary _debuggerCommands[] = {
{ "status", _printStatus, 0, "Print the current status" },
{ "w", _setWatchpoint, CLIDVParse, "Set a watchpoint" },
{ "watch", _setWatchpoint, CLIDVParse, "Set a watchpoint" },
{ "wb", _writeByte, CLIDVParse, "Write a byte at a specified offset" },
{ "wh", _writeHalfword, CLIDVParse, "Write a halfword at a specified offset" },
{ "ww", _writeWord, CLIDVParse, "Write a word at a specified offset" },
{ "x", _breakInto, 0, "Break into attached debugger (for developers)" },
{ 0, 0, 0, 0 }
};
@ -310,6 +317,56 @@ static void _readWord(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
printf(" 0x%08X\n", value);
}
static void _writeByte(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
if (!dv || dv->type != CLIDV_INT_TYPE) {
printf("%s\n", ERROR_MISSING_ARGS);
return;
}
if (!dv->next || dv->next->type != CLIDV_INT_TYPE) {
printf("%s\n", ERROR_MISSING_ARGS);
return;
}
uint32_t address = dv->intValue;
uint32_t value = dv->next->intValue;
if (value > 0xFF) {
printf("%s\n", ERROR_OVERFLOW);
return;
}
debugger->d.cpu->memory.store8(debugger->d.cpu, address, value, 0);
}
static void _writeHalfword(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
if (!dv || dv->type != CLIDV_INT_TYPE) {
printf("%s\n", ERROR_MISSING_ARGS);
return;
}
if (!dv->next || dv->next->type != CLIDV_INT_TYPE) {
printf("%s\n", ERROR_MISSING_ARGS);
return;
}
uint32_t address = dv->intValue;
uint32_t value = dv->next->intValue;
if (value > 0xFFFF) {
printf("%s\n", ERROR_OVERFLOW);
return;
}
debugger->d.cpu->memory.store16(debugger->d.cpu, address, value, 0);
}
static void _writeWord(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
if (!dv || dv->type != CLIDV_INT_TYPE) {
printf("%s\n", ERROR_MISSING_ARGS);
return;
}
if (!dv->next || dv->next->type != CLIDV_INT_TYPE) {
printf("%s\n", ERROR_MISSING_ARGS);
return;
}
uint32_t address = dv->intValue;
uint32_t value = dv->next->intValue;
debugger->d.cpu->memory.store32(debugger->d.cpu, address, value, 0);
}
static void _setBreakpoint(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
if (!dv || dv->type != CLIDV_INT_TYPE) {
printf("%s\n", ERROR_MISSING_ARGS);