helper/command: get current target from dedicated API
[openocd.git] / src / target / target.c
index e481d526cd24ee905215c667ff5fe0692166c81d..619a8b49088b38cd6de988c83d9b2979865e38b0 100644 (file)
@@ -5206,24 +5206,27 @@ static int jim_target_configure(Jim_Interp *interp, int argc, Jim_Obj * const *a
                                 "missing: -option ...");
                return JIM_ERR;
        }
-       struct command *c = jim_to_command(goi.interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        return target_configure(&goi, target);
 }
 
 static int jim_target_mem2array(Jim_Interp *interp,
                int argc, Jim_Obj *const *argv)
 {
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        return target_mem2array(interp, target, argc - 1, argv + 1);
 }
 
 static int jim_target_array2mem(Jim_Interp *interp,
                int argc, Jim_Obj *const *argv)
 {
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        return target_array2mem(interp, target, argc - 1, argv + 1);
 }
 
@@ -5255,8 +5258,9 @@ static int jim_target_examine(Jim_Interp *interp, int argc, Jim_Obj *const *argv
                allow_defer = true;
        }
 
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        if (!target->tap->enabled)
                return jim_target_tap_disabled(interp);
 
@@ -5274,8 +5278,9 @@ static int jim_target_examine(Jim_Interp *interp, int argc, Jim_Obj *const *argv
 
 static int jim_target_was_examined(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
 {
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
 
        Jim_SetResultBool(interp, target_was_examined(target));
        return JIM_OK;
@@ -5283,8 +5288,9 @@ static int jim_target_was_examined(Jim_Interp *interp, int argc, Jim_Obj * const
 
 static int jim_target_examine_deferred(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
 {
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
 
        Jim_SetResultBool(interp, target->defer_examine);
        return JIM_OK;
@@ -5296,8 +5302,9 @@ static int jim_target_halt_gdb(Jim_Interp *interp, int argc, Jim_Obj *const *arg
                Jim_WrongNumArgs(interp, 1, argv, "[no parameters]");
                return JIM_ERR;
        }
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
 
        if (target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT) != ERROR_OK)
                return JIM_ERR;
@@ -5311,8 +5318,9 @@ static int jim_target_poll(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                Jim_WrongNumArgs(interp, 1, argv, "[no parameters]");
                return JIM_ERR;
        }
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        if (!target->tap->enabled)
                return jim_target_tap_disabled(interp);
 
@@ -5349,8 +5357,9 @@ static int jim_target_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        if (e != JIM_OK)
                return e;
 
-       struct command *c = jim_to_command(goi.interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        if (!target->tap->enabled)
                return jim_target_tap_disabled(interp);
 
@@ -5383,8 +5392,9 @@ static int jim_target_halt(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                Jim_WrongNumArgs(interp, 1, argv, "[no parameters]");
                return JIM_ERR;
        }
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        if (!target->tap->enabled)
                return jim_target_tap_disabled(interp);
        int e = target->type->halt(target);
@@ -5414,8 +5424,9 @@ static int jim_target_wait_state(Jim_Interp *interp, int argc, Jim_Obj *const *a
        e = Jim_GetOpt_Wide(&goi, &a);
        if (e != JIM_OK)
                return e;
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        if (!target->tap->enabled)
                return jim_target_tap_disabled(interp);
 
@@ -5459,8 +5470,9 @@ static int jim_target_current_state(Jim_Interp *interp, int argc, Jim_Obj *const
                Jim_WrongNumArgs(interp, 1, argv, "[no parameters]");
                return JIM_ERR;
        }
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        Jim_SetResultString(interp, target_state_name(target), -1);
        return JIM_OK;
 }
@@ -5479,8 +5491,9 @@ static int jim_target_invoke_event(Jim_Interp *interp, int argc, Jim_Obj *const
                Jim_GetOpt_NvpUnknown(&goi, nvp_target_event, 1);
                return e;
        }
-       struct command *c = jim_to_command(interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        target_handle_event(target, n->value);
        return JIM_OK;
 }

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)