This is an automated email from Gerrit.

"Tomas Vanek <[email protected]>" just uploaded a new patch set to Gerrit, which 
you can find at https://review.openocd.org/c/openocd/+/9273

-- gerrit

commit 037b83ad0cd17d4c3cf7fb9fecce2e958c76b031
Author: Tomas Vanek <[email protected]>
Date:   Sat Nov 29 20:45:19 2025 +0100

    target: log target and return proper error if target not examined
    
    While on it remove two copy pasta comments.
    
    Change-Id: I66613741d64781c31d5195c9b52e8a30c56bb405
    Signed-off-by: Tomas Vanek <[email protected]>

diff --git a/src/target/target.c b/src/target/target.c
index ababa57fbd..bb02d94be5 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -490,7 +490,7 @@ int target_poll(struct target *target)
        /* We can't poll until after examine */
        if (!target_was_examined(target)) {
                /* Fail silently lest we pollute the log */
-               return ERROR_FAIL;
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        retval = target->type->poll(target);
@@ -516,10 +516,10 @@ int target_poll(struct target *target)
 int target_halt(struct target *target)
 {
        int retval;
-       /* We can't poll until after examine */
+
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        retval = target->type->halt(target);
@@ -567,10 +567,9 @@ int target_resume(struct target *target, bool current, 
target_addr_t address,
 {
        int retval;
 
-       /* We can't poll until after examine */
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        target_call_event_callbacks(target, TARGET_EVENT_RESUME_START);
@@ -751,8 +750,8 @@ const char *target_type_name(const struct target *target)
 static int target_soft_reset_halt(struct target *target)
 {
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
        if (!target->type->soft_reset_halt) {
                LOG_ERROR("Target %s does not support soft_reset_halt",
@@ -789,7 +788,8 @@ int target_run_algorithm(struct target *target,
        int retval = ERROR_FAIL;
 
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
+               LOG_TARGET_ERROR(target, "not examined");
+               retval = ERROR_TARGET_NOT_EXAMINED;
                goto done;
        }
        if (!target->type->run_algorithm) {
@@ -830,7 +830,8 @@ int target_start_algorithm(struct target *target,
        int retval = ERROR_FAIL;
 
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
+               LOG_TARGET_ERROR(target, "not examined");
+               retval = ERROR_TARGET_NOT_EXAMINED;
                goto done;
        }
        if (!target->type->start_algorithm) {
@@ -1248,8 +1249,8 @@ int target_read_memory(struct target *target,
                target_addr_t address, uint32_t size, uint32_t count, uint8_t 
*buffer)
 {
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
        if (!target->type->read_memory) {
                LOG_ERROR("Target %s doesn't support read_memory", 
target_name(target));
@@ -1262,8 +1263,8 @@ int target_read_phys_memory(struct target *target,
                target_addr_t address, uint32_t size, uint32_t count, uint8_t 
*buffer)
 {
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
        if (!target->type->read_phys_memory) {
                LOG_ERROR("Target %s doesn't support read_phys_memory", 
target_name(target));
@@ -1276,8 +1277,8 @@ int target_write_memory(struct target *target,
                target_addr_t address, uint32_t size, uint32_t count, const 
uint8_t *buffer)
 {
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
        if (!target->type->write_memory) {
                LOG_ERROR("Target %s doesn't support write_memory", 
target_name(target));
@@ -1290,8 +1291,8 @@ int target_write_phys_memory(struct target *target,
                target_addr_t address, uint32_t size, uint32_t count, const 
uint8_t *buffer)
 {
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
        if (!target->type->write_phys_memory) {
                LOG_ERROR("Target %s doesn't support write_phys_memory", 
target_name(target));
@@ -1382,7 +1383,8 @@ int target_get_gdb_reg_list(struct target *target,
        int result = ERROR_FAIL;
 
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
+               LOG_TARGET_ERROR(target, "not examined");
+               result = ERROR_TARGET_NOT_EXAMINED;
                goto done;
        }
 
@@ -2354,8 +2356,8 @@ int target_write_buffer(struct target *target, 
target_addr_t address, uint32_t s
                          size, address);
 
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        if (size == 0)
@@ -2419,8 +2421,8 @@ int target_read_buffer(struct target *target, 
target_addr_t address, uint32_t si
                          size, address);
 
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        if (size == 0)
@@ -2480,8 +2482,8 @@ int target_checksum_memory(struct target *target, 
target_addr_t address, uint32_
        uint32_t i;
        uint32_t checksum = 0;
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
        if (!target->type->checksum_memory) {
                LOG_ERROR("Target %s doesn't support checksum_memory", 
target_name(target));
@@ -2522,8 +2524,8 @@ int target_blank_check_memory(struct target *target,
        uint8_t erased_value)
 {
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        if (!target->type->blank_check_memory)
@@ -2536,8 +2538,8 @@ int target_read_u64(struct target *target, target_addr_t 
address, uint64_t *valu
 {
        uint8_t value_buf[8];
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        int retval = target_read_memory(target, address, 8, 1, value_buf);
@@ -2560,8 +2562,8 @@ int target_read_u32(struct target *target, target_addr_t 
address, uint32_t *valu
 {
        uint8_t value_buf[4];
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        int retval = target_read_memory(target, address, 4, 1, value_buf);
@@ -2584,8 +2586,8 @@ int target_read_u16(struct target *target, target_addr_t 
address, uint16_t *valu
 {
        uint8_t value_buf[2];
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        int retval = target_read_memory(target, address, 2, 1, value_buf);
@@ -2607,8 +2609,8 @@ int target_read_u16(struct target *target, target_addr_t 
address, uint16_t *valu
 int target_read_u8(struct target *target, target_addr_t address, uint8_t 
*value)
 {
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        int retval = target_read_memory(target, address, 1, 1, value);
@@ -2631,8 +2633,8 @@ int target_write_u64(struct target *target, target_addr_t 
address, uint64_t valu
        int retval;
        uint8_t value_buf[8];
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        LOG_DEBUG("address: " TARGET_ADDR_FMT ", value: 0x%16.16" PRIx64,
@@ -2652,8 +2654,8 @@ int target_write_u32(struct target *target, target_addr_t 
address, uint32_t valu
        int retval;
        uint8_t value_buf[4];
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        LOG_DEBUG("address: " TARGET_ADDR_FMT ", value: 0x%8.8" PRIx32,
@@ -2673,8 +2675,8 @@ int target_write_u16(struct target *target, target_addr_t 
address, uint16_t valu
        int retval;
        uint8_t value_buf[2];
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        LOG_DEBUG("address: " TARGET_ADDR_FMT ", value: 0x%8.8" PRIx16,
@@ -2693,8 +2695,8 @@ int target_write_u8(struct target *target, target_addr_t 
address, uint8_t value)
 {
        int retval;
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        LOG_DEBUG("address: " TARGET_ADDR_FMT ", value: 0x%2.2" PRIx8,
@@ -2712,8 +2714,8 @@ int target_write_phys_u64(struct target *target, 
target_addr_t address, uint64_t
        int retval;
        uint8_t value_buf[8];
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        LOG_DEBUG("address: " TARGET_ADDR_FMT ", value: 0x%16.16" PRIx64,
@@ -2733,8 +2735,8 @@ int target_write_phys_u32(struct target *target, 
target_addr_t address, uint32_t
        int retval;
        uint8_t value_buf[4];
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        LOG_DEBUG("address: " TARGET_ADDR_FMT ", value: 0x%8.8" PRIx32,
@@ -2754,8 +2756,8 @@ int target_write_phys_u16(struct target *target, 
target_addr_t address, uint16_t
        int retval;
        uint8_t value_buf[2];
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        LOG_DEBUG("address: " TARGET_ADDR_FMT ", value: 0x%8.8" PRIx16,
@@ -2774,8 +2776,8 @@ int target_write_phys_u8(struct target *target, 
target_addr_t address, uint8_t v
 {
        int retval;
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
+               LOG_TARGET_ERROR(target, "not examined");
+               return ERROR_TARGET_NOT_EXAMINED;
        }
 
        LOG_DEBUG("address: " TARGET_ADDR_FMT ", value: 0x%2.2" PRIx8,
@@ -3032,7 +3034,7 @@ COMMAND_HANDLER(handle_reg_command)
 
        struct target *target = get_current_target(CMD_CTX);
        if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
+               command_print(CMD, "Error: [%s] not examined", 
target_name(target));
                return ERROR_TARGET_NOT_EXAMINED;
        }
        struct reg *reg = NULL;

-- 

Reply via email to