From 6eadd35ee6b0670b0bc4e348df5b5edde5707fea Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 23 Dec 2016 15:40:24 -0800 Subject: [PATCH] Debugger: Add functions for read- or write-only watchpoints --- CHANGES | 1 + src/debugger/cli-debugger.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 7afe57efa..e4a87bdf6 100644 --- a/CHANGES +++ b/CHANGES @@ -61,6 +61,7 @@ Misc: - GB Audio: Simplify envelope code - GB Audio: Improve initial envelope samples - GB Audio: Initialize wave RAM to GBC values + - Debugger: Add functions for read- or write-only watchpoints 0.5.1: (2016-10-05) Bugfixes: diff --git a/src/debugger/cli-debugger.c b/src/debugger/cli-debugger.c index 011b90508..8f5a7d6b6 100644 --- a/src/debugger/cli-debugger.c +++ b/src/debugger/cli-debugger.c @@ -40,6 +40,8 @@ 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 _setReadWatchpoint(struct CLIDebugger*, struct CLIDebugVector*); +static void _setWriteWatchpoint(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*); @@ -81,6 +83,8 @@ static struct CLIDebuggerCommandSummary _debuggerCommands[] = { { "w/2", _writeHalfword, CLIDVParse, "Write a halfword at a specified offset" }, { "w/4", _writeWord, CLIDVParse, "Write a word at a specified offset" }, { "watch", _setWatchpoint, CLIDVParse, "Set a watchpoint" }, + { "watch/r", _setReadWatchpoint, CLIDVParse, "Set a read watchpoint" }, + { "watch/w", _setWriteWatchpoint, CLIDVParse, "Set a write watchpoint" }, { "x/1", _dumpByte, CLIDVParse, "Examine bytes at a specified offset" }, { "x/2", _dumpHalfword, CLIDVParse, "Examine halfwords at a specified offset" }, { "x/4", _dumpWord, CLIDVParse, "Examine words at a specified offset" }, @@ -376,7 +380,33 @@ static void _setWatchpoint(struct CLIDebugger* debugger, struct CLIDebugVector* return; } uint32_t address = dv->intValue; - debugger->d.platform->setWatchpoint(debugger->d.platform, address, WATCHPOINT_RW); // TODO: ro/wo + debugger->d.platform->setWatchpoint(debugger->d.platform, address, WATCHPOINT_RW); +} + +static void _setReadWatchpoint(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { + if (!dv || dv->type != CLIDV_INT_TYPE) { + debugger->backend->printf(debugger->backend, "%s\n", ERROR_MISSING_ARGS); + return; + } + if (!debugger->d.platform->setWatchpoint) { + debugger->backend->printf(debugger->backend, "Watchpoints are not supported by this platform.\n"); + return; + } + uint32_t address = dv->intValue; + debugger->d.platform->setWatchpoint(debugger->d.platform, address, WATCHPOINT_READ); +} + +static void _setWriteWatchpoint(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { + if (!dv || dv->type != CLIDV_INT_TYPE) { + debugger->backend->printf(debugger->backend, "%s\n", ERROR_MISSING_ARGS); + return; + } + if (!debugger->d.platform->setWatchpoint) { + debugger->backend->printf(debugger->backend, "Watchpoints are not supported by this platform.\n"); + return; + } + uint32_t address = dv->intValue; + debugger->d.platform->setWatchpoint(debugger->d.platform, address, WATCHPOINT_WRITE); } static void _clearBreakpoint(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {