aboutsummaryrefslogtreecommitdiff
path: root/src/target
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2020-05-12 00:22:13 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2021-04-18 15:32:57 +0100
commita510c8e23c23b7a888623faf0c4a9982489ddf83 (patch)
treeec3b098397f97524aa7314cbe5e361611e8d7147 /src/target
parenta9904ba22c6a8c9cd56c85296e80396c9e05ee9e (diff)
downloadriscv-openocd-a510c8e23c23b7a888623faf0c4a9982489ddf83.zip
riscv-openocd-a510c8e23c23b7a888623faf0c4a9982489ddf83.tar.gz
riscv-openocd-a510c8e23c23b7a888623faf0c4a9982489ddf83.tar.bz2
helper/command: always pass struct command as jim private data
While registering a new command, jim accepts a pointer to command's private data that will be accessible during the command execution. Today openocd is not consistent and passes different private data depending on the command, and then even overwrites it: - "simple" commands (.handler) are registered with their own struct command pointer as command private data; - "native" commands (.jim_handler) at root level are registered with NULL command private data; - "native" commands (.jim_handler) not at root level are registered with the struct command pointer of their root command as command private data but, when executed, the command private data is overwritten by the value in field jim_handler_data taken from their struct command. Uniform the usage of command private data by always set it to the struct command pointer while registering the new commands. Note: for multi-word commands only the root command is registered, so command private data will be set to the struct command of the root command. This will change later in this series when the full- name of the command will be registered. Don't overwrite the command private data, but let the commands that needs jim_handler_data to get it directly through struct command. For sake of uniformity, let function command_set_handler_data() to set the field jim_handler_data also for "group" commands, even if such value will not be used. Now Jim_CmdPrivData() always returns a struct command pointer, so wrap it in the inline function jim_to_command() to gain compile time check on the returned type. While there, uniform the code to use the macro Jim_CmdPrivData() to access the command's private data pointer. Change-Id: Idba16242ba1f6769341b4030a49cdf35a5278695 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5664 Tested-by: jenkins Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Diffstat (limited to 'src/target')
-rw-r--r--src/target/arm_tpiu_swo.c9
-rw-r--r--src/target/nds32_cmd.c15
-rw-r--r--src/target/target.c39
3 files changed, 42 insertions, 21 deletions
diff --git a/src/target/arm_tpiu_swo.c b/src/target/arm_tpiu_swo.c
index 2da52e8..543b4f0 100644
--- a/src/target/arm_tpiu_swo.c
+++ b/src/target/arm_tpiu_swo.c
@@ -559,7 +559,8 @@ static int jim_arm_tpiu_swo_configure(Jim_Interp *interp, int argc, Jim_Obj * co
"missing: -option ...");
return JIM_ERR;
}
- struct arm_tpiu_swo_object *obj = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct arm_tpiu_swo_object *obj = c->jim_handler_data;
return arm_tpiu_swo_configure(&goi, obj);
}
@@ -583,7 +584,8 @@ static int wrap_read_u32(struct target *target, struct adiv5_ap *tpiu_ap,
static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
- struct arm_tpiu_swo_object *obj = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct arm_tpiu_swo_object *obj = c->jim_handler_data;
struct command_context *cmd_ctx = current_command_context(interp);
struct adiv5_ap *tpiu_ap = dap_ap(obj->spot.dap, obj->spot.ap_num);
uint32_t value;
@@ -786,7 +788,8 @@ error_exit:
static int jim_arm_tpiu_swo_disable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
- struct arm_tpiu_swo_object *obj = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct arm_tpiu_swo_object *obj = c->jim_handler_data;
if (argc != 1) {
Jim_WrongNumArgs(interp, 1, argv, "Too many parameters");
diff --git a/src/target/nds32_cmd.c b/src/target/nds32_cmd.c
index 1684ea8..89da845 100644
--- a/src/target/nds32_cmd.c
+++ b/src/target/nds32_cmd.c
@@ -722,7 +722,8 @@ static int jim_nds32_bulk_write(Jim_Interp *interp, int argc, Jim_Obj * const *a
return JIM_ERR;
}
- struct target *target = Jim_CmdPrivData(goi.interp);
+ struct command *c = jim_to_command(goi.interp);
+ struct target *target = c->jim_handler_data;
int result;
result = target_write_buffer(target, address, count * 4, (const uint8_t *)data);
@@ -751,7 +752,8 @@ static int jim_nds32_multi_write(Jim_Interp *interp, int argc, Jim_Obj * const *
if (e != JIM_OK)
return e;
- struct target *target = Jim_CmdPrivData(goi.interp);
+ struct command *c = jim_to_command(goi.interp);
+ struct target *target = c->jim_handler_data;
struct aice_port_s *aice = target_to_aice(target);
int result;
uint32_t address;
@@ -812,7 +814,8 @@ static int jim_nds32_bulk_read(Jim_Interp *interp, int argc, Jim_Obj * const *ar
if (goi.argc != 0)
return JIM_ERR;
- struct target *target = Jim_CmdPrivData(goi.interp);
+ struct command *c = jim_to_command(goi.interp);
+ struct target *target = c->jim_handler_data;
uint32_t *data = malloc(count * sizeof(uint32_t));
int result;
result = target_read_buffer(target, address, count * 4, (uint8_t *)data);
@@ -863,7 +866,8 @@ static int jim_nds32_read_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const *
else
return ERROR_FAIL;
- struct target *target = Jim_CmdPrivData(goi.interp);
+ struct command *c = jim_to_command(goi.interp);
+ struct target *target = c->jim_handler_data;
struct aice_port_s *aice = target_to_aice(target);
char data_str[11];
@@ -911,7 +915,8 @@ static int jim_nds32_write_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const
else
return ERROR_FAIL;
- struct target *target = Jim_CmdPrivData(goi.interp);
+ struct command *c = jim_to_command(goi.interp);
+ struct target *target = c->jim_handler_data;
struct aice_port_s *aice = target_to_aice(target);
aice_write_debug_reg(aice, edm_sr_number, value);
diff --git a/src/target/target.c b/src/target/target.c
index 200368b..e481d52 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -5206,21 +5206,24 @@ static int jim_target_configure(Jim_Interp *interp, int argc, Jim_Obj * const *a
"missing: -option ...");
return JIM_ERR;
}
- struct target *target = Jim_CmdPrivData(goi.interp);
+ struct command *c = jim_to_command(goi.interp);
+ struct target *target = c->jim_handler_data;
return target_configure(&goi, target);
}
static int jim_target_mem2array(Jim_Interp *interp,
int argc, Jim_Obj *const *argv)
{
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
return target_mem2array(interp, target, argc - 1, argv + 1);
}
static int jim_target_array2mem(Jim_Interp *interp,
int argc, Jim_Obj *const *argv)
{
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
return target_array2mem(interp, target, argc - 1, argv + 1);
}
@@ -5252,7 +5255,8 @@ static int jim_target_examine(Jim_Interp *interp, int argc, Jim_Obj *const *argv
allow_defer = true;
}
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
if (!target->tap->enabled)
return jim_target_tap_disabled(interp);
@@ -5270,7 +5274,8 @@ static int jim_target_examine(Jim_Interp *interp, int argc, Jim_Obj *const *argv
static int jim_target_was_examined(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
Jim_SetResultBool(interp, target_was_examined(target));
return JIM_OK;
@@ -5278,7 +5283,8 @@ static int jim_target_was_examined(Jim_Interp *interp, int argc, Jim_Obj * const
static int jim_target_examine_deferred(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
Jim_SetResultBool(interp, target->defer_examine);
return JIM_OK;
@@ -5290,7 +5296,8 @@ static int jim_target_halt_gdb(Jim_Interp *interp, int argc, Jim_Obj *const *arg
Jim_WrongNumArgs(interp, 1, argv, "[no parameters]");
return JIM_ERR;
}
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
if (target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT) != ERROR_OK)
return JIM_ERR;
@@ -5304,7 +5311,8 @@ static int jim_target_poll(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Jim_WrongNumArgs(interp, 1, argv, "[no parameters]");
return JIM_ERR;
}
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
if (!target->tap->enabled)
return jim_target_tap_disabled(interp);
@@ -5341,7 +5349,8 @@ static int jim_target_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
if (e != JIM_OK)
return e;
- struct target *target = Jim_CmdPrivData(goi.interp);
+ struct command *c = jim_to_command(goi.interp);
+ struct target *target = c->jim_handler_data;
if (!target->tap->enabled)
return jim_target_tap_disabled(interp);
@@ -5374,7 +5383,8 @@ static int jim_target_halt(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Jim_WrongNumArgs(interp, 1, argv, "[no parameters]");
return JIM_ERR;
}
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
if (!target->tap->enabled)
return jim_target_tap_disabled(interp);
int e = target->type->halt(target);
@@ -5404,7 +5414,8 @@ static int jim_target_wait_state(Jim_Interp *interp, int argc, Jim_Obj *const *a
e = Jim_GetOpt_Wide(&goi, &a);
if (e != JIM_OK)
return e;
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
if (!target->tap->enabled)
return jim_target_tap_disabled(interp);
@@ -5448,7 +5459,8 @@ static int jim_target_current_state(Jim_Interp *interp, int argc, Jim_Obj *const
Jim_WrongNumArgs(interp, 1, argv, "[no parameters]");
return JIM_ERR;
}
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
Jim_SetResultString(interp, target_state_name(target), -1);
return JIM_OK;
}
@@ -5467,7 +5479,8 @@ static int jim_target_invoke_event(Jim_Interp *interp, int argc, Jim_Obj *const
Jim_GetOpt_NvpUnknown(&goi, nvp_target_event, 1);
return e;
}
- struct target *target = Jim_CmdPrivData(interp);
+ struct command *c = jim_to_command(interp);
+ struct target *target = c->jim_handler_data;
target_handle_event(target, n->value);
return JIM_OK;
}