more debug output for breakpoints
[openocd.git] / src / target / target.c
index 670b4ba8b5921e3230e48cddc34ab5562fd82fd7..b6ea65551632635d69aead809957c495b0be7455 100644 (file)
@@ -249,22 +249,6 @@ target_state_name( target_t *t )
        return cp;
 }
 
-static int max_target_number(void)
-{
-       target_t *t;
-       int x;
-
-       x = -1;
-       t = all_targets;
-       while (t) {
-               if (x < t->target_number) {
-                       x = (t->target_number) + 1;
-               }
-               t = t->next;
-       }
-       return x;
-}
-
 /* determine the number of the new target */
 static int new_target_number(void)
 {
@@ -346,14 +330,19 @@ target_t *get_target(const char *id)
                        return target;
        }
 
+       /* It's OK to remove this fallback sometime after August 2010 or so */
+
        /* no match, try as number */
        unsigned num;
        if (parse_uint(id, &num) != ERROR_OK)
                return NULL;
 
        for (target = all_targets; target; target = target->next) {
-               if (target->target_number == (int)num)
+               if (target->target_number == (int)num) {
+                       LOG_WARNING("use '%s' as target identifier, not '%u'",
+                                       target->cmd_name, num);
                        return target;
+               }
        }
 
        return NULL;
@@ -374,11 +363,6 @@ static target_t *get_target_by_num(int num)
        return NULL;
 }
 
-int get_num_by_target(target_t *query_target)
-{
-       return query_target->target_number;
-}
-
 target_t* get_current_target(command_context_t *cmd_ctx)
 {
        target_t *target = get_target_by_num(cmd_ctx->current_target);
@@ -559,6 +543,11 @@ static int target_soft_reset_halt_imp(struct target_s *target)
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
        }
+       if (!target->type->soft_reset_halt_imp) {
+               LOG_ERROR("Target %s does not support soft_reset_halt",
+                               target->cmd_name);
+               return ERROR_FAIL;
+       }
        return target->type->soft_reset_halt_imp(target);
 }
 
@@ -1505,10 +1494,19 @@ int target_register_user_commands(struct command_context_s *cmd_ctx)
        register_command(cmd_ctx,  NULL, "mwh", handle_mw_command, COMMAND_EXEC, "write memory half-word <addr> <value> [count]");
        register_command(cmd_ctx,  NULL, "mwb", handle_mw_command, COMMAND_EXEC, "write memory byte <addr> <value> [count]");
 
-       register_command(cmd_ctx,  NULL, "bp", handle_bp_command, COMMAND_EXEC, "set breakpoint <address> <length> [hw]");
-       register_command(cmd_ctx,  NULL, "rbp", handle_rbp_command, COMMAND_EXEC, "remove breakpoint <adress>");
-       register_command(cmd_ctx,  NULL, "wp", handle_wp_command, COMMAND_EXEC, "set watchpoint <address> <length> <r/w/a> [value] [mask]");
-       register_command(cmd_ctx,  NULL, "rwp", handle_rwp_command, COMMAND_EXEC, "remove watchpoint <adress>");
+       register_command(cmd_ctx,  NULL, "bp",
+                       handle_bp_command, COMMAND_EXEC,
+                       "list or set breakpoint [<address> <length> [hw]]");
+       register_command(cmd_ctx,  NULL, "rbp",
+                       handle_rbp_command, COMMAND_EXEC,
+                       "remove breakpoint <address>");
+       register_command(cmd_ctx,  NULL, "wp",
+                       handle_wp_command, COMMAND_EXEC,
+                       "list or set watchpoint "
+                               "[<address> <length> <r/w/a> [value] [mask]]");
+       register_command(cmd_ctx,  NULL, "rwp",
+                       handle_rwp_command, COMMAND_EXEC,
+                       "remove watchpoint <address>");
 
        register_command(cmd_ctx,  NULL, "load_image", handle_load_image_command, COMMAND_EXEC, "load_image <file> <address> ['bin'|'ihex'|'elf'|'s19'] [min_address] [max_length]");
        register_command(cmd_ctx,  NULL, "dump_image", handle_dump_image_command, COMMAND_EXEC, "dump_image <file> <address> <size>");
