-
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
riscv: simplify state management during examine #900
riscv: simplify state management during examine #900
Conversation
f058b30
to
e2bdf0e
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.
I think this is an improvement, especially later when the state is restored.
src/target/riscv/riscv-013.c
Outdated
target->state = TARGET_HALTED; | ||
target->debug_reason = DBG_REASON_DBGRQ; |
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.
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.
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.
Agreed, this seems redundant. The change of the recorded target state will be covered by lines 1979 and 1980.
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.
Agreed. Remove these 2 lines.
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'll take look. on the first glance, yes it looks like we should remove this.
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.
addressed
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.
This looks all right to me.
src/target/riscv/riscv-013.c
Outdated
target->state = TARGET_UNKNOWN; | ||
target->debug_reason = DBG_REASON_UNDEFINED; |
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 does this achieve? I don't think it's accessed below, it's just unconditionally overwritten.
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 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:
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.
corrected the message. arp_init
-> arp_examine
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.
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.
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.
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.
src/target/riscv/riscv-013.c
Outdated
target->state = TARGET_HALTED; | ||
target->debug_reason = DBG_REASON_DBGRQ; |
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.
Agreed. Remove these 2 lines.
target->state = TARGET_HALTED; | ||
target->debug_reason = DBG_REASON_UNDEFINED; |
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.
Why is this necessary? We know that the hart is halted on line 2054, and the state should reflect that.
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.
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.
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.
Got it. Thanks.
e2bdf0e
to
0fbdf8c
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.
Just a minor change request. Otherwise good to go.
src/target/riscv/riscv-013.c
Outdated
target->state = TARGET_UNKNOWN; | ||
target->debug_reason = DBG_REASON_UNDEFINED; |
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.
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.
target->state = TARGET_HALTED; | ||
target->debug_reason = DBG_REASON_UNDEFINED; |
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.
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]>
0fbdf8c
to
198edca
Compare
This also fixes a bug when, after
examine
completion, the target stillhas
unknown
status. To reproduce this one spike, it is enough to dothe following:
this behavior is quite dangerous and leads to segfaults in some cases
Change-Id: I13915f7038ad6d0251d56d2d519fbad9a2f13c18