Skip to content

Commit b6b6774

Browse files
committed
simplify debug_until_ret_handle_indirect_jump
1 parent 8502b93 commit b6b6774

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

core/debug/debug.c

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -339,42 +339,27 @@ void debug_clear_step(void) {
339339
debug.untilRetIndex = 0;
340340
}
341341

342-
void debug_until_ret_handle_indirect_jump(uint32_t target, uint32_t currentSp) {
343-
/* stop if this JP(rr) is an actual return for a
344-
* recorded call frame, where target matches its retAddr and
345-
* SP has been restored to that frame's precall stack
346-
* value (or frame was detected popped) */
347-
uint32_t idx = debug.stackIndex;
348-
uint32_t sz = debug.stackSize;
349-
debug_stack_entry_t *hit = NULL;
350-
uint32_t hit_idx = ~0u;
351-
352-
while (sz--) {
353-
debug_stack_entry_t *entry = &debug.stack[idx];
354-
const uint32_t this_idx = idx;
355-
idx = (idx - 1) & DBG_STACK_MASK;
356-
if (entry->mode == cpu.L &&
357-
/* only consider frames above current SP baseline. target
358-
* must also match the frame's retAddr window */
359-
entry->stack >= debug.untilRetBase &&
360-
(target - entry->retAddr) <= entry->range) {
361-
hit = entry;
362-
hit_idx = this_idx;
363-
break;
364-
}
342+
void debug_until_ret_handle_indirect_jump(const uint32_t target, const uint32_t currentSp) {
343+
const debug_stack_entry_t *e = &debug.stack[debug.untilRetIndex];
344+
345+
if (!(e->mode == cpu.L &&
346+
/* only consider frames above current SP baseline */
347+
e->stack >= debug.untilRetBase &&
348+
/* target must also match the frame's retAddr window */
349+
(target - e->retAddr) <= e->range &&
350+
/* SP restored to precall value, or frame popped */
351+
(currentSp == e->stack || e->popped))) {
352+
return;
365353
}
366354

367-
/* break if we are returning from the same frame
368-
* where DBG_UNTIL_RET started */
369-
if (hit && hit_idx == debug.untilRetIndex &&
370-
(currentSp == hit->stack || hit->popped)) {
371-
const uint32_t len = 1 + (cpu.PREFIX != 0);
372-
const uint32_t start = cpu_mask_mode(
373-
cpu.registers.PC - (len + (cpu.SUFFIX ? 1u : 0u)),
374-
cpu.ADL);
375-
cpu.registers.PC = start;
376-
debug_open(DBG_STEP, cpu.registers.PC);
377-
}
355+
const uint32_t len = 1 + (cpu.PREFIX != 0);
356+
const uint32_t start = cpu_mask_mode(
357+
cpu.registers.PC - (len + (cpu.SUFFIX ? 1u : 0u)),
358+
cpu.ADL);
359+
360+
cpu.registers.PC = start;
361+
362+
debug_open(DBG_STEP, cpu.registers.PC);
378363
}
379364

380365
void debug_clear_basic_step(void) {

0 commit comments

Comments
 (0)