|
From: openocd-gerrit <ope...@us...> - 2023-03-25 18:10:05
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via d05c68667129705ecfd42c6029a60e849518d50c (commit)
via 1ec8b83cbdb407536966b4e455dbb39d1cb42b3a (commit)
from 5f6ceebbba3a34fc4bfcf56e963739dd2e9cf056 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d05c68667129705ecfd42c6029a60e849518d50c
Author: Antonio Borneo <bor...@gm...>
Date: Sun Dec 18 15:26:56 2022 +0100
transport: rewrite command 'transport select' as COMMAND_HANDLER
The mixed use of jim commands and OpenOCD commands is error prone
due to handling of errors through JIM_xx and ERROR_yy.
Rewrite the jim command 'transport select' as OpenOCD command.
This fixes and incorrect check for the return value of function
transport_select(); it returns ERROR_yy but the check is on JIM_xx.
While there, fix the coding style.
Change-Id: I9f3e8394c1a0cc0312b414c58275e1220217bbed
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/7485
Reviewed-by: Tomas Vanek <va...@fb...>
Tested-by: jenkins
diff --git a/src/transport/transport.c b/src/transport/transport.c
index c05db3f00..81d3d583b 100644
--- a/src/transport/transport.c
+++ b/src/transport/transport.c
@@ -252,64 +252,62 @@ COMMAND_HANDLER(handle_transport_list)
* set supported by the debug adapter being used. Return value
* is scriptable (allowing "if swd then..." etc).
*/
-static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
+COMMAND_HANDLER(handle_transport_select)
{
- int res;
- switch (argc) {
- case 1: /* autoselect if necessary, then return/display current config */
- if (!session) {
- if (!allowed_transports) {
- LOG_ERROR("Debug adapter does not support any transports? Check config file order.");
- return JIM_ERR;
- }
- LOG_INFO("auto-selecting first available session transport \"%s\". "
- "To override use 'transport select <transport>'.", allowed_transports[0]);
- res = transport_select(global_cmd_ctx, allowed_transports[0]);
- if (res != JIM_OK)
- return res;
- }
- Jim_SetResultString(interp, session->name, -1);
- return JIM_OK;
- case 2: /* assign */
- if (session) {
- if (!strcmp(session->name, argv[1]->bytes)) {
- LOG_WARNING("Transport \"%s\" was already selected", session->name);
- Jim_SetResultString(interp, session->name, -1);
- return JIM_OK;
- } else {
- LOG_ERROR("Can't change session's transport after the initial selection was made");
- return JIM_ERR;
- }
- }
+ if (CMD_ARGC > 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
- /* Is this transport supported by our debug adapter?
- * Example, "JTAG-only" means SWD is not supported.
- *
- * NOTE: requires adapter to have been set up, with
- * transports declared via C.
- */
+ if (CMD_ARGC == 0) {
+ /* autoselect if necessary, then return/display current config */
+ if (!session) {
if (!allowed_transports) {
- LOG_ERROR("Debug adapter doesn't support any transports?");
- return JIM_ERR;
+ command_print(CMD, "Debug adapter does not support any transports? Check config file order.");
+ return ERROR_FAIL;
}
+ LOG_INFO("auto-selecting first available session transport \"%s\". "
+ "To override use 'transport select <transport>'.", allowed_transports[0]);
+ int retval = transport_select(CMD_CTX, allowed_transports[0]);
+ if (retval != ERROR_OK)
+ return retval;
+ }
+ command_print(CMD, "%s", session->name);
+ return ERROR_OK;
+ }
- for (unsigned i = 0; allowed_transports[i]; i++) {
+ /* assign transport */
+ if (session) {
+ if (!strcmp(session->name, CMD_ARGV[0])) {
+ LOG_WARNING("Transport \"%s\" was already selected", session->name);
+ command_print(CMD, "%s", session->name);
+ return ERROR_OK;
+ }
+ command_print(CMD, "Can't change session's transport after the initial selection was made");
+ return ERROR_FAIL;
+ }
- if (strcmp(allowed_transports[i], argv[1]->bytes) == 0) {
- if (transport_select(global_cmd_ctx, argv[1]->bytes) == ERROR_OK) {
- Jim_SetResultString(interp, session->name, -1);
- return JIM_OK;
- }
- return JIM_ERR;
- }
- }
+ /* Is this transport supported by our debug adapter?
+ * Example, "JTAG-only" means SWD is not supported.
+ *
+ * NOTE: requires adapter to have been set up, with
+ * transports declared via C.
+ */
+ if (!allowed_transports) {
+ command_print(CMD, "Debug adapter doesn't support any transports?");
+ return ERROR_FAIL;
+ }
- LOG_ERROR("Debug adapter doesn't support '%s' transport", argv[1]->bytes);
- return JIM_ERR;
- default:
- Jim_WrongNumArgs(interp, 1, argv, "[too many parameters]");
- return JIM_ERR;
+ for (unsigned int i = 0; allowed_transports[i]; i++) {
+ if (!strcmp(allowed_transports[i], CMD_ARGV[0])) {
+ int retval = transport_select(CMD_CTX, CMD_ARGV[0]);
+ if (retval != ERROR_OK)
+ return retval;
+ command_print(CMD, "%s", session->name);
+ return ERROR_OK;
+ }
}
+
+ command_print(CMD, "Debug adapter doesn't support '%s' transport", CMD_ARGV[0]);
+ return ERROR_FAIL;
}
static const struct command_registration transport_commands[] = {
@@ -333,7 +331,7 @@ static const struct command_registration transport_commands[] = {
},
{
.name = "select",
- .jim_handler = jim_transport_select,
+ .handler = handle_transport_select,
.mode = COMMAND_ANY,
.help = "Select this session's transport",
.usage = "[transport_name]",
commit 1ec8b83cbdb407536966b4e455dbb39d1cb42b3a
Author: Antonio Borneo <bor...@gm...>
Date: Mon Dec 19 00:01:00 2022 +0100
helper: command: rewrite command 'ocd_find' as COMMAND_HANDLER
The mixed use of jim commands and OpenOCD commands is error prone
due to handling of errors through JIM_xx and ERROR_yy.
Rewrite the jim command 'ocd_find' as OpenOCD command.
Change-Id: Id775bccc12840bcf95d8c19787beda5e7c3107fc
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/7484
Reviewed-by: Tomas Vanek <va...@fb...>
Tested-by: jenkins
diff --git a/src/helper/command.c b/src/helper/command.c
index b358e18aa..235bec858 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -662,19 +662,19 @@ void command_done(struct command_context *cmd_ctx)
}
/* find full path to file */
-static int jim_find(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+COMMAND_HANDLER(handle_find)
{
- if (argc != 2)
- return JIM_ERR;
- const char *file = Jim_GetString(argv[1], NULL);
- char *full_path = find_file(file);
+ if (CMD_ARGC != 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ char *full_path = find_file(CMD_ARGV[0]);
if (!full_path)
- return JIM_ERR;
- Jim_Obj *result = Jim_NewStringObj(interp, full_path, strlen(full_path));
+ return ERROR_COMMAND_ARGUMENT_INVALID;
+
+ command_print(CMD, "%s", full_path);
free(full_path);
- Jim_SetResult(interp, result);
- return JIM_OK;
+ return ERROR_OK;
}
COMMAND_HANDLER(handle_echo)
@@ -1165,7 +1165,7 @@ static const struct command_registration command_builtin_handlers[] = {
{
.name = "ocd_find",
.mode = COMMAND_ANY,
- .jim_handler = jim_find,
+ .handler = handle_find,
.help = "find full path to file",
.usage = "file",
},
-----------------------------------------------------------------------
Summary of changes:
src/helper/command.c | 20 +++++-----
src/transport/transport.c | 100 +++++++++++++++++++++++-----------------------
2 files changed, 59 insertions(+), 61 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|