flash/nor/efr32: fixed lockbits and user data
[fw/openocd] / src / target / breakpoints.c
index dc8f3c5730a38e37fa255a9ba003ba2100ef299b..dd901ef25ba2b5e27ca56a62e75bc070e28bed8f 100644 (file)
@@ -95,7 +95,9 @@ fail:
                        return retval;
        }
 
-       LOG_DEBUG("added %s breakpoint at " TARGET_ADDR_FMT " of length 0x%8.8x, (BPID: %" PRIu32 ")",
+       LOG_DEBUG("[%d] added %s breakpoint at " TARGET_ADDR_FMT
+                       " of length 0x%8.8x, (BPID: %" PRIu32 ")",
+               target->coreid,
                breakpoint_type_strings[(*breakpoint_p)->type],
                (*breakpoint_p)->address, (*breakpoint_p)->length,
                (*breakpoint_p)->unique_id);
@@ -222,7 +224,7 @@ int breakpoint_add(struct target *target,
                if (type == BKPT_SOFT)
                        return breakpoint_add_internal(head->target, address, length, type);
 
-               while (head != (struct target_list *)NULL) {
+               while (head) {
                        curr = head->target;
                        retval = breakpoint_add_internal(curr, address, length, type);
                        if (retval != ERROR_OK)
@@ -245,7 +247,7 @@ int context_breakpoint_add(struct target *target,
                struct target_list *head;
                struct target *curr;
                head = target->head;
-               while (head != (struct target_list *)NULL) {
+               while (head) {
                        curr = head->target;
                        retval = context_breakpoint_add_internal(curr, asid, length, type);
                        if (retval != ERROR_OK)
@@ -269,7 +271,7 @@ int hybrid_breakpoint_add(struct target *target,
                struct target_list *head;
                struct target *curr;
                head = target->head;
-               while (head != (struct target_list *)NULL) {
+               while (head) {
                        curr = head->target;
                        retval = hybrid_breakpoint_add_internal(curr, address, asid, length, type);
                        if (retval != ERROR_OK)
@@ -345,7 +347,7 @@ void breakpoint_remove(struct target *target, target_addr_t address)
                struct target_list *head;
                struct target *curr;
                head = target->head;
-               while (head != (struct target_list *)NULL) {
+               while (head) {
                        curr = head->target;
                        num_breakpoints += breakpoint_remove_internal(curr, address);
                        head = head->next;
@@ -363,7 +365,7 @@ void breakpoint_remove_all(struct target *target)
                struct target_list *head;
                struct target *curr;
                head = target->head;
-               while (head != (struct target_list *)NULL) {
+               while (head) {
                        curr = head->target;
                        breakpoint_remove_all_internal(curr);
                        head = head->next;
@@ -377,7 +379,7 @@ static void breakpoint_clear_target_internal(struct target *target)
 {
        LOG_DEBUG("Delete all breakpoints for target: %s",
                target_name(target));
-       while (target->breakpoints != NULL)
+       while (target->breakpoints)
                breakpoint_free(target, target->breakpoints);
 }
 
@@ -387,7 +389,7 @@ void breakpoint_clear_target(struct target *target)
                struct target_list *head;
                struct target *curr;
                head = target->head;
-               while (head != (struct target_list *)NULL) {
+               while (head) {
                        curr = head->target;
                        breakpoint_clear_target_internal(curr);
                        head = head->next;
@@ -410,8 +412,8 @@ struct breakpoint *breakpoint_find(struct target *target, target_addr_t address)
        return NULL;
 }
 
-int watchpoint_add(struct target *target, target_addr_t address, uint32_t length,
-       enum watchpoint_rw rw, uint32_t value, uint32_t mask)
+int watchpoint_add_internal(struct target *target, target_addr_t address,
+               uint32_t length, enum watchpoint_rw rw, uint32_t value, uint32_t mask)
 {
        struct watchpoint *watchpoint = target->watchpoints;
        struct watchpoint **watchpoint_p = &target->watchpoints;
@@ -466,8 +468,9 @@ bye:
                        return retval;
        }
 
-       LOG_DEBUG("added %s watchpoint at " TARGET_ADDR_FMT
-               " of length 0x%8.8" PRIx32 " (WPID: %d)",
+       LOG_DEBUG("[%d] added %s watchpoint at " TARGET_ADDR_FMT
+                       " of length 0x%8.8" PRIx32 " (WPID: %d)",
+               target->coreid,
                watchpoint_rw_strings[(*watchpoint_p)->rw],
                (*watchpoint_p)->address,
                (*watchpoint_p)->length,
@@ -476,6 +479,30 @@ bye:
        return ERROR_OK;
 }
 
+int watchpoint_add(struct target *target, target_addr_t address,
+               uint32_t length, enum watchpoint_rw rw, uint32_t value, uint32_t mask)
+{
+       int retval = ERROR_OK;
+       if (target->smp) {
+               struct target_list *head;
+               struct target *curr;
+               head = target->head;
+
+               while (head != (struct target_list *)NULL) {
+                       curr = head->target;
+                       retval = watchpoint_add_internal(curr, address, length, rw, value,
+                                       mask);
+                       if (retval != ERROR_OK)
+                               return retval;
+                       head = head->next;
+               }
+               return retval;
+       } else {
+               return watchpoint_add_internal(target, address, length, rw, value,
+                               mask);
+       }
+}
+
 static void watchpoint_free(struct target *target, struct watchpoint *watchpoint_to_remove)
 {
        struct watchpoint *watchpoint = target->watchpoints;
@@ -497,7 +524,7 @@ static void watchpoint_free(struct target *target, struct watchpoint *watchpoint
        free(watchpoint);
 }
 
-void watchpoint_remove(struct target *target, target_addr_t address)
+int watchpoint_remove_internal(struct target *target, target_addr_t address)
 {
        struct watchpoint *watchpoint = target->watchpoints;
 
@@ -507,17 +534,40 @@ void watchpoint_remove(struct target *target, target_addr_t address)
                watchpoint = watchpoint->next;
        }
 
-       if (watchpoint)
+       if (watchpoint) {
                watchpoint_free(target, watchpoint);
-       else
-               LOG_ERROR("no watchpoint at address " TARGET_ADDR_FMT " found", address);
+               return 1;
+       } else {
+               if (!target->smp)
+                       LOG_ERROR("no watchpoint at address " TARGET_ADDR_FMT " found", address);
+               return 0;
+       }
+}
+
+void watchpoint_remove(struct target *target, target_addr_t address)
+{
+       if (target->smp) {
+               unsigned int num_watchpoints = 0;
+               struct target_list *head;
+               struct target *curr;
+               head = target->head;
+               while (head) {
+                       curr = head->target;
+                       num_watchpoints += watchpoint_remove_internal(curr, address);
+                       head = head->next;
+               }
+               if (num_watchpoints == 0)
+                       LOG_ERROR("no watchpoint at address " TARGET_ADDR_FMT " num_watchpoints", address);
+       } else {
+               watchpoint_remove_internal(target, address);
+       }
 }
 
 void watchpoint_clear_target(struct target *target)
 {
        LOG_DEBUG("Delete all watchpoints for target: %s",
                target_name(target));
-       while (target->watchpoints != NULL)
+       while (target->watchpoints)
                watchpoint_free(target, target->watchpoints);
 }