This is an automated email from Gerrit.

"Tomas Vanek <van...@fbl.cz>" just uploaded a new patch set to Gerrit, which 
you can find at https://review.openocd.org/c/openocd/+/8925

-- gerrit

commit 644c98357558a51dbb979d0222f5b1704dd93619
Author: Tomas Vanek <van...@fbl.cz>
Date:   Mon May 19 16:29:26 2025 +0200

    target, server, rtos: introduce and use target_is_available() helper
    
    Use the new helper function instead of TARGET_UNAVAILABLE tests
    imported from riscv-collab.
    
    Later we can extend TARGET_UNAVAILABLE testing by simply replacing most
    of target_was_examined() tests by target_is_available()
    
    Change-Id: If024cc2e8ed02dbcb68ca660dfd929882aff1035
    Signed-off-by: Tomas Vanek <van...@fbl.cz>

diff --git a/src/rtos/hwthread.c b/src/rtos/hwthread.c
index 5c6c45f78f..4156236c68 100644
--- a/src/rtos/hwthread.c
+++ b/src/rtos/hwthread.c
@@ -105,8 +105,7 @@ static int hwthread_update_threads(struct rtos *rtos)
                foreach_smp_target(head, target->smp_targets) {
                        struct target *curr = head->target;
 
-                       if (!target_was_examined(curr) ||
-                                       curr->state == TARGET_UNAVAILABLE)
+                       if (!target_is_available(curr))
                                continue;
 
                        ++thread_list_size;
@@ -131,8 +130,7 @@ static int hwthread_update_threads(struct rtos *rtos)
                foreach_smp_target(head, target->smp_targets) {
                        struct target *curr = head->target;
 
-                       if (!target_was_examined(curr) ||
-                                       curr->state == TARGET_UNAVAILABLE)
+                       if (!target_is_available(curr))
                                continue;
 
                        threadid_t tid = threadid_from_target(curr);
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index 580a96d98f..512a7e7f7b 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -159,11 +159,11 @@ struct target 
*get_available_target_from_connection(struct connection *connectio
 {
        struct gdb_service *gdb_service = connection->service->priv;
        struct target *target = gdb_service->target;
-       if (target->state == TARGET_UNAVAILABLE && target->smp) {
+       if (!target_is_available(target) && target->smp) {
                struct target_list *tlist;
                foreach_smp_target(tlist, target->smp_targets) {
                        struct target *t = tlist->target;
-                       if (t->state != TARGET_UNAVAILABLE)
+                       if (target_is_available(t))
                                return t;
                }
                /* If we can't find an available target, just return the
@@ -3043,7 +3043,7 @@ static bool gdb_handle_vcont_packet(struct connection 
*connection, const char *p
        if (parse[0] == 'c') {
                gdb_running_type = 'c';
 
-               if (target->state == TARGET_UNAVAILABLE) {
+               if (!target_is_available(target)) {
                        struct target *available_target = 
get_available_target_from_connection(connection);
                        if (target == available_target) {
                                LOG_DEBUG("All targets for this gdb connection "
@@ -3188,7 +3188,7 @@ static bool gdb_handle_vcont_packet(struct connection 
*connection, const char *p
                        return true;
                }
 
-               if (ct->state == TARGET_UNAVAILABLE) {
+               if (!target_is_available(ct)) {
                        LOG_TARGET_INFO(ct, "Target is unavailable, so cannot 
be stepped. "
                                "Pretending to gdb that it is running until 
it's available again.");
                        retval = ERROR_FAIL;
diff --git a/src/target/target.h b/src/target/target.h
index b850b49cf3..89dd7be4aa 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -434,6 +434,13 @@ static inline bool target_was_examined(const struct target 
*target)
        return target->examined;
 }
 
+/** @returns @c true if target is available: was examined
+ * and is not in TARGET_UNAVAILABLE state */
+static inline bool target_is_available(const struct target *target)
+{
+       return target_was_examined(target) && target->state != 
TARGET_UNAVAILABLE;
+}
+
 /** Sets the @c examined flag for the given target. */
 /** Use in target->type->examine() after one-time setup is done. */
 static inline void target_set_examined(struct target *target)

-- 

Reply via email to