-
Notifications
You must be signed in to change notification settings - Fork 142
Add registers::debug #286
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
Add registers::debug #286
Conversation
1961e1e
to
805333e
Compare
af0e41e
to
d2fe1cb
Compare
d2fe1cb
to
4422d54
Compare
I added docs to everything and properly integrated the assembly. Could you enable the CI for this PR and review it? :) |
@mkroening The basic structure here looks reasonable, I'll see if I have time for a full review this weekend. |
src/registers/debug.rs
Outdated
/// | ||
/// This can be used to modify the flags of this value in-place. | ||
#[inline] | ||
pub fn flags_mut(&mut self) -> &mut Dr7Flags { |
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'm not completely happy with this function, as it could be misused.
I added it to have a way of modifying the Dr7Flags
bits inside the Dr7Value
. Doing so via this mutable reference causes unintended side effects to the fields in Dr7Value
. Perhaps it would be better to manually implement all operations for adding/removing flags from the value instead of transmuting self to the flags. What do you 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.
If additional bits are allowed for Dr7Flags
, can't we make use Dr7Flags
for the inner value directly (instead of u64
)?
Alternatively, we could also merge the Dr7Value
type into the Dr7Flags
type by defining the additional methods in an impl Dr7Flags
block. To get the same behavior for from_bits_truncate
, we could define an addional bitflag const for all the additional value, i.e. const CONDITIONS_AND_SIZE = (1 << 32) - (1 << 16);
.
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, yes. We could use Dr7Flags
for the inner value.
It would expose the same (problematic?) behavior as defining methods on Dr7Flags
or the current behavior: When you have a valid Dr7Value
, there are values which are no bitflags (HwBreakpointCondition
and HwBreakpointSize
). If those values are set to some non-zero value, the behavior of BitAnd
and similar traits are not behaving as one might expect.
So I think to cleanly solve this problem, we would have to remove flags_mut
and implement BitAnd<Flags> for Value
and similar traits manually. We could additionally make use of Dr7Flags
for the inner value, but I am not sure yet if that would be beneficial. What do you 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.
All right. I went ahead and removed this method and any unsafe code handling this type in 0eff064.
I forbid any use of extra bits in the representation of Dr7Flags
and added the explicit *_flags
methods for manipulating Dr7Value
. What do you think?
4422d54
to
57bd96e
Compare
3e6f627
to
6da9989
Compare
Rebased on latest |
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.
Looks very good, thanks a lot! I left a few comments, otherwise this seems ready to be merged.
Sorry for the delay from our side. Thanks for keeping the PR up-to-date!
src/registers/debug.rs
Outdated
/// | ||
/// This can be used to modify the flags of this value in-place. | ||
#[inline] | ||
pub fn flags_mut(&mut self) -> &mut Dr7Flags { |
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.
If additional bits are allowed for Dr7Flags
, can't we make use Dr7Flags
for the inner value directly (instead of u64
)?
Alternatively, we could also merge the Dr7Value
type into the Dr7Flags
type by defining the additional methods in an impl Dr7Flags
block. To get the same behavior for from_bits_truncate
, we could define an addional bitflag const for all the additional value, i.e. const CONDITIONS_AND_SIZE = (1 << 32) - (1 << 16);
.
Thanks a lot for the review! I addressed all small issues and have added my thoughts on the big remaining one. |
0eff064
to
78bd682
Compare
78bd682
to
f38f4e7
Compare
They don't add value over the inherent constructor functions.
Thanks a lot for your reviews and sorry for the wait! I addressed all comments and would appreciate another round of reviews. :) |
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.
Looks good to me!
@josephlr Do you also want to do another round of review?
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.
LGTM, the only thing we might want to change is the fact that we have really long names starting with Debug
, given that the module is also called debug
. So it might make sense to shorten the names to remove the Debug
prefix.
@Freax13 your thoughts?
I think we should keep the prefix, this only affects two types and the names might sound a bit too generic without the |
I renamed them to |
Thank you for your contribution! 🥳 |
🥳 Thanks for your help! |
Would it be possible to have a |
I created a release PR at #386. |
Fixes #284.
This adds
registers::debug
.Dr0
-Dr3
implementDebugAddressRegister
.Dr6Flags
can be read fromDr6
.For
Dr7
I addedDr7Value
which containDr7Flags
but has functions to modify the bits corresponding to the condition and size fields. ViaDr7Value::flags_mut
, you can modify flags in place.