Andreas Fritiofson <andreas.fritiofson@gmail.com> UTF8 fixes
[openocd.git] / src / target / target.c
index 67bbcfc137cdbb7ac996f630962acbd1b31e187a..670b4ba8b5921e3230e48cddc34ab5562fd82fd7 100644 (file)
@@ -2,7 +2,7 @@
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
- *   Copyright (C) 2007,2008 Øyvind Harboe                                 *
+ *   Copyright (C) 2007,2008 Øyvind Harboe                                 *
  *   oyvind.harboe@zylin.com                                               *
  *                                                                         *
  *   Copyright (C) 2008, Duane Ellis                                       *
@@ -237,6 +237,18 @@ const Jim_Nvp nvp_reset_modes[] = {
        { .name = NULL     , .value = -1 },
 };
 
+const char *
+target_state_name( target_t *t )
+{
+       const char *cp;
+       cp = Jim_Nvp_value2name_simple(nvp_target_state, t->state)->name;
+       if( !cp ){
+               LOG_ERROR("Invalid target state: %d", (int)(t->state));
+               cp = "(*BUG*unknown*BUG*)";
+       }
+       return cp;
+}
+
 static int max_target_number(void)
 {
        target_t *t;
@@ -969,7 +981,7 @@ int target_alloc_working_area(struct target_s *target, uint32_t size, working_ar
 
                if (free_size < size)
                {
-                       LOG_WARNING("not enough working area available(requested %u, free %u)", 
+                       LOG_WARNING("not enough working area available(requested %u, free %u)",
                                    (unsigned)(size), (unsigned)(free_size));
                        return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
                }
@@ -1085,8 +1097,7 @@ int target_arch_state(struct target_s *target)
                return ERROR_OK;
        }
 
-       LOG_USER("target state: %s",
-                Jim_Nvp_value2name_simple(nvp_target_state,target->state)->name);
+       LOG_USER("target state: %s", target_state_name( target ));
 
        if (target->state != TARGET_HALTED)
                return ERROR_OK;
@@ -1102,7 +1113,7 @@ int target_arch_state(struct target_s *target)
 int target_write_buffer(struct target_s *target, uint32_t address, uint32_t size, uint8_t *buffer)
 {
        int retval;
-       LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", 
+       LOG_DEBUG("writing buffer of %i byte at 0x%8.8x",
                  (int)size, (unsigned)address);
 
        if (!target_was_examined(target))
@@ -1118,8 +1129,8 @@ int target_write_buffer(struct target_s *target, uint32_t address, uint32_t size
        if ((address + size - 1) < address)
        {
                /* GDB can request this when e.g. PC is 0xfffffffc*/
-               LOG_ERROR("address + size wrapped(0x%08x, 0x%08x)", 
-                                 (unsigned)address, 
+               LOG_ERROR("address + size wrapped(0x%08x, 0x%08x)",
+                                 (unsigned)address,
                                  (unsigned)size);
                return ERROR_FAIL;
        }
@@ -1184,7 +1195,7 @@ int target_write_buffer(struct target_s *target, uint32_t address, uint32_t size
 int target_read_buffer(struct target_s *target, uint32_t address, uint32_t size, uint8_t *buffer)
 {
        int retval;
-       LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", 
+       LOG_DEBUG("reading buffer of %i byte at 0x%8.8x",
                          (int)size, (unsigned)address);
 
        if (!target_was_examined(target))
@@ -1200,8 +1211,8 @@ int target_read_buffer(struct target_s *target, uint32_t address, uint32_t size,
        if ((address + size - 1) < address)
        {
                /* GDB can request this when e.g. PC is 0xfffffffc*/
-               LOG_ERROR("address + size wrapped(0x%08" PRIx32 ", 0x%08" PRIx32 ")", 
-                                 address, 
+               LOG_ERROR("address + size wrapped(0x%08" PRIx32 ", 0x%08" PRIx32 ")",
+                                 address,
                                  size);
                return ERROR_FAIL;
        }
@@ -1326,14 +1337,14 @@ int target_read_u32(struct target_s *target, uint32_t address, uint32_t *value)
        if (retval == ERROR_OK)
        {
                *value = target_buffer_get_u32(target, value_buf);
-               LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8" PRIx32 "", 
-                                 address, 
+               LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8" PRIx32 "",
+                                 address,
                                  *value);
        }
        else
        {
                *value = 0x0;
-               LOG_DEBUG("address: 0x%8.8" PRIx32 " failed", 
+               LOG_DEBUG("address: 0x%8.8" PRIx32 " failed",
                                  address);
        }
 
@@ -1354,14 +1365,14 @@ int target_read_u16(struct target_s *target, uint32_t address, uint16_t *value)
        if (retval == ERROR_OK)
        {
                *value = target_buffer_get_u16(target, value_buf);
-               LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%4.4x", 
-                                 address, 
+               LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%4.4x",
+                                 address,
                                  *value);
        }
        else
        {
                *value = 0x0;
-               LOG_DEBUG("address: 0x%8.8" PRIx32 " failed", 
+               LOG_DEBUG("address: 0x%8.8" PRIx32 " failed",
                                  address);
        }
 
@@ -1379,14 +1390,14 @@ int target_read_u8(struct target_s *target, uint32_t address, uint8_t *value)
 
        if (retval == ERROR_OK)
        {
-               LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%2.2x", 
-                                 address, 
+               LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%2.2x",
+                                 address,
                                  *value);
        }
        else
        {
                *value = 0x0;
-               LOG_DEBUG("address: 0x%8.8" PRIx32 " failed", 
+               LOG_DEBUG("address: 0x%8.8" PRIx32 " failed",
                                  address);
        }
 
@@ -1403,8 +1414,8 @@ int target_write_u32(struct target_s *target, uint32_t address, uint32_t value)
                return ERROR_FAIL;
        }
 
-       LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8" PRIx32 "", 
-                         address, 
+       LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8" PRIx32 "",
+                         address,
                          value);
 
        target_buffer_set_u32(target, value_buf, value);
@@ -1426,8 +1437,8 @@ int target_write_u16(struct target_s *target, uint32_t address, uint16_t value)
                return ERROR_FAIL;
        }
 
-       LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8x", 
-                         address, 
+       LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8x",
+                         address,
                          value);
 
        target_buffer_set_u16(target, value_buf, value);
@@ -1448,7 +1459,7 @@ int target_write_u8(struct target_s *target, uint32_t address, uint8_t value)
                return ERROR_FAIL;
        }
 
-       LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%2.2x", 
+       LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%2.2x",
                          address, value);
 
        if ((retval = target_write_memory(target, address, 1, 1, &value)) != ERROR_OK)
@@ -1544,8 +1555,7 @@ DumpTargets:
                char marker = ' ';
 
                if (target->tap->enabled)
-                       state = Jim_Nvp_value2name_simple(nvp_target_state,
-                                       target->state)->name;
+                       state = target_state_name( target );
                else
                        state = "tap-disabled";
 
@@ -1734,12 +1744,12 @@ static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char
                        for (i = 0; i < cache->num_regs; i++)
                        {
                                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, 
+                               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, 
+                                                         value,
+                                                         cache->reg_list[i].dirty,
                                                          cache->reg_list[i].valid);
                                free(value);
                        }
@@ -2029,15 +2039,18 @@ static int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, cha
         * with one argument addr = args[0],
         * handle breakpoints, debugging */
        uint32_t addr = 0;
+       int current_pc = 1;
        if (argc == 1)
        {
                int retval = parse_u32(args[0], &addr);
                if (ERROR_OK != retval)
                        return retval;
+               current_pc = 0;
        }
 
        target_t *target = get_current_target(cmd_ctx);
-       return target->type->step(target, 0, addr, 1);
+
+       return target->type->step(target, current_pc, addr, 1);
 }
 
 static void handle_md_output(struct command_context_s *cmd_ctx,
@@ -2066,7 +2079,7 @@ static void handle_md_output(struct command_context_s *cmd_ctx,
                {
                        output_len += snprintf(output + output_len,
                                        sizeof(output) - output_len,
-                                       "0x%8.8x: ", 
+                                       "0x%8.8x: ",
                                        (unsigned)(address + (i*size)));
                }
 
@@ -2241,7 +2254,7 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm
 
        duration_t duration;
        char *duration_text;
-       
+
        int retval = parse_load_image_command_args(args, argc,
                        &image, &min_address, &max_address);
        if (ERROR_OK != retval)
@@ -2262,8 +2275,8 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm
                buffer = malloc(image.sections[i].size);
                if (buffer == NULL)
                {
-                       command_print(cmd_ctx, 
-                                                 "error allocating buffer for section (%d bytes)", 
+                       command_print(cmd_ctx,
+                                                 "error allocating buffer for section (%d bytes)",
                                                  (int)(image.sections[i].size));
                        break;
                }
@@ -2300,8 +2313,8 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm
                                break;
                        }
                        image_size += length;
-                       command_print(cmd_ctx, "%u byte written at address 0x%8.8" PRIx32 "", 
-                                                 (unsigned int)length, 
+                       command_print(cmd_ctx, "%u byte written at address 0x%8.8" PRIx32 "",
+                                                 (unsigned int)length,
                                                  image.sections[i].base_address + offset);
                }
 
@@ -2316,8 +2329,8 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm
 
        if (retval == ERROR_OK)
        {
-               command_print(cmd_ctx, "downloaded %u byte in %s", 
-                                         (unsigned int)image_size, 
+               command_print(cmd_ctx, "downloaded %u byte in %s",
+                                         (unsigned int)image_size,
                                          duration_text);
        }
        free(duration_text);
@@ -2459,8 +2472,8 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct
                buffer = malloc(image.sections[i].size);
                if (buffer == NULL)
                {
-                       command_print(cmd_ctx, 
-                                                 "error allocating buffer for section (%d bytes)", 
+                       command_print(cmd_ctx,
+                                                 "error allocating buffer for section (%d bytes)",
                                                  (int)(image.sections[i].size));
                        break;
                }
@@ -2507,10 +2520,10 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct
                                        {
                                                if (data[t] != buffer[t])
                                                {
-                                                       command_print(cmd_ctx, 
-                                                                                 "Verify operation failed address 0x%08x. Was 0x%02x instead of 0x%02x\n", 
-                                                                                 (unsigned)(t + image.sections[i].base_address), 
-                                                                                 data[t], 
+                                                       command_print(cmd_ctx,
+                                                                                 "Verify operation failed address 0x%08x. Was 0x%02x instead of 0x%02x\n",
+                                                                                 (unsigned)(t + image.sections[i].base_address),
+                                                                                 data[t],
                                                                                  buffer[t]);
                                                        free(data);
                                                        free(buffer);
@@ -2528,8 +2541,8 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct
                        }
                } else
                {
-                       command_print(cmd_ctx, "address 0x%08" PRIx32 " length 0x%08" PRIx32 "", 
-                                                 image.sections[i].base_address, 
+                       command_print(cmd_ctx, "address 0x%08" PRIx32 " length 0x%08" PRIx32 "",
+                                                 image.sections[i].base_address,
                                                  buf_cnt);
                }
 
@@ -2546,8 +2559,8 @@ done:
 
        if (retval == ERROR_OK)
        {
-               command_print(cmd_ctx, "verified %u bytes in %s", 
-                                         (unsigned int)image_size, 
+               command_print(cmd_ctx, "verified %u bytes in %s",
+                                         (unsigned int)image_size,
                                          duration_text);
        }
        free(duration_text);
@@ -2578,7 +2591,7 @@ static int handle_bp_command_list(struct command_context_s *cmd_ctx)
                        char* buf = buf_to_str(breakpoint->orig_instr,
                                        breakpoint->length, 16);
                        command_print(cmd_ctx, "0x%8.8" PRIx32 ", 0x%x, %i, 0x%s",
-                                       breakpoint->address, 
+                                       breakpoint->address,
                                        breakpoint->length,
                                        breakpoint->set, buf);
                        free(buf);
@@ -2586,7 +2599,7 @@ static int handle_bp_command_list(struct command_context_s *cmd_ctx)
                else
                {
                        command_print(cmd_ctx, "0x%8.8" PRIx32 ", 0x%x, %i",
-                                                 breakpoint->address, 
+                                                 breakpoint->address,
                                                  breakpoint->length, breakpoint->set);
                }
 
@@ -2667,9 +2680,9 @@ static int handle_wp_command(struct command_context_s *cmd_ctx, char *cmd, char
 
                while (watchpoint)
                {
-                       command_print(cmd_ctx, 
-                                                 "address: 0x%8.8" PRIx32 ", len: 0x%8.8x, r/w/a: %i, value: 0x%8.8" PRIx32 ", mask: 0x%8.8" PRIx32 "", 
-                                                 watchpoint->address, 
+                       command_print(cmd_ctx,
+                                                 "address: 0x%8.8" PRIx32 ", len: 0x%8.8x, r/w/a: %i, value: 0x%8.8" PRIx32 ", mask: 0x%8.8" PRIx32 "",
+                                                 watchpoint->address,
                                                  watchpoint->length,
                                                  (int)(watchpoint->rw),
                                                  watchpoint->value,
@@ -3111,8 +3124,8 @@ static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_
        } else {
                char buf[100];
                Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
-               sprintf(buf, "mem2array address: 0x%08" PRIx32 " is not aligned for %" PRId32 " byte reads", 
-                               addr, 
+               sprintf(buf, "mem2array address: 0x%08" PRIx32 " is not aligned for %" PRId32 " byte reads",
+                               addr,
                                width);
                Jim_AppendStrings(interp, Jim_GetResult(interp), buf , NULL);
                return JIM_ERR;
@@ -3135,9 +3148,9 @@ static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_
                retval = target_read_memory(target, addr, width, count, buffer);
                if (retval != ERROR_OK) {
                        /* BOO !*/
-                       LOG_ERROR("mem2array: Read @ 0x%08x, w=%d, cnt=%d, failed", 
-                                         (unsigned int)addr, 
-                                         (int)width, 
+                       LOG_ERROR("mem2array: Read @ 0x%08x, w=%d, cnt=%d, failed",
+                                         (unsigned int)addr,
+                                         (int)width,
                                          (int)count);
                        Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
                        Jim_AppendStrings(interp, Jim_GetResult(interp), "mem2array: cannot read memory", NULL);
@@ -3298,8 +3311,8 @@ static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_
        } else {
                char buf[100];
                Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
-               sprintf(buf, "array2mem address: 0x%08x is not aligned for %d byte reads", 
-                               (unsigned int)addr, 
+               sprintf(buf, "array2mem address: 0x%08x is not aligned for %d byte reads",
+                               (unsigned int)addr,
                                (int)width);
                Jim_AppendStrings(interp, Jim_GetResult(interp), buf , NULL);
                return JIM_ERR;
@@ -3339,9 +3352,9 @@ static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_
                retval = target_write_memory(target, addr, width, count, buffer);
                if (retval != ERROR_OK) {
                        /* BOO !*/
-                       LOG_ERROR("array2mem: Write @ 0x%08x, w=%d, cnt=%d, failed", 
-                                         (unsigned int)addr, 
-                                         (int)width, 
+                       LOG_ERROR("array2mem: Write @ 0x%08x, w=%d, cnt=%d, failed",
+                                         (unsigned int)addr,
+                                         (int)width,
                                          (int)count);
                        Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
                        Jim_AppendStrings(interp, Jim_GetResult(interp), "array2mem: cannot read memory", NULL);
@@ -3381,7 +3394,7 @@ void target_handle_event(target_t *target, enum target_event e)
        while (teap) {
                if (teap->event == e) {
                        done = 1;
-                       LOG_DEBUG("target: (%d) %s (%s) event: %d (%s) action: %s\n",
+                       LOG_DEBUG("target: (%d) %s (%s) event: %d (%s) action: %s",
                                           target->target_number,
                                           target->cmd_name,
                                           target_get_name(target),
@@ -4079,7 +4092,8 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                        return JIM_ERR;
                }
                Jim_SetResultString(goi.interp,
-                                                        Jim_Nvp_value2name_simple(nvp_target_state,target->state)->name,-1);
+                                                       target_state_name( target ),
+                                                       -1);
                return JIM_OK;
        case TS_CMD_INVOKE_EVENT:
                if (goi.argc != 1) {
@@ -4443,7 +4457,7 @@ static int handle_fast_load_image_command(struct command_context_s *cmd_ctx, cha
                buffer = malloc(image.sections[i].size);
                if (buffer == NULL)
                {
-                       command_print(cmd_ctx, "error allocating buffer for section (%d bytes)", 
+                       command_print(cmd_ctx, "error allocating buffer for section (%d bytes)",
                                                  (int)(image.sections[i].size));
                        break;
                }
@@ -4486,8 +4500,8 @@ static int handle_fast_load_image_command(struct command_context_s *cmd_ctx, cha
                        fastload[i].length = length;
 
                        image_size += length;
-                       command_print(cmd_ctx, "%u byte written at address 0x%8.8x", 
-                                                 (unsigned int)length, 
+                       command_print(cmd_ctx, "%u byte written at address 0x%8.8x",
+                                                 (unsigned int)length,
                                                  ((unsigned int)(image.sections[i].base_address + offset)));
                }
 
@@ -4528,8 +4542,8 @@ static int handle_fast_load_command(struct command_context_s *cmd_ctx, char *cmd
        for (i = 0; i < fastload_num;i++)
        {
                target_t *target = get_current_target(cmd_ctx);
-               command_print(cmd_ctx, "Write to 0x%08x, length 0x%08x", 
-                                         (unsigned int)(fastload[i].address), 
+               command_print(cmd_ctx, "Write to 0x%08x, length 0x%08x",
+                                         (unsigned int)(fastload[i].address),
                                          (unsigned int)(fastload[i].length));
                if (retval == ERROR_OK)
                {
@@ -4544,7 +4558,7 @@ static int handle_fast_load_command(struct command_context_s *cmd_ctx, char *cmd
 
 
 /*
- * Local Variables: 
+ * Local Variables:
  * c-basic-offset: 4
  * tab-width: 4
  * End:

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)