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

riscv: simplify state management during examine #900

Merged

Conversation

aap-sc
Copy link
Collaborator

@aap-sc aap-sc commented Aug 4, 2023

This also fixes a bug when, after examine completion, the target still
has unknown status. To reproduce this one spike, it is enough to do
the following:

// make sure spike harts are halted
openocd ... -c init -c 'echo "[targets]"'

this behavior is quite dangerous and leads to segfaults in some cases

Change-Id: I13915f7038ad6d0251d56d2d519fbad9a2f13c18

Copy link
Collaborator

@MarekVCodasip MarekVCodasip left a comment

Choose a reason for hiding this comment

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

I think this is an improvement, especially later when the state is restored.

Comment on lines 1975 to 1976
target->state = TARGET_HALTED;
target->debug_reason = DBG_REASON_DBGRQ;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seeing as the target-> state is set here and also in riscv013_halt_go and debug_reason later. I would just delete these two lines.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed, this seems redundant. The change of the recorded target state will be covered by lines 1979 and 1980.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. Remove these 2 lines.

Choose a reason for hiding this comment

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

I'll take look. on the first glance, yes it looks like we should remove this.

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 Aug 9, 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.

This looks all right to me.

Comment on lines 1961 to 1962
target->state = TARGET_UNKNOWN;
target->debug_reason = DBG_REASON_UNDEFINED;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this achieve? I don't think it's accessed below, it's just unconditionally overwritten.

Copy link

@EccoTheDolphin EccoTheDolphin Aug 14, 2023

Choose a reason for hiding this comment

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

What does this achieve? I don't think it's accessed below, it's just unconditionally overwritten.

This is for the case when examine fails. Imagine we could not examine/could not finish examination process. This allows us just to reset the state from whatever it was. My understanding is that examine (regardless of the current implementation) can actually be invoked several times (via arp_examine for example). See here:

https://sourceforge.net/p/openocd/mailman/message/33948884/

Choose a reason for hiding this comment

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

corrected the message. arp_init -> arp_examine

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK. Can you add a short comment, like /* In case e.g. riscv013_halt_go() fails. */

Generally I would like to see these status updates happen where we know the status changed, but that's a much larger change.

Choose a reason for hiding this comment

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

OK. Can you add a short comment, like /* In case e.g. riscv013_halt_go() fails. */

Addressed. Please do note that I moved these to lines way higher. I think this is more appropriate place.

Comment on lines 1975 to 1976
target->state = TARGET_HALTED;
target->debug_reason = DBG_REASON_DBGRQ;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. Remove these 2 lines.

Comment on lines +2059 to +2134
target->state = TARGET_HALTED;
target->debug_reason = DBG_REASON_UNDEFINED;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this necessary? We know that the hart is halted on line 2054, and the state should reflect that.

Choose a reason for hiding this comment

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

Why is this necessary? We know that the hart is halted on line 2054, and the state should reflect that.

Yes, we know that the hart is halted. And we have target->state = TARGET_HALTED to indicate that. However, we don't know why hart was halted (since we've just connected) and thus we set the reason to UNDEFINED.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it. Thanks.

JanMatCodasip
JanMatCodasip previously approved these changes Aug 16, 2023
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 a minor change request. Otherwise good to go.

Comment on lines 1961 to 1962
target->state = TARGET_UNKNOWN;
target->debug_reason = DBG_REASON_UNDEFINED;
Copy link
Collaborator

Choose a reason for hiding this comment

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

OK. Can you add a short comment, like /* In case e.g. riscv013_halt_go() fails. */

Generally I would like to see these status updates happen where we know the status changed, but that's a much larger change.

Comment on lines +2059 to +2134
target->state = TARGET_HALTED;
target->debug_reason = DBG_REASON_UNDEFINED;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it. Thanks.

This also fixes a bug when, after `examine` completion, the target still
has  `unknown` status. To reproduce this one spike, it is enough to do
the following:

---
// make sure spike harts are halted
openocd ... -c init -c 'echo "[targets]"'
---

this behavior is quite dangerous and leads to segfaults in some cases

Change-Id: I13915f7038ad6d0251d56d2d519fbad9a2f13c18
Signed-off-by: Parshintsev Anatoly <[email protected]>
@aap-sc aap-sc force-pushed the aap-sc/simplify_state_managment branch from 0fbdf8c to 198edca Compare August 18, 2023 12:29
@aap-sc aap-sc requested a review from timsifive August 23, 2023 19:11
@timsifive timsifive merged commit 5efea16 into riscv-collab:riscv Aug 29, 2023
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