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>
This commit is contained in:
Paul Fertser
2015-03-13 16:32:53 +03:00
parent 33bb0fe619
commit 19f219f731
6 changed files with 48 additions and 30 deletions

View File

@@ -44,7 +44,8 @@
static struct service *services;
/* shutdown_openocd == 1: exit the main event loop, and quit the debugger */
/* shutdown_openocd == 1: exit the main event loop, and quit the
* debugger; 2: quit with non-zero return code */
static int shutdown_openocd;
/* store received signal to exit application by killing ourselves */
@@ -499,7 +500,7 @@ int server_loop(struct command_context *command_context)
#endif
}
return ERROR_OK;
return shutdown_openocd != 2 ? ERROR_OK : ERROR_FAIL;
}
#ifdef _WIN32
@@ -608,6 +609,13 @@ COMMAND_HANDLER(handle_shutdown_command)
shutdown_openocd = 1;
if (CMD_ARGC == 1) {
if (!strcmp(CMD_ARGV[0], "error")) {
shutdown_openocd = 2;
return ERROR_FAIL;
}
}
return ERROR_COMMAND_CLOSE_CONNECTION;
}