all repos — mgba @ a6fc606a2d2a5471c1998bde0c4d39a380e2709b

mGBA Game Boy Advance Emulator

Debugger: Separate aliases from main commands
Vicki Pfau vi@endrift.com
Sat, 21 Dec 2019 13:52:16 -0800
commit

a6fc606a2d2a5471c1998bde0c4d39a380e2709b

parent

84000ed7fc093021721021735f79f7074bcf54c5

M CHANGESCHANGES

@@ -108,6 +108,7 @@ - Qt: Fix sprite view using wrong base address (fixes mgba.io/i/1603)

Misc: - GB Memory: Support manual SRAM editing (fixes mgba.io/i/1580) - SDL: Use controller GUID instead of name + - Debugger: Separate aliases from main commands 0.8 beta 1: (2019-10-20) - Initial beta for 0.8
M include/mgba/internal/debugger/cli-debugger.hinclude/mgba/internal/debugger/cli-debugger.h

@@ -42,6 +42,11 @@ const char* format;

const char* summary; }; +struct CLIDebuggerCommandAlias { + const char* name; + const char* original; +}; + struct CLIDebuggerSystem { struct CLIDebugger* p;

@@ -53,8 +58,10 @@ void (*disassemble)(struct CLIDebuggerSystem*, struct CLIDebugVector* dv);

void (*printStatus)(struct CLIDebuggerSystem*); struct CLIDebuggerCommandSummary* commands; + struct CLIDebuggerCommandAlias* commandAliases; const char* name; struct CLIDebuggerCommandSummary* platformCommands; + struct CLIDebuggerCommandAlias* platformCommandAliases; const char* platformName; };
M src/arm/debugger/cli-debugger.csrc/arm/debugger/cli-debugger.c

@@ -22,17 +22,21 @@ static void _disassembleMode(struct CLIDebugger*, struct CLIDebugVector*, enum ExecutionMode mode);

static uint32_t _printLine(struct CLIDebugger* debugger, uint32_t address, enum ExecutionMode mode); static struct CLIDebuggerCommandSummary _armCommands[] = { - { "b/a", _setBreakpointARM, "I", "Set a software breakpoint as ARM" }, - { "b/t", _setBreakpointThumb, "I", "Set a software breakpoint as Thumb" }, { "break/a", _setBreakpointARM, "I", "Set a software breakpoint as ARM" }, { "break/t", _setBreakpointThumb, "I", "Set a software breakpoint as Thumb" }, - { "dis/a", _disassembleArm, "Ii", "Disassemble instructions as ARM" }, - { "dis/t", _disassembleThumb, "Ii", "Disassemble instructions as Thumb" }, - { "disasm/a", _disassembleArm, "Ii", "Disassemble instructions as ARM" }, - { "disasm/t", _disassembleThumb, "Ii", "Disassemble instructions as Thumb" }, { "disassemble/a", _disassembleArm, "Ii", "Disassemble instructions as ARM" }, { "disassemble/t", _disassembleThumb, "Ii", "Disassemble instructions as Thumb" }, { 0, 0, 0, 0 } +}; + +static struct CLIDebuggerCommandAlias _armCommandAliases[] = { + { "b/a", "break/a" }, + { "b/t", "break/t" }, + { "dis/a", "disassemble/a" }, + { "dis/t", "disassemble/t" }, + { "disasm/a", "disassemble/a" }, + { "disasm/t", "disassemble/t" }, + { 0, 0 } }; static inline void _printPSR(struct CLIDebuggerBackend* be, union PSR psr) {

@@ -175,4 +179,5 @@ debugger->printStatus = _printStatus;

debugger->disassemble = _disassemble; debugger->platformName = "ARM"; debugger->platformCommands = _armCommands; + debugger->platformCommandAliases = _armCommandAliases; }
M src/debugger/cli-debugger.csrc/debugger/cli-debugger.c

@@ -71,32 +71,17 @@ static void _source(struct CLIDebugger*, struct CLIDebugVector*);

#endif static struct CLIDebuggerCommandSummary _debuggerCommands[] = { - { "b", _setBreakpoint, "Is", "Set a breakpoint" }, { "break", _setBreakpoint, "Is", "Set a breakpoint" }, - { "c", _continue, "", "Continue execution" }, { "continue", _continue, "", "Continue execution" }, - { "d", _clearBreakpoint, "I", "Delete a breakpoint or watchpoint" }, { "delete", _clearBreakpoint, "I", "Delete a breakpoint or watchpoint" }, - { "dis", _disassemble, "Ii", "Disassemble instructions" }, - { "disasm", _disassemble, "Ii", "Disassemble instructions" }, { "disassemble", _disassemble, "Ii", "Disassemble instructions" }, - { "h", _printHelp, "S", "Print help" }, { "help", _printHelp, "S", "Print help" }, - { "i", _printStatus, "", "Print the current status" }, - { "info", _printStatus, "", "Print the current status" }, - { "lb", _listBreakpoints, "", "List breakpoints" }, { "listb", _listBreakpoints, "", "List breakpoints" }, - { "lw", _listWatchpoints, "", "List watchpoints" }, { "listw", _listWatchpoints, "", "List watchpoints" }, - { "n", _next, "", "Execute next instruction" }, { "next", _next, "", "Execute next instruction" }, - { "p", _print, "S+", "Print a value" }, - { "p/t", _printBin, "S+", "Print a value as binary" }, - { "p/x", _printHex, "S+", "Print a value as hexadecimal" }, { "print", _print, "S+", "Print a value" }, { "print/t", _printBin, "S+", "Print a value as binary" }, { "print/x", _printHex, "S+", "Print a value as hexadecimal" }, - { "q", _quit, "", "Quit the emulator" }, { "quit", _quit, "", "Quit the emulator" }, { "reset", _reset, "", "Reset the emulation" }, { "r/1", _readByte, "I", "Read a byte from a specified offset" },

