Skip to content

Commit 98d9f11

Browse files
tarek-bochkatiborneoa
authored andcommitted
target: reset target examined flag if target::examine() fails
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 <tarek.bouchkati@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6548 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
1 parent ba1061f commit 98d9f11

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/target/target.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,15 @@ static int no_mmu(struct target *target, int *enabled)
717717
return ERROR_OK;
718718
}
719719

720+
/**
721+
* Reset the @c examined flag for the given target.
722+
* Pure paranoia -- targets are zeroed on allocation.
723+
*/
724+
static inline void target_reset_examined(struct target *target)
725+
{
726+
target->examined = false;
727+
}
728+
720729
static int default_examine(struct target *target)
721730
{
722731
target_set_examined(target);
@@ -737,10 +746,12 @@ int target_examine_one(struct target *target)
737746

738747
int retval = target->type->examine(target);
739748
if (retval != ERROR_OK) {
749+
target_reset_examined(target);
740750
target_call_event_callbacks(target, TARGET_EVENT_EXAMINE_FAIL);
741751
return retval;
742752
}
743753

754+
target_set_examined(target);
744755
target_call_event_callbacks(target, TARGET_EVENT_EXAMINE_END);
745756

746757
return ERROR_OK;
@@ -1522,15 +1533,6 @@ static int target_profiling(struct target *target, uint32_t *samples,
15221533
num_samples, seconds);
15231534
}
15241535

1525-
/**
1526-
* Reset the @c examined flag for the given target.
1527-
* Pure paranoia -- targets are zeroed on allocation.
1528-
*/
1529-
static void target_reset_examined(struct target *target)
1530-
{
1531-
target->examined = false;
1532-
}
1533-
15341536
static int handle_target(void *priv);
15351537

15361538
static int target_init_one(struct command_context *cmd_ctx,
@@ -3055,7 +3057,7 @@ static int handle_target(void *priv)
30553057
/* Target examination could have failed due to unstable connection,
30563058
* but we set the examined flag anyway to repoll it later */
30573059
if (retval != ERROR_OK) {
3058-
target->examined = true;
3060+
target_set_examined(target);
30593061
LOG_USER("Examination failed, GDB will be halted. Polling again in %dms",
30603062
target->backoff.times * polling_interval);
30613063
return retval;
@@ -5308,8 +5310,13 @@ static int jim_target_examine(Jim_Interp *interp, int argc, Jim_Obj *const *argv
53085310
}
53095311

53105312
int e = target->type->examine(target);
5311-
if (e != ERROR_OK)
5313+
if (e != ERROR_OK) {
5314+
target_reset_examined(target);
53125315
return JIM_ERR;
5316+
}
5317+
5318+
target_set_examined(target);
5319+
53135320
return JIM_OK;
53145321
}
53155322

0 commit comments

Comments
 (0)