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/+/9275
-- gerrit commit 112ecba8697b11db340d54f7a35454bc952b0054 Author: Tomas Vanek <[email protected]> Date: Sat Nov 29 20:16:29 2025 +0100 target/riscv: add target_was_examined() checks If a RISC-V target does not pass the initial examination some commands fail by assert() or log lot of hardly understandable errors. Check if target was examined otherwise fail early. Although command_print() is preferred in OpenOCD commands, use LOG_TARGET_ERROR() if the rest of command uses the same. Change-Id: I615e48f348a0f3bdaf71630a2fcd6fc7665115d5 Signed-off-by: Tomas Vanek <[email protected]> diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 8054a1c9b7..fc59468b7b 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -5007,6 +5007,11 @@ COMMAND_HANDLER(riscv_itrigger) struct target *target = get_current_target(CMD_CTX); const int ITRIGGER_UNIQUE_ID = -CSR_TDATA1_TYPE_ITRIGGER; + if (!target_was_examined(target)) { + LOG_TARGET_ERROR(target, "not examined"); + return ERROR_TARGET_NOT_EXAMINED; + } + if (riscv_enumerate_triggers(target) != ERROR_OK) return ERROR_FAIL; @@ -5072,6 +5077,11 @@ COMMAND_HANDLER(riscv_icount) struct target *target = get_current_target(CMD_CTX); const int ICOUNT_UNIQUE_ID = -CSR_TDATA1_TYPE_ICOUNT; + if (!target_was_examined(target)) { + LOG_TARGET_ERROR(target, "not examined"); + return ERROR_TARGET_NOT_EXAMINED; + } + if (riscv_enumerate_triggers(target) != ERROR_OK) return ERROR_FAIL; @@ -5137,6 +5147,11 @@ COMMAND_HANDLER(riscv_etrigger) struct target *target = get_current_target(CMD_CTX); const int ETRIGGER_UNIQUE_ID = -CSR_TDATA1_TYPE_ETRIGGER; + if (!target_was_examined(target)) { + LOG_TARGET_ERROR(target, "not examined"); + return ERROR_TARGET_NOT_EXAMINED; + } + if (riscv_enumerate_triggers(target) != ERROR_OK) return ERROR_FAIL; @@ -5194,6 +5209,11 @@ COMMAND_HANDLER(riscv_etrigger) COMMAND_HANDLER(handle_repeat_read) { struct target *target = get_current_target(CMD_CTX); + if (!target_was_examined(target)) { + LOG_TARGET_ERROR(target, "not examined"); + return ERROR_TARGET_NOT_EXAMINED; + } + RISCV_INFO(r); if (CMD_ARGC < 2 || CMD_ARGC > 3) @@ -5408,6 +5428,11 @@ COMMAND_HANDLER(riscv_exec_progbuf) struct target *target = get_current_target(CMD_CTX); + if (!target_was_examined(target)) { + LOG_TARGET_ERROR(target, "not examined"); + return ERROR_TARGET_NOT_EXAMINED; + } + RISCV_INFO(r); if (r->dtm_version != DTM_DTMCS_VERSION_1_0) { LOG_TARGET_ERROR(target, "exec_progbuf: Program buffer is " @@ -5514,6 +5539,11 @@ static COMMAND_HELPER(report_reserved_triggers, struct target *target) COMMAND_HANDLER(handle_reserve_trigger) { struct target *target = get_current_target(CMD_CTX); + if (!target_was_examined(target)) { + command_print(CMD, "Error: Target not examined"); + return ERROR_TARGET_NOT_EXAMINED; + } + if (CMD_ARGC == 0) return CALL_COMMAND_HANDLER(report_reserved_triggers, target); diff --git a/src/target/riscv/riscv_reg.c b/src/target/riscv/riscv_reg.c index ba1bc2a858..21bda2b4a7 100644 --- a/src/target/riscv/riscv_reg.c +++ b/src/target/riscv/riscv_reg.c @@ -918,6 +918,11 @@ void riscv_reg_cache_invalidate_all(struct target *target) int riscv_reg_set(struct target *target, enum gdb_regno regid, riscv_reg_t value) { + if (!target_was_examined(target)) { + LOG_TARGET_ERROR(target, "not examined"); + return ERROR_TARGET_NOT_EXAMINED; + } + return riscv_set_or_write_register(target, regid, value, /* write_through */ false); } @@ -935,6 +940,11 @@ int riscv_reg_set(struct target *target, enum gdb_regno regid, int riscv_reg_write(struct target *target, enum gdb_regno regid, riscv_reg_t value) { + if (!target_was_examined(target)) { + LOG_TARGET_ERROR(target, "not examined"); + return ERROR_TARGET_NOT_EXAMINED; + } + return riscv_set_or_write_register(target, regid, value, /* write_through */ true); } @@ -952,6 +962,11 @@ int riscv_reg_write(struct target *target, enum gdb_regno regid, int riscv_reg_get(struct target *target, riscv_reg_t *value, enum gdb_regno regid) { + if (!target_was_examined(target)) { + LOG_TARGET_ERROR(target, "not examined"); + return ERROR_TARGET_NOT_EXAMINED; + } + RISCV_INFO(r); assert(r); if (r->dtm_version == DTM_DTMCS_VERSION_0_11) --
