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

provide riscv-specific controls to disable triggers from being used for watchpoints #917

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

kr-sc
Copy link
Contributor

@kr-sc kr-sc commented Sep 14, 2023

Add a new riscv specific commands to disable triggers

@JanMatCodasip
Copy link
Collaborator

I have done only a superficial review so far.

What is the motivation for having these new configuration options, please? If the target supports the given trigger types, why not to always use them? Why would someone force-disable that functionality when the target provides it?

@kr-sc
Copy link
Contributor Author

kr-sc commented Sep 18, 2023

What is the motivation for having these new configuration options, please? If the target supports the given trigger types, why not to always use them? Why would someone force-disable that functionality when the target provides it?

I think, it will be usefull for hardware debugging (for testing particular type of trigger).

@JanMatCodasip
Copy link
Collaborator

I think, it will be useful for hardware debugging (for testing particular type of trigger).

If you wish to test the HW with the help of OpenOCD, I recommend to stick with the existing low-level commands (poll off, riscv dmi_read, riscv dmi_write, reg, ...). You can for example write own TCL script that will perform the requested operations (e.g. set some triggers) and check the outcome. The tests can even be scripted in python -- you can connect through the telnet or TCL channels and execute commands this way. This approach provides more flexibility and allows to test virtually any debug feature.

I would rather not add any TCL commands that have no other use case than testing.

@kr-sc
Copy link
Contributor Author

kr-sc commented Sep 18, 2023

If you wish to test the HW with the help of OpenOCD, I recommend to stick with the existing low-level commands (poll off, riscv dmi_read, riscv dmi_write, reg, ...). You can for example write own TCL script that will perform the requested operations (e.g. set some triggers) and check the outcome. The tests can even be scripted in python -- you can connect through the telnet or TCL channels and execute commands this way. This approach provides more flexibility and allows to test virtually any debug feature.

If we think like that we can write everything with low-level jtag commands (and it is possible, I think), but I think that we want to extend existing codebase to simplify control of debugged unit.

We have a problem with our hardware: equality_match trigger is supported, but it compare only first byte of address of memory access request: for example, if you set a wp on 0x100 with size 4 and try to read from 0x98 with size 4, wp will not hit. So, we want to add an option to turn off usage of this trigger for wp (and at the same time we made a same options for other types of triggers).

@JanMatCodasip
Copy link
Collaborator

JanMatCodasip commented Sep 19, 2023

Thank you for sharing the motivation for this feature.

If we think like that we can write everything with low-level jtag commands (and it is possible, I think) ...

If it would be a hw-testing-only feature, I maintain the opinion that these should not be added to OpenOCD. Test cases for hardware should be developed separately. And if someone wishes to execute them through OpenOCD, the interface to do so is already available (as mentioned in the previous comment).

... but I think that we want to extend existing codebase to simplify control of debugged unit.

I agree as long as there are real use cases for those commands or options (beyond testing).

We have a problem with our hardware: equality_match trigger is supported, but ...

Known issues in existing hardware - that is IMO a good argument to include the feature 👍

@kr-sc kr-sc force-pushed the kr-sc/disable-triggers-option branch 2 times, most recently from a541283 to 27839b1 Compare September 19, 2023 11:50
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
@kr-sc kr-sc force-pushed the kr-sc/disable-triggers-option branch from 27839b1 to fe16177 Compare September 20, 2023 08:26
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.

This looks fine to me overall. I have few last suggestions.

I will not be able to make another review of this since I am out of office until Oct 9. This should not be an issue as this merge request is very close to completion and only minor items are left.

doc/openocd.texi Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
@JanMatCodasip JanMatCodasip dismissed their stale review September 21, 2023 06:28

Previous review dismissed.

@JanMatCodasip JanMatCodasip changed the title provide riscv-specific controls to disable triggers from beeing used for watchpoints provide riscv-specific controls to disable triggers from being used for watchpoints Sep 21, 2023
@kr-sc kr-sc force-pushed the kr-sc/disable-triggers-option branch from fe16177 to fb9486a Compare September 25, 2023 10:22
@timsifive
Copy link
Collaborator

I finally read this. General comments:

  1. You can set custom triggers simply by writing tselect, tdata1, etc. OpenOCD won't overwrite triggers that are already set. No need to mess around with poll or dmi_read/dmi_write.
  2. Work-around for buggy hardware is a good reason for configuration options, assuming they don't make the code too complex.

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.

The implemented feature applies only to watchpoints, but the documentation and command names don't say anything about that.

Instead of making the command names even more cumbersome, I propose:
riscv set_enable_eq_match_trigger [r][w][x]