@@ -104,7 +89,6 @@ { "r/2", _readHalfword, "I", "Read a halfword from a specified offset" },

{ "r/4", _readWord, "I", "Read a word from a specified offset" }, { "status", _printStatus, "", "Print the current status" }, { "trace", _trace, "Is", "Trace a number of instructions" }, - { "w", _setReadWriteWatchpoint, "Is", "Set a watchpoint" }, { "w/1", _writeByte, "II", "Write a byte at a specified offset" }, { "w/2", _writeHalfword, "II", "Write a halfword at a specified offset" }, { "w/r", _writeRegister, "SI", "Write a register" },

@@ -123,6 +107,26 @@ #if !defined(NDEBUG) && !defined(_WIN32)

{ "!", _breakInto, "", "Break into attached debugger (for developers)" }, #endif { 0, 0, 0, 0 } +}; + +static struct CLIDebuggerCommandAlias _debuggerCommandAliases[] = { + { "b", "break" }, + { "c", "continue" }, + { "d", "delete" }, + { "dis", "disassemble" }, + { "disasm", "disassemble" }, + { "h", "help" }, + { "i", "status" }, + { "info", "status" }, + { "lb", "listb" }, + { "lw", "listw" }, + { "n", "next" }, + { "p", "print" }, + { "p/t", "print/t" }, + { "p/x", "print/x" }, + { "q", "quit" }, + { "w", "watch" }, + { 0, 0 } }; #if !defined(NDEBUG) && !defined(_WIN32)

@@ -232,42 +236,71 @@ }

debugger->backend->printf(debugger->backend, " 0x%08X\n", intValue); } +static void _printCommands(struct CLIDebugger* debugger, struct CLIDebuggerCommandSummary* commands, struct CLIDebuggerCommandAlias* aliases) { + int i; + for (i = 0; commands[i].name; ++i) { + debugger->backend->printf(debugger->backend, "%-15s %s\n", commands[i].name, commands[i].summary); + if (aliases) { + bool printedAlias = false; + int j; + for (j = 0; aliases[j].name; ++j) { + if (strcmp(aliases[j].original, commands[i].name) == 0) { + if (!printedAlias) { + debugger->backend->printf(debugger->backend, " Aliases:"); + printedAlias = true; + } + debugger->backend->printf(debugger->backend, " %s", aliases[j].name); + } + } + if (printedAlias) { + debugger->backend->printf(debugger->backend, "\n"); + } + } + } +} + +static void _printCommandSummary(struct CLIDebugger* debugger, const char* name, struct CLIDebuggerCommandSummary* commands, struct CLIDebuggerCommandAlias* aliases) { + int i; + for (i = 0; commands[i].name; ++i) { + if (strcmp(commands[i].name, name) == 0) { + debugger->backend->printf(debugger->backend, " %s\n", commands[i].summary); + if (aliases) { + bool printedAlias = false; + int j; + for (j = 0; aliases[j].name; ++j) { + if (strcmp(aliases[j].original, commands[i].name) == 0) { + if (!printedAlias) { + debugger->backend->printf(debugger->backend, " Aliases:"); + printedAlias = true; + } + debugger->backend->printf(debugger->backend, " %s", aliases[j].name); + } + } + if (printedAlias) { + debugger->backend->printf(debugger->backend, "\n"); + } + } + return; + } + } +} + static void _printHelp(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { UNUSED(dv); if (!dv) { debugger->backend->printf(debugger->backend, "Generic commands:\n"); - int i; - for (i = 0; _debuggerCommands[i].name; ++i) { - debugger->backend->printf(debugger->backend, "%-10s %s\n", _debuggerCommands[i].name, _debuggerCommands[i].summary); - } + _printCommands(debugger, _debuggerCommands, _debuggerCommandAliases); if (debugger->system) { - debugger->backend->printf(debugger->backend, "%s commands:\n", debugger->system->platformName); - for (i = 0; debugger->system->platformCommands[i].name; ++i) { - debugger->backend->printf(debugger->backend, "%-10s %s\n", debugger->system->platformCommands[i].name, debugger->system->platformCommands[i].summary); - } - debugger->backend->printf(debugger->backend, "%s commands:\n", debugger->system->name); - for (i = 0; debugger->system->commands[i].name; ++i) { - debugger->backend->printf(debugger->backend, "%-10s %s\n", debugger->system->commands[i].name, debugger->system->commands[i].summary); - } + debugger->backend->printf(debugger->backend, "\n%s commands:\n", debugger->system->platformName); + _printCommands(debugger, debugger->system->platformCommands, debugger->system->platformCommandAliases); + debugger->backend->printf(debugger->backend, "\n%s commands:\n", debugger->system->name); + _printCommands(debugger, debugger->system->commands, debugger->system->commandAliases); } } else { - int i; - for (i = 0; _debuggerCommands[i].name; ++i) { - if (strcmp(_debuggerCommands[i].name, dv->charValue) == 0) { - debugger->backend->printf(debugger->backend, " %s\n", _debuggerCommands[i].summary); - } - } + _printCommandSummary(debugger, dv->charValue, _debuggerCommands, _debuggerCommandAliases); if (debugger->system) { - for (i = 0; debugger->system->platformCommands[i].name; ++i) { - if (strcmp(debugger->system->platformCommands[i].name, dv->charValue) == 0) { - debugger->backend->printf(debugger->backend, " %s\n", debugger->system->platformCommands[i].summary); - } - } - for (i = 0; debugger->system->commands[i].name; ++i) { - if (strcmp(debugger->system->commands[i].name, dv->charValue) == 0) { - debugger->backend->printf(debugger->backend, " %s\n", debugger->system->commands[i].summary); - } - } + _printCommandSummary(debugger, dv->charValue, debugger->system->platformCommands, debugger->system->platformCommandAliases); + _printCommandSummary(debugger, dv->charValue, debugger->system->commands, debugger->system->commandAliases); } } }

@@ -784,11 +817,22 @@ }

