- (*watchpoint_p)->set = 0;
- (*watchpoint_p)->next = NULL;
-
- DEBUG("added %s watchpoint at 0x%8.8x of length 0x%8.8x", watchpoint_rw_strings[rw], address, length);
-
+ (*watchpoint_p)->unique_id = bpwp_unique_id++;
+
+ retval = target_add_watchpoint(target, *watchpoint_p);
+ switch (retval) {
+ case ERROR_OK:
+ break;
+ case ERROR_TARGET_RESOURCE_NOT_AVAILABLE:
+ reason = "resource not available";
+ goto bye;
+ case ERROR_TARGET_NOT_HALTED:
+ reason = "target running";
+ goto bye;
+ default:
+ reason = "unrecognized error";
+bye:
+ LOG_ERROR("can't add %s watchpoint at 0x%8.8" PRIx32 ", %s",
+ watchpoint_rw_strings[(*watchpoint_p)->rw],
+ address, reason);
+ free (*watchpoint_p);
+ *watchpoint_p = NULL;
+ return retval;
+ }
+
+ LOG_DEBUG("added %s watchpoint at 0x%8.8" PRIx32 " of length 0x%8.8x (WPID: %d)",
+ watchpoint_rw_strings[(*watchpoint_p)->rw],
+ (*watchpoint_p)->address,
+ (*watchpoint_p)->length,
+ (*watchpoint_p)->unique_id );
+