target: do not print an error on shutdown in target events

Before commit b3ce5a0ae5 ("target: use LOG_USER to print errors
in events") an error in an event handler was silently lost, while
now the associated message is printed out.

A "shutdown" command in a target event (e.g. in gdb-detach) causes
the event to end with error code ERROR_COMMAND_CLOSE_CONNECTION,
that triggers the error message:
	shutdown command invoked
	Error executing event <event-name> on target <target-name>:

The error code returned by the command "shutdown" is required to
stop the execution in a script/proc and avoid executing any
further command in the script/proc.
It is then normal to get an error code from the "shutdown" command
and it should not be printed out.

Intercept the return code of the event in case of "shutdown", then
skip scheduling other target events and return without printing
the incorrect error message.

Change-Id: Ia3085fb46beacb90a5e4bf0abf7c6e28bb9e6a9b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Laurent Lemele <laurent.lemele@st.com>
Reviewed-on: http://openocd.zylin.com/5710
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2020-06-02 14:43:29 +02:00
parent 64733434e2
commit 7c88e76a76
1 changed files with 6 additions and 2 deletions

View File

@ -4582,8 +4582,14 @@ void target_handle_event(struct target *target, enum target_event e)
struct command_context *cmd_ctx = current_command_context(teap->interp);
struct target *saved_target_override = cmd_ctx->current_target_override;
cmd_ctx->current_target_override = target;
retval = Jim_EvalObj(teap->interp, teap->body);
cmd_ctx->current_target_override = saved_target_override;
if (retval == ERROR_COMMAND_CLOSE_CONNECTION)
return;
if (retval == JIM_RETURN)
retval = teap->interp->returnCode;
@ -4596,8 +4602,6 @@ void target_handle_event(struct target *target, enum target_event e)
/* clean both error code and stacktrace before return */
Jim_Eval(teap->interp, "error \"\" \"\"");
}
cmd_ctx->current_target_override = saved_target_override;
}
}
}