From 09731b69a6f50c7e0e2f6fa0ba245374034217cb Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Sun, 30 Oct 2022 08:22:37 +0000 Subject: [PATCH] Revert "Remove duplicate of a counter in hwthread_update_threads" Commit 0cedf10f8fd6 ("Remove duplicate of a counter in hwthread_update_threads") introduced a code bug. In the second foreach_smp_target() loop, variable "threads_found" gets passed to routine hwthread_fill_thread(). By removing the counting of threads_found from the second loop, the incorrect thread counter value gets passed to hwthread_fill_thread(). Change-Id: Ie89e53ccd28bb72b6838ef2f12106a1fe8d00994 Suggested-by: Daniel Goehring Signed-off-by: Tomas Vanek Reviewed-on: https://review.openocd.org/c/openocd/+/7307 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/rtos/hwthread.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rtos/hwthread.c b/src/rtos/hwthread.c index bdd5835c27..e5eaf425f6 100644 --- a/src/rtos/hwthread.c +++ b/src/rtos/hwthread.c @@ -78,6 +78,7 @@ static int hwthread_fill_thread(struct rtos *rtos, struct target *curr, int thre static int hwthread_update_threads(struct rtos *rtos) { int threads_found = 0; + int thread_list_size = 0; struct target_list *head; struct target *target; int64_t current_thread = 0; @@ -99,13 +100,13 @@ static int hwthread_update_threads(struct rtos *rtos) if (!target_was_examined(curr)) continue; - ++threads_found; + ++thread_list_size; } } else - threads_found = 1; + thread_list_size = 1; /* create space for new thread details */ - rtos->thread_details = malloc(sizeof(struct thread_detail) * threads_found); + rtos->thread_details = malloc(sizeof(struct thread_detail) * thread_list_size); if (target->smp) { /* loop over all threads */ @@ -170,10 +171,13 @@ static int hwthread_update_threads(struct rtos *rtos) default: break; } + + threads_found++; } } else { hwthread_fill_thread(rtos, target, threads_found); current_thread = threadid_from_target(target); + threads_found++; } rtos->thread_count = threads_found; -- 2.30.2