diff --git a/src/helper/command.c b/src/helper/command.c index ab0654b6e..7b93df6e1 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;