Permit null target on TCL connection 30/4730/3
authorChristopher Head <chead@zaber.com>
Thu, 18 Oct 2018 21:20:45 +0000 (14:20 -0700)
committerTomas Vanek <vanekt@fbl.cz>
Tue, 13 Nov 2018 07:02:58 +0000 (07:02 +0000)
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 bb9d9c60264a905926e0d15f84842858d0de80b7, 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>
src/server/tcl_server.c
src/target/target.c
src/target/target.h

index 3cb63a275ce37b9f693d72fc1dd1ad7ea7b03dda..0676c883b9b92551ee1d3f506bdadcf286775130 100644 (file)
@@ -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)
                tclc->tc_laststate = target->state;
 
        if (target != NULL)
                tclc->tc_laststate = target->state;
 
index 871588393b52bdf76372954722d18a4cb10206f5..74b332df5b0403b53f30e74ac2b45faf95fa7020 100644 (file)
@@ -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
-               ? cmd_ctx->current_target_override
-               : cmd_ctx->current_target;
+       struct target *target = get_current_target_or_null(cmd_ctx);
 
        if (target == NULL) {
                LOG_ERROR("BUG: current_target out of bounds");
 
        if (target == NULL) {
                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 retval;
 int target_poll(struct target *target)
 {
        int retval;
index d7961313887bcd5795b488c7e6a03d52ffbaa87c..fb9d7146587362e7ded1527ce20dbc4270daf9f2 100644 (file)
@@ -396,6 +396,7 @@ int target_call_timer_callbacks_now(void);
 
 struct target *get_target_by_num(int num);
 struct target *get_current_target(struct command_context *cmd_ctx);
 
 struct target *get_target_by_num(int num);
 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);
 
 /**

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)