From 3b0c654c6767ee73a2861e07200ca81ae7a89604 Mon Sep 17 00:00:00 2001 From: Evgeniy Naydanov Date: Wed, 1 Nov 2023 17:04:33 +0300 Subject: [PATCH 1/2] target/riscv: dump_field() shouldn't always decode Sometimes, the value from of some DMI scans has no meaning (e.g. when `op` is read). Such values should not be decoded. To make the dumps more consistent, `` is printed when there is no decoding for a register. Change-Id: I415f06a5a80f2fc8fb8ab3f79132bdf0602c8ad6 Signed-off-by: Evgeniy Naydanov --- src/target/riscv/riscv-013.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 04a430d2c..8ec7b257d 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 discard_in) { static const char * const op_string[] = {"-", "r", "w", "?"}; static const char * const status_string[] = {"+", "?", "F", "b"}; @@ -390,18 +390,22 @@ 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); + if (out_op == DTM_DMI_OP_WRITE) { + char out_decoded[decode_dmi(target, NULL, out_address, out_data) + 1]; + decode_dmi(target, out_decoded, out_address, out_data); + log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, __PRETTY_FUNCTION__, + "write: %s", out_decoded); + } + if (!discard_in && in_op == DTM_DMI_OP_SUCCESS) { + char in_decoded[decode_dmi(target, NULL, in_address, in_data) + 1]; + decode_dmi(target, in_decoded, in_address, in_data); + log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, __PRETTY_FUNCTION__, + "read: %s", in_decoded); } } @@ -542,7 +546,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, /*discard_in*/ !data_in); return buf_get_u32(in, DTM_DMI_OP_OFFSET, DTM_DMI_OP_LENGTH); } From 00320fd198868eb5eb1672126a4f96ead3411ff0 Mon Sep 17 00:00:00 2001 From: Evgeniy Naydanov Date: Sat, 11 Nov 2023 14:21:24 +0300 Subject: [PATCH 2/2] target/riscv: replace `__PRETTY_FUNCTION__` with `__func__` The reasoning for the change: * `__func__` is part of C99, `__PRETTY_FUNCTION__` is GNU extension. * `__PRETTY_FUNCTION__` is defined to be the same as `__func__` for C sources by GCC documentation but differ for C++ sources (full signature instead of just a name). * Currently Clang does support `__PRETTY_FUNCTION__`, though it uses GCC's C++ variant across C and C++. Therefore using `__PRETTY_FUNCTION__` creates confusion and does not provide any valueble information in the logs. Change-Id: Ie0db6d73f602784b6752a30911dcef3dd7ee4594 --- src/target/riscv/batch.c | 4 ++-- src/target/riscv/riscv-013.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/target/riscv/batch.c b/src/target/riscv/batch.c index 2dbf851ba..cdbf32ed3 100644 --- a/src/target/riscv/batch.c +++ b/src/target/riscv/batch.c @@ -215,13 +215,13 @@ static void dump_field(int idle, const struct scan_field *field) unsigned int in_address = in >> DTM_DMI_ADDRESS_OFFSET; log_printf_lf(LOG_LVL_DEBUG, - __FILE__, __LINE__, __PRETTY_FUNCTION__, + __FILE__, __LINE__, __func__, "%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); } else { log_printf_lf(LOG_LVL_DEBUG, - __FILE__, __LINE__, __PRETTY_FUNCTION__, "%db %s %08x @%02x -> ?; %di", + __FILE__, __LINE__, __func__, "%db %s %08x @%02x -> ?; %di", field->num_bits, op_string[out_op], out_data, out_address, idle); } } diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 8ec7b257d..3c7fd11f8 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -389,8 +389,7 @@ static void dump_field(struct target *target, int idle, const struct scan_field unsigned int in_data = get_field(in, DTM_DMI_DATA); unsigned int in_address = in >> DTM_DMI_ADDRESS_OFFSET; - log_printf_lf(LOG_LVL_DEBUG, - __FILE__, __LINE__, __PRETTY_FUNCTION__, + log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, __func__, "%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); @@ -398,13 +397,13 @@ static void dump_field(struct target *target, int idle, const struct scan_field if (out_op == DTM_DMI_OP_WRITE) { char out_decoded[decode_dmi(target, NULL, out_address, out_data) + 1]; decode_dmi(target, out_decoded, out_address, out_data); - log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, __PRETTY_FUNCTION__, + log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, __func__, "write: %s", out_decoded); } if (!discard_in && in_op == DTM_DMI_OP_SUCCESS) { char in_decoded[decode_dmi(target, NULL, in_address, in_data) + 1]; decode_dmi(target, in_decoded, in_address, in_data); - log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, __PRETTY_FUNCTION__, + log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, __func__, "read: %s", in_decoded); } }