diff options
author | Angus Gratton <gus@projectgus.com> | 2015-02-25 08:19:15 +1100 |
---|---|---|
committer | Spencer Oliver <spen@spen-soft.co.uk> | 2015-03-25 21:32:49 +0000 |
commit | d90b86d8e35f4f681eb341ca534985eb1046cc59 (patch) | |
tree | 17296b2511be7e3235f7d7dc4f073f1c6d624e98 /src | |
parent | 492bab62abe6e94a302899ed19af7e1b23365e78 (diff) |
transport: make 'transport select' auto-select the first available transport if not set
This should allow most of the existing configurations for older
versions to remain compatible without forcing the user to change his
or her config to explicitly select transport.
Also in some circumstances can remove the need to chain a "-c transport
select X" when building custom configs on the command line, which seems
like a common new user pitfall.
Change-Id: Ic87a38c0b9b88e88fb6d106385efce2f39381d3d
Suggested-by: Petteri Aimonen <jpa@git.mail.kapsi.fi>
Signed-off-by: Angus Gratton <gus@projectgus.com>
Reviewed-on: http://openocd.zylin.com/2551
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/transport.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/transport/transport.c b/src/transport/transport.c index c57064bb..c973e1c3 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -275,20 +275,28 @@ COMMAND_HANDLER(handle_transport_list) */ static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj * const *argv) { + int res; switch (argc) { - case 1: /* return/display */ + case 1: /* autoselect if necessary, then return/display current config */ if (!session) { - LOG_ERROR("session transport was not selected. Use 'transport select <transport>'"); - return JIM_ERR; - } else { - Jim_SetResultString(interp, session->name, -1); - return JIM_OK; + 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; break; - case 2: /* assign */ + 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"); @@ -309,8 +317,13 @@ static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj * const *a for (unsigned i = 0; allowed_transports[i]; i++) { - if (strcmp(allowed_transports[i], argv[1]->bytes) == 0) - return transport_select(global_cmd_ctx, argv[1]->bytes); + 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; + } } LOG_ERROR("Debug adapter doesn't support '%s' transport", argv[1]->bytes); |