From: Tomas Vanek Date: Thu, 22 Nov 2018 18:05:04 +0000 (+0100) Subject: target: make handle_md_output() global X-Git-Tag: v0.11.0-rc1~650 X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=commitdiff_plain;h=51ef02a5d161820f6d0be8f7984c3dc057b395a9 target: make handle_md_output() global Remove a copy of handle_md_output() from src/target/dsp563xx.c Change-Id: Iadd003fd1dcdbc7990d46a58ee2e7c30826ac6af Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/5175 Tested-by: jenkins Reviewed-by: Antonio Borneo --- diff --git a/src/target/dsp563xx.c b/src/target/dsp563xx.c index d8285e49c8..ef7a31aa65 100644 --- a/src/target/dsp563xx.c +++ b/src/target/dsp563xx.c @@ -1875,67 +1875,6 @@ static int dsp563xx_remove_watchpoint(struct target *target, struct watchpoint * return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } -static void handle_md_output(struct command_invocation *cmd, - struct target *target, - uint32_t address, - unsigned size, - unsigned count, - const uint8_t *buffer) -{ - const unsigned line_bytecnt = 32; - unsigned line_modulo = line_bytecnt / size; - - char output[line_bytecnt * 4 + 1]; - unsigned output_len = 0; - - const char *value_fmt; - switch (size) { - case 4: - value_fmt = "%8.8x "; - break; - case 2: - value_fmt = "%4.4x "; - break; - case 1: - value_fmt = "%2.2x "; - break; - default: - /* "can't happen", caller checked */ - LOG_ERROR("invalid memory read size: %u", size); - return; - } - - for (unsigned i = 0; i < count; i++) { - if (i % line_modulo == 0) - output_len += snprintf(output + output_len, - sizeof(output) - output_len, - "0x%8.8x: ", - (unsigned) (address + i)); - - uint32_t value = 0; - const uint8_t *value_ptr = buffer + i * size; - switch (size) { - case 4: - value = target_buffer_get_u32(target, value_ptr); - break; - case 2: - value = target_buffer_get_u16(target, value_ptr); - break; - case 1: - value = *value_ptr; - } - output_len += snprintf(output + output_len, - sizeof(output) - output_len, - value_fmt, - value); - - if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd, "%s", output); - output_len = 0; - } - } -} - static int dsp563xx_add_custom_watchpoint(struct target *target, uint32_t address, uint32_t memType, enum watchpoint_rw rw, enum watchpoint_condition cond) { @@ -2208,7 +2147,7 @@ COMMAND_HANDLER(dsp563xx_mem_command) err = dsp563xx_read_memory(target, mem_type, address, sizeof(uint32_t), count, buffer); if (err == ERROR_OK) - handle_md_output(CMD, target, address, sizeof(uint32_t), count, buffer); + target_handle_md_output(CMD, target, address, sizeof(uint32_t), count, buffer); } else { b = buffer; diff --git a/src/target/target.c b/src/target/target.c index 0401ff01c9..1e42c5eea9 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3119,7 +3119,7 @@ COMMAND_HANDLER(handle_step_command) return target->type->step(target, current_pc, addr, 1); } -static void handle_md_output(struct command_invocation *cmd, +void target_handle_md_output(struct command_invocation *cmd, struct target *target, target_addr_t address, unsigned size, unsigned count, const uint8_t *buffer) { @@ -3234,7 +3234,7 @@ COMMAND_HANDLER(handle_md_command) struct target *target = get_current_target(CMD_CTX); int retval = fn(target, address, size, count, buffer); if (ERROR_OK == retval) - handle_md_output(CMD, target, address, size, count, buffer); + target_handle_md_output(CMD, target, address, size, count, buffer); free(buffer); diff --git a/src/target/target.h b/src/target/target.h index 65494afd0b..e944838ace 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -36,6 +36,7 @@ struct reg; struct trace; struct command_context; +struct command_invocation; struct breakpoint; struct watchpoint; struct mem_param; @@ -729,6 +730,10 @@ int target_arch_state(struct target *target); void target_handle_event(struct target *t, enum target_event e); +void target_handle_md_output(struct command_invocation *cmd, + struct target *target, target_addr_t address, unsigned size, + unsigned count, const uint8_t *buffer); + #define ERROR_TARGET_INVALID (-300) #define ERROR_TARGET_INIT_FAILED (-301) #define ERROR_TARGET_TIMEOUT (-302)