target: fix messages and return values of failed op because not halted

Lot of messages was logged as LOG_WARNING, but the operation failed
immediately. Sometimes no error message was logged at all.
Add missing messages, change warnings to errors.

Sometimes ERROR_TARGET_INVALID was returned. Some command handlers
returned ERROR_OK! Always return ERROR_TARGET_NOT_HALTED.

While on it use LOG_TARGET_ERROR() whenever possible.
Prefix command_print() message with 'Error:' to get closer
to LOG_TARGET_ERROR() variant.

Error message was not added to get() and set() methods of
struct xxx_reg_type - the return value is properly checked and a message
is logged by the caller in case of ERROR_TARGET_NOT_HALTED.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I2fe4187c6025f0038956ab387edbf3f461c69398
Reviewed-on: https://review.openocd.org/c/openocd/+/7819
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Tomas Vanek
2023-07-20 14:52:54 +02:00
parent 7023deb06a
commit a5108240f9
29 changed files with 145 additions and 131 deletions

View File

@@ -1325,7 +1325,7 @@ int target_add_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
if ((target->state != TARGET_HALTED) && (breakpoint->type != BKPT_HARD)) {
LOG_WARNING("target %s is not halted (add breakpoint)", target_name(target));
LOG_TARGET_ERROR(target, "not halted (add breakpoint)");
return ERROR_TARGET_NOT_HALTED;
}
return target->type->add_breakpoint(target, breakpoint);
@@ -1335,7 +1335,7 @@ int target_add_context_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
if (target->state != TARGET_HALTED) {
LOG_WARNING("target %s is not halted (add context breakpoint)", target_name(target));
LOG_TARGET_ERROR(target, "not halted (add context breakpoint)");
return ERROR_TARGET_NOT_HALTED;
}
return target->type->add_context_breakpoint(target, breakpoint);
@@ -1345,7 +1345,7 @@ int target_add_hybrid_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
if (target->state != TARGET_HALTED) {
LOG_WARNING("target %s is not halted (add hybrid breakpoint)", target_name(target));
LOG_TARGET_ERROR(target, "not halted (add hybrid breakpoint)");
return ERROR_TARGET_NOT_HALTED;
}
return target->type->add_hybrid_breakpoint(target, breakpoint);
@@ -1361,7 +1361,7 @@ int target_add_watchpoint(struct target *target,
struct watchpoint *watchpoint)
{
if (target->state != TARGET_HALTED) {
LOG_WARNING("target %s is not halted (add watchpoint)", target_name(target));
LOG_TARGET_ERROR(target, "not halted (add watchpoint)");
return ERROR_TARGET_NOT_HALTED;
}
return target->type->add_watchpoint(target, watchpoint);
@@ -1375,7 +1375,7 @@ int target_hit_watchpoint(struct target *target,
struct watchpoint **hit_watchpoint)
{
if (target->state != TARGET_HALTED) {
LOG_WARNING("target %s is not halted (hit watchpoint)", target->cmd_name);
LOG_TARGET_ERROR(target, "not halted (hit watchpoint)");
return ERROR_TARGET_NOT_HALTED;
}
@@ -1457,7 +1457,7 @@ int target_step(struct target *target,
int target_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info)
{
if (target->state != TARGET_HALTED) {
LOG_WARNING("target %s is not halted (gdb fileio)", target->cmd_name);
LOG_TARGET_ERROR(target, "not halted (gdb fileio)");
return ERROR_TARGET_NOT_HALTED;
}
return target->type->get_gdb_fileio_info(target, fileio_info);
@@ -1466,7 +1466,7 @@ int target_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fi
int target_gdb_fileio_end(struct target *target, int retcode, int fileio_errno, bool ctrl_c)
{
if (target->state != TARGET_HALTED) {
LOG_WARNING("target %s is not halted (gdb fileio end)", target->cmd_name);
LOG_TARGET_ERROR(target, "not halted (gdb fileio end)");
return ERROR_TARGET_NOT_HALTED;
}
return target->type->gdb_fileio_end(target, retcode, fileio_errno, ctrl_c);
@@ -6666,8 +6666,8 @@ COMMAND_HANDLER(handle_ps_command)
struct target *target = get_current_target(CMD_CTX);
char *display;
if (target->state != TARGET_HALTED) {
LOG_INFO("target not halted !!");
return ERROR_OK;
command_print(CMD, "Error: [%s] not halted", target_name(target));
return ERROR_TARGET_NOT_HALTED;
}
if ((target->rtos) && (target->rtos->type)
@@ -6698,8 +6698,8 @@ COMMAND_HANDLER(handle_test_mem_access_command)
int retval = ERROR_OK;
if (target->state != TARGET_HALTED) {
LOG_INFO("target not halted !!");
return ERROR_FAIL;
command_print(CMD, "Error: [%s] not halted", target_name(target));
return ERROR_TARGET_NOT_HALTED;
}
if (CMD_ARGC != 1)