command_handler: change to 'argc' to CMD_ARGC
[openocd.git] / src / target / target.c
index 85c228a0c97308b97c35d8df5081f11814515f8d..88fea1778f21ae0165c07be8ba15368d0cd366b9 100644 (file)
@@ -36,6 +36,7 @@
 #include "target.h"
 #include "target_type.h"
 #include "target_request.h"
+#include "breakpoints.h"
 #include "time_support.h"
 #include "register.h"
 #include "trace.h"
@@ -644,20 +645,13 @@ int target_run_algorithm(struct target *target,
                        entry_point, exit_point, timeout_ms, arch_info);
 }
 
-/// @returns @c true if the target has been examined.
-bool target_was_examined(struct target *target)
-{
-       return target->type->examined;
-}
-/// Sets the @c examined flag for the given target.
-void target_set_examined(struct target *target)
-{
-       target->type->examined = true;
-}
-// Reset the @c examined flag for the given target.
-void target_reset_examined(struct target *target)
+/**
+ * Reset the @c examined flag for the given target.
+ * Pure paranoia -- targets are zeroed on allocation.
+ */
+static void target_reset_examined(struct target *target)
 {
-       target->type->examined = false;
+       target->examined = false;
 }
 
 
@@ -1654,7 +1648,7 @@ COMMAND_HANDLER(handle_targets_command)
 {
        struct target *target = all_targets;
 
-       if (argc == 1)
+       if (CMD_ARGC == 1)
        {
                target = get_target(args[0]);
                if (target == NULL) {
@@ -1874,7 +1868,7 @@ COMMAND_HANDLER(handle_reg_command)
        target = get_current_target(cmd_ctx);
 
        /* list all available registers for the current target */
-       if (argc == 0)
+       if (CMD_ARGC == 0)
        {
                struct reg_cache *cache = target->reg_cache;
 
@@ -1954,15 +1948,14 @@ COMMAND_HANDLER(handle_reg_command)
        }
 
        /* display a register */
-       if ((argc == 1) || ((argc == 2) && !((args[1][0] >= '0') && (args[1][0] <= '9'))))
+       if ((CMD_ARGC == 1) || ((CMD_ARGC == 2) && !((args[1][0] >= '0') && (args[1][0] <= '9'))))
        {
-               if ((argc == 2) && (strcmp(args[1], "force") == 0))
+               if ((CMD_ARGC == 2) && (strcmp(args[1], "force") == 0))
                        reg->valid = 0;
 
                if (reg->valid == 0)
                {
-                       struct reg_arch_type *arch_type = register_get_arch_type(reg->arch_type);
-                       arch_type->get(reg);
+                       reg->type->get(reg);
                }
                value = buf_to_str(reg->value, reg->size, 16);
                command_print(cmd_ctx, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value);
@@ -1971,13 +1964,12 @@ COMMAND_HANDLER(handle_reg_command)
        }
 
        /* set register value */
-       if (argc == 2)
+       if (CMD_ARGC == 2)
        {
-               uint8_t *buf = malloc(CEIL(reg->size, 8));
+               uint8_t *buf = malloc(DIV_ROUND_UP(reg->size, 8));
                str_to_buf(args[1], strlen(args[1]), buf, reg->size, 0);
 
-               struct reg_arch_type *arch_type = register_get_arch_type(reg->arch_type);
-               arch_type->set(reg, buf);
+               reg->type->set(reg, buf);
 
                value = buf_to_str(reg->value, reg->size, 16);
                command_print(cmd_ctx, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value);
@@ -1998,7 +1990,7 @@ COMMAND_HANDLER(handle_poll_command)
        int retval = ERROR_OK;
        struct target *target = get_current_target(cmd_ctx);
 
-       if (argc == 0)
+       if (CMD_ARGC == 0)
        {
                command_print(cmd_ctx, "background polling: %s",
                                jtag_poll_get_enabled() ? "on" : "off");
@@ -2013,7 +2005,7 @@ COMMAND_HANDLER(handle_poll_command)
                        return retval;
 
        }
-       else if (argc == 1)
+       else if (CMD_ARGC == 1)
        {
                if (strcmp(args[0], "on") == 0)
                {
@@ -2037,11 +2029,11 @@ COMMAND_HANDLER(handle_poll_command)
 
 COMMAND_HANDLER(handle_wait_halt_command)
 {
-       if (argc > 1)
+       if (CMD_ARGC > 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        unsigned ms = 5000;
-       if (1 == argc)
+       if (1 == CMD_ARGC)
        {
                int retval = parse_uint(args[0], &ms);
                if (ERROR_OK != retval)
@@ -2111,7 +2103,7 @@ COMMAND_HANDLER(handle_halt_command)
        if (ERROR_OK != retval)
                return retval;
 
-       if (argc == 1)
+       if (CMD_ARGC == 1)
        {
                unsigned wait;
                retval = parse_uint(args[0], &wait);
@@ -2137,11 +2129,11 @@ COMMAND_HANDLER(handle_soft_reset_halt_command)
 
 COMMAND_HANDLER(handle_reset_command)
 {
-       if (argc > 1)
+       if (CMD_ARGC > 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        enum target_reset_mode reset_mode = RESET_RUN;
-       if (argc == 1)
+       if (CMD_ARGC == 1)
        {
                const Jim_Nvp *n;
                n = Jim_Nvp_name2value_simple(nvp_reset_modes, args[0]);
@@ -2159,7 +2151,7 @@ COMMAND_HANDLER(handle_reset_command)
 COMMAND_HANDLER(handle_resume_command)
 {
        int current = 1;
-       if (argc > 1)
+       if (CMD_ARGC > 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        struct target *target = get_current_target(cmd_ctx);
@@ -2169,7 +2161,7 @@ COMMAND_HANDLER(handle_resume_command)
         * with one arguments, addr = args[0],
         * handle breakpoints, not debugging */
        uint32_t addr = 0;
-       if (argc == 1)
+       if (CMD_ARGC == 1)
        {
                COMMAND_PARSE_NUMBER(u32, args[0], addr);
                current = 0;
@@ -2180,7 +2172,7 @@ COMMAND_HANDLER(handle_resume_command)
 
 COMMAND_HANDLER(handle_step_command)
 {
-       if (argc > 1)
+       if (CMD_ARGC > 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        LOG_DEBUG("-");
@@ -2190,7 +2182,7 @@ COMMAND_HANDLER(handle_step_command)
         * handle breakpoints, debugging */
        uint32_t addr = 0;
        int current_pc = 1;
-       if (argc == 1)
+       if (CMD_ARGC == 1)
        {
                COMMAND_PARSE_NUMBER(u32, args[0], addr);
                current_pc = 0;
@@ -2252,11 +2244,12 @@ static void handle_md_output(struct command_context *cmd_ctx,
 
 COMMAND_HANDLER(handle_md_command)
 {
-       if (argc < 1)
+       if (CMD_ARGC < 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        unsigned size = 0;
-       switch (CMD_NAME[2]) {
+       const char *cmd_name = CMD_NAME;
+       switch (cmd_name[6]) {
        case 'w': size = 4; break;
        case 'h': size = 2; break;
        case 'b': size = 1; break;
@@ -2268,14 +2261,14 @@ COMMAND_HANDLER(handle_md_command)
                        uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
        if (physical)
        {
-               argc--;
+               CMD_ARGC--;
                args++;
                fn=target_read_phys_memory;
        } else
        {
                fn=target_read_memory;
        }
-       if ((argc < 1) || (argc > 2))
+       if ((CMD_ARGC < 1) || (CMD_ARGC > 2))
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
@@ -2284,7 +2277,7 @@ COMMAND_HANDLER(handle_md_command)
        COMMAND_PARSE_NUMBER(u32, args[0], address);
 
        unsigned count = 1;
-       if (argc == 2)
+       if (CMD_ARGC == 2)
                COMMAND_PARSE_NUMBER(uint, args[1], count);
 
        uint8_t *buffer = calloc(count, size);
@@ -2301,23 +2294,24 @@ COMMAND_HANDLER(handle_md_command)
 
 COMMAND_HANDLER(handle_mw_command)
 {
-       if (argc < 2)
+       if (CMD_ARGC < 2)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
        bool physical=strcmp(args[0], "phys")==0;
        int (*fn)(struct target *target,
                        uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
+       const char *cmd_name = CMD_NAME;
        if (physical)
        {
-               argc--;
+               CMD_ARGC--;
                args++;
                fn=target_write_phys_memory;
        } else
        {
                fn=target_write_memory;
        }
-       if ((argc < 2) || (argc > 3))
+       if ((CMD_ARGC < 2) || (CMD_ARGC > 3))
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        uint32_t address;
@@ -2327,13 +2321,13 @@ COMMAND_HANDLER(handle_mw_command)
        COMMAND_PARSE_NUMBER(u32, args[1], value);
 
        unsigned count = 1;
-       if (argc == 3)
+       if (CMD_ARGC == 3)
                COMMAND_PARSE_NUMBER(uint, args[2], count);
 
        struct target *target = get_current_target(cmd_ctx);
        unsigned wordsize;
        uint8_t value_buf[4];
-       switch (CMD_NAME[2])
+       switch (cmd_name[6])
        {
                case 'w':
                        wordsize = 4;
@@ -2366,12 +2360,12 @@ COMMAND_HANDLER(handle_mw_command)
 static COMMAND_HELPER(parse_load_image_command_args, struct image *image,
                uint32_t *min_address, uint32_t *max_address)
 {
-       if (argc < 1 || argc > 5)
+       if (CMD_ARGC < 1 || CMD_ARGC > 5)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        /* a base address isn't always necessary,
         * default to 0x0 (i.e. don't relocate) */
-       if (argc >= 2)
+       if (CMD_ARGC >= 2)
        {
                uint32_t addr;
                COMMAND_PARSE_NUMBER(u32, args[1], addr);
@@ -2383,11 +2377,11 @@ static COMMAND_HELPER(parse_load_image_command_args, struct image *image,
 
        image->start_address_set = 0;
 
-       if (argc >= 4)
+       if (CMD_ARGC >= 4)
        {
                COMMAND_PARSE_NUMBER(u32, args[3], *min_address);
        }
-       if (argc == 5)
+       if (CMD_ARGC == 5)
        {
                COMMAND_PARSE_NUMBER(u32, args[4], *max_address);
                // use size (given) to find max (required)
@@ -2403,7 +2397,7 @@ static COMMAND_HELPER(parse_load_image_command_args, struct image *image,
 COMMAND_HANDLER(handle_load_image_command)
 {
        uint8_t *buffer;
-       uint32_t buf_cnt;
+       size_t buf_cnt;
        uint32_t image_size;
        uint32_t min_address = 0;
        uint32_t max_address = 0xffffffff;
@@ -2420,7 +2414,7 @@ COMMAND_HANDLER(handle_load_image_command)
        struct duration bench;
        duration_start(&bench);
 
-       if (image_open(&image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
+       if (image_open(&image, args[0], (CMD_ARGC >= 3) ? args[2] : NULL) != ERROR_OK)
        {
                return ERROR_OK;
        }
@@ -2501,7 +2495,7 @@ COMMAND_HANDLER(handle_dump_image_command)
 
        struct target *target = get_current_target(cmd_ctx);
 
-       if (argc != 3)
+       if (CMD_ARGC != 3)
        {
                command_print(cmd_ctx, "usage: dump_image <filename> <address> <size>");
                return ERROR_OK;
@@ -2523,7 +2517,7 @@ COMMAND_HANDLER(handle_dump_image_command)
        int retval = ERROR_OK;
        while (size > 0)
        {
-               uint32_t size_written;
+               size_t size_written;
                uint32_t this_run_size = (size > 560) ? 560 : size;
                retval = target_read_buffer(target, address, this_run_size, buffer);
                if (retval != ERROR_OK)
@@ -2547,7 +2541,7 @@ COMMAND_HANDLER(handle_dump_image_command)
        if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
        {
                command_print(cmd_ctx,
-                               "dumped %lld bytes in %fs (%0.3f kb/s)", fileio.size,
+                               "dumped %zu bytes in %fs (%0.3f kb/s)", fileio.size,
                                duration_elapsed(&bench), duration_kbps(&bench, fileio.size));
        }
 
@@ -2557,7 +2551,7 @@ COMMAND_HANDLER(handle_dump_image_command)
 static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
 {
        uint8_t *buffer;
-       uint32_t buf_cnt;
+       size_t buf_cnt;
        uint32_t image_size;
        int i;
        int retval;
@@ -2568,7 +2562,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
 
        struct target *target = get_current_target(cmd_ctx);
 
-       if (argc < 1)
+       if (CMD_ARGC < 1)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
@@ -2582,7 +2576,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
        struct duration bench;
        duration_start(&bench);
 
-       if (argc >= 2)
+       if (CMD_ARGC >= 2)
        {
                uint32_t addr;
                COMMAND_PARSE_NUMBER(u32, args[1], addr);
@@ -2597,7 +2591,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
 
        image.start_address_set = 0;
 
-       if ((retval = image_open(&image, args[0], (argc == 3) ? args[2] : NULL)) != ERROR_OK)
+       if ((retval = image_open(&image, args[0], (CMD_ARGC == 3) ? args[2] : NULL)) != ERROR_OK)
        {
                return retval;
        }
@@ -2678,7 +2672,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
                        }
                } else
                {
-                       command_print(cmd_ctx, "address 0x%08" PRIx32 " length 0x%08" PRIx32 "",
+                       command_print(cmd_ctx, "address 0x%08" PRIx32 " length 0x%08zx",
                                                  image.sections[i].base_address,
                                                  buf_cnt);
                }
@@ -2751,10 +2745,10 @@ static int handle_bp_command_set(struct command_context *cmd_ctx,
 
 COMMAND_HANDLER(handle_bp_command)
 {
-       if (argc == 0)
+       if (CMD_ARGC == 0)
                return handle_bp_command_list(cmd_ctx);
 
-       if (argc < 2 || argc > 3)
+       if (CMD_ARGC < 2 || CMD_ARGC > 3)
        {
                command_print(cmd_ctx, "usage: bp <address> <length> ['hw']");
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -2766,7 +2760,7 @@ COMMAND_HANDLER(handle_bp_command)
        COMMAND_PARSE_NUMBER(u32, args[1], length);
 
        int hw = BKPT_SOFT;
-       if (argc == 3)
+       if (CMD_ARGC == 3)
        {
                if (strcmp(args[2], "hw") == 0)
                        hw = BKPT_HARD;
@@ -2779,7 +2773,7 @@ COMMAND_HANDLER(handle_bp_command)
 
 COMMAND_HANDLER(handle_rbp_command)
 {
-       if (argc != 1)
+       if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        uint32_t addr;
@@ -2795,19 +2789,21 @@ COMMAND_HANDLER(handle_wp_command)
 {
        struct target *target = get_current_target(cmd_ctx);
 
-       if (argc == 0)
+       if (CMD_ARGC == 0)
        {
                struct watchpoint *watchpoint = target->watchpoints;
 
                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,
-                                                 watchpoint->length,
-                                                 (int)(watchpoint->rw),
-                                                 watchpoint->value,
-                                                 watchpoint->mask);
+                       command_print(cmd_ctx, "address: 0x%8.8" PRIx32
+                                       ", len: 0x%8.8" PRIx32
+                                       ", r/w/a: %i, value: 0x%8.8" PRIx32
+                                       ", mask: 0x%8.8" PRIx32,
+                                       watchpoint->address,
+                                       watchpoint->length,
+                                       (int)watchpoint->rw,
+                                       watchpoint->value,
+                                       watchpoint->mask);
                        watchpoint = watchpoint->next;
                }
                return ERROR_OK;
@@ -2819,7 +2815,7 @@ COMMAND_HANDLER(handle_wp_command)
        uint32_t data_value = 0x0;
        uint32_t data_mask = 0xffffffff;
 
-       switch (argc)
+       switch (CMD_ARGC)
        {
        case 5:
                COMMAND_PARSE_NUMBER(u32, args[4], data_mask);
@@ -2865,7 +2861,7 @@ COMMAND_HANDLER(handle_wp_command)
 
 COMMAND_HANDLER(handle_rwp_command)
 {
-       if (argc != 1)
+       if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        uint32_t addr;
@@ -2886,7 +2882,7 @@ COMMAND_HANDLER(handle_rwp_command)
  */
 COMMAND_HANDLER(handle_virt2phys_command)
 {
-       if (argc != 1)
+       if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        uint32_t va;
@@ -3024,7 +3020,7 @@ COMMAND_HANDLER(handle_profile_command)
        struct timeval timeout, now;
 
        gettimeofday(&timeout, NULL);
-       if (argc != 2)
+       if (CMD_ARGC != 2)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
@@ -4539,7 +4535,7 @@ static void free_fastload(void)
 COMMAND_HANDLER(handle_fast_load_image_command)
 {
        uint8_t *buffer;
-       uint32_t buf_cnt;
+       size_t buf_cnt;
        uint32_t image_size;
        uint32_t min_address = 0;
        uint32_t max_address = 0xffffffff;
@@ -4555,7 +4551,7 @@ COMMAND_HANDLER(handle_fast_load_image_command)
        struct duration bench;
        duration_start(&bench);
 
-       if (image_open(&image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
+       if (image_open(&image, args[0], (CMD_ARGC >= 3) ? args[2] : NULL) != ERROR_OK)
        {
                return ERROR_OK;
        }
@@ -4649,7 +4645,7 @@ COMMAND_HANDLER(handle_fast_load_image_command)
 
 COMMAND_HANDLER(handle_fast_load_command)
 {
-       if (argc > 0)
+       if (CMD_ARGC > 0)
                return ERROR_COMMAND_SYNTAX_ERROR;
        if (fastload == NULL)
        {

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)