target: Unify the output of "bp" command
[openocd.git] / src / target / target.c
index c55b67cc953c1f7c8f8932348ea32cb5d5ba2c59..1219743750ae707e111670143031c120f9b1f0a5 100644 (file)
@@ -31,6 +31,7 @@
 #endif
 
 #include <helper/align.h>
+#include <helper/nvp.h>
 #include <helper/time_support.h>
 #include <jtag/jtag.h>
 #include <flash/nor/core.h>
@@ -65,46 +66,6 @@ static int target_get_gdb_fileio_info_default(struct target *target,
 static int target_gdb_fileio_end_default(struct target *target, int retcode,
                int fileio_errno, bool ctrl_c);
 
-/* targets */
-extern struct target_type arm7tdmi_target;
-extern struct target_type arm720t_target;
-extern struct target_type arm9tdmi_target;
-extern struct target_type arm920t_target;
-extern struct target_type arm966e_target;
-extern struct target_type arm946e_target;
-extern struct target_type arm926ejs_target;
-extern struct target_type fa526_target;
-extern struct target_type feroceon_target;
-extern struct target_type dragonite_target;
-extern struct target_type xscale_target;
-extern struct target_type xtensa_chip_target;
-extern struct target_type cortexm_target;
-extern struct target_type cortexa_target;
-extern struct target_type aarch64_target;
-extern struct target_type cortexr4_target;
-extern struct target_type armv8r_target;
-extern struct target_type arm11_target;
-extern struct target_type ls1_sap_target;
-extern struct target_type mips_m4k_target;
-extern struct target_type mips_mips64_target;
-extern struct target_type avr_target;
-extern struct target_type dsp563xx_target;
-extern struct target_type dsp5680xx_target;
-extern struct target_type testee_target;
-extern struct target_type avr32_ap7k_target;
-extern struct target_type hla_target;
-extern struct target_type esp32_target;
-extern struct target_type esp32s2_target;
-extern struct target_type esp32s3_target;
-extern struct target_type or1k_target;
-extern struct target_type quark_x10xx_target;
-extern struct target_type quark_d20xx_target;
-extern struct target_type stm8_target;
-extern struct target_type riscv_target;
-extern struct target_type mem_ap_target;
-extern struct target_type esirisc_target;
-extern struct target_type arcv2_target;
-
 static struct target_type *target_types[] = {
        &arm7tdmi_target,
        &arm9tdmi_target,
@@ -156,7 +117,12 @@ static LIST_HEAD(target_trace_callback_list);
 static const int polling_interval = TARGET_DEFAULT_POLLING_INTERVAL;
 static LIST_HEAD(empty_smp_targets);
 
-static const struct jim_nvp nvp_assert[] = {
+enum nvp_assert {
+       NVP_DEASSERT,
+       NVP_ASSERT,
+};
+
+static const struct nvp nvp_assert[] = {
        { .name = "assert", NVP_ASSERT },
        { .name = "deassert", NVP_DEASSERT },
        { .name = "T", NVP_ASSERT },
@@ -166,7 +132,7 @@ static const struct jim_nvp nvp_assert[] = {
        { .name = NULL, .value = -1 }
 };
 
-static const struct jim_nvp nvp_error_target[] = {
+static const struct nvp nvp_error_target[] = {
        { .value = ERROR_TARGET_INVALID, .name = "err-invalid" },
        { .value = ERROR_TARGET_INIT_FAILED, .name = "err-init-failed" },
        { .value = ERROR_TARGET_TIMEOUT, .name = "err-timeout" },
@@ -183,9 +149,9 @@ static const struct jim_nvp nvp_error_target[] = {
 
 static const char *target_strerror_safe(int err)
 {
-       const struct jim_nvp *n;
+       const struct nvp *n;
 
-       n = jim_nvp_value2name_simple(nvp_error_target, err);
+       n = nvp_value2name(nvp_error_target, err);
        if (!n->name)
                return "unknown";
        else
@@ -244,7 +210,7 @@ static const struct jim_nvp nvp_target_event[] = {
        { .name = NULL, .value = -1 }
 };
 
-static const struct jim_nvp nvp_target_state[] = {
+static const struct nvp nvp_target_state[] = {
        { .name = "unknown", .value = TARGET_UNKNOWN },
        { .name = "running", .value = TARGET_RUNNING },
        { .name = "halted",  .value = TARGET_HALTED },
@@ -253,7 +219,7 @@ static const struct jim_nvp nvp_target_state[] = {
        { .name = NULL, .value = -1 },
 };
 
-static const struct jim_nvp nvp_target_debug_reason[] = {
+static const struct nvp nvp_target_debug_reason[] = {
        { .name = "debug-request",             .value = DBG_REASON_DBGRQ },
        { .name = "breakpoint",                .value = DBG_REASON_BREAKPOINT },
        { .name = "watchpoint",                .value = DBG_REASON_WATCHPOINT },
@@ -274,7 +240,7 @@ static const struct jim_nvp nvp_target_endian[] = {
        { .name = NULL,     .value = -1 },
 };
 
-static const struct jim_nvp nvp_reset_modes[] = {
+static const struct nvp nvp_reset_modes[] = {
        { .name = "unknown", .value = RESET_UNKNOWN },
        { .name = "run",     .value = RESET_RUN },
        { .name = "halt",    .value = RESET_HALT },
@@ -286,7 +252,7 @@ const char *debug_reason_name(struct target *t)
 {
        const char *cp;
 
-       cp = jim_nvp_value2name_simple(nvp_target_debug_reason,
+       cp = nvp_value2name(nvp_target_debug_reason,
                        t->debug_reason)->name;
        if (!cp) {
                LOG_ERROR("Invalid debug reason: %d", (int)(t->debug_reason));
@@ -298,7 +264,7 @@ const char *debug_reason_name(struct target *t)
 const char *target_state_name(struct target *t)
 {
        const char *cp;
-       cp = jim_nvp_value2name_simple(nvp_target_state, t->state)->name;
+       cp = nvp_value2name(nvp_target_state, t->state)->name;
        if (!cp) {
                LOG_ERROR("Invalid target state: %d", (int)(t->state));
                cp = "(*BUG*unknown*BUG*)";
@@ -324,7 +290,7 @@ const char *target_event_name(enum target_event event)
 const char *target_reset_mode_name(enum target_reset_mode reset_mode)
 {
        const char *cp;
-       cp = jim_nvp_value2name_simple(nvp_reset_modes, reset_mode)->name;
+       cp = nvp_value2name(nvp_reset_modes, reset_mode)->name;
        if (!cp) {
                LOG_ERROR("Invalid target reset mode: %d", (int)(reset_mode));
                cp = "(*BUG*unknown*BUG*)";
@@ -668,8 +634,8 @@ static int target_process_reset(struct command_invocation *cmd, enum target_rese
 {
        char buf[100];
        int retval;
-       struct jim_nvp *n;
-       n = jim_nvp_value2name_simple(nvp_reset_modes, reset_mode);
+       const struct nvp *n;
+       n = nvp_value2name(nvp_reset_modes, reset_mode);
        if (!n->name) {
                LOG_ERROR("invalid reset mode");
                return ERROR_FAIL;
@@ -843,7 +809,7 @@ int target_run_algorithm(struct target *target,
                int num_mem_params, struct mem_param *mem_params,
                int num_reg_params, struct reg_param *reg_param,
                target_addr_t entry_point, target_addr_t exit_point,
-               int timeout_ms, void *arch_info)
+               unsigned int timeout_ms, void *arch_info)
 {
        int retval = ERROR_FAIL;
 
@@ -927,7 +893,7 @@ done:
 int target_wait_algorithm(struct target *target,
                int num_mem_params, struct mem_param *mem_params,
                int num_reg_params, struct reg_param *reg_params,
-               target_addr_t exit_point, int timeout_ms,
+               target_addr_t exit_point, unsigned int timeout_ms,
                void *arch_info)
 {
        int retval = ERROR_FAIL;
@@ -1359,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);
@@ -1369,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);
@@ -1379,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);
@@ -1395,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);
@@ -1409,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;
        }
 
@@ -1491,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);
@@ -1500,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);
@@ -1856,7 +1822,7 @@ int target_call_reset_callbacks(struct target *target, enum target_reset_mode re
        struct target_reset_callback *callback;
 
        LOG_DEBUG("target reset %i (%s)", reset_mode,
-                       jim_nvp_value2name_simple(nvp_reset_modes, reset_mode)->name);
+                       nvp_value2name(nvp_reset_modes, reset_mode)->name);
 
        list_for_each_entry(callback, &target_reset_callback_list, list)
                callback->callback(target, reset_mode, callback->priv);
@@ -3263,7 +3229,7 @@ COMMAND_HANDLER(handle_wait_halt_command)
  *
  * After 500ms, keep_alive() is invoked
  */
-int target_wait_state(struct target *target, enum target_state state, int ms)
+int target_wait_state(struct target *target, enum target_state state, unsigned int ms)
 {
        int retval;
        int64_t then = 0, cur;
@@ -3280,7 +3246,7 @@ int target_wait_state(struct target *target, enum target_state state, int ms)
                        once = false;
                        then = timeval_ms();
                        LOG_DEBUG("waiting for target %s...",
-                               jim_nvp_value2name_simple(nvp_target_state, state)->name);
+                               nvp_value2name(nvp_target_state, state)->name);
                }
 
                if (cur-then > 500)
@@ -3288,7 +3254,7 @@ int target_wait_state(struct target *target, enum target_state state, int ms)
 
                if ((cur-then) > ms) {
                        LOG_ERROR("timed out while waiting for target %s",
-                               jim_nvp_value2name_simple(nvp_target_state, state)->name);
+                               nvp_value2name(nvp_target_state, state)->name);
                        return ERROR_FAIL;
                }
        }
@@ -3338,8 +3304,8 @@ COMMAND_HANDLER(handle_reset_command)
 
        enum target_reset_mode reset_mode = RESET_RUN;
        if (CMD_ARGC == 1) {
-               const struct jim_nvp *n;
-               n = jim_nvp_name2value_simple(nvp_reset_modes, CMD_ARGV[0]);
+               const struct nvp *n;
+               n = nvp_name2value(nvp_reset_modes, CMD_ARGV[0]);
                if ((!n->name) || (n->value == RESET_UNKNOWN))
                        return ERROR_COMMAND_SYNTAX_ERROR;
                reset_mode = n->value;
@@ -3960,24 +3926,24 @@ static int handle_bp_command_list(struct command_invocation *cmd)
                if (breakpoint->type == BKPT_SOFT) {
                        char *buf = buf_to_hex_str(breakpoint->orig_instr,
                                        breakpoint->length);
-                       command_print(cmd, "IVA breakpoint: " TARGET_ADDR_FMT ", 0x%x, 0x%s",
+                       command_print(cmd, "Software breakpoint(IVA): addr=" TARGET_ADDR_FMT ", len=0x%x, orig_instr=0x%s",
                                        breakpoint->address,
                                        breakpoint->length,
                                        buf);
                        free(buf);
                } else {
                        if ((breakpoint->address == 0) && (breakpoint->asid != 0))
-                               command_print(cmd, "Context breakpoint: 0x%8.8" PRIx32 ", 0x%x, %u",
+                               command_print(cmd, "Context breakpoint: asid=0x%8.8" PRIx32 ", len=0x%x, num=%u",
                                                        breakpoint->asid,
                                                        breakpoint->length, breakpoint->number);
                        else if ((breakpoint->address != 0) && (breakpoint->asid != 0)) {
-                               command_print(cmd, "Hybrid breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %u",
+                               command_print(cmd, "Hybrid breakpoint(IVA): addr=" TARGET_ADDR_FMT ", len=0x%x, num=%u",
                                                        breakpoint->address,
                                                        breakpoint->length, breakpoint->number);
                                command_print(cmd, "\t|--->linked with ContextID: 0x%8.8" PRIx32,
                                                        breakpoint->asid);
                        } else
-                               command_print(cmd, "Breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %u",
+                               command_print(cmd, "Hardware breakpoint(IVA): addr=" TARGET_ADDR_FMT ", len=0x%x, num=%u",
                                                        breakpoint->address,
                                                        breakpoint->length, breakpoint->number);
                }
@@ -4068,21 +4034,31 @@ COMMAND_HANDLER(handle_bp_command)
 
 COMMAND_HANDLER(handle_rbp_command)
 {
+       int retval;
+
        if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        struct target *target = get_current_target(CMD_CTX);
 
        if (!strcmp(CMD_ARGV[0], "all")) {
-               breakpoint_remove_all(target);
+               retval = breakpoint_remove_all(target);
+
+               if (retval != ERROR_OK) {
+                       command_print(CMD, "Error encountered during removal of all breakpoints.");
+                       command_print(CMD, "Some breakpoints may have remained set.");
+               }
        } else {
                target_addr_t addr;
                COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr);
 
-               breakpoint_remove(target, addr);
+               retval = breakpoint_remove(target, addr);
+
+               if (retval != ERROR_OK)
+                       command_print(CMD, "Error during removal of breakpoint at address " TARGET_ADDR_FMT, addr);
        }
 
-       return ERROR_OK;
+       return retval;
 }
 
 COMMAND_HANDLER(handle_wp_command)
@@ -4095,8 +4071,8 @@ COMMAND_HANDLER(handle_wp_command)
                while (watchpoint) {
                        command_print(CMD, "address: " TARGET_ADDR_FMT
                                        ", len: 0x%8.8" PRIx32
-                                       ", r/w/a: %i, value: 0x%8.8" PRIx32
-                                       ", mask: 0x%8.8" PRIx32,
+                                       ", r/w/a: %i, value: 0x%8.8" PRIx64
+                                       ", mask: 0x%8.8" PRIx64,
                                        watchpoint->address,
                                        watchpoint->length,
                                        (int)watchpoint->rw,
@@ -4110,15 +4086,20 @@ COMMAND_HANDLER(handle_wp_command)
        enum watchpoint_rw type = WPT_ACCESS;
        target_addr_t addr = 0;
        uint32_t length = 0;
-       uint32_t data_value = 0x0;
-       uint32_t data_mask = 0xffffffff;
+       uint64_t data_value = 0x0;
+       uint64_t data_mask = WATCHPOINT_IGNORE_DATA_VALUE_MASK;
+       bool mask_specified = false;
 
        switch (CMD_ARGC) {
        case 5:
-               COMMAND_PARSE_NUMBER(u32, CMD_ARGV[4], data_mask);
+               COMMAND_PARSE_NUMBER(u64, CMD_ARGV[4], data_mask);
+               mask_specified = true;
                /* fall through */
        case 4:
-               COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], data_value);
+               COMMAND_PARSE_NUMBER(u64, CMD_ARGV[3], data_value);
+               // if user specified only data value without mask - the mask should be 0
+               if (!mask_specified)
+                       data_mask = 0;
                /* fall through */
        case 3:
                switch (CMD_ARGV[2][0]) {
@@ -4162,9 +4143,12 @@ COMMAND_HANDLER(handle_rwp_command)
        COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr);
 
        struct target *target = get_current_target(CMD_CTX);
-       watchpoint_remove(target, addr);
+       int retval = watchpoint_remove(target, addr);
 
-       return ERROR_OK;
+       if (retval != ERROR_OK)
+               command_print(CMD, "Error during removal of watchpoint at address " TARGET_ADDR_FMT, addr);
+
+       return retval;
 }
 
 /**
@@ -5667,55 +5651,40 @@ static int jim_target_array2mem(Jim_Interp *interp,
        return target_array2mem(interp, target, argc - 1, argv + 1);
 }
 
-static int jim_target_tap_disabled(Jim_Interp *interp)
-{
-       Jim_SetResultFormatted(interp, "[TAP is disabled]");
-       return JIM_ERR;
-}
-
-static int jim_target_examine(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+COMMAND_HANDLER(handle_target_examine)
 {
        bool allow_defer = false;
 
-       struct jim_getopt_info goi;
-       jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
-       if (goi.argc > 1) {
-               const char *cmd_name = Jim_GetString(argv[0], NULL);
-               Jim_SetResultFormatted(goi.interp,
-                               "usage: %s ['allow-defer']", cmd_name);
-               return JIM_ERR;
-       }
-       if (goi.argc > 0 &&
-           strcmp(Jim_GetString(argv[1], NULL), "allow-defer") == 0) {
-               /* consume it */
-               Jim_Obj *obj;
-               int e = jim_getopt_obj(&goi, &obj);
-               if (e != JIM_OK)
-                       return e;
+       if (CMD_ARGC > 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       if (CMD_ARGC == 1) {
+               if (strcmp(CMD_ARGV[0], "allow-defer"))
+                       return ERROR_COMMAND_ARGUMENT_INVALID;
                allow_defer = true;
        }
 
-       struct command_context *cmd_ctx = current_command_context(interp);
-       assert(cmd_ctx);
-       struct target *target = get_current_target(cmd_ctx);
-       if (!target->tap->enabled)
-               return jim_target_tap_disabled(interp);
+       struct target *target = get_current_target(CMD_CTX);
+       if (!target->tap->enabled) {
+               command_print(CMD, "[TAP is disabled]");
+               return ERROR_FAIL;
+       }
 
        if (allow_defer && target->defer_examine) {
                LOG_INFO("Deferring arp_examine of %s", target_name(target));
                LOG_INFO("Use arp_examine command to examine it manually!");
-               return JIM_OK;
+               return ERROR_OK;
        }
 
-       int e = target->type->examine(target);
-       if (e != ERROR_OK) {
+       int retval = target->type->examine(target);
+       if (retval != ERROR_OK) {
                target_reset_examined(target);
-               return JIM_ERR;
+               return retval;
        }
 
        target_set_examined(target);
 
-       return JIM_OK;
+       return ERROR_OK;
 }
 
 COMMAND_HANDLER(handle_target_was_examined)
@@ -5752,62 +5721,47 @@ COMMAND_HANDLER(handle_target_halt_gdb)
        return target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
 }
 
-static int jim_target_poll(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+COMMAND_HANDLER(handle_target_poll)
 {
-       if (argc != 1) {
-               Jim_WrongNumArgs(interp, 1, argv, "[no parameters]");
-               return JIM_ERR;
+       if (CMD_ARGC != 0)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       struct target *target = get_current_target(CMD_CTX);
+       if (!target->tap->enabled) {
+               command_print(CMD, "[TAP is disabled]");
+               return ERROR_FAIL;
        }
-       struct command_context *cmd_ctx = current_command_context(interp);
-       assert(cmd_ctx);
-       struct target *target = get_current_target(cmd_ctx);
-       if (!target->tap->enabled)
-               return jim_target_tap_disabled(interp);
 
-       int e;
        if (!(target_was_examined(target)))
-               e = ERROR_TARGET_NOT_EXAMINED;
-       else
-               e = target->type->poll(target);
-       if (e != ERROR_OK)
-               return JIM_ERR;
-       return JIM_OK;
+               return ERROR_TARGET_NOT_EXAMINED;
+
+       return target->type->poll(target);
 }
 
-static int jim_target_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+COMMAND_HANDLER(handle_target_reset)
 {
-       struct jim_getopt_info goi;
-       jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
+       if (CMD_ARGC != 2)
+               return ERROR_COMMAND_SYNTAX_ERROR;
 
-       if (goi.argc != 2) {
-               Jim_WrongNumArgs(interp, 0, argv,
-                               "([tT]|[fF]|assert|deassert) BOOL");
-               return JIM_ERR;
+       const struct nvp *n = nvp_name2value(nvp_assert, CMD_ARGV[0]);
+       if (!n->name) {
+               nvp_unknown_command_print(CMD, nvp_assert, NULL, CMD_ARGV[0]);
+               return ERROR_COMMAND_ARGUMENT_INVALID;
        }
 
-       struct jim_nvp *n;
-       int e = jim_getopt_nvp(&goi, nvp_assert, &n);
-       if (e != JIM_OK) {
-               jim_getopt_nvp_unknown(&goi, nvp_assert, 1);
-               return e;
-       }
        /* the halt or not param */
-       jim_wide a;
-       e = jim_getopt_wide(&goi, &a);
-       if (e != JIM_OK)
-               return e;
+       int a;
+       COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], a);
 
-       struct command_context *cmd_ctx = current_command_context(interp);
-       assert(cmd_ctx);
-       struct target *target = get_current_target(cmd_ctx);
-       if (!target->tap->enabled)
-               return jim_target_tap_disabled(interp);
+       struct target *target = get_current_target(CMD_CTX);
+       if (!target->tap->enabled) {
+               command_print(CMD, "[TAP is disabled]");
+               return ERROR_FAIL;
+       }
 
        if (!target->type->assert_reset || !target->type->deassert_reset) {
-               Jim_SetResultFormatted(interp,
-                               "No target-specific reset for %s",
-                               target_name(target));
-               return JIM_ERR;
+               command_print(CMD, "No target-specific reset for %s", target_name(target));
+               return ERROR_FAIL;
        }
 
        if (target->defer_examine)
@@ -5820,66 +5774,53 @@ static int jim_target_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 
        /* do the assert */
        if (n->value == NVP_ASSERT)
-               e = target->type->assert_reset(target);
-       else
-               e = target->type->deassert_reset(target);
-       return (e == ERROR_OK) ? JIM_OK : JIM_ERR;
+               return target->type->assert_reset(target);
+       return target->type->deassert_reset(target);
 }
 
-static int jim_target_halt(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+COMMAND_HANDLER(handle_target_halt)
 {
-       if (argc != 1) {
-               Jim_WrongNumArgs(interp, 1, argv, "[no parameters]");
-               return JIM_ERR;
+       if (CMD_ARGC != 0)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       struct target *target = get_current_target(CMD_CTX);
+       if (!target->tap->enabled) {
+               command_print(CMD, "[TAP is disabled]");
+               return ERROR_FAIL;
        }
-       struct command_context *cmd_ctx = current_command_context(interp);
-       assert(cmd_ctx);
-       struct target *target = get_current_target(cmd_ctx);
-       if (!target->tap->enabled)
-               return jim_target_tap_disabled(interp);
-       int e = target->type->halt(target);
-       return (e == ERROR_OK) ? JIM_OK : JIM_ERR;
+
+       return target->type->halt(target);
 }
 
-static int jim_target_wait_state(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+COMMAND_HANDLER(handle_target_wait_state)
 {
-       struct jim_getopt_info goi;
-       jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
+       if (CMD_ARGC != 2)
+               return ERROR_COMMAND_SYNTAX_ERROR;
 
-       /* params:  <name>  statename timeoutmsecs */
-       if (goi.argc != 2) {
-               const char *cmd_name = Jim_GetString(argv[0], NULL);
-               Jim_SetResultFormatted(goi.interp,
-                               "%s <state_name> <timeout_in_msec>", cmd_name);
-               return JIM_ERR;
+       const struct nvp *n = nvp_name2value(nvp_target_state, CMD_ARGV[0]);
+       if (!n->name) {
+               nvp_unknown_command_print(CMD, nvp_target_state, NULL, CMD_ARGV[0]);
+               return ERROR_COMMAND_ARGUMENT_INVALID;
        }
 
-       struct jim_nvp *n;
-       int e = jim_getopt_nvp(&goi, nvp_target_state, &n);
-       if (e != JIM_OK) {
-               jim_getopt_nvp_unknown(&goi, nvp_target_state, 1);
-               return e;
+       unsigned int a;
+       COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], a);
+
+       struct target *target = get_current_target(CMD_CTX);
+       if (!target->tap->enabled) {
+               command_print(CMD, "[TAP is disabled]");
+               return ERROR_FAIL;
        }
-       jim_wide a;
-       e = jim_getopt_wide(&goi, &a);
-       if (e != JIM_OK)
-               return e;
-       struct command_context *cmd_ctx = current_command_context(interp);
-       assert(cmd_ctx);
-       struct target *target = get_current_target(cmd_ctx);
-       if (!target->tap->enabled)
-               return jim_target_tap_disabled(interp);
 
-       e = target_wait_state(target, n->value, a);
-       if (e != ERROR_OK) {
-               Jim_Obj *obj = Jim_NewIntObj(interp, e);
-               Jim_SetResultFormatted(goi.interp,
-                               "target: %s wait %s fails (%#s) %s",
+       int retval = target_wait_state(target, n->value, a);
+       if (retval != ERROR_OK) {
+               command_print(CMD,
+                               "target: %s wait %s fails (%d) %s",
                                target_name(target), n->name,
-                               obj, target_strerror_safe(e));
-               return JIM_ERR;
+                               retval, target_strerror_safe(retval));
+               return retval;
        }
-       return JIM_OK;
+       return ERROR_OK;
 }
 /* List for human, Events defined for this target.
  * scripts/programs should use 'name cget -event NAME'
@@ -6071,7 +6012,7 @@ static const struct command_registration target_instance_command_handlers[] = {
        {
                .name = "arp_examine",
                .mode = COMMAND_EXEC,
-               .jim_handler = jim_target_examine,
+               .handler = handle_target_examine,
                .help = "used internally for reset processing",
                .usage = "['allow-defer']",
        },
@@ -6099,26 +6040,30 @@ static const struct command_registration target_instance_command_handlers[] = {
        {
                .name = "arp_poll",
                .mode = COMMAND_EXEC,
-               .jim_handler = jim_target_poll,
+               .handler = handle_target_poll,
                .help = "used internally for reset processing",
+               .usage = "",
        },
        {
                .name = "arp_reset",
                .mode = COMMAND_EXEC,
-               .jim_handler = jim_target_reset,
+               .handler = handle_target_reset,
                .help = "used internally for reset processing",
+               .usage = "'assert'|'deassert' halt",
        },
        {
                .name = "arp_halt",
                .mode = COMMAND_EXEC,
-               .jim_handler = jim_target_halt,
+               .handler = handle_target_halt,
                .help = "used internally for reset processing",
+               .usage = "",
        },
        {
                .name = "arp_waitstate",
                .mode = COMMAND_EXEC,
-               .jim_handler = jim_target_wait_state,
+               .handler = handle_target_wait_state,
                .help = "used internally for reset processing",
+               .usage = "statename timeoutmsecs",
        },
        {
                .name = "invoke-event",
@@ -6739,8 +6684,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)
@@ -6771,8 +6716,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)
@@ -7220,3 +7165,29 @@ static int target_register_user_commands(struct command_context *cmd_ctx)
 
        return register_commands(cmd_ctx, NULL, target_exec_command_handlers);
 }
+
+const char *target_debug_reason_str(enum target_debug_reason reason)
+{
+       switch (reason) {
+               case DBG_REASON_DBGRQ:
+                       return "DBGRQ";
+               case DBG_REASON_BREAKPOINT:
+                       return "BREAKPOINT";
+               case DBG_REASON_WATCHPOINT:
+                       return "WATCHPOINT";
+               case DBG_REASON_WPTANDBKPT:
+                       return "WPTANDBKPT";
+               case DBG_REASON_SINGLESTEP:
+                       return "SINGLESTEP";
+               case DBG_REASON_NOTHALTED:
+                       return "NOTHALTED";
+               case DBG_REASON_EXIT:
+                       return "EXIT";
+               case DBG_REASON_EXC_CATCH:
+                       return "EXC_CATCH";
+               case DBG_REASON_UNDEFINED:
+                       return "UNDEFINED";
+               default:
+                       return "UNKNOWN!";
+       }
+}

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)