This lets a user set those trigger types for any combination of read, write, and execute. It might make the implementation a bit more straightforward even. I think you can simply modify try_setup_single_match_trigger() and try_setup_chained_match_triggers() to return error when a type is passed that doesn't fit with the r/w/x bits that are requested.

doc/openocd.texi Outdated
@@ -10871,6 +10871,20 @@ Control dcsr.ebreaku. When on (default), U-mode ebreak instructions trap to
OpenOCD. When off, they generate a breakpoint exception handled internally.
@end deffn

The commands below can be used to prevent OpenOCD from using certain RISC-V trigger features, for example in cases when there are known issues in the target hardware.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you wrap this line? No need to be strictly 80 columns, but 166 is a bit much.
(I know there are a few exceptions to this already, but going forward we're trying to keep the line lengths reasonable.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

src/target/riscv/riscv.c Outdated Show resolved Hide resolved
@kr-sc
Copy link
Contributor Author

kr-sc commented Sep 26, 2023

The implemented feature applies only to watchpoints, but the documentation and command names don't say anything about that.

When on (default), allow OpenOCD to use exact-match triggers in watchpoints. - description of eq_match_trigger_enable command from doc/openocd.texi

When on, allow OpenOCD to use equality match trigger in wp - help message of eq_match_trigger_enable command

@kr-sc
Copy link
Contributor Author

kr-sc commented Sep 26, 2023

Instead of making the command names even more cumbersome, I propose:
riscv set_enable_eq_match_trigger [r][w][x]

As I know, OpenOCD use only equality match trigger for bp. Do we really need command that disables, for example, NAPOT trigger for bp (e mode)?

@kr-sc
Copy link
Contributor Author

kr-sc commented Sep 26, 2023

This lets a user set those trigger types for any combination of read, write, and execute. It might make the implementation a bit more straightforward even. I think you can simply modify try_setup_single_match_trigger() and try_setup_chained_match_triggers() to return error when a type is passed that doesn't fit with the r/w/x bits that are requested.

We don't now type of trigger inside of try_setup_single_match_trigger, because we only pass trigger_request_info struct in it, so I think that it's better not to modify this function.

@kr-sc kr-sc force-pushed the kr-sc/disable-triggers-option branch 2 times, most recently from 63547f4 to 4c12f4a Compare September 26, 2023 08:42
@kr-sc
Copy link
Contributor Author

kr-sc commented Sep 26, 2023

Change output of set_ebable_*_trigger comamnds when it is called without args (like in #918 (comment))

…for watchpoints

Add a new riscv specific commands to disable triggers

Change-Id: Ic1842085aa66851c740e0abcbfbe0adbe930920e
Signed-off-by: Kirill Radkin <[email protected]>
@kr-sc kr-sc force-pushed the kr-sc/disable-triggers-option branch from 4c12f4a to e76a9b7 Compare October 2, 2023 08:54
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.

I have re-checked the code visually and it looks all right.

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.

We don't know type of trigger inside of try_setup_single_match_trigger, because we only pass trigger_request_info struct in it, so I think that it's better not to modify this function.

The type is encoded in tdata1 of the trigger_request_info, though. It would be trivial to add a line there that checks the type and match fields, and then compares it against whatever the user configured.

Regardless. Since you've already implemented this, I guess it's good enough. In the future, can you open an issue or something when you're planning on adding new commands? That way we can have a little discussion on what commands make the most sense. I think my idea would have been just as much work to implement, and would have left us with a command that is more useful in the future, when OpenOCD implementation changes, or when we encounter hardware with different bugs.

@kr-sc
Copy link
Contributor Author

kr-sc commented Oct 11, 2023

In the future, can you open an issue or something when you're planning on adding new commands?

Yes, next time I'll do it.

@timsifive timsifive merged commit beb7059 into riscv-collab:riscv Oct 11, 2023
5 checks passed
.tdata1_ignore_mask = fields.tdata1_ignore_mask
};
struct trigger_request_info ge_2 = {
if (r->enable_ge_lt_trigger) {
Copy link
Collaborator

@aap-sc aap-sc Oct 18, 2023

Choose a reason for hiding this comment

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

@kr-sc , I'd like to request few additional improvements:

  1. enable_ge_lt_trigger should be renamed to wp_enable_ge_lt_trigger (this applies to other controls as well). This is to clearly identify that these controls are for watchpoints only.
  2. when trigger->length == 0 we should allow for equality match to be used regardless of this control (otherwise we won't be able to set such wathcpoints)

Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

4 participants