This is an automated email from Gerrit.

"Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>" just uploaded a new patch 
set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7222

-- gerrit

commit 2a9cfd0c2615764e102dd49c5aea0f5ae34a0b11
Author: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>
Date:   Fri Sep 16 16:01:46 2022 +0300

    Fix breackpoint_add for rtos swbp
    
    breakpoint_add should use rtos only if request is done by gdb.
    If multiple targets are specified as -rtos <rtos_type>, the
    rtos_update_threads was called only if the last target was specified as 
rtos,
    which is inconcistent with other checks of whether or not smp target is
    an rtos one.
    
    Signed-off-by: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>
    Change-Id: I46b2d9a5a691c9e01bdf3f9f94ea65bfe82daf20

diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index d8dbc2c8b7..91bad4c274 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -1773,7 +1773,13 @@ static int gdb_breakpoint_watchpoint_packet(struct 
connection *connection,
                case 0:
                case 1:
                        if (packet[0] == 'Z') {
-                               retval = breakpoint_add(target, address, size, 
bp_type);
+                               struct target *bp_target = target;
+                               if (target->rtos && (bp_type == BKPT_SOFT)) {
+                                       bp_target = rtos_swbp_target(target, 
address, size, bp_type);
+                                       if (!bp_target)
+                                               return ERROR_FAIL;
+                               }
+                               retval = breakpoint_add(bp_target, address, 
size, bp_type);
                                if (retval == ERROR_NOT_IMPLEMENTED) {
                                        /* Send empty reply to report that 
breakpoints of this type are not supported */
                                        gdb_put_packet(connection, "", 0);
diff --git a/src/target/breakpoints.c b/src/target/breakpoints.c
index bbaff4e756..433d49d26a 100644
--- a/src/target/breakpoints.c
+++ b/src/target/breakpoints.c
@@ -206,14 +206,9 @@ int breakpoint_add(struct target *target,
        uint32_t length,
        enum breakpoint_type type)
 {
-       if (target->smp) {
-               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);
-               }
-
+       if (target->smp && (type == BKPT_HARD)) {
+               struct target_list *head = list_first_entry(target->smp_targets,
+                struct target_list, lh);
                foreach_smp_target(head, target->smp_targets) {
                        struct target *curr = head->target;
                        int retval = breakpoint_add_internal(curr, address, 
length, type);
diff --git a/src/target/target.c b/src/target/target.c
index 783159fecc..1bbb7500a3 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -6433,16 +6433,31 @@ static int jim_target_names(Jim_Interp *interp, int 
argc, Jim_Obj *const *argv)
        return JIM_OK;
 }
 
+static struct target_list *
+__attribute__((warn_unused_result))
+create_target_list_node(Jim_Obj *const name) {
+       int len;
+       const char *targetname = Jim_GetString(name, &len);
+       struct target *target = get_target(targetname);
+       LOG_DEBUG("%s ", targetname);
+       if (!target)
+               return NULL;
+
+       struct target_list *new = malloc(sizeof(struct target_list));
+       if (!new) {
+               LOG_ERROR("Out of memory");
+               return new;
+       }
+
+       new->target = target;
+       return new;
+}
+
 static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
-       int i;
-       const char *targetname;
-       int retval, len;
+       int retval = 0;
        static int smp_group = 1;
-       struct target *target = NULL;
-       struct target_list *head, *new;
 
-       retval = 0;
        LOG_DEBUG("%d", argc);
        /* argv[1] = target to associate in smp
         * argv[2] = target to associate in smp
@@ -6456,27 +6471,24 @@ static int jim_target_smp(Jim_Interp *interp, int argc, 
Jim_Obj *const *argv)
        }
        INIT_LIST_HEAD(lh);
 
-       for (i = 1; i < argc; i++) {
-
-               targetname = Jim_GetString(argv[i], &len);
-               target = get_target(targetname);
-               LOG_DEBUG("%s ", targetname);
-               if (target) {
-                       new = malloc(sizeof(struct target_list));
-                       new->target = target;
+       for (int i = 1; i < argc; i++) {
+               struct target_list *new = create_target_list_node(argv[i]);
+               if (new)
                        list_add_tail(&new->lh, lh);
-               }
        }
        /*  now parse the list of cpu and put the target in smp mode*/
-       foreach_smp_target(head, lh) {
-               target = head->target;
+       struct target_list *curr;
+       foreach_smp_target(curr, lh) {
+               struct target *target = curr->target;
                target->smp = smp_group;
                target->smp_targets = lh;
        }
        smp_group++;
 
-       if (target && target->rtos)
-               retval = rtos_smp_init(target);
+       struct target_list *first =
+               list_first_entry_or_null(lh, typeof(*first), lh);
+       if (first && first->target && first->target->rtos)
+               retval = rtos_smp_init(first->target);
 
        return retval;
 }

-- 

Reply via email to