aboutsummaryrefslogtreecommitdiff
path: root/src/helper/command.c
diff options
context:
space:
mode:
authorPaul Fertser <fercerpav@gmail.com>2015-03-13 16:32:53 +0300
committerPaul Fertser <fercerpav@gmail.com>2015-04-14 12:11:48 +0100
commit19f219f731f29503c8e4d432935d3ea558cc1659 (patch)
treed776e27c82b8c7f535c6043e5c275d733c7da019 /src/helper/command.c
parent33bb0fe6194b697bfc7e89338c0ffac1c54d09be (diff)
Tcl exception codes cleanup, shutdown command amendments
This patch might influence openocd Tcl commands behaviour in subtle ways, please give it a nice testing. The idea is that if an OpenOCD Tcl command returns an error, an exception is raised, and then the return code is propogated all the way up (or to the "catch" if present). This allows to detect "shutdown" which is not actually an error but has to raise an exception to stop execution of the commands that follow it in the script. openocd_thread special-cases shutdown because it should then terminate OpenOCD with a success error code, unless shutdown was called with an optional "error" argument which means terminate with a non-zero exit code. Change-Id: I7b6fa8a2e24c947dc45d8def0008b4b007c478b3 Signed-off-by: Paul Fertser <fercerpav@gmail.com> Reviewed-on: http://openocd.zylin.com/2600 Tested-by: jenkins Reviewed-by: Juha Niskanen <juha.niskanen@haltian.com> Reviewed-by: Jens Bauer <jens@gpio.dk> Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Diffstat (limited to 'src/helper/command.c')
-rw-r--r--src/helper/command.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 9d19cff4..a0aa9e85 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -121,7 +121,7 @@ static int command_retval_set(Jim_Interp *interp, int retval)
if (return_retval != NULL)
*return_retval = retval;
- return (retval == ERROR_OK) ? JIM_OK : JIM_ERR;
+ return (retval == ERROR_OK) ? JIM_OK : retval;
}
extern struct command_context *global_cmd_ctx;
@@ -659,24 +659,7 @@ int command_run_line(struct command_context *context, char *line)
}
Jim_DeleteAssocData(interp, "context");
}
- if (retcode == JIM_ERR) {
- if (retval == ERROR_COMMAND_CLOSE_CONNECTION) {
- /* Shutdown request is not an error */
- return ERROR_OK;
- } else {
- /* We do not print the connection closed error message */
- Jim_MakeErrorMessage(interp);
- LOG_USER("%s", Jim_GetString(Jim_GetResult(interp), NULL));
- }
- if (retval == ERROR_OK) {
- /* It wasn't a low level OpenOCD command that failed */
- return ERROR_FAIL;
- }
- return retval;
- } else if (retcode == JIM_EXIT) {
- /* ignore.
- * exit(Jim_GetExitCode(interp)); */
- } else {
+ if (retcode == JIM_OK) {
const char *result;
int reslen;
@@ -696,7 +679,22 @@ int command_run_line(struct command_context *context, char *line)
LOG_USER_N("\n");
}
retval = ERROR_OK;
+ } else if (retcode == JIM_EXIT) {
+ /* ignore.
+ * exit(Jim_GetExitCode(interp)); */
+ } else if (retcode == ERROR_COMMAND_CLOSE_CONNECTION) {
+ return retcode;
+ } else {
+ Jim_MakeErrorMessage(interp);
+ LOG_USER("%s", Jim_GetString(Jim_GetResult(interp), NULL));
+
+ if (retval == ERROR_OK) {
+ /* It wasn't a low level OpenOCD command that failed */
+ return ERROR_FAIL;
+ }
+ return retval;
}
+
return retval;
}