Skip to content

Commit ece9f18

Browse files
authored
Merge pull request #909 from riscv/concise_regdump
Make register dump output more concise.
2 parents c4d9ff1 + bdae19a commit ece9f18

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

debug_reg_printer.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,35 @@ static uint64_t riscv_debug_reg_field_value(riscv_debug_reg_field_info_t field,
6262

6363
static unsigned int riscv_debug_reg_fields_to_s(char *buf, unsigned int offset,
6464
struct riscv_debug_reg_field_list_t (*get_next)(riscv_debug_reg_ctx_t contex),
65-
riscv_debug_reg_ctx_t context, uint64_t value)
65+
riscv_debug_reg_ctx_t context, uint64_t value,
66+
enum riscv_debug_reg_show show)
6667
{
6768
unsigned int curr = offset;
68-
curr += get_len_or_sprintf(buf, curr, " { ");
69+
curr += get_len_or_sprintf(buf, curr, " {");
70+
char *separator = "";
6971
for (struct riscv_debug_reg_field_list_t list; get_next; get_next = list.get_next) {
7072
list = get_next(context);
71-
curr += riscv_debug_reg_field_to_s(buf, curr, list.field, context,
72-
riscv_debug_reg_field_value(list.field, value));
73-
curr += get_len_or_sprintf(buf, curr, ", ");
73+
74+
uint64_t field_value = riscv_debug_reg_field_value(list.field, value);
75+
76+
if ((show == RISCV_DEBUG_REG_SHOW_ALL) ||
77+
(show == RISCV_DEBUG_REG_HIDE_UNNAMED_0 &&
78+
(field_value != 0 ||
79+
(list.field.values && list.field.values[0]))) ||
80+
(show == RISCV_DEBUG_REG_HIDE_ALL_0 && field_value != 0)) {
81+
curr += get_len_or_sprintf(buf, curr, separator);
82+
curr += riscv_debug_reg_field_to_s(buf, curr, list.field, context,
83+
field_value);
84+
separator = " ";
85+
}
7486
}
7587
curr += get_len_or_sprintf(buf, curr, "}");
7688
return curr - offset;
7789
}
7890

7991
unsigned int riscv_debug_reg_to_s(char *buf, enum riscv_debug_reg_ordinal reg_ordinal,
80-
riscv_debug_reg_ctx_t context, uint64_t value)
92+
riscv_debug_reg_ctx_t context, uint64_t value,
93+
enum riscv_debug_reg_show show)
8194
{
8295
unsigned int length = 0;
8396

@@ -88,7 +101,7 @@ unsigned int riscv_debug_reg_to_s(char *buf, enum riscv_debug_reg_ordinal reg_or
88101

89102
if (reg.get_fields_head)
90103
length += riscv_debug_reg_fields_to_s(buf, length,
91-
reg.get_fields_head, context, value);
104+
reg.get_fields_head, context, value, show);
92105

93106
if (buf)
94107
buf[length] = '\0';

debug_reg_printer.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
#include "debug_defines.h"
44

5+
enum riscv_debug_reg_show {
6+
RISCV_DEBUG_REG_SHOW_ALL,
7+
RISCV_DEBUG_REG_HIDE_ALL_0,
8+
RISCV_DEBUG_REG_HIDE_UNNAMED_0,
9+
};
10+
511
/**
612
* This function is used to fill a buffer with a decoded string representation
713
* of register's value.
@@ -25,4 +31,5 @@
2531
* riscv_debug_reg_to_s(buf, DTM_DMI_ORDINAL, context, <dmi value>);
2632
*/
2733
unsigned int riscv_debug_reg_to_s(char *buf, enum riscv_debug_reg_ordinal reg_ordinal,
28-
riscv_debug_reg_ctx_t context, uint64_t value);
34+
riscv_debug_reg_ctx_t context, uint64_t value,
35+
enum riscv_debug_reg_show show);

registers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,12 @@ def c_values_array_name(self):
242242

243243
def c_values_array_def(self):
244244
assert len(self.values)
245-
arr_elem_def = (f'[{v.value}] = "{v.name}"' for v in self.values if v.value is not None)
245+
246+
# Remove whitespace from the names, so when they're displayed we can use
247+
# only ' ' as a separator.
248+
arr_elem_def = (f'[{v.value}] = "{toCIdentifier(v.name)}"'
249+
for v in self.values if v.value is not None)
250+
246251
#WA for *lo & *hi splitted fields
247252
if len(self.values) > 2**self.length():
248253
return f"static const char *{self.c_values_array_name()}[{2**self.length()}] = {{}};"

0 commit comments

Comments
 (0)