return dv; } -static int _tryCommands(struct CLIDebugger* debugger, struct CLIDebuggerCommandSummary* commands, const char* command, size_t commandLen, const char* args, size_t argsLen) { +static int _tryCommands(struct CLIDebugger* debugger, struct CLIDebuggerCommandSummary* commands, struct CLIDebuggerCommandAlias* aliases, const char* command, size_t commandLen, const char* args, size_t argsLen) { struct CLIDebugVector* dv = NULL; struct CLIDebugVector* dvLast = NULL; int i; const char* name; + if (aliases) { + for (i = 0; (name = aliases[i].name); ++i) { + if (strlen(name) != commandLen) { + continue; + } + if (strncasecmp(name, command, commandLen) == 0) { + command = aliases[i].original; + commandLen = strlen(aliases[i].original); + } + } + } for (i = 0; (name = commands[i].name); ++i) { if (strlen(name) != commandLen) { continue;

@@ -885,11 +929,11 @@ const char* args = 0;

if (firstSpace) { args = firstSpace + 1; } - int result = _tryCommands(debugger, _debuggerCommands, line, cmdLength, args, count - cmdLength - 1); + int result = _tryCommands(debugger, _debuggerCommands, _debuggerCommandAliases, line, cmdLength, args, count - cmdLength - 1); if (result < 0 && debugger->system) { - result = _tryCommands(debugger, debugger->system->commands, line, cmdLength, args, count - cmdLength - 1); + result = _tryCommands(debugger, debugger->system->commands, debugger->system->commandAliases, line, cmdLength, args, count - cmdLength - 1); if (result < 0) { - result = _tryCommands(debugger, debugger->system->platformCommands, line, cmdLength, args, count - cmdLength - 1); + result = _tryCommands(debugger, debugger->system->platformCommands, debugger->system->platformCommandAliases, line, cmdLength, args, count - cmdLength - 1); } } if (result < 0) {
M src/gb/debugger/cli.csrc/gb/debugger/cli.c

@@ -36,6 +36,7 @@ debugger->d.custom = _GBCLIDebuggerCustom;

debugger->d.name = "Game Boy"; debugger->d.commands = _GBCLIDebuggerCommands; + debugger->d.commandAliases = NULL; debugger->core = core;
M src/gba/debugger/cli.csrc/gba/debugger/cli.c

@@ -35,6 +35,7 @@ debugger->d.custom = _GBACLIDebuggerCustom;

debugger->d.name = "Game Boy Advance"; debugger->d.commands = _GBACLIDebuggerCommands; + debugger->d.commandAliases = NULL; debugger->core = core;
M src/lr35902/debugger/cli-debugger.csrc/lr35902/debugger/cli-debugger.c

@@ -108,4 +108,5 @@ debugger->printStatus = _printStatus;

debugger->disassemble = _disassemble; debugger->platformName = "GB-Z80"; debugger->platformCommands = _lr35902Commands; + debugger->platformCommandAliases = NULL; }