This is an automated email from Gerrit.

"Tim Newsome <t...@sifive.com>" just uploaded a new patch set to Gerrit, which 
you can find at https://review.openocd.org/c/openocd/+/6964

-- gerrit

commit 3f7599d09ee5a4e6d4431926371ff2d69b5c9829
Author: Tim Newsome <t...@sifive.com>
Date:   Thu Oct 21 17:08:49 2021 -0700

    Properly handle held-in-reset targets.
    
    * Properly handle held-in-reset targets.
    
    1. Let OpenOCD continue into some pre-existing code that will periodically
       call examine() until it passes.
    2. Fix crash in riscv_openocd_poll()
       When SMP is configured, it's not guaranteed that all targets have been
       examine()d when poll is called on one of them.
    3. Actually poll for examine at least every 5s.
    
    See https://github.com/riscv/riscv-openocd/pull/654
    
    Change-Id: Id865f191f0fbb48abece8b8558cc9fa2041a26df
    Signed-off-by: Tim Newsome <t...@sifive.com>

diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index 2b9179d538..a4d52aa17b 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -653,10 +653,10 @@ static int dmi_op(struct target *target, uint32_t 
*data_in,
        int result = dmi_op_timeout(target, data_in, dmi_busy_encountered, 
dmi_op,
                        address, data_out, riscv_command_timeout_sec, exec, 
ensure_success);
        if (result == ERROR_TIMEOUT_REACHED) {
-               LOG_ERROR("DMI operation didn't complete in %d seconds. The 
target is "
+               LOG_ERROR("[%s] DMI operation didn't complete in %d seconds. 
The target is "
                                "either really slow or broken. You could 
increase the "
                                "timeout with riscv set_command_timeout_sec.",
-                               riscv_command_timeout_sec);
+                               target_name(target), riscv_command_timeout_sec);
                return ERROR_FAIL;
        }
        return result;
@@ -864,8 +864,8 @@ static uint32_t access_register_command(struct target 
*target, uint32_t number,
                        command = set_field(command, 
AC_ACCESS_REGISTER_AARSIZE, 3);
                        break;
                default:
-                       LOG_ERROR("%d-bit register %s not supported.", size,
-                                       gdb_regno_name(number));
+                       LOG_ERROR("[%s] %d-bit register %s not supported.",
+                                       target_name(target), size, 
gdb_regno_name(number));
                        assert(0);
        }
 
@@ -1576,8 +1576,8 @@ static int examine(struct target *target)
                return ERROR_FAIL;
        }
        if (get_field(dtmcontrol, DTM_DTMCS_VERSION) != 1) {
-               LOG_ERROR("Unsupported DTM version %d. (dtmcontrol=0x%x)",
-                               get_field(dtmcontrol, DTM_DTMCS_VERSION), 
dtmcontrol);
+               LOG_ERROR("[%s] Unsupported DTM version %d. (dtmcontrol=0x%x)",
+                               target_name(target), get_field(dtmcontrol, 
DTM_DTMCS_VERSION), dtmcontrol);
                return ERROR_FAIL;
        }
 
@@ -1662,7 +1662,8 @@ static int examine(struct target *target)
        info->datacount = get_field(abstractcs, DM_ABSTRACTCS_DATACOUNT);
        info->progbufsize = get_field(abstractcs, DM_ABSTRACTCS_PROGBUFSIZE);
 
-       LOG_INFO("datacount=%d progbufsize=%d", info->datacount, 
info->progbufsize);
+       LOG_INFO("[%s] datacount=%d progbufsize=%d", target_name(target),
+                       info->datacount, info->progbufsize);
 
        RISCV_INFO(r);
        r->impebreak = get_field(dmstatus, DM_DMSTATUS_IMPEBREAK);
@@ -1719,7 +1720,8 @@ static int examine(struct target *target)
        bool halted = riscv_is_halted(target);
        if (!halted) {
                if (riscv013_halt_go(target) != ERROR_OK) {
-                       LOG_ERROR("Fatal: Hart %d failed to halt during 
examine()", r->current_hartid);
+                       LOG_ERROR("[%s] Fatal: Hart %d failed to halt during 
examine()",
+                                       target_name(target), r->current_hartid);
                        return ERROR_FAIL;
                }
        }
@@ -1749,7 +1751,7 @@ static int examine(struct target *target)
                return ERROR_FAIL;
 
        /* Display this as early as possible to help people who are using
-               * really slow simulators. */
+        * really slow simulators. */
        LOG_DEBUG(" hart %d: XLEN=%d, misa=0x%" PRIx64, r->current_hartid, 
r->xlen,
                        r->misa);
 
@@ -4234,9 +4236,8 @@ static int riscv013_halt_go(struct target *target)
                if (dmi_read(target, &dmcontrol, DM_DMCONTROL) != ERROR_OK)
                        return ERROR_FAIL;
 
-               LOG_ERROR("unable to halt hart %d", r->current_hartid);
-               LOG_ERROR("  dmcontrol=0x%08x", dmcontrol);
-               LOG_ERROR("  dmstatus =0x%08x", dmstatus);
+               LOG_ERROR("[%s] Unable to halt hart %d. dmcontrol=0x%08x, 
dmstatus=0x%08x",
+                                 target_name(target), r->current_hartid, 
dmcontrol, dmstatus);
                return ERROR_FAIL;
        }
 
diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c
index a266f5da3a..9e0701faa6 100644
--- a/src/target/riscv/riscv.c
+++ b/src/target/riscv/riscv.c
@@ -418,7 +418,8 @@ static struct target_type *get_target_type(struct target 
*target)
                case 1:
                        return &riscv013_target;
                default:
-                       LOG_ERROR("Unsupported DTM version: %d", 
info->dtm_version);
+                       LOG_ERROR("[%s] Unsupported DTM version: %d",
+                                       target_name(target), info->dtm_version);
                        return NULL;
        }
 }
@@ -1112,10 +1113,9 @@ static int old_or_new_riscv_step(struct target *target, 
int current,
                return riscv_openocd_step(target, current, address, 
handle_breakpoints);
 }
 
-
 static int riscv_examine(struct target *target)
 {
-       LOG_DEBUG("riscv_examine()");
+       LOG_DEBUG("[%s]", target_name(target));
        if (target_was_examined(target)) {
                LOG_DEBUG("Target was already examined.");
                return ERROR_OK;
@@ -2084,7 +2084,8 @@ static enum riscv_poll_hart riscv_poll_hart(struct target 
*target, int hartid)
        if (riscv_set_current_hartid(target, hartid) != ERROR_OK)
                return RPH_ERROR;
 
-       LOG_DEBUG("polling hart %d, target->state=%d", hartid, target->state);
+       LOG_DEBUG("[%s] polling hart %d, target->state=%d", target_name(target),
+                       hartid, target->state);
 
        /* If OpenOCD thinks we're running but this hart is halted then it's 
time
         * to raise an event. */
@@ -2189,6 +2190,8 @@ int riscv_openocd_poll(struct target *target)
                struct target_list *list;
                foreach_smp_target(list, target->smp_targets) {
                        struct target *t = list->target;
+                       if (!target_was_examined(t))
+                               continue;
                        riscv_info_t *r = riscv_info(t);
                        enum riscv_poll_hart out = riscv_poll_hart(t, 
r->current_hartid);
                        switch (out) {
@@ -3882,8 +3885,8 @@ int riscv_init_registers(struct target *target)
                        target->reg_cache->num_regs += entry->high - entry->low 
+ 1;
        }
 
-       LOG_DEBUG("create register cache for %d registers",
-                       target->reg_cache->num_regs);
+       LOG_DEBUG("[%s] create register cache for %d registers",
+                       target_name(target), target->reg_cache->num_regs);
 
        target->reg_cache->reg_list =
                calloc(target->reg_cache->num_regs, sizeof(struct reg));
diff --git a/src/target/target.c b/src/target/target.c
index 690526eb75..53b75b98ff 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -762,6 +762,7 @@ int target_examine_one(struct target *target)
                return retval;
        }
 
+       LOG_USER("[%s] Target successfully examined.", target_name(target));
        target_set_examined(target);
        target_call_event_callbacks(target, TARGET_EVENT_EXAMINE_END);
 
@@ -3037,9 +3038,6 @@ static int handle_target(void *priv)
                        is_jtag_poll_safe() && target;
                        target = target->next) {
 
-               if (!target_was_examined(target))
-                       continue;
-
                if (!target->tap->enabled)
                        continue;
 
@@ -3056,10 +3054,9 @@ static int handle_target(void *priv)
                        retval = target_poll(target);
                        if (retval != ERROR_OK) {
                                /* 100ms polling interval. Increase interval 
between polling up to 5000ms */
-                               if (target->backoff.times * polling_interval < 
5000) {
-                                       target->backoff.times *= 2;
-                                       target->backoff.times++;
-                               }
+                               if (target->backoff.times * polling_interval < 
5000)
+                                       target->backoff.times = 
MIN(target->backoff.times * 2 + 1,
+                                                                               
                5000 / polling_interval);
 
                                /* Tell GDB to halt the debugger. This allows 
the user to
                                 * run monitor commands to handle the situation.
@@ -3067,15 +3064,12 @@ static int handle_target(void *priv)
                                target_call_event_callbacks(target, 
TARGET_EVENT_GDB_HALT);
                        }
                        if (target->backoff.times > 0) {
-                               LOG_USER("Polling target %s failed, trying to 
reexamine", target_name(target));
+                               LOG_DEBUG("[%s] Polling failed, trying to 
reexamine", target_name(target));
                                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_USER("Examination failed, GDB will 
be halted. Polling again in %dms",
-                                                target->backoff.times * 
polling_interval);
+                                       LOG_DEBUG("[%s] Examination failed, GDB 
will be halted. Polling again in %dms",
+                                                target_name(target), 
target->backoff.times * polling_interval);
                                        return retval;
                                }
                        }

-- 

Reply via email to