rtos: Refactor rtos_get_gdb_reg()

Exit early if conditions aren't satisfied, instead of putting the core
code inside an if().

Also return ERROR_FAIL if conditions are satisfied but no matching
registers were found.

Change-Id: I77aa63d9f707bc38d1a71899275ba603914b52c9
Signed-off-by: Tim Newsome <tim@sifive.com>
This commit is contained in:
Tim Newsome 2023-10-10 10:45:15 -07:00
parent 15f399691e
commit 969b30326c
1 changed files with 64 additions and 62 deletions

View File

@ -529,18 +529,20 @@ int rtos_get_gdb_reg(struct connection *connection, int reg_num)
{
struct target *target = get_target_from_connection(connection);
threadid_t current_threadid = target->rtos->current_threadid;
if ((target->rtos) && (current_threadid != -1) &&
(current_threadid != 0) &&
((current_threadid != target->rtos->current_thread) ||
(target->smp))) { /* in smp several current thread are possible */
if (!target->rtos ||
current_threadid == -1 ||
current_threadid == 0 ||
(current_threadid == target->rtos->current_thread &&
!target->smp)) { /* in smp several current thread are possible */
return ERROR_NOT_IMPLEMENTED;
}
struct rtos_reg *reg_list;
int num_regs;
LOG_DEBUG("getting register %d for thread 0x%" PRIx64
LOG_TARGET_DEBUG(target, "getting register %d for thread 0x%" PRIx64
", target->rtos->current_thread=0x%" PRIx64,
reg_num,
current_threadid,
target->rtos->current_thread);
reg_num, current_threadid, target->rtos->current_thread);
int retval;
if (target->rtos->type->get_thread_reg_value) {
@ -590,8 +592,8 @@ int rtos_get_gdb_reg(struct connection *connection, int reg_num)
}
free(reg_list);
}
return ERROR_NOT_IMPLEMENTED;
return ERROR_FAIL;
}
/** Return a list of general registers. */