This is an automated email from Gerrit. "Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8862
-- gerrit commit 45e7515bb8f12cbfe5d0eb4afe3c2ed3c7d05713 Author: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com> Date: Tue Apr 29 14:14:26 2025 +0300 target: use NVP names in `target_configure()` This commit replaces uses of `CMD_ARGV[index - ...]` with the corresponding `struct nvp::name` where possible for the following reasons: * shorter * more specific * less error-prone Change-Id: Ie7c450f55c3965ebf204de0ecf0a624e47cfd36f Signed-off-by: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com> diff --git a/src/target/target.c b/src/target/target.c index 1af36778e8..3d8f49b6a2 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4925,13 +4925,14 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_EVENT: if (index == CMD_ARGC) { command_print(CMD, "expecting %s event-name event-body", - CMD_ARGV[index - 1]); + n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } - n = nvp_name2value(nvp_target_event, CMD_ARGV[index]); - if (!n->name) { - nvp_unknown_command_print(CMD, nvp_target_event, CMD_ARGV[index - 1], CMD_ARGV[index]); + const struct nvp *event_nvp = nvp_name2value(nvp_target_event, + CMD_ARGV[index]); + if (!event_nvp->name) { + nvp_unknown_command_print(CMD, nvp_target_event, n->name, CMD_ARGV[index]); return ERROR_COMMAND_ARGUMENT_INVALID; } index++; @@ -4939,7 +4940,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde if (is_configure) { if (index == CMD_ARGC) { command_print(CMD, "expecting %s %s event-body", - CMD_ARGV[index - 2], CMD_ARGV[index - 1]); + n->name, event_nvp->name); return ERROR_COMMAND_ARGUMENT_INVALID; } } @@ -4949,7 +4950,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde /* replace existing? */ list_for_each_entry(teap, &target->events_action, list) - if (teap->event == (enum target_event)n->value) + if (teap->event == (enum target_event)event_nvp->value) break; /* not found! */ @@ -4958,8 +4959,10 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde if (is_configure) { /* START_DEPRECATED_TPIU */ - if (n->value == TARGET_EVENT_TRACE_CONFIG) - LOG_INFO("DEPRECATED target event %s; use TPIU events {pre,post}-{enable,disable}", n->name); + if (event_nvp->value == TARGET_EVENT_TRACE_CONFIG) + LOG_INFO("DEPRECATED target event %s; " + "use TPIU events {pre,post}-{enable,disable}", + event_nvp->name); /* END_DEPRECATED_TPIU */ if (strlen(CMD_ARGV[index]) == 0) { @@ -4979,7 +4982,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde teap = calloc(1, sizeof(*teap)); replace = false; } - teap->event = n->value; + teap->event = event_nvp->value; teap->interp = CMD_CTX->interp; if (teap->body) Jim_DecrRefCount(teap->interp, teap->body); @@ -5017,7 +5020,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_WORK_AREA_VIRT: if (is_configure) { if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } COMMAND_PARSE_NUMBER(u64, CMD_ARGV[index], target->working_area_virt); @@ -5035,7 +5038,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_WORK_AREA_PHYS: if (is_configure) { if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } COMMAND_PARSE_NUMBER(u64, CMD_ARGV[index], target->working_area_phys); @@ -5053,7 +5056,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_WORK_AREA_SIZE: if (is_configure) { if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } COMMAND_PARSE_NUMBER(u32, CMD_ARGV[index], target->working_area_size); @@ -5070,7 +5073,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_WORK_AREA_BACKUP: if (is_configure) { if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } retval = command_parse_bool_arg(CMD_ARGV[index], &target->backup_working_area); @@ -5089,12 +5092,13 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_ENDIAN: if (is_configure) { if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } n = nvp_name2value(nvp_target_endian, CMD_ARGV[index]); if (!n->name) { - nvp_unknown_command_print(CMD, nvp_target_endian, CMD_ARGV[index - 1], CMD_ARGV[index]); + nvp_unknown_command_print(CMD, nvp_target_endian, n->name, + CMD_ARGV[index]); return ERROR_COMMAND_ARGUMENT_INVALID; } index++; @@ -5115,7 +5119,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_COREID: if (is_configure) { if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } COMMAND_PARSE_NUMBER(s32, CMD_ARGV[index], target->coreid); @@ -5136,7 +5140,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde } if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } struct jtag_tap *tap = jtag_tap_by_string(CMD_ARGV[index]); @@ -5158,7 +5162,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_DBGBASE: if (is_configure) { if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } COMMAND_PARSE_NUMBER(u32, CMD_ARGV[index], target->dbgbase); @@ -5175,7 +5179,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_RTOS: if (is_configure) { if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } struct jim_getopt_info goi; @@ -5209,7 +5213,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_GDB_PORT: if (is_configure) { if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -5238,7 +5242,7 @@ static COMMAND_HELPER(target_configure, struct target *target, unsigned int inde case TCFG_GDB_MAX_CONNECTIONS: if (is_configure) { if (index == CMD_ARGC) { - command_print(CMD, "missing argument to %s", CMD_ARGV[index - 1]); + command_print(CMD, "missing argument to %s", n->name); return ERROR_COMMAND_ARGUMENT_INVALID; } --