This is an automated email from Gerrit.

"Tomas Vanek <[email protected]>" just uploaded a new patch set to Gerrit, which 
you can find at https://review.openocd.org/c/openocd/+/9180

-- gerrit

commit 9c021e898697725cd6ad583ecfee2a90307cace0
Author: Tomas Vanek <[email protected]>
Date:   Wed Oct 22 21:57:59 2025 +0200

    target: introduce active_polled flag in struct target
    
    The spliting of examined status to two partialy independent flags
    resolves the dirty hack of setting examined after failed examine call
    in handle_target() and ambiguity in the examined flag usage.
    
    Change-Id: I16567248f81d6b096d864ef11480e6c611398494
    Signed-off-by: Tomas Vanek <[email protected]>

diff --git a/src/target/target.c b/src/target/target.c
index 75dd01e2cc..05f1fe361e 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -658,13 +658,17 @@ static int no_mmu(struct target *target, bool *enabled)
 
 /**
  * Reset the @c examined flag for the given target.
- * Pure paranoia -- targets are zeroed on allocation.
  */
 static inline void target_reset_examined(struct target *target)
 {
        target->examined = false;
 }
 
+static inline void target_reset_active_polled(struct target *target)
+{
+       target->active_polled = false;
+}
+
 static int default_examine(struct target *target)
 {
        target_set_examined(target);
@@ -1495,6 +1499,7 @@ static int target_init_one(struct command_context 
*cmd_ctx,
                struct target *target)
 {
        target_reset_examined(target);
+       target_reset_active_polled(target);
 
        struct target_type *type = target->type;
        if (!type->examine)
@@ -2934,7 +2939,7 @@ static int handle_target(void *priv)
                        is_jtag_poll_safe() && target;
                        target = target->next) {
 
-               if (!target_was_examined(target))
+               if (!target_active_polled(target))
                        continue;
 
                if (!target->tap->enabled)
@@ -2967,10 +2972,7 @@ static int handle_target(void *priv)
                                LOG_TARGET_ERROR(target, "Polling failed, 
trying to reexamine");
                                target_reset_examined(target);
                                retval = target_examine_one(target);
-                               /* Target examination could have failed due to 
unstable connection,
-                                * but we set the examined flag anyway to 
repoll it later */
                                if (retval != ERROR_OK) {
-                                       target_set_examined(target);
                                        LOG_TARGET_ERROR(target, "Examination 
failed, GDB will be halted. Polling again in %dms",
                                                 target->backoff.times * 
polling_interval);
                                        return retval;
@@ -5361,8 +5363,10 @@ COMMAND_HANDLER(handle_target_reset)
        /* do the assert */
        if (n->value == NVP_ASSERT) {
                int retval = target->type->assert_reset(target);
-               if (target->defer_examine)
+               if (target->defer_examine) {
                        target_reset_examined(target);
+                       target_reset_active_polled(target);
+               }
                return retval;
        }
 
diff --git a/src/target/target.h b/src/target/target.h
index ab3b1e59d0..882339ded3 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -126,12 +126,19 @@ struct target {
        bool defer_examine;
 
        /**
-        * Indicates whether this target has been examined.
+        * Indicates whether this target has been examined,
+        * remembers the last result of examine call.
         *
         * Do @b not access this field directly, use target_was_examined()
         * or target_set_examined().
         */
        bool examined;
+       /**
+        * The flag is set after a successful examine call.
+        * It remains set forever or in the case of defer examine
+        * gets reset by reset command.
+        */
+       bool active_polled;
 
        /**
         * true if the  target is currently running a downloaded
@@ -428,16 +435,26 @@ const char *target_type_name(const struct target *target);
  */
 int target_examine_one(struct target *target);
 
-/** @returns @c true if target_set_examined() has been called. */
+/** @returns @c true if target_set_examined() has been called.
+ *  The returned value reflects the last examination result. */
 static inline bool target_was_examined(const struct target *target)
 {
        return target->examined;
 }
 
-/** Sets the @c examined flag for the given target. */
+/** @returns @c true if target_set_examined() has been called.
+ *  The flag remains set forever or in the case of defer examine
+ *  gets reset by reset command */
+static inline bool target_active_polled(const struct target *target)
+{
+       return target->active_polled;
+}
+
+/** Sets the @c examined and @c active_polled flags for the given target. */
 /** Use in target->type->examine() after one-time setup is done. */
 static inline void target_set_examined(struct target *target)
 {
+       target->active_polled = true;
        target->examined = true;
 }
 

-- 

Reply via email to