-
Notifications
You must be signed in to change notification settings - Fork 334
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: manage triggers available to OpenOCD for internal use #1111
Conversation
After riscv-collab/riscv-openocd#1111 is merged, the registers a user wishes to have direct control of should be reserved. This is the case in `HwbpManual`. The test still works with older OpenOCD versions, since no exception is generated when a command (`riscv reserve_trigger` in this case) is not found.
After riscv-collab/riscv-openocd#1111 is merged, the registers a user wishes to have direct control of should be reserved. This is the case in `HwbpManual`. The test still works with older OpenOCD versions, since no exception is generated when a command (`riscv reserve_trigger` in this case) is not found.
This one needs a patch to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch, but I do think at least one of the changes needs further discussion.
if (reg->number == GDB_REGNO_TDATA1 || | ||
reg->number == GDB_REGNO_TDATA2) { | ||
r->manual_hwbp_set = true; | ||
/* When enumerating triggers, we clear any triggers with DMODE set, | ||
* assuming they were left over from a previous debug session. So make | ||
* sure that is done before a user might be setting their own triggers. | ||
*/ | ||
if (riscv_enumerate_triggers(target) != ERROR_OK) | ||
return ERROR_FAIL; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should reserve the trigger (together with an INFO or a WARNING print if it isn't already reserved) if the user touches it via reg_set()
Trough, this raises a question if a watchpoint is set on said trigger, if we should remove it from memory.
What do others think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to avoid it.
- This will require reading
tselect
to know which trigger to reserve. IMHOreg
command should strive to minimize the number of operations it does. - TBH, I think Trigger Module registers should probably be marked as hidden and should not be accessible to user by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do others think?
- My vote is to always print big ugly error message when user tries to access trigger module registers explicitly.
- I would go as far as to render trigger module registers as unavailable to the user by default.
Otherwise it may create way too much hassle because of some obscure corner case when a user wants to mess up with the trigger module while having bp/wp set. I don't think any sane person want to do that. If user is crazy enough to mess with this stuff - he can unlock them an do whatever she/he wants (without any baby-sitting from OpenOCD side).
That being said I would recommend to file an issue for this functionality and merge this patch as is, since in my opinion this patch makes things a little bit better compared to what we have now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy to see the manual_hwbp_set
heuristics removed, since it silently changed the behavior of enabling/disabling triggers when the user touched any of the trigger registers.
I think we should reserve the trigger if (...) What do others think?
My preference would be to keep the trigger CSRs normally visible to the user, and don't perform any extra action if the user modifies any of the trigger CSRs. OpenOCD is a low-level debug tool, and as such it gives the user generally a lot of freedom about what it can do, and at the same time it requires cautious use, otherwise things may go awry.
I'd apply the same logic to the trigger manipulation, and not try to make OpenOCD any more "clever" - just do what the user says. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I like the reserve_trigger
feature. Please, if you can take a look at my comments. Thank you.
if (reg->number == GDB_REGNO_TDATA1 || | ||
reg->number == GDB_REGNO_TDATA2) { | ||
r->manual_hwbp_set = true; | ||
/* When enumerating triggers, we clear any triggers with DMODE set, | ||
* assuming they were left over from a previous debug session. So make | ||
* sure that is done before a user might be setting their own triggers. | ||
*/ | ||
if (riscv_enumerate_triggers(target) != ERROR_OK) | ||
return ERROR_FAIL; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy to see the manual_hwbp_set
heuristics removed, since it silently changed the behavior of enabling/disabling triggers when the user touched any of the trigger registers.
I think we should reserve the trigger if (...) What do others think?
My preference would be to keep the trigger CSRs normally visible to the user, and don't perform any extra action if the user modifies any of the trigger CSRs. OpenOCD is a low-level debug tool, and as such it gives the user generally a lot of freedom about what it can do, and at the same time it requires cautious use, otherwise things may go awry.
I'd apply the same logic to the trigger manipulation, and not try to make OpenOCD any more "clever" - just do what the user says. :)
9a935fc
to
bb02b5f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I had few review comments that I thought I submitted but I forgot. I'm sorry and sending them now.
bb02b5f
to
2ec79ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I like the reserve_triggers
feature very much. This merge request looks very close to completion.
When I read the code again, I made some minor comments and suggestions. If you can please look at them. I don't expect to have any further review findings than what I posted so far.
Thank you.
Before the change, if the user wrote to any `tdata*` register, OpenOCD would sometimes start to disable all the triggers (by writing zeroes to `tdata1`) and re-enable them again (by witing all trigger registers to the values read before for each `tselect` value), e.g. on `step` (see `disable/enable_triggers()`). There are a couple of issues with such approach: 1. RISC-V Debug Specification does not require custom register types to support re-enabling by such sequence of writes (e.g. some custom trigger type may require writing a custom CSR to enable it). 2. OpenOCD may still overwrite these triggers when a user asks to set a new WP. This commit introduces `riscv reserve_trigger ...` command to explicitly mark the triggers OpenOCD should not touch. Such approach allows to separate management of custom triggers and offload it onto the user (e.g. disable/enable such triggers by setting up an event handler on `step`-related events). Change-Id: I3339000445185ab221368442a070f412bf44bfab Signed-off-by: Evgeniy Naydanov <[email protected]>
2ec79ce
to
5a8697b
Compare
riscv-collab/riscv-openocd#1111 introduces a change in OpenOCD behavior: a manual trigger should be manually removed to step/resume from it. This was not concidered in previous stop-gap solutions. This commit on the other hand: 1. Determins if `reserve trigger` is supported by the target. 2. Changes `HwbpManual` test's behavior depending on that. 3. Cleans up some minor mistakes in `HwbpManual`
riscv-collab/riscv-openocd#1111 introduces a change in OpenOCD behavior: a manual trigger should be manually removed to step/resume from it. This was not concidered in previous stop-gap solutions (76ff703 and 8cc4918) This commit on the other hand: 1. Determines if `reserve trigger` is supported by the target. 2. Changes `HwbpManual` test's behavior depending on that. 3. Cleans up some minor mistakes in `HwbpManual`
riscv-collab/riscv-openocd#1111 introduces a change in OpenOCD behavior: a manual trigger should be manually removed to step/resume from it. This was not concidered in previous stop-gap solutions (76ff703 and 8cc4918) This commit: 1. Determines if `reserve trigger` is supported by the target. This can be removed once riscv-collab/riscv-openocd#1111 is merged. 2. Marks `HwbpManual` test as not applicable in case `reserve trigger` is not supported. 3. Accounts for the change in OpenOCD's behavior when stepping from a manual BP. 4. Cleans up some minor mistakes in `HwbpManual`
Before the change, if the user wrote to any
tdata*
register, OpenOCD would sometimes start to disable all the triggers (by writing zeroes totdata1
) and re-enable them again (by witing all trigger registers to the values read before for eachtselect
value), e.g. onstep
(seedisable/enable_triggers()
).There are a couple of issues with such approach:
This commit introduces
riscv reserve_trigger ...
command to explicitly mark the triggers OpenOCD should not touch.Such approach allows to separate management of custom triggers and offload it onto the user (e.g. disable/enable such triggers by setting up an event handler on
step
-related events).Change-Id: I3339000445185ab221368442a070f412bf44bfab