From: openocd-gerrit <ope...@us...> - 2025-05-25 12:41:56
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via c8979f6441eb62bb261827daa252c4e5596c4a39 (commit) via 1aef2ae18d709a141404777dc5bce3ec59b37909 (commit) from 532db01df29ab0636911f5cb0b40ed5747879c4e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit c8979f6441eb62bb261827daa252c4e5596c4a39 Author: Antonio Borneo <bor...@gm...> Date: Tue Dec 5 01:10:10 2023 +0100 target: arm_cti: rewrite commands 'cti create' as COMMAND_HANDLER Rewrite only the command, but still use the old jimtcl specific code in cti_configure(). Change-Id: I29fb952a7c8148416b301cbf78b6e342979af7d3 Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: https://review.openocd.org/c/openocd/+/8898 Tested-by: jenkins diff --git a/src/target/arm_cti.c b/src/target/arm_cti.c index b2f78eef7..830956e5c 100644 --- a/src/target/arm_cti.c +++ b/src/target/arm_cti.c @@ -434,49 +434,47 @@ static int cti_configure(struct jim_getopt_info *goi, struct arm_cti *cti) return JIM_OK; } -static int cti_create(struct jim_getopt_info *goi) +COMMAND_HANDLER(handle_cti_create) { - struct command_context *cmd_ctx; - static struct arm_cti *cti; - Jim_Obj *new_cmd; - Jim_Cmd *cmd; - const char *cp; - int e; - - cmd_ctx = current_command_context(goi->interp); - assert(cmd_ctx); - - if (goi->argc < 3) { - Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ..options..."); - return JIM_ERR; - } - /* COMMAND */ - jim_getopt_obj(goi, &new_cmd); - /* does this command exist? */ - cmd = Jim_GetCommand(goi->interp, new_cmd, JIM_NONE); - if (cmd) { - cp = Jim_GetString(new_cmd, NULL); - Jim_SetResultFormatted(goi->interp, "Command: %s Exists", cp); - return JIM_ERR; + if (CMD_ARGC < 3) + return ERROR_COMMAND_SYNTAX_ERROR; + + /* check if the cti name clashes with an existing command name */ + Jim_Cmd *jimcmd = Jim_GetCommand(CMD_CTX->interp, CMD_JIMTCL_ARGV[0], JIM_NONE); + if (jimcmd) { + command_print(CMD, "Command/cti: %s Exists", CMD_ARGV[0]); + return ERROR_FAIL; } /* Create it */ - cti = calloc(1, sizeof(*cti)); - if (!cti) - return JIM_ERR; + struct arm_cti *cti = calloc(1, sizeof(*cti)); + if (!cti) { + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } adiv5_mem_ap_spot_init(&cti->spot); /* Do the rest as "configure" options */ - goi->is_configure = true; - e = cti_configure(goi, cti); + struct jim_getopt_info goi; + jim_getopt_setup(&goi, CMD_CTX->interp, CMD_ARGC - 1, CMD_JIMTCL_ARGV + 1); + goi.is_configure = 1; + int e = cti_configure(&goi, cti); if (e != JIM_OK) { + int reslen; + const char *result = Jim_GetString(Jim_GetResult(CMD_CTX->interp), &reslen); + if (reslen > 0) + command_print(CMD, "%s", result); free(cti); - return e; + return ERROR_COMMAND_ARGUMENT_INVALID; } - cp = Jim_GetString(new_cmd, NULL); - cti->name = strdup(cp); + cti->name = strdup(CMD_ARGV[0]); + if (!cti->name) { + LOG_ERROR("Out of memory"); + free(cti); + return ERROR_FAIL; + } /* now - create the new cti name command */ const struct command_registration cti_subcommands[] = { @@ -487,7 +485,7 @@ static int cti_create(struct jim_getopt_info *goi) }; const struct command_registration cti_commands[] = { { - .name = cp, + .name = CMD_ARGV[0], .mode = COMMAND_ANY, .help = "cti instance command group", .usage = "", @@ -495,31 +493,24 @@ static int cti_create(struct jim_getopt_info *goi) }, COMMAND_REGISTRATION_DONE }; - e = register_commands_with_data(cmd_ctx, NULL, cti_commands, cti); - if (e != ERROR_OK) - return JIM_ERR; + int retval = register_commands_with_data(CMD_CTX, NULL, cti_commands, cti); + if (retval != ERROR_OK) { + free(cti->name); + free(cti); + return retval; + } list_add_tail(&cti->lh, &all_cti); cti->ap = dap_get_ap(cti->spot.dap, cti->spot.ap_num); if (!cti->ap) { - Jim_SetResultString(goi->interp, "Cannot get AP", -1); - return JIM_ERR; + command_print(CMD, "Cannot get AP"); + free(cti->name); + free(cti); + return ERROR_FAIL; } - return JIM_OK; -} - -static int jim_cti_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv) -{ - struct jim_getopt_info goi; - jim_getopt_setup(&goi, interp, argc - 1, argv + 1); - if (goi.argc < 2) { - Jim_WrongNumArgs(goi.interp, goi.argc, goi.argv, - "<name> [<cti_options> ...]"); - return JIM_ERR; - } - return cti_create(&goi); + return ERROR_OK; } COMMAND_HANDLER(cti_handle_names) @@ -539,7 +530,7 @@ static const struct command_registration cti_subcommand_handlers[] = { { .name = "create", .mode = COMMAND_ANY, - .jim_handler = jim_cti_create, + .handler = handle_cti_create, .usage = "name '-chain-position' name [options ...]", .help = "Creates a new CTI object", }, commit 1aef2ae18d709a141404777dc5bce3ec59b37909 Author: Antonio Borneo <bor...@gm...> Date: Tue Dec 5 00:45:54 2023 +0100 target: arm_dap: rewrite commands 'dap create' as COMMAND_HANDLER Rewrite only the command, but still use the old jimtcl specific code in dap_configure(). Change-Id: I3360884616367aae52f5b32247d9864000c53fdc Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: https://review.openocd.org/c/openocd/+/8897 Tested-by: jenkins diff --git a/src/target/arm_dap.c b/src/target/arm_dap.c index c5bd6ccd4..be5e63c7c 100644 --- a/src/target/arm_dap.c +++ b/src/target/arm_dap.c @@ -333,61 +333,59 @@ static int dap_check_config(struct adiv5_dap *dap) return ERROR_OK; } -static int dap_create(struct jim_getopt_info *goi) +COMMAND_HANDLER(handle_dap_create) { - struct command_context *cmd_ctx; - static struct arm_dap_object *dap; - Jim_Obj *new_cmd; - Jim_Cmd *cmd; - const char *cp; - int e; + if (CMD_ARGC < 3) + return ERROR_COMMAND_SYNTAX_ERROR; - cmd_ctx = current_command_context(goi->interp); - assert(cmd_ctx); + int retval = ERROR_COMMAND_ARGUMENT_INVALID; - if (goi->argc < 3) { - Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ..options..."); - return JIM_ERR; - } - /* COMMAND */ - jim_getopt_obj(goi, &new_cmd); - /* does this command exist? */ - cmd = Jim_GetCommand(goi->interp, new_cmd, JIM_NONE); - if (cmd) { - cp = Jim_GetString(new_cmd, NULL); - Jim_SetResultFormatted(goi->interp, "Command: %s Exists", cp); - return JIM_ERR; + /* check if the dap name clashes with an existing command name */ + Jim_Cmd *jimcmd = Jim_GetCommand(CMD_CTX->interp, CMD_JIMTCL_ARGV[0], JIM_NONE); + if (jimcmd) { + command_print(CMD, "Command/dap: %s Exists", CMD_ARGV[0]); + return ERROR_FAIL; } /* Create it */ - dap = calloc(1, sizeof(struct arm_dap_object)); - if (!dap) - return JIM_ERR; + struct arm_dap_object *dap = calloc(1, sizeof(struct arm_dap_object)); + if (!dap) { + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } dap_instance_init(&dap->dap); - cp = Jim_GetString(new_cmd, NULL); - dap->name = strdup(cp); + dap->name = strdup(CMD_ARGV[0]); + if (!dap->name) { + LOG_ERROR("Out of memory"); + free(dap); + return ERROR_FAIL; + } - e = dap_configure(goi, dap); - if (e != JIM_OK) + struct jim_getopt_info goi; + jim_getopt_setup(&goi, CMD_CTX->interp, CMD_ARGC - 1, CMD_JIMTCL_ARGV + 1); + int e = dap_configure(&goi, dap); + if (e != JIM_OK) { + int reslen; + const char *result = Jim_GetString(Jim_GetResult(CMD_CTX->interp), &reslen); + if (reslen > 0) + command_print(CMD, "%s", result); goto err; + } if (!dap->dap.tap) { - Jim_SetResultString(goi->interp, "-chain-position required when creating DAP", -1); - e = JIM_ERR; + command_print(CMD, "-chain-position required when creating DAP"); goto err; } - e = dap_check_config(&dap->dap); - if (e != ERROR_OK) { - e = JIM_ERR; + retval = dap_check_config(&dap->dap); + if (retval != ERROR_OK) goto err; - } struct command_registration dap_create_commands[] = { { - .name = cp, + .name = CMD_ARGV[0], .mode = COMMAND_ANY, .help = "dap instance command group", .usage = "", @@ -400,32 +398,18 @@ static int dap_create(struct jim_getopt_info *goi) if (transport_is_hla()) dap_create_commands[0].chain = NULL; - e = register_commands_with_data(cmd_ctx, NULL, dap_create_commands, dap); - if (e != ERROR_OK) { - e = JIM_ERR; + retval = register_commands_with_data(CMD_CTX, NULL, dap_create_commands, dap); + if (retval != ERROR_OK) goto err; - } list_add_tail(&dap->lh, &all_dap); - return JIM_OK; + return ERROR_OK; err: free(dap->name); free(dap); - return e; -} - -static int jim_dap_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv) -{ - struct jim_getopt_info goi; - jim_getopt_setup(&goi, interp, argc - 1, argv + 1); - if (goi.argc < 2) { - Jim_WrongNumArgs(goi.interp, goi.argc, goi.argv, - "<name> [<dap_options> ...]"); - return JIM_ERR; - } - return dap_create(&goi); + return retval; } COMMAND_HANDLER(handle_dap_names) @@ -496,7 +480,7 @@ static const struct command_registration dap_subcommand_handlers[] = { { .name = "create", .mode = COMMAND_ANY, - .jim_handler = jim_dap_create, + .handler = handle_dap_create, .usage = "name '-chain-position' name", .help = "Creates a new DAP instance", }, ----------------------------------------------------------------------- Summary of changes: src/target/arm_cti.c | 93 ++++++++++++++++++++++++---------------------------- src/target/arm_dap.c | 92 +++++++++++++++++++++------------------------------ 2 files changed, 80 insertions(+), 105 deletions(-) hooks/post-receive -- Main OpenOCD repository |