This is an automated email from Gerrit. "Tarek BOCHKATI <[email protected]>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/6548
-- gerrit commit a94844f7ff5244671bf3b776a26d45dc99e4495a Author: Tarek BOCHKATI <[email protected]> Date: Mon Sep 6 14:36:39 2021 +0100 target: centralize the reset/set of target examine flag this change permits to take into consideration the return value of target->examine. For example: before this change in cortex_m_examine, if we fail reading CPUID we return a failure code but target was set to examined which is not consistent. Change-Id: I9f0ebe8f811849e54d1b350b0db506cb3fdd58f4 Signed-off-by: Tarek BOCHKATI <[email protected]> diff --git a/src/target/aarch64.c b/src/target/aarch64.c index 70e727cf9..907ac0453 100644 --- a/src/target/aarch64.c +++ b/src/target/aarch64.c @@ -2677,7 +2677,6 @@ static int aarch64_examine_first(struct target *target) target->state = TARGET_UNKNOWN; target->debug_reason = DBG_REASON_NOTHALTED; aarch64->isrmasking_mode = AARCH64_ISRMASK_ON; - target_set_examined(target); return ERROR_OK; } diff --git a/src/target/arc.c b/src/target/arc.c index 4b546c3b4..82dd72847 100644 --- a/src/target/arc.c +++ b/src/target/arc.c @@ -741,8 +741,6 @@ static int arc_examine(struct target *target) /* Read BCRs and configure optional registers. */ CHECK_RETVAL(arc_configure(target)); - - target_set_examined(target); } return ERROR_OK; diff --git a/src/target/arm11.c b/src/target/arm11.c index e3b0975fb..ddc219115 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -1238,8 +1238,6 @@ static int arm11_examine(struct target *target) CHECK_RETVAL(etm_setup(target)); } - target_set_examined(target); - return ERROR_OK; } diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index cf77a81a7..c76494bed 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -2686,8 +2686,6 @@ int arm7_9_examine(struct target *target) (*cache_p)->next = etm_build_reg_cache(target, &arm7_9->jtag_info, arm7_9->arm.etm); - - target_set_examined(target); } retval = embeddedice_setup(target); diff --git a/src/target/avr32_ap7k.c b/src/target/avr32_ap7k.c index 4cf0276d6..fc6206681 100644 --- a/src/target/avr32_ap7k.c +++ b/src/target/avr32_ap7k.c @@ -538,7 +538,6 @@ static int avr32_ap7k_examine(struct target *target) struct avr32_ap7k_common *ap7k = target_to_ap7k(target); if (!target_was_examined(target)) { - target_set_examined(target); avr32_jtag_nexus_read(&ap7k->jtag, AVR32_OCDREG_DID, &devid); LOG_INFO("device id: %08" PRIx32, devid); avr32_ocd_setbits(&ap7k->jtag, AVR32_OCDREG_DC, OCDREG_DC_DBE); diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index b1f22067f..79d3fea23 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -3067,7 +3067,6 @@ static int cortex_a_examine_first(struct target *target) /* select debug_ap as default */ swjdp->apsel = armv7a->debug_ap->ap_num; - target_set_examined(target); return ERROR_OK; } diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 08f2eb911..aad64a551 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2057,8 +2057,6 @@ int cortex_m_examine(struct target *target) } if (!target_was_examined(target)) { - target_set_examined(target); - /* Read from Device Identification Registers */ retval = target_read_u32(target, CPUID, &cpuid); if (retval != ERROR_OK) diff --git a/src/target/dsp563xx.c b/src/target/dsp563xx.c index 0d80ed367..8436b03b5 100644 --- a/src/target/dsp563xx.c +++ b/src/target/dsp563xx.c @@ -929,7 +929,6 @@ static int dsp563xx_examine(struct target *target) } if (!target_was_examined(target)) { - target_set_examined(target); /* examine core and chip derivate number */ chip = (target->tap->idcode>>12) & 0x3ff; diff --git a/src/target/esirisc.c b/src/target/esirisc.c index e49f5f659..d48662ba1 100644 --- a/src/target/esirisc.c +++ b/src/target/esirisc.c @@ -1648,8 +1648,6 @@ static int esirisc_examine(struct target *target) } } - target_set_examined(target); - LOG_INFO("%s: %d bit, %d registers, %s%s%s", target_name(target), esirisc->num_bits, esirisc->num_regs, target_endianness(target), diff --git a/src/target/mem_ap.c b/src/target/mem_ap.c index eef05b44b..88e3eb4b6 100644 --- a/src/target/mem_ap.c +++ b/src/target/mem_ap.c @@ -140,7 +140,6 @@ static int mem_ap_examine(struct target *target) if (!target_was_examined(target)) { mem_ap->ap = dap_ap(mem_ap->dap, mem_ap->ap_num); - target_set_examined(target); target->state = TARGET_UNKNOWN; target->debug_reason = DBG_REASON_UNDEFINED; return mem_ap_init(mem_ap->ap); diff --git a/src/target/mips32.c b/src/target/mips32.c index c82536931..c2130c9fa 100644 --- a/src/target/mips32.c +++ b/src/target/mips32.c @@ -547,8 +547,6 @@ int mips32_examine(struct target *target) struct mips32_common *mips32 = target_to_mips32(target); if (!target_was_examined(target)) { - target_set_examined(target); - /* we will configure later */ mips32->bp_scanned = 0; mips32->num_inst_bpoints = 0; diff --git a/src/target/mips64.c b/src/target/mips64.c index 347cdfc4b..467c04d27 100644 --- a/src/target/mips64.c +++ b/src/target/mips64.c @@ -479,8 +479,6 @@ int mips64_examine(struct target *target) mips64->num_inst_bpoints = 0; mips64->num_inst_bpoints_avail = 0; - target_set_examined(target); - return ERROR_OK; } diff --git a/src/target/nds32_v2.c b/src/target/nds32_v2.c index 49a5758f7..fb2c6185f 100644 --- a/src/target/nds32_v2.c +++ b/src/target/nds32_v2.c @@ -630,8 +630,6 @@ static int nds32_v2_examine(struct target *target) nds32->target->state = TARGET_RUNNING; nds32->target->debug_reason = DBG_REASON_NOTHALTED; - target_set_examined(target); - return ERROR_OK; } diff --git a/src/target/nds32_v3.c b/src/target/nds32_v3.c index fde86d6e8..797b753ff 100644 --- a/src/target/nds32_v3.c +++ b/src/target/nds32_v3.c @@ -462,8 +462,6 @@ static int nds32_v3_examine(struct target *target) nds32->target->state = TARGET_RUNNING; nds32->target->debug_reason = DBG_REASON_NOTHALTED; - target_set_examined(target); - return ERROR_OK; } diff --git a/src/target/nds32_v3m.c b/src/target/nds32_v3m.c index ffd646f33..48844daff 100644 --- a/src/target/nds32_v3m.c +++ b/src/target/nds32_v3m.c @@ -449,8 +449,6 @@ static int nds32_v3m_examine(struct target *target) nds32->target->state = TARGET_RUNNING; nds32->target->debug_reason = DBG_REASON_NOTHALTED; - target_set_examined(target); - return ERROR_OK; } diff --git a/src/target/openrisc/or1k.c b/src/target/openrisc/or1k.c index 8fbcd9620..11c09fe3a 100644 --- a/src/target/openrisc/or1k.c +++ b/src/target/openrisc/or1k.c @@ -1135,9 +1135,6 @@ static int or1k_examine(struct target *target) struct or1k_du *du_core = or1k_to_du(or1k); if (!target_was_examined(target)) { - - target_set_examined(target); - int running; int retval = du_core->or1k_is_cpu_running(&or1k->jtag, &running); diff --git a/src/target/riscv/riscv-011.c b/src/target/riscv/riscv-011.c index 7a5e990ca..4ed4daa63 100644 --- a/src/target/riscv/riscv-011.c +++ b/src/target/riscv/riscv-011.c @@ -1586,7 +1586,6 @@ static int examine(struct target *target) if (result != ERROR_OK) return result; - target_set_examined(target); riscv_set_current_hartid(target, 0); for (size_t i = 0; i < 32; ++i) reg_cache_set(target, i, -1); diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 24fb79ccf..8b8389643 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1761,8 +1761,6 @@ static int examine(struct target *target) riscv013_step_or_resume_current_hart(target, false, false); } - target_set_examined(target); - if (target->smp) { bool haltgroup_supported; if (set_haltgroup(target, &haltgroup_supported) != ERROR_OK) diff --git a/src/target/stm8.c b/src/target/stm8.c index 21fc8c54f..7bb63920b 100644 --- a/src/target/stm8.c +++ b/src/target/stm8.c @@ -1716,8 +1716,6 @@ static int stm8_examine(struct target *target) } } - target_set_examined(target); - return ERROR_OK; } diff --git a/src/target/target.c b/src/target/target.c index 7bace83f9..0e49f34d6 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -717,9 +717,24 @@ static int no_mmu(struct target *target, int *enabled) return ERROR_OK; } +/** 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) +{ + target->examined = true; +} + +/** + * 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 int default_examine(struct target *target) { - target_set_examined(target); return ERROR_OK; } @@ -737,10 +752,12 @@ int target_examine_one(struct target *target) int retval = target->type->examine(target); if (retval != ERROR_OK) { + target_reset_examined(target); target_call_event_callbacks(target, TARGET_EVENT_EXAMINE_FAIL); return retval; } + target_set_examined(target); target_call_event_callbacks(target, TARGET_EVENT_EXAMINE_END); return ERROR_OK; @@ -1522,15 +1539,6 @@ static int target_profiling(struct target *target, uint32_t *samples, num_samples, seconds); } -/** - * Reset the @c examined flag for the given target. - * Pure paranoia -- targets are zeroed on allocation. - */ -static void target_reset_examined(struct target *target) -{ - target->examined = false; -} - static int handle_target(void *priv); static int target_init_one(struct command_context *cmd_ctx, @@ -3055,7 +3063,7 @@ static int handle_target(void *priv) /* 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->examined = true; + target_set_examined(target); LOG_USER("Examination failed, GDB will be halted. Polling again in %dms", target->backoff.times * polling_interval); return retval; @@ -5308,8 +5316,13 @@ static int jim_target_examine(Jim_Interp *interp, int argc, Jim_Obj *const *argv } int e = target->type->examine(target); - if (e != ERROR_OK) + if (e != ERROR_OK) { + target_reset_examined(target); return JIM_ERR; + } + + target_set_examined(target); + return JIM_OK; } diff --git a/src/target/target.h b/src/target/target.h index 1e19434e4..e2b464437 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -440,13 +440,6 @@ static inline bool target_was_examined(struct target *target) return target->examined; } -/** 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) -{ - target->examined = true; -} - /** * Add the @a breakpoint for @a target. * --
