+ retval = breakpoint_remove_internal(target, address);
+
+ if (retval != ERROR_BREAKPOINT_NOT_FOUND) {
+ num_found_breakpoints++;
+
+ if (retval != ERROR_OK)
+ LOG_TARGET_ERROR(target, "failed to remove breakpoint at address " TARGET_ADDR_FMT, address);
+ }
+ }
+
+ if (num_found_breakpoints == 0) {
+ LOG_TARGET_ERROR(target, "no breakpoint at address " TARGET_ADDR_FMT " found", address);
+ return ERROR_BREAKPOINT_NOT_FOUND;
+ }
+
+ return retval;
+}
+
+static int watchpoint_free(struct target *target, struct watchpoint *watchpoint_to_remove)
+{
+ struct watchpoint *watchpoint = target->watchpoints;
+ struct watchpoint **watchpoint_p = &target->watchpoints;
+ int retval;
+
+ while (watchpoint) {
+ if (watchpoint == watchpoint_to_remove)
+ break;
+ watchpoint_p = &watchpoint->next;
+ watchpoint = watchpoint->next;
+ }
+
+ if (!watchpoint)
+ return ERROR_OK;
+ retval = target_remove_watchpoint(target, watchpoint);
+ if (retval != ERROR_OK) {
+ LOG_TARGET_ERROR(target, "could not remove watchpoint #%d on this target",
+ watchpoint->number);
+ return retval;
+ }
+
+ LOG_TARGET_DEBUG(target, "free WPID: %d --> %d", watchpoint->unique_id, retval);
+ (*watchpoint_p) = watchpoint->next;
+ free(watchpoint);
+
+ return ERROR_OK;
+}
+
+static int watchpoint_remove_all_internal(struct target *target)
+{
+ struct watchpoint *watchpoint = target->watchpoints;
+ int retval = ERROR_OK;
+
+ while (watchpoint) {
+ struct watchpoint *tmp = watchpoint;
+ watchpoint = watchpoint->next;
+ int status = watchpoint_free(target, tmp);
+ if (status != ERROR_OK)
+ retval = status;