target: Add a debug_reason command
[openocd.git] / src / target / target.c
index 5c4f67b6a7357979bd4d2ae0d27a30cf0e79edac..d368cb5156f4befdf9a895d8a9dc1122da1d694c 100644 (file)
@@ -3052,6 +3052,10 @@ COMMAND_HANDLER(handle_reg_command)
        LOG_DEBUG("-");
 
        struct target *target = get_current_target(CMD_CTX);
+       if (!target_was_examined(target)) {
+               LOG_ERROR("Target not examined yet");
+               return ERROR_TARGET_NOT_EXAMINED;
+       }
        struct reg *reg = NULL;
 
        /* list all available registers for the current target */
@@ -3116,7 +3120,7 @@ COMMAND_HANDLER(handle_reg_command)
                if (!reg) {
                        command_print(CMD, "%i is out of bounds, the current target "
                                        "has only %i registers (0 - %i)", num, count, count - 1);
-                       return ERROR_OK;
+                       return ERROR_FAIL;
                }
        } else {
                /* access a single register by its name */
@@ -3135,9 +3139,9 @@ COMMAND_HANDLER(handle_reg_command)
        if ((CMD_ARGC == 1) || ((CMD_ARGC == 2) && !((CMD_ARGV[1][0] >= '0')
                        && (CMD_ARGV[1][0] <= '9')))) {
                if ((CMD_ARGC == 2) && (strcmp(CMD_ARGV[1], "force") == 0))
-                       reg->valid = 0;
+                       reg->valid = false;
 
-               if (reg->valid == 0) {
+               if (!reg->valid) {
                        int retval = reg->type->get(reg);
                        if (retval != ERROR_OK) {
                                LOG_ERROR("Could not read register '%s'", reg->name);
@@ -3175,7 +3179,7 @@ COMMAND_HANDLER(handle_reg_command)
 
 not_found:
        command_print(CMD, "register %s not found in current target", CMD_ARGV[0]);
-       return ERROR_OK;
+       return ERROR_FAIL;
 }
 
 COMMAND_HANDLER(handle_poll_command)
@@ -3926,24 +3930,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);
                }
@@ -4069,13 +4073,14 @@ COMMAND_HANDLER(handle_wp_command)
                struct watchpoint *watchpoint = target->watchpoints;
 
                while (watchpoint) {
+                       char wp_type = (watchpoint->rw == WPT_READ ? 'r' : (watchpoint->rw == WPT_WRITE ? 'w' : 'a'));
                        command_print(CMD, "address: " TARGET_ADDR_FMT
                                        ", len: 0x%8.8" PRIx32
-                                       ", r/w/a: %i, value: 0x%8.8" PRIx64
+                                       ", r/w/a: %c, value: 0x%8.8" PRIx64
                                        ", mask: 0x%8.8" PRIx64,
                                        watchpoint->address,
                                        watchpoint->length,
-                                       (int)watchpoint->rw,
+                                       wp_type,
                                        watchpoint->value,
                                        watchpoint->mask);
                        watchpoint = watchpoint->next;
@@ -4136,17 +4141,28 @@ COMMAND_HANDLER(handle_wp_command)
 
 COMMAND_HANDLER(handle_rwp_command)
 {
+       int retval;
+
        if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       target_addr_t addr;
-       COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr);
-
        struct target *target = get_current_target(CMD_CTX);
-       int retval = watchpoint_remove(target, addr);
+       if (!strcmp(CMD_ARGV[0], "all")) {
+               retval = watchpoint_remove_all(target);
 
-       if (retval != ERROR_OK)
-               command_print(CMD, "Error during removal of watchpoint at address " TARGET_ADDR_FMT, addr);
+               if (retval != ERROR_OK) {
+                       command_print(CMD, "Error encountered during removal of all watchpoints.");
+                       command_print(CMD, "Some watchpoints may have remained set.");
+               }
+       } else {
+               target_addr_t addr;
+               COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr);
+
+               retval = watchpoint_remove(target, addr);
+
+               if (retval != ERROR_OK)
+                       command_print(CMD, "Error during removal of watchpoint at address " TARGET_ADDR_FMT, addr);
+       }
 
        return retval;
 }
@@ -5133,7 +5149,7 @@ static int target_jim_get_reg(Jim_Interp *interp, int argc,
                        return JIM_ERR;
                }
 
-               if (force) {
+               if (force || !reg->valid) {
                        int retval = reg->type->get(reg);
 
                        if (retval != ERROR_OK) {
@@ -5858,6 +5874,18 @@ COMMAND_HANDLER(handle_target_current_state)
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(handle_target_debug_reason)
+{
+       if (CMD_ARGC != 0)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       struct target *target = get_current_target(CMD_CTX);
+
+       command_print(CMD, "%s", debug_reason_name(target));
+
+       return ERROR_OK;
+}
+
 static int jim_target_invoke_event(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
        struct jim_getopt_info goi;
@@ -6009,6 +6037,13 @@ static const struct command_registration target_instance_command_handlers[] = {
                .help = "displays the current state of this target",
                .usage = "",
        },
+       {
+               .name = "debug_reason",
+               .mode = COMMAND_EXEC,
+               .handler = handle_target_debug_reason,
+               .help = "displays the debug reason of this target",
+               .usage = "",
+       },
        {
                .name = "arp_examine",
                .mode = COMMAND_EXEC,
@@ -7065,7 +7100,7 @@ static const struct command_registration target_exec_command_handlers[] = {
                .handler = handle_rwp_command,
                .mode = COMMAND_EXEC,
                .help = "remove watchpoint",
-               .usage = "address",
+               .usage = "'all' | address",
        },
        {
                .name = "load_image",

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)