From: openocd-gerrit <ope...@us...> - 2025-05-09 12:08:19
|
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 3a879c7dcb718f7e575f5a35beeb42d0f67eaa85 (commit) from b3b790e4e01331f79b196f8312193ae0130d2394 (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 3a879c7dcb718f7e575f5a35beeb42d0f67eaa85 Author: Antonio Borneo <bor...@gm...> Date: Fri Apr 18 17:04:47 2025 +0200 rtos: rework rtos_types[] and rtos_try_next() Drop the NULL sentinel at the end of the array and use ARRAY_SIZE() to bound the loops. Adapt rtos_try_next() to use ARRAY_SIZE(). While there: - change to bool the return type of rtos_try_next(); - move rtos_try_next() to avoid the forward declaration. Change-Id: I1bee11db943b670789e62f1bebe2509bbef451a0 Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: https://review.openocd.org/c/openocd/+/8855 Tested-by: jenkins diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index 5cac316ed..216129b97 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -13,6 +13,7 @@ #include "target/target.h" #include "helper/log.h" #include "helper/binarybuffer.h" +#include "helper/types.h" #include "server/gdb_server.h" static const struct rtos_type *rtos_types[] = { @@ -31,11 +32,8 @@ static const struct rtos_type *rtos_types[] = { &rtkernel_rtos, /* keep this as last, as it always matches with rtos auto */ &hwthread_rtos, - NULL }; -static int rtos_try_next(struct target *target); - int rtos_smp_init(struct target *target) { if (target->rtos->type->smp_init) @@ -116,12 +114,12 @@ int rtos_create(struct command_invocation *cmd, struct target *target, return os_alloc(target, rtos_types[0]); } - for (int x = 0; rtos_types[x]; x++) + for (size_t x = 0; x < ARRAY_SIZE(rtos_types); x++) if (strcmp(rtos_name, rtos_types[x]->name) == 0) return os_alloc_create(target, rtos_types[x]); char *all = NULL; - for (int x = 0; rtos_types[x]; x++) { + for (size_t x = 0; x < ARRAY_SIZE(rtos_types); x++) { char *prev = all; if (all) all = alloc_printf("%s, %s", all, rtos_types[x]->name); @@ -155,6 +153,29 @@ int gdb_thread_packet(struct connection *connection, char const *packet, int pac return target->rtos->gdb_thread_packet(connection, packet, packet_size); } +static bool rtos_try_next(struct target *target) +{ + struct rtos *os = target->rtos; + + if (!os) + return false; + + for (size_t x = 0; x < ARRAY_SIZE(rtos_types) - 1; x++) { + if (os->type == rtos_types[x]) { + // Use next RTOS in the list + os->type = rtos_types[x + 1]; + + free(os->symbols); + os->symbols = NULL; + + return true; + } + } + + // No next RTOS to try + return false; +} + static struct symbol_table_elem *find_symbol(const struct rtos *os, const char *symbol) { struct symbol_table_elem *s; @@ -667,28 +688,6 @@ int rtos_generic_stack_read(struct target *target, return ERROR_OK; } -static int rtos_try_next(struct target *target) -{ - struct rtos *os = target->rtos; - const struct rtos_type **type = rtos_types; - - if (!os) - return 0; - - while (*type && os->type != *type) - type++; - - if (!*type || !*(++type)) - return 0; - - os->type = *type; - - free(os->symbols); - os->symbols = NULL; - - return 1; -} - int rtos_update_threads(struct target *target) { if ((target->rtos) && (target->rtos->type)) ----------------------------------------------------------------------- Summary of changes: src/rtos/rtos.c | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) hooks/post-receive -- Main OpenOCD repository |