-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Dynamic RegId
Support
#58
Conversation
Not too sure what's up with that |
gdbstub_arch/src/arm/reg/id.rs
Outdated
@@ -31,6 +33,6 @@ impl RegId for ArmCoreRegId { | |||
25 => Self::Cpsr, | |||
_ => return None, | |||
}; | |||
Some((reg, 4)) | |||
Some((reg, Some(NonZeroUsize::new(4).unwrap()))) |
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.
Any recommendations for these unwrap()
calls? I know they're not allowed in gdbstub
code, but this will just get optimized out by the compiler.
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 mean, since you're already in a function that returns Option<_>
, you can just use NonZeroUsize::new(x)?
.
At the end of the day, any reasonably optimizing compiler should generate equivalent code when using ?
or unwrap
in these trivial cases (i.e: it'll elide the None branch entirely)
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.
👍 using the ?
operator is a nicer shorthand :)
I wish there was a new()
compile-time constructor that threw a compiler error if the constant evaluated to 0 - that'd be a bit nicer.
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.
sigh, preaching to the choir...
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.
😂 time to submit some RFCs to Rust I guess
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.
Yeah, this change is looking pretty reasonable!
I've left some comments, but all in all, this seems to be on the right track.
I'll also pop open a dev/0.6
branch which is based off the current master
, and we'll switch the branch target for this PR over to it. EDIT: I just did that, so this PR will land in dev/0.6
With regards to I should probably add that to the PR template... As for how to read single registers from the GDB client... that's a bit tricky. Here is the relevant code in GDB itself that fetches register values using the RSP: https://github.com/bminor/binutils-gdb/blob/master/gdb/remote.c#L8552-L8598 As you can see, it'll only fall back to using The motivating example that came up when this feature was first implemented was the RISC-V Instead, if there's a similar scenario that you can test in one of the architectures that your project uses, I would appreciate it if you could post the GDB output + protocol from your project. If not, that's probably fine, since the diff is pretty small, and the implementation seems reasonable. |
As always, thanks for the ⚡ fast review :) I will work through your comments and make the appropriate changes. |
No problem!
Unfortunate, but totally understandable. Since this is landing in the |
Howdy! I'm back after a refreshing long weekend, and it's time to get back into the swing of things. A cursory review of the PR indicates that there are still some comments that need to get resolved. Namely, there's still a matter of updating the documentation, replacing the current Since this is landing in p.s: feel free to un-draft the PR |
Appreciate it! Yeah, I still have some work to do with addressing those comments. Got distracted with other stuff so I just pushed off the changes I had :) |
Going to need some thought on that latest commit - I appear to have hit an odd compiler error:
I see the following issue on Rust that discusses this specific error: rust-lang/rust#70263 |
Ignore what I just said. It's actually fixable simply by not using a variable for the closure, and instead defining it inline. the explanation is something something lifetimes something something Rust magic ✨ let mut err = Ok(());
// TODO: Limit the number of bytes transferred on the wire to the register size
// (if specified).
ops.read_register(
id,
reg_id,
SendRegisterOutput::new(&mut |buf| match res.write_hex_buf(buf) {
Ok(_) => {}
Err(e) => err = Err(e),
}),
)
.handle_error()?;
err?; |
¯\_(ツ)_/¯ Well, the compiler was probably right but I don't know why. |
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.
You've also still got to swap those .unwrap()
calls for ?
invocations.
Good to go! Will still need to do testing though... Edit: Ah, appears not. Perhaps we can add one? I see |
If you'd like to add SPRS to the armv4t example, that would be great! That said, I'm not sure how easy it'll be, and it might require tweaking the underling If not, then let me know once you've tested it and confirmed that things are working as expected. |
Ack. It appears that GDB does not expose P.S: Can we put down some links to GDB source above the |
That's a good idea. It shouldn't be too hard, since IIRC they should just be the same links as those linked to by the associated |
Perfect - I'll do that as part of this PR! Also, it looks like GDB prefers the
|
Yep, I know. Too bad we aren't actually modifying the |
True - just a little note for myself so I can use it to test |
Any updates on this PR? Did you have a chance to validate that things are working as expected? |
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.
a couple of minor doc tweaks
@@ -65,3 +65,19 @@ pub trait SingleRegisterAccess<Id>: Target { | |||
/// See [`SingleRegisterAccess`] | |||
pub type SingleRegisterAccessOps<'a, Id, T> = | |||
&'a mut dyn SingleRegisterAccess<Id, Arch = <T as Target>::Arch, Error = <T as Target>::Error>; | |||
|
|||
/// An interface to send register data to the GDB remote debugger. |
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.
/// An interface to send register data to the GDB remote debugger. | |
/// An interface to send register data back to the GDB client. |
Self { inner } | ||
} | ||
|
||
/// Write out raw register bytes to the GDB debugger. |
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.
/// Write out raw register bytes to the GDB debugger. | |
/// Write raw register bytes to GDB. Bytes must be sent in the target's native endian order. |
GDB stands for GNU DeBugger, so "GDB debugger" is redundant (like ATM Machine)
Hey - no updates as of now. I got hung up on the issue that gdb does not actually expose SPRs for common PPC architectures (even OEA SPRs) and went to different tasking. I can apply your suggested changes on Monday and then I probably won't be working on this for a few weeks. |
Gotcha. All good! FYI, it seems that 0.6 will be coming out a bit sooner than expected (thanks to a recently reported bug in the breakpoint/watchpoints API + the in-progress state-machine refactoring I've been working on), so there's a non-zero chance I'll just pull the trigger and merge this PR as-is at some point in the coming weeks. I think these changes are worthwhile, and I'd rather have them land as part of 0.6, rather than some future 0.7 release. |
P.S: you should be able to manually define custom SPRs by returning a custom target.xml. Just because all the architectures currently implemented in See https://sourceware.org/gdb/current/onlinedocs/gdb/Target-Description-Format.html#Target-Description-Format for more details (with special attention to |
Oh - huh, I never thought of that! |
Hey, heads up, I decided to see what exactly defining a custom If you run the armv4t example now, you'll see two new non-standard registers show up: Hopefully this new example helps you out with defining custom target.xml files. Also, you'll need to rebase this PR on-top of these changes, and make sure that the 'p' packet still works as intended. Cheers |
Ah - perfect! Thanks for looking into that! |
Yeah, no worries. Playing around with custom target.xml files is something I've been meaning to do for a while now :) |
Hope this PR will be merged in |
Yep, I'll formally add it to the roadmap, and I'll look into merging it into dev/0.6 sometime soon-ish. I've been a bit busy lately, and haven't had too much time to work on gdbstub. Hopefully I'll have some time over the July 4th long weekend to polish up some changes I've been working on + integrate these changes. Not sure about a hard release date for 0.6 yet, but I'd wager it's still a few weeks away. |
Any updates? |
As you might have guessed, my plan to "polish up my local changes + integrate these changes" hadn't panned out as I hoped 😅 I've been quite busy with work / life recently, so while I've been able to carve out some time in the morning to review PRs, I haven't had the chance to get back into "hands-on programming" mode with With the vFile stuff coming in though, |
abdaca5
to
7b15a18
Compare
Description
As per a discussion in #53, (comment),
gdbstub
'sRegId
abstraction does not have a way to support dynamic register files due to the register size field returned fromRegId::from_raw_id
.As suggested by @daniel5151, we can make the register size an optional hint, and enforce register sizing based on that.
This changeset also removes the array allocated in the single register access handler, and instead passes the target a closure that behaves in a similar manner to the one passed to
Registers::gdb_serialize
.API Stability
This will break SemVer compatibility, though for a good reason.
Checklist
cargo build
compiles withouterrors
orwarnings
cargo clippy
runs withouterrors
orwarnings
cargo fmt
was runValidation
TODO...
P.S: How do I query a single register using a GDB client?
GDB output
armv4t output