This is an automated email from Gerrit.

"Tomas Vanek <[email protected]>" just uploaded a new patch set to Gerrit, which 
you can find at https://review.openocd.org/c/openocd/+/9125

-- gerrit

commit eda4c13b621b3cc3978a7d99eff803e204be2fcd
Author: Tomas Vanek <[email protected]>
Date:   Mon Jun 2 17:50:40 2025 +0200

    target/breakpoints: breakpoint_add() rework
    
    Always start with the selected target, not the first one in SMP group.
    Allow to retry bp add if the target specific code returns
    ERROR_BREAKPOINT_NOT_SET_TRY_NEXT_SMP_CORE
    
    Change-Id: I0d46b832f480d9659487a8d925c067164e27cfe3
    Signed-off-by: Tomas Vanek <[email protected]>

diff --git a/src/target/breakpoints.c b/src/target/breakpoints.c
index 8cd761013f..03a1c94d78 100644
--- a/src/target/breakpoints.c
+++ b/src/target/breakpoints.c
@@ -210,25 +210,41 @@ int breakpoint_add(struct target *target,
        unsigned int length,
        enum breakpoint_type type)
 {
-       if (target->smp) {
+       /* always add to the requested target first */
+       int retval = breakpoint_add_internal(target, address, length, type);
+
+       /* treat SMP */
+       if (target->smp
+                       && (type != BKPT_SOFT
+                                       /* hard/ctx/hybrid bp must be set on 
all SMP cores */
+                               || retval == 
ERROR_BREAKPOINT_NOT_SET_TRY_NEXT_SMP_CORE)) {
+                                       /* soft bp could be re-tried on other 
cores until succeeds */
                struct target_list *head;
 
-               if (type == BKPT_SOFT) {
-                       head = list_first_entry(target->smp_targets, struct 
target_list, lh);
-                       return breakpoint_add_internal(head->target, address, 
length, type);
-               }
-
                foreach_smp_target(head, target->smp_targets) {
-                       struct target *curr = head->target;
-                       int retval = breakpoint_add_internal(curr, address, 
length, type);
-                       if (retval != ERROR_OK)
-                               return retval;
-               }
+                       struct target *t = head->target;
+                       if (t == target)
+                               continue;                       /* done at the 
beginning */
+
+                       int retval2 = breakpoint_add_internal(t, address, 
length, type);
+
+                       if (retval2 != 
ERROR_BREAKPOINT_NOT_SET_TRY_NEXT_SMP_CORE) {
+                               if (type == BKPT_SOFT)
+                                       /* A soft breakpoint has been set on 
one core
+                                        * or failed without a hint to try the 
next core.
+                                        * SMP cores share memory, we can stop 
iteration */
+                                       break;
+
+                               if (retval == ERROR_OK
+                                               || retval == 
ERROR_BREAKPOINT_NOT_SET_TRY_NEXT_SMP_CORE)
+                                       retval= retval2;        /* keep the 
first error for return */
+                       }
 
-               return ERROR_OK;
-       } else {
-               return breakpoint_add_internal(target, address, length, type);
+                       /* continue regardless of error: we may succeed on 
other cores */
+               }
        }
+
+       return retval;
 }
 
 int context_breakpoint_add(struct target *target,
diff --git a/src/target/breakpoints.h b/src/target/breakpoints.h
index 840c051aa8..7aadcd9ed6 100644
--- a/src/target/breakpoints.h
+++ b/src/target/breakpoints.h
@@ -89,5 +89,6 @@ static inline void watchpoint_set(struct watchpoint 
*watchpoint, unsigned int nu
 #define ERROR_BREAKPOINT_NOT_FOUND (-1600)
 #define ERROR_WATCHPOINT_NOT_FOUND (-1601)
 #define ERROR_BREAKPOINT_DUPLICATED (-1602)
+#define ERROR_BREAKPOINT_NOT_SET_TRY_NEXT_SMP_CORE (-1603)
 
 #endif /* OPENOCD_TARGET_BREAKPOINTS_H */

-- 

Reply via email to