diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 04c39a11fc..1111674ef6 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -371,7 +371,7 @@ static unsigned int decode_dmi(struct target *target, char *text, unsigned int a return decode_dm(text, address - dm->base, data); } -static void dump_field(struct target *target, int idle, const struct scan_field *field) +static void dump_field(struct target *target, int idle, const struct scan_field *field, bool decode_in) { static const char * const op_string[] = {"-", "r", "w", "?"}; static const char * const status_string[] = {"+", "?", "F", "b"}; @@ -390,18 +390,29 @@ static void dump_field(struct target *target, int idle, const struct scan_field unsigned int in_address = in >> DTM_DMI_ADDRESS_OFFSET; log_printf_lf(LOG_LVL_DEBUG, - __FILE__, __LINE__, "scan", + __FILE__, __LINE__, __PRETTY_FUNCTION__, "%db %s %08x @%02x -> %s %08x @%02x; %di", field->num_bits, op_string[out_op], out_data, out_address, status_string[in_op], in_data, in_address, idle); - char out_text[decode_dmi(target, NULL, out_address, out_data) + 1]; - unsigned int out_len = decode_dmi(target, out_text, out_address, out_data); - char in_text[decode_dmi(target, NULL, in_address, in_data) + 1]; - unsigned int in_len = decode_dmi(target, in_text, in_address, in_data); - if (in_text[0] || out_text[0]) { - log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, "scan", "%.*s -> %.*s", - out_len, out_text, in_len, in_text); + const bool decode_out = out_op == DTM_DMI_OP_WRITE; + char out_decoded[decode_dmi(target, NULL, out_address, out_data) + 1]; + const char *out_text = ""; + if (decode_out) + out_text = decode_dmi(target, out_decoded, out_address, out_data) + ? out_decoded + : ""; + + char in_decoded[decode_dmi(target, NULL, in_address, in_data) + 1]; + const char *in_text = ""; + if (decode_in) + in_text = decode_dmi(target, in_decoded, in_address, in_data) + ? in_decoded + : ""; + + if (decode_out || decode_in) { + log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, __PRETTY_FUNCTION__, + "%s -> %s", out_text, in_text); } } @@ -542,7 +553,7 @@ static dmi_status_t dmi_scan(struct target *target, uint32_t *address_in, if (address_in) *address_in = buf_get_u32(in, DTM_DMI_ADDRESS_OFFSET, info->abits); - dump_field(target, idle_count, &field); + dump_field(target, idle_count, &field, /*decode_in*/ data_in); return buf_get_u32(in, DTM_DMI_OP_OFFSET, DTM_DMI_OP_LENGTH); }