Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target/riscv: cleanup riscv_enumerate_triggers() #909

Merged

Conversation

en-sc
Copy link
Collaborator

@en-sc en-sc commented Aug 25, 2023

  1. Propagate error codes.
  2. Disable leftover triggers in case tinfo is supported.

Change-Id: Ie20edb4d8b9245e13ac8757bf6afe549ac99c4f1


r->triggers_enumerated = true;
r->trigger_count = t + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is incorrect. Why do you do this increment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed.

@en-sc en-sc force-pushed the en-sc/cleanup-enumerate-triggers branch from 4069033 to d4cdb99 Compare August 28, 2023 14:48
@en-sc en-sc requested a review from aap-sc August 28, 2023 14:51
src/target/riscv/riscv.c Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Show resolved Hide resolved
@en-sc en-sc requested a review from JanMatCodasip August 29, 2023 12:40
@en-sc en-sc force-pushed the en-sc/cleanup-enumerate-triggers branch from d4cdb99 to ea43a46 Compare August 29, 2023 14:23
Comment on lines 5065 to 5073
if (get_field(tinfo, CSR_TINFO_INFO) == 1)
/* trigger doesn’t exist */
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
Copy link
Collaborator

@JanMatCodasip JanMatCodasip Aug 30, 2023

Choose a reason for hiding this comment

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

This check has been made less defensive instead of more defensive.

The original code checked for tinfo==1 and tinfo==0.

Please, if you do not wish to extend the condition to the suggested tinfo & 0x1, leave at least the current state, unless there is very good reason to make the check weaker.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed.

@en-sc en-sc force-pushed the en-sc/cleanup-enumerate-triggers branch 3 times, most recently from ff1f07d to 9306ab4 Compare August 31, 2023 08:28
Copy link
Collaborator

@timsifive timsifive left a comment

Choose a reason for hiding this comment

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

This does make things a bit more readable.

Comment on lines +4193 to +4196
const bool trigger_count_available =
riscv_enumerate_triggers(target) == ERROR_OK;
riscv_print_info_line_if_available(CMD, "hart", "trigger_count",
r->trigger_count, trigger_count_available);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You shouldn't print "unavailable" if the problem is that the number of triggers could not be detected, because it could also be interpreted to mean that there are no triggers present. Something like "detection failed" is much more clear.

Instead of creating riscv_print_info_line_if_available, I prefer adding riscv_print_info_line_str and renaming riscv_print_info_line to riscv_print_info_line_int. Then the caller, which knows much more about the details, can decide what to show the user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

According to this comment, the format of the riscv info command is intended to be used directly with TCL's array set.
So I have assumed that it is intended for the output to be machine-readable. Providing a programmer with a way to output an arbitrary string will greatly complicate the parsing of the output.
I can change the string that is currently used.
Currently:

hart.trigger_count           unavailable

Reports that trigger_count is not available.
I can document this in doc/openocd.texi.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point about the TCL array command. Please update the documentation and then leave the code as-is.

src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
@en-sc en-sc force-pushed the en-sc/cleanup-enumerate-triggers branch 2 times, most recently from 8608f17 to 8092e4d Compare September 1, 2023 12:12
Comment on lines 5051 to 5052
/* Mask off the top bit, which is used as tdrmode in old
* implementations. */
Copy link
Collaborator

@JanMatCodasip JanMatCodasip Sep 4, 2023

Choose a reason for hiding this comment

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

It'd be good to adjust this comment per Tim's reply:

Suggested change
/* Mask off the top bit, which is used as tdrmode in old
* implementations. */
/* Mask off the top bit, which is used as tdrmode in legacy RISC-V Debug Spec
* (old revisions of v0.11 spec). */

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed.

JanMatCodasip
JanMatCodasip previously approved these changes Sep 4, 2023
Copy link
Collaborator

@JanMatCodasip JanMatCodasip left a comment

Choose a reason for hiding this comment

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

Looks good to me.

JanMatCodasip
JanMatCodasip previously approved these changes Sep 4, 2023
@en-sc en-sc requested a review from timsifive September 6, 2023 10:26
Copy link
Collaborator

@timsifive timsifive left a comment

Choose a reason for hiding this comment

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

Just the documentation change left.

1. Propagate error codes.
2. Disable leftover triggers in case `tinfo` is supported.

Change-Id: Ie20edb4d8b9245e13ac8757bf6afe549ac99c4f1
Signed-off-by: Evgeniy Naydanov <[email protected]>
@en-sc
Copy link
Collaborator Author

en-sc commented Sep 7, 2023

Just the documentation change left.

Addressed.

@en-sc en-sc requested a review from timsifive September 7, 2023 10:44
@timsifive timsifive merged commit 42dcc99 into riscv-collab:riscv Sep 8, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants