Permit null target on TCL connection
In previous versions of OpenOCD, it was possible to connect to the TCL
RPC interface without a current target. In `tcl_new_connection`, the
curent target would be queried by number, and the possibility of a null
current target was handled properly.
In commit bb9d9c6026
, the
`get_target_by_num` call was replaced by a `get_current_target` call,
without noticing that `get_current_target` aborts if there is no current
target, whereas `tcl_new_connection` is perfectly able to handle that
situation.
Provide a `get_current_target_or_null` function for use by consumers who
are OK with a null current target, and use it in `tcl_new_connection`.
Change-Id: I06f7e1e149f1169e23c73ba328c7ad9f9425cc2a
Signed-off-by: Christopher Head <chead@zaber.com>
Reviewed-on: http://openocd.zylin.com/4730
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Franck Jullien <franck.jullien@gmail.com>
bscan_tunnel
parent
8d914e4d97
commit
ea41048830
|
@ -157,7 +157,7 @@ static int tcl_new_connection(struct connection *connection)
|
||||||
|
|
||||||
connection->priv = tclc;
|
connection->priv = tclc;
|
||||||
|
|
||||||
struct target *target = get_current_target(connection->cmd_ctx);
|
struct target *target = get_current_target_or_null(connection->cmd_ctx);
|
||||||
if (target != NULL)
|
if (target != NULL)
|
||||||
tclc->tc_laststate = target->state;
|
tclc->tc_laststate = target->state;
|
||||||
|
|
||||||
|
|
|
@ -517,9 +517,7 @@ struct target *get_target_by_num(int num)
|
||||||
|
|
||||||
struct target *get_current_target(struct command_context *cmd_ctx)
|
struct target *get_current_target(struct command_context *cmd_ctx)
|
||||||
{
|
{
|
||||||
struct target *target = cmd_ctx->current_target_override
|
struct target *target = get_current_target_or_null(cmd_ctx);
|
||||||
? cmd_ctx->current_target_override
|
|
||||||
: cmd_ctx->current_target;
|
|
||||||
|
|
||||||
if (target == NULL) {
|
if (target == NULL) {
|
||||||
LOG_ERROR("BUG: current_target out of bounds");
|
LOG_ERROR("BUG: current_target out of bounds");
|
||||||
|
@ -529,6 +527,13 @@ struct target *get_current_target(struct command_context *cmd_ctx)
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct target *get_current_target_or_null(struct command_context *cmd_ctx)
|
||||||
|
{
|
||||||
|
return cmd_ctx->current_target_override
|
||||||
|
? cmd_ctx->current_target_override
|
||||||
|
: cmd_ctx->current_target;
|
||||||
|
}
|
||||||
|
|
||||||
int target_poll(struct target *target)
|
int target_poll(struct target *target)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
|
|
@ -396,6 +396,7 @@ int target_call_timer_callbacks_now(void);
|
||||||
|
|
||||||
struct target *get_target_by_num(int num);
|
struct target *get_target_by_num(int num);
|
||||||
struct target *get_current_target(struct command_context *cmd_ctx);
|
struct target *get_current_target(struct command_context *cmd_ctx);
|
||||||
|
struct target *get_current_target_or_null(struct command_context *cmd_ctx);
|
||||||
struct target *get_target(const char *id);
|
struct target *get_target(const char *id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue