This is an automated email from Gerrit. Marc Schink ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/5312
-- gerrit commit e53f3df0d3bf2280381191a8767eabe2d60f1b25 Author: Marc Schink <[email protected]> Date: Wed Jul 10 07:30:35 2019 +0200 target/tcl: Add reg2array function Change-Id: Id1be9554d1df2c07cec3161a0fd3a586fdf18246 Signed-off-by: Marc Schink <[email protected]> diff --git a/doc/openocd.texi b/doc/openocd.texi index c5a926c..4193d02 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -4634,6 +4634,16 @@ and neither store nor return those values. @end itemize @end deffn +@deffn Command {$target_name reg2array} arrayname register [register ...] +Load target register values into a Tcl array. The array contains the register +numbers and their corresponding values. + +@itemize +@item @var{arrayname} ... name of an array variable +@item @var{register} ... register number +@end itemize +@end deffn + @deffn Command {$target_name cget} queryparm Each configuration parameter accepted by @command{$target_name configure} diff --git a/src/target/target.c b/src/target/target.c index 51fdff3..6c73dd6 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -67,6 +67,8 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc, Jim_Obj * const *argv); static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, Jim_Obj * const *argv); +static int target_reg2array(Jim_Interp *interp, struct target *target, + int argc, Jim_Obj * const *argv); static int target_register_user_commands(struct command_context *cmd_ctx); static int target_get_gdb_fileio_info_default(struct target *target, struct gdb_fileio_info *fileio_info); @@ -4332,6 +4334,66 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, return e; } +static int jim_reg2array(Jim_Interp *interp, int argc, Jim_Obj * const *argv) +{ + struct command_context *context; + struct target *target; + + context = current_command_context(interp); + assert(context != NULL); + + target = get_current_target(context); + if (target == NULL) { + LOG_ERROR("reg2array: no current target"); + return JIM_ERR; + } + + return target_reg2array(interp, target, argc - 1, argv + 1); +} + +static int target_reg2array(Jim_Interp *interp, struct target *target, + int argc, Jim_Obj * const *argv) +{ + /* + * argv[1]: name of array to store the register values. + * argv[2..N]: register indices. + */ + + if (argc < 2) { + Jim_WrongNumArgs(interp, 0, argv, "arrayname register [register ...]"); + return JIM_ERR; + } + + int len; + const char *varname = Jim_GetString(argv[0], &len); + + for (int i = 0; i < argc - 1; i++) { + long reg_num; + + if (Jim_GetLong(interp, argv[i + 1], ®_num) != JIM_OK) { + return JIM_ERR; + } + + struct reg *reg = register_get_by_number(target->reg_cache, reg_num, + true); + + if (!reg) { + Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); + Jim_AppendStrings(interp, Jim_GetResult(interp), + "reg2array: cannot read register", NULL); + return ERROR_FAIL; + } + + new_int_array_element(interp, varname, reg_num, + buf_get_u32(reg->value, 0, 32)); + } + + Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); + + return ERROR_OK; +} + + static int get_int_array_element(Jim_Interp *interp, const char *varname, int idx, uint32_t *val) { char *namebuf; @@ -4964,6 +5026,13 @@ static int jim_target_mem2array(Jim_Interp *interp, return target_mem2array(interp, target, argc - 1, argv + 1); } +static int jim_target_reg2array(Jim_Interp *interp, + int argc, Jim_Obj * const *argv) +{ + struct target *target = Jim_CmdPrivData(interp); + return target_reg2array(interp, target, argc - 1, argv + 1); +} + static int jim_target_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { @@ -5308,6 +5377,13 @@ static const struct command_registration target_instance_command_handlers[] = { .usage = "arrayname bitwidth address count", }, { + .name = "reg2array", + .mode = COMMAND_EXEC, + .jim_handler = jim_target_reg2array, + .help = "Load target register values into a Tcl array", + .usage = "arrayname register [register ...]", + }, + { .name = "eventlist", .handler = handle_target_event_list, .mode = COMMAND_EXEC, @@ -6363,6 +6439,13 @@ static const struct command_registration target_exec_command_handlers[] = { .usage = "filename [offset [type]]", }, { + .name = "reg2array", + .mode = COMMAND_EXEC, + .jim_handler = jim_reg2array, + .help = "Load target register values into a Tcl array", + .usage = "arrayname register [register ...]", + }, + { .name = "mem2array", .mode = COMMAND_EXEC, .jim_handler = jim_mem2array, -- _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
