aboutsummaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
authorChristopher Head <chead@zaber.com>2019-06-07 11:40:25 -0700
committerTomas Vanek <vanekt@fbl.cz>2019-06-20 19:50:22 +0100
commit77a8914b7f960a304406ba4fd39b410c50f25be8 (patch)
tree13fe02d3e71ae0177b067c7f3e18d7bd3fd3bae8 /src/helper
parent23b6aa9bf864d8e8648394b72f62611f442cc6d0 (diff)
downloadriscv-openocd-77a8914b7f960a304406ba4fd39b410c50f25be8.zip
riscv-openocd-77a8914b7f960a304406ba4fd39b410c50f25be8.tar.gz
riscv-openocd-77a8914b7f960a304406ba4fd39b410c50f25be8.tar.bz2
helper/command: make command_run_line reentrant
The `command_run_line` function contains a comment saying it should be reentrant. However, it isn’t: it NULLs out `current_target_override` and doesn’t restore it before returning, and it changes the `context` associated data of the `interp` object and then deletes that associated data before returning rather than restoring it to its previous value. Change-Id: I84fd46ef7173f08cf7c57b9a5b76e4986a60816f Signed-off-by: Christopher Head <chead@zaber.com> Reviewed-on: http://openocd.zylin.com/5223 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/command.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index ab0654b..7b93df6 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -652,9 +652,11 @@ int command_run_line(struct command_context *context, char *line)
* happen when the Jim Tcl interpreter is provided by eCos for
* instance.
*/
+ struct target *saved_target_override = context->current_target_override;
context->current_target_override = NULL;
Jim_Interp *interp = context->interp;
+ struct command_context *old_context = Jim_GetAssocData(interp, "context");
Jim_DeleteAssocData(interp, "context");
retcode = Jim_SetAssocData(interp, "context", NULL, context);
if (retcode == JIM_OK) {
@@ -667,7 +669,11 @@ int command_run_line(struct command_context *context, char *line)
Jim_DeleteAssocData(interp, "retval");
}
Jim_DeleteAssocData(interp, "context");
+ int inner_retcode = Jim_SetAssocData(interp, "context", NULL, old_context);
+ if (retcode == JIM_OK)
+ retcode = inner_retcode;
}
+ context->current_target_override = saved_target_override;
if (retcode == JIM_OK) {
const char *result;
int reslen;