#include "target.h"
#include "target_type.h"
#include "target_request.h"
+#include "breakpoints.h"
#include "time_support.h"
#include "register.h"
#include "trace.h"
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;
}
{
struct target *target = all_targets;
- if (argc == 1)
+ if (CMD_ARGC == 1)
{
target = get_target(args[0]);
if (target == NULL) {
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;
}
/* 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);
}
/* 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);
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");
return retval;
}
- else if (argc == 1)
+ else if (CMD_ARGC == 1)
{
if (strcmp(args[0], "on") == 0)
{
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)
if (ERROR_OK != retval)
return retval;
- if (argc == 1)
+ if (CMD_ARGC == 1)
{
unsigned wait;
retval = parse_uint(args[0], &wait);
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]);
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);
* 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;
COMMAND_HANDLER(handle_step_command)
{
- if (argc > 1)
+ if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR;
LOG_DEBUG("-");
* 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;
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;
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;
}
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);
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;
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;
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);
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)
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;
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;
}
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;
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)
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));
}
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;
struct target *target = get_current_target(cmd_ctx);
- if (argc < 1)
+ if (CMD_ARGC < 1)
{
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct duration bench;
duration_start(&bench);
- if (argc >= 2)
+ if (CMD_ARGC >= 2)
{
uint32_t addr;
COMMAND_PARSE_NUMBER(u32, args[1], addr);
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;
}
}
} 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);
}
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;
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;
COMMAND_HANDLER(handle_rbp_command)
{
- if (argc != 1)
+ if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
uint32_t addr;
{
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;
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);
COMMAND_HANDLER(handle_rwp_command)
{
- if (argc != 1)
+ if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
uint32_t addr;
*/
COMMAND_HANDLER(handle_virt2phys_command)
{
- if (argc != 1)
+ if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
uint32_t va;
struct timeval timeout, now;
gettimeofday(&timeout, NULL);
- if (argc != 2)
+ if (CMD_ARGC != 2)
{
return ERROR_COMMAND_SYNTAX_ERROR;
}
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;
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;
}
COMMAND_HANDLER(handle_fast_load_command)
{
- if (argc > 0)
+ if (CMD_ARGC > 0)
return ERROR_COMMAND_SYNTAX_ERROR;
if (fastload == NULL)
{