This is an automated email from Gerrit.

"Kirill Radkin <kirill.rad...@syntacore.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7738

-- gerrit

commit 45843c49f83cbe70c500d2a9d52743f72f943bc8
Author: Kirill Radkin <kirill.rad...@syntacore.com>
Date:   Thu Jun 15 18:18:06 2023 +0300

    target: Change functions for delete watchpoints and breakpoints. Now they 
can return something.
    
    Also change policy of removing breakpoints/watchpoints.
    Now internal watchpoint/breakpoint will not be removed in case of error 
during removing triggers from hardware
    
    Change-Id: I71cd1f556a33975005d0ee372fc384fddfddc3bf
    Signed-off-by: Kirill Radkin <kirill.rad...@syntacore.com>

diff --git a/src/target/breakpoints.c b/src/target/breakpoints.c
index bbaff4e756..8fdb11118b 100644
--- a/src/target/breakpoints.c
+++ b/src/target/breakpoints.c
@@ -270,7 +270,7 @@ int hybrid_breakpoint_add(struct target *target,
 }
 
 /* free up a breakpoint */
-static void breakpoint_free(struct target *target, struct breakpoint 
*breakpoint_to_remove)
+static int breakpoint_free(struct target *target, struct breakpoint 
*breakpoint_to_remove)
 {
        struct breakpoint *breakpoint = target->breakpoints;
        struct breakpoint **breakpoint_p = &target->breakpoints;
@@ -284,20 +284,30 @@ static void breakpoint_free(struct target *target, struct 
breakpoint *breakpoint
        }
 
        if (!breakpoint)
-               return;
+               return ERROR_OK;
 
        retval = target_remove_breakpoint(target, breakpoint);
+       if (retval != ERROR_OK) {
+               LOG_TARGET_ERROR(target, "fail during running target-specific 
part of removing breakpoint %d",
+                                               breakpoint->number);
+               return retval;
+       }
 
        LOG_DEBUG("free BPID: %" PRIu32 " --> %d", breakpoint->unique_id, 
retval);
        (*breakpoint_p) = breakpoint->next;
        free(breakpoint->orig_instr);
        free(breakpoint);
+
+       return ERROR_OK;
 }
 
-static int breakpoint_remove_internal(struct target *target, target_addr_t 
address)
+static int breakpoint_remove_internal(struct target *target, target_addr_t 
address, int *status)
 {
        struct breakpoint *breakpoint = target->breakpoints;
 
+       if (status)
+               *status = ERROR_OK;
+
        while (breakpoint) {
                if ((breakpoint->address == address) ||
                    (breakpoint->address == 0 && breakpoint->asid == address))
@@ -306,7 +316,14 @@ static int breakpoint_remove_internal(struct target 
*target, target_addr_t addre
        }
 
        if (breakpoint) {
-               breakpoint_free(target, breakpoint);
+               int retval = breakpoint_free(target, breakpoint);
+               if (retval != ERROR_OK) {
+                       LOG_TARGET_ERROR(target, "fail during remove breakpoint 
%d", breakpoint->number);
+
+                       if (status)
+                               *status = retval;
+               }
+
                return 1;
        } else {
                if (!target->smp)
@@ -315,46 +332,66 @@ static int breakpoint_remove_internal(struct target 
*target, target_addr_t addre
        }
 }
 
-static void breakpoint_remove_all_internal(struct target *target)
+static int breakpoint_remove_all_internal(struct target *target)
 {
        struct breakpoint *breakpoint = target->breakpoints;
 
        while (breakpoint) {
                struct breakpoint *tmp = breakpoint;
                breakpoint = breakpoint->next;
-               breakpoint_free(target, tmp);
+               int retval = breakpoint_free(target, tmp);
+               if (retval != ERROR_OK) {
+                       LOG_TARGET_ERROR(target, "fail during remove breakpoint 
%d", tmp->number);
+                       return retval;
+               }
        }
+
+       return ERROR_OK;
 }
 
-void breakpoint_remove(struct target *target, target_addr_t address)
+int breakpoint_remove(struct target *target, target_addr_t address)
 {
+       int status;
        if (target->smp) {
                unsigned int num_breakpoints = 0;
                struct target_list *head;
 
                foreach_smp_target(head, target->smp_targets) {
                        struct target *curr = head->target;
-                       num_breakpoints += breakpoint_remove_internal(curr, 
address);
+                       int retval = breakpoint_remove_internal(curr, address, 
&status);
+
+                       if (status == ERROR_OK)
+                               num_breakpoints += retval;
+                       else
+                               return status;
                }
-               if (!num_breakpoints)
+               if (num_breakpoints == 0)
                        LOG_ERROR("no breakpoint at address " TARGET_ADDR_FMT " 
found", address);
        } else {
-               breakpoint_remove_internal(target, address);
+               breakpoint_remove_internal(target, address, &status);
        }
+
+       return status;
 }
 
-void breakpoint_remove_all(struct target *target)
+int breakpoint_remove_all(struct target *target)
 {
+       int retval;
        if (target->smp) {
                struct target_list *head;
 
                foreach_smp_target(head, target->smp_targets) {
                        struct target *curr = head->target;
-                       breakpoint_remove_all_internal(curr);
+                       retval = breakpoint_remove_all_internal(curr);
+
+                       if (retval != ERROR_OK)
+                               return retval;
                }
        } else {
-               breakpoint_remove_all_internal(target);
+               retval = breakpoint_remove_all_internal(target);
        }
+
+       return retval;
 }
 
 static void breakpoint_clear_target_internal(struct target *target)
@@ -362,7 +399,10 @@ static void breakpoint_clear_target_internal(struct target 
*target)
        LOG_DEBUG("Delete all breakpoints for target: %s",
                target_name(target));
        while (target->breakpoints)
-               breakpoint_free(target, target->breakpoints);
+               if (breakpoint_free(target, target->breakpoints) != ERROR_OK) {
+                       LOG_TARGET_ERROR(target, "fail during remove breakpoint 
%d", target->breakpoints->number);
+                       return;
+               }
 }
 
 void breakpoint_clear_target(struct target *target)
@@ -479,7 +519,7 @@ int watchpoint_add(struct target *target, target_addr_t 
address,
        }
 }
 
-static void watchpoint_free(struct target *target, struct watchpoint 
*watchpoint_to_remove)
+static int watchpoint_free(struct target *target, struct watchpoint 
*watchpoint_to_remove)
 {
        struct watchpoint *watchpoint = target->watchpoints;
        struct watchpoint **watchpoint_p = &target->watchpoints;
@@ -493,17 +533,28 @@ static void watchpoint_free(struct target *target, struct 
watchpoint *watchpoint
        }
 
        if (!watchpoint)
-               return;
+               return ERROR_OK;
        retval = target_remove_watchpoint(target, watchpoint);
+       if (retval != ERROR_OK) {
+               LOG_TARGET_ERROR(target, "fail during running target-specific 
part of removing watchpoint %d",
+                                               watchpoint->number);
+               return retval;
+       }
+
        LOG_DEBUG("free WPID: %d --> %d", watchpoint->unique_id, retval);
        (*watchpoint_p) = watchpoint->next;
        free(watchpoint);
+
+       return ERROR_OK;
 }
 
-static int watchpoint_remove_internal(struct target *target, target_addr_t 
address)
+static int watchpoint_remove_internal(struct target *target, target_addr_t 
address, int *status)
 {
        struct watchpoint *watchpoint = target->watchpoints;
 
+       if (status)
+               *status = ERROR_OK;
+
        while (watchpoint) {
                if (watchpoint->address == address)
                        break;
@@ -511,7 +562,15 @@ static int watchpoint_remove_internal(struct target 
*target, target_addr_t addre
        }
 
        if (watchpoint) {
-               watchpoint_free(target, watchpoint);
+               int retval = watchpoint_free(target, watchpoint);
+
+               if (retval != ERROR_OK) {
+                       LOG_TARGET_ERROR(target, "fail during remove watchpoint 
%d", watchpoint->number);
+
+                       if (status)
+                               *status = retval;
+               }
+
                return 1;
        } else {
                if (!target->smp)
@@ -520,21 +579,29 @@ static int watchpoint_remove_internal(struct target 
*target, target_addr_t addre
        }
 }
 
-void watchpoint_remove(struct target *target, target_addr_t address)
+int watchpoint_remove(struct target *target, target_addr_t address)
 {
+       int status;
        if (target->smp) {
                unsigned int num_watchpoints = 0;
                struct target_list *head;
 
                foreach_smp_target(head, target->smp_targets) {
                        struct target *curr = head->target;
-                       num_watchpoints += watchpoint_remove_internal(curr, 
address);
+                       int retval = watchpoint_remove_internal(curr, address, 
&status);
+
+                       if (status == ERROR_OK)
+                               num_watchpoints += retval;
+                       else
+                               return status;
                }
                if (num_watchpoints == 0)
-                       LOG_ERROR("no watchpoint at address " TARGET_ADDR_FMT " 
num_watchpoints", address);
+                       LOG_ERROR("no watchpoint at address " TARGET_ADDR_FMT " 
found", address);
        } else {
-               watchpoint_remove_internal(target, address);
+               watchpoint_remove_internal(target, address, &status);
        }
+
+       return status;
 }
 
 void watchpoint_clear_target(struct target *target)
@@ -542,7 +609,10 @@ void watchpoint_clear_target(struct target *target)
        LOG_DEBUG("Delete all watchpoints for target: %s",
                target_name(target));
        while (target->watchpoints)
-               watchpoint_free(target, target->watchpoints);
+               if (watchpoint_free(target, target->watchpoints) != ERROR_OK) {
+                       LOG_TARGET_ERROR(target, "fail during remove breakpoint 
%d", target->breakpoints->number);
+                       return;
+               }
 }
 
 int watchpoint_hit(struct target *target, enum watchpoint_rw *rw,
diff --git a/src/target/breakpoints.h b/src/target/breakpoints.h
index a9ae484357..a7f7ace9d4 100644
--- a/src/target/breakpoints.h
+++ b/src/target/breakpoints.h
@@ -55,8 +55,8 @@ int context_breakpoint_add(struct target *target,
                uint32_t asid, uint32_t length, enum breakpoint_type type);
 int hybrid_breakpoint_add(struct target *target,
                target_addr_t address, uint32_t asid, uint32_t length, enum 
breakpoint_type type);
-void breakpoint_remove(struct target *target, target_addr_t address);
-void breakpoint_remove_all(struct target *target);
+int breakpoint_remove(struct target *target, target_addr_t address);
+int breakpoint_remove_all(struct target *target);
 
 struct breakpoint *breakpoint_find(struct target *target, target_addr_t 
address);
 
@@ -70,7 +70,7 @@ void watchpoint_clear_target(struct target *target);
 int watchpoint_add(struct target *target,
                target_addr_t address, uint32_t length,
                enum watchpoint_rw rw, uint32_t value, uint32_t mask);
-void watchpoint_remove(struct target *target, target_addr_t address);
+int watchpoint_remove(struct target *target, target_addr_t address);
 
 /* report type and address of just hit watchpoint */
 int watchpoint_hit(struct target *target, enum watchpoint_rw *rw,
diff --git a/src/target/target.c b/src/target/target.c
index 5858aa573b..188fbe1ba4 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -4034,21 +4034,26 @@ COMMAND_HANDLER(handle_bp_command)
 
 COMMAND_HANDLER(handle_rbp_command)
 {
+       int retval;
+
        if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        struct target *target = get_current_target(CMD_CTX);
 
        if (!strcmp(CMD_ARGV[0], "all")) {
-               breakpoint_remove_all(target);
+               retval = breakpoint_remove_all(target);
        } else {
                target_addr_t addr;
                COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr);
 
-               breakpoint_remove(target, addr);
+               retval = breakpoint_remove(target, addr);
        }
 
-       return ERROR_OK;
+       if (retval != ERROR_OK)
+               LOG_ERROR("Failure removing breakpoints");
+
+       return retval;
 }
 
 COMMAND_HANDLER(handle_wp_command)
@@ -4128,11 +4133,15 @@ COMMAND_HANDLER(handle_rwp_command)
        COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr);
 
        struct target *target = get_current_target(CMD_CTX);
-       watchpoint_remove(target, addr);
+       int retval = watchpoint_remove(target, addr);
 
-       return ERROR_OK;
+       if (retval != ERROR_OK)
+               LOG_ERROR("Failure removing watchpoints");
+
+       return retval;
 }
 
+
 /**
  * Translate a virtual address to a physical address.
  *

-- 

Reply via email to