From 98777e1ec3d1403c835869431ef92d4981340d6a Mon Sep 17 00:00:00 2001 From: Lars Rademacher Date: Tue, 31 Dec 2013 16:37:54 +0100 Subject: [PATCH] openocd: get activated watchpoint from openocd Decoding the current instruction sometimes failes, so we need to extract the currently activated watchpoint from the openocd internal list of watchpoints. If we have more than one watchpoint, we are in trouble. Change-Id: I14b172e4f933ca894cf66685c6d2ca8e573a3151 --- debuggers/openocd/openocd_wrapper.cc | 34 ++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/debuggers/openocd/openocd_wrapper.cc b/debuggers/openocd/openocd_wrapper.cc index d8781922..ef1f1ece 100644 --- a/debuggers/openocd/openocd_wrapper.cc +++ b/debuggers/openocd/openocd_wrapper.cc @@ -155,7 +155,7 @@ fail::Logger LOG("OpenOCD", false); static void update_timers(); static void freeze_timers(); static void unfreeze_timers(); -static struct watchpoint *getHaltingWatchpoint(); +static bool getHaltingWatchpoint(struct halt_condition *hc); static bool getCurrentMemAccess(struct halt_condition *access); static bool getMemAccess(uint32_t opcode, struct halt_condition *access); static uint32_t getCurrentPC(); @@ -514,7 +514,11 @@ int main(int argc, char *argv[]) { // ToDo: Replace with calls of every current memory access struct halt_condition halt; - if (!getCurrentMemAccess(&halt)) { +// if (!getCurrentMemAccess(&halt)) { +// LOG << "FATAL ERROR: Can't determine memory-access address of halt cause" << endl; +// exit(-1); +// } + if(!getHaltingWatchpoint(&halt)) { LOG << "FATAL ERROR: Can't determine memory-access address of halt cause" << endl; exit(-1); } @@ -1332,16 +1336,36 @@ static bool getCurrentMemAccess(struct halt_condition *access) * this function * Will be eliminated by disassembling and evaluating instruction */ -static struct watchpoint *getHaltingWatchpoint() +static bool getHaltingWatchpoint(struct halt_condition *hc) { struct watchpoint *watchpoint = target_a9->watchpoints; if (!watchpoint || watchpoint->next) { // Multiple watchpoints activated? No single answer possible - return NULL; + return false; } - return watchpoint; + + hc->address = watchpoint->address; + hc->addr_len = watchpoint->length; + switch (watchpoint->rw) { + case WPT_READ: + hc->type = HALT_TYPE_WP_READ; + break; + case WPT_WRITE: + hc->type = HALT_TYPE_WP_WRITE; + break; + case WPT_ACCESS: + hc->type = HALT_TYPE_WP_READWRITE; + break; + default: + LOG << "FATAL ERROR: Something went seriously wrong, here" << endl; + break; + } + + return true; } + + static uint32_t cc_overflow = 0; void freeze_cycle_counter()