aboutsummaryrefslogtreecommitdiff
path: root/src/helper/command.c
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2020-05-12 11:52:56 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2021-04-18 15:33:23 +0100
commit428938993742f4f961cdc948593d9553f721c321 (patch)
tree7a0373acf08898f0df43fd6acc726e4c66f54f02 /src/helper/command.c
parent7cd679a2de697065bbd36cde9042516ccf20f0f1 (diff)
downloadriscv-openocd-428938993742f4f961cdc948593d9553f721c321.zip
riscv-openocd-428938993742f4f961cdc948593d9553f721c321.tar.gz
riscv-openocd-428938993742f4f961cdc948593d9553f721c321.tar.bz2
helper/command: override target only on target prefixed cmds
In current code the current target is overridden whenever jim_handler_data is not NULL. This happens not only with target prefixed commands, but also with cti, dap and swo/tpiu prefixed commands. While this is not causing any run-time issue, by now, the behaviour is tricky and makes the code cryptic. Add a specific field to struct command for the target override so the content of jim_handler_data can be restricted to command specific data only (today only cti, dap and swo/tpiu). Extend the API register_commands() to specify the presence of either the command data or the override target. The new API makes obsolete calling command_set_handler_data() to set jim_handler_data, so remove it. Change-Id: Icc323faf754b0546a72208f90abd9e68ff2ef52f Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5667 Tested-by: jenkins Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Diffstat (limited to 'src/helper/command.c')
-rw-r--r--src/helper/command.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index ecca75d..89e2173 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -391,8 +391,9 @@ static struct command *register_command(struct command_context *context,
return c;
}
-int register_commands(struct command_context *cmd_ctx, struct command *parent,
- const struct command_registration *cmds)
+int __register_commands(struct command_context *cmd_ctx, struct command *parent,
+ const struct command_registration *cmds, void *data,
+ struct target *override_target)
{
int retval = ERROR_OK;
unsigned i;
@@ -406,10 +407,12 @@ int register_commands(struct command_context *cmd_ctx, struct command *parent,
retval = ERROR_FAIL;
break;
}
+ c->jim_handler_data = data;
+ c->jim_override_target = override_target;
}
if (NULL != cr->chain) {
struct command *p = c ? : parent;
- retval = register_commands(cmd_ctx, p, cr->chain);
+ retval = __register_commands(cmd_ctx, p, cr->chain, data, override_target);
if (ERROR_OK != retval)
break;
}
@@ -461,13 +464,6 @@ static int unregister_command(struct command_context *context,
return ERROR_OK;
}
-void command_set_handler_data(struct command *c, void *p)
-{
- c->jim_handler_data = p;
- for (struct command *cc = c->children; NULL != cc; cc = cc->next)
- command_set_handler_data(cc, p);
-}
-
void command_output_text(struct command_context *context, const char *data)
{
if (context && context->output_handler && data)
@@ -1057,12 +1053,12 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
* correct work when command_unknown() is re-entered.
*/
struct target *saved_target_override = cmd_ctx->current_target_override;
- if (c->jim_handler_data)
- cmd_ctx->current_target_override = c->jim_handler_data;
+ if (c->jim_override_target)
+ cmd_ctx->current_target_override = c->jim_override_target;
int retval = exec_command(interp, cmd_ctx, c, count, start);
- if (c->jim_handler_data)
+ if (c->jim_override_target)
cmd_ctx->current_target_override = saved_target_override;
return retval;