@@ -1741,17 +1739,28 @@ static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char
                while (cache)
                {
                        int i;
-                       for (i = 0; i < cache->num_regs; i++)
+
+                       for (i = 0, reg = cache->reg_list;
+                                       i < cache->num_regs;
+                                       i++, reg++, count++)
                        {
-                               value = buf_to_str(cache->reg_list[i].value, cache->reg_list[i].size, 16);
-                               command_print(cmd_ctx, "(%i) %s (/%i): 0x%s (dirty: %i, valid: %i)",
-                                                         count++,
-                                                         cache->reg_list[i].name,
-                                                         (int)(cache->reg_list[i].size),
-                                                         value,
-                                                         cache->reg_list[i].dirty,
-                                                         cache->reg_list[i].valid);
-                               free(value);
+                               /* only print cached values if they are valid */
+                               if (reg->valid) {
+                                       value = buf_to_str(reg->value,
+                                                       reg->size, 16);
+                                       command_print(cmd_ctx,
+                                                       "(%i) %s (/%" PRIu32 "): 0x%s%s",
+                                                       count, reg->name,
+                                                       reg->size, value,
+                                                       reg->dirty
+                                                               ? " (dirty)"
+                                                               : "");
+                                       free(value);
+                               } else {
+                                       command_print(cmd_ctx, "(%i) %s (/%" PRIu32 ")",
+                                                         count, reg->name,
+                                                         reg->size) ;
+                               }
                        }
                        cache = cache->next;
                }
@@ -4015,6 +4024,13 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                }
                if (!target->tap->enabled)
                        goto err_tap_disabled;
+               if (!target->type->assert_reset
+                               || !target->type->deassert_reset) {
+                       Jim_SetResult_sprintf(interp,
+                                       "No target-specific reset for %s",
+                                       target->cmd_name);
+                       return JIM_ERR;
+               }
                /* determine if we should halt or not. */
                target->reset_halt = !!a;
                /* When this happens - all workareas are invalid. */
@@ -4355,6 +4371,8 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                return target_create(&goi);
                break;
        case TG_CMD_NUMBER:
+               /* It's OK to remove this mechanism sometime after August 2010 or so */
+               LOG_WARNING("don't use numbers as target identifiers; use names");
                if (goi.argc != 1) {
                        Jim_SetResult_sprintf(goi.interp, "expected: target number ?NUMBER?");
                        return JIM_ERR;
@@ -4363,23 +4381,25 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                if (e != JIM_OK) {
                        return JIM_ERR;
                }
-               {
-                       target_t *t;
-                       t = get_target_by_num(w);
-                       if (t == NULL) {
-                               Jim_SetResult_sprintf(goi.interp,"Target: number %d does not exist", (int)(w));
-                               return JIM_ERR;
-                       }
-                       Jim_SetResultString(goi.interp, t->cmd_name, -1);
-                       return JIM_OK;
+               for (x = 0, target = all_targets; target; target = target->next, x++) {
+                       if (target->target_number == w)
+                               break;
                }
+               if (target == NULL) {
+                       Jim_SetResult_sprintf(goi.interp,
+                                       "Target: number %d does not exist", (int)(w));
+                       return JIM_ERR;
+               }
+               Jim_SetResultString(goi.interp, target->cmd_name, -1);
+               return JIM_OK;
        case TG_CMD_COUNT:
                if (goi.argc != 0) {
                        Jim_WrongNumArgs(goi.interp, 0, goi.argv, "<no parameters>");
                        return JIM_ERR;
                }
-               Jim_SetResult(goi.interp,
-                                          Jim_NewIntObj(goi.interp, max_target_number()));
+               for (x = 0, target = all_targets; target; target = target->next, x++)
+                       continue;
+               Jim_SetResult(goi.interp, Jim_NewIntObj(goi.interp, x));
                return JIM_OK;
        }
 

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)