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>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user