This is an automated email from Gerrit.

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

-- gerrit

commit 8ef7160b76b143f243ba69ae0625331bfdd0b33c
Author: Tomas Vanek <[email protected]>
Date:   Tue Nov 21 22:57:39 2017 +0100

    target: use correct target in target-prefixed commands
    
    This change is an alternative to Matthias Welwarsky's #4130.
    
    get_current_target() must retrieve the target associated to the current
    command. If no target associated, the current target of the command
    context is used as a fallback.
    
    Jim handlers lacked ability to extract the current command.
    The change introduces 'invocation' pointer in struct command_context.
    It serves as back-link to easily extract current command from the context.
    
    Change-Id: I9a82102e94dcac063743834a1d28da861b2e74ea
    Signed-off-by: Tomas Vanek <[email protected]>
    Suggested-by: Matthias Welwarsky <[email protected]>

diff --git a/src/helper/command.c b/src/helper/command.c
index 40e8b05..c1c9590 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -608,7 +608,11 @@ static int run_command(struct command_context *context,
                .argc = num_words - 1,
                .argv = words + 1,
        };
+       struct command_invocation *save_cmd = context->invocation;
+       context->invocation = &cmd;
        int retval = c->handler(&cmd);
+       context->invocation = save_cmd;
+
        if (retval == ERROR_COMMAND_SYNTAX_ERROR) {
                /* Print help for command */
                char *full_name = command_name(c, ' ');
diff --git a/src/helper/command.h b/src/helper/command.h
index bd24156..afc76a5 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -52,6 +52,7 @@ struct command_context {
        int current_target;
        command_output_handler_t output_handler;
        void *output_handler_priv;
+       struct command_invocation *invocation;
 };
 
 struct command;
diff --git a/src/target/target.c b/src/target/target.c
index 36318d8..c2dc819 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -512,7 +512,17 @@ struct target *get_target_by_num(int num)
 
 struct target *get_current_target(struct command_context *cmd_ctx)
 {
-       struct target *target = get_target_by_num(cmd_ctx->current_target);
+       struct target *target = NULL;
+
+       if (cmd_ctx->invocation) {
+               if (cmd_ctx->invocation->current)
+                       target = cmd_ctx->invocation->current->jim_handler_data;
+       } else {
+               LOG_WARNING("get_current_target: no invocation pointer BUG?");
+       }
+
+       if (target == NULL)
+               target = get_target_by_num(cmd_ctx->current_target);
 
        if (target == NULL) {
                LOG_ERROR("BUG: current_target out of bounds");

-- 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to