This is an automated email from Gerrit. "Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8899
-- gerrit commit 90571acc97719c227780c965a920bd0f37718694 Author: Antonio Borneo <borneo.anto...@gmail.com> Date: Sun May 26 12:34:58 2024 +0200 target/arm_tpiu_swo: rewrite command 'swo create' as COMMAND_HANDLER Rewrite only the command, but still use the old jimtcl specific code in arm_tpiu_swo_configure(), shared with commands 'configure' and 'cget'. Change-Id: I39c69b1cdc23f7b5f875df3e15be987c715b0bcf Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com> diff --git a/src/target/arm_tpiu_swo.c b/src/target/arm_tpiu_swo.c index e20cd59272..f2cb1a0fd1 100644 --- a/src/target/arm_tpiu_swo.c +++ b/src/target/arm_tpiu_swo.c @@ -907,56 +907,25 @@ static const struct command_registration arm_tpiu_swo_instance_command_handlers[ COMMAND_REGISTRATION_DONE }; -static int arm_tpiu_swo_create(Jim_Interp *interp, struct arm_tpiu_swo_object *obj) +COMMAND_HANDLER(handle_arm_tpiu_swo_create) { - struct command_context *cmd_ctx; - Jim_Cmd *cmd; - int e; + int retval = ERROR_FAIL; - cmd_ctx = current_command_context(interp); - assert(cmd_ctx); + if (!CMD_ARGC) + return ERROR_COMMAND_SYNTAX_ERROR; /* does this command exist? */ - cmd = Jim_GetCommand(interp, Jim_NewStringObj(interp, obj->name, -1), JIM_NONE); - if (cmd) { - Jim_SetResultFormatted(interp, "cannot create TPIU object because a command with name '%s' already exists", - obj->name); - return JIM_ERR; - } - - /* now - create the new tpiu/swo name command */ - const struct command_registration obj_commands[] = { - { - .name = obj->name, - .mode = COMMAND_ANY, - .help = "tpiu/swo instance command group", - .usage = "", - .chain = arm_tpiu_swo_instance_command_handlers, - }, - COMMAND_REGISTRATION_DONE - }; - e = register_commands_with_data(cmd_ctx, NULL, obj_commands, obj); - if (e != ERROR_OK) - return JIM_ERR; - - list_add_tail(&obj->lh, &all_tpiu_swo); - - return JIM_OK; -} - -static int jim_arm_tpiu_swo_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 < 1) { - Jim_WrongNumArgs(interp, 1, argv, "name ?option option ...?"); - return JIM_ERR; + Jim_Cmd *jimcmd = Jim_GetCommand(CMD_CTX->interp, CMD_JIMTCL_ARGV[0], JIM_NONE); + if (jimcmd) { + command_print(CMD, "cannot create TPIU object because a command with name '%s' already exists", + CMD_ARGV[0]); + return ERROR_FAIL; } struct arm_tpiu_swo_object *obj = calloc(1, sizeof(struct arm_tpiu_swo_object)); if (!obj) { LOG_ERROR("Out of memory"); - return JIM_ERR; + return ERROR_FAIL; } INIT_LIST_HEAD(&obj->connections); adiv5_mem_ap_spot_init(&obj->spot); @@ -968,36 +937,55 @@ static int jim_arm_tpiu_swo_create(Jim_Interp *interp, int argc, Jim_Obj *const goto err_exit; } - Jim_Obj *n; - jim_getopt_obj(&goi, &n); - obj->name = strdup(Jim_GetString(n, NULL)); + obj->name = strdup(CMD_ARGV[0]); if (!obj->name) { LOG_ERROR("Out of memory"); goto err_exit; } /* Do the rest as "configure" options */ - goi.is_configure = true; + 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 = arm_tpiu_swo_configure(&goi, obj); + + int reslen; + const char *result = Jim_GetString(Jim_GetResult(CMD_CTX->interp), &reslen); + if (reslen > 0) + command_print(CMD, "%s", result); + if (e != JIM_OK) goto err_exit; if (!obj->spot.dap || obj->spot.ap_num == DP_APSEL_INVALID) { - Jim_SetResultString(goi.interp, "-dap and -ap-num required when creating TPIU", -1); + command_print(CMD, "-dap and -ap-num required when creating TPIU"); goto err_exit; } - e = arm_tpiu_swo_create(goi.interp, obj); - if (e != JIM_OK) + /* now - create the new tpiu/swo name command */ + const struct command_registration obj_commands[] = { + { + .name = obj->name, + .mode = COMMAND_ANY, + .help = "tpiu/swo instance command group", + .usage = "", + .chain = arm_tpiu_swo_instance_command_handlers, + }, + COMMAND_REGISTRATION_DONE + }; + retval = register_commands_with_data(CMD_CTX, NULL, obj_commands, obj); + if (retval != ERROR_OK) goto err_exit; - return JIM_OK; + list_add_tail(&obj->lh, &all_tpiu_swo); + + return ERROR_OK; err_exit: free(obj->name); free(obj->out_filename); free(obj); - return JIM_ERR; + return retval; } COMMAND_HANDLER(handle_arm_tpiu_swo_names) @@ -1192,7 +1180,7 @@ static const struct command_registration arm_tpiu_swo_subcommand_handlers[] = { { .name = "create", .mode = COMMAND_ANY, - .jim_handler = jim_arm_tpiu_swo_create, + .handler = handle_arm_tpiu_swo_create, .usage = "name [-dap dap] [-ap-num num] [-baseaddr baseaddr]", .help = "Creates a new TPIU or SWO object", }, --