Merge pull request #868 from en-sc/en-sc/upstream-resume-err-2

target/riscv: resume only halted harts
This commit is contained in:
Tim Newsome 2023-06-21 09:37:40 -07:00 committed by GitHub
commit 470c2a402c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 23 deletions

View File

@ -4597,6 +4597,7 @@ static int riscv013_step_current_hart(struct target *target)
static int riscv013_resume_prep(struct target *target) static int riscv013_resume_prep(struct target *target)
{ {
assert(target->state == TARGET_HALTED);
return riscv013_on_step_or_resume(target, false); return riscv013_on_step_or_resume(target, false);
} }

View File

@ -1786,16 +1786,9 @@ static int enable_triggers(struct target *target, riscv_reg_t *state)
static int resume_prep(struct target *target, int current, static int resume_prep(struct target *target, int current,
target_addr_t address, int handle_breakpoints, int debug_execution) target_addr_t address, int handle_breakpoints, int debug_execution)
{ {
assert(target->state == TARGET_HALTED);
RISCV_INFO(r); RISCV_INFO(r);
LOG_TARGET_DEBUG(target, "target->state=%d, current=%s, address=0x%"
TARGET_PRIxADDR ", handle_breakpoints=%s, debug_exec=%s",
target->state,
current ? "true" : "false",
address,
handle_breakpoints ? "true" : "false",
debug_execution ? "true" : "false");
if (!current && riscv_set_register(target, GDB_REGNO_PC, address) != ERROR_OK) if (!current && riscv_set_register(target, GDB_REGNO_PC, address) != ERROR_OK)
return ERROR_FAIL; return ERROR_FAIL;
@ -1825,6 +1818,7 @@ static int resume_prep(struct target *target, int current,
static int resume_go(struct target *target, int current, static int resume_go(struct target *target, int current,
target_addr_t address, int handle_breakpoints, int debug_execution) target_addr_t address, int handle_breakpoints, int debug_execution)
{ {
assert(target->state == TARGET_HALTED);
RISCV_INFO(r); RISCV_INFO(r);
int result; int result;
if (!r->get_hart_state) { if (!r->get_hart_state) {
@ -1840,6 +1834,7 @@ static int resume_go(struct target *target, int current,
static int resume_finish(struct target *target, int debug_execution) static int resume_finish(struct target *target, int debug_execution)
{ {
assert(target->state == TARGET_HALTED);
register_cache_invalidate(target->reg_cache); register_cache_invalidate(target->reg_cache);
target->state = debug_execution ? TARGET_DEBUG_RUNNING : TARGET_RUNNING; target->state = debug_execution ? TARGET_DEBUG_RUNNING : TARGET_RUNNING;
@ -1860,7 +1855,6 @@ static int riscv_resume(
int debug_execution, int debug_execution,
bool single_hart) bool single_hart)
{ {
LOG_DEBUG("handle_breakpoints=%d", handle_breakpoints);
int result = ERROR_OK; int result = ERROR_OK;
struct list_head *targets; struct list_head *targets;
@ -1880,14 +1874,22 @@ static int riscv_resume(
targets = &single_target_list; targets = &single_target_list;
} }
LOG_TARGET_DEBUG(target, "current=%s, address=0x%"
TARGET_PRIxADDR ", handle_breakpoints=%s, debug_exec=%s",
current ? "true" : "false",
address,
handle_breakpoints ? "true" : "false",
debug_execution ? "true" : "false");
struct target_list *tlist; struct target_list *tlist;
foreach_smp_target_direction(resume_order == RO_NORMAL, tlist, targets) { foreach_smp_target_direction(resume_order == RO_NORMAL, tlist, targets) {
struct target *t = tlist->target; struct target *t = tlist->target;
if (t->state != TARGET_UNAVAILABLE) { LOG_TARGET_DEBUG(t, "target->state=%s", target_state_name(t));
if (resume_prep(t, current, address, handle_breakpoints, if (t->state != TARGET_HALTED)
debug_execution) != ERROR_OK) LOG_TARGET_DEBUG(t, "skipping this target: target not halted");
result = ERROR_FAIL; else if (resume_prep(t, current, address, handle_breakpoints,
} debug_execution) != ERROR_OK)
result = ERROR_FAIL;
} }
foreach_smp_target_direction(resume_order == RO_NORMAL, tlist, targets) { foreach_smp_target_direction(resume_order == RO_NORMAL, tlist, targets) {
@ -1902,7 +1904,7 @@ static int riscv_resume(
foreach_smp_target_direction(resume_order == RO_NORMAL, tlist, targets) { foreach_smp_target_direction(resume_order == RO_NORMAL, tlist, targets) {
struct target *t = tlist->target; struct target *t = tlist->target;
if (t->state != TARGET_UNAVAILABLE) { if (t->state == TARGET_HALTED) {
if (resume_finish(t, debug_execution) != ERROR_OK) if (resume_finish(t, debug_execution) != ERROR_OK)
result = ERROR_FAIL; result = ERROR_FAIL;
} }
@ -1914,13 +1916,10 @@ static int riscv_resume(
static int riscv_target_resume(struct target *target, int current, static int riscv_target_resume(struct target *target, int current,
target_addr_t address, int handle_breakpoints, int debug_execution) target_addr_t address, int handle_breakpoints, int debug_execution)
{ {
LOG_TARGET_DEBUG(target, "target->state=%d, current=%s, address=0x%" if (target->state != TARGET_HALTED) {
TARGET_PRIxADDR ", handle_breakpoints=%s, debug_exec=%s", LOG_TARGET_ERROR(target, "not halted");
target->state, return ERROR_TARGET_NOT_HALTED;
current ? "true" : "false", }
address,
handle_breakpoints ? "true" : "false",
debug_execution ? "true" : "false");
return riscv_resume(target, current, address, handle_breakpoints, return riscv_resume(target, current, address, handle_breakpoints,
debug_execution, false); debug_execution, false);
} }
@ -2914,7 +2913,7 @@ int riscv_openocd_poll(struct target *target)
should_remain_halted); should_remain_halted);
riscv_halt(target); riscv_halt(target);
} else if (should_resume) { } else if (should_resume) {
LOG_DEBUG("resume all"); LOG_TARGET_DEBUG(target, "resume all");
riscv_resume(target, true, 0, 0, 0, false); riscv_resume(target, true, 0, 0, 0, false);
} else if (halted && running) { } else if (halted && running) {
LOG_TARGET_DEBUG(target, "halt all; halted=%d", LOG_TARGET_DEBUG(target, "halt all; halted=%d",