@@ -62,22 +62,35 @@ static uint64_t riscv_debug_reg_field_value(riscv_debug_reg_field_info_t field,
6262
6363static 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
7991unsigned 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' ;
0 commit comments