This is an automated email from Gerrit.

Antonio Borneo ([email protected]) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/5666

-- gerrit

commit d2f5312eeacae01ff69d66f12599890339d777d1
Author: Antonio Borneo <[email protected]>
Date:   Tue May 12 02:36:56 2020 +0200

    helper/command: get current target from dedicated API
    
    Now that target override is uniformly implemented for all types of
    commands, there is no need for target-prefixed "native" commands
    (.jim_handler) to sneakily extract the overridden target from the
    struct command.
    
    Modify the commands to use the standard API get_current_target().
    
    Change-Id: I732a09c3261e56524edd5217634fa409eb97a8c6
    Signed-off-by: Antonio Borneo <[email protected]>

diff --git a/src/target/nds32_cmd.c b/src/target/nds32_cmd.c
index ef219e7..65e30bf 100644
--- a/src/target/nds32_cmd.c
+++ b/src/target/nds32_cmd.c
@@ -722,8 +722,9 @@ static int jim_nds32_bulk_write(Jim_Interp *interp, int 
argc, Jim_Obj * const *a
                return JIM_ERR;
        }
 
-       struct command *c = Jim_CmdPrivData(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);
        int result;
 
        result = target_write_buffer(target, address, count * 4, (const uint8_t 
*)data);
@@ -752,8 +753,9 @@ static int jim_nds32_multi_write(Jim_Interp *interp, int 
argc, Jim_Obj * const *
        if (e != JIM_OK)
                return e;
 
-       struct command *c = Jim_CmdPrivData(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);
        struct aice_port_s *aice = target_to_aice(target);
        int result;
        uint32_t address;
@@ -814,8 +816,9 @@ static int jim_nds32_bulk_read(Jim_Interp *interp, int 
argc, Jim_Obj * const *ar
        if (goi.argc != 0)
                return JIM_ERR;
 
-       struct command *c = Jim_CmdPrivData(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);
        uint32_t *data = malloc(count * sizeof(uint32_t));
        int result;
        result = target_read_buffer(target, address, count * 4, (uint8_t 
*)data);
@@ -866,8 +869,9 @@ static int jim_nds32_read_edm_sr(Jim_Interp *interp, int 
argc, Jim_Obj * const *
        else
                return ERROR_FAIL;
 
-       struct command *c = Jim_CmdPrivData(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);
        struct aice_port_s *aice = target_to_aice(target);
        char data_str[11];
 
@@ -915,8 +919,9 @@ static int jim_nds32_write_edm_sr(Jim_Interp *interp, int 
argc, Jim_Obj * const
        else
                return ERROR_FAIL;
 
-       struct command *c = Jim_CmdPrivData(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);
        struct aice_port_s *aice = target_to_aice(target);
 
        aice_write_debug_reg(aice, edm_sr_number, value);
diff --git a/src/target/target.c b/src/target/target.c
index 2e55f51..a43c1a5 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -4972,24 +4972,27 @@ static int jim_target_configure(Jim_Interp *interp, int 
argc, Jim_Obj * const *a
                                 "missing: -option ...");
                return JIM_ERR;
        }
-       struct command *c = Jim_CmdPrivData(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_CmdPrivData(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_CmdPrivData(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);
 }
 
@@ -5021,8 +5024,9 @@ static int jim_target_examine(Jim_Interp *interp, int 
argc, Jim_Obj *const *argv
                allow_defer = true;
        }
 
-       struct command *c = Jim_CmdPrivData(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);
 
@@ -5040,8 +5044,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_CmdPrivData(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;
@@ -5049,8 +5054,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_CmdPrivData(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;
@@ -5062,8 +5068,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_CmdPrivData(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;
@@ -5077,8 +5084,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_CmdPrivData(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);
 
@@ -5115,8 +5123,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_CmdPrivData(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);
 
@@ -5149,8 +5158,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_CmdPrivData(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);
@@ -5180,8 +5190,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_CmdPrivData(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);
 
@@ -5225,8 +5236,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_CmdPrivData(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;
 }
@@ -5245,8 +5257,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_CmdPrivData(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;
 }

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to