target: rewrite command 'target smp' as COMMAND_HANDLER 11/7511/2
authorAntonio Borneo <borneo.antonio@gmail.com>
Mon, 19 Dec 2022 23:11:41 +0000 (00:11 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 25 Mar 2023 18:16:02 +0000 (18:16 +0000)
This also fixes an incorrect return ERROR_xx from a jim command,
propagated from return value of rtos_smp_init().

Change-Id: Icf4893c00aabd8fadd60077c5e8a2e926f687518
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7511
Tested-by: jenkins
src/target/target.c

index 3fdb34ec6f9f937c903f540e2db305b305dda821..47abd2823193f016f03a6810e92d82be4966758a 100644 (file)
@@ -6404,9 +6404,8 @@ COMMAND_HANDLER(handle_target_names)
 
 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);
+create_target_list_node(const char *targetname)
+{
        struct target *target = get_target(targetname);
        LOG_DEBUG("%s ", targetname);
        if (!target)
@@ -6422,7 +6421,8 @@ create_target_list_node(Jim_Obj *const name) {
        return new;
 }
 
-static int get_target_with_common_rtos_type(struct list_head *lh, struct target **result)
+static int get_target_with_common_rtos_type(struct command_invocation *cmd,
+       struct list_head *lh, struct target **result)
 {
        struct target *target = NULL;
        struct target_list *curr;
@@ -6430,39 +6430,39 @@ static int get_target_with_common_rtos_type(struct list_head *lh, struct target
                struct rtos *curr_rtos = curr->target->rtos;
                if (curr_rtos) {
                        if (target && target->rtos && target->rtos->type != curr_rtos->type) {
-                               LOG_ERROR("Different rtos types in members of one smp target!");
-                               return JIM_ERR;
+                               command_print(cmd, "Different rtos types in members of one smp target!");
+                               return ERROR_FAIL;
                        }
                        target = curr->target;
                }
        }
        *result = target;
-       return JIM_OK;
+       return ERROR_OK;
 }
 
-static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+COMMAND_HANDLER(handle_target_smp)
 {
        static int smp_group = 1;
 
-       if (argc == 1) {
+       if (CMD_ARGC == 0) {
                LOG_DEBUG("Empty SMP target");
-               return JIM_OK;
+               return ERROR_OK;
        }
-       LOG_DEBUG("%d", argc);
-       /* argv[1] = target to associate in smp
-        * argv[2] = target to associate in smp
-        * argv[3] ...
+       LOG_DEBUG("%d", CMD_ARGC);
+       /* CMD_ARGC[0] = target to associate in smp
+        * CMD_ARGC[1] = target to associate in smp
+        * CMD_ARGC[2] ...
         */
 
        struct list_head *lh = malloc(sizeof(*lh));
        if (!lh) {
                LOG_ERROR("Out of memory");
-               return JIM_ERR;
+               return ERROR_FAIL;
        }
        INIT_LIST_HEAD(lh);
 
-       for (int i = 1; i < argc; i++) {
-               struct target_list *new = create_target_list_node(argv[i]);
+       for (unsigned int i = 0; i < CMD_ARGC; i++) {
+               struct target_list *new = create_target_list_node(CMD_ARGV[i]);
                if (new)
                        list_add_tail(&new->lh, lh);
        }
@@ -6476,14 +6476,13 @@ static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        smp_group++;
 
        struct target *rtos_target;
-       int retval = get_target_with_common_rtos_type(lh, &rtos_target);
-       if (retval == JIM_OK && rtos_target)
+       int retval = get_target_with_common_rtos_type(CMD, lh, &rtos_target);
+       if (retval == ERROR_OK && rtos_target)
                retval = rtos_smp_init(rtos_target);
 
        return retval;
 }
 
-
 static int jim_target_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
        struct jim_getopt_info goi;
@@ -6536,7 +6535,7 @@ static const struct command_registration target_subcommand_handlers[] = {
        {
                .name = "smp",
                .mode = COMMAND_ANY,
-               .jim_handler = jim_target_smp,
+               .handler = handle_target_smp,
                .usage = "targetname1 targetname2 ...",
                .help = "gather several target in a smp list"
        },

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)