Skip to content

The last field of a register was not printed#908

Merged
timsifive merged 1 commit into
riscv:masterfrom
en-sc:en-sc/fix-reg-printers
Oct 25, 2023
Merged

The last field of a register was not printed#908
timsifive merged 1 commit into
riscv:masterfrom
en-sc:en-sc/fix-reg-printers

Conversation

@en-sc
Copy link
Copy Markdown
Contributor

@en-sc en-sc commented Oct 20, 2023

riscv_debug_reg_fields_to_s() exited early without processing the last field.

`riscv_debug_reg_fields_to_s()` exited early without processing the last
field.

Signed-off-by: Evgeniy Naydanov <[email protected]>
Comment thread debug_reg_printer.c
Comment on lines +69 to +70
for (struct riscv_debug_reg_field_list_t list; get_next; get_next = list.get_next) {
list = get_next(context);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see how the old code would omit the last field, because when list.get_next is NULL you still need to print out one more field.

Comment thread debug_reg_printer.c
Comment on lines +64 to +65
struct riscv_debug_reg_field_list_t (*get_next)(riscv_debug_reg_ctx_t contex),
riscv_debug_reg_ctx_t context, uint64_t value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to pass a function get_next instead of the list?

Also, I'm surprised that there are no callers to this function that needed to be updated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to pass a function get_next instead of the list?

IMHO it makes the loop more concise. If one were to transition to passing a list node, the loop would be required to be a do ... while () since there would always be at least one node. I find for loops easier to read. Don't you agree?

Also, I'm surprised that there are no callers to this function that needed to be updated.

This is a static function, only called from riscv_debug_reg_to_s(). The appropriate adjustment (transition from passing a list node to passing a function pointer which generates such node) is made on line 90.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed the github info showing me that line 90 was a different function. Thanks for explaining. This is fine.

Comment thread debug_reg_printer.c
Comment on lines +64 to +65
struct riscv_debug_reg_field_list_t (*get_next)(riscv_debug_reg_ctx_t contex),
riscv_debug_reg_ctx_t context, uint64_t value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed the github info showing me that line 90 was a different function. Thanks for explaining. This